@rspack/cli 1.5.0-beta.1 → 1.5.0-rc.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/index.js +50 -28
- package/dist/index.mjs +50 -18
- package/dist/utils/isTsFile.d.ts +1 -0
- package/dist/utils/loadConfig.d.ts +1 -0
- package/package.json +4 -7
package/dist/index.js
CHANGED
@@ -24,16 +24,6 @@ var __webpack_modules__ = {
|
|
24
24
|
return module;
|
25
25
|
});
|
26
26
|
},
|
27
|
-
interpret: function(module) {
|
28
|
-
module.exports = import("interpret").then(function(module) {
|
29
|
-
return module;
|
30
|
-
});
|
31
|
-
},
|
32
|
-
rechoir: function(module) {
|
33
|
-
module.exports = import("rechoir").then(function(module) {
|
34
|
-
return module;
|
35
|
-
});
|
36
|
-
},
|
37
27
|
"webpack-bundle-analyzer": function(module) {
|
38
28
|
module.exports = import("webpack-bundle-analyzer").then(function(module) {
|
39
29
|
return module;
|
@@ -489,6 +479,7 @@ var __webpack_exports__ = {};
|
|
489
479
|
});
|
490
480
|
}
|
491
481
|
}
|
482
|
+
const external_pirates_namespaceObject = require("pirates");
|
492
483
|
const external_node_url_namespaceObject = require("node:url");
|
493
484
|
const readPackageUp = (cwd = process.cwd())=>{
|
494
485
|
let currentDir = external_node_path_default().resolve(cwd);
|
@@ -534,29 +525,60 @@ var __webpack_exports__ = {};
|
|
534
525
|
];
|
535
526
|
const findConfig = (basePath)=>DEFAULT_EXTENSIONS.map((ext)=>basePath + ext).find(external_node_fs_default().existsSync);
|
536
527
|
const utils_findConfig = findConfig;
|
528
|
+
const TS_EXTENSION = [
|
529
|
+
".ts",
|
530
|
+
".cts",
|
531
|
+
".mts"
|
532
|
+
];
|
537
533
|
const isTsFile_isTsFile = (configPath)=>{
|
538
534
|
const ext = external_node_path_default().extname(configPath);
|
539
|
-
return
|
535
|
+
return TS_EXTENSION.includes(ext);
|
540
536
|
};
|
541
537
|
const isTsFile = isTsFile_isTsFile;
|
538
|
+
const injectInlineSourceMap = ({ filename, code, map })=>{
|
539
|
+
if (map) {
|
540
|
+
const base64Map = Buffer.from(map, "utf8").toString("base64");
|
541
|
+
const sourceMapContent = `//# sourceMappingURL=data:application/json;charset=utf-8;base64,${base64Map}`;
|
542
|
+
return `${code}\n${sourceMapContent}`;
|
543
|
+
}
|
544
|
+
return code;
|
545
|
+
};
|
546
|
+
function compile(sourcecode, filename) {
|
547
|
+
const { code, map } = core_.experiments.swc.transformSync(sourcecode, {
|
548
|
+
jsc: {
|
549
|
+
parser: {
|
550
|
+
syntax: "typescript",
|
551
|
+
tsx: false,
|
552
|
+
decorators: true,
|
553
|
+
dynamicImport: true
|
554
|
+
}
|
555
|
+
},
|
556
|
+
filename: filename,
|
557
|
+
module: {
|
558
|
+
type: "commonjs"
|
559
|
+
},
|
560
|
+
sourceMaps: true,
|
561
|
+
isModule: true
|
562
|
+
});
|
563
|
+
return injectInlineSourceMap({
|
564
|
+
filename,
|
565
|
+
code,
|
566
|
+
map
|
567
|
+
});
|
568
|
+
}
|
542
569
|
const loadConfig_DEFAULT_CONFIG_NAME = "rspack.config";
|
543
|
-
const registerLoader =
|
544
|
-
const ext = external_node_path_default().extname(configPath);
|
570
|
+
const registerLoader = (configPath)=>{
|
545
571
|
if (utils_isEsmFile(configPath) && isTsFile(configPath)) return;
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
} catch (error) {
|
553
|
-
const failures = error?.failures;
|
554
|
-
if (failures) {
|
555
|
-
const messages = failures.map((failure)=>failure.error.message);
|
556
|
-
throw new Error(`${messages.join("\n")}`);
|
572
|
+
if (!isTsFile(configPath)) throw new Error(`config file "${configPath}" is not supported.`);
|
573
|
+
(0, external_pirates_namespaceObject.addHook)((code, filename)=>{
|
574
|
+
try {
|
575
|
+
return compile(code, filename);
|
576
|
+
} catch (err) {
|
577
|
+
throw new Error(`Failed to transform file "${filename}" when loading TypeScript config file:\n ${err instanceof Error ? err.message : String(err)}`);
|
557
578
|
}
|
558
|
-
|
559
|
-
|
579
|
+
}, {
|
580
|
+
exts: TS_EXTENSION
|
581
|
+
});
|
560
582
|
};
|
561
583
|
const checkIsMultiRspackOptions = (config)=>Array.isArray(config);
|
562
584
|
async function loadExtendedConfig(config, configPath, cwd, options) {
|
@@ -610,7 +632,7 @@ var __webpack_exports__ = {};
|
|
610
632
|
throw new Error(`Cannot find module '${extendPath}' to extend from.`);
|
611
633
|
}
|
612
634
|
if (!external_node_fs_default().existsSync(resolvedPath)) throw new Error(`Extended configuration file "${resolvedPath}" not found.`);
|
613
|
-
if (isTsFile(resolvedPath) && "register" === options.configLoader)
|
635
|
+
if (isTsFile(resolvedPath) && "register" === options.configLoader) registerLoader(resolvedPath);
|
614
636
|
let loadedConfig = await crossImport(resolvedPath, cwd);
|
615
637
|
if ("function" == typeof loadedConfig) {
|
616
638
|
loadedConfig = loadedConfig(options.argv?.env, options.argv);
|
@@ -639,7 +661,7 @@ var __webpack_exports__ = {};
|
|
639
661
|
if (!defaultConfig) return null;
|
640
662
|
configPath = defaultConfig;
|
641
663
|
}
|
642
|
-
if (isTsFile(configPath) && "register" === options.configLoader)
|
664
|
+
if (isTsFile(configPath) && "register" === options.configLoader) registerLoader(configPath);
|
643
665
|
const loadedConfig = await crossImport(configPath, cwd);
|
644
666
|
return {
|
645
667
|
loadedConfig,
|
package/dist/index.mjs
CHANGED
@@ -5,6 +5,7 @@ import node_util from "node:util";
|
|
5
5
|
import { createColors, isColorSupported } from "colorette";
|
6
6
|
import yargs_0 from "yargs";
|
7
7
|
import { hideBin } from "yargs/helpers";
|
8
|
+
import { addHook } from "pirates";
|
8
9
|
import { pathToFileURL } from "node:url";
|
9
10
|
var __webpack_modules__ = {
|
10
11
|
"@rspack/core": function(module) {
|
@@ -498,29 +499,60 @@ const DEFAULT_EXTENSIONS = [
|
|
498
499
|
];
|
499
500
|
const findConfig = (basePath)=>DEFAULT_EXTENSIONS.map((ext)=>basePath + ext).find(external_node_fs_["default"].existsSync);
|
500
501
|
const utils_findConfig = findConfig;
|
502
|
+
const TS_EXTENSION = [
|
503
|
+
".ts",
|
504
|
+
".cts",
|
505
|
+
".mts"
|
506
|
+
];
|
501
507
|
const isTsFile_isTsFile = (configPath)=>{
|
502
508
|
const ext = external_node_path_["default"].extname(configPath);
|
503
|
-
return
|
509
|
+
return TS_EXTENSION.includes(ext);
|
504
510
|
};
|
505
511
|
const isTsFile = isTsFile_isTsFile;
|
512
|
+
const injectInlineSourceMap = ({ filename, code, map })=>{
|
513
|
+
if (map) {
|
514
|
+
const base64Map = Buffer.from(map, "utf8").toString("base64");
|
515
|
+
const sourceMapContent = `//# sourceMappingURL=data:application/json;charset=utf-8;base64,${base64Map}`;
|
516
|
+
return `${code}\n${sourceMapContent}`;
|
517
|
+
}
|
518
|
+
return code;
|
519
|
+
};
|
520
|
+
function compile(sourcecode, filename) {
|
521
|
+
const { code, map } = core_.experiments.swc.transformSync(sourcecode, {
|
522
|
+
jsc: {
|
523
|
+
parser: {
|
524
|
+
syntax: "typescript",
|
525
|
+
tsx: false,
|
526
|
+
decorators: true,
|
527
|
+
dynamicImport: true
|
528
|
+
}
|
529
|
+
},
|
530
|
+
filename: filename,
|
531
|
+
module: {
|
532
|
+
type: "commonjs"
|
533
|
+
},
|
534
|
+
sourceMaps: true,
|
535
|
+
isModule: true
|
536
|
+
});
|
537
|
+
return injectInlineSourceMap({
|
538
|
+
filename,
|
539
|
+
code,
|
540
|
+
map
|
541
|
+
});
|
542
|
+
}
|
506
543
|
const loadConfig_DEFAULT_CONFIG_NAME = "rspack.config";
|
507
|
-
const registerLoader =
|
508
|
-
const ext = external_node_path_["default"].extname(configPath);
|
544
|
+
const registerLoader = (configPath)=>{
|
509
545
|
if (utils_isEsmFile(configPath) && isTsFile(configPath)) return;
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
} catch (error) {
|
517
|
-
const failures = error?.failures;
|
518
|
-
if (failures) {
|
519
|
-
const messages = failures.map((failure)=>failure.error.message);
|
520
|
-
throw new Error(`${messages.join("\n")}`);
|
546
|
+
if (!isTsFile(configPath)) throw new Error(`config file "${configPath}" is not supported.`);
|
547
|
+
addHook((code, filename)=>{
|
548
|
+
try {
|
549
|
+
return compile(code, filename);
|
550
|
+
} catch (err) {
|
551
|
+
throw new Error(`Failed to transform file "${filename}" when loading TypeScript config file:\n ${err instanceof Error ? err.message : String(err)}`);
|
521
552
|
}
|
522
|
-
|
523
|
-
|
553
|
+
}, {
|
554
|
+
exts: TS_EXTENSION
|
555
|
+
});
|
524
556
|
};
|
525
557
|
const checkIsMultiRspackOptions = (config)=>Array.isArray(config);
|
526
558
|
async function loadExtendedConfig(config, configPath, cwd, options) {
|
@@ -574,7 +606,7 @@ async function loadExtendedConfig(config, configPath, cwd, options) {
|
|
574
606
|
throw new Error(`Cannot find module '${extendPath}' to extend from.`);
|
575
607
|
}
|
576
608
|
if (!external_node_fs_["default"].existsSync(resolvedPath)) throw new Error(`Extended configuration file "${resolvedPath}" not found.`);
|
577
|
-
if (isTsFile(resolvedPath) && "register" === options.configLoader)
|
609
|
+
if (isTsFile(resolvedPath) && "register" === options.configLoader) registerLoader(resolvedPath);
|
578
610
|
let loadedConfig = await crossImport(resolvedPath, cwd);
|
579
611
|
if ("function" == typeof loadedConfig) {
|
580
612
|
loadedConfig = loadedConfig(options.argv?.env, options.argv);
|
@@ -603,7 +635,7 @@ async function loadRspackConfig(options, cwd = process.cwd()) {
|
|
603
635
|
if (!defaultConfig) return null;
|
604
636
|
configPath = defaultConfig;
|
605
637
|
}
|
606
|
-
if (isTsFile(configPath) && "register" === options.configLoader)
|
638
|
+
if (isTsFile(configPath) && "register" === options.configLoader) registerLoader(configPath);
|
607
639
|
const loadedConfig = await crossImport(configPath, cwd);
|
608
640
|
return {
|
609
641
|
loadedConfig,
|
package/dist/utils/isTsFile.d.ts
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
import { type MultiRspackOptions, type RspackOptions } from "@rspack/core";
|
2
2
|
import type { RspackCLIOptions } from "../types";
|
3
|
+
export declare function compile(sourcecode: string, filename: string): string;
|
3
4
|
export type LoadedRspackConfig = undefined | RspackOptions | MultiRspackOptions | ((env: Record<string, any>, argv?: Record<string, any>) => RspackOptions | MultiRspackOptions);
|
4
5
|
/**
|
5
6
|
* Loads and merges configurations from the 'extends' property
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@rspack/cli",
|
3
|
-
"version": "1.5.0-
|
3
|
+
"version": "1.5.0-rc.0",
|
4
4
|
"description": "CLI for rspack",
|
5
5
|
"homepage": "https://rspack.rs",
|
6
6
|
"bugs": "https://github.com/web-infra-dev/rspack/issues",
|
@@ -32,15 +32,12 @@
|
|
32
32
|
"@rspack/dev-server": "~1.1.3",
|
33
33
|
"colorette": "2.0.20",
|
34
34
|
"exit-hook": "^4.0.0",
|
35
|
-
"interpret": "^3.1.1",
|
36
|
-
"rechoir": "^0.8.0",
|
37
35
|
"webpack-bundle-analyzer": "4.10.2",
|
38
|
-
"yargs": "17.7.2"
|
36
|
+
"yargs": "17.7.2",
|
37
|
+
"pirates": "^4.0.7"
|
39
38
|
},
|
40
39
|
"devDependencies": {
|
41
40
|
"@rslib/core": "0.12.1",
|
42
|
-
"@types/interpret": "^1.1.3",
|
43
|
-
"@types/rechoir": "^0.6.4",
|
44
41
|
"@types/webpack-bundle-analyzer": "^4.7.0",
|
45
42
|
"@types/yargs": "17.0.33",
|
46
43
|
"concat-stream": "^2.0.0",
|
@@ -48,7 +45,7 @@
|
|
48
45
|
"execa": "^5.1.1",
|
49
46
|
"ts-node": "^10.9.2",
|
50
47
|
"typescript": "^5.9.2",
|
51
|
-
"@rspack/core": "1.5.0-
|
48
|
+
"@rspack/core": "1.5.0-rc.0"
|
52
49
|
},
|
53
50
|
"peerDependencies": {
|
54
51
|
"@rspack/core": "^1.0.0-alpha || ^1.x"
|