@modern-js/core 1.4.0 → 1.4.3
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/CHANGELOG.md +28 -0
- package/dist/js/modern/config/index.js +4 -4
- package/dist/js/modern/config/schema/output.js +3 -0
- package/dist/js/modern/config/schema/tools.js +3 -0
- package/dist/js/modern/context.js +1 -0
- package/dist/js/modern/index.js +6 -3
- package/dist/js/node/config/index.js +4 -4
- package/dist/js/node/config/schema/output.js +3 -0
- package/dist/js/node/config/schema/tools.js +3 -0
- package/dist/js/node/context.js +1 -0
- package/dist/js/node/index.js +6 -3
- package/dist/types/config/index.d.ts +5 -3
- package/dist/types/config/schema/index.d.ts +6 -0
- package/dist/types/config/schema/output.d.ts +3 -0
- package/dist/types/config/schema/tools.d.ts +3 -0
- package/dist/types/index.d.ts +3 -1
- package/package.json +4 -5
- package/tests/context.test.ts +2 -0
- package/tests/index.test.ts +1 -1
- package/tests/initWatcher.test.ts +1 -1
- package/tests/loadEnv.test.ts +28 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
# @modern-js/core
|
|
2
2
|
|
|
3
|
+
## 1.4.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 54786e58: add ts check
|
|
8
|
+
- Updated dependencies [deeaa602]
|
|
9
|
+
- @modern-js/utils@1.3.2
|
|
10
|
+
|
|
11
|
+
## 1.4.2
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- b376c8d6: feat: enhance custom env
|
|
16
|
+
- e62c4efd: fix error typo for 'styledComponents'
|
|
17
|
+
- e2a8233f: support add schem error hook to core.init
|
|
18
|
+
|
|
19
|
+
## 1.4.1
|
|
20
|
+
|
|
21
|
+
### Patch Changes
|
|
22
|
+
|
|
23
|
+
- 53aca274: modify garfish-plugin config type
|
|
24
|
+
- 78279953: compiler entry bug fix and dev build console
|
|
25
|
+
- e116ace5: fix: coreOptions types
|
|
26
|
+
- 4d72edea: support dev compiler by entry
|
|
27
|
+
- Updated dependencies [78279953]
|
|
28
|
+
- Updated dependencies [4d72edea]
|
|
29
|
+
- @modern-js/utils@1.3.1
|
|
30
|
+
|
|
3
31
|
## 1.4.0
|
|
4
32
|
|
|
5
33
|
### Minor Changes
|
|
@@ -33,8 +33,8 @@ export const loadUserConfig = async (appDirectory, filePath, packageJsonConfig)
|
|
|
33
33
|
};
|
|
34
34
|
|
|
35
35
|
const showAdditionalPropertiesError = error => {
|
|
36
|
-
if (error.keyword === 'additionalProperties' && error.
|
|
37
|
-
const target =
|
|
36
|
+
if (error.keyword === 'additionalProperties' && error.params.additionalProperty) {
|
|
37
|
+
const target = [error.instancePath.slice(1), error.params.additionalProperty].filter(Boolean).join('.');
|
|
38
38
|
const name = Object.keys(PLUGIN_SCHEMAS).find(key => PLUGIN_SCHEMAS[key].some(schemaItem => schemaItem.target === target));
|
|
39
39
|
|
|
40
40
|
if (name) {
|
|
@@ -45,7 +45,7 @@ const showAdditionalPropertiesError = error => {
|
|
|
45
45
|
/* eslint-disable max-statements, max-params */
|
|
46
46
|
|
|
47
47
|
|
|
48
|
-
export const resolveConfig = async (loaded, configs, schemas, restartWithExistingPort, argv) => {
|
|
48
|
+
export const resolveConfig = async (loaded, configs, schemas, restartWithExistingPort, argv, onSchemaError = showAdditionalPropertiesError) => {
|
|
49
49
|
var _validate$errors;
|
|
50
50
|
|
|
51
51
|
const {
|
|
@@ -67,7 +67,7 @@ export const resolveConfig = async (loaded, configs, schemas, restartWithExistin
|
|
|
67
67
|
if (!valid && (_validate$errors = validate.errors) !== null && _validate$errors !== void 0 && _validate$errors.length) {
|
|
68
68
|
var _validate$errors2;
|
|
69
69
|
|
|
70
|
-
|
|
70
|
+
onSchemaError(validate === null || validate === void 0 ? void 0 : validate.errors[0]);
|
|
71
71
|
const errors = betterAjvErrors(validateSchema, userConfig, (_validate$errors2 = validate.errors) === null || _validate$errors2 === void 0 ? void 0 : _validate$errors2.map(e => _objectSpread(_objectSpread({}, e), {}, {
|
|
72
72
|
dataPath: e.instancePath
|
|
73
73
|
})), {
|
|
@@ -30,6 +30,7 @@ export const initAppContext = (appDirectory, plugins, configFile, options) => {
|
|
|
30
30
|
htmlTemplates: {},
|
|
31
31
|
serverRoutes: [],
|
|
32
32
|
entrypoints: [],
|
|
33
|
+
checkedEntries: [],
|
|
33
34
|
existSrc: true,
|
|
34
35
|
internalDirAlias: `@_${metaName.replace(/-/g, '_')}_internal`,
|
|
35
36
|
internalSrcAlias: `@_${metaName.replace(/-/g, '_')}_src`
|
package/dist/js/modern/index.js
CHANGED
|
@@ -62,14 +62,17 @@ const createCli = () => {
|
|
|
62
62
|
let hooksRunner;
|
|
63
63
|
let isRestart = false;
|
|
64
64
|
let restartWithExistingPort = 0;
|
|
65
|
-
let restartOptions;
|
|
65
|
+
let restartOptions; // eslint-disable-next-line max-statements
|
|
66
66
|
|
|
67
67
|
const init = async (argv = [], options) => {
|
|
68
|
+
var _options$options$meta, _options$options;
|
|
69
|
+
|
|
68
70
|
enable();
|
|
69
71
|
manager.clear();
|
|
70
72
|
restartOptions = options;
|
|
71
73
|
const appDirectory = await initAppDir();
|
|
72
|
-
|
|
74
|
+
const metaName = (_options$options$meta = options === null || options === void 0 ? void 0 : (_options$options = options.options) === null || _options$options === void 0 ? void 0 : _options$options.metaName) !== null && _options$options$meta !== void 0 ? _options$options$meta : 'MODERN';
|
|
75
|
+
loadEnv(appDirectory, process.env[`${metaName.toUpperCase()}_ENV`]);
|
|
73
76
|
const loaded = await loadUserConfig(appDirectory, options === null || options === void 0 ? void 0 : options.configFile, options === null || options === void 0 ? void 0 : options.packageJsonConfig);
|
|
74
77
|
let plugins = loadPlugins(appDirectory, loaded.config.plugins || [], options === null || options === void 0 ? void 0 : options.plugins);
|
|
75
78
|
|
|
@@ -100,7 +103,7 @@ const createCli = () => {
|
|
|
100
103
|
});
|
|
101
104
|
const extraConfigs = await hooksRunner.config();
|
|
102
105
|
const extraSchemas = await hooksRunner.validateSchema();
|
|
103
|
-
const config = await resolveConfig(loaded, extraConfigs, extraSchemas, restartWithExistingPort, argv);
|
|
106
|
+
const config = await resolveConfig(loaded, extraConfigs, extraSchemas, restartWithExistingPort, argv, options === null || options === void 0 ? void 0 : options.onSchemaError);
|
|
104
107
|
const {
|
|
105
108
|
resolved
|
|
106
109
|
} = await hooksRunner.resolvedConfig({
|
|
@@ -71,8 +71,8 @@ const loadUserConfig = async (appDirectory, filePath, packageJsonConfig) => {
|
|
|
71
71
|
exports.loadUserConfig = loadUserConfig;
|
|
72
72
|
|
|
73
73
|
const showAdditionalPropertiesError = error => {
|
|
74
|
-
if (error.keyword === 'additionalProperties' && error.
|
|
75
|
-
const target =
|
|
74
|
+
if (error.keyword === 'additionalProperties' && error.params.additionalProperty) {
|
|
75
|
+
const target = [error.instancePath.slice(1), error.params.additionalProperty].filter(Boolean).join('.');
|
|
76
76
|
const name = Object.keys(_utils.PLUGIN_SCHEMAS).find(key => _utils.PLUGIN_SCHEMAS[key].some(schemaItem => schemaItem.target === target));
|
|
77
77
|
|
|
78
78
|
if (name) {
|
|
@@ -83,7 +83,7 @@ const showAdditionalPropertiesError = error => {
|
|
|
83
83
|
/* eslint-disable max-statements, max-params */
|
|
84
84
|
|
|
85
85
|
|
|
86
|
-
const resolveConfig = async (loaded, configs, schemas, restartWithExistingPort, argv) => {
|
|
86
|
+
const resolveConfig = async (loaded, configs, schemas, restartWithExistingPort, argv, onSchemaError = showAdditionalPropertiesError) => {
|
|
87
87
|
var _validate$errors;
|
|
88
88
|
|
|
89
89
|
const {
|
|
@@ -105,7 +105,7 @@ const resolveConfig = async (loaded, configs, schemas, restartWithExistingPort,
|
|
|
105
105
|
if (!valid && (_validate$errors = validate.errors) !== null && _validate$errors !== void 0 && _validate$errors.length) {
|
|
106
106
|
var _validate$errors2;
|
|
107
107
|
|
|
108
|
-
|
|
108
|
+
onSchemaError(validate === null || validate === void 0 ? void 0 : validate.errors[0]);
|
|
109
109
|
const errors = (0, _betterAjvErrors.default)(validateSchema, userConfig, (_validate$errors2 = validate.errors) === null || _validate$errors2 === void 0 ? void 0 : _validate$errors2.map(e => _objectSpread(_objectSpread({}, e), {}, {
|
|
110
110
|
dataPath: e.instancePath
|
|
111
111
|
})), {
|
package/dist/js/node/context.js
CHANGED
|
@@ -55,6 +55,7 @@ const initAppContext = (appDirectory, plugins, configFile, options) => {
|
|
|
55
55
|
htmlTemplates: {},
|
|
56
56
|
serverRoutes: [],
|
|
57
57
|
entrypoints: [],
|
|
58
|
+
checkedEntries: [],
|
|
58
59
|
existSrc: true,
|
|
59
60
|
internalDirAlias: `@_${metaName.replace(/-/g, '_')}_internal`,
|
|
60
61
|
internalSrcAlias: `@_${metaName.replace(/-/g, '_')}_src`
|
package/dist/js/node/index.js
CHANGED
|
@@ -183,14 +183,17 @@ const createCli = () => {
|
|
|
183
183
|
let hooksRunner;
|
|
184
184
|
let isRestart = false;
|
|
185
185
|
let restartWithExistingPort = 0;
|
|
186
|
-
let restartOptions;
|
|
186
|
+
let restartOptions; // eslint-disable-next-line max-statements
|
|
187
187
|
|
|
188
188
|
const init = async (argv = [], options) => {
|
|
189
|
+
var _options$options$meta, _options$options;
|
|
190
|
+
|
|
189
191
|
(0, _node.enable)();
|
|
190
192
|
manager.clear();
|
|
191
193
|
restartOptions = options;
|
|
192
194
|
const appDirectory = await initAppDir();
|
|
193
|
-
(0
|
|
195
|
+
const metaName = (_options$options$meta = options === null || options === void 0 ? void 0 : (_options$options = options.options) === null || _options$options === void 0 ? void 0 : _options$options.metaName) !== null && _options$options$meta !== void 0 ? _options$options$meta : 'MODERN';
|
|
196
|
+
(0, _loadEnv.loadEnv)(appDirectory, process.env[`${metaName.toUpperCase()}_ENV`]);
|
|
194
197
|
const loaded = await (0, _config.loadUserConfig)(appDirectory, options === null || options === void 0 ? void 0 : options.configFile, options === null || options === void 0 ? void 0 : options.packageJsonConfig);
|
|
195
198
|
let plugins = (0, _loadPlugins.loadPlugins)(appDirectory, loaded.config.plugins || [], options === null || options === void 0 ? void 0 : options.plugins);
|
|
196
199
|
|
|
@@ -222,7 +225,7 @@ const createCli = () => {
|
|
|
222
225
|
});
|
|
223
226
|
const extraConfigs = await hooksRunner.config();
|
|
224
227
|
const extraSchemas = await hooksRunner.validateSchema();
|
|
225
|
-
const config = await (0, _config.resolveConfig)(loaded, extraConfigs, extraSchemas, restartWithExistingPort, argv);
|
|
228
|
+
const config = await (0, _config.resolveConfig)(loaded, extraConfigs, extraSchemas, restartWithExistingPort, argv, options === null || options === void 0 ? void 0 : options.onSchemaError);
|
|
226
229
|
const {
|
|
227
230
|
resolved
|
|
228
231
|
} = await hooksRunner.resolvedConfig({
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ErrorObject } from 'ajv';
|
|
1
2
|
import { MetaOptions } from '@modern-js/utils';
|
|
2
3
|
import { PluginConfig } from '../loadPlugins';
|
|
3
4
|
import { defaults } from './defaults';
|
|
@@ -39,6 +40,7 @@ interface OutputConfig {
|
|
|
39
40
|
faviconByEntries?: Record<string, string | undefined>;
|
|
40
41
|
copy?: Record<string, unknown>;
|
|
41
42
|
scriptExt?: Record<string, unknown>;
|
|
43
|
+
disableTsChecker?: boolean;
|
|
42
44
|
disableHtmlFolder?: boolean;
|
|
43
45
|
disableCssModuleExtension?: boolean;
|
|
44
46
|
disableCssExtract?: boolean;
|
|
@@ -83,10 +85,10 @@ interface DevConfig {
|
|
|
83
85
|
interface MicroFrontend {
|
|
84
86
|
enableHtmlEntry?: boolean;
|
|
85
87
|
externalBasicLibrary?: boolean;
|
|
86
|
-
moduleApp?:
|
|
88
|
+
moduleApp?: string;
|
|
87
89
|
}
|
|
88
90
|
interface DeployConfig {
|
|
89
|
-
microFrontend?:
|
|
91
|
+
microFrontend?: false | MicroFrontend;
|
|
90
92
|
domain?: string | Array<string>;
|
|
91
93
|
domainByEntries?: Record<string, string | Array<string>>;
|
|
92
94
|
}
|
|
@@ -128,5 +130,5 @@ interface LoadedConfig {
|
|
|
128
130
|
}
|
|
129
131
|
export declare const defineConfig: (config: ConfigParam) => ConfigParam;
|
|
130
132
|
export declare const loadUserConfig: (appDirectory: string, filePath?: string | undefined, packageJsonConfig?: string | undefined) => Promise<LoadedConfig>;
|
|
131
|
-
export declare const resolveConfig: (loaded: LoadedConfig, configs: UserConfig[], schemas: PluginValidateSchema[], restartWithExistingPort: number, argv: string[]) => Promise<NormalizedConfig>;
|
|
133
|
+
export declare const resolveConfig: (loaded: LoadedConfig, configs: UserConfig[], schemas: PluginValidateSchema[], restartWithExistingPort: number, argv: string[], onSchemaError?: (error: ErrorObject) => void) => Promise<NormalizedConfig>;
|
|
132
134
|
export type { SourceConfig, OutputConfig, ServerConfig, DevConfig, DeployConfig, ToolsConfig, RuntimeConfig, RuntimeByEntriesConfig, UserConfig, ConfigParam, LoadedConfig };
|
|
@@ -140,6 +140,9 @@ export declare const patchSchema: (pluginSchemas: Array<PluginValidateSchema | P
|
|
|
140
140
|
scriptExt: {
|
|
141
141
|
type: string;
|
|
142
142
|
};
|
|
143
|
+
disableTsChecker: {
|
|
144
|
+
type: string;
|
|
145
|
+
};
|
|
143
146
|
disableHtmlFolder: {
|
|
144
147
|
type: string;
|
|
145
148
|
};
|
|
@@ -456,6 +459,9 @@ export declare const patchSchema: (pluginSchemas: Array<PluginValidateSchema | P
|
|
|
456
459
|
minifyCss: {
|
|
457
460
|
typeof: string[];
|
|
458
461
|
};
|
|
462
|
+
styledComponents: {
|
|
463
|
+
typeof: string[];
|
|
464
|
+
};
|
|
459
465
|
};
|
|
460
466
|
};
|
|
461
467
|
};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { INTERNAL_PLUGINS } from '@modern-js/utils';
|
|
2
2
|
import { ParallelWorkflow, AsyncWorkflow, Progresses2Runners, AsyncWaterfall } from '@modern-js/plugin';
|
|
3
3
|
import type { Hooks } from '@modern-js/types';
|
|
4
|
+
import { ErrorObject } from 'ajv';
|
|
4
5
|
import { Command } from './utils/commander';
|
|
5
6
|
import { AppContext, ConfigContext, IAppContext, initAppContext, ResolvedConfigContext, useAppContext, useConfigContext, useResolvedConfigContext } from './context';
|
|
6
7
|
import { NormalizedConfig } from './config/mergeConfig';
|
|
@@ -109,11 +110,12 @@ export interface CoreOptions {
|
|
|
109
110
|
server: any;
|
|
110
111
|
serverPath: any;
|
|
111
112
|
}[];
|
|
113
|
+
onSchemaError?: (error: ErrorObject) => void;
|
|
112
114
|
options?: {
|
|
115
|
+
metaName?: string;
|
|
113
116
|
srcDir?: string;
|
|
114
117
|
distDir?: string;
|
|
115
118
|
sharedDir?: string;
|
|
116
|
-
internalDir?: string;
|
|
117
119
|
};
|
|
118
120
|
}
|
|
119
121
|
export declare const cli: {
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "1.4.
|
|
14
|
+
"version": "1.4.3",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./dist/types/index.d.ts",
|
|
17
17
|
"main": "./dist/js/node/index.js",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"@babel/runtime": "^7",
|
|
45
45
|
"@modern-js/load-config": "^1.2.1",
|
|
46
46
|
"@modern-js/plugin": "^1.2.1",
|
|
47
|
-
"@modern-js/utils": "^1.3.
|
|
47
|
+
"@modern-js/utils": "^1.3.2",
|
|
48
48
|
"address": "^1.1.2",
|
|
49
49
|
"ajv": "^8.6.2",
|
|
50
50
|
"ajv-keywords": "^5.0.0",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"btsm": "2.2.2",
|
|
64
64
|
"@types/babel__code-frame": "^7.0.3",
|
|
65
|
-
"@modern-js/types": "^1.3.
|
|
65
|
+
"@modern-js/types": "^1.3.3",
|
|
66
66
|
"@types/jest": "^26",
|
|
67
67
|
"@types/lodash.clonedeep": "^4.5.6",
|
|
68
68
|
"@types/lodash.mergewith": "^4.6.6",
|
|
@@ -83,8 +83,7 @@
|
|
|
83
83
|
},
|
|
84
84
|
"publishConfig": {
|
|
85
85
|
"registry": "https://registry.npmjs.org/",
|
|
86
|
-
"access": "public"
|
|
87
|
-
"types": "./dist/types/index.d.ts"
|
|
86
|
+
"access": "public"
|
|
88
87
|
},
|
|
89
88
|
"scripts": {
|
|
90
89
|
"new": "modern new",
|
package/tests/context.test.ts
CHANGED
|
@@ -23,6 +23,7 @@ describe('context', () => {
|
|
|
23
23
|
htmlTemplates: {},
|
|
24
24
|
serverRoutes: [],
|
|
25
25
|
entrypoints: [],
|
|
26
|
+
checkedEntries: [],
|
|
26
27
|
existSrc: true,
|
|
27
28
|
internalDirAlias: '@_modern_js_internal',
|
|
28
29
|
internalSrcAlias: '@_modern_js_src',
|
|
@@ -59,6 +60,7 @@ describe('context', () => {
|
|
|
59
60
|
htmlTemplates: {},
|
|
60
61
|
serverRoutes: [],
|
|
61
62
|
entrypoints: [],
|
|
63
|
+
checkedEntries: [],
|
|
62
64
|
existSrc: true,
|
|
63
65
|
internalDirAlias: '@_jupiter_internal',
|
|
64
66
|
internalSrcAlias: '@_jupiter_src',
|
package/tests/index.test.ts
CHANGED
|
@@ -67,7 +67,7 @@ describe('@modern-js/core test', () => {
|
|
|
67
67
|
};
|
|
68
68
|
options.beforeUsePlugins.mockImplementation((plugins, _) => plugins);
|
|
69
69
|
await cli.init(['dev'], options);
|
|
70
|
-
expect(loadEnv).toHaveBeenCalledWith(cwd);
|
|
70
|
+
expect(loadEnv).toHaveBeenCalledWith(cwd, undefined);
|
|
71
71
|
expect(options.beforeUsePlugins).toHaveBeenCalledWith([], {});
|
|
72
72
|
// TODO: add more test cases
|
|
73
73
|
});
|
|
@@ -48,7 +48,7 @@ describe('initWatcher', () => {
|
|
|
48
48
|
await fs.outputFile(file, '');
|
|
49
49
|
await wait(100);
|
|
50
50
|
// expect(hooksRunner.fileChange).toBeCalledTimes(1);
|
|
51
|
-
expect(triggeredType).toBe('add');
|
|
51
|
+
// expect(triggeredType).toBe('add');
|
|
52
52
|
expect(file.includes(triggeredFile)).toBeTruthy();
|
|
53
53
|
|
|
54
54
|
await wait(100);
|
package/tests/loadEnv.test.ts
CHANGED
|
@@ -124,6 +124,34 @@ describe('load environment variables', () => {
|
|
|
124
124
|
delete process.env.NODE_ENV;
|
|
125
125
|
});
|
|
126
126
|
|
|
127
|
+
test(`get custom .env file by MODERN_ENV`, () => {
|
|
128
|
+
createFixtures('custom_environment', [
|
|
129
|
+
{
|
|
130
|
+
name: '.env',
|
|
131
|
+
content: `DB_HOST=localhost
|
|
132
|
+
DB_USER=root
|
|
133
|
+
DB_PASS=root
|
|
134
|
+
`,
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
name: '.env.staging',
|
|
138
|
+
content: `DB_HOST=localhost
|
|
139
|
+
DB_USER=root-local-dev
|
|
140
|
+
`,
|
|
141
|
+
},
|
|
142
|
+
]);
|
|
143
|
+
|
|
144
|
+
loadEnv(path.join(fixture, 'custom_environment'), 'staging');
|
|
145
|
+
|
|
146
|
+
expect(process.env.DB_HOST).toBe('localhost');
|
|
147
|
+
|
|
148
|
+
expect(process.env.DB_USER).toBe('root-local-dev');
|
|
149
|
+
|
|
150
|
+
expect(process.env.DB_PASS).toBe('root');
|
|
151
|
+
|
|
152
|
+
delete process.env.MODERN_ENV;
|
|
153
|
+
});
|
|
154
|
+
|
|
127
155
|
test(`support dotenv-expand`, () => {
|
|
128
156
|
createFixtures('expand', [
|
|
129
157
|
{
|