@nasti-toolchain/nasti 2.0.0 → 2.0.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 +64 -21
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +64 -21
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +62 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +62 -19
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1350,6 +1350,28 @@ async function transformRequest(url, ctx) {
|
|
|
1350
1350
|
if (cleanReqUrl === "/@react-refresh") {
|
|
1351
1351
|
return { code: getReactRefreshRuntimeEsm() };
|
|
1352
1352
|
}
|
|
1353
|
+
if (cleanReqUrl.startsWith("/@modules/") && url.includes("?")) {
|
|
1354
|
+
const idParam = new URLSearchParams(url.slice(url.indexOf("?") + 1)).get("id");
|
|
1355
|
+
let realId = null;
|
|
1356
|
+
let realIdValid = false;
|
|
1357
|
+
try {
|
|
1358
|
+
if (idParam) {
|
|
1359
|
+
realId = fs4.realpathSync(idParam);
|
|
1360
|
+
realIdValid = fs4.statSync(realId).isFile() && (realId.includes(`${path4.sep}node_modules${path4.sep}`) || isUnderRoot(realId, config.root));
|
|
1361
|
+
}
|
|
1362
|
+
} catch {
|
|
1363
|
+
realId = null;
|
|
1364
|
+
realIdValid = false;
|
|
1365
|
+
}
|
|
1366
|
+
if (realId && realIdValid) {
|
|
1367
|
+
const mod2 = await moduleGraph.ensureEntryFromUrl(url);
|
|
1368
|
+
moduleGraph.registerModule(mod2, realId);
|
|
1369
|
+
const code2 = await bundlePackageAsEsm(realId, config.root);
|
|
1370
|
+
const transformResult2 = { code: code2 };
|
|
1371
|
+
mod2.transformResult = transformResult2;
|
|
1372
|
+
return transformResult2;
|
|
1373
|
+
}
|
|
1374
|
+
}
|
|
1353
1375
|
if (cleanReqUrl.startsWith("/@modules/")) {
|
|
1354
1376
|
const spec = cleanReqUrl.slice("/@modules/".length);
|
|
1355
1377
|
const virtual = await loadVirtualModule(spec, ctx);
|
|
@@ -1387,7 +1409,7 @@ async function transformRequest(url, ctx) {
|
|
|
1387
1409
|
const mod = await moduleGraph.ensureEntryFromUrl(url);
|
|
1388
1410
|
moduleGraph.registerModule(mod, filePath);
|
|
1389
1411
|
if (cleanReqUrl.startsWith("/@modules/")) {
|
|
1390
|
-
const code2 = await bundlePackageAsEsm(filePath);
|
|
1412
|
+
const code2 = await bundlePackageAsEsm(filePath, config.root);
|
|
1391
1413
|
const transformResult2 = { code: code2 };
|
|
1392
1414
|
mod.transformResult = transformResult2;
|
|
1393
1415
|
return transformResult2;
|
|
@@ -1450,14 +1472,14 @@ async function loadVirtualModule(spec, ctx) {
|
|
|
1450
1472
|
code = rewriteImports(code, config, anchor);
|
|
1451
1473
|
return { id: resolvedId, result: { code } };
|
|
1452
1474
|
}
|
|
1453
|
-
async function bundlePackageAsEsm(entryFile) {
|
|
1475
|
+
async function bundlePackageAsEsm(entryFile, root) {
|
|
1454
1476
|
if (!esmBundleCache.has(entryFile)) {
|
|
1455
|
-
esmBundleCache.set(entryFile, doBundlePackage(entryFile));
|
|
1477
|
+
esmBundleCache.set(entryFile, doBundlePackage(entryFile, root));
|
|
1456
1478
|
}
|
|
1457
1479
|
return esmBundleCache.get(entryFile);
|
|
1458
1480
|
}
|
|
1459
|
-
async function doBundlePackage(entryFile) {
|
|
1460
|
-
const shim = await tryGenerateSubpathShim(entryFile);
|
|
1481
|
+
async function doBundlePackage(entryFile, root) {
|
|
1482
|
+
const shim = await tryGenerateSubpathShim(entryFile, root);
|
|
1461
1483
|
if (shim != null) return shim;
|
|
1462
1484
|
const { rolldown: rolldown4 } = await import("rolldown");
|
|
1463
1485
|
const bundle2 = await rolldown4({
|
|
@@ -1472,23 +1494,24 @@ async function doBundlePackage(entryFile) {
|
|
|
1472
1494
|
await bundle2.close();
|
|
1473
1495
|
let code = result.output[0].code;
|
|
1474
1496
|
code = code.replace(/process\.env\.NODE_ENV/g, '"development"');
|
|
1497
|
+
const externalBaseDir = path4.dirname(entryFile);
|
|
1475
1498
|
code = code.replace(
|
|
1476
1499
|
/^(import\b[^;'"]*?\bfrom\s+)(['"])([^'"./][^'"]*)(\2)/gm,
|
|
1477
|
-
(_, prefix, q, spec) => `${prefix}${q}
|
|
1500
|
+
(_, prefix, q, spec) => `${prefix}${q}${externalSpecToModuleUrl(spec, externalBaseDir)}${q}`
|
|
1478
1501
|
).replace(
|
|
1479
1502
|
/^(export\b[^;'"]*?\bfrom\s+)(['"])([^'"./][^'"]*)(\2)/gm,
|
|
1480
|
-
(_, prefix, q, spec) => `${prefix}${q}
|
|
1503
|
+
(_, prefix, q, spec) => `${prefix}${q}${externalSpecToModuleUrl(spec, externalBaseDir)}${q}`
|
|
1481
1504
|
).replace(
|
|
1482
1505
|
/^(import\s+)(['"])([^'"./][^'"]*)(\2)/gm,
|
|
1483
|
-
(_, prefix, q, spec) => `${prefix}${q}
|
|
1506
|
+
(_, prefix, q, spec) => `${prefix}${q}${externalSpecToModuleUrl(spec, externalBaseDir)}${q}`
|
|
1484
1507
|
);
|
|
1485
|
-
code = rewriteExternalRequires(code);
|
|
1508
|
+
code = rewriteExternalRequires(code, externalBaseDir);
|
|
1486
1509
|
if (code.includes("__commonJSMin")) {
|
|
1487
1510
|
code = await injectCjsNamedExports(code, entryFile);
|
|
1488
1511
|
}
|
|
1489
1512
|
return code;
|
|
1490
1513
|
}
|
|
1491
|
-
async function tryGenerateSubpathShim(entryFile) {
|
|
1514
|
+
async function tryGenerateSubpathShim(entryFile, root) {
|
|
1492
1515
|
const NM = `${path4.sep}node_modules${path4.sep}`;
|
|
1493
1516
|
if (!entryFile.includes(NM)) return null;
|
|
1494
1517
|
let pkgDir = null;
|
|
@@ -1539,9 +1562,11 @@ async function tryGenerateSubpathShim(entryFile) {
|
|
|
1539
1562
|
if (!("default" in mainNs)) return null;
|
|
1540
1563
|
if (mainNs["default"] !== subNs["default"]) return null;
|
|
1541
1564
|
}
|
|
1565
|
+
const rootMain = resolveNodeModule(root, pkgName);
|
|
1566
|
+
const mainEntryUrl = rootMain && rootMain.startsWith(pkgDir + path4.sep) ? `/@modules/${pkgName}` : `/@modules/${pkgName}?id=${encodeURIComponent(mainEntry)}`;
|
|
1542
1567
|
const lines = [
|
|
1543
1568
|
`// Nasti subpath shim \u2192 ${pkgName} (avoid duplicate bundling)`,
|
|
1544
|
-
`import * as __pkg from "
|
|
1569
|
+
`import * as __pkg from "${mainEntryUrl}";`
|
|
1545
1570
|
];
|
|
1546
1571
|
for (const k of subKeys) {
|
|
1547
1572
|
lines.push(`export const ${k} = __pkg[${JSON.stringify(k)}];`);
|
|
@@ -1585,7 +1610,7 @@ function pickMainEntryByExtension(pkgDir, preferredExt) {
|
|
|
1585
1610
|
}
|
|
1586
1611
|
return null;
|
|
1587
1612
|
}
|
|
1588
|
-
function rewriteExternalRequires(code) {
|
|
1613
|
+
function rewriteExternalRequires(code, baseDir) {
|
|
1589
1614
|
const pkgs = /* @__PURE__ */ new Set();
|
|
1590
1615
|
const re = /__require\(["']([^"']+)["']\)/g;
|
|
1591
1616
|
let m;
|
|
@@ -1597,7 +1622,7 @@ function rewriteExternalRequires(code) {
|
|
|
1597
1622
|
const imports = [];
|
|
1598
1623
|
for (const pkg of pkgs) {
|
|
1599
1624
|
const safe = pkg.replace(/[^a-zA-Z0-9_$]/g, "_");
|
|
1600
|
-
imports.push(`import * as __ns_${safe} from "
|
|
1625
|
+
imports.push(`import * as __ns_${safe} from "${externalSpecToModuleUrl(pkg, baseDir)}";`);
|
|
1601
1626
|
imports.push(`var __req_${safe} = "default" in __ns_${safe} ? __ns_${safe}["default"] : __ns_${safe};`);
|
|
1602
1627
|
result = result.replaceAll(`__require("${pkg}")`, `__req_${safe}`);
|
|
1603
1628
|
result = result.replaceAll(`__require('${pkg}')`, `__req_${safe}`);
|
|
@@ -1694,7 +1719,20 @@ function isUnderRoot(abs, root) {
|
|
|
1694
1719
|
const rel = path4.relative(root, abs);
|
|
1695
1720
|
return !!rel && !rel.startsWith("..") && !path4.isAbsolute(rel);
|
|
1696
1721
|
}
|
|
1697
|
-
function
|
|
1722
|
+
function externalSpecToModuleUrl(spec, baseDir) {
|
|
1723
|
+
const resolved = resolveNodeModule(baseDir, spec);
|
|
1724
|
+
return resolved ? `/@modules/${spec}?id=${encodeURIComponent(resolved)}` : `/@modules/${spec}`;
|
|
1725
|
+
}
|
|
1726
|
+
function resolveNodeModule(baseDir, moduleName) {
|
|
1727
|
+
const resolved = resolveNodeModuleEntry(baseDir, moduleName);
|
|
1728
|
+
if (!resolved) return null;
|
|
1729
|
+
try {
|
|
1730
|
+
return fs4.realpathSync(resolved);
|
|
1731
|
+
} catch {
|
|
1732
|
+
return resolved;
|
|
1733
|
+
}
|
|
1734
|
+
}
|
|
1735
|
+
function resolveNodeModuleEntry(root, moduleName) {
|
|
1698
1736
|
let pkgName;
|
|
1699
1737
|
let subpath;
|
|
1700
1738
|
if (moduleName.startsWith("@")) {
|
|
@@ -1764,7 +1802,12 @@ function resolvePackageExports(exports, key, pkgDir) {
|
|
|
1764
1802
|
return key === "." ? path4.join(pkgDir, exports) : null;
|
|
1765
1803
|
}
|
|
1766
1804
|
const entry = exports[key];
|
|
1767
|
-
if (entry === void 0)
|
|
1805
|
+
if (entry === void 0) {
|
|
1806
|
+
if (key === "." && typeof exports === "object" && !Object.keys(exports).some((k) => k.startsWith("."))) {
|
|
1807
|
+
return resolveExportValue(exports, pkgDir);
|
|
1808
|
+
}
|
|
1809
|
+
return null;
|
|
1810
|
+
}
|
|
1768
1811
|
return resolveExportValue(entry, pkgDir);
|
|
1769
1812
|
}
|
|
1770
1813
|
function resolveExportValue(value, pkgDir) {
|
|
@@ -3994,7 +4037,7 @@ async function build(inlineConfig = {}) {
|
|
|
3994
4037
|
const startTime = performance.now();
|
|
3995
4038
|
logger.info(
|
|
3996
4039
|
pc6.cyan(`
|
|
3997
|
-
nasti v${"2.0.
|
|
4040
|
+
nasti v${"2.0.1"} `) + pc6.green(`building for ${config.mode}...`)
|
|
3998
4041
|
);
|
|
3999
4042
|
debug5?.(`root: ${config.root}`);
|
|
4000
4043
|
const buildableNames = Object.keys(config.environments).filter(
|
|
@@ -4715,7 +4758,7 @@ async function createServer(inlineConfig = {}) {
|
|
|
4715
4758
|
const readyIn = Math.ceil(performance.now() - startTime);
|
|
4716
4759
|
logger.info(
|
|
4717
4760
|
`
|
|
4718
|
-
${pc8.cyan(pc8.bold("NASTI"))} ${pc8.cyan(`v${"2.0.
|
|
4761
|
+
${pc8.cyan(pc8.bold("NASTI"))} ${pc8.cyan(`v${"2.0.1"}`)} ${pc8.dim("ready in")} ${pc8.bold(readyIn)} ${pc8.dim("ms")}
|
|
4719
4762
|
`
|
|
4720
4763
|
);
|
|
4721
4764
|
printServerUrls(
|
|
@@ -4845,7 +4888,7 @@ async function buildElectron(inlineConfig = {}) {
|
|
|
4845
4888
|
const config = await resolveConfig({ ...inlineConfig, target: "electron" }, "build");
|
|
4846
4889
|
const startTime = performance.now();
|
|
4847
4890
|
assertElectronVersion(config);
|
|
4848
|
-
console.log(pc9.cyan("\n\u26A1 nasti build (electron)") + pc9.dim(` v${"2.0.
|
|
4891
|
+
console.log(pc9.cyan("\n\u26A1 nasti build (electron)") + pc9.dim(` v${"2.0.1"}`));
|
|
4849
4892
|
console.log(pc9.dim(` root: ${config.root}`));
|
|
4850
4893
|
console.log(pc9.dim(` mode: ${config.mode}`));
|
|
4851
4894
|
console.log(pc9.dim(` target: electron (\u2265 ${config.electron.minVersion})`));
|
|
@@ -5003,7 +5046,7 @@ async function startElectronDev(inlineConfig = {}) {
|
|
|
5003
5046
|
const { noSpawn, ...rest } = inlineConfig;
|
|
5004
5047
|
const config = await resolveConfig({ ...rest, target: "electron" }, "serve");
|
|
5005
5048
|
warnElectronVersion(config);
|
|
5006
|
-
console.log(pc10.cyan("\n\u26A1 nasti electron dev") + pc10.dim(` v${"2.0.
|
|
5049
|
+
console.log(pc10.cyan("\n\u26A1 nasti electron dev") + pc10.dim(` v${"2.0.1"}`));
|
|
5007
5050
|
const { createServer: createServer2 } = await Promise.resolve().then(() => (init_server(), server_exports));
|
|
5008
5051
|
const server = await createServer2({ ...rest, target: "electron" });
|
|
5009
5052
|
await server.listen();
|
|
@@ -5348,7 +5391,7 @@ cli.command("preview [root]", "Preview production build").option("--port <port>"
|
|
|
5348
5391
|
const host = options.host === true ? "0.0.0.0" : options.host ?? "localhost";
|
|
5349
5392
|
http2.createServer(app).listen(port, host, () => {
|
|
5350
5393
|
logger.info(`
|
|
5351
|
-
${pc11.cyan(pc11.bold("NASTI"))} ${pc11.cyan(`v${"2.0.
|
|
5394
|
+
${pc11.cyan(pc11.bold("NASTI"))} ${pc11.cyan(`v${"2.0.1"}`)} ${pc11.dim("preview")}
|
|
5352
5395
|
`);
|
|
5353
5396
|
printServerUrls2(
|
|
5354
5397
|
{
|
|
@@ -5365,6 +5408,6 @@ cli.command("preview [root]", "Preview production build").option("--port <port>"
|
|
|
5365
5408
|
}
|
|
5366
5409
|
});
|
|
5367
5410
|
cli.help();
|
|
5368
|
-
cli.version("2.0.
|
|
5411
|
+
cli.version("2.0.1");
|
|
5369
5412
|
cli.parse();
|
|
5370
5413
|
//# sourceMappingURL=cli.js.map
|