@nasti-toolchain/nasti 1.7.0 → 1.7.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/index.cjs CHANGED
@@ -305,6 +305,17 @@ function resolvePlugin(config) {
305
305
  const aliasEntries = Object.entries(alias).sort(
306
306
  ([a], [b]) => b.length - a.length
307
307
  );
308
+ let vueRuntimeEntry = null;
309
+ if (config.framework === "vue") {
310
+ try {
311
+ const vuePkgJson = require2.resolve("vue/package.json", { paths: [config.root] });
312
+ const vueDir = import_node_path2.default.dirname(vuePkgJson);
313
+ const mod = JSON.parse(import_node_fs2.default.readFileSync(vuePkgJson, "utf-8")).module;
314
+ const entry = import_node_path2.default.join(vueDir, mod ?? "dist/vue.runtime.esm-bundler.js");
315
+ if (import_node_fs2.default.existsSync(entry)) vueRuntimeEntry = entry;
316
+ } catch {
317
+ }
318
+ }
308
319
  return {
309
320
  name: "nasti:resolve",
310
321
  enforce: "pre",
@@ -335,6 +346,7 @@ function resolvePlugin(config) {
335
346
  if (resolved) return resolved;
336
347
  }
337
348
  if (!source.startsWith("/") && !source.startsWith(".")) {
349
+ if (vueRuntimeEntry && source === "vue") return vueRuntimeEntry;
338
350
  try {
339
351
  const resolved = require2.resolve(source, {
340
352
  paths: [importer ? import_node_path2.default.dirname(importer) : config.root]
@@ -420,15 +432,15 @@ async function loadTailwind(projectRoot) {
420
432
  async function compileTailwind(css, fromFile, projectRoot) {
421
433
  const { node, oxide } = await loadTailwind(projectRoot);
422
434
  const dependencies = [];
423
- const compiler = await node.compile(css, {
435
+ const compiler2 = await node.compile(css, {
424
436
  base: import_node_path3.default.dirname(fromFile),
425
437
  from: fromFile,
426
438
  onDependency: (p) => dependencies.push(p)
427
439
  });
428
- const scanner = new oxide.Scanner({ sources: compiler.sources });
440
+ const scanner = new oxide.Scanner({ sources: compiler2.sources });
429
441
  const candidates = scanner.scan();
430
442
  return {
431
- css: compiler.build(candidates),
443
+ css: compiler2.build(candidates),
432
444
  dependencies: [...dependencies, ...scanner.files]
433
445
  };
434
446
  }
@@ -614,6 +626,215 @@ var init_assets = __esm({
614
626
  }
615
627
  });
616
628
 
629
+ // src/core/transformer.ts
630
+ function shouldTransform(id) {
631
+ return TS_EXTENSIONS.test(id) || JSX_EXTENSIONS.test(id) || JS_EXTENSIONS.test(id) && false;
632
+ }
633
+ function transformCode(filename, code, options = {}) {
634
+ const isTS = TS_EXTENSIONS.test(filename) || /\.tsx$/.test(filename);
635
+ const isJSX = JSX_EXTENSIONS.test(filename);
636
+ const result = (0, import_oxc_transform.transformSync)(filename, code, {
637
+ typescript: isTS ? {} : void 0,
638
+ jsx: isJSX || /\.tsx$/.test(filename) ? {
639
+ runtime: options.jsxRuntime ?? "automatic",
640
+ importSource: options.jsxImportSource ?? "react",
641
+ refresh: options.reactRefresh ?? false
642
+ } : void 0,
643
+ sourcemap: options.sourcemap ?? true
644
+ });
645
+ if (result.errors && result.errors.length > 0) {
646
+ const msg = result.errors.map((e) => e.message ?? String(e)).join("\n");
647
+ throw new Error(`OXC transform failed for ${filename}:
648
+ ${msg}`);
649
+ }
650
+ return {
651
+ code: result.code,
652
+ map: result.map ? JSON.stringify(result.map) : null
653
+ };
654
+ }
655
+ var import_oxc_transform, JS_EXTENSIONS, TS_EXTENSIONS, JSX_EXTENSIONS;
656
+ var init_transformer = __esm({
657
+ "src/core/transformer.ts"() {
658
+ "use strict";
659
+ import_oxc_transform = require("oxc-transform");
660
+ JS_EXTENSIONS = /\.(js|mjs|cjs)$/;
661
+ TS_EXTENSIONS = /\.(ts|mts|cts)$/;
662
+ JSX_EXTENSIONS = /\.(jsx|tsx)$/;
663
+ }
664
+ });
665
+
666
+ // src/plugins/vue.ts
667
+ async function loadVueCompiler() {
668
+ if (compiler) return compiler;
669
+ try {
670
+ compiler = await import("@vue/compiler-sfc");
671
+ return compiler;
672
+ } catch {
673
+ return null;
674
+ }
675
+ }
676
+ function vuePlugin(config) {
677
+ const isDev = config.command === "serve";
678
+ const descriptorCache = /* @__PURE__ */ new Map();
679
+ return {
680
+ name: "nasti:vue",
681
+ enforce: "pre",
682
+ async resolveId(source) {
683
+ if (VUE_QUERY_RE.test(source)) {
684
+ return source;
685
+ }
686
+ return null;
687
+ },
688
+ async transform(code, id) {
689
+ if (!VUE_FILE_RE.test(id) && !VUE_QUERY_RE.test(id)) return null;
690
+ const sfc = await loadVueCompiler();
691
+ if (!sfc) {
692
+ console.warn("[nasti:vue] @vue/compiler-sfc not found. Install it: npm install @vue/compiler-sfc");
693
+ return null;
694
+ }
695
+ if (VUE_QUERY_RE.test(id)) {
696
+ return handleVueSubBlock(id, sfc, descriptorCache, config);
697
+ }
698
+ const { descriptor, errors } = sfc.parse(code, { filename: id });
699
+ if (errors.length) {
700
+ console.error(`[nasti:vue] Parse error in ${id}:`, errors[0].message);
701
+ return null;
702
+ }
703
+ descriptorCache.set(id, descriptor);
704
+ const scopeId = hashId(id);
705
+ let scriptCode = "";
706
+ if (descriptor.script || descriptor.scriptSetup) {
707
+ const compiled = sfc.compileScript(descriptor, {
708
+ id: scopeId,
709
+ isProd: !isDev,
710
+ inlineTemplate: true,
711
+ // 让 compileScript 产出 `const __sfc__ = ...`(而非默认的 `export default {...}`)。
712
+ // 否则下方追加的 `__sfc__.render` / `__sfc__.__scopeId` / HMR 记录会引用一个
713
+ // 不存在的 `__sfc__`,并与 compileScript 自带的 `export default` 形成双重默认导出。
714
+ genDefaultAs: "__sfc__"
715
+ });
716
+ scriptCode = compiled.content;
717
+ }
718
+ let templateCode = "";
719
+ if (descriptor.template && !descriptor.scriptSetup) {
720
+ const compiled = sfc.compileTemplate({
721
+ source: descriptor.template.content,
722
+ filename: id,
723
+ id: scopeId,
724
+ compilerOptions: { scopeId: `data-v-${scopeId}` }
725
+ });
726
+ templateCode = compiled.code;
727
+ }
728
+ let output = scriptCode || "const __sfc__ = {}";
729
+ if (templateCode) {
730
+ output += `
731
+ ${templateCode}
732
+ `;
733
+ output += `
734
+ __sfc__.render = render
735
+ `;
736
+ }
737
+ if (descriptor.styles.length > 0) {
738
+ for (let i = 0; i < descriptor.styles.length; i++) {
739
+ const style = descriptor.styles[i];
740
+ const lang2 = style.lang ?? "css";
741
+ output += `
742
+ import "${id}?vue&type=style&index=${i}&lang=${lang2}"
743
+ `;
744
+ }
745
+ }
746
+ output += `
747
+ __sfc__.__scopeId = "data-v-${scopeId}"
748
+ `;
749
+ if (isDev) {
750
+ output += `
751
+ __sfc__.__hmrId = ${JSON.stringify(scopeId)}
752
+ if (typeof __VUE_HMR_RUNTIME__ !== 'undefined') {
753
+ __VUE_HMR_RUNTIME__.createRecord(__sfc__.__hmrId, __sfc__)
754
+ }
755
+ if (import.meta.hot) {
756
+ import.meta.hot.accept((mod) => {
757
+ if (!mod) return
758
+ const { default: updated } = mod
759
+ if (typeof __VUE_HMR_RUNTIME__ !== 'undefined') {
760
+ __VUE_HMR_RUNTIME__.rerender(updated.__hmrId, updated.render)
761
+ }
762
+ })
763
+ }
764
+ `;
765
+ }
766
+ output += `
767
+ export default __sfc__
768
+ `;
769
+ const lang = descriptor.scriptSetup?.lang ?? descriptor.script?.lang;
770
+ if (lang === "ts") {
771
+ const transpiled = transformCode(`${id}.ts`, output, { sourcemap: false });
772
+ return { code: transpiled.code };
773
+ }
774
+ return { code: output };
775
+ },
776
+ handleHotUpdate(ctx) {
777
+ const { file, modules } = ctx;
778
+ if (VUE_FILE_RE.test(file)) {
779
+ for (const mod of modules) {
780
+ mod.isSelfAccepting = true;
781
+ }
782
+ descriptorCache.delete(file);
783
+ }
784
+ return modules;
785
+ }
786
+ };
787
+ }
788
+ async function handleVueSubBlock(id, sfc, cache, config) {
789
+ const match = id.match(/(.+\.vue)\?vue&type=(\w+)(?:&index=(\d+))?(?:&lang=(\w+))?/);
790
+ if (!match) return null;
791
+ const [, filePath, type, indexStr, lang] = match;
792
+ const descriptor = cache.get(filePath);
793
+ if (!descriptor) return null;
794
+ if (type === "style") {
795
+ const index = parseInt(indexStr ?? "0", 10);
796
+ const style = descriptor.styles[index];
797
+ if (!style) return null;
798
+ const scopeId = hashId(filePath);
799
+ const result = await sfc.compileStyleAsync({
800
+ source: style.content,
801
+ filename: filePath,
802
+ id: `data-v-${scopeId}`,
803
+ scoped: style.scoped ?? false
804
+ });
805
+ const cssCode = JSON.stringify(result.code);
806
+ return {
807
+ code: `
808
+ const css = ${cssCode};
809
+ const style = document.createElement('style');
810
+ style.setAttribute('data-v-${scopeId}', '');
811
+ style.textContent = css;
812
+ document.head.appendChild(style);
813
+
814
+ if (import.meta.hot) {
815
+ import.meta.hot.accept();
816
+ import.meta.hot.prune(() => style.remove());
817
+ }
818
+ `
819
+ };
820
+ }
821
+ return null;
822
+ }
823
+ function hashId(filename) {
824
+ return import_node_crypto2.default.createHash("sha256").update(filename).digest("hex").slice(0, 8);
825
+ }
826
+ var import_node_crypto2, VUE_FILE_RE, VUE_QUERY_RE, compiler;
827
+ var init_vue = __esm({
828
+ "src/plugins/vue.ts"() {
829
+ "use strict";
830
+ import_node_crypto2 = __toESM(require("crypto"), 1);
831
+ init_transformer();
832
+ VUE_FILE_RE = /\.vue$/;
833
+ VUE_QUERY_RE = /\.vue\?vue&type=(script|template|style)(&index=\d+)?(&lang=\w+)?/;
834
+ compiler = null;
835
+ }
836
+ });
837
+
617
838
  // src/plugins/html.ts
618
839
  function htmlPlugin(config) {
619
840
  return {
@@ -697,43 +918,6 @@ window.__vite_plugin_react_preamble_installed__ = true;
697
918
  }
698
919
  });
699
920
 
700
- // src/core/transformer.ts
701
- function shouldTransform(id) {
702
- return TS_EXTENSIONS.test(id) || JSX_EXTENSIONS.test(id) || JS_EXTENSIONS.test(id) && false;
703
- }
704
- function transformCode(filename, code, options = {}) {
705
- const isTS = TS_EXTENSIONS.test(filename) || /\.tsx$/.test(filename);
706
- const isJSX = JSX_EXTENSIONS.test(filename);
707
- const result = (0, import_oxc_transform.transformSync)(filename, code, {
708
- typescript: isTS ? {} : void 0,
709
- jsx: isJSX || /\.tsx$/.test(filename) ? {
710
- runtime: options.jsxRuntime ?? "automatic",
711
- importSource: options.jsxImportSource ?? "react",
712
- refresh: options.reactRefresh ?? false
713
- } : void 0,
714
- sourcemap: options.sourcemap ?? true
715
- });
716
- if (result.errors && result.errors.length > 0) {
717
- const msg = result.errors.map((e) => e.message ?? String(e)).join("\n");
718
- throw new Error(`OXC transform failed for ${filename}:
719
- ${msg}`);
720
- }
721
- return {
722
- code: result.code,
723
- map: result.map ? JSON.stringify(result.map) : null
724
- };
725
- }
726
- var import_oxc_transform, JS_EXTENSIONS, TS_EXTENSIONS, JSX_EXTENSIONS;
727
- var init_transformer = __esm({
728
- "src/core/transformer.ts"() {
729
- "use strict";
730
- import_oxc_transform = require("oxc-transform");
731
- JS_EXTENSIONS = /\.(js|mjs|cjs)$/;
732
- TS_EXTENSIONS = /\.(ts|mts|cts)$/;
733
- JSX_EXTENSIONS = /\.(jsx|tsx)$/;
734
- }
735
- });
736
-
737
921
  // src/core/env.ts
738
922
  function loadEnv(mode, root, prefixes) {
739
923
  const envFiles = [
@@ -924,7 +1108,7 @@ __export(build_exports, {
924
1108
  async function build(inlineConfig = {}) {
925
1109
  const config = await resolveConfig(inlineConfig, "build");
926
1110
  const startTime = performance.now();
927
- console.log(import_picocolors.default.cyan("\n\u{1F528} nasti build") + import_picocolors.default.dim(` v${"1.7.0"}`));
1111
+ console.log(import_picocolors.default.cyan("\n\u{1F528} nasti build") + import_picocolors.default.dim(` v${"1.7.1"}`));
928
1112
  console.log(import_picocolors.default.dim(` root: ${config.root}`));
929
1113
  console.log(import_picocolors.default.dim(` mode: ${config.mode}`));
930
1114
  const outDir = import_node_path8.default.resolve(config.root, config.build.outDir);
@@ -957,6 +1141,7 @@ async function build(inlineConfig = {}) {
957
1141
  throw new Error("No entry point found. Add a <script> tag to index.html or create src/main.ts");
958
1142
  }
959
1143
  const builtinPlugins = [
1144
+ ...config.framework === "vue" ? [vuePlugin(config)] : [],
960
1145
  resolvePlugin(config),
961
1146
  cssPlugin(config),
962
1147
  assetsPlugin(config)
@@ -979,7 +1164,12 @@ async function build(inlineConfig = {}) {
979
1164
  const env = loadEnv(config.mode, config.root, config.envPrefix);
980
1165
  const envDefine = buildEnvDefine(env, config.mode);
981
1166
  const { output: userOutput, transform: userTransform, ...restInputOptions } = config.build.rolldownOptions;
982
- const mergedDefine = { ...userTransform?.define ?? {}, ...envDefine };
1167
+ const vueDefine = config.framework === "vue" ? {
1168
+ __VUE_OPTIONS_API__: "true",
1169
+ __VUE_PROD_DEVTOOLS__: "false",
1170
+ __VUE_PROD_HYDRATION_MISMATCH_DETAILS__: "false"
1171
+ } : {};
1172
+ const mergedDefine = { ...vueDefine, ...userTransform?.define ?? {}, ...envDefine };
983
1173
  const bundle = await (0, import_rolldown.rolldown)({
984
1174
  ...restInputOptions,
985
1175
  input: entryPoints,
@@ -1075,6 +1265,7 @@ var init_build = __esm({
1075
1265
  init_resolve();
1076
1266
  init_css();
1077
1267
  init_assets();
1268
+ init_vue();
1078
1269
  init_html();
1079
1270
  init_transformer();
1080
1271
  init_env();
@@ -2077,6 +2268,7 @@ __export(server_exports, {
2077
2268
  async function createServer(inlineConfig = {}) {
2078
2269
  const config = await resolveConfig(inlineConfig, "serve");
2079
2270
  const allPlugins = [
2271
+ ...config.framework === "vue" ? [vuePlugin(config)] : [],
2080
2272
  resolvePlugin(config),
2081
2273
  cssPlugin(config),
2082
2274
  assetsPlugin(config),
@@ -2137,7 +2329,7 @@ async function createServer(inlineConfig = {}) {
2137
2329
  const localUrl = `http://localhost:${actualPort}`;
2138
2330
  const networkUrl = host === "0.0.0.0" ? `http://${getNetworkAddress()}:${actualPort}` : null;
2139
2331
  console.log();
2140
- console.log(import_picocolors3.default.cyan(" nasti dev server") + import_picocolors3.default.dim(` v${"1.7.0"}`));
2332
+ console.log(import_picocolors3.default.cyan(" nasti dev server") + import_picocolors3.default.dim(` v${"1.7.1"}`));
2141
2333
  console.log();
2142
2334
  console.log(` ${import_picocolors3.default.green(">")} Local: ${import_picocolors3.default.cyan(localUrl)}`);
2143
2335
  if (networkUrl) {
@@ -2213,6 +2405,7 @@ var init_server = __esm({
2213
2405
  init_resolve();
2214
2406
  init_css();
2215
2407
  init_assets();
2408
+ init_vue();
2216
2409
  init_html();
2217
2410
  }
2218
2411
  });
@@ -2281,7 +2474,7 @@ async function buildElectron(inlineConfig = {}) {
2281
2474
  const config = await resolveConfig({ ...inlineConfig, target: "electron" }, "build");
2282
2475
  const startTime = performance.now();
2283
2476
  assertElectronVersion(config);
2284
- console.log(import_picocolors2.default.cyan("\n\u26A1 nasti build (electron)") + import_picocolors2.default.dim(` v${"1.7.0"}`));
2477
+ console.log(import_picocolors2.default.cyan("\n\u26A1 nasti build (electron)") + import_picocolors2.default.dim(` v${"1.7.1"}`));
2285
2478
  console.log(import_picocolors2.default.dim(` root: ${config.root}`));
2286
2479
  console.log(import_picocolors2.default.dim(` mode: ${config.mode}`));
2287
2480
  console.log(import_picocolors2.default.dim(` target: electron (\u2265 ${config.electron.minVersion})`));
@@ -2432,7 +2625,7 @@ async function startElectronDev(inlineConfig = {}) {
2432
2625
  const { noSpawn, ...rest } = inlineConfig;
2433
2626
  const config = await resolveConfig({ ...rest, target: "electron" }, "serve");
2434
2627
  warnElectronVersion(config);
2435
- console.log(import_picocolors4.default.cyan("\n\u26A1 nasti electron dev") + import_picocolors4.default.dim(` v${"1.7.0"}`));
2628
+ console.log(import_picocolors4.default.cyan("\n\u26A1 nasti electron dev") + import_picocolors4.default.dim(` v${"1.7.1"}`));
2436
2629
  const { createServer: createServer2 } = await Promise.resolve().then(() => (init_server(), server_exports));
2437
2630
  const server = await createServer2({ ...rest, target: "electron" });
2438
2631
  await server.listen();
@@ -2618,7 +2811,7 @@ function warnElectronVersion(config) {
2618
2811
  // src/plugins/monaco-editor.ts
2619
2812
  var import_node_path14 = __toESM(require("path"), 1);
2620
2813
  var import_node_fs11 = __toESM(require("fs"), 1);
2621
- var import_node_crypto2 = __toESM(require("crypto"), 1);
2814
+ var import_node_crypto3 = __toESM(require("crypto"), 1);
2622
2815
  var import_node_module6 = require("module");
2623
2816
  var DEFAULT_WORKERS = {
2624
2817
  editorWorkerService: "monaco-editor/esm/vs/editor/editor.worker",
@@ -2732,7 +2925,7 @@ function monacoEditorPlugin(options = {}) {
2732
2925
  configResolved(config) {
2733
2926
  resolvedConfig = config;
2734
2927
  const version = readMonacoVersion(config.root);
2735
- const key = import_node_crypto2.default.createHash("sha1").update(version + "|" + publicPath).digest("hex").slice(0, 8);
2928
+ const key = import_node_crypto3.default.createHash("sha1").update(version + "|" + publicPath).digest("hex").slice(0, 8);
2736
2929
  cacheDir = import_node_path14.default.resolve(config.root, "node_modules/.nasti/monaco", key);
2737
2930
  },
2738
2931
  async configureServer(server) {