unplugin-vue-components 0.21.0 → 0.22.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 +6 -4
- package/dist/chunk-AKU6F3WT.mjs +11 -0
- package/dist/chunk-EZUCZHGV.js +11 -0
- package/dist/{chunk-VM6XO3CV.js → chunk-HTGYYKG5.js} +52 -28
- package/dist/{chunk-3PQFLYJJ.mjs → chunk-L5GWKUOR.mjs} +51 -27
- package/dist/esbuild.js +3 -3
- package/dist/esbuild.mjs +2 -2
- 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 +23 -2
- package/dist/resolvers.js +138 -61
- package/dist/resolvers.mjs +138 -61
- package/dist/rollup.js +3 -3
- package/dist/rollup.mjs +2 -2
- package/dist/{src-4OAWGTJE.js → src-KKLCUN63.js} +1 -1
- package/dist/{src-WRIQ2NEL.mjs → src-Z5BCFXFD.mjs} +1 -1
- 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 +14 -14
- package/dist/chunk-BTQOTIPQ.js +0 -32
- package/dist/chunk-ZKNUHGJ4.mjs +0 -32
package/README.md
CHANGED
|
@@ -176,7 +176,7 @@ Components({
|
|
|
176
176
|
|
|
177
177
|
Once the setup is done, a `components.d.ts` will be generated and updates automatically with the type definitions. Feel free to commit it into git or not as you want.
|
|
178
178
|
|
|
179
|
-
> **Make sure you also add `components.d.ts` to your `tsconfig.json` under `
|
|
179
|
+
> **Make sure you also add `components.d.ts` to your `tsconfig.json` under `include`.**
|
|
180
180
|
|
|
181
181
|
## Importing from UI Libraries
|
|
182
182
|
|
|
@@ -186,6 +186,7 @@ Supported Resolvers:
|
|
|
186
186
|
|
|
187
187
|
- [Ant Design Vue](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/antdv.ts)
|
|
188
188
|
- [Arco Design Vue](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/arco.ts)
|
|
189
|
+
- [BootstrapVue](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/bootstrap-vue.ts)
|
|
189
190
|
- [Element Plus](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/element-plus.ts)
|
|
190
191
|
- [Element UI](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/element-ui.ts)
|
|
191
192
|
- [Headless UI](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/headless-ui.ts)
|
|
@@ -193,14 +194,15 @@ Supported Resolvers:
|
|
|
193
194
|
- [Inkline](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/inkline.ts)
|
|
194
195
|
- [Naive UI](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/naive-ui.ts)
|
|
195
196
|
- [Prime Vue](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/prime-vue.ts)
|
|
197
|
+
- [Quasar](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/quasar.ts)
|
|
198
|
+
- [TDesign](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/tdesign.ts)
|
|
196
199
|
- [Vant](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/vant.ts)
|
|
197
|
-
- [VEUI](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/veui.ts)
|
|
198
200
|
- [Varlet UI](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/varlet-ui.ts)
|
|
201
|
+
- [VEUI](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/veui.ts)
|
|
199
202
|
- [View UI](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/view-ui.ts)
|
|
200
203
|
- [Vuetify](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/vuetify.ts)
|
|
201
204
|
- [VueUse Components](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/vueuse.ts)
|
|
202
|
-
- [
|
|
203
|
-
- [TDesign](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/tdesign.ts)
|
|
205
|
+
- [Dev UI](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/devui.ts)
|
|
204
206
|
|
|
205
207
|
```ts
|
|
206
208
|
// vite.config.js
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
+
}) : x)(function(x) {
|
|
4
|
+
if (typeof require !== "undefined")
|
|
5
|
+
return require.apply(this, arguments);
|
|
6
|
+
throw new Error('Dynamic require of "' + x + '" is not supported');
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
export {
|
|
10
|
+
__require
|
|
11
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
+
}) : x)(function(x) {
|
|
4
|
+
if (typeof require !== "undefined")
|
|
5
|
+
return require.apply(this, arguments);
|
|
6
|
+
throw new Error('Dynamic require of "' + x + '" is not supported');
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
exports.__require = __require;
|
|
@@ -13,11 +13,10 @@
|
|
|
13
13
|
var _chunk2GXY7E6Xjs = require('./chunk-2GXY7E6X.js');
|
|
14
14
|
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
var _chunkBTQOTIPQjs = require('./chunk-BTQOTIPQ.js');
|
|
16
|
+
var _chunkEZUCZHGVjs = require('./chunk-EZUCZHGV.js');
|
|
19
17
|
|
|
20
18
|
// src/core/unplugin.ts
|
|
19
|
+
var _fs = require('fs');
|
|
21
20
|
var _unplugin = require('unplugin');
|
|
22
21
|
var _pluginutils = require('@rollup/pluginutils');
|
|
23
22
|
var _chokidar = require('chokidar'); var _chokidar2 = _interopRequireDefault(_chokidar);
|
|
@@ -69,6 +68,7 @@ var defaultOptions = {
|
|
|
69
68
|
deep: true,
|
|
70
69
|
dts: _localpkg.isPackageExists.call(void 0, "typescript"),
|
|
71
70
|
directoryAsNamespace: false,
|
|
71
|
+
collapseSamePrefixes: false,
|
|
72
72
|
globalNamespaces: [],
|
|
73
73
|
resolvers: [],
|
|
74
74
|
importPathTransform: (v) => v,
|
|
@@ -88,11 +88,16 @@ function resolveOptions(options, root) {
|
|
|
88
88
|
const extsGlob = resolved.extensions.length === 1 ? resolved.extensions : `{${resolved.extensions.join(",")}}`;
|
|
89
89
|
resolved.dirs = _utils.toArray.call(void 0, resolved.dirs);
|
|
90
90
|
resolved.resolvedDirs = resolved.dirs.map((i) => _utils.slash.call(void 0, _path.resolve.call(void 0, root, i)));
|
|
91
|
-
resolved.globs = resolved.resolvedDirs.map(
|
|
91
|
+
resolved.globs = resolved.resolvedDirs.map(
|
|
92
|
+
(i) => resolved.deep ? _utils.slash.call(void 0, _path.join.call(void 0, i, `**/*.${extsGlob}`)) : _utils.slash.call(void 0, _path.join.call(void 0, i, `*.${extsGlob}`))
|
|
93
|
+
);
|
|
92
94
|
if (!resolved.extensions.length)
|
|
93
95
|
throw new Error("[unplugin-vue-components] `extensions` option is required to search for components");
|
|
94
96
|
}
|
|
95
|
-
resolved.dts = !resolved.dts ? false : _path.resolve.call(void 0,
|
|
97
|
+
resolved.dts = !resolved.dts ? false : _path.resolve.call(void 0,
|
|
98
|
+
root,
|
|
99
|
+
typeof resolved.dts === "string" ? resolved.dts : "components.d.ts"
|
|
100
|
+
);
|
|
96
101
|
if (!resolved.types && resolved.dts)
|
|
97
102
|
resolved.types = detectTypeImports();
|
|
98
103
|
resolved.types = resolved.types || [];
|
|
@@ -104,7 +109,7 @@ function resolveOptions(options, root) {
|
|
|
104
109
|
function getVueVersion() {
|
|
105
110
|
var _a;
|
|
106
111
|
try {
|
|
107
|
-
const vue =
|
|
112
|
+
const vue = _chunkEZUCZHGVjs.__require.call(void 0, "vue");
|
|
108
113
|
const version = ((_a = vue == null ? void 0 : vue.default) == null ? void 0 : _a.version) || (vue == null ? void 0 : vue.version) || "3";
|
|
109
114
|
return version.startsWith("2.") ? "vue2" : "vue3";
|
|
110
115
|
} catch (e2) {
|
|
@@ -134,13 +139,13 @@ function searchComponents(ctx) {
|
|
|
134
139
|
|
|
135
140
|
// src/core/declaration.ts
|
|
136
141
|
|
|
137
|
-
|
|
142
|
+
|
|
138
143
|
var _promises = require('fs/promises');
|
|
139
144
|
|
|
140
145
|
var multilineCommentsRE = /\/\*.*?\*\//gms;
|
|
141
146
|
var singlelineCommentsRE = /\/\/.*$/gm;
|
|
142
147
|
function extractImports(code) {
|
|
143
|
-
return Object.fromEntries(Array.from(code.matchAll(/['"]?([
|
|
148
|
+
return Object.fromEntries(Array.from(code.matchAll(/['"]?([^\s'"]+)['"]?\s*:\s*(.+?)[,;\n]/g)).map((i) => [i[1], i[2]]));
|
|
144
149
|
}
|
|
145
150
|
function parseDeclaration(code) {
|
|
146
151
|
var _a, _b;
|
|
@@ -168,14 +173,23 @@ function stringifyComponentInfo(filepath, { from: path, as: name, name: importNa
|
|
|
168
173
|
return [name, entry];
|
|
169
174
|
}
|
|
170
175
|
function stringifyComponentsInfo(filepath, components, importPathTransform) {
|
|
171
|
-
return Object.fromEntries(
|
|
176
|
+
return Object.fromEntries(
|
|
177
|
+
components.map((info) => stringifyComponentInfo(filepath, info, importPathTransform)).filter(_utils.notNullish)
|
|
178
|
+
);
|
|
172
179
|
}
|
|
173
180
|
function getDeclarationImports(ctx, filepath) {
|
|
174
181
|
const component = stringifyComponentsInfo(filepath, [
|
|
175
|
-
...Object.values(
|
|
182
|
+
...Object.values({
|
|
183
|
+
...ctx.componentNameMap,
|
|
184
|
+
...ctx.componentCustomMap
|
|
185
|
+
}),
|
|
176
186
|
...resolveTypeImports(ctx.options.types)
|
|
177
187
|
], ctx.options.importPathTransform);
|
|
178
|
-
const directive = stringifyComponentsInfo(
|
|
188
|
+
const directive = stringifyComponentsInfo(
|
|
189
|
+
filepath,
|
|
190
|
+
Object.values(ctx.directiveCustomMap),
|
|
191
|
+
ctx.options.importPathTransform
|
|
192
|
+
);
|
|
179
193
|
if (Object.keys(component).length + Object.keys(directive).length === 0)
|
|
180
194
|
return;
|
|
181
195
|
return { component, directive };
|
|
@@ -192,8 +206,8 @@ function getDeclaration(ctx, filepath, originalImports) {
|
|
|
192
206
|
if (!imports)
|
|
193
207
|
return;
|
|
194
208
|
const declarations = {
|
|
195
|
-
component: stringifyDeclarationImports(
|
|
196
|
-
directive: stringifyDeclarationImports(
|
|
209
|
+
component: stringifyDeclarationImports({ ...originalImports == null ? void 0 : originalImports.component, ...imports.component }),
|
|
210
|
+
directive: stringifyDeclarationImports({ ...originalImports == null ? void 0 : originalImports.directive, ...imports.directive })
|
|
197
211
|
};
|
|
198
212
|
let code = `// generated by unplugin-vue-components
|
|
199
213
|
// We suggest you to commit this file into source control
|
|
@@ -207,8 +221,7 @@ declare module '@vue/runtime-core' {`;
|
|
|
207
221
|
code += `
|
|
208
222
|
export interface GlobalComponents {
|
|
209
223
|
${declarations.component.join("\n ")}
|
|
210
|
-
}
|
|
211
|
-
`;
|
|
224
|
+
}`;
|
|
212
225
|
}
|
|
213
226
|
if (Object.keys(declarations.directive).length > 0) {
|
|
214
227
|
code += `
|
|
@@ -253,7 +266,7 @@ var resolveVue2 = (code, s) => {
|
|
|
253
266
|
};
|
|
254
267
|
var resolveVue3 = (code, s) => {
|
|
255
268
|
const results = [];
|
|
256
|
-
for (const match of code.matchAll(/_resolveComponent
|
|
269
|
+
for (const match of code.matchAll(/_resolveComponent[0-9]*\("(.+?)"\)/g)) {
|
|
257
270
|
const matchedName = match[1];
|
|
258
271
|
if (match.index != null && matchedName && !matchedName.startsWith("_")) {
|
|
259
272
|
const start = match.index;
|
|
@@ -276,7 +289,7 @@ async function transformComponent(code, transformer2, s, ctx, sfcPath) {
|
|
|
276
289
|
const component = await ctx.findComponent(name, "component", [sfcPath]);
|
|
277
290
|
if (component) {
|
|
278
291
|
const varName = `__unplugin_components_${no}`;
|
|
279
|
-
s.prepend(`${_chunk2GXY7E6Xjs.stringifyComponentImport.call(void 0,
|
|
292
|
+
s.prepend(`${_chunk2GXY7E6Xjs.stringifyComponentImport.call(void 0, { ...component, as: varName }, ctx)};
|
|
280
293
|
`);
|
|
281
294
|
no += 1;
|
|
282
295
|
replace(varName);
|
|
@@ -292,7 +305,9 @@ async function transformComponent(code, transformer2, s, ctx, sfcPath) {
|
|
|
292
305
|
|
|
293
306
|
var getRenderFnStart = (ast) => {
|
|
294
307
|
var _a, _b;
|
|
295
|
-
const renderFn = ast.program.body.find(
|
|
308
|
+
const renderFn = ast.program.body.find(
|
|
309
|
+
(node) => node.type === "VariableDeclaration" && node.declarations[0].id.type === "Identifier" && node.declarations[0].id.name === "render"
|
|
310
|
+
);
|
|
296
311
|
const start = (_b = (_a = renderFn == null ? void 0 : renderFn.declarations[0].init) == null ? void 0 : _a.body) == null ? void 0 : _b.start;
|
|
297
312
|
if (start === null || start === void 0)
|
|
298
313
|
throw new Error("[unplugin-vue-components:directive] Cannot find render function position.");
|
|
@@ -307,7 +322,7 @@ async function resolveVue22(code, s) {
|
|
|
307
322
|
sourceType: "module"
|
|
308
323
|
});
|
|
309
324
|
const nodes = [];
|
|
310
|
-
const { walk } = await Promise.resolve().then(() => require("./src-
|
|
325
|
+
const { walk } = await Promise.resolve().then(() => require("./src-KKLCUN63.js"));
|
|
311
326
|
walk(ast.program, {
|
|
312
327
|
enter(node) {
|
|
313
328
|
if (node.type === "CallExpression")
|
|
@@ -319,14 +334,18 @@ async function resolveVue22(code, s) {
|
|
|
319
334
|
const { callee, arguments: args } = node;
|
|
320
335
|
if (callee.type !== "Identifier" || callee.name !== "_c" || ((_a = args[1]) == null ? void 0 : _a.type) !== "ObjectExpression")
|
|
321
336
|
continue;
|
|
322
|
-
const directives = (_b = args[1].properties.find(
|
|
337
|
+
const directives = (_b = args[1].properties.find(
|
|
338
|
+
(property) => property.type === "ObjectProperty" && property.key.type === "Identifier" && property.key.name === "directives"
|
|
339
|
+
)) == null ? void 0 : _b.value;
|
|
323
340
|
if (!directives || directives.type !== "ArrayExpression")
|
|
324
341
|
continue;
|
|
325
342
|
const renderStart = getRenderFnStart(ast);
|
|
326
343
|
for (const directive of directives.elements) {
|
|
327
344
|
if ((directive == null ? void 0 : directive.type) !== "ObjectExpression")
|
|
328
345
|
continue;
|
|
329
|
-
const nameNode = (_c = directive.properties.find(
|
|
346
|
+
const nameNode = (_c = directive.properties.find(
|
|
347
|
+
(p) => p.type === "ObjectProperty" && p.key.type === "Identifier" && p.key.name === "name"
|
|
348
|
+
)) == null ? void 0 : _c.value;
|
|
330
349
|
if ((nameNode == null ? void 0 : nameNode.type) !== "StringLiteral")
|
|
331
350
|
continue;
|
|
332
351
|
const name = nameNode.value;
|
|
@@ -374,7 +393,7 @@ async function transformDirective(code, transformer2, s, ctx, sfcPath) {
|
|
|
374
393
|
if (!directive)
|
|
375
394
|
continue;
|
|
376
395
|
const varName = `__unplugin_directives_${no}`;
|
|
377
|
-
s.prepend(`${_chunk2GXY7E6Xjs.stringifyComponentImport.call(void 0,
|
|
396
|
+
s.prepend(`${_chunk2GXY7E6Xjs.stringifyComponentImport.call(void 0, { ...directive, as: varName }, ctx)};
|
|
378
397
|
`);
|
|
379
398
|
no += 1;
|
|
380
399
|
replace(varName);
|
|
@@ -570,9 +589,10 @@ var Context = class {
|
|
|
570
589
|
from: result
|
|
571
590
|
};
|
|
572
591
|
} else {
|
|
573
|
-
info =
|
|
574
|
-
as: name
|
|
575
|
-
|
|
592
|
+
info = {
|
|
593
|
+
as: name,
|
|
594
|
+
..._chunk2GXY7E6Xjs.normalizeComponetInfo.call(void 0, result)
|
|
595
|
+
};
|
|
576
596
|
}
|
|
577
597
|
if (type === "component")
|
|
578
598
|
this.addCustomComponents(info);
|
|
@@ -618,7 +638,10 @@ var Context = class {
|
|
|
618
638
|
// src/core/unplugin.ts
|
|
619
639
|
var PLUGIN_NAME = "unplugin:webpack";
|
|
620
640
|
var unplugin_default = _unplugin.createUnplugin.call(void 0, (options = {}) => {
|
|
621
|
-
const filter = _pluginutils.createFilter.call(void 0,
|
|
641
|
+
const filter = _pluginutils.createFilter.call(void 0,
|
|
642
|
+
options.include || [/\.vue$/, /\.vue\?vue/],
|
|
643
|
+
options.exclude || [/[\\/]node_modules[\\/]/, /[\\/]\.git[\\/]/, /[\\/]\.nuxt[\\/]/]
|
|
644
|
+
);
|
|
622
645
|
const ctx = new Context(options);
|
|
623
646
|
const api = {
|
|
624
647
|
async findComponent(name, filename) {
|
|
@@ -652,9 +675,10 @@ var unplugin_default = _unplugin.createUnplugin.call(void 0, (options = {}) => {
|
|
|
652
675
|
ctx.sourcemap = true;
|
|
653
676
|
if (config.plugins.find((i) => i.name === "vite-plugin-vue2"))
|
|
654
677
|
ctx.setTransformer("vue2");
|
|
655
|
-
if (options.dts) {
|
|
678
|
+
if (ctx.options.dts) {
|
|
656
679
|
ctx.searchGlob();
|
|
657
|
-
ctx.
|
|
680
|
+
if (!_fs.existsSync.call(void 0, ctx.options.dts))
|
|
681
|
+
ctx.generateDeclaration();
|
|
658
682
|
}
|
|
659
683
|
if (config.build.watch && config.command === "build")
|
|
660
684
|
ctx.setupWatcher(_chokidar2.default.watch(ctx.options.globs));
|
|
@@ -12,12 +12,11 @@ import {
|
|
|
12
12
|
stringifyComponentImport
|
|
13
13
|
} from "./chunk-667B3WUW.mjs";
|
|
14
14
|
import {
|
|
15
|
-
__require
|
|
16
|
-
|
|
17
|
-
__spreadValues
|
|
18
|
-
} from "./chunk-ZKNUHGJ4.mjs";
|
|
15
|
+
__require
|
|
16
|
+
} from "./chunk-AKU6F3WT.mjs";
|
|
19
17
|
|
|
20
18
|
// src/core/unplugin.ts
|
|
19
|
+
import { existsSync as existsSync2 } from "fs";
|
|
21
20
|
import { createUnplugin } from "unplugin";
|
|
22
21
|
import { createFilter } from "@rollup/pluginutils";
|
|
23
22
|
import chokidar from "chokidar";
|
|
@@ -69,6 +68,7 @@ var defaultOptions = {
|
|
|
69
68
|
deep: true,
|
|
70
69
|
dts: isPackageExists2("typescript"),
|
|
71
70
|
directoryAsNamespace: false,
|
|
71
|
+
collapseSamePrefixes: false,
|
|
72
72
|
globalNamespaces: [],
|
|
73
73
|
resolvers: [],
|
|
74
74
|
importPathTransform: (v) => v,
|
|
@@ -88,11 +88,16 @@ function resolveOptions(options, root) {
|
|
|
88
88
|
const extsGlob = resolved.extensions.length === 1 ? resolved.extensions : `{${resolved.extensions.join(",")}}`;
|
|
89
89
|
resolved.dirs = toArray(resolved.dirs);
|
|
90
90
|
resolved.resolvedDirs = resolved.dirs.map((i) => slash(resolve(root, i)));
|
|
91
|
-
resolved.globs = resolved.resolvedDirs.map(
|
|
91
|
+
resolved.globs = resolved.resolvedDirs.map(
|
|
92
|
+
(i) => resolved.deep ? slash(join(i, `**/*.${extsGlob}`)) : slash(join(i, `*.${extsGlob}`))
|
|
93
|
+
);
|
|
92
94
|
if (!resolved.extensions.length)
|
|
93
95
|
throw new Error("[unplugin-vue-components] `extensions` option is required to search for components");
|
|
94
96
|
}
|
|
95
|
-
resolved.dts = !resolved.dts ? false : resolve(
|
|
97
|
+
resolved.dts = !resolved.dts ? false : resolve(
|
|
98
|
+
root,
|
|
99
|
+
typeof resolved.dts === "string" ? resolved.dts : "components.d.ts"
|
|
100
|
+
);
|
|
96
101
|
if (!resolved.types && resolved.dts)
|
|
97
102
|
resolved.types = detectTypeImports();
|
|
98
103
|
resolved.types = resolved.types || [];
|
|
@@ -140,7 +145,7 @@ import { notNullish as notNullish2, slash as slash2 } from "@antfu/utils";
|
|
|
140
145
|
var multilineCommentsRE = /\/\*.*?\*\//gms;
|
|
141
146
|
var singlelineCommentsRE = /\/\/.*$/gm;
|
|
142
147
|
function extractImports(code) {
|
|
143
|
-
return Object.fromEntries(Array.from(code.matchAll(/['"]?([
|
|
148
|
+
return Object.fromEntries(Array.from(code.matchAll(/['"]?([^\s'"]+)['"]?\s*:\s*(.+?)[,;\n]/g)).map((i) => [i[1], i[2]]));
|
|
144
149
|
}
|
|
145
150
|
function parseDeclaration(code) {
|
|
146
151
|
var _a, _b;
|
|
@@ -168,14 +173,23 @@ function stringifyComponentInfo(filepath, { from: path, as: name, name: importNa
|
|
|
168
173
|
return [name, entry];
|
|
169
174
|
}
|
|
170
175
|
function stringifyComponentsInfo(filepath, components, importPathTransform) {
|
|
171
|
-
return Object.fromEntries(
|
|
176
|
+
return Object.fromEntries(
|
|
177
|
+
components.map((info) => stringifyComponentInfo(filepath, info, importPathTransform)).filter(notNullish2)
|
|
178
|
+
);
|
|
172
179
|
}
|
|
173
180
|
function getDeclarationImports(ctx, filepath) {
|
|
174
181
|
const component = stringifyComponentsInfo(filepath, [
|
|
175
|
-
...Object.values(
|
|
182
|
+
...Object.values({
|
|
183
|
+
...ctx.componentNameMap,
|
|
184
|
+
...ctx.componentCustomMap
|
|
185
|
+
}),
|
|
176
186
|
...resolveTypeImports(ctx.options.types)
|
|
177
187
|
], ctx.options.importPathTransform);
|
|
178
|
-
const directive = stringifyComponentsInfo(
|
|
188
|
+
const directive = stringifyComponentsInfo(
|
|
189
|
+
filepath,
|
|
190
|
+
Object.values(ctx.directiveCustomMap),
|
|
191
|
+
ctx.options.importPathTransform
|
|
192
|
+
);
|
|
179
193
|
if (Object.keys(component).length + Object.keys(directive).length === 0)
|
|
180
194
|
return;
|
|
181
195
|
return { component, directive };
|
|
@@ -192,8 +206,8 @@ function getDeclaration(ctx, filepath, originalImports) {
|
|
|
192
206
|
if (!imports)
|
|
193
207
|
return;
|
|
194
208
|
const declarations = {
|
|
195
|
-
component: stringifyDeclarationImports(
|
|
196
|
-
directive: stringifyDeclarationImports(
|
|
209
|
+
component: stringifyDeclarationImports({ ...originalImports == null ? void 0 : originalImports.component, ...imports.component }),
|
|
210
|
+
directive: stringifyDeclarationImports({ ...originalImports == null ? void 0 : originalImports.directive, ...imports.directive })
|
|
197
211
|
};
|
|
198
212
|
let code = `// generated by unplugin-vue-components
|
|
199
213
|
// We suggest you to commit this file into source control
|
|
@@ -207,8 +221,7 @@ declare module '@vue/runtime-core' {`;
|
|
|
207
221
|
code += `
|
|
208
222
|
export interface GlobalComponents {
|
|
209
223
|
${declarations.component.join("\n ")}
|
|
210
|
-
}
|
|
211
|
-
`;
|
|
224
|
+
}`;
|
|
212
225
|
}
|
|
213
226
|
if (Object.keys(declarations.directive).length > 0) {
|
|
214
227
|
code += `
|
|
@@ -253,7 +266,7 @@ var resolveVue2 = (code, s) => {
|
|
|
253
266
|
};
|
|
254
267
|
var resolveVue3 = (code, s) => {
|
|
255
268
|
const results = [];
|
|
256
|
-
for (const match of code.matchAll(/_resolveComponent
|
|
269
|
+
for (const match of code.matchAll(/_resolveComponent[0-9]*\("(.+?)"\)/g)) {
|
|
257
270
|
const matchedName = match[1];
|
|
258
271
|
if (match.index != null && matchedName && !matchedName.startsWith("_")) {
|
|
259
272
|
const start = match.index;
|
|
@@ -276,7 +289,7 @@ async function transformComponent(code, transformer2, s, ctx, sfcPath) {
|
|
|
276
289
|
const component = await ctx.findComponent(name, "component", [sfcPath]);
|
|
277
290
|
if (component) {
|
|
278
291
|
const varName = `__unplugin_components_${no}`;
|
|
279
|
-
s.prepend(`${stringifyComponentImport(
|
|
292
|
+
s.prepend(`${stringifyComponentImport({ ...component, as: varName }, ctx)};
|
|
280
293
|
`);
|
|
281
294
|
no += 1;
|
|
282
295
|
replace(varName);
|
|
@@ -292,7 +305,9 @@ import Debug3 from "debug";
|
|
|
292
305
|
import { importModule, isPackageExists as isPackageExists3 } from "local-pkg";
|
|
293
306
|
var getRenderFnStart = (ast) => {
|
|
294
307
|
var _a, _b;
|
|
295
|
-
const renderFn = ast.program.body.find(
|
|
308
|
+
const renderFn = ast.program.body.find(
|
|
309
|
+
(node) => node.type === "VariableDeclaration" && node.declarations[0].id.type === "Identifier" && node.declarations[0].id.name === "render"
|
|
310
|
+
);
|
|
296
311
|
const start = (_b = (_a = renderFn == null ? void 0 : renderFn.declarations[0].init) == null ? void 0 : _a.body) == null ? void 0 : _b.start;
|
|
297
312
|
if (start === null || start === void 0)
|
|
298
313
|
throw new Error("[unplugin-vue-components:directive] Cannot find render function position.");
|
|
@@ -307,7 +322,7 @@ async function resolveVue22(code, s) {
|
|
|
307
322
|
sourceType: "module"
|
|
308
323
|
});
|
|
309
324
|
const nodes = [];
|
|
310
|
-
const { walk } = await import("./src-
|
|
325
|
+
const { walk } = await import("./src-Z5BCFXFD.mjs");
|
|
311
326
|
walk(ast.program, {
|
|
312
327
|
enter(node) {
|
|
313
328
|
if (node.type === "CallExpression")
|
|
@@ -319,14 +334,18 @@ async function resolveVue22(code, s) {
|
|
|
319
334
|
const { callee, arguments: args } = node;
|
|
320
335
|
if (callee.type !== "Identifier" || callee.name !== "_c" || ((_a = args[1]) == null ? void 0 : _a.type) !== "ObjectExpression")
|
|
321
336
|
continue;
|
|
322
|
-
const directives = (_b = args[1].properties.find(
|
|
337
|
+
const directives = (_b = args[1].properties.find(
|
|
338
|
+
(property) => property.type === "ObjectProperty" && property.key.type === "Identifier" && property.key.name === "directives"
|
|
339
|
+
)) == null ? void 0 : _b.value;
|
|
323
340
|
if (!directives || directives.type !== "ArrayExpression")
|
|
324
341
|
continue;
|
|
325
342
|
const renderStart = getRenderFnStart(ast);
|
|
326
343
|
for (const directive of directives.elements) {
|
|
327
344
|
if ((directive == null ? void 0 : directive.type) !== "ObjectExpression")
|
|
328
345
|
continue;
|
|
329
|
-
const nameNode = (_c = directive.properties.find(
|
|
346
|
+
const nameNode = (_c = directive.properties.find(
|
|
347
|
+
(p) => p.type === "ObjectProperty" && p.key.type === "Identifier" && p.key.name === "name"
|
|
348
|
+
)) == null ? void 0 : _c.value;
|
|
330
349
|
if ((nameNode == null ? void 0 : nameNode.type) !== "StringLiteral")
|
|
331
350
|
continue;
|
|
332
351
|
const name = nameNode.value;
|
|
@@ -374,7 +393,7 @@ async function transformDirective(code, transformer2, s, ctx, sfcPath) {
|
|
|
374
393
|
if (!directive)
|
|
375
394
|
continue;
|
|
376
395
|
const varName = `__unplugin_directives_${no}`;
|
|
377
|
-
s.prepend(`${stringifyComponentImport(
|
|
396
|
+
s.prepend(`${stringifyComponentImport({ ...directive, as: varName }, ctx)};
|
|
378
397
|
`);
|
|
379
398
|
no += 1;
|
|
380
399
|
replace(varName);
|
|
@@ -570,9 +589,10 @@ var Context = class {
|
|
|
570
589
|
from: result
|
|
571
590
|
};
|
|
572
591
|
} else {
|
|
573
|
-
info =
|
|
574
|
-
as: name
|
|
575
|
-
|
|
592
|
+
info = {
|
|
593
|
+
as: name,
|
|
594
|
+
...normalizeComponetInfo(result)
|
|
595
|
+
};
|
|
576
596
|
}
|
|
577
597
|
if (type === "component")
|
|
578
598
|
this.addCustomComponents(info);
|
|
@@ -618,7 +638,10 @@ var Context = class {
|
|
|
618
638
|
// src/core/unplugin.ts
|
|
619
639
|
var PLUGIN_NAME = "unplugin:webpack";
|
|
620
640
|
var unplugin_default = createUnplugin((options = {}) => {
|
|
621
|
-
const filter = createFilter(
|
|
641
|
+
const filter = createFilter(
|
|
642
|
+
options.include || [/\.vue$/, /\.vue\?vue/],
|
|
643
|
+
options.exclude || [/[\\/]node_modules[\\/]/, /[\\/]\.git[\\/]/, /[\\/]\.nuxt[\\/]/]
|
|
644
|
+
);
|
|
622
645
|
const ctx = new Context(options);
|
|
623
646
|
const api = {
|
|
624
647
|
async findComponent(name, filename) {
|
|
@@ -652,9 +675,10 @@ var unplugin_default = createUnplugin((options = {}) => {
|
|
|
652
675
|
ctx.sourcemap = true;
|
|
653
676
|
if (config.plugins.find((i) => i.name === "vite-plugin-vue2"))
|
|
654
677
|
ctx.setTransformer("vue2");
|
|
655
|
-
if (options.dts) {
|
|
678
|
+
if (ctx.options.dts) {
|
|
656
679
|
ctx.searchGlob();
|
|
657
|
-
ctx.
|
|
680
|
+
if (!existsSync2(ctx.options.dts))
|
|
681
|
+
ctx.generateDeclaration();
|
|
658
682
|
}
|
|
659
683
|
if (config.build.watch && config.command === "build")
|
|
660
684
|
ctx.setupWatcher(chokidar.watch(ctx.options.globs));
|
package/dist/esbuild.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkHTGYYKG5js = require('./chunk-HTGYYKG5.js');
|
|
4
4
|
require('./chunk-2GXY7E6X.js');
|
|
5
|
-
require('./chunk-
|
|
5
|
+
require('./chunk-EZUCZHGV.js');
|
|
6
6
|
require('./chunk-6F4PWJZI.js');
|
|
7
7
|
|
|
8
8
|
// src/esbuild.ts
|
|
9
|
-
var esbuild_default =
|
|
9
|
+
var esbuild_default = _chunkHTGYYKG5js.unplugin_default.esbuild;
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
module.exports = esbuild_default;
|
package/dist/esbuild.mjs
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkHTGYYKG5js = require('./chunk-HTGYYKG5.js');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
var _chunk2GXY7E6Xjs = require('./chunk-2GXY7E6X.js');
|
|
9
|
-
require('./chunk-
|
|
9
|
+
require('./chunk-EZUCZHGV.js');
|
|
10
10
|
require('./chunk-6F4PWJZI.js');
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
|
|
16
|
-
exports.camelCase = _chunk2GXY7E6Xjs.camelCase; exports.default =
|
|
16
|
+
exports.camelCase = _chunk2GXY7E6Xjs.camelCase; exports.default = _chunkHTGYYKG5js.unplugin_default; exports.kebabCase = _chunk2GXY7E6Xjs.kebabCase; exports.pascalCase = _chunk2GXY7E6Xjs.pascalCase;
|
package/dist/index.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
unplugin_default
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-L5GWKUOR.mjs";
|
|
4
4
|
import {
|
|
5
5
|
camelCase,
|
|
6
6
|
kebabCase,
|
|
7
7
|
pascalCase
|
|
8
8
|
} from "./chunk-667B3WUW.mjs";
|
|
9
|
-
import "./chunk-
|
|
9
|
+
import "./chunk-AKU6F3WT.mjs";
|
|
10
10
|
import "./chunk-WBQAMGXK.mjs";
|
|
11
11
|
export {
|
|
12
12
|
camelCase,
|
package/dist/nuxt.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkHTGYYKG5js = require('./chunk-HTGYYKG5.js');
|
|
4
4
|
require('./chunk-2GXY7E6X.js');
|
|
5
|
-
require('./chunk-
|
|
5
|
+
require('./chunk-EZUCZHGV.js');
|
|
6
6
|
require('./chunk-6F4PWJZI.js');
|
|
7
7
|
|
|
8
8
|
// src/nuxt.ts
|
|
9
9
|
function nuxt_default(options) {
|
|
10
10
|
this.extendBuild((config) => {
|
|
11
11
|
config.plugins = config.plugins || [];
|
|
12
|
-
config.plugins.unshift(
|
|
12
|
+
config.plugins.unshift(_chunkHTGYYKG5js.unplugin_default.webpack(options));
|
|
13
13
|
});
|
|
14
14
|
this.nuxt.hook("vite:extend", async (vite) => {
|
|
15
15
|
vite.config.plugins = vite.config.plugins || [];
|
|
16
|
-
vite.config.plugins.push(
|
|
16
|
+
vite.config.plugins.push(_chunkHTGYYKG5js.unplugin_default.vite(options));
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
19
|
|
package/dist/nuxt.mjs
CHANGED
package/dist/resolvers.d.ts
CHANGED
|
@@ -76,6 +76,10 @@ interface ElementPlusResolverOptions {
|
|
|
76
76
|
* exclude component name, if match do not resolve the name
|
|
77
77
|
*/
|
|
78
78
|
exclude?: RegExp;
|
|
79
|
+
/**
|
|
80
|
+
* a list of component names that have no styles, so resolving their styles file should be prevented
|
|
81
|
+
*/
|
|
82
|
+
noStylesComponents?: string[];
|
|
79
83
|
}
|
|
80
84
|
/**
|
|
81
85
|
* Resolver for Element Plus
|
|
@@ -350,6 +354,10 @@ interface DevResolverOptions {
|
|
|
350
354
|
* @default true
|
|
351
355
|
*/
|
|
352
356
|
directives?: boolean;
|
|
357
|
+
/**
|
|
358
|
+
* use umd lib file
|
|
359
|
+
*/
|
|
360
|
+
ssr?: boolean;
|
|
353
361
|
}
|
|
354
362
|
declare function DevUiResolver(options?: DevResolverOptions): ComponentResolver[];
|
|
355
363
|
|
|
@@ -400,6 +408,11 @@ interface TDesignResolverOptions {
|
|
|
400
408
|
* @default false
|
|
401
409
|
*/
|
|
402
410
|
resolveIcons?: boolean;
|
|
411
|
+
/**
|
|
412
|
+
* whether to import ESM version
|
|
413
|
+
* @default false
|
|
414
|
+
*/
|
|
415
|
+
esm?: boolean;
|
|
403
416
|
}
|
|
404
417
|
declare function TDesignResolver(options?: TDesignResolverOptions): ComponentResolver;
|
|
405
418
|
|
|
@@ -431,11 +444,19 @@ interface LayuiVueResolverOptions {
|
|
|
431
444
|
*/
|
|
432
445
|
declare function LayuiVueResolver(options?: LayuiVueResolverOptions): ComponentResolver;
|
|
433
446
|
|
|
447
|
+
interface BootstrapVueResolverOptions {
|
|
448
|
+
/**
|
|
449
|
+
* Auto import for directives.
|
|
450
|
+
*
|
|
451
|
+
* @default true
|
|
452
|
+
*/
|
|
453
|
+
directives?: boolean;
|
|
454
|
+
}
|
|
434
455
|
/**
|
|
435
456
|
* Resolver for BootstrapVue
|
|
436
457
|
*
|
|
437
458
|
* @link https://github.com/bootstrap-vue/bootstrap-vue
|
|
438
459
|
*/
|
|
439
|
-
declare function BootstrapVueResolver(): ComponentResolver;
|
|
460
|
+
declare function BootstrapVueResolver(_options?: BootstrapVueResolverOptions): ComponentResolver[];
|
|
440
461
|
|
|
441
|
-
export { AntDesignVueResolver, AntDesignVueResolverOptions, ArcoResolver, ArcoResolverOptions, BootstrapVueResolver, DevResolverOptions, DevUiResolver, ElementPlusResolver, ElementPlusResolverOptions, ElementUiResolver, ElementUiResolverOptions, HeadlessUiResolver, HeadlessUiResolverOptions, IduxResolver, IduxResolverOptions, InklineResolver, LayuiVueResolver, LayuiVueResolverOptions, NaiveUiResolver, PrimeVueResolver, PrimeVueResolverOptions, QuasarResolver, TDesignResolver, TDesignResolverOptions, VantResolver, VantResolverOptions, VarletUIResolver, VarletUIResolverOptions, VeuiResolver, VeuiResolverOptions, ViewUiResolver, VueUseComponentsResolver, Vuetify3Resolver, VuetifyResolver, getResolved };
|
|
462
|
+
export { AntDesignVueResolver, AntDesignVueResolverOptions, ArcoResolver, ArcoResolverOptions, BootstrapVueResolver, BootstrapVueResolverOptions, DevResolverOptions, DevUiResolver, ElementPlusResolver, ElementPlusResolverOptions, ElementUiResolver, ElementUiResolverOptions, HeadlessUiResolver, HeadlessUiResolverOptions, IduxResolver, IduxResolverOptions, InklineResolver, LayuiVueResolver, LayuiVueResolverOptions, NaiveUiResolver, PrimeVueResolver, PrimeVueResolverOptions, QuasarResolver, TDesignResolver, TDesignResolverOptions, VantResolver, VantResolverOptions, VarletUIResolver, VarletUIResolverOptions, VeuiResolver, VeuiResolverOptions, ViewUiResolver, VueUseComponentsResolver, Vuetify3Resolver, VuetifyResolver, getResolved };
|