@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/cli.js
CHANGED
|
@@ -935,7 +935,7 @@ async function transformRequest(url, ctx) {
|
|
|
935
935
|
config.mode
|
|
936
936
|
);
|
|
937
937
|
code = replaceEnvInCode(code, envDefine);
|
|
938
|
-
code = rewriteImports(code, config);
|
|
938
|
+
code = rewriteImports(code, config, filePath);
|
|
939
939
|
const transformResult = { code };
|
|
940
940
|
mod.transformResult = transformResult;
|
|
941
941
|
return transformResult;
|
|
@@ -1017,26 +1017,73 @@ async function injectCjsNamedExports(code, entryFile) {
|
|
|
1017
1017
|
return code;
|
|
1018
1018
|
}
|
|
1019
1019
|
}
|
|
1020
|
-
function rewriteImports(code,
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1020
|
+
function rewriteImports(code, config, filePath) {
|
|
1021
|
+
const root = config.root;
|
|
1022
|
+
const fileDir = path4.dirname(filePath);
|
|
1023
|
+
const aliasEntries = Object.entries(config.resolve.alias).sort(
|
|
1024
|
+
([a], [b]) => b.length - a.length
|
|
1025
|
+
);
|
|
1026
|
+
const toRootUrl = (abs) => "/" + path4.relative(root, abs).replace(/\\/g, "/");
|
|
1027
|
+
const transformSpec = (spec) => {
|
|
1028
|
+
const suffixMatch = spec.match(/[?#].*$/);
|
|
1029
|
+
const suffix = suffixMatch ? suffixMatch[0] : "";
|
|
1030
|
+
const baseSpec = suffix ? spec.slice(0, -suffix.length) : spec;
|
|
1031
|
+
for (const [key, value] of aliasEntries) {
|
|
1032
|
+
if (baseSpec === key || baseSpec.startsWith(key + "/")) {
|
|
1033
|
+
const aliasBase = resolveAliasTarget(value, root);
|
|
1034
|
+
const sub = baseSpec.slice(key.length).replace(/^\//, "");
|
|
1035
|
+
const target = sub ? path4.join(aliasBase, sub) : aliasBase;
|
|
1036
|
+
const resolved = tryResolveDiskPath(target);
|
|
1037
|
+
return resolved && isUnderRoot(resolved, root) ? toRootUrl(resolved) + suffix : spec;
|
|
1038
|
+
}
|
|
1025
1039
|
}
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
return `import ${quote}/@modules/${specifier}${quote}`;
|
|
1040
|
+
if (baseSpec.startsWith("./") || baseSpec.startsWith("../")) {
|
|
1041
|
+
const target = path4.resolve(fileDir, baseSpec);
|
|
1042
|
+
const resolved = tryResolveDiskPath(target);
|
|
1043
|
+
return resolved && isUnderRoot(resolved, root) ? toRootUrl(resolved) + suffix : spec;
|
|
1031
1044
|
}
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
return `import(${quote}/@modules/${specifier}${quote})`;
|
|
1045
|
+
if (baseSpec.startsWith("/") && !baseSpec.startsWith("/@")) {
|
|
1046
|
+
const target = path4.join(root, baseSpec.replace(/^\//, ""));
|
|
1047
|
+
const resolved = tryResolveDiskPath(target);
|
|
1048
|
+
return resolved && isUnderRoot(resolved, root) ? toRootUrl(resolved) + suffix : spec;
|
|
1037
1049
|
}
|
|
1050
|
+
if (baseSpec.startsWith("/")) return spec;
|
|
1051
|
+
return `/@modules/${spec}`;
|
|
1052
|
+
};
|
|
1053
|
+
return code.replace(
|
|
1054
|
+
/\bfrom\s+(['"])([^'"]+)\1/g,
|
|
1055
|
+
(_m, q, s) => `from ${q}${transformSpec(s)}${q}`
|
|
1056
|
+
).replace(
|
|
1057
|
+
/\bimport\s+(['"])([^'"]+)\1/g,
|
|
1058
|
+
(_m, q, s) => `import ${q}${transformSpec(s)}${q}`
|
|
1059
|
+
).replace(
|
|
1060
|
+
/\bimport\s*\(\s*(['"])([^'"]+)\1\s*\)/g,
|
|
1061
|
+
(_m, q, s) => `import(${q}${transformSpec(s)}${q})`
|
|
1038
1062
|
);
|
|
1039
1063
|
}
|
|
1064
|
+
function resolveAliasTarget(value, root) {
|
|
1065
|
+
if (path4.isAbsolute(value) && fs4.existsSync(value)) return value;
|
|
1066
|
+
if (value.startsWith("/")) return path4.join(root, value.slice(1));
|
|
1067
|
+
return path4.resolve(root, value);
|
|
1068
|
+
}
|
|
1069
|
+
function tryResolveDiskPath(target) {
|
|
1070
|
+
if (fs4.existsSync(target) && fs4.statSync(target).isFile()) return target;
|
|
1071
|
+
for (const ext of RESOLVE_EXTENSIONS) {
|
|
1072
|
+
const withExt = target + ext;
|
|
1073
|
+
if (fs4.existsSync(withExt) && fs4.statSync(withExt).isFile()) return withExt;
|
|
1074
|
+
}
|
|
1075
|
+
if (fs4.existsSync(target) && fs4.statSync(target).isDirectory()) {
|
|
1076
|
+
for (const ext of RESOLVE_EXTENSIONS) {
|
|
1077
|
+
const idx = path4.join(target, "index" + ext);
|
|
1078
|
+
if (fs4.existsSync(idx) && fs4.statSync(idx).isFile()) return idx;
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
return null;
|
|
1082
|
+
}
|
|
1083
|
+
function isUnderRoot(abs, root) {
|
|
1084
|
+
const rel = path4.relative(root, abs);
|
|
1085
|
+
return !!rel && !rel.startsWith("..") && !path4.isAbsolute(rel);
|
|
1086
|
+
}
|
|
1040
1087
|
function resolveNodeModule(root, moduleName) {
|
|
1041
1088
|
let pkgName;
|
|
1042
1089
|
let subpath;
|
|
@@ -1644,7 +1691,7 @@ async function createServer(inlineConfig = {}) {
|
|
|
1644
1691
|
const localUrl = `http://localhost:${actualPort}`;
|
|
1645
1692
|
const networkUrl = host === "0.0.0.0" ? `http://${getNetworkAddress()}:${actualPort}` : null;
|
|
1646
1693
|
console.log();
|
|
1647
|
-
console.log(pc.cyan(" nasti dev server") + pc.dim(` v${"1.6.
|
|
1694
|
+
console.log(pc.cyan(" nasti dev server") + pc.dim(` v${"1.6.1"}`));
|
|
1648
1695
|
console.log();
|
|
1649
1696
|
console.log(` ${pc.green(">")} Local: ${pc.cyan(localUrl)}`);
|
|
1650
1697
|
if (networkUrl) {
|
|
@@ -1767,7 +1814,7 @@ import pc2 from "picocolors";
|
|
|
1767
1814
|
async function build(inlineConfig = {}) {
|
|
1768
1815
|
const config = await resolveConfig(inlineConfig, "build");
|
|
1769
1816
|
const startTime = performance.now();
|
|
1770
|
-
console.log(pc2.cyan("\n\u{1F528} nasti build") + pc2.dim(` v${"1.6.
|
|
1817
|
+
console.log(pc2.cyan("\n\u{1F528} nasti build") + pc2.dim(` v${"1.6.1"}`));
|
|
1771
1818
|
console.log(pc2.dim(` root: ${config.root}`));
|
|
1772
1819
|
console.log(pc2.dim(` mode: ${config.mode}`));
|
|
1773
1820
|
const outDir = path10.resolve(config.root, config.build.outDir);
|
|
@@ -1927,7 +1974,7 @@ async function buildElectron(inlineConfig = {}) {
|
|
|
1927
1974
|
const config = await resolveConfig({ ...inlineConfig, target: "electron" }, "build");
|
|
1928
1975
|
const startTime = performance.now();
|
|
1929
1976
|
assertElectronVersion(config);
|
|
1930
|
-
console.log(pc3.cyan("\n\u26A1 nasti build (electron)") + pc3.dim(` v${"1.6.
|
|
1977
|
+
console.log(pc3.cyan("\n\u26A1 nasti build (electron)") + pc3.dim(` v${"1.6.1"}`));
|
|
1931
1978
|
console.log(pc3.dim(` root: ${config.root}`));
|
|
1932
1979
|
console.log(pc3.dim(` mode: ${config.mode}`));
|
|
1933
1980
|
console.log(pc3.dim(` target: electron (\u2265 ${config.electron.minVersion})`));
|
|
@@ -2081,7 +2128,7 @@ async function startElectronDev(inlineConfig = {}) {
|
|
|
2081
2128
|
const { noSpawn, ...rest } = inlineConfig;
|
|
2082
2129
|
const config = await resolveConfig({ ...rest, target: "electron" }, "serve");
|
|
2083
2130
|
warnElectronVersion(config);
|
|
2084
|
-
console.log(pc4.cyan("\n\u26A1 nasti electron dev") + pc4.dim(` v${"1.6.
|
|
2131
|
+
console.log(pc4.cyan("\n\u26A1 nasti electron dev") + pc4.dim(` v${"1.6.1"}`));
|
|
2085
2132
|
const { createServer: createServer2 } = await Promise.resolve().then(() => (init_server(), server_exports));
|
|
2086
2133
|
const server = await createServer2({ ...rest, target: "electron" });
|
|
2087
2134
|
await server.listen();
|
|
@@ -2408,6 +2455,6 @@ cli.command("preview [root]", "Preview production build").option("--port <port>"
|
|
|
2408
2455
|
}
|
|
2409
2456
|
});
|
|
2410
2457
|
cli.help();
|
|
2411
|
-
cli.version("1.6.
|
|
2458
|
+
cli.version("1.6.1");
|
|
2412
2459
|
cli.parse();
|
|
2413
2460
|
//# sourceMappingURL=cli.js.map
|