@modern-js/app-tools 2.0.0-beta.1 → 2.0.0-beta.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 +445 -0
- package/bin/modern.js +10 -1
- package/dist/js/modern/analyze/constants.js +2 -0
- package/dist/js/modern/analyze/generateCode.js +39 -19
- package/dist/js/modern/analyze/getBundleEntry.js +1 -1
- package/dist/js/modern/analyze/getFileSystemEntry.js +1 -1
- package/dist/js/modern/analyze/getHtmlTemplate.js +1 -1
- package/dist/js/modern/analyze/getServerRoutes.js +8 -4
- package/dist/js/modern/analyze/index.js +12 -27
- package/dist/js/modern/analyze/nestedRoutes.js +17 -6
- package/dist/js/modern/analyze/templates.js +59 -27
- package/dist/js/modern/analyze/utils.js +30 -4
- package/dist/js/modern/builder/builderPlugins/compatModern.js +18 -12
- package/dist/js/modern/builder/index.js +31 -16
- package/dist/js/modern/builder/loaders/routerLoader.js +20 -0
- package/dist/js/modern/builder/loaders/serverModuleLoader.js +4 -0
- package/dist/js/modern/builder/share.js +1 -1
- package/dist/js/modern/commands/build.js +8 -2
- package/dist/js/modern/commands/dev.js +37 -32
- package/dist/js/modern/commands/inspect.js +4 -2
- package/dist/js/modern/config/default.js +206 -0
- package/dist/js/modern/config/index.js +2 -0
- package/dist/js/modern/config/initial/createHtmlConfig.js +32 -0
- package/dist/js/modern/{builder → config/initial}/createOutputConfig.js +16 -15
- package/dist/js/modern/config/initial/createSourceConfig.js +32 -0
- package/dist/js/modern/config/initial/createToolsConfig.js +41 -0
- package/dist/js/modern/config/initial/index.js +11 -0
- package/dist/js/modern/config/initial/inits.js +117 -0
- package/dist/js/modern/config/initial/transformNormalizedConfig.js +40 -0
- package/dist/js/modern/defineConfig.js +12 -0
- package/dist/js/modern/hooks.js +23 -19
- package/dist/js/modern/index.js +7 -5
- package/dist/js/modern/initialize/index.js +72 -0
- package/dist/js/modern/schema/Schema.js +39 -0
- package/dist/js/modern/schema/index.js +139 -0
- package/dist/js/modern/schema/legacy.js +284 -0
- package/dist/js/modern/types/config/deploy.js +0 -0
- package/dist/js/modern/types/config/dev.js +0 -0
- package/dist/js/modern/types/config/experiments.js +0 -0
- package/dist/js/modern/types/config/html.js +0 -0
- package/dist/js/modern/types/config/index.js +2 -0
- package/dist/js/modern/types/config/output.js +0 -0
- package/dist/js/modern/types/config/performance.js +0 -0
- package/dist/js/modern/types/config/security.js +0 -0
- package/dist/js/modern/types/config/source.js +0 -0
- package/dist/js/modern/types/config/tools.js +0 -0
- package/dist/js/modern/types/hooks.js +0 -0
- package/dist/js/modern/types/index.js +4 -0
- package/dist/js/modern/types/legacyConfig/deploy.js +0 -0
- package/dist/js/modern/types/legacyConfig/dev.js +0 -0
- package/dist/js/modern/types/legacyConfig/index.js +0 -0
- package/dist/js/modern/types/legacyConfig/output.js +1 -0
- package/dist/js/modern/types/legacyConfig/source.js +0 -0
- package/dist/js/modern/types/legacyConfig/tools.js +0 -0
- package/dist/js/modern/utils/config.js +1 -1
- package/dist/js/modern/utils/createFileWatcher.js +82 -0
- package/dist/js/modern/utils/restart.js +17 -0
- package/dist/js/node/analyze/constants.js +5 -1
- package/dist/js/node/analyze/generateCode.js +37 -17
- package/dist/js/node/analyze/getBundleEntry.js +1 -1
- package/dist/js/node/analyze/getFileSystemEntry.js +1 -1
- package/dist/js/node/analyze/getHtmlTemplate.js +1 -1
- package/dist/js/node/analyze/getServerRoutes.js +8 -4
- package/dist/js/node/analyze/index.js +13 -39
- package/dist/js/node/analyze/nestedRoutes.js +15 -4
- package/dist/js/node/analyze/templates.js +60 -27
- package/dist/js/node/analyze/utils.js +31 -3
- package/dist/js/node/builder/builderPlugins/compatModern.js +18 -12
- package/dist/js/node/builder/index.js +32 -16
- package/dist/js/node/builder/loaders/routerLoader.js +27 -0
- package/dist/js/node/builder/loaders/serverModuleLoader.js +11 -0
- package/dist/js/node/builder/share.js +1 -1
- package/dist/js/node/commands/build.js +8 -2
- package/dist/js/node/commands/dev.js +37 -32
- package/dist/js/node/commands/inspect.js +4 -2
- package/dist/js/node/config/default.js +213 -0
- package/dist/js/node/config/index.js +31 -0
- package/dist/js/node/config/initial/createHtmlConfig.js +38 -0
- package/dist/js/node/{builder → config/initial}/createOutputConfig.js +16 -15
- package/dist/js/node/config/initial/createSourceConfig.js +38 -0
- package/dist/js/node/config/initial/createToolsConfig.js +47 -0
- package/dist/js/node/config/initial/index.js +24 -0
- package/dist/js/node/config/initial/inits.js +127 -0
- package/dist/js/node/config/initial/transformNormalizedConfig.js +46 -0
- package/dist/js/node/defineConfig.js +20 -0
- package/dist/js/node/hooks.js +23 -28
- package/dist/js/node/index.js +30 -16
- package/dist/js/node/initialize/index.js +79 -0
- package/dist/js/node/schema/Schema.js +46 -0
- package/dist/js/node/schema/index.js +152 -0
- package/dist/js/node/schema/legacy.js +291 -0
- package/dist/js/node/types/config/deploy.js +0 -0
- package/dist/js/node/types/config/dev.js +0 -0
- package/dist/js/node/types/config/experiments.js +0 -0
- package/dist/js/node/types/config/html.js +0 -0
- package/dist/js/node/types/config/index.js +16 -0
- package/dist/js/node/types/config/output.js +0 -0
- package/dist/js/node/types/config/performance.js +0 -0
- package/dist/js/node/types/config/security.js +0 -0
- package/dist/js/node/types/config/source.js +0 -0
- package/dist/js/node/types/config/tools.js +0 -0
- package/dist/js/node/types/hooks.js +0 -0
- package/dist/js/node/types/index.js +38 -0
- package/dist/js/node/types/legacyConfig/deploy.js +0 -0
- package/dist/js/node/types/legacyConfig/dev.js +0 -0
- package/dist/js/node/types/legacyConfig/index.js +0 -0
- package/dist/js/node/types/legacyConfig/output.js +5 -0
- package/dist/js/node/types/legacyConfig/source.js +0 -0
- package/dist/js/node/types/legacyConfig/tools.js +0 -0
- package/dist/js/node/utils/config.js +1 -1
- package/dist/js/node/utils/createFileWatcher.js +91 -0
- package/dist/js/node/utils/restart.js +23 -0
- package/dist/js/treeshaking/analyze/constants.js +2 -0
- package/dist/js/treeshaking/analyze/generateCode.js +138 -82
- package/dist/js/treeshaking/analyze/getBundleEntry.js +1 -1
- package/dist/js/treeshaking/analyze/getFileSystemEntry.js +1 -1
- package/dist/js/treeshaking/analyze/getHtmlTemplate.js +1 -1
- package/dist/js/treeshaking/analyze/getServerRoutes.js +7 -5
- package/dist/js/treeshaking/analyze/index.js +10 -26
- package/dist/js/treeshaking/analyze/nestedRoutes.js +98 -55
- package/dist/js/treeshaking/analyze/templates.js +175 -101
- package/dist/js/treeshaking/analyze/utils.js +80 -4
- package/dist/js/treeshaking/builder/builderPlugins/compatModern.js +18 -12
- package/dist/js/treeshaking/builder/index.js +29 -16
- package/dist/js/treeshaking/builder/loaders/routerLoader.js +14 -0
- package/dist/js/treeshaking/builder/loaders/serverModuleLoader.js +4 -0
- package/dist/js/treeshaking/builder/share.js +1 -1
- package/dist/js/treeshaking/commands/build.js +33 -23
- package/dist/js/treeshaking/commands/dev.js +56 -43
- package/dist/js/treeshaking/commands/inspect.js +8 -3
- package/dist/js/treeshaking/config/default.js +199 -0
- package/dist/js/treeshaking/config/index.js +2 -0
- package/dist/js/treeshaking/config/initial/createHtmlConfig.js +31 -0
- package/dist/js/treeshaking/config/initial/createOutputConfig.js +70 -0
- package/dist/js/treeshaking/config/initial/createSourceConfig.js +41 -0
- package/dist/js/treeshaking/config/initial/createToolsConfig.js +38 -0
- package/dist/js/treeshaking/config/initial/index.js +11 -0
- package/dist/js/treeshaking/config/initial/inits.js +114 -0
- package/dist/js/treeshaking/config/initial/transformNormalizedConfig.js +38 -0
- package/dist/js/treeshaking/defineConfig.js +14 -0
- package/dist/js/treeshaking/hooks.js +23 -19
- package/dist/js/treeshaking/index.js +7 -5
- package/dist/js/treeshaking/initialize/index.js +121 -0
- package/dist/js/treeshaking/schema/Schema.js +75 -0
- package/dist/js/treeshaking/schema/index.js +138 -0
- package/dist/js/treeshaking/schema/legacy.js +273 -0
- package/dist/js/treeshaking/types/config/deploy.js +0 -0
- package/dist/js/treeshaking/types/config/dev.js +0 -0
- package/dist/js/treeshaking/types/config/experiments.js +0 -0
- package/dist/js/treeshaking/types/config/html.js +0 -0
- package/dist/js/treeshaking/types/config/index.js +2 -0
- package/dist/js/treeshaking/types/config/output.js +0 -0
- package/dist/js/treeshaking/types/config/performance.js +0 -0
- package/dist/js/treeshaking/types/config/security.js +0 -0
- package/dist/js/treeshaking/types/config/source.js +0 -0
- package/dist/js/treeshaking/types/config/tools.js +0 -0
- package/dist/js/treeshaking/types/hooks.js +0 -0
- package/dist/js/treeshaking/types/index.js +4 -0
- package/dist/js/treeshaking/types/legacyConfig/deploy.js +0 -0
- package/dist/js/treeshaking/types/legacyConfig/dev.js +0 -0
- package/dist/js/treeshaking/types/legacyConfig/index.js +0 -0
- package/dist/js/treeshaking/types/legacyConfig/output.js +1 -0
- package/dist/js/treeshaking/types/legacyConfig/source.js +0 -0
- package/dist/js/treeshaking/types/legacyConfig/tools.js +0 -0
- package/dist/js/treeshaking/utils/config.js +1 -1
- package/dist/js/treeshaking/utils/createFileWatcher.js +123 -0
- package/dist/js/treeshaking/utils/restart.js +45 -0
- package/dist/types/analyze/constants.d.ts +2 -0
- package/dist/types/analyze/generateCode.d.ts +3 -2
- package/dist/types/analyze/getBundleEntry.d.ts +2 -2
- package/dist/types/analyze/getFileSystemEntry.d.ts +2 -2
- package/dist/types/analyze/getHtmlTemplate.d.ts +3 -3
- package/dist/types/analyze/getServerRoutes.d.ts +3 -2
- package/dist/types/analyze/index.d.ts +3 -41
- package/dist/types/analyze/templates.d.ts +9 -8
- package/dist/types/analyze/utils.d.ts +10 -2
- package/dist/types/builder/builderPlugins/compatModern.d.ts +2 -2
- package/dist/types/builder/index.d.ts +5 -2
- package/dist/types/builder/loaders/routerLoader.d.ts +3 -0
- package/dist/types/builder/loaders/serverModuleLoader.d.ts +3 -0
- package/dist/types/builder/share.d.ts +2 -2
- package/dist/types/commands/build.d.ts +2 -2
- package/dist/types/commands/deploy.d.ts +2 -2
- package/dist/types/commands/dev.d.ts +2 -2
- package/dist/types/commands/inspect.d.ts +9 -1
- package/dist/types/commands/start.d.ts +2 -2
- package/dist/types/config/default.d.ts +3 -0
- package/dist/types/config/index.d.ts +2 -0
- package/dist/types/config/initial/createHtmlConfig.d.ts +2 -0
- package/dist/types/config/initial/createOutputConfig.d.ts +2 -0
- package/dist/types/config/initial/createSourceConfig.d.ts +2 -0
- package/dist/types/config/initial/createToolsConfig.d.ts +2 -0
- package/dist/types/config/initial/index.d.ts +4 -0
- package/dist/types/config/initial/inits.d.ts +4 -0
- package/dist/types/config/initial/transformNormalizedConfig.d.ts +2 -0
- package/dist/types/defineConfig.d.ts +7 -0
- package/dist/types/hooks.d.ts +2 -42
- package/dist/types/index.d.ts +5 -5
- package/dist/types/initialize/index.d.ts +3 -0
- package/dist/types/schema/Schema.d.ts +14 -0
- package/dist/types/schema/index.d.ts +4 -0
- package/dist/types/schema/legacy.d.ts +3 -0
- package/dist/types/types/config/deploy.d.ts +9 -0
- package/dist/types/types/config/dev.d.ts +13 -0
- package/dist/types/types/config/experiments.d.ts +4 -0
- package/dist/types/types/config/html.d.ts +4 -0
- package/dist/types/types/config/index.d.ts +62 -0
- package/dist/types/types/config/output.d.ts +23 -0
- package/dist/types/types/config/performance.d.ts +4 -0
- package/dist/types/types/config/security.d.ts +4 -0
- package/dist/types/types/config/source.d.ts +22 -0
- package/dist/types/types/config/tools.d.ts +22 -0
- package/dist/types/types/hooks.d.ts +81 -0
- package/dist/types/types/index.d.ts +23 -0
- package/dist/types/types/legacyConfig/deploy.d.ts +8 -0
- package/dist/types/types/legacyConfig/dev.d.ts +12 -0
- package/dist/types/types/legacyConfig/index.d.ts +33 -0
- package/dist/types/types/legacyConfig/output.d.ts +51 -0
- package/dist/types/types/legacyConfig/source.d.ts +25 -0
- package/dist/types/types/legacyConfig/tools.d.ts +16 -0
- package/dist/types/utils/config.d.ts +2 -2
- package/dist/types/utils/createFileWatcher.d.ts +4 -0
- package/dist/types/utils/printInstructions.d.ts +3 -3
- package/dist/types/utils/restart.d.ts +3 -0
- package/lib/types.d.ts +1 -1
- package/package.json +28 -25
- package/dist/js/modern/builder/createHtmlConfig.js +0 -58
- package/dist/js/modern/builder/createSourceConfig.js +0 -74
- package/dist/js/modern/builder/createToolsConfig.js +0 -87
- package/dist/js/node/builder/createHtmlConfig.js +0 -68
- package/dist/js/node/builder/createSourceConfig.js +0 -82
- package/dist/js/node/builder/createToolsConfig.js +0 -94
- package/dist/js/treeshaking/builder/createHtmlConfig.js +0 -59
- package/dist/js/treeshaking/builder/createOutputConfig.js +0 -70
- package/dist/js/treeshaking/builder/createSourceConfig.js +0 -88
- package/dist/js/treeshaking/builder/createToolsConfig.js +0 -85
- package/dist/types/builder/createHtmlConfig.d.ts +0 -6
- package/dist/types/builder/createOutputConfig.d.ts +0 -3
- package/dist/types/builder/createSourceConfig.d.ts +0 -5
- package/dist/types/builder/createToolsConfig.d.ts +0 -13
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
2
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
3
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
4
|
+
import { ensureAbsolutePath, getPort, isDev } from '@modern-js/utils';
|
|
5
|
+
import { legacySchema, schema } from "../schema";
|
|
6
|
+
import { getCommand } from "../utils/commands";
|
|
7
|
+
import { transformNormalizedConfig } from "../config/initial/transformNormalizedConfig";
|
|
8
|
+
import { checkIsLegacyConfig, createDefaultConfig, createLegacyDefaultConfig } from "../config";
|
|
9
|
+
export default (() => ({
|
|
10
|
+
name: '@modern-js/plugin-initialize',
|
|
11
|
+
setup(api) {
|
|
12
|
+
const config = () => {
|
|
13
|
+
const appContext = api.useAppContext();
|
|
14
|
+
const userConfig = api.useConfigContext();
|
|
15
|
+
return checkIsLegacyConfig(userConfig) ? createLegacyDefaultConfig(appContext) : createDefaultConfig(appContext);
|
|
16
|
+
};
|
|
17
|
+
const validateSchema = () => {
|
|
18
|
+
const userConfig = api.useConfigContext();
|
|
19
|
+
const schemas = checkIsLegacyConfig(userConfig) ? legacySchema : schema;
|
|
20
|
+
return schemas.generate();
|
|
21
|
+
};
|
|
22
|
+
return {
|
|
23
|
+
config,
|
|
24
|
+
validateSchema,
|
|
25
|
+
async resolvedConfig({
|
|
26
|
+
resolved
|
|
27
|
+
}) {
|
|
28
|
+
var _resolved$output$dist, _normalizedConfig$ser;
|
|
29
|
+
let appContext = api.useAppContext();
|
|
30
|
+
const userConfig = api.useConfigContext();
|
|
31
|
+
const port = await getDevServerPort(appContext, resolved);
|
|
32
|
+
appContext = _objectSpread(_objectSpread({}, appContext), {}, {
|
|
33
|
+
port,
|
|
34
|
+
distDirectory: ensureAbsolutePath(appContext.distDirectory, ((_resolved$output$dist = resolved.output.distPath) === null || _resolved$output$dist === void 0 ? void 0 : _resolved$output$dist.root) || 'dist')
|
|
35
|
+
});
|
|
36
|
+
api.setAppContext(appContext);
|
|
37
|
+
const normalizedConfig = checkIsLegacyConfig(resolved) ? transformNormalizedConfig(resolved) : resolved;
|
|
38
|
+
return {
|
|
39
|
+
resolved: {
|
|
40
|
+
// FIXME: the userConfig mayby legacy userConfig
|
|
41
|
+
_raw: userConfig,
|
|
42
|
+
source: normalizedConfig.source || {},
|
|
43
|
+
server: _objectSpread(_objectSpread({}, normalizedConfig.server || {}), {}, {
|
|
44
|
+
port: port || ((_normalizedConfig$ser = normalizedConfig.server) === null || _normalizedConfig$ser === void 0 ? void 0 : _normalizedConfig$ser.port)
|
|
45
|
+
}),
|
|
46
|
+
bff: normalizedConfig.bff || {},
|
|
47
|
+
dev: normalizedConfig.dev || {},
|
|
48
|
+
html: normalizedConfig.html || {},
|
|
49
|
+
output: normalizedConfig.output || {},
|
|
50
|
+
security: normalizedConfig.security || {},
|
|
51
|
+
tools: normalizedConfig.tools || {},
|
|
52
|
+
testing: normalizedConfig.testing || {},
|
|
53
|
+
plugins: normalizedConfig.plugins || [],
|
|
54
|
+
runtime: normalizedConfig.runtime || {},
|
|
55
|
+
runtimeByEntries: normalizedConfig.runtimeByEntries || {},
|
|
56
|
+
deploy: normalizedConfig.deploy || {},
|
|
57
|
+
performance: normalizedConfig.performance || {},
|
|
58
|
+
experiments: normalizedConfig.experiments || {}
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
}));
|
|
65
|
+
async function getDevServerPort(appContext, resolved) {
|
|
66
|
+
const command = getCommand();
|
|
67
|
+
if (isDev() && command === 'dev') {
|
|
68
|
+
var _appContext$port;
|
|
69
|
+
return ((_appContext$port = appContext.port) !== null && _appContext$port !== void 0 ? _appContext$port : 0) > 0 ? appContext.port : await getPort(resolved.server.port || 8080);
|
|
70
|
+
}
|
|
71
|
+
return resolved.server.port;
|
|
72
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
2
|
+
import { merge } from '@modern-js/utils/lodash';
|
|
3
|
+
export class Schema extends Map {
|
|
4
|
+
constructor(baseSchema = {}) {
|
|
5
|
+
super();
|
|
6
|
+
_defineProperty(this, "schema", void 0);
|
|
7
|
+
this.schema = baseSchema;
|
|
8
|
+
}
|
|
9
|
+
setSchema(key, object) {
|
|
10
|
+
Object.entries(object).forEach(([k, v]) => {
|
|
11
|
+
const target = `${key}.${k}`;
|
|
12
|
+
this.set(target, v);
|
|
13
|
+
});
|
|
14
|
+
return this;
|
|
15
|
+
}
|
|
16
|
+
set(key, value) {
|
|
17
|
+
if (this.has(key)) {
|
|
18
|
+
merge(this.schema[key], value);
|
|
19
|
+
} else {
|
|
20
|
+
this.schema[key] = value;
|
|
21
|
+
}
|
|
22
|
+
return this;
|
|
23
|
+
}
|
|
24
|
+
has(key) {
|
|
25
|
+
return key in this.schema;
|
|
26
|
+
}
|
|
27
|
+
get(key) {
|
|
28
|
+
return this.schema[key];
|
|
29
|
+
}
|
|
30
|
+
delete(key) {
|
|
31
|
+
return delete this.schema[key];
|
|
32
|
+
}
|
|
33
|
+
generate() {
|
|
34
|
+
return Object.entries(this.schema).map(([target, schema]) => ({
|
|
35
|
+
target,
|
|
36
|
+
schema
|
|
37
|
+
}));
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { ENTRY_NAME_PATTERN } from '@modern-js/utils/constants';
|
|
2
|
+
import { Schema } from "./Schema";
|
|
3
|
+
const source = {
|
|
4
|
+
entries: {
|
|
5
|
+
type: 'object',
|
|
6
|
+
patternProperties: {
|
|
7
|
+
[ENTRY_NAME_PATTERN]: {
|
|
8
|
+
if: {
|
|
9
|
+
type: 'object'
|
|
10
|
+
},
|
|
11
|
+
then: {
|
|
12
|
+
required: ['entry'],
|
|
13
|
+
properties: {
|
|
14
|
+
entry: {
|
|
15
|
+
type: ['string', 'array']
|
|
16
|
+
},
|
|
17
|
+
disableMount: {
|
|
18
|
+
type: 'boolean'
|
|
19
|
+
},
|
|
20
|
+
enableFileSystemRoutes: {
|
|
21
|
+
type: 'boolean'
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
additionalProperties: false
|
|
25
|
+
},
|
|
26
|
+
else: {
|
|
27
|
+
type: ['string', 'array']
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
enableAsyncEntry: {
|
|
33
|
+
type: 'boolean'
|
|
34
|
+
},
|
|
35
|
+
disableDefaultEntries: {
|
|
36
|
+
type: 'boolean'
|
|
37
|
+
},
|
|
38
|
+
entriesDir: {
|
|
39
|
+
type: 'string'
|
|
40
|
+
},
|
|
41
|
+
configDir: {
|
|
42
|
+
type: 'string'
|
|
43
|
+
},
|
|
44
|
+
designSystem: {
|
|
45
|
+
type: 'object'
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
const bff = {
|
|
49
|
+
prefix: {
|
|
50
|
+
type: 'string'
|
|
51
|
+
},
|
|
52
|
+
proxy: {
|
|
53
|
+
type: 'object',
|
|
54
|
+
additionalProperties: {
|
|
55
|
+
type: 'string'
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
const output = {
|
|
60
|
+
ssg: {
|
|
61
|
+
typeof: ['boolean', 'object', 'function']
|
|
62
|
+
},
|
|
63
|
+
enableModernMode: {
|
|
64
|
+
type: 'boolean'
|
|
65
|
+
},
|
|
66
|
+
disableNodePolyfill: {
|
|
67
|
+
type: 'boolean'
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
const dev = {
|
|
71
|
+
proxy: {
|
|
72
|
+
type: ['boolean', 'object']
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
const server = {
|
|
76
|
+
routes: {
|
|
77
|
+
type: 'object'
|
|
78
|
+
},
|
|
79
|
+
publicRoutes: {
|
|
80
|
+
type: 'object'
|
|
81
|
+
},
|
|
82
|
+
ssr: {
|
|
83
|
+
type: ['boolean', 'object']
|
|
84
|
+
},
|
|
85
|
+
ssrByEntries: {
|
|
86
|
+
type: 'object'
|
|
87
|
+
},
|
|
88
|
+
baseUrl: {
|
|
89
|
+
anyOf: [{
|
|
90
|
+
type: 'string'
|
|
91
|
+
}, {
|
|
92
|
+
type: 'array',
|
|
93
|
+
items: {
|
|
94
|
+
type: 'string'
|
|
95
|
+
}
|
|
96
|
+
}]
|
|
97
|
+
},
|
|
98
|
+
port: {
|
|
99
|
+
type: 'number'
|
|
100
|
+
},
|
|
101
|
+
logger: {
|
|
102
|
+
type: ['boolean', 'object']
|
|
103
|
+
},
|
|
104
|
+
metrics: {
|
|
105
|
+
type: ['boolean', 'object']
|
|
106
|
+
},
|
|
107
|
+
enableMicroFrontendDebug: {
|
|
108
|
+
type: 'boolean'
|
|
109
|
+
},
|
|
110
|
+
watchOptions: {
|
|
111
|
+
type: 'object'
|
|
112
|
+
},
|
|
113
|
+
compiler: {
|
|
114
|
+
type: 'string'
|
|
115
|
+
},
|
|
116
|
+
disableFrameworkExt: {
|
|
117
|
+
type: 'boolean'
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
const tools = {
|
|
121
|
+
tailwindcss: {
|
|
122
|
+
type: 'object'
|
|
123
|
+
},
|
|
124
|
+
jest: {
|
|
125
|
+
typeof: ['object', 'function']
|
|
126
|
+
},
|
|
127
|
+
esbuild: {
|
|
128
|
+
typeof: ['object']
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
const deploy = {
|
|
132
|
+
microFrontend: {
|
|
133
|
+
type: ['boolean', 'object']
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
const schema = new Schema();
|
|
137
|
+
schema.setSchema('bff', bff).setSchema('dev', dev).setSchema('server', server).setSchema('source', source).setSchema('output', output).setSchema('tools', tools).setSchema('deploy', deploy);
|
|
138
|
+
export { default as legacySchema } from "./legacy";
|
|
139
|
+
export { schema };
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
import { ENTRY_NAME_PATTERN } from '@modern-js/utils/constants';
|
|
2
|
+
import { Schema } from "./Schema";
|
|
3
|
+
const source = {
|
|
4
|
+
entries: {
|
|
5
|
+
type: 'object',
|
|
6
|
+
patternProperties: {
|
|
7
|
+
[ENTRY_NAME_PATTERN]: {
|
|
8
|
+
if: {
|
|
9
|
+
type: 'object'
|
|
10
|
+
},
|
|
11
|
+
then: {
|
|
12
|
+
required: ['entry'],
|
|
13
|
+
properties: {
|
|
14
|
+
entry: {
|
|
15
|
+
type: ['string', 'array']
|
|
16
|
+
},
|
|
17
|
+
disableMount: {
|
|
18
|
+
type: 'boolean'
|
|
19
|
+
},
|
|
20
|
+
enableFileSystemRoutes: {
|
|
21
|
+
type: 'boolean'
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
additionalProperties: false
|
|
25
|
+
},
|
|
26
|
+
else: {
|
|
27
|
+
type: ['string', 'array']
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
preEntry: {
|
|
33
|
+
type: ['string', 'array']
|
|
34
|
+
},
|
|
35
|
+
alias: {
|
|
36
|
+
typeof: ['object', 'function']
|
|
37
|
+
},
|
|
38
|
+
enableAsyncEntry: {
|
|
39
|
+
type: 'boolean'
|
|
40
|
+
},
|
|
41
|
+
disableDefaultEntries: {
|
|
42
|
+
type: 'boolean'
|
|
43
|
+
},
|
|
44
|
+
envVars: {
|
|
45
|
+
type: 'array'
|
|
46
|
+
},
|
|
47
|
+
globalVars: {
|
|
48
|
+
type: 'object'
|
|
49
|
+
},
|
|
50
|
+
moduleScopes: {
|
|
51
|
+
instanceof: ['Array', 'Function']
|
|
52
|
+
},
|
|
53
|
+
entriesDir: {
|
|
54
|
+
type: 'string'
|
|
55
|
+
},
|
|
56
|
+
configDir: {
|
|
57
|
+
type: 'string'
|
|
58
|
+
},
|
|
59
|
+
include: {
|
|
60
|
+
type: ['array']
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
const output = {
|
|
64
|
+
assetPrefix: {
|
|
65
|
+
type: 'string'
|
|
66
|
+
},
|
|
67
|
+
path: {
|
|
68
|
+
type: 'string'
|
|
69
|
+
},
|
|
70
|
+
jsPath: {
|
|
71
|
+
type: 'string'
|
|
72
|
+
},
|
|
73
|
+
cssPath: {
|
|
74
|
+
type: 'string'
|
|
75
|
+
},
|
|
76
|
+
htmlPath: {
|
|
77
|
+
type: 'string'
|
|
78
|
+
},
|
|
79
|
+
mediaPath: {
|
|
80
|
+
type: 'string'
|
|
81
|
+
},
|
|
82
|
+
mountId: {
|
|
83
|
+
type: 'string'
|
|
84
|
+
},
|
|
85
|
+
favicon: {
|
|
86
|
+
type: 'string'
|
|
87
|
+
},
|
|
88
|
+
faviconByEntries: {
|
|
89
|
+
type: 'object',
|
|
90
|
+
patternProperties: {
|
|
91
|
+
[ENTRY_NAME_PATTERN]: {
|
|
92
|
+
type: 'string'
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
title: {
|
|
97
|
+
type: 'string'
|
|
98
|
+
},
|
|
99
|
+
titleByEntries: {
|
|
100
|
+
type: 'object',
|
|
101
|
+
patternProperties: {
|
|
102
|
+
[ENTRY_NAME_PATTERN]: {
|
|
103
|
+
type: 'string'
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
meta: {
|
|
108
|
+
type: 'object'
|
|
109
|
+
},
|
|
110
|
+
metaByEntries: {
|
|
111
|
+
type: 'object',
|
|
112
|
+
patternProperties: {
|
|
113
|
+
[ENTRY_NAME_PATTERN]: {
|
|
114
|
+
type: 'object'
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
inject: {
|
|
119
|
+
enum: [true, 'head', 'body', false]
|
|
120
|
+
},
|
|
121
|
+
injectByEntries: {
|
|
122
|
+
type: 'object',
|
|
123
|
+
patternProperties: {
|
|
124
|
+
[ENTRY_NAME_PATTERN]: {
|
|
125
|
+
enum: [true, 'head', 'body', false]
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
copy: {
|
|
130
|
+
type: 'array'
|
|
131
|
+
},
|
|
132
|
+
scriptExt: {
|
|
133
|
+
type: 'object'
|
|
134
|
+
},
|
|
135
|
+
disableTsChecker: {
|
|
136
|
+
type: 'boolean'
|
|
137
|
+
},
|
|
138
|
+
disableHtmlFolder: {
|
|
139
|
+
type: 'boolean'
|
|
140
|
+
},
|
|
141
|
+
disableCssModuleExtension: {
|
|
142
|
+
type: 'boolean'
|
|
143
|
+
},
|
|
144
|
+
disableCssExtract: {
|
|
145
|
+
type: 'boolean'
|
|
146
|
+
},
|
|
147
|
+
enableCssModuleTSDeclaration: {
|
|
148
|
+
type: 'boolean'
|
|
149
|
+
},
|
|
150
|
+
disableMinimize: {
|
|
151
|
+
type: 'boolean'
|
|
152
|
+
},
|
|
153
|
+
enableInlineStyles: {
|
|
154
|
+
type: 'boolean'
|
|
155
|
+
},
|
|
156
|
+
enableInlineScripts: {
|
|
157
|
+
type: 'boolean'
|
|
158
|
+
},
|
|
159
|
+
disableSourceMap: {
|
|
160
|
+
type: 'boolean'
|
|
161
|
+
},
|
|
162
|
+
disableInlineRuntimeChunk: {
|
|
163
|
+
type: 'boolean'
|
|
164
|
+
},
|
|
165
|
+
disableAssetsCache: {
|
|
166
|
+
type: 'boolean'
|
|
167
|
+
},
|
|
168
|
+
enableLatestDecorators: {
|
|
169
|
+
type: 'boolean'
|
|
170
|
+
},
|
|
171
|
+
enableTsLoader: {
|
|
172
|
+
type: 'boolean'
|
|
173
|
+
},
|
|
174
|
+
dataUriLimit: {
|
|
175
|
+
type: 'number'
|
|
176
|
+
},
|
|
177
|
+
templateParameters: {
|
|
178
|
+
type: 'object'
|
|
179
|
+
},
|
|
180
|
+
templateParametersByEntries: {
|
|
181
|
+
type: 'object',
|
|
182
|
+
patternProperties: {
|
|
183
|
+
[ENTRY_NAME_PATTERN]: {
|
|
184
|
+
type: 'object'
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
},
|
|
188
|
+
polyfill: {
|
|
189
|
+
type: 'string',
|
|
190
|
+
enum: ['usage', 'entry', 'off', 'ua']
|
|
191
|
+
},
|
|
192
|
+
cssModuleLocalIdentName: {
|
|
193
|
+
type: 'string'
|
|
194
|
+
},
|
|
195
|
+
federation: {
|
|
196
|
+
type: 'object'
|
|
197
|
+
},
|
|
198
|
+
disableNodePolyfill: {
|
|
199
|
+
type: 'boolean'
|
|
200
|
+
},
|
|
201
|
+
enableModernMode: {
|
|
202
|
+
type: 'boolean'
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
const server = {
|
|
206
|
+
routes: {
|
|
207
|
+
type: 'object'
|
|
208
|
+
},
|
|
209
|
+
publicRoutes: {
|
|
210
|
+
type: 'object'
|
|
211
|
+
},
|
|
212
|
+
ssr: {
|
|
213
|
+
type: ['boolean', 'object']
|
|
214
|
+
},
|
|
215
|
+
ssrByEntries: {
|
|
216
|
+
type: 'object'
|
|
217
|
+
},
|
|
218
|
+
baseUrl: {
|
|
219
|
+
anyOf: [{
|
|
220
|
+
type: 'string'
|
|
221
|
+
}, {
|
|
222
|
+
type: 'array',
|
|
223
|
+
items: {
|
|
224
|
+
type: 'string'
|
|
225
|
+
}
|
|
226
|
+
}]
|
|
227
|
+
},
|
|
228
|
+
port: {
|
|
229
|
+
type: 'number'
|
|
230
|
+
},
|
|
231
|
+
logger: {
|
|
232
|
+
type: ['boolean', 'object']
|
|
233
|
+
},
|
|
234
|
+
metrics: {
|
|
235
|
+
type: ['boolean', 'object']
|
|
236
|
+
},
|
|
237
|
+
enableMicroFrontendDebug: {
|
|
238
|
+
type: 'boolean'
|
|
239
|
+
},
|
|
240
|
+
watchOptions: {
|
|
241
|
+
type: 'object'
|
|
242
|
+
},
|
|
243
|
+
compiler: {
|
|
244
|
+
type: 'string'
|
|
245
|
+
},
|
|
246
|
+
disableFrameworkExt: {
|
|
247
|
+
type: 'boolean'
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
const dev = {
|
|
251
|
+
proxy: {
|
|
252
|
+
type: ['boolean', 'object']
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
const deploy = {
|
|
256
|
+
microFrontend: {
|
|
257
|
+
type: ['boolean', 'object']
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
const tools = {
|
|
261
|
+
tailwindcss: {
|
|
262
|
+
type: 'object'
|
|
263
|
+
},
|
|
264
|
+
jest: {
|
|
265
|
+
typeof: ['object', 'function']
|
|
266
|
+
},
|
|
267
|
+
esbuild: {
|
|
268
|
+
typeof: ['object']
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
const bff = {
|
|
272
|
+
prefix: {
|
|
273
|
+
type: 'string'
|
|
274
|
+
},
|
|
275
|
+
proxy: {
|
|
276
|
+
type: 'object',
|
|
277
|
+
additionalProperties: {
|
|
278
|
+
type: 'string'
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
const schema = new Schema();
|
|
283
|
+
schema.setSchema('bff', bff).setSchema('dev', dev).setSchema('server', server).setSchema('source', source).setSchema('output', output).setSchema('tools', tools).setSchema('deploy', deploy);
|
|
284
|
+
export default schema;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
File without changes
|
|
File without changes
|
|
@@ -59,7 +59,7 @@ export const safeReplacer = () => {
|
|
|
59
59
|
};
|
|
60
60
|
export const emitResolvedConfig = async (appDirectory, resolvedConfig) => {
|
|
61
61
|
var _resolvedConfig$outpu;
|
|
62
|
-
const outputPath = path.join(appDirectory, (
|
|
62
|
+
const outputPath = path.join(appDirectory, ((_resolvedConfig$outpu = resolvedConfig.output.distPath) === null || _resolvedConfig$outpu === void 0 ? void 0 : _resolvedConfig$outpu.root) || './dist', OUTPUT_CONFIG_FILE);
|
|
63
63
|
await fs.writeJSON(outputPath, resolvedConfig, {
|
|
64
64
|
spaces: 2,
|
|
65
65
|
replacer: safeReplacer()
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import crypto from 'crypto';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { isDev, chokidar, createDebugger, isTest, getServerConfig } from '@modern-js/utils';
|
|
5
|
+
/**
|
|
6
|
+
* Get user config from package.json.
|
|
7
|
+
* @param appDirectory - App root directory.
|
|
8
|
+
* @returns modernConfig or undefined
|
|
9
|
+
*/
|
|
10
|
+
// FIXME: read package.json again;
|
|
11
|
+
const getPackageConfig = (appDirectory, packageJsonConfig) => {
|
|
12
|
+
const PACKAGE_JSON_CONFIG_NAME = 'modernConfig';
|
|
13
|
+
const json = JSON.parse(fs.readFileSync(path.resolve(appDirectory, './package.json'), 'utf8'));
|
|
14
|
+
return json[packageJsonConfig !== null && packageJsonConfig !== void 0 ? packageJsonConfig : PACKAGE_JSON_CONFIG_NAME];
|
|
15
|
+
};
|
|
16
|
+
export const addServerConfigToDeps = async (dependencies, appDirectory, serverConfigFile) => {
|
|
17
|
+
const serverConfig = await getServerConfig(appDirectory, serverConfigFile);
|
|
18
|
+
if (serverConfig) {
|
|
19
|
+
dependencies.push(serverConfig);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
const debug = createDebugger('watch-files');
|
|
23
|
+
const md5 = data => crypto.createHash('md5').update(data).digest('hex');
|
|
24
|
+
const hashMap = new Map();
|
|
25
|
+
export const createFileWatcher = async (appContext, configDir, hooksRunner) => {
|
|
26
|
+
// only add fs watcher on dev mode.
|
|
27
|
+
if (isDev() || isTest()) {
|
|
28
|
+
const {
|
|
29
|
+
appDirectory,
|
|
30
|
+
configFile
|
|
31
|
+
} = appContext;
|
|
32
|
+
const extraFiles = await hooksRunner.watchFiles();
|
|
33
|
+
const configPath = path.join(appDirectory, configDir);
|
|
34
|
+
const dependencies = getPackageConfig(appContext.appDirectory, appContext.packageName) ? [path.resolve(appDirectory, './package.json')] : [];
|
|
35
|
+
|
|
36
|
+
// 将 server.config 加入到 loaded.dependencies,以便对文件监听做热更新
|
|
37
|
+
await addServerConfigToDeps(dependencies, appContext.appDirectory, appContext.serverConfigFile);
|
|
38
|
+
const watched = [`${configPath}/html`, ...extraFiles, ...dependencies, configFile].filter(Boolean);
|
|
39
|
+
debug(`watched: %o`, watched);
|
|
40
|
+
const watcher = chokidar.watch(watched, {
|
|
41
|
+
cwd: appDirectory,
|
|
42
|
+
ignoreInitial: true,
|
|
43
|
+
ignorePermissionErrors: true,
|
|
44
|
+
ignored: [/node_modules/, '**/__test__/**', '**/*.test.(js|jsx|ts|tsx)', '**/*.spec.(js|jsx|ts|tsx)', '**/*.stories.(js|jsx|ts|tsx)']
|
|
45
|
+
});
|
|
46
|
+
watcher.on('change', changed => {
|
|
47
|
+
const lastHash = hashMap.get(changed);
|
|
48
|
+
const currentHash = md5(fs.readFileSync(path.join(appDirectory, changed), 'utf8'));
|
|
49
|
+
if (currentHash !== lastHash) {
|
|
50
|
+
debug(`file change: %s`, changed);
|
|
51
|
+
hashMap.set(changed, currentHash);
|
|
52
|
+
hooksRunner.fileChange({
|
|
53
|
+
filename: changed,
|
|
54
|
+
eventType: 'change'
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
watcher.on('add', name => {
|
|
59
|
+
debug(`add file: %s`, name);
|
|
60
|
+
const currentHash = md5(fs.readFileSync(path.join(appDirectory, name), 'utf8'));
|
|
61
|
+
hashMap.set(name, currentHash);
|
|
62
|
+
hooksRunner.fileChange({
|
|
63
|
+
filename: name,
|
|
64
|
+
eventType: 'add'
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
watcher.on('unlink', name => {
|
|
68
|
+
debug(`remove file: %s`, name);
|
|
69
|
+
if (hashMap.has(name)) {
|
|
70
|
+
hashMap.delete(name);
|
|
71
|
+
}
|
|
72
|
+
hooksRunner.fileChange({
|
|
73
|
+
filename: name,
|
|
74
|
+
eventType: 'unlink'
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
watcher.on('error', err => {
|
|
78
|
+
throw err;
|
|
79
|
+
});
|
|
80
|
+
return watcher;
|
|
81
|
+
}
|
|
82
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { cli } from '@modern-js/core';
|
|
2
|
+
import { logger, program } from '@modern-js/utils';
|
|
3
|
+
export async function restart(hooksRunner) {
|
|
4
|
+
logger.info('Restart...\n');
|
|
5
|
+
let hasGetError = false;
|
|
6
|
+
await hooksRunner.beforeRestart();
|
|
7
|
+
try {
|
|
8
|
+
await cli.init(cli.getPrevInitOptions());
|
|
9
|
+
} catch (err) {
|
|
10
|
+
console.error(err);
|
|
11
|
+
hasGetError = true;
|
|
12
|
+
} finally {
|
|
13
|
+
if (!hasGetError) {
|
|
14
|
+
program.parse(process.argv);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|