@nasti-toolchain/nasti 1.5.2 → 1.6.1
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.cjs +84 -28
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +84 -28
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +84 -28
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +84 -28
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
|
@@ -954,7 +954,7 @@ async function transformRequest(url, ctx) {
|
|
|
954
954
|
config.mode
|
|
955
955
|
);
|
|
956
956
|
code = replaceEnvInCode(code, envDefine);
|
|
957
|
-
code = rewriteImports(code, config);
|
|
957
|
+
code = rewriteImports(code, config, filePath);
|
|
958
958
|
const transformResult = { code };
|
|
959
959
|
mod.transformResult = transformResult;
|
|
960
960
|
return transformResult;
|
|
@@ -1036,26 +1036,73 @@ async function injectCjsNamedExports(code, entryFile) {
|
|
|
1036
1036
|
return code;
|
|
1037
1037
|
}
|
|
1038
1038
|
}
|
|
1039
|
-
function rewriteImports(code,
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1039
|
+
function rewriteImports(code, config, filePath) {
|
|
1040
|
+
const root = config.root;
|
|
1041
|
+
const fileDir = import_node_path4.default.dirname(filePath);
|
|
1042
|
+
const aliasEntries = Object.entries(config.resolve.alias).sort(
|
|
1043
|
+
([a], [b]) => b.length - a.length
|
|
1044
|
+
);
|
|
1045
|
+
const toRootUrl = (abs) => "/" + import_node_path4.default.relative(root, abs).replace(/\\/g, "/");
|
|
1046
|
+
const transformSpec = (spec) => {
|
|
1047
|
+
const suffixMatch = spec.match(/[?#].*$/);
|
|
1048
|
+
const suffix = suffixMatch ? suffixMatch[0] : "";
|
|
1049
|
+
const baseSpec = suffix ? spec.slice(0, -suffix.length) : spec;
|
|
1050
|
+
for (const [key, value] of aliasEntries) {
|
|
1051
|
+
if (baseSpec === key || baseSpec.startsWith(key + "/")) {
|
|
1052
|
+
const aliasBase = resolveAliasTarget(value, root);
|
|
1053
|
+
const sub = baseSpec.slice(key.length).replace(/^\//, "");
|
|
1054
|
+
const target = sub ? import_node_path4.default.join(aliasBase, sub) : aliasBase;
|
|
1055
|
+
const resolved = tryResolveDiskPath(target);
|
|
1056
|
+
return resolved && isUnderRoot(resolved, root) ? toRootUrl(resolved) + suffix : spec;
|
|
1057
|
+
}
|
|
1044
1058
|
}
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
return `import ${quote}/@modules/${specifier}${quote}`;
|
|
1059
|
+
if (baseSpec.startsWith("./") || baseSpec.startsWith("../")) {
|
|
1060
|
+
const target = import_node_path4.default.resolve(fileDir, baseSpec);
|
|
1061
|
+
const resolved = tryResolveDiskPath(target);
|
|
1062
|
+
return resolved && isUnderRoot(resolved, root) ? toRootUrl(resolved) + suffix : spec;
|
|
1050
1063
|
}
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
return `import(${quote}/@modules/${specifier}${quote})`;
|
|
1064
|
+
if (baseSpec.startsWith("/") && !baseSpec.startsWith("/@")) {
|
|
1065
|
+
const target = import_node_path4.default.join(root, baseSpec.replace(/^\//, ""));
|
|
1066
|
+
const resolved = tryResolveDiskPath(target);
|
|
1067
|
+
return resolved && isUnderRoot(resolved, root) ? toRootUrl(resolved) + suffix : spec;
|
|
1056
1068
|
}
|
|
1069
|
+
if (baseSpec.startsWith("/")) return spec;
|
|
1070
|
+
return `/@modules/${spec}`;
|
|
1071
|
+
};
|
|
1072
|
+
return code.replace(
|
|
1073
|
+
/\bfrom\s+(['"])([^'"]+)\1/g,
|
|
1074
|
+
(_m, q, s) => `from ${q}${transformSpec(s)}${q}`
|
|
1075
|
+
).replace(
|
|
1076
|
+
/\bimport\s+(['"])([^'"]+)\1/g,
|
|
1077
|
+
(_m, q, s) => `import ${q}${transformSpec(s)}${q}`
|
|
1078
|
+
).replace(
|
|
1079
|
+
/\bimport\s*\(\s*(['"])([^'"]+)\1\s*\)/g,
|
|
1080
|
+
(_m, q, s) => `import(${q}${transformSpec(s)}${q})`
|
|
1057
1081
|
);
|
|
1058
1082
|
}
|
|
1083
|
+
function resolveAliasTarget(value, root) {
|
|
1084
|
+
if (import_node_path4.default.isAbsolute(value) && import_node_fs4.default.existsSync(value)) return value;
|
|
1085
|
+
if (value.startsWith("/")) return import_node_path4.default.join(root, value.slice(1));
|
|
1086
|
+
return import_node_path4.default.resolve(root, value);
|
|
1087
|
+
}
|
|
1088
|
+
function tryResolveDiskPath(target) {
|
|
1089
|
+
if (import_node_fs4.default.existsSync(target) && import_node_fs4.default.statSync(target).isFile()) return target;
|
|
1090
|
+
for (const ext of RESOLVE_EXTENSIONS) {
|
|
1091
|
+
const withExt = target + ext;
|
|
1092
|
+
if (import_node_fs4.default.existsSync(withExt) && import_node_fs4.default.statSync(withExt).isFile()) return withExt;
|
|
1093
|
+
}
|
|
1094
|
+
if (import_node_fs4.default.existsSync(target) && import_node_fs4.default.statSync(target).isDirectory()) {
|
|
1095
|
+
for (const ext of RESOLVE_EXTENSIONS) {
|
|
1096
|
+
const idx = import_node_path4.default.join(target, "index" + ext);
|
|
1097
|
+
if (import_node_fs4.default.existsSync(idx) && import_node_fs4.default.statSync(idx).isFile()) return idx;
|
|
1098
|
+
}
|
|
1099
|
+
}
|
|
1100
|
+
return null;
|
|
1101
|
+
}
|
|
1102
|
+
function isUnderRoot(abs, root) {
|
|
1103
|
+
const rel = import_node_path4.default.relative(root, abs);
|
|
1104
|
+
return !!rel && !rel.startsWith("..") && !import_node_path4.default.isAbsolute(rel);
|
|
1105
|
+
}
|
|
1059
1106
|
function resolveNodeModule(root, moduleName) {
|
|
1060
1107
|
let pkgName;
|
|
1061
1108
|
let subpath;
|
|
@@ -1624,12 +1671,19 @@ async function createServer(inlineConfig = {}) {
|
|
|
1624
1671
|
app.use((0, import_sirv.default)(config.root, { dev: true, etag: true }));
|
|
1625
1672
|
const httpServer = import_node_http.default.createServer(app);
|
|
1626
1673
|
const ws = createWebSocketServer(httpServer);
|
|
1674
|
+
const ignoredSegments = /* @__PURE__ */ new Set(["node_modules", ".git", ".nasti"]);
|
|
1675
|
+
const outDirAbs = import_node_path9.default.resolve(config.root, config.build.outDir);
|
|
1627
1676
|
const watcher = (0, import_chokidar.watch)(config.root, {
|
|
1628
|
-
ignored:
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1677
|
+
ignored: (filePath) => {
|
|
1678
|
+
if (filePath === config.root) return false;
|
|
1679
|
+
if (filePath === outDirAbs || filePath.startsWith(outDirAbs + import_node_path9.default.sep)) return true;
|
|
1680
|
+
const rel = import_node_path9.default.relative(config.root, filePath);
|
|
1681
|
+
if (!rel || rel.startsWith("..") || import_node_path9.default.isAbsolute(rel)) return false;
|
|
1682
|
+
for (const seg of rel.split(import_node_path9.default.sep)) {
|
|
1683
|
+
if (ignoredSegments.has(seg)) return true;
|
|
1684
|
+
}
|
|
1685
|
+
return false;
|
|
1686
|
+
},
|
|
1633
1687
|
ignoreInitial: true
|
|
1634
1688
|
});
|
|
1635
1689
|
let server;
|
|
@@ -1657,7 +1711,7 @@ async function createServer(inlineConfig = {}) {
|
|
|
1657
1711
|
const localUrl = `http://localhost:${actualPort}`;
|
|
1658
1712
|
const networkUrl = host === "0.0.0.0" ? `http://${getNetworkAddress()}:${actualPort}` : null;
|
|
1659
1713
|
console.log();
|
|
1660
|
-
console.log(import_picocolors.default.cyan(" nasti dev server") + import_picocolors.default.dim(` v${"1.
|
|
1714
|
+
console.log(import_picocolors.default.cyan(" nasti dev server") + import_picocolors.default.dim(` v${"1.6.1"}`));
|
|
1661
1715
|
console.log();
|
|
1662
1716
|
console.log(` ${import_picocolors.default.green(">")} Local: ${import_picocolors.default.cyan(localUrl)}`);
|
|
1663
1717
|
if (networkUrl) {
|
|
@@ -1784,7 +1838,7 @@ __export(build_exports, {
|
|
|
1784
1838
|
async function build(inlineConfig = {}) {
|
|
1785
1839
|
const config = await resolveConfig(inlineConfig, "build");
|
|
1786
1840
|
const startTime = performance.now();
|
|
1787
|
-
console.log(import_picocolors2.default.cyan("\n\u{1F528} nasti build") + import_picocolors2.default.dim(` v${"1.
|
|
1841
|
+
console.log(import_picocolors2.default.cyan("\n\u{1F528} nasti build") + import_picocolors2.default.dim(` v${"1.6.1"}`));
|
|
1788
1842
|
console.log(import_picocolors2.default.dim(` root: ${config.root}`));
|
|
1789
1843
|
console.log(import_picocolors2.default.dim(` mode: ${config.mode}`));
|
|
1790
1844
|
const outDir = import_node_path10.default.resolve(config.root, config.build.outDir);
|
|
@@ -1945,7 +1999,7 @@ async function buildElectron(inlineConfig = {}) {
|
|
|
1945
1999
|
const config = await resolveConfig({ ...inlineConfig, target: "electron" }, "build");
|
|
1946
2000
|
const startTime = performance.now();
|
|
1947
2001
|
assertElectronVersion(config);
|
|
1948
|
-
console.log(import_picocolors3.default.cyan("\n\u26A1 nasti build (electron)") + import_picocolors3.default.dim(` v${"1.
|
|
2002
|
+
console.log(import_picocolors3.default.cyan("\n\u26A1 nasti build (electron)") + import_picocolors3.default.dim(` v${"1.6.1"}`));
|
|
1949
2003
|
console.log(import_picocolors3.default.dim(` root: ${config.root}`));
|
|
1950
2004
|
console.log(import_picocolors3.default.dim(` mode: ${config.mode}`));
|
|
1951
2005
|
console.log(import_picocolors3.default.dim(` target: electron (\u2265 ${config.electron.minVersion})`));
|
|
@@ -2036,7 +2090,7 @@ async function bundleNode(config, entry, opts) {
|
|
|
2036
2090
|
format: opts.format === "cjs" ? "cjs" : "esm",
|
|
2037
2091
|
sourcemap: !!config.build.sourcemap,
|
|
2038
2092
|
minify: !!config.build.minify,
|
|
2039
|
-
|
|
2093
|
+
codeSplitting: false
|
|
2040
2094
|
});
|
|
2041
2095
|
await bundle.close();
|
|
2042
2096
|
console.log(import_picocolors3.default.dim(` \u2713 ${opts.label} \u2192 ${import_node_path11.default.relative(config.root, opts.outFile)}`));
|
|
@@ -2097,7 +2151,7 @@ async function startElectronDev(inlineConfig = {}) {
|
|
|
2097
2151
|
const { noSpawn, ...rest } = inlineConfig;
|
|
2098
2152
|
const config = await resolveConfig({ ...rest, target: "electron" }, "serve");
|
|
2099
2153
|
warnElectronVersion(config);
|
|
2100
|
-
console.log(import_picocolors4.default.cyan("\n\u26A1 nasti electron dev") + import_picocolors4.default.dim(` v${"1.
|
|
2154
|
+
console.log(import_picocolors4.default.cyan("\n\u26A1 nasti electron dev") + import_picocolors4.default.dim(` v${"1.6.1"}`));
|
|
2101
2155
|
const { createServer: createServer2 } = await Promise.resolve().then(() => (init_server(), server_exports));
|
|
2102
2156
|
const server = await createServer2({ ...rest, target: "electron" });
|
|
2103
2157
|
await server.listen();
|
|
@@ -2240,7 +2294,9 @@ async function compileNode(config, entry, opts) {
|
|
|
2240
2294
|
format: opts.format === "cjs" ? "cjs" : "esm",
|
|
2241
2295
|
sourcemap: false,
|
|
2242
2296
|
minify: false,
|
|
2243
|
-
inlineDynamicImports:
|
|
2297
|
+
// rolldown 已弃用 inlineDynamicImports,改用 codeSplitting:false 表达
|
|
2298
|
+
// 同样语义(单 chunk、内联 dynamic import)
|
|
2299
|
+
codeSplitting: false
|
|
2244
2300
|
});
|
|
2245
2301
|
await bundle.close();
|
|
2246
2302
|
}
|
|
@@ -2430,6 +2486,6 @@ cli.command("preview [root]", "Preview production build").option("--port <port>"
|
|
|
2430
2486
|
}
|
|
2431
2487
|
});
|
|
2432
2488
|
cli.help();
|
|
2433
|
-
cli.version("1.
|
|
2489
|
+
cli.version("1.6.1");
|
|
2434
2490
|
cli.parse();
|
|
2435
2491
|
//# sourceMappingURL=cli.cjs.map
|