@nocobase/app 2.2.0-beta.10 → 2.2.0-beta.12
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/client/src/__tests__/runtimePublicPath.test.ts +13 -3
- package/client/src/runtimePublicPath.ts +12 -3
- package/client-v2/src/__tests__/runtimePublicPath.test.ts +26 -0
- package/client-v2/src/main.tsx +2 -3
- package/client-v2/src/runtimePublicPath.ts +34 -0
- package/dist/client/assets/{index-d9f84b83.js → index-45bf8cbd.js} +316 -316
- package/dist/client/assets/{vendor-misc-0f74f11a.js → vendor-misc-c30c528b.js} +5 -5
- package/dist/client/index.html +1 -1
- package/dist/client/index.html.tpl +1 -1
- package/dist/client/v/assets/{2025-87ab227c.js → 4574-1995d64e.js} +2 -2
- package/dist/client/v/assets/{index-a312bffe.js → index-e93c3298.js} +117 -117
- package/dist/client/v/index.html +1 -1
- package/lib/config/cache.js +1 -1
- package/package.json +7 -7
- package/src/config/cache.ts +1 -1
- /package/dist/client/assets/{index-d9f84b83.js.LICENSE.txt → index-45bf8cbd.js.LICENSE.txt} +0 -0
- /package/dist/client/assets/{vendor-misc-0f74f11a.js.LICENSE.txt → vendor-misc-c30c528b.js.LICENSE.txt} +0 -0
- /package/dist/client/v/assets/{2025-87ab227c.js.LICENSE.txt → 4574-1995d64e.js.LICENSE.txt} +0 -0
- /package/dist/client/v/assets/{2025-5c7b4a6f.css → 4574-5c7b4a6f.css} +0 -0
- /package/dist/client/v/assets/{index-a312bffe.js.LICENSE.txt → index-e93c3298.js.LICENSE.txt} +0 -0
|
@@ -11,13 +11,23 @@ import { resolveRuntimeAssetPublicPath } from '../runtimePublicPath';
|
|
|
11
11
|
|
|
12
12
|
describe('resolveRuntimeAssetPublicPath', () => {
|
|
13
13
|
it('should prefer the injected window public path over an auto-detected runtime path', () => {
|
|
14
|
-
expect(resolveRuntimeAssetPublicPath('/dist/2.1.8/', 'https://static.cloudflareinsights.com/assets/../')).toBe(
|
|
14
|
+
expect(resolveRuntimeAssetPublicPath('/dist/2.1.8/', '/', 'https://static.cloudflareinsights.com/assets/../')).toBe(
|
|
15
15
|
'/dist/2.1.8/',
|
|
16
16
|
);
|
|
17
17
|
});
|
|
18
18
|
|
|
19
|
-
it('should
|
|
20
|
-
expect(resolveRuntimeAssetPublicPath(
|
|
19
|
+
it('should use the app public path when the CDN base URL is empty', () => {
|
|
20
|
+
expect(resolveRuntimeAssetPublicPath('', '/', 'https://static.cloudflareinsights.com/assets/../')).toBe('/');
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('should use the configured APP_PUBLIC_PATH when the CDN base URL is empty', () => {
|
|
24
|
+
expect(resolveRuntimeAssetPublicPath('', '/custom-base/', 'https://static.cloudflareinsights.com/assets/../')).toBe(
|
|
25
|
+
'/custom-base/',
|
|
26
|
+
);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('should fall back to the runtime public path when the injected paths are missing', () => {
|
|
30
|
+
expect(resolveRuntimeAssetPublicPath(undefined, undefined, 'https://cdn.nocobase.com/dist/2.1.8/')).toBe(
|
|
21
31
|
'https://cdn.nocobase.com/dist/2.1.8/',
|
|
22
32
|
);
|
|
23
33
|
});
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
declare global {
|
|
11
11
|
interface Window {
|
|
12
|
+
__nocobase_public_path__?: string;
|
|
12
13
|
__webpack_public_path__?: string;
|
|
13
14
|
}
|
|
14
15
|
}
|
|
@@ -22,10 +23,14 @@ function normalizePublicPath(value: string | undefined, fallback = '/') {
|
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
export function resolveRuntimeAssetPublicPath(
|
|
25
|
-
|
|
26
|
+
cdnPublicPath: string | undefined,
|
|
27
|
+
appPublicPath: string | undefined,
|
|
26
28
|
runtimePublicPath: string | undefined,
|
|
27
29
|
) {
|
|
28
|
-
return normalizePublicPath(
|
|
30
|
+
return normalizePublicPath(
|
|
31
|
+
cdnPublicPath,
|
|
32
|
+
normalizePublicPath(appPublicPath, normalizePublicPath(runtimePublicPath, '/')),
|
|
33
|
+
);
|
|
29
34
|
}
|
|
30
35
|
|
|
31
36
|
// `__webpack_public_path__` is a webpack magic global that must be assigned
|
|
@@ -36,5 +41,9 @@ const runtimePublicPath = typeof __webpack_public_path__ === 'string' ? __webpac
|
|
|
36
41
|
|
|
37
42
|
if (typeof window !== 'undefined' && typeof __webpack_public_path__ !== 'undefined') {
|
|
38
43
|
// eslint-disable-next-line prefer-const
|
|
39
|
-
__webpack_public_path__ = resolveRuntimeAssetPublicPath(
|
|
44
|
+
__webpack_public_path__ = resolveRuntimeAssetPublicPath(
|
|
45
|
+
window.__webpack_public_path__,
|
|
46
|
+
window.__nocobase_public_path__,
|
|
47
|
+
runtimePublicPath,
|
|
48
|
+
);
|
|
40
49
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
import { resolveRuntimeAssetPublicPath } from '../runtimePublicPath';
|
|
11
|
+
|
|
12
|
+
describe('resolveRuntimeAssetPublicPath', () => {
|
|
13
|
+
it('should append the fixed build asset directory to the CDN base URL', () => {
|
|
14
|
+
expect(resolveRuntimeAssetPublicPath('https://cdn.nocobase.com/dist/2.1.22/', '/v/', 'v')).toBe(
|
|
15
|
+
'https://cdn.nocobase.com/dist/2.1.22/v/',
|
|
16
|
+
);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('should use the modern client public path when the CDN base URL is empty', () => {
|
|
20
|
+
expect(resolveRuntimeAssetPublicPath('', '/v/', 'v')).toBe('/v/');
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('should use APP_PUBLIC_PATH plus the runtime modern prefix when the CDN base URL is empty', () => {
|
|
24
|
+
expect(resolveRuntimeAssetPublicPath('', '/custom-base/modern/', 'v')).toBe('/custom-base/modern/');
|
|
25
|
+
});
|
|
26
|
+
});
|
package/client-v2/src/main.tsx
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
import { Application, getModernClientPrefix } from '@nocobase/client-v2';
|
|
11
11
|
import devDynamicImport from './.plugins';
|
|
12
12
|
import { NocoBaseClientPresetPluginV2 } from '@nocobase/preset-nocobase/client-v2';
|
|
13
|
+
import { resolveRuntimeAssetPublicPath } from './runtimePublicPath';
|
|
13
14
|
|
|
14
15
|
declare global {
|
|
15
16
|
interface Window {
|
|
@@ -113,9 +114,7 @@ function getBuildAssetDir() {
|
|
|
113
114
|
declare let __webpack_public_path__: string;
|
|
114
115
|
const cdnBase = window.__webpack_public_path__;
|
|
115
116
|
// eslint-disable-next-line prefer-const
|
|
116
|
-
__webpack_public_path__ = cdnBase
|
|
117
|
-
? ensureSlash(`${cdnBase.replace(/\/$/, '')}/${getBuildAssetDir()}/`, '/')
|
|
118
|
-
: v2PublicPath;
|
|
117
|
+
__webpack_public_path__ = resolveRuntimeAssetPublicPath(cdnBase, v2PublicPath, getBuildAssetDir());
|
|
119
118
|
|
|
120
119
|
const app = new Application({
|
|
121
120
|
publicPath: v2PublicPath,
|
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
function normalizePublicPath(value: string, fallback: string) {
|
|
11
|
+
let normalized = value.trim() || fallback;
|
|
12
|
+
if (!normalized.endsWith('/')) {
|
|
13
|
+
normalized = `${normalized}/`;
|
|
14
|
+
}
|
|
15
|
+
return normalized;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function resolveRuntimeAssetPublicPath(
|
|
19
|
+
cdnPublicPath: string | undefined,
|
|
20
|
+
appPublicPath: string,
|
|
21
|
+
buildAssetDir: string,
|
|
22
|
+
) {
|
|
23
|
+
const normalizedAppPublicPath = normalizePublicPath(appPublicPath, '/');
|
|
24
|
+
const normalizedCdnPublicPath = cdnPublicPath?.trim();
|
|
25
|
+
if (!normalizedCdnPublicPath) {
|
|
26
|
+
return normalizedAppPublicPath;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const normalizedBuildAssetDir = buildAssetDir.replace(/^\/+|\/+$/g, '');
|
|
30
|
+
return normalizePublicPath(
|
|
31
|
+
`${normalizedCdnPublicPath.replace(/\/+$/, '')}/${normalizedBuildAssetDir}/`,
|
|
32
|
+
normalizedAppPublicPath,
|
|
33
|
+
);
|
|
34
|
+
}
|