@modern-js/app-tools 2.0.0-beta.0 → 2.0.0-beta.2
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 +375 -0
- package/dist/js/modern/analyze/generateCode.js +30 -38
- package/dist/js/modern/analyze/getBundleEntry.js +5 -13
- package/dist/js/modern/analyze/getClientRoutes/getRoutes.js +5 -30
- package/dist/js/modern/analyze/getClientRoutes/getRoutesLegacy.js +5 -30
- package/dist/js/modern/analyze/getClientRoutes/utils.js +0 -3
- package/dist/js/modern/analyze/getFileSystemEntry.js +5 -18
- package/dist/js/modern/analyze/getHtmlTemplate.js +3 -10
- package/dist/js/modern/analyze/getServerRoutes.js +25 -38
- package/dist/js/modern/analyze/index.js +90 -48
- package/dist/js/modern/analyze/isDefaultExportFunction.js +0 -4
- package/dist/js/modern/analyze/makeLegalIdentifier.js +0 -2
- package/dist/js/modern/analyze/nestedRoutes.js +8 -33
- package/dist/js/modern/analyze/templates.js +22 -37
- package/dist/js/modern/analyze/utils.js +0 -7
- package/dist/js/modern/builder/builderPlugins/compatModern.js +41 -58
- package/dist/js/modern/builder/index.js +56 -37
- package/dist/js/modern/builder/share.js +1 -5
- package/dist/js/modern/builder/webpackPlugins/htmlAsyncChunkPlugin.js +0 -8
- package/dist/js/modern/builder/webpackPlugins/htmlBottomTemplate.js +2 -13
- package/dist/js/modern/builder/webpackPlugins/routerPlugin.js +97 -0
- package/dist/js/modern/commands/build.js +12 -46
- package/dist/js/modern/commands/dev.js +20 -23
- package/dist/js/modern/commands/inspect.js +4 -19
- package/dist/js/modern/commands/start.js +1 -2
- package/dist/js/modern/config/default.js +207 -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 +19 -18
- 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 +12 -19
- 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 +2 -13
- package/dist/js/modern/utils/createFileWatcher.js +82 -0
- package/dist/js/modern/utils/createServer.js +0 -5
- package/dist/js/modern/utils/getSpecifiedEntries.js +0 -6
- package/dist/js/modern/utils/printInstructions.js +2 -1
- package/dist/js/modern/utils/restart.js +17 -0
- package/dist/js/modern/utils/routes.js +0 -2
- package/dist/js/node/analyze/generateCode.js +30 -61
- package/dist/js/node/analyze/getBundleEntry.js +5 -19
- package/dist/js/node/analyze/getClientRoutes/getRoutes.js +5 -45
- package/dist/js/node/analyze/getClientRoutes/getRoutesLegacy.js +5 -45
- package/dist/js/node/analyze/getClientRoutes/index.js +0 -2
- package/dist/js/node/analyze/getClientRoutes/utils.js +0 -14
- package/dist/js/node/analyze/getFileSystemEntry.js +5 -26
- package/dist/js/node/analyze/getHtmlTemplate.js +3 -24
- package/dist/js/node/analyze/getServerRoutes.js +24 -46
- package/dist/js/node/analyze/index.js +91 -70
- package/dist/js/node/analyze/isDefaultExportFunction.js +0 -12
- package/dist/js/node/analyze/makeLegalIdentifier.js +0 -4
- package/dist/js/node/analyze/nestedRoutes.js +8 -41
- package/dist/js/node/analyze/templates.js +22 -47
- package/dist/js/node/analyze/utils.js +0 -20
- package/dist/js/node/builder/builderPlugins/compatModern.js +41 -69
- package/dist/js/node/builder/index.js +57 -51
- package/dist/js/node/builder/share.js +1 -13
- package/dist/js/node/builder/webpackPlugins/htmlAsyncChunkPlugin.js +0 -10
- package/dist/js/node/builder/webpackPlugins/htmlBottomTemplate.js +2 -15
- package/dist/js/node/builder/webpackPlugins/routerPlugin.js +105 -0
- package/dist/js/node/commands/build.js +10 -57
- package/dist/js/node/commands/deploy.js +0 -2
- package/dist/js/node/commands/dev.js +19 -34
- package/dist/js/node/commands/index.js +0 -6
- package/dist/js/node/commands/inspect.js +4 -26
- package/dist/js/node/commands/start.js +1 -11
- package/dist/js/node/config/default.js +214 -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 +19 -20
- 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/exports/server.js +0 -1
- package/dist/js/node/hooks.js +23 -30
- package/dist/js/node/index.js +35 -48
- package/dist/js/node/initialize/index.js +79 -0
- package/dist/js/node/locale/index.js +0 -4
- 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/commands.js +0 -2
- package/dist/js/node/utils/config.js +2 -26
- package/dist/js/node/utils/createFileWatcher.js +90 -0
- package/dist/js/node/utils/createServer.js +0 -15
- package/dist/js/node/utils/getSpecifiedEntries.js +0 -9
- package/dist/js/node/utils/language.js +0 -2
- package/dist/js/node/utils/printInstructions.js +2 -5
- package/dist/js/node/utils/restart.js +23 -0
- package/dist/js/node/utils/routes.js +0 -5
- package/dist/js/treeshaking/analyze/generateCode.js +58 -101
- package/dist/js/treeshaking/analyze/getBundleEntry.js +12 -20
- package/dist/js/treeshaking/analyze/getClientRoutes/getRoutes.js +16 -42
- package/dist/js/treeshaking/analyze/getClientRoutes/getRoutesLegacy.js +16 -42
- package/dist/js/treeshaking/analyze/getClientRoutes/utils.js +0 -3
- package/dist/js/treeshaking/analyze/getFileSystemEntry.js +5 -18
- package/dist/js/treeshaking/analyze/getHtmlTemplate.js +3 -27
- package/dist/js/treeshaking/analyze/getServerRoutes.js +29 -41
- package/dist/js/treeshaking/analyze/index.js +195 -91
- package/dist/js/treeshaking/analyze/isDefaultExportFunction.js +0 -4
- package/dist/js/treeshaking/analyze/makeLegalIdentifier.js +0 -2
- package/dist/js/treeshaking/analyze/nestedRoutes.js +9 -51
- package/dist/js/treeshaking/analyze/templates.js +31 -50
- package/dist/js/treeshaking/analyze/utils.js +7 -14
- package/dist/js/treeshaking/builder/builderPlugins/compatModern.js +50 -68
- package/dist/js/treeshaking/builder/index.js +69 -65
- package/dist/js/treeshaking/builder/share.js +1 -5
- package/dist/js/treeshaking/builder/webpackPlugins/htmlAsyncChunkPlugin.js +1 -13
- package/dist/js/treeshaking/builder/webpackPlugins/htmlBottomTemplate.js +2 -14
- package/dist/js/treeshaking/builder/webpackPlugins/routerPlugin.js +121 -0
- package/dist/js/treeshaking/commands/build.js +41 -116
- package/dist/js/treeshaking/commands/deploy.js +0 -3
- package/dist/js/treeshaking/commands/dev.js +38 -46
- package/dist/js/treeshaking/commands/inspect.js +9 -27
- package/dist/js/treeshaking/commands/start.js +1 -9
- package/dist/js/treeshaking/config/default.js +200 -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 +67 -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 +8 -43
- 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 +2 -18
- package/dist/js/treeshaking/utils/createFileWatcher.js +123 -0
- package/dist/js/treeshaking/utils/createServer.js +0 -10
- package/dist/js/treeshaking/utils/getSpecifiedEntries.js +0 -10
- package/dist/js/treeshaking/utils/printInstructions.js +0 -5
- package/dist/js/treeshaking/utils/restart.js +45 -0
- package/dist/js/treeshaking/utils/routes.js +0 -4
- 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 -42
- package/dist/types/analyze/nestedRoutes.d.ts +1 -1
- package/dist/types/analyze/templates.d.ts +4 -2
- package/dist/types/analyze/utils.d.ts +1 -1
- package/dist/types/builder/builderPlugins/compatModern.d.ts +2 -3
- package/dist/types/builder/index.d.ts +7 -8
- package/dist/types/builder/share.d.ts +2 -2
- package/dist/types/builder/webpackPlugins/routerPlugin.d.ts +10 -0
- 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 +6 -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 -7
- 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 +15 -0
- package/dist/types/types/hooks.d.ts +80 -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 -3
- package/dist/types/utils/createFileWatcher.d.ts +3 -0
- package/dist/types/utils/printInstructions.d.ts +3 -3
- package/dist/types/utils/restart.d.ts +3 -0
- package/package.json +26 -25
- package/dist/js/modern/builder/createHtmlConfig.js +0 -58
- package/dist/js/modern/builder/createSourceConfig.js +0 -85
- package/dist/js/modern/builder/createToolsConfig.js +0 -94
- package/dist/js/modern/utils/createCompiler.js +0 -58
- package/dist/js/node/builder/createHtmlConfig.js +0 -76
- package/dist/js/node/builder/createSourceConfig.js +0 -99
- package/dist/js/node/builder/createToolsConfig.js +0 -103
- package/dist/js/node/utils/createCompiler.js +0 -75
- package/dist/js/treeshaking/builder/createHtmlConfig.js +0 -59
- package/dist/js/treeshaking/builder/createOutputConfig.js +0 -67
- package/dist/js/treeshaking/builder/createSourceConfig.js +0 -100
- package/dist/js/treeshaking/builder/createToolsConfig.js +0 -90
- package/dist/js/treeshaking/utils/createCompiler.js +0 -117
- 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
- package/dist/types/utils/createCompiler.d.ts +0 -12
|
@@ -4,27 +4,16 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.safeReplacer = exports.emitResolvedConfig = exports.defineServerConfig = exports.buildServerConfig = void 0;
|
|
7
|
-
|
|
8
7
|
var path = _interopRequireWildcard(require("path"));
|
|
9
|
-
|
|
10
8
|
var _nodeBundleRequire = require("@modern-js/node-bundle-require");
|
|
11
|
-
|
|
12
9
|
var _utils = require("@modern-js/utils");
|
|
13
|
-
|
|
14
10
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
15
|
-
|
|
16
11
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
17
|
-
|
|
18
12
|
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; }
|
|
19
|
-
|
|
20
13
|
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; }
|
|
21
|
-
|
|
22
14
|
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; }
|
|
23
|
-
|
|
24
15
|
const defineServerConfig = config => config;
|
|
25
|
-
|
|
26
16
|
exports.defineServerConfig = defineServerConfig;
|
|
27
|
-
|
|
28
17
|
const buildServerConfig = async ({
|
|
29
18
|
appDirectory,
|
|
30
19
|
distDirectory,
|
|
@@ -32,9 +21,7 @@ const buildServerConfig = async ({
|
|
|
32
21
|
options
|
|
33
22
|
}) => {
|
|
34
23
|
const configFilePath = await (0, _utils.getServerConfig)(appDirectory, configFile);
|
|
35
|
-
|
|
36
24
|
const getOutputFile = async filepath => path.resolve(distDirectory, `${filepath.replace(new RegExp(_utils.CONFIG_FILE_EXTENSIONS.join('|')), '')}.js`);
|
|
37
|
-
|
|
38
25
|
if (configFilePath) {
|
|
39
26
|
const configHelperFilePath = path.normalize(path.join(distDirectory, './config-helper.js'));
|
|
40
27
|
const helperCode = `
|
|
@@ -46,7 +33,6 @@ const buildServerConfig = async ({
|
|
|
46
33
|
getOutputFile,
|
|
47
34
|
esbuildPlugins: [{
|
|
48
35
|
name: 'native-build-config',
|
|
49
|
-
|
|
50
36
|
setup(ctx) {
|
|
51
37
|
ctx.onResolve({
|
|
52
38
|
filter: /app-tools\/server/
|
|
@@ -56,48 +42,38 @@ const buildServerConfig = async ({
|
|
|
56
42
|
};
|
|
57
43
|
});
|
|
58
44
|
}
|
|
59
|
-
|
|
60
45
|
}]
|
|
61
46
|
}));
|
|
62
47
|
}
|
|
63
48
|
};
|
|
49
|
+
|
|
64
50
|
/**
|
|
65
51
|
*
|
|
66
52
|
* 处理循环引用的 replacer
|
|
67
53
|
*/
|
|
68
|
-
|
|
69
|
-
|
|
70
54
|
exports.buildServerConfig = buildServerConfig;
|
|
71
|
-
|
|
72
55
|
const safeReplacer = () => {
|
|
73
56
|
const cache = [];
|
|
74
57
|
const keyCache = [];
|
|
75
58
|
return function (key, value) {
|
|
76
59
|
if (typeof value === 'object' && value !== null) {
|
|
77
60
|
const index = cache.indexOf(value);
|
|
78
|
-
|
|
79
61
|
if (index !== -1) {
|
|
80
62
|
return `[Circular ${keyCache[index]}]`;
|
|
81
63
|
}
|
|
82
|
-
|
|
83
64
|
cache.push(value);
|
|
84
65
|
keyCache.push(key || 'root');
|
|
85
66
|
}
|
|
86
|
-
|
|
87
67
|
return value;
|
|
88
68
|
};
|
|
89
69
|
};
|
|
90
|
-
|
|
91
70
|
exports.safeReplacer = safeReplacer;
|
|
92
|
-
|
|
93
71
|
const emitResolvedConfig = async (appDirectory, resolvedConfig) => {
|
|
94
72
|
var _resolvedConfig$outpu;
|
|
95
|
-
|
|
96
|
-
const outputPath = path.join(appDirectory, (resolvedConfig === null || resolvedConfig === void 0 ? void 0 : (_resolvedConfig$outpu = resolvedConfig.output) === null || _resolvedConfig$outpu === void 0 ? void 0 : _resolvedConfig$outpu.path) || './dist', _utils.OUTPUT_CONFIG_FILE);
|
|
73
|
+
const outputPath = path.join(appDirectory, ((_resolvedConfig$outpu = resolvedConfig.output.distPath) === null || _resolvedConfig$outpu === void 0 ? void 0 : _resolvedConfig$outpu.root) || './dist', _utils.OUTPUT_CONFIG_FILE);
|
|
97
74
|
await _utils.fs.writeJSON(outputPath, resolvedConfig, {
|
|
98
75
|
spaces: 2,
|
|
99
76
|
replacer: safeReplacer()
|
|
100
77
|
});
|
|
101
78
|
};
|
|
102
|
-
|
|
103
79
|
exports.emitResolvedConfig = emitResolvedConfig;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createFileWatcher = void 0;
|
|
7
|
+
var _crypto = _interopRequireDefault(require("crypto"));
|
|
8
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
9
|
+
var _path = _interopRequireDefault(require("path"));
|
|
10
|
+
var _utils = require("@modern-js/utils");
|
|
11
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
+
/**
|
|
13
|
+
* Get user config from package.json.
|
|
14
|
+
* @param appDirectory - App root directory.
|
|
15
|
+
* @returns modernConfig or undefined
|
|
16
|
+
*/
|
|
17
|
+
// FIXME: read package.json again;
|
|
18
|
+
const getPackageConfig = (appDirectory, packageJsonConfig) => {
|
|
19
|
+
const PACKAGE_JSON_CONFIG_NAME = 'modernConfig';
|
|
20
|
+
const json = JSON.parse(_fs.default.readFileSync(_path.default.resolve(appDirectory, './package.json'), 'utf8'));
|
|
21
|
+
return json[packageJsonConfig !== null && packageJsonConfig !== void 0 ? packageJsonConfig : PACKAGE_JSON_CONFIG_NAME];
|
|
22
|
+
};
|
|
23
|
+
const addServerConfigToDeps = async (dependencies, appDirectory, serverConfigFile) => {
|
|
24
|
+
const serverConfig = await (0, _utils.getServerConfig)(appDirectory, serverConfigFile);
|
|
25
|
+
if (serverConfig) {
|
|
26
|
+
dependencies.push(serverConfig);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
const debug = (0, _utils.createDebugger)('watch-files');
|
|
30
|
+
const md5 = data => _crypto.default.createHash('md5').update(data).digest('hex');
|
|
31
|
+
const hashMap = new Map();
|
|
32
|
+
const createFileWatcher = async (appContext, configDir, hooksRunner) => {
|
|
33
|
+
// only add fs watcher on dev mode.
|
|
34
|
+
if ((0, _utils.isDev)() || (0, _utils.isTest)()) {
|
|
35
|
+
const {
|
|
36
|
+
appDirectory,
|
|
37
|
+
configFile
|
|
38
|
+
} = appContext;
|
|
39
|
+
const extraFiles = await hooksRunner.watchFiles();
|
|
40
|
+
const configPath = _path.default.join(appDirectory, configDir);
|
|
41
|
+
const dependencies = getPackageConfig(appContext.appDirectory, appContext.packageName) ? [_path.default.resolve(appDirectory, './package.json')] : [];
|
|
42
|
+
|
|
43
|
+
// 将 server.config 加入到 loaded.dependencies,以便对文件监听做热更新
|
|
44
|
+
await addServerConfigToDeps(dependencies, appContext.appDirectory, appContext.serverConfigFile);
|
|
45
|
+
const watched = [`${configPath}/html`, ...extraFiles, ...dependencies, configFile].filter(Boolean);
|
|
46
|
+
debug(`watched: %o`, watched);
|
|
47
|
+
const watcher = _utils.chokidar.watch(watched, {
|
|
48
|
+
cwd: appDirectory,
|
|
49
|
+
ignoreInitial: true,
|
|
50
|
+
ignorePermissionErrors: true,
|
|
51
|
+
ignored: [/node_modules/, '**/__test__/**', '**/*.test.(js|jsx|ts|tsx)', '**/*.spec.(js|jsx|ts|tsx)', '**/*.stories.(js|jsx|ts|tsx)']
|
|
52
|
+
});
|
|
53
|
+
watcher.on('change', changed => {
|
|
54
|
+
const lastHash = hashMap.get(changed);
|
|
55
|
+
const currentHash = md5(_fs.default.readFileSync(_path.default.join(appDirectory, changed), 'utf8'));
|
|
56
|
+
if (currentHash !== lastHash) {
|
|
57
|
+
debug(`file change: %s`, changed);
|
|
58
|
+
hashMap.set(changed, currentHash);
|
|
59
|
+
hooksRunner.fileChange({
|
|
60
|
+
filename: changed,
|
|
61
|
+
eventType: 'change'
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
watcher.on('add', name => {
|
|
66
|
+
debug(`add file: %s`, name);
|
|
67
|
+
const currentHash = md5(_fs.default.readFileSync(_path.default.join(appDirectory, name), 'utf8'));
|
|
68
|
+
hashMap.set(name, currentHash);
|
|
69
|
+
hooksRunner.fileChange({
|
|
70
|
+
filename: name,
|
|
71
|
+
eventType: 'add'
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
watcher.on('unlink', name => {
|
|
75
|
+
debug(`remove file: %s`, name);
|
|
76
|
+
if (hashMap.has(name)) {
|
|
77
|
+
hashMap.delete(name);
|
|
78
|
+
}
|
|
79
|
+
hooksRunner.fileChange({
|
|
80
|
+
filename: name,
|
|
81
|
+
eventType: 'unlink'
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
watcher.on('error', err => {
|
|
85
|
+
throw err;
|
|
86
|
+
});
|
|
87
|
+
return watcher;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
exports.createFileWatcher = createFileWatcher;
|
|
@@ -4,45 +4,31 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.injectDataLoaderPlugin = exports.getServer = exports.createServer = exports.closeServer = void 0;
|
|
7
|
-
|
|
8
7
|
var _server = require("@modern-js/server");
|
|
9
|
-
|
|
10
8
|
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; }
|
|
11
|
-
|
|
12
9
|
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; }
|
|
13
|
-
|
|
14
10
|
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; }
|
|
15
|
-
|
|
16
11
|
let server = null;
|
|
17
|
-
|
|
18
12
|
const getServer = () => server;
|
|
19
|
-
|
|
20
13
|
exports.getServer = getServer;
|
|
21
|
-
|
|
22
14
|
const closeServer = async () => {
|
|
23
15
|
if (server) {
|
|
24
16
|
await server.close();
|
|
25
17
|
server = null;
|
|
26
18
|
}
|
|
27
19
|
};
|
|
28
|
-
|
|
29
20
|
exports.closeServer = closeServer;
|
|
30
|
-
|
|
31
21
|
const createServer = async options => {
|
|
32
22
|
if (server) {
|
|
33
23
|
await server.close();
|
|
34
24
|
}
|
|
35
|
-
|
|
36
25
|
server = new _server.Server(options);
|
|
37
26
|
const app = await server.init();
|
|
38
27
|
return app;
|
|
39
28
|
};
|
|
40
|
-
|
|
41
29
|
exports.createServer = createServer;
|
|
42
|
-
|
|
43
30
|
const injectDataLoaderPlugin = internalPlugins => {
|
|
44
31
|
const DataLoaderPlugin = require.resolve('@modern-js/plugin-data-loader/server');
|
|
45
|
-
|
|
46
32
|
return _objectSpread(_objectSpread({}, internalPlugins), {}, {
|
|
47
33
|
'@modern-js/plugin-data-loader': {
|
|
48
34
|
path: DataLoaderPlugin,
|
|
@@ -50,5 +36,4 @@ const injectDataLoaderPlugin = internalPlugins => {
|
|
|
50
36
|
}
|
|
51
37
|
});
|
|
52
38
|
};
|
|
53
|
-
|
|
54
39
|
exports.injectDataLoaderPlugin = injectDataLoaderPlugin;
|
|
@@ -4,16 +4,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getSpecifiedEntries = void 0;
|
|
7
|
-
|
|
8
7
|
var _utils = require("@modern-js/utils");
|
|
9
|
-
|
|
10
8
|
const getSpecifiedEntries = async (entry, entrypoints) => {
|
|
11
9
|
const entryNames = entrypoints.map(e => e.entryName);
|
|
12
|
-
|
|
13
10
|
if (!entry) {
|
|
14
11
|
return entryNames;
|
|
15
12
|
}
|
|
16
|
-
|
|
17
13
|
if (typeof entry === 'boolean') {
|
|
18
14
|
const {
|
|
19
15
|
selected
|
|
@@ -22,19 +18,15 @@ const getSpecifiedEntries = async (entry, entrypoints) => {
|
|
|
22
18
|
name: 'selected',
|
|
23
19
|
choices: entryNames,
|
|
24
20
|
message: '请选择需要构建的入口',
|
|
25
|
-
|
|
26
21
|
validate(answer) {
|
|
27
22
|
if (answer.length < 1) {
|
|
28
23
|
return 'You must choose at least one topping.';
|
|
29
24
|
}
|
|
30
|
-
|
|
31
25
|
return true;
|
|
32
26
|
}
|
|
33
|
-
|
|
34
27
|
}]);
|
|
35
28
|
return selected;
|
|
36
29
|
}
|
|
37
|
-
|
|
38
30
|
entry.forEach(name => {
|
|
39
31
|
if (!entryNames.includes(name)) {
|
|
40
32
|
throw new Error(`can not found entry ${name}, compiler entry should in ${entryNames.join(', ')}`);
|
|
@@ -42,5 +34,4 @@ const getSpecifiedEntries = async (entry, entrypoints) => {
|
|
|
42
34
|
});
|
|
43
35
|
return entry;
|
|
44
36
|
};
|
|
45
|
-
|
|
46
37
|
exports.getSpecifiedEntries = getSpecifiedEntries;
|
|
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getLocaleLanguage = getLocaleLanguage;
|
|
7
|
-
|
|
8
7
|
var _languageDetector = require("@modern-js/plugin-i18n/language-detector");
|
|
9
|
-
|
|
10
8
|
function getLocaleLanguage() {
|
|
11
9
|
const detector = new _languageDetector.I18CLILanguageDetector();
|
|
12
10
|
return detector.detect();
|
|
@@ -4,19 +4,16 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.printInstructions = void 0;
|
|
7
|
-
|
|
8
7
|
var _utils = require("@modern-js/utils");
|
|
9
|
-
|
|
10
8
|
const printInstructions = async (hookRunners, appContext, config) => {
|
|
11
|
-
const message = (0, _utils.prettyInstructions)(appContext, config);
|
|
9
|
+
const message = (0, _utils.prettyInstructions)(appContext, config);
|
|
12
10
|
|
|
11
|
+
// call beforePrintInstructions hook.
|
|
13
12
|
const {
|
|
14
13
|
instructions
|
|
15
14
|
} = await hookRunners.beforePrintInstructions({
|
|
16
15
|
instructions: message
|
|
17
16
|
});
|
|
18
|
-
|
|
19
17
|
_utils.logger.info(instructions);
|
|
20
18
|
};
|
|
21
|
-
|
|
22
19
|
exports.printInstructions = printInstructions;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.restart = restart;
|
|
7
|
+
var _core = require("@modern-js/core");
|
|
8
|
+
var _utils = require("@modern-js/utils");
|
|
9
|
+
async function restart(hooksRunner) {
|
|
10
|
+
_utils.logger.info('Restart...\n');
|
|
11
|
+
let hasGetError = false;
|
|
12
|
+
await hooksRunner.beforeRestart();
|
|
13
|
+
try {
|
|
14
|
+
await _core.cli.init(_core.cli.initOptions);
|
|
15
|
+
} catch (err) {
|
|
16
|
+
console.error(err);
|
|
17
|
+
hasGetError = true;
|
|
18
|
+
} finally {
|
|
19
|
+
if (!hasGetError) {
|
|
20
|
+
_utils.program.parse(process.argv);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -4,13 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.generateRoutes = void 0;
|
|
7
|
-
|
|
8
7
|
var _path = _interopRequireDefault(require("path"));
|
|
9
|
-
|
|
10
8
|
var _utils = require("@modern-js/utils");
|
|
11
|
-
|
|
12
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
10
|
const generateRoutes = async appContext => {
|
|
15
11
|
const {
|
|
16
12
|
serverRoutes,
|
|
@@ -21,5 +17,4 @@ const generateRoutes = async appContext => {
|
|
|
21
17
|
}, null, 2);
|
|
22
18
|
await _utils.fs.outputFile(_path.default.join(distDirectory, _utils.ROUTE_SPEC_FILE), output);
|
|
23
19
|
};
|
|
24
|
-
|
|
25
20
|
exports.generateRoutes = generateRoutes;
|