@nasti-toolchain/nasti 2.0.0 → 2.0.2
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 +67 -21
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +67 -21
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +65 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +65 -19
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
|
@@ -1342,6 +1342,28 @@ async function transformRequest(url, ctx) {
|
|
|
1342
1342
|
if (cleanReqUrl === "/@react-refresh") {
|
|
1343
1343
|
return { code: getReactRefreshRuntimeEsm() };
|
|
1344
1344
|
}
|
|
1345
|
+
if (cleanReqUrl.startsWith("/@modules/") && url.includes("?")) {
|
|
1346
|
+
const idParam = new URLSearchParams(url.slice(url.indexOf("?") + 1)).get("id");
|
|
1347
|
+
let realId = null;
|
|
1348
|
+
let realIdValid = false;
|
|
1349
|
+
try {
|
|
1350
|
+
if (idParam) {
|
|
1351
|
+
realId = import_node_fs4.default.realpathSync(idParam);
|
|
1352
|
+
realIdValid = import_node_fs4.default.statSync(realId).isFile() && (realId.includes(`${import_node_path4.default.sep}node_modules${import_node_path4.default.sep}`) || isUnderRoot(realId, config.root));
|
|
1353
|
+
}
|
|
1354
|
+
} catch {
|
|
1355
|
+
realId = null;
|
|
1356
|
+
realIdValid = false;
|
|
1357
|
+
}
|
|
1358
|
+
if (realId && realIdValid) {
|
|
1359
|
+
const mod2 = await moduleGraph.ensureEntryFromUrl(url);
|
|
1360
|
+
moduleGraph.registerModule(mod2, realId);
|
|
1361
|
+
const code2 = await bundlePackageAsEsm(realId, config.root);
|
|
1362
|
+
const transformResult2 = { code: code2 };
|
|
1363
|
+
mod2.transformResult = transformResult2;
|
|
1364
|
+
return transformResult2;
|
|
1365
|
+
}
|
|
1366
|
+
}
|
|
1345
1367
|
if (cleanReqUrl.startsWith("/@modules/")) {
|
|
1346
1368
|
const spec = cleanReqUrl.slice("/@modules/".length);
|
|
1347
1369
|
const virtual = await loadVirtualModule(spec, ctx);
|
|
@@ -1379,7 +1401,7 @@ async function transformRequest(url, ctx) {
|
|
|
1379
1401
|
const mod = await moduleGraph.ensureEntryFromUrl(url);
|
|
1380
1402
|
moduleGraph.registerModule(mod, filePath);
|
|
1381
1403
|
if (cleanReqUrl.startsWith("/@modules/")) {
|
|
1382
|
-
const code2 = await bundlePackageAsEsm(filePath);
|
|
1404
|
+
const code2 = await bundlePackageAsEsm(filePath, config.root);
|
|
1383
1405
|
const transformResult2 = { code: code2 };
|
|
1384
1406
|
mod.transformResult = transformResult2;
|
|
1385
1407
|
return transformResult2;
|
|
@@ -1442,14 +1464,14 @@ async function loadVirtualModule(spec, ctx) {
|
|
|
1442
1464
|
code = rewriteImports(code, config, anchor);
|
|
1443
1465
|
return { id: resolvedId, result: { code } };
|
|
1444
1466
|
}
|
|
1445
|
-
async function bundlePackageAsEsm(entryFile) {
|
|
1467
|
+
async function bundlePackageAsEsm(entryFile, root) {
|
|
1446
1468
|
if (!esmBundleCache.has(entryFile)) {
|
|
1447
|
-
esmBundleCache.set(entryFile, doBundlePackage(entryFile));
|
|
1469
|
+
esmBundleCache.set(entryFile, doBundlePackage(entryFile, root));
|
|
1448
1470
|
}
|
|
1449
1471
|
return esmBundleCache.get(entryFile);
|
|
1450
1472
|
}
|
|
1451
|
-
async function doBundlePackage(entryFile) {
|
|
1452
|
-
const shim = await tryGenerateSubpathShim(entryFile);
|
|
1473
|
+
async function doBundlePackage(entryFile, root) {
|
|
1474
|
+
const shim = await tryGenerateSubpathShim(entryFile, root);
|
|
1453
1475
|
if (shim != null) return shim;
|
|
1454
1476
|
const { rolldown: rolldown4 } = await import("rolldown");
|
|
1455
1477
|
const bundle2 = await rolldown4({
|
|
@@ -1464,23 +1486,24 @@ async function doBundlePackage(entryFile) {
|
|
|
1464
1486
|
await bundle2.close();
|
|
1465
1487
|
let code = result.output[0].code;
|
|
1466
1488
|
code = code.replace(/process\.env\.NODE_ENV/g, '"development"');
|
|
1489
|
+
const externalBaseDir = import_node_path4.default.dirname(entryFile);
|
|
1467
1490
|
code = code.replace(
|
|
1468
1491
|
/^(import\b[^;'"]*?\bfrom\s+)(['"])([^'"./][^'"]*)(\2)/gm,
|
|
1469
|
-
(_, prefix, q, spec) => `${prefix}${q}
|
|
1492
|
+
(_, prefix, q, spec) => `${prefix}${q}${externalSpecToModuleUrl(spec, externalBaseDir, root)}${q}`
|
|
1470
1493
|
).replace(
|
|
1471
1494
|
/^(export\b[^;'"]*?\bfrom\s+)(['"])([^'"./][^'"]*)(\2)/gm,
|
|
1472
|
-
(_, prefix, q, spec) => `${prefix}${q}
|
|
1495
|
+
(_, prefix, q, spec) => `${prefix}${q}${externalSpecToModuleUrl(spec, externalBaseDir, root)}${q}`
|
|
1473
1496
|
).replace(
|
|
1474
1497
|
/^(import\s+)(['"])([^'"./][^'"]*)(\2)/gm,
|
|
1475
|
-
(_, prefix, q, spec) => `${prefix}${q}
|
|
1498
|
+
(_, prefix, q, spec) => `${prefix}${q}${externalSpecToModuleUrl(spec, externalBaseDir, root)}${q}`
|
|
1476
1499
|
);
|
|
1477
|
-
code = rewriteExternalRequires(code);
|
|
1500
|
+
code = rewriteExternalRequires(code, externalBaseDir, root);
|
|
1478
1501
|
if (code.includes("__commonJSMin")) {
|
|
1479
1502
|
code = await injectCjsNamedExports(code, entryFile);
|
|
1480
1503
|
}
|
|
1481
1504
|
return code;
|
|
1482
1505
|
}
|
|
1483
|
-
async function tryGenerateSubpathShim(entryFile) {
|
|
1506
|
+
async function tryGenerateSubpathShim(entryFile, root) {
|
|
1484
1507
|
const NM = `${import_node_path4.default.sep}node_modules${import_node_path4.default.sep}`;
|
|
1485
1508
|
if (!entryFile.includes(NM)) return null;
|
|
1486
1509
|
let pkgDir = null;
|
|
@@ -1531,9 +1554,11 @@ async function tryGenerateSubpathShim(entryFile) {
|
|
|
1531
1554
|
if (!("default" in mainNs)) return null;
|
|
1532
1555
|
if (mainNs["default"] !== subNs["default"]) return null;
|
|
1533
1556
|
}
|
|
1557
|
+
const rootMain = resolveNodeModule(root, pkgName);
|
|
1558
|
+
const mainEntryUrl = rootMain && rootMain.startsWith(pkgDir + import_node_path4.default.sep) ? `/@modules/${pkgName}` : `/@modules/${pkgName}?id=${encodeURIComponent(mainEntry)}`;
|
|
1534
1559
|
const lines = [
|
|
1535
1560
|
`// Nasti subpath shim \u2192 ${pkgName} (avoid duplicate bundling)`,
|
|
1536
|
-
`import * as __pkg from "
|
|
1561
|
+
`import * as __pkg from "${mainEntryUrl}";`
|
|
1537
1562
|
];
|
|
1538
1563
|
for (const k of subKeys) {
|
|
1539
1564
|
lines.push(`export const ${k} = __pkg[${JSON.stringify(k)}];`);
|
|
@@ -1577,7 +1602,7 @@ function pickMainEntryByExtension(pkgDir, preferredExt) {
|
|
|
1577
1602
|
}
|
|
1578
1603
|
return null;
|
|
1579
1604
|
}
|
|
1580
|
-
function rewriteExternalRequires(code) {
|
|
1605
|
+
function rewriteExternalRequires(code, baseDir, root) {
|
|
1581
1606
|
const pkgs = /* @__PURE__ */ new Set();
|
|
1582
1607
|
const re = /__require\(["']([^"']+)["']\)/g;
|
|
1583
1608
|
let m;
|
|
@@ -1589,7 +1614,7 @@ function rewriteExternalRequires(code) {
|
|
|
1589
1614
|
const imports = [];
|
|
1590
1615
|
for (const pkg of pkgs) {
|
|
1591
1616
|
const safe = pkg.replace(/[^a-zA-Z0-9_$]/g, "_");
|
|
1592
|
-
imports.push(`import * as __ns_${safe} from "
|
|
1617
|
+
imports.push(`import * as __ns_${safe} from "${externalSpecToModuleUrl(pkg, baseDir, root)}";`);
|
|
1593
1618
|
imports.push(`var __req_${safe} = "default" in __ns_${safe} ? __ns_${safe}["default"] : __ns_${safe};`);
|
|
1594
1619
|
result = result.replaceAll(`__require("${pkg}")`, `__req_${safe}`);
|
|
1595
1620
|
result = result.replaceAll(`__require('${pkg}')`, `__req_${safe}`);
|
|
@@ -1686,7 +1711,23 @@ function isUnderRoot(abs, root) {
|
|
|
1686
1711
|
const rel = import_node_path4.default.relative(root, abs);
|
|
1687
1712
|
return !!rel && !rel.startsWith("..") && !import_node_path4.default.isAbsolute(rel);
|
|
1688
1713
|
}
|
|
1689
|
-
function
|
|
1714
|
+
function externalSpecToModuleUrl(spec, baseDir, root) {
|
|
1715
|
+
const resolved = resolveNodeModule(baseDir, spec);
|
|
1716
|
+
if (!resolved) return `/@modules/${spec}`;
|
|
1717
|
+
const rootResolved = resolveNodeModule(root, spec);
|
|
1718
|
+
if (rootResolved && rootResolved === resolved) return `/@modules/${spec}`;
|
|
1719
|
+
return `/@modules/${spec}?id=${encodeURIComponent(resolved)}`;
|
|
1720
|
+
}
|
|
1721
|
+
function resolveNodeModule(baseDir, moduleName) {
|
|
1722
|
+
const resolved = resolveNodeModuleEntry(baseDir, moduleName);
|
|
1723
|
+
if (!resolved) return null;
|
|
1724
|
+
try {
|
|
1725
|
+
return import_node_fs4.default.realpathSync(resolved);
|
|
1726
|
+
} catch {
|
|
1727
|
+
return resolved;
|
|
1728
|
+
}
|
|
1729
|
+
}
|
|
1730
|
+
function resolveNodeModuleEntry(root, moduleName) {
|
|
1690
1731
|
let pkgName;
|
|
1691
1732
|
let subpath;
|
|
1692
1733
|
if (moduleName.startsWith("@")) {
|
|
@@ -1756,7 +1797,12 @@ function resolvePackageExports(exports2, key, pkgDir) {
|
|
|
1756
1797
|
return key === "." ? import_node_path4.default.join(pkgDir, exports2) : null;
|
|
1757
1798
|
}
|
|
1758
1799
|
const entry = exports2[key];
|
|
1759
|
-
if (entry === void 0)
|
|
1800
|
+
if (entry === void 0) {
|
|
1801
|
+
if (key === "." && typeof exports2 === "object" && !Object.keys(exports2).some((k) => k.startsWith("."))) {
|
|
1802
|
+
return resolveExportValue(exports2, pkgDir);
|
|
1803
|
+
}
|
|
1804
|
+
return null;
|
|
1805
|
+
}
|
|
1760
1806
|
return resolveExportValue(entry, pkgDir);
|
|
1761
1807
|
}
|
|
1762
1808
|
function resolveExportValue(value, pkgDir) {
|
|
@@ -3990,7 +4036,7 @@ async function build(inlineConfig = {}) {
|
|
|
3990
4036
|
const startTime = performance.now();
|
|
3991
4037
|
logger.info(
|
|
3992
4038
|
import_picocolors6.default.cyan(`
|
|
3993
|
-
nasti v${"2.0.
|
|
4039
|
+
nasti v${"2.0.2"} `) + import_picocolors6.default.green(`building for ${config.mode}...`)
|
|
3994
4040
|
);
|
|
3995
4041
|
debug5?.(`root: ${config.root}`);
|
|
3996
4042
|
const buildableNames = Object.keys(config.environments).filter(
|
|
@@ -4709,7 +4755,7 @@ async function createServer(inlineConfig = {}) {
|
|
|
4709
4755
|
const readyIn = Math.ceil(performance.now() - startTime);
|
|
4710
4756
|
logger.info(
|
|
4711
4757
|
`
|
|
4712
|
-
${import_picocolors8.default.cyan(import_picocolors8.default.bold("NASTI"))} ${import_picocolors8.default.cyan(`v${"2.0.
|
|
4758
|
+
${import_picocolors8.default.cyan(import_picocolors8.default.bold("NASTI"))} ${import_picocolors8.default.cyan(`v${"2.0.2"}`)} ${import_picocolors8.default.dim("ready in")} ${import_picocolors8.default.bold(readyIn)} ${import_picocolors8.default.dim("ms")}
|
|
4713
4759
|
`
|
|
4714
4760
|
);
|
|
4715
4761
|
printServerUrls(
|
|
@@ -4843,7 +4889,7 @@ async function buildElectron(inlineConfig = {}) {
|
|
|
4843
4889
|
const config = await resolveConfig({ ...inlineConfig, target: "electron" }, "build");
|
|
4844
4890
|
const startTime = performance.now();
|
|
4845
4891
|
assertElectronVersion(config);
|
|
4846
|
-
console.log(import_picocolors9.default.cyan("\n\u26A1 nasti build (electron)") + import_picocolors9.default.dim(` v${"2.0.
|
|
4892
|
+
console.log(import_picocolors9.default.cyan("\n\u26A1 nasti build (electron)") + import_picocolors9.default.dim(` v${"2.0.2"}`));
|
|
4847
4893
|
console.log(import_picocolors9.default.dim(` root: ${config.root}`));
|
|
4848
4894
|
console.log(import_picocolors9.default.dim(` mode: ${config.mode}`));
|
|
4849
4895
|
console.log(import_picocolors9.default.dim(` target: electron (\u2265 ${config.electron.minVersion})`));
|
|
@@ -4999,7 +5045,7 @@ async function startElectronDev(inlineConfig = {}) {
|
|
|
4999
5045
|
const { noSpawn, ...rest } = inlineConfig;
|
|
5000
5046
|
const config = await resolveConfig({ ...rest, target: "electron" }, "serve");
|
|
5001
5047
|
warnElectronVersion(config);
|
|
5002
|
-
console.log(import_picocolors10.default.cyan("\n\u26A1 nasti electron dev") + import_picocolors10.default.dim(` v${"2.0.
|
|
5048
|
+
console.log(import_picocolors10.default.cyan("\n\u26A1 nasti electron dev") + import_picocolors10.default.dim(` v${"2.0.2"}`));
|
|
5003
5049
|
const { createServer: createServer2 } = await Promise.resolve().then(() => (init_server(), server_exports));
|
|
5004
5050
|
const server = await createServer2({ ...rest, target: "electron" });
|
|
5005
5051
|
await server.listen();
|
|
@@ -5352,7 +5398,7 @@ cli.command("preview [root]", "Preview production build").option("--port <port>"
|
|
|
5352
5398
|
const host = options.host === true ? "0.0.0.0" : options.host ?? "localhost";
|
|
5353
5399
|
http2.createServer(app).listen(port, host, () => {
|
|
5354
5400
|
logger.info(`
|
|
5355
|
-
${import_picocolors11.default.cyan(import_picocolors11.default.bold("NASTI"))} ${import_picocolors11.default.cyan(`v${"2.0.
|
|
5401
|
+
${import_picocolors11.default.cyan(import_picocolors11.default.bold("NASTI"))} ${import_picocolors11.default.cyan(`v${"2.0.2"}`)} ${import_picocolors11.default.dim("preview")}
|
|
5356
5402
|
`);
|
|
5357
5403
|
printServerUrls2(
|
|
5358
5404
|
{
|
|
@@ -5369,6 +5415,6 @@ cli.command("preview [root]", "Preview production build").option("--port <port>"
|
|
|
5369
5415
|
}
|
|
5370
5416
|
});
|
|
5371
5417
|
cli.help();
|
|
5372
|
-
cli.version("2.0.
|
|
5418
|
+
cli.version("2.0.2");
|
|
5373
5419
|
cli.parse();
|
|
5374
5420
|
//# sourceMappingURL=cli.cjs.map
|