@vizejs/vite-plugin 0.0.1-alpha.70 → 0.0.1-alpha.72

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.js +27 -29
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import path from "node:path";
2
2
  import fs from "node:fs";
3
3
  import { glob } from "tinyglobby";
4
- import { createRequire } from "node:module";
4
+ import * as native from "@vizejs/native";
5
5
  import { createHash } from "node:crypto";
6
6
 
7
7
  //#region src/hmr.ts
@@ -118,35 +118,12 @@ ${output}`;
118
118
 
119
119
  //#endregion
120
120
  //#region src/compiler.ts
121
- const require = createRequire(import.meta.url);
122
- let compileSfc = null;
123
- let compileSfcBatchWithResults = null;
124
- function loadNative() {
125
- if (compileSfc) return compileSfc;
126
- try {
127
- const native = require("@vizejs/native");
128
- compileSfc = native.compileSfc;
129
- return compileSfc;
130
- } catch (e) {
131
- throw new Error(`Failed to load @vizejs/native. Make sure it's installed and built:\n${String(e)}`);
132
- }
133
- }
134
- function loadNativeBatch() {
135
- if (compileSfcBatchWithResults) return compileSfcBatchWithResults;
136
- try {
137
- const native = require("@vizejs/native");
138
- compileSfcBatchWithResults = native.compileSfcBatchWithResults;
139
- return compileSfcBatchWithResults;
140
- } catch (e) {
141
- throw new Error(`Failed to load @vizejs/native. Make sure it's installed and built:\n${String(e)}`);
142
- }
143
- }
121
+ const { compileSfc, compileSfcBatchWithResults } = native;
144
122
  function compileFile(filePath, cache, options, source) {
145
- const compile = loadNative();
146
123
  const content = source ?? fs.readFileSync(filePath, "utf-8");
147
124
  const scopeId = generateScopeId(filePath);
148
125
  const hasScoped = /<style[^>]*\bscoped\b/.test(content);
149
- const result = compile(content, {
126
+ const result = compileSfc(content, {
150
127
  filename: filePath,
151
128
  sourceMap: options.sourceMap,
152
129
  ssr: options.ssr,
@@ -173,12 +150,11 @@ function compileFile(filePath, cache, options, source) {
173
150
  * Returns per-file results with content hashes for HMR.
174
151
  */
175
152
  function compileBatch(files, cache, options) {
176
- const compile = loadNativeBatch();
177
153
  const inputs = files.map((f) => ({
178
154
  path: f.path,
179
155
  source: f.source
180
156
  }));
181
- const result = compile(inputs, { ssr: options.ssr });
157
+ const result = compileSfcBatchWithResults(inputs, { ssr: options.ssr });
182
158
  for (const fileResult of result.results) {
183
159
  if (fileResult.errors.length === 0) cache.set(fileResult.path, {
184
160
  code: fileResult.code,
@@ -306,9 +282,11 @@ function vize(options = {}) {
306
282
  else if (id.startsWith("/") && !fs.existsSync(id)) resolved = path.resolve(root, id.slice(1));
307
283
  else if (path.isAbsolute(id)) resolved = id;
308
284
  else if (importer) {
309
- const realImporter = importer.startsWith(VIRTUAL_PREFIX) ? virtualToReal.get(importer) ?? importer.slice(VIRTUAL_PREFIX.length) : importer;
285
+ let realImporter = importer.startsWith(VIRTUAL_PREFIX) ? virtualToReal.get(importer) ?? importer.slice(VIRTUAL_PREFIX.length) : importer;
286
+ if (realImporter.endsWith(".vue.ts")) realImporter = realImporter.slice(0, -3);
310
287
  resolved = path.resolve(path.dirname(realImporter), id);
311
288
  } else resolved = path.resolve(root, id);
289
+ if (!path.isAbsolute(resolved)) resolved = path.resolve(root, resolved);
312
290
  return path.normalize(resolved);
313
291
  }
314
292
  return {
@@ -370,6 +348,14 @@ function vize(options = {}) {
370
348
  logger.log("Cache keys:", [...cache.keys()].slice(0, 3));
371
349
  },
372
350
  async resolveId(id, importer) {
351
+ if (id.startsWith("\0")) return null;
352
+ if (id.startsWith("vize:")) {
353
+ let realPath = id.slice(5);
354
+ if (realPath.endsWith(".ts")) realPath = realPath.slice(0, -3);
355
+ logger.log(`resolveId: redirecting stale vize: ID to ${realPath}`);
356
+ if (realPath.includes("node_modules")) return realPath;
357
+ return this.resolve(realPath, importer, { skipSelf: true });
358
+ }
373
359
  if (id === VIRTUAL_CSS_MODULE) return RESOLVED_CSS_MODULE;
374
360
  if (id.includes("?vue&type=style")) return id;
375
361
  if (importer?.startsWith(VIRTUAL_PREFIX)) {
@@ -404,7 +390,19 @@ function vize(options = {}) {
404
390
  }
405
391
  }
406
392
  if (id.endsWith(".vue")) {
393
+ if (id.includes("node_modules")) {
394
+ logger.log(`resolveId: skipping node_modules import ${id}`);
395
+ return null;
396
+ }
407
397
  const resolved = resolveVuePath(id, importer);
398
+ if (resolved.includes("node_modules")) {
399
+ logger.log(`resolveId: skipping node_modules path ${resolved}`);
400
+ return null;
401
+ }
402
+ if (!filter(resolved)) {
403
+ logger.log(`resolveId: skipping filtered path ${resolved}`);
404
+ return null;
405
+ }
408
406
  const hasCache = cache.has(resolved);
409
407
  const fileExists = fs.existsSync(resolved);
410
408
  logger.log(`resolveId: id=${id}, resolved=${resolved}, hasCache=${hasCache}, fileExists=${fileExists}, importer=${importer ?? "none"}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vizejs/vite-plugin",
3
- "version": "0.0.1-alpha.70",
3
+ "version": "0.0.1-alpha.72",
4
4
  "description": "High-performance native Vite plugin for Vue SFC compilation powered by Vize",
5
5
  "publishConfig": {
6
6
  "provenance": true,
@@ -44,7 +44,7 @@
44
44
  },
45
45
  "dependencies": {
46
46
  "tinyglobby": "^0.2.0",
47
- "@vizejs/native": "0.0.1-alpha.70"
47
+ "@vizejs/native": "0.0.1-alpha.72"
48
48
  },
49
49
  "scripts": {
50
50
  "build": "tsdown",