@nocobase/cli-v1 2.1.0-beta.45 → 2.1.0-beta.46

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/cli-v1",
3
- "version": "2.1.0-beta.45",
3
+ "version": "2.1.0-beta.46",
4
4
  "description": "",
5
5
  "license": "Apache-2.0",
6
6
  "main": "./src/index.js",
@@ -8,9 +8,9 @@
8
8
  "nocobase-v1": "./bin/index.js"
9
9
  },
10
10
  "dependencies": {
11
- "@nocobase/cli": "2.1.0-beta.45",
11
+ "@nocobase/cli": "2.1.0-beta.46",
12
12
  "@nocobase/license-kit": "^0.3.8",
13
- "@nocobase/utils": "2.1.0-beta.45",
13
+ "@nocobase/utils": "2.1.0-beta.46",
14
14
  "chalk": "^4.1.1",
15
15
  "commander": "^9.2.0",
16
16
  "deepmerge": "^4.3.1",
@@ -25,7 +25,7 @@
25
25
  "tree-kill": "^1.2.2"
26
26
  },
27
27
  "devDependencies": {
28
- "@nocobase/devtools": "2.1.0-beta.45",
28
+ "@nocobase/devtools": "2.1.0-beta.46",
29
29
  "@types/fs-extra": "^11.0.1"
30
30
  },
31
31
  "repository": {
@@ -33,5 +33,5 @@
33
33
  "url": "git+https://github.com/nocobase/nocobase.git",
34
34
  "directory": "packages/core/cli"
35
35
  },
36
- "gitHead": "42587115fc34c3eb01ef2b2549f1c998e5708318"
36
+ "gitHead": "91fd3ab238a5ff58735bbfca04a8cb05d233b0af"
37
37
  }
@@ -0,0 +1,45 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ /* eslint-env jest */
11
+
12
+ const fs = require('fs-extra');
13
+ const os = require('os');
14
+ const path = require('path');
15
+ const { resolveDefaultCdnBaseUrlFromActiveVersion } = require('../util');
16
+
17
+ describe('cli-v1 default CDN_BASE_URL', () => {
18
+ const originalEnv = { ...process.env };
19
+
20
+ afterEach(() => {
21
+ process.env = { ...originalEnv };
22
+ });
23
+
24
+ test('prefers the extracted dist-client active version when available', async () => {
25
+ const storagePath = await fs.mkdtemp(path.join(os.tmpdir(), 'nocobase-dist-client-'));
26
+ const distClientRoot = path.join(storagePath, 'dist-client');
27
+ await fs.ensureDir(distClientRoot);
28
+ await fs.writeFile(path.join(distClientRoot, 'active-version'), '2.1.0-beta.45\n', 'utf8');
29
+ process.env.STORAGE_PATH = storagePath;
30
+
31
+ expect(resolveDefaultCdnBaseUrlFromActiveVersion('/console/')).toBe('/console/dist/2.1.0-beta.45/');
32
+ expect(resolveDefaultCdnBaseUrlFromActiveVersion('/')).toBe('/dist/2.1.0-beta.45/');
33
+
34
+ await fs.remove(storagePath);
35
+ });
36
+
37
+ test('returns undefined when the active version file is missing', async () => {
38
+ const storagePath = await fs.mkdtemp(path.join(os.tmpdir(), 'nocobase-dist-client-empty-'));
39
+ process.env.STORAGE_PATH = storagePath;
40
+
41
+ expect(resolveDefaultCdnBaseUrlFromActiveVersion('/console/')).toBeUndefined();
42
+
43
+ await fs.remove(storagePath);
44
+ });
45
+ });
package/src/util.js CHANGED
@@ -367,6 +367,38 @@ function resolvePublicPath(appPublicPath = '/') {
367
367
 
368
368
  exports.resolvePublicPath = resolvePublicPath;
369
369
 
370
+ function resolveDistPublicPath(appPublicPath = '/') {
371
+ const publicPath = resolvePublicPath(appPublicPath).replace(/\/+$/, '');
372
+ return `${publicPath}/dist/`;
373
+ }
374
+
375
+ function buildDefaultCdnBaseUrl(appPublicPath, version) {
376
+ const normalizedVersion = String(version || '')
377
+ .trim()
378
+ .replace(/^\/+|\/+$/g, '');
379
+ if (!normalizedVersion) {
380
+ return undefined;
381
+ }
382
+ return `${resolveDistPublicPath(appPublicPath)}${normalizedVersion}/`;
383
+ }
384
+
385
+ exports.buildDefaultCdnBaseUrl = buildDefaultCdnBaseUrl;
386
+
387
+ function resolveDefaultCdnBaseUrlFromActiveVersion(appPublicPath = '/') {
388
+ try {
389
+ const activeVersionFile = storagePathJoin('dist-client', 'active-version');
390
+ if (!fs.existsSync(activeVersionFile)) {
391
+ return undefined;
392
+ }
393
+ const activeVersion = String(fs.readFileSync(activeVersionFile, 'utf8') || '').trim();
394
+ return buildDefaultCdnBaseUrl(appPublicPath, activeVersion);
395
+ } catch (_error) {
396
+ return undefined;
397
+ }
398
+ }
399
+
400
+ exports.resolveDefaultCdnBaseUrlFromActiveVersion = resolveDefaultCdnBaseUrlFromActiveVersion;
401
+
370
402
  // Default URL segment under which the modern (v2) client is served.
371
403
  // Kept local here so the CLI bootstrap (bin/index.js -> initEnv) stays lightweight
372
404
  // and does not have to require heavier packages. A second copy of the fixed
@@ -622,8 +654,10 @@ exports.initEnv = function initEnv() {
622
654
  process.env.__env_modified__ = true;
623
655
  }
624
656
 
625
- if (!process.env.CDN_BASE_URL && process.env.APP_PUBLIC_PATH !== '/') {
626
- process.env.CDN_BASE_URL = process.env.APP_PUBLIC_PATH;
657
+ if (!process.env.CDN_BASE_URL) {
658
+ process.env.CDN_BASE_URL =
659
+ resolveDefaultCdnBaseUrlFromActiveVersion(process.env.APP_PUBLIC_PATH) ||
660
+ (process.env.APP_PUBLIC_PATH !== '/' ? process.env.APP_PUBLIC_PATH : '');
627
661
  }
628
662
 
629
663
  if (process.env.CDN_BASE_URL.includes('http') && process.env.CDN_VERSION === 'auto') {