@shuvi/platform-shared 1.0.0-rc.16 → 1.0.0-rc.18
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/esm/shared/application.js +1 -1
- package/esm/shared/runtimPlugin.d.ts +1 -1
- package/esm/shared/runtimPlugin.js +2 -2
- package/esm/shared/shuvi-singleton-runtimeConfig.d.ts +5 -4
- package/esm/shared/shuvi-singleton-runtimeConfig.js +38 -8
- package/lib/node/platform/plugins/main/index.js +0 -3
- package/lib/node/platform/runtimeFiles.js +7 -7
- package/lib/node/project/file-presets/files/app/core/setRuntimeConfig.js.js +1 -1
- package/lib/shared/application.js +1 -1
- package/lib/shared/runtimPlugin.d.ts +1 -1
- package/lib/shared/runtimPlugin.js +1 -1
- package/lib/shared/shuvi-singleton-runtimeConfig.d.ts +5 -4
- package/lib/shared/shuvi-singleton-runtimeConfig.js +41 -10
- package/package.json +10 -10
- package/shuvi-type-extensions-runtime.d.ts +0 -5
- package/lib/node/project/file-presets/files/app/core/setPublicRuntimeConfig.js.d.ts +0 -2
- package/lib/node/project/file-presets/files/app/core/setPublicRuntimeConfig.js.js +0 -7
|
@@ -85,7 +85,7 @@ export class ApplicationImpl {
|
|
|
85
85
|
}
|
|
86
86
|
_initAppContext() {
|
|
87
87
|
return __awaiter(this, void 0, void 0, function* () {
|
|
88
|
-
|
|
88
|
+
yield this._pluginManager.runner.appContext(this._context);
|
|
89
89
|
});
|
|
90
90
|
}
|
|
91
91
|
_initAppComponent() {
|
|
@@ -3,7 +3,7 @@ import { CustomRuntimePluginHooks } from '@shuvi/runtime';
|
|
|
3
3
|
import { IAppContext } from './applicationTypes';
|
|
4
4
|
export declare type AppComponent = unknown;
|
|
5
5
|
declare const init: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
|
|
6
|
-
declare const appContext: import("@shuvi/hook").
|
|
6
|
+
declare const appContext: import("@shuvi/hook").AsyncSeriesHook<IAppContext, void, void>;
|
|
7
7
|
declare const appComponent: import("@shuvi/hook").AsyncSeriesWaterfallHook<unknown, IAppContext>;
|
|
8
8
|
declare const dispose: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
|
|
9
9
|
export interface BuiltInRuntimePluginHooks extends HookMap {
|
|
@@ -7,10 +7,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import { createAsyncParallelHook, createAsyncSeriesWaterfallHook, createHookManager, isPluginInstance } from '@shuvi/hook';
|
|
10
|
+
import { createAsyncParallelHook, createAsyncSeriesHook, createAsyncSeriesWaterfallHook, createHookManager, isPluginInstance } from '@shuvi/hook';
|
|
11
11
|
import { createPluginCreator } from '@shuvi/shared/lib/plugins';
|
|
12
12
|
const init = createAsyncParallelHook();
|
|
13
|
-
const appContext =
|
|
13
|
+
const appContext = createAsyncSeriesHook();
|
|
14
14
|
const appComponent = createAsyncSeriesWaterfallHook();
|
|
15
15
|
const dispose = createAsyncParallelHook();
|
|
16
16
|
const builtinRuntimePluginHooks = {
|
|
@@ -2,11 +2,12 @@ import { IRuntimeConfig } from './runtimeConfigTypes';
|
|
|
2
2
|
/**
|
|
3
3
|
* getRuntimeConfig function
|
|
4
4
|
*
|
|
5
|
-
* @returns
|
|
5
|
+
* @returns serverRuntimeConfig
|
|
6
6
|
*/
|
|
7
7
|
export declare function getRuntimeConfig(): {
|
|
8
8
|
[x: string]: string;
|
|
9
9
|
};
|
|
10
|
-
export declare function getPublicRuntimeConfig(): IRuntimeConfig | null;
|
|
11
|
-
export declare function
|
|
12
|
-
export declare function
|
|
10
|
+
export declare function getPublicRuntimeConfig(): IRuntimeConfig | undefined | null;
|
|
11
|
+
export declare function setPublicRuntimeConfig(config: IRuntimeConfig | null): void;
|
|
12
|
+
export declare function getServerRuntimeConfig(): IRuntimeConfig | undefined | null;
|
|
13
|
+
export declare function setServerRuntimeConfig(config: IRuntimeConfig | null): void;
|
|
@@ -1,19 +1,49 @@
|
|
|
1
|
-
|
|
1
|
+
const isServer = typeof window === 'undefined';
|
|
2
|
+
/**
|
|
3
|
+
* use global this to store runtime config, so we can safely bundle this module
|
|
4
|
+
* and get rid of the multiple-module-instance problem.
|
|
5
|
+
* */
|
|
6
|
+
const KEY_SERVER_RUNTIME_CONFIG = Symbol.for('shuvi_server_runtime_config');
|
|
7
|
+
const KEY_PUBLIC_RUNTIME_CONFIG = Symbol.for('shuvi_client_runtime_config');
|
|
2
8
|
let publicRuntimeConfig;
|
|
9
|
+
let serverRuntimeConfig;
|
|
3
10
|
/**
|
|
4
11
|
* getRuntimeConfig function
|
|
5
12
|
*
|
|
6
|
-
* @returns
|
|
13
|
+
* @returns serverRuntimeConfig
|
|
7
14
|
*/
|
|
8
15
|
export function getRuntimeConfig() {
|
|
9
|
-
return Object.assign(Object.assign({}, (
|
|
16
|
+
return Object.assign(Object.assign({}, (getServerRuntimeConfig() || {})), (getPublicRuntimeConfig() || {}));
|
|
10
17
|
}
|
|
11
18
|
export function getPublicRuntimeConfig() {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
19
|
+
if (isServer) {
|
|
20
|
+
return globalThis[KEY_PUBLIC_RUNTIME_CONFIG];
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
return publicRuntimeConfig;
|
|
24
|
+
}
|
|
16
25
|
}
|
|
17
26
|
export function setPublicRuntimeConfig(config) {
|
|
18
|
-
|
|
27
|
+
if (isServer) {
|
|
28
|
+
globalThis[KEY_PUBLIC_RUNTIME_CONFIG] = config;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
publicRuntimeConfig = config;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export function getServerRuntimeConfig() {
|
|
35
|
+
if (isServer) {
|
|
36
|
+
return globalThis[KEY_SERVER_RUNTIME_CONFIG];
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
return serverRuntimeConfig;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
export function setServerRuntimeConfig(config) {
|
|
43
|
+
if (isServer) {
|
|
44
|
+
globalThis[KEY_SERVER_RUNTIME_CONFIG] = config;
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
serverRuntimeConfig = config;
|
|
48
|
+
}
|
|
19
49
|
}
|
|
@@ -9,9 +9,6 @@ const core = (0, service_1.createPlugin)({
|
|
|
9
9
|
},
|
|
10
10
|
addRuntimeService: () => [
|
|
11
11
|
{
|
|
12
|
-
// must be export separately, we need the module path to always be the
|
|
13
|
-
// same as what we've defined in
|
|
14
|
-
// "packages/toolpack/src/webpack/config/parts/external.ts"
|
|
15
12
|
source: (0, paths_1.resolvePkgFile)('lib/shared/shuvi-singleton-runtimeConfig'),
|
|
16
13
|
exported: '{ getRuntimeConfig }'
|
|
17
14
|
},
|
|
@@ -8,9 +8,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
15
|
exports.getPresetRuntimeFilesCreator = void 0;
|
|
13
16
|
const project_1 = require("@shuvi/service/lib/project");
|
|
17
|
+
const logger_1 = __importDefault(require("@shuvi/utils/lib/logger"));
|
|
14
18
|
const shuvi_singleton_runtimeConfig_1 = require("../../shared/shuvi-singleton-runtimeConfig");
|
|
15
19
|
const projectContext_1 = require("../project/projectContext");
|
|
16
20
|
const file_presets_1 = require("../project/file-presets");
|
|
@@ -32,16 +36,12 @@ const getPresetRuntimeFilesCreator = (platformModule) => (pluginContext) => __aw
|
|
|
32
36
|
const key = serverKeys[index];
|
|
33
37
|
const hasSameKey = publicKeys.includes(key);
|
|
34
38
|
if (hasSameKey) {
|
|
35
|
-
|
|
39
|
+
logger_1.default.warn(`Warning: key "${key}" exist in both "runtimeConfig" and "publicRuntimeConfig". Please rename the key, or the value from "publicRuntimeConfig" will be applied.\n`);
|
|
36
40
|
break;
|
|
37
41
|
}
|
|
38
42
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
if (publicKeys) {
|
|
43
|
-
(0, shuvi_singleton_runtimeConfig_1.setPublicRuntimeConfig)(publicRuntimeConfig);
|
|
44
|
-
}
|
|
43
|
+
(0, shuvi_singleton_runtimeConfig_1.setServerRuntimeConfig)(serverKeys ? serverRuntimeConfig : null);
|
|
44
|
+
(0, shuvi_singleton_runtimeConfig_1.setPublicRuntimeConfig)(publicKeys ? publicRuntimeConfig : null);
|
|
45
45
|
const context = (0, projectContext_1.createProjectContext)();
|
|
46
46
|
context.userModule = {
|
|
47
47
|
error: getCandidates('error', 'nullish'),
|
|
@@ -3,5 +3,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const __1 = require("../../..");
|
|
4
4
|
const paths_1 = require("../../../../../paths");
|
|
5
5
|
exports.default = () => (0, __1.defineFile)({
|
|
6
|
-
content: () => `export {
|
|
6
|
+
content: () => `export { setPublicRuntimeConfig as default } from '${(0, paths_1.resolvePkgFile)('lib/shared/shuvi-singleton-runtimeConfig')}'`
|
|
7
7
|
});
|
|
@@ -88,7 +88,7 @@ class ApplicationImpl {
|
|
|
88
88
|
}
|
|
89
89
|
_initAppContext() {
|
|
90
90
|
return __awaiter(this, void 0, void 0, function* () {
|
|
91
|
-
|
|
91
|
+
yield this._pluginManager.runner.appContext(this._context);
|
|
92
92
|
});
|
|
93
93
|
}
|
|
94
94
|
_initAppComponent() {
|
|
@@ -3,7 +3,7 @@ import { CustomRuntimePluginHooks } from '@shuvi/runtime';
|
|
|
3
3
|
import { IAppContext } from './applicationTypes';
|
|
4
4
|
export declare type AppComponent = unknown;
|
|
5
5
|
declare const init: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
|
|
6
|
-
declare const appContext: import("@shuvi/hook").
|
|
6
|
+
declare const appContext: import("@shuvi/hook").AsyncSeriesHook<IAppContext, void, void>;
|
|
7
7
|
declare const appComponent: import("@shuvi/hook").AsyncSeriesWaterfallHook<unknown, IAppContext>;
|
|
8
8
|
declare const dispose: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
|
|
9
9
|
export interface BuiltInRuntimePluginHooks extends HookMap {
|
|
@@ -14,7 +14,7 @@ exports.initPlugins = exports.createRuntimePluginAfter = exports.createRuntimePl
|
|
|
14
14
|
const hook_1 = require("@shuvi/hook");
|
|
15
15
|
const plugins_1 = require("@shuvi/shared/lib/plugins");
|
|
16
16
|
const init = (0, hook_1.createAsyncParallelHook)();
|
|
17
|
-
const appContext = (0, hook_1.
|
|
17
|
+
const appContext = (0, hook_1.createAsyncSeriesHook)();
|
|
18
18
|
const appComponent = (0, hook_1.createAsyncSeriesWaterfallHook)();
|
|
19
19
|
const dispose = (0, hook_1.createAsyncParallelHook)();
|
|
20
20
|
const builtinRuntimePluginHooks = {
|
|
@@ -2,11 +2,12 @@ import { IRuntimeConfig } from './runtimeConfigTypes';
|
|
|
2
2
|
/**
|
|
3
3
|
* getRuntimeConfig function
|
|
4
4
|
*
|
|
5
|
-
* @returns
|
|
5
|
+
* @returns serverRuntimeConfig
|
|
6
6
|
*/
|
|
7
7
|
export declare function getRuntimeConfig(): {
|
|
8
8
|
[x: string]: string;
|
|
9
9
|
};
|
|
10
|
-
export declare function getPublicRuntimeConfig(): IRuntimeConfig | null;
|
|
11
|
-
export declare function
|
|
12
|
-
export declare function
|
|
10
|
+
export declare function getPublicRuntimeConfig(): IRuntimeConfig | undefined | null;
|
|
11
|
+
export declare function setPublicRuntimeConfig(config: IRuntimeConfig | null): void;
|
|
12
|
+
export declare function getServerRuntimeConfig(): IRuntimeConfig | undefined | null;
|
|
13
|
+
export declare function setServerRuntimeConfig(config: IRuntimeConfig | null): void;
|
|
@@ -1,26 +1,57 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
3
|
+
exports.setServerRuntimeConfig = exports.getServerRuntimeConfig = exports.setPublicRuntimeConfig = exports.getPublicRuntimeConfig = exports.getRuntimeConfig = void 0;
|
|
4
|
+
const isServer = typeof window === 'undefined';
|
|
5
|
+
/**
|
|
6
|
+
* use global this to store runtime config, so we can safely bundle this module
|
|
7
|
+
* and get rid of the multiple-module-instance problem.
|
|
8
|
+
* */
|
|
9
|
+
const KEY_SERVER_RUNTIME_CONFIG = Symbol.for('shuvi_server_runtime_config');
|
|
10
|
+
const KEY_PUBLIC_RUNTIME_CONFIG = Symbol.for('shuvi_client_runtime_config');
|
|
5
11
|
let publicRuntimeConfig;
|
|
12
|
+
let serverRuntimeConfig;
|
|
6
13
|
/**
|
|
7
14
|
* getRuntimeConfig function
|
|
8
15
|
*
|
|
9
|
-
* @returns
|
|
16
|
+
* @returns serverRuntimeConfig
|
|
10
17
|
*/
|
|
11
18
|
function getRuntimeConfig() {
|
|
12
|
-
return Object.assign(Object.assign({}, (
|
|
19
|
+
return Object.assign(Object.assign({}, (getServerRuntimeConfig() || {})), (getPublicRuntimeConfig() || {}));
|
|
13
20
|
}
|
|
14
21
|
exports.getRuntimeConfig = getRuntimeConfig;
|
|
15
22
|
function getPublicRuntimeConfig() {
|
|
16
|
-
|
|
23
|
+
if (isServer) {
|
|
24
|
+
return globalThis[KEY_PUBLIC_RUNTIME_CONFIG];
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
return publicRuntimeConfig;
|
|
28
|
+
}
|
|
17
29
|
}
|
|
18
30
|
exports.getPublicRuntimeConfig = getPublicRuntimeConfig;
|
|
19
|
-
function setRuntimeConfig(config) {
|
|
20
|
-
runtimeConfig = config;
|
|
21
|
-
}
|
|
22
|
-
exports.setRuntimeConfig = setRuntimeConfig;
|
|
23
31
|
function setPublicRuntimeConfig(config) {
|
|
24
|
-
|
|
32
|
+
if (isServer) {
|
|
33
|
+
globalThis[KEY_PUBLIC_RUNTIME_CONFIG] = config;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
publicRuntimeConfig = config;
|
|
37
|
+
}
|
|
25
38
|
}
|
|
26
39
|
exports.setPublicRuntimeConfig = setPublicRuntimeConfig;
|
|
40
|
+
function getServerRuntimeConfig() {
|
|
41
|
+
if (isServer) {
|
|
42
|
+
return globalThis[KEY_SERVER_RUNTIME_CONFIG];
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
return serverRuntimeConfig;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.getServerRuntimeConfig = getServerRuntimeConfig;
|
|
49
|
+
function setServerRuntimeConfig(config) {
|
|
50
|
+
if (isServer) {
|
|
51
|
+
globalThis[KEY_SERVER_RUNTIME_CONFIG] = config;
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
serverRuntimeConfig = config;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.setServerRuntimeConfig = setServerRuntimeConfig;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shuvi/platform-shared",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.18",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/shuvijs/shuvi.git",
|
|
@@ -83,18 +83,18 @@
|
|
|
83
83
|
"node": ">= 12.0.0"
|
|
84
84
|
},
|
|
85
85
|
"dependencies": {
|
|
86
|
-
"@shuvi/hook": "1.0.0-rc.
|
|
87
|
-
"@shuvi/redox": "0.0.
|
|
88
|
-
"@shuvi/router": "1.0.0-rc.
|
|
89
|
-
"@shuvi/runtime": "1.0.0-rc.
|
|
90
|
-
"@shuvi/service": "1.0.0-rc.
|
|
91
|
-
"@shuvi/shared": "1.0.0-rc.
|
|
92
|
-
"@shuvi/toolpack": "1.0.0-rc.
|
|
93
|
-
"@shuvi/utils": "1.0.0-rc.
|
|
86
|
+
"@shuvi/hook": "1.0.0-rc.18",
|
|
87
|
+
"@shuvi/redox": "0.0.7",
|
|
88
|
+
"@shuvi/router": "1.0.0-rc.18",
|
|
89
|
+
"@shuvi/runtime": "1.0.0-rc.18",
|
|
90
|
+
"@shuvi/service": "1.0.0-rc.18",
|
|
91
|
+
"@shuvi/shared": "1.0.0-rc.18",
|
|
92
|
+
"@shuvi/toolpack": "1.0.0-rc.18",
|
|
93
|
+
"@shuvi/utils": "1.0.0-rc.18",
|
|
94
94
|
"redux": "4.1.2"
|
|
95
95
|
},
|
|
96
96
|
"peerDependencies": {
|
|
97
|
-
"@shuvi/service": "1.0.0-rc.
|
|
97
|
+
"@shuvi/service": "1.0.0-rc.18"
|
|
98
98
|
},
|
|
99
99
|
"devDependencies": {
|
|
100
100
|
"@types/minimatch": "3.0.5"
|
|
@@ -35,11 +35,6 @@ declare module '@shuvi/app/core/setRuntimeConfig' {
|
|
|
35
35
|
export default function setRuntimeConfig(config: IRuntimeConfig): void;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
declare module '@shuvi/app/core/setPublicRuntimeConfig' {
|
|
39
|
-
import { IRuntimeConfig } from '@shuvi/platform-shared/shared';
|
|
40
|
-
export default function setPublicRuntimeConfig(config: IRuntimeConfig): void;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
38
|
declare module '@shuvi/app/user/error' {
|
|
44
39
|
const Error: any;
|
|
45
40
|
export default Error;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const __1 = require("../../..");
|
|
4
|
-
const paths_1 = require("../../../../../paths");
|
|
5
|
-
exports.default = () => (0, __1.defineFile)({
|
|
6
|
-
content: () => `export { setPublicRuntimeConfig as default } from '${(0, paths_1.resolvePkgFile)('lib/shared/shuvi-singleton-runtimeConfig')}'`
|
|
7
|
-
});
|