vite-plugin-components
Advanced tools
Comparing version 0.10.4 to 0.11.0
@@ -87,2 +87,8 @@ import { Plugin } from 'vite'; | ||
globalComponentsDeclaration?: boolean | string; | ||
/** | ||
* Do not emit warning on component overriding | ||
* | ||
* @default false | ||
*/ | ||
allowOverrides?: boolean; | ||
} | ||
@@ -96,2 +102,4 @@ declare type ResolvedOptions = Omit<Required<Options>, 'customComponentResolvers' | 'libraries' | 'extensions' | 'dirs'> & { | ||
globs: string[]; | ||
globalComponentsDeclaration: string | false; | ||
root: string; | ||
}; | ||
@@ -167,2 +175,10 @@ declare type ComponentsImportMap = Record<string, string[] | undefined>; | ||
/** | ||
* Resolver for Naive UI | ||
* | ||
* @author @antfu | ||
* @link https://www.naiveui.com/ | ||
*/ | ||
declare const NaiveUiResolver: () => ComponentResolver; | ||
declare function pascalCase(str: string): string; | ||
@@ -175,2 +191,2 @@ declare function camelCase(str: string): string; | ||
export default VitePluginComponents; | ||
export { AntDesignVueResolver, ComponentInfo, ComponentResolveResult, ComponentResolver, ComponentsImportMap, ElementPlusResolver, ElementPlusResolverOptions, HeadlessUiResolver, ImportInfo, LibraryResolver, Matcher, Options, ResolvedOptions, Transformer, UILibraryOptions, VantResolver, VantResolverOptions, VueUseComponentsResolver, VuetifyResolver, camelCase, kebabCase, pascalCase, tryLoadVeturTags }; | ||
export { AntDesignVueResolver, ComponentInfo, ComponentResolveResult, ComponentResolver, ComponentsImportMap, ElementPlusResolver, ElementPlusResolverOptions, HeadlessUiResolver, ImportInfo, LibraryResolver, Matcher, NaiveUiResolver, Options, ResolvedOptions, Transformer, UILibraryOptions, VantResolver, VantResolverOptions, VueUseComponentsResolver, VuetifyResolver, camelCase, kebabCase, pascalCase, tryLoadVeturTags }; |
@@ -1,5 +0,9 @@ | ||
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var __defProp = Object.defineProperty; | ||
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var __create = Object.create; | ||
var __defProp = Object.defineProperty; | ||
var __defProps = Object.defineProperties; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropDescs = Object.getOwnPropertyDescriptors; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __getOwnPropSymbols = Object.getOwnPropertySymbols; | ||
var __getProtoOf = Object.getPrototypeOf; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
@@ -20,2 +24,3 @@ var __propIsEnum = Object.prototype.propertyIsEnumerable; | ||
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b)); | ||
var __markAsModule = (target) => __defProp(target, "__esModule", {value: true}); | ||
var __require = (x) => { | ||
@@ -26,8 +31,309 @@ if (typeof require !== "undefined") | ||
}; | ||
var __commonJS = (cb, mod) => function __require2() { | ||
return mod || (0, cb[Object.keys(cb)[0]])((mod = {exports: {}}).exports, mod), mod.exports; | ||
}; | ||
var __reExport = (target, module, desc) => { | ||
if (module && typeof module === "object" || typeof module === "function") { | ||
for (let key of __getOwnPropNames(module)) | ||
if (!__hasOwnProp.call(target, key) && key !== "default") | ||
__defProp(target, key, {get: () => module[key], enumerable: !(desc = __getOwnPropDesc(module, key)) || desc.enumerable}); | ||
} | ||
return target; | ||
}; | ||
var __toModule = (module) => { | ||
return __reExport(__markAsModule(__defProp(module != null ? __create(__getProtoOf(module)) : {}, "default", module && module.__esModule && "default" in module ? {get: () => module.default, enumerable: true} : {value: module, enumerable: true})), module); | ||
}; | ||
// src/index.ts | ||
var _path = require('path'); | ||
// node_modules/.pnpm/@antfu+utils@0.2.1/node_modules/@antfu/utils/dist/index.js | ||
var require_dist = __commonJS({ | ||
"node_modules/.pnpm/@antfu+utils@0.2.1/node_modules/@antfu/utils/dist/index.js"(exports) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", {value: true}); | ||
function clamp(n, min, max) { | ||
return Math.min(max, Math.max(min, n)); | ||
} | ||
function sum(...args) { | ||
return flattenArrayable(args).reduce((a, b) => a + b, 0); | ||
} | ||
function toArray2(array) { | ||
array = array || []; | ||
if (Array.isArray(array)) | ||
return array; | ||
return [array]; | ||
} | ||
function flattenArrayable(array) { | ||
return toArray2(array).flat(1); | ||
} | ||
function mergeArrayable(...args) { | ||
return args.flatMap((i) => toArray2(i)); | ||
} | ||
function partition(array, filter) { | ||
const pass = []; | ||
const fail = []; | ||
array.forEach((e, idx, arr) => (filter(e, idx, arr) ? pass : fail).push(e)); | ||
return [pass, fail]; | ||
} | ||
function uniq(array) { | ||
return Array.from(new Set(array)); | ||
} | ||
function last(array) { | ||
return at(array, -1); | ||
} | ||
function remove(array, value) { | ||
if (!array) | ||
return false; | ||
const index = array.indexOf(value); | ||
if (index >= 0) { | ||
array.splice(index, 1); | ||
return true; | ||
} | ||
return false; | ||
} | ||
function at(array, index) { | ||
const len = array.length; | ||
if (!len) | ||
return void 0; | ||
if (index < 0) | ||
index += len; | ||
return array[index]; | ||
} | ||
function range(...args) { | ||
let start, stop, step; | ||
if (args.length === 1) { | ||
start = 0; | ||
step = 1; | ||
[stop] = args; | ||
} else { | ||
[start, stop, step = 1] = args; | ||
} | ||
const arr = []; | ||
let current = start; | ||
while (current < stop) { | ||
arr.push(current); | ||
current += step || 1; | ||
} | ||
return arr; | ||
} | ||
function move(arr, from, to) { | ||
arr.splice(to, 0, arr.splice(from, 1)[0]); | ||
return arr; | ||
} | ||
function clampArrayRange(n, arr) { | ||
return clamp(n, 0, arr.length - 1); | ||
} | ||
var assert = (condition, ...infos) => { | ||
if (!condition) | ||
throw new Error(...infos); | ||
}; | ||
var toString2 = Object.prototype.toString; | ||
var noop = () => { | ||
}; | ||
function notNullish(v) { | ||
return v != null; | ||
} | ||
function noNull(v) { | ||
return v !== null; | ||
} | ||
function notUndefined(v) { | ||
return v !== void 0; | ||
} | ||
function isTruthy(v) { | ||
return Boolean(v); | ||
} | ||
var isBrowser = typeof window !== "undefined"; | ||
var isDef = (val) => typeof val !== "undefined"; | ||
var isBoolean = (val) => typeof val === "boolean"; | ||
var isFunction = (val) => typeof val === "function"; | ||
var isNumber = (val) => typeof val === "number"; | ||
var isString = (val) => typeof val === "string"; | ||
var isObject = (val) => toString.call(val) === "[object Object]"; | ||
var isWindow = (val) => typeof window !== "undefined" && toString.call(val) === "[object Window]"; | ||
function slash2(str) { | ||
return str.replace(/\\/g, "/"); | ||
} | ||
function ensurePrefix(prefix, str) { | ||
if (!str.startsWith(prefix)) | ||
return prefix + str; | ||
return str; | ||
} | ||
var timestamp = () => +Date.now(); | ||
function batchInvoke(functions) { | ||
functions.forEach((fn) => fn && fn()); | ||
} | ||
function invoke(fn) { | ||
return fn(); | ||
} | ||
function tap(value, callback) { | ||
callback(value); | ||
return value; | ||
} | ||
function objectMap(obj, fn) { | ||
return Object.fromEntries(Object.entries(obj).map(([k, v]) => fn(k, v)).filter(notNullish)); | ||
} | ||
function isKeyOf(obj, k) { | ||
return k in obj; | ||
} | ||
function objectKeys(obj) { | ||
return Object.keys(obj); | ||
} | ||
function objectEntries(obj) { | ||
return Object.entries(obj); | ||
} | ||
function deepMerge(target, ...sources) { | ||
if (!sources.length) | ||
return target; | ||
const source = sources.shift(); | ||
if (source === void 0) | ||
return target; | ||
if (isMergableObject(target) && isMergableObject(source)) { | ||
objectKeys(source).forEach((key) => { | ||
if (isMergableObject(source[key])) { | ||
if (!target[key]) | ||
target[key] = {}; | ||
deepMerge(target[key], source[key]); | ||
} else { | ||
target[key] = source[key]; | ||
} | ||
}); | ||
} | ||
return deepMerge(target, ...sources); | ||
} | ||
function isMergableObject(item) { | ||
return isObject(item) && !Array.isArray(item); | ||
} | ||
function objectPick(obj, keys, omitUndefined = false) { | ||
return keys.reduce((n, k) => { | ||
if (k in obj) { | ||
if (!omitUndefined || !obj[k] === void 0) | ||
n[k] = obj[k]; | ||
} | ||
return n; | ||
}, {}); | ||
} | ||
function clearUndefined(obj) { | ||
Object.keys(obj).forEach((key) => obj[key] === void 0 ? delete obj[key] : {}); | ||
return obj; | ||
} | ||
function createSingletonPromise(fn) { | ||
let _promise; | ||
function wrapper() { | ||
if (!_promise) | ||
_promise = fn(); | ||
return _promise; | ||
} | ||
wrapper.reset = async () => { | ||
const _prev = _promise; | ||
_promise = void 0; | ||
if (_prev) | ||
await _prev; | ||
}; | ||
return wrapper; | ||
} | ||
function sleep(ms, callback) { | ||
return new Promise((resolve3) => setTimeout(async () => { | ||
await (callback == null ? void 0 : callback()); | ||
resolve3(); | ||
}, ms)); | ||
} | ||
function throttle2(delay, noTrailing, callback, debounceMode) { | ||
var timeoutID; | ||
var cancelled = false; | ||
var lastExec = 0; | ||
function clearExistingTimeout() { | ||
if (timeoutID) { | ||
clearTimeout(timeoutID); | ||
} | ||
} | ||
function cancel() { | ||
clearExistingTimeout(); | ||
cancelled = true; | ||
} | ||
if (typeof noTrailing !== "boolean") { | ||
debounceMode = callback; | ||
callback = noTrailing; | ||
noTrailing = void 0; | ||
} | ||
function wrapper() { | ||
for (var _len = arguments.length, arguments_ = new Array(_len), _key = 0; _key < _len; _key++) { | ||
arguments_[_key] = arguments[_key]; | ||
} | ||
var self = this; | ||
var elapsed = Date.now() - lastExec; | ||
if (cancelled) { | ||
return; | ||
} | ||
function exec() { | ||
lastExec = Date.now(); | ||
callback.apply(self, arguments_); | ||
} | ||
function clear() { | ||
timeoutID = void 0; | ||
} | ||
if (debounceMode && !timeoutID) { | ||
exec(); | ||
} | ||
clearExistingTimeout(); | ||
if (debounceMode === void 0 && elapsed > delay) { | ||
exec(); | ||
} else if (noTrailing !== true) { | ||
timeoutID = setTimeout(debounceMode ? clear : exec, debounceMode === void 0 ? delay - elapsed : delay); | ||
} | ||
} | ||
wrapper.cancel = cancel; | ||
return wrapper; | ||
} | ||
function debounce(delay, atBegin, callback) { | ||
return callback === void 0 ? throttle2(delay, atBegin, false) : throttle2(delay, callback, atBegin !== false); | ||
} | ||
exports.assert = assert; | ||
exports.at = at; | ||
exports.batchInvoke = batchInvoke; | ||
exports.clamp = clamp; | ||
exports.clampArrayRange = clampArrayRange; | ||
exports.clearUndefined = clearUndefined; | ||
exports.createSingletonPromise = createSingletonPromise; | ||
exports.debounce = debounce; | ||
exports.deepMerge = deepMerge; | ||
exports.ensurePrefix = ensurePrefix; | ||
exports.flattenArrayable = flattenArrayable; | ||
exports.invoke = invoke; | ||
exports.isBoolean = isBoolean; | ||
exports.isBrowser = isBrowser; | ||
exports.isDef = isDef; | ||
exports.isFunction = isFunction; | ||
exports.isKeyOf = isKeyOf; | ||
exports.isNumber = isNumber; | ||
exports.isObject = isObject; | ||
exports.isString = isString; | ||
exports.isTruthy = isTruthy; | ||
exports.isWindow = isWindow; | ||
exports.last = last; | ||
exports.mergeArrayable = mergeArrayable; | ||
exports.move = move; | ||
exports.noNull = noNull; | ||
exports.noop = noop; | ||
exports.notNullish = notNullish; | ||
exports.notUndefined = notUndefined; | ||
exports.objectEntries = objectEntries; | ||
exports.objectKeys = objectKeys; | ||
exports.objectMap = objectMap; | ||
exports.objectPick = objectPick; | ||
exports.partition = partition; | ||
exports.range = range; | ||
exports.remove = remove; | ||
exports.slash = slash2; | ||
exports.sleep = sleep; | ||
exports.sum = sum; | ||
exports.tap = tap; | ||
exports.throttle = throttle2; | ||
exports.timestamp = timestamp; | ||
exports.toArray = toArray2; | ||
exports.toString = toString2; | ||
exports.uniq = uniq; | ||
} | ||
}); | ||
// src/context.ts | ||
var import_utils4 = __toModule(require_dist()); | ||
var _path = require('path'); | ||
var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug); | ||
@@ -37,2 +343,3 @@ var _chokidar = require('chokidar'); var _chokidar2 = _interopRequireDefault(_chokidar); | ||
// src/utils.ts | ||
var import_utils2 = __toModule(require_dist()); | ||
@@ -103,9 +410,7 @@ var _minimatch = require('minimatch'); var _minimatch2 = _interopRequireDefault(_minimatch); | ||
customComponentResolvers: [], | ||
importPathTransform: (v) => v | ||
importPathTransform: (v) => v, | ||
allowOverrides: false | ||
}; | ||
// src/utils.ts | ||
function slash(str) { | ||
return str.replace(/\\/g, "/"); | ||
} | ||
function pascalCase(str) { | ||
@@ -124,7 +429,2 @@ return capitalize(camelCase(str)); | ||
} | ||
function toArray(arr) { | ||
if (Array.isArray(arr)) | ||
return arr; | ||
return [arr]; | ||
} | ||
function parseId(id) { | ||
@@ -150,3 +450,3 @@ const index = id.indexOf("?"); | ||
for (const glob of globs) { | ||
if (_minimatch2.default.call(void 0, slash(filepath), glob)) | ||
if (_minimatch2.default.call(void 0, (0, import_utils2.slash)(filepath), glob)) | ||
return true; | ||
@@ -176,3 +476,3 @@ } | ||
if (sideEffects) | ||
toArray(sideEffects).forEach((i) => imports.push(stringifyImport(i))); | ||
(0, import_utils2.toArray)(sideEffects).forEach((i) => imports.push(stringifyImport(i))); | ||
return imports.join("\n"); | ||
@@ -182,12 +482,14 @@ } | ||
const resolved = Object.assign({}, defaultOptions, options); | ||
resolved.libraries = toArray(resolved.libraries).map((i) => typeof i === "string" ? {name: i} : i); | ||
resolved.customComponentResolvers = toArray(resolved.customComponentResolvers); | ||
resolved.libraries = (0, import_utils2.toArray)(resolved.libraries).map((i) => typeof i === "string" ? {name: i} : i); | ||
resolved.customComponentResolvers = (0, import_utils2.toArray)(resolved.customComponentResolvers); | ||
resolved.customComponentResolvers.push(...resolved.libraries.map((lib) => LibraryResolver(lib))); | ||
resolved.extensions = toArray(resolved.extensions); | ||
resolved.extensions = (0, import_utils2.toArray)(resolved.extensions); | ||
const extsGlob = resolved.extensions.length === 1 ? resolved.extensions : `{${resolved.extensions.join(",")}}`; | ||
resolved.dirs = toArray(resolved.dirs); | ||
resolved.resolvedDirs = resolved.dirs.map((i) => slash(_path.resolve.call(void 0, viteConfig.root, i))); | ||
resolved.globs = resolved.dirs.map((i) => resolved.deep ? slash(_path.join.call(void 0, i, `**/*.${extsGlob}`)) : slash(_path.join.call(void 0, i, `*.${extsGlob}`))); | ||
resolved.dirs = (0, import_utils2.toArray)(resolved.dirs); | ||
resolved.resolvedDirs = resolved.dirs.map((i) => (0, import_utils2.slash)(_path.resolve.call(void 0, viteConfig.root, i))); | ||
resolved.globs = resolved.dirs.map((i) => resolved.deep ? (0, import_utils2.slash)(_path.join.call(void 0, i, `**/*.${extsGlob}`)) : (0, import_utils2.slash)(_path.join.call(void 0, i, `*.${extsGlob}`))); | ||
if (!resolved.extensions.length) | ||
throw new Error("[vite-plugin-components] extensions are required to search for components"); | ||
resolved.globalComponentsDeclaration = !options.globalComponentsDeclaration ? false : _path.resolve.call(void 0, viteConfig.root, typeof options.globalComponentsDeclaration === "string" ? options.globalComponentsDeclaration : "components.d.ts"); | ||
resolved.root = viteConfig.root; | ||
return resolved; | ||
@@ -197,3 +499,3 @@ } | ||
const {resolvedDirs, directoryAsNamespace, globalNamespaces} = options; | ||
const parsedFilePath = _path.parse.call(void 0, slash(filePath)); | ||
const parsedFilePath = _path.parse.call(void 0, (0, import_utils2.slash)(filePath)); | ||
let strippedPath = ""; | ||
@@ -253,2 +555,31 @@ for (const dir of resolvedDirs) { | ||
// src/declaration.ts | ||
async function generateDeclaration(ctx, root, filepath) { | ||
const lines = Object.values(__spreadValues(__spreadValues({}, ctx.componentNameMap), ctx.componentCustomMap)).map(({path, name, importName}) => { | ||
const related = (0, import_utils2.slash)(path).startsWith("/") ? `./${_path.relative.call(void 0, _path.dirname.call(void 0, filepath), _path.resolve.call(void 0, root, path.slice(1)))}` : path; | ||
let entry = `${name}: typeof import('${(0, import_utils2.slash)(related)}')`; | ||
if (importName) | ||
entry += `['${importName}']`; | ||
else | ||
entry += "['default']"; | ||
return entry; | ||
}); | ||
if (!lines.length) | ||
return; | ||
const code = `// generated by vite-plugin-components | ||
// read more https://github.com/vuejs/vue-next/pull/3399 | ||
declare module 'vue' { | ||
export interface GlobalComponents { | ||
${lines.join("\n ")} | ||
} | ||
} | ||
export { } | ||
`; | ||
await _fs.promises.writeFile(filepath, code, "utf-8"); | ||
} | ||
// src/context.ts | ||
@@ -258,3 +589,4 @@ var debug3 = { | ||
search: _debug2.default.call(void 0, "vite-plugin-components:context:search"), | ||
hmr: _debug2.default.call(void 0, "vite-plugin-components:context:hmr") | ||
hmr: _debug2.default.call(void 0, "vite-plugin-components:context:hmr"), | ||
decleration: _debug2.default.call(void 0, "vite-plugin-components:decleration") | ||
}; | ||
@@ -267,2 +599,3 @@ var Context = class { | ||
this._componentUsageMap = {}; | ||
this._componentCustomMap = {}; | ||
this._searched = false; | ||
@@ -284,2 +617,3 @@ this.options = resolveOptions(options, viteConfig); | ||
} | ||
this.generateDeclaration = (0, import_utils4.throttle)(500, false, this.generateDeclaration.bind(this)); | ||
} | ||
@@ -302,3 +636,3 @@ get root() { | ||
const size = this._componentPaths.size; | ||
toArray(paths).forEach((p) => this._componentPaths.add(p)); | ||
(0, import_utils2.toArray)(paths).forEach((p) => this._componentPaths.add(p)); | ||
if (this._componentPaths.size !== size) { | ||
@@ -310,6 +644,10 @@ this.updateComponentNameMap(); | ||
} | ||
addCustomComponents(info) { | ||
if (info.name) | ||
this._componentCustomMap[info.name] = info; | ||
} | ||
removeComponents(paths) { | ||
debug3.components("remove", paths); | ||
const size = this._componentPaths.size; | ||
toArray(paths).forEach((p) => this._componentPaths.delete(p)); | ||
(0, import_utils2.toArray)(paths).forEach((p) => this._componentPaths.delete(p)); | ||
if (this._componentPaths.size !== size) { | ||
@@ -332,3 +670,3 @@ this.updateComponentNameMap(); | ||
if (values.has(name)) { | ||
const r = `/${slash(_path.relative.call(void 0, this.viteConfig.root, key))}`; | ||
const r = `/${(0, import_utils2.slash)(_path.relative.call(void 0, this.viteConfig.root, key))}`; | ||
payload.updates.push({ | ||
@@ -344,2 +682,3 @@ acceptedPath: r, | ||
this._server.ws.send(payload); | ||
this.generateDeclaration(); | ||
} | ||
@@ -350,3 +689,3 @@ updateComponentNameMap() { | ||
const name = pascalCase(getNameFromFilePath(path, this.options)); | ||
if (this._componentNameMap[name]) { | ||
if (this._componentNameMap[name] && !this.options.allowOverrides) { | ||
console.warn(`[vite-plugin-components] component "${name}"(${path}) has naming conflicts with other components, ignored.`); | ||
@@ -362,3 +701,3 @@ return; | ||
findComponent(name, excludePaths = []) { | ||
const info = this._componentNameMap[name]; | ||
let info = this._componentNameMap[name]; | ||
if (info && !excludePaths.includes(info.path) && !excludePaths.includes(info.path.slice(1))) | ||
@@ -370,10 +709,14 @@ return info; | ||
if (typeof result === "string") { | ||
return { | ||
info = { | ||
name, | ||
path: result | ||
}; | ||
this.addCustomComponents(info); | ||
return info; | ||
} else { | ||
return __spreadValues({ | ||
info = __spreadValues({ | ||
name | ||
}, result); | ||
this.addCustomComponents(info); | ||
return info; | ||
} | ||
@@ -393,4 +736,4 @@ } | ||
if (path.startsWith("/") && !path.startsWith(this.root)) | ||
return slash(path.slice(1)); | ||
return slash(_path.relative.call(void 0, this.root, path)); | ||
return (0, import_utils2.slash)(path.slice(1)); | ||
return (0, import_utils2.slash)(_path.relative.call(void 0, this.root, path)); | ||
} | ||
@@ -404,5 +747,14 @@ searchGlob() { | ||
} | ||
generateDeclaration() { | ||
if (!this.options.globalComponentsDeclaration) | ||
return; | ||
debug3.decleration("generating"); | ||
generateDeclaration(this, this.options.root, this.options.globalComponentsDeclaration); | ||
} | ||
get componentNameMap() { | ||
return this._componentNameMap; | ||
} | ||
get componentCustomMap() { | ||
return this._componentCustomMap; | ||
} | ||
}; | ||
@@ -496,29 +848,2 @@ | ||
// src/declaration.ts | ||
var _promises = require('fs/promises'); var _promises2 = _interopRequireDefault(_promises); | ||
async function generateDeclaration(ctx, root, filepath) { | ||
const lines = Object.values(ctx.componentNameMap).map(({path, name, importName}) => { | ||
const related = slash(path).startsWith("/") ? `./${_path.relative.call(void 0, _path.dirname.call(void 0, filepath), _path.resolve.call(void 0, root, path.slice(1)))}` : path; | ||
let entry = `${name}: typeof import('${slash(related)}')`; | ||
if (importName) | ||
entry += `['${importName}']`; | ||
else | ||
entry += "['default']"; | ||
return entry; | ||
}); | ||
const code = `// generated by vite-plugin-components | ||
// read more https://github.com/vuejs/vue-next/pull/3399 | ||
declare module 'vue' { | ||
export interface GlobalComponents { | ||
${lines.join("\n ")} | ||
} | ||
} | ||
export { } | ||
`; | ||
await _promises2.default.writeFile(filepath, code, "utf-8"); | ||
} | ||
// src/resolvers/antdv.ts | ||
@@ -542,3 +867,3 @@ var AntDesignVueResolver = () => (name) => { | ||
// src/resolvers/headlessUi.ts | ||
// src/resolvers/headless-ui.ts | ||
var components = [ | ||
@@ -619,2 +944,8 @@ "Dialog", | ||
// src/resolvers/naive-ui.ts | ||
var NaiveUiResolver = () => (name) => { | ||
if (name.match(/^N[A-Z]/)) | ||
return {importName: name, path: "naive-ui"}; | ||
}; | ||
// src/index.ts | ||
@@ -634,4 +965,3 @@ function VitePluginComponents(options = {}) { | ||
ctx.searchGlob(); | ||
const path = _path.resolve.call(void 0, config.root, typeof options.globalComponentsDeclaration === "string" ? options.globalComponentsDeclaration : "components.d.ts"); | ||
generateDeclaration(ctx, config.root, path); | ||
ctx.generateDeclaration(); | ||
} | ||
@@ -642,5 +972,7 @@ }, | ||
}, | ||
transform(code, id) { | ||
async transform(code, id) { | ||
const {path, query} = parseId(id); | ||
return transformer(code, id, path, query); | ||
const result = await transformer(code, id, path, query); | ||
ctx.generateDeclaration(); | ||
return result; | ||
} | ||
@@ -663,2 +995,3 @@ }; | ||
exports.AntDesignVueResolver = AntDesignVueResolver; exports.ElementPlusResolver = ElementPlusResolver; exports.HeadlessUiResolver = HeadlessUiResolver; exports.LibraryResolver = LibraryResolver; exports.VantResolver = VantResolver; exports.VueUseComponentsResolver = VueUseComponentsResolver; exports.VuetifyResolver = VuetifyResolver; exports.camelCase = camelCase; exports.default = src_default; exports.kebabCase = kebabCase; exports.pascalCase = pascalCase; exports.tryLoadVeturTags = tryLoadVeturTags; | ||
exports.AntDesignVueResolver = AntDesignVueResolver; exports.ElementPlusResolver = ElementPlusResolver; exports.HeadlessUiResolver = HeadlessUiResolver; exports.LibraryResolver = LibraryResolver; exports.NaiveUiResolver = NaiveUiResolver; exports.VantResolver = VantResolver; exports.VueUseComponentsResolver = VueUseComponentsResolver; exports.VuetifyResolver = VuetifyResolver; exports.camelCase = camelCase; exports.default = src_default; exports.kebabCase = kebabCase; exports.pascalCase = pascalCase; exports.tryLoadVeturTags = tryLoadVeturTags; |
{ | ||
"name": "vite-plugin-components", | ||
"version": "0.10.4", | ||
"version": "0.11.0", | ||
"description": "Components auto importing for Vite", | ||
"homepage": "https://github.com/antfu/vite-plugin-components", | ||
"bugs": "https://github.com/antfu/vite-plugin-components/issues", | ||
"license": "MIT", | ||
"repository": { | ||
@@ -12,10 +13,9 @@ "type": "git", | ||
"funding": "https://github.com/sponsors/antfu", | ||
"license": "MIT", | ||
"author": "antfu <anthonyfu117@hotmail.com>", | ||
"files": [ | ||
"dist" | ||
], | ||
"main": "dist/index.js", | ||
"module": "dist/index.mjs", | ||
"types": "dist/index.d.ts", | ||
"files": [ | ||
"dist" | ||
], | ||
"scripts": { | ||
@@ -31,2 +31,5 @@ "build": "tsup src/index.ts --dts --format cjs,esm", | ||
}, | ||
"peerDependencies": { | ||
"vite": "^2.0.0-beta.69" | ||
}, | ||
"dependencies": { | ||
@@ -40,20 +43,18 @@ "chokidar": "^3.5.1", | ||
"devDependencies": { | ||
"@antfu/eslint-config": "^0.6.5", | ||
"@antfu/eslint-config": "^0.6.6", | ||
"@antfu/utils": "^0.2.1", | ||
"@types/debug": "^4.1.5", | ||
"@types/jest": "^26.0.23", | ||
"@types/minimatch": "^3.0.4", | ||
"@types/node": "^15.6.1", | ||
"@typescript-eslint/eslint-plugin": "^4.25.0", | ||
"eslint": "^7.27.0", | ||
"jest": "^27.0.1", | ||
"rollup": "^2.50.2", | ||
"@types/node": "^15.12.2", | ||
"@typescript-eslint/eslint-plugin": "^4.26.1", | ||
"eslint": "^7.28.0", | ||
"jest": "^27.0.4", | ||
"rollup": "^2.51.2", | ||
"standard-version": "^9.3.0", | ||
"ts-jest": "^27.0.1", | ||
"tsup": "^4.11.1", | ||
"ts-jest": "^27.0.3", | ||
"tsup": "^4.11.2", | ||
"typescript": "^4.3.2", | ||
"vite": "^2.3.4" | ||
}, | ||
"peerDependencies": { | ||
"vite": "^2.0.0-beta.69" | ||
"vite": "^2.3.7" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
75341
2051
5
15