unplugin-vue-components 0.27.1 → 0.27.3

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.
@@ -10,11 +10,7 @@ import {
10
10
  resolveAlias,
11
11
  shouldTransform,
12
12
  stringifyComponentImport
13
- } from "./chunk-5LSX6IQN.js";
14
- import {
15
- __spreadProps,
16
- __spreadValues
17
- } from "./chunk-5JVO2UWC.js";
13
+ } from "./chunk-4KHLF5I7.js";
18
14
 
19
15
  // src/core/unplugin.ts
20
16
  import { existsSync as existsSync2 } from "fs";
@@ -85,7 +81,6 @@ function resolveGlobsExclude(root, glob) {
85
81
  return `${excludeReg.test(glob) ? "!" : ""}${resolve(root, glob.replace(excludeReg, ""))}`;
86
82
  }
87
83
  function resolveOptions(options, root) {
88
- var _a;
89
84
  const resolved = Object.assign({}, defaultOptions, options);
90
85
  resolved.resolvers = normalizeResolvers(resolved.resolvers);
91
86
  resolved.extensions = toArray(resolved.extensions);
@@ -110,7 +105,7 @@ function resolveOptions(options, root) {
110
105
  resolved.types = detectTypeImports();
111
106
  resolved.types = resolved.types || [];
112
107
  resolved.root = root;
113
- resolved.version = (_a = resolved.version) != null ? _a : getVueVersion(root);
108
+ resolved.version = resolved.version ?? getVueVersion(root);
114
109
  if (resolved.version < 2 || resolved.version >= 4)
115
110
  throw new Error(`[unplugin-vue-components] unsupported version: ${resolved.version}`);
116
111
  resolved.transformer = options.transformer || `vue${Math.trunc(resolved.version)}`;
@@ -118,8 +113,7 @@ function resolveOptions(options, root) {
118
113
  return resolved;
119
114
  }
120
115
  function getVueVersion(root) {
121
- var _a;
122
- const raw = ((_a = getPackageInfoSync("vue", { paths: [root] })) == null ? void 0 : _a.version) || "3";
116
+ const raw = getPackageInfoSync("vue", { paths: [root] })?.version || "3";
123
117
  const version = +raw.split(".").slice(0, 2).join(".");
124
118
  if (version === 2.7)
125
119
  return 2.7;
@@ -133,7 +127,6 @@ import fg from "fast-glob";
133
127
  import Debug from "debug";
134
128
  var debug = Debug("unplugin-vue-components:glob");
135
129
  function searchComponents(ctx) {
136
- var _a;
137
130
  debug(`started with: [${ctx.options.globs.join(", ")}]`);
138
131
  const root = ctx.root;
139
132
  const files = fg.sync(ctx.options.globs, {
@@ -142,7 +135,7 @@ function searchComponents(ctx) {
142
135
  cwd: root,
143
136
  absolute: true
144
137
  });
145
- if (!files.length && !((_a = ctx.options.resolvers) == null ? void 0 : _a.length))
138
+ if (!files.length && !ctx.options.resolvers?.length)
146
139
  console.warn("[unplugin-vue-components] no components found");
147
140
  debug(`${files.length} components found.`);
148
141
  ctx.addComponents(files);
@@ -153,13 +146,12 @@ import { dirname, isAbsolute, relative } from "path";
153
146
  import { existsSync } from "fs";
154
147
  import { mkdir, readFile, writeFile as writeFile_ } from "fs/promises";
155
148
  import { notNullish as notNullish2, slash as slash2 } from "@antfu/utils";
156
- var multilineCommentsRE = new RegExp("\\/\\*.*?\\*\\/", "gms");
149
+ var multilineCommentsRE = /\/\*.*?\*\//gs;
157
150
  var singlelineCommentsRE = /\/\/.*$/gm;
158
151
  function extractImports(code) {
159
152
  return Object.fromEntries(Array.from(code.matchAll(/['"]?([^\s'"]+)['"]?\s*:\s*(.+?)[,;\n]/g)).map((i) => [i[1], i[2]]));
160
153
  }
161
154
  function parseDeclaration(code) {
162
- var _a, _b;
163
155
  if (!code)
164
156
  return;
165
157
  code = code.replace(multilineCommentsRE, "").replace(singlelineCommentsRE, "");
@@ -167,10 +159,10 @@ function parseDeclaration(code) {
167
159
  component: {},
168
160
  directive: {}
169
161
  };
170
- const componentDeclaration = (_a = new RegExp("export\\s+interface\\s+GlobalComponents\\s*{(.*?)}", "s").exec(code)) == null ? void 0 : _a[0];
162
+ const componentDeclaration = /export\s+interface\s+GlobalComponents\s*\{.*?\}/s.exec(code)?.[0];
171
163
  if (componentDeclaration)
172
164
  imports.component = extractImports(componentDeclaration);
173
- const directiveDeclaration = (_b = new RegExp("export\\s+interface\\s+ComponentCustomProperties\\s*{(.*?)}", "s").exec(code)) == null ? void 0 : _b[0];
165
+ const directiveDeclaration = /export\s+interface\s+ComponentCustomProperties\s*\{.*?\}/s.exec(code)?.[0];
174
166
  if (directiveDeclaration)
175
167
  imports.directive = extractImports(directiveDeclaration);
176
168
  return imports;
@@ -190,7 +182,10 @@ function stringifyComponentsInfo(filepath, components, importPathTransform) {
190
182
  }
191
183
  function getDeclarationImports(ctx, filepath) {
192
184
  const component = stringifyComponentsInfo(filepath, [
193
- ...Object.values(__spreadValues(__spreadValues({}, ctx.componentNameMap), ctx.componentCustomMap)),
185
+ ...Object.values({
186
+ ...ctx.componentNameMap,
187
+ ...ctx.componentCustomMap
188
+ }),
194
189
  ...resolveTypeImports(ctx.options.types)
195
190
  ], ctx.options.importPathTransform);
196
191
  const directive = stringifyComponentsInfo(
@@ -214,8 +209,8 @@ function getDeclaration(ctx, filepath, originalImports) {
214
209
  if (!imports)
215
210
  return;
216
211
  const declarations = {
217
- component: stringifyDeclarationImports(__spreadValues(__spreadValues({}, originalImports == null ? void 0 : originalImports.component), imports.component)),
218
- directive: stringifyDeclarationImports(__spreadValues(__spreadValues({}, originalImports == null ? void 0 : originalImports.directive), imports.directive))
212
+ component: stringifyDeclarationImports({ ...originalImports?.component, ...imports.component }),
213
+ directive: stringifyDeclarationImports({ ...originalImports?.directive, ...imports.directive })
219
214
  };
220
215
  let code = `/* eslint-disable */
221
216
  // @ts-nocheck
@@ -263,7 +258,7 @@ import Debug2 from "debug";
263
258
  var debug2 = Debug2("unplugin-vue-components:transform:component");
264
259
  function resolveVue2(code, s) {
265
260
  const results = [];
266
- for (const match of code.matchAll(/\b(_c|h)\([\s\n\t]*['"](.+?)["']([,)])/g)) {
261
+ for (const match of code.matchAll(/\b(_c|h)\(\s*['"](.+?)["']([,)])/g)) {
267
262
  const [full, renderFunctionName, matchedName, append] = match;
268
263
  if (match.index != null && matchedName && !matchedName.startsWith("_")) {
269
264
  const start = match.index;
@@ -278,7 +273,7 @@ function resolveVue2(code, s) {
278
273
  }
279
274
  function resolveVue3(code, s) {
280
275
  const results = [];
281
- for (const match of code.matchAll(/_resolveComponent[0-9]*\("(.+?)"\)/g)) {
276
+ for (const match of code.matchAll(/_resolveComponent\d*\("(.+?)"\)/g)) {
282
277
  const matchedName = match[1];
283
278
  if (match.index != null && matchedName && !matchedName.startsWith("_")) {
284
279
  const start = match.index;
@@ -301,7 +296,7 @@ async function transformComponent(code, transformer2, s, ctx, sfcPath) {
301
296
  const component = await ctx.findComponent(name, "component", [sfcPath]);
302
297
  if (component) {
303
298
  const varName = `__unplugin_components_${no}`;
304
- s.prepend(`${stringifyComponentImport(__spreadProps(__spreadValues({}, component), { as: varName }), ctx)};
299
+ s.prepend(`${stringifyComponentImport({ ...component, as: varName }, ctx)};
305
300
  `);
306
301
  no += 1;
307
302
  replace(varName);
@@ -316,17 +311,15 @@ import Debug3 from "debug";
316
311
  // src/core/transforms/directive/vue2.ts
317
312
  import { importModule, isPackageExists as isPackageExists3 } from "local-pkg";
318
313
  function getRenderFnStart(program) {
319
- var _a, _b;
320
314
  const renderFn = program.body.find(
321
315
  (node) => node.type === "VariableDeclaration" && node.declarations[0].id.type === "Identifier" && ["render", "_sfc_render"].includes(node.declarations[0].id.name)
322
316
  );
323
- const start = (_b = (_a = renderFn == null ? void 0 : renderFn.declarations[0].init) == null ? void 0 : _a.body) == null ? void 0 : _b.start;
317
+ const start = renderFn?.declarations[0].init?.body?.start;
324
318
  if (start === null || start === void 0)
325
319
  throw new Error("[unplugin-vue-components:directive] Cannot find render function position.");
326
320
  return start + 1;
327
321
  }
328
322
  async function resolveVue22(code, s) {
329
- var _a, _b, _c;
330
323
  if (!isPackageExists3("@babel/parser"))
331
324
  throw new Error('[unplugin-vue-components:directive] To use Vue 2 directive you will need to install Babel first: "npm install -D @babel/parser"');
332
325
  const { parse } = await importModule("@babel/parser");
@@ -334,7 +327,7 @@ async function resolveVue22(code, s) {
334
327
  sourceType: "module"
335
328
  });
336
329
  const nodes = [];
337
- const { walk } = await import("./src-WIQNDB4Q.js");
330
+ const { walk } = await import("./src-QRDHCXVL.js");
338
331
  walk(program, {
339
332
  enter(node) {
340
333
  if (node.type === "CallExpression")
@@ -352,20 +345,20 @@ async function resolveVue22(code, s) {
352
345
  const results = [];
353
346
  for (const node of nodes) {
354
347
  const { callee, arguments: args } = node;
355
- if (callee.type !== "Identifier" || callee.name !== "_c" || ((_a = args[1]) == null ? void 0 : _a.type) !== "ObjectExpression")
348
+ if (callee.type !== "Identifier" || callee.name !== "_c" || args[1]?.type !== "ObjectExpression")
356
349
  continue;
357
- const directives = (_b = args[1].properties.find(
350
+ const directives = args[1].properties.find(
358
351
  (property) => property.type === "ObjectProperty" && property.key.type === "Identifier" && property.key.name === "directives"
359
- )) == null ? void 0 : _b.value;
352
+ )?.value;
360
353
  if (!directives || directives.type !== "ArrayExpression")
361
354
  continue;
362
355
  for (const directive of directives.elements) {
363
- if ((directive == null ? void 0 : directive.type) !== "ObjectExpression")
356
+ if (directive?.type !== "ObjectExpression")
364
357
  continue;
365
- const nameNode = (_c = directive.properties.find(
358
+ const nameNode = directive.properties.find(
366
359
  (p) => p.type === "ObjectProperty" && p.key.type === "Identifier" && p.key.name === "name"
367
- )) == null ? void 0 : _c.value;
368
- if ((nameNode == null ? void 0 : nameNode.type) !== "StringLiteral")
360
+ )?.value;
361
+ if (nameNode?.type !== "StringLiteral")
369
362
  continue;
370
363
  const name = nameNode.value;
371
364
  if (!name || name.startsWith("_"))
@@ -412,7 +405,7 @@ async function transformDirective(code, transformer2, s, ctx, sfcPath) {
412
405
  if (!directive)
413
406
  continue;
414
407
  const varName = `__unplugin_directives_${no}`;
415
- s.prepend(`${stringifyComponentImport(__spreadProps(__spreadValues({}, directive), { as: varName }), ctx)};
408
+ s.prepend(`${stringifyComponentImport({ ...directive, as: varName }, ctx)};
416
409
  `);
417
410
  no += 1;
418
411
  replace(varName);
@@ -450,20 +443,21 @@ var debug5 = {
450
443
  var Context = class {
451
444
  constructor(rawOptions) {
452
445
  this.rawOptions = rawOptions;
453
- this.transformer = void 0;
454
- this._componentPaths = /* @__PURE__ */ new Set();
455
- this._componentNameMap = {};
456
- this._componentUsageMap = {};
457
- this._componentCustomMap = {};
458
- this._directiveCustomMap = {};
459
- this.root = process.cwd();
460
- this.sourcemap = true;
461
- this.alias = {};
462
- this._searched = false;
463
446
  this.options = resolveOptions(rawOptions, this.root);
464
447
  this.generateDeclaration = throttle(500, this._generateDeclaration.bind(this), { noLeading: false });
465
448
  this.setTransformer(this.options.transformer);
466
449
  }
450
+ options;
451
+ transformer = void 0;
452
+ _componentPaths = /* @__PURE__ */ new Set();
453
+ _componentNameMap = {};
454
+ _componentUsageMap = {};
455
+ _componentCustomMap = {};
456
+ _directiveCustomMap = {};
457
+ _server;
458
+ root = process.cwd();
459
+ sourcemap = true;
460
+ alias = {};
467
461
  setRoot(root) {
468
462
  if (this.root === root)
469
463
  return;
@@ -616,9 +610,10 @@ var Context = class {
616
610
  from: result
617
611
  };
618
612
  } else {
619
- info = __spreadValues({
620
- as: name
621
- }, normalizeComponentInfo(result));
613
+ info = {
614
+ as: name,
615
+ ...normalizeComponentInfo(result)
616
+ };
622
617
  }
623
618
  if (type === "component")
624
619
  this.addCustomComponents(info);
@@ -629,14 +624,14 @@ var Context = class {
629
624
  return void 0;
630
625
  }
631
626
  normalizePath(path) {
632
- var _a, _b, _c;
633
- return resolveAlias(path, ((_b = (_a = this.viteConfig) == null ? void 0 : _a.resolve) == null ? void 0 : _b.alias) || ((_c = this.viteConfig) == null ? void 0 : _c.alias) || []);
627
+ return resolveAlias(path, this.viteConfig?.resolve?.alias || this.viteConfig?.alias || []);
634
628
  }
635
629
  relative(path) {
636
630
  if (path.startsWith("/") && !path.startsWith(this.root))
637
631
  return slash3(path.slice(1));
638
632
  return slash3(relative2(this.root, path));
639
633
  }
634
+ _searched = false;
640
635
  /**
641
636
  * This search for components in with the given options.
642
637
  * Will be called multiple times to ensure file loaded,
@@ -655,6 +650,7 @@ var Context = class {
655
650
  debug5.declaration("generating");
656
651
  return writeDeclaration(this, this.options.dts, removeUnused);
657
652
  }
653
+ generateDeclaration;
658
654
  get componentNameMap() {
659
655
  return this._componentNameMap;
660
656
  }
package/dist/esbuild.cjs CHANGED
@@ -1,12 +1,12 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkMB5VKJR2cjs = require('./chunk-MB5VKJR2.cjs');
4
- require('./chunk-VPUTCXXP.cjs');
5
- require('./chunk-WJIU4Q36.cjs');
3
+ var _chunkV7E5BH3Ycjs = require('./chunk-V7E5BH3Y.cjs');
4
+ require('./chunk-5RDO6MHS.cjs');
5
+ require('./chunk-OBGZSXTJ.cjs');
6
6
  require('./chunk-ZBPRDZS4.cjs');
7
7
 
8
8
  // src/esbuild.ts
9
- var esbuild_default = _chunkMB5VKJR2cjs.unplugin_default.esbuild;
9
+ var esbuild_default = _chunkV7E5BH3Ycjs.unplugin_default.esbuild;
10
10
 
11
11
 
12
12
  exports.default = esbuild_default;
package/dist/esbuild.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  unplugin_default
3
- } from "./chunk-WH3OXX67.js";
4
- import "./chunk-5LSX6IQN.js";
5
- import "./chunk-5JVO2UWC.js";
3
+ } from "./chunk-YOHL3P33.js";
4
+ import "./chunk-4KHLF5I7.js";
5
+ import "./chunk-3RG5ZIWI.js";
6
6
  import "./chunk-6F4PWJZI.js";
7
7
 
8
8
  // src/esbuild.ts
package/dist/index.cjs CHANGED
@@ -1,16 +1,16 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkMB5VKJR2cjs = require('./chunk-MB5VKJR2.cjs');
3
+ var _chunkV7E5BH3Ycjs = require('./chunk-V7E5BH3Y.cjs');
4
4
 
5
5
 
6
6
 
7
7
 
8
- var _chunkVPUTCXXPcjs = require('./chunk-VPUTCXXP.cjs');
9
- require('./chunk-WJIU4Q36.cjs');
8
+ var _chunk5RDO6MHScjs = require('./chunk-5RDO6MHS.cjs');
9
+ require('./chunk-OBGZSXTJ.cjs');
10
10
  require('./chunk-ZBPRDZS4.cjs');
11
11
 
12
12
 
13
13
 
14
14
 
15
15
 
16
- exports.camelCase = _chunkVPUTCXXPcjs.camelCase; exports.default = _chunkMB5VKJR2cjs.unplugin_default; exports.kebabCase = _chunkVPUTCXXPcjs.kebabCase; exports.pascalCase = _chunkVPUTCXXPcjs.pascalCase;
16
+ exports.camelCase = _chunk5RDO6MHScjs.camelCase; exports.default = _chunkV7E5BH3Ycjs.unplugin_default; exports.kebabCase = _chunk5RDO6MHScjs.kebabCase; exports.pascalCase = _chunk5RDO6MHScjs.pascalCase;
package/dist/index.js CHANGED
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  unplugin_default
3
- } from "./chunk-WH3OXX67.js";
3
+ } from "./chunk-YOHL3P33.js";
4
4
  import {
5
5
  camelCase,
6
6
  kebabCase,
7
7
  pascalCase
8
- } from "./chunk-5LSX6IQN.js";
9
- import "./chunk-5JVO2UWC.js";
8
+ } from "./chunk-4KHLF5I7.js";
9
+ import "./chunk-3RG5ZIWI.js";
10
10
  import "./chunk-6F4PWJZI.js";
11
11
  export {
12
12
  camelCase,
package/dist/nuxt.cjs CHANGED
@@ -1,16 +1,16 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkMB5VKJR2cjs = require('./chunk-MB5VKJR2.cjs');
4
- require('./chunk-VPUTCXXP.cjs');
5
- require('./chunk-WJIU4Q36.cjs');
3
+ var _chunkV7E5BH3Ycjs = require('./chunk-V7E5BH3Y.cjs');
4
+ require('./chunk-5RDO6MHS.cjs');
5
+ require('./chunk-OBGZSXTJ.cjs');
6
6
  require('./chunk-ZBPRDZS4.cjs');
7
7
 
8
8
  // src/nuxt.ts
9
9
  var _kit = require('@nuxt/kit');
10
10
  var nuxt_default = _kit.defineNuxtModule.call(void 0, {
11
11
  setup(options) {
12
- _kit.addWebpackPlugin.call(void 0, _chunkMB5VKJR2cjs.unplugin_default.webpack(options));
13
- _kit.addVitePlugin.call(void 0, _chunkMB5VKJR2cjs.unplugin_default.vite(options));
12
+ _kit.addWebpackPlugin.call(void 0, _chunkV7E5BH3Ycjs.unplugin_default.webpack(options));
13
+ _kit.addVitePlugin.call(void 0, _chunkV7E5BH3Ycjs.unplugin_default.vite(options));
14
14
  }
15
15
  });
16
16
 
package/dist/nuxt.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  unplugin_default
3
- } from "./chunk-WH3OXX67.js";
4
- import "./chunk-5LSX6IQN.js";
5
- import "./chunk-5JVO2UWC.js";
3
+ } from "./chunk-YOHL3P33.js";
4
+ import "./chunk-4KHLF5I7.js";
5
+ import "./chunk-3RG5ZIWI.js";
6
6
  import "./chunk-6F4PWJZI.js";
7
7
 
8
8
  // src/nuxt.ts