@nasti-toolchain/nasti 1.4.0 → 1.5.0
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/README.md +57 -5
- package/dist/cli.cjs +15 -14
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +15 -14
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +227 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +22 -1
- package/dist/index.d.ts +22 -1
- package/dist/index.js +226 -15
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -723,7 +723,7 @@ __export(build_exports, {
|
|
|
723
723
|
async function build(inlineConfig = {}) {
|
|
724
724
|
const config = await resolveConfig(inlineConfig, "build");
|
|
725
725
|
const startTime = performance.now();
|
|
726
|
-
console.log(import_picocolors.default.cyan("\n\u{1F528} nasti build") + import_picocolors.default.dim(` v${"1.
|
|
726
|
+
console.log(import_picocolors.default.cyan("\n\u{1F528} nasti build") + import_picocolors.default.dim(` v${"1.5.0"}`));
|
|
727
727
|
console.log(import_picocolors.default.dim(` root: ${config.root}`));
|
|
728
728
|
console.log(import_picocolors.default.dim(` mode: ${config.mode}`));
|
|
729
729
|
const outDir = import_node_path7.default.resolve(config.root, config.build.outDir);
|
|
@@ -1207,8 +1207,8 @@ function rewriteExternalRequires(code) {
|
|
|
1207
1207
|
}
|
|
1208
1208
|
async function injectCjsNamedExports(code, entryFile) {
|
|
1209
1209
|
try {
|
|
1210
|
-
const { createRequire:
|
|
1211
|
-
const req =
|
|
1210
|
+
const { createRequire: createRequire4 } = await import("module");
|
|
1211
|
+
const req = createRequire4(entryFile);
|
|
1212
1212
|
const cjsExports = req(entryFile);
|
|
1213
1213
|
if (!cjsExports || typeof cjsExports !== "object" && typeof cjsExports !== "function" || Array.isArray(cjsExports)) return code;
|
|
1214
1214
|
const namedKeys = Object.keys(cjsExports).filter(
|
|
@@ -1599,15 +1599,6 @@ async function createServer(inlineConfig = {}) {
|
|
|
1599
1599
|
watcher.on("add", (file) => {
|
|
1600
1600
|
handleFileChange(file, server);
|
|
1601
1601
|
});
|
|
1602
|
-
const postMiddlewares = [];
|
|
1603
|
-
for (const plugin of allPlugins) {
|
|
1604
|
-
if (plugin.configureServer) {
|
|
1605
|
-
const result = await plugin.configureServer(server);
|
|
1606
|
-
if (typeof result === "function") {
|
|
1607
|
-
postMiddlewares.push(result);
|
|
1608
|
-
}
|
|
1609
|
-
}
|
|
1610
|
-
}
|
|
1611
1602
|
server = {
|
|
1612
1603
|
config: configWithPlugins,
|
|
1613
1604
|
middlewares: app,
|
|
@@ -1626,7 +1617,7 @@ async function createServer(inlineConfig = {}) {
|
|
|
1626
1617
|
const localUrl = `http://localhost:${actualPort}`;
|
|
1627
1618
|
const networkUrl = host === "0.0.0.0" ? `http://${getNetworkAddress()}:${actualPort}` : null;
|
|
1628
1619
|
console.log();
|
|
1629
|
-
console.log(import_picocolors3.default.cyan(" nasti dev server") + import_picocolors3.default.dim(` v${"1.
|
|
1620
|
+
console.log(import_picocolors3.default.cyan(" nasti dev server") + import_picocolors3.default.dim(` v${"1.5.0"}`));
|
|
1630
1621
|
console.log();
|
|
1631
1622
|
console.log(` ${import_picocolors3.default.green(">")} Local: ${import_picocolors3.default.cyan(localUrl)}`);
|
|
1632
1623
|
if (networkUrl) {
|
|
@@ -1659,6 +1650,16 @@ async function createServer(inlineConfig = {}) {
|
|
|
1659
1650
|
httpServer.close();
|
|
1660
1651
|
}
|
|
1661
1652
|
};
|
|
1653
|
+
const postMiddlewares = [];
|
|
1654
|
+
for (const plugin of allPlugins) {
|
|
1655
|
+
if (plugin.configureServer) {
|
|
1656
|
+
const result = await plugin.configureServer(server);
|
|
1657
|
+
if (typeof result === "function") {
|
|
1658
|
+
postMiddlewares.push(result);
|
|
1659
|
+
}
|
|
1660
|
+
}
|
|
1661
|
+
}
|
|
1662
|
+
for (const run of postMiddlewares) run();
|
|
1662
1663
|
return server;
|
|
1663
1664
|
}
|
|
1664
1665
|
function getNetworkAddress() {
|
|
@@ -1704,6 +1705,7 @@ __export(src_exports, {
|
|
|
1704
1705
|
createServer: () => createServer,
|
|
1705
1706
|
defineConfig: () => defineConfig,
|
|
1706
1707
|
electronPlugin: () => electronPlugin,
|
|
1708
|
+
monacoEditorPlugin: () => monacoEditorPlugin,
|
|
1707
1709
|
resolveConfig: () => resolveConfig,
|
|
1708
1710
|
startElectronDev: () => startElectronDev
|
|
1709
1711
|
});
|
|
@@ -1759,7 +1761,7 @@ async function buildElectron(inlineConfig = {}) {
|
|
|
1759
1761
|
const config = await resolveConfig({ ...inlineConfig, target: "electron" }, "build");
|
|
1760
1762
|
const startTime = performance.now();
|
|
1761
1763
|
assertElectronVersion(config);
|
|
1762
|
-
console.log(import_picocolors2.default.cyan("\n\u26A1 nasti build (electron)") + import_picocolors2.default.dim(` v${"1.
|
|
1764
|
+
console.log(import_picocolors2.default.cyan("\n\u26A1 nasti build (electron)") + import_picocolors2.default.dim(` v${"1.5.0"}`));
|
|
1763
1765
|
console.log(import_picocolors2.default.dim(` root: ${config.root}`));
|
|
1764
1766
|
console.log(import_picocolors2.default.dim(` mode: ${config.mode}`));
|
|
1765
1767
|
console.log(import_picocolors2.default.dim(` target: electron (\u2265 ${config.electron.minVersion})`));
|
|
@@ -1906,7 +1908,7 @@ async function startElectronDev(inlineConfig = {}) {
|
|
|
1906
1908
|
const { noSpawn, ...rest } = inlineConfig;
|
|
1907
1909
|
const config = await resolveConfig({ ...rest, target: "electron" }, "serve");
|
|
1908
1910
|
warnElectronVersion(config);
|
|
1909
|
-
console.log(import_picocolors4.default.cyan("\n\u26A1 nasti electron dev") + import_picocolors4.default.dim(` v${"1.
|
|
1911
|
+
console.log(import_picocolors4.default.cyan("\n\u26A1 nasti electron dev") + import_picocolors4.default.dim(` v${"1.5.0"}`));
|
|
1910
1912
|
const { createServer: createServer2 } = await Promise.resolve().then(() => (init_server(), server_exports));
|
|
1911
1913
|
const server = await createServer2({ ...rest, target: "electron" });
|
|
1912
1914
|
await server.listen();
|
|
@@ -2069,6 +2071,215 @@ function warnElectronVersion(config) {
|
|
|
2069
2071
|
);
|
|
2070
2072
|
}
|
|
2071
2073
|
}
|
|
2074
|
+
|
|
2075
|
+
// src/plugins/monaco-editor.ts
|
|
2076
|
+
var import_node_path13 = __toESM(require("path"), 1);
|
|
2077
|
+
var import_node_fs11 = __toESM(require("fs"), 1);
|
|
2078
|
+
var import_node_crypto2 = __toESM(require("crypto"), 1);
|
|
2079
|
+
var import_node_module4 = require("module");
|
|
2080
|
+
var DEFAULT_WORKERS = {
|
|
2081
|
+
editorWorkerService: "monaco-editor/esm/vs/editor/editor.worker",
|
|
2082
|
+
css: "monaco-editor/esm/vs/language/css/css.worker",
|
|
2083
|
+
html: "monaco-editor/esm/vs/language/html/html.worker",
|
|
2084
|
+
json: "monaco-editor/esm/vs/language/json/json.worker",
|
|
2085
|
+
typescript: "monaco-editor/esm/vs/language/typescript/ts.worker"
|
|
2086
|
+
};
|
|
2087
|
+
var DEFAULT_PUBLIC_PATH = "monacoeditorwork";
|
|
2088
|
+
function isCDN(p) {
|
|
2089
|
+
return /^((https?:)?\/\/|file:)/.test(p);
|
|
2090
|
+
}
|
|
2091
|
+
function normalizePublicPath(p) {
|
|
2092
|
+
if (isCDN(p)) return p.replace(/\/+$/, "");
|
|
2093
|
+
const withLead = p.startsWith("/") ? p : "/" + p;
|
|
2094
|
+
return withLead.replace(/\/+$/, "") || "/";
|
|
2095
|
+
}
|
|
2096
|
+
function readMonacoVersion(root) {
|
|
2097
|
+
try {
|
|
2098
|
+
const require2 = (0, import_node_module4.createRequire)(import_node_path13.default.resolve(root, "package.json"));
|
|
2099
|
+
const pkgJsonPath = require2.resolve("monaco-editor/package.json", { paths: [root] });
|
|
2100
|
+
const pkg = JSON.parse(import_node_fs11.default.readFileSync(pkgJsonPath, "utf-8"));
|
|
2101
|
+
return typeof pkg.version === "string" ? pkg.version : "unknown";
|
|
2102
|
+
} catch {
|
|
2103
|
+
return "unknown";
|
|
2104
|
+
}
|
|
2105
|
+
}
|
|
2106
|
+
function monacoEditorPlugin(options = {}) {
|
|
2107
|
+
const languageWorkers = options.languageWorkers ?? Object.keys(DEFAULT_WORKERS);
|
|
2108
|
+
const customWorkers = options.customWorkers ?? [];
|
|
2109
|
+
const publicPath = normalizePublicPath(options.publicPath ?? DEFAULT_PUBLIC_PATH);
|
|
2110
|
+
const globalAPI = !!options.globalAPI;
|
|
2111
|
+
const forceBuildCDN = !!options.forceBuildCDN;
|
|
2112
|
+
const workers = [
|
|
2113
|
+
...languageWorkers.map((label) => ({ label, entry: DEFAULT_WORKERS[label] })),
|
|
2114
|
+
...customWorkers
|
|
2115
|
+
];
|
|
2116
|
+
let resolvedConfig;
|
|
2117
|
+
let cacheDir = "";
|
|
2118
|
+
const building = /* @__PURE__ */ new Map();
|
|
2119
|
+
async function buildWorker(worker) {
|
|
2120
|
+
const cacheFile = import_node_path13.default.join(cacheDir, `${worker.label}.worker.js`);
|
|
2121
|
+
if (import_node_fs11.default.existsSync(cacheFile)) return cacheFile;
|
|
2122
|
+
const existing = building.get(worker.label);
|
|
2123
|
+
if (existing) return existing;
|
|
2124
|
+
const task = (async () => {
|
|
2125
|
+
const { rolldown: rolldown4 } = await import("rolldown");
|
|
2126
|
+
const require2 = (0, import_node_module4.createRequire)(import_node_path13.default.resolve(resolvedConfig.root, "package.json"));
|
|
2127
|
+
let entry;
|
|
2128
|
+
try {
|
|
2129
|
+
entry = require2.resolve(worker.entry, { paths: [resolvedConfig.root] });
|
|
2130
|
+
} catch {
|
|
2131
|
+
entry = require2.resolve(worker.entry + ".js", { paths: [resolvedConfig.root] });
|
|
2132
|
+
}
|
|
2133
|
+
import_node_fs11.default.mkdirSync(cacheDir, { recursive: true });
|
|
2134
|
+
const bundle = await rolldown4({
|
|
2135
|
+
input: entry,
|
|
2136
|
+
platform: "browser"
|
|
2137
|
+
});
|
|
2138
|
+
await bundle.write({
|
|
2139
|
+
file: cacheFile,
|
|
2140
|
+
format: "iife",
|
|
2141
|
+
sourcemap: false,
|
|
2142
|
+
minify: true,
|
|
2143
|
+
inlineDynamicImports: true
|
|
2144
|
+
});
|
|
2145
|
+
await bundle.close();
|
|
2146
|
+
return cacheFile;
|
|
2147
|
+
})();
|
|
2148
|
+
building.set(worker.label, task);
|
|
2149
|
+
try {
|
|
2150
|
+
return await task;
|
|
2151
|
+
} finally {
|
|
2152
|
+
building.delete(worker.label);
|
|
2153
|
+
}
|
|
2154
|
+
}
|
|
2155
|
+
function runtimeInitScript() {
|
|
2156
|
+
let normalizedPrefix = publicPath;
|
|
2157
|
+
if (!isCDN(publicPath)) {
|
|
2158
|
+
const base = resolvedConfig.base.replace(/\/+$/, "") || "";
|
|
2159
|
+
const pub = publicPath.replace(/^\/+/, "");
|
|
2160
|
+
normalizedPrefix = base ? `${base}/${pub}` : `/${pub}`;
|
|
2161
|
+
}
|
|
2162
|
+
const map = {};
|
|
2163
|
+
for (const w of workers) {
|
|
2164
|
+
map[w.label] = `${normalizedPrefix}/${w.label}.worker.js`;
|
|
2165
|
+
}
|
|
2166
|
+
return `;(function () {
|
|
2167
|
+
var map = ${JSON.stringify(map)};
|
|
2168
|
+
function getWorkerUrl(_moduleId, label) {
|
|
2169
|
+
var url = map[label] || map['editorWorkerService'];
|
|
2170
|
+
if (/^(https?:)?\\/\\//.test(url)) {
|
|
2171
|
+
// \u8DE8\u57DF Worker \u9700\u7528 Blob + importScripts \u7ED5\u8FC7\u540C\u6E90\u9650\u5236
|
|
2172
|
+
var blob = new Blob(
|
|
2173
|
+
['importScripts(' + JSON.stringify(url) + ');'],
|
|
2174
|
+
{ type: 'application/javascript' }
|
|
2175
|
+
);
|
|
2176
|
+
return URL.createObjectURL(blob);
|
|
2177
|
+
}
|
|
2178
|
+
return url;
|
|
2179
|
+
}
|
|
2180
|
+
self.MonacoEnvironment = self.MonacoEnvironment || {};
|
|
2181
|
+
if (!self.MonacoEnvironment.getWorker && !self.MonacoEnvironment.getWorkerUrl) {
|
|
2182
|
+
self.MonacoEnvironment.getWorkerUrl = getWorkerUrl;
|
|
2183
|
+
}
|
|
2184
|
+
})();`;
|
|
2185
|
+
}
|
|
2186
|
+
return {
|
|
2187
|
+
name: "nasti:monaco-editor",
|
|
2188
|
+
enforce: "pre",
|
|
2189
|
+
configResolved(config) {
|
|
2190
|
+
resolvedConfig = config;
|
|
2191
|
+
const version = readMonacoVersion(config.root);
|
|
2192
|
+
const key = import_node_crypto2.default.createHash("sha1").update(version + "|" + publicPath).digest("hex").slice(0, 8);
|
|
2193
|
+
cacheDir = import_node_path13.default.resolve(config.root, "node_modules/.nasti/monaco", key);
|
|
2194
|
+
},
|
|
2195
|
+
async configureServer(server) {
|
|
2196
|
+
const shouldBuild = !isCDN(publicPath) || forceBuildCDN;
|
|
2197
|
+
const watcher = server.watcher;
|
|
2198
|
+
const monacoDir = import_node_path13.default.resolve(resolvedConfig.root, "node_modules/monaco-editor");
|
|
2199
|
+
try {
|
|
2200
|
+
watcher?.unwatch?.(monacoDir);
|
|
2201
|
+
} catch {
|
|
2202
|
+
}
|
|
2203
|
+
if (!shouldBuild) return;
|
|
2204
|
+
void Promise.all(
|
|
2205
|
+
workers.map(
|
|
2206
|
+
(w) => buildWorker(w).catch((e) => {
|
|
2207
|
+
console.warn(
|
|
2208
|
+
`[nasti:monaco-editor] worker build failed for "${w.label}": ${e.message}`
|
|
2209
|
+
);
|
|
2210
|
+
})
|
|
2211
|
+
)
|
|
2212
|
+
);
|
|
2213
|
+
const base = resolvedConfig.base.replace(/\/+$/, "") || "";
|
|
2214
|
+
const pub = publicPath.replace(/^\/+/, "");
|
|
2215
|
+
const prefix = (base ? `${base}/${pub}` : `/${pub}`) + "/";
|
|
2216
|
+
server.middlewares.use(
|
|
2217
|
+
async (req, res, next) => {
|
|
2218
|
+
if (req.method !== "GET") return next();
|
|
2219
|
+
const url = (req.url ?? "").split("?")[0];
|
|
2220
|
+
if (!url.startsWith(prefix)) return next();
|
|
2221
|
+
const name = url.slice(prefix.length).replace(/\.worker\.js$/, "");
|
|
2222
|
+
const worker = workers.find((w) => w.label === name);
|
|
2223
|
+
if (!worker) return next();
|
|
2224
|
+
try {
|
|
2225
|
+
const file = await buildWorker(worker);
|
|
2226
|
+
res.setHeader("Content-Type", "application/javascript; charset=utf-8");
|
|
2227
|
+
res.setHeader("Cache-Control", "public, max-age=604800, immutable");
|
|
2228
|
+
import_node_fs11.default.createReadStream(file).pipe(res);
|
|
2229
|
+
} catch (e) {
|
|
2230
|
+
res.statusCode = 500;
|
|
2231
|
+
res.end(`Monaco worker build failed: ${e.message}`);
|
|
2232
|
+
}
|
|
2233
|
+
}
|
|
2234
|
+
);
|
|
2235
|
+
},
|
|
2236
|
+
transformIndexHtml(html) {
|
|
2237
|
+
const tags = [
|
|
2238
|
+
{
|
|
2239
|
+
tag: "script",
|
|
2240
|
+
children: runtimeInitScript(),
|
|
2241
|
+
injectTo: "head-prepend"
|
|
2242
|
+
}
|
|
2243
|
+
];
|
|
2244
|
+
if (globalAPI) {
|
|
2245
|
+
tags.push({
|
|
2246
|
+
tag: "script",
|
|
2247
|
+
attrs: { type: "module" },
|
|
2248
|
+
children: `import * as monaco from 'monaco-editor';
|
|
2249
|
+
self.monaco = monaco;`,
|
|
2250
|
+
injectTo: "head"
|
|
2251
|
+
});
|
|
2252
|
+
}
|
|
2253
|
+
return { html, tags };
|
|
2254
|
+
},
|
|
2255
|
+
// 生产构建:把所有 Worker 预打包并拷到 outDir/<publicPath>/ 下
|
|
2256
|
+
async buildStart() {
|
|
2257
|
+
if (resolvedConfig.command !== "build") return;
|
|
2258
|
+
if (isCDN(publicPath) && !forceBuildCDN) return;
|
|
2259
|
+
const outDir = options.customDistPath ? options.customDistPath(
|
|
2260
|
+
resolvedConfig.root,
|
|
2261
|
+
resolvedConfig.build.outDir,
|
|
2262
|
+
resolvedConfig.base
|
|
2263
|
+
) : isCDN(publicPath) ? import_node_path13.default.resolve(resolvedConfig.root, resolvedConfig.build.outDir, "monaco") : import_node_path13.default.resolve(
|
|
2264
|
+
resolvedConfig.root,
|
|
2265
|
+
resolvedConfig.build.outDir,
|
|
2266
|
+
publicPath.replace(/^\//, "")
|
|
2267
|
+
);
|
|
2268
|
+
import_node_fs11.default.mkdirSync(outDir, { recursive: true });
|
|
2269
|
+
for (const worker of workers) {
|
|
2270
|
+
try {
|
|
2271
|
+
const cacheFile = await buildWorker(worker);
|
|
2272
|
+
import_node_fs11.default.copyFileSync(cacheFile, import_node_path13.default.join(outDir, `${worker.label}.worker.js`));
|
|
2273
|
+
} catch (e) {
|
|
2274
|
+
throw new Error(
|
|
2275
|
+
`[nasti:monaco-editor] worker build failed for "${worker.label}": ${e.message}
|
|
2276
|
+
${e.stack || ""}`
|
|
2277
|
+
);
|
|
2278
|
+
}
|
|
2279
|
+
}
|
|
2280
|
+
}
|
|
2281
|
+
};
|
|
2282
|
+
}
|
|
2072
2283
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2073
2284
|
0 && (module.exports = {
|
|
2074
2285
|
build,
|
|
@@ -2076,6 +2287,7 @@ function warnElectronVersion(config) {
|
|
|
2076
2287
|
createServer,
|
|
2077
2288
|
defineConfig,
|
|
2078
2289
|
electronPlugin,
|
|
2290
|
+
monacoEditorPlugin,
|
|
2079
2291
|
resolveConfig,
|
|
2080
2292
|
startElectronDev
|
|
2081
2293
|
});
|