@4399ywkf/core 5.1.3 → 5.1.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/index.js +93 -27
- package/dist/cli/index.js.map +1 -1
- package/dist/config/index.d.ts +2 -2
- package/dist/config/index.js +1 -0
- package/dist/config/index.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +92 -26
- package/dist/index.js.map +1 -1
- package/dist/plugin/index.d.ts +2 -2
- package/dist/rspack/index.d.ts +1 -1
- package/dist/rspack/index.js +3 -2
- package/dist/rspack/index.js.map +1 -1
- package/dist/{schema-C91lhskq.d.ts → schema-CuEnqbqQ.d.ts} +5 -0
- package/package.json +5 -5
package/dist/cli/index.js
CHANGED
|
@@ -2125,6 +2125,7 @@ var defaultConfig = {
|
|
|
2125
2125
|
appName: "app",
|
|
2126
2126
|
appCName: "\u5E94\u7528",
|
|
2127
2127
|
strictMode: true,
|
|
2128
|
+
reactCompiler: false,
|
|
2128
2129
|
dev: {
|
|
2129
2130
|
port: 3e3,
|
|
2130
2131
|
host: "127.0.0.1",
|
|
@@ -3440,7 +3441,7 @@ var coreNodeModules = join12(__dirname, "../../node_modules");
|
|
|
3440
3441
|
function createBaseConfig(config, cwd, options = {}) {
|
|
3441
3442
|
const isDev = options.isDev ?? process.env.NODE_ENV !== "production";
|
|
3442
3443
|
const { resolveApp } = createPathResolver(cwd);
|
|
3443
|
-
const { appName, appCName, output, html, alias: userAlias, microFrontend, router } = config;
|
|
3444
|
+
const { appName, appCName, output, html, alias: userAlias, microFrontend, router, reactCompiler } = config;
|
|
3444
3445
|
const ywkfOutputDir = resolveApp(".ywkf");
|
|
3445
3446
|
const defaultAlias = {
|
|
3446
3447
|
"@": resolveApp("src"),
|
|
@@ -3526,7 +3527,8 @@ function createBaseConfig(config, cwd, options = {}) {
|
|
|
3526
3527
|
runtime: "automatic",
|
|
3527
3528
|
development: isDev,
|
|
3528
3529
|
refresh: isDev
|
|
3529
|
-
}
|
|
3530
|
+
},
|
|
3531
|
+
...reactCompiler ? { reactCompiler } : {}
|
|
3530
3532
|
},
|
|
3531
3533
|
target: "es2015"
|
|
3532
3534
|
},
|
|
@@ -4444,33 +4446,74 @@ import { RspackDevServer } from "@rspack/dev-server";
|
|
|
4444
4446
|
import chalk3 from "chalk";
|
|
4445
4447
|
|
|
4446
4448
|
// src/cli/port.ts
|
|
4449
|
+
import { execFile } from "child_process";
|
|
4447
4450
|
import net from "net";
|
|
4448
|
-
|
|
4449
|
-
|
|
4451
|
+
import { promisify } from "util";
|
|
4452
|
+
var execFileAsync = promisify(execFile);
|
|
4453
|
+
var PortInUseError = class extends Error {
|
|
4454
|
+
constructor(port, host) {
|
|
4455
|
+
super(`Port ${port} is already in use on ${host}`);
|
|
4456
|
+
this.port = port;
|
|
4457
|
+
this.host = host;
|
|
4458
|
+
this.name = "PortInUseError";
|
|
4459
|
+
}
|
|
4460
|
+
};
|
|
4461
|
+
function ensurePortAvailable(port, host) {
|
|
4462
|
+
return new Promise((resolve5, reject) => {
|
|
4450
4463
|
const server = net.createServer();
|
|
4451
4464
|
server.once("error", (err) => {
|
|
4452
4465
|
if (err.code === "EADDRINUSE") {
|
|
4453
|
-
|
|
4466
|
+
reject(new PortInUseError(port, host));
|
|
4454
4467
|
} else {
|
|
4455
|
-
|
|
4468
|
+
reject(err);
|
|
4456
4469
|
}
|
|
4457
4470
|
});
|
|
4458
4471
|
server.once("listening", () => {
|
|
4459
|
-
server.close(() => resolve5(
|
|
4472
|
+
server.close(() => resolve5());
|
|
4460
4473
|
});
|
|
4461
4474
|
server.listen(port, host);
|
|
4462
4475
|
});
|
|
4463
4476
|
}
|
|
4464
|
-
async function
|
|
4465
|
-
|
|
4466
|
-
|
|
4467
|
-
|
|
4468
|
-
|
|
4469
|
-
|
|
4470
|
-
|
|
4471
|
-
|
|
4472
|
-
|
|
4473
|
-
|
|
4477
|
+
async function findPortHolder(port) {
|
|
4478
|
+
try {
|
|
4479
|
+
if (process.platform === "win32") {
|
|
4480
|
+
const { stdout: stdout2 } = await execFileAsync("netstat", ["-ano", "-p", "tcp"], {
|
|
4481
|
+
timeout: 1500
|
|
4482
|
+
});
|
|
4483
|
+
const pid2 = parseWindowsNetstatPid(stdout2, port);
|
|
4484
|
+
return pid2 === null ? null : { pid: pid2 };
|
|
4485
|
+
}
|
|
4486
|
+
const { stdout } = await execFileAsync(
|
|
4487
|
+
"lsof",
|
|
4488
|
+
["-nP", `-iTCP:${port}`, "-sTCP:LISTEN", "-t"],
|
|
4489
|
+
{ timeout: 1500 }
|
|
4490
|
+
);
|
|
4491
|
+
const pid = Number.parseInt(stdout.trim().split(/\s+/)[0], 10);
|
|
4492
|
+
if (!Number.isInteger(pid)) return null;
|
|
4493
|
+
let name;
|
|
4494
|
+
try {
|
|
4495
|
+
const { stdout: comm } = await execFileAsync(
|
|
4496
|
+
"ps",
|
|
4497
|
+
["-p", String(pid), "-o", "comm="],
|
|
4498
|
+
{ timeout: 1500 }
|
|
4499
|
+
);
|
|
4500
|
+
name = comm.trim().split("/").pop() || void 0;
|
|
4501
|
+
} catch {
|
|
4502
|
+
}
|
|
4503
|
+
return { pid, name };
|
|
4504
|
+
} catch {
|
|
4505
|
+
return null;
|
|
4506
|
+
}
|
|
4507
|
+
}
|
|
4508
|
+
function parseWindowsNetstatPid(stdout, port) {
|
|
4509
|
+
for (const line of stdout.split(/\r?\n/)) {
|
|
4510
|
+
const parts = line.trim().split(/\s+/);
|
|
4511
|
+
if (parts.length >= 5 && parts[3] === "LISTENING" && parts[1]?.endsWith(`:${port}`)) {
|
|
4512
|
+
const pid = Number.parseInt(parts[4], 10);
|
|
4513
|
+
if (Number.isInteger(pid)) return pid;
|
|
4514
|
+
}
|
|
4515
|
+
}
|
|
4516
|
+
return null;
|
|
4474
4517
|
}
|
|
4475
4518
|
|
|
4476
4519
|
// src/cli/restart-watcher.ts
|
|
@@ -4535,6 +4578,22 @@ async function loadFullConfig(cwd, mode, envSnapshot, opts = {}) {
|
|
|
4535
4578
|
loadEnv(config, cwd, mode, "development");
|
|
4536
4579
|
return config;
|
|
4537
4580
|
}
|
|
4581
|
+
async function renderPortInUseError(err) {
|
|
4582
|
+
const holder = await findPortHolder(err.port);
|
|
4583
|
+
console.error();
|
|
4584
|
+
console.error(chalk3.red(` \u2716 \u7AEF\u53E3 ${err.port} \u5DF2\u88AB\u5360\u7528\uFF0C\u65E0\u6CD5\u542F\u52A8 dev server`));
|
|
4585
|
+
if (holder) {
|
|
4586
|
+
const label = holder.name ? `${holder.name} ` : "";
|
|
4587
|
+
const killCmd = process.platform === "win32" ? `taskkill /PID ${holder.pid} /F` : `kill ${holder.pid}`;
|
|
4588
|
+
console.error(chalk3.gray(` \u5360\u7528\u8FDB\u7A0B\uFF1A${label}(PID ${holder.pid})`));
|
|
4589
|
+
console.error(chalk3.gray(` \xB7 \u7ED3\u675F\u5B83\uFF1A${killCmd}`));
|
|
4590
|
+
console.error(chalk3.gray(" \xB7 \u6216\u4FEE\u6539\u914D\u7F6E dev.port \u6362\u4E00\u4E2A\u7AEF\u53E3"));
|
|
4591
|
+
} else {
|
|
4592
|
+
console.error(chalk3.gray(" \xB7 \u4FEE\u6539\u914D\u7F6E dev.port \u6362\u4E00\u4E2A\u7AEF\u53E3"));
|
|
4593
|
+
console.error(chalk3.gray(" \xB7 \u6216\u5148\u91CA\u653E\u5360\u7528\u8BE5\u7AEF\u53E3\u7684\u8FDB\u7A0B"));
|
|
4594
|
+
}
|
|
4595
|
+
console.error();
|
|
4596
|
+
}
|
|
4538
4597
|
async function startDevServer(cwd, config) {
|
|
4539
4598
|
const pluginManager = new PluginManager(config, cwd, true);
|
|
4540
4599
|
if (config.plugins && config.plugins.length > 0) {
|
|
@@ -4544,13 +4603,9 @@ async function startDevServer(cwd, config) {
|
|
|
4544
4603
|
let rspackConfig = createRspackConfig(config, cwd, { isDev: true });
|
|
4545
4604
|
rspackConfig = await pluginManager.applyRspackConfigHooks(rspackConfig);
|
|
4546
4605
|
const host = config.dev.host || "127.0.0.1";
|
|
4547
|
-
const
|
|
4548
|
-
|
|
4606
|
+
const port = config.dev.port || 3e3;
|
|
4607
|
+
await ensurePortAvailable(port, host);
|
|
4549
4608
|
const pluginNames = pluginManager.getPluginNames();
|
|
4550
|
-
if (port !== preferredPort) {
|
|
4551
|
-
console.log(chalk3.yellow(` Port ${preferredPort} is in use, using ${port} instead.
|
|
4552
|
-
`));
|
|
4553
|
-
}
|
|
4554
4609
|
const printer = new DevPrinter(host, port, pluginNames);
|
|
4555
4610
|
printer.printBanner();
|
|
4556
4611
|
printer.printBuildStart();
|
|
@@ -4668,10 +4723,17 @@ async function dev(options = {}) {
|
|
|
4668
4723
|
await current.close();
|
|
4669
4724
|
current = await startDevServer(cwd, nextConfig);
|
|
4670
4725
|
} catch (error) {
|
|
4671
|
-
|
|
4672
|
-
|
|
4673
|
-
|
|
4674
|
-
|
|
4726
|
+
if (error instanceof PortInUseError) {
|
|
4727
|
+
await renderPortInUseError(error);
|
|
4728
|
+
console.error(
|
|
4729
|
+
chalk3.red(" \u2716 dev server \u91CD\u542F\u5931\u8D25\uFF0C\u5F53\u524D\u670D\u52A1\u4E0D\u53EF\u7528\uFF0C\u8BF7\u4FEE\u6B63\u540E\u4FDD\u5B58\u91CD\u8BD5")
|
|
4730
|
+
);
|
|
4731
|
+
} else {
|
|
4732
|
+
console.error(
|
|
4733
|
+
chalk3.red(" \u2716 dev server \u91CD\u542F\u5931\u8D25\uFF0C\u5F53\u524D\u670D\u52A1\u4E0D\u53EF\u7528\uFF0C\u8BF7\u4FEE\u6B63\u540E\u4FDD\u5B58\u91CD\u8BD5:")
|
|
4734
|
+
);
|
|
4735
|
+
console.error(error);
|
|
4736
|
+
}
|
|
4675
4737
|
}
|
|
4676
4738
|
} while (pending);
|
|
4677
4739
|
} finally {
|
|
@@ -4680,6 +4742,10 @@ async function dev(options = {}) {
|
|
|
4680
4742
|
}
|
|
4681
4743
|
});
|
|
4682
4744
|
} catch (error) {
|
|
4745
|
+
if (error instanceof PortInUseError) {
|
|
4746
|
+
await renderPortInUseError(error);
|
|
4747
|
+
process.exit(1);
|
|
4748
|
+
}
|
|
4683
4749
|
console.error();
|
|
4684
4750
|
console.error(chalk3.red(" \u2716 Dev server failed to start"));
|
|
4685
4751
|
console.error(error);
|