@modern-js/app-tools 3.9.1 → 3.9.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/commands/build.js +1 -2
- package/dist/cjs/commands/deploy.js +1 -3
- package/dist/cjs/commands/index.js +4 -0
- package/dist/cjs/compat/hooks.js +1 -1
- package/dist/cjs/index.js +27 -57
- package/dist/cjs/plugins/analyze/getFileSystemEntry.js +1 -1
- package/dist/cjs/plugins/analyze/getServerRoutes.js +1 -1
- package/dist/cjs/plugins/analyze/index.js +2 -2
- package/dist/cjs/plugins/analyze/utils.js +4 -5
- package/dist/cjs/plugins/initialize/index.js +3 -4
- package/dist/esm/commands/build.mjs +1 -2
- package/dist/esm/commands/deploy.mjs +1 -3
- package/dist/esm/commands/index.mjs +4 -0
- package/dist/esm/compat/hooks.mjs +1 -1
- package/dist/esm/index.mjs +2 -12
- package/dist/esm/plugins/analyze/getFileSystemEntry.mjs +1 -1
- package/dist/esm/plugins/analyze/getServerRoutes.mjs +1 -1
- package/dist/esm/plugins/analyze/index.mjs +2 -2
- package/dist/esm/plugins/analyze/utils.mjs +4 -5
- package/dist/esm/plugins/initialize/index.mjs +3 -4
- package/dist/esm-node/commands/build.mjs +1 -2
- package/dist/esm-node/commands/deploy.mjs +1 -3
- package/dist/esm-node/commands/index.mjs +4 -0
- package/dist/esm-node/compat/hooks.mjs +1 -1
- package/dist/esm-node/index.mjs +2 -12
- package/dist/esm-node/plugins/analyze/getFileSystemEntry.mjs +1 -1
- package/dist/esm-node/plugins/analyze/getServerRoutes.mjs +1 -1
- package/dist/esm-node/plugins/analyze/index.mjs +2 -2
- package/dist/esm-node/plugins/analyze/utils.mjs +4 -5
- package/dist/esm-node/plugins/initialize/index.mjs +3 -4
- package/dist/types/index.d.ts +1 -3
- package/dist/types/plugins/analyze/utils.d.ts +1 -1
- package/docs/configure/app/output/disable-svgr.md +4 -0
- package/docs/configure/app/output/svg-default-export.md +4 -0
- package/docs/configure/app/tools/less.md +94 -19
- package/docs/configure/app/tools/sass.md +87 -18
- package/docs/configure/app/tools/svgr.md +89 -0
- package/docs/guides/basic-features/static-assets/svg-assets.md +29 -17
- package/docs/llms.txt +3 -2
- package/docs/plugin/introduction.md +10 -10
- package/package.json +16 -16
- package/dist/cjs/plugins/serverRuntime.js +0 -53
- package/dist/esm/plugins/serverRuntime.mjs +0 -15
- package/dist/esm-node/plugins/serverRuntime.mjs +0 -16
- package/dist/types/plugins/serverRuntime.d.ts +0 -3
|
@@ -98,10 +98,9 @@ const build = async (api, options)=>{
|
|
|
98
98
|
utils_namespaceObject.logger.info('Starting production build...');
|
|
99
99
|
if (!appContext.builder) throw new Error('Expect the Builder to have been initialized, But the appContext.builder received `undefined`');
|
|
100
100
|
await appContext.builder.onAfterBuild(async ()=>copyEnvFiles(appContext.appDirectory, appContext.distDirectory));
|
|
101
|
-
|
|
101
|
+
await appContext.builder.build({
|
|
102
102
|
watch: options?.watch
|
|
103
103
|
});
|
|
104
|
-
if (!options?.watch) await buildResult?.close();
|
|
105
104
|
};
|
|
106
105
|
exports.build = __webpack_exports__.build;
|
|
107
106
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
@@ -31,12 +31,10 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
31
31
|
deploy: ()=>deploy
|
|
32
32
|
});
|
|
33
33
|
const loadPlugins_js_namespaceObject = require("../utils/loadPlugins.js");
|
|
34
|
-
const external_build_js_namespaceObject = require("./build.js");
|
|
35
34
|
const deploy = async (api, options = {})=>{
|
|
36
35
|
const hooks = api.getHooks();
|
|
37
36
|
const { metaName } = api.getAppContext();
|
|
38
|
-
|
|
39
|
-
else await (0, external_build_js_namespaceObject.build)(api);
|
|
37
|
+
await (0, loadPlugins_js_namespaceObject.getServerPlugins)(api, metaName);
|
|
40
38
|
await hooks.onBeforeDeploy.call(options);
|
|
41
39
|
await hooks.deploy.call();
|
|
42
40
|
await hooks.onAfterDeploy.call(options);
|
|
@@ -56,6 +56,10 @@ const serverCommand = (program, api)=>{
|
|
|
56
56
|
};
|
|
57
57
|
const deployCommand = (program, api)=>{
|
|
58
58
|
program.command('deploy').usage('[options]').option('-c --config <config>', index_js_namespaceObject.i18n.t(index_js_namespaceObject.localeKeys.command.shared.config)).option('-s --skip-build', index_js_namespaceObject.i18n.t(index_js_namespaceObject.localeKeys.command.shared.skipBuild)).description(index_js_namespaceObject.i18n.t(index_js_namespaceObject.localeKeys.command.deploy.describe)).action(async (options)=>{
|
|
59
|
+
if (!options.skipBuild) {
|
|
60
|
+
const { build } = await import("./build.js");
|
|
61
|
+
await build(api);
|
|
62
|
+
}
|
|
59
63
|
const { deploy } = await import("./deploy.js");
|
|
60
64
|
await deploy(api, options);
|
|
61
65
|
process.exit(0);
|
package/dist/cjs/compat/hooks.js
CHANGED
|
@@ -92,7 +92,7 @@ function handleSetupResult(setupResult, api) {
|
|
|
92
92
|
if (newAPI && api[newAPI]) api[newAPI](async (...params)=>{
|
|
93
93
|
const { isMultiple, params: transformParams } = (0, external_utils_js_namespaceObject.transformHookParams)(key, params);
|
|
94
94
|
if (isMultiple) return (0, external_utils_js_namespaceObject.transformHookResult)(key, await fn(...transformParams));
|
|
95
|
-
return (0, external_utils_js_namespaceObject.transformHookResult)(key, await fn(transformParams));
|
|
95
|
+
else return (0, external_utils_js_namespaceObject.transformHookResult)(key, await fn(transformParams));
|
|
96
96
|
});
|
|
97
97
|
}
|
|
98
98
|
});
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __webpack_modules__ = {
|
|
3
|
-
"./commands/build" (module) {
|
|
4
|
-
module.exports = require("./commands/build.js");
|
|
5
|
-
},
|
|
6
|
-
"./commands/deploy" (module) {
|
|
7
|
-
module.exports = require("./commands/deploy.js");
|
|
8
|
-
},
|
|
9
3
|
"./commands/dev" (module) {
|
|
10
4
|
module.exports = require("./commands/dev.js");
|
|
11
5
|
},
|
|
@@ -39,9 +33,6 @@ var __webpack_modules__ = {
|
|
|
39
33
|
"./plugins/serverBuild" (module) {
|
|
40
34
|
module.exports = require("./plugins/serverBuild.js");
|
|
41
35
|
},
|
|
42
|
-
"./plugins/serverRuntime" (module) {
|
|
43
|
-
module.exports = require("./plugins/serverRuntime.js");
|
|
44
|
-
},
|
|
45
36
|
"./rsbuild" (module) {
|
|
46
37
|
module.exports = require("./rsbuild.js");
|
|
47
38
|
},
|
|
@@ -144,14 +135,12 @@ var __webpack_exports__ = {};
|
|
|
144
135
|
var _plugins_initialize__rspack_import_11_default = /*#__PURE__*/ __webpack_require__.n(_plugins_initialize__rspack_import_11);
|
|
145
136
|
var _plugins_serverBuild__rspack_import_12 = __webpack_require__("./plugins/serverBuild");
|
|
146
137
|
var _plugins_serverBuild__rspack_import_12_default = /*#__PURE__*/ __webpack_require__.n(_plugins_serverBuild__rspack_import_12);
|
|
147
|
-
var
|
|
148
|
-
var
|
|
149
|
-
var
|
|
150
|
-
var
|
|
151
|
-
var _utils_restart__rspack_import_16 = __webpack_require__("./utils/restart");
|
|
152
|
-
var _defineConfig__rspack_import_17 = __webpack_require__("./defineConfig");
|
|
138
|
+
var _utils_generateWatchFiles__rspack_import_13 = __webpack_require__("./utils/generateWatchFiles");
|
|
139
|
+
var _utils_initAppContext__rspack_import_14 = __webpack_require__("./utils/initAppContext");
|
|
140
|
+
var _utils_restart__rspack_import_15 = __webpack_require__("./utils/restart");
|
|
141
|
+
var _defineConfig__rspack_import_16 = __webpack_require__("./defineConfig");
|
|
153
142
|
var __rspack_reexport = {};
|
|
154
|
-
for(const __rspack_import_key in
|
|
143
|
+
for(const __rspack_import_key in _defineConfig__rspack_import_16)if ([
|
|
155
144
|
"dev",
|
|
156
145
|
"resolveModernRsbuildConfig",
|
|
157
146
|
"mergeConfig",
|
|
@@ -160,21 +149,17 @@ var __webpack_exports__ = {};
|
|
|
160
149
|
"serve",
|
|
161
150
|
"generateWatchFiles",
|
|
162
151
|
"initAppContext",
|
|
163
|
-
"deploy",
|
|
164
152
|
"defineConfig",
|
|
165
|
-
"build",
|
|
166
153
|
"closeServer"
|
|
167
|
-
].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>
|
|
154
|
+
].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>_defineConfig__rspack_import_16[__rspack_import_key];
|
|
168
155
|
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
169
|
-
var
|
|
170
|
-
var
|
|
171
|
-
var
|
|
172
|
-
var
|
|
173
|
-
var
|
|
174
|
-
var _rsbuild__rspack_import_23 = __webpack_require__("./rsbuild");
|
|
175
|
-
var _types__rspack_import_24 = __webpack_require__("./types?6efa");
|
|
156
|
+
var _commands_dev__rspack_import_17 = __webpack_require__("./commands/dev");
|
|
157
|
+
var _commands_serve__rspack_import_18 = __webpack_require__("./commands/serve");
|
|
158
|
+
var _utils_createServer__rspack_import_19 = __webpack_require__("./utils/createServer");
|
|
159
|
+
var _rsbuild__rspack_import_20 = __webpack_require__("./rsbuild");
|
|
160
|
+
var _types__rspack_import_21 = __webpack_require__("./types?6efa");
|
|
176
161
|
var __rspack_reexport = {};
|
|
177
|
-
for(const __rspack_import_key in
|
|
162
|
+
for(const __rspack_import_key in _types__rspack_import_21)if ([
|
|
178
163
|
"dev",
|
|
179
164
|
"resolveModernRsbuildConfig",
|
|
180
165
|
"mergeConfig",
|
|
@@ -183,17 +168,14 @@ var __webpack_exports__ = {};
|
|
|
183
168
|
"serve",
|
|
184
169
|
"generateWatchFiles",
|
|
185
170
|
"initAppContext",
|
|
186
|
-
"deploy",
|
|
187
171
|
"defineConfig",
|
|
188
|
-
"build",
|
|
189
172
|
"closeServer"
|
|
190
|
-
].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>
|
|
173
|
+
].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>_types__rspack_import_21[__rspack_import_key];
|
|
191
174
|
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
192
|
-
var
|
|
175
|
+
var _modern_js_plugin_cli__rspack_import_22 = __webpack_require__("@modern-js/plugin/cli");
|
|
193
176
|
const appTools = ()=>({
|
|
194
177
|
name: '@modern-js/app-tools',
|
|
195
178
|
usePlugins: [
|
|
196
|
-
_plugins_serverRuntime__rspack_import_13_default()(),
|
|
197
179
|
(0, _compat__rspack_import_6.compatPlugin)(),
|
|
198
180
|
_plugins_initialize__rspack_import_11_default()(),
|
|
199
181
|
_plugins_analyze__rspack_import_9_default()(),
|
|
@@ -226,7 +208,7 @@ var __webpack_exports__ = {};
|
|
|
226
208
|
_locale__rspack_import_8.i18n.changeLanguage({
|
|
227
209
|
locale
|
|
228
210
|
});
|
|
229
|
-
api.updateAppContext((0,
|
|
211
|
+
api.updateAppContext((0, _utils_initAppContext__rspack_import_14.initAppContext)({
|
|
230
212
|
metaName: context.metaName,
|
|
231
213
|
appDirectory: context.appDirectory,
|
|
232
214
|
runtimeConfigFile: _constants__rspack_import_7.DEFAULT_RUNTIME_CONFIG_FILE,
|
|
@@ -250,18 +232,12 @@ var __webpack_exports__ = {};
|
|
|
250
232
|
].some((tag)=>(0, _modern_js_utils__rspack_import_4.getArgv)().includes(tag));
|
|
251
233
|
if (isSkipBuild) return;
|
|
252
234
|
}
|
|
253
|
-
|
|
254
|
-
const shouldClean = [
|
|
235
|
+
if ([
|
|
255
236
|
'dev',
|
|
256
237
|
'start',
|
|
257
238
|
'build',
|
|
258
239
|
'deploy'
|
|
259
|
-
].includes(command)
|
|
260
|
-
'dev',
|
|
261
|
-
'start',
|
|
262
|
-
'build'
|
|
263
|
-
].includes(contextCommand);
|
|
264
|
-
if (shouldClean) {
|
|
240
|
+
].includes(command)) {
|
|
265
241
|
const resolvedConfig = api.getNormalizedConfig();
|
|
266
242
|
if (resolvedConfig.output.cleanDistPath) {
|
|
267
243
|
const appContext = api.getAppContext();
|
|
@@ -272,7 +248,7 @@ var __webpack_exports__ = {};
|
|
|
272
248
|
api.addWatchFiles(async ()=>{
|
|
273
249
|
const appContext = api.getAppContext();
|
|
274
250
|
const config = api.getNormalizedConfig();
|
|
275
|
-
const files = await (0,
|
|
251
|
+
const files = await (0, _utils_generateWatchFiles__rspack_import_13.generateWatchFiles)(appContext, config.source.configDir);
|
|
276
252
|
const watchFiles = (0, _modern_js_builder__rspack_import_1.castArray)(config.dev.watchFiles);
|
|
277
253
|
watchFiles.forEach(({ type, paths })=>{
|
|
278
254
|
if ('reload-server' === type) files.push(...Array.isArray(paths) ? paths : [
|
|
@@ -289,7 +265,7 @@ var __webpack_exports__ = {};
|
|
|
289
265
|
if (!isPrivate && ('change' === eventType || 'unlink' === eventType) && !isApiProject) {
|
|
290
266
|
const { closeServer } = await import("./utils/createServer.js");
|
|
291
267
|
await closeServer();
|
|
292
|
-
await (0,
|
|
268
|
+
await (0, _utils_restart__rspack_import_15.restart)(api.getHooks(), filename);
|
|
293
269
|
}
|
|
294
270
|
});
|
|
295
271
|
api.onBeforeRestart(()=>{
|
|
@@ -301,27 +277,23 @@ var __webpack_exports__ = {};
|
|
|
301
277
|
});
|
|
302
278
|
const __rspack_default_export = appTools;
|
|
303
279
|
__webpack_require__.d(__webpack_exports__, {
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
resolveModernRsbuildConfig: ()=>_rsbuild__rspack_import_23.resolveModernRsbuildConfig,
|
|
313
|
-
serve: ()=>_commands_serve__rspack_import_21.serve
|
|
280
|
+
closeServer: ()=>_utils_createServer__rspack_import_19.closeServer,
|
|
281
|
+
defineConfig: ()=>_defineConfig__rspack_import_16.defineConfig,
|
|
282
|
+
dev: ()=>_commands_dev__rspack_import_17.dev,
|
|
283
|
+
generateWatchFiles: ()=>_utils_generateWatchFiles__rspack_import_13.generateWatchFiles,
|
|
284
|
+
initAppContext: ()=>_utils_initAppContext__rspack_import_14.initAppContext,
|
|
285
|
+
mergeConfig: ()=>_modern_js_plugin_cli__rspack_import_22.mergeConfig,
|
|
286
|
+
resolveModernRsbuildConfig: ()=>_rsbuild__rspack_import_20.resolveModernRsbuildConfig,
|
|
287
|
+
serve: ()=>_commands_serve__rspack_import_18.serve
|
|
314
288
|
}, {
|
|
315
289
|
appTools: appTools,
|
|
316
290
|
default: __rspack_default_export
|
|
317
291
|
});
|
|
318
292
|
})();
|
|
319
293
|
exports.appTools = __webpack_exports__.appTools;
|
|
320
|
-
exports.build = __webpack_exports__.build;
|
|
321
294
|
exports.closeServer = __webpack_exports__.closeServer;
|
|
322
295
|
exports["default"] = __webpack_exports__["default"];
|
|
323
296
|
exports.defineConfig = __webpack_exports__.defineConfig;
|
|
324
|
-
exports.deploy = __webpack_exports__.deploy;
|
|
325
297
|
exports.dev = __webpack_exports__.dev;
|
|
326
298
|
exports.generateWatchFiles = __webpack_exports__.generateWatchFiles;
|
|
327
299
|
exports.initAppContext = __webpack_exports__.initAppContext;
|
|
@@ -330,11 +302,9 @@ exports.resolveModernRsbuildConfig = __webpack_exports__.resolveModernRsbuildCon
|
|
|
330
302
|
exports.serve = __webpack_exports__.serve;
|
|
331
303
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
332
304
|
"appTools",
|
|
333
|
-
"build",
|
|
334
305
|
"closeServer",
|
|
335
306
|
"default",
|
|
336
307
|
"defineConfig",
|
|
337
|
-
"deploy",
|
|
338
308
|
"dev",
|
|
339
309
|
"generateWatchFiles",
|
|
340
310
|
"initAppContext",
|
|
@@ -106,7 +106,7 @@ const getFileSystemEntry = async (hooks, appContext, config)=>{
|
|
|
106
106
|
}));
|
|
107
107
|
return scanDir(hooks, dirs);
|
|
108
108
|
} else throw Error("source.entriesDir accept a directory.");
|
|
109
|
-
throw Error(`src dir ${entriesDir} not found.`);
|
|
109
|
+
else throw Error(`src dir ${entriesDir} not found.`);
|
|
110
110
|
};
|
|
111
111
|
exports.getFileSystemEntry = __webpack_exports__.getFileSystemEntry;
|
|
112
112
|
exports.hasEntry = __webpack_exports__.hasEntry;
|
|
@@ -55,7 +55,7 @@ const analyze = ()=>({
|
|
|
55
55
|
const resolvedConfig = api.getNormalizedConfig();
|
|
56
56
|
const hooks = api.getHooks();
|
|
57
57
|
try {
|
|
58
|
-
if ((0, external_utils_js_namespaceObject.checkIsBuildCommands)(
|
|
58
|
+
if ((0, external_utils_js_namespaceObject.checkIsBuildCommands)()) utils_namespaceObject.fs.emptydirSync(appContext.internalDirectory);
|
|
59
59
|
} catch {}
|
|
60
60
|
const apiOnly = await (0, utils_namespaceObject.isApiOnly)(appContext.appDirectory, resolvedConfig.source?.entriesDir, appContext.apiDirectory);
|
|
61
61
|
const [{ getProdServerRoutes }] = await Promise.all([
|
|
@@ -149,7 +149,7 @@ const analyze = ()=>({
|
|
|
149
149
|
htmlTemplates
|
|
150
150
|
};
|
|
151
151
|
api.updateAppContext(appContext);
|
|
152
|
-
if ((0, external_utils_js_namespaceObject.checkIsBuildCommands)(
|
|
152
|
+
if ((0, external_utils_js_namespaceObject.checkIsBuildCommands)()) {
|
|
153
153
|
await hooks.generateEntryCode.call({
|
|
154
154
|
entrypoints
|
|
155
155
|
});
|
|
@@ -58,14 +58,14 @@ const walkDirectory = (dir)=>external_fs_default().readdirSync(dir).reduce((prev
|
|
|
58
58
|
...previous,
|
|
59
59
|
...walkDirectory(filePath)
|
|
60
60
|
];
|
|
61
|
-
return [
|
|
61
|
+
else return [
|
|
62
62
|
...previous,
|
|
63
63
|
filePath
|
|
64
64
|
];
|
|
65
65
|
}, []);
|
|
66
66
|
const replaceWithAlias = (base, filePath, alias)=>{
|
|
67
67
|
if (filePath.includes(base)) return (0, utils_namespaceObject.normalizeToPosixPath)(external_path_default().join(alias, external_path_default().relative(base, filePath)));
|
|
68
|
-
return filePath;
|
|
68
|
+
else return filePath;
|
|
69
69
|
};
|
|
70
70
|
const parseModule = async ({ source, filename })=>{
|
|
71
71
|
let content = source;
|
|
@@ -101,7 +101,7 @@ const parseModule = async ({ source, filename })=>{
|
|
|
101
101
|
return await (0, external_es_module_lexer_namespaceObject.parse)(content);
|
|
102
102
|
};
|
|
103
103
|
const getServerCombinedModuleFile = (internalDirectory, entryName)=>external_path_default().join(internalDirectory, entryName, 'server-loader-combined.js');
|
|
104
|
-
const checkIsBuildCommands = (
|
|
104
|
+
const checkIsBuildCommands = ()=>{
|
|
105
105
|
const buildCommands = [
|
|
106
106
|
'dev',
|
|
107
107
|
'start',
|
|
@@ -111,8 +111,7 @@ const checkIsBuildCommands = (contextCommand)=>{
|
|
|
111
111
|
'dev-worker'
|
|
112
112
|
];
|
|
113
113
|
const command = (0, utils_namespaceObject.getCommand)();
|
|
114
|
-
|
|
115
|
-
return 'dev' === contextCommand || 'start' === contextCommand || 'build' === contextCommand || 'deploy' === contextCommand;
|
|
114
|
+
return buildCommands.includes(command);
|
|
116
115
|
};
|
|
117
116
|
const checkIsServeCommand = ()=>{
|
|
118
117
|
const command = (0, utils_namespaceObject.getCommand)();
|
|
@@ -57,7 +57,7 @@ const initialize = ()=>({
|
|
|
57
57
|
api.modifyResolvedConfig(async (resolved)=>{
|
|
58
58
|
let appContext = api.getAppContext();
|
|
59
59
|
const userConfig = api.getConfig();
|
|
60
|
-
const port = await getServerPort(resolved
|
|
60
|
+
const port = await getServerPort(resolved);
|
|
61
61
|
appContext = {
|
|
62
62
|
...appContext,
|
|
63
63
|
port,
|
|
@@ -92,10 +92,9 @@ function stabilizeConfig(resolve, config, keys) {
|
|
|
92
92
|
resolve[key] = config[key] || {};
|
|
93
93
|
});
|
|
94
94
|
}
|
|
95
|
-
async function getServerPort(config
|
|
95
|
+
async function getServerPort(config) {
|
|
96
96
|
const prodPort = Number(process.env.PORT) || config.server.port || 8080;
|
|
97
|
-
|
|
98
|
-
if ((0, utils_namespaceObject.isDev)() && ((0, utils_namespaceObject.isDevCommand)() || isProgrammaticDev)) return (0, utils_namespaceObject.getPort)(Number(process.env.PORT) || prodPort);
|
|
97
|
+
if ((0, utils_namespaceObject.isDev)() && (0, utils_namespaceObject.isDevCommand)()) return (0, utils_namespaceObject.getPort)(Number(process.env.PORT) || prodPort);
|
|
99
98
|
return prodPort;
|
|
100
99
|
}
|
|
101
100
|
exports["default"] = __webpack_exports__["default"];
|
|
@@ -56,9 +56,8 @@ const build = async (api, options)=>{
|
|
|
56
56
|
logger.info('Starting production build...');
|
|
57
57
|
if (!appContext.builder) throw new Error('Expect the Builder to have been initialized, But the appContext.builder received `undefined`');
|
|
58
58
|
await appContext.builder.onAfterBuild(async ()=>copyEnvFiles(appContext.appDirectory, appContext.distDirectory));
|
|
59
|
-
|
|
59
|
+
await appContext.builder.build({
|
|
60
60
|
watch: options?.watch
|
|
61
61
|
});
|
|
62
|
-
if (!options?.watch) await buildResult?.close();
|
|
63
62
|
};
|
|
64
63
|
export { build };
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { getServerPlugins } from "../utils/loadPlugins.mjs";
|
|
2
|
-
import { build } from "./build.mjs";
|
|
3
2
|
const deploy = async (api, options = {})=>{
|
|
4
3
|
const hooks = api.getHooks();
|
|
5
4
|
const { metaName } = api.getAppContext();
|
|
6
|
-
|
|
7
|
-
else await build(api);
|
|
5
|
+
await getServerPlugins(api, metaName);
|
|
8
6
|
await hooks.onBeforeDeploy.call(options);
|
|
9
7
|
await hooks.deploy.call();
|
|
10
8
|
await hooks.onAfterDeploy.call(options);
|
|
@@ -19,6 +19,10 @@ const serverCommand = (program, api)=>{
|
|
|
19
19
|
};
|
|
20
20
|
const deployCommand = (program, api)=>{
|
|
21
21
|
program.command('deploy').usage('[options]').option('-c --config <config>', i18n.t(localeKeys.command.shared.config)).option('-s --skip-build', i18n.t(localeKeys.command.shared.skipBuild)).description(i18n.t(localeKeys.command.deploy.describe)).action(async (options)=>{
|
|
22
|
+
if (!options.skipBuild) {
|
|
23
|
+
const { build } = await import("./build.mjs");
|
|
24
|
+
await build(api);
|
|
25
|
+
}
|
|
22
26
|
const { deploy } = await import("./deploy.mjs");
|
|
23
27
|
await deploy(api, options);
|
|
24
28
|
process.exit(0);
|
|
@@ -59,7 +59,7 @@ function handleSetupResult(setupResult, api) {
|
|
|
59
59
|
if (newAPI && api[newAPI]) api[newAPI](async (...params)=>{
|
|
60
60
|
const { isMultiple, params: transformParams } = transformHookParams(key, params);
|
|
61
61
|
if (isMultiple) return transformHookResult(key, await fn(...transformParams));
|
|
62
|
-
return transformHookResult(key, await fn(transformParams));
|
|
62
|
+
else return transformHookResult(key, await fn(transformParams));
|
|
63
63
|
});
|
|
64
64
|
}
|
|
65
65
|
});
|
package/dist/esm/index.mjs
CHANGED
|
@@ -11,7 +11,6 @@ import analyze from "./plugins/analyze/index.mjs";
|
|
|
11
11
|
import deploy from "./plugins/deploy/index.mjs";
|
|
12
12
|
import initialize from "./plugins/initialize/index.mjs";
|
|
13
13
|
import serverBuild from "./plugins/serverBuild.mjs";
|
|
14
|
-
import serverRuntime from "./plugins/serverRuntime.mjs";
|
|
15
14
|
import { generateWatchFiles } from "./utils/generateWatchFiles.mjs";
|
|
16
15
|
import { initAppContext } from "./utils/initAppContext.mjs";
|
|
17
16
|
import { restart } from "./utils/restart.mjs";
|
|
@@ -20,7 +19,6 @@ export * from "./types/index.mjs";
|
|
|
20
19
|
const appTools = ()=>({
|
|
21
20
|
name: '@modern-js/app-tools',
|
|
22
21
|
usePlugins: [
|
|
23
|
-
serverRuntime(),
|
|
24
22
|
compatPlugin(),
|
|
25
23
|
initialize(),
|
|
26
24
|
analyze(),
|
|
@@ -77,18 +75,12 @@ const appTools = ()=>({
|
|
|
77
75
|
].some((tag)=>getArgv().includes(tag));
|
|
78
76
|
if (isSkipBuild) return;
|
|
79
77
|
}
|
|
80
|
-
|
|
81
|
-
const shouldClean = [
|
|
78
|
+
if ([
|
|
82
79
|
'dev',
|
|
83
80
|
'start',
|
|
84
81
|
'build',
|
|
85
82
|
'deploy'
|
|
86
|
-
].includes(command)
|
|
87
|
-
'dev',
|
|
88
|
-
'start',
|
|
89
|
-
'build'
|
|
90
|
-
].includes(contextCommand);
|
|
91
|
-
if (shouldClean) {
|
|
83
|
+
].includes(command)) {
|
|
92
84
|
const resolvedConfig = api.getNormalizedConfig();
|
|
93
85
|
if (resolvedConfig.output.cleanDistPath) {
|
|
94
86
|
const appContext = api.getAppContext();
|
|
@@ -128,8 +120,6 @@ const appTools = ()=>({
|
|
|
128
120
|
});
|
|
129
121
|
const src = appTools;
|
|
130
122
|
export { defineConfig } from "./defineConfig.mjs";
|
|
131
|
-
export { build } from "./commands/build.mjs";
|
|
132
|
-
export { deploy } from "./commands/deploy.mjs";
|
|
133
123
|
export { dev } from "./commands/dev.mjs";
|
|
134
124
|
export { serve } from "./commands/serve.mjs";
|
|
135
125
|
export { closeServer } from "./utils/createServer.mjs";
|
|
@@ -61,6 +61,6 @@ const getFileSystemEntry = async (hooks, appContext, config)=>{
|
|
|
61
61
|
}));
|
|
62
62
|
return scanDir(hooks, dirs);
|
|
63
63
|
} else throw Error("source.entriesDir accept a directory.");
|
|
64
|
-
throw Error(`src dir ${entriesDir} not found.`);
|
|
64
|
+
else throw Error(`src dir ${entriesDir} not found.`);
|
|
65
65
|
};
|
|
66
66
|
export { getFileSystemEntry, hasEntry, hasServerEntry };
|
|
@@ -23,7 +23,7 @@ const analyze = ()=>({
|
|
|
23
23
|
const resolvedConfig = api.getNormalizedConfig();
|
|
24
24
|
const hooks = api.getHooks();
|
|
25
25
|
try {
|
|
26
|
-
if (checkIsBuildCommands(
|
|
26
|
+
if (checkIsBuildCommands()) fs.emptydirSync(appContext.internalDirectory);
|
|
27
27
|
} catch {}
|
|
28
28
|
const apiOnly = await isApiOnly(appContext.appDirectory, resolvedConfig.source?.entriesDir, appContext.apiDirectory);
|
|
29
29
|
const [{ getProdServerRoutes }] = await Promise.all([
|
|
@@ -117,7 +117,7 @@ const analyze = ()=>({
|
|
|
117
117
|
htmlTemplates
|
|
118
118
|
};
|
|
119
119
|
api.updateAppContext(appContext);
|
|
120
|
-
if (checkIsBuildCommands(
|
|
120
|
+
if (checkIsBuildCommands()) {
|
|
121
121
|
await hooks.generateEntryCode.call({
|
|
122
122
|
entrypoints
|
|
123
123
|
});
|
|
@@ -9,14 +9,14 @@ const walkDirectory = (dir)=>fs.readdirSync(dir).reduce((previous, filename)=>{
|
|
|
9
9
|
...previous,
|
|
10
10
|
...walkDirectory(filePath)
|
|
11
11
|
];
|
|
12
|
-
return [
|
|
12
|
+
else return [
|
|
13
13
|
...previous,
|
|
14
14
|
filePath
|
|
15
15
|
];
|
|
16
16
|
}, []);
|
|
17
17
|
const replaceWithAlias = (base, filePath, alias)=>{
|
|
18
18
|
if (filePath.includes(base)) return normalizeToPosixPath(path.join(alias, path.relative(base, filePath)));
|
|
19
|
-
return filePath;
|
|
19
|
+
else return filePath;
|
|
20
20
|
};
|
|
21
21
|
const parseModule = async ({ source, filename })=>{
|
|
22
22
|
let content = source;
|
|
@@ -52,7 +52,7 @@ const parseModule = async ({ source, filename })=>{
|
|
|
52
52
|
return await parse(content);
|
|
53
53
|
};
|
|
54
54
|
const getServerCombinedModuleFile = (internalDirectory, entryName)=>path.join(internalDirectory, entryName, 'server-loader-combined.js');
|
|
55
|
-
const checkIsBuildCommands = (
|
|
55
|
+
const checkIsBuildCommands = ()=>{
|
|
56
56
|
const buildCommands = [
|
|
57
57
|
'dev',
|
|
58
58
|
'start',
|
|
@@ -62,8 +62,7 @@ const checkIsBuildCommands = (contextCommand)=>{
|
|
|
62
62
|
'dev-worker'
|
|
63
63
|
];
|
|
64
64
|
const command = getCommand();
|
|
65
|
-
|
|
66
|
-
return 'dev' === contextCommand || 'start' === contextCommand || 'build' === contextCommand || 'deploy' === contextCommand;
|
|
65
|
+
return buildCommands.includes(command);
|
|
67
66
|
};
|
|
68
67
|
const checkIsServeCommand = ()=>{
|
|
69
68
|
const command = getCommand();
|
|
@@ -25,7 +25,7 @@ const initialize = ()=>({
|
|
|
25
25
|
api.modifyResolvedConfig(async (resolved)=>{
|
|
26
26
|
let appContext = api.getAppContext();
|
|
27
27
|
const userConfig = api.getConfig();
|
|
28
|
-
const port = await getServerPort(resolved
|
|
28
|
+
const port = await getServerPort(resolved);
|
|
29
29
|
appContext = {
|
|
30
30
|
...appContext,
|
|
31
31
|
port,
|
|
@@ -60,10 +60,9 @@ function stabilizeConfig(resolve, config, keys) {
|
|
|
60
60
|
resolve[key] = config[key] || {};
|
|
61
61
|
});
|
|
62
62
|
}
|
|
63
|
-
async function getServerPort(config
|
|
63
|
+
async function getServerPort(config) {
|
|
64
64
|
const prodPort = Number(process.env.PORT) || config.server.port || 8080;
|
|
65
|
-
|
|
66
|
-
if (isDev() && (isDevCommand() || isProgrammaticDev)) return getPort(Number(process.env.PORT) || prodPort);
|
|
65
|
+
if (isDev() && isDevCommand()) return getPort(Number(process.env.PORT) || prodPort);
|
|
67
66
|
return prodPort;
|
|
68
67
|
}
|
|
69
68
|
export default initialize;
|
|
@@ -57,9 +57,8 @@ const build = async (api, options)=>{
|
|
|
57
57
|
logger.info('Starting production build...');
|
|
58
58
|
if (!appContext.builder) throw new Error('Expect the Builder to have been initialized, But the appContext.builder received `undefined`');
|
|
59
59
|
await appContext.builder.onAfterBuild(async ()=>copyEnvFiles(appContext.appDirectory, appContext.distDirectory));
|
|
60
|
-
|
|
60
|
+
await appContext.builder.build({
|
|
61
61
|
watch: options?.watch
|
|
62
62
|
});
|
|
63
|
-
if (!options?.watch) await buildResult?.close();
|
|
64
63
|
};
|
|
65
64
|
export { build };
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import "node:module";
|
|
2
2
|
import { getServerPlugins } from "../utils/loadPlugins.mjs";
|
|
3
|
-
import { build } from "./build.mjs";
|
|
4
3
|
const deploy = async (api, options = {})=>{
|
|
5
4
|
const hooks = api.getHooks();
|
|
6
5
|
const { metaName } = api.getAppContext();
|
|
7
|
-
|
|
8
|
-
else await build(api);
|
|
6
|
+
await getServerPlugins(api, metaName);
|
|
9
7
|
await hooks.onBeforeDeploy.call(options);
|
|
10
8
|
await hooks.deploy.call();
|
|
11
9
|
await hooks.onAfterDeploy.call(options);
|
|
@@ -20,6 +20,10 @@ const serverCommand = (program, api)=>{
|
|
|
20
20
|
};
|
|
21
21
|
const deployCommand = (program, api)=>{
|
|
22
22
|
program.command('deploy').usage('[options]').option('-c --config <config>', i18n.t(localeKeys.command.shared.config)).option('-s --skip-build', i18n.t(localeKeys.command.shared.skipBuild)).description(i18n.t(localeKeys.command.deploy.describe)).action(async (options)=>{
|
|
23
|
+
if (!options.skipBuild) {
|
|
24
|
+
const { build } = await import("./build.mjs");
|
|
25
|
+
await build(api);
|
|
26
|
+
}
|
|
23
27
|
const { deploy } = await import("./deploy.mjs");
|
|
24
28
|
await deploy(api, options);
|
|
25
29
|
process.exit(0);
|
|
@@ -60,7 +60,7 @@ function handleSetupResult(setupResult, api) {
|
|
|
60
60
|
if (newAPI && api[newAPI]) api[newAPI](async (...params)=>{
|
|
61
61
|
const { isMultiple, params: transformParams } = transformHookParams(key, params);
|
|
62
62
|
if (isMultiple) return transformHookResult(key, await fn(...transformParams));
|
|
63
|
-
return transformHookResult(key, await fn(transformParams));
|
|
63
|
+
else return transformHookResult(key, await fn(transformParams));
|
|
64
64
|
});
|
|
65
65
|
}
|
|
66
66
|
});
|
package/dist/esm-node/index.mjs
CHANGED
|
@@ -13,7 +13,6 @@ import analyze from "./plugins/analyze/index.mjs";
|
|
|
13
13
|
import deploy from "./plugins/deploy/index.mjs";
|
|
14
14
|
import initialize from "./plugins/initialize/index.mjs";
|
|
15
15
|
import serverBuild from "./plugins/serverBuild.mjs";
|
|
16
|
-
import serverRuntime from "./plugins/serverRuntime.mjs";
|
|
17
16
|
import { generateWatchFiles } from "./utils/generateWatchFiles.mjs";
|
|
18
17
|
import { initAppContext } from "./utils/initAppContext.mjs";
|
|
19
18
|
import { restart } from "./utils/restart.mjs";
|
|
@@ -22,7 +21,6 @@ export * from "./types/index.mjs";
|
|
|
22
21
|
const appTools = ()=>({
|
|
23
22
|
name: '@modern-js/app-tools',
|
|
24
23
|
usePlugins: [
|
|
25
|
-
serverRuntime(),
|
|
26
24
|
compatPlugin(),
|
|
27
25
|
initialize(),
|
|
28
26
|
analyze(),
|
|
@@ -79,18 +77,12 @@ const appTools = ()=>({
|
|
|
79
77
|
].some((tag)=>getArgv().includes(tag));
|
|
80
78
|
if (isSkipBuild) return;
|
|
81
79
|
}
|
|
82
|
-
|
|
83
|
-
const shouldClean = [
|
|
80
|
+
if ([
|
|
84
81
|
'dev',
|
|
85
82
|
'start',
|
|
86
83
|
'build',
|
|
87
84
|
'deploy'
|
|
88
|
-
].includes(command)
|
|
89
|
-
'dev',
|
|
90
|
-
'start',
|
|
91
|
-
'build'
|
|
92
|
-
].includes(contextCommand);
|
|
93
|
-
if (shouldClean) {
|
|
85
|
+
].includes(command)) {
|
|
94
86
|
const resolvedConfig = api.getNormalizedConfig();
|
|
95
87
|
if (resolvedConfig.output.cleanDistPath) {
|
|
96
88
|
const appContext = api.getAppContext();
|
|
@@ -130,8 +122,6 @@ const appTools = ()=>({
|
|
|
130
122
|
});
|
|
131
123
|
const src = appTools;
|
|
132
124
|
export { defineConfig } from "./defineConfig.mjs";
|
|
133
|
-
export { build } from "./commands/build.mjs";
|
|
134
|
-
export { deploy } from "./commands/deploy.mjs";
|
|
135
125
|
export { dev } from "./commands/dev.mjs";
|
|
136
126
|
export { serve } from "./commands/serve.mjs";
|
|
137
127
|
export { closeServer } from "./utils/createServer.mjs";
|
|
@@ -62,6 +62,6 @@ const getFileSystemEntry = async (hooks, appContext, config)=>{
|
|
|
62
62
|
}));
|
|
63
63
|
return scanDir(hooks, dirs);
|
|
64
64
|
} else throw Error("source.entriesDir accept a directory.");
|
|
65
|
-
throw Error(`src dir ${entriesDir} not found.`);
|
|
65
|
+
else throw Error(`src dir ${entriesDir} not found.`);
|
|
66
66
|
};
|
|
67
67
|
export { getFileSystemEntry, hasEntry, hasServerEntry };
|