@modern-js/app-tools 2.63.1-alpha.0 → 2.63.1
Sign up to get free protection for your applications and to get access to all the features.
- package/bin/modern.js +1 -1
- package/dist/cjs/commands/build.js +13 -19
- 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/hooks.js +60 -0
- package/dist/cjs/index.js +5 -154
- package/dist/cjs/{compat → new/compat}/hooks.js +5 -5
- package/dist/cjs/{compat → new/compat}/index.js +1 -4
- package/dist/cjs/{utils/initAppContext.js → new/context.js} +3 -3
- package/dist/cjs/{utils → new}/getConfigFile.js +1 -1
- package/dist/cjs/new/index.js +79 -0
- package/dist/cjs/new/loadPlugins.js +57 -0
- package/dist/cjs/{run/index.js → new/run.js} +6 -6
- package/dist/cjs/{utils/isAutoLoadPlugins.js → new/utils/index.js} +6 -6
- package/dist/cjs/old.js +179 -0
- package/dist/cjs/plugins/serverBuild.js +32 -30
- package/dist/cjs/utils/loadPlugins.js +4 -35
- package/dist/cjs/utils/printInstructions.js +11 -2
- package/dist/cjs/utils/restart.js +2 -2
- package/dist/esm/commands/build.js +12 -18
- package/dist/esm/commands/deploy.js +6 -6
- package/dist/esm/commands/dev.js +11 -11
- package/dist/esm/commands/index.js +8 -8
- package/dist/esm/commands/inspect.js +1 -1
- package/dist/esm/commands/serve.js +6 -6
- package/dist/esm/hooks.js +36 -0
- package/dist/esm/index.js +2 -245
- package/dist/esm/{compat → new/compat}/hooks.js +25 -15
- package/dist/esm/{compat → new/compat}/index.js +1 -4
- package/dist/esm/{utils → new}/getConfigFile.js +1 -1
- package/dist/esm/new/index.js +55 -0
- package/dist/esm/new/loadPlugins.js +94 -0
- package/dist/esm/{run/index.js → new/run.js} +6 -6
- package/dist/esm/{utils/isAutoLoadPlugins.js → new/utils/index.js} +6 -6
- package/dist/esm/old.js +258 -0
- package/dist/esm/plugins/serverBuild.js +56 -52
- package/dist/esm/utils/loadPlugins.js +7 -95
- package/dist/esm/utils/printInstructions.js +28 -1
- package/dist/esm/utils/restart.js +3 -3
- package/dist/esm-node/commands/build.js +13 -19
- package/dist/esm-node/commands/deploy.js +5 -5
- package/dist/esm-node/commands/dev.js +12 -12
- 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 +5 -5
- package/dist/esm-node/hooks.js +36 -0
- package/dist/esm-node/index.js +2 -140
- package/dist/esm-node/{compat → new/compat}/hooks.js +5 -5
- package/dist/esm-node/{compat → new/compat}/index.js +1 -4
- package/dist/esm-node/{utils → new}/getConfigFile.js +1 -1
- package/dist/esm-node/new/index.js +52 -0
- package/dist/esm-node/new/loadPlugins.js +33 -0
- package/dist/esm-node/{run/index.js → new/run.js} +6 -6
- package/dist/esm-node/{utils/isAutoLoadPlugins.js → new/utils/index.js} +2 -2
- package/dist/esm-node/old.js +140 -0
- package/dist/esm-node/plugins/serverBuild.js +32 -30
- package/dist/esm-node/utils/loadPlugins.js +4 -34
- package/dist/esm-node/utils/printInstructions.js +9 -1
- package/dist/esm-node/utils/restart.js +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/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/hooks.d.ts +2 -0
- package/dist/types/index.d.ts +3 -5
- package/dist/types/{compat → new/compat}/hooks.d.ts +2 -2
- package/dist/types/new/compat/index.d.ts +2 -0
- package/dist/types/new/index.d.ts +6 -0
- package/dist/types/new/loadPlugins.d.ts +9 -0
- package/dist/types/new/utils/index.d.ts +1 -0
- package/dist/types/old.d.ts +13 -0
- package/dist/types/plugins/serverBuild.d.ts +2 -2
- package/dist/types/types/index.d.ts +0 -2
- package/dist/types/types/new.d.ts +16 -11
- package/dist/types/utils/generateWatchFiles.d.ts +2 -2
- package/dist/types/utils/loadPlugins.d.ts +3 -13
- package/dist/types/utils/printInstructions.d.ts +3 -1
- package/dist/types/utils/restart.d.ts +3 -2
- package/package.json +23 -22
- package/dist/types/compat/index.d.ts +0 -2
- package/dist/types/utils/isAutoLoadPlugins.d.ts +0 -1
- /package/dist/cjs/{compat → new/compat}/utils.js +0 -0
- /package/dist/cjs/{constants.js → new/constants.js} +0 -0
- /package/dist/esm/{compat → new/compat}/utils.js +0 -0
- /package/dist/esm/{constants.js → new/constants.js} +0 -0
- /package/dist/esm/{utils/initAppContext.js → new/context.js} +0 -0
- /package/dist/esm-node/{compat → new/compat}/utils.js +0 -0
- /package/dist/esm-node/{constants.js → new/constants.js} +0 -0
- /package/dist/esm-node/{utils/initAppContext.js → new/context.js} +0 -0
- /package/dist/types/{compat → new/compat}/utils.d.ts +0 -0
- /package/dist/types/{constants.d.ts → new/constants.d.ts} +0 -0
- /package/dist/types/{utils/initAppContext.d.ts → new/context.d.ts} +0 -0
- /package/dist/types/{utils → new}/getConfigFile.d.ts +0 -0
- /package/dist/types/{run/index.d.ts → new/run.d.ts} +0 -0
@@ -0,0 +1,57 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __defProp = Object.defineProperty;
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
+
var __export = (target, all) => {
|
7
|
+
for (var name in all)
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
9
|
+
};
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
12
|
+
for (let key of __getOwnPropNames(from))
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
15
|
+
}
|
16
|
+
return to;
|
17
|
+
};
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
|
+
var loadPlugins_exports = {};
|
20
|
+
__export(loadPlugins_exports, {
|
21
|
+
loadInternalPlugins: () => loadInternalPlugins
|
22
|
+
});
|
23
|
+
module.exports = __toCommonJS(loadPlugins_exports);
|
24
|
+
var import_utils = require("@modern-js/utils");
|
25
|
+
const debug = (0, import_utils.createDebugger)("load-plugins");
|
26
|
+
const resolveCliPlugin = async (p, appDirectory) => {
|
27
|
+
const pkg = typeof p === "string" ? p : p[0];
|
28
|
+
const pluginOptions = typeof p === "string" ? void 0 : p[1];
|
29
|
+
const path = (0, import_utils.tryResolve)(pkg, appDirectory);
|
30
|
+
let module2;
|
31
|
+
try {
|
32
|
+
module2 = await (0, import_utils.compatibleRequire)(path);
|
33
|
+
} catch (e) {
|
34
|
+
({ default: module2 } = await (0, import_utils.dynamicImport)(path));
|
35
|
+
}
|
36
|
+
if (typeof module2 === "function") {
|
37
|
+
const result = module2(pluginOptions);
|
38
|
+
return result;
|
39
|
+
}
|
40
|
+
return module2;
|
41
|
+
};
|
42
|
+
const loadInternalPlugins = async (appDirectory, internalPlugins, autoLoad, autoLoadPlugins) => {
|
43
|
+
const plugins = [
|
44
|
+
...autoLoadPlugins ? (0, import_utils.getInternalPlugins)(appDirectory, internalPlugins) : [],
|
45
|
+
...autoLoad ? (0, import_utils.getInternalPlugins)(appDirectory, autoLoad) : []
|
46
|
+
];
|
47
|
+
const loadedPlugins = await Promise.all(plugins.map((plugin) => {
|
48
|
+
const loadedPlugin = resolveCliPlugin(plugin, appDirectory);
|
49
|
+
debug(`resolve plugin %s: %s`, plugin, loadedPlugin);
|
50
|
+
return loadedPlugin;
|
51
|
+
}));
|
52
|
+
return loadedPlugins;
|
53
|
+
};
|
54
|
+
// Annotate the CommonJS export names for ESM import in node:
|
55
|
+
0 && (module.exports = {
|
56
|
+
loadInternalPlugins
|
57
|
+
});
|
@@ -24,11 +24,11 @@ module.exports = __toCommonJS(run_exports);
|
|
24
24
|
var import_cli = require("@modern-js/plugin-v2/cli");
|
25
25
|
var import_run = require("@modern-js/plugin-v2/run");
|
26
26
|
var import_utils = require("@modern-js/utils");
|
27
|
-
var import_hooks = require("
|
28
|
-
var import_constants = require("
|
29
|
-
var import_getConfigFile = require("
|
30
|
-
var
|
31
|
-
var
|
27
|
+
var import_hooks = require("./compat/hooks");
|
28
|
+
var import_constants = require("./constants");
|
29
|
+
var import_getConfigFile = require("./getConfigFile");
|
30
|
+
var import_loadPlugins = require("./loadPlugins");
|
31
|
+
var import_utils2 = require("./utils");
|
32
32
|
async function run({ cwd, initialLog, version, internalPlugins, packageJsonConfig, configFile }) {
|
33
33
|
const command = process.argv[2];
|
34
34
|
const cliParams = (0, import_utils.minimist)(process.argv.slice(2));
|
@@ -50,7 +50,7 @@ async function run({ cwd, initialLog, version, internalPlugins, packageJsonConfi
|
|
50
50
|
}
|
51
51
|
const appDirectory = await (0, import_cli.initAppDir)(cwd);
|
52
52
|
const finalConfigFile = customConfigFile || (0, import_getConfigFile.getConfigFile)(configFile);
|
53
|
-
const autoLoadPlugins = await (0,
|
53
|
+
const autoLoadPlugins = await (0, import_utils2.getIsAutoLoadPlugins)(appDirectory, finalConfigFile);
|
54
54
|
const plugins = await (0, import_loadPlugins.loadInternalPlugins)(appDirectory, internalPlugins === null || internalPlugins === void 0 ? void 0 : internalPlugins.cli, internalPlugins === null || internalPlugins === void 0 ? void 0 : internalPlugins.autoLoad, autoLoadPlugins);
|
55
55
|
await (0, import_run.run)({
|
56
56
|
cwd,
|
@@ -16,13 +16,13 @@ var __copyProps = (to, from, except, desc) => {
|
|
16
16
|
return to;
|
17
17
|
};
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
|
-
var
|
20
|
-
__export(
|
21
|
-
|
19
|
+
var utils_exports = {};
|
20
|
+
__export(utils_exports, {
|
21
|
+
getIsAutoLoadPlugins: () => getIsAutoLoadPlugins
|
22
22
|
});
|
23
|
-
module.exports = __toCommonJS(
|
23
|
+
module.exports = __toCommonJS(utils_exports);
|
24
24
|
var import_cli = require("@modern-js/plugin-v2/cli");
|
25
|
-
async function
|
25
|
+
async function getIsAutoLoadPlugins(appDirectory, configFile = "modern.config.ts", packageJsonConfig = "ModernConfig") {
|
26
26
|
var _loaded_config;
|
27
27
|
const loaded = await (0, import_cli.createLoadedConfig)(appDirectory, configFile, packageJsonConfig);
|
28
28
|
const autoLoadPlugins = (_loaded_config = loaded.config) === null || _loaded_config === void 0 ? void 0 : _loaded_config.autoLoadPlugins;
|
@@ -30,5 +30,5 @@ async function isAutoLoadPlugins(appDirectory, configFile = "modern.config.ts",
|
|
30
30
|
}
|
31
31
|
// Annotate the CommonJS export names for ESM import in node:
|
32
32
|
0 && (module.exports = {
|
33
|
-
|
33
|
+
getIsAutoLoadPlugins
|
34
34
|
});
|
package/dist/cjs/old.js
ADDED
@@ -0,0 +1,179 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __create = Object.create;
|
3
|
+
var __defProp = Object.defineProperty;
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
+
var __export = (target, all) => {
|
9
|
+
for (var name in all)
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
11
|
+
};
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
14
|
+
for (let key of __getOwnPropNames(from))
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
17
|
+
}
|
18
|
+
return to;
|
19
|
+
};
|
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
|
+
));
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
30
|
+
var old_exports = {};
|
31
|
+
__export(old_exports, {
|
32
|
+
appTools: () => appTools,
|
33
|
+
default: () => old_default,
|
34
|
+
dev: () => import_dev.dev,
|
35
|
+
mergeConfig: () => import_core.mergeConfig
|
36
|
+
});
|
37
|
+
module.exports = __toCommonJS(old_exports);
|
38
|
+
var import_path = __toESM(require("path"));
|
39
|
+
var import_language_detector = require("@modern-js/plugin-i18n/language-detector");
|
40
|
+
var import_uni_builder = require("@modern-js/uni-builder");
|
41
|
+
var import_utils = require("@modern-js/utils");
|
42
|
+
var import_hooks = require("./hooks");
|
43
|
+
var import_locale = require("./locale");
|
44
|
+
var import_analyze = __toESM(require("./plugins/analyze"));
|
45
|
+
var import_deploy = __toESM(require("./plugins/deploy"));
|
46
|
+
var import_initialize = __toESM(require("./plugins/initialize"));
|
47
|
+
var import_serverBuild = __toESM(require("./plugins/serverBuild"));
|
48
|
+
var import_commands = require("./commands");
|
49
|
+
var import_generateWatchFiles = require("./utils/generateWatchFiles");
|
50
|
+
var import_restart = require("./utils/restart");
|
51
|
+
var import_dev = require("./commands/dev");
|
52
|
+
var import_core = require("@modern-js/core");
|
53
|
+
__reExport(old_exports, require("./defineConfig"), module.exports);
|
54
|
+
__reExport(old_exports, require("./types"), module.exports);
|
55
|
+
const appTools = (options = {
|
56
|
+
// default webpack to be compatible with original projects
|
57
|
+
bundler: "webpack"
|
58
|
+
}) => ({
|
59
|
+
name: "@modern-js/app-tools-old",
|
60
|
+
post: [
|
61
|
+
"@modern-js/plugin-initialize",
|
62
|
+
"@modern-js/plugin-analyze",
|
63
|
+
"@modern-js/plugin-ssr",
|
64
|
+
"@modern-js/plugin-document",
|
65
|
+
"@modern-js/plugin-state",
|
66
|
+
"@modern-js/plugin-router",
|
67
|
+
"@modern-js/plugin-router-v5",
|
68
|
+
"@modern-js/plugin-polyfill"
|
69
|
+
],
|
70
|
+
registerHook: import_hooks.hooks,
|
71
|
+
usePlugins: [
|
72
|
+
(0, import_initialize.default)({
|
73
|
+
bundler: (options === null || options === void 0 ? void 0 : options.bundler) && [
|
74
|
+
"rspack",
|
75
|
+
"experimental-rspack"
|
76
|
+
].includes(options.bundler) ? "rspack" : "webpack"
|
77
|
+
}),
|
78
|
+
(0, import_analyze.default)({
|
79
|
+
bundler: (options === null || options === void 0 ? void 0 : options.bundler) && [
|
80
|
+
"rspack",
|
81
|
+
"experimental-rspack"
|
82
|
+
].includes(options.bundler) ? "rspack" : "webpack"
|
83
|
+
}),
|
84
|
+
(0, import_serverBuild.default)(),
|
85
|
+
(0, import_deploy.default)()
|
86
|
+
],
|
87
|
+
setup: (api) => {
|
88
|
+
const appContext = api.useAppContext();
|
89
|
+
api.setAppContext({
|
90
|
+
...appContext,
|
91
|
+
toolsType: "app-tools"
|
92
|
+
});
|
93
|
+
const locale = (0, import_language_detector.getLocaleLanguage)();
|
94
|
+
import_locale.i18n.changeLanguage({
|
95
|
+
locale
|
96
|
+
});
|
97
|
+
return {
|
98
|
+
async beforeConfig() {
|
99
|
+
var _userConfig_output;
|
100
|
+
const userConfig = api.useConfigContext();
|
101
|
+
const appContext2 = api.useAppContext();
|
102
|
+
if ((_userConfig_output = userConfig.output) === null || _userConfig_output === void 0 ? void 0 : _userConfig_output.tempDir) {
|
103
|
+
api.setAppContext({
|
104
|
+
...appContext2,
|
105
|
+
internalDirectory: import_path.default.resolve(appContext2.appDirectory, userConfig.output.tempDir)
|
106
|
+
});
|
107
|
+
}
|
108
|
+
},
|
109
|
+
async commands({ program }) {
|
110
|
+
await (0, import_commands.devCommand)(program, api);
|
111
|
+
await (0, import_commands.buildCommand)(program, api);
|
112
|
+
(0, import_commands.serverCommand)(program, api);
|
113
|
+
(0, import_commands.deployCommand)(program, api);
|
114
|
+
(0, import_commands.newCommand)(program, locale);
|
115
|
+
(0, import_commands.inspectCommand)(program, api);
|
116
|
+
(0, import_commands.upgradeCommand)(program);
|
117
|
+
(0, import_utils.deprecatedCommands)(program);
|
118
|
+
},
|
119
|
+
async prepare() {
|
120
|
+
const command = (0, import_utils.getCommand)();
|
121
|
+
if (command === "deploy") {
|
122
|
+
const isSkipBuild = [
|
123
|
+
"-s",
|
124
|
+
"--skip-build"
|
125
|
+
].some((tag) => {
|
126
|
+
return (0, import_utils.getArgv)().includes(tag);
|
127
|
+
});
|
128
|
+
if (isSkipBuild) {
|
129
|
+
return;
|
130
|
+
}
|
131
|
+
}
|
132
|
+
if (command === "dev" || command === "start" || command === "build" || command === "deploy") {
|
133
|
+
const resolvedConfig = api.useResolvedConfigContext();
|
134
|
+
if (resolvedConfig.output.cleanDistPath) {
|
135
|
+
const appContext2 = api.useAppContext();
|
136
|
+
await (0, import_utils.emptyDir)(appContext2.distDirectory);
|
137
|
+
}
|
138
|
+
}
|
139
|
+
},
|
140
|
+
async watchFiles() {
|
141
|
+
const appContext2 = api.useAppContext();
|
142
|
+
const config = api.useResolvedConfigContext();
|
143
|
+
const files = await (0, import_generateWatchFiles.generateWatchFiles)(appContext2, config.source.configDir);
|
144
|
+
const watchFiles = (0, import_uni_builder.castArray)(config.dev.watchFiles);
|
145
|
+
watchFiles.forEach(({ type, paths }) => {
|
146
|
+
if (type === "reload-server") {
|
147
|
+
files.push(...Array.isArray(paths) ? paths : [
|
148
|
+
paths
|
149
|
+
]);
|
150
|
+
}
|
151
|
+
});
|
152
|
+
return files;
|
153
|
+
},
|
154
|
+
// 这里会被 core/initWatcher 监听的文件变动触发,如果是 src 目录下的文件变动,则不做 restart
|
155
|
+
async fileChange(e) {
|
156
|
+
const { filename, eventType, isPrivate } = e;
|
157
|
+
if (!isPrivate && (eventType === "change" || eventType === "unlink")) {
|
158
|
+
const { closeServer } = await import("./utils/createServer.js");
|
159
|
+
await closeServer();
|
160
|
+
await (0, import_restart.restart)(api.useHookRunners(), filename);
|
161
|
+
}
|
162
|
+
},
|
163
|
+
async beforeRestart() {
|
164
|
+
(0, import_utils.cleanRequireCache)([
|
165
|
+
require.resolve("./plugins/analyze")
|
166
|
+
]);
|
167
|
+
}
|
168
|
+
};
|
169
|
+
}
|
170
|
+
});
|
171
|
+
var old_default = appTools;
|
172
|
+
// Annotate the CommonJS export names for ESM import in node:
|
173
|
+
0 && (module.exports = {
|
174
|
+
appTools,
|
175
|
+
dev,
|
176
|
+
mergeConfig,
|
177
|
+
...require("./defineConfig"),
|
178
|
+
...require("./types")
|
179
|
+
});
|
@@ -50,37 +50,39 @@ function checkHasConfig(appDir, metaName = "modern-js") {
|
|
50
50
|
var serverBuild_default = () => ({
|
51
51
|
name: "@modern-js/server-build",
|
52
52
|
setup(api) {
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
53
|
+
return {
|
54
|
+
async afterBuild() {
|
55
|
+
const { appDirectory, distDirectory, metaName } = api.useAppContext();
|
56
|
+
if (!checkHasCache(appDirectory) && !checkHasConfig(appDirectory, metaName)) {
|
57
|
+
return;
|
58
|
+
}
|
59
|
+
const modernConfig = api.useResolvedConfigContext();
|
60
|
+
const distDir = import_path.default.resolve(distDirectory);
|
61
|
+
const serverDir = import_path.default.resolve(appDirectory, import_utils.SERVER_DIR);
|
62
|
+
const sharedDir = import_path.default.resolve(appDirectory, import_utils.SHARED_DIR);
|
63
|
+
const tsconfigPath = import_path.default.resolve(appDirectory, TS_CONFIG_FILENAME);
|
64
|
+
const sourceDirs = [];
|
65
|
+
if (import_fs.default.existsSync(serverDir)) {
|
66
|
+
sourceDirs.push(serverDir);
|
67
|
+
if (import_fs.default.existsSync(sharedDir)) {
|
68
|
+
sourceDirs.push(sharedDir);
|
69
|
+
}
|
70
|
+
}
|
71
|
+
const { server } = modernConfig;
|
72
|
+
const { alias } = modernConfig.source;
|
73
|
+
const { babel } = modernConfig.tools;
|
74
|
+
if (sourceDirs.length > 0) {
|
75
|
+
await (0, import_server_utils.compile)(appDirectory, {
|
76
|
+
server,
|
77
|
+
alias,
|
78
|
+
babelConfig: babel
|
79
|
+
}, {
|
80
|
+
sourceDirs,
|
81
|
+
distDir,
|
82
|
+
tsconfigPath
|
83
|
+
});
|
68
84
|
}
|
69
85
|
}
|
70
|
-
|
71
|
-
const { alias } = modernConfig.source;
|
72
|
-
const { babel } = modernConfig.tools;
|
73
|
-
if (sourceDirs.length > 0) {
|
74
|
-
await (0, import_server_utils.compile)(appDirectory, {
|
75
|
-
server,
|
76
|
-
alias,
|
77
|
-
babelConfig: babel
|
78
|
-
}, {
|
79
|
-
sourceDirs,
|
80
|
-
distDir,
|
81
|
-
tsconfigPath
|
82
|
-
});
|
83
|
-
}
|
84
|
-
});
|
86
|
+
};
|
85
87
|
}
|
86
88
|
});
|
@@ -19,20 +19,18 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
19
19
|
var loadPlugins_exports = {};
|
20
20
|
__export(loadPlugins_exports, {
|
21
21
|
getServerPlugins: () => getServerPlugins,
|
22
|
-
loadInternalPlugins: () => loadInternalPlugins,
|
23
22
|
loadServerPlugins: () => loadServerPlugins
|
24
23
|
});
|
25
24
|
module.exports = __toCommonJS(loadPlugins_exports);
|
26
25
|
var import_prod_server = require("@modern-js/prod-server");
|
27
|
-
var import_utils = require("@modern-js/utils");
|
28
|
-
const debug = (0, import_utils.createDebugger)("load-plugins");
|
29
26
|
async function getServerPlugins(api, metaName = "modern-js") {
|
30
|
-
const
|
31
|
-
const { plugins } = await
|
27
|
+
const runner = api.useHookRunners();
|
28
|
+
const { plugins } = await runner._internalServerPlugins({
|
32
29
|
plugins: []
|
33
30
|
});
|
34
31
|
const filtedPlugins = plugins.filter((plugin) => plugin.name.includes(metaName));
|
35
|
-
api.
|
32
|
+
api.setAppContext({
|
33
|
+
...api.useAppContext(),
|
36
34
|
serverPlugins: filtedPlugins
|
37
35
|
});
|
38
36
|
return filtedPlugins;
|
@@ -42,37 +40,8 @@ async function loadServerPlugins(api, appDirectory, metaName) {
|
|
42
40
|
const instances = await (0, import_prod_server.loadServerPlugins)(plugins, appDirectory);
|
43
41
|
return instances;
|
44
42
|
}
|
45
|
-
const resolveCliPlugin = async (p, appDirectory) => {
|
46
|
-
const pkg = typeof p === "string" ? p : p[0];
|
47
|
-
const pluginOptions = typeof p === "string" ? void 0 : p[1];
|
48
|
-
const path = (0, import_utils.tryResolve)(pkg, appDirectory);
|
49
|
-
let module2;
|
50
|
-
try {
|
51
|
-
module2 = await (0, import_utils.compatibleRequire)(path);
|
52
|
-
} catch (e) {
|
53
|
-
({ default: module2 } = await (0, import_utils.dynamicImport)(path));
|
54
|
-
}
|
55
|
-
if (typeof module2 === "function") {
|
56
|
-
const result = module2(pluginOptions);
|
57
|
-
return result;
|
58
|
-
}
|
59
|
-
return module2;
|
60
|
-
};
|
61
|
-
const loadInternalPlugins = async (appDirectory, internalPlugins, autoLoad, autoLoadPlugins) => {
|
62
|
-
const plugins = [
|
63
|
-
...autoLoadPlugins ? (0, import_utils.getInternalPlugins)(appDirectory, internalPlugins) : [],
|
64
|
-
...autoLoad ? (0, import_utils.getInternalPlugins)(appDirectory, autoLoad) : []
|
65
|
-
];
|
66
|
-
const loadedPlugins = await Promise.all(plugins.map((plugin) => {
|
67
|
-
const loadedPlugin = resolveCliPlugin(plugin, appDirectory);
|
68
|
-
debug(`resolve plugin %s: %s`, plugin, loadedPlugin);
|
69
|
-
return loadedPlugin;
|
70
|
-
}));
|
71
|
-
return loadedPlugins;
|
72
|
-
};
|
73
43
|
// Annotate the CommonJS export names for ESM import in node:
|
74
44
|
0 && (module.exports = {
|
75
45
|
getServerPlugins,
|
76
|
-
loadInternalPlugins,
|
77
46
|
loadServerPlugins
|
78
47
|
});
|
@@ -18,7 +18,8 @@ var __copyProps = (to, from, except, desc) => {
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
19
|
var printInstructions_exports = {};
|
20
20
|
__export(printInstructions_exports, {
|
21
|
-
printInstructions: () => printInstructions
|
21
|
+
printInstructions: () => printInstructions,
|
22
|
+
printInstructionsCompat: () => printInstructionsCompat
|
22
23
|
});
|
23
24
|
module.exports = __toCommonJS(printInstructions_exports);
|
24
25
|
var import_utils = require("@modern-js/utils");
|
@@ -29,7 +30,15 @@ const printInstructions = async (hooks, appContext, config) => {
|
|
29
30
|
});
|
30
31
|
import_utils.logger.log(instructions);
|
31
32
|
};
|
33
|
+
const printInstructionsCompat = async (hookRunners, appContext, config) => {
|
34
|
+
const message = (0, import_utils.prettyInstructions)(appContext, config);
|
35
|
+
const { instructions } = await hookRunners.beforePrintInstructions({
|
36
|
+
instructions: message
|
37
|
+
});
|
38
|
+
import_utils.logger.log(instructions);
|
39
|
+
};
|
32
40
|
// Annotate the CommonJS export names for ESM import in node:
|
33
41
|
0 && (module.exports = {
|
34
|
-
printInstructions
|
42
|
+
printInstructions,
|
43
|
+
printInstructionsCompat
|
35
44
|
});
|
@@ -24,12 +24,12 @@ module.exports = __toCommonJS(restart_exports);
|
|
24
24
|
var import_cli = require("@modern-js/plugin-v2/cli");
|
25
25
|
var import_utils = require("@modern-js/utils");
|
26
26
|
var import_commander = require("@modern-js/utils/commander");
|
27
|
-
async function restart(
|
27
|
+
async function restart(hooksRunner, filename) {
|
28
28
|
(0, import_utils.clearConsole)();
|
29
29
|
import_utils.logger.info(`Restart because ${import_utils.chalk.yellow(filename)} is changed...
|
30
30
|
`);
|
31
31
|
let hasGetError = false;
|
32
|
-
await
|
32
|
+
await hooksRunner.beforeRestart();
|
33
33
|
try {
|
34
34
|
await import_cli.cli.init(import_cli.cli.getPrevInitOptions());
|
35
35
|
} catch (err) {
|
@@ -2,6 +2,7 @@ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
2
|
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
3
3
|
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
4
4
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
5
|
+
import { ResolvedConfigContext } from "@modern-js/core";
|
5
6
|
import { logger } from "@modern-js/utils";
|
6
7
|
import { buildServerConfig } from "../utils/config";
|
7
8
|
import { loadServerPlugins } from "../utils/loadPlugins";
|
@@ -9,16 +10,16 @@ import { registerCompiler } from "../utils/register";
|
|
9
10
|
import { generateRoutes } from "../utils/routes";
|
10
11
|
var build = function() {
|
11
12
|
var _ref = _async_to_generator(function(api, options) {
|
12
|
-
var _resolvedConfig_source, resolvedConfig, appContext,
|
13
|
+
var _resolvedConfig_source, resolvedConfig, appContext, hookRunners, _resolvedConfig_source1, registerEsm, apiOnly, appDirectory, distDirectory, serverConfigFile, distDirectory1, appDirectory1, serverConfigFile1;
|
13
14
|
return _ts_generator(this, function(_state) {
|
14
15
|
switch (_state.label) {
|
15
16
|
case 0:
|
16
17
|
if (options === null || options === void 0 ? void 0 : options.analyze) {
|
17
18
|
process.env.BUNDLE_ANALYZE = "true";
|
18
19
|
}
|
19
|
-
resolvedConfig = api.
|
20
|
-
appContext = api.
|
21
|
-
|
20
|
+
resolvedConfig = api.useResolvedConfigContext();
|
21
|
+
appContext = api.useAppContext();
|
22
|
+
hookRunners = api.useHookRunners();
|
22
23
|
return [
|
23
24
|
4,
|
24
25
|
loadServerPlugins(api, appContext.appDirectory, appContext.metaName)
|
@@ -63,12 +64,9 @@ var build = function() {
|
|
63
64
|
appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory, serverConfigFile = appContext.serverConfigFile;
|
64
65
|
return [
|
65
66
|
4,
|
66
|
-
|
67
|
-
environments: {},
|
67
|
+
hookRunners.beforeBuild({
|
68
68
|
// "null" bundlerConfigs
|
69
|
-
bundlerConfigs: void 0
|
70
|
-
isFirstCompile: false,
|
71
|
-
isWatch: false
|
69
|
+
bundlerConfigs: void 0
|
72
70
|
})
|
73
71
|
];
|
74
72
|
case 6:
|
@@ -91,12 +89,9 @@ var build = function() {
|
|
91
89
|
_state.sent();
|
92
90
|
return [
|
93
91
|
4,
|
94
|
-
|
95
|
-
environments: {},
|
92
|
+
hookRunners.afterBuild({
|
96
93
|
// "null" stats
|
97
|
-
stats: void 0
|
98
|
-
isFirstCompile: false,
|
99
|
-
isWatch: false
|
94
|
+
stats: void 0
|
100
95
|
})
|
101
96
|
];
|
102
97
|
case 9:
|
@@ -105,11 +100,10 @@ var build = function() {
|
|
105
100
|
2
|
106
101
|
];
|
107
102
|
case 10:
|
108
|
-
|
109
|
-
|
110
|
-
cliOptions: options
|
111
|
-
});
|
103
|
+
resolvedConfig = _object_spread_props(_object_spread({}, resolvedConfig), {
|
104
|
+
cliOptions: options
|
112
105
|
});
|
106
|
+
ResolvedConfigContext.set(resolvedConfig);
|
113
107
|
distDirectory1 = appContext.distDirectory, appDirectory1 = appContext.appDirectory, serverConfigFile1 = appContext.serverConfigFile;
|
114
108
|
return [
|
115
109
|
4,
|
@@ -3,12 +3,12 @@ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
3
3
|
import { getServerPlugins } from "../utils/loadPlugins";
|
4
4
|
var deploy = function() {
|
5
5
|
var _ref = _async_to_generator(function(api, options) {
|
6
|
-
var
|
6
|
+
var hookRunners, metaName;
|
7
7
|
return _ts_generator(this, function(_state) {
|
8
8
|
switch (_state.label) {
|
9
9
|
case 0:
|
10
|
-
|
11
|
-
metaName = api.
|
10
|
+
hookRunners = api.useHookRunners();
|
11
|
+
metaName = api.useAppContext().metaName;
|
12
12
|
return [
|
13
13
|
4,
|
14
14
|
getServerPlugins(api, metaName)
|
@@ -17,19 +17,19 @@ var deploy = function() {
|
|
17
17
|
_state.sent();
|
18
18
|
return [
|
19
19
|
4,
|
20
|
-
|
20
|
+
hookRunners.beforeDeploy(options)
|
21
21
|
];
|
22
22
|
case 2:
|
23
23
|
_state.sent();
|
24
24
|
return [
|
25
25
|
4,
|
26
|
-
|
26
|
+
hookRunners.deploy(options)
|
27
27
|
];
|
28
28
|
case 3:
|
29
29
|
_state.sent();
|
30
30
|
return [
|
31
31
|
4,
|
32
|
-
|
32
|
+
hookRunners.afterDeploy(options)
|
33
33
|
];
|
34
34
|
case 4:
|
35
35
|
_state.sent();
|
package/dist/esm/commands/dev.js
CHANGED
@@ -3,27 +3,28 @@ import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
|
3
3
|
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
4
4
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
5
5
|
import path from "node:path";
|
6
|
+
import { ResolvedConfigContext } from "@modern-js/core";
|
6
7
|
import { applyPlugins } from "@modern-js/prod-server";
|
7
8
|
import { createDevServer } from "@modern-js/server";
|
8
9
|
import { DEFAULT_DEV_HOST, SERVER_DIR, getMeta, logger } from "@modern-js/utils";
|
9
10
|
import { buildServerConfig } from "../utils/config";
|
10
11
|
import { setServer } from "../utils/createServer";
|
11
12
|
import { loadServerPlugins } from "../utils/loadPlugins";
|
12
|
-
import {
|
13
|
+
import { printInstructionsCompat } from "../utils/printInstructions";
|
13
14
|
import { registerCompiler } from "../utils/register";
|
14
15
|
import { generateRoutes } from "../utils/routes";
|
15
16
|
var dev = function() {
|
16
17
|
var _ref = _async_to_generator(function(api, options, devServerOptions) {
|
17
|
-
var _normalizedConfig_source, _normalizedConfig_tools, _normalizedConfig_dev, normalizedConfig, appContext,
|
18
|
+
var _normalizedConfig_source, _normalizedConfig_tools, _normalizedConfig_dev, normalizedConfig, appContext, hookRunners, _normalizedConfig_source1, registerEsm, appDirectory, distDirectory, port, apiOnly, serverConfigFile, metaName, serverRoutes, meta, serverConfigPath, pluginInstances, serverOptions, host, server, _ref2, server1, afterListen;
|
18
19
|
return _ts_generator(this, function(_state) {
|
19
20
|
switch (_state.label) {
|
20
21
|
case 0:
|
21
22
|
if (options.analyze) {
|
22
23
|
process.env.BUNDLE_ANALYZE = "true";
|
23
24
|
}
|
24
|
-
normalizedConfig = api.
|
25
|
-
appContext = api.
|
26
|
-
|
25
|
+
normalizedConfig = api.useResolvedConfigContext();
|
26
|
+
appContext = api.useAppContext();
|
27
|
+
hookRunners = api.useHookRunners();
|
27
28
|
if (!(appContext.moduleType && appContext.moduleType === "module"))
|
28
29
|
return [
|
29
30
|
3,
|
@@ -53,11 +54,10 @@ var dev = function() {
|
|
53
54
|
];
|
54
55
|
case 4:
|
55
56
|
_state.sent();
|
56
|
-
|
57
|
-
|
58
|
-
cliOptions: options
|
59
|
-
});
|
57
|
+
normalizedConfig = _object_spread_props(_object_spread({}, normalizedConfig), {
|
58
|
+
cliOptions: options
|
60
59
|
});
|
60
|
+
ResolvedConfigContext.set(normalizedConfig);
|
61
61
|
appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory, port = appContext.port, apiOnly = appContext.apiOnly, serverConfigFile = appContext.serverConfigFile, metaName = appContext.metaName, serverRoutes = appContext.serverRoutes;
|
62
62
|
return [
|
63
63
|
4,
|
@@ -74,7 +74,7 @@ var dev = function() {
|
|
74
74
|
serverConfigPath = path.resolve(appDirectory, SERVER_DIR, "".concat(meta, ".server"));
|
75
75
|
return [
|
76
76
|
4,
|
77
|
-
|
77
|
+
hookRunners.beforeDev()
|
78
78
|
];
|
79
79
|
case 6:
|
80
80
|
_state.sent();
|
@@ -132,7 +132,7 @@ var dev = function() {
|
|
132
132
|
port,
|
133
133
|
host
|
134
134
|
}, function() {
|
135
|
-
|
135
|
+
printInstructionsCompat(hookRunners, appContext, normalizedConfig);
|
136
136
|
});
|
137
137
|
return [
|
138
138
|
3,
|