unplugin-vue-components 0.18.5 → 0.19.2

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
@@ -227,10 +227,10 @@ You can also write your own resolver quickly:
227
227
  Components({
228
228
  resolvers: [
229
229
  // example of importing Vant
230
- (name) => {
231
- // where `name` is always CapitalCase
232
- if (name.startsWith('Van'))
233
- return { importName: name.slice(3), path: 'vant' }
230
+ (componentName) => {
231
+ // where `componentName` is always CapitalCase
232
+ if (componentName.startsWith('Van'))
233
+ return { name: componentName.slice(3), from: 'vant' }
234
234
  },
235
235
  ],
236
236
  })
@@ -238,6 +238,33 @@ Components({
238
238
 
239
239
  If you successfully configured other UI libraries, please feel free to contribute and help others using them out-of-box. Thanks!
240
240
 
241
+ ## Types for global registered components
242
+
243
+ Some libraries might register some global components for you to use anywhere (e.g. Vue Router provides `<RouterLink>` and `<RouterView>`). Since they are global available, there is no need for this plugin to import them. However, those are commonly not TypeScript friendly, and you might need to register their types manually.
244
+
245
+ Thus `unplugin-vue-components` provided a way to only register types for global components.
246
+
247
+ ```ts
248
+ Components({
249
+ dts: true,
250
+ types: [{
251
+ from: 'vue-router',
252
+ names: ['RouterLink', 'RouterView'],
253
+ }],
254
+ })
255
+ ```
256
+
257
+ So the `RouterLink` and `RouterView` will be presented in `components.d.ts`.
258
+
259
+ By default, `unplugin-vue-components` detects supported libraries automatically (e.g. `vue-router`) when their are installed in the workspace. If you want to disable it completely, you can pass an empty array to it:
260
+
261
+ ```ts
262
+ Components({
263
+ // Disable type only registration
264
+ types: [],
265
+ })
266
+ ```
267
+
241
268
  ## Migrate from `vite-plugin-components`
242
269
 
243
270
  `package.json`
@@ -300,6 +327,7 @@ Components({
300
327
 
301
328
  // generate `components.d.ts` global declarations,
302
329
  // also accepts a path for custom filename
330
+ // default: `true` if package typescript is installed
303
331
  dts: false,
304
332
 
305
333
  // Allow subdirectories as namespace prefix for components.
@@ -12,7 +12,7 @@
12
12
 
13
13
 
14
14
 
15
- var _chunkI3PYM4HQjs = require('./chunk-I3PYM4HQ.js');
15
+ var _chunkTMX2H7L5js = require('./chunk-TMX2H7L5.js');
16
16
 
17
17
  // src/core/unplugin.ts
18
18
  var _unplugin = require('unplugin');
@@ -28,6 +28,38 @@ var _utils = require('@antfu/utils');
28
28
 
29
29
 
30
30
  var _localpkg = require('local-pkg');
31
+
32
+ // src/core/type-imports/detect.ts
33
+
34
+
35
+
36
+ // src/core/type-imports/index.ts
37
+ var TypeImportPresets = [
38
+ {
39
+ from: "vue-router",
40
+ names: [
41
+ "RouterView",
42
+ "RouterLink"
43
+ ]
44
+ },
45
+ {
46
+ from: "vue-starport",
47
+ names: [
48
+ "Starport",
49
+ "StarportCarrier"
50
+ ]
51
+ }
52
+ ];
53
+
54
+ // src/core/type-imports/detect.ts
55
+ function detectTypeImports() {
56
+ return TypeImportPresets.map((i) => _localpkg.isPackageExists.call(void 0, i.from) ? i : void 0).filter(_utils.notNullish);
57
+ }
58
+ function resolveTypeImports(imports) {
59
+ return imports.flatMap((i) => i.names.map((n) => ({ from: i.from, name: n, as: n })));
60
+ }
61
+
62
+ // src/core/options.ts
31
63
  var defaultOptions = {
32
64
  dirs: "src/components",
33
65
  extensions: "vue",
@@ -35,7 +67,6 @@ var defaultOptions = {
35
67
  dts: _localpkg.isPackageExists.call(void 0, "typescript"),
36
68
  directoryAsNamespace: false,
37
69
  globalNamespaces: [],
38
- libraries: [],
39
70
  resolvers: [],
40
71
  importPathTransform: (v) => v,
41
72
  allowOverrides: false
@@ -45,9 +76,7 @@ function normalizeResolvers(resolvers) {
45
76
  }
46
77
  function resolveOptions(options, root) {
47
78
  const resolved = Object.assign({}, defaultOptions, options);
48
- resolved.libraries = _utils.toArray.call(void 0, resolved.libraries).map((i) => typeof i === "string" ? { name: i } : i);
49
79
  resolved.resolvers = normalizeResolvers(resolved.resolvers);
50
- resolved.resolvers.push(...resolved.libraries.map((lib) => _chunkI3PYM4HQjs.LibraryResolver.call(void 0, lib)));
51
80
  resolved.extensions = _utils.toArray.call(void 0, resolved.extensions);
52
81
  if (resolved.globs) {
53
82
  resolved.globs = _utils.toArray.call(void 0, resolved.globs).map((glob) => _utils.slash.call(void 0, _path.resolve.call(void 0, root, glob)));
@@ -61,6 +90,9 @@ function resolveOptions(options, root) {
61
90
  throw new Error("[unplugin-vue-components] `extensions` option is required to search for components");
62
91
  }
63
92
  resolved.dts = !resolved.dts ? false : _path.resolve.call(void 0, root, typeof resolved.dts === "string" ? resolved.dts : "components.d.ts");
93
+ if (!resolved.types && resolved.dts)
94
+ resolved.types = detectTypeImports();
95
+ resolved.types = resolved.types || [];
64
96
  resolved.root = root;
65
97
  resolved.transformer = options.transformer || getVueVersion() || "vue3";
66
98
  resolved.directives = typeof options.directives === "boolean" ? options.directives : !resolved.resolvers.some((i) => i.type === "directive") ? false : getVueVersion() === "vue3";
@@ -69,7 +101,7 @@ function resolveOptions(options, root) {
69
101
  function getVueVersion() {
70
102
  var _a;
71
103
  try {
72
- const vue = _chunkI3PYM4HQjs.__require.call(void 0, "vue");
104
+ const vue = _chunkTMX2H7L5js.__require.call(void 0, "vue");
73
105
  const version = ((_a = vue == null ? void 0 : vue.default) == null ? void 0 : _a.version) || (vue == null ? void 0 : vue.version) || "3";
74
106
  return version.startsWith("2.") ? "vue2" : "vue3";
75
107
  } catch (e2) {
@@ -107,10 +139,14 @@ function parseDeclaration(code) {
107
139
  return Object.fromEntries(Array.from(code.matchAll(/(?<!\/\/)\s+\s+['"]?(.+?)['"]?:\s(.+?)\n/g)).map((i) => [i[1], i[2]]));
108
140
  }
109
141
  async function generateDeclaration(ctx, root, filepath, removeUnused = false) {
110
- const imports = Object.fromEntries(Object.values(_chunkI3PYM4HQjs.__spreadValues.call(void 0, _chunkI3PYM4HQjs.__spreadValues.call(void 0, {}, ctx.componentNameMap), ctx.componentCustomMap)).map(({ path, name, importName }) => {
142
+ const items = [
143
+ ...Object.values(_chunkTMX2H7L5js.__spreadValues.call(void 0, _chunkTMX2H7L5js.__spreadValues.call(void 0, {}, ctx.componentNameMap), ctx.componentCustomMap)),
144
+ ...resolveTypeImports(ctx.options.types)
145
+ ];
146
+ const imports = Object.fromEntries(items.map(({ from: path, as: name, name: importName }) => {
111
147
  if (!name)
112
148
  return void 0;
113
- path = _chunkI3PYM4HQjs.getTransformedPath.call(void 0, path, ctx);
149
+ path = _chunkTMX2H7L5js.getTransformedPath.call(void 0, path, ctx);
114
150
  const related = _path.isAbsolute.call(void 0, path) ? `./${_path.relative.call(void 0, _path.dirname.call(void 0, filepath), path)}` : path;
115
151
  let entry = `typeof import('${_utils.slash.call(void 0, related)}')`;
116
152
  if (importName)
@@ -123,7 +159,7 @@ async function generateDeclaration(ctx, root, filepath, removeUnused = false) {
123
159
  return;
124
160
  const originalContent = _fs.existsSync.call(void 0, filepath) ? await _fs.promises.readFile(filepath, "utf-8") : "";
125
161
  const originalImports = parseDeclaration(originalContent);
126
- const lines = Object.entries(_chunkI3PYM4HQjs.__spreadValues.call(void 0, _chunkI3PYM4HQjs.__spreadValues.call(void 0, {}, originalImports), imports)).sort((a, b) => a[0].localeCompare(b[0])).filter(([name]) => removeUnused ? ctx.componentCustomMap[name] || ctx.componentNameMap[name] : true).map(([name, v]) => {
162
+ const lines = Object.entries(_chunkTMX2H7L5js.__spreadValues.call(void 0, _chunkTMX2H7L5js.__spreadValues.call(void 0, {}, originalImports), imports)).sort((a, b) => a[0].localeCompare(b[0])).filter(([name]) => removeUnused ? items.find((i) => i.as === name) : true).map(([name, v]) => {
127
163
  if (!/^\w+$/.test(name))
128
164
  name = `'${name}'`;
129
165
  return `${name}: ${v}`;
@@ -132,7 +168,7 @@ async function generateDeclaration(ctx, root, filepath, removeUnused = false) {
132
168
  // We suggest you to commit this file into source control
133
169
  // Read more: https://github.com/vuejs/vue-next/pull/3399
134
170
 
135
- declare module 'vue' {
171
+ declare module '@vue/runtime-core' {
136
172
  export interface GlobalComponents {
137
173
  ${lines.join("\n ")}
138
174
  }
@@ -186,12 +222,12 @@ async function transformComponent(code, transformer2, s, ctx, sfcPath) {
186
222
  const results = transformer2 === "vue2" ? resolveVue2(code, s) : resolveVue3(code, s);
187
223
  for (const { rawName, replace } of results) {
188
224
  debug2(`| ${rawName}`);
189
- const name = _chunkI3PYM4HQjs.pascalCase.call(void 0, rawName);
225
+ const name = _chunkTMX2H7L5js.pascalCase.call(void 0, rawName);
190
226
  ctx.updateUsageMap(sfcPath, [name]);
191
227
  const component = await ctx.findComponent(name, "component", [sfcPath]);
192
228
  if (component) {
193
229
  const varName = `__unplugin_components_${no}`;
194
- s.prepend(`${_chunkI3PYM4HQjs.stringifyComponentImport.call(void 0, _chunkI3PYM4HQjs.__spreadProps.call(void 0, _chunkI3PYM4HQjs.__spreadValues.call(void 0, {}, component), { name: varName }), ctx)};
230
+ s.prepend(`${_chunkTMX2H7L5js.stringifyComponentImport.call(void 0, _chunkTMX2H7L5js.__spreadProps.call(void 0, _chunkTMX2H7L5js.__spreadValues.call(void 0, {}, component), { as: varName }), ctx)};
195
231
  `);
196
232
  no += 1;
197
233
  replace(varName);
@@ -281,13 +317,13 @@ async function transformDirective(code, transformer2, s, ctx, sfcPath) {
281
317
  const results = await (transformer2 === "vue2" ? resolveVue22(code, s) : resolveVue32(code, s));
282
318
  for (const { rawName, replace } of results) {
283
319
  debug3(`| ${rawName}`);
284
- const name = _chunkI3PYM4HQjs.pascalCase.call(void 0, rawName);
320
+ const name = _chunkTMX2H7L5js.pascalCase.call(void 0, rawName);
285
321
  ctx.updateUsageMap(sfcPath, [name]);
286
322
  const directive = await ctx.findComponent(name, "directive", [sfcPath]);
287
323
  if (!directive)
288
324
  continue;
289
325
  const varName = `__unplugin_directives_${no}`;
290
- s.prepend(`${_chunkI3PYM4HQjs.stringifyComponentImport.call(void 0, _chunkI3PYM4HQjs.__spreadProps.call(void 0, _chunkI3PYM4HQjs.__spreadValues.call(void 0, {}, directive), { name: varName }), ctx)};
326
+ s.prepend(`${_chunkTMX2H7L5js.stringifyComponentImport.call(void 0, _chunkTMX2H7L5js.__spreadProps.call(void 0, _chunkTMX2H7L5js.__spreadValues.call(void 0, {}, directive), { as: varName }), ctx)};
291
327
  `);
292
328
  no += 1;
293
329
  replace(varName);
@@ -306,7 +342,7 @@ function transformer(ctx, transformer2) {
306
342
  await transformComponent(code, transformer2, s, ctx, sfcPath);
307
343
  if (ctx.options.directives)
308
344
  await transformDirective(code, transformer2, s, ctx, sfcPath);
309
- s.prepend(_chunkI3PYM4HQjs.DISABLE_COMMENT);
345
+ s.prepend(_chunkTMX2H7L5js.DISABLE_COMMENT);
310
346
  const result = { code: s.toString() };
311
347
  if (ctx.sourcemap)
312
348
  result.map = s.generateMap({ source: id, includeContent: true });
@@ -350,7 +386,7 @@ var Context = class {
350
386
  this.transformer = transformer(this, name || "vue3");
351
387
  }
352
388
  transform(code, id) {
353
- const { path, query } = _chunkI3PYM4HQjs.parseId.call(void 0, id);
389
+ const { path, query } = _chunkTMX2H7L5js.parseId.call(void 0, id);
354
390
  return this.transformer(code, id, path, query);
355
391
  }
356
392
  setupViteServer(server) {
@@ -362,14 +398,14 @@ var Context = class {
362
398
  setupWatcher(watcher) {
363
399
  const { globs } = this.options;
364
400
  watcher.on("unlink", (path) => {
365
- if (!_chunkI3PYM4HQjs.matchGlobs.call(void 0, path, globs))
401
+ if (!_chunkTMX2H7L5js.matchGlobs.call(void 0, path, globs))
366
402
  return;
367
403
  path = _utils.slash.call(void 0, path);
368
404
  this.removeComponents(path);
369
405
  this.onUpdate(path);
370
406
  });
371
407
  watcher.on("add", (path) => {
372
- if (!_chunkI3PYM4HQjs.matchGlobs.call(void 0, path, globs))
408
+ if (!_chunkTMX2H7L5js.matchGlobs.call(void 0, path, globs))
373
409
  return;
374
410
  path = _utils.slash.call(void 0, path);
375
411
  this.addComponents(path);
@@ -394,8 +430,8 @@ var Context = class {
394
430
  return false;
395
431
  }
396
432
  addCustomComponents(info) {
397
- if (info.name)
398
- this._componentCustomMap[info.name] = info;
433
+ if (info.as)
434
+ this._componentCustomMap[info.as] = info;
399
435
  }
400
436
  removeComponents(paths) {
401
437
  debug5.components("remove", paths);
@@ -416,7 +452,7 @@ var Context = class {
416
452
  updates: []
417
453
  };
418
454
  const timestamp = +new Date();
419
- const name = _chunkI3PYM4HQjs.pascalCase.call(void 0, _chunkI3PYM4HQjs.getNameFromFilePath.call(void 0, path, this.options));
455
+ const name = _chunkTMX2H7L5js.pascalCase.call(void 0, _chunkTMX2H7L5js.getNameFromFilePath.call(void 0, path, this.options));
420
456
  Object.entries(this._componentUsageMap).forEach(([key, values]) => {
421
457
  if (values.has(name)) {
422
458
  const r = `/${_utils.slash.call(void 0, _path.relative.call(void 0, this.root, key))}`;
@@ -434,20 +470,20 @@ var Context = class {
434
470
  updateComponentNameMap() {
435
471
  this._componentNameMap = {};
436
472
  Array.from(this._componentPaths).forEach((path) => {
437
- const name = _chunkI3PYM4HQjs.pascalCase.call(void 0, _chunkI3PYM4HQjs.getNameFromFilePath.call(void 0, path, this.options));
473
+ const name = _chunkTMX2H7L5js.pascalCase.call(void 0, _chunkTMX2H7L5js.getNameFromFilePath.call(void 0, path, this.options));
438
474
  if (this._componentNameMap[name] && !this.options.allowOverrides) {
439
475
  console.warn(`[unplugin-vue-components] component "${name}"(${path}) has naming conflicts with other components, ignored.`);
440
476
  return;
441
477
  }
442
478
  this._componentNameMap[name] = {
443
- name,
444
- path
479
+ as: name,
480
+ from: path
445
481
  };
446
482
  });
447
483
  }
448
484
  async findComponent(name, type, excludePaths = []) {
449
485
  let info = this._componentNameMap[name];
450
- if (info && !excludePaths.includes(info.path) && !excludePaths.includes(info.path.slice(1)))
486
+ if (info && !excludePaths.includes(info.from) && !excludePaths.includes(info.from.slice(1)))
451
487
  return info;
452
488
  for (const resolver of this.options.resolvers) {
453
489
  if (resolver.type !== type)
@@ -456,15 +492,15 @@ var Context = class {
456
492
  if (result) {
457
493
  if (typeof result === "string") {
458
494
  info = {
459
- name,
460
- path: result
495
+ as: name,
496
+ from: result
461
497
  };
462
498
  this.addCustomComponents(info);
463
499
  return info;
464
500
  } else {
465
- info = _chunkI3PYM4HQjs.__spreadValues.call(void 0, {
466
- name
467
- }, result);
501
+ info = _chunkTMX2H7L5js.__spreadValues.call(void 0, {
502
+ as: name
503
+ }, _chunkTMX2H7L5js.normalizeComponetInfo.call(void 0, result));
468
504
  this.addCustomComponents(info);
469
505
  return info;
470
506
  }
@@ -474,7 +510,7 @@ var Context = class {
474
510
  }
475
511
  normalizePath(path) {
476
512
  var _a, _b, _c;
477
- return _chunkI3PYM4HQjs.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) || []);
513
+ return _chunkTMX2H7L5js.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) || []);
478
514
  }
479
515
  relative(path) {
480
516
  if (path.startsWith("/") && !path.startsWith(this.root))
@@ -511,7 +547,7 @@ var unplugin_default = _unplugin.createUnplugin.call(void 0, (options = {}) => {
511
547
  return await ctx.findComponent(name, "component", filename ? [filename] : []);
512
548
  },
513
549
  stringifyImport(info) {
514
- return _chunkI3PYM4HQjs.stringifyComponentImport.call(void 0, info, ctx);
550
+ return _chunkTMX2H7L5js.stringifyComponentImport.call(void 0, info, ctx);
515
551
  }
516
552
  };
517
553
  return {
@@ -522,7 +558,7 @@ var unplugin_default = _unplugin.createUnplugin.call(void 0, (options = {}) => {
522
558
  return filter(id);
523
559
  },
524
560
  async transform(code, id) {
525
- if (!_chunkI3PYM4HQjs.shouldTransform.call(void 0, code))
561
+ if (!_chunkTMX2H7L5js.shouldTransform.call(void 0, code))
526
562
  return null;
527
563
  try {
528
564
  const result = await ctx.transform(code, id);
@@ -1,7 +1,6 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __defProps = Object.defineProperties;
3
3
  var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
4
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
6
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
6
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
@@ -25,9 +24,6 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
25
24
  return require.apply(this, arguments);
26
25
  throw new Error('Dynamic require of "' + x + '" is not supported');
27
26
  });
28
- var __commonJS = (cb, mod) => function __require2() {
29
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
30
- };
31
27
 
32
28
  // src/core/utils.ts
33
29
  import { parse } from "path";
@@ -93,17 +89,28 @@ function getTransformedPath(path, ctx) {
93
89
  function stringifyImport(info) {
94
90
  if (typeof info === "string")
95
91
  return `import '${info}'`;
96
- if (!info.name)
97
- return `import '${info.path}'`;
98
- else if (info.importName)
99
- return `import { ${info.importName} as ${info.name} } from '${info.path}'`;
92
+ if (!info.as)
93
+ return `import '${info.from}'`;
94
+ else if (info.name)
95
+ return `import { ${info.name} as ${info.as} } from '${info.from}'`;
100
96
  else
101
- return `import ${info.name} from '${info.path}'`;
97
+ return `import ${info.as} from '${info.from}'`;
98
+ }
99
+ function normalizeComponetInfo(info) {
100
+ if ("path" in info) {
101
+ return {
102
+ from: info.path,
103
+ as: info.name,
104
+ name: info.importName,
105
+ sideEffects: info.sideEffects
106
+ };
107
+ }
108
+ return info;
102
109
  }
103
- function stringifyComponentImport({ name, path, importName, sideEffects }, ctx) {
110
+ function stringifyComponentImport({ as: name, from: path, name: importName, sideEffects }, ctx) {
104
111
  path = getTransformedPath(path, ctx);
105
112
  const imports = [
106
- stringifyImport({ name, path, importName })
113
+ stringifyImport({ as: name, from: path, name: importName })
107
114
  ];
108
115
  if (sideEffects)
109
116
  toArray(sideEffects).forEach((i) => imports.push(stringifyImport(i)));
@@ -171,67 +178,10 @@ function resolveImportPath(importName) {
171
178
  });
172
179
  }
173
180
 
174
- // src/core/helpers/libraryResolver.ts
175
- import fs from "fs";
176
- import { dirname, join } from "path";
177
- import Debug from "debug";
178
- var debug = Debug("unplugin-vue-components:helper:library");
179
- function tryLoadVeturTags(name) {
180
- var _a;
181
- try {
182
- const pkgPath = resolveImportPath(`${name}/package.json`);
183
- if (!pkgPath)
184
- return;
185
- const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
186
- const tagsPath = (_a = pkg == null ? void 0 : pkg.vetur) == null ? void 0 : _a.tags;
187
- if (!tagsPath)
188
- return;
189
- const tags = JSON.parse(fs.readFileSync(join(dirname(pkgPath), tagsPath), "utf-8"));
190
- return Object.keys(tags).map((i) => camelCase(i));
191
- } catch (e) {
192
- console.error(e);
193
- }
194
- }
195
- function LibraryResolver(options) {
196
- const {
197
- name: libraryName,
198
- entries = tryLoadVeturTags(options.name),
199
- prefix = ""
200
- } = options;
201
- if (!entries) {
202
- console.warn(`[unplugin-vue-components] Failed to load Vetur tags from library "${libraryName}"`);
203
- return {
204
- type: "component",
205
- resolve: () => {
206
- }
207
- };
208
- }
209
- debug(entries);
210
- const prefixKebab = kebabCase(prefix);
211
- const kebabEntries = entries.map((name) => ({ name, kebab: kebabCase(name) }));
212
- return {
213
- type: "component",
214
- resolve: (name) => {
215
- const kebab = kebabCase(name);
216
- let componentName = kebab;
217
- if (prefixKebab) {
218
- if (!kebab.startsWith(`${prefixKebab}-`))
219
- return;
220
- componentName = kebab.slice(prefixKebab.length + 1);
221
- }
222
- for (const entry of kebabEntries) {
223
- if (entry.kebab === componentName)
224
- return { path: libraryName, importName: entry.name };
225
- }
226
- }
227
- };
228
- }
229
-
230
181
  export {
231
182
  __spreadValues,
232
183
  __spreadProps,
233
184
  __require,
234
- __commonJS,
235
185
  DISABLE_COMMENT,
236
186
  isSSR,
237
187
  pascalCase,
@@ -240,12 +190,11 @@ export {
240
190
  parseId,
241
191
  matchGlobs,
242
192
  getTransformedPath,
193
+ normalizeComponetInfo,
243
194
  stringifyComponentImport,
244
195
  getNameFromFilePath,
245
196
  resolveAlias,
246
197
  getPkgVersion,
247
198
  shouldTransform,
248
- resolveImportPath,
249
- tryLoadVeturTags,
250
- LibraryResolver
199
+ resolveImportPath
251
200
  };
@@ -1,7 +1,6 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var __defProp = Object.defineProperty;
2
2
  var __defProps = Object.defineProperties;
3
3
  var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
4
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
6
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
6
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
@@ -25,9 +24,6 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
25
24
  return require.apply(this, arguments);
26
25
  throw new Error('Dynamic require of "' + x + '" is not supported');
27
26
  });
28
- var __commonJS = (cb, mod) => function __require2() {
29
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
30
- };
31
27
 
32
28
  // src/core/utils.ts
33
29
  var _path = require('path');
@@ -93,17 +89,28 @@ function getTransformedPath(path, ctx) {
93
89
  function stringifyImport(info) {
94
90
  if (typeof info === "string")
95
91
  return `import '${info}'`;
96
- if (!info.name)
97
- return `import '${info.path}'`;
98
- else if (info.importName)
99
- return `import { ${info.importName} as ${info.name} } from '${info.path}'`;
92
+ if (!info.as)
93
+ return `import '${info.from}'`;
94
+ else if (info.name)
95
+ return `import { ${info.name} as ${info.as} } from '${info.from}'`;
100
96
  else
101
- return `import ${info.name} from '${info.path}'`;
97
+ return `import ${info.as} from '${info.from}'`;
98
+ }
99
+ function normalizeComponetInfo(info) {
100
+ if ("path" in info) {
101
+ return {
102
+ from: info.path,
103
+ as: info.name,
104
+ name: info.importName,
105
+ sideEffects: info.sideEffects
106
+ };
107
+ }
108
+ return info;
102
109
  }
103
- function stringifyComponentImport({ name, path, importName, sideEffects }, ctx) {
110
+ function stringifyComponentImport({ as: name, from: path, name: importName, sideEffects }, ctx) {
104
111
  path = getTransformedPath(path, ctx);
105
112
  const imports = [
106
- stringifyImport({ name, path, importName })
113
+ stringifyImport({ as: name, from: path, name: importName })
107
114
  ];
108
115
  if (sideEffects)
109
116
  _utils.toArray.call(void 0, sideEffects).forEach((i) => imports.push(stringifyImport(i)));
@@ -171,64 +178,6 @@ function resolveImportPath(importName) {
171
178
  });
172
179
  }
173
180
 
174
- // src/core/helpers/libraryResolver.ts
175
- var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs);
176
-
177
- var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
178
- var debug = _debug2.default.call(void 0, "unplugin-vue-components:helper:library");
179
- function tryLoadVeturTags(name) {
180
- var _a;
181
- try {
182
- const pkgPath = resolveImportPath(`${name}/package.json`);
183
- if (!pkgPath)
184
- return;
185
- const pkg = JSON.parse(_fs2.default.readFileSync(pkgPath, "utf-8"));
186
- const tagsPath = (_a = pkg == null ? void 0 : pkg.vetur) == null ? void 0 : _a.tags;
187
- if (!tagsPath)
188
- return;
189
- const tags = JSON.parse(_fs2.default.readFileSync(_path.join.call(void 0, _path.dirname.call(void 0, pkgPath), tagsPath), "utf-8"));
190
- return Object.keys(tags).map((i) => camelCase(i));
191
- } catch (e) {
192
- console.error(e);
193
- }
194
- }
195
- function LibraryResolver(options) {
196
- const {
197
- name: libraryName,
198
- entries = tryLoadVeturTags(options.name),
199
- prefix = ""
200
- } = options;
201
- if (!entries) {
202
- console.warn(`[unplugin-vue-components] Failed to load Vetur tags from library "${libraryName}"`);
203
- return {
204
- type: "component",
205
- resolve: () => {
206
- }
207
- };
208
- }
209
- debug(entries);
210
- const prefixKebab = kebabCase(prefix);
211
- const kebabEntries = entries.map((name) => ({ name, kebab: kebabCase(name) }));
212
- return {
213
- type: "component",
214
- resolve: (name) => {
215
- const kebab = kebabCase(name);
216
- let componentName = kebab;
217
- if (prefixKebab) {
218
- if (!kebab.startsWith(`${prefixKebab}-`))
219
- return;
220
- componentName = kebab.slice(prefixKebab.length + 1);
221
- }
222
- for (const entry of kebabEntries) {
223
- if (entry.kebab === componentName)
224
- return { path: libraryName, importName: entry.name };
225
- }
226
- }
227
- };
228
- }
229
-
230
-
231
-
232
181
 
233
182
 
234
183
 
@@ -248,4 +197,4 @@ function LibraryResolver(options) {
248
197
 
249
198
 
250
199
 
251
- exports.__spreadValues = __spreadValues; exports.__spreadProps = __spreadProps; exports.__require = __require; exports.__commonJS = __commonJS; exports.DISABLE_COMMENT = DISABLE_COMMENT; exports.isSSR = isSSR; 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;
200
+ exports.__spreadValues = __spreadValues; exports.__spreadProps = __spreadProps; exports.__require = __require; exports.DISABLE_COMMENT = DISABLE_COMMENT; exports.isSSR = isSSR; exports.pascalCase = pascalCase; exports.camelCase = camelCase; exports.kebabCase = kebabCase; exports.parseId = parseId; exports.matchGlobs = matchGlobs; exports.getTransformedPath = getTransformedPath; exports.normalizeComponetInfo = normalizeComponetInfo; exports.stringifyComponentImport = stringifyComponentImport; exports.getNameFromFilePath = getNameFromFilePath; exports.resolveAlias = resolveAlias; exports.getPkgVersion = getPkgVersion; exports.shouldTransform = shouldTransform; exports.resolveImportPath = resolveImportPath;