unplugin-vue-components 0.16.0 → 0.17.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 +1 -0
- package/dist/{chunk-RDW5UCGS.mjs → chunk-E4HYBXJJ.mjs} +95 -17
- package/dist/{chunk-VAQPFZLT.mjs → chunk-GZWBUYKE.mjs} +28 -17
- package/dist/{chunk-YBT6MD7S.js → chunk-LWMWOXVQ.js} +29 -18
- package/dist/{chunk-6FGVCWLF.js → chunk-SFAP23Y4.js} +108 -28
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -3
- package/dist/index.mjs +2 -2
- package/dist/nuxt.js +4 -4
- package/dist/nuxt.mjs +2 -2
- package/dist/resolvers.d.ts +4 -4
- package/dist/resolvers.js +1323 -134
- package/dist/resolvers.mjs +1313 -124
- package/dist/rollup.js +3 -3
- package/dist/rollup.mjs +2 -2
- package/dist/types.d.ts +10 -4
- package/dist/vite.js +3 -3
- package/dist/vite.mjs +2 -2
- package/dist/webpack.js +3 -3
- package/dist/webpack.mjs +2 -2
- package/package.json +12 -1
- package/dist/vue2-6CUOXSRO.mjs +0 -42268
- package/dist/vue2-7V6W2UKA.js +0 -42438
- package/dist/vue3-G4UGETVC.mjs +0 -21
- package/dist/vue3-RH55KBXM.js +0 -25
- package/vue2-7V6W2UKA.d.ts +0 -2
- package/vue3-RH55KBXM.d.ts +0 -2
package/README.md
CHANGED
|
@@ -288,6 +288,7 @@ Components({
|
|
|
288
288
|
// auto import for directives
|
|
289
289
|
// default: `true` for Vue 3, `false` for Vue 2
|
|
290
290
|
// Babel is needed to do the transformation for Vue 2, it's disabled by default for performance concerns.
|
|
291
|
+
// To install Babel, run: `npm install -D @babel/parser @babel/traverse`
|
|
291
292
|
directives: true,
|
|
292
293
|
|
|
293
294
|
// filters for transforming targets
|
|
@@ -2,18 +2,18 @@ import {
|
|
|
2
2
|
DISABLE_COMMENT,
|
|
3
3
|
LibraryResolver,
|
|
4
4
|
getNameFromFilePath,
|
|
5
|
+
getTransformedPath,
|
|
5
6
|
matchGlobs,
|
|
6
7
|
parseId,
|
|
7
8
|
pascalCase,
|
|
8
9
|
resolveAlias,
|
|
9
10
|
shouldTransform,
|
|
10
11
|
stringifyComponentImport
|
|
11
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-GZWBUYKE.mjs";
|
|
12
13
|
import {
|
|
13
14
|
__require,
|
|
14
15
|
__spreadProps,
|
|
15
|
-
__spreadValues
|
|
16
|
-
__toModule
|
|
16
|
+
__spreadValues
|
|
17
17
|
} from "./chunk-PJJOEYQ7.mjs";
|
|
18
18
|
|
|
19
19
|
// src/core/unplugin.ts
|
|
@@ -42,10 +42,13 @@ var defaultOptions = {
|
|
|
42
42
|
importPathTransform: (v) => v,
|
|
43
43
|
allowOverrides: false
|
|
44
44
|
};
|
|
45
|
+
function normalizeResolvers(resolvers) {
|
|
46
|
+
return toArray(resolvers).flat().map((r) => typeof r === "function" ? { resolve: r, type: "component" } : r);
|
|
47
|
+
}
|
|
45
48
|
function resolveOptions(options, root) {
|
|
46
49
|
const resolved = Object.assign({}, defaultOptions, options);
|
|
47
50
|
resolved.libraries = toArray(resolved.libraries).map((i) => typeof i === "string" ? { name: i } : i);
|
|
48
|
-
resolved.resolvers =
|
|
51
|
+
resolved.resolvers = normalizeResolvers(resolved.resolvers);
|
|
49
52
|
resolved.resolvers.push(...resolved.libraries.map((lib) => LibraryResolver(lib)));
|
|
50
53
|
resolved.extensions = toArray(resolved.extensions);
|
|
51
54
|
if (resolved.globs) {
|
|
@@ -61,7 +64,7 @@ function resolveOptions(options, root) {
|
|
|
61
64
|
resolved.dts = !options.dts ? false : resolve(root, typeof options.dts === "string" ? options.dts : "components.d.ts");
|
|
62
65
|
resolved.root = root;
|
|
63
66
|
resolved.transformer = options.transformer || getVueVersion() || "vue3";
|
|
64
|
-
resolved.directives = typeof options.directives === "boolean" ? options.directives : getVueVersion() === "vue3";
|
|
67
|
+
resolved.directives = typeof options.directives === "boolean" ? options.directives : !resolved.resolvers.some((i) => i.type === "directive") ? false : getVueVersion() === "vue3";
|
|
65
68
|
return resolved;
|
|
66
69
|
}
|
|
67
70
|
function getVueVersion() {
|
|
@@ -108,6 +111,7 @@ async function generateDeclaration(ctx, root, filepath) {
|
|
|
108
111
|
const imports = Object.fromEntries(Object.values(__spreadValues(__spreadValues({}, ctx.componentNameMap), ctx.componentCustomMap)).map(({ path, name, importName }) => {
|
|
109
112
|
if (!name)
|
|
110
113
|
return void 0;
|
|
114
|
+
path = getTransformedPath(path, ctx);
|
|
111
115
|
const related = isAbsolute(path) ? `./${relative(dirname(filepath), path)}` : path;
|
|
112
116
|
let entry = `typeof import('${slash2(related)}')`;
|
|
113
117
|
if (importName)
|
|
@@ -178,7 +182,7 @@ var resolveVue3 = (code, s) => {
|
|
|
178
182
|
}
|
|
179
183
|
return results;
|
|
180
184
|
};
|
|
181
|
-
|
|
185
|
+
async function transformComponent(code, transformer, s, ctx, sfcPath) {
|
|
182
186
|
let no = 0;
|
|
183
187
|
const results = transformer === "vue2" ? resolveVue2(code, s) : resolveVue3(code, s);
|
|
184
188
|
for (const { rawName, replace } of results) {
|
|
@@ -195,15 +199,87 @@ var component_default = async (code, transformer, s, ctx, sfcPath) => {
|
|
|
195
199
|
}
|
|
196
200
|
}
|
|
197
201
|
debug2(`^ (${no})`);
|
|
198
|
-
}
|
|
202
|
+
}
|
|
199
203
|
|
|
200
204
|
// src/core/transforms/directive/index.ts
|
|
201
205
|
import Debug3 from "debug";
|
|
206
|
+
|
|
207
|
+
// src/core/transforms/directive/vue2.ts
|
|
208
|
+
import { importModule, isPackageExists as isPackageExists2 } from "local-pkg";
|
|
209
|
+
var getRenderFnStart = (ast) => {
|
|
210
|
+
const renderFn = ast.program.body.find((node) => node.type === "VariableDeclaration" && node.declarations[0].id.type === "Identifier" && node.declarations[0].id.name === "render");
|
|
211
|
+
const start = (renderFn == null ? void 0 : renderFn.declarations[0].init).body.start;
|
|
212
|
+
if (start === null)
|
|
213
|
+
throw new Error("[unplugin-vue-components:directive] Cannot find render function position.");
|
|
214
|
+
return start + 1;
|
|
215
|
+
};
|
|
216
|
+
async function resolveVue22(code, s) {
|
|
217
|
+
var _a, _b;
|
|
218
|
+
if (!isPackageExists2("@babel/parser") || !isPackageExists2("@babel/traverse"))
|
|
219
|
+
throw new Error('[unplugin-vue-components:directive] To use Vue 2 directive you will need to install Babel first: "npm install -D @babel/parser @babel/traverse"');
|
|
220
|
+
const { parse } = await importModule("@babel/parser");
|
|
221
|
+
const ast = parse(code, {
|
|
222
|
+
sourceType: "module"
|
|
223
|
+
});
|
|
224
|
+
const nodes = [];
|
|
225
|
+
const { default: traverse } = await importModule("@babel/traverse");
|
|
226
|
+
traverse(ast, {
|
|
227
|
+
CallExpression(path) {
|
|
228
|
+
nodes.push(path.node);
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
const results = [];
|
|
232
|
+
for (const node of nodes) {
|
|
233
|
+
const { callee, arguments: args } = node;
|
|
234
|
+
if (callee.type !== "Identifier" || callee.name !== "_c" || args[1].type !== "ObjectExpression")
|
|
235
|
+
continue;
|
|
236
|
+
const directives = (_a = args[1].properties.find((property) => property.type === "ObjectProperty" && property.key.type === "Identifier" && property.key.name === "directives")) == null ? void 0 : _a.value;
|
|
237
|
+
if (!directives || directives.type !== "ArrayExpression")
|
|
238
|
+
continue;
|
|
239
|
+
const renderStart = getRenderFnStart(ast);
|
|
240
|
+
for (const directive of directives.elements) {
|
|
241
|
+
if ((directive == null ? void 0 : directive.type) !== "ObjectExpression")
|
|
242
|
+
continue;
|
|
243
|
+
const nameNode = (_b = directive.properties.find((p) => p.type === "ObjectProperty" && p.key.type === "Identifier" && p.key.name === "name")) == null ? void 0 : _b.value;
|
|
244
|
+
if ((nameNode == null ? void 0 : nameNode.type) !== "StringLiteral")
|
|
245
|
+
continue;
|
|
246
|
+
const name = nameNode.value;
|
|
247
|
+
if (!name || name.startsWith("_"))
|
|
248
|
+
continue;
|
|
249
|
+
results.push({
|
|
250
|
+
rawName: name,
|
|
251
|
+
replace: (resolved) => {
|
|
252
|
+
s.prependLeft(renderStart, `
|
|
253
|
+
this.$options.directives["${name}"] = ${resolved};`);
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
return results;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// src/core/transforms/directive/vue3.ts
|
|
262
|
+
function resolveVue32(code, s) {
|
|
263
|
+
const results = [];
|
|
264
|
+
for (const match of code.matchAll(/_resolveDirective\("(.+?)"\)/g)) {
|
|
265
|
+
const matchedName = match[1];
|
|
266
|
+
if (match.index != null && matchedName && !matchedName.startsWith("_")) {
|
|
267
|
+
const start = match.index;
|
|
268
|
+
const end = start + match[0].length;
|
|
269
|
+
results.push({
|
|
270
|
+
rawName: matchedName,
|
|
271
|
+
replace: (resolved) => s.overwrite(start, end, resolved)
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
return results;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// src/core/transforms/directive/index.ts
|
|
202
279
|
var debug3 = Debug3("unplugin-vue-components:transform:directive");
|
|
203
|
-
|
|
280
|
+
async function transformDirective(code, transformer, s, ctx, sfcPath) {
|
|
204
281
|
let no = 0;
|
|
205
|
-
const
|
|
206
|
-
const results = resolve3(code, s);
|
|
282
|
+
const results = await (transformer === "vue2" ? resolveVue22(code, s) : resolveVue32(code, s));
|
|
207
283
|
for (const { rawName, replace } of results) {
|
|
208
284
|
debug3(`| ${rawName}`);
|
|
209
285
|
const name = pascalCase(rawName);
|
|
@@ -218,26 +294,26 @@ var directive_default = async (code, transformer, s, ctx, sfcPath) => {
|
|
|
218
294
|
replace(varName);
|
|
219
295
|
}
|
|
220
296
|
debug3(`^ (${no})`);
|
|
221
|
-
}
|
|
297
|
+
}
|
|
222
298
|
|
|
223
299
|
// src/core/transformer.ts
|
|
224
300
|
var debug4 = Debug4("unplugin-vue-components:transformer");
|
|
225
|
-
|
|
301
|
+
function tranformer(ctx, transformer) {
|
|
226
302
|
return async (code, id, path) => {
|
|
227
303
|
ctx.searchGlob();
|
|
228
304
|
const sfcPath = ctx.normalizePath(path);
|
|
229
305
|
debug4(sfcPath);
|
|
230
306
|
const s = new MagicString(code);
|
|
231
|
-
await
|
|
307
|
+
await transformComponent(code, transformer, s, ctx, sfcPath);
|
|
232
308
|
if (ctx.options.directives)
|
|
233
|
-
await
|
|
309
|
+
await transformDirective(code, transformer, s, ctx, sfcPath);
|
|
234
310
|
s.prepend(DISABLE_COMMENT);
|
|
235
311
|
const result = { code: s.toString() };
|
|
236
312
|
if (ctx.sourcemap)
|
|
237
313
|
result.map = s.generateMap({ source: id, includeContent: true });
|
|
238
314
|
return result;
|
|
239
315
|
};
|
|
240
|
-
}
|
|
316
|
+
}
|
|
241
317
|
|
|
242
318
|
// src/core/context.ts
|
|
243
319
|
var debug5 = {
|
|
@@ -272,7 +348,7 @@ var Context = class {
|
|
|
272
348
|
}
|
|
273
349
|
setTransformer(name) {
|
|
274
350
|
debug5.env("transformer", name);
|
|
275
|
-
this.transformer =
|
|
351
|
+
this.transformer = tranformer(this, name || "vue3");
|
|
276
352
|
}
|
|
277
353
|
transform(code, id) {
|
|
278
354
|
const { path, query } = parseId(id);
|
|
@@ -373,7 +449,9 @@ var Context = class {
|
|
|
373
449
|
if (info && !excludePaths.includes(info.path) && !excludePaths.includes(info.path.slice(1)))
|
|
374
450
|
return info;
|
|
375
451
|
for (const resolver of this.options.resolvers) {
|
|
376
|
-
|
|
452
|
+
if (resolver.type !== type)
|
|
453
|
+
continue;
|
|
454
|
+
const result = await resolver.resolve(name);
|
|
377
455
|
if (result) {
|
|
378
456
|
if (typeof result === "string") {
|
|
379
457
|
info = {
|
|
@@ -50,6 +50,14 @@ function matchGlobs(filepath, globs) {
|
|
|
50
50
|
}
|
|
51
51
|
return false;
|
|
52
52
|
}
|
|
53
|
+
function getTransformedPath(path, ctx) {
|
|
54
|
+
if (ctx.options.importPathTransform) {
|
|
55
|
+
const result = ctx.options.importPathTransform(path);
|
|
56
|
+
if (result != null)
|
|
57
|
+
path = result;
|
|
58
|
+
}
|
|
59
|
+
return path;
|
|
60
|
+
}
|
|
53
61
|
function stringifyImport(info) {
|
|
54
62
|
if (typeof info === "string")
|
|
55
63
|
return `import '${info}'`;
|
|
@@ -61,11 +69,7 @@ function stringifyImport(info) {
|
|
|
61
69
|
return `import ${info.name} from '${info.path}'`;
|
|
62
70
|
}
|
|
63
71
|
function stringifyComponentImport({ name, path, importName, sideEffects }, ctx) {
|
|
64
|
-
|
|
65
|
-
const result = ctx.options.importPathTransform(path);
|
|
66
|
-
if (result != null)
|
|
67
|
-
path = result;
|
|
68
|
-
}
|
|
72
|
+
path = getTransformedPath(path, ctx);
|
|
69
73
|
const imports = [
|
|
70
74
|
stringifyImport({ name, path, importName })
|
|
71
75
|
];
|
|
@@ -157,23 +161,29 @@ function LibraryResolver(options) {
|
|
|
157
161
|
} = options;
|
|
158
162
|
if (!entries) {
|
|
159
163
|
console.warn(`[unplugin-vue-components] Failed to load Vetur tags from library "${libraryName}"`);
|
|
160
|
-
return
|
|
164
|
+
return {
|
|
165
|
+
type: "component",
|
|
166
|
+
resolve: () => {
|
|
167
|
+
}
|
|
161
168
|
};
|
|
162
169
|
}
|
|
163
170
|
debug(entries);
|
|
164
171
|
const prefixKebab = kebabCase(prefix);
|
|
165
172
|
const kebabEntries = entries.map((name) => ({ name, kebab: kebabCase(name) }));
|
|
166
|
-
return
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
173
|
+
return {
|
|
174
|
+
type: "component",
|
|
175
|
+
resolve: (name) => {
|
|
176
|
+
const kebab = kebabCase(name);
|
|
177
|
+
let componentName = kebab;
|
|
178
|
+
if (prefixKebab) {
|
|
179
|
+
if (!kebab.startsWith(`${prefixKebab}-`))
|
|
180
|
+
return;
|
|
181
|
+
componentName = kebab.slice(prefixKebab.length + 1);
|
|
182
|
+
}
|
|
183
|
+
for (const entry of kebabEntries) {
|
|
184
|
+
if (entry.kebab === componentName)
|
|
185
|
+
return { path: libraryName, importName: entry.name };
|
|
186
|
+
}
|
|
177
187
|
}
|
|
178
188
|
};
|
|
179
189
|
}
|
|
@@ -185,6 +195,7 @@ export {
|
|
|
185
195
|
kebabCase,
|
|
186
196
|
parseId,
|
|
187
197
|
matchGlobs,
|
|
198
|
+
getTransformedPath,
|
|
188
199
|
stringifyComponentImport,
|
|
189
200
|
getNameFromFilePath,
|
|
190
201
|
resolveAlias,
|
|
@@ -53,6 +53,14 @@ function matchGlobs(filepath, globs) {
|
|
|
53
53
|
}
|
|
54
54
|
return false;
|
|
55
55
|
}
|
|
56
|
+
function getTransformedPath(path, ctx) {
|
|
57
|
+
if (ctx.options.importPathTransform) {
|
|
58
|
+
const result = ctx.options.importPathTransform(path);
|
|
59
|
+
if (result != null)
|
|
60
|
+
path = result;
|
|
61
|
+
}
|
|
62
|
+
return path;
|
|
63
|
+
}
|
|
56
64
|
function stringifyImport(info) {
|
|
57
65
|
if (typeof info === "string")
|
|
58
66
|
return `import '${info}'`;
|
|
@@ -64,11 +72,7 @@ function stringifyImport(info) {
|
|
|
64
72
|
return `import ${info.name} from '${info.path}'`;
|
|
65
73
|
}
|
|
66
74
|
function stringifyComponentImport({ name, path, importName, sideEffects }, ctx) {
|
|
67
|
-
|
|
68
|
-
const result = ctx.options.importPathTransform(path);
|
|
69
|
-
if (result != null)
|
|
70
|
-
path = result;
|
|
71
|
-
}
|
|
75
|
+
path = getTransformedPath(path, ctx);
|
|
72
76
|
const imports = [
|
|
73
77
|
stringifyImport({ name, path, importName })
|
|
74
78
|
];
|
|
@@ -161,23 +165,29 @@ function LibraryResolver(options) {
|
|
|
161
165
|
} = options;
|
|
162
166
|
if (!entries) {
|
|
163
167
|
console.warn(`[unplugin-vue-components] Failed to load Vetur tags from library "${libraryName}"`);
|
|
164
|
-
return
|
|
168
|
+
return {
|
|
169
|
+
type: "component",
|
|
170
|
+
resolve: () => {
|
|
171
|
+
}
|
|
165
172
|
};
|
|
166
173
|
}
|
|
167
174
|
debug(entries);
|
|
168
175
|
const prefixKebab = kebabCase(prefix);
|
|
169
176
|
const kebabEntries = entries.map((name) => ({ name, kebab: kebabCase(name) }));
|
|
170
|
-
return
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
177
|
+
return {
|
|
178
|
+
type: "component",
|
|
179
|
+
resolve: (name) => {
|
|
180
|
+
const kebab = kebabCase(name);
|
|
181
|
+
let componentName = kebab;
|
|
182
|
+
if (prefixKebab) {
|
|
183
|
+
if (!kebab.startsWith(`${prefixKebab}-`))
|
|
184
|
+
return;
|
|
185
|
+
componentName = kebab.slice(prefixKebab.length + 1);
|
|
186
|
+
}
|
|
187
|
+
for (const entry of kebabEntries) {
|
|
188
|
+
if (entry.kebab === componentName)
|
|
189
|
+
return { path: libraryName, importName: entry.name };
|
|
190
|
+
}
|
|
181
191
|
}
|
|
182
192
|
};
|
|
183
193
|
}
|
|
@@ -197,4 +207,5 @@ function LibraryResolver(options) {
|
|
|
197
207
|
|
|
198
208
|
|
|
199
209
|
|
|
200
|
-
|
|
210
|
+
|
|
211
|
+
exports.DISABLE_COMMENT = DISABLE_COMMENT; exports.pascalCase = pascalCase; exports.camelCase = camelCase; exports.kebabCase = kebabCase; exports.parseId = parseId; exports.matchGlobs = matchGlobs; exports.getTransformedPath = getTransformedPath; exports.stringifyComponentImport = stringifyComponentImport; exports.getNameFromFilePath = getNameFromFilePath; exports.resolveAlias = resolveAlias; exports.getPkgVersion = getPkgVersion; exports.shouldTransform = shouldTransform; exports.resolveImportPath = resolveImportPath; exports.tryLoadVeturTags = tryLoadVeturTags; exports.LibraryResolver = LibraryResolver;
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
var _chunkYBT6MD7Sjs = require('./chunk-YBT6MD7S.js');
|
|
12
11
|
|
|
12
|
+
var _chunkLWMWOXVQjs = require('./chunk-LWMWOXVQ.js');
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
|
|
@@ -49,11 +49,14 @@ var defaultOptions = {
|
|
|
49
49
|
importPathTransform: (v) => v,
|
|
50
50
|
allowOverrides: false
|
|
51
51
|
};
|
|
52
|
+
function normalizeResolvers(resolvers) {
|
|
53
|
+
return _utils.toArray.call(void 0, resolvers).flat().map((r) => typeof r === "function" ? { resolve: r, type: "component" } : r);
|
|
54
|
+
}
|
|
52
55
|
function resolveOptions(options, root) {
|
|
53
56
|
const resolved = Object.assign({}, defaultOptions, options);
|
|
54
57
|
resolved.libraries = _utils.toArray.call(void 0, resolved.libraries).map((i) => typeof i === "string" ? { name: i } : i);
|
|
55
|
-
resolved.resolvers =
|
|
56
|
-
resolved.resolvers.push(...resolved.libraries.map((lib) =>
|
|
58
|
+
resolved.resolvers = normalizeResolvers(resolved.resolvers);
|
|
59
|
+
resolved.resolvers.push(...resolved.libraries.map((lib) => _chunkLWMWOXVQjs.LibraryResolver.call(void 0, lib)));
|
|
57
60
|
resolved.extensions = _utils.toArray.call(void 0, resolved.extensions);
|
|
58
61
|
if (resolved.globs) {
|
|
59
62
|
resolved.globs = _utils.toArray.call(void 0, resolved.globs).map((glob) => _utils.slash.call(void 0, _path.resolve.call(void 0, root, glob)));
|
|
@@ -68,7 +71,7 @@ function resolveOptions(options, root) {
|
|
|
68
71
|
resolved.dts = !options.dts ? false : _path.resolve.call(void 0, root, typeof options.dts === "string" ? options.dts : "components.d.ts");
|
|
69
72
|
resolved.root = root;
|
|
70
73
|
resolved.transformer = options.transformer || getVueVersion() || "vue3";
|
|
71
|
-
resolved.directives = typeof options.directives === "boolean" ? options.directives : getVueVersion() === "vue3";
|
|
74
|
+
resolved.directives = typeof options.directives === "boolean" ? options.directives : !resolved.resolvers.some((i) => i.type === "directive") ? false : getVueVersion() === "vue3";
|
|
72
75
|
return resolved;
|
|
73
76
|
}
|
|
74
77
|
function getVueVersion() {
|
|
@@ -117,6 +120,7 @@ async function generateDeclaration(ctx, root, filepath) {
|
|
|
117
120
|
const imports = Object.fromEntries(Object.values(_chunk7T67WII5js.__spreadValues.call(void 0, _chunk7T67WII5js.__spreadValues.call(void 0, {}, ctx.componentNameMap), ctx.componentCustomMap)).map(({ path, name, importName }) => {
|
|
118
121
|
if (!name)
|
|
119
122
|
return void 0;
|
|
123
|
+
path = _chunkLWMWOXVQjs.getTransformedPath.call(void 0, path, ctx);
|
|
120
124
|
const related = _path.isAbsolute.call(void 0, path) ? `./${_path.relative.call(void 0, _path.dirname.call(void 0, filepath), path)}` : path;
|
|
121
125
|
let entry = `typeof import('${_utils.slash.call(void 0, related)}')`;
|
|
122
126
|
if (importName)
|
|
@@ -189,67 +193,141 @@ var resolveVue3 = (code, s) => {
|
|
|
189
193
|
}
|
|
190
194
|
return results;
|
|
191
195
|
};
|
|
192
|
-
|
|
196
|
+
async function transformComponent(code, transformer, s, ctx, sfcPath) {
|
|
193
197
|
let no = 0;
|
|
194
198
|
const results = transformer === "vue2" ? resolveVue2(code, s) : resolveVue3(code, s);
|
|
195
199
|
for (const { rawName, replace } of results) {
|
|
196
200
|
debug2(`| ${rawName}`);
|
|
197
|
-
const name =
|
|
201
|
+
const name = _chunkLWMWOXVQjs.pascalCase.call(void 0, rawName);
|
|
198
202
|
ctx.updateUsageMap(sfcPath, [name]);
|
|
199
203
|
const component = await ctx.findComponent(name, "component", [sfcPath]);
|
|
200
204
|
if (component) {
|
|
201
205
|
const varName = `__unplugin_components_${no}`;
|
|
202
|
-
s.prepend(`${
|
|
206
|
+
s.prepend(`${_chunkLWMWOXVQjs.stringifyComponentImport.call(void 0, _chunk7T67WII5js.__spreadProps.call(void 0, _chunk7T67WII5js.__spreadValues.call(void 0, {}, component), { name: varName }), ctx)};
|
|
203
207
|
`);
|
|
204
208
|
no += 1;
|
|
205
209
|
replace(varName);
|
|
206
210
|
}
|
|
207
211
|
}
|
|
208
212
|
debug2(`^ (${no})`);
|
|
209
|
-
}
|
|
213
|
+
}
|
|
210
214
|
|
|
211
215
|
// src/core/transforms/directive/index.ts
|
|
212
216
|
_chunk7T67WII5js.init_cjs_shims.call(void 0, );
|
|
213
217
|
|
|
218
|
+
|
|
219
|
+
// src/core/transforms/directive/vue2.ts
|
|
220
|
+
_chunk7T67WII5js.init_cjs_shims.call(void 0, );
|
|
221
|
+
|
|
222
|
+
var getRenderFnStart = (ast) => {
|
|
223
|
+
const renderFn = ast.program.body.find((node) => node.type === "VariableDeclaration" && node.declarations[0].id.type === "Identifier" && node.declarations[0].id.name === "render");
|
|
224
|
+
const start = (renderFn == null ? void 0 : renderFn.declarations[0].init).body.start;
|
|
225
|
+
if (start === null)
|
|
226
|
+
throw new Error("[unplugin-vue-components:directive] Cannot find render function position.");
|
|
227
|
+
return start + 1;
|
|
228
|
+
};
|
|
229
|
+
async function resolveVue22(code, s) {
|
|
230
|
+
var _a, _b;
|
|
231
|
+
if (!_localpkg.isPackageExists.call(void 0, "@babel/parser") || !_localpkg.isPackageExists.call(void 0, "@babel/traverse"))
|
|
232
|
+
throw new Error('[unplugin-vue-components:directive] To use Vue 2 directive you will need to install Babel first: "npm install -D @babel/parser @babel/traverse"');
|
|
233
|
+
const { parse } = await _localpkg.importModule.call(void 0, "@babel/parser");
|
|
234
|
+
const ast = parse(code, {
|
|
235
|
+
sourceType: "module"
|
|
236
|
+
});
|
|
237
|
+
const nodes = [];
|
|
238
|
+
const { default: traverse } = await _localpkg.importModule.call(void 0, "@babel/traverse");
|
|
239
|
+
traverse(ast, {
|
|
240
|
+
CallExpression(path) {
|
|
241
|
+
nodes.push(path.node);
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
const results = [];
|
|
245
|
+
for (const node of nodes) {
|
|
246
|
+
const { callee, arguments: args } = node;
|
|
247
|
+
if (callee.type !== "Identifier" || callee.name !== "_c" || args[1].type !== "ObjectExpression")
|
|
248
|
+
continue;
|
|
249
|
+
const directives = (_a = args[1].properties.find((property) => property.type === "ObjectProperty" && property.key.type === "Identifier" && property.key.name === "directives")) == null ? void 0 : _a.value;
|
|
250
|
+
if (!directives || directives.type !== "ArrayExpression")
|
|
251
|
+
continue;
|
|
252
|
+
const renderStart = getRenderFnStart(ast);
|
|
253
|
+
for (const directive of directives.elements) {
|
|
254
|
+
if ((directive == null ? void 0 : directive.type) !== "ObjectExpression")
|
|
255
|
+
continue;
|
|
256
|
+
const nameNode = (_b = directive.properties.find((p) => p.type === "ObjectProperty" && p.key.type === "Identifier" && p.key.name === "name")) == null ? void 0 : _b.value;
|
|
257
|
+
if ((nameNode == null ? void 0 : nameNode.type) !== "StringLiteral")
|
|
258
|
+
continue;
|
|
259
|
+
const name = nameNode.value;
|
|
260
|
+
if (!name || name.startsWith("_"))
|
|
261
|
+
continue;
|
|
262
|
+
results.push({
|
|
263
|
+
rawName: name,
|
|
264
|
+
replace: (resolved) => {
|
|
265
|
+
s.prependLeft(renderStart, `
|
|
266
|
+
this.$options.directives["${name}"] = ${resolved};`);
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
return results;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// src/core/transforms/directive/vue3.ts
|
|
275
|
+
_chunk7T67WII5js.init_cjs_shims.call(void 0, );
|
|
276
|
+
function resolveVue32(code, s) {
|
|
277
|
+
const results = [];
|
|
278
|
+
for (const match of code.matchAll(/_resolveDirective\("(.+?)"\)/g)) {
|
|
279
|
+
const matchedName = match[1];
|
|
280
|
+
if (match.index != null && matchedName && !matchedName.startsWith("_")) {
|
|
281
|
+
const start = match.index;
|
|
282
|
+
const end = start + match[0].length;
|
|
283
|
+
results.push({
|
|
284
|
+
rawName: matchedName,
|
|
285
|
+
replace: (resolved) => s.overwrite(start, end, resolved)
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
return results;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// src/core/transforms/directive/index.ts
|
|
214
293
|
var debug3 = _debug2.default.call(void 0, "unplugin-vue-components:transform:directive");
|
|
215
|
-
|
|
294
|
+
async function transformDirective(code, transformer, s, ctx, sfcPath) {
|
|
216
295
|
let no = 0;
|
|
217
|
-
const
|
|
218
|
-
const results = resolve3(code, s);
|
|
296
|
+
const results = await (transformer === "vue2" ? resolveVue22(code, s) : resolveVue32(code, s));
|
|
219
297
|
for (const { rawName, replace } of results) {
|
|
220
298
|
debug3(`| ${rawName}`);
|
|
221
|
-
const name =
|
|
299
|
+
const name = _chunkLWMWOXVQjs.pascalCase.call(void 0, rawName);
|
|
222
300
|
ctx.updateUsageMap(sfcPath, [name]);
|
|
223
301
|
const directive = await ctx.findComponent(name, "directive", [sfcPath]);
|
|
224
302
|
if (!directive)
|
|
225
303
|
continue;
|
|
226
304
|
const varName = `__unplugin_directives_${no}`;
|
|
227
|
-
s.prepend(`${
|
|
305
|
+
s.prepend(`${_chunkLWMWOXVQjs.stringifyComponentImport.call(void 0, _chunk7T67WII5js.__spreadProps.call(void 0, _chunk7T67WII5js.__spreadValues.call(void 0, {}, directive), { name: varName }), ctx)};
|
|
228
306
|
`);
|
|
229
307
|
no += 1;
|
|
230
308
|
replace(varName);
|
|
231
309
|
}
|
|
232
310
|
debug3(`^ (${no})`);
|
|
233
|
-
}
|
|
311
|
+
}
|
|
234
312
|
|
|
235
313
|
// src/core/transformer.ts
|
|
236
314
|
var debug4 = _debug2.default.call(void 0, "unplugin-vue-components:transformer");
|
|
237
|
-
|
|
315
|
+
function tranformer(ctx, transformer) {
|
|
238
316
|
return async (code, id, path) => {
|
|
239
317
|
ctx.searchGlob();
|
|
240
318
|
const sfcPath = ctx.normalizePath(path);
|
|
241
319
|
debug4(sfcPath);
|
|
242
320
|
const s = new (0, _magicstring2.default)(code);
|
|
243
|
-
await
|
|
321
|
+
await transformComponent(code, transformer, s, ctx, sfcPath);
|
|
244
322
|
if (ctx.options.directives)
|
|
245
|
-
await
|
|
246
|
-
s.prepend(
|
|
323
|
+
await transformDirective(code, transformer, s, ctx, sfcPath);
|
|
324
|
+
s.prepend(_chunkLWMWOXVQjs.DISABLE_COMMENT);
|
|
247
325
|
const result = { code: s.toString() };
|
|
248
326
|
if (ctx.sourcemap)
|
|
249
327
|
result.map = s.generateMap({ source: id, includeContent: true });
|
|
250
328
|
return result;
|
|
251
329
|
};
|
|
252
|
-
}
|
|
330
|
+
}
|
|
253
331
|
|
|
254
332
|
// src/core/context.ts
|
|
255
333
|
var debug5 = {
|
|
@@ -284,10 +362,10 @@ var Context = class {
|
|
|
284
362
|
}
|
|
285
363
|
setTransformer(name) {
|
|
286
364
|
debug5.env("transformer", name);
|
|
287
|
-
this.transformer =
|
|
365
|
+
this.transformer = tranformer(this, name || "vue3");
|
|
288
366
|
}
|
|
289
367
|
transform(code, id) {
|
|
290
|
-
const { path, query } =
|
|
368
|
+
const { path, query } = _chunkLWMWOXVQjs.parseId.call(void 0, id);
|
|
291
369
|
return this.transformer(code, id, path, query);
|
|
292
370
|
}
|
|
293
371
|
setupViteServer(server) {
|
|
@@ -299,13 +377,13 @@ var Context = class {
|
|
|
299
377
|
setupWatcher(watcher) {
|
|
300
378
|
const { globs } = this.options;
|
|
301
379
|
watcher.on("unlink", (path) => {
|
|
302
|
-
if (!
|
|
380
|
+
if (!_chunkLWMWOXVQjs.matchGlobs.call(void 0, path, globs))
|
|
303
381
|
return;
|
|
304
382
|
this.removeComponents(path);
|
|
305
383
|
this.onUpdate(path);
|
|
306
384
|
});
|
|
307
385
|
watcher.on("add", (path) => {
|
|
308
|
-
if (!
|
|
386
|
+
if (!_chunkLWMWOXVQjs.matchGlobs.call(void 0, path, globs))
|
|
309
387
|
return;
|
|
310
388
|
this.addComponents(path);
|
|
311
389
|
this.onUpdate(path);
|
|
@@ -351,7 +429,7 @@ var Context = class {
|
|
|
351
429
|
updates: []
|
|
352
430
|
};
|
|
353
431
|
const timestamp = +new Date();
|
|
354
|
-
const name =
|
|
432
|
+
const name = _chunkLWMWOXVQjs.pascalCase.call(void 0, _chunkLWMWOXVQjs.getNameFromFilePath.call(void 0, path, this.options));
|
|
355
433
|
Object.entries(this._componentUsageMap).forEach(([key, values]) => {
|
|
356
434
|
if (values.has(name)) {
|
|
357
435
|
const r = `/${_utils.slash.call(void 0, _path.relative.call(void 0, this.root, key))}`;
|
|
@@ -369,7 +447,7 @@ var Context = class {
|
|
|
369
447
|
updateComponentNameMap() {
|
|
370
448
|
this._componentNameMap = {};
|
|
371
449
|
Array.from(this._componentPaths).forEach((path) => {
|
|
372
|
-
const name =
|
|
450
|
+
const name = _chunkLWMWOXVQjs.pascalCase.call(void 0, _chunkLWMWOXVQjs.getNameFromFilePath.call(void 0, path, this.options));
|
|
373
451
|
if (this._componentNameMap[name] && !this.options.allowOverrides) {
|
|
374
452
|
console.warn(`[unplugin-vue-components] component "${name}"(${path}) has naming conflicts with other components, ignored.`);
|
|
375
453
|
return;
|
|
@@ -385,7 +463,9 @@ var Context = class {
|
|
|
385
463
|
if (info && !excludePaths.includes(info.path) && !excludePaths.includes(info.path.slice(1)))
|
|
386
464
|
return info;
|
|
387
465
|
for (const resolver of this.options.resolvers) {
|
|
388
|
-
|
|
466
|
+
if (resolver.type !== type)
|
|
467
|
+
continue;
|
|
468
|
+
const result = await resolver.resolve(name);
|
|
389
469
|
if (result) {
|
|
390
470
|
if (typeof result === "string") {
|
|
391
471
|
info = {
|
|
@@ -407,7 +487,7 @@ var Context = class {
|
|
|
407
487
|
}
|
|
408
488
|
normalizePath(path) {
|
|
409
489
|
var _a, _b, _c;
|
|
410
|
-
return
|
|
490
|
+
return _chunkLWMWOXVQjs.resolveAlias.call(void 0, path, ((_b = (_a = this.viteConfig) == null ? void 0 : _a.resolve) == null ? void 0 : _b.alias) || ((_c = this.viteConfig) == null ? void 0 : _c.alias) || []);
|
|
411
491
|
}
|
|
412
492
|
relative(path) {
|
|
413
493
|
if (path.startsWith("/") && !path.startsWith(this.root))
|
|
@@ -446,7 +526,7 @@ var unplugin_default = _unplugin.createUnplugin.call(void 0, (options = {}) => {
|
|
|
446
526
|
return filter(id);
|
|
447
527
|
},
|
|
448
528
|
async transform(code, id) {
|
|
449
|
-
if (!
|
|
529
|
+
if (!_chunkLWMWOXVQjs.shouldTransform.call(void 0, code))
|
|
450
530
|
return null;
|
|
451
531
|
try {
|
|
452
532
|
const result = await ctx.transform(code, id);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Options } from './types';
|
|
2
|
-
export { ComponentInfo, ComponentResolveResult, ComponentResolver, ComponentsImportMap, ImportInfo, Matcher, Options, ResolvedOptions, SideEffectsInfo, SupportedTransformer, Transformer, UILibraryOptions } from './types';
|
|
2
|
+
export { ComponentInfo, ComponentResolveResult, ComponentResolver, ComponentResolverFunction, ComponentResolverObject, ComponentsImportMap, ImportInfo, Matcher, Options, ResolvedOptions, SideEffectsInfo, SupportedTransformer, Transformer, UILibraryOptions } from './types';
|
|
3
3
|
import * as unplugin from 'unplugin';
|
|
4
4
|
import '@rollup/pluginutils';
|
|
5
5
|
import '@antfu/utils';
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkSFAP23Y4js = require('./chunk-SFAP23Y4.js');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _chunkLWMWOXVQjs = require('./chunk-LWMWOXVQ.js');
|
|
9
9
|
require('./chunk-LKFHSEPW.js');
|
|
10
10
|
require('./chunk-7T67WII5.js');
|
|
11
11
|
|
|
@@ -13,4 +13,4 @@ require('./chunk-7T67WII5.js');
|
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
|
|
16
|
-
exports.camelCase =
|
|
16
|
+
exports.camelCase = _chunkLWMWOXVQjs.camelCase; exports.default = _chunkSFAP23Y4js.unplugin_default; exports.kebabCase = _chunkLWMWOXVQjs.kebabCase; exports.pascalCase = _chunkLWMWOXVQjs.pascalCase;
|