unplugin-vue-components 0.27.4 → 0.28.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 CHANGED
@@ -230,7 +230,9 @@ Supported Resolvers:
230
230
  - [Quasar](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/quasar.ts)
231
231
  - [TDesign](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/tdesign.ts)
232
232
  - [Vant](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/vant.ts)
233
+ - [`@vant/auto-import-resolver`](https://github.com/youzan/vant/blob/main/packages/vant-auto-import-resolver/README.md) - Vant's own auto-import resolver
233
234
  - [Varlet UI](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/varlet-ui.ts)
235
+ - [`@varlet/import-resolver`](https://github.com/varletjs/varlet/blob/dev/packages/varlet-import-resolver/README.md) - Varlet's own auto-import resolver
234
236
  - [VEUI](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/veui.ts)
235
237
  - [View UI](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/view-ui.ts)
236
238
  - [Vuetify](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/vuetify.ts) — Prefer first-party plugins when possible: [v3 + vite](https://www.npmjs.com/package/vite-plugin-vuetify), [v3 + webpack](https://www.npmjs.com/package/webpack-plugin-vuetify), [v2 + webpack](https://npmjs.com/package/vuetify-loader)
@@ -239,13 +241,13 @@ Supported Resolvers:
239
241
  - [Dev UI](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/devui.ts)
240
242
 
241
243
  ```ts
242
- // vite.config.js
243
- import Components from 'unplugin-vue-components/vite'
244
244
  import {
245
245
  AntDesignVueResolver,
246
246
  ElementPlusResolver,
247
247
  VantResolver,
248
248
  } from 'unplugin-vue-components/resolvers'
249
+ // vite.config.js
250
+ import Components from 'unplugin-vue-components/vite'
249
251
 
250
252
  // your plugin installation
251
253
  Components({
@@ -11,29 +11,30 @@ import {
11
11
  resolveAlias,
12
12
  shouldTransform,
13
13
  stringifyComponentImport
14
- } from "./chunk-VFBNI2IV.js";
14
+ } from "./chunk-X53Y3GEO.js";
15
15
 
16
16
  // src/core/unplugin.ts
17
- import { existsSync as existsSync2 } from "fs";
18
- import process2 from "process";
19
- import { createUnplugin } from "unplugin";
17
+ import { existsSync as existsSync2 } from "node:fs";
18
+ import process2 from "node:process";
20
19
  import { createFilter } from "@rollup/pluginutils";
21
20
  import chokidar from "chokidar";
21
+ import { createUnplugin } from "unplugin";
22
22
 
23
23
  // src/core/context.ts
24
- import { relative as relative2 } from "path";
25
- import process from "process";
26
- import Debug5 from "debug";
24
+ import { relative as relative2 } from "node:path";
25
+ import process from "node:process";
27
26
  import { slash as slash3, throttle, toArray as toArray2 } from "@antfu/utils";
27
+ import Debug5 from "debug";
28
28
 
29
- // src/core/options.ts
30
- import { join, resolve } from "path";
31
- import { slash, toArray } from "@antfu/utils";
32
- import { getPackageInfoSync, isPackageExists as isPackageExists2 } from "local-pkg";
29
+ // src/core/declaration.ts
30
+ import { existsSync } from "node:fs";
31
+ import { mkdir, readFile, writeFile as writeFile_ } from "node:fs/promises";
32
+ import { dirname, isAbsolute, relative } from "node:path";
33
+ import { notNullish as notNullish2, slash } from "@antfu/utils";
33
34
 
34
35
  // src/core/type-imports/detect.ts
35
- import { isPackageExists } from "local-pkg";
36
36
  import { notNullish } from "@antfu/utils";
37
+ import { isPackageExists } from "local-pkg";
37
38
 
38
39
  // src/core/type-imports/index.ts
39
40
  var TypeImportPresets = [
@@ -61,92 +62,7 @@ function resolveTypeImports(imports) {
61
62
  return imports.flatMap((i) => i.names.map((n) => ({ from: i.from, name: n, as: n })));
62
63
  }
63
64
 
64
- // src/core/options.ts
65
- var defaultOptions = {
66
- dirs: "src/components",
67
- extensions: "vue",
68
- deep: true,
69
- dts: isPackageExists2("typescript"),
70
- directoryAsNamespace: false,
71
- collapseSamePrefixes: false,
72
- globalNamespaces: [],
73
- resolvers: [],
74
- importPathTransform: (v) => v,
75
- allowOverrides: false
76
- };
77
- function normalizeResolvers(resolvers) {
78
- return toArray(resolvers).flat().map((r) => typeof r === "function" ? { resolve: r, type: "component" } : r);
79
- }
80
- function resolveGlobsExclude(root, glob) {
81
- const excludeReg = /^!/;
82
- return `${excludeReg.test(glob) ? "!" : ""}${resolve(root, glob.replace(excludeReg, ""))}`;
83
- }
84
- function resolveOptions(options, root) {
85
- const resolved = Object.assign({}, defaultOptions, options);
86
- resolved.resolvers = normalizeResolvers(resolved.resolvers);
87
- resolved.extensions = toArray(resolved.extensions);
88
- if (resolved.globs) {
89
- resolved.globs = toArray(resolved.globs).map((glob) => slash(resolveGlobsExclude(root, glob)));
90
- resolved.resolvedDirs = [];
91
- } else {
92
- const extsGlob = resolved.extensions.length === 1 ? resolved.extensions : `{${resolved.extensions.join(",")}}`;
93
- resolved.dirs = toArray(resolved.dirs);
94
- resolved.resolvedDirs = resolved.dirs.map((i) => slash(resolveGlobsExclude(root, i)));
95
- resolved.globs = resolved.resolvedDirs.map(
96
- (i) => resolved.deep ? slash(join(i, `**/*.${extsGlob}`)) : slash(join(i, `*.${extsGlob}`))
97
- );
98
- if (!resolved.extensions.length)
99
- throw new Error("[unplugin-vue-components] `extensions` option is required to search for components");
100
- }
101
- resolved.dts = !resolved.dts ? false : resolve(
102
- root,
103
- typeof resolved.dts === "string" ? resolved.dts : "components.d.ts"
104
- );
105
- if (!resolved.types && resolved.dts)
106
- resolved.types = detectTypeImports();
107
- resolved.types = resolved.types || [];
108
- resolved.root = root;
109
- resolved.version = resolved.version ?? getVueVersion(root);
110
- if (resolved.version < 2 || resolved.version >= 4)
111
- throw new Error(`[unplugin-vue-components] unsupported version: ${resolved.version}`);
112
- resolved.transformer = options.transformer || `vue${Math.trunc(resolved.version)}`;
113
- resolved.directives = typeof options.directives === "boolean" ? options.directives : !resolved.resolvers.some((i) => i.type === "directive") ? false : resolved.version >= 3;
114
- return resolved;
115
- }
116
- function getVueVersion(root) {
117
- const raw = getPackageInfoSync("vue", { paths: [join(root, "/")] })?.version || "3";
118
- const version = +raw.split(".").slice(0, 2).join(".");
119
- if (version === 2.7)
120
- return 2.7;
121
- else if (version < 2.7)
122
- return 2;
123
- return 3;
124
- }
125
-
126
- // src/core/fs/glob.ts
127
- import fg from "fast-glob";
128
- import Debug from "debug";
129
- var debug = Debug("unplugin-vue-components:glob");
130
- function searchComponents(ctx) {
131
- debug(`started with: [${ctx.options.globs.join(", ")}]`);
132
- const root = ctx.root;
133
- const files = fg.sync(ctx.options.globs, {
134
- ignore: ["node_modules"],
135
- onlyFiles: true,
136
- cwd: root,
137
- absolute: true
138
- });
139
- if (!files.length && !ctx.options.resolvers?.length)
140
- console.warn("[unplugin-vue-components] no components found");
141
- debug(`${files.length} components found.`);
142
- ctx.addComponents(files);
143
- }
144
-
145
65
  // src/core/declaration.ts
146
- import { dirname, isAbsolute, relative } from "path";
147
- import { existsSync } from "fs";
148
- import { mkdir, readFile, writeFile as writeFile_ } from "fs/promises";
149
- import { notNullish as notNullish2, slash as slash2 } from "@antfu/utils";
150
66
  var multilineCommentsRE = /\/\*.*?\*\//gs;
151
67
  var singlelineCommentsRE = /\/\/.*$/gm;
152
68
  function extractImports(code) {
@@ -173,7 +89,7 @@ function stringifyComponentInfo(filepath, { from: path, as: name, name: importNa
173
89
  return void 0;
174
90
  path = getTransformedPath(path, importPathTransform);
175
91
  const related = isAbsolute(path) ? `./${relative(dirname(filepath), path)}` : path;
176
- const entry = `typeof import('${slash2(related)}')['${importName || "default"}']`;
92
+ const entry = `typeof import('${slash(related)}')['${importName || "default"}']`;
177
93
  return [name, entry];
178
94
  }
179
95
  function stringifyComponentsInfo(filepath, components, importPathTransform) {
@@ -250,6 +166,90 @@ async function writeDeclaration(ctx, filepath, removeUnused = false) {
250
166
  await writeFile(filepath, code);
251
167
  }
252
168
 
169
+ // src/core/fs/glob.ts
170
+ import Debug from "debug";
171
+ import fg from "fast-glob";
172
+ var debug = Debug("unplugin-vue-components:glob");
173
+ function searchComponents(ctx) {
174
+ debug(`started with: [${ctx.options.globs.join(", ")}]`);
175
+ const root = ctx.root;
176
+ const files = fg.sync(ctx.options.globs, {
177
+ ignore: ["node_modules"],
178
+ onlyFiles: true,
179
+ cwd: root,
180
+ absolute: true
181
+ });
182
+ if (!files.length && !ctx.options.resolvers?.length)
183
+ console.warn("[unplugin-vue-components] no components found");
184
+ debug(`${files.length} components found.`);
185
+ ctx.addComponents(files);
186
+ }
187
+
188
+ // src/core/options.ts
189
+ import { join, resolve } from "node:path";
190
+ import { slash as slash2, toArray } from "@antfu/utils";
191
+ import { getPackageInfoSync, isPackageExists as isPackageExists2 } from "local-pkg";
192
+ var defaultOptions = {
193
+ dirs: "src/components",
194
+ extensions: "vue",
195
+ deep: true,
196
+ dts: isPackageExists2("typescript"),
197
+ directoryAsNamespace: false,
198
+ collapseSamePrefixes: false,
199
+ globalNamespaces: [],
200
+ resolvers: [],
201
+ importPathTransform: (v) => v,
202
+ allowOverrides: false
203
+ };
204
+ function normalizeResolvers(resolvers) {
205
+ return toArray(resolvers).flat().map((r) => typeof r === "function" ? { resolve: r, type: "component" } : r);
206
+ }
207
+ function resolveGlobsExclude(root, glob) {
208
+ const excludeReg = /^!/;
209
+ return `${excludeReg.test(glob) ? "!" : ""}${resolve(root, glob.replace(excludeReg, ""))}`;
210
+ }
211
+ function resolveOptions(options, root) {
212
+ const resolved = Object.assign({}, defaultOptions, options);
213
+ resolved.resolvers = normalizeResolvers(resolved.resolvers);
214
+ resolved.extensions = toArray(resolved.extensions);
215
+ if (resolved.globs) {
216
+ resolved.globs = toArray(resolved.globs).map((glob) => slash2(resolveGlobsExclude(root, glob)));
217
+ resolved.resolvedDirs = [];
218
+ } else {
219
+ const extsGlob = resolved.extensions.length === 1 ? resolved.extensions : `{${resolved.extensions.join(",")}}`;
220
+ resolved.dirs = toArray(resolved.dirs);
221
+ resolved.resolvedDirs = resolved.dirs.map((i) => slash2(resolveGlobsExclude(root, i)));
222
+ resolved.globs = resolved.resolvedDirs.map(
223
+ (i) => resolved.deep ? slash2(join(i, `**/*.${extsGlob}`)) : slash2(join(i, `*.${extsGlob}`))
224
+ );
225
+ if (!resolved.extensions.length)
226
+ throw new Error("[unplugin-vue-components] `extensions` option is required to search for components");
227
+ }
228
+ resolved.dts = !resolved.dts ? false : resolve(
229
+ root,
230
+ typeof resolved.dts === "string" ? resolved.dts : "components.d.ts"
231
+ );
232
+ if (!resolved.types && resolved.dts)
233
+ resolved.types = detectTypeImports();
234
+ resolved.types = resolved.types || [];
235
+ resolved.root = root;
236
+ resolved.version = resolved.version ?? getVueVersion(root);
237
+ if (resolved.version < 2 || resolved.version >= 4)
238
+ throw new Error(`[unplugin-vue-components] unsupported version: ${resolved.version}`);
239
+ resolved.transformer = options.transformer || `vue${Math.trunc(resolved.version)}`;
240
+ resolved.directives = typeof options.directives === "boolean" ? options.directives : !resolved.resolvers.some((i) => i.type === "directive") ? false : resolved.version >= 3;
241
+ return resolved;
242
+ }
243
+ function getVueVersion(root) {
244
+ const raw = getPackageInfoSync("vue", { paths: [join(root, "/")] })?.version || "3";
245
+ const version = +raw.split(".").slice(0, 2).join(".");
246
+ if (version === 2.7)
247
+ return 2.7;
248
+ else if (version < 2.7)
249
+ return 2;
250
+ return 3;
251
+ }
252
+
253
253
  // src/core/transformer.ts
254
254
  import Debug4 from "debug";
255
255
  import MagicString from "magic-string";
@@ -11,29 +11,30 @@
11
11
 
12
12
 
13
13
 
14
- var _chunk6IWOTYMJcjs = require('./chunk-6IWOTYMJ.cjs');
14
+ var _chunkMU27IQTBcjs = require('./chunk-MU27IQTB.cjs');
15
15
 
16
16
  // src/core/unplugin.ts
17
17
  var _fs = require('fs');
18
18
  var _process = require('process'); var _process2 = _interopRequireDefault(_process);
19
- var _unplugin = require('unplugin');
20
19
  var _pluginutils = require('@rollup/pluginutils');
21
20
  var _chokidar = require('chokidar'); var _chokidar2 = _interopRequireDefault(_chokidar);
21
+ var _unplugin = require('unplugin');
22
22
 
23
23
  // src/core/context.ts
24
24
  var _path = require('path');
25
25
 
26
- var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
27
26
  var _utils = require('@antfu/utils');
27
+ var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
28
28
 
29
- // src/core/options.ts
29
+ // src/core/declaration.ts
30
30
 
31
+ var _promises = require('fs/promises');
31
32
 
32
- var _localpkg = require('local-pkg');
33
33
 
34
- // src/core/type-imports/detect.ts
35
34
 
35
+ // src/core/type-imports/detect.ts
36
36
 
37
+ var _localpkg = require('local-pkg');
37
38
 
38
39
  // src/core/type-imports/index.ts
39
40
  var TypeImportPresets = [
@@ -61,92 +62,7 @@ function resolveTypeImports(imports) {
61
62
  return imports.flatMap((i) => i.names.map((n) => ({ from: i.from, name: n, as: n })));
62
63
  }
63
64
 
64
- // src/core/options.ts
65
- var defaultOptions = {
66
- dirs: "src/components",
67
- extensions: "vue",
68
- deep: true,
69
- dts: _localpkg.isPackageExists.call(void 0, "typescript"),
70
- directoryAsNamespace: false,
71
- collapseSamePrefixes: false,
72
- globalNamespaces: [],
73
- resolvers: [],
74
- importPathTransform: (v) => v,
75
- allowOverrides: false
76
- };
77
- function normalizeResolvers(resolvers) {
78
- return _utils.toArray.call(void 0, resolvers).flat().map((r) => typeof r === "function" ? { resolve: r, type: "component" } : r);
79
- }
80
- function resolveGlobsExclude(root, glob) {
81
- const excludeReg = /^!/;
82
- return `${excludeReg.test(glob) ? "!" : ""}${_path.resolve.call(void 0, root, glob.replace(excludeReg, ""))}`;
83
- }
84
- function resolveOptions(options, root) {
85
- const resolved = Object.assign({}, defaultOptions, options);
86
- resolved.resolvers = normalizeResolvers(resolved.resolvers);
87
- resolved.extensions = _utils.toArray.call(void 0, resolved.extensions);
88
- if (resolved.globs) {
89
- resolved.globs = _utils.toArray.call(void 0, resolved.globs).map((glob) => _utils.slash.call(void 0, resolveGlobsExclude(root, glob)));
90
- resolved.resolvedDirs = [];
91
- } else {
92
- const extsGlob = resolved.extensions.length === 1 ? resolved.extensions : `{${resolved.extensions.join(",")}}`;
93
- resolved.dirs = _utils.toArray.call(void 0, resolved.dirs);
94
- resolved.resolvedDirs = resolved.dirs.map((i) => _utils.slash.call(void 0, resolveGlobsExclude(root, i)));
95
- resolved.globs = resolved.resolvedDirs.map(
96
- (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}`))
97
- );
98
- if (!resolved.extensions.length)
99
- throw new Error("[unplugin-vue-components] `extensions` option is required to search for components");
100
- }
101
- resolved.dts = !resolved.dts ? false : _path.resolve.call(void 0,
102
- root,
103
- typeof resolved.dts === "string" ? resolved.dts : "components.d.ts"
104
- );
105
- if (!resolved.types && resolved.dts)
106
- resolved.types = detectTypeImports();
107
- resolved.types = resolved.types || [];
108
- resolved.root = root;
109
- resolved.version = _nullishCoalesce(resolved.version, () => ( getVueVersion(root)));
110
- if (resolved.version < 2 || resolved.version >= 4)
111
- throw new Error(`[unplugin-vue-components] unsupported version: ${resolved.version}`);
112
- resolved.transformer = options.transformer || `vue${Math.trunc(resolved.version)}`;
113
- resolved.directives = typeof options.directives === "boolean" ? options.directives : !resolved.resolvers.some((i) => i.type === "directive") ? false : resolved.version >= 3;
114
- return resolved;
115
- }
116
- function getVueVersion(root) {
117
- const raw = _optionalChain([_localpkg.getPackageInfoSync.call(void 0, "vue", { paths: [_path.join.call(void 0, root, "/")] }), 'optionalAccess', _ => _.version]) || "3";
118
- const version = +raw.split(".").slice(0, 2).join(".");
119
- if (version === 2.7)
120
- return 2.7;
121
- else if (version < 2.7)
122
- return 2;
123
- return 3;
124
- }
125
-
126
- // src/core/fs/glob.ts
127
- var _fastglob = require('fast-glob'); var _fastglob2 = _interopRequireDefault(_fastglob);
128
-
129
- var debug = _debug2.default.call(void 0, "unplugin-vue-components:glob");
130
- function searchComponents(ctx) {
131
- debug(`started with: [${ctx.options.globs.join(", ")}]`);
132
- const root = ctx.root;
133
- const files = _fastglob2.default.sync(ctx.options.globs, {
134
- ignore: ["node_modules"],
135
- onlyFiles: true,
136
- cwd: root,
137
- absolute: true
138
- });
139
- if (!files.length && !_optionalChain([ctx, 'access', _2 => _2.options, 'access', _3 => _3.resolvers, 'optionalAccess', _4 => _4.length]))
140
- console.warn("[unplugin-vue-components] no components found");
141
- debug(`${files.length} components found.`);
142
- ctx.addComponents(files);
143
- }
144
-
145
65
  // src/core/declaration.ts
146
-
147
-
148
- var _promises = require('fs/promises');
149
-
150
66
  var multilineCommentsRE = /\/\*.*?\*\//gs;
151
67
  var singlelineCommentsRE = /\/\/.*$/gm;
152
68
  function extractImports(code) {
@@ -160,10 +76,10 @@ function parseDeclaration(code) {
160
76
  component: {},
161
77
  directive: {}
162
78
  };
163
- const componentDeclaration = _optionalChain([/export\s+interface\s+GlobalComponents\s*\{.*?\}/s, 'access', _5 => _5.exec, 'call', _6 => _6(code), 'optionalAccess', _7 => _7[0]]);
79
+ const componentDeclaration = _optionalChain([/export\s+interface\s+GlobalComponents\s*\{.*?\}/s, 'access', _ => _.exec, 'call', _2 => _2(code), 'optionalAccess', _3 => _3[0]]);
164
80
  if (componentDeclaration)
165
81
  imports.component = extractImports(componentDeclaration);
166
- const directiveDeclaration = _optionalChain([/export\s+interface\s+ComponentCustomProperties\s*\{.*?\}/s, 'access', _8 => _8.exec, 'call', _9 => _9(code), 'optionalAccess', _10 => _10[0]]);
82
+ const directiveDeclaration = _optionalChain([/export\s+interface\s+ComponentCustomProperties\s*\{.*?\}/s, 'access', _4 => _4.exec, 'call', _5 => _5(code), 'optionalAccess', _6 => _6[0]]);
167
83
  if (directiveDeclaration)
168
84
  imports.directive = extractImports(directiveDeclaration);
169
85
  return imports;
@@ -171,7 +87,7 @@ function parseDeclaration(code) {
171
87
  function stringifyComponentInfo(filepath, { from: path, as: name, name: importName }, importPathTransform) {
172
88
  if (!name)
173
89
  return void 0;
174
- path = _chunk6IWOTYMJcjs.getTransformedPath.call(void 0, path, importPathTransform);
90
+ path = _chunkMU27IQTBcjs.getTransformedPath.call(void 0, path, importPathTransform);
175
91
  const related = _path.isAbsolute.call(void 0, path) ? `./${_path.relative.call(void 0, _path.dirname.call(void 0, filepath), path)}` : path;
176
92
  const entry = `typeof import('${_utils.slash.call(void 0, related)}')['${importName || "default"}']`;
177
93
  return [name, entry];
@@ -210,8 +126,8 @@ function getDeclaration(ctx, filepath, originalImports) {
210
126
  if (!imports)
211
127
  return;
212
128
  const declarations = {
213
- component: stringifyDeclarationImports({ ..._optionalChain([originalImports, 'optionalAccess', _11 => _11.component]), ...imports.component }),
214
- directive: stringifyDeclarationImports({ ..._optionalChain([originalImports, 'optionalAccess', _12 => _12.directive]), ...imports.directive })
129
+ component: stringifyDeclarationImports({ ..._optionalChain([originalImports, 'optionalAccess', _7 => _7.component]), ...imports.component }),
130
+ directive: stringifyDeclarationImports({ ..._optionalChain([originalImports, 'optionalAccess', _8 => _8.directive]), ...imports.directive })
215
131
  };
216
132
  let code = `/* eslint-disable */
217
133
  // @ts-nocheck
@@ -250,6 +166,90 @@ async function writeDeclaration(ctx, filepath, removeUnused = false) {
250
166
  await writeFile(filepath, code);
251
167
  }
252
168
 
169
+ // src/core/fs/glob.ts
170
+
171
+ var _fastglob = require('fast-glob'); var _fastglob2 = _interopRequireDefault(_fastglob);
172
+ var debug = _debug2.default.call(void 0, "unplugin-vue-components:glob");
173
+ function searchComponents(ctx) {
174
+ debug(`started with: [${ctx.options.globs.join(", ")}]`);
175
+ const root = ctx.root;
176
+ const files = _fastglob2.default.sync(ctx.options.globs, {
177
+ ignore: ["node_modules"],
178
+ onlyFiles: true,
179
+ cwd: root,
180
+ absolute: true
181
+ });
182
+ if (!files.length && !_optionalChain([ctx, 'access', _9 => _9.options, 'access', _10 => _10.resolvers, 'optionalAccess', _11 => _11.length]))
183
+ console.warn("[unplugin-vue-components] no components found");
184
+ debug(`${files.length} components found.`);
185
+ ctx.addComponents(files);
186
+ }
187
+
188
+ // src/core/options.ts
189
+
190
+
191
+
192
+ var defaultOptions = {
193
+ dirs: "src/components",
194
+ extensions: "vue",
195
+ deep: true,
196
+ dts: _localpkg.isPackageExists.call(void 0, "typescript"),
197
+ directoryAsNamespace: false,
198
+ collapseSamePrefixes: false,
199
+ globalNamespaces: [],
200
+ resolvers: [],
201
+ importPathTransform: (v) => v,
202
+ allowOverrides: false
203
+ };
204
+ function normalizeResolvers(resolvers) {
205
+ return _utils.toArray.call(void 0, resolvers).flat().map((r) => typeof r === "function" ? { resolve: r, type: "component" } : r);
206
+ }
207
+ function resolveGlobsExclude(root, glob) {
208
+ const excludeReg = /^!/;
209
+ return `${excludeReg.test(glob) ? "!" : ""}${_path.resolve.call(void 0, root, glob.replace(excludeReg, ""))}`;
210
+ }
211
+ function resolveOptions(options, root) {
212
+ const resolved = Object.assign({}, defaultOptions, options);
213
+ resolved.resolvers = normalizeResolvers(resolved.resolvers);
214
+ resolved.extensions = _utils.toArray.call(void 0, resolved.extensions);
215
+ if (resolved.globs) {
216
+ resolved.globs = _utils.toArray.call(void 0, resolved.globs).map((glob) => _utils.slash.call(void 0, resolveGlobsExclude(root, glob)));
217
+ resolved.resolvedDirs = [];
218
+ } else {
219
+ const extsGlob = resolved.extensions.length === 1 ? resolved.extensions : `{${resolved.extensions.join(",")}}`;
220
+ resolved.dirs = _utils.toArray.call(void 0, resolved.dirs);
221
+ resolved.resolvedDirs = resolved.dirs.map((i) => _utils.slash.call(void 0, resolveGlobsExclude(root, i)));
222
+ resolved.globs = resolved.resolvedDirs.map(
223
+ (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}`))
224
+ );
225
+ if (!resolved.extensions.length)
226
+ throw new Error("[unplugin-vue-components] `extensions` option is required to search for components");
227
+ }
228
+ resolved.dts = !resolved.dts ? false : _path.resolve.call(void 0,
229
+ root,
230
+ typeof resolved.dts === "string" ? resolved.dts : "components.d.ts"
231
+ );
232
+ if (!resolved.types && resolved.dts)
233
+ resolved.types = detectTypeImports();
234
+ resolved.types = resolved.types || [];
235
+ resolved.root = root;
236
+ resolved.version = _nullishCoalesce(resolved.version, () => ( getVueVersion(root)));
237
+ if (resolved.version < 2 || resolved.version >= 4)
238
+ throw new Error(`[unplugin-vue-components] unsupported version: ${resolved.version}`);
239
+ resolved.transformer = options.transformer || `vue${Math.trunc(resolved.version)}`;
240
+ resolved.directives = typeof options.directives === "boolean" ? options.directives : !resolved.resolvers.some((i) => i.type === "directive") ? false : resolved.version >= 3;
241
+ return resolved;
242
+ }
243
+ function getVueVersion(root) {
244
+ const raw = _optionalChain([_localpkg.getPackageInfoSync.call(void 0, "vue", { paths: [_path.join.call(void 0, root, "/")] }), 'optionalAccess', _12 => _12.version]) || "3";
245
+ const version = +raw.split(".").slice(0, 2).join(".");
246
+ if (version === 2.7)
247
+ return 2.7;
248
+ else if (version < 2.7)
249
+ return 2;
250
+ return 3;
251
+ }
252
+
253
253
  // src/core/transformer.ts
254
254
 
255
255
  var _magicstring = require('magic-string'); var _magicstring2 = _interopRequireDefault(_magicstring);
@@ -292,12 +292,12 @@ async function transformComponent(code, transformer2, s, ctx, sfcPath) {
292
292
  const results = transformer2 === "vue2" ? resolveVue2(code, s) : resolveVue3(code, s);
293
293
  for (const { rawName, replace } of results) {
294
294
  debug2(`| ${rawName}`);
295
- const name = _chunk6IWOTYMJcjs.pascalCase.call(void 0, rawName);
295
+ const name = _chunkMU27IQTBcjs.pascalCase.call(void 0, rawName);
296
296
  ctx.updateUsageMap(sfcPath, [name]);
297
297
  const component = await ctx.findComponent(name, "component", [sfcPath]);
298
298
  if (component) {
299
299
  const varName = `__unplugin_components_${no}`;
300
- s.prepend(`${_chunk6IWOTYMJcjs.stringifyComponentImport.call(void 0, { ...component, as: varName }, ctx)};
300
+ s.prepend(`${_chunkMU27IQTBcjs.stringifyComponentImport.call(void 0, { ...component, as: varName }, ctx)};
301
301
  `);
302
302
  no += 1;
303
303
  replace(varName);
@@ -400,13 +400,13 @@ async function transformDirective(code, transformer2, s, ctx, sfcPath) {
400
400
  const results = await (transformer2 === "vue2" ? resolveVue22(code, s) : resolveVue32(code, s));
401
401
  for (const { rawName, replace } of results) {
402
402
  debug3(`| ${rawName}`);
403
- const name = `${_chunk6IWOTYMJcjs.DIRECTIVE_IMPORT_PREFIX}${_chunk6IWOTYMJcjs.pascalCase.call(void 0, rawName)}`;
403
+ const name = `${_chunkMU27IQTBcjs.DIRECTIVE_IMPORT_PREFIX}${_chunkMU27IQTBcjs.pascalCase.call(void 0, rawName)}`;
404
404
  ctx.updateUsageMap(sfcPath, [name]);
405
405
  const directive = await ctx.findComponent(name, "directive", [sfcPath]);
406
406
  if (!directive)
407
407
  continue;
408
408
  const varName = `__unplugin_directives_${no}`;
409
- s.prepend(`${_chunk6IWOTYMJcjs.stringifyComponentImport.call(void 0, { ...directive, as: varName }, ctx)};
409
+ s.prepend(`${_chunkMU27IQTBcjs.stringifyComponentImport.call(void 0, { ...directive, as: varName }, ctx)};
410
410
  `);
411
411
  no += 1;
412
412
  replace(varName);
@@ -425,7 +425,7 @@ function transformer(ctx, transformer2) {
425
425
  await transformComponent(code, transformer2, s, ctx, sfcPath);
426
426
  if (ctx.options.directives)
427
427
  await transformDirective(code, transformer2, s, ctx, sfcPath);
428
- s.prepend(_chunk6IWOTYMJcjs.DISABLE_COMMENT);
428
+ s.prepend(_chunkMU27IQTBcjs.DISABLE_COMMENT);
429
429
  const result = { code: s.toString() };
430
430
  if (ctx.sourcemap)
431
431
  result.map = s.generateMap({ source: id, includeContent: true, hires: "boundary" });
@@ -471,7 +471,7 @@ var Context = (_class = class {
471
471
  this.transformer = transformer(this, name || "vue3");
472
472
  }
473
473
  transform(code, id) {
474
- const { path, query } = _chunk6IWOTYMJcjs.parseId.call(void 0, id);
474
+ const { path, query } = _chunkMU27IQTBcjs.parseId.call(void 0, id);
475
475
  return this.transformer(code, id, path, query);
476
476
  }
477
477
  setupViteServer(server) {
@@ -483,14 +483,14 @@ var Context = (_class = class {
483
483
  setupWatcher(watcher) {
484
484
  const { globs } = this.options;
485
485
  watcher.on("unlink", (path) => {
486
- if (!_chunk6IWOTYMJcjs.matchGlobs.call(void 0, path, globs))
486
+ if (!_chunkMU27IQTBcjs.matchGlobs.call(void 0, path, globs))
487
487
  return;
488
488
  path = _utils.slash.call(void 0, path);
489
489
  this.removeComponents(path);
490
490
  this.onUpdate(path);
491
491
  });
492
492
  watcher.on("add", (path) => {
493
- if (!_chunk6IWOTYMJcjs.matchGlobs.call(void 0, path, globs))
493
+ if (!_chunkMU27IQTBcjs.matchGlobs.call(void 0, path, globs))
494
494
  return;
495
495
  path = _utils.slash.call(void 0, path);
496
496
  this.addComponents(path);
@@ -503,14 +503,14 @@ var Context = (_class = class {
503
503
  setupWatcherWebpack(watcher, emitUpdate) {
504
504
  const { globs } = this.options;
505
505
  watcher.on("unlink", (path) => {
506
- if (!_chunk6IWOTYMJcjs.matchGlobs.call(void 0, path, globs))
506
+ if (!_chunkMU27IQTBcjs.matchGlobs.call(void 0, path, globs))
507
507
  return;
508
508
  path = _utils.slash.call(void 0, path);
509
509
  this.removeComponents(path);
510
510
  emitUpdate(path, "unlink");
511
511
  });
512
512
  watcher.on("add", (path) => {
513
- if (!_chunk6IWOTYMJcjs.matchGlobs.call(void 0, path, globs))
513
+ if (!_chunkMU27IQTBcjs.matchGlobs.call(void 0, path, globs))
514
514
  return;
515
515
  path = _utils.slash.call(void 0, path);
516
516
  this.addComponents(path);
@@ -566,7 +566,7 @@ var Context = (_class = class {
566
566
  updates: []
567
567
  };
568
568
  const timestamp = +/* @__PURE__ */ new Date();
569
- const name = _chunk6IWOTYMJcjs.pascalCase.call(void 0, _chunk6IWOTYMJcjs.getNameFromFilePath.call(void 0, path, this.options));
569
+ const name = _chunkMU27IQTBcjs.pascalCase.call(void 0, _chunkMU27IQTBcjs.getNameFromFilePath.call(void 0, path, this.options));
570
570
  Object.entries(this._componentUsageMap).forEach(([key, values]) => {
571
571
  if (values.has(name)) {
572
572
  const r = `/${_utils.slash.call(void 0, _path.relative.call(void 0, this.root, key))}`;
@@ -584,8 +584,8 @@ var Context = (_class = class {
584
584
  updateComponentNameMap() {
585
585
  this._componentNameMap = {};
586
586
  Array.from(this._componentPaths).forEach((path) => {
587
- const name = _chunk6IWOTYMJcjs.pascalCase.call(void 0, _chunk6IWOTYMJcjs.getNameFromFilePath.call(void 0, path, this.options));
588
- if (_chunk6IWOTYMJcjs.isExclude.call(void 0, name, this.options.excludeNames)) {
587
+ const name = _chunkMU27IQTBcjs.pascalCase.call(void 0, _chunkMU27IQTBcjs.getNameFromFilePath.call(void 0, path, this.options));
588
+ if (_chunkMU27IQTBcjs.isExclude.call(void 0, name, this.options.excludeNames)) {
589
589
  debug5.components("exclude", name);
590
590
  return;
591
591
  }
@@ -606,7 +606,7 @@ var Context = (_class = class {
606
606
  for (const resolver of this.options.resolvers) {
607
607
  if (resolver.type !== type)
608
608
  continue;
609
- const result = await resolver.resolve(type === "directive" ? name.slice(_chunk6IWOTYMJcjs.DIRECTIVE_IMPORT_PREFIX.length) : name);
609
+ const result = await resolver.resolve(type === "directive" ? name.slice(_chunkMU27IQTBcjs.DIRECTIVE_IMPORT_PREFIX.length) : name);
610
610
  if (!result)
611
611
  continue;
612
612
  if (typeof result === "string") {
@@ -617,7 +617,7 @@ var Context = (_class = class {
617
617
  } else {
618
618
  info = {
619
619
  as: name,
620
- ..._chunk6IWOTYMJcjs.normalizeComponentInfo.call(void 0, result)
620
+ ..._chunkMU27IQTBcjs.normalizeComponentInfo.call(void 0, result)
621
621
  };
622
622
  }
623
623
  if (type === "component")
@@ -629,7 +629,7 @@ var Context = (_class = class {
629
629
  return void 0;
630
630
  }
631
631
  normalizePath(path) {
632
- return _chunk6IWOTYMJcjs.resolveAlias.call(void 0, path, _optionalChain([this, 'access', _31 => _31.viteConfig, 'optionalAccess', _32 => _32.resolve, 'optionalAccess', _33 => _33.alias]) || _optionalChain([this, 'access', _34 => _34.viteConfig, 'optionalAccess', _35 => _35.alias]) || []);
632
+ return _chunkMU27IQTBcjs.resolveAlias.call(void 0, path, _optionalChain([this, 'access', _31 => _31.viteConfig, 'optionalAccess', _32 => _32.resolve, 'optionalAccess', _33 => _33.alias]) || _optionalChain([this, 'access', _34 => _34.viteConfig, 'optionalAccess', _35 => _35.alias]) || []);
633
633
  }
634
634
  relative(path) {
635
635
  if (path.startsWith("/") && !path.startsWith(this.root))
@@ -680,7 +680,7 @@ var unplugin_default = _unplugin.createUnplugin.call(void 0, (options = {}) => {
680
680
  return await ctx.findComponent(name, "component", filename ? [filename] : []);
681
681
  },
682
682
  stringifyImport(info) {
683
- return _chunk6IWOTYMJcjs.stringifyComponentImport.call(void 0, info, ctx);
683
+ return _chunkMU27IQTBcjs.stringifyComponentImport.call(void 0, info, ctx);
684
684
  }
685
685
  };
686
686
  return {
@@ -691,7 +691,7 @@ var unplugin_default = _unplugin.createUnplugin.call(void 0, (options = {}) => {
691
691
  return filter(id);
692
692
  },
693
693
  async transform(code, id) {
694
- if (!_chunk6IWOTYMJcjs.shouldTransform.call(void 0, code))
694
+ if (!_chunkMU27IQTBcjs.shouldTransform.call(void 0, code))
695
695
  return null;
696
696
  try {
697
697
  const result = await ctx.transform(code, id);
@@ -1,12 +1,12 @@
1
1
  // src/core/utils.ts
2
- import { parse } from "path";
3
- import process from "process";
4
- import { minimatch } from "minimatch";
2
+ import { parse } from "node:path";
3
+ import process from "node:process";
5
4
  import { slash, toArray } from "@antfu/utils";
6
5
  import {
7
6
  getPackageInfo,
8
7
  isPackageExists
9
8
  } from "local-pkg";
9
+ import { minimatch } from "minimatch";
10
10
 
11
11
  // src/core/constants.ts
12
12
  var DISABLE_COMMENT = "/* unplugin-vue-components disabled */";