@modern-js/plugin-v2 2.64.0 → 2.64.1-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/cli/run/config/loadConfig.js +15 -19
- package/dist/cjs/cli/run/create.js +23 -14
- package/dist/esm/cli/run/config/loadConfig.js +37 -112
- package/dist/esm/cli/run/create.js +42 -33
- package/dist/esm-node/cli/run/config/loadConfig.js +16 -20
- package/dist/esm-node/cli/run/create.js +23 -14
- package/dist/types/cli/hooks.d.ts +4 -4
- package/dist/types/cli/run/create.d.ts +2 -1
- package/dist/types/cli/run/index.d.ts +4 -4
- package/dist/types/types/cli/api.d.ts +3 -3
- package/dist/types/types/cli/context.d.ts +1 -1
- package/dist/types/types/cli/hooks.d.ts +4 -5
- package/dist/types/types/cli/plugin.d.ts +2 -1
- package/dist/types/types/hooks.d.ts +2 -2
- package/package.json +4 -5
|
@@ -35,8 +35,8 @@ __export(loadConfig_exports, {
|
|
|
35
35
|
});
|
|
36
36
|
module.exports = __toCommonJS(loadConfig_exports);
|
|
37
37
|
var import_path = __toESM(require("path"));
|
|
38
|
-
var import_node_bundle_require = require("@modern-js/node-bundle-require");
|
|
39
38
|
var import_utils = require("@modern-js/utils");
|
|
39
|
+
var import_jiti = __toESM(require("jiti"));
|
|
40
40
|
const getPackageConfig = (appDirectory, packageJsonConfig) => {
|
|
41
41
|
const json = JSON.parse(import_utils.fs.readFileSync(import_path.default.resolve(appDirectory, "./package.json"), "utf8"));
|
|
42
42
|
return json[packageJsonConfig];
|
|
@@ -64,19 +64,19 @@ const clearFilesOverTime = async (targetDir, overtime) => {
|
|
|
64
64
|
} catch (err) {
|
|
65
65
|
}
|
|
66
66
|
};
|
|
67
|
-
|
|
67
|
+
function loadConfigContent(configFile) {
|
|
68
|
+
const _require = (0, import_jiti.default)(__filename, {
|
|
69
|
+
esmResolve: true,
|
|
70
|
+
// disable require cache to support restart CLI and read the new config
|
|
71
|
+
requireCache: false,
|
|
72
|
+
interopDefault: true
|
|
73
|
+
});
|
|
74
|
+
if (!import_utils.fs.existsSync(configFile)) {
|
|
75
|
+
throw new Error(`Configuration file does not exist: ${configFile}`);
|
|
76
|
+
}
|
|
68
77
|
try {
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
getOutputFile: async (filePath) => {
|
|
72
|
-
const defaultOutputFileName = import_path.default.basename(await (0, import_node_bundle_require.defaultGetOutputFile)(filePath));
|
|
73
|
-
const outputPath = import_path.default.join(appDirectory, import_utils.CONFIG_CACHE_DIR);
|
|
74
|
-
const timeLimit = 10 * 60;
|
|
75
|
-
await clearFilesOverTime(outputPath, timeLimit);
|
|
76
|
-
return import_path.default.join(outputPath, defaultOutputFileName);
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
return mod;
|
|
78
|
+
const config = _require(configFile);
|
|
79
|
+
return config.default || config;
|
|
80
80
|
} catch (e) {
|
|
81
81
|
if (e instanceof Error) {
|
|
82
82
|
e.message = `Get Error while loading config file: ${configFile}, please check it and retry.
|
|
@@ -84,7 +84,7 @@ ${e.message || ""}`;
|
|
|
84
84
|
}
|
|
85
85
|
throw e;
|
|
86
86
|
}
|
|
87
|
-
}
|
|
87
|
+
}
|
|
88
88
|
const loadConfig = async (appDirectory, configFile, packageJsonConfig) => {
|
|
89
89
|
let pkgConfig;
|
|
90
90
|
if (packageJsonConfig) {
|
|
@@ -93,11 +93,7 @@ const loadConfig = async (appDirectory, configFile, packageJsonConfig) => {
|
|
|
93
93
|
const packageName = require(import_path.default.resolve(appDirectory, "./package.json")).name;
|
|
94
94
|
let config;
|
|
95
95
|
if (configFile) {
|
|
96
|
-
|
|
97
|
-
const mod = await bundleRequireWithCatch(configFile, {
|
|
98
|
-
appDirectory
|
|
99
|
-
});
|
|
100
|
-
config = mod.default || mod;
|
|
96
|
+
config = loadConfigContent(configFile);
|
|
101
97
|
}
|
|
102
98
|
return {
|
|
103
99
|
packageName,
|
|
@@ -37,6 +37,23 @@ const debug = (0, import_utils.createDebugger)("plugin-v2");
|
|
|
37
37
|
const createCli = () => {
|
|
38
38
|
let initOptions;
|
|
39
39
|
const pluginManager = (0, import_manager.createPluginManager)();
|
|
40
|
+
const existListenerMap = /* @__PURE__ */ new Map();
|
|
41
|
+
function createExistListener(event, context) {
|
|
42
|
+
return async function(err) {
|
|
43
|
+
await context.hooks.onBeforeExit.call();
|
|
44
|
+
let hasError = false;
|
|
45
|
+
if (err instanceof Error) {
|
|
46
|
+
import_utils.logger.error(err.stack);
|
|
47
|
+
hasError = true;
|
|
48
|
+
} else if (err && (event === "unhandledRejection" || event === "uncaughtException")) {
|
|
49
|
+
console.trace("Unknown Error", err);
|
|
50
|
+
hasError = true;
|
|
51
|
+
}
|
|
52
|
+
process.nextTick(() => {
|
|
53
|
+
process.exit(hasError ? 1 : 0);
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
}
|
|
40
57
|
async function init(options) {
|
|
41
58
|
var _context_hooks_onAfterPrepare, _context_hooks;
|
|
42
59
|
pluginManager.clear();
|
|
@@ -84,20 +101,12 @@ const createCli = () => {
|
|
|
84
101
|
"unhandledRejection",
|
|
85
102
|
"uncaughtException"
|
|
86
103
|
].forEach((event) => {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
} else if (err && (event === "unhandledRejection" || event === "uncaughtException")) {
|
|
94
|
-
console.trace("Unknown Error", err);
|
|
95
|
-
hasError = true;
|
|
96
|
-
}
|
|
97
|
-
process.nextTick(() => {
|
|
98
|
-
process.exit(hasError ? 1 : 0);
|
|
99
|
-
});
|
|
100
|
-
});
|
|
104
|
+
if (existListenerMap.get(event)) {
|
|
105
|
+
process.off(event, existListenerMap.get(event));
|
|
106
|
+
}
|
|
107
|
+
const existListener = createExistListener(event, context);
|
|
108
|
+
existListenerMap.set(event, existListener);
|
|
109
|
+
process.on(event, existListener);
|
|
101
110
|
});
|
|
102
111
|
const extraConfigs = await context.hooks.config.call();
|
|
103
112
|
const normalizedConfig = await (0, import_createResolvedConfig.createResolveConfig)(loaded, extraConfigs);
|
|
@@ -2,8 +2,8 @@ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
|
2
2
|
import { _ as _instanceof } from "@swc/helpers/_/_instanceof";
|
|
3
3
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
4
4
|
import path from "path";
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
5
|
+
import { fs, globby } from "@modern-js/utils";
|
|
6
|
+
import jiti from "jiti";
|
|
7
7
|
var getPackageConfig = function(appDirectory, packageJsonConfig) {
|
|
8
8
|
var json = JSON.parse(fs.readFileSync(path.resolve(appDirectory, "./package.json"), "utf8"));
|
|
9
9
|
return json[packageJsonConfig];
|
|
@@ -81,121 +81,46 @@ var clearFilesOverTime = function() {
|
|
|
81
81
|
return _ref.apply(this, arguments);
|
|
82
82
|
};
|
|
83
83
|
}();
|
|
84
|
-
|
|
85
|
-
var
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
appDirectory = param.appDirectory;
|
|
91
|
-
_state.label = 1;
|
|
92
|
-
case 1:
|
|
93
|
-
_state.trys.push([
|
|
94
|
-
1,
|
|
95
|
-
3,
|
|
96
|
-
,
|
|
97
|
-
4
|
|
98
|
-
]);
|
|
99
|
-
return [
|
|
100
|
-
4,
|
|
101
|
-
bundleRequire(configFile, {
|
|
102
|
-
autoClear: false,
|
|
103
|
-
getOutputFile: function() {
|
|
104
|
-
var _ref2 = _async_to_generator(function(filePath) {
|
|
105
|
-
var defaultOutputFileName, _, outputPath, timeLimit;
|
|
106
|
-
return _ts_generator(this, function(_state2) {
|
|
107
|
-
switch (_state2.label) {
|
|
108
|
-
case 0:
|
|
109
|
-
_ = path.basename;
|
|
110
|
-
return [
|
|
111
|
-
4,
|
|
112
|
-
defaultGetOutputFile(filePath)
|
|
113
|
-
];
|
|
114
|
-
case 1:
|
|
115
|
-
defaultOutputFileName = _.apply(path, [
|
|
116
|
-
_state2.sent()
|
|
117
|
-
]);
|
|
118
|
-
outputPath = path.join(appDirectory, CONFIG_CACHE_DIR);
|
|
119
|
-
timeLimit = 10 * 60;
|
|
120
|
-
return [
|
|
121
|
-
4,
|
|
122
|
-
clearFilesOverTime(outputPath, timeLimit)
|
|
123
|
-
];
|
|
124
|
-
case 2:
|
|
125
|
-
_state2.sent();
|
|
126
|
-
return [
|
|
127
|
-
2,
|
|
128
|
-
path.join(outputPath, defaultOutputFileName)
|
|
129
|
-
];
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
});
|
|
133
|
-
return function(filePath) {
|
|
134
|
-
return _ref2.apply(this, arguments);
|
|
135
|
-
};
|
|
136
|
-
}()
|
|
137
|
-
})
|
|
138
|
-
];
|
|
139
|
-
case 2:
|
|
140
|
-
mod = _state.sent();
|
|
141
|
-
return [
|
|
142
|
-
2,
|
|
143
|
-
mod
|
|
144
|
-
];
|
|
145
|
-
case 3:
|
|
146
|
-
e = _state.sent();
|
|
147
|
-
if (_instanceof(e, Error)) {
|
|
148
|
-
e.message = "Get Error while loading config file: ".concat(configFile, ", please check it and retry.\n").concat(e.message || "");
|
|
149
|
-
}
|
|
150
|
-
throw e;
|
|
151
|
-
case 4:
|
|
152
|
-
return [
|
|
153
|
-
2
|
|
154
|
-
];
|
|
155
|
-
}
|
|
156
|
-
});
|
|
84
|
+
function loadConfigContent(configFile) {
|
|
85
|
+
var _require = jiti(__filename, {
|
|
86
|
+
esmResolve: true,
|
|
87
|
+
// disable require cache to support restart CLI and read the new config
|
|
88
|
+
requireCache: false,
|
|
89
|
+
interopDefault: true
|
|
157
90
|
});
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
}
|
|
161
|
-
|
|
91
|
+
if (!fs.existsSync(configFile)) {
|
|
92
|
+
throw new Error("Configuration file does not exist: ".concat(configFile));
|
|
93
|
+
}
|
|
94
|
+
try {
|
|
95
|
+
var config = _require(configFile);
|
|
96
|
+
return config.default || config;
|
|
97
|
+
} catch (e) {
|
|
98
|
+
if (_instanceof(e, Error)) {
|
|
99
|
+
e.message = "Get Error while loading config file: ".concat(configFile, ", please check it and retry.\n").concat(e.message || "");
|
|
100
|
+
}
|
|
101
|
+
throw e;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
162
104
|
var loadConfig = function() {
|
|
163
105
|
var _ref = _async_to_generator(function(appDirectory, configFile, packageJsonConfig) {
|
|
164
|
-
var pkgConfig, packageName, config
|
|
106
|
+
var pkgConfig, packageName, config;
|
|
165
107
|
return _ts_generator(this, function(_state) {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
if (!configFile)
|
|
173
|
-
return [
|
|
174
|
-
3,
|
|
175
|
-
2
|
|
176
|
-
];
|
|
177
|
-
delete require.cache[configFile];
|
|
178
|
-
return [
|
|
179
|
-
4,
|
|
180
|
-
bundleRequireWithCatch(configFile, {
|
|
181
|
-
appDirectory
|
|
182
|
-
})
|
|
183
|
-
];
|
|
184
|
-
case 1:
|
|
185
|
-
mod = _state.sent();
|
|
186
|
-
config = mod.default || mod;
|
|
187
|
-
_state.label = 2;
|
|
188
|
-
case 2:
|
|
189
|
-
return [
|
|
190
|
-
2,
|
|
191
|
-
{
|
|
192
|
-
packageName,
|
|
193
|
-
configFile,
|
|
194
|
-
config,
|
|
195
|
-
pkgConfig
|
|
196
|
-
}
|
|
197
|
-
];
|
|
108
|
+
if (packageJsonConfig) {
|
|
109
|
+
pkgConfig = getPackageConfig(appDirectory, packageJsonConfig);
|
|
110
|
+
}
|
|
111
|
+
packageName = require(path.resolve(appDirectory, "./package.json")).name;
|
|
112
|
+
if (configFile) {
|
|
113
|
+
config = loadConfigContent(configFile);
|
|
198
114
|
}
|
|
115
|
+
return [
|
|
116
|
+
2,
|
|
117
|
+
{
|
|
118
|
+
packageName,
|
|
119
|
+
configFile,
|
|
120
|
+
config,
|
|
121
|
+
pkgConfig
|
|
122
|
+
}
|
|
123
|
+
];
|
|
199
124
|
});
|
|
200
125
|
});
|
|
201
126
|
return function loadConfig2(appDirectory, configFile, packageJsonConfig) {
|
|
@@ -16,6 +16,41 @@ import { initAppDir } from "./utils/initAppDir";
|
|
|
16
16
|
import { loadEnv } from "./utils/loadEnv";
|
|
17
17
|
var debug = createDebugger("plugin-v2");
|
|
18
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
|
+
};
|
|
19
54
|
var init = function init2(options) {
|
|
20
55
|
return _init.apply(this, arguments);
|
|
21
56
|
};
|
|
@@ -24,6 +59,7 @@ var createCli = function() {
|
|
|
24
59
|
};
|
|
25
60
|
var initOptions;
|
|
26
61
|
var pluginManager = createPluginManager();
|
|
62
|
+
var existListenerMap = /* @__PURE__ */ new Map();
|
|
27
63
|
function _init() {
|
|
28
64
|
_init = _async_to_generator(function(options) {
|
|
29
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;
|
|
@@ -158,39 +194,12 @@ var createCli = function() {
|
|
|
158
194
|
"unhandledRejection",
|
|
159
195
|
"uncaughtException"
|
|
160
196
|
].forEach(function(event) {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
return [
|
|
168
|
-
4,
|
|
169
|
-
context.hooks.onBeforeExit.call()
|
|
170
|
-
];
|
|
171
|
-
case 1:
|
|
172
|
-
_state2.sent();
|
|
173
|
-
hasError = false;
|
|
174
|
-
if (_instanceof(err2, Error)) {
|
|
175
|
-
logger.error(err2.stack);
|
|
176
|
-
hasError = true;
|
|
177
|
-
} else if (err2 && (event === "unhandledRejection" || event === "uncaughtException")) {
|
|
178
|
-
console.trace("Unknown Error", err2);
|
|
179
|
-
hasError = true;
|
|
180
|
-
}
|
|
181
|
-
process.nextTick(function() {
|
|
182
|
-
process.exit(hasError ? 1 : 0);
|
|
183
|
-
});
|
|
184
|
-
return [
|
|
185
|
-
2
|
|
186
|
-
];
|
|
187
|
-
}
|
|
188
|
-
});
|
|
189
|
-
});
|
|
190
|
-
return function(err2) {
|
|
191
|
-
return _ref.apply(this, arguments);
|
|
192
|
-
};
|
|
193
|
-
}());
|
|
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);
|
|
194
203
|
});
|
|
195
204
|
return [
|
|
196
205
|
4,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import path from "path";
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
2
|
+
import { fs, globby } from "@modern-js/utils";
|
|
3
|
+
import jiti from "jiti";
|
|
4
4
|
const getPackageConfig = (appDirectory, packageJsonConfig) => {
|
|
5
5
|
const json = JSON.parse(fs.readFileSync(path.resolve(appDirectory, "./package.json"), "utf8"));
|
|
6
6
|
return json[packageJsonConfig];
|
|
@@ -28,19 +28,19 @@ const clearFilesOverTime = async (targetDir, overtime) => {
|
|
|
28
28
|
} catch (err) {
|
|
29
29
|
}
|
|
30
30
|
};
|
|
31
|
-
|
|
31
|
+
function loadConfigContent(configFile) {
|
|
32
|
+
const _require = jiti(__filename, {
|
|
33
|
+
esmResolve: true,
|
|
34
|
+
// disable require cache to support restart CLI and read the new config
|
|
35
|
+
requireCache: false,
|
|
36
|
+
interopDefault: true
|
|
37
|
+
});
|
|
38
|
+
if (!fs.existsSync(configFile)) {
|
|
39
|
+
throw new Error(`Configuration file does not exist: ${configFile}`);
|
|
40
|
+
}
|
|
32
41
|
try {
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
getOutputFile: async (filePath) => {
|
|
36
|
-
const defaultOutputFileName = path.basename(await defaultGetOutputFile(filePath));
|
|
37
|
-
const outputPath = path.join(appDirectory, CONFIG_CACHE_DIR);
|
|
38
|
-
const timeLimit = 10 * 60;
|
|
39
|
-
await clearFilesOverTime(outputPath, timeLimit);
|
|
40
|
-
return path.join(outputPath, defaultOutputFileName);
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
return mod;
|
|
42
|
+
const config = _require(configFile);
|
|
43
|
+
return config.default || config;
|
|
44
44
|
} catch (e) {
|
|
45
45
|
if (e instanceof Error) {
|
|
46
46
|
e.message = `Get Error while loading config file: ${configFile}, please check it and retry.
|
|
@@ -48,7 +48,7 @@ ${e.message || ""}`;
|
|
|
48
48
|
}
|
|
49
49
|
throw e;
|
|
50
50
|
}
|
|
51
|
-
}
|
|
51
|
+
}
|
|
52
52
|
const loadConfig = async (appDirectory, configFile, packageJsonConfig) => {
|
|
53
53
|
let pkgConfig;
|
|
54
54
|
if (packageJsonConfig) {
|
|
@@ -57,11 +57,7 @@ const loadConfig = async (appDirectory, configFile, packageJsonConfig) => {
|
|
|
57
57
|
const packageName = require(path.resolve(appDirectory, "./package.json")).name;
|
|
58
58
|
let config;
|
|
59
59
|
if (configFile) {
|
|
60
|
-
|
|
61
|
-
const mod = await bundleRequireWithCatch(configFile, {
|
|
62
|
-
appDirectory
|
|
63
|
-
});
|
|
64
|
-
config = mod.default || mod;
|
|
60
|
+
config = loadConfigContent(configFile);
|
|
65
61
|
}
|
|
66
62
|
return {
|
|
67
63
|
packageName,
|
|
@@ -14,6 +14,23 @@ const debug = createDebugger("plugin-v2");
|
|
|
14
14
|
const createCli = () => {
|
|
15
15
|
let initOptions;
|
|
16
16
|
const pluginManager = createPluginManager();
|
|
17
|
+
const existListenerMap = /* @__PURE__ */ new Map();
|
|
18
|
+
function createExistListener(event, context) {
|
|
19
|
+
return async function(err) {
|
|
20
|
+
await context.hooks.onBeforeExit.call();
|
|
21
|
+
let hasError = false;
|
|
22
|
+
if (err instanceof Error) {
|
|
23
|
+
logger.error(err.stack);
|
|
24
|
+
hasError = true;
|
|
25
|
+
} else if (err && (event === "unhandledRejection" || event === "uncaughtException")) {
|
|
26
|
+
console.trace("Unknown Error", err);
|
|
27
|
+
hasError = true;
|
|
28
|
+
}
|
|
29
|
+
process.nextTick(() => {
|
|
30
|
+
process.exit(hasError ? 1 : 0);
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
}
|
|
17
34
|
async function init(options) {
|
|
18
35
|
var _context_hooks_onAfterPrepare, _context_hooks;
|
|
19
36
|
pluginManager.clear();
|
|
@@ -61,20 +78,12 @@ const createCli = () => {
|
|
|
61
78
|
"unhandledRejection",
|
|
62
79
|
"uncaughtException"
|
|
63
80
|
].forEach((event) => {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
} else if (err && (event === "unhandledRejection" || event === "uncaughtException")) {
|
|
71
|
-
console.trace("Unknown Error", err);
|
|
72
|
-
hasError = true;
|
|
73
|
-
}
|
|
74
|
-
process.nextTick(() => {
|
|
75
|
-
process.exit(hasError ? 1 : 0);
|
|
76
|
-
});
|
|
77
|
-
});
|
|
81
|
+
if (existListenerMap.get(event)) {
|
|
82
|
+
process.off(event, existListenerMap.get(event));
|
|
83
|
+
}
|
|
84
|
+
const existListener = createExistListener(event, context);
|
|
85
|
+
existListenerMap.set(event, existListener);
|
|
86
|
+
process.on(event, existListener);
|
|
78
87
|
});
|
|
79
88
|
const extraConfigs = await context.hooks.config.call();
|
|
80
89
|
const normalizedConfig = await createResolveConfig(loaded, extraConfigs);
|
|
@@ -2,7 +2,7 @@ import type { OnAfterBuildFn, OnAfterCreateCompilerFn, OnBeforeBuildFn, OnBefore
|
|
|
2
2
|
import type { AddCommandFn, AddWatchFilesFn, ConfigFn, ModifyBundlerChainFn, ModifyConfigFn, ModifyHtmlPartialsFn, ModifyResolvedConfigFn, ModifyRsbuildConfigFn, ModifyRspackConfigFn, ModifyWebpackChainFn, ModifyWebpackConfigFn, OnAfterDeployFn, OnAfterDevFn, OnBeforeDeployFn, OnBeforeDevFn, OnBeforeExitFn, OnBeforeRestartFn, OnFileChangedFn, OnPrepareFn } from '../types/cli/hooks';
|
|
3
3
|
import type { DeepPartial } from '../types/utils';
|
|
4
4
|
export type { OnAfterBuildFn, OnAfterCreateCompilerFn, OnBeforeBuildFn, OnBeforeCreateCompilerFn, OnDevCompileDoneFn, AddCommandFn, AddWatchFilesFn, ConfigFn, ModifyBundlerChainFn, ModifyConfigFn, ModifyHtmlPartialsFn, ModifyResolvedConfigFn, ModifyRsbuildConfigFn, ModifyRspackConfigFn, ModifyWebpackChainFn, ModifyWebpackConfigFn, OnAfterDeployFn, OnBeforeDeployFn, OnBeforeDevFn, OnAfterDevFn, OnBeforeExitFn, OnBeforeRestartFn, OnFileChangedFn, OnPrepareFn, };
|
|
5
|
-
export declare function initHooks<Config, NormalizedConfig, ExtendBuildUtils>(): {
|
|
5
|
+
export declare function initHooks<Config, NormalizedConfig, ExtendBuildUtils, ExtendConfigUtils>(): {
|
|
6
6
|
/**
|
|
7
7
|
* add config for this cli plugin
|
|
8
8
|
*/
|
|
@@ -11,11 +11,11 @@ export declare function initHooks<Config, NormalizedConfig, ExtendBuildUtils>():
|
|
|
11
11
|
* @private
|
|
12
12
|
* modify config for this cli plugin
|
|
13
13
|
*/
|
|
14
|
-
modifyConfig: import("..").AsyncHook<ModifyConfigFn<Config>>;
|
|
14
|
+
modifyConfig: import("..").AsyncHook<ModifyConfigFn<Config, ExtendConfigUtils>>;
|
|
15
15
|
/**
|
|
16
16
|
* modify final config
|
|
17
17
|
*/
|
|
18
|
-
modifyResolvedConfig: import("..").AsyncHook<ModifyResolvedConfigFn<NormalizedConfig>>;
|
|
18
|
+
modifyResolvedConfig: import("..").AsyncHook<ModifyResolvedConfigFn<NormalizedConfig, ExtendConfigUtils>>;
|
|
19
19
|
modifyRsbuildConfig: import("..").AsyncHook<ModifyRsbuildConfigFn<ExtendBuildUtils>>;
|
|
20
20
|
modifyBundlerChain: import("..").AsyncHook<ModifyBundlerChainFn<ExtendBuildUtils>>;
|
|
21
21
|
modifyRspackConfig: import("..").AsyncHook<ModifyRspackConfigFn<ExtendBuildUtils>>;
|
|
@@ -38,4 +38,4 @@ export declare function initHooks<Config, NormalizedConfig, ExtendBuildUtils>():
|
|
|
38
38
|
onAfterDeploy: import("..").AsyncHook<OnAfterDeployFn>;
|
|
39
39
|
onBeforeExit: import("..").AsyncHook<OnBeforeExitFn>;
|
|
40
40
|
};
|
|
41
|
-
export type Hooks<Config, NormalizedConfig, ExtendBuildUtils> = ReturnType<typeof initHooks<Config, NormalizedConfig, ExtendBuildUtils>>;
|
|
41
|
+
export type Hooks<Config, NormalizedConfig, ExtendBuildUtils, ExtendConfigUtils> = ReturnType<typeof initHooks<Config, NormalizedConfig, ExtendBuildUtils, ExtendConfigUtils>>;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import type { InternalContext } from '../../types/cli/context';
|
|
1
2
|
import type { CLIPluginExtends } from '../../types/cli/plugin';
|
|
2
3
|
import type { CLIRunOptions } from './types';
|
|
3
4
|
export declare const createCli: <Extends extends CLIPluginExtends>() => {
|
|
4
5
|
init: (options: CLIRunOptions<Extends>) => Promise<{
|
|
5
|
-
appContext:
|
|
6
|
+
appContext: InternalContext<Extends>;
|
|
6
7
|
}>;
|
|
7
8
|
run: (options: CLIRunOptions<Extends>) => Promise<void>;
|
|
8
9
|
getPrevInitOptions: () => CLIRunOptions<Extends>;
|
|
@@ -3,9 +3,9 @@ export { createLoadedConfig } from './config/createLoadedConfig';
|
|
|
3
3
|
export { initAppDir } from './utils/initAppDir';
|
|
4
4
|
export { createCli };
|
|
5
5
|
export declare const cli: {
|
|
6
|
-
init: (options: import("./types").CLIRunOptions<import("../..").CLIPluginExtends<{}, {}, {}, {}, {}, {}>>) => Promise<{
|
|
7
|
-
appContext: import("../..").InternalContext<import("../..").CLIPluginExtends<{}, {}, {}, {}, {}, {}>>;
|
|
6
|
+
init: (options: import("./types").CLIRunOptions<import("../..").CLIPluginExtends<{}, {}, {}, {}, {}, {}, {}>>) => Promise<{
|
|
7
|
+
appContext: import("../..").InternalContext<import("../..").CLIPluginExtends<{}, {}, {}, {}, {}, {}, {}>>;
|
|
8
8
|
}>;
|
|
9
|
-
run: (options: import("./types").CLIRunOptions<import("../..").CLIPluginExtends<{}, {}, {}, {}, {}, {}>>) => Promise<void>;
|
|
10
|
-
getPrevInitOptions: () => import("./types").CLIRunOptions<import("../..").CLIPluginExtends<{}, {}, {}, {}, {}, {}>>;
|
|
9
|
+
run: (options: import("./types").CLIRunOptions<import("../..").CLIPluginExtends<{}, {}, {}, {}, {}, {}, {}>>) => Promise<void>;
|
|
10
|
+
getPrevInitOptions: () => import("./types").CLIRunOptions<import("../..").CLIPluginExtends<{}, {}, {}, {}, {}, {}, {}>>;
|
|
11
11
|
};
|
|
@@ -13,11 +13,11 @@ export type CLIPluginAPI<Extends extends CLIPluginExtends> = Readonly<{
|
|
|
13
13
|
getAppContext: () => Readonly<AppContext<Extends> & Extends['extendContext']>;
|
|
14
14
|
getConfig: () => Readonly<Extends['config']>;
|
|
15
15
|
getNormalizedConfig: () => Readonly<Extends['normalizedConfig']>;
|
|
16
|
-
getHooks: () => Readonly<Hooks<Extends['config'], Extends['normalizedConfig'], Extends['extendBuildUtils']> & Extends['extendHooks']>;
|
|
16
|
+
getHooks: () => Readonly<Hooks<Extends['config'], Extends['normalizedConfig'], Extends['extendBuildUtils'], Extends['extendConfigUtils']> & Extends['extendHooks']>;
|
|
17
17
|
updateAppContext: (appContext: DeepPartial<AppContext<Extends> & Extends['extendContext']>) => void;
|
|
18
18
|
config: PluginHookTap<ConfigFn<DeepPartial<Extends['config']>>>;
|
|
19
|
-
modifyConfig: PluginHookTap<ModifyConfigFn<Extends['config']>>;
|
|
20
|
-
modifyResolvedConfig: PluginHookTap<ModifyResolvedConfigFn<Extends['normalizedConfig']>>;
|
|
19
|
+
modifyConfig: PluginHookTap<ModifyConfigFn<Extends['config'], Extends['extendConfigUtils']>>;
|
|
20
|
+
modifyResolvedConfig: PluginHookTap<ModifyResolvedConfigFn<Extends['normalizedConfig'], Extends['extendConfigUtils']>>;
|
|
21
21
|
modifyRsbuildConfig: PluginHookTap<ModifyRsbuildConfigFn<Extends['extendBuildUtils']>>;
|
|
22
22
|
modifyBundlerChain: PluginHookTap<ModifyBundlerChainFn<Extends['extendBuildUtils']>>;
|
|
23
23
|
/** Only works when bundler is Rspack */
|
|
@@ -28,7 +28,7 @@ export type AppContext<Extends extends CLIPluginExtends> = {
|
|
|
28
28
|
/** The inner context. */
|
|
29
29
|
export type InternalContext<Extends extends CLIPluginExtends> = AppContext<Extends> & {
|
|
30
30
|
/** All hooks. */
|
|
31
|
-
hooks: Hooks<Extends['config'], Extends['normalizedConfig'], Extends['extendBuildUtils']> & Extends['extendHooks'];
|
|
31
|
+
hooks: Hooks<Extends['config'], Extends['normalizedConfig'], Extends['extendBuildUtils'], Extends['extendConfigUtils']> & Extends['extendHooks'];
|
|
32
32
|
/** All plugin registry hooks */
|
|
33
33
|
extendsHooks: Extends['extendHooks'];
|
|
34
34
|
/** Current App config. */
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { WebpackConfig } from '@modern-js/uni-builder';
|
|
2
2
|
import type { Command } from '@modern-js/utils/commander';
|
|
3
3
|
import type { ModifyBundlerChainUtils, ModifyRspackConfigUtils, ModifyWebpackChainUtils, ModifyWebpackConfigUtils, RsbuildConfig, Rspack, RspackChain } from '@rsbuild/core';
|
|
4
|
-
import type { TransformFunction } from '../plugin';
|
|
5
4
|
import type { MaybePromise } from '../utils';
|
|
6
5
|
import type { Entrypoint } from './context';
|
|
7
6
|
declare module '@modern-js/utils/commander' {
|
|
@@ -10,8 +9,8 @@ declare module '@modern-js/utils/commander' {
|
|
|
10
9
|
}
|
|
11
10
|
}
|
|
12
11
|
export type ConfigFn<Config> = () => Config;
|
|
13
|
-
export type ModifyConfigFn<Config> =
|
|
14
|
-
export type ModifyResolvedConfigFn<NormalizedConfig> =
|
|
12
|
+
export type ModifyConfigFn<Config, ExtendConfigUtils> = (arg: Config, utils?: ExtendConfigUtils) => Config | Promise<Config>;
|
|
13
|
+
export type ModifyResolvedConfigFn<NormalizedConfig, ExtendConfigUtils> = (arg: NormalizedConfig, utils?: ExtendConfigUtils) => NormalizedConfig | Promise<NormalizedConfig>;
|
|
15
14
|
type IPartialMethod = (...script: string[]) => void;
|
|
16
15
|
export interface PartialMethod {
|
|
17
16
|
append: IPartialMethod;
|
|
@@ -44,8 +43,8 @@ export type OnBeforeDevFn = () => Promise<void> | void;
|
|
|
44
43
|
export type OnAfterDevFn = (params: {
|
|
45
44
|
port: number;
|
|
46
45
|
}) => Promise<void> | void;
|
|
47
|
-
export type OnBeforeDeployFn = (options
|
|
48
|
-
export type OnAfterDeployFn = (options
|
|
46
|
+
export type OnBeforeDeployFn = (options?: Record<string, any>) => Promise<void> | void;
|
|
47
|
+
export type OnAfterDeployFn = (options?: Record<string, any>) => Promise<void> | void;
|
|
49
48
|
export type OnBeforeExitFn = () => void;
|
|
50
49
|
export type ModifyBundlerChainFn<ExtendsUtils> = (chain: RspackChain, utils: ModifyBundlerChainUtils & ExtendsUtils) => MaybePromise<void>;
|
|
51
50
|
export type ModifyRsbuildConfigUtils = {
|
|
@@ -2,13 +2,14 @@ import type { PluginHook } from '../hooks';
|
|
|
2
2
|
import type { Plugin } from '../plugin';
|
|
3
3
|
import type { CLIPluginAPI } from './api';
|
|
4
4
|
import type { AppContext } from './context';
|
|
5
|
-
export interface CLIPluginExtends<Config extends Record<string, any> = {}, NormalizedConfig extends Record<string, any> = {}, ExtendContext extends Record<string, any> = {}, ExtendAPI extends Record<string, any> = {}, ExtendHook extends Record<string, PluginHook<(...args: any[]) => any>> = {}, ExtendBuildUtils extends Record<string, any> = {}> {
|
|
5
|
+
export interface CLIPluginExtends<Config extends Record<string, any> = {}, NormalizedConfig extends Record<string, any> = {}, ExtendContext extends Record<string, any> = {}, ExtendAPI extends Record<string, any> = {}, ExtendHook extends Record<string, PluginHook<(...args: any[]) => any>> = {}, ExtendBuildUtils extends Record<string, any> = {}, ExtendConfigUtils extends Record<string, any> = {}> {
|
|
6
6
|
config?: Config;
|
|
7
7
|
normalizedConfig?: NormalizedConfig;
|
|
8
8
|
extendContext?: ExtendContext;
|
|
9
9
|
extendApi?: ExtendAPI;
|
|
10
10
|
extendHooks?: ExtendHook;
|
|
11
11
|
extendBuildUtils?: ExtendBuildUtils;
|
|
12
|
+
extendConfigUtils?: ExtendConfigUtils;
|
|
12
13
|
}
|
|
13
14
|
/**
|
|
14
15
|
* The type of the CLI plugin object.
|
|
@@ -5,11 +5,11 @@ export type SyncHook<Callback extends (...args: any[]) => any> = {
|
|
|
5
5
|
};
|
|
6
6
|
export type AsyncHook<Callback extends (...args: any[]) => any> = {
|
|
7
7
|
tap: (cb: Callback) => void;
|
|
8
|
-
call: (...args: Parameters<Callback>) => Promise<ReturnType<Callback
|
|
8
|
+
call: (...args: Parameters<Callback>) => Promise<ReturnType<UnwrapPromise<Callback>>>;
|
|
9
9
|
};
|
|
10
10
|
export type AsyncInterruptHook<Callback extends (...args: any[]) => any> = {
|
|
11
11
|
tap: (cb: Callback) => void;
|
|
12
|
-
call: (...args: Tail<Parameters<Callback>>) => Promise<ReturnType<Callback
|
|
12
|
+
call: (...args: Tail<Parameters<Callback>>) => Promise<ReturnType<UnwrapPromise<Callback>>>;
|
|
13
13
|
};
|
|
14
14
|
export type CollectAsyncHook<Callback extends (...params: any[]) => any> = {
|
|
15
15
|
tap: (cb: Callback) => void;
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "2.64.0",
|
|
18
|
+
"version": "2.64.1-alpha.0",
|
|
19
19
|
"jsnext:source": "./src/index.ts",
|
|
20
20
|
"types": "./dist/types/index.d.ts",
|
|
21
21
|
"main": "./dist/cjs/index.js",
|
|
@@ -63,8 +63,8 @@
|
|
|
63
63
|
}
|
|
64
64
|
},
|
|
65
65
|
"dependencies": {
|
|
66
|
+
"jiti": "1.21.7",
|
|
66
67
|
"@swc/helpers": "0.5.13",
|
|
67
|
-
"@modern-js/node-bundle-require": "2.64.0",
|
|
68
68
|
"@modern-js/utils": "2.64.0",
|
|
69
69
|
"@modern-js/runtime-utils": "2.64.0"
|
|
70
70
|
},
|
|
@@ -75,16 +75,15 @@
|
|
|
75
75
|
"@types/node": "^14",
|
|
76
76
|
"jest": "^29",
|
|
77
77
|
"typescript": "^5",
|
|
78
|
-
"@modern-js/types": "2.64.0",
|
|
79
78
|
"@modern-js/uni-builder": "2.64.0",
|
|
80
79
|
"@scripts/build": "2.64.0",
|
|
80
|
+
"@modern-js/types": "2.64.0",
|
|
81
81
|
"@scripts/jest-config": "2.64.0"
|
|
82
82
|
},
|
|
83
83
|
"sideEffects": false,
|
|
84
84
|
"publishConfig": {
|
|
85
85
|
"registry": "https://registry.npmjs.org/",
|
|
86
|
-
"access": "public"
|
|
87
|
-
"provenance": true
|
|
86
|
+
"access": "public"
|
|
88
87
|
},
|
|
89
88
|
"scripts": {
|
|
90
89
|
"new": "modern-lib new",
|