@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/index.js
CHANGED
|
@@ -793,7 +793,7 @@ import pc from "picocolors";
|
|
|
793
793
|
async function build(inlineConfig = {}) {
|
|
794
794
|
const config = await resolveConfig(inlineConfig, "build");
|
|
795
795
|
const startTime = performance.now();
|
|
796
|
-
console.log(pc.cyan("\n\u{1F528} nasti build") + pc.dim(` v${"1.
|
|
796
|
+
console.log(pc.cyan("\n\u{1F528} nasti build") + pc.dim(` v${"1.6.1"}`));
|
|
797
797
|
console.log(pc.dim(` root: ${config.root}`));
|
|
798
798
|
console.log(pc.dim(` mode: ${config.mode}`));
|
|
799
799
|
const outDir = path7.resolve(config.root, config.build.outDir);
|
|
@@ -1300,7 +1300,7 @@ async function transformRequest(url, ctx) {
|
|
|
1300
1300
|
config.mode
|
|
1301
1301
|
);
|
|
1302
1302
|
code = replaceEnvInCode(code, envDefine);
|
|
1303
|
-
code = rewriteImports(code, config);
|
|
1303
|
+
code = rewriteImports(code, config, filePath);
|
|
1304
1304
|
const transformResult = { code };
|
|
1305
1305
|
mod.transformResult = transformResult;
|
|
1306
1306
|
return transformResult;
|
|
@@ -1382,26 +1382,73 @@ async function injectCjsNamedExports(code, entryFile) {
|
|
|
1382
1382
|
return code;
|
|
1383
1383
|
}
|
|
1384
1384
|
}
|
|
1385
|
-
function rewriteImports(code,
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1385
|
+
function rewriteImports(code, config, filePath) {
|
|
1386
|
+
const root = config.root;
|
|
1387
|
+
const fileDir = path9.dirname(filePath);
|
|
1388
|
+
const aliasEntries = Object.entries(config.resolve.alias).sort(
|
|
1389
|
+
([a], [b]) => b.length - a.length
|
|
1390
|
+
);
|
|
1391
|
+
const toRootUrl = (abs) => "/" + path9.relative(root, abs).replace(/\\/g, "/");
|
|
1392
|
+
const transformSpec = (spec) => {
|
|
1393
|
+
const suffixMatch = spec.match(/[?#].*$/);
|
|
1394
|
+
const suffix = suffixMatch ? suffixMatch[0] : "";
|
|
1395
|
+
const baseSpec = suffix ? spec.slice(0, -suffix.length) : spec;
|
|
1396
|
+
for (const [key, value] of aliasEntries) {
|
|
1397
|
+
if (baseSpec === key || baseSpec.startsWith(key + "/")) {
|
|
1398
|
+
const aliasBase = resolveAliasTarget(value, root);
|
|
1399
|
+
const sub = baseSpec.slice(key.length).replace(/^\//, "");
|
|
1400
|
+
const target = sub ? path9.join(aliasBase, sub) : aliasBase;
|
|
1401
|
+
const resolved = tryResolveDiskPath(target);
|
|
1402
|
+
return resolved && isUnderRoot(resolved, root) ? toRootUrl(resolved) + suffix : spec;
|
|
1403
|
+
}
|
|
1390
1404
|
}
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
return `import ${quote}/@modules/${specifier}${quote}`;
|
|
1405
|
+
if (baseSpec.startsWith("./") || baseSpec.startsWith("../")) {
|
|
1406
|
+
const target = path9.resolve(fileDir, baseSpec);
|
|
1407
|
+
const resolved = tryResolveDiskPath(target);
|
|
1408
|
+
return resolved && isUnderRoot(resolved, root) ? toRootUrl(resolved) + suffix : spec;
|
|
1396
1409
|
}
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
return `import(${quote}/@modules/${specifier}${quote})`;
|
|
1410
|
+
if (baseSpec.startsWith("/") && !baseSpec.startsWith("/@")) {
|
|
1411
|
+
const target = path9.join(root, baseSpec.replace(/^\//, ""));
|
|
1412
|
+
const resolved = tryResolveDiskPath(target);
|
|
1413
|
+
return resolved && isUnderRoot(resolved, root) ? toRootUrl(resolved) + suffix : spec;
|
|
1402
1414
|
}
|
|
1415
|
+
if (baseSpec.startsWith("/")) return spec;
|
|
1416
|
+
return `/@modules/${spec}`;
|
|
1417
|
+
};
|
|
1418
|
+
return code.replace(
|
|
1419
|
+
/\bfrom\s+(['"])([^'"]+)\1/g,
|
|
1420
|
+
(_m, q, s) => `from ${q}${transformSpec(s)}${q}`
|
|
1421
|
+
).replace(
|
|
1422
|
+
/\bimport\s+(['"])([^'"]+)\1/g,
|
|
1423
|
+
(_m, q, s) => `import ${q}${transformSpec(s)}${q}`
|
|
1424
|
+
).replace(
|
|
1425
|
+
/\bimport\s*\(\s*(['"])([^'"]+)\1\s*\)/g,
|
|
1426
|
+
(_m, q, s) => `import(${q}${transformSpec(s)}${q})`
|
|
1403
1427
|
);
|
|
1404
1428
|
}
|
|
1429
|
+
function resolveAliasTarget(value, root) {
|
|
1430
|
+
if (path9.isAbsolute(value) && fs8.existsSync(value)) return value;
|
|
1431
|
+
if (value.startsWith("/")) return path9.join(root, value.slice(1));
|
|
1432
|
+
return path9.resolve(root, value);
|
|
1433
|
+
}
|
|
1434
|
+
function tryResolveDiskPath(target) {
|
|
1435
|
+
if (fs8.existsSync(target) && fs8.statSync(target).isFile()) return target;
|
|
1436
|
+
for (const ext of RESOLVE_EXTENSIONS) {
|
|
1437
|
+
const withExt = target + ext;
|
|
1438
|
+
if (fs8.existsSync(withExt) && fs8.statSync(withExt).isFile()) return withExt;
|
|
1439
|
+
}
|
|
1440
|
+
if (fs8.existsSync(target) && fs8.statSync(target).isDirectory()) {
|
|
1441
|
+
for (const ext of RESOLVE_EXTENSIONS) {
|
|
1442
|
+
const idx = path9.join(target, "index" + ext);
|
|
1443
|
+
if (fs8.existsSync(idx) && fs8.statSync(idx).isFile()) return idx;
|
|
1444
|
+
}
|
|
1445
|
+
}
|
|
1446
|
+
return null;
|
|
1447
|
+
}
|
|
1448
|
+
function isUnderRoot(abs, root) {
|
|
1449
|
+
const rel = path9.relative(root, abs);
|
|
1450
|
+
return !!rel && !rel.startsWith("..") && !path9.isAbsolute(rel);
|
|
1451
|
+
}
|
|
1405
1452
|
function resolveNodeModule(root, moduleName) {
|
|
1406
1453
|
let pkgName;
|
|
1407
1454
|
let subpath;
|
|
@@ -1764,12 +1811,19 @@ async function createServer(inlineConfig = {}) {
|
|
|
1764
1811
|
app.use(sirv(config.root, { dev: true, etag: true }));
|
|
1765
1812
|
const httpServer = http.createServer(app);
|
|
1766
1813
|
const ws = createWebSocketServer(httpServer);
|
|
1814
|
+
const ignoredSegments = /* @__PURE__ */ new Set(["node_modules", ".git", ".nasti"]);
|
|
1815
|
+
const outDirAbs = path11.resolve(config.root, config.build.outDir);
|
|
1767
1816
|
const watcher = watch(config.root, {
|
|
1768
|
-
ignored:
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1817
|
+
ignored: (filePath) => {
|
|
1818
|
+
if (filePath === config.root) return false;
|
|
1819
|
+
if (filePath === outDirAbs || filePath.startsWith(outDirAbs + path11.sep)) return true;
|
|
1820
|
+
const rel = path11.relative(config.root, filePath);
|
|
1821
|
+
if (!rel || rel.startsWith("..") || path11.isAbsolute(rel)) return false;
|
|
1822
|
+
for (const seg of rel.split(path11.sep)) {
|
|
1823
|
+
if (ignoredSegments.has(seg)) return true;
|
|
1824
|
+
}
|
|
1825
|
+
return false;
|
|
1826
|
+
},
|
|
1773
1827
|
ignoreInitial: true
|
|
1774
1828
|
});
|
|
1775
1829
|
let server;
|
|
@@ -1797,7 +1851,7 @@ async function createServer(inlineConfig = {}) {
|
|
|
1797
1851
|
const localUrl = `http://localhost:${actualPort}`;
|
|
1798
1852
|
const networkUrl = host === "0.0.0.0" ? `http://${getNetworkAddress()}:${actualPort}` : null;
|
|
1799
1853
|
console.log();
|
|
1800
|
-
console.log(pc3.cyan(" nasti dev server") + pc3.dim(` v${"1.
|
|
1854
|
+
console.log(pc3.cyan(" nasti dev server") + pc3.dim(` v${"1.6.1"}`));
|
|
1801
1855
|
console.log();
|
|
1802
1856
|
console.log(` ${pc3.green(">")} Local: ${pc3.cyan(localUrl)}`);
|
|
1803
1857
|
if (networkUrl) {
|
|
@@ -1921,7 +1975,7 @@ async function buildElectron(inlineConfig = {}) {
|
|
|
1921
1975
|
const config = await resolveConfig({ ...inlineConfig, target: "electron" }, "build");
|
|
1922
1976
|
const startTime = performance.now();
|
|
1923
1977
|
assertElectronVersion(config);
|
|
1924
|
-
console.log(pc2.cyan("\n\u26A1 nasti build (electron)") + pc2.dim(` v${"1.
|
|
1978
|
+
console.log(pc2.cyan("\n\u26A1 nasti build (electron)") + pc2.dim(` v${"1.6.1"}`));
|
|
1925
1979
|
console.log(pc2.dim(` root: ${config.root}`));
|
|
1926
1980
|
console.log(pc2.dim(` mode: ${config.mode}`));
|
|
1927
1981
|
console.log(pc2.dim(` target: electron (\u2265 ${config.electron.minVersion})`));
|
|
@@ -2012,7 +2066,7 @@ async function bundleNode(config, entry, opts) {
|
|
|
2012
2066
|
format: opts.format === "cjs" ? "cjs" : "esm",
|
|
2013
2067
|
sourcemap: !!config.build.sourcemap,
|
|
2014
2068
|
minify: !!config.build.minify,
|
|
2015
|
-
|
|
2069
|
+
codeSplitting: false
|
|
2016
2070
|
});
|
|
2017
2071
|
await bundle.close();
|
|
2018
2072
|
console.log(pc2.dim(` \u2713 ${opts.label} \u2192 ${path8.relative(config.root, opts.outFile)}`));
|
|
@@ -2068,7 +2122,7 @@ async function startElectronDev(inlineConfig = {}) {
|
|
|
2068
2122
|
const { noSpawn, ...rest } = inlineConfig;
|
|
2069
2123
|
const config = await resolveConfig({ ...rest, target: "electron" }, "serve");
|
|
2070
2124
|
warnElectronVersion(config);
|
|
2071
|
-
console.log(pc4.cyan("\n\u26A1 nasti electron dev") + pc4.dim(` v${"1.
|
|
2125
|
+
console.log(pc4.cyan("\n\u26A1 nasti electron dev") + pc4.dim(` v${"1.6.1"}`));
|
|
2072
2126
|
const { createServer: createServer2 } = await Promise.resolve().then(() => (init_server(), server_exports));
|
|
2073
2127
|
const server = await createServer2({ ...rest, target: "electron" });
|
|
2074
2128
|
await server.listen();
|
|
@@ -2211,7 +2265,9 @@ async function compileNode(config, entry, opts) {
|
|
|
2211
2265
|
format: opts.format === "cjs" ? "cjs" : "esm",
|
|
2212
2266
|
sourcemap: false,
|
|
2213
2267
|
minify: false,
|
|
2214
|
-
inlineDynamicImports:
|
|
2268
|
+
// rolldown 已弃用 inlineDynamicImports,改用 codeSplitting:false 表达
|
|
2269
|
+
// 同样语义(单 chunk、内联 dynamic import)
|
|
2270
|
+
codeSplitting: false
|
|
2215
2271
|
});
|
|
2216
2272
|
await bundle.close();
|
|
2217
2273
|
}
|
|
@@ -2317,7 +2373,7 @@ function monacoEditorPlugin(options = {}) {
|
|
|
2317
2373
|
format: "iife",
|
|
2318
2374
|
sourcemap: false,
|
|
2319
2375
|
minify: true,
|
|
2320
|
-
|
|
2376
|
+
codeSplitting: false
|
|
2321
2377
|
});
|
|
2322
2378
|
await bundle.close();
|
|
2323
2379
|
return cacheFile;
|