@vizejs/nuxt 0.97.0 → 0.101.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.
Files changed (2) hide show
  1. package/dist/index.mjs +46 -19
  2. package/package.json +5 -5
package/dist/index.mjs CHANGED
@@ -1,8 +1,8 @@
1
1
  import { createRequire } from "node:module";
2
- import fs from "node:fs";
3
2
  import { addServerPlugin, addVitePlugin, createResolver, defineNuxtModule } from "@nuxt/kit";
4
3
  import vize from "@vizejs/vite-plugin";
5
4
  import { musea } from "@vizejs/vite-plugin-musea";
5
+ import fs from "node:fs";
6
6
  import path from "node:path";
7
7
  import { createHash } from "node:crypto";
8
8
  //#region src/components.ts
@@ -77,21 +77,27 @@ function getNuxtComponentDtsFiles(rootDir, buildDir) {
77
77
  ];
78
78
  return Array.from(new Set(candidates.filter((candidate) => fs.existsSync(candidate))));
79
79
  }
80
+ function forEachLine(content, visit) {
81
+ let lineStart = 0;
82
+ for (let index = 0; index <= content.length; index++) {
83
+ if (index !== content.length && content.charCodeAt(index) !== 10) continue;
84
+ const lineEnd = index > lineStart && content.charCodeAt(index - 1) === 13 ? index - 1 : index;
85
+ visit(content.slice(lineStart, lineEnd));
86
+ lineStart = index + 1;
87
+ }
88
+ }
80
89
  function loadDtsComponents(rootDir, buildDir) {
81
90
  const resolved = /* @__PURE__ */ new Map();
82
- for (const filePath of getNuxtComponentDtsFiles(rootDir, buildDir)) {
83
- const lines = fs.readFileSync(filePath, "utf-8").split("\n");
84
- for (const line of lines) {
85
- const match = line.match(DTS_COMPONENT_RE);
86
- if (!match) continue;
87
- const [, name, , importPath, exportNameDot, exportNameBracket] = match;
88
- const exportName = exportNameDot || exportNameBracket;
89
- if (!exportName) continue;
90
- const componentImport = createComponentImport(resolveImportPath(path.resolve(path.dirname(filePath), importPath)), exportName, name.startsWith("Lazy"));
91
- addComponentAlias(resolved, name, componentImport);
92
- addLazyComponentAlias(resolved, name, componentImport);
93
- }
94
- }
91
+ for (const filePath of getNuxtComponentDtsFiles(rootDir, buildDir)) forEachLine(fs.readFileSync(filePath, "utf-8"), (line) => {
92
+ const match = line.match(DTS_COMPONENT_RE);
93
+ if (!match) return;
94
+ const [, name, , importPath, exportNameDot, exportNameBracket] = match;
95
+ const exportName = exportNameDot || exportNameBracket;
96
+ if (!exportName) return;
97
+ const componentImport = createComponentImport(resolveImportPath(path.resolve(path.dirname(filePath), importPath)), exportName, name.startsWith("Lazy"));
98
+ addComponentAlias(resolved, name, componentImport);
99
+ addLazyComponentAlias(resolved, name, componentImport);
100
+ });
95
101
  return resolved;
96
102
  }
97
103
  function getProjectPackageNames(moduleNames) {
@@ -289,7 +295,8 @@ function buildNuxtDevAssetBase(baseURL = "/", buildAssetsDir = "/_nuxt/") {
289
295
  function buildNuxtCompilerOptions(rootDir, baseURL = "/", buildAssetsDir = "/_nuxt/") {
290
296
  return {
291
297
  devUrlBase: buildNuxtDevAssetBase(baseURL, buildAssetsDir),
292
- root: rootDir
298
+ root: rootDir,
299
+ scanPatterns: []
293
300
  };
294
301
  }
295
302
  function isVizeVirtualVueModuleId(id) {
@@ -311,6 +318,29 @@ function normalizeNuxtInjectedKeysForVizeVirtualModule(code, id) {
311
318
  return `'$${buildStableNuxtKey(normalizedId, index)}' ${NUXT_INJECTED_MARKER}`;
312
319
  });
313
320
  }
321
+ function readTextFile(filePath) {
322
+ return fs.readFileSync(filePath, "utf-8");
323
+ }
324
+ function readFileSize(filePath) {
325
+ return fs.statSync(filePath).size;
326
+ }
327
+ function appendOriginalVueSourceForUnoCss(code, normalizedId, options = {}) {
328
+ const filePath = normalizedId.split("?")[0];
329
+ if (!filePath) return code;
330
+ const maxBytes = Math.max(1, Math.floor(options.maxBytes ?? 2097152));
331
+ const readSize = options.readSize ?? readFileSize;
332
+ const readFile = options.readFile ?? readTextFile;
333
+ try {
334
+ if (readSize(filePath) > maxBytes) return code;
335
+ } catch {
336
+ return code;
337
+ }
338
+ try {
339
+ return `${code}\n${readFile(filePath)}`;
340
+ } catch {
341
+ return code;
342
+ }
343
+ }
314
344
  //#endregion
315
345
  //#region src/index.ts
316
346
  /**
@@ -438,10 +468,7 @@ var src_default = defineNuxtModule({
438
468
  if (isVizeVirtualVueModuleId(id)) {
439
469
  const normalizedId = normalizeVizeVirtualVueModuleId(id);
440
470
  let effectiveCode = code;
441
- if (isExtractionOnly) try {
442
- const originalSource = fs.readFileSync(normalizedId.split("?")[0], "utf-8");
443
- effectiveCode = code + "\n" + originalSource;
444
- } catch {}
471
+ if (isExtractionOnly) effectiveCode = appendOriginalVueSourceForUnoCss(code, normalizedId);
445
472
  return origTransform.call(this, effectiveCode, normalizedId, ...args);
446
473
  }
447
474
  return origTransform.call(this, code, id, ...args);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vizejs/nuxt",
3
- "version": "0.97.0",
3
+ "version": "0.101.0",
4
4
  "description": "Nuxt module for Vize - compiler, musea gallery, linter, and type checker",
5
5
  "keywords": [
6
6
  "compiler",
@@ -37,10 +37,10 @@
37
37
  },
38
38
  "dependencies": {
39
39
  "@nuxt/kit": "4.4.5",
40
- "@vizejs/musea-nuxt": "0.97.0",
41
- "@vizejs/vite-plugin": "0.97.0",
42
- "@vizejs/vite-plugin-musea": "0.97.0",
43
- "vize": "0.97.0"
40
+ "@vizejs/musea-nuxt": "0.101.0",
41
+ "@vizejs/vite-plugin": "0.101.0",
42
+ "@vizejs/vite-plugin-musea": "0.101.0",
43
+ "vize": "0.101.0"
44
44
  },
45
45
  "devDependencies": {
46
46
  "typescript": "6.0.3",