@nocobase/app 2.2.0-beta.1 → 2.2.0-beta.11

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.
@@ -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
+ import { resolveRuntimeAssetPublicPath } from '../runtimePublicPath';
11
+
12
+ describe('resolveRuntimeAssetPublicPath', () => {
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(
15
+ '/dist/2.1.8/',
16
+ );
17
+ });
18
+
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(
31
+ 'https://cdn.nocobase.com/dist/2.1.8/',
32
+ );
33
+ });
34
+ });
@@ -7,6 +7,7 @@
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
9
 
10
+ import './runtimePublicPath';
10
11
  import { app } from './pages/index';
11
12
 
12
13
  app.mount('#root');
@@ -0,0 +1,49 @@
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
+ declare global {
11
+ interface Window {
12
+ __nocobase_public_path__?: string;
13
+ __webpack_public_path__?: string;
14
+ }
15
+ }
16
+
17
+ function normalizePublicPath(value: string | undefined, fallback = '/') {
18
+ let normalized = value?.trim() || fallback;
19
+ if (!normalized.endsWith('/')) {
20
+ normalized = `${normalized}/`;
21
+ }
22
+ return normalized;
23
+ }
24
+
25
+ export function resolveRuntimeAssetPublicPath(
26
+ cdnPublicPath: string | undefined,
27
+ appPublicPath: string | undefined,
28
+ runtimePublicPath: string | undefined,
29
+ ) {
30
+ return normalizePublicPath(
31
+ cdnPublicPath,
32
+ normalizePublicPath(appPublicPath, normalizePublicPath(runtimePublicPath, '/')),
33
+ );
34
+ }
35
+
36
+ // `__webpack_public_path__` is a webpack magic global that must be assigned
37
+ // before any lazy-loaded chunk request happens.
38
+ declare let __webpack_public_path__: string;
39
+
40
+ const runtimePublicPath = typeof __webpack_public_path__ === 'string' ? __webpack_public_path__ : undefined;
41
+
42
+ if (typeof window !== 'undefined' && typeof __webpack_public_path__ !== 'undefined') {
43
+ // eslint-disable-next-line prefer-const
44
+ __webpack_public_path__ = resolveRuntimeAssetPublicPath(
45
+ window.__webpack_public_path__,
46
+ window.__nocobase_public_path__,
47
+ runtimePublicPath,
48
+ );
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
+ });
@@ -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
+ }