@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/index.cjs CHANGED
@@ -814,7 +814,7 @@ __export(build_exports, {
814
814
  async function build(inlineConfig = {}) {
815
815
  const config = await resolveConfig(inlineConfig, "build");
816
816
  const startTime = performance.now();
817
- console.log(import_picocolors.default.cyan("\n\u{1F528} nasti build") + import_picocolors.default.dim(` v${"1.5.2"}`));
817
+ console.log(import_picocolors.default.cyan("\n\u{1F528} nasti build") + import_picocolors.default.dim(` v${"1.6.1"}`));
818
818
  console.log(import_picocolors.default.dim(` root: ${config.root}`));
819
819
  console.log(import_picocolors.default.dim(` mode: ${config.mode}`));
820
820
  const outDir = import_node_path7.default.resolve(config.root, config.build.outDir);
@@ -1323,7 +1323,7 @@ async function transformRequest(url, ctx) {
1323
1323
  config.mode
1324
1324
  );
1325
1325
  code = replaceEnvInCode(code, envDefine);
1326
- code = rewriteImports(code, config);
1326
+ code = rewriteImports(code, config, filePath);
1327
1327
  const transformResult = { code };
1328
1328
  mod.transformResult = transformResult;
1329
1329
  return transformResult;
@@ -1405,26 +1405,73 @@ async function injectCjsNamedExports(code, entryFile) {
1405
1405
  return code;
1406
1406
  }
1407
1407
  }
1408
- function rewriteImports(code, _config) {
1409
- return code.replace(
1410
- /\bfrom\s+(['"])([^'"./][^'"]*)\1/g,
1411
- (match, quote, specifier) => {
1412
- return `from ${quote}/@modules/${specifier}${quote}`;
1408
+ function rewriteImports(code, config, filePath) {
1409
+ const root = config.root;
1410
+ const fileDir = import_node_path9.default.dirname(filePath);
1411
+ const aliasEntries = Object.entries(config.resolve.alias).sort(
1412
+ ([a], [b]) => b.length - a.length
1413
+ );
1414
+ const toRootUrl = (abs) => "/" + import_node_path9.default.relative(root, abs).replace(/\\/g, "/");
1415
+ const transformSpec = (spec) => {
1416
+ const suffixMatch = spec.match(/[?#].*$/);
1417
+ const suffix = suffixMatch ? suffixMatch[0] : "";
1418
+ const baseSpec = suffix ? spec.slice(0, -suffix.length) : spec;
1419
+ for (const [key, value] of aliasEntries) {
1420
+ if (baseSpec === key || baseSpec.startsWith(key + "/")) {
1421
+ const aliasBase = resolveAliasTarget(value, root);
1422
+ const sub = baseSpec.slice(key.length).replace(/^\//, "");
1423
+ const target = sub ? import_node_path9.default.join(aliasBase, sub) : aliasBase;
1424
+ const resolved = tryResolveDiskPath(target);
1425
+ return resolved && isUnderRoot(resolved, root) ? toRootUrl(resolved) + suffix : spec;
1426
+ }
1413
1427
  }
1414
- ).replace(
1415
- // 处理纯副作用导入: import 'bare-specifier'
1416
- /\bimport\s+(['"])([^'"./][^'"]*)\1/g,
1417
- (match, quote, specifier) => {
1418
- return `import ${quote}/@modules/${specifier}${quote}`;
1428
+ if (baseSpec.startsWith("./") || baseSpec.startsWith("../")) {
1429
+ const target = import_node_path9.default.resolve(fileDir, baseSpec);
1430
+ const resolved = tryResolveDiskPath(target);
1431
+ return resolved && isUnderRoot(resolved, root) ? toRootUrl(resolved) + suffix : spec;
1419
1432
  }
1420
- ).replace(
1421
- // 处理动态导入: import('bare-specifier')
1422
- /\bimport\s*\(\s*(['"])([^'"./][^'"]*)\1\s*\)/g,
1423
- (match, quote, specifier) => {
1424
- return `import(${quote}/@modules/${specifier}${quote})`;
1433
+ if (baseSpec.startsWith("/") && !baseSpec.startsWith("/@")) {
1434
+ const target = import_node_path9.default.join(root, baseSpec.replace(/^\//, ""));
1435
+ const resolved = tryResolveDiskPath(target);
1436
+ return resolved && isUnderRoot(resolved, root) ? toRootUrl(resolved) + suffix : spec;
1425
1437
  }
1438
+ if (baseSpec.startsWith("/")) return spec;
1439
+ return `/@modules/${spec}`;
1440
+ };
1441
+ return code.replace(
1442
+ /\bfrom\s+(['"])([^'"]+)\1/g,
1443
+ (_m, q, s) => `from ${q}${transformSpec(s)}${q}`
1444
+ ).replace(
1445
+ /\bimport\s+(['"])([^'"]+)\1/g,
1446
+ (_m, q, s) => `import ${q}${transformSpec(s)}${q}`
1447
+ ).replace(
1448
+ /\bimport\s*\(\s*(['"])([^'"]+)\1\s*\)/g,
1449
+ (_m, q, s) => `import(${q}${transformSpec(s)}${q})`
1426
1450
  );
1427
1451
  }
1452
+ function resolveAliasTarget(value, root) {
1453
+ if (import_node_path9.default.isAbsolute(value) && import_node_fs8.default.existsSync(value)) return value;
1454
+ if (value.startsWith("/")) return import_node_path9.default.join(root, value.slice(1));
1455
+ return import_node_path9.default.resolve(root, value);
1456
+ }
1457
+ function tryResolveDiskPath(target) {
1458
+ if (import_node_fs8.default.existsSync(target) && import_node_fs8.default.statSync(target).isFile()) return target;
1459
+ for (const ext of RESOLVE_EXTENSIONS) {
1460
+ const withExt = target + ext;
1461
+ if (import_node_fs8.default.existsSync(withExt) && import_node_fs8.default.statSync(withExt).isFile()) return withExt;
1462
+ }
1463
+ if (import_node_fs8.default.existsSync(target) && import_node_fs8.default.statSync(target).isDirectory()) {
1464
+ for (const ext of RESOLVE_EXTENSIONS) {
1465
+ const idx = import_node_path9.default.join(target, "index" + ext);
1466
+ if (import_node_fs8.default.existsSync(idx) && import_node_fs8.default.statSync(idx).isFile()) return idx;
1467
+ }
1468
+ }
1469
+ return null;
1470
+ }
1471
+ function isUnderRoot(abs, root) {
1472
+ const rel = import_node_path9.default.relative(root, abs);
1473
+ return !!rel && !rel.startsWith("..") && !import_node_path9.default.isAbsolute(rel);
1474
+ }
1428
1475
  function resolveNodeModule(root, moduleName) {
1429
1476
  let pkgName;
1430
1477
  let subpath;
@@ -1786,12 +1833,19 @@ async function createServer(inlineConfig = {}) {
1786
1833
  app.use((0, import_sirv.default)(config.root, { dev: true, etag: true }));
1787
1834
  const httpServer = import_node_http.default.createServer(app);
1788
1835
  const ws = createWebSocketServer(httpServer);
1836
+ const ignoredSegments = /* @__PURE__ */ new Set(["node_modules", ".git", ".nasti"]);
1837
+ const outDirAbs = import_node_path11.default.resolve(config.root, config.build.outDir);
1789
1838
  const watcher = (0, import_chokidar.watch)(config.root, {
1790
- ignored: [
1791
- "**/node_modules/**",
1792
- "**/.git/**",
1793
- `**/${config.build.outDir}/**`
1794
- ],
1839
+ ignored: (filePath) => {
1840
+ if (filePath === config.root) return false;
1841
+ if (filePath === outDirAbs || filePath.startsWith(outDirAbs + import_node_path11.default.sep)) return true;
1842
+ const rel = import_node_path11.default.relative(config.root, filePath);
1843
+ if (!rel || rel.startsWith("..") || import_node_path11.default.isAbsolute(rel)) return false;
1844
+ for (const seg of rel.split(import_node_path11.default.sep)) {
1845
+ if (ignoredSegments.has(seg)) return true;
1846
+ }
1847
+ return false;
1848
+ },
1795
1849
  ignoreInitial: true
1796
1850
  });
1797
1851
  let server;
@@ -1819,7 +1873,7 @@ async function createServer(inlineConfig = {}) {
1819
1873
  const localUrl = `http://localhost:${actualPort}`;
1820
1874
  const networkUrl = host === "0.0.0.0" ? `http://${getNetworkAddress()}:${actualPort}` : null;
1821
1875
  console.log();
1822
- console.log(import_picocolors3.default.cyan(" nasti dev server") + import_picocolors3.default.dim(` v${"1.5.2"}`));
1876
+ console.log(import_picocolors3.default.cyan(" nasti dev server") + import_picocolors3.default.dim(` v${"1.6.1"}`));
1823
1877
  console.log();
1824
1878
  console.log(` ${import_picocolors3.default.green(">")} Local: ${import_picocolors3.default.cyan(localUrl)}`);
1825
1879
  if (networkUrl) {
@@ -1963,7 +2017,7 @@ async function buildElectron(inlineConfig = {}) {
1963
2017
  const config = await resolveConfig({ ...inlineConfig, target: "electron" }, "build");
1964
2018
  const startTime = performance.now();
1965
2019
  assertElectronVersion(config);
1966
- console.log(import_picocolors2.default.cyan("\n\u26A1 nasti build (electron)") + import_picocolors2.default.dim(` v${"1.5.2"}`));
2020
+ console.log(import_picocolors2.default.cyan("\n\u26A1 nasti build (electron)") + import_picocolors2.default.dim(` v${"1.6.1"}`));
1967
2021
  console.log(import_picocolors2.default.dim(` root: ${config.root}`));
1968
2022
  console.log(import_picocolors2.default.dim(` mode: ${config.mode}`));
1969
2023
  console.log(import_picocolors2.default.dim(` target: electron (\u2265 ${config.electron.minVersion})`));
@@ -2054,7 +2108,7 @@ async function bundleNode(config, entry, opts) {
2054
2108
  format: opts.format === "cjs" ? "cjs" : "esm",
2055
2109
  sourcemap: !!config.build.sourcemap,
2056
2110
  minify: !!config.build.minify,
2057
- inlineDynamicImports: true
2111
+ codeSplitting: false
2058
2112
  });
2059
2113
  await bundle.close();
2060
2114
  console.log(import_picocolors2.default.dim(` \u2713 ${opts.label} \u2192 ${import_node_path8.default.relative(config.root, opts.outFile)}`));
@@ -2110,7 +2164,7 @@ async function startElectronDev(inlineConfig = {}) {
2110
2164
  const { noSpawn, ...rest } = inlineConfig;
2111
2165
  const config = await resolveConfig({ ...rest, target: "electron" }, "serve");
2112
2166
  warnElectronVersion(config);
2113
- console.log(import_picocolors4.default.cyan("\n\u26A1 nasti electron dev") + import_picocolors4.default.dim(` v${"1.5.2"}`));
2167
+ console.log(import_picocolors4.default.cyan("\n\u26A1 nasti electron dev") + import_picocolors4.default.dim(` v${"1.6.1"}`));
2114
2168
  const { createServer: createServer2 } = await Promise.resolve().then(() => (init_server(), server_exports));
2115
2169
  const server = await createServer2({ ...rest, target: "electron" });
2116
2170
  await server.listen();
@@ -2253,7 +2307,9 @@ async function compileNode(config, entry, opts) {
2253
2307
  format: opts.format === "cjs" ? "cjs" : "esm",
2254
2308
  sourcemap: false,
2255
2309
  minify: false,
2256
- inlineDynamicImports: true
2310
+ // rolldown 已弃用 inlineDynamicImports,改用 codeSplitting:false 表达
2311
+ // 同样语义(单 chunk、内联 dynamic import)
2312
+ codeSplitting: false
2257
2313
  });
2258
2314
  await bundle.close();
2259
2315
  }
@@ -2359,7 +2415,7 @@ function monacoEditorPlugin(options = {}) {
2359
2415
  format: "iife",
2360
2416
  sourcemap: false,
2361
2417
  minify: true,
2362
- inlineDynamicImports: true
2418
+ codeSplitting: false
2363
2419
  });
2364
2420
  await bundle.close();
2365
2421
  return cacheFile;