@nasti-toolchain/nasti 1.6.0 → 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/cli.cjs +68 -21
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +68 -21
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +67 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +67 -20
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -793,7 +793,7 @@ import pc from "picocolors";
|
|
|
793
793
|
async function build(inlineConfig = {}) {
|
|
794
794
|
const config = await resolveConfig(inlineConfig, "build");
|
|
795
795
|
const startTime = performance.now();
|
|
796
|
-
console.log(pc.cyan("\n\u{1F528} nasti build") + pc.dim(` v${"1.6.
|
|
796
|
+
console.log(pc.cyan("\n\u{1F528} nasti build") + pc.dim(` v${"1.6.1"}`));
|
|
797
797
|
console.log(pc.dim(` root: ${config.root}`));
|
|
798
798
|
console.log(pc.dim(` mode: ${config.mode}`));
|
|
799
799
|
const outDir = path7.resolve(config.root, config.build.outDir);
|
|
@@ -1300,7 +1300,7 @@ async function transformRequest(url, ctx) {
|
|
|
1300
1300
|
config.mode
|
|
1301
1301
|
);
|
|
1302
1302
|
code = replaceEnvInCode(code, envDefine);
|
|
1303
|
-
code = rewriteImports(code, config);
|
|
1303
|
+
code = rewriteImports(code, config, filePath);
|
|
1304
1304
|
const transformResult = { code };
|
|
1305
1305
|
mod.transformResult = transformResult;
|
|
1306
1306
|
return transformResult;
|
|
@@ -1382,26 +1382,73 @@ async function injectCjsNamedExports(code, entryFile) {
|
|
|
1382
1382
|
return code;
|
|
1383
1383
|
}
|
|
1384
1384
|
}
|
|
1385
|
-
function rewriteImports(code,
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1385
|
+
function rewriteImports(code, config, filePath) {
|
|
1386
|
+
const root = config.root;
|
|
1387
|
+
const fileDir = path9.dirname(filePath);
|
|
1388
|
+
const aliasEntries = Object.entries(config.resolve.alias).sort(
|
|
1389
|
+
([a], [b]) => b.length - a.length
|
|
1390
|
+
);
|
|
1391
|
+
const toRootUrl = (abs) => "/" + path9.relative(root, abs).replace(/\\/g, "/");
|
|
1392
|
+
const transformSpec = (spec) => {
|
|
1393
|
+
const suffixMatch = spec.match(/[?#].*$/);
|
|
1394
|
+
const suffix = suffixMatch ? suffixMatch[0] : "";
|
|
1395
|
+
const baseSpec = suffix ? spec.slice(0, -suffix.length) : spec;
|
|
1396
|
+
for (const [key, value] of aliasEntries) {
|
|
1397
|
+
if (baseSpec === key || baseSpec.startsWith(key + "/")) {
|
|
1398
|
+
const aliasBase = resolveAliasTarget(value, root);
|
|
1399
|
+
const sub = baseSpec.slice(key.length).replace(/^\//, "");
|
|
1400
|
+
const target = sub ? path9.join(aliasBase, sub) : aliasBase;
|
|
1401
|
+
const resolved = tryResolveDiskPath(target);
|
|
1402
|
+
return resolved && isUnderRoot(resolved, root) ? toRootUrl(resolved) + suffix : spec;
|
|
1403
|
+
}
|
|
1390
1404
|
}
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
return `import ${quote}/@modules/${specifier}${quote}`;
|
|
1405
|
+
if (baseSpec.startsWith("./") || baseSpec.startsWith("../")) {
|
|
1406
|
+
const target = path9.resolve(fileDir, baseSpec);
|
|
1407
|
+
const resolved = tryResolveDiskPath(target);
|
|
1408
|
+
return resolved && isUnderRoot(resolved, root) ? toRootUrl(resolved) + suffix : spec;
|
|
1396
1409
|
}
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
return `import(${quote}/@modules/${specifier}${quote})`;
|
|
1410
|
+
if (baseSpec.startsWith("/") && !baseSpec.startsWith("/@")) {
|
|
1411
|
+
const target = path9.join(root, baseSpec.replace(/^\//, ""));
|
|
1412
|
+
const resolved = tryResolveDiskPath(target);
|
|
1413
|
+
return resolved && isUnderRoot(resolved, root) ? toRootUrl(resolved) + suffix : spec;
|
|
1402
1414
|
}
|
|
1415
|
+
if (baseSpec.startsWith("/")) return spec;
|
|
1416
|
+
return `/@modules/${spec}`;
|
|
1417
|
+
};
|
|
1418
|
+
return code.replace(
|
|
1419
|
+
/\bfrom\s+(['"])([^'"]+)\1/g,
|
|
1420
|
+
(_m, q, s) => `from ${q}${transformSpec(s)}${q}`
|
|
1421
|
+
).replace(
|
|
1422
|
+
/\bimport\s+(['"])([^'"]+)\1/g,
|
|
1423
|
+
(_m, q, s) => `import ${q}${transformSpec(s)}${q}`
|
|
1424
|
+
).replace(
|
|
1425
|
+
/\bimport\s*\(\s*(['"])([^'"]+)\1\s*\)/g,
|
|
1426
|
+
(_m, q, s) => `import(${q}${transformSpec(s)}${q})`
|
|
1403
1427
|
);
|
|
1404
1428
|
}
|
|
1429
|
+
function resolveAliasTarget(value, root) {
|
|
1430
|
+
if (path9.isAbsolute(value) && fs8.existsSync(value)) return value;
|
|
1431
|
+
if (value.startsWith("/")) return path9.join(root, value.slice(1));
|
|
1432
|
+
return path9.resolve(root, value);
|
|
1433
|
+
}
|
|
1434
|
+
function tryResolveDiskPath(target) {
|
|
1435
|
+
if (fs8.existsSync(target) && fs8.statSync(target).isFile()) return target;
|
|
1436
|
+
for (const ext of RESOLVE_EXTENSIONS) {
|
|
1437
|
+
const withExt = target + ext;
|
|
1438
|
+
if (fs8.existsSync(withExt) && fs8.statSync(withExt).isFile()) return withExt;
|
|
1439
|
+
}
|
|
1440
|
+
if (fs8.existsSync(target) && fs8.statSync(target).isDirectory()) {
|
|
1441
|
+
for (const ext of RESOLVE_EXTENSIONS) {
|
|
1442
|
+
const idx = path9.join(target, "index" + ext);
|
|
1443
|
+
if (fs8.existsSync(idx) && fs8.statSync(idx).isFile()) return idx;
|
|
1444
|
+
}
|
|
1445
|
+
}
|
|
1446
|
+
return null;
|
|
1447
|
+
}
|
|
1448
|
+
function isUnderRoot(abs, root) {
|
|
1449
|
+
const rel = path9.relative(root, abs);
|
|
1450
|
+
return !!rel && !rel.startsWith("..") && !path9.isAbsolute(rel);
|
|
1451
|
+
}
|
|
1405
1452
|
function resolveNodeModule(root, moduleName) {
|
|
1406
1453
|
let pkgName;
|
|
1407
1454
|
let subpath;
|
|
@@ -1804,7 +1851,7 @@ async function createServer(inlineConfig = {}) {
|
|
|
1804
1851
|
const localUrl = `http://localhost:${actualPort}`;
|
|
1805
1852
|
const networkUrl = host === "0.0.0.0" ? `http://${getNetworkAddress()}:${actualPort}` : null;
|
|
1806
1853
|
console.log();
|
|
1807
|
-
console.log(pc3.cyan(" nasti dev server") + pc3.dim(` v${"1.6.
|
|
1854
|
+
console.log(pc3.cyan(" nasti dev server") + pc3.dim(` v${"1.6.1"}`));
|
|
1808
1855
|
console.log();
|
|
1809
1856
|
console.log(` ${pc3.green(">")} Local: ${pc3.cyan(localUrl)}`);
|
|
1810
1857
|
if (networkUrl) {
|
|
@@ -1928,7 +1975,7 @@ async function buildElectron(inlineConfig = {}) {
|
|
|
1928
1975
|
const config = await resolveConfig({ ...inlineConfig, target: "electron" }, "build");
|
|
1929
1976
|
const startTime = performance.now();
|
|
1930
1977
|
assertElectronVersion(config);
|
|
1931
|
-
console.log(pc2.cyan("\n\u26A1 nasti build (electron)") + pc2.dim(` v${"1.6.
|
|
1978
|
+
console.log(pc2.cyan("\n\u26A1 nasti build (electron)") + pc2.dim(` v${"1.6.1"}`));
|
|
1932
1979
|
console.log(pc2.dim(` root: ${config.root}`));
|
|
1933
1980
|
console.log(pc2.dim(` mode: ${config.mode}`));
|
|
1934
1981
|
console.log(pc2.dim(` target: electron (\u2265 ${config.electron.minVersion})`));
|
|
@@ -2075,7 +2122,7 @@ async function startElectronDev(inlineConfig = {}) {
|
|
|
2075
2122
|
const { noSpawn, ...rest } = inlineConfig;
|
|
2076
2123
|
const config = await resolveConfig({ ...rest, target: "electron" }, "serve");
|
|
2077
2124
|
warnElectronVersion(config);
|
|
2078
|
-
console.log(pc4.cyan("\n\u26A1 nasti electron dev") + pc4.dim(` v${"1.6.
|
|
2125
|
+
console.log(pc4.cyan("\n\u26A1 nasti electron dev") + pc4.dim(` v${"1.6.1"}`));
|
|
2079
2126
|
const { createServer: createServer2 } = await Promise.resolve().then(() => (init_server(), server_exports));
|
|
2080
2127
|
const server = await createServer2({ ...rest, target: "electron" });
|
|
2081
2128
|
await server.listen();
|