@modern-js/app-tools 2.63.0 → 2.63.1-alpha.0
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/bin/modern.js +1 -1
- package/dist/cjs/commands/build.js +19 -13
- package/dist/cjs/commands/deploy.js +5 -5
- package/dist/cjs/commands/dev.js +11 -11
- package/dist/cjs/commands/index.js +6 -6
- package/dist/cjs/commands/inspect.js +1 -1
- package/dist/cjs/commands/serve.js +4 -4
- package/dist/cjs/{new/compat → compat}/hooks.js +15 -8
- package/dist/cjs/{new/compat → compat}/index.js +4 -1
- package/dist/cjs/{new/compat → compat}/utils.js +10 -1
- package/dist/cjs/index.js +154 -5
- package/dist/cjs/plugins/analyze/getBundleEntry.js +2 -2
- package/dist/cjs/plugins/analyze/getFileSystemEntry.js +9 -9
- package/dist/cjs/plugins/analyze/getHtmlTemplate.js +51 -25
- package/dist/cjs/plugins/analyze/index.js +128 -130
- package/dist/cjs/plugins/deploy/index.js +12 -14
- package/dist/cjs/plugins/initialize/index.js +1 -1
- package/dist/cjs/plugins/serverBuild.js +30 -32
- package/dist/cjs/{new/run.js → run/index.js} +6 -6
- package/dist/cjs/{new → utils}/getConfigFile.js +1 -1
- package/dist/cjs/{new/context.js → utils/initAppContext.js} +3 -4
- package/dist/cjs/{new/utils/index.js → utils/isAutoLoadPlugins.js} +6 -6
- package/dist/cjs/utils/loadPlugins.js +35 -4
- package/dist/cjs/utils/printInstructions.js +2 -2
- package/dist/cjs/utils/restart.js +4 -3
- package/dist/esm/commands/build.js +18 -12
- package/dist/esm/commands/deploy.js +6 -6
- package/dist/esm/commands/dev.js +10 -10
- package/dist/esm/commands/index.js +8 -8
- package/dist/esm/commands/inspect.js +1 -1
- package/dist/esm/commands/serve.js +5 -5
- package/dist/esm/{new/compat → compat}/hooks.js +41 -41
- package/dist/esm/{new/compat → compat}/index.js +4 -1
- package/dist/esm/{new/compat → compat}/utils.js +10 -1
- package/dist/esm/index.js +245 -2
- package/dist/esm/plugins/analyze/getBundleEntry.js +3 -3
- package/dist/esm/plugins/analyze/getFileSystemEntry.js +12 -12
- package/dist/esm/plugins/analyze/getHtmlTemplate.js +101 -28
- package/dist/esm/plugins/analyze/index.js +328 -331
- package/dist/esm/plugins/deploy/index.js +84 -88
- package/dist/esm/plugins/initialize/index.js +1 -1
- package/dist/esm/plugins/serverBuild.js +52 -56
- package/dist/esm/{new/run.js → run/index.js} +6 -6
- package/dist/esm/{new → utils}/getConfigFile.js +1 -1
- package/dist/esm/{new/context.js → utils/initAppContext.js} +0 -1
- package/dist/esm/{new/utils/index.js → utils/isAutoLoadPlugins.js} +6 -6
- package/dist/esm/utils/loadPlugins.js +95 -7
- package/dist/esm/utils/printInstructions.js +3 -3
- package/dist/esm/utils/restart.js +5 -4
- package/dist/esm-node/commands/build.js +19 -13
- package/dist/esm-node/commands/deploy.js +5 -5
- package/dist/esm-node/commands/dev.js +11 -11
- package/dist/esm-node/commands/index.js +6 -6
- package/dist/esm-node/commands/inspect.js +1 -1
- package/dist/esm-node/commands/serve.js +4 -4
- package/dist/esm-node/{new/compat → compat}/hooks.js +15 -8
- package/dist/esm-node/{new/compat → compat}/index.js +4 -1
- package/dist/esm-node/{new/compat → compat}/utils.js +10 -1
- package/dist/esm-node/index.js +140 -2
- package/dist/esm-node/plugins/analyze/getBundleEntry.js +2 -2
- package/dist/esm-node/plugins/analyze/getFileSystemEntry.js +9 -9
- package/dist/esm-node/plugins/analyze/getHtmlTemplate.js +49 -24
- package/dist/esm-node/plugins/analyze/index.js +128 -130
- package/dist/esm-node/plugins/deploy/index.js +12 -14
- package/dist/esm-node/plugins/initialize/index.js +1 -1
- package/dist/esm-node/plugins/serverBuild.js +30 -32
- package/dist/esm-node/{new/run.js → run/index.js} +6 -6
- package/dist/esm-node/{new → utils}/getConfigFile.js +1 -1
- package/dist/esm-node/{new/context.js → utils/initAppContext.js} +0 -1
- package/dist/esm-node/{new/utils/index.js → utils/isAutoLoadPlugins.js} +2 -2
- package/dist/esm-node/utils/loadPlugins.js +34 -4
- package/dist/esm-node/utils/printInstructions.js +2 -2
- package/dist/esm-node/utils/restart.js +4 -3
- package/dist/types/builder/generator/adapterCopy.d.ts +2 -1
- package/dist/types/builder/generator/createBuilderProviderConfig.d.ts +3 -2
- package/dist/types/builder/generator/createCopyPattern.d.ts +4 -3
- package/dist/types/builder/generator/getBuilderEnvironments.d.ts +2 -2
- package/dist/types/builder/index.d.ts +1 -1
- package/dist/types/builder/shared/createCopyInfo.d.ts +3 -2
- package/dist/types/builder/shared/types.d.ts +3 -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/index.d.ts +6 -6
- package/dist/types/commands/inspect.d.ts +2 -2
- package/dist/types/commands/serve.d.ts +2 -2
- package/dist/types/{new/compat → compat}/hooks.d.ts +2 -2
- package/dist/types/compat/index.d.ts +2 -0
- package/dist/types/config/initialize/index.d.ts +3 -2
- package/dist/types/config/initialize/inits.d.ts +4 -3
- package/dist/types/index.d.ts +5 -3
- package/dist/types/plugins/analyze/getBundleEntry.d.ts +3 -3
- package/dist/types/plugins/analyze/getFileSystemEntry.d.ts +3 -3
- package/dist/types/plugins/analyze/getHtmlTemplate.d.ts +26 -5
- package/dist/types/plugins/analyze/getServerRoutes.d.ts +2 -2
- package/dist/types/plugins/analyze/index.d.ts +2 -3
- package/dist/types/plugins/deploy/index.d.ts +2 -3
- package/dist/types/plugins/deploy/platforms/platform.d.ts +3 -3
- package/dist/types/plugins/deploy/utils.d.ts +2 -2
- package/dist/types/plugins/serverBuild.d.ts +2 -2
- package/dist/types/types/index.d.ts +2 -0
- package/dist/types/types/new.d.ts +46 -34
- package/dist/types/utils/generateWatchFiles.d.ts +2 -2
- package/dist/types/{new/context.d.ts → utils/initAppContext.d.ts} +0 -1
- package/dist/types/utils/isAutoLoadPlugins.d.ts +1 -0
- package/dist/types/utils/loadPlugins.d.ts +13 -3
- package/dist/types/utils/printInstructions.d.ts +3 -3
- package/dist/types/utils/restart.d.ts +2 -3
- package/dist/types/utils/routes.d.ts +2 -1
- package/package.json +14 -15
- package/dist/cjs/hooks.js +0 -60
- package/dist/cjs/new/index.js +0 -79
- package/dist/cjs/new/loadPlugins.js +0 -57
- package/dist/cjs/old.js +0 -179
- package/dist/esm/hooks.js +0 -36
- package/dist/esm/new/index.js +0 -55
- package/dist/esm/new/loadPlugins.js +0 -94
- package/dist/esm/old.js +0 -258
- package/dist/esm-node/hooks.js +0 -36
- package/dist/esm-node/new/index.js +0 -52
- package/dist/esm-node/new/loadPlugins.js +0 -33
- package/dist/esm-node/old.js +0 -140
- package/dist/types/hooks.d.ts +0 -2
- package/dist/types/new/compat/index.d.ts +0 -2
- package/dist/types/new/index.d.ts +0 -6
- package/dist/types/new/loadPlugins.d.ts +0 -9
- package/dist/types/new/utils/index.d.ts +0 -1
- package/dist/types/old.d.ts +0 -13
- /package/dist/cjs/{new/constants.js → constants.js} +0 -0
- /package/dist/esm/{new/constants.js → constants.js} +0 -0
- /package/dist/esm-node/{new/constants.js → constants.js} +0 -0
- /package/dist/types/{new/compat → compat}/utils.d.ts +0 -0
- /package/dist/types/{new/constants.d.ts → constants.d.ts} +0 -0
- /package/dist/types/{new/run.d.ts → run/index.d.ts} +0 -0
- /package/dist/types/{new → utils}/getConfigFile.d.ts +0 -0
package/bin/modern.js
CHANGED
|
@@ -10,7 +10,7 @@ if (!process.env.MODERN_JS_VERSION) {
|
|
|
10
10
|
process.env.MODERN_JS_VERSION = version;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
require('../dist/cjs/
|
|
13
|
+
require('../dist/cjs/run/index.js').run({
|
|
14
14
|
internalPlugins: {
|
|
15
15
|
cli: INTERNAL_APP_TOOLS_PLUGINS,
|
|
16
16
|
autoLoad: INTERNAL_APP_TOOLS_RUNTIME_PLUGINS,
|
|
@@ -31,7 +31,6 @@ __export(build_exports, {
|
|
|
31
31
|
build: () => build
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(build_exports);
|
|
34
|
-
var import_core = require("@modern-js/core");
|
|
35
34
|
var import_utils = require("@modern-js/utils");
|
|
36
35
|
var import_config = require("../utils/config");
|
|
37
36
|
var import_loadPlugins = require("../utils/loadPlugins");
|
|
@@ -42,9 +41,9 @@ const build = async (api, options) => {
|
|
|
42
41
|
if (options === null || options === void 0 ? void 0 : options.analyze) {
|
|
43
42
|
process.env.BUNDLE_ANALYZE = "true";
|
|
44
43
|
}
|
|
45
|
-
|
|
46
|
-
const appContext = api.
|
|
47
|
-
const
|
|
44
|
+
const resolvedConfig = api.getNormalizedConfig();
|
|
45
|
+
const appContext = api.getAppContext();
|
|
46
|
+
const hooks = api.getHooks();
|
|
48
47
|
await (0, import_loadPlugins.loadServerPlugins)(api, appContext.appDirectory, appContext.metaName);
|
|
49
48
|
if (appContext.moduleType && appContext.moduleType === "module") {
|
|
50
49
|
var _resolvedConfig_source1;
|
|
@@ -59,9 +58,12 @@ const build = async (api, options) => {
|
|
|
59
58
|
const { apiOnly } = appContext;
|
|
60
59
|
if (apiOnly) {
|
|
61
60
|
const { appDirectory: appDirectory2, distDirectory: distDirectory2, serverConfigFile: serverConfigFile2 } = appContext;
|
|
62
|
-
await
|
|
61
|
+
await hooks.onBeforeBuild.call({
|
|
62
|
+
environments: {},
|
|
63
63
|
// "null" bundlerConfigs
|
|
64
|
-
bundlerConfigs: void 0
|
|
64
|
+
bundlerConfigs: void 0,
|
|
65
|
+
isFirstCompile: false,
|
|
66
|
+
isWatch: false
|
|
65
67
|
});
|
|
66
68
|
await (0, import_config.buildServerConfig)({
|
|
67
69
|
appDirectory: appDirectory2,
|
|
@@ -69,17 +71,21 @@ const build = async (api, options) => {
|
|
|
69
71
|
configFile: serverConfigFile2
|
|
70
72
|
});
|
|
71
73
|
await (0, import_routes.generateRoutes)(appContext);
|
|
72
|
-
await
|
|
74
|
+
await hooks.onAfterBuild.call({
|
|
75
|
+
environments: {},
|
|
73
76
|
// "null" stats
|
|
74
|
-
stats: void 0
|
|
77
|
+
stats: void 0,
|
|
78
|
+
isFirstCompile: false,
|
|
79
|
+
isWatch: false
|
|
75
80
|
});
|
|
76
81
|
return;
|
|
77
82
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
+
api.modifyResolvedConfig((config) => {
|
|
84
|
+
return {
|
|
85
|
+
...config,
|
|
86
|
+
cliOptions: options
|
|
87
|
+
};
|
|
88
|
+
});
|
|
83
89
|
const { distDirectory, appDirectory, serverConfigFile } = appContext;
|
|
84
90
|
await (0, import_config.buildServerConfig)({
|
|
85
91
|
appDirectory,
|
|
@@ -23,12 +23,12 @@ __export(deploy_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(deploy_exports);
|
|
24
24
|
var import_loadPlugins = require("../utils/loadPlugins");
|
|
25
25
|
const deploy = async (api, options) => {
|
|
26
|
-
const
|
|
27
|
-
const { metaName } = api.
|
|
26
|
+
const hooks = api.getHooks();
|
|
27
|
+
const { metaName } = api.getAppContext();
|
|
28
28
|
await (0, import_loadPlugins.getServerPlugins)(api, metaName);
|
|
29
|
-
await
|
|
30
|
-
await
|
|
31
|
-
await
|
|
29
|
+
await hooks.onBeforeDeploy.call(options);
|
|
30
|
+
await hooks.deploy.call();
|
|
31
|
+
await hooks.onAfterDeploy.call(options);
|
|
32
32
|
};
|
|
33
33
|
// Annotate the CommonJS export names for ESM import in node:
|
|
34
34
|
0 && (module.exports = {
|
package/dist/cjs/commands/dev.js
CHANGED
|
@@ -32,7 +32,6 @@ __export(dev_exports, {
|
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(dev_exports);
|
|
34
34
|
var import_node_path = __toESM(require("node:path"));
|
|
35
|
-
var import_core = require("@modern-js/core");
|
|
36
35
|
var import_prod_server = require("@modern-js/prod-server");
|
|
37
36
|
var import_server = require("@modern-js/server");
|
|
38
37
|
var import_utils = require("@modern-js/utils");
|
|
@@ -47,9 +46,9 @@ const dev = async (api, options, devServerOptions) => {
|
|
|
47
46
|
if (options.analyze) {
|
|
48
47
|
process.env.BUNDLE_ANALYZE = "true";
|
|
49
48
|
}
|
|
50
|
-
|
|
51
|
-
const appContext = api.
|
|
52
|
-
const
|
|
49
|
+
const normalizedConfig = api.getNormalizedConfig();
|
|
50
|
+
const appContext = api.getAppContext();
|
|
51
|
+
const hooks = api.getHooks();
|
|
53
52
|
if (appContext.moduleType && appContext.moduleType === "module") {
|
|
54
53
|
var _normalizedConfig_source1;
|
|
55
54
|
const { registerEsm } = await import("../esm/register-esm.mjs");
|
|
@@ -60,11 +59,12 @@ const dev = async (api, options, devServerOptions) => {
|
|
|
60
59
|
});
|
|
61
60
|
}
|
|
62
61
|
await (0, import_register.registerCompiler)(appContext.appDirectory, appContext.distDirectory, normalizedConfig === null || normalizedConfig === void 0 ? void 0 : (_normalizedConfig_source = normalizedConfig.source) === null || _normalizedConfig_source === void 0 ? void 0 : _normalizedConfig_source.alias);
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
62
|
+
api.modifyResolvedConfig((config) => {
|
|
63
|
+
return {
|
|
64
|
+
...config,
|
|
65
|
+
cliOptions: options
|
|
66
|
+
};
|
|
67
|
+
});
|
|
68
68
|
const { appDirectory, distDirectory, port, apiOnly, serverConfigFile, metaName, serverRoutes } = appContext;
|
|
69
69
|
await (0, import_config.buildServerConfig)({
|
|
70
70
|
appDirectory,
|
|
@@ -74,7 +74,7 @@ const dev = async (api, options, devServerOptions) => {
|
|
|
74
74
|
});
|
|
75
75
|
const meta = (0, import_utils.getMeta)(metaName);
|
|
76
76
|
const serverConfigPath = import_node_path.default.resolve(appDirectory, import_utils.SERVER_DIR, `${meta}.server`);
|
|
77
|
-
await
|
|
77
|
+
await hooks.onBeforeDev.call();
|
|
78
78
|
if (!appContext.builder && !apiOnly) {
|
|
79
79
|
throw new Error("Expect the Builder to have been initialized, But the appContext.builder received `undefined`");
|
|
80
80
|
}
|
|
@@ -113,7 +113,7 @@ const dev = async (api, options, devServerOptions) => {
|
|
|
113
113
|
port,
|
|
114
114
|
host
|
|
115
115
|
}, () => {
|
|
116
|
-
(0, import_printInstructions.printInstructions)(
|
|
116
|
+
(0, import_printInstructions.printInstructions)(hooks, appContext, normalizedConfig);
|
|
117
117
|
});
|
|
118
118
|
} else {
|
|
119
119
|
const { server, afterListen } = await (0, import_server.createDevServer)({
|
|
@@ -41,8 +41,8 @@ var import_uni_builder = require("@modern-js/uni-builder");
|
|
|
41
41
|
var import_utils = require("@modern-js/utils");
|
|
42
42
|
var import_locale = require("../locale");
|
|
43
43
|
const devCommand = async (program, api) => {
|
|
44
|
-
const
|
|
45
|
-
const devToolMetas = await
|
|
44
|
+
const hooks = api.getHooks();
|
|
45
|
+
const devToolMetas = await hooks.registerDev.call();
|
|
46
46
|
const devProgram = program.command("dev").alias("start").usage("[options]").description(import_locale.i18n.t(import_locale.localeKeys.command.dev.describe)).option("-c --config <config>", import_locale.i18n.t(import_locale.localeKeys.command.shared.config)).option("-e --entry [entry...]", import_locale.i18n.t(import_locale.localeKeys.command.dev.entry)).option("--analyze", import_locale.i18n.t(import_locale.localeKeys.command.shared.analyze)).option("--api-only", import_locale.i18n.t(import_locale.localeKeys.command.dev.apiOnly)).option("--web-only", import_locale.i18n.t(import_locale.localeKeys.command.dev.webOnly)).action(async (options) => {
|
|
47
47
|
const { dev } = await import("./dev.js");
|
|
48
48
|
await dev(api, options);
|
|
@@ -53,7 +53,7 @@ const devCommand = async (program, api) => {
|
|
|
53
53
|
}
|
|
54
54
|
for (const subCmd of meta.subCommands) {
|
|
55
55
|
devProgram.command(subCmd).action(async (options = {}) => {
|
|
56
|
-
const { appDirectory } = api.
|
|
56
|
+
const { appDirectory } = api.getAppContext();
|
|
57
57
|
const { isTypescript } = await import("@modern-js/utils");
|
|
58
58
|
await meta.action(options, {
|
|
59
59
|
isTsProject: isTypescript(appDirectory)
|
|
@@ -63,8 +63,8 @@ const devCommand = async (program, api) => {
|
|
|
63
63
|
}
|
|
64
64
|
};
|
|
65
65
|
const buildCommand = async (program, api) => {
|
|
66
|
-
const
|
|
67
|
-
const platformBuilders = await
|
|
66
|
+
const hooks = api.getHooks();
|
|
67
|
+
const platformBuilders = await hooks.registerBuildPlatform.call();
|
|
68
68
|
const buildProgram = program.command("build").usage("[options]").description(import_locale.i18n.t(import_locale.localeKeys.command.build.describe)).option("-c --config <config>", import_locale.i18n.t(import_locale.localeKeys.command.shared.config)).option("--analyze", import_locale.i18n.t(import_locale.localeKeys.command.shared.analyze)).action(async (options) => {
|
|
69
69
|
const { build } = await import("./build.js");
|
|
70
70
|
await build(api, options);
|
|
@@ -73,7 +73,7 @@ const buildCommand = async (program, api) => {
|
|
|
73
73
|
const platforms = (0, import_uni_builder.castArray)(platformBuilder.platform);
|
|
74
74
|
for (const platform of platforms) {
|
|
75
75
|
buildProgram.command(platform).action(async () => {
|
|
76
|
-
const { appDirectory } = api.
|
|
76
|
+
const { appDirectory } = api.getAppContext();
|
|
77
77
|
const { isTypescript } = await import("@modern-js/utils");
|
|
78
78
|
await platformBuilder.build(platform, {
|
|
79
79
|
isTsProject: isTypescript(appDirectory)
|
|
@@ -22,7 +22,7 @@ __export(inspect_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(inspect_exports);
|
|
24
24
|
const inspect = async (api, options) => {
|
|
25
|
-
const appContext = api.
|
|
25
|
+
const appContext = api.getAppContext();
|
|
26
26
|
if (!appContext.builder) {
|
|
27
27
|
throw new Error("Expect the Builder to have been initialized, But the appContext.builder received `undefined`");
|
|
28
28
|
}
|
|
@@ -38,9 +38,9 @@ var import_loadPlugins = require("../utils/loadPlugins");
|
|
|
38
38
|
var import_printInstructions = require("../utils/printInstructions");
|
|
39
39
|
const start = async (api) => {
|
|
40
40
|
var _userConfig_source, _userConfig_output_distPath;
|
|
41
|
-
const appContext = api.
|
|
42
|
-
const userConfig = api.
|
|
43
|
-
const
|
|
41
|
+
const appContext = api.getAppContext();
|
|
42
|
+
const userConfig = api.getNormalizedConfig();
|
|
43
|
+
const hooks = api.getHooks();
|
|
44
44
|
const { distDirectory, appDirectory, internalDirectory, port, metaName, serverRoutes, serverConfigFile } = appContext;
|
|
45
45
|
import_utils.logger.info(`Starting production server...`);
|
|
46
46
|
const apiOnly = await (0, import_utils.isApiOnly)(appContext.appDirectory, userConfig === null || userConfig === void 0 ? void 0 : (_userConfig_source = userConfig.source) === null || _userConfig_source === void 0 ? void 0 : _userConfig_source.entriesDir, appContext.apiDirectory);
|
|
@@ -77,7 +77,7 @@ const start = async (api) => {
|
|
|
77
77
|
runMode
|
|
78
78
|
});
|
|
79
79
|
app.listen(port, async () => {
|
|
80
|
-
await (0, import_printInstructions.printInstructions)(
|
|
80
|
+
await (0, import_printInstructions.printInstructions)(hooks, appContext, userConfig);
|
|
81
81
|
});
|
|
82
82
|
};
|
|
83
83
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -22,6 +22,7 @@ __export(hooks_exports, {
|
|
|
22
22
|
handleSetupResult: () => handleSetupResult
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(hooks_exports);
|
|
25
|
+
var import_getHtmlTemplate = require("../plugins/analyze/getHtmlTemplate");
|
|
25
26
|
var import_utils = require("./utils");
|
|
26
27
|
function getHookRunners(context) {
|
|
27
28
|
const { hooks } = context;
|
|
@@ -80,7 +81,13 @@ function getHookRunners(context) {
|
|
|
80
81
|
return hooks.modifyResolvedConfig.call(params);
|
|
81
82
|
},
|
|
82
83
|
htmlPartials: async (params) => {
|
|
83
|
-
|
|
84
|
+
await hooks.modifyHtmlPartials.call({
|
|
85
|
+
entrypoint: params.entrypoint,
|
|
86
|
+
partials: (0, import_getHtmlTemplate.getModifyHtmlPartials)(params.partials)
|
|
87
|
+
});
|
|
88
|
+
return {
|
|
89
|
+
partials: params.partials
|
|
90
|
+
};
|
|
84
91
|
},
|
|
85
92
|
commands: async (params) => {
|
|
86
93
|
return hooks.addCommand.call(params);
|
|
@@ -91,7 +98,7 @@ function getHookRunners(context) {
|
|
|
91
98
|
prepare: async () => {
|
|
92
99
|
return hooks.onPrepare.call();
|
|
93
100
|
},
|
|
94
|
-
|
|
101
|
+
fileChange: async (params) => {
|
|
95
102
|
return hooks.onFileChanged.call(params);
|
|
96
103
|
},
|
|
97
104
|
beforeCreateCompiler: async (params) => {
|
|
@@ -127,20 +134,20 @@ function getHookRunners(context) {
|
|
|
127
134
|
/**
|
|
128
135
|
* @deprecated
|
|
129
136
|
*/
|
|
130
|
-
registerDev: async (
|
|
131
|
-
return hooks.registerDev.call(
|
|
137
|
+
registerDev: async () => {
|
|
138
|
+
return hooks.registerDev.call();
|
|
132
139
|
},
|
|
133
140
|
/**
|
|
134
141
|
* @deprecated
|
|
135
142
|
*/
|
|
136
|
-
registerBuildPlatform: async (
|
|
137
|
-
return hooks.registerBuildPlatform.call(
|
|
143
|
+
registerBuildPlatform: async () => {
|
|
144
|
+
return hooks.registerBuildPlatform.call();
|
|
138
145
|
},
|
|
139
146
|
/**
|
|
140
147
|
* @deprecated
|
|
141
148
|
*/
|
|
142
|
-
addRuntimeExports: async (
|
|
143
|
-
return hooks.addRuntimeExports.call(
|
|
149
|
+
addRuntimeExports: async () => {
|
|
150
|
+
return hooks.addRuntimeExports.call();
|
|
144
151
|
}
|
|
145
152
|
};
|
|
146
153
|
}
|
|
@@ -51,7 +51,10 @@ const compatPlugin = () => ({
|
|
|
51
51
|
registryHooks: {
|
|
52
52
|
appendEntryCode: (0, import_plugin_v2.createCollectAsyncHook)()
|
|
53
53
|
},
|
|
54
|
-
setup: (
|
|
54
|
+
setup: (api) => {
|
|
55
|
+
api.updateAppContext({
|
|
56
|
+
toolsType: "app-tools"
|
|
57
|
+
});
|
|
55
58
|
}
|
|
56
59
|
});
|
|
57
60
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -41,7 +41,7 @@ function transformHookRunner(hookRunnerName) {
|
|
|
41
41
|
return "addCommand";
|
|
42
42
|
case "watchFiles":
|
|
43
43
|
return "addWatchFiles";
|
|
44
|
-
case "
|
|
44
|
+
case "fileChange":
|
|
45
45
|
return "onFileChanged";
|
|
46
46
|
case "beforeCreateCompiler":
|
|
47
47
|
return "onBeforeCreateCompiler";
|
|
@@ -75,6 +75,15 @@ function transformHookParams(hookRunnerName, params) {
|
|
|
75
75
|
return {
|
|
76
76
|
resolved: params
|
|
77
77
|
};
|
|
78
|
+
case "htmlPartials":
|
|
79
|
+
return {
|
|
80
|
+
partials: {
|
|
81
|
+
top: params.partials.top.current,
|
|
82
|
+
head: params.partials.head.current,
|
|
83
|
+
body: params.partials.body.current
|
|
84
|
+
},
|
|
85
|
+
entrypoint: params.entrypoint
|
|
86
|
+
};
|
|
78
87
|
default:
|
|
79
88
|
return params;
|
|
80
89
|
}
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -16,25 +18,171 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
18
20
|
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
19
29
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
30
|
var src_exports = {};
|
|
21
31
|
__export(src_exports, {
|
|
22
|
-
appTools: () =>
|
|
32
|
+
appTools: () => appTools,
|
|
23
33
|
default: () => src_default,
|
|
24
34
|
defineConfig: () => import_defineConfig.defineConfig,
|
|
25
35
|
defineLegacyConfig: () => import_defineConfig.defineLegacyConfig,
|
|
26
36
|
dev: () => import_dev.dev,
|
|
27
|
-
initAppContext: () =>
|
|
37
|
+
initAppContext: () => import_initAppContext.initAppContext,
|
|
28
38
|
mergeConfig: () => import_core.mergeConfig
|
|
29
39
|
});
|
|
30
40
|
module.exports = __toCommonJS(src_exports);
|
|
31
|
-
var
|
|
32
|
-
var
|
|
41
|
+
var import_language_detector = require("@modern-js/plugin-i18n/language-detector");
|
|
42
|
+
var import_plugin_v2 = require("@modern-js/plugin-v2");
|
|
43
|
+
var import_uni_builder = require("@modern-js/uni-builder");
|
|
44
|
+
var import_utils = require("@modern-js/utils");
|
|
45
|
+
var import_commands = require("./commands");
|
|
46
|
+
var import_compat = require("./compat");
|
|
47
|
+
var import_constants = require("./constants");
|
|
48
|
+
var import_locale = require("./locale");
|
|
49
|
+
var import_analyze = __toESM(require("./plugins/analyze"));
|
|
50
|
+
var import_deploy = __toESM(require("./plugins/deploy"));
|
|
51
|
+
var import_initialize = __toESM(require("./plugins/initialize"));
|
|
52
|
+
var import_serverBuild = __toESM(require("./plugins/serverBuild"));
|
|
53
|
+
var import_generateWatchFiles = require("./utils/generateWatchFiles");
|
|
54
|
+
var import_initAppContext = require("./utils/initAppContext");
|
|
55
|
+
var import_restart = require("./utils/restart");
|
|
56
|
+
__reExport(src_exports, require("./defineConfig"), module.exports);
|
|
33
57
|
var import_defineConfig = require("./defineConfig");
|
|
34
58
|
var import_core = require("@modern-js/core");
|
|
35
59
|
var import_dev = require("./commands/dev");
|
|
36
60
|
__reExport(src_exports, require("./types"), module.exports);
|
|
37
|
-
|
|
61
|
+
const appTools = (options = {
|
|
62
|
+
// default webpack to be compatible with original projects
|
|
63
|
+
bundler: "webpack"
|
|
64
|
+
}) => ({
|
|
65
|
+
name: "@modern-js/app-tools",
|
|
66
|
+
usePlugins: [
|
|
67
|
+
(0, import_compat.compatPlugin)(),
|
|
68
|
+
(0, import_initialize.default)({
|
|
69
|
+
bundler: (options === null || options === void 0 ? void 0 : options.bundler) && [
|
|
70
|
+
"rspack",
|
|
71
|
+
"experimental-rspack"
|
|
72
|
+
].includes(options.bundler) ? "rspack" : "webpack"
|
|
73
|
+
}),
|
|
74
|
+
(0, import_analyze.default)({
|
|
75
|
+
bundler: (options === null || options === void 0 ? void 0 : options.bundler) && [
|
|
76
|
+
"rspack",
|
|
77
|
+
"experimental-rspack"
|
|
78
|
+
].includes(options.bundler) ? "rspack" : "webpack"
|
|
79
|
+
}),
|
|
80
|
+
(0, import_serverBuild.default)(),
|
|
81
|
+
(0, import_deploy.default)()
|
|
82
|
+
],
|
|
83
|
+
post: [
|
|
84
|
+
"@modern-js/plugin-initialize",
|
|
85
|
+
"@modern-js/plugin-analyze",
|
|
86
|
+
"@modern-js/plugin-ssr",
|
|
87
|
+
"@modern-js/plugin-document",
|
|
88
|
+
"@modern-js/plugin-state",
|
|
89
|
+
"@modern-js/plugin-router",
|
|
90
|
+
"@modern-js/plugin-router-v5",
|
|
91
|
+
"@modern-js/plugin-polyfill"
|
|
92
|
+
],
|
|
93
|
+
registryHooks: {
|
|
94
|
+
onBeforeConfig: (0, import_plugin_v2.createAsyncHook)(),
|
|
95
|
+
onAfterPrepare: (0, import_plugin_v2.createAsyncHook)(),
|
|
96
|
+
deploy: (0, import_plugin_v2.createAsyncHook)(),
|
|
97
|
+
_internalRuntimePlugins: (0, import_plugin_v2.createAsyncHook)(),
|
|
98
|
+
_internalServerPlugins: (0, import_plugin_v2.createAsyncHook)(),
|
|
99
|
+
checkEntryPoint: (0, import_plugin_v2.createAsyncHook)(),
|
|
100
|
+
modifyEntrypoints: (0, import_plugin_v2.createAsyncHook)(),
|
|
101
|
+
modifyFileSystemRoutes: (0, import_plugin_v2.createAsyncHook)(),
|
|
102
|
+
modifyServerRoutes: (0, import_plugin_v2.createAsyncHook)(),
|
|
103
|
+
generateEntryCode: (0, import_plugin_v2.createAsyncHook)(),
|
|
104
|
+
onBeforeGenerateRoutes: (0, import_plugin_v2.createAsyncHook)(),
|
|
105
|
+
onBeforePrintInstructions: (0, import_plugin_v2.createAsyncHook)(),
|
|
106
|
+
registerDev: (0, import_plugin_v2.createCollectAsyncHook)(),
|
|
107
|
+
registerBuildPlatform: (0, import_plugin_v2.createCollectAsyncHook)(),
|
|
108
|
+
addRuntimeExports: (0, import_plugin_v2.createAsyncHook)()
|
|
109
|
+
},
|
|
110
|
+
setup: (api) => {
|
|
111
|
+
var _userConfig_output;
|
|
112
|
+
const context = api.getAppContext();
|
|
113
|
+
const userConfig = api.getConfig();
|
|
114
|
+
const locale = (0, import_language_detector.getLocaleLanguage)();
|
|
115
|
+
import_locale.i18n.changeLanguage({
|
|
116
|
+
locale
|
|
117
|
+
});
|
|
118
|
+
api.updateAppContext((0, import_initAppContext.initAppContext)({
|
|
119
|
+
appDirectory: context.appDirectory,
|
|
120
|
+
options: {},
|
|
121
|
+
serverConfigFile: import_constants.DEFAULT_SERVER_CONFIG_FILE,
|
|
122
|
+
runtimeConfigFile: import_constants.DEFAULT_RUNTIME_CONFIG_FILE,
|
|
123
|
+
tempDir: (_userConfig_output = userConfig.output) === null || _userConfig_output === void 0 ? void 0 : _userConfig_output.tempDir
|
|
124
|
+
}));
|
|
125
|
+
api.addCommand(async ({ program }) => {
|
|
126
|
+
await (0, import_commands.devCommand)(program, api);
|
|
127
|
+
await (0, import_commands.buildCommand)(program, api);
|
|
128
|
+
(0, import_commands.serverCommand)(program, api);
|
|
129
|
+
(0, import_commands.deployCommand)(program, api);
|
|
130
|
+
(0, import_commands.newCommand)(program, locale);
|
|
131
|
+
(0, import_commands.inspectCommand)(program, api);
|
|
132
|
+
(0, import_commands.upgradeCommand)(program);
|
|
133
|
+
(0, import_utils.deprecatedCommands)(program);
|
|
134
|
+
});
|
|
135
|
+
api.onPrepare(async () => {
|
|
136
|
+
const command = (0, import_utils.getCommand)();
|
|
137
|
+
if (command === "deploy") {
|
|
138
|
+
const isSkipBuild = [
|
|
139
|
+
"-s",
|
|
140
|
+
"--skip-build"
|
|
141
|
+
].some((tag) => {
|
|
142
|
+
return (0, import_utils.getArgv)().includes(tag);
|
|
143
|
+
});
|
|
144
|
+
if (isSkipBuild) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (command === "dev" || command === "start" || command === "build" || command === "deploy") {
|
|
149
|
+
const resolvedConfig = api.getNormalizedConfig();
|
|
150
|
+
if (resolvedConfig.output.cleanDistPath) {
|
|
151
|
+
const appContext = api.getAppContext();
|
|
152
|
+
await (0, import_utils.emptyDir)(appContext.distDirectory);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
api.addWatchFiles(async () => {
|
|
157
|
+
const appContext = api.getAppContext();
|
|
158
|
+
const config = api.getNormalizedConfig();
|
|
159
|
+
const files = await (0, import_generateWatchFiles.generateWatchFiles)(appContext, config.source.configDir);
|
|
160
|
+
const watchFiles = (0, import_uni_builder.castArray)(config.dev.watchFiles);
|
|
161
|
+
watchFiles.forEach(({ type, paths }) => {
|
|
162
|
+
if (type === "reload-server") {
|
|
163
|
+
files.push(...Array.isArray(paths) ? paths : [
|
|
164
|
+
paths
|
|
165
|
+
]);
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
return files;
|
|
169
|
+
});
|
|
170
|
+
api.onFileChanged(async (e) => {
|
|
171
|
+
const { filename, eventType, isPrivate } = e;
|
|
172
|
+
if (!isPrivate && (eventType === "change" || eventType === "unlink")) {
|
|
173
|
+
const { closeServer } = await import("./utils/createServer.js");
|
|
174
|
+
await closeServer();
|
|
175
|
+
await (0, import_restart.restart)(api.getHooks(), filename);
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
api.onBeforeRestart(() => {
|
|
179
|
+
(0, import_utils.cleanRequireCache)([
|
|
180
|
+
require.resolve("./plugins/analyze")
|
|
181
|
+
]);
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
var src_default = appTools;
|
|
38
186
|
// Annotate the CommonJS export names for ESM import in node:
|
|
39
187
|
0 && (module.exports = {
|
|
40
188
|
appTools,
|
|
@@ -43,5 +191,6 @@ var src_default = import_new.appTools;
|
|
|
43
191
|
dev,
|
|
44
192
|
initAppContext,
|
|
45
193
|
mergeConfig,
|
|
194
|
+
...require("./defineConfig"),
|
|
46
195
|
...require("./types")
|
|
47
196
|
});
|
|
@@ -55,10 +55,10 @@ const ifAlreadyExists = (entrypoints, checked) => entrypoints.some((entrypoint)
|
|
|
55
55
|
}
|
|
56
56
|
return false;
|
|
57
57
|
});
|
|
58
|
-
const getBundleEntry = async (
|
|
58
|
+
const getBundleEntry = async (hooks, appContext, config) => {
|
|
59
59
|
const { appDirectory, packageName } = appContext;
|
|
60
60
|
const { disableDefaultEntries, entries, entriesDir, mainEntryName } = config.source;
|
|
61
|
-
const defaults = disableDefaultEntries ? [] : await (0, import_getFileSystemEntry.getFileSystemEntry)(
|
|
61
|
+
const defaults = disableDefaultEntries ? [] : await (0, import_getFileSystemEntry.getFileSystemEntry)(hooks, appContext, config);
|
|
62
62
|
if (entries) {
|
|
63
63
|
Object.keys(entries).forEach((name) => {
|
|
64
64
|
const value = entries[name];
|
|
@@ -39,8 +39,8 @@ var import_isDefaultExportFunction = require("./isDefaultExportFunction");
|
|
|
39
39
|
const hasIndex = (dir) => (0, import_utils.findExists)(import_utils.JS_EXTENSIONS.map((ext) => import_path.default.resolve(dir, `${import_constants.INDEX_FILE_NAME}${ext}`)));
|
|
40
40
|
const hasEntry = (dir) => (0, import_utils.findExists)(import_utils.JS_EXTENSIONS.map((ext) => import_path.default.resolve(dir, `${import_constants.ENTRY_FILE_NAME}${ext}`)));
|
|
41
41
|
const hasServerEntry = (dir) => (0, import_utils.findExists)(import_utils.JS_EXTENSIONS.map((ext) => import_path.default.resolve(dir, `${import_constants.ENTRY_FILE_NAME}.server${ext}`)));
|
|
42
|
-
const isBundleEntry = async (
|
|
43
|
-
const { entry } = await
|
|
42
|
+
const isBundleEntry = async (hooks, dir, enableCustomEntry) => {
|
|
43
|
+
const { entry } = await hooks.checkEntryPoint.call({
|
|
44
44
|
path: dir,
|
|
45
45
|
entry: false
|
|
46
46
|
});
|
|
@@ -53,7 +53,7 @@ const isBundleEntry = async (hookRunners, dir, enableCustomEntry) => {
|
|
|
53
53
|
}
|
|
54
54
|
return hasIndex(dir);
|
|
55
55
|
};
|
|
56
|
-
const scanDir = async (
|
|
56
|
+
const scanDir = async (hooks, dirs, enableCustomEntry) => {
|
|
57
57
|
const entries = await Promise.all(dirs.map(async (dir) => {
|
|
58
58
|
const indexFile = hasIndex(dir);
|
|
59
59
|
const customBootstrap = (0, import_isDefaultExportFunction.isDefaultExportFunction)(indexFile) ? indexFile : false;
|
|
@@ -70,7 +70,7 @@ const scanDir = async (hookRunners, dirs, enableCustomEntry) => {
|
|
|
70
70
|
customBootstrap
|
|
71
71
|
};
|
|
72
72
|
}
|
|
73
|
-
const entryFile = (await
|
|
73
|
+
const entryFile = (await hooks.checkEntryPoint.call({
|
|
74
74
|
path: dir,
|
|
75
75
|
entry: false
|
|
76
76
|
})).entry;
|
|
@@ -104,7 +104,7 @@ const scanDir = async (hookRunners, dirs, enableCustomEntry) => {
|
|
|
104
104
|
}
|
|
105
105
|
return entries;
|
|
106
106
|
};
|
|
107
|
-
const getFileSystemEntry = async (
|
|
107
|
+
const getFileSystemEntry = async (hooks, appContext, config) => {
|
|
108
108
|
const { appDirectory } = appContext;
|
|
109
109
|
const { source: { entriesDir, disableEntryDirs, enableCustomEntry } } = config;
|
|
110
110
|
let disabledDirs = [];
|
|
@@ -114,19 +114,19 @@ const getFileSystemEntry = async (hookRunners, appContext, config) => {
|
|
|
114
114
|
const src = (0, import_utils.ensureAbsolutePath)(appDirectory, entriesDir || "");
|
|
115
115
|
if (import_fs.default.existsSync(src)) {
|
|
116
116
|
if (import_fs.default.statSync(src).isDirectory()) {
|
|
117
|
-
if (await isBundleEntry(
|
|
118
|
-
return scanDir(
|
|
117
|
+
if (await isBundleEntry(hooks, src, enableCustomEntry)) {
|
|
118
|
+
return scanDir(hooks, [
|
|
119
119
|
src
|
|
120
120
|
], enableCustomEntry);
|
|
121
121
|
}
|
|
122
122
|
const dirs = [];
|
|
123
123
|
await Promise.all(import_fs.default.readdirSync(src).map(async (filename) => {
|
|
124
124
|
const file = import_path.default.join(src, filename);
|
|
125
|
-
if (import_fs.default.statSync(file).isDirectory() && await isBundleEntry(
|
|
125
|
+
if (import_fs.default.statSync(file).isDirectory() && await isBundleEntry(hooks, file, enableCustomEntry) && !disabledDirs.includes(file)) {
|
|
126
126
|
dirs.push(file);
|
|
127
127
|
}
|
|
128
128
|
}));
|
|
129
|
-
return scanDir(
|
|
129
|
+
return scanDir(hooks, dirs, enableCustomEntry);
|
|
130
130
|
} else {
|
|
131
131
|
throw Error(`source.entriesDir accept a directory.`);
|
|
132
132
|
}
|