@modern-js/app-tools 2.62.1-alpha.0 → 2.62.1
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 +2 -2
- package/dist/cjs/index.js +142 -4
- package/dist/esm/index.js +248 -2
- package/dist/esm-node/index.js +130 -2
- package/dist/types/index.d.ts +6 -2
- package/package.json +18 -26
- package/dist/cjs/new/compat/hooks.js +0 -160
- package/dist/cjs/new/compat/index.js +0 -52
- package/dist/cjs/new/compat/utils.js +0 -95
- package/dist/cjs/new/constants.js +0 -37
- package/dist/cjs/new/context.js +0 -63
- package/dist/cjs/new/getConfigFile.js +0 -41
- package/dist/cjs/new/index.js +0 -76
- package/dist/cjs/new/loadPlugins.js +0 -57
- package/dist/cjs/new/run.js +0 -66
- package/dist/cjs/new/types/index.js +0 -16
- package/dist/cjs/new/utils/index.js +0 -34
- package/dist/cjs/old.js +0 -179
- package/dist/esm/new/compat/hooks.js +0 -418
- package/dist/esm/new/compat/index.js +0 -30
- package/dist/esm/new/compat/utils.js +0 -69
- package/dist/esm/new/constants.js +0 -10
- package/dist/esm/new/context.js +0 -30
- package/dist/esm/new/getConfigFile.js +0 -11
- package/dist/esm/new/index.js +0 -52
- package/dist/esm/new/loadPlugins.js +0 -94
- package/dist/esm/new/run.js +0 -79
- package/dist/esm/new/types/index.js +0 -0
- package/dist/esm/new/utils/index.js +0 -33
- package/dist/esm/old.js +0 -258
- package/dist/esm-node/new/compat/hooks.js +0 -135
- package/dist/esm-node/new/compat/index.js +0 -28
- package/dist/esm-node/new/compat/utils.js +0 -69
- package/dist/esm-node/new/constants.js +0 -10
- package/dist/esm-node/new/context.js +0 -29
- package/dist/esm-node/new/getConfigFile.js +0 -7
- package/dist/esm-node/new/index.js +0 -49
- package/dist/esm-node/new/loadPlugins.js +0 -33
- package/dist/esm-node/new/run.js +0 -42
- package/dist/esm-node/new/types/index.js +0 -0
- package/dist/esm-node/new/utils/index.js +0 -10
- package/dist/esm-node/old.js +0 -140
- package/dist/types/new/compat/hooks.d.ts +0 -8
- package/dist/types/new/compat/index.d.ts +0 -4
- package/dist/types/new/compat/utils.d.ts +0 -6
- package/dist/types/new/constants.d.ts +0 -4
- package/dist/types/new/context.d.ts +0 -32
- package/dist/types/new/getConfigFile.d.ts +0 -1
- package/dist/types/new/index.d.ts +0 -15
- package/dist/types/new/loadPlugins.d.ts +0 -9
- package/dist/types/new/run.d.ts +0 -13
- package/dist/types/new/types/index.d.ts +0 -89
- package/dist/types/new/utils/index.d.ts +0 -1
- package/dist/types/old.d.ts +0 -20
package/bin/modern.js
CHANGED
@@ -10,10 +10,10 @@ if (!process.env.MODERN_JS_VERSION) {
|
|
10
10
|
process.env.MODERN_JS_VERSION = version;
|
11
11
|
}
|
12
12
|
|
13
|
-
require('
|
13
|
+
require('@modern-js/core/runBin').run({
|
14
14
|
internalPlugins: {
|
15
15
|
cli: INTERNAL_APP_TOOLS_PLUGINS,
|
16
16
|
autoLoad: INTERNAL_APP_TOOLS_RUNTIME_PLUGINS,
|
17
17
|
},
|
18
|
-
version
|
18
|
+
initialLog: `Modern.js Framework v${version}`,
|
19
19
|
});
|
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,26 +18,162 @@ 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, {
|
32
|
+
appTools: () => appTools,
|
22
33
|
default: () => src_default,
|
23
34
|
dev: () => import_dev.dev,
|
24
35
|
mergeConfig: () => import_core.mergeConfig
|
25
36
|
});
|
26
37
|
module.exports = __toCommonJS(src_exports);
|
27
|
-
var
|
28
|
-
|
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");
|
29
51
|
var import_dev = require("./commands/dev");
|
30
52
|
var import_core = require("@modern-js/core");
|
31
53
|
__reExport(src_exports, require("./defineConfig"), module.exports);
|
32
54
|
__reExport(src_exports, require("./types"), module.exports);
|
33
|
-
|
55
|
+
const appTools = (options = {
|
56
|
+
// default webpack to be compatible with original projects
|
57
|
+
bundler: "webpack"
|
58
|
+
}) => ({
|
59
|
+
name: "@modern-js/app-tools",
|
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 src_default = appTools;
|
34
172
|
// Annotate the CommonJS export names for ESM import in node:
|
35
173
|
0 && (module.exports = {
|
174
|
+
appTools,
|
36
175
|
dev,
|
37
176
|
mergeConfig,
|
38
|
-
...require("./new/index"),
|
39
177
|
...require("./defineConfig"),
|
40
178
|
...require("./types")
|
41
179
|
});
|
package/dist/esm/index.js
CHANGED
@@ -1,11 +1,257 @@
|
|
1
|
-
import {
|
2
|
-
|
1
|
+
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
2
|
+
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
3
|
+
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
4
|
+
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
5
|
+
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
6
|
+
import path from "path";
|
7
|
+
import { getLocaleLanguage } from "@modern-js/plugin-i18n/language-detector";
|
8
|
+
import { castArray } from "@modern-js/uni-builder";
|
9
|
+
import { cleanRequireCache, deprecatedCommands, emptyDir, getArgv, getCommand } from "@modern-js/utils";
|
10
|
+
import { hooks } from "./hooks";
|
11
|
+
import { i18n } from "./locale";
|
12
|
+
import analyzePlugin from "./plugins/analyze";
|
13
|
+
import deployPlugin from "./plugins/deploy";
|
14
|
+
import initializePlugin from "./plugins/initialize";
|
15
|
+
import serverBuildPlugin from "./plugins/serverBuild";
|
16
|
+
import { buildCommand, deployCommand, devCommand, inspectCommand, newCommand, serverCommand, upgradeCommand } from "./commands";
|
17
|
+
import { generateWatchFiles } from "./utils/generateWatchFiles";
|
18
|
+
import { restart } from "./utils/restart";
|
3
19
|
import { dev } from "./commands/dev";
|
4
20
|
import { mergeConfig } from "@modern-js/core";
|
5
21
|
export * from "./defineConfig";
|
6
22
|
export * from "./types";
|
23
|
+
var appTools = function() {
|
24
|
+
var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {
|
25
|
+
// default webpack to be compatible with original projects
|
26
|
+
bundler: "webpack"
|
27
|
+
};
|
28
|
+
return {
|
29
|
+
name: "@modern-js/app-tools",
|
30
|
+
post: [
|
31
|
+
"@modern-js/plugin-initialize",
|
32
|
+
"@modern-js/plugin-analyze",
|
33
|
+
"@modern-js/plugin-ssr",
|
34
|
+
"@modern-js/plugin-document",
|
35
|
+
"@modern-js/plugin-state",
|
36
|
+
"@modern-js/plugin-router",
|
37
|
+
"@modern-js/plugin-router-v5",
|
38
|
+
"@modern-js/plugin-polyfill"
|
39
|
+
],
|
40
|
+
registerHook: hooks,
|
41
|
+
usePlugins: [
|
42
|
+
initializePlugin({
|
43
|
+
bundler: (options === null || options === void 0 ? void 0 : options.bundler) && [
|
44
|
+
"rspack",
|
45
|
+
"experimental-rspack"
|
46
|
+
].includes(options.bundler) ? "rspack" : "webpack"
|
47
|
+
}),
|
48
|
+
analyzePlugin({
|
49
|
+
bundler: (options === null || options === void 0 ? void 0 : options.bundler) && [
|
50
|
+
"rspack",
|
51
|
+
"experimental-rspack"
|
52
|
+
].includes(options.bundler) ? "rspack" : "webpack"
|
53
|
+
}),
|
54
|
+
serverBuildPlugin(),
|
55
|
+
deployPlugin()
|
56
|
+
],
|
57
|
+
setup: function(api) {
|
58
|
+
var appContext = api.useAppContext();
|
59
|
+
api.setAppContext(_object_spread_props(_object_spread({}, appContext), {
|
60
|
+
toolsType: "app-tools"
|
61
|
+
}));
|
62
|
+
var locale = getLocaleLanguage();
|
63
|
+
i18n.changeLanguage({
|
64
|
+
locale
|
65
|
+
});
|
66
|
+
return {
|
67
|
+
beforeConfig: function beforeConfig() {
|
68
|
+
return _async_to_generator(function() {
|
69
|
+
var _userConfig_output, userConfig, appContext2;
|
70
|
+
return _ts_generator(this, function(_state) {
|
71
|
+
userConfig = api.useConfigContext();
|
72
|
+
appContext2 = api.useAppContext();
|
73
|
+
if ((_userConfig_output = userConfig.output) === null || _userConfig_output === void 0 ? void 0 : _userConfig_output.tempDir) {
|
74
|
+
api.setAppContext(_object_spread_props(_object_spread({}, appContext2), {
|
75
|
+
internalDirectory: path.resolve(appContext2.appDirectory, userConfig.output.tempDir)
|
76
|
+
}));
|
77
|
+
}
|
78
|
+
return [
|
79
|
+
2
|
80
|
+
];
|
81
|
+
});
|
82
|
+
})();
|
83
|
+
},
|
84
|
+
commands: function commands(param) {
|
85
|
+
var program = param.program;
|
86
|
+
return _async_to_generator(function() {
|
87
|
+
return _ts_generator(this, function(_state) {
|
88
|
+
switch (_state.label) {
|
89
|
+
case 0:
|
90
|
+
return [
|
91
|
+
4,
|
92
|
+
devCommand(program, api)
|
93
|
+
];
|
94
|
+
case 1:
|
95
|
+
_state.sent();
|
96
|
+
return [
|
97
|
+
4,
|
98
|
+
buildCommand(program, api)
|
99
|
+
];
|
100
|
+
case 2:
|
101
|
+
_state.sent();
|
102
|
+
serverCommand(program, api);
|
103
|
+
deployCommand(program, api);
|
104
|
+
newCommand(program, locale);
|
105
|
+
inspectCommand(program, api);
|
106
|
+
upgradeCommand(program);
|
107
|
+
deprecatedCommands(program);
|
108
|
+
return [
|
109
|
+
2
|
110
|
+
];
|
111
|
+
}
|
112
|
+
});
|
113
|
+
})();
|
114
|
+
},
|
115
|
+
prepare: function prepare() {
|
116
|
+
return _async_to_generator(function() {
|
117
|
+
var command, isSkipBuild, resolvedConfig, appContext2;
|
118
|
+
return _ts_generator(this, function(_state) {
|
119
|
+
switch (_state.label) {
|
120
|
+
case 0:
|
121
|
+
command = getCommand();
|
122
|
+
if (command === "deploy") {
|
123
|
+
isSkipBuild = [
|
124
|
+
"-s",
|
125
|
+
"--skip-build"
|
126
|
+
].some(function(tag) {
|
127
|
+
return getArgv().includes(tag);
|
128
|
+
});
|
129
|
+
if (isSkipBuild) {
|
130
|
+
return [
|
131
|
+
2
|
132
|
+
];
|
133
|
+
}
|
134
|
+
}
|
135
|
+
if (!(command === "dev" || command === "start" || command === "build" || command === "deploy"))
|
136
|
+
return [
|
137
|
+
3,
|
138
|
+
2
|
139
|
+
];
|
140
|
+
resolvedConfig = api.useResolvedConfigContext();
|
141
|
+
if (!resolvedConfig.output.cleanDistPath)
|
142
|
+
return [
|
143
|
+
3,
|
144
|
+
2
|
145
|
+
];
|
146
|
+
appContext2 = api.useAppContext();
|
147
|
+
return [
|
148
|
+
4,
|
149
|
+
emptyDir(appContext2.distDirectory)
|
150
|
+
];
|
151
|
+
case 1:
|
152
|
+
_state.sent();
|
153
|
+
_state.label = 2;
|
154
|
+
case 2:
|
155
|
+
return [
|
156
|
+
2
|
157
|
+
];
|
158
|
+
}
|
159
|
+
});
|
160
|
+
})();
|
161
|
+
},
|
162
|
+
watchFiles: function watchFiles() {
|
163
|
+
return _async_to_generator(function() {
|
164
|
+
var appContext2, config, files, watchFiles2;
|
165
|
+
return _ts_generator(this, function(_state) {
|
166
|
+
switch (_state.label) {
|
167
|
+
case 0:
|
168
|
+
appContext2 = api.useAppContext();
|
169
|
+
config = api.useResolvedConfigContext();
|
170
|
+
return [
|
171
|
+
4,
|
172
|
+
generateWatchFiles(appContext2, config.source.configDir)
|
173
|
+
];
|
174
|
+
case 1:
|
175
|
+
files = _state.sent();
|
176
|
+
watchFiles2 = castArray(config.dev.watchFiles);
|
177
|
+
watchFiles2.forEach(function(param) {
|
178
|
+
var type = param.type, paths = param.paths;
|
179
|
+
if (type === "reload-server") {
|
180
|
+
var _files;
|
181
|
+
(_files = files).push.apply(_files, _to_consumable_array(Array.isArray(paths) ? paths : [
|
182
|
+
paths
|
183
|
+
]));
|
184
|
+
}
|
185
|
+
});
|
186
|
+
return [
|
187
|
+
2,
|
188
|
+
files
|
189
|
+
];
|
190
|
+
}
|
191
|
+
});
|
192
|
+
})();
|
193
|
+
},
|
194
|
+
fileChange: (
|
195
|
+
// 这里会被 core/initWatcher 监听的文件变动触发,如果是 src 目录下的文件变动,则不做 restart
|
196
|
+
function fileChange(e) {
|
197
|
+
return _async_to_generator(function() {
|
198
|
+
var filename, eventType, isPrivate, closeServer;
|
199
|
+
return _ts_generator(this, function(_state) {
|
200
|
+
switch (_state.label) {
|
201
|
+
case 0:
|
202
|
+
filename = e.filename, eventType = e.eventType, isPrivate = e.isPrivate;
|
203
|
+
if (!(!isPrivate && (eventType === "change" || eventType === "unlink")))
|
204
|
+
return [
|
205
|
+
3,
|
206
|
+
4
|
207
|
+
];
|
208
|
+
return [
|
209
|
+
4,
|
210
|
+
import("./utils/createServer.js")
|
211
|
+
];
|
212
|
+
case 1:
|
213
|
+
closeServer = _state.sent().closeServer;
|
214
|
+
return [
|
215
|
+
4,
|
216
|
+
closeServer()
|
217
|
+
];
|
218
|
+
case 2:
|
219
|
+
_state.sent();
|
220
|
+
return [
|
221
|
+
4,
|
222
|
+
restart(api.useHookRunners(), filename)
|
223
|
+
];
|
224
|
+
case 3:
|
225
|
+
_state.sent();
|
226
|
+
_state.label = 4;
|
227
|
+
case 4:
|
228
|
+
return [
|
229
|
+
2
|
230
|
+
];
|
231
|
+
}
|
232
|
+
});
|
233
|
+
})();
|
234
|
+
}
|
235
|
+
),
|
236
|
+
beforeRestart: function beforeRestart() {
|
237
|
+
return _async_to_generator(function() {
|
238
|
+
return _ts_generator(this, function(_state) {
|
239
|
+
cleanRequireCache([
|
240
|
+
require.resolve("./plugins/analyze")
|
241
|
+
]);
|
242
|
+
return [
|
243
|
+
2
|
244
|
+
];
|
245
|
+
});
|
246
|
+
})();
|
247
|
+
}
|
248
|
+
};
|
249
|
+
}
|
250
|
+
};
|
251
|
+
};
|
7
252
|
var src_default = appTools;
|
8
253
|
export {
|
254
|
+
appTools,
|
9
255
|
src_default as default,
|
10
256
|
dev,
|
11
257
|
mergeConfig
|
package/dist/esm-node/index.js
CHANGED
@@ -1,11 +1,139 @@
|
|
1
|
-
import
|
2
|
-
|
1
|
+
import path from "path";
|
2
|
+
import { getLocaleLanguage } from "@modern-js/plugin-i18n/language-detector";
|
3
|
+
import { castArray } from "@modern-js/uni-builder";
|
4
|
+
import { cleanRequireCache, deprecatedCommands, emptyDir, getArgv, getCommand } from "@modern-js/utils";
|
5
|
+
import { hooks } from "./hooks";
|
6
|
+
import { i18n } from "./locale";
|
7
|
+
import analyzePlugin from "./plugins/analyze";
|
8
|
+
import deployPlugin from "./plugins/deploy";
|
9
|
+
import initializePlugin from "./plugins/initialize";
|
10
|
+
import serverBuildPlugin from "./plugins/serverBuild";
|
11
|
+
import { buildCommand, deployCommand, devCommand, inspectCommand, newCommand, serverCommand, upgradeCommand } from "./commands";
|
12
|
+
import { generateWatchFiles } from "./utils/generateWatchFiles";
|
13
|
+
import { restart } from "./utils/restart";
|
3
14
|
import { dev } from "./commands/dev";
|
4
15
|
import { mergeConfig } from "@modern-js/core";
|
5
16
|
export * from "./defineConfig";
|
6
17
|
export * from "./types";
|
18
|
+
const appTools = (options = {
|
19
|
+
// default webpack to be compatible with original projects
|
20
|
+
bundler: "webpack"
|
21
|
+
}) => ({
|
22
|
+
name: "@modern-js/app-tools",
|
23
|
+
post: [
|
24
|
+
"@modern-js/plugin-initialize",
|
25
|
+
"@modern-js/plugin-analyze",
|
26
|
+
"@modern-js/plugin-ssr",
|
27
|
+
"@modern-js/plugin-document",
|
28
|
+
"@modern-js/plugin-state",
|
29
|
+
"@modern-js/plugin-router",
|
30
|
+
"@modern-js/plugin-router-v5",
|
31
|
+
"@modern-js/plugin-polyfill"
|
32
|
+
],
|
33
|
+
registerHook: hooks,
|
34
|
+
usePlugins: [
|
35
|
+
initializePlugin({
|
36
|
+
bundler: (options === null || options === void 0 ? void 0 : options.bundler) && [
|
37
|
+
"rspack",
|
38
|
+
"experimental-rspack"
|
39
|
+
].includes(options.bundler) ? "rspack" : "webpack"
|
40
|
+
}),
|
41
|
+
analyzePlugin({
|
42
|
+
bundler: (options === null || options === void 0 ? void 0 : options.bundler) && [
|
43
|
+
"rspack",
|
44
|
+
"experimental-rspack"
|
45
|
+
].includes(options.bundler) ? "rspack" : "webpack"
|
46
|
+
}),
|
47
|
+
serverBuildPlugin(),
|
48
|
+
deployPlugin()
|
49
|
+
],
|
50
|
+
setup: (api) => {
|
51
|
+
const appContext = api.useAppContext();
|
52
|
+
api.setAppContext({
|
53
|
+
...appContext,
|
54
|
+
toolsType: "app-tools"
|
55
|
+
});
|
56
|
+
const locale = getLocaleLanguage();
|
57
|
+
i18n.changeLanguage({
|
58
|
+
locale
|
59
|
+
});
|
60
|
+
return {
|
61
|
+
async beforeConfig() {
|
62
|
+
var _userConfig_output;
|
63
|
+
const userConfig = api.useConfigContext();
|
64
|
+
const appContext2 = api.useAppContext();
|
65
|
+
if ((_userConfig_output = userConfig.output) === null || _userConfig_output === void 0 ? void 0 : _userConfig_output.tempDir) {
|
66
|
+
api.setAppContext({
|
67
|
+
...appContext2,
|
68
|
+
internalDirectory: path.resolve(appContext2.appDirectory, userConfig.output.tempDir)
|
69
|
+
});
|
70
|
+
}
|
71
|
+
},
|
72
|
+
async commands({ program }) {
|
73
|
+
await devCommand(program, api);
|
74
|
+
await buildCommand(program, api);
|
75
|
+
serverCommand(program, api);
|
76
|
+
deployCommand(program, api);
|
77
|
+
newCommand(program, locale);
|
78
|
+
inspectCommand(program, api);
|
79
|
+
upgradeCommand(program);
|
80
|
+
deprecatedCommands(program);
|
81
|
+
},
|
82
|
+
async prepare() {
|
83
|
+
const command = getCommand();
|
84
|
+
if (command === "deploy") {
|
85
|
+
const isSkipBuild = [
|
86
|
+
"-s",
|
87
|
+
"--skip-build"
|
88
|
+
].some((tag) => {
|
89
|
+
return getArgv().includes(tag);
|
90
|
+
});
|
91
|
+
if (isSkipBuild) {
|
92
|
+
return;
|
93
|
+
}
|
94
|
+
}
|
95
|
+
if (command === "dev" || command === "start" || command === "build" || command === "deploy") {
|
96
|
+
const resolvedConfig = api.useResolvedConfigContext();
|
97
|
+
if (resolvedConfig.output.cleanDistPath) {
|
98
|
+
const appContext2 = api.useAppContext();
|
99
|
+
await emptyDir(appContext2.distDirectory);
|
100
|
+
}
|
101
|
+
}
|
102
|
+
},
|
103
|
+
async watchFiles() {
|
104
|
+
const appContext2 = api.useAppContext();
|
105
|
+
const config = api.useResolvedConfigContext();
|
106
|
+
const files = await generateWatchFiles(appContext2, config.source.configDir);
|
107
|
+
const watchFiles = castArray(config.dev.watchFiles);
|
108
|
+
watchFiles.forEach(({ type, paths }) => {
|
109
|
+
if (type === "reload-server") {
|
110
|
+
files.push(...Array.isArray(paths) ? paths : [
|
111
|
+
paths
|
112
|
+
]);
|
113
|
+
}
|
114
|
+
});
|
115
|
+
return files;
|
116
|
+
},
|
117
|
+
// 这里会被 core/initWatcher 监听的文件变动触发,如果是 src 目录下的文件变动,则不做 restart
|
118
|
+
async fileChange(e) {
|
119
|
+
const { filename, eventType, isPrivate } = e;
|
120
|
+
if (!isPrivate && (eventType === "change" || eventType === "unlink")) {
|
121
|
+
const { closeServer } = await import("./utils/createServer.js");
|
122
|
+
await closeServer();
|
123
|
+
await restart(api.useHookRunners(), filename);
|
124
|
+
}
|
125
|
+
},
|
126
|
+
async beforeRestart() {
|
127
|
+
cleanRequireCache([
|
128
|
+
require.resolve("./plugins/analyze")
|
129
|
+
]);
|
130
|
+
}
|
131
|
+
};
|
132
|
+
}
|
133
|
+
});
|
7
134
|
var src_default = appTools;
|
8
135
|
export {
|
136
|
+
appTools,
|
9
137
|
src_default as default,
|
10
138
|
dev,
|
11
139
|
mergeConfig
|
package/dist/types/index.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import {
|
2
|
-
|
1
|
+
import type { CliPlugin } from '@modern-js/core';
|
2
|
+
import type { AppTools } from './types';
|
3
3
|
export { dev } from './commands/dev';
|
4
4
|
export type { DevOptions } from './utils/types';
|
5
5
|
export { mergeConfig } from '@modern-js/core';
|
@@ -13,4 +13,8 @@ export type AppToolsOptions = {
|
|
13
13
|
* */
|
14
14
|
bundler?: 'rspack' | 'webpack' | 'experimental-rspack';
|
15
15
|
};
|
16
|
+
/**
|
17
|
+
* The core package of the framework, providing CLI commands, build capabilities, configuration parsing and more.
|
18
|
+
*/
|
19
|
+
export declare const appTools: (options?: AppToolsOptions) => CliPlugin<AppTools<'shared'>>;
|
16
20
|
export default appTools;
|