@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/index.js
CHANGED
|
@@ -2877,7 +2877,7 @@ async function build(inlineConfig = {}) {
|
|
|
2877
2877
|
const startTime = performance.now();
|
|
2878
2878
|
logger.info(
|
|
2879
2879
|
pc4.cyan(`
|
|
2880
|
-
nasti v${"2.0.
|
|
2880
|
+
nasti v${"2.0.2"} `) + pc4.green(`building for ${config.mode}...`)
|
|
2881
2881
|
);
|
|
2882
2882
|
debug4?.(`root: ${config.root}`);
|
|
2883
2883
|
const buildableNames = Object.keys(config.environments).filter(
|
|
@@ -3259,6 +3259,28 @@ async function transformRequest(url, ctx) {
|
|
|
3259
3259
|
if (cleanReqUrl === "/@react-refresh") {
|
|
3260
3260
|
return { code: getReactRefreshRuntimeEsm() };
|
|
3261
3261
|
}
|
|
3262
|
+
if (cleanReqUrl.startsWith("/@modules/") && url.includes("?")) {
|
|
3263
|
+
const idParam = new URLSearchParams(url.slice(url.indexOf("?") + 1)).get("id");
|
|
3264
|
+
let realId = null;
|
|
3265
|
+
let realIdValid = false;
|
|
3266
|
+
try {
|
|
3267
|
+
if (idParam) {
|
|
3268
|
+
realId = fs8.realpathSync(idParam);
|
|
3269
|
+
realIdValid = fs8.statSync(realId).isFile() && (realId.includes(`${path11.sep}node_modules${path11.sep}`) || isUnderRoot(realId, config.root));
|
|
3270
|
+
}
|
|
3271
|
+
} catch {
|
|
3272
|
+
realId = null;
|
|
3273
|
+
realIdValid = false;
|
|
3274
|
+
}
|
|
3275
|
+
if (realId && realIdValid) {
|
|
3276
|
+
const mod2 = await moduleGraph.ensureEntryFromUrl(url);
|
|
3277
|
+
moduleGraph.registerModule(mod2, realId);
|
|
3278
|
+
const code2 = await bundlePackageAsEsm(realId, config.root);
|
|
3279
|
+
const transformResult2 = { code: code2 };
|
|
3280
|
+
mod2.transformResult = transformResult2;
|
|
3281
|
+
return transformResult2;
|
|
3282
|
+
}
|
|
3283
|
+
}
|
|
3262
3284
|
if (cleanReqUrl.startsWith("/@modules/")) {
|
|
3263
3285
|
const spec = cleanReqUrl.slice("/@modules/".length);
|
|
3264
3286
|
const virtual = await loadVirtualModule(spec, ctx);
|
|
@@ -3296,7 +3318,7 @@ async function transformRequest(url, ctx) {
|
|
|
3296
3318
|
const mod = await moduleGraph.ensureEntryFromUrl(url);
|
|
3297
3319
|
moduleGraph.registerModule(mod, filePath);
|
|
3298
3320
|
if (cleanReqUrl.startsWith("/@modules/")) {
|
|
3299
|
-
const code2 = await bundlePackageAsEsm(filePath);
|
|
3321
|
+
const code2 = await bundlePackageAsEsm(filePath, config.root);
|
|
3300
3322
|
const transformResult2 = { code: code2 };
|
|
3301
3323
|
mod.transformResult = transformResult2;
|
|
3302
3324
|
return transformResult2;
|
|
@@ -3359,14 +3381,14 @@ async function loadVirtualModule(spec, ctx) {
|
|
|
3359
3381
|
code = rewriteImports(code, config, anchor);
|
|
3360
3382
|
return { id: resolvedId, result: { code } };
|
|
3361
3383
|
}
|
|
3362
|
-
async function bundlePackageAsEsm(entryFile) {
|
|
3384
|
+
async function bundlePackageAsEsm(entryFile, root) {
|
|
3363
3385
|
if (!esmBundleCache.has(entryFile)) {
|
|
3364
|
-
esmBundleCache.set(entryFile, doBundlePackage(entryFile));
|
|
3386
|
+
esmBundleCache.set(entryFile, doBundlePackage(entryFile, root));
|
|
3365
3387
|
}
|
|
3366
3388
|
return esmBundleCache.get(entryFile);
|
|
3367
3389
|
}
|
|
3368
|
-
async function doBundlePackage(entryFile) {
|
|
3369
|
-
const shim = await tryGenerateSubpathShim(entryFile);
|
|
3390
|
+
async function doBundlePackage(entryFile, root) {
|
|
3391
|
+
const shim = await tryGenerateSubpathShim(entryFile, root);
|
|
3370
3392
|
if (shim != null) return shim;
|
|
3371
3393
|
const { rolldown: rolldown4 } = await import("rolldown");
|
|
3372
3394
|
const bundle2 = await rolldown4({
|
|
@@ -3381,23 +3403,24 @@ async function doBundlePackage(entryFile) {
|
|
|
3381
3403
|
await bundle2.close();
|
|
3382
3404
|
let code = result.output[0].code;
|
|
3383
3405
|
code = code.replace(/process\.env\.NODE_ENV/g, '"development"');
|
|
3406
|
+
const externalBaseDir = path11.dirname(entryFile);
|
|
3384
3407
|
code = code.replace(
|
|
3385
3408
|
/^(import\b[^;'"]*?\bfrom\s+)(['"])([^'"./][^'"]*)(\2)/gm,
|
|
3386
|
-
(_, prefix, q, spec) => `${prefix}${q}
|
|
3409
|
+
(_, prefix, q, spec) => `${prefix}${q}${externalSpecToModuleUrl(spec, externalBaseDir, root)}${q}`
|
|
3387
3410
|
).replace(
|
|
3388
3411
|
/^(export\b[^;'"]*?\bfrom\s+)(['"])([^'"./][^'"]*)(\2)/gm,
|
|
3389
|
-
(_, prefix, q, spec) => `${prefix}${q}
|
|
3412
|
+
(_, prefix, q, spec) => `${prefix}${q}${externalSpecToModuleUrl(spec, externalBaseDir, root)}${q}`
|
|
3390
3413
|
).replace(
|
|
3391
3414
|
/^(import\s+)(['"])([^'"./][^'"]*)(\2)/gm,
|
|
3392
|
-
(_, prefix, q, spec) => `${prefix}${q}
|
|
3415
|
+
(_, prefix, q, spec) => `${prefix}${q}${externalSpecToModuleUrl(spec, externalBaseDir, root)}${q}`
|
|
3393
3416
|
);
|
|
3394
|
-
code = rewriteExternalRequires(code);
|
|
3417
|
+
code = rewriteExternalRequires(code, externalBaseDir, root);
|
|
3395
3418
|
if (code.includes("__commonJSMin")) {
|
|
3396
3419
|
code = await injectCjsNamedExports(code, entryFile);
|
|
3397
3420
|
}
|
|
3398
3421
|
return code;
|
|
3399
3422
|
}
|
|
3400
|
-
async function tryGenerateSubpathShim(entryFile) {
|
|
3423
|
+
async function tryGenerateSubpathShim(entryFile, root) {
|
|
3401
3424
|
const NM = `${path11.sep}node_modules${path11.sep}`;
|
|
3402
3425
|
if (!entryFile.includes(NM)) return null;
|
|
3403
3426
|
let pkgDir = null;
|
|
@@ -3448,9 +3471,11 @@ async function tryGenerateSubpathShim(entryFile) {
|
|
|
3448
3471
|
if (!("default" in mainNs)) return null;
|
|
3449
3472
|
if (mainNs["default"] !== subNs["default"]) return null;
|
|
3450
3473
|
}
|
|
3474
|
+
const rootMain = resolveNodeModule(root, pkgName);
|
|
3475
|
+
const mainEntryUrl = rootMain && rootMain.startsWith(pkgDir + path11.sep) ? `/@modules/${pkgName}` : `/@modules/${pkgName}?id=${encodeURIComponent(mainEntry)}`;
|
|
3451
3476
|
const lines = [
|
|
3452
3477
|
`// Nasti subpath shim \u2192 ${pkgName} (avoid duplicate bundling)`,
|
|
3453
|
-
`import * as __pkg from "
|
|
3478
|
+
`import * as __pkg from "${mainEntryUrl}";`
|
|
3454
3479
|
];
|
|
3455
3480
|
for (const k of subKeys) {
|
|
3456
3481
|
lines.push(`export const ${k} = __pkg[${JSON.stringify(k)}];`);
|
|
@@ -3494,7 +3519,7 @@ function pickMainEntryByExtension(pkgDir, preferredExt) {
|
|
|
3494
3519
|
}
|
|
3495
3520
|
return null;
|
|
3496
3521
|
}
|
|
3497
|
-
function rewriteExternalRequires(code) {
|
|
3522
|
+
function rewriteExternalRequires(code, baseDir, root) {
|
|
3498
3523
|
const pkgs = /* @__PURE__ */ new Set();
|
|
3499
3524
|
const re = /__require\(["']([^"']+)["']\)/g;
|
|
3500
3525
|
let m;
|
|
@@ -3506,7 +3531,7 @@ function rewriteExternalRequires(code) {
|
|
|
3506
3531
|
const imports = [];
|
|
3507
3532
|
for (const pkg of pkgs) {
|
|
3508
3533
|
const safe = pkg.replace(/[^a-zA-Z0-9_$]/g, "_");
|
|
3509
|
-
imports.push(`import * as __ns_${safe} from "
|
|
3534
|
+
imports.push(`import * as __ns_${safe} from "${externalSpecToModuleUrl(pkg, baseDir, root)}";`);
|
|
3510
3535
|
imports.push(`var __req_${safe} = "default" in __ns_${safe} ? __ns_${safe}["default"] : __ns_${safe};`);
|
|
3511
3536
|
result = result.replaceAll(`__require("${pkg}")`, `__req_${safe}`);
|
|
3512
3537
|
result = result.replaceAll(`__require('${pkg}')`, `__req_${safe}`);
|
|
@@ -3603,7 +3628,23 @@ function isUnderRoot(abs, root) {
|
|
|
3603
3628
|
const rel = path11.relative(root, abs);
|
|
3604
3629
|
return !!rel && !rel.startsWith("..") && !path11.isAbsolute(rel);
|
|
3605
3630
|
}
|
|
3606
|
-
function
|
|
3631
|
+
function externalSpecToModuleUrl(spec, baseDir, root) {
|
|
3632
|
+
const resolved = resolveNodeModule(baseDir, spec);
|
|
3633
|
+
if (!resolved) return `/@modules/${spec}`;
|
|
3634
|
+
const rootResolved = resolveNodeModule(root, spec);
|
|
3635
|
+
if (rootResolved && rootResolved === resolved) return `/@modules/${spec}`;
|
|
3636
|
+
return `/@modules/${spec}?id=${encodeURIComponent(resolved)}`;
|
|
3637
|
+
}
|
|
3638
|
+
function resolveNodeModule(baseDir, moduleName) {
|
|
3639
|
+
const resolved = resolveNodeModuleEntry(baseDir, moduleName);
|
|
3640
|
+
if (!resolved) return null;
|
|
3641
|
+
try {
|
|
3642
|
+
return fs8.realpathSync(resolved);
|
|
3643
|
+
} catch {
|
|
3644
|
+
return resolved;
|
|
3645
|
+
}
|
|
3646
|
+
}
|
|
3647
|
+
function resolveNodeModuleEntry(root, moduleName) {
|
|
3607
3648
|
let pkgName;
|
|
3608
3649
|
let subpath;
|
|
3609
3650
|
if (moduleName.startsWith("@")) {
|
|
@@ -3673,7 +3714,12 @@ function resolvePackageExports(exports, key, pkgDir) {
|
|
|
3673
3714
|
return key === "." ? path11.join(pkgDir, exports) : null;
|
|
3674
3715
|
}
|
|
3675
3716
|
const entry = exports[key];
|
|
3676
|
-
if (entry === void 0)
|
|
3717
|
+
if (entry === void 0) {
|
|
3718
|
+
if (key === "." && typeof exports === "object" && !Object.keys(exports).some((k) => k.startsWith("."))) {
|
|
3719
|
+
return resolveExportValue(exports, pkgDir);
|
|
3720
|
+
}
|
|
3721
|
+
return null;
|
|
3722
|
+
}
|
|
3677
3723
|
return resolveExportValue(entry, pkgDir);
|
|
3678
3724
|
}
|
|
3679
3725
|
function resolveExportValue(value, pkgDir) {
|
|
@@ -4712,7 +4758,7 @@ async function createServer(inlineConfig = {}) {
|
|
|
4712
4758
|
const readyIn = Math.ceil(performance.now() - startTime);
|
|
4713
4759
|
logger.info(
|
|
4714
4760
|
`
|
|
4715
|
-
${pc9.cyan(pc9.bold("NASTI"))} ${pc9.cyan(`v${"2.0.
|
|
4761
|
+
${pc9.cyan(pc9.bold("NASTI"))} ${pc9.cyan(`v${"2.0.2"}`)} ${pc9.dim("ready in")} ${pc9.bold(readyIn)} ${pc9.dim("ms")}
|
|
4716
4762
|
`
|
|
4717
4763
|
);
|
|
4718
4764
|
printServerUrls(
|
|
@@ -4840,7 +4886,7 @@ async function buildElectron(inlineConfig = {}) {
|
|
|
4840
4886
|
const config = await resolveConfig({ ...inlineConfig, target: "electron" }, "build");
|
|
4841
4887
|
const startTime = performance.now();
|
|
4842
4888
|
assertElectronVersion(config);
|
|
4843
|
-
console.log(pc5.cyan("\n\u26A1 nasti build (electron)") + pc5.dim(` v${"2.0.
|
|
4889
|
+
console.log(pc5.cyan("\n\u26A1 nasti build (electron)") + pc5.dim(` v${"2.0.2"}`));
|
|
4844
4890
|
console.log(pc5.dim(` root: ${config.root}`));
|
|
4845
4891
|
console.log(pc5.dim(` mode: ${config.mode}`));
|
|
4846
4892
|
console.log(pc5.dim(` target: electron (\u2265 ${config.electron.minVersion})`));
|
|
@@ -4991,7 +5037,7 @@ async function startElectronDev(inlineConfig = {}) {
|
|
|
4991
5037
|
const { noSpawn, ...rest } = inlineConfig;
|
|
4992
5038
|
const config = await resolveConfig({ ...rest, target: "electron" }, "serve");
|
|
4993
5039
|
warnElectronVersion(config);
|
|
4994
|
-
console.log(pc10.cyan("\n\u26A1 nasti electron dev") + pc10.dim(` v${"2.0.
|
|
5040
|
+
console.log(pc10.cyan("\n\u26A1 nasti electron dev") + pc10.dim(` v${"2.0.2"}`));
|
|
4995
5041
|
const { createServer: createServer2 } = await Promise.resolve().then(() => (init_server(), server_exports));
|
|
4996
5042
|
const server = await createServer2({ ...rest, target: "electron" });
|
|
4997
5043
|
await server.listen();
|