vite-plugin-dts 1.3.1 → 1.4.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/dist/index.js +35 -2
- package/dist/index.mjs +35 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -256,9 +256,11 @@ function transferSetupPosition(content) {
|
|
|
256
256
|
// src/compile.ts
|
|
257
257
|
var exportDefaultRE = /export\s+default/;
|
|
258
258
|
var exportDefaultClassRE = /(?:(?:^|\n|;)\s*)export\s+default\s+class\s+([\w$]+)/;
|
|
259
|
+
var noScriptContent = "import { defineComponent } from 'vue'\nexport default defineComponent({})";
|
|
259
260
|
var index = 1;
|
|
260
261
|
var compileRoot = null;
|
|
261
262
|
var compiler;
|
|
263
|
+
var vue;
|
|
262
264
|
function requireCompiler() {
|
|
263
265
|
if (!compiler) {
|
|
264
266
|
if (compileRoot) {
|
|
@@ -281,15 +283,43 @@ function requireCompiler() {
|
|
|
281
283
|
}
|
|
282
284
|
return compiler;
|
|
283
285
|
}
|
|
286
|
+
function isVue3() {
|
|
287
|
+
if (!vue) {
|
|
288
|
+
if (compileRoot) {
|
|
289
|
+
try {
|
|
290
|
+
vue = require(require.resolve("vue", { paths: [compileRoot] }));
|
|
291
|
+
} catch (e) {
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
if (!vue) {
|
|
295
|
+
try {
|
|
296
|
+
vue = require("vue");
|
|
297
|
+
} catch (e) {
|
|
298
|
+
throw new Error("vue is not present in the dependency tree.\n");
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
return vue.version.startsWith("3");
|
|
303
|
+
}
|
|
284
304
|
function setCompileRoot(root) {
|
|
285
305
|
if (root && root !== compileRoot) {
|
|
286
306
|
compileRoot = root;
|
|
287
307
|
compiler = null;
|
|
288
308
|
}
|
|
289
309
|
}
|
|
310
|
+
function parseCode(code) {
|
|
311
|
+
const { parse } = requireCompiler();
|
|
312
|
+
let descriptor;
|
|
313
|
+
if (isVue3()) {
|
|
314
|
+
descriptor = parse(code).descriptor;
|
|
315
|
+
} else {
|
|
316
|
+
descriptor = parse({ source: code });
|
|
317
|
+
}
|
|
318
|
+
return descriptor;
|
|
319
|
+
}
|
|
290
320
|
function compileVueCode(code) {
|
|
291
|
-
const {
|
|
292
|
-
const
|
|
321
|
+
const { compileScript, rewriteDefault } = requireCompiler();
|
|
322
|
+
const descriptor = parseCode(code);
|
|
293
323
|
const { script, scriptSetup } = descriptor;
|
|
294
324
|
let content = null;
|
|
295
325
|
let ext = null;
|
|
@@ -317,6 +347,9 @@ const _sfc_main = ${classMatch[1]}`;
|
|
|
317
347
|
content += "\nexport default _sfc_main\n";
|
|
318
348
|
ext = script.lang || "js";
|
|
319
349
|
}
|
|
350
|
+
} else {
|
|
351
|
+
content = noScriptContent;
|
|
352
|
+
ext = "ts";
|
|
320
353
|
}
|
|
321
354
|
return { content, ext };
|
|
322
355
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -235,9 +235,11 @@ function transferSetupPosition(content) {
|
|
|
235
235
|
// src/compile.ts
|
|
236
236
|
var exportDefaultRE = /export\s+default/;
|
|
237
237
|
var exportDefaultClassRE = /(?:(?:^|\n|;)\s*)export\s+default\s+class\s+([\w$]+)/;
|
|
238
|
+
var noScriptContent = "import { defineComponent } from 'vue'\nexport default defineComponent({})";
|
|
238
239
|
var index = 1;
|
|
239
240
|
var compileRoot = null;
|
|
240
241
|
var compiler;
|
|
242
|
+
var vue;
|
|
241
243
|
function requireCompiler() {
|
|
242
244
|
if (!compiler) {
|
|
243
245
|
if (compileRoot) {
|
|
@@ -260,15 +262,43 @@ function requireCompiler() {
|
|
|
260
262
|
}
|
|
261
263
|
return compiler;
|
|
262
264
|
}
|
|
265
|
+
function isVue3() {
|
|
266
|
+
if (!vue) {
|
|
267
|
+
if (compileRoot) {
|
|
268
|
+
try {
|
|
269
|
+
vue = __require(__require.resolve("vue", { paths: [compileRoot] }));
|
|
270
|
+
} catch (e) {
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
if (!vue) {
|
|
274
|
+
try {
|
|
275
|
+
vue = __require("vue");
|
|
276
|
+
} catch (e) {
|
|
277
|
+
throw new Error("vue is not present in the dependency tree.\n");
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
return vue.version.startsWith("3");
|
|
282
|
+
}
|
|
263
283
|
function setCompileRoot(root) {
|
|
264
284
|
if (root && root !== compileRoot) {
|
|
265
285
|
compileRoot = root;
|
|
266
286
|
compiler = null;
|
|
267
287
|
}
|
|
268
288
|
}
|
|
289
|
+
function parseCode(code) {
|
|
290
|
+
const { parse } = requireCompiler();
|
|
291
|
+
let descriptor;
|
|
292
|
+
if (isVue3()) {
|
|
293
|
+
descriptor = parse(code).descriptor;
|
|
294
|
+
} else {
|
|
295
|
+
descriptor = parse({ source: code });
|
|
296
|
+
}
|
|
297
|
+
return descriptor;
|
|
298
|
+
}
|
|
269
299
|
function compileVueCode(code) {
|
|
270
|
-
const {
|
|
271
|
-
const
|
|
300
|
+
const { compileScript, rewriteDefault } = requireCompiler();
|
|
301
|
+
const descriptor = parseCode(code);
|
|
272
302
|
const { script, scriptSetup } = descriptor;
|
|
273
303
|
let content = null;
|
|
274
304
|
let ext = null;
|
|
@@ -296,6 +326,9 @@ const _sfc_main = ${classMatch[1]}`;
|
|
|
296
326
|
content += "\nexport default _sfc_main\n";
|
|
297
327
|
ext = script.lang || "js";
|
|
298
328
|
}
|
|
329
|
+
} else {
|
|
330
|
+
content = noScriptContent;
|
|
331
|
+
ext = "ts";
|
|
299
332
|
}
|
|
300
333
|
return { content, ext };
|
|
301
334
|
}
|
package/package.json
CHANGED