@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.js
CHANGED
|
@@ -935,7 +935,7 @@ async function transformRequest(url, ctx) {
|
|
|
935
935
|
config.mode
|
|
936
936
|
);
|
|
937
937
|
code = replaceEnvInCode(code, envDefine);
|
|
938
|
-
code = rewriteImports(code, config);
|
|
938
|
+
code = rewriteImports(code, config, filePath);
|
|
939
939
|
const transformResult = { code };
|
|
940
940
|
mod.transformResult = transformResult;
|
|
941
941
|
return transformResult;
|
|
@@ -1017,26 +1017,73 @@ async function injectCjsNamedExports(code, entryFile) {
|
|
|
1017
1017
|
return code;
|
|
1018
1018
|
}
|
|
1019
1019
|
}
|
|
1020
|
-
function rewriteImports(code,
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1020
|
+
function rewriteImports(code, config, filePath) {
|
|
1021
|
+
const root = config.root;
|
|
1022
|
+
const fileDir = path4.dirname(filePath);
|
|
1023
|
+
const aliasEntries = Object.entries(config.resolve.alias).sort(
|
|
1024
|
+
([a], [b]) => b.length - a.length
|
|
1025
|
+
);
|
|
1026
|
+
const toRootUrl = (abs) => "/" + path4.relative(root, abs).replace(/\\/g, "/");
|
|
1027
|
+
const transformSpec = (spec) => {
|
|
1028
|
+
const suffixMatch = spec.match(/[?#].*$/);
|
|
1029
|
+
const suffix = suffixMatch ? suffixMatch[0] : "";
|
|
1030
|
+
const baseSpec = suffix ? spec.slice(0, -suffix.length) : spec;
|
|
1031
|
+
for (const [key, value] of aliasEntries) {
|
|
1032
|
+
if (baseSpec === key || baseSpec.startsWith(key + "/")) {
|
|
1033
|
+
const aliasBase = resolveAliasTarget(value, root);
|
|
1034
|
+
const sub = baseSpec.slice(key.length).replace(/^\//, "");
|
|
1035
|
+
const target = sub ? path4.join(aliasBase, sub) : aliasBase;
|
|
1036
|
+
const resolved = tryResolveDiskPath(target);
|
|
1037
|
+
return resolved && isUnderRoot(resolved, root) ? toRootUrl(resolved) + suffix : spec;
|
|
1038
|
+
}
|
|
1025
1039
|
}
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
return `import ${quote}/@modules/${specifier}${quote}`;
|
|
1040
|
+
if (baseSpec.startsWith("./") || baseSpec.startsWith("../")) {
|
|
1041
|
+
const target = path4.resolve(fileDir, baseSpec);
|
|
1042
|
+
const resolved = tryResolveDiskPath(target);
|
|
1043
|
+
return resolved && isUnderRoot(resolved, root) ? toRootUrl(resolved) + suffix : spec;
|
|
1031
1044
|
}
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
return `import(${quote}/@modules/${specifier}${quote})`;
|
|
1045
|
+
if (baseSpec.startsWith("/") && !baseSpec.startsWith("/@")) {
|
|
1046
|
+
const target = path4.join(root, baseSpec.replace(/^\//, ""));
|
|
1047
|
+
const resolved = tryResolveDiskPath(target);
|
|
1048
|
+
return resolved && isUnderRoot(resolved, root) ? toRootUrl(resolved) + suffix : spec;
|
|
1037
1049
|
}
|
|
1050
|
+
if (baseSpec.startsWith("/")) return spec;
|
|
1051
|
+
return `/@modules/${spec}`;
|
|
1052
|
+
};
|
|
1053
|
+
return code.replace(
|
|
1054
|
+
/\bfrom\s+(['"])([^'"]+)\1/g,
|
|
1055
|
+
(_m, q, s) => `from ${q}${transformSpec(s)}${q}`
|
|
1056
|
+
).replace(
|
|
1057
|
+
/\bimport\s+(['"])([^'"]+)\1/g,
|
|
1058
|
+
(_m, q, s) => `import ${q}${transformSpec(s)}${q}`
|
|
1059
|
+
).replace(
|
|
1060
|
+
/\bimport\s*\(\s*(['"])([^'"]+)\1\s*\)/g,
|
|
1061
|
+
(_m, q, s) => `import(${q}${transformSpec(s)}${q})`
|
|
1038
1062
|
);
|
|
1039
1063
|
}
|
|
1064
|
+
function resolveAliasTarget(value, root) {
|
|
1065
|
+
if (path4.isAbsolute(value) && fs4.existsSync(value)) return value;
|
|
1066
|
+
if (value.startsWith("/")) return path4.join(root, value.slice(1));
|
|
1067
|
+
return path4.resolve(root, value);
|
|
1068
|
+
}
|
|
1069
|
+
function tryResolveDiskPath(target) {
|
|
1070
|
+
if (fs4.existsSync(target) && fs4.statSync(target).isFile()) return target;
|
|
1071
|
+
for (const ext of RESOLVE_EXTENSIONS) {
|
|
1072
|
+
const withExt = target + ext;
|
|
1073
|
+
if (fs4.existsSync(withExt) && fs4.statSync(withExt).isFile()) return withExt;
|
|
1074
|
+
}
|
|
1075
|
+
if (fs4.existsSync(target) && fs4.statSync(target).isDirectory()) {
|
|
1076
|
+
for (const ext of RESOLVE_EXTENSIONS) {
|
|
1077
|
+
const idx = path4.join(target, "index" + ext);
|
|
1078
|
+
if (fs4.existsSync(idx) && fs4.statSync(idx).isFile()) return idx;
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
return null;
|
|
1082
|
+
}
|
|
1083
|
+
function isUnderRoot(abs, root) {
|
|
1084
|
+
const rel = path4.relative(root, abs);
|
|
1085
|
+
return !!rel && !rel.startsWith("..") && !path4.isAbsolute(rel);
|
|
1086
|
+
}
|
|
1040
1087
|
function resolveNodeModule(root, moduleName) {
|
|
1041
1088
|
let pkgName;
|
|
1042
1089
|
let subpath;
|
|
@@ -1604,12 +1651,19 @@ async function createServer(inlineConfig = {}) {
|
|
|
1604
1651
|
app.use(sirv(config.root, { dev: true, etag: true }));
|
|
1605
1652
|
const httpServer = http.createServer(app);
|
|
1606
1653
|
const ws = createWebSocketServer(httpServer);
|
|
1654
|
+
const ignoredSegments = /* @__PURE__ */ new Set(["node_modules", ".git", ".nasti"]);
|
|
1655
|
+
const outDirAbs = path9.resolve(config.root, config.build.outDir);
|
|
1607
1656
|
const watcher = watch(config.root, {
|
|
1608
|
-
ignored:
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1657
|
+
ignored: (filePath) => {
|
|
1658
|
+
if (filePath === config.root) return false;
|
|
1659
|
+
if (filePath === outDirAbs || filePath.startsWith(outDirAbs + path9.sep)) return true;
|
|
1660
|
+
const rel = path9.relative(config.root, filePath);
|
|
1661
|
+
if (!rel || rel.startsWith("..") || path9.isAbsolute(rel)) return false;
|
|
1662
|
+
for (const seg of rel.split(path9.sep)) {
|
|
1663
|
+
if (ignoredSegments.has(seg)) return true;
|
|
1664
|
+
}
|
|
1665
|
+
return false;
|
|
1666
|
+
},
|
|
1613
1667
|
ignoreInitial: true
|
|
1614
1668
|
});
|
|
1615
1669
|
let server;
|
|
@@ -1637,7 +1691,7 @@ async function createServer(inlineConfig = {}) {
|
|
|
1637
1691
|
const localUrl = `http://localhost:${actualPort}`;
|
|
1638
1692
|
const networkUrl = host === "0.0.0.0" ? `http://${getNetworkAddress()}:${actualPort}` : null;
|
|
1639
1693
|
console.log();
|
|
1640
|
-
console.log(pc.cyan(" nasti dev server") + pc.dim(` v${"1.
|
|
1694
|
+
console.log(pc.cyan(" nasti dev server") + pc.dim(` v${"1.6.1"}`));
|
|
1641
1695
|
console.log();
|
|
1642
1696
|
console.log(` ${pc.green(">")} Local: ${pc.cyan(localUrl)}`);
|
|
1643
1697
|
if (networkUrl) {
|
|
@@ -1760,7 +1814,7 @@ import pc2 from "picocolors";
|
|
|
1760
1814
|
async function build(inlineConfig = {}) {
|
|
1761
1815
|
const config = await resolveConfig(inlineConfig, "build");
|
|
1762
1816
|
const startTime = performance.now();
|
|
1763
|
-
console.log(pc2.cyan("\n\u{1F528} nasti build") + pc2.dim(` v${"1.
|
|
1817
|
+
console.log(pc2.cyan("\n\u{1F528} nasti build") + pc2.dim(` v${"1.6.1"}`));
|
|
1764
1818
|
console.log(pc2.dim(` root: ${config.root}`));
|
|
1765
1819
|
console.log(pc2.dim(` mode: ${config.mode}`));
|
|
1766
1820
|
const outDir = path10.resolve(config.root, config.build.outDir);
|
|
@@ -1920,7 +1974,7 @@ async function buildElectron(inlineConfig = {}) {
|
|
|
1920
1974
|
const config = await resolveConfig({ ...inlineConfig, target: "electron" }, "build");
|
|
1921
1975
|
const startTime = performance.now();
|
|
1922
1976
|
assertElectronVersion(config);
|
|
1923
|
-
console.log(pc3.cyan("\n\u26A1 nasti build (electron)") + pc3.dim(` v${"1.
|
|
1977
|
+
console.log(pc3.cyan("\n\u26A1 nasti build (electron)") + pc3.dim(` v${"1.6.1"}`));
|
|
1924
1978
|
console.log(pc3.dim(` root: ${config.root}`));
|
|
1925
1979
|
console.log(pc3.dim(` mode: ${config.mode}`));
|
|
1926
1980
|
console.log(pc3.dim(` target: electron (\u2265 ${config.electron.minVersion})`));
|
|
@@ -2011,7 +2065,7 @@ async function bundleNode(config, entry, opts) {
|
|
|
2011
2065
|
format: opts.format === "cjs" ? "cjs" : "esm",
|
|
2012
2066
|
sourcemap: !!config.build.sourcemap,
|
|
2013
2067
|
minify: !!config.build.minify,
|
|
2014
|
-
|
|
2068
|
+
codeSplitting: false
|
|
2015
2069
|
});
|
|
2016
2070
|
await bundle.close();
|
|
2017
2071
|
console.log(pc3.dim(` \u2713 ${opts.label} \u2192 ${path11.relative(config.root, opts.outFile)}`));
|
|
@@ -2074,7 +2128,7 @@ async function startElectronDev(inlineConfig = {}) {
|
|
|
2074
2128
|
const { noSpawn, ...rest } = inlineConfig;
|
|
2075
2129
|
const config = await resolveConfig({ ...rest, target: "electron" }, "serve");
|
|
2076
2130
|
warnElectronVersion(config);
|
|
2077
|
-
console.log(pc4.cyan("\n\u26A1 nasti electron dev") + pc4.dim(` v${"1.
|
|
2131
|
+
console.log(pc4.cyan("\n\u26A1 nasti electron dev") + pc4.dim(` v${"1.6.1"}`));
|
|
2078
2132
|
const { createServer: createServer2 } = await Promise.resolve().then(() => (init_server(), server_exports));
|
|
2079
2133
|
const server = await createServer2({ ...rest, target: "electron" });
|
|
2080
2134
|
await server.listen();
|
|
@@ -2217,7 +2271,9 @@ async function compileNode(config, entry, opts) {
|
|
|
2217
2271
|
format: opts.format === "cjs" ? "cjs" : "esm",
|
|
2218
2272
|
sourcemap: false,
|
|
2219
2273
|
minify: false,
|
|
2220
|
-
inlineDynamicImports:
|
|
2274
|
+
// rolldown 已弃用 inlineDynamicImports,改用 codeSplitting:false 表达
|
|
2275
|
+
// 同样语义(单 chunk、内联 dynamic import)
|
|
2276
|
+
codeSplitting: false
|
|
2221
2277
|
});
|
|
2222
2278
|
await bundle.close();
|
|
2223
2279
|
}
|
|
@@ -2399,6 +2455,6 @@ cli.command("preview [root]", "Preview production build").option("--port <port>"
|
|
|
2399
2455
|
}
|
|
2400
2456
|
});
|
|
2401
2457
|
cli.help();
|
|
2402
|
-
cli.version("1.
|
|
2458
|
+
cli.version("1.6.1");
|
|
2403
2459
|
cli.parse();
|
|
2404
2460
|
//# sourceMappingURL=cli.js.map
|