@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.cjs
CHANGED
|
@@ -2871,7 +2871,7 @@ async function build(inlineConfig = {}) {
|
|
|
2871
2871
|
const startTime = performance.now();
|
|
2872
2872
|
logger.info(
|
|
2873
2873
|
import_picocolors4.default.cyan(`
|
|
2874
|
-
nasti v${"2.0.
|
|
2874
|
+
nasti v${"2.0.2"} `) + import_picocolors4.default.green(`building for ${config.mode}...`)
|
|
2875
2875
|
);
|
|
2876
2876
|
debug4?.(`root: ${config.root}`);
|
|
2877
2877
|
const buildableNames = Object.keys(config.environments).filter(
|
|
@@ -3254,6 +3254,28 @@ async function transformRequest(url, ctx) {
|
|
|
3254
3254
|
if (cleanReqUrl === "/@react-refresh") {
|
|
3255
3255
|
return { code: getReactRefreshRuntimeEsm() };
|
|
3256
3256
|
}
|
|
3257
|
+
if (cleanReqUrl.startsWith("/@modules/") && url.includes("?")) {
|
|
3258
|
+
const idParam = new URLSearchParams(url.slice(url.indexOf("?") + 1)).get("id");
|
|
3259
|
+
let realId = null;
|
|
3260
|
+
let realIdValid = false;
|
|
3261
|
+
try {
|
|
3262
|
+
if (idParam) {
|
|
3263
|
+
realId = import_node_fs8.default.realpathSync(idParam);
|
|
3264
|
+
realIdValid = import_node_fs8.default.statSync(realId).isFile() && (realId.includes(`${import_node_path11.default.sep}node_modules${import_node_path11.default.sep}`) || isUnderRoot(realId, config.root));
|
|
3265
|
+
}
|
|
3266
|
+
} catch {
|
|
3267
|
+
realId = null;
|
|
3268
|
+
realIdValid = false;
|
|
3269
|
+
}
|
|
3270
|
+
if (realId && realIdValid) {
|
|
3271
|
+
const mod2 = await moduleGraph.ensureEntryFromUrl(url);
|
|
3272
|
+
moduleGraph.registerModule(mod2, realId);
|
|
3273
|
+
const code2 = await bundlePackageAsEsm(realId, config.root);
|
|
3274
|
+
const transformResult2 = { code: code2 };
|
|
3275
|
+
mod2.transformResult = transformResult2;
|
|
3276
|
+
return transformResult2;
|
|
3277
|
+
}
|
|
3278
|
+
}
|
|
3257
3279
|
if (cleanReqUrl.startsWith("/@modules/")) {
|
|
3258
3280
|
const spec = cleanReqUrl.slice("/@modules/".length);
|
|
3259
3281
|
const virtual = await loadVirtualModule(spec, ctx);
|
|
@@ -3291,7 +3313,7 @@ async function transformRequest(url, ctx) {
|
|
|
3291
3313
|
const mod = await moduleGraph.ensureEntryFromUrl(url);
|
|
3292
3314
|
moduleGraph.registerModule(mod, filePath);
|
|
3293
3315
|
if (cleanReqUrl.startsWith("/@modules/")) {
|
|
3294
|
-
const code2 = await bundlePackageAsEsm(filePath);
|
|
3316
|
+
const code2 = await bundlePackageAsEsm(filePath, config.root);
|
|
3295
3317
|
const transformResult2 = { code: code2 };
|
|
3296
3318
|
mod.transformResult = transformResult2;
|
|
3297
3319
|
return transformResult2;
|
|
@@ -3354,14 +3376,14 @@ async function loadVirtualModule(spec, ctx) {
|
|
|
3354
3376
|
code = rewriteImports(code, config, anchor);
|
|
3355
3377
|
return { id: resolvedId, result: { code } };
|
|
3356
3378
|
}
|
|
3357
|
-
async function bundlePackageAsEsm(entryFile) {
|
|
3379
|
+
async function bundlePackageAsEsm(entryFile, root) {
|
|
3358
3380
|
if (!esmBundleCache.has(entryFile)) {
|
|
3359
|
-
esmBundleCache.set(entryFile, doBundlePackage(entryFile));
|
|
3381
|
+
esmBundleCache.set(entryFile, doBundlePackage(entryFile, root));
|
|
3360
3382
|
}
|
|
3361
3383
|
return esmBundleCache.get(entryFile);
|
|
3362
3384
|
}
|
|
3363
|
-
async function doBundlePackage(entryFile) {
|
|
3364
|
-
const shim = await tryGenerateSubpathShim(entryFile);
|
|
3385
|
+
async function doBundlePackage(entryFile, root) {
|
|
3386
|
+
const shim = await tryGenerateSubpathShim(entryFile, root);
|
|
3365
3387
|
if (shim != null) return shim;
|
|
3366
3388
|
const { rolldown: rolldown4 } = await import("rolldown");
|
|
3367
3389
|
const bundle2 = await rolldown4({
|
|
@@ -3376,23 +3398,24 @@ async function doBundlePackage(entryFile) {
|
|
|
3376
3398
|
await bundle2.close();
|
|
3377
3399
|
let code = result.output[0].code;
|
|
3378
3400
|
code = code.replace(/process\.env\.NODE_ENV/g, '"development"');
|
|
3401
|
+
const externalBaseDir = import_node_path11.default.dirname(entryFile);
|
|
3379
3402
|
code = code.replace(
|
|
3380
3403
|
/^(import\b[^;'"]*?\bfrom\s+)(['"])([^'"./][^'"]*)(\2)/gm,
|
|
3381
|
-
(_, prefix, q, spec) => `${prefix}${q}
|
|
3404
|
+
(_, prefix, q, spec) => `${prefix}${q}${externalSpecToModuleUrl(spec, externalBaseDir, root)}${q}`
|
|
3382
3405
|
).replace(
|
|
3383
3406
|
/^(export\b[^;'"]*?\bfrom\s+)(['"])([^'"./][^'"]*)(\2)/gm,
|
|
3384
|
-
(_, prefix, q, spec) => `${prefix}${q}
|
|
3407
|
+
(_, prefix, q, spec) => `${prefix}${q}${externalSpecToModuleUrl(spec, externalBaseDir, root)}${q}`
|
|
3385
3408
|
).replace(
|
|
3386
3409
|
/^(import\s+)(['"])([^'"./][^'"]*)(\2)/gm,
|
|
3387
|
-
(_, prefix, q, spec) => `${prefix}${q}
|
|
3410
|
+
(_, prefix, q, spec) => `${prefix}${q}${externalSpecToModuleUrl(spec, externalBaseDir, root)}${q}`
|
|
3388
3411
|
);
|
|
3389
|
-
code = rewriteExternalRequires(code);
|
|
3412
|
+
code = rewriteExternalRequires(code, externalBaseDir, root);
|
|
3390
3413
|
if (code.includes("__commonJSMin")) {
|
|
3391
3414
|
code = await injectCjsNamedExports(code, entryFile);
|
|
3392
3415
|
}
|
|
3393
3416
|
return code;
|
|
3394
3417
|
}
|
|
3395
|
-
async function tryGenerateSubpathShim(entryFile) {
|
|
3418
|
+
async function tryGenerateSubpathShim(entryFile, root) {
|
|
3396
3419
|
const NM = `${import_node_path11.default.sep}node_modules${import_node_path11.default.sep}`;
|
|
3397
3420
|
if (!entryFile.includes(NM)) return null;
|
|
3398
3421
|
let pkgDir = null;
|
|
@@ -3443,9 +3466,11 @@ async function tryGenerateSubpathShim(entryFile) {
|
|
|
3443
3466
|
if (!("default" in mainNs)) return null;
|
|
3444
3467
|
if (mainNs["default"] !== subNs["default"]) return null;
|
|
3445
3468
|
}
|
|
3469
|
+
const rootMain = resolveNodeModule(root, pkgName);
|
|
3470
|
+
const mainEntryUrl = rootMain && rootMain.startsWith(pkgDir + import_node_path11.default.sep) ? `/@modules/${pkgName}` : `/@modules/${pkgName}?id=${encodeURIComponent(mainEntry)}`;
|
|
3446
3471
|
const lines = [
|
|
3447
3472
|
`// Nasti subpath shim \u2192 ${pkgName} (avoid duplicate bundling)`,
|
|
3448
|
-
`import * as __pkg from "
|
|
3473
|
+
`import * as __pkg from "${mainEntryUrl}";`
|
|
3449
3474
|
];
|
|
3450
3475
|
for (const k of subKeys) {
|
|
3451
3476
|
lines.push(`export const ${k} = __pkg[${JSON.stringify(k)}];`);
|
|
@@ -3489,7 +3514,7 @@ function pickMainEntryByExtension(pkgDir, preferredExt) {
|
|
|
3489
3514
|
}
|
|
3490
3515
|
return null;
|
|
3491
3516
|
}
|
|
3492
|
-
function rewriteExternalRequires(code) {
|
|
3517
|
+
function rewriteExternalRequires(code, baseDir, root) {
|
|
3493
3518
|
const pkgs = /* @__PURE__ */ new Set();
|
|
3494
3519
|
const re = /__require\(["']([^"']+)["']\)/g;
|
|
3495
3520
|
let m;
|
|
@@ -3501,7 +3526,7 @@ function rewriteExternalRequires(code) {
|
|
|
3501
3526
|
const imports = [];
|
|
3502
3527
|
for (const pkg of pkgs) {
|
|
3503
3528
|
const safe = pkg.replace(/[^a-zA-Z0-9_$]/g, "_");
|
|
3504
|
-
imports.push(`import * as __ns_${safe} from "
|
|
3529
|
+
imports.push(`import * as __ns_${safe} from "${externalSpecToModuleUrl(pkg, baseDir, root)}";`);
|
|
3505
3530
|
imports.push(`var __req_${safe} = "default" in __ns_${safe} ? __ns_${safe}["default"] : __ns_${safe};`);
|
|
3506
3531
|
result = result.replaceAll(`__require("${pkg}")`, `__req_${safe}`);
|
|
3507
3532
|
result = result.replaceAll(`__require('${pkg}')`, `__req_${safe}`);
|
|
@@ -3598,7 +3623,23 @@ function isUnderRoot(abs, root) {
|
|
|
3598
3623
|
const rel = import_node_path11.default.relative(root, abs);
|
|
3599
3624
|
return !!rel && !rel.startsWith("..") && !import_node_path11.default.isAbsolute(rel);
|
|
3600
3625
|
}
|
|
3601
|
-
function
|
|
3626
|
+
function externalSpecToModuleUrl(spec, baseDir, root) {
|
|
3627
|
+
const resolved = resolveNodeModule(baseDir, spec);
|
|
3628
|
+
if (!resolved) return `/@modules/${spec}`;
|
|
3629
|
+
const rootResolved = resolveNodeModule(root, spec);
|
|
3630
|
+
if (rootResolved && rootResolved === resolved) return `/@modules/${spec}`;
|
|
3631
|
+
return `/@modules/${spec}?id=${encodeURIComponent(resolved)}`;
|
|
3632
|
+
}
|
|
3633
|
+
function resolveNodeModule(baseDir, moduleName) {
|
|
3634
|
+
const resolved = resolveNodeModuleEntry(baseDir, moduleName);
|
|
3635
|
+
if (!resolved) return null;
|
|
3636
|
+
try {
|
|
3637
|
+
return import_node_fs8.default.realpathSync(resolved);
|
|
3638
|
+
} catch {
|
|
3639
|
+
return resolved;
|
|
3640
|
+
}
|
|
3641
|
+
}
|
|
3642
|
+
function resolveNodeModuleEntry(root, moduleName) {
|
|
3602
3643
|
let pkgName;
|
|
3603
3644
|
let subpath;
|
|
3604
3645
|
if (moduleName.startsWith("@")) {
|
|
@@ -3668,7 +3709,12 @@ function resolvePackageExports(exports2, key, pkgDir) {
|
|
|
3668
3709
|
return key === "." ? import_node_path11.default.join(pkgDir, exports2) : null;
|
|
3669
3710
|
}
|
|
3670
3711
|
const entry = exports2[key];
|
|
3671
|
-
if (entry === void 0)
|
|
3712
|
+
if (entry === void 0) {
|
|
3713
|
+
if (key === "." && typeof exports2 === "object" && !Object.keys(exports2).some((k) => k.startsWith("."))) {
|
|
3714
|
+
return resolveExportValue(exports2, pkgDir);
|
|
3715
|
+
}
|
|
3716
|
+
return null;
|
|
3717
|
+
}
|
|
3672
3718
|
return resolveExportValue(entry, pkgDir);
|
|
3673
3719
|
}
|
|
3674
3720
|
function resolveExportValue(value, pkgDir) {
|
|
@@ -4707,7 +4753,7 @@ async function createServer(inlineConfig = {}) {
|
|
|
4707
4753
|
const readyIn = Math.ceil(performance.now() - startTime);
|
|
4708
4754
|
logger.info(
|
|
4709
4755
|
`
|
|
4710
|
-
${import_picocolors9.default.cyan(import_picocolors9.default.bold("NASTI"))} ${import_picocolors9.default.cyan(`v${"2.0.
|
|
4756
|
+
${import_picocolors9.default.cyan(import_picocolors9.default.bold("NASTI"))} ${import_picocolors9.default.cyan(`v${"2.0.2"}`)} ${import_picocolors9.default.dim("ready in")} ${import_picocolors9.default.bold(readyIn)} ${import_picocolors9.default.dim("ms")}
|
|
4711
4757
|
`
|
|
4712
4758
|
);
|
|
4713
4759
|
printServerUrls(
|
|
@@ -4866,7 +4912,7 @@ async function buildElectron(inlineConfig = {}) {
|
|
|
4866
4912
|
const config = await resolveConfig({ ...inlineConfig, target: "electron" }, "build");
|
|
4867
4913
|
const startTime = performance.now();
|
|
4868
4914
|
assertElectronVersion(config);
|
|
4869
|
-
console.log(import_picocolors5.default.cyan("\n\u26A1 nasti build (electron)") + import_picocolors5.default.dim(` v${"2.0.
|
|
4915
|
+
console.log(import_picocolors5.default.cyan("\n\u26A1 nasti build (electron)") + import_picocolors5.default.dim(` v${"2.0.2"}`));
|
|
4870
4916
|
console.log(import_picocolors5.default.dim(` root: ${config.root}`));
|
|
4871
4917
|
console.log(import_picocolors5.default.dim(` mode: ${config.mode}`));
|
|
4872
4918
|
console.log(import_picocolors5.default.dim(` target: electron (\u2265 ${config.electron.minVersion})`));
|
|
@@ -5017,7 +5063,7 @@ async function startElectronDev(inlineConfig = {}) {
|
|
|
5017
5063
|
const { noSpawn, ...rest } = inlineConfig;
|
|
5018
5064
|
const config = await resolveConfig({ ...rest, target: "electron" }, "serve");
|
|
5019
5065
|
warnElectronVersion(config);
|
|
5020
|
-
console.log(import_picocolors10.default.cyan("\n\u26A1 nasti electron dev") + import_picocolors10.default.dim(` v${"2.0.
|
|
5066
|
+
console.log(import_picocolors10.default.cyan("\n\u26A1 nasti electron dev") + import_picocolors10.default.dim(` v${"2.0.2"}`));
|
|
5021
5067
|
const { createServer: createServer2 } = await Promise.resolve().then(() => (init_server(), server_exports));
|
|
5022
5068
|
const server = await createServer2({ ...rest, target: "electron" });
|
|
5023
5069
|
await server.listen();
|