Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vite-plugin-components

Package Overview
Dependencies
Maintainers
1
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vite-plugin-components - npm Package Compare versions

Comparing version 0.11.2 to 0.11.4

32

dist/index.d.ts

@@ -109,11 +109,23 @@ import { Plugin } from 'vite';

/**
* Resolver for Ant Design Vue
*
* See https://github.com/antfu/vite-plugin-components/issues/26#issuecomment-789767941 for more details
*
* @author @yangss3
* @link https://antdv.com/
*/
declare const AntDesignVueResolver: () => ComponentResolver;
interface AntDesignVueResolverOptions {
/**
* import style along with components
*
* @default true
*/
importStyle?: boolean;
/**
* import css along with components
*
* @default true
*/
importCss?: boolean;
/**
* import less along with components
*
* @default false
*/
importLess?: boolean;
}
declare const AntDesignVueResolver: (options?: AntDesignVueResolverOptions) => ComponentResolver;

@@ -210,2 +222,2 @@ interface ElementPlusResolverOptions {

export default VitePluginComponents;
export { AntDesignVueResolver, ComponentInfo, ComponentResolveResult, ComponentResolver, ComponentsImportMap, ElementPlusResolver, ElementPlusResolverOptions, HeadlessUiResolver, ImportInfo, LibraryResolver, Matcher, NaiveUiResolver, Options, ResolvedOptions, Transformer, UILibraryOptions, VantResolver, VantResolverOptions, VarletUIResolver, VarletUIResolverOptions, VueUseComponentsResolver, VuetifyResolver, camelCase, kebabCase, pascalCase, tryLoadVeturTags };
export { AntDesignVueResolver, AntDesignVueResolverOptions, ComponentInfo, ComponentResolveResult, ComponentResolver, ComponentsImportMap, ElementPlusResolver, ElementPlusResolverOptions, HeadlessUiResolver, ImportInfo, LibraryResolver, Matcher, NaiveUiResolver, Options, ResolvedOptions, Transformer, UILibraryOptions, VantResolver, VantResolverOptions, VarletUIResolver, VarletUIResolverOptions, VueUseComponentsResolver, VuetifyResolver, camelCase, kebabCase, pascalCase, tryLoadVeturTags };

@@ -11,3 +11,3 @@ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var __create = Object.create;

var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {enumerable: true, configurable: true, writable: true, value}) : obj[key] = value;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {

@@ -25,3 +25,3 @@ for (var prop in b || (b = {}))

var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
var __require = (x) => {

@@ -33,3 +33,3 @@ if (typeof require !== "undefined")

var __commonJS = (cb, mod) => function __require2() {
return mod || (0, cb[Object.keys(cb)[0]])((mod = {exports: {}}).exports, mod), mod.exports;
return mod || (0, cb[Object.keys(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
};

@@ -40,3 +40,3 @@ var __reExport = (target, module, desc) => {

if (!__hasOwnProp.call(target, key) && key !== "default")
__defProp(target, key, {get: () => module[key], enumerable: !(desc = __getOwnPropDesc(module, key)) || desc.enumerable});
__defProp(target, key, { get: () => module[key], enumerable: !(desc = __getOwnPropDesc(module, key)) || desc.enumerable });
}

@@ -46,10 +46,10 @@ 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);
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);
};
// node_modules/.pnpm/@antfu+utils@0.2.1/node_modules/@antfu/utils/dist/index.js
// node_modules/.pnpm/@antfu+utils@0.2.4/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) {
"node_modules/.pnpm/@antfu+utils@0.2.4/node_modules/@antfu/utils/dist/index.js"(exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {value: true});
Object.defineProperty(exports, "__esModule", { value: true });
function clamp(n, min, max) {

@@ -127,5 +127,5 @@ return Math.min(max, Math.max(min, n));

}
var assert = (condition, ...infos) => {
var assert = (condition, message) => {
if (!condition)
throw new Error(...infos);
throw new Error(message);
};

@@ -221,2 +221,7 @@ var toString2 = Object.prototype.toString;

}
function hasOwnProperty(obj, v) {
if (obj == null)
return false;
return Object.prototype.hasOwnProperty.call(obj, v);
}
function createSingletonPromise(fn) {

@@ -304,2 +309,3 @@ let _promise;

exports.flattenArrayable = flattenArrayable;
exports.hasOwnProperty = hasOwnProperty;
exports.invoke = invoke;

@@ -387,3 +393,3 @@ exports.isBoolean = isBoolean;

const prefixKebab = kebabCase(prefix);
const kebabEntries = entries.map((name) => ({name, kebab: kebabCase(name)}));
const kebabEntries = entries.map((name) => ({ name, kebab: kebabCase(name) }));
return (name) => {

@@ -399,3 +405,3 @@ const kebab = kebabCase(name);

if (entry.kebab === componentName)
return {path: libraryName, importName: entry.name};
return { path: libraryName, importName: entry.name };
}

@@ -438,3 +444,3 @@ };

if (index < 0) {
return {path: id, query: {}};
return { path: id, query: {} };
} else {

@@ -471,3 +477,3 @@ const query = Object.fromEntries(new URLSearchParams(id.slice(index)));

}
function stringifyComponentImport({name, path, importName, sideEffects}, ctx) {
function stringifyComponentImport({ name, path, importName, sideEffects }, ctx) {
if (ctx.options.importPathTransform) {

@@ -479,3 +485,3 @@ const result = ctx.options.importPathTransform(path);

const imports = [
stringifyImport({name, path, importName})
stringifyImport({ name, path, importName })
];

@@ -488,3 +494,3 @@ if (sideEffects)

const resolved = Object.assign({}, defaultOptions, options);
resolved.libraries = (0, import_utils2.toArray)(resolved.libraries).map((i) => typeof i === "string" ? {name: i} : i);
resolved.libraries = (0, import_utils2.toArray)(resolved.libraries).map((i) => typeof i === "string" ? { name: i } : i);
resolved.customComponentResolvers = (0, import_utils2.toArray)(resolved.customComponentResolvers);

@@ -504,3 +510,3 @@ resolved.customComponentResolvers.push(...resolved.libraries.map((lib) => LibraryResolver(lib)));

function getNameFromFilePath(filePath, options) {
const {resolvedDirs, directoryAsNamespace, globalNamespaces} = options;
const { resolvedDirs, directoryAsNamespace, globalNamespaces } = options;
const parsedFilePath = _path.parse.call(void 0, (0, import_utils2.slash)(filePath));

@@ -535,3 +541,3 @@ let strippedPath = "";

if (Array.isArray(alias)) {
for (const {find, replacement} of alias)
for (const { find, replacement } of alias)
result.replace(find, replacement);

@@ -567,3 +573,3 @@ }

async function generateDeclaration(ctx, root, filepath) {
const lines = Object.values(__spreadValues(__spreadValues({}, ctx.componentNameMap), ctx.componentCustomMap)).map(({path, name, importName}) => {
const lines = Object.values(__spreadValues(__spreadValues({}, ctx.componentNameMap), ctx.componentCustomMap)).map(({ path, name, importName }) => {
if (!name)

@@ -613,5 +619,5 @@ return void 0;

this.options = resolveOptions(options, viteConfig);
const {globs, dirs} = this.options;
const { globs, dirs } = this.options;
if (viteConfig.command === "serve") {
_chokidar2.default.watch(dirs, {ignoreInitial: true, cwd: this.root}).on("unlink", (path) => {
_chokidar2.default.watch(dirs, { ignoreInitial: true, cwd: this.root }).on("unlink", (path) => {
if (matchGlobs(path, globs)) {

@@ -789,3 +795,3 @@ this.removeComponents(path);

const var_name = `__vite_components_${no}`;
head.push(stringifyComponentImport(__spreadProps(__spreadValues({}, component), {name: var_name}), ctx));
head.push(stringifyComponentImport(__spreadProps(__spreadValues({}, component), { name: var_name }), ctx));
no += 1;

@@ -800,5 +806,5 @@ s.overwrite(start, end, var_name);

`);
const result = {code: s.toString()};
const result = { code: s.toString() };
if (ctx.viteConfig.build.sourcemap)
result.map = s.generateMap({hires: true});
result.map = s.generateMap({ hires: true });
return result;

@@ -834,3 +840,3 @@ };

const var_name = `__vite_components_${no}`;
head.push(stringifyComponentImport(__spreadProps(__spreadValues({}, component), {name: var_name}), ctx));
head.push(stringifyComponentImport(__spreadProps(__spreadValues({}, component), { name: var_name }), ctx));
no += 1;

@@ -845,5 +851,5 @@ s.overwrite(start, end, `_c(${var_name}${append}`);

`);
const result = {code: s.toString()};
const result = { code: s.toString() };
if (ctx.viteConfig.build.sourcemap)
result.map = s.generateMap({hires: true});
result.map = s.generateMap({ hires: true });
return result;

@@ -854,10 +860,172 @@ };

// src/resolvers/antdv.ts
var AntDesignVueResolver = () => (name) => {
if (name.match(/^A[A-Z]/))
return {importName: name.slice(1), path: "ant-design-vue/es"};
var matchComponents = [
{
pattern: /^Avatar/,
styleDir: "avatar"
},
{
pattern: /^AutoComplete/,
styleDir: "auto-complete"
},
{
pattern: /^Anchor/,
styleDir: "anchor"
},
{
pattern: /^Badge/,
styleDir: "badge"
},
{
pattern: /^Breadcrumb/,
styleDir: "breadcrumb"
},
{
pattern: /^Button/,
styleDir: "button"
},
{
pattern: /^Checkbox/,
styleDir: "checkbox"
},
{
pattern: /^Card/,
styleDir: "card"
},
{
pattern: /^Collapse/,
styleDir: "collapse"
},
{
pattern: /^Descriptions/,
styleDir: "descriptions"
},
{
pattern: /^RangePicker|^WeekPicker|^MonthPicker/,
styleDir: "date-picker"
},
{
pattern: /^Dropdown/,
styleDir: "dropdown"
},
{
pattern: /^Form/,
styleDir: "form"
},
{
pattern: /^InputNumber/,
styleDir: "input-number"
},
{
pattern: /^Input|^Textarea/,
styleDir: "input"
},
{
pattern: /^Statistic/,
styleDir: "statistic"
},
{
pattern: /^CheckableTag/,
styleDir: "tag"
},
{
pattern: /^Layout/,
styleDir: "layout"
},
{
pattern: /^Menu|^SubMenu/,
styleDir: "menu"
},
{
pattern: /^Table/,
styleDir: "table"
},
{
pattern: /^Radio/,
styleDir: "radio"
},
{
pattern: /^Image/,
styleDir: "image"
},
{
pattern: /^List/,
styleDir: "list"
},
{
pattern: /^Tab/,
styleDir: "tabs"
},
{
pattern: /^Mentions/,
styleDir: "mentions"
},
{
pattern: /^Step/,
styleDir: "steps"
},
{
pattern: /^Skeleton/,
styleDir: "skeleton"
},
{
pattern: /^Select/,
styleDir: "select"
},
{
pattern: /^TreeSelect/,
styleDir: "tree-select"
},
{
pattern: /^Tree|^DirectoryTree/,
styleDir: "tree"
},
{
pattern: /^Typography/,
styleDir: "typography"
},
{
pattern: /^Timeline/,
styleDir: "timeline"
}
];
var getStyleDir = (compName) => {
let styleDir;
const total = matchComponents.length;
for (let i = 0; i < total; i++) {
const matcher = matchComponents[i];
if (compName.match(matcher.pattern)) {
styleDir = matcher.styleDir;
break;
}
}
if (!styleDir)
styleDir = kebabCase(compName);
return styleDir;
};
var getSideEffects = (compName, opts) => {
const { importStyle = true, importCss = true, importLess = false } = opts;
if (importStyle) {
if (importLess) {
const styleDir = getStyleDir(compName);
return `ant-design-vue/es/${styleDir}/style`;
} else if (importCss) {
const styleDir = getStyleDir(compName);
return `ant-design-vue/es/${styleDir}/style/css`;
}
}
};
var AntDesignVueResolver = (options = {}) => (name) => {
if (name.match(/^A[A-Z]/)) {
const importName = name.slice(1);
return {
importName,
path: "ant-design-vue/es",
sideEffects: getSideEffects(importName, options)
};
}
};
// src/resolvers/element-plus.ts
var ElementPlusResolver = (options = {}) => (name) => {
const {importStyle = true} = options;
const { importStyle = true } = options;
if (name.startsWith("El")) {

@@ -911,3 +1079,3 @@ const partialName = name[2].toLowerCase() + name.substring(3).replace(/[A-Z]/g, (l) => `-${l.toLowerCase()}`);

if (components.includes(name))
return {importName: name, path: "@headlessui/vue"};
return { importName: name, path: "@headlessui/vue" };
};

@@ -917,3 +1085,3 @@

var VantResolver = (options = {}) => (name) => {
const {importStyle = true} = options;
const { importStyle = true } = options;
if (name.startsWith("Van")) {

@@ -932,3 +1100,3 @@ const partialName = name.slice(3);

if (name.match(/^V[A-Z]/))
return {importName: name, path: "vuetify/lib"};
return { importName: name, path: "vuetify/lib" };
};

@@ -942,3 +1110,3 @@

const indexesJson = __require("@vueuse/core/indexes.json");
components2 = indexesJson.functions.filter((i) => i.component && i.name).map(({name: name2}) => name2[0].toUpperCase() + name2.slice(1));
components2 = indexesJson.functions.filter((i) => i.component && i.name).map(({ name: name2 }) => name2[0].toUpperCase() + name2.slice(1));
} catch (error) {

@@ -949,3 +1117,3 @@ components2 = [];

if (components2 && components2.includes(name))
return {importName: name, path: "@vueuse/components"};
return { importName: name, path: "@vueuse/components" };
};

@@ -956,3 +1124,3 @@

if (name.match(/^N[A-Z]/))
return {importName: name, path: "naive-ui"};
return { importName: name, path: "naive-ui" };
};

@@ -970,3 +1138,3 @@

importName: partialName,
path: "@varlet/ui/es",
path: "@varlet/ui",
sideEffects: importLess ? `@varlet/ui/es/${kebabCase(partialName)}/style/less.js` : importCss ? `@varlet/ui/es/${kebabCase(partialName)}/style` : void 0

@@ -998,3 +1166,3 @@ };

async transform(code, id) {
const {path, query} = parseId(id);
const { path, query } = parseId(id);
const result = await transformer(code, id, path, query);

@@ -1001,0 +1169,0 @@ ctx.generateDeclaration();

{
"name": "vite-plugin-components",
"version": "0.11.2",
"version": "0.11.4",
"description": "Components auto importing for Vite",

@@ -26,3 +26,3 @@ "homepage": "https://github.com/antfu/vite-plugin-components",

"prepublishOnly": "npm run build",
"release": "npx git-ensure -a && npx bumpp --commit --tag --push",
"release": "npx bumpp --commit --tag --push",
"test": "jest",

@@ -32,8 +32,8 @@ "test:update": "jest --u"

"peerDependencies": {
"vite": "^2.0.0-beta.69"
"vite": "^2.0.0"
},
"dependencies": {
"chokidar": "^3.5.1",
"chokidar": "^3.5.2",
"debug": "^4.3.2",
"fast-glob": "^3.2.5",
"fast-glob": "^3.2.6",
"magic-string": "^0.25.7",

@@ -44,17 +44,17 @@ "minimatch": "^3.0.4"

"@antfu/eslint-config": "^0.6.6",
"@antfu/utils": "^0.2.1",
"@antfu/utils": "^0.2.4",
"@types/debug": "^4.1.5",
"@types/jest": "^26.0.23",
"@types/minimatch": "^3.0.4",
"@types/node": "^15.12.2",
"@typescript-eslint/eslint-plugin": "^4.26.1",
"eslint": "^7.28.0",
"jest": "^27.0.4",
"rollup": "^2.51.2",
"@types/node": "^15.12.5",
"@typescript-eslint/eslint-plugin": "^4.28.1",
"eslint": "^7.29.0",
"jest": "^27.0.6",
"rollup": "^2.52.3",
"standard-version": "^9.3.0",
"ts-jest": "^27.0.3",
"tsup": "^4.11.2",
"typescript": "^4.3.2",
"vite": "^2.3.7"
"tsup": "^4.12.0",
"typescript": "^4.3.4",
"vite": "^2.3.8"
}
}

@@ -107,2 +107,4 @@ <h2 align='center'><samp>vite-plugin-components</samp></h2>

**Make sure you also add `components.d.ts` to your `tsconfig.json` under `includes`.**
## Vue 2 Support

@@ -134,3 +136,3 @@

- [Headless UI](https://github.com/antfu/vite-plugin-components/blob/master/src/resolvers/headless-ui.ts)
- [Native UI](https://github.com/antfu/vite-plugin-components/blob/master/src/resolvers/naive-ui.ts)
- [Naive UI](https://github.com/antfu/vite-plugin-components/blob/master/src/resolvers/naive-ui.ts)
- [Vant](https://github.com/antfu/vite-plugin-components/blob/master/src/resolvers/vant.ts)

@@ -137,0 +139,0 @@ - [Varlet UI](https://github.com/antfu/vite-plugin-components/blob/master/src/resolvers/varlet-ui.ts)

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc