@rspack/cli 1.0.0-alpha.3 → 1.0.0-alpha.5
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/cli.js +9 -9
- package/dist/commands/build.js +1 -1
- package/dist/commands/preview.js +3 -3
- package/dist/utils/crossImport.js +2 -2
- package/dist/utils/findConfig.js +2 -2
- package/dist/utils/isEsmFile.js +2 -2
- package/dist/utils/isTsFile.js +2 -2
- package/dist/utils/loadConfig.js +6 -6
- package/dist/utils/profile.js +18 -18
- package/dist/utils/readPackageUp.js +8 -8
- package/package.json +7 -4
package/dist/cli.js
CHANGED
|
@@ -27,8 +27,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
exports.definePlugin = exports.defineConfig = exports.RspackCLI = void 0;
|
|
30
|
-
const
|
|
31
|
-
const
|
|
30
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
31
|
+
const node_util_1 = __importDefault(require("node:util"));
|
|
32
32
|
const core_1 = require("@rspack/core");
|
|
33
33
|
const rspackCore = __importStar(require("@rspack/core"));
|
|
34
34
|
const semver_1 = __importDefault(require("semver"));
|
|
@@ -50,8 +50,8 @@ class RspackCLI {
|
|
|
50
50
|
process.env.RSPACK_CONFIG_VALIDATE = "loose";
|
|
51
51
|
process.env.WATCHPACK_WATCHER_LIMIT =
|
|
52
52
|
process.env.WATCHPACK_WATCHER_LIMIT || "20";
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
const nodeEnv = process?.env?.NODE_ENV;
|
|
54
|
+
const rspackCommandDefaultEnv = rspackCommand === "build" ? "production" : "development";
|
|
55
55
|
if (typeof options.nodeEnv === "string") {
|
|
56
56
|
process.env.NODE_ENV = nodeEnv || options.nodeEnv;
|
|
57
57
|
}
|
|
@@ -81,7 +81,7 @@ class RspackCLI {
|
|
|
81
81
|
}
|
|
82
82
|
getLogger() {
|
|
83
83
|
return {
|
|
84
|
-
error: val => console.error(`[rspack-cli] ${this.colors.red(
|
|
84
|
+
error: val => console.error(`[rspack-cli] ${this.colors.red(node_util_1.default.format(val))}`),
|
|
85
85
|
warn: val => console.warn(`[rspack-cli] ${this.colors.yellow(val)}`),
|
|
86
86
|
info: val => console.info(`[rspack-cli] ${this.colors.cyan(val)}`),
|
|
87
87
|
success: val => console.log(`[rspack-cli] ${this.colors.green(val)}`),
|
|
@@ -120,11 +120,11 @@ class RspackCLI {
|
|
|
120
120
|
const internalBuildConfig = async (item) => {
|
|
121
121
|
if (options.entry) {
|
|
122
122
|
item.entry = {
|
|
123
|
-
main: options.entry.map(x =>
|
|
123
|
+
main: options.entry.map(x => node_path_1.default.resolve(process.cwd(), x))[0] // Fix me when entry supports array
|
|
124
124
|
};
|
|
125
125
|
}
|
|
126
126
|
else if (!item.entry) {
|
|
127
|
-
const defaultEntryBase =
|
|
127
|
+
const defaultEntryBase = node_path_1.default.resolve(process.cwd(), defaultEntry);
|
|
128
128
|
const defaultEntryPath = (0, findConfig_1.default)(defaultEntryBase) || defaultEntryBase + ".js"; // default entry is js
|
|
129
129
|
item.entry = {
|
|
130
130
|
main: defaultEntryPath
|
|
@@ -133,7 +133,7 @@ class RspackCLI {
|
|
|
133
133
|
// to set output.path
|
|
134
134
|
item.output = item.output || {};
|
|
135
135
|
if (options["output-path"]) {
|
|
136
|
-
item.output.path =
|
|
136
|
+
item.output.path = node_path_1.default.resolve(process.cwd(), options["output-path"]);
|
|
137
137
|
}
|
|
138
138
|
if (options.analyze) {
|
|
139
139
|
const { BundleAnalyzerPlugin } = await import("webpack-bundle-analyzer");
|
|
@@ -170,7 +170,7 @@ class RspackCLI {
|
|
|
170
170
|
item.devtool = isBuild ? "source-map" : "cheap-module-source-map";
|
|
171
171
|
}
|
|
172
172
|
if (isServe) {
|
|
173
|
-
|
|
173
|
+
const installed = (item.plugins ||= []).find(item => item instanceof rspackCore.ProgressPlugin);
|
|
174
174
|
if (!installed) {
|
|
175
175
|
(item.plugins ??= []).push(new rspackCore.ProgressPlugin());
|
|
176
176
|
}
|
package/dist/commands/build.js
CHANGED
|
@@ -24,7 +24,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.BuildCommand = void 0;
|
|
27
|
-
const fs = __importStar(require("fs"));
|
|
27
|
+
const fs = __importStar(require("node:fs"));
|
|
28
28
|
const options_1 = require("../utils/options");
|
|
29
29
|
class BuildCommand {
|
|
30
30
|
async apply(cli) {
|
package/dist/commands/preview.js
CHANGED
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.PreviewCommand = void 0;
|
|
7
|
-
const
|
|
7
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
8
8
|
const core_1 = require("@rspack/core");
|
|
9
9
|
const options_1 = require("../utils/options");
|
|
10
10
|
const defaultRoot = "dist";
|
|
@@ -52,9 +52,9 @@ async function getPreviewConfig(item, options) {
|
|
|
52
52
|
item.devServer = {
|
|
53
53
|
static: {
|
|
54
54
|
directory: options.dir
|
|
55
|
-
?
|
|
55
|
+
? node_path_1.default.join(item.context ?? process.cwd(), options.dir)
|
|
56
56
|
: item.output?.path ??
|
|
57
|
-
|
|
57
|
+
node_path_1.default.join(item.context ?? process.cwd(), defaultRoot),
|
|
58
58
|
publicPath: options.publicPath ?? "/"
|
|
59
59
|
},
|
|
60
60
|
port: options.port ?? 8080,
|
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.dynamicImport = void 0;
|
|
7
|
-
const
|
|
7
|
+
const node_url_1 = require("node:url");
|
|
8
8
|
const isEsmFile_1 = __importDefault(require("./isEsmFile"));
|
|
9
9
|
/**
|
|
10
10
|
* Dynamically import files. It will make sure it's not being compiled away by TS/Rollup.
|
|
@@ -12,7 +12,7 @@ const isEsmFile_1 = __importDefault(require("./isEsmFile"));
|
|
|
12
12
|
exports.dynamicImport = new Function("path", "return import(path)");
|
|
13
13
|
const crossImport = async (path, cwd = process.cwd()) => {
|
|
14
14
|
if ((0, isEsmFile_1.default)(path, cwd)) {
|
|
15
|
-
const url = (0,
|
|
15
|
+
const url = (0, node_url_1.pathToFileURL)(path).href;
|
|
16
16
|
const { default: config } = await (0, exports.dynamicImport)(url);
|
|
17
17
|
return config;
|
|
18
18
|
}
|
package/dist/utils/findConfig.js
CHANGED
|
@@ -3,13 +3,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const
|
|
6
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
7
7
|
const constants_1 = require("../constants");
|
|
8
8
|
/**
|
|
9
9
|
* Takes a basePath like `webpack.config`, return `webpack.config.{ext}` if
|
|
10
10
|
* exists. returns undefined if none of them exists
|
|
11
11
|
*/
|
|
12
12
|
const findConfig = (basePath) => {
|
|
13
|
-
return constants_1.DEFAULT_EXTENSIONS.map(ext => basePath + ext).find(
|
|
13
|
+
return constants_1.DEFAULT_EXTENSIONS.map(ext => basePath + ext).find(node_fs_1.default.existsSync);
|
|
14
14
|
};
|
|
15
15
|
exports.default = findConfig;
|
package/dist/utils/isEsmFile.js
CHANGED
|
@@ -3,10 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const
|
|
6
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
7
7
|
const readPackageUp_1 = __importDefault(require("./readPackageUp"));
|
|
8
8
|
const isEsmFile = (filePath, cwd = process.cwd()) => {
|
|
9
|
-
const ext =
|
|
9
|
+
const ext = node_path_1.default.extname(filePath);
|
|
10
10
|
if (/\.(mjs|mts)$/.test(ext)) {
|
|
11
11
|
return true;
|
|
12
12
|
}
|
package/dist/utils/isTsFile.js
CHANGED
|
@@ -3,9 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const
|
|
6
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
7
7
|
const isTsFile = (configPath) => {
|
|
8
|
-
const ext =
|
|
8
|
+
const ext = node_path_1.default.extname(configPath);
|
|
9
9
|
return /\.(c|m)?ts$/.test(ext);
|
|
10
10
|
};
|
|
11
11
|
exports.default = isTsFile;
|
package/dist/utils/loadConfig.js
CHANGED
|
@@ -4,8 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.loadRspackConfig = void 0;
|
|
7
|
-
const
|
|
8
|
-
const
|
|
7
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
9
9
|
const interpret_1 = __importDefault(require("interpret"));
|
|
10
10
|
const rechoir_1 = __importDefault(require("rechoir"));
|
|
11
11
|
const crossImport_1 = __importDefault(require("./crossImport"));
|
|
@@ -14,7 +14,7 @@ const isEsmFile_1 = __importDefault(require("./isEsmFile"));
|
|
|
14
14
|
const isTsFile_1 = __importDefault(require("./isTsFile"));
|
|
15
15
|
const DEFAULT_CONFIG_NAME = "rspack.config";
|
|
16
16
|
const registerLoader = (configPath) => {
|
|
17
|
-
const ext =
|
|
17
|
+
const ext = node_path_1.default.extname(configPath);
|
|
18
18
|
// TODO implement good `.mts` support after https://github.com/gulpjs/rechoir/issues/43
|
|
19
19
|
// For ESM and `.mts` you need to use: 'NODE_OPTIONS="--loader ts-node/esm" rspack build --config ./rspack.config.mts'
|
|
20
20
|
if ((0, isEsmFile_1.default)(configPath) && (0, isTsFile_1.default)(configPath)) {
|
|
@@ -40,15 +40,15 @@ const registerLoader = (configPath) => {
|
|
|
40
40
|
};
|
|
41
41
|
async function loadRspackConfig(options, cwd = process.cwd()) {
|
|
42
42
|
if (options.config) {
|
|
43
|
-
const configPath =
|
|
44
|
-
if (!
|
|
43
|
+
const configPath = node_path_1.default.resolve(cwd, options.config);
|
|
44
|
+
if (!node_fs_1.default.existsSync(configPath)) {
|
|
45
45
|
throw new Error(`config file "${configPath}" not found.`);
|
|
46
46
|
}
|
|
47
47
|
(0, isTsFile_1.default)(configPath) && registerLoader(configPath);
|
|
48
48
|
return (0, crossImport_1.default)(configPath, cwd);
|
|
49
49
|
}
|
|
50
50
|
else {
|
|
51
|
-
const defaultConfig = (0, findConfig_1.default)(
|
|
51
|
+
const defaultConfig = (0, findConfig_1.default)(node_path_1.default.resolve(cwd, DEFAULT_CONFIG_NAME));
|
|
52
52
|
if (defaultConfig) {
|
|
53
53
|
(0, isTsFile_1.default)(defaultConfig) && registerLoader(defaultConfig);
|
|
54
54
|
return (0, crossImport_1.default)(defaultConfig, cwd);
|
package/dist/utils/profile.js
CHANGED
|
@@ -36,19 +36,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
36
36
|
};
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
38
|
exports.applyProfile = void 0;
|
|
39
|
-
const
|
|
40
|
-
const
|
|
41
|
-
const
|
|
39
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
40
|
+
const node_inspector_1 = __importDefault(require("node:inspector"));
|
|
41
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
42
|
+
const node_url_1 = require("node:url");
|
|
42
43
|
const core_1 = require("@rspack/core");
|
|
43
|
-
const inspector_1 = __importDefault(require("inspector"));
|
|
44
44
|
const timestamp = Date.now();
|
|
45
|
-
const defaultOutputDirname =
|
|
46
|
-
const defaultJSCPUProfileOutput =
|
|
47
|
-
const defaultRustTraceChromeOutput =
|
|
48
|
-
const defaultRustTraceLoggerOutput =
|
|
45
|
+
const defaultOutputDirname = node_path_1.default.resolve(`.rspack-profile-${timestamp}-${process.pid}`);
|
|
46
|
+
const defaultJSCPUProfileOutput = node_path_1.default.join(defaultOutputDirname, "./jscpuprofile.json");
|
|
47
|
+
const defaultRustTraceChromeOutput = node_path_1.default.join(defaultOutputDirname, "./trace.json");
|
|
48
|
+
const defaultRustTraceLoggerOutput = "stdout";
|
|
49
49
|
const defaultRustTraceFilter = "trace";
|
|
50
50
|
const defaultRustTraceLayer = "chrome";
|
|
51
|
-
const defaultLoggingOutput =
|
|
51
|
+
const defaultLoggingOutput = node_path_1.default.join(defaultOutputDirname, "./logging.json");
|
|
52
52
|
function resolveProfile(value) {
|
|
53
53
|
if (value.toUpperCase() === "ALL") {
|
|
54
54
|
return {
|
|
@@ -86,7 +86,7 @@ function resolveProfile(value) {
|
|
|
86
86
|
function resolveJSCPUProfileOptions(value) {
|
|
87
87
|
// output=filepath
|
|
88
88
|
if (value.includes("=")) {
|
|
89
|
-
const parsed = new
|
|
89
|
+
const parsed = new node_url_1.URLSearchParams(value);
|
|
90
90
|
return { output: parsed.get("output") || defaultJSCPUProfileOutput };
|
|
91
91
|
}
|
|
92
92
|
// filepath
|
|
@@ -96,7 +96,7 @@ function resolveJSCPUProfileOptions(value) {
|
|
|
96
96
|
function resolveRustTraceOptions(value) {
|
|
97
97
|
// filter=trace&output=stdout&layer=logger
|
|
98
98
|
if (value.includes("=")) {
|
|
99
|
-
const parsed = new
|
|
99
|
+
const parsed = new node_url_1.URLSearchParams(value);
|
|
100
100
|
const filter = parsed.get("filter") || defaultRustTraceFilter;
|
|
101
101
|
const layer = parsed.get("layer") || defaultRustTraceLayer;
|
|
102
102
|
const output = layer === "chrome"
|
|
@@ -122,7 +122,7 @@ function resolveRustTraceOptions(value) {
|
|
|
122
122
|
function resolveLoggingOptions(value) {
|
|
123
123
|
// output=filepath
|
|
124
124
|
if (value.includes("=")) {
|
|
125
|
-
const parsed = new
|
|
125
|
+
const parsed = new node_url_1.URLSearchParams(value);
|
|
126
126
|
return { output: parsed.get("output") || defaultLoggingOutput };
|
|
127
127
|
}
|
|
128
128
|
// filepath
|
|
@@ -133,7 +133,7 @@ class RspackProfileJSCPUProfilePlugin {
|
|
|
133
133
|
this.output = output;
|
|
134
134
|
}
|
|
135
135
|
apply(compiler) {
|
|
136
|
-
const session = new
|
|
136
|
+
const session = new node_inspector_1.default.Session();
|
|
137
137
|
session.connect();
|
|
138
138
|
session.post("Profiler.enable");
|
|
139
139
|
session.post("Profiler.start");
|
|
@@ -145,7 +145,7 @@ class RspackProfileJSCPUProfilePlugin {
|
|
|
145
145
|
console.error("Failed to generate JS CPU profile:", error);
|
|
146
146
|
return;
|
|
147
147
|
}
|
|
148
|
-
|
|
148
|
+
node_fs_1.default.writeFileSync(this.output, JSON.stringify(param.profile));
|
|
149
149
|
});
|
|
150
150
|
return callback();
|
|
151
151
|
});
|
|
@@ -164,7 +164,7 @@ class RspackProfileLoggingPlugin {
|
|
|
164
164
|
logging: "verbose",
|
|
165
165
|
loggingTrace: true
|
|
166
166
|
});
|
|
167
|
-
|
|
167
|
+
node_fs_1.default.writeFileSync(this.output, JSON.stringify(logging));
|
|
168
168
|
return callback();
|
|
169
169
|
});
|
|
170
170
|
}
|
|
@@ -174,7 +174,7 @@ async function applyProfile(profileValue, item) {
|
|
|
174
174
|
const entries = Object.entries(resolveProfile(profileValue));
|
|
175
175
|
if (entries.length <= 0)
|
|
176
176
|
return;
|
|
177
|
-
await
|
|
177
|
+
await node_fs_1.default.promises.mkdir(defaultOutputDirname);
|
|
178
178
|
for (const [kind, value] of entries) {
|
|
179
179
|
await ensureFileDir(value.output);
|
|
180
180
|
if (kind === "TRACE" && "filter" in value) {
|
|
@@ -191,7 +191,7 @@ async function applyProfile(profileValue, item) {
|
|
|
191
191
|
}
|
|
192
192
|
exports.applyProfile = applyProfile;
|
|
193
193
|
async function ensureFileDir(outputFilePath) {
|
|
194
|
-
const dir =
|
|
195
|
-
await
|
|
194
|
+
const dir = node_path_1.default.dirname(outputFilePath);
|
|
195
|
+
await node_fs_1.default.promises.mkdir(dir, { recursive: true });
|
|
196
196
|
return dir;
|
|
197
197
|
}
|
|
@@ -3,21 +3,21 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const
|
|
7
|
-
const
|
|
6
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
7
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
8
8
|
const readPackageUp = (cwd = process.cwd()) => {
|
|
9
|
-
let currentDir =
|
|
10
|
-
let packageJsonPath =
|
|
11
|
-
while (!
|
|
12
|
-
const parentDir =
|
|
9
|
+
let currentDir = node_path_1.default.resolve(cwd);
|
|
10
|
+
let packageJsonPath = node_path_1.default.join(currentDir, "package.json");
|
|
11
|
+
while (!node_fs_1.default.existsSync(packageJsonPath)) {
|
|
12
|
+
const parentDir = node_path_1.default.dirname(currentDir);
|
|
13
13
|
if (parentDir === currentDir) {
|
|
14
14
|
return null;
|
|
15
15
|
}
|
|
16
16
|
currentDir = parentDir;
|
|
17
|
-
packageJsonPath =
|
|
17
|
+
packageJsonPath = node_path_1.default.join(currentDir, "package.json");
|
|
18
18
|
}
|
|
19
19
|
try {
|
|
20
|
-
return JSON.parse(
|
|
20
|
+
return JSON.parse(node_fs_1.default.readFileSync(packageJsonPath, "utf8"));
|
|
21
21
|
}
|
|
22
22
|
catch (error) {
|
|
23
23
|
return null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rspack/cli",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.5",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "CLI for rspack",
|
|
6
6
|
"publishConfig": {
|
|
@@ -24,17 +24,20 @@
|
|
|
24
24
|
"directory": "packages/rspack-cli"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
|
-
"@rspack/core": "
|
|
27
|
+
"@rspack/core": "^1.0.0-alpha"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@types/rechoir": "^0.6.1",
|
|
31
|
+
"@types/interpret": "^1.1.3",
|
|
31
32
|
"@types/semver": "^7.5.6",
|
|
32
33
|
"@types/webpack-bundle-analyzer": "^4.6.0",
|
|
34
|
+
"@types/yargs": "17.0.32",
|
|
35
|
+
"ts-node": "^10.9.2",
|
|
33
36
|
"concat-stream": "^2.0.0",
|
|
34
37
|
"cross-env": "^7.0.3",
|
|
35
38
|
"execa": "^5.0.0",
|
|
36
39
|
"internal-ip": "6.2.0",
|
|
37
|
-
"@rspack/core": "1.0.0-alpha.
|
|
40
|
+
"@rspack/core": "1.0.0-alpha.5"
|
|
38
41
|
},
|
|
39
42
|
"dependencies": {
|
|
40
43
|
"@discoveryjs/json-ext": "^0.5.7",
|
|
@@ -45,7 +48,7 @@
|
|
|
45
48
|
"semver": "6.3.1",
|
|
46
49
|
"webpack-bundle-analyzer": "4.6.1",
|
|
47
50
|
"yargs": "17.6.2",
|
|
48
|
-
"@rspack/dev-server": "1.0.0-alpha.
|
|
51
|
+
"@rspack/dev-server": "1.0.0-alpha.5"
|
|
49
52
|
},
|
|
50
53
|
"scripts": {
|
|
51
54
|
"build": "tsc -b ./tsconfig.build.json",
|