@rspack/cli 1.1.8 → 1.2.0-beta.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/{629.js → 574.js} +12 -53
- package/dist/{629.mjs → 574.mjs} +9 -50
- package/dist/index.js +83 -238
- package/dist/index.mjs +59 -174
- package/dist/utils/crossImport.d.ts +1 -6
- package/package.json +5 -8
package/dist/index.mjs
CHANGED
|
@@ -5,73 +5,9 @@ import * as __WEBPACK_EXTERNAL_MODULE_node_path__ from "node:path";
|
|
|
5
5
|
import * as __WEBPACK_EXTERNAL_MODULE_node_url__ from "node:url";
|
|
6
6
|
import * as __WEBPACK_EXTERNAL_MODULE_node_util__ from "node:util";
|
|
7
7
|
import * as __WEBPACK_EXTERNAL_MODULE_colorette__ from "colorette";
|
|
8
|
-
import * as __WEBPACK_EXTERNAL_MODULE_semver__ from "semver";
|
|
9
8
|
import * as __WEBPACK_EXTERNAL_MODULE_yargs__ from "yargs";
|
|
10
9
|
import * as __WEBPACK_EXTERNAL_MODULE_yargs_helpers__ from "yargs/helpers";
|
|
11
|
-
import * as __WEBPACK_EXTERNAL_MODULE_interpret__ from "interpret";
|
|
12
|
-
import * as __WEBPACK_EXTERNAL_MODULE_rechoir__ from "rechoir";
|
|
13
10
|
var __webpack_modules__ = {
|
|
14
|
-
"./src/utils/crossImport.ts": function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
|
|
15
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
16
|
-
Z: function() {
|
|
17
|
-
return __WEBPACK_DEFAULT_EXPORT__;
|
|
18
|
-
},
|
|
19
|
-
y: function() {
|
|
20
|
-
return dynamicImport;
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
/* ESM import */ var node_url__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("node:url");
|
|
24
|
-
/* ESM import */ var _isEsmFile__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./src/utils/isEsmFile.ts");
|
|
25
|
-
/**
|
|
26
|
-
* Dynamically import files. It will make sure it's not being compiled away by TS/Rslib.
|
|
27
|
-
*/ const dynamicImport = new Function("path", "return import(path)");
|
|
28
|
-
const crossImport = async (path, cwd = process.cwd())=>{
|
|
29
|
-
if ((0, _isEsmFile__WEBPACK_IMPORTED_MODULE_1__ /* ["default"] */ .Z)(path, cwd)) {
|
|
30
|
-
const url = (0, node_url__WEBPACK_IMPORTED_MODULE_0__.pathToFileURL)(path).href;
|
|
31
|
-
const { default: config } = await dynamicImport(url);
|
|
32
|
-
return config;
|
|
33
|
-
}
|
|
34
|
-
let result = require(path);
|
|
35
|
-
// compatible with export default config in common ts config
|
|
36
|
-
if (result && "object" == typeof result && "default" in result) result = result.default || {};
|
|
37
|
-
return result;
|
|
38
|
-
};
|
|
39
|
-
/* ESM default export */ const __WEBPACK_DEFAULT_EXPORT__ = crossImport;
|
|
40
|
-
},
|
|
41
|
-
"./src/utils/isEsmFile.ts": function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
|
|
42
|
-
// EXPORTS
|
|
43
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
44
|
-
Z: ()=>/* binding */ isEsmFile
|
|
45
|
-
});
|
|
46
|
-
// EXTERNAL MODULE: external "node:path"
|
|
47
|
-
var external_node_path_ = __webpack_require__("node:path");
|
|
48
|
-
// EXTERNAL MODULE: external "node:fs"
|
|
49
|
-
var external_node_fs_ = __webpack_require__("node:fs");
|
|
50
|
-
const readPackageUp_readPackageUp = (cwd = process.cwd())=>{
|
|
51
|
-
let currentDir = external_node_path_["default"].resolve(cwd);
|
|
52
|
-
let packageJsonPath = external_node_path_["default"].join(currentDir, "package.json");
|
|
53
|
-
while(!external_node_fs_["default"].existsSync(packageJsonPath)){
|
|
54
|
-
const parentDir = external_node_path_["default"].dirname(currentDir);
|
|
55
|
-
if (parentDir === currentDir) return null;
|
|
56
|
-
currentDir = parentDir;
|
|
57
|
-
packageJsonPath = external_node_path_["default"].join(currentDir, "package.json");
|
|
58
|
-
}
|
|
59
|
-
try {
|
|
60
|
-
return JSON.parse(external_node_fs_["default"].readFileSync(packageJsonPath, "utf8"));
|
|
61
|
-
} catch (error) {
|
|
62
|
-
return null;
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
/* ESM default export */ const readPackageUp = readPackageUp_readPackageUp;
|
|
66
|
-
const isEsmFile_isEsmFile = (filePath, cwd = process.cwd())=>{
|
|
67
|
-
const ext = external_node_path_["default"].extname(filePath);
|
|
68
|
-
if (/\.(mjs|mts)$/.test(ext)) return true;
|
|
69
|
-
if (/\.(cjs|cts)/.test(ext)) return false;
|
|
70
|
-
const packageJson = readPackageUp(cwd);
|
|
71
|
-
return (null == packageJson ? void 0 : packageJson.type) === "module";
|
|
72
|
-
};
|
|
73
|
-
/* ESM default export */ const isEsmFile = isEsmFile_isEsmFile;
|
|
74
|
-
},
|
|
75
11
|
"@rspack/core": function(module) {
|
|
76
12
|
module.exports = __WEBPACK_EXTERNAL_MODULE__rspack_core__;
|
|
77
13
|
},
|
|
@@ -88,25 +24,17 @@ var __webpack_modules__ = {
|
|
|
88
24
|
module.exports = __WEBPACK_EXTERNAL_MODULE_node_url__;
|
|
89
25
|
}
|
|
90
26
|
};
|
|
91
|
-
/************************************************************************/ // The module cache
|
|
92
27
|
var __webpack_module_cache__ = {};
|
|
93
|
-
// The require function
|
|
94
28
|
function __webpack_require__(moduleId) {
|
|
95
|
-
// Check if module is in cache
|
|
96
29
|
var cachedModule = __webpack_module_cache__[moduleId];
|
|
97
30
|
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
98
|
-
// Create a new module (and put it into the cache)
|
|
99
31
|
var module = __webpack_module_cache__[moduleId] = {
|
|
100
32
|
exports: {}
|
|
101
33
|
};
|
|
102
|
-
// Execute the module function
|
|
103
34
|
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
104
|
-
// Return the exports of the module
|
|
105
35
|
return module.exports;
|
|
106
36
|
}
|
|
107
|
-
// expose the modules object (__webpack_modules__)
|
|
108
37
|
__webpack_require__.m = __webpack_modules__;
|
|
109
|
-
/************************************************************************/ // webpack/runtime/define_property_getters
|
|
110
38
|
(()=>{
|
|
111
39
|
__webpack_require__.d = function(exports, definition) {
|
|
112
40
|
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) Object.defineProperty(exports, key, {
|
|
@@ -115,11 +43,8 @@ __webpack_require__.m = __webpack_modules__;
|
|
|
115
43
|
});
|
|
116
44
|
};
|
|
117
45
|
})();
|
|
118
|
-
// webpack/runtime/ensure_chunk
|
|
119
46
|
(()=>{
|
|
120
47
|
__webpack_require__.f = {};
|
|
121
|
-
// This file contains only the entry chunk.
|
|
122
|
-
// The chunk loading function for additional chunks
|
|
123
48
|
__webpack_require__.e = function(chunkId) {
|
|
124
49
|
return Promise.all(Object.keys(__webpack_require__.f).reduce(function(promises, key) {
|
|
125
50
|
__webpack_require__.f[key](chunkId, promises);
|
|
@@ -127,26 +52,17 @@ __webpack_require__.m = __webpack_modules__;
|
|
|
127
52
|
}, []));
|
|
128
53
|
};
|
|
129
54
|
})();
|
|
130
|
-
// webpack/runtime/get javascript chunk filename
|
|
131
55
|
(()=>{
|
|
132
|
-
// This function allow to reference chunks
|
|
133
56
|
__webpack_require__.u = function(chunkId) {
|
|
134
|
-
// return url for filenames not based on template
|
|
135
|
-
// return url for filenames based on template
|
|
136
57
|
return "" + chunkId + ".mjs";
|
|
137
58
|
};
|
|
138
59
|
})();
|
|
139
|
-
// webpack/runtime/has_own_property
|
|
140
60
|
(()=>{
|
|
141
61
|
__webpack_require__.o = function(obj, prop) {
|
|
142
62
|
return Object.prototype.hasOwnProperty.call(obj, prop);
|
|
143
63
|
};
|
|
144
64
|
})();
|
|
145
|
-
// webpack/runtime/module_chunk_loading
|
|
146
65
|
(()=>{
|
|
147
|
-
// object to store loaded and loading chunks
|
|
148
|
-
// undefined = chunk not loaded, null = chunk preloaded/prefetched
|
|
149
|
-
// [resolve, reject, Promise] = chunk loading, 0 = chunk loaded
|
|
150
66
|
var installedChunks = {
|
|
151
67
|
980: 0
|
|
152
68
|
};
|
|
@@ -154,8 +70,6 @@ __webpack_require__.m = __webpack_modules__;
|
|
|
154
70
|
var ids = data.ids;
|
|
155
71
|
var modules = data.modules;
|
|
156
72
|
var runtime = data.runtime;
|
|
157
|
-
// add "modules" to the modules object,
|
|
158
|
-
// then flag all "ids" as loaded and fire callback
|
|
159
73
|
var moduleId, chunkId, i = 0;
|
|
160
74
|
for(moduleId in modules)if (__webpack_require__.o(modules, moduleId)) __webpack_require__.m[moduleId] = modules[moduleId];
|
|
161
75
|
if (runtime) runtime(__webpack_require__);
|
|
@@ -166,13 +80,10 @@ __webpack_require__.m = __webpack_modules__;
|
|
|
166
80
|
}
|
|
167
81
|
};
|
|
168
82
|
__webpack_require__.f.j = function(chunkId, promises) {
|
|
169
|
-
// import() chunk loading for javascript
|
|
170
83
|
var installedChunkData = __webpack_require__.o(installedChunks, chunkId) ? installedChunks[chunkId] : void 0;
|
|
171
84
|
if (0 !== installedChunkData) {
|
|
172
|
-
// a Promise means "currently loading".
|
|
173
85
|
if (installedChunkData) promises.push(installedChunkData[1]);
|
|
174
86
|
else {
|
|
175
|
-
// setup Promise in chunk cache
|
|
176
87
|
var promise = import("./" + __webpack_require__.u(chunkId)).then(installChunk, function(e) {
|
|
177
88
|
if (0 !== installedChunks[chunkId]) installedChunks[chunkId] = void 0;
|
|
178
89
|
throw e;
|
|
@@ -190,11 +101,8 @@ __webpack_require__.m = __webpack_modules__;
|
|
|
190
101
|
}
|
|
191
102
|
};
|
|
192
103
|
})();
|
|
193
|
-
// EXTERNAL MODULE: external "node:path"
|
|
194
104
|
var external_node_path_ = __webpack_require__("node:path");
|
|
195
|
-
// EXTERNAL MODULE: external "@rspack/core"
|
|
196
105
|
var core_ = __webpack_require__("@rspack/core");
|
|
197
|
-
// EXTERNAL MODULE: external "node:fs"
|
|
198
106
|
var external_node_fs_ = __webpack_require__("node:fs");
|
|
199
107
|
const commonOptions = (yargs)=>yargs.options({
|
|
200
108
|
config: {
|
|
@@ -274,7 +182,6 @@ const previewOptions = (yargs)=>yargs.positional("dir", {
|
|
|
274
182
|
type: "boolean",
|
|
275
183
|
describe: "open browser"
|
|
276
184
|
},
|
|
277
|
-
// same as devServer.server
|
|
278
185
|
server: {
|
|
279
186
|
type: "string",
|
|
280
187
|
describe: "Configuration items for the server."
|
|
@@ -292,9 +199,7 @@ function normalizeEnv(argv) {
|
|
|
292
199
|
let prevRef = previous;
|
|
293
200
|
splitKeys.forEach((key, index)=>{
|
|
294
201
|
let someKey = key;
|
|
295
|
-
// https://github.com/webpack/webpack-cli/issues/3284
|
|
296
202
|
if (someKey.endsWith("=")) {
|
|
297
|
-
// remove '=' from key
|
|
298
203
|
someKey = someKey.slice(0, -1);
|
|
299
204
|
prevRef[someKey] = void 0;
|
|
300
205
|
return;
|
|
@@ -311,27 +216,16 @@ function normalizeEnv(argv) {
|
|
|
311
216
|
const envObj = (argv.env ?? []).reduce(parseValue, {});
|
|
312
217
|
argv.env = envObj;
|
|
313
218
|
}
|
|
314
|
-
|
|
315
|
-
* set builtin env from cli - like `WEBPACK_BUNDLE=true`. also for `RSPACK_` prefixed.
|
|
316
|
-
* @param env the `argv.env` object
|
|
317
|
-
* @param envNameSuffix the added env will be `WEBPACK_${envNameSuffix}` and `RSPACK_${envNameSuffix}`
|
|
318
|
-
* @param value
|
|
319
|
-
*/ function setBuiltinEnvArg(env, envNameSuffix, value) {
|
|
219
|
+
function setBuiltinEnvArg(env, envNameSuffix, value) {
|
|
320
220
|
const envNames = [
|
|
321
|
-
// TODO: breaking change
|
|
322
|
-
// `WEBPACK_${envNameSuffix}`,
|
|
323
221
|
`RSPACK_${envNameSuffix}`
|
|
324
222
|
];
|
|
325
223
|
for (const envName of envNames){
|
|
326
224
|
if (!(envName in env)) env[envName] = value;
|
|
327
225
|
}
|
|
328
226
|
}
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
* @returns the reference of `argv.env` object
|
|
332
|
-
*/ function ensureEnvObject(options) {
|
|
333
|
-
if (Array.isArray(options.env)) // in case that cli haven't got `normalizeEnv` middleware applied
|
|
334
|
-
normalizeEnv(options);
|
|
227
|
+
function ensureEnvObject(options) {
|
|
228
|
+
if (Array.isArray(options.env)) normalizeEnv(options);
|
|
335
229
|
options.env = options.env || {};
|
|
336
230
|
return options.env;
|
|
337
231
|
}
|
|
@@ -385,13 +279,11 @@ class BuildCommand {
|
|
|
385
279
|
process.exit(2);
|
|
386
280
|
};
|
|
387
281
|
if (true === options.json) createJsonStringifyStream(stats.toJson(statsOptions)).on("error", handleWriteError).pipe(process.stdout).on("error", handleWriteError).on("close", ()=>process.stdout.write("\n"));
|
|
388
|
-
else if ("string" == typeof options.json) createJsonStringifyStream(stats.toJson(statsOptions)).on("error", handleWriteError).pipe(external_node_fs_.createWriteStream(options.json)).on("error", handleWriteError)
|
|
389
|
-
.on("close", ()=>{
|
|
282
|
+
else if ("string" == typeof options.json) createJsonStringifyStream(stats.toJson(statsOptions)).on("error", handleWriteError).pipe(external_node_fs_.createWriteStream(options.json)).on("error", handleWriteError).on("close", ()=>{
|
|
390
283
|
process.stderr.write(`[rspack-cli] ${cli.colors.green(`stats are successfully stored as json to ${options.json}`)}\n`);
|
|
391
284
|
});
|
|
392
285
|
} else {
|
|
393
286
|
const printedStats = stats.toString(statsOptions);
|
|
394
|
-
// Avoid extra empty line when `stats: 'none'`
|
|
395
287
|
if (printedStats) logger.raw(printedStats);
|
|
396
288
|
}
|
|
397
289
|
};
|
|
@@ -404,8 +296,6 @@ class BuildCommand {
|
|
|
404
296
|
const compiler = await cli.createCompiler(rspackOptions, "build", errorHandler);
|
|
405
297
|
if (!compiler || cli.isWatch(compiler)) return;
|
|
406
298
|
compiler.run((error, stats)=>{
|
|
407
|
-
// If there is a compilation error, the close method should not be called,
|
|
408
|
-
// Otherwise Rspack may generate invalid caches.
|
|
409
299
|
if (error || (null == stats ? void 0 : stats.hasErrors())) errorHandler(error, stats);
|
|
410
300
|
else compiler.close((closeErr)=>{
|
|
411
301
|
if (closeErr) logger.error(closeErr);
|
|
@@ -423,7 +313,6 @@ class PreviewCommand {
|
|
|
423
313
|
"preview",
|
|
424
314
|
"p"
|
|
425
315
|
], "run the rspack server for build output", previewOptions, async (options)=>{
|
|
426
|
-
// config、configName are necessary for loadConfig
|
|
427
316
|
const rspackOptions = {
|
|
428
317
|
config: options.config,
|
|
429
318
|
configName: options.configName,
|
|
@@ -437,7 +326,6 @@ class PreviewCommand {
|
|
|
437
326
|
if (!Array.isArray(config)) config = [
|
|
438
327
|
config
|
|
439
328
|
];
|
|
440
|
-
// find the possible devServer config
|
|
441
329
|
config = config.find((item)=>item.devServer) || config[0];
|
|
442
330
|
const devServerOptions = config.devServer;
|
|
443
331
|
try {
|
|
@@ -455,11 +343,9 @@ class PreviewCommand {
|
|
|
455
343
|
});
|
|
456
344
|
}
|
|
457
345
|
}
|
|
458
|
-
// get the devServerOptions from the config
|
|
459
346
|
async function getPreviewConfig(item, options) {
|
|
460
347
|
const internalPreviewConfig = async (item)=>{
|
|
461
348
|
var _item_output, _item_devServer, _item_devServer1, _item_devServer2, _item_devServer3, _item_devServer4;
|
|
462
|
-
// all of the options that a preview static server needs(maybe not all)
|
|
463
349
|
item.devServer = {
|
|
464
350
|
static: {
|
|
465
351
|
directory: options.dir ? external_node_path_["default"].join(item.context ?? process.cwd(), options.dir) : (null === (_item_output = item.output) || void 0 === _item_output ? void 0 : _item_output.path) ?? external_node_path_["default"].join(item.context ?? process.cwd(), defaultRoot),
|
|
@@ -510,15 +396,7 @@ class ServeCommand {
|
|
|
510
396
|
...options
|
|
511
397
|
}
|
|
512
398
|
};
|
|
513
|
-
|
|
514
|
-
* webpack-dev-server will set `process.env.WEBPACK_SERVE` to true
|
|
515
|
-
* when its module is imported, so we have to lazy load the package
|
|
516
|
-
* to make sure the envvar is not set on build mode.
|
|
517
|
-
* when run in serve mode, we have to load the package before config
|
|
518
|
-
* module is imported so that the envvar `process.env.WEBPACK_SERVE`
|
|
519
|
-
* got in config module could be `true`.
|
|
520
|
-
* related issue: https://github.com/web-infra-dev/rspack/issues/6359
|
|
521
|
-
*/ const { RspackDevServer } = await import("@rspack/dev-server");
|
|
399
|
+
const { RspackDevServer } = await import("@rspack/dev-server");
|
|
522
400
|
const compiler = await cli.createCompiler(rspackOptions, "serve");
|
|
523
401
|
if (!compiler) return;
|
|
524
402
|
const compilers = cli.isMultipleCompiler(compiler) ? compiler.compilers : [
|
|
@@ -527,16 +405,8 @@ class ServeCommand {
|
|
|
527
405
|
const possibleCompilers = compilers.filter((compiler)=>compiler.options.devServer);
|
|
528
406
|
const usedPorts = [];
|
|
529
407
|
const servers = [];
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
* however according to it's doc https://webpack.js.org/configuration/dev-server/#devserverhot
|
|
533
|
-
* It should use only the first one
|
|
534
|
-
*
|
|
535
|
-
* Choose the one for configure devServer
|
|
536
|
-
*/ const compilerForDevServer = possibleCompilers.length > 0 ? possibleCompilers[0] : compilers[0];
|
|
537
|
-
/**
|
|
538
|
-
* Rspack relies on devServer.hot to enable HMR
|
|
539
|
-
*/ for (const compiler of compilers){
|
|
408
|
+
const compilerForDevServer = possibleCompilers.length > 0 ? possibleCompilers[0] : compilers[0];
|
|
409
|
+
for (const compiler of compilers){
|
|
540
410
|
const devServer = compiler.options.devServer ??= {};
|
|
541
411
|
devServer.hot = options.hot ?? devServer.hot ?? true;
|
|
542
412
|
if (false !== devServer.client) {
|
|
@@ -551,9 +421,7 @@ class ServeCommand {
|
|
|
551
421
|
}
|
|
552
422
|
}
|
|
553
423
|
const result = compilerForDevServer.options.devServer ??= {};
|
|
554
|
-
|
|
555
|
-
* Enable this to tell Rspack that we need to enable React Refresh by default
|
|
556
|
-
*/ result.hot = options.hot ?? result.hot ?? true;
|
|
424
|
+
result.hot = options.hot ?? result.hot ?? true;
|
|
557
425
|
result.host = options.host || result.host;
|
|
558
426
|
result.port = options.port || result.port;
|
|
559
427
|
if (false !== result.client) {
|
|
@@ -586,8 +454,41 @@ class ServeCommand {
|
|
|
586
454
|
});
|
|
587
455
|
}
|
|
588
456
|
}
|
|
589
|
-
|
|
590
|
-
|
|
457
|
+
var external_node_url_ = __webpack_require__("node:url");
|
|
458
|
+
const readPackageUp = (cwd = process.cwd())=>{
|
|
459
|
+
let currentDir = external_node_path_["default"].resolve(cwd);
|
|
460
|
+
let packageJsonPath = external_node_path_["default"].join(currentDir, "package.json");
|
|
461
|
+
while(!external_node_fs_["default"].existsSync(packageJsonPath)){
|
|
462
|
+
const parentDir = external_node_path_["default"].dirname(currentDir);
|
|
463
|
+
if (parentDir === currentDir) return null;
|
|
464
|
+
currentDir = parentDir;
|
|
465
|
+
packageJsonPath = external_node_path_["default"].join(currentDir, "package.json");
|
|
466
|
+
}
|
|
467
|
+
try {
|
|
468
|
+
return JSON.parse(external_node_fs_["default"].readFileSync(packageJsonPath, "utf8"));
|
|
469
|
+
} catch (error) {
|
|
470
|
+
return null;
|
|
471
|
+
}
|
|
472
|
+
};
|
|
473
|
+
const utils_readPackageUp = readPackageUp;
|
|
474
|
+
const isEsmFile = (filePath, cwd = process.cwd())=>{
|
|
475
|
+
const ext = external_node_path_["default"].extname(filePath);
|
|
476
|
+
if (/\.(mjs|mts)$/.test(ext)) return true;
|
|
477
|
+
if (/\.(cjs|cts)/.test(ext)) return false;
|
|
478
|
+
const packageJson = utils_readPackageUp(cwd);
|
|
479
|
+
return (null == packageJson ? void 0 : packageJson.type) === "module";
|
|
480
|
+
};
|
|
481
|
+
const utils_isEsmFile = isEsmFile;
|
|
482
|
+
const crossImport = async (path, cwd = process.cwd())=>{
|
|
483
|
+
if (utils_isEsmFile(path, cwd)) {
|
|
484
|
+
const url = (0, external_node_url_.pathToFileURL)(path).href;
|
|
485
|
+
const { default: config } = await import(url);
|
|
486
|
+
return config;
|
|
487
|
+
}
|
|
488
|
+
let result = require(path);
|
|
489
|
+
if (result && "object" == typeof result && "default" in result) result = result.default || {};
|
|
490
|
+
return result;
|
|
491
|
+
};
|
|
591
492
|
const DEFAULT_EXTENSIONS = [
|
|
592
493
|
".js",
|
|
593
494
|
".ts",
|
|
@@ -596,28 +497,23 @@ const DEFAULT_EXTENSIONS = [
|
|
|
596
497
|
".cjs",
|
|
597
498
|
".cts"
|
|
598
499
|
];
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
*/ const findConfig = (basePath)=>DEFAULT_EXTENSIONS.map((ext)=>basePath + ext).find(external_node_fs_["default"].existsSync);
|
|
603
|
-
/* ESM default export */ const utils_findConfig = findConfig;
|
|
604
|
-
// EXTERNAL MODULE: ./src/utils/isEsmFile.ts + 1 modules
|
|
605
|
-
var isEsmFile = __webpack_require__("./src/utils/isEsmFile.ts");
|
|
606
|
-
const isTsFile = (configPath)=>{
|
|
500
|
+
const findConfig = (basePath)=>DEFAULT_EXTENSIONS.map((ext)=>basePath + ext).find(external_node_fs_["default"].existsSync);
|
|
501
|
+
const utils_findConfig = findConfig;
|
|
502
|
+
const isTsFile_isTsFile = (configPath)=>{
|
|
607
503
|
const ext = external_node_path_["default"].extname(configPath);
|
|
608
504
|
return /\.(c|m)?ts$/.test(ext);
|
|
609
505
|
};
|
|
610
|
-
|
|
506
|
+
const isTsFile = isTsFile_isTsFile;
|
|
611
507
|
const loadConfig_DEFAULT_CONFIG_NAME = "rspack.config";
|
|
612
|
-
const registerLoader = (configPath)=>{
|
|
508
|
+
const registerLoader = async (configPath)=>{
|
|
613
509
|
const ext = external_node_path_["default"].extname(configPath);
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
const extensions = Object.fromEntries(Object.entries(__WEBPACK_EXTERNAL_MODULE_interpret__["default"].extensions).filter(([key])=>key === ext));
|
|
510
|
+
if (utils_isEsmFile(configPath) && isTsFile(configPath)) return;
|
|
511
|
+
const { default: interpret } = await import("interpret");
|
|
512
|
+
const extensions = Object.fromEntries(Object.entries(interpret.extensions).filter(([key])=>key === ext));
|
|
618
513
|
if (0 === Object.keys(extensions).length) throw new Error(`config file "${configPath}" is not supported.`);
|
|
619
514
|
try {
|
|
620
|
-
|
|
515
|
+
const { default: rechoir } = await import("rechoir");
|
|
516
|
+
rechoir.prepare(extensions, configPath);
|
|
621
517
|
} catch (error) {
|
|
622
518
|
const failures = null == error ? void 0 : error.failures;
|
|
623
519
|
if (failures) {
|
|
@@ -631,13 +527,13 @@ async function loadRspackConfig(options, cwd = process.cwd()) {
|
|
|
631
527
|
if (options.config) {
|
|
632
528
|
const configPath = external_node_path_["default"].resolve(cwd, options.config);
|
|
633
529
|
if (!external_node_fs_["default"].existsSync(configPath)) throw new Error(`config file "${configPath}" not found.`);
|
|
634
|
-
|
|
635
|
-
return
|
|
530
|
+
if (isTsFile(configPath)) await registerLoader(configPath);
|
|
531
|
+
return crossImport(configPath, cwd);
|
|
636
532
|
}
|
|
637
533
|
const defaultConfig = utils_findConfig(external_node_path_["default"].resolve(cwd, loadConfig_DEFAULT_CONFIG_NAME));
|
|
638
534
|
if (defaultConfig) {
|
|
639
|
-
|
|
640
|
-
return
|
|
535
|
+
if (isTsFile(defaultConfig)) await registerLoader(defaultConfig);
|
|
536
|
+
return crossImport(defaultConfig, cwd);
|
|
641
537
|
}
|
|
642
538
|
return {};
|
|
643
539
|
}
|
|
@@ -667,8 +563,6 @@ class RspackCLI {
|
|
|
667
563
|
try {
|
|
668
564
|
compiler = (0, core_.rspack)(config, isWatch ? callback : void 0);
|
|
669
565
|
} catch (e) {
|
|
670
|
-
// Aligned with webpack-cli
|
|
671
|
-
// See: https://github.com/webpack/webpack-cli/blob/eea6adf7d34dfbfd3b5b784ece4a4664834f5a6a/packages/webpack-cli/src/webpack-cli.ts#L2394
|
|
672
566
|
if (e instanceof core_.ValidationError) {
|
|
673
567
|
this.getLogger().error(e.message);
|
|
674
568
|
process.exit(2);
|
|
@@ -701,7 +595,6 @@ class RspackCLI {
|
|
|
701
595
|
};
|
|
702
596
|
}
|
|
703
597
|
async run(argv) {
|
|
704
|
-
if (__WEBPACK_EXTERNAL_MODULE_semver__["default"].lt(__WEBPACK_EXTERNAL_MODULE_semver__["default"].clean(process.version), "14.0.0")) this.getLogger().warn(`Minimum recommended Node.js version is 14.0.0, current version is ${process.version}`);
|
|
705
598
|
this.program.showHelpOnFail(false);
|
|
706
599
|
this.program.usage("[options]");
|
|
707
600
|
this.program.scriptName("rspack");
|
|
@@ -724,9 +617,8 @@ class RspackCLI {
|
|
|
724
617
|
const commandDefaultEnv = isBuild ? "production" : "development";
|
|
725
618
|
const internalBuildConfig = async (item)=>{
|
|
726
619
|
if (options.entry) item.entry = {
|
|
727
|
-
main: options.entry.map((x)=>external_node_path_["default"].resolve(process.cwd(), x))[0]
|
|
620
|
+
main: options.entry.map((x)=>external_node_path_["default"].resolve(process.cwd(), x))[0]
|
|
728
621
|
};
|
|
729
|
-
// to set output.path
|
|
730
622
|
item.output = item.output || {};
|
|
731
623
|
if (options["output-path"]) item.output.path = external_node_path_["default"].resolve(process.cwd(), options["output-path"]);
|
|
732
624
|
if (options.analyze) {
|
|
@@ -742,16 +634,12 @@ class RspackCLI {
|
|
|
742
634
|
}
|
|
743
635
|
if (options.profile) item.profile = true;
|
|
744
636
|
if (process.env.RSPACK_PROFILE) {
|
|
745
|
-
const { applyProfile } = await __webpack_require__.e(
|
|
637
|
+
const { applyProfile } = await __webpack_require__.e("574").then(__webpack_require__.bind(__webpack_require__, "./src/utils/profile.ts"));
|
|
746
638
|
await applyProfile(process.env.RSPACK_PROFILE, item);
|
|
747
639
|
}
|
|
748
|
-
// cli --watch overrides the watch config
|
|
749
640
|
if (options.watch) item.watch = options.watch;
|
|
750
|
-
// auto set default mode if user config don't set it
|
|
751
641
|
if (!item.mode) item.mode = commandDefaultEnv ?? "none";
|
|
752
|
-
// user parameters always has highest priority than default mode and config mode
|
|
753
642
|
if (options.mode) item.mode = options.mode;
|
|
754
|
-
// false is also a valid value for sourcemap, so don't override it
|
|
755
643
|
if (void 0 === item.devtool) item.devtool = isBuild ? "source-map" : "cheap-module-source-map";
|
|
756
644
|
if (isServe) {
|
|
757
645
|
const installed = (item.plugins ||= []).find((item)=>item instanceof core_.ProgressPlugin);
|
|
@@ -780,7 +668,6 @@ class RspackCLI {
|
|
|
780
668
|
if ("function" == typeof loadedConfig) {
|
|
781
669
|
var _options_argv;
|
|
782
670
|
loadedConfig = loadedConfig(null === (_options_argv = options.argv) || void 0 === _options_argv ? void 0 : _options_argv.env, options.argv);
|
|
783
|
-
// if return promise we should await its result
|
|
784
671
|
if ("function" == typeof loadedConfig.then) loadedConfig = await loadedConfig;
|
|
785
672
|
}
|
|
786
673
|
if (options.configName) {
|
|
@@ -789,8 +676,6 @@ class RspackCLI {
|
|
|
789
676
|
let found;
|
|
790
677
|
found = Array.isArray(loadedConfig) ? loadedConfig.find((options)=>options.name === configName) : loadedConfig.name === configName ? loadedConfig : void 0;
|
|
791
678
|
if (!found) notFoundConfigNames.push(configName);
|
|
792
|
-
// WARNING: if config is not found, the program will exit
|
|
793
|
-
// so assert here is okay to avoid runtime filtering
|
|
794
679
|
return found;
|
|
795
680
|
});
|
|
796
681
|
if (notFoundConfigNames.length > 0) {
|
|
@@ -1,6 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* Dynamically import files. It will make sure it's not being compiled away by TS/Rslib.
|
|
3
|
-
*/
|
|
4
|
-
export declare const dynamicImport: Function;
|
|
5
|
-
declare const crossImport: <T = any>(path: string, cwd?: string) => Promise<T>;
|
|
6
|
-
export default crossImport;
|
|
1
|
+
export declare const crossImport: <T = any>(path: string, cwd?: string) => Promise<T>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rspack/cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0-beta.0",
|
|
4
4
|
"description": "CLI for rspack",
|
|
5
5
|
"homepage": "https://rspack.dev",
|
|
6
6
|
"bugs": "https://github.com/web-infra-dev/rspack/issues",
|
|
@@ -29,29 +29,26 @@
|
|
|
29
29
|
],
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@discoveryjs/json-ext": "^0.5.7",
|
|
32
|
-
"@rspack/dev-server": "1.0.
|
|
32
|
+
"@rspack/dev-server": "1.0.10",
|
|
33
33
|
"colorette": "2.0.19",
|
|
34
34
|
"exit-hook": "^4.0.0",
|
|
35
35
|
"interpret": "^3.1.1",
|
|
36
36
|
"rechoir": "^0.8.0",
|
|
37
|
-
"semver": "^7.6.2",
|
|
38
37
|
"webpack-bundle-analyzer": "4.6.1",
|
|
39
38
|
"yargs": "17.6.2"
|
|
40
39
|
},
|
|
41
40
|
"devDependencies": {
|
|
42
|
-
"@rslib/core": "0.
|
|
41
|
+
"@rslib/core": "0.2.2",
|
|
43
42
|
"@types/interpret": "^1.1.3",
|
|
44
43
|
"@types/rechoir": "^0.6.1",
|
|
45
|
-
"@types/semver": "^7.5.6",
|
|
46
44
|
"@types/webpack-bundle-analyzer": "^4.6.0",
|
|
47
45
|
"@types/yargs": "17.0.33",
|
|
48
46
|
"concat-stream": "^2.0.0",
|
|
49
47
|
"cross-env": "^7.0.3",
|
|
50
48
|
"execa": "^5.0.0",
|
|
51
|
-
"internal-ip": "6.2.0",
|
|
52
49
|
"ts-node": "^10.9.2",
|
|
53
|
-
"typescript": "^5.
|
|
54
|
-
"@rspack/core": "1.
|
|
50
|
+
"typescript": "^5.7.2",
|
|
51
|
+
"@rspack/core": "1.2.0-beta.0"
|
|
55
52
|
},
|
|
56
53
|
"peerDependencies": {
|
|
57
54
|
"@rspack/core": "^1.0.0-alpha || ^1.x"
|