@modern-js/plugin-v2 2.63.7 → 2.63.8-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/dist/cjs/cli/run/create.js +25 -14
- package/dist/cjs/hooks.js +74 -2
- package/dist/cjs/index.js +8 -2
- package/dist/cjs/manager.js +3 -5
- package/dist/cjs/runtime/api.js +79 -0
- package/dist/cjs/runtime/context.js +51 -0
- package/dist/cjs/runtime/hooks.js +36 -0
- package/dist/cjs/runtime/index.js +39 -0
- package/dist/cjs/runtime/run/create.js +74 -0
- package/dist/cjs/runtime/run/index.js +29 -0
- package/dist/cjs/runtime/run/types.js +16 -0
- package/dist/cjs/types/runtime/api.js +16 -0
- package/dist/cjs/types/runtime/context.js +16 -0
- package/dist/cjs/types/runtime/hooks.js +16 -0
- package/dist/cjs/types/runtime/index.js +16 -0
- package/dist/cjs/types/runtime/plugin.js +16 -0
- package/dist/esm/cli/api.js +103 -0
- package/dist/esm/cli/context.js +53 -0
- package/dist/esm/cli/hooks.js +42 -0
- package/dist/esm/cli/index.js +14 -0
- package/dist/esm/cli/run/config/createLoadedConfig.js +190 -0
- package/dist/esm/cli/run/config/createResolvedConfig.js +30 -0
- package/dist/esm/cli/run/config/loadConfig.js +210 -0
- package/dist/esm/cli/run/create.js +300 -0
- package/dist/esm/cli/run/index.js +10 -0
- package/dist/esm/cli/run/run.js +60 -0
- package/dist/esm/cli/run/types.js +0 -0
- package/dist/esm/cli/run/utils/checkIsDuplicationPlugin.js +24 -0
- package/dist/esm/cli/run/utils/commander.js +42 -0
- package/dist/esm/cli/run/utils/createFileWatcher.js +110 -0
- package/dist/esm/cli/run/utils/debug.js +5 -0
- package/dist/esm/cli/run/utils/initAppDir.js +36 -0
- package/dist/esm/cli/run/utils/loadEnv.js +24 -0
- package/dist/esm/cli/run/utils/mergeConfig.js +43 -0
- package/dist/esm/hooks.js +378 -0
- package/dist/esm/index.js +6 -357
- package/dist/esm/manager.js +161 -0
- package/dist/esm/runtime/api.js +59 -0
- package/dist/esm/runtime/context.js +25 -0
- package/dist/esm/runtime/hooks.js +12 -0
- package/dist/esm/runtime/index.js +11 -0
- package/dist/esm/runtime/run/create.js +72 -0
- package/dist/esm/runtime/run/index.js +5 -0
- package/dist/esm/runtime/run/types.js +0 -0
- package/dist/esm/types/cli/api.js +0 -0
- package/dist/esm/types/cli/context.js +0 -0
- package/dist/esm/types/cli/hooks.js +0 -0
- package/dist/esm/types/cli/index.js +0 -0
- package/dist/esm/types/cli/plugin.js +0 -0
- package/dist/esm/types/hooks.js +0 -0
- package/dist/esm/types/index.js +0 -0
- package/dist/esm/types/plugin.js +0 -0
- package/dist/esm/types/runtime/api.js +0 -0
- package/dist/esm/types/runtime/context.js +0 -0
- package/dist/esm/types/runtime/hooks.js +0 -0
- package/dist/esm/types/runtime/index.js +0 -0
- package/dist/esm/types/runtime/plugin.js +0 -0
- package/dist/esm/types/utils.js +0 -0
- package/dist/esm-node/cli/run/create.js +26 -15
- package/dist/esm-node/hooks.js +70 -1
- package/dist/esm-node/index.js +5 -2
- package/dist/esm-node/manager.js +2 -4
- package/dist/esm-node/runtime/api.js +55 -0
- package/dist/esm-node/runtime/context.js +26 -0
- package/dist/esm-node/runtime/hooks.js +12 -0
- package/dist/esm-node/runtime/index.js +11 -0
- package/dist/esm-node/runtime/run/create.js +50 -0
- package/dist/esm-node/runtime/run/index.js +5 -0
- package/dist/esm-node/runtime/run/types.js +0 -0
- package/dist/esm-node/types/runtime/api.js +0 -0
- package/dist/esm-node/types/runtime/context.js +0 -0
- package/dist/esm-node/types/runtime/hooks.js +0 -0
- package/dist/esm-node/types/runtime/index.js +0 -0
- package/dist/esm-node/types/runtime/plugin.js +0 -0
- package/dist/types/cli/run/create.d.ts +2 -1
- package/dist/types/hooks.d.ts +4 -1
- package/dist/types/index.d.ts +2 -1
- package/dist/types/manager.d.ts +3 -0
- package/dist/types/runtime/api.d.ts +9 -0
- package/dist/types/runtime/context.d.ts +11 -0
- package/dist/types/runtime/hooks.d.ts +2 -0
- package/dist/types/runtime/index.d.ts +5 -0
- package/dist/types/runtime/run/create.d.ts +7 -0
- package/dist/types/runtime/run/index.d.ts +5 -0
- package/dist/types/runtime/run/types.d.ts +6 -0
- package/dist/types/types/cli/hooks.d.ts +2 -2
- package/dist/types/types/hooks.d.ts +14 -2
- package/dist/types/types/index.d.ts +1 -0
- package/dist/types/types/plugin.d.ts +1 -1
- package/dist/types/types/runtime/api.d.ts +15 -0
- package/dist/types/types/runtime/context.d.ts +13 -0
- package/dist/types/types/runtime/hooks.d.ts +12 -0
- package/dist/types/types/runtime/index.d.ts +4 -0
- package/dist/types/types/runtime/plugin.d.ts +14 -0
- package/dist/types/types/utils.d.ts +1 -0
- package/package.json +15 -11
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
|
+
import { _ as _instanceof } from "@swc/helpers/_/_instanceof";
|
|
3
|
+
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
4
|
+
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
5
|
+
import { createDebugger, logger } from "@modern-js/utils";
|
|
6
|
+
import { program } from "@modern-js/utils/commander";
|
|
7
|
+
import { createPluginManager } from "../../manager";
|
|
8
|
+
import { initPluginAPI } from "../api";
|
|
9
|
+
import { createContext, initAppContext } from "../context";
|
|
10
|
+
import { createLoadedConfig } from "./config/createLoadedConfig";
|
|
11
|
+
import { createResolveConfig } from "./config/createResolvedConfig";
|
|
12
|
+
import { checkIsDuplicationPlugin } from "./utils/checkIsDuplicationPlugin";
|
|
13
|
+
import { initCommandsMap, setProgramVersion } from "./utils/commander";
|
|
14
|
+
import { createFileWatcher } from "./utils/createFileWatcher";
|
|
15
|
+
import { initAppDir } from "./utils/initAppDir";
|
|
16
|
+
import { loadEnv } from "./utils/loadEnv";
|
|
17
|
+
var debug = createDebugger("plugin-v2");
|
|
18
|
+
var createCli = function() {
|
|
19
|
+
var createExistListener = function createExistListener2(event, context) {
|
|
20
|
+
return function() {
|
|
21
|
+
var _ref = _async_to_generator(function(err) {
|
|
22
|
+
var hasError;
|
|
23
|
+
return _ts_generator(this, function(_state) {
|
|
24
|
+
switch (_state.label) {
|
|
25
|
+
case 0:
|
|
26
|
+
return [
|
|
27
|
+
4,
|
|
28
|
+
context.hooks.onBeforeExit.call()
|
|
29
|
+
];
|
|
30
|
+
case 1:
|
|
31
|
+
_state.sent();
|
|
32
|
+
hasError = false;
|
|
33
|
+
if (_instanceof(err, Error)) {
|
|
34
|
+
logger.error(err.stack);
|
|
35
|
+
hasError = true;
|
|
36
|
+
} else if (err && (event === "unhandledRejection" || event === "uncaughtException")) {
|
|
37
|
+
console.trace("Unknown Error", err);
|
|
38
|
+
hasError = true;
|
|
39
|
+
}
|
|
40
|
+
process.nextTick(function() {
|
|
41
|
+
process.exit(hasError ? 1 : 0);
|
|
42
|
+
});
|
|
43
|
+
return [
|
|
44
|
+
2
|
|
45
|
+
];
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
return function(err) {
|
|
50
|
+
return _ref.apply(this, arguments);
|
|
51
|
+
};
|
|
52
|
+
}();
|
|
53
|
+
};
|
|
54
|
+
var init = function init2(options) {
|
|
55
|
+
return _init.apply(this, arguments);
|
|
56
|
+
};
|
|
57
|
+
var run = function run2(options) {
|
|
58
|
+
return _run.apply(this, arguments);
|
|
59
|
+
};
|
|
60
|
+
var initOptions;
|
|
61
|
+
var pluginManager = createPluginManager();
|
|
62
|
+
var existListenerMap = /* @__PURE__ */ new Map();
|
|
63
|
+
function _init() {
|
|
64
|
+
_init = _async_to_generator(function(options) {
|
|
65
|
+
var _context_hooks_onAfterPrepare, _context_hooks, _options_metaName, metaName, configFile, config, command, version, packageJsonConfig, internalPlugins, handleSetupResult, appDirectory, loaded, allPlugins, plugins, context, pluginAPI, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, plugin, _plugin_setup, setupResult, err, extraConfigs, normalizedConfig, resolved;
|
|
66
|
+
return _ts_generator(this, function(_state) {
|
|
67
|
+
switch (_state.label) {
|
|
68
|
+
case 0:
|
|
69
|
+
pluginManager.clear();
|
|
70
|
+
initOptions = options;
|
|
71
|
+
_options_metaName = options.metaName, metaName = _options_metaName === void 0 ? "MODERN" : _options_metaName, configFile = options.configFile, config = options.config, command = options.command, version = options.version, packageJsonConfig = options.packageJsonConfig, internalPlugins = options.internalPlugins, handleSetupResult = options.handleSetupResult;
|
|
72
|
+
return [
|
|
73
|
+
4,
|
|
74
|
+
initAppDir(options === null || options === void 0 ? void 0 : options.cwd)
|
|
75
|
+
];
|
|
76
|
+
case 1:
|
|
77
|
+
appDirectory = _state.sent();
|
|
78
|
+
initCommandsMap();
|
|
79
|
+
setProgramVersion(version);
|
|
80
|
+
loadEnv(appDirectory, process.env["".concat(metaName.toUpperCase(), "_ENV")]);
|
|
81
|
+
return [
|
|
82
|
+
4,
|
|
83
|
+
createLoadedConfig(appDirectory, configFile, packageJsonConfig, config)
|
|
84
|
+
];
|
|
85
|
+
case 2:
|
|
86
|
+
loaded = _state.sent();
|
|
87
|
+
allPlugins = _to_consumable_array(internalPlugins || []).concat(_to_consumable_array(loaded.config.plugins || []));
|
|
88
|
+
checkIsDuplicationPlugin(allPlugins.map(function(plugin2) {
|
|
89
|
+
return plugin2.name;
|
|
90
|
+
}), loaded.config.autoLoadPlugins);
|
|
91
|
+
pluginManager.addPlugins(allPlugins);
|
|
92
|
+
return [
|
|
93
|
+
4,
|
|
94
|
+
pluginManager.getPlugins()
|
|
95
|
+
];
|
|
96
|
+
case 3:
|
|
97
|
+
plugins = _state.sent();
|
|
98
|
+
debug("CLI Plugins:", plugins.map(function(p) {
|
|
99
|
+
return p.name;
|
|
100
|
+
}));
|
|
101
|
+
return [
|
|
102
|
+
4,
|
|
103
|
+
createContext({
|
|
104
|
+
appContext: initAppContext({
|
|
105
|
+
packageName: loaded.packageName,
|
|
106
|
+
configFile: loaded.configFile,
|
|
107
|
+
command,
|
|
108
|
+
appDirectory,
|
|
109
|
+
plugins
|
|
110
|
+
}),
|
|
111
|
+
config: loaded.config,
|
|
112
|
+
normalizedConfig: {}
|
|
113
|
+
})
|
|
114
|
+
];
|
|
115
|
+
case 4:
|
|
116
|
+
context = _state.sent();
|
|
117
|
+
pluginAPI = initPluginAPI({
|
|
118
|
+
context,
|
|
119
|
+
pluginManager
|
|
120
|
+
});
|
|
121
|
+
context.pluginAPI = pluginAPI;
|
|
122
|
+
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
|
123
|
+
_state.label = 5;
|
|
124
|
+
case 5:
|
|
125
|
+
_state.trys.push([
|
|
126
|
+
5,
|
|
127
|
+
11,
|
|
128
|
+
12,
|
|
129
|
+
13
|
|
130
|
+
]);
|
|
131
|
+
_iterator = plugins[Symbol.iterator]();
|
|
132
|
+
_state.label = 6;
|
|
133
|
+
case 6:
|
|
134
|
+
if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done))
|
|
135
|
+
return [
|
|
136
|
+
3,
|
|
137
|
+
10
|
|
138
|
+
];
|
|
139
|
+
plugin = _step.value;
|
|
140
|
+
return [
|
|
141
|
+
4,
|
|
142
|
+
(_plugin_setup = plugin.setup) === null || _plugin_setup === void 0 ? void 0 : _plugin_setup.call(plugin, pluginAPI)
|
|
143
|
+
];
|
|
144
|
+
case 7:
|
|
145
|
+
setupResult = _state.sent();
|
|
146
|
+
if (!handleSetupResult)
|
|
147
|
+
return [
|
|
148
|
+
3,
|
|
149
|
+
9
|
|
150
|
+
];
|
|
151
|
+
return [
|
|
152
|
+
4,
|
|
153
|
+
handleSetupResult(setupResult, pluginAPI)
|
|
154
|
+
];
|
|
155
|
+
case 8:
|
|
156
|
+
_state.sent();
|
|
157
|
+
_state.label = 9;
|
|
158
|
+
case 9:
|
|
159
|
+
_iteratorNormalCompletion = true;
|
|
160
|
+
return [
|
|
161
|
+
3,
|
|
162
|
+
6
|
|
163
|
+
];
|
|
164
|
+
case 10:
|
|
165
|
+
return [
|
|
166
|
+
3,
|
|
167
|
+
13
|
|
168
|
+
];
|
|
169
|
+
case 11:
|
|
170
|
+
err = _state.sent();
|
|
171
|
+
_didIteratorError = true;
|
|
172
|
+
_iteratorError = err;
|
|
173
|
+
return [
|
|
174
|
+
3,
|
|
175
|
+
13
|
|
176
|
+
];
|
|
177
|
+
case 12:
|
|
178
|
+
try {
|
|
179
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
180
|
+
_iterator.return();
|
|
181
|
+
}
|
|
182
|
+
} finally {
|
|
183
|
+
if (_didIteratorError) {
|
|
184
|
+
throw _iteratorError;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return [
|
|
188
|
+
7
|
|
189
|
+
];
|
|
190
|
+
case 13:
|
|
191
|
+
[
|
|
192
|
+
"SIGINT",
|
|
193
|
+
"SIGTERM",
|
|
194
|
+
"unhandledRejection",
|
|
195
|
+
"uncaughtException"
|
|
196
|
+
].forEach(function(event) {
|
|
197
|
+
if (existListenerMap.get(event)) {
|
|
198
|
+
process.off(event, existListenerMap.get(event));
|
|
199
|
+
}
|
|
200
|
+
var existListener = createExistListener(event, context);
|
|
201
|
+
existListenerMap.set(event, existListener);
|
|
202
|
+
process.on(event, existListener);
|
|
203
|
+
});
|
|
204
|
+
return [
|
|
205
|
+
4,
|
|
206
|
+
context.hooks.config.call()
|
|
207
|
+
];
|
|
208
|
+
case 14:
|
|
209
|
+
extraConfigs = _state.sent();
|
|
210
|
+
return [
|
|
211
|
+
4,
|
|
212
|
+
createResolveConfig(loaded, extraConfigs)
|
|
213
|
+
];
|
|
214
|
+
case 15:
|
|
215
|
+
normalizedConfig = _state.sent();
|
|
216
|
+
return [
|
|
217
|
+
4,
|
|
218
|
+
context.hooks.modifyResolvedConfig.call(normalizedConfig)
|
|
219
|
+
];
|
|
220
|
+
case 16:
|
|
221
|
+
resolved = _state.sent();
|
|
222
|
+
context.normalizedConfig = resolved || normalizedConfig;
|
|
223
|
+
return [
|
|
224
|
+
4,
|
|
225
|
+
pluginAPI.updateAppContext(context)
|
|
226
|
+
];
|
|
227
|
+
case 17:
|
|
228
|
+
_state.sent();
|
|
229
|
+
return [
|
|
230
|
+
4,
|
|
231
|
+
context.hooks.onPrepare.call()
|
|
232
|
+
];
|
|
233
|
+
case 18:
|
|
234
|
+
_state.sent();
|
|
235
|
+
return [
|
|
236
|
+
4,
|
|
237
|
+
(_context_hooks = context.hooks) === null || _context_hooks === void 0 ? void 0 : (_context_hooks_onAfterPrepare = _context_hooks.onAfterPrepare) === null || _context_hooks_onAfterPrepare === void 0 ? void 0 : _context_hooks_onAfterPrepare.call()
|
|
238
|
+
];
|
|
239
|
+
case 19:
|
|
240
|
+
_state.sent();
|
|
241
|
+
return [
|
|
242
|
+
2,
|
|
243
|
+
{
|
|
244
|
+
appContext: context
|
|
245
|
+
}
|
|
246
|
+
];
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
return _init.apply(this, arguments);
|
|
251
|
+
}
|
|
252
|
+
function _run() {
|
|
253
|
+
_run = _async_to_generator(function(options) {
|
|
254
|
+
var _program_commands, appContext;
|
|
255
|
+
return _ts_generator(this, function(_state) {
|
|
256
|
+
switch (_state.label) {
|
|
257
|
+
case 0:
|
|
258
|
+
return [
|
|
259
|
+
4,
|
|
260
|
+
init(options)
|
|
261
|
+
];
|
|
262
|
+
case 1:
|
|
263
|
+
appContext = _state.sent().appContext;
|
|
264
|
+
return [
|
|
265
|
+
4,
|
|
266
|
+
appContext.hooks.addCommand.call({
|
|
267
|
+
program
|
|
268
|
+
})
|
|
269
|
+
];
|
|
270
|
+
case 2:
|
|
271
|
+
_state.sent();
|
|
272
|
+
return [
|
|
273
|
+
4,
|
|
274
|
+
createFileWatcher(appContext)
|
|
275
|
+
];
|
|
276
|
+
case 3:
|
|
277
|
+
_state.sent();
|
|
278
|
+
program.parse(process.argv);
|
|
279
|
+
if (!((_program_commands = program.commands) === null || _program_commands === void 0 ? void 0 : _program_commands.length)) {
|
|
280
|
+
logger.warn("No command found, please make sure you have registered plugins correctly.");
|
|
281
|
+
}
|
|
282
|
+
return [
|
|
283
|
+
2
|
|
284
|
+
];
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
});
|
|
288
|
+
return _run.apply(this, arguments);
|
|
289
|
+
}
|
|
290
|
+
return {
|
|
291
|
+
init,
|
|
292
|
+
run,
|
|
293
|
+
getPrevInitOptions: function() {
|
|
294
|
+
return initOptions;
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
};
|
|
298
|
+
export {
|
|
299
|
+
createCli
|
|
300
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
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_without_properties } from "@swc/helpers/_/_object_without_properties";
|
|
4
|
+
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
5
|
+
import { logger } from "@modern-js/utils";
|
|
6
|
+
import { cli } from ".";
|
|
7
|
+
var run = function() {
|
|
8
|
+
var _ref = _async_to_generator(function(options) {
|
|
9
|
+
var initialLog, version, cwd, configFile, params, command;
|
|
10
|
+
return _ts_generator(this, function(_state) {
|
|
11
|
+
switch (_state.label) {
|
|
12
|
+
case 0:
|
|
13
|
+
initialLog = options.initialLog, version = options.version, cwd = options.cwd, configFile = options.configFile, params = _object_without_properties(options, [
|
|
14
|
+
"initialLog",
|
|
15
|
+
"version",
|
|
16
|
+
"cwd",
|
|
17
|
+
"configFile"
|
|
18
|
+
]);
|
|
19
|
+
if (initialLog) {
|
|
20
|
+
logger.greet(" ".concat(initialLog, "\n"));
|
|
21
|
+
}
|
|
22
|
+
command = process.argv[2];
|
|
23
|
+
if (!process.env.NODE_ENV) {
|
|
24
|
+
if ([
|
|
25
|
+
"build",
|
|
26
|
+
"serve",
|
|
27
|
+
"deploy",
|
|
28
|
+
"analyze"
|
|
29
|
+
].includes(command)) {
|
|
30
|
+
process.env.NODE_ENV = "production";
|
|
31
|
+
} else if (command === "test") {
|
|
32
|
+
process.env.NODE_ENV = "test";
|
|
33
|
+
} else {
|
|
34
|
+
process.env.NODE_ENV = "development";
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return [
|
|
38
|
+
4,
|
|
39
|
+
cli.run(_object_spread({
|
|
40
|
+
version,
|
|
41
|
+
cwd,
|
|
42
|
+
command,
|
|
43
|
+
configFile
|
|
44
|
+
}, params))
|
|
45
|
+
];
|
|
46
|
+
case 1:
|
|
47
|
+
_state.sent();
|
|
48
|
+
return [
|
|
49
|
+
2
|
|
50
|
+
];
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
return function run2(options) {
|
|
55
|
+
return _ref.apply(this, arguments);
|
|
56
|
+
};
|
|
57
|
+
}();
|
|
58
|
+
export {
|
|
59
|
+
run
|
|
60
|
+
};
|
|
File without changes
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { logger } from "@modern-js/utils";
|
|
2
|
+
function checkIsDuplicationPlugin(plugins) {
|
|
3
|
+
var autoLoadPlugin = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
|
|
4
|
+
var set = /* @__PURE__ */ new Set();
|
|
5
|
+
var duplicationPlugins = [];
|
|
6
|
+
plugins.filter(function(plugin) {
|
|
7
|
+
return typeof plugin === "string";
|
|
8
|
+
}).forEach(function(plugin) {
|
|
9
|
+
if (set.has(plugin)) {
|
|
10
|
+
duplicationPlugins.push(plugin);
|
|
11
|
+
} else {
|
|
12
|
+
set.add(plugin);
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
if (duplicationPlugins.length > 0) {
|
|
16
|
+
logger.warn("Duplicate registration plugins: ".concat(duplicationPlugins.join(","), "."));
|
|
17
|
+
if (autoLoadPlugin) {
|
|
18
|
+
logger.warn("This is probably because you enabled `autoLoadPlugin` configuration and also registered these plugins manually");
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export {
|
|
23
|
+
checkIsDuplicationPlugin
|
|
24
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { program } from "@modern-js/utils";
|
|
2
|
+
var setProgramVersion = function() {
|
|
3
|
+
var version = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : "unknown";
|
|
4
|
+
var name = process.argv[1];
|
|
5
|
+
program.name(name).usage("<command> [options]").version(version);
|
|
6
|
+
};
|
|
7
|
+
function initCommandsMap() {
|
|
8
|
+
if (!program.hasOwnProperty("commandsMap")) {
|
|
9
|
+
Object.defineProperty(program, "commandsMap", {
|
|
10
|
+
get: function get() {
|
|
11
|
+
var map = /* @__PURE__ */ new Map();
|
|
12
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
|
13
|
+
try {
|
|
14
|
+
for (var _iterator = program.commands[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
15
|
+
var command = _step.value;
|
|
16
|
+
map.set(command._name, command);
|
|
17
|
+
}
|
|
18
|
+
} catch (err) {
|
|
19
|
+
_didIteratorError = true;
|
|
20
|
+
_iteratorError = err;
|
|
21
|
+
} finally {
|
|
22
|
+
try {
|
|
23
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
24
|
+
_iterator.return();
|
|
25
|
+
}
|
|
26
|
+
} finally {
|
|
27
|
+
if (_didIteratorError) {
|
|
28
|
+
throw _iteratorError;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return map;
|
|
33
|
+
},
|
|
34
|
+
configurable: false
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export {
|
|
39
|
+
initCommandsMap,
|
|
40
|
+
program,
|
|
41
|
+
setProgramVersion
|
|
42
|
+
};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
|
+
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
3
|
+
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
4
|
+
import crypto from "crypto";
|
|
5
|
+
import * as fs from "fs";
|
|
6
|
+
import * as path from "path";
|
|
7
|
+
import { chokidar, createDebugger, isDevCommand } from "@modern-js/utils";
|
|
8
|
+
var debug = createDebugger("watch-files");
|
|
9
|
+
var hashMap = /* @__PURE__ */ new Map();
|
|
10
|
+
var md5 = function(data) {
|
|
11
|
+
return crypto.createHash("md5").update(data).digest("hex");
|
|
12
|
+
};
|
|
13
|
+
var createFileWatcher = function() {
|
|
14
|
+
var _ref = _async_to_generator(function(appContext) {
|
|
15
|
+
var appDirectory, extraFiles, watched, privateWatched, isPrivate, watcher;
|
|
16
|
+
return _ts_generator(this, function(_state) {
|
|
17
|
+
switch (_state.label) {
|
|
18
|
+
case 0:
|
|
19
|
+
if (!isDevCommand())
|
|
20
|
+
return [
|
|
21
|
+
3,
|
|
22
|
+
2
|
|
23
|
+
];
|
|
24
|
+
appDirectory = appContext.appDirectory;
|
|
25
|
+
return [
|
|
26
|
+
4,
|
|
27
|
+
appContext.hooks.addWatchFiles.call()
|
|
28
|
+
];
|
|
29
|
+
case 1:
|
|
30
|
+
extraFiles = _state.sent();
|
|
31
|
+
watched = extraFiles.filter(function(extra) {
|
|
32
|
+
return Array.isArray(extra);
|
|
33
|
+
}).flat();
|
|
34
|
+
privateWatched = extraFiles.filter(function(extra) {
|
|
35
|
+
return !Array.isArray(extra) && extra.isPrivate;
|
|
36
|
+
}).map(function(extra) {
|
|
37
|
+
return extra.files;
|
|
38
|
+
}).flat();
|
|
39
|
+
isPrivate = function(filename) {
|
|
40
|
+
return privateWatched.some(function(ff) {
|
|
41
|
+
return path.resolve(appDirectory, filename).startsWith(ff);
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
debug("watched: %o", watched);
|
|
45
|
+
watcher = chokidar.watch(_to_consumable_array(watched).concat(_to_consumable_array(privateWatched)), {
|
|
46
|
+
cwd: appDirectory,
|
|
47
|
+
ignoreInitial: true,
|
|
48
|
+
ignorePermissionErrors: true,
|
|
49
|
+
ignored: [
|
|
50
|
+
"**/__test__/**",
|
|
51
|
+
"**/*.test.(js|jsx|ts|tsx)",
|
|
52
|
+
"**/*.spec.(js|jsx|ts|tsx)",
|
|
53
|
+
"**/*.stories.(js|jsx|ts|tsx)"
|
|
54
|
+
]
|
|
55
|
+
});
|
|
56
|
+
watcher.on("change", function(changed) {
|
|
57
|
+
var lastHash = hashMap.get(changed);
|
|
58
|
+
var currentHash = md5(fs.readFileSync(path.join(appDirectory, changed), "utf8"));
|
|
59
|
+
if (currentHash !== lastHash) {
|
|
60
|
+
debug("file change: %s", changed);
|
|
61
|
+
hashMap.set(changed, currentHash);
|
|
62
|
+
appContext.hooks.onFileChanged.call({
|
|
63
|
+
filename: changed,
|
|
64
|
+
eventType: "change",
|
|
65
|
+
isPrivate: isPrivate(changed)
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
watcher.on("add", function(changed) {
|
|
70
|
+
debug("add file: %s", changed);
|
|
71
|
+
var currentHash = md5(fs.readFileSync(path.join(appDirectory, changed), "utf8"));
|
|
72
|
+
hashMap.set(changed, currentHash);
|
|
73
|
+
appContext.hooks.onFileChanged.call({
|
|
74
|
+
filename: changed,
|
|
75
|
+
eventType: "add",
|
|
76
|
+
isPrivate: isPrivate(changed)
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
watcher.on("unlink", function(changed) {
|
|
80
|
+
debug("remove file: %s", changed);
|
|
81
|
+
if (hashMap.has(changed)) {
|
|
82
|
+
hashMap.delete(changed);
|
|
83
|
+
}
|
|
84
|
+
appContext.hooks.onFileChanged.call({
|
|
85
|
+
filename: changed,
|
|
86
|
+
eventType: "unlink",
|
|
87
|
+
isPrivate: isPrivate(changed)
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
watcher.on("error", function(err) {
|
|
91
|
+
throw err;
|
|
92
|
+
});
|
|
93
|
+
return [
|
|
94
|
+
2,
|
|
95
|
+
watcher
|
|
96
|
+
];
|
|
97
|
+
case 2:
|
|
98
|
+
return [
|
|
99
|
+
2
|
|
100
|
+
];
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
return function createFileWatcher2(appContext) {
|
|
105
|
+
return _ref.apply(this, arguments);
|
|
106
|
+
};
|
|
107
|
+
}();
|
|
108
|
+
export {
|
|
109
|
+
createFileWatcher
|
|
110
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
|
+
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import { pkgUp } from "@modern-js/utils";
|
|
5
|
+
var initAppDir = function() {
|
|
6
|
+
var _ref = _async_to_generator(function(currentDir) {
|
|
7
|
+
var cwd, pkg;
|
|
8
|
+
return _ts_generator(this, function(_state) {
|
|
9
|
+
switch (_state.label) {
|
|
10
|
+
case 0:
|
|
11
|
+
cwd = currentDir || process.cwd();
|
|
12
|
+
return [
|
|
13
|
+
4,
|
|
14
|
+
pkgUp({
|
|
15
|
+
cwd
|
|
16
|
+
})
|
|
17
|
+
];
|
|
18
|
+
case 1:
|
|
19
|
+
pkg = _state.sent();
|
|
20
|
+
if (!pkg) {
|
|
21
|
+
throw new Error("no package.json found in current work dir: ".concat(cwd));
|
|
22
|
+
}
|
|
23
|
+
return [
|
|
24
|
+
2,
|
|
25
|
+
path.dirname(pkg)
|
|
26
|
+
];
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
return function initAppDir2(currentDir) {
|
|
31
|
+
return _ref.apply(this, arguments);
|
|
32
|
+
};
|
|
33
|
+
}();
|
|
34
|
+
export {
|
|
35
|
+
initAppDir
|
|
36
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { dotenv, dotenvExpand } from "@modern-js/utils";
|
|
4
|
+
var loadEnv = function(appDirectory) {
|
|
5
|
+
var mode = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : process.env.NODE_ENV;
|
|
6
|
+
[
|
|
7
|
+
".env.".concat(mode, ".local"),
|
|
8
|
+
".env.local",
|
|
9
|
+
".env.".concat(mode),
|
|
10
|
+
".env"
|
|
11
|
+
].map(function(name) {
|
|
12
|
+
return path.resolve(appDirectory, name);
|
|
13
|
+
}).filter(function(filePath) {
|
|
14
|
+
return fs.existsSync(filePath) && !fs.statSync(filePath).isDirectory();
|
|
15
|
+
}).forEach(function(filePath) {
|
|
16
|
+
var envConfig = dotenv.config({
|
|
17
|
+
path: filePath
|
|
18
|
+
});
|
|
19
|
+
dotenvExpand(envConfig);
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
export {
|
|
23
|
+
loadEnv
|
|
24
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
2
|
+
import { _ as _type_of } from "@swc/helpers/_/_type_of";
|
|
3
|
+
import { ensureArray, isOverriddenConfigKey } from "@modern-js/utils";
|
|
4
|
+
import { isFunction, mergeWith } from "@modern-js/utils/lodash";
|
|
5
|
+
var mergeConfig = function(configs) {
|
|
6
|
+
return mergeWith.apply(void 0, [
|
|
7
|
+
{}
|
|
8
|
+
].concat(_to_consumable_array(configs), [
|
|
9
|
+
function(target, source, key) {
|
|
10
|
+
if (key === "designSystem" || key === "tailwindcss" && (typeof source === "undefined" ? "undefined" : _type_of(source)) === "object") {
|
|
11
|
+
return mergeWith({}, target !== null && target !== void 0 ? target : {}, source !== null && source !== void 0 ? source : {});
|
|
12
|
+
}
|
|
13
|
+
if (isOverriddenConfigKey(key)) {
|
|
14
|
+
return source !== null && source !== void 0 ? source : target;
|
|
15
|
+
}
|
|
16
|
+
if (Array.isArray(target) || Array.isArray(source)) {
|
|
17
|
+
if (target === void 0) {
|
|
18
|
+
return source;
|
|
19
|
+
}
|
|
20
|
+
if (source === void 0) {
|
|
21
|
+
return target;
|
|
22
|
+
}
|
|
23
|
+
return _to_consumable_array(ensureArray(target)).concat(_to_consumable_array(ensureArray(source)));
|
|
24
|
+
}
|
|
25
|
+
if (isFunction(target) || isFunction(source)) {
|
|
26
|
+
if (source === void 0) {
|
|
27
|
+
return target;
|
|
28
|
+
}
|
|
29
|
+
if (target === void 0) {
|
|
30
|
+
return source;
|
|
31
|
+
}
|
|
32
|
+
return [
|
|
33
|
+
target,
|
|
34
|
+
source
|
|
35
|
+
];
|
|
36
|
+
}
|
|
37
|
+
return void 0;
|
|
38
|
+
}
|
|
39
|
+
]));
|
|
40
|
+
};
|
|
41
|
+
export {
|
|
42
|
+
mergeConfig
|
|
43
|
+
};
|