UI优化完善初版
This commit is contained in:
+21
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2020 Anthony Fu<https://github.com/antfu>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
+407
@@ -0,0 +1,407 @@
|
||||
# unplugin-vue-components
|
||||
|
||||
[](https://www.npmjs.com/package/unplugin-vue-components)
|
||||
|
||||
On-demand components auto importing for Vue.
|
||||
|
||||
###### Features
|
||||
|
||||
- 💚 Supports both Vue 2 and Vue 3 out-of-the-box.
|
||||
- ✨ Supports both components and directives.
|
||||
- ⚡️ Supports Vite, Webpack, Rspack, Vue CLI, Rollup, esbuild and more, powered by <a href="https://github.com/unjs/unplugin">unplugin</a>.
|
||||
- 🏝 Tree-shakable, only registers the components you use.
|
||||
- 🪐 Folder names as namespaces.
|
||||
- 🦾 Full TypeScript support.
|
||||
- 🌈 [Built-in resolvers](#importing-from-ui-libraries) for popular UI libraries.
|
||||
- 😃 Works perfectly with [unplugin-icons](https://github.com/antfu/unplugin-icons).
|
||||
|
||||
<br>
|
||||
|
||||
<p align="center">
|
||||
<a href="https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg">
|
||||
<img src='https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg'/>
|
||||
</a>
|
||||
</p>
|
||||
|
||||
<br>
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
npm i unplugin-vue-components -D
|
||||
```
|
||||
|
||||
> **`vite-plugin-components` has been renamed to `unplugin-vue-components`**, see the [migration guide](#migrate-from-vite-plugin-components).
|
||||
|
||||
<details>
|
||||
<summary>Vite</summary><br>
|
||||
|
||||
```ts
|
||||
// vite.config.ts
|
||||
import Components from 'unplugin-vue-components/vite'
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [
|
||||
Components({ /* options */ }),
|
||||
],
|
||||
})
|
||||
```
|
||||
|
||||
<br></details>
|
||||
|
||||
<details>
|
||||
<summary>Rollup</summary><br>
|
||||
|
||||
```ts
|
||||
// rollup.config.js
|
||||
import Components from 'unplugin-vue-components/rollup'
|
||||
|
||||
export default {
|
||||
plugins: [
|
||||
Components({ /* options */ }),
|
||||
],
|
||||
}
|
||||
```
|
||||
|
||||
<br></details>
|
||||
|
||||
|
||||
<details>
|
||||
<summary>Webpack</summary><br>
|
||||
|
||||
```ts
|
||||
// webpack.config.js
|
||||
module.exports = {
|
||||
/* ... */
|
||||
plugins: [
|
||||
require('unplugin-vue-components/webpack')({ /* options */ }),
|
||||
],
|
||||
}
|
||||
```
|
||||
|
||||
<br></details>
|
||||
|
||||
<details>
|
||||
<summary>Rspack</summary><br>
|
||||
|
||||
```ts
|
||||
// rspack.config.js
|
||||
module.exports = {
|
||||
/* ... */
|
||||
plugins: [
|
||||
require('unplugin-vue-components/rspack')({ /* options */ }),
|
||||
],
|
||||
}
|
||||
```
|
||||
|
||||
<br></details>
|
||||
|
||||
<details>
|
||||
<summary>Nuxt</summary><br>
|
||||
|
||||
You might not need this plugin for Nuxt. Use [`@nuxt/components`](https://github.com/nuxt/components) instead.
|
||||
|
||||
<br></details>
|
||||
|
||||
<details>
|
||||
<summary>Vue CLI</summary><br>
|
||||
|
||||
```ts
|
||||
// vue.config.js
|
||||
module.exports = {
|
||||
configureWebpack: {
|
||||
plugins: [
|
||||
require('unplugin-vue-components/webpack')({ /* options */ }),
|
||||
],
|
||||
},
|
||||
}
|
||||
```
|
||||
|
||||
<br></details>
|
||||
|
||||
<details>
|
||||
<summary>esbuild</summary><br>
|
||||
|
||||
```ts
|
||||
// esbuild.config.js
|
||||
import { build } from 'esbuild'
|
||||
|
||||
build({
|
||||
/* ... */
|
||||
plugins: [
|
||||
require('unplugin-vue-components/esbuild')({
|
||||
/* options */
|
||||
}),
|
||||
],
|
||||
})
|
||||
```
|
||||
|
||||
<br></details>
|
||||
|
||||
## Usage
|
||||
|
||||
Use components in templates as you would usually do, it will import components on demand, and there is no `import` and `component registration` required anymore! If you register the parent component asynchronously (or lazy route), the auto-imported components will be code-split along with their parent.
|
||||
|
||||
It will automatically turn this
|
||||
|
||||
```html
|
||||
<template>
|
||||
<div>
|
||||
<HelloWorld msg="Hello Vue 3.0 + Vite" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: 'App'
|
||||
}
|
||||
</script>
|
||||
```
|
||||
|
||||
into this
|
||||
|
||||
```html
|
||||
<template>
|
||||
<div>
|
||||
<HelloWorld msg="Hello Vue 3.0 + Vite" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import HelloWorld from './src/components/HelloWorld.vue'
|
||||
|
||||
export default {
|
||||
name: 'App',
|
||||
components: {
|
||||
HelloWorld
|
||||
}
|
||||
}
|
||||
</script>
|
||||
```
|
||||
> **Note**
|
||||
> By default this plugin will import components in the `src/components` path. You can customize it using the `dirs` option.
|
||||
|
||||
## TypeScript
|
||||
|
||||
To get TypeScript support for auto-imported components, there is [a PR](https://github.com/vuejs/core/pull/3399) to Vue 3 extending the interface of global components. Currently, [Volar](https://github.com/johnsoncodehk/volar) has supported this usage already. If you are using Volar, you can change the config as following to get the support.
|
||||
|
||||
```ts
|
||||
Components({
|
||||
dts: true, // enabled by default if `typescript` is installed
|
||||
})
|
||||
```
|
||||
|
||||
Once the setup is done, a `components.d.ts` will be generated and updates automatically with the type definitions. Feel free to commit it into git or not as you want.
|
||||
|
||||
> **Make sure you also add `components.d.ts` to your `tsconfig.json` under `include`.**
|
||||
|
||||
## Importing from UI Libraries
|
||||
|
||||
We have several built-in resolvers for popular UI libraries like **Vuetify**, **Ant Design Vue**, and **Element Plus**, where you can enable them by:
|
||||
|
||||
Supported Resolvers:
|
||||
|
||||
- [Ant Design Vue](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/antdv.ts)
|
||||
- [Arco Design Vue](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/arco.ts)
|
||||
- [BootstrapVue](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/bootstrap-vue.ts)
|
||||
- [Element Plus](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/element-plus.ts)
|
||||
- [Element UI](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/element-ui.ts)
|
||||
- [Headless UI](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/headless-ui.ts)
|
||||
- [IDux](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/idux.ts)
|
||||
- [Inkline](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/inkline.ts)
|
||||
- [Ionic](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/ionic.ts)
|
||||
- [Naive UI](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/naive-ui.ts)
|
||||
- [Prime Vue](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/prime-vue.ts)
|
||||
- [Quasar](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/quasar.ts)
|
||||
- [TDesign](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/tdesign.ts)
|
||||
- [Vant](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/vant.ts)
|
||||
- [Varlet UI](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/varlet-ui.ts)
|
||||
- [VEUI](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/veui.ts)
|
||||
- [View UI](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/view-ui.ts)
|
||||
- [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)
|
||||
- [VueUse Components](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/vueuse.ts)
|
||||
- [VueUse Directives](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/vueuse-directive.ts)
|
||||
- [Dev UI](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/devui.ts)
|
||||
|
||||
```ts
|
||||
// vite.config.js
|
||||
import Components from 'unplugin-vue-components/vite'
|
||||
import {
|
||||
AntDesignVueResolver,
|
||||
ElementPlusResolver,
|
||||
VantResolver,
|
||||
} from 'unplugin-vue-components/resolvers'
|
||||
|
||||
// your plugin installation
|
||||
Components({
|
||||
resolvers: [
|
||||
AntDesignVueResolver(),
|
||||
ElementPlusResolver(),
|
||||
VantResolver(),
|
||||
],
|
||||
})
|
||||
```
|
||||
|
||||
You can also write your own resolver quickly:
|
||||
|
||||
```ts
|
||||
Components({
|
||||
resolvers: [
|
||||
// example of importing Vant
|
||||
(componentName) => {
|
||||
// where `componentName` is always CapitalCase
|
||||
if (componentName.startsWith('Van'))
|
||||
return { name: componentName.slice(3), from: 'vant' }
|
||||
},
|
||||
],
|
||||
})
|
||||
```
|
||||
|
||||
> [We no longer accept new resolvers](./src/core/resolvers/_READ_BEFORE_CONTRIBUTE.md).
|
||||
|
||||
## Types for global registered components
|
||||
|
||||
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.
|
||||
|
||||
Thus `unplugin-vue-components` provided a way to only register types for global components.
|
||||
|
||||
```ts
|
||||
Components({
|
||||
dts: true,
|
||||
types: [{
|
||||
from: 'vue-router',
|
||||
names: ['RouterLink', 'RouterView'],
|
||||
}],
|
||||
})
|
||||
```
|
||||
|
||||
So the `RouterLink` and `RouterView` will be presented in `components.d.ts`.
|
||||
|
||||
By default, `unplugin-vue-components` detects supported libraries automatically (e.g. `vue-router`) when they are installed in the workspace. If you want to disable it completely, you can pass an empty array to it:
|
||||
|
||||
```ts
|
||||
Components({
|
||||
// Disable type only registration
|
||||
types: [],
|
||||
})
|
||||
```
|
||||
|
||||
## Migrate from `vite-plugin-components`
|
||||
|
||||
`package.json`
|
||||
|
||||
```diff
|
||||
{
|
||||
"devDependencies": {
|
||||
- "vite-plugin-components": "*",
|
||||
+ "unplugin-vue-components": "^0.14.0",
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
`vite.config.js`
|
||||
|
||||
```diff
|
||||
- import Components, { ElementPlusResolver } from 'vite-plugin-components'
|
||||
+ import Components from 'unplugin-vue-components/vite'
|
||||
+ import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
|
||||
|
||||
export default {
|
||||
plugins: [
|
||||
/* ... */
|
||||
Components({
|
||||
/* ... */
|
||||
|
||||
// `customComponentsResolvers` has renamed to `resolver`
|
||||
- customComponentsResolvers: [
|
||||
+ resolvers: [
|
||||
ElementPlusResolver(),
|
||||
],
|
||||
|
||||
// `globalComponentsDeclaration` has renamed to `dts`
|
||||
- globalComponentsDeclaration: true,
|
||||
+ dts: true,
|
||||
|
||||
// `customLoaderMatcher` is depreacted, use `include` instead
|
||||
- customLoaderMatcher: id => id.endsWith('.md'),
|
||||
+ include: [/\.vue$/, /\.vue\?vue/, /\.md$/],
|
||||
}),
|
||||
],
|
||||
}
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
||||
The following show the default values of the configuration
|
||||
|
||||
```ts
|
||||
Components({
|
||||
// relative paths to the directory to search for components.
|
||||
dirs: ['src/components'],
|
||||
|
||||
// valid file extensions for components.
|
||||
extensions: ['vue'],
|
||||
|
||||
// Glob patterns to match file names to be detected as components.
|
||||
// When specified, the `dirs` and `extensions` options will be ignored.
|
||||
globs: ['src/components/*.{vue}'],
|
||||
|
||||
// search for subdirectories
|
||||
deep: true,
|
||||
|
||||
// resolvers for custom components
|
||||
resolvers: [],
|
||||
|
||||
// generate `components.d.ts` global declarations,
|
||||
// also accepts a path for custom filename
|
||||
// default: `true` if package typescript is installed
|
||||
dts: false,
|
||||
|
||||
// Allow subdirectories as namespace prefix for components.
|
||||
directoryAsNamespace: false,
|
||||
|
||||
// Collapse same prefixes (camel-sensitive) of folders and components
|
||||
// to prevent duplication inside namespaced component name.
|
||||
// works when `directoryAsNamespace: true`
|
||||
collapseSamePrefixes: false,
|
||||
|
||||
// Subdirectory paths for ignoring namespace prefixes.
|
||||
// works when `directoryAsNamespace: true`
|
||||
globalNamespaces: [],
|
||||
|
||||
// auto import for directives
|
||||
// default: `true` for Vue 3, `false` for Vue 2
|
||||
// Babel is needed to do the transformation for Vue 2, it's disabled by default for performance concerns.
|
||||
// To install Babel, run: `npm install -D @babel/parser`
|
||||
directives: true,
|
||||
|
||||
// Transform path before resolving
|
||||
importPathTransform: v => v,
|
||||
|
||||
// Allow for components to override other components with the same name
|
||||
allowOverrides: false,
|
||||
|
||||
// filters for transforming targets
|
||||
include: [/\.vue$/, /\.vue\?vue/],
|
||||
exclude: [/[\\/]node_modules[\\/]/, /[\\/]\.git[\\/]/, /[\\/]\.nuxt[\\/]/],
|
||||
|
||||
// Vue version of project. It will detect automatically if not specified.
|
||||
// Acceptable value: 2 | 2.7 | 3
|
||||
version: 2.7,
|
||||
|
||||
// Only provide types of components in library (registered globally)
|
||||
types: []
|
||||
})
|
||||
```
|
||||
|
||||
## Example
|
||||
|
||||
[Vitesse](https://github.com/antfu/vitesse) starter template.
|
||||
|
||||
## Thanks
|
||||
|
||||
Thanks to [@brattonross](https://github.com/brattonross), this project is heavily inspired by [vite-plugin-voie](https://github.com/vamplate/vite-plugin-voie).
|
||||
|
||||
## License
|
||||
|
||||
MIT License © 2020-PRESENT [Anthony Fu](https://github.com/antfu)
|
||||
Generated
Vendored
+32
@@ -0,0 +1,32 @@
|
||||
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var __defProp = Object.defineProperty;
|
||||
var __defProps = Object.defineProperties;
|
||||
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
||||
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
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 __spreadValues = (a, b) => {
|
||||
for (var prop in b || (b = {}))
|
||||
if (__hasOwnProp.call(b, prop))
|
||||
__defNormalProp(a, prop, b[prop]);
|
||||
if (__getOwnPropSymbols)
|
||||
for (var prop of __getOwnPropSymbols(b)) {
|
||||
if (__propIsEnum.call(b, prop))
|
||||
__defNormalProp(a, prop, b[prop]);
|
||||
}
|
||||
return a;
|
||||
};
|
||||
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
||||
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
||||
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
||||
}) : x)(function(x) {
|
||||
if (typeof require !== "undefined")
|
||||
return require.apply(this, arguments);
|
||||
throw Error('Dynamic require of "' + x + '" is not supported');
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
exports.__spreadValues = __spreadValues; exports.__spreadProps = __spreadProps; exports.__require = __require;
|
||||
Generated
Vendored
+755
@@ -0,0 +1,755 @@
|
||||
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
var _chunkWRE7G5ODjs = require('./chunk-WRE7G5OD.js');
|
||||
|
||||
|
||||
|
||||
var _chunk5JVO2UWCjs = require('./chunk-5JVO2UWC.js');
|
||||
|
||||
// src/core/unplugin.ts
|
||||
var _fs = require('fs');
|
||||
var _process = require('process'); var _process2 = _interopRequireDefault(_process);
|
||||
var _unplugin = require('unplugin');
|
||||
var _pluginutils = require('@rollup/pluginutils');
|
||||
var _chokidar = require('chokidar'); var _chokidar2 = _interopRequireDefault(_chokidar);
|
||||
|
||||
// src/core/context.ts
|
||||
var _path = require('path');
|
||||
|
||||
var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
|
||||
var _utils = require('@antfu/utils');
|
||||
|
||||
// src/core/options.ts
|
||||
|
||||
|
||||
var _localpkg = require('local-pkg');
|
||||
|
||||
// src/core/type-imports/detect.ts
|
||||
|
||||
|
||||
|
||||
// src/core/type-imports/index.ts
|
||||
var TypeImportPresets = [
|
||||
{
|
||||
from: "vue-router",
|
||||
names: [
|
||||
"RouterView",
|
||||
"RouterLink"
|
||||
]
|
||||
},
|
||||
{
|
||||
from: "vue-starport",
|
||||
names: [
|
||||
"Starport",
|
||||
"StarportCarrier"
|
||||
]
|
||||
}
|
||||
];
|
||||
|
||||
// src/core/type-imports/detect.ts
|
||||
function detectTypeImports() {
|
||||
return TypeImportPresets.map((i) => _localpkg.isPackageExists.call(void 0, i.from) ? i : void 0).filter(_utils.notNullish);
|
||||
}
|
||||
function resolveTypeImports(imports) {
|
||||
return imports.flatMap((i) => i.names.map((n) => ({ from: i.from, name: n, as: n })));
|
||||
}
|
||||
|
||||
// src/core/options.ts
|
||||
var defaultOptions = {
|
||||
dirs: "src/components",
|
||||
extensions: "vue",
|
||||
deep: true,
|
||||
dts: _localpkg.isPackageExists.call(void 0, "typescript"),
|
||||
directoryAsNamespace: false,
|
||||
collapseSamePrefixes: false,
|
||||
globalNamespaces: [],
|
||||
resolvers: [],
|
||||
importPathTransform: (v) => v,
|
||||
allowOverrides: false
|
||||
};
|
||||
function normalizeResolvers(resolvers) {
|
||||
return _utils.toArray.call(void 0, resolvers).flat().map((r) => typeof r === "function" ? { resolve: r, type: "component" } : r);
|
||||
}
|
||||
function resolveGlobsExclude(root, glob) {
|
||||
const excludeReg = /^!/;
|
||||
return `${excludeReg.test(glob) ? "!" : ""}${_path.resolve.call(void 0, root, glob.replace(excludeReg, ""))}`;
|
||||
}
|
||||
function resolveOptions(options, root) {
|
||||
var _a;
|
||||
const resolved = Object.assign({}, defaultOptions, options);
|
||||
resolved.resolvers = normalizeResolvers(resolved.resolvers);
|
||||
resolved.extensions = _utils.toArray.call(void 0, resolved.extensions);
|
||||
if (resolved.globs) {
|
||||
resolved.globs = _utils.toArray.call(void 0, resolved.globs).map((glob) => _utils.slash.call(void 0, resolveGlobsExclude(root, glob)));
|
||||
resolved.resolvedDirs = [];
|
||||
} else {
|
||||
const extsGlob = resolved.extensions.length === 1 ? resolved.extensions : `{${resolved.extensions.join(",")}}`;
|
||||
resolved.dirs = _utils.toArray.call(void 0, resolved.dirs);
|
||||
resolved.resolvedDirs = resolved.dirs.map((i) => _utils.slash.call(void 0, resolveGlobsExclude(root, i)));
|
||||
resolved.globs = resolved.resolvedDirs.map(
|
||||
(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}`))
|
||||
);
|
||||
if (!resolved.extensions.length)
|
||||
throw new Error("[unplugin-vue-components] `extensions` option is required to search for components");
|
||||
}
|
||||
resolved.dts = !resolved.dts ? false : _path.resolve.call(void 0,
|
||||
root,
|
||||
typeof resolved.dts === "string" ? resolved.dts : "components.d.ts"
|
||||
);
|
||||
if (!resolved.types && resolved.dts)
|
||||
resolved.types = detectTypeImports();
|
||||
resolved.types = resolved.types || [];
|
||||
resolved.root = root;
|
||||
resolved.version = (_a = resolved.version) != null ? _a : getVueVersion(root);
|
||||
if (resolved.version < 2 || resolved.version >= 4)
|
||||
throw new Error(`[unplugin-vue-components] unsupported version: ${resolved.version}`);
|
||||
resolved.transformer = options.transformer || `vue${Math.trunc(resolved.version)}`;
|
||||
resolved.directives = typeof options.directives === "boolean" ? options.directives : !resolved.resolvers.some((i) => i.type === "directive") ? false : resolved.version >= 3;
|
||||
return resolved;
|
||||
}
|
||||
function getVueVersion(root) {
|
||||
var _a;
|
||||
const raw = ((_a = _localpkg.getPackageInfoSync.call(void 0, "vue", { paths: [root] })) == null ? void 0 : _a.version) || "3";
|
||||
const version = +raw.split(".").slice(0, 2).join(".");
|
||||
if (version === 2.7)
|
||||
return 2.7;
|
||||
else if (version < 2.7)
|
||||
return 2;
|
||||
return 3;
|
||||
}
|
||||
|
||||
// src/core/fs/glob.ts
|
||||
var _fastglob = require('fast-glob'); var _fastglob2 = _interopRequireDefault(_fastglob);
|
||||
|
||||
var debug = _debug2.default.call(void 0, "unplugin-vue-components:glob");
|
||||
function searchComponents(ctx) {
|
||||
var _a;
|
||||
debug(`started with: [${ctx.options.globs.join(", ")}]`);
|
||||
const root = ctx.root;
|
||||
const files = _fastglob2.default.sync(ctx.options.globs, {
|
||||
ignore: ["node_modules"],
|
||||
onlyFiles: true,
|
||||
cwd: root,
|
||||
absolute: true
|
||||
});
|
||||
if (!files.length && !((_a = ctx.options.resolvers) == null ? void 0 : _a.length))
|
||||
console.warn("[unplugin-vue-components] no components found");
|
||||
debug(`${files.length} components found.`);
|
||||
ctx.addComponents(files);
|
||||
}
|
||||
|
||||
// src/core/declaration.ts
|
||||
|
||||
|
||||
var _promises = require('fs/promises');
|
||||
|
||||
var multilineCommentsRE = new RegExp("\\/\\*.*?\\*\\/", "gms");
|
||||
var singlelineCommentsRE = /\/\/.*$/gm;
|
||||
function extractImports(code) {
|
||||
return Object.fromEntries(Array.from(code.matchAll(/['"]?([^\s'"]+)['"]?\s*:\s*(.+?)[,;\n]/g)).map((i) => [i[1], i[2]]));
|
||||
}
|
||||
function parseDeclaration(code) {
|
||||
var _a, _b;
|
||||
if (!code)
|
||||
return;
|
||||
code = code.replace(multilineCommentsRE, "").replace(singlelineCommentsRE, "");
|
||||
const imports = {
|
||||
component: {},
|
||||
directive: {}
|
||||
};
|
||||
const componentDeclaration = (_a = new RegExp("export\\s+interface\\s+GlobalComponents\\s*{(.*?)}", "s").exec(code)) == null ? void 0 : _a[0];
|
||||
if (componentDeclaration)
|
||||
imports.component = extractImports(componentDeclaration);
|
||||
const directiveDeclaration = (_b = new RegExp("export\\s+interface\\s+ComponentCustomProperties\\s*{(.*?)}", "s").exec(code)) == null ? void 0 : _b[0];
|
||||
if (directiveDeclaration)
|
||||
imports.directive = extractImports(directiveDeclaration);
|
||||
return imports;
|
||||
}
|
||||
function stringifyComponentInfo(filepath, { from: path, as: name, name: importName }, importPathTransform) {
|
||||
if (!name)
|
||||
return void 0;
|
||||
path = _chunkWRE7G5ODjs.getTransformedPath.call(void 0, path, importPathTransform);
|
||||
const related = _path.isAbsolute.call(void 0, path) ? `./${_path.relative.call(void 0, _path.dirname.call(void 0, filepath), path)}` : path;
|
||||
const entry = `typeof import('${_utils.slash.call(void 0, related)}')['${importName || "default"}']`;
|
||||
return [name, entry];
|
||||
}
|
||||
function stringifyComponentsInfo(filepath, components, importPathTransform) {
|
||||
return Object.fromEntries(
|
||||
components.map((info) => stringifyComponentInfo(filepath, info, importPathTransform)).filter(_utils.notNullish)
|
||||
);
|
||||
}
|
||||
function getDeclarationImports(ctx, filepath) {
|
||||
const component = stringifyComponentsInfo(filepath, [
|
||||
...Object.values(_chunk5JVO2UWCjs.__spreadValues.call(void 0, _chunk5JVO2UWCjs.__spreadValues.call(void 0, {}, ctx.componentNameMap), ctx.componentCustomMap)),
|
||||
...resolveTypeImports(ctx.options.types)
|
||||
], ctx.options.importPathTransform);
|
||||
const directive = stringifyComponentsInfo(
|
||||
filepath,
|
||||
Object.values(ctx.directiveCustomMap),
|
||||
ctx.options.importPathTransform
|
||||
);
|
||||
if (Object.keys(component).length + Object.keys(directive).length === 0)
|
||||
return;
|
||||
return { component, directive };
|
||||
}
|
||||
function stringifyDeclarationImports(imports) {
|
||||
return Object.entries(imports).sort(([a], [b]) => a.localeCompare(b)).map(([name, v]) => {
|
||||
if (!/^\w+$/.test(name))
|
||||
name = `'${name}'`;
|
||||
return `${name}: ${v}`;
|
||||
});
|
||||
}
|
||||
function getDeclaration(ctx, filepath, originalImports) {
|
||||
const imports = getDeclarationImports(ctx, filepath);
|
||||
if (!imports)
|
||||
return;
|
||||
const declarations = {
|
||||
component: stringifyDeclarationImports(_chunk5JVO2UWCjs.__spreadValues.call(void 0, _chunk5JVO2UWCjs.__spreadValues.call(void 0, {}, originalImports == null ? void 0 : originalImports.component), imports.component)),
|
||||
directive: stringifyDeclarationImports(_chunk5JVO2UWCjs.__spreadValues.call(void 0, _chunk5JVO2UWCjs.__spreadValues.call(void 0, {}, originalImports == null ? void 0 : originalImports.directive), imports.directive))
|
||||
};
|
||||
const head = ctx.options.version === 2.7 ? `export {}
|
||||
|
||||
declare module 'vue' {` : `export {}
|
||||
|
||||
declare module 'vue' {`;
|
||||
let code = `/* eslint-disable */
|
||||
/* prettier-ignore */
|
||||
// @ts-nocheck
|
||||
// Generated by unplugin-vue-components
|
||||
// Read more: https://github.com/vuejs/core/pull/3399
|
||||
${head}`;
|
||||
if (Object.keys(declarations.component).length > 0) {
|
||||
code += `
|
||||
export interface GlobalComponents {
|
||||
${declarations.component.join("\n ")}
|
||||
}`;
|
||||
}
|
||||
if (Object.keys(declarations.directive).length > 0) {
|
||||
code += `
|
||||
export interface ComponentCustomProperties {
|
||||
${declarations.directive.join("\n ")}
|
||||
}`;
|
||||
}
|
||||
code += "\n}\n";
|
||||
return code;
|
||||
}
|
||||
async function writeFile(filePath, content) {
|
||||
await _promises.mkdir.call(void 0, _path.dirname.call(void 0, filePath), { recursive: true });
|
||||
return await _promises.writeFile.call(void 0, filePath, content, "utf-8");
|
||||
}
|
||||
async function writeDeclaration(ctx, filepath, removeUnused = false) {
|
||||
const originalContent = _fs.existsSync.call(void 0, filepath) ? await _promises.readFile.call(void 0, filepath, "utf-8") : "";
|
||||
const originalImports = removeUnused ? void 0 : parseDeclaration(originalContent);
|
||||
const code = getDeclaration(ctx, filepath, originalImports);
|
||||
if (!code)
|
||||
return;
|
||||
if (code !== originalContent)
|
||||
await writeFile(filepath, code);
|
||||
}
|
||||
|
||||
// src/core/transformer.ts
|
||||
|
||||
var _magicstring = require('magic-string'); var _magicstring2 = _interopRequireDefault(_magicstring);
|
||||
|
||||
// src/core/transforms/component.ts
|
||||
|
||||
var debug2 = _debug2.default.call(void 0, "unplugin-vue-components:transform:component");
|
||||
function resolveVue2(code, s) {
|
||||
const results = [];
|
||||
for (const match of code.matchAll(/\b(_c|h)\([\s\n\t]*['"](.+?)["']([,)])/g)) {
|
||||
const [full, renderFunctionName, matchedName, append] = match;
|
||||
if (match.index != null && matchedName && !matchedName.startsWith("_")) {
|
||||
const start = match.index;
|
||||
const end = start + full.length;
|
||||
results.push({
|
||||
rawName: matchedName,
|
||||
replace: (resolved) => s.overwrite(start, end, `${renderFunctionName}(${resolved}${append}`)
|
||||
});
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
function resolveVue3(code, s) {
|
||||
const results = [];
|
||||
for (const match of code.matchAll(/_resolveComponent[0-9]*\("(.+?)"\)/g)) {
|
||||
const matchedName = match[1];
|
||||
if (match.index != null && matchedName && !matchedName.startsWith("_")) {
|
||||
const start = match.index;
|
||||
const end = start + match[0].length;
|
||||
results.push({
|
||||
rawName: matchedName,
|
||||
replace: (resolved) => s.overwrite(start, end, resolved)
|
||||
});
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
async function transformComponent(code, transformer2, s, ctx, sfcPath) {
|
||||
let no = 0;
|
||||
const results = transformer2 === "vue2" ? resolveVue2(code, s) : resolveVue3(code, s);
|
||||
for (const { rawName, replace } of results) {
|
||||
debug2(`| ${rawName}`);
|
||||
const name = _chunkWRE7G5ODjs.pascalCase.call(void 0, rawName);
|
||||
ctx.updateUsageMap(sfcPath, [name]);
|
||||
const component = await ctx.findComponent(name, "component", [sfcPath]);
|
||||
if (component) {
|
||||
const varName = `__unplugin_components_${no}`;
|
||||
s.prepend(`${_chunkWRE7G5ODjs.stringifyComponentImport.call(void 0, _chunk5JVO2UWCjs.__spreadProps.call(void 0, _chunk5JVO2UWCjs.__spreadValues.call(void 0, {}, component), { as: varName }), ctx)};
|
||||
`);
|
||||
no += 1;
|
||||
replace(varName);
|
||||
}
|
||||
}
|
||||
debug2(`^ (${no})`);
|
||||
}
|
||||
|
||||
// src/core/transforms/directive/index.ts
|
||||
|
||||
|
||||
// src/core/transforms/directive/vue2.ts
|
||||
|
||||
function getRenderFnStart(program) {
|
||||
var _a, _b;
|
||||
const renderFn = program.body.find(
|
||||
(node) => node.type === "VariableDeclaration" && node.declarations[0].id.type === "Identifier" && ["render", "_sfc_render"].includes(node.declarations[0].id.name)
|
||||
);
|
||||
const start = (_b = (_a = renderFn == null ? void 0 : renderFn.declarations[0].init) == null ? void 0 : _a.body) == null ? void 0 : _b.start;
|
||||
if (start === null || start === void 0)
|
||||
throw new Error("[unplugin-vue-components:directive] Cannot find render function position.");
|
||||
return start + 1;
|
||||
}
|
||||
async function resolveVue22(code, s) {
|
||||
var _a, _b, _c;
|
||||
if (!_localpkg.isPackageExists.call(void 0, "@babel/parser"))
|
||||
throw new Error('[unplugin-vue-components:directive] To use Vue 2 directive you will need to install Babel first: "npm install -D @babel/parser"');
|
||||
const { parse } = await _localpkg.importModule.call(void 0, "@babel/parser");
|
||||
const { program } = parse(code, {
|
||||
sourceType: "module"
|
||||
});
|
||||
const nodes = [];
|
||||
const { walk } = await Promise.resolve().then(() => require("./src-WIQNDB4Q.js"));
|
||||
walk(program, {
|
||||
enter(node) {
|
||||
if (node.type === "CallExpression")
|
||||
nodes.push(node);
|
||||
}
|
||||
});
|
||||
if (nodes.length === 0)
|
||||
return [];
|
||||
let _renderStart;
|
||||
const getRenderStart = () => {
|
||||
if (_renderStart !== void 0)
|
||||
return _renderStart;
|
||||
return _renderStart = getRenderFnStart(program);
|
||||
};
|
||||
const results = [];
|
||||
for (const node of nodes) {
|
||||
const { callee, arguments: args } = node;
|
||||
if (callee.type !== "Identifier" || callee.name !== "_c" || ((_a = args[1]) == null ? void 0 : _a.type) !== "ObjectExpression")
|
||||
continue;
|
||||
const directives = (_b = args[1].properties.find(
|
||||
(property) => property.type === "ObjectProperty" && property.key.type === "Identifier" && property.key.name === "directives"
|
||||
)) == null ? void 0 : _b.value;
|
||||
if (!directives || directives.type !== "ArrayExpression")
|
||||
continue;
|
||||
for (const directive of directives.elements) {
|
||||
if ((directive == null ? void 0 : directive.type) !== "ObjectExpression")
|
||||
continue;
|
||||
const nameNode = (_c = directive.properties.find(
|
||||
(p) => p.type === "ObjectProperty" && p.key.type === "Identifier" && p.key.name === "name"
|
||||
)) == null ? void 0 : _c.value;
|
||||
if ((nameNode == null ? void 0 : nameNode.type) !== "StringLiteral")
|
||||
continue;
|
||||
const name = nameNode.value;
|
||||
if (!name || name.startsWith("_"))
|
||||
continue;
|
||||
results.push({
|
||||
rawName: name,
|
||||
replace: (resolved) => {
|
||||
s.prependLeft(getRenderStart(), `
|
||||
this.$options.directives["${name}"] = ${resolved};`);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
// src/core/transforms/directive/vue3.ts
|
||||
function resolveVue32(code, s) {
|
||||
const results = [];
|
||||
for (const match of code.matchAll(/_resolveDirective\("(.+?)"\)/g)) {
|
||||
const matchedName = match[1];
|
||||
if (match.index != null && matchedName && !matchedName.startsWith("_")) {
|
||||
const start = match.index;
|
||||
const end = start + match[0].length;
|
||||
results.push({
|
||||
rawName: matchedName,
|
||||
replace: (resolved) => s.overwrite(start, end, resolved)
|
||||
});
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
// src/core/transforms/directive/index.ts
|
||||
var debug3 = _debug2.default.call(void 0, "unplugin-vue-components:transform:directive");
|
||||
async function transformDirective(code, transformer2, s, ctx, sfcPath) {
|
||||
let no = 0;
|
||||
const results = await (transformer2 === "vue2" ? resolveVue22(code, s) : resolveVue32(code, s));
|
||||
for (const { rawName, replace } of results) {
|
||||
debug3(`| ${rawName}`);
|
||||
const name = `${_chunkWRE7G5ODjs.DIRECTIVE_IMPORT_PREFIX}${_chunkWRE7G5ODjs.pascalCase.call(void 0, rawName)}`;
|
||||
ctx.updateUsageMap(sfcPath, [name]);
|
||||
const directive = await ctx.findComponent(name, "directive", [sfcPath]);
|
||||
if (!directive)
|
||||
continue;
|
||||
const varName = `__unplugin_directives_${no}`;
|
||||
s.prepend(`${_chunkWRE7G5ODjs.stringifyComponentImport.call(void 0, _chunk5JVO2UWCjs.__spreadProps.call(void 0, _chunk5JVO2UWCjs.__spreadValues.call(void 0, {}, directive), { as: varName }), ctx)};
|
||||
`);
|
||||
no += 1;
|
||||
replace(varName);
|
||||
}
|
||||
debug3(`^ (${no})`);
|
||||
}
|
||||
|
||||
// src/core/transformer.ts
|
||||
var debug4 = _debug2.default.call(void 0, "unplugin-vue-components:transformer");
|
||||
function transformer(ctx, transformer2) {
|
||||
return async (code, id, path) => {
|
||||
ctx.searchGlob();
|
||||
const sfcPath = ctx.normalizePath(path);
|
||||
debug4(sfcPath);
|
||||
const s = new (0, _magicstring2.default)(code);
|
||||
await transformComponent(code, transformer2, s, ctx, sfcPath);
|
||||
if (ctx.options.directives)
|
||||
await transformDirective(code, transformer2, s, ctx, sfcPath);
|
||||
s.prepend(_chunkWRE7G5ODjs.DISABLE_COMMENT);
|
||||
const result = { code: s.toString() };
|
||||
if (ctx.sourcemap)
|
||||
result.map = s.generateMap({ source: id, includeContent: true });
|
||||
return result;
|
||||
};
|
||||
}
|
||||
|
||||
// src/core/context.ts
|
||||
var debug5 = {
|
||||
components: _debug2.default.call(void 0, "unplugin-vue-components:context:components"),
|
||||
search: _debug2.default.call(void 0, "unplugin-vue-components:context:search"),
|
||||
hmr: _debug2.default.call(void 0, "unplugin-vue-components:context:hmr"),
|
||||
declaration: _debug2.default.call(void 0, "unplugin-vue-components:declaration"),
|
||||
env: _debug2.default.call(void 0, "unplugin-vue-components:env")
|
||||
};
|
||||
var Context = class {
|
||||
constructor(rawOptions) {
|
||||
this.rawOptions = rawOptions;
|
||||
this.transformer = void 0;
|
||||
this._componentPaths = /* @__PURE__ */ new Set();
|
||||
this._componentNameMap = {};
|
||||
this._componentUsageMap = {};
|
||||
this._componentCustomMap = {};
|
||||
this._directiveCustomMap = {};
|
||||
this.root = _process2.default.cwd();
|
||||
this.sourcemap = true;
|
||||
this.alias = {};
|
||||
this._searched = false;
|
||||
this.options = resolveOptions(rawOptions, this.root);
|
||||
this.generateDeclaration = _utils.throttle.call(void 0, 500, this._generateDeclaration.bind(this), { noLeading: false });
|
||||
this.setTransformer(this.options.transformer);
|
||||
}
|
||||
setRoot(root) {
|
||||
if (this.root === root)
|
||||
return;
|
||||
debug5.env("root", root);
|
||||
this.root = root;
|
||||
this.options = resolveOptions(this.rawOptions, this.root);
|
||||
}
|
||||
setTransformer(name) {
|
||||
debug5.env("transformer", name);
|
||||
this.transformer = transformer(this, name || "vue3");
|
||||
}
|
||||
transform(code, id) {
|
||||
const { path, query } = _chunkWRE7G5ODjs.parseId.call(void 0, id);
|
||||
return this.transformer(code, id, path, query);
|
||||
}
|
||||
setupViteServer(server) {
|
||||
if (this._server === server)
|
||||
return;
|
||||
this._server = server;
|
||||
this.setupWatcher(server.watcher);
|
||||
}
|
||||
setupWatcher(watcher) {
|
||||
const { globs } = this.options;
|
||||
watcher.on("unlink", (path) => {
|
||||
if (!_chunkWRE7G5ODjs.matchGlobs.call(void 0, path, globs))
|
||||
return;
|
||||
path = _utils.slash.call(void 0, path);
|
||||
this.removeComponents(path);
|
||||
this.onUpdate(path);
|
||||
});
|
||||
watcher.on("add", (path) => {
|
||||
if (!_chunkWRE7G5ODjs.matchGlobs.call(void 0, path, globs))
|
||||
return;
|
||||
path = _utils.slash.call(void 0, path);
|
||||
this.addComponents(path);
|
||||
this.onUpdate(path);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* start watcher for webpack
|
||||
*/
|
||||
setupWatcherWebpack(watcher, emitUpdate) {
|
||||
const { globs } = this.options;
|
||||
watcher.on("unlink", (path) => {
|
||||
if (!_chunkWRE7G5ODjs.matchGlobs.call(void 0, path, globs))
|
||||
return;
|
||||
path = _utils.slash.call(void 0, path);
|
||||
this.removeComponents(path);
|
||||
emitUpdate(path, "unlink");
|
||||
});
|
||||
watcher.on("add", (path) => {
|
||||
if (!_chunkWRE7G5ODjs.matchGlobs.call(void 0, path, globs))
|
||||
return;
|
||||
path = _utils.slash.call(void 0, path);
|
||||
this.addComponents(path);
|
||||
emitUpdate(path, "add");
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Record the usage of components
|
||||
* @param path
|
||||
* @param paths paths of used components
|
||||
*/
|
||||
updateUsageMap(path, paths) {
|
||||
if (!this._componentUsageMap[path])
|
||||
this._componentUsageMap[path] = /* @__PURE__ */ new Set();
|
||||
paths.forEach((p) => {
|
||||
this._componentUsageMap[path].add(p);
|
||||
});
|
||||
}
|
||||
addComponents(paths) {
|
||||
debug5.components("add", paths);
|
||||
const size = this._componentPaths.size;
|
||||
_utils.toArray.call(void 0, paths).forEach((p) => this._componentPaths.add(p));
|
||||
if (this._componentPaths.size !== size) {
|
||||
this.updateComponentNameMap();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
addCustomComponents(info) {
|
||||
if (info.as)
|
||||
this._componentCustomMap[info.as] = info;
|
||||
}
|
||||
addCustomDirectives(info) {
|
||||
if (info.as)
|
||||
this._directiveCustomMap[info.as] = info;
|
||||
}
|
||||
removeComponents(paths) {
|
||||
debug5.components("remove", paths);
|
||||
const size = this._componentPaths.size;
|
||||
_utils.toArray.call(void 0, paths).forEach((p) => this._componentPaths.delete(p));
|
||||
if (this._componentPaths.size !== size) {
|
||||
this.updateComponentNameMap();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
onUpdate(path) {
|
||||
this.generateDeclaration();
|
||||
if (!this._server)
|
||||
return;
|
||||
const payload = {
|
||||
type: "update",
|
||||
updates: []
|
||||
};
|
||||
const timestamp = +/* @__PURE__ */ new Date();
|
||||
const name = _chunkWRE7G5ODjs.pascalCase.call(void 0, _chunkWRE7G5ODjs.getNameFromFilePath.call(void 0, path, this.options));
|
||||
Object.entries(this._componentUsageMap).forEach(([key, values]) => {
|
||||
if (values.has(name)) {
|
||||
const r = `/${_utils.slash.call(void 0, _path.relative.call(void 0, this.root, key))}`;
|
||||
payload.updates.push({
|
||||
acceptedPath: r,
|
||||
path: r,
|
||||
timestamp,
|
||||
type: "js-update"
|
||||
});
|
||||
}
|
||||
});
|
||||
if (payload.updates.length)
|
||||
this._server.ws.send(payload);
|
||||
}
|
||||
updateComponentNameMap() {
|
||||
this._componentNameMap = {};
|
||||
Array.from(this._componentPaths).forEach((path) => {
|
||||
const name = _chunkWRE7G5ODjs.pascalCase.call(void 0, _chunkWRE7G5ODjs.getNameFromFilePath.call(void 0, path, this.options));
|
||||
if (this._componentNameMap[name] && !this.options.allowOverrides) {
|
||||
console.warn(`[unplugin-vue-components] component "${name}"(${path}) has naming conflicts with other components, ignored.`);
|
||||
return;
|
||||
}
|
||||
this._componentNameMap[name] = {
|
||||
as: name,
|
||||
from: path
|
||||
};
|
||||
});
|
||||
}
|
||||
async findComponent(name, type, excludePaths = []) {
|
||||
let info = this._componentNameMap[name];
|
||||
if (info && !excludePaths.includes(info.from) && !excludePaths.includes(info.from.slice(1)))
|
||||
return info;
|
||||
for (const resolver of this.options.resolvers) {
|
||||
if (resolver.type !== type)
|
||||
continue;
|
||||
const result = await resolver.resolve(type === "directive" ? name.slice(_chunkWRE7G5ODjs.DIRECTIVE_IMPORT_PREFIX.length) : name);
|
||||
if (!result)
|
||||
continue;
|
||||
if (typeof result === "string") {
|
||||
info = {
|
||||
as: name,
|
||||
from: result
|
||||
};
|
||||
} else {
|
||||
info = _chunk5JVO2UWCjs.__spreadValues.call(void 0, {
|
||||
as: name
|
||||
}, _chunkWRE7G5ODjs.normalizeComponentInfo.call(void 0, result));
|
||||
}
|
||||
if (type === "component")
|
||||
this.addCustomComponents(info);
|
||||
else if (type === "directive")
|
||||
this.addCustomDirectives(info);
|
||||
return info;
|
||||
}
|
||||
return void 0;
|
||||
}
|
||||
normalizePath(path) {
|
||||
var _a, _b, _c;
|
||||
return _chunkWRE7G5ODjs.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) || []);
|
||||
}
|
||||
relative(path) {
|
||||
if (path.startsWith("/") && !path.startsWith(this.root))
|
||||
return _utils.slash.call(void 0, path.slice(1));
|
||||
return _utils.slash.call(void 0, _path.relative.call(void 0, this.root, path));
|
||||
}
|
||||
/**
|
||||
* This search for components in with the given options.
|
||||
* Will be called multiple times to ensure file loaded,
|
||||
* should normally run only once.
|
||||
*/
|
||||
searchGlob() {
|
||||
if (this._searched)
|
||||
return;
|
||||
searchComponents(this);
|
||||
debug5.search(this._componentNameMap);
|
||||
this._searched = true;
|
||||
}
|
||||
_generateDeclaration(removeUnused = !this._server) {
|
||||
if (!this.options.dts)
|
||||
return;
|
||||
debug5.declaration("generating");
|
||||
return writeDeclaration(this, this.options.dts, removeUnused);
|
||||
}
|
||||
get componentNameMap() {
|
||||
return this._componentNameMap;
|
||||
}
|
||||
get componentCustomMap() {
|
||||
return this._componentCustomMap;
|
||||
}
|
||||
get directiveCustomMap() {
|
||||
return this._directiveCustomMap;
|
||||
}
|
||||
};
|
||||
|
||||
// src/core/unplugin.ts
|
||||
var PLUGIN_NAME = "unplugin:webpack";
|
||||
var unplugin_default = _unplugin.createUnplugin.call(void 0, (options = {}) => {
|
||||
const filter = _pluginutils.createFilter.call(void 0,
|
||||
options.include || [/\.vue$/, /\.vue\?vue/, /\.vue\?v=/],
|
||||
options.exclude || [/[\\/]node_modules[\\/]/, /[\\/]\.git[\\/]/, /[\\/]\.nuxt[\\/]/]
|
||||
);
|
||||
const ctx = new Context(options);
|
||||
const api = {
|
||||
async findComponent(name, filename) {
|
||||
return await ctx.findComponent(name, "component", filename ? [filename] : []);
|
||||
},
|
||||
stringifyImport(info) {
|
||||
return _chunkWRE7G5ODjs.stringifyComponentImport.call(void 0, info, ctx);
|
||||
}
|
||||
};
|
||||
return {
|
||||
name: "unplugin-vue-components",
|
||||
enforce: "post",
|
||||
api,
|
||||
transformInclude(id) {
|
||||
return filter(id);
|
||||
},
|
||||
async transform(code, id) {
|
||||
if (!_chunkWRE7G5ODjs.shouldTransform.call(void 0, code))
|
||||
return null;
|
||||
try {
|
||||
const result = await ctx.transform(code, id);
|
||||
ctx.generateDeclaration();
|
||||
return result;
|
||||
} catch (e) {
|
||||
this.error(e);
|
||||
}
|
||||
},
|
||||
vite: {
|
||||
configResolved(config) {
|
||||
ctx.setRoot(config.root);
|
||||
ctx.sourcemap = true;
|
||||
if (config.plugins.find((i) => i.name === "vite-plugin-vue2"))
|
||||
ctx.setTransformer("vue2");
|
||||
if (ctx.options.dts) {
|
||||
ctx.searchGlob();
|
||||
if (!_fs.existsSync.call(void 0, ctx.options.dts))
|
||||
ctx.generateDeclaration();
|
||||
}
|
||||
if (config.build.watch && config.command === "build")
|
||||
ctx.setupWatcher(_chokidar2.default.watch(ctx.options.globs));
|
||||
},
|
||||
configureServer(server) {
|
||||
ctx.setupViteServer(server);
|
||||
}
|
||||
},
|
||||
webpack(compiler) {
|
||||
let watcher;
|
||||
let fileDepQueue = [];
|
||||
compiler.hooks.watchRun.tap(PLUGIN_NAME, () => {
|
||||
if (!watcher && compiler.watching) {
|
||||
watcher = compiler.watching;
|
||||
ctx.setupWatcherWebpack(_chokidar2.default.watch(ctx.options.globs), (path, type) => {
|
||||
fileDepQueue.push({ path, type });
|
||||
_process2.default.nextTick(() => {
|
||||
watcher.invalidate();
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
|
||||
if (fileDepQueue.length) {
|
||||
fileDepQueue.forEach(({ path, type }) => {
|
||||
if (type === "unlink")
|
||||
compilation.fileDependencies.delete(path);
|
||||
else
|
||||
compilation.fileDependencies.add(path);
|
||||
});
|
||||
fileDepQueue = [];
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
|
||||
exports.unplugin_default = unplugin_default;
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
"use strict";
|
||||
Generated
Vendored
+196
@@ -0,0 +1,196 @@
|
||||
// src/core/utils.ts
|
||||
import { parse } from "path";
|
||||
import process from "process";
|
||||
import { minimatch } from "minimatch";
|
||||
import resolve from "resolve";
|
||||
import { slash, toArray } from "@antfu/utils";
|
||||
import {
|
||||
getPackageInfo,
|
||||
isPackageExists
|
||||
} from "local-pkg";
|
||||
|
||||
// src/core/constants.ts
|
||||
var DISABLE_COMMENT = "/* unplugin-vue-components disabled */";
|
||||
var DIRECTIVE_IMPORT_PREFIX = "v";
|
||||
|
||||
// src/core/utils.ts
|
||||
var isSSR = Boolean(process.env.SSR || process.env.SSG || process.env.VITE_SSR || process.env.VITE_SSG);
|
||||
function pascalCase(str) {
|
||||
return capitalize(camelCase(str));
|
||||
}
|
||||
function camelCase(str) {
|
||||
return str.replace(/-(\w)/g, (_, c) => c ? c.toUpperCase() : "");
|
||||
}
|
||||
function kebabCase(key) {
|
||||
const result = key.replace(/([A-Z])/g, " $1").trim();
|
||||
return result.split(" ").join("-").toLowerCase();
|
||||
}
|
||||
function capitalize(str) {
|
||||
return str.charAt(0).toUpperCase() + str.slice(1);
|
||||
}
|
||||
function parseId(id) {
|
||||
const index = id.indexOf("?");
|
||||
if (index < 0) {
|
||||
return { path: id, query: {} };
|
||||
} else {
|
||||
const query = Object.fromEntries(new URLSearchParams(id.slice(index)));
|
||||
return {
|
||||
path: id.slice(0, index),
|
||||
query
|
||||
};
|
||||
}
|
||||
}
|
||||
function isEmpty(value) {
|
||||
if (!value || value === null || value === void 0 || Array.isArray(value) && Object.keys(value).length <= 0)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
function matchGlobs(filepath, globs) {
|
||||
for (const glob of globs) {
|
||||
if (minimatch(slash(filepath), glob))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function getTransformedPath(path, importPathTransform) {
|
||||
if (importPathTransform) {
|
||||
const result = importPathTransform(path);
|
||||
if (result != null)
|
||||
path = result;
|
||||
}
|
||||
return path;
|
||||
}
|
||||
function stringifyImport(info) {
|
||||
if (typeof info === "string")
|
||||
return `import '${info}'`;
|
||||
if (!info.as)
|
||||
return `import '${info.from}'`;
|
||||
else if (info.name)
|
||||
return `import { ${info.name} as ${info.as} } from '${info.from}'`;
|
||||
else
|
||||
return `import ${info.as} from '${info.from}'`;
|
||||
}
|
||||
function normalizeComponentInfo(info) {
|
||||
if ("path" in info) {
|
||||
return {
|
||||
from: info.path,
|
||||
as: info.name,
|
||||
name: info.importName,
|
||||
sideEffects: info.sideEffects
|
||||
};
|
||||
}
|
||||
return info;
|
||||
}
|
||||
function stringifyComponentImport({ as: name, from: path, name: importName, sideEffects }, ctx) {
|
||||
path = getTransformedPath(path, ctx.options.importPathTransform);
|
||||
const imports = [
|
||||
stringifyImport({ as: name, from: path, name: importName })
|
||||
];
|
||||
if (sideEffects)
|
||||
toArray(sideEffects).forEach((i) => imports.push(stringifyImport(i)));
|
||||
return imports.join(";");
|
||||
}
|
||||
function getNameFromFilePath(filePath, options) {
|
||||
const { resolvedDirs, directoryAsNamespace, globalNamespaces, collapseSamePrefixes, root } = options;
|
||||
const parsedFilePath = parse(slash(filePath));
|
||||
let strippedPath = "";
|
||||
for (const dir of resolvedDirs) {
|
||||
if (parsedFilePath.dir.startsWith(dir)) {
|
||||
strippedPath = parsedFilePath.dir.slice(dir.length);
|
||||
break;
|
||||
}
|
||||
}
|
||||
let folders = strippedPath.slice(1).split("/").filter(Boolean);
|
||||
let filename = parsedFilePath.name;
|
||||
if (filename === "index" && !directoryAsNamespace) {
|
||||
if (isEmpty(folders))
|
||||
folders = parsedFilePath.dir.slice(root.length + 1).split("/").filter(Boolean);
|
||||
filename = `${folders.slice(-1)[0]}`;
|
||||
return filename;
|
||||
}
|
||||
if (directoryAsNamespace) {
|
||||
if (globalNamespaces.some((name) => folders.includes(name)))
|
||||
folders = folders.filter((f) => !globalNamespaces.includes(f));
|
||||
folders = folders.map((f) => f.replace(/[^a-zA-Z0-9\-]/g, ""));
|
||||
if (filename.toLowerCase() === "index")
|
||||
filename = "";
|
||||
if (!isEmpty(folders)) {
|
||||
let namespaced = [...folders, filename];
|
||||
if (collapseSamePrefixes) {
|
||||
const collapsed = [];
|
||||
for (const fileOrFolderName of namespaced) {
|
||||
let cumulativePrefix = "";
|
||||
let didCollapse = false;
|
||||
for (const parentFolder of [...collapsed].reverse()) {
|
||||
cumulativePrefix = `${capitalize(parentFolder)}${cumulativePrefix}`;
|
||||
if (pascalCase(fileOrFolderName).startsWith(pascalCase(cumulativePrefix))) {
|
||||
const collapseSamePrefix = fileOrFolderName.slice(cumulativePrefix.length);
|
||||
collapsed.push(collapseSamePrefix);
|
||||
didCollapse = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!didCollapse)
|
||||
collapsed.push(fileOrFolderName);
|
||||
}
|
||||
namespaced = collapsed;
|
||||
}
|
||||
filename = namespaced.filter(Boolean).join("-");
|
||||
}
|
||||
return filename;
|
||||
}
|
||||
return filename;
|
||||
}
|
||||
function resolveAlias(filepath, alias) {
|
||||
const result = filepath;
|
||||
if (Array.isArray(alias)) {
|
||||
for (const { find, replacement } of alias)
|
||||
result.replace(find, replacement);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
async function getPkgVersion(pkgName, defaultVersion) {
|
||||
var _a;
|
||||
try {
|
||||
const isExist = isPackageExists(pkgName);
|
||||
if (isExist) {
|
||||
const pkg = await getPackageInfo(pkgName);
|
||||
return (_a = pkg == null ? void 0 : pkg.version) != null ? _a : defaultVersion;
|
||||
} else {
|
||||
return defaultVersion;
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
return defaultVersion;
|
||||
}
|
||||
}
|
||||
function shouldTransform(code) {
|
||||
if (code.includes(DISABLE_COMMENT))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
function resolveImportPath(importName) {
|
||||
return resolve.sync(importName, {
|
||||
preserveSymlinks: false
|
||||
});
|
||||
}
|
||||
|
||||
export {
|
||||
DISABLE_COMMENT,
|
||||
DIRECTIVE_IMPORT_PREFIX,
|
||||
isSSR,
|
||||
pascalCase,
|
||||
camelCase,
|
||||
kebabCase,
|
||||
parseId,
|
||||
matchGlobs,
|
||||
getTransformedPath,
|
||||
normalizeComponentInfo,
|
||||
stringifyComponentImport,
|
||||
getNameFromFilePath,
|
||||
resolveAlias,
|
||||
getPkgVersion,
|
||||
shouldTransform,
|
||||
resolveImportPath
|
||||
};
|
||||
Generated
Vendored
+32
@@ -0,0 +1,32 @@
|
||||
var __defProp = Object.defineProperty;
|
||||
var __defProps = Object.defineProperties;
|
||||
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
||||
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
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 __spreadValues = (a, b) => {
|
||||
for (var prop in b || (b = {}))
|
||||
if (__hasOwnProp.call(b, prop))
|
||||
__defNormalProp(a, prop, b[prop]);
|
||||
if (__getOwnPropSymbols)
|
||||
for (var prop of __getOwnPropSymbols(b)) {
|
||||
if (__propIsEnum.call(b, prop))
|
||||
__defNormalProp(a, prop, b[prop]);
|
||||
}
|
||||
return a;
|
||||
};
|
||||
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
||||
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
||||
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
||||
}) : x)(function(x) {
|
||||
if (typeof require !== "undefined")
|
||||
return require.apply(this, arguments);
|
||||
throw Error('Dynamic require of "' + x + '" is not supported');
|
||||
});
|
||||
|
||||
export {
|
||||
__spreadValues,
|
||||
__spreadProps,
|
||||
__require
|
||||
};
|
||||
Generated
Vendored
Generated
Vendored
+196
@@ -0,0 +1,196 @@
|
||||
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }// src/core/utils.ts
|
||||
var _path = require('path');
|
||||
var _process = require('process'); var _process2 = _interopRequireDefault(_process);
|
||||
var _minimatch = require('minimatch');
|
||||
var _resolve = require('resolve'); var _resolve2 = _interopRequireDefault(_resolve);
|
||||
var _utils = require('@antfu/utils');
|
||||
|
||||
|
||||
|
||||
var _localpkg = require('local-pkg');
|
||||
|
||||
// src/core/constants.ts
|
||||
var DISABLE_COMMENT = "/* unplugin-vue-components disabled */";
|
||||
var DIRECTIVE_IMPORT_PREFIX = "v";
|
||||
|
||||
// src/core/utils.ts
|
||||
var isSSR = Boolean(_process2.default.env.SSR || _process2.default.env.SSG || _process2.default.env.VITE_SSR || _process2.default.env.VITE_SSG);
|
||||
function pascalCase(str) {
|
||||
return capitalize(camelCase(str));
|
||||
}
|
||||
function camelCase(str) {
|
||||
return str.replace(/-(\w)/g, (_, c) => c ? c.toUpperCase() : "");
|
||||
}
|
||||
function kebabCase(key) {
|
||||
const result = key.replace(/([A-Z])/g, " $1").trim();
|
||||
return result.split(" ").join("-").toLowerCase();
|
||||
}
|
||||
function capitalize(str) {
|
||||
return str.charAt(0).toUpperCase() + str.slice(1);
|
||||
}
|
||||
function parseId(id) {
|
||||
const index = id.indexOf("?");
|
||||
if (index < 0) {
|
||||
return { path: id, query: {} };
|
||||
} else {
|
||||
const query = Object.fromEntries(new URLSearchParams(id.slice(index)));
|
||||
return {
|
||||
path: id.slice(0, index),
|
||||
query
|
||||
};
|
||||
}
|
||||
}
|
||||
function isEmpty(value) {
|
||||
if (!value || value === null || value === void 0 || Array.isArray(value) && Object.keys(value).length <= 0)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
function matchGlobs(filepath, globs) {
|
||||
for (const glob of globs) {
|
||||
if (_minimatch.minimatch.call(void 0, _utils.slash.call(void 0, filepath), glob))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function getTransformedPath(path, importPathTransform) {
|
||||
if (importPathTransform) {
|
||||
const result = importPathTransform(path);
|
||||
if (result != null)
|
||||
path = result;
|
||||
}
|
||||
return path;
|
||||
}
|
||||
function stringifyImport(info) {
|
||||
if (typeof info === "string")
|
||||
return `import '${info}'`;
|
||||
if (!info.as)
|
||||
return `import '${info.from}'`;
|
||||
else if (info.name)
|
||||
return `import { ${info.name} as ${info.as} } from '${info.from}'`;
|
||||
else
|
||||
return `import ${info.as} from '${info.from}'`;
|
||||
}
|
||||
function normalizeComponentInfo(info) {
|
||||
if ("path" in info) {
|
||||
return {
|
||||
from: info.path,
|
||||
as: info.name,
|
||||
name: info.importName,
|
||||
sideEffects: info.sideEffects
|
||||
};
|
||||
}
|
||||
return info;
|
||||
}
|
||||
function stringifyComponentImport({ as: name, from: path, name: importName, sideEffects }, ctx) {
|
||||
path = getTransformedPath(path, ctx.options.importPathTransform);
|
||||
const imports = [
|
||||
stringifyImport({ as: name, from: path, name: importName })
|
||||
];
|
||||
if (sideEffects)
|
||||
_utils.toArray.call(void 0, sideEffects).forEach((i) => imports.push(stringifyImport(i)));
|
||||
return imports.join(";");
|
||||
}
|
||||
function getNameFromFilePath(filePath, options) {
|
||||
const { resolvedDirs, directoryAsNamespace, globalNamespaces, collapseSamePrefixes, root } = options;
|
||||
const parsedFilePath = _path.parse.call(void 0, _utils.slash.call(void 0, filePath));
|
||||
let strippedPath = "";
|
||||
for (const dir of resolvedDirs) {
|
||||
if (parsedFilePath.dir.startsWith(dir)) {
|
||||
strippedPath = parsedFilePath.dir.slice(dir.length);
|
||||
break;
|
||||
}
|
||||
}
|
||||
let folders = strippedPath.slice(1).split("/").filter(Boolean);
|
||||
let filename = parsedFilePath.name;
|
||||
if (filename === "index" && !directoryAsNamespace) {
|
||||
if (isEmpty(folders))
|
||||
folders = parsedFilePath.dir.slice(root.length + 1).split("/").filter(Boolean);
|
||||
filename = `${folders.slice(-1)[0]}`;
|
||||
return filename;
|
||||
}
|
||||
if (directoryAsNamespace) {
|
||||
if (globalNamespaces.some((name) => folders.includes(name)))
|
||||
folders = folders.filter((f) => !globalNamespaces.includes(f));
|
||||
folders = folders.map((f) => f.replace(/[^a-zA-Z0-9\-]/g, ""));
|
||||
if (filename.toLowerCase() === "index")
|
||||
filename = "";
|
||||
if (!isEmpty(folders)) {
|
||||
let namespaced = [...folders, filename];
|
||||
if (collapseSamePrefixes) {
|
||||
const collapsed = [];
|
||||
for (const fileOrFolderName of namespaced) {
|
||||
let cumulativePrefix = "";
|
||||
let didCollapse = false;
|
||||
for (const parentFolder of [...collapsed].reverse()) {
|
||||
cumulativePrefix = `${capitalize(parentFolder)}${cumulativePrefix}`;
|
||||
if (pascalCase(fileOrFolderName).startsWith(pascalCase(cumulativePrefix))) {
|
||||
const collapseSamePrefix = fileOrFolderName.slice(cumulativePrefix.length);
|
||||
collapsed.push(collapseSamePrefix);
|
||||
didCollapse = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!didCollapse)
|
||||
collapsed.push(fileOrFolderName);
|
||||
}
|
||||
namespaced = collapsed;
|
||||
}
|
||||
filename = namespaced.filter(Boolean).join("-");
|
||||
}
|
||||
return filename;
|
||||
}
|
||||
return filename;
|
||||
}
|
||||
function resolveAlias(filepath, alias) {
|
||||
const result = filepath;
|
||||
if (Array.isArray(alias)) {
|
||||
for (const { find, replacement } of alias)
|
||||
result.replace(find, replacement);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
async function getPkgVersion(pkgName, defaultVersion) {
|
||||
var _a;
|
||||
try {
|
||||
const isExist = _localpkg.isPackageExists.call(void 0, pkgName);
|
||||
if (isExist) {
|
||||
const pkg = await _localpkg.getPackageInfo.call(void 0, pkgName);
|
||||
return (_a = pkg == null ? void 0 : pkg.version) != null ? _a : defaultVersion;
|
||||
} else {
|
||||
return defaultVersion;
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
return defaultVersion;
|
||||
}
|
||||
}
|
||||
function shouldTransform(code) {
|
||||
if (code.includes(DISABLE_COMMENT))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
function resolveImportPath(importName) {
|
||||
return _resolve2.default.sync(importName, {
|
||||
preserveSymlinks: false
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
exports.DISABLE_COMMENT = DISABLE_COMMENT; exports.DIRECTIVE_IMPORT_PREFIX = DIRECTIVE_IMPORT_PREFIX; exports.isSSR = isSSR; exports.pascalCase = pascalCase; exports.camelCase = camelCase; exports.kebabCase = kebabCase; exports.parseId = parseId; exports.matchGlobs = matchGlobs; exports.getTransformedPath = getTransformedPath; exports.normalizeComponentInfo = normalizeComponentInfo; exports.stringifyComponentImport = stringifyComponentImport; exports.getNameFromFilePath = getNameFromFilePath; exports.resolveAlias = resolveAlias; exports.getPkgVersion = getPkgVersion; exports.shouldTransform = shouldTransform; exports.resolveImportPath = resolveImportPath;
|
||||
Generated
Vendored
+755
@@ -0,0 +1,755 @@
|
||||
import {
|
||||
DIRECTIVE_IMPORT_PREFIX,
|
||||
DISABLE_COMMENT,
|
||||
getNameFromFilePath,
|
||||
getTransformedPath,
|
||||
matchGlobs,
|
||||
normalizeComponentInfo,
|
||||
parseId,
|
||||
pascalCase,
|
||||
resolveAlias,
|
||||
shouldTransform,
|
||||
stringifyComponentImport
|
||||
} from "./chunk-L2JFDMEX.mjs";
|
||||
import {
|
||||
__spreadProps,
|
||||
__spreadValues
|
||||
} from "./chunk-T2FESLJY.mjs";
|
||||
|
||||
// src/core/unplugin.ts
|
||||
import { existsSync as existsSync2 } from "fs";
|
||||
import process2 from "process";
|
||||
import { createUnplugin } from "unplugin";
|
||||
import { createFilter } from "@rollup/pluginutils";
|
||||
import chokidar from "chokidar";
|
||||
|
||||
// src/core/context.ts
|
||||
import { relative as relative2 } from "path";
|
||||
import process from "process";
|
||||
import Debug5 from "debug";
|
||||
import { slash as slash3, throttle, toArray as toArray2 } from "@antfu/utils";
|
||||
|
||||
// src/core/options.ts
|
||||
import { join, resolve } from "path";
|
||||
import { slash, toArray } from "@antfu/utils";
|
||||
import { getPackageInfoSync, isPackageExists as isPackageExists2 } from "local-pkg";
|
||||
|
||||
// src/core/type-imports/detect.ts
|
||||
import { isPackageExists } from "local-pkg";
|
||||
import { notNullish } from "@antfu/utils";
|
||||
|
||||
// src/core/type-imports/index.ts
|
||||
var TypeImportPresets = [
|
||||
{
|
||||
from: "vue-router",
|
||||
names: [
|
||||
"RouterView",
|
||||
"RouterLink"
|
||||
]
|
||||
},
|
||||
{
|
||||
from: "vue-starport",
|
||||
names: [
|
||||
"Starport",
|
||||
"StarportCarrier"
|
||||
]
|
||||
}
|
||||
];
|
||||
|
||||
// src/core/type-imports/detect.ts
|
||||
function detectTypeImports() {
|
||||
return TypeImportPresets.map((i) => isPackageExists(i.from) ? i : void 0).filter(notNullish);
|
||||
}
|
||||
function resolveTypeImports(imports) {
|
||||
return imports.flatMap((i) => i.names.map((n) => ({ from: i.from, name: n, as: n })));
|
||||
}
|
||||
|
||||
// src/core/options.ts
|
||||
var defaultOptions = {
|
||||
dirs: "src/components",
|
||||
extensions: "vue",
|
||||
deep: true,
|
||||
dts: isPackageExists2("typescript"),
|
||||
directoryAsNamespace: false,
|
||||
collapseSamePrefixes: false,
|
||||
globalNamespaces: [],
|
||||
resolvers: [],
|
||||
importPathTransform: (v) => v,
|
||||
allowOverrides: false
|
||||
};
|
||||
function normalizeResolvers(resolvers) {
|
||||
return toArray(resolvers).flat().map((r) => typeof r === "function" ? { resolve: r, type: "component" } : r);
|
||||
}
|
||||
function resolveGlobsExclude(root, glob) {
|
||||
const excludeReg = /^!/;
|
||||
return `${excludeReg.test(glob) ? "!" : ""}${resolve(root, glob.replace(excludeReg, ""))}`;
|
||||
}
|
||||
function resolveOptions(options, root) {
|
||||
var _a;
|
||||
const resolved = Object.assign({}, defaultOptions, options);
|
||||
resolved.resolvers = normalizeResolvers(resolved.resolvers);
|
||||
resolved.extensions = toArray(resolved.extensions);
|
||||
if (resolved.globs) {
|
||||
resolved.globs = toArray(resolved.globs).map((glob) => slash(resolveGlobsExclude(root, glob)));
|
||||
resolved.resolvedDirs = [];
|
||||
} else {
|
||||
const extsGlob = resolved.extensions.length === 1 ? resolved.extensions : `{${resolved.extensions.join(",")}}`;
|
||||
resolved.dirs = toArray(resolved.dirs);
|
||||
resolved.resolvedDirs = resolved.dirs.map((i) => slash(resolveGlobsExclude(root, i)));
|
||||
resolved.globs = resolved.resolvedDirs.map(
|
||||
(i) => resolved.deep ? slash(join(i, `**/*.${extsGlob}`)) : slash(join(i, `*.${extsGlob}`))
|
||||
);
|
||||
if (!resolved.extensions.length)
|
||||
throw new Error("[unplugin-vue-components] `extensions` option is required to search for components");
|
||||
}
|
||||
resolved.dts = !resolved.dts ? false : resolve(
|
||||
root,
|
||||
typeof resolved.dts === "string" ? resolved.dts : "components.d.ts"
|
||||
);
|
||||
if (!resolved.types && resolved.dts)
|
||||
resolved.types = detectTypeImports();
|
||||
resolved.types = resolved.types || [];
|
||||
resolved.root = root;
|
||||
resolved.version = (_a = resolved.version) != null ? _a : getVueVersion(root);
|
||||
if (resolved.version < 2 || resolved.version >= 4)
|
||||
throw new Error(`[unplugin-vue-components] unsupported version: ${resolved.version}`);
|
||||
resolved.transformer = options.transformer || `vue${Math.trunc(resolved.version)}`;
|
||||
resolved.directives = typeof options.directives === "boolean" ? options.directives : !resolved.resolvers.some((i) => i.type === "directive") ? false : resolved.version >= 3;
|
||||
return resolved;
|
||||
}
|
||||
function getVueVersion(root) {
|
||||
var _a;
|
||||
const raw = ((_a = getPackageInfoSync("vue", { paths: [root] })) == null ? void 0 : _a.version) || "3";
|
||||
const version = +raw.split(".").slice(0, 2).join(".");
|
||||
if (version === 2.7)
|
||||
return 2.7;
|
||||
else if (version < 2.7)
|
||||
return 2;
|
||||
return 3;
|
||||
}
|
||||
|
||||
// src/core/fs/glob.ts
|
||||
import fg from "fast-glob";
|
||||
import Debug from "debug";
|
||||
var debug = Debug("unplugin-vue-components:glob");
|
||||
function searchComponents(ctx) {
|
||||
var _a;
|
||||
debug(`started with: [${ctx.options.globs.join(", ")}]`);
|
||||
const root = ctx.root;
|
||||
const files = fg.sync(ctx.options.globs, {
|
||||
ignore: ["node_modules"],
|
||||
onlyFiles: true,
|
||||
cwd: root,
|
||||
absolute: true
|
||||
});
|
||||
if (!files.length && !((_a = ctx.options.resolvers) == null ? void 0 : _a.length))
|
||||
console.warn("[unplugin-vue-components] no components found");
|
||||
debug(`${files.length} components found.`);
|
||||
ctx.addComponents(files);
|
||||
}
|
||||
|
||||
// src/core/declaration.ts
|
||||
import { dirname, isAbsolute, relative } from "path";
|
||||
import { existsSync } from "fs";
|
||||
import { mkdir, readFile, writeFile as writeFile_ } from "fs/promises";
|
||||
import { notNullish as notNullish2, slash as slash2 } from "@antfu/utils";
|
||||
var multilineCommentsRE = new RegExp("\\/\\*.*?\\*\\/", "gms");
|
||||
var singlelineCommentsRE = /\/\/.*$/gm;
|
||||
function extractImports(code) {
|
||||
return Object.fromEntries(Array.from(code.matchAll(/['"]?([^\s'"]+)['"]?\s*:\s*(.+?)[,;\n]/g)).map((i) => [i[1], i[2]]));
|
||||
}
|
||||
function parseDeclaration(code) {
|
||||
var _a, _b;
|
||||
if (!code)
|
||||
return;
|
||||
code = code.replace(multilineCommentsRE, "").replace(singlelineCommentsRE, "");
|
||||
const imports = {
|
||||
component: {},
|
||||
directive: {}
|
||||
};
|
||||
const componentDeclaration = (_a = new RegExp("export\\s+interface\\s+GlobalComponents\\s*{(.*?)}", "s").exec(code)) == null ? void 0 : _a[0];
|
||||
if (componentDeclaration)
|
||||
imports.component = extractImports(componentDeclaration);
|
||||
const directiveDeclaration = (_b = new RegExp("export\\s+interface\\s+ComponentCustomProperties\\s*{(.*?)}", "s").exec(code)) == null ? void 0 : _b[0];
|
||||
if (directiveDeclaration)
|
||||
imports.directive = extractImports(directiveDeclaration);
|
||||
return imports;
|
||||
}
|
||||
function stringifyComponentInfo(filepath, { from: path, as: name, name: importName }, importPathTransform) {
|
||||
if (!name)
|
||||
return void 0;
|
||||
path = getTransformedPath(path, importPathTransform);
|
||||
const related = isAbsolute(path) ? `./${relative(dirname(filepath), path)}` : path;
|
||||
const entry = `typeof import('${slash2(related)}')['${importName || "default"}']`;
|
||||
return [name, entry];
|
||||
}
|
||||
function stringifyComponentsInfo(filepath, components, importPathTransform) {
|
||||
return Object.fromEntries(
|
||||
components.map((info) => stringifyComponentInfo(filepath, info, importPathTransform)).filter(notNullish2)
|
||||
);
|
||||
}
|
||||
function getDeclarationImports(ctx, filepath) {
|
||||
const component = stringifyComponentsInfo(filepath, [
|
||||
...Object.values(__spreadValues(__spreadValues({}, ctx.componentNameMap), ctx.componentCustomMap)),
|
||||
...resolveTypeImports(ctx.options.types)
|
||||
], ctx.options.importPathTransform);
|
||||
const directive = stringifyComponentsInfo(
|
||||
filepath,
|
||||
Object.values(ctx.directiveCustomMap),
|
||||
ctx.options.importPathTransform
|
||||
);
|
||||
if (Object.keys(component).length + Object.keys(directive).length === 0)
|
||||
return;
|
||||
return { component, directive };
|
||||
}
|
||||
function stringifyDeclarationImports(imports) {
|
||||
return Object.entries(imports).sort(([a], [b]) => a.localeCompare(b)).map(([name, v]) => {
|
||||
if (!/^\w+$/.test(name))
|
||||
name = `'${name}'`;
|
||||
return `${name}: ${v}`;
|
||||
});
|
||||
}
|
||||
function getDeclaration(ctx, filepath, originalImports) {
|
||||
const imports = getDeclarationImports(ctx, filepath);
|
||||
if (!imports)
|
||||
return;
|
||||
const declarations = {
|
||||
component: stringifyDeclarationImports(__spreadValues(__spreadValues({}, originalImports == null ? void 0 : originalImports.component), imports.component)),
|
||||
directive: stringifyDeclarationImports(__spreadValues(__spreadValues({}, originalImports == null ? void 0 : originalImports.directive), imports.directive))
|
||||
};
|
||||
const head = ctx.options.version === 2.7 ? `export {}
|
||||
|
||||
declare module 'vue' {` : `export {}
|
||||
|
||||
declare module 'vue' {`;
|
||||
let code = `/* eslint-disable */
|
||||
/* prettier-ignore */
|
||||
// @ts-nocheck
|
||||
// Generated by unplugin-vue-components
|
||||
// Read more: https://github.com/vuejs/core/pull/3399
|
||||
${head}`;
|
||||
if (Object.keys(declarations.component).length > 0) {
|
||||
code += `
|
||||
export interface GlobalComponents {
|
||||
${declarations.component.join("\n ")}
|
||||
}`;
|
||||
}
|
||||
if (Object.keys(declarations.directive).length > 0) {
|
||||
code += `
|
||||
export interface ComponentCustomProperties {
|
||||
${declarations.directive.join("\n ")}
|
||||
}`;
|
||||
}
|
||||
code += "\n}\n";
|
||||
return code;
|
||||
}
|
||||
async function writeFile(filePath, content) {
|
||||
await mkdir(dirname(filePath), { recursive: true });
|
||||
return await writeFile_(filePath, content, "utf-8");
|
||||
}
|
||||
async function writeDeclaration(ctx, filepath, removeUnused = false) {
|
||||
const originalContent = existsSync(filepath) ? await readFile(filepath, "utf-8") : "";
|
||||
const originalImports = removeUnused ? void 0 : parseDeclaration(originalContent);
|
||||
const code = getDeclaration(ctx, filepath, originalImports);
|
||||
if (!code)
|
||||
return;
|
||||
if (code !== originalContent)
|
||||
await writeFile(filepath, code);
|
||||
}
|
||||
|
||||
// src/core/transformer.ts
|
||||
import Debug4 from "debug";
|
||||
import MagicString from "magic-string";
|
||||
|
||||
// src/core/transforms/component.ts
|
||||
import Debug2 from "debug";
|
||||
var debug2 = Debug2("unplugin-vue-components:transform:component");
|
||||
function resolveVue2(code, s) {
|
||||
const results = [];
|
||||
for (const match of code.matchAll(/\b(_c|h)\([\s\n\t]*['"](.+?)["']([,)])/g)) {
|
||||
const [full, renderFunctionName, matchedName, append] = match;
|
||||
if (match.index != null && matchedName && !matchedName.startsWith("_")) {
|
||||
const start = match.index;
|
||||
const end = start + full.length;
|
||||
results.push({
|
||||
rawName: matchedName,
|
||||
replace: (resolved) => s.overwrite(start, end, `${renderFunctionName}(${resolved}${append}`)
|
||||
});
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
function resolveVue3(code, s) {
|
||||
const results = [];
|
||||
for (const match of code.matchAll(/_resolveComponent[0-9]*\("(.+?)"\)/g)) {
|
||||
const matchedName = match[1];
|
||||
if (match.index != null && matchedName && !matchedName.startsWith("_")) {
|
||||
const start = match.index;
|
||||
const end = start + match[0].length;
|
||||
results.push({
|
||||
rawName: matchedName,
|
||||
replace: (resolved) => s.overwrite(start, end, resolved)
|
||||
});
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
async function transformComponent(code, transformer2, s, ctx, sfcPath) {
|
||||
let no = 0;
|
||||
const results = transformer2 === "vue2" ? resolveVue2(code, s) : resolveVue3(code, s);
|
||||
for (const { rawName, replace } of results) {
|
||||
debug2(`| ${rawName}`);
|
||||
const name = pascalCase(rawName);
|
||||
ctx.updateUsageMap(sfcPath, [name]);
|
||||
const component = await ctx.findComponent(name, "component", [sfcPath]);
|
||||
if (component) {
|
||||
const varName = `__unplugin_components_${no}`;
|
||||
s.prepend(`${stringifyComponentImport(__spreadProps(__spreadValues({}, component), { as: varName }), ctx)};
|
||||
`);
|
||||
no += 1;
|
||||
replace(varName);
|
||||
}
|
||||
}
|
||||
debug2(`^ (${no})`);
|
||||
}
|
||||
|
||||
// src/core/transforms/directive/index.ts
|
||||
import Debug3 from "debug";
|
||||
|
||||
// src/core/transforms/directive/vue2.ts
|
||||
import { importModule, isPackageExists as isPackageExists3 } from "local-pkg";
|
||||
function getRenderFnStart(program) {
|
||||
var _a, _b;
|
||||
const renderFn = program.body.find(
|
||||
(node) => node.type === "VariableDeclaration" && node.declarations[0].id.type === "Identifier" && ["render", "_sfc_render"].includes(node.declarations[0].id.name)
|
||||
);
|
||||
const start = (_b = (_a = renderFn == null ? void 0 : renderFn.declarations[0].init) == null ? void 0 : _a.body) == null ? void 0 : _b.start;
|
||||
if (start === null || start === void 0)
|
||||
throw new Error("[unplugin-vue-components:directive] Cannot find render function position.");
|
||||
return start + 1;
|
||||
}
|
||||
async function resolveVue22(code, s) {
|
||||
var _a, _b, _c;
|
||||
if (!isPackageExists3("@babel/parser"))
|
||||
throw new Error('[unplugin-vue-components:directive] To use Vue 2 directive you will need to install Babel first: "npm install -D @babel/parser"');
|
||||
const { parse } = await importModule("@babel/parser");
|
||||
const { program } = parse(code, {
|
||||
sourceType: "module"
|
||||
});
|
||||
const nodes = [];
|
||||
const { walk } = await import("./src-B32PW6M3.mjs");
|
||||
walk(program, {
|
||||
enter(node) {
|
||||
if (node.type === "CallExpression")
|
||||
nodes.push(node);
|
||||
}
|
||||
});
|
||||
if (nodes.length === 0)
|
||||
return [];
|
||||
let _renderStart;
|
||||
const getRenderStart = () => {
|
||||
if (_renderStart !== void 0)
|
||||
return _renderStart;
|
||||
return _renderStart = getRenderFnStart(program);
|
||||
};
|
||||
const results = [];
|
||||
for (const node of nodes) {
|
||||
const { callee, arguments: args } = node;
|
||||
if (callee.type !== "Identifier" || callee.name !== "_c" || ((_a = args[1]) == null ? void 0 : _a.type) !== "ObjectExpression")
|
||||
continue;
|
||||
const directives = (_b = args[1].properties.find(
|
||||
(property) => property.type === "ObjectProperty" && property.key.type === "Identifier" && property.key.name === "directives"
|
||||
)) == null ? void 0 : _b.value;
|
||||
if (!directives || directives.type !== "ArrayExpression")
|
||||
continue;
|
||||
for (const directive of directives.elements) {
|
||||
if ((directive == null ? void 0 : directive.type) !== "ObjectExpression")
|
||||
continue;
|
||||
const nameNode = (_c = directive.properties.find(
|
||||
(p) => p.type === "ObjectProperty" && p.key.type === "Identifier" && p.key.name === "name"
|
||||
)) == null ? void 0 : _c.value;
|
||||
if ((nameNode == null ? void 0 : nameNode.type) !== "StringLiteral")
|
||||
continue;
|
||||
const name = nameNode.value;
|
||||
if (!name || name.startsWith("_"))
|
||||
continue;
|
||||
results.push({
|
||||
rawName: name,
|
||||
replace: (resolved) => {
|
||||
s.prependLeft(getRenderStart(), `
|
||||
this.$options.directives["${name}"] = ${resolved};`);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
// src/core/transforms/directive/vue3.ts
|
||||
function resolveVue32(code, s) {
|
||||
const results = [];
|
||||
for (const match of code.matchAll(/_resolveDirective\("(.+?)"\)/g)) {
|
||||
const matchedName = match[1];
|
||||
if (match.index != null && matchedName && !matchedName.startsWith("_")) {
|
||||
const start = match.index;
|
||||
const end = start + match[0].length;
|
||||
results.push({
|
||||
rawName: matchedName,
|
||||
replace: (resolved) => s.overwrite(start, end, resolved)
|
||||
});
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
// src/core/transforms/directive/index.ts
|
||||
var debug3 = Debug3("unplugin-vue-components:transform:directive");
|
||||
async function transformDirective(code, transformer2, s, ctx, sfcPath) {
|
||||
let no = 0;
|
||||
const results = await (transformer2 === "vue2" ? resolveVue22(code, s) : resolveVue32(code, s));
|
||||
for (const { rawName, replace } of results) {
|
||||
debug3(`| ${rawName}`);
|
||||
const name = `${DIRECTIVE_IMPORT_PREFIX}${pascalCase(rawName)}`;
|
||||
ctx.updateUsageMap(sfcPath, [name]);
|
||||
const directive = await ctx.findComponent(name, "directive", [sfcPath]);
|
||||
if (!directive)
|
||||
continue;
|
||||
const varName = `__unplugin_directives_${no}`;
|
||||
s.prepend(`${stringifyComponentImport(__spreadProps(__spreadValues({}, directive), { as: varName }), ctx)};
|
||||
`);
|
||||
no += 1;
|
||||
replace(varName);
|
||||
}
|
||||
debug3(`^ (${no})`);
|
||||
}
|
||||
|
||||
// src/core/transformer.ts
|
||||
var debug4 = Debug4("unplugin-vue-components:transformer");
|
||||
function transformer(ctx, transformer2) {
|
||||
return async (code, id, path) => {
|
||||
ctx.searchGlob();
|
||||
const sfcPath = ctx.normalizePath(path);
|
||||
debug4(sfcPath);
|
||||
const s = new MagicString(code);
|
||||
await transformComponent(code, transformer2, s, ctx, sfcPath);
|
||||
if (ctx.options.directives)
|
||||
await transformDirective(code, transformer2, s, ctx, sfcPath);
|
||||
s.prepend(DISABLE_COMMENT);
|
||||
const result = { code: s.toString() };
|
||||
if (ctx.sourcemap)
|
||||
result.map = s.generateMap({ source: id, includeContent: true });
|
||||
return result;
|
||||
};
|
||||
}
|
||||
|
||||
// src/core/context.ts
|
||||
var debug5 = {
|
||||
components: Debug5("unplugin-vue-components:context:components"),
|
||||
search: Debug5("unplugin-vue-components:context:search"),
|
||||
hmr: Debug5("unplugin-vue-components:context:hmr"),
|
||||
declaration: Debug5("unplugin-vue-components:declaration"),
|
||||
env: Debug5("unplugin-vue-components:env")
|
||||
};
|
||||
var Context = class {
|
||||
constructor(rawOptions) {
|
||||
this.rawOptions = rawOptions;
|
||||
this.transformer = void 0;
|
||||
this._componentPaths = /* @__PURE__ */ new Set();
|
||||
this._componentNameMap = {};
|
||||
this._componentUsageMap = {};
|
||||
this._componentCustomMap = {};
|
||||
this._directiveCustomMap = {};
|
||||
this.root = process.cwd();
|
||||
this.sourcemap = true;
|
||||
this.alias = {};
|
||||
this._searched = false;
|
||||
this.options = resolveOptions(rawOptions, this.root);
|
||||
this.generateDeclaration = throttle(500, this._generateDeclaration.bind(this), { noLeading: false });
|
||||
this.setTransformer(this.options.transformer);
|
||||
}
|
||||
setRoot(root) {
|
||||
if (this.root === root)
|
||||
return;
|
||||
debug5.env("root", root);
|
||||
this.root = root;
|
||||
this.options = resolveOptions(this.rawOptions, this.root);
|
||||
}
|
||||
setTransformer(name) {
|
||||
debug5.env("transformer", name);
|
||||
this.transformer = transformer(this, name || "vue3");
|
||||
}
|
||||
transform(code, id) {
|
||||
const { path, query } = parseId(id);
|
||||
return this.transformer(code, id, path, query);
|
||||
}
|
||||
setupViteServer(server) {
|
||||
if (this._server === server)
|
||||
return;
|
||||
this._server = server;
|
||||
this.setupWatcher(server.watcher);
|
||||
}
|
||||
setupWatcher(watcher) {
|
||||
const { globs } = this.options;
|
||||
watcher.on("unlink", (path) => {
|
||||
if (!matchGlobs(path, globs))
|
||||
return;
|
||||
path = slash3(path);
|
||||
this.removeComponents(path);
|
||||
this.onUpdate(path);
|
||||
});
|
||||
watcher.on("add", (path) => {
|
||||
if (!matchGlobs(path, globs))
|
||||
return;
|
||||
path = slash3(path);
|
||||
this.addComponents(path);
|
||||
this.onUpdate(path);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* start watcher for webpack
|
||||
*/
|
||||
setupWatcherWebpack(watcher, emitUpdate) {
|
||||
const { globs } = this.options;
|
||||
watcher.on("unlink", (path) => {
|
||||
if (!matchGlobs(path, globs))
|
||||
return;
|
||||
path = slash3(path);
|
||||
this.removeComponents(path);
|
||||
emitUpdate(path, "unlink");
|
||||
});
|
||||
watcher.on("add", (path) => {
|
||||
if (!matchGlobs(path, globs))
|
||||
return;
|
||||
path = slash3(path);
|
||||
this.addComponents(path);
|
||||
emitUpdate(path, "add");
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Record the usage of components
|
||||
* @param path
|
||||
* @param paths paths of used components
|
||||
*/
|
||||
updateUsageMap(path, paths) {
|
||||
if (!this._componentUsageMap[path])
|
||||
this._componentUsageMap[path] = /* @__PURE__ */ new Set();
|
||||
paths.forEach((p) => {
|
||||
this._componentUsageMap[path].add(p);
|
||||
});
|
||||
}
|
||||
addComponents(paths) {
|
||||
debug5.components("add", paths);
|
||||
const size = this._componentPaths.size;
|
||||
toArray2(paths).forEach((p) => this._componentPaths.add(p));
|
||||
if (this._componentPaths.size !== size) {
|
||||
this.updateComponentNameMap();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
addCustomComponents(info) {
|
||||
if (info.as)
|
||||
this._componentCustomMap[info.as] = info;
|
||||
}
|
||||
addCustomDirectives(info) {
|
||||
if (info.as)
|
||||
this._directiveCustomMap[info.as] = info;
|
||||
}
|
||||
removeComponents(paths) {
|
||||
debug5.components("remove", paths);
|
||||
const size = this._componentPaths.size;
|
||||
toArray2(paths).forEach((p) => this._componentPaths.delete(p));
|
||||
if (this._componentPaths.size !== size) {
|
||||
this.updateComponentNameMap();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
onUpdate(path) {
|
||||
this.generateDeclaration();
|
||||
if (!this._server)
|
||||
return;
|
||||
const payload = {
|
||||
type: "update",
|
||||
updates: []
|
||||
};
|
||||
const timestamp = +/* @__PURE__ */ new Date();
|
||||
const name = pascalCase(getNameFromFilePath(path, this.options));
|
||||
Object.entries(this._componentUsageMap).forEach(([key, values]) => {
|
||||
if (values.has(name)) {
|
||||
const r = `/${slash3(relative2(this.root, key))}`;
|
||||
payload.updates.push({
|
||||
acceptedPath: r,
|
||||
path: r,
|
||||
timestamp,
|
||||
type: "js-update"
|
||||
});
|
||||
}
|
||||
});
|
||||
if (payload.updates.length)
|
||||
this._server.ws.send(payload);
|
||||
}
|
||||
updateComponentNameMap() {
|
||||
this._componentNameMap = {};
|
||||
Array.from(this._componentPaths).forEach((path) => {
|
||||
const name = pascalCase(getNameFromFilePath(path, this.options));
|
||||
if (this._componentNameMap[name] && !this.options.allowOverrides) {
|
||||
console.warn(`[unplugin-vue-components] component "${name}"(${path}) has naming conflicts with other components, ignored.`);
|
||||
return;
|
||||
}
|
||||
this._componentNameMap[name] = {
|
||||
as: name,
|
||||
from: path
|
||||
};
|
||||
});
|
||||
}
|
||||
async findComponent(name, type, excludePaths = []) {
|
||||
let info = this._componentNameMap[name];
|
||||
if (info && !excludePaths.includes(info.from) && !excludePaths.includes(info.from.slice(1)))
|
||||
return info;
|
||||
for (const resolver of this.options.resolvers) {
|
||||
if (resolver.type !== type)
|
||||
continue;
|
||||
const result = await resolver.resolve(type === "directive" ? name.slice(DIRECTIVE_IMPORT_PREFIX.length) : name);
|
||||
if (!result)
|
||||
continue;
|
||||
if (typeof result === "string") {
|
||||
info = {
|
||||
as: name,
|
||||
from: result
|
||||
};
|
||||
} else {
|
||||
info = __spreadValues({
|
||||
as: name
|
||||
}, normalizeComponentInfo(result));
|
||||
}
|
||||
if (type === "component")
|
||||
this.addCustomComponents(info);
|
||||
else if (type === "directive")
|
||||
this.addCustomDirectives(info);
|
||||
return info;
|
||||
}
|
||||
return void 0;
|
||||
}
|
||||
normalizePath(path) {
|
||||
var _a, _b, _c;
|
||||
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) || []);
|
||||
}
|
||||
relative(path) {
|
||||
if (path.startsWith("/") && !path.startsWith(this.root))
|
||||
return slash3(path.slice(1));
|
||||
return slash3(relative2(this.root, path));
|
||||
}
|
||||
/**
|
||||
* This search for components in with the given options.
|
||||
* Will be called multiple times to ensure file loaded,
|
||||
* should normally run only once.
|
||||
*/
|
||||
searchGlob() {
|
||||
if (this._searched)
|
||||
return;
|
||||
searchComponents(this);
|
||||
debug5.search(this._componentNameMap);
|
||||
this._searched = true;
|
||||
}
|
||||
_generateDeclaration(removeUnused = !this._server) {
|
||||
if (!this.options.dts)
|
||||
return;
|
||||
debug5.declaration("generating");
|
||||
return writeDeclaration(this, this.options.dts, removeUnused);
|
||||
}
|
||||
get componentNameMap() {
|
||||
return this._componentNameMap;
|
||||
}
|
||||
get componentCustomMap() {
|
||||
return this._componentCustomMap;
|
||||
}
|
||||
get directiveCustomMap() {
|
||||
return this._directiveCustomMap;
|
||||
}
|
||||
};
|
||||
|
||||
// src/core/unplugin.ts
|
||||
var PLUGIN_NAME = "unplugin:webpack";
|
||||
var unplugin_default = createUnplugin((options = {}) => {
|
||||
const filter = createFilter(
|
||||
options.include || [/\.vue$/, /\.vue\?vue/, /\.vue\?v=/],
|
||||
options.exclude || [/[\\/]node_modules[\\/]/, /[\\/]\.git[\\/]/, /[\\/]\.nuxt[\\/]/]
|
||||
);
|
||||
const ctx = new Context(options);
|
||||
const api = {
|
||||
async findComponent(name, filename) {
|
||||
return await ctx.findComponent(name, "component", filename ? [filename] : []);
|
||||
},
|
||||
stringifyImport(info) {
|
||||
return stringifyComponentImport(info, ctx);
|
||||
}
|
||||
};
|
||||
return {
|
||||
name: "unplugin-vue-components",
|
||||
enforce: "post",
|
||||
api,
|
||||
transformInclude(id) {
|
||||
return filter(id);
|
||||
},
|
||||
async transform(code, id) {
|
||||
if (!shouldTransform(code))
|
||||
return null;
|
||||
try {
|
||||
const result = await ctx.transform(code, id);
|
||||
ctx.generateDeclaration();
|
||||
return result;
|
||||
} catch (e) {
|
||||
this.error(e);
|
||||
}
|
||||
},
|
||||
vite: {
|
||||
configResolved(config) {
|
||||
ctx.setRoot(config.root);
|
||||
ctx.sourcemap = true;
|
||||
if (config.plugins.find((i) => i.name === "vite-plugin-vue2"))
|
||||
ctx.setTransformer("vue2");
|
||||
if (ctx.options.dts) {
|
||||
ctx.searchGlob();
|
||||
if (!existsSync2(ctx.options.dts))
|
||||
ctx.generateDeclaration();
|
||||
}
|
||||
if (config.build.watch && config.command === "build")
|
||||
ctx.setupWatcher(chokidar.watch(ctx.options.globs));
|
||||
},
|
||||
configureServer(server) {
|
||||
ctx.setupViteServer(server);
|
||||
}
|
||||
},
|
||||
webpack(compiler) {
|
||||
let watcher;
|
||||
let fileDepQueue = [];
|
||||
compiler.hooks.watchRun.tap(PLUGIN_NAME, () => {
|
||||
if (!watcher && compiler.watching) {
|
||||
watcher = compiler.watching;
|
||||
ctx.setupWatcherWebpack(chokidar.watch(ctx.options.globs), (path, type) => {
|
||||
fileDepQueue.push({ path, type });
|
||||
process2.nextTick(() => {
|
||||
watcher.invalidate();
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
|
||||
if (fileDepQueue.length) {
|
||||
fileDepQueue.forEach(({ path, type }) => {
|
||||
if (type === "unlink")
|
||||
compilation.fileDependencies.delete(path);
|
||||
else
|
||||
compilation.fileDependencies.add(path);
|
||||
});
|
||||
fileDepQueue = [];
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
export {
|
||||
unplugin_default
|
||||
};
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
import * as esbuild from 'esbuild';
|
||||
import { Options } from './types.mjs';
|
||||
import '@rollup/pluginutils';
|
||||
import 'unplugin';
|
||||
import '@antfu/utils';
|
||||
|
||||
declare const _default: (options: Options) => esbuild.Plugin;
|
||||
|
||||
export { _default as default };
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
import * as esbuild from 'esbuild';
|
||||
import { Options } from './types.js';
|
||||
import '@rollup/pluginutils';
|
||||
import 'unplugin';
|
||||
import '@antfu/utils';
|
||||
|
||||
declare const _default: (options: Options) => esbuild.Plugin;
|
||||
|
||||
export { _default as default };
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
||||
|
||||
var _chunk5MUHROAQjs = require('./chunk-5MUHROAQ.js');
|
||||
require('./chunk-WRE7G5OD.js');
|
||||
require('./chunk-5JVO2UWC.js');
|
||||
require('./chunk-6F4PWJZI.js');
|
||||
|
||||
// src/esbuild.ts
|
||||
var esbuild_default = _chunk5MUHROAQjs.unplugin_default.esbuild;
|
||||
|
||||
|
||||
module.exports = esbuild_default;
|
||||
exports.default = module.exports;
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
import {
|
||||
unplugin_default
|
||||
} from "./chunk-XR5T4LZ3.mjs";
|
||||
import "./chunk-L2JFDMEX.mjs";
|
||||
import "./chunk-T2FESLJY.mjs";
|
||||
import "./chunk-WBQAMGXK.mjs";
|
||||
|
||||
// src/esbuild.ts
|
||||
var esbuild_default = unplugin_default.esbuild;
|
||||
export {
|
||||
esbuild_default as default
|
||||
};
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
import { Options } from './types.mjs';
|
||||
export { ComponentInfo, ComponentResolveResult, ComponentResolver, ComponentResolverFunction, ComponentResolverObject, ComponentsImportMap, ImportInfo, ImportInfoLegacy, Matcher, PublicPluginAPI, ResolvedOptions, SideEffectsInfo, SupportedTransformer, Transformer, TypeImport } from './types.mjs';
|
||||
import * as unplugin from 'unplugin';
|
||||
import '@rollup/pluginutils';
|
||||
import '@antfu/utils';
|
||||
|
||||
declare const _default: unplugin.UnpluginInstance<Options, boolean>;
|
||||
|
||||
declare function pascalCase(str: string): string;
|
||||
declare function camelCase(str: string): string;
|
||||
declare function kebabCase(key: string): string;
|
||||
|
||||
export { Options, camelCase, _default as default, kebabCase, pascalCase };
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
import { Options } from './types.js';
|
||||
export { ComponentInfo, ComponentResolveResult, ComponentResolver, ComponentResolverFunction, ComponentResolverObject, ComponentsImportMap, ImportInfo, ImportInfoLegacy, Matcher, PublicPluginAPI, ResolvedOptions, SideEffectsInfo, SupportedTransformer, Transformer, TypeImport } from './types.js';
|
||||
import * as unplugin from 'unplugin';
|
||||
import '@rollup/pluginutils';
|
||||
import '@antfu/utils';
|
||||
|
||||
declare const _default: unplugin.UnpluginInstance<Options, boolean>;
|
||||
|
||||
declare function pascalCase(str: string): string;
|
||||
declare function camelCase(str: string): string;
|
||||
declare function kebabCase(key: string): string;
|
||||
|
||||
export { Options, camelCase, _default as default, kebabCase, pascalCase };
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
||||
|
||||
var _chunk5MUHROAQjs = require('./chunk-5MUHROAQ.js');
|
||||
|
||||
|
||||
|
||||
|
||||
var _chunkWRE7G5ODjs = require('./chunk-WRE7G5OD.js');
|
||||
require('./chunk-5JVO2UWC.js');
|
||||
require('./chunk-6F4PWJZI.js');
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
exports.camelCase = _chunkWRE7G5ODjs.camelCase; exports.default = _chunk5MUHROAQjs.unplugin_default; exports.kebabCase = _chunkWRE7G5ODjs.kebabCase; exports.pascalCase = _chunkWRE7G5ODjs.pascalCase;
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
import {
|
||||
unplugin_default
|
||||
} from "./chunk-XR5T4LZ3.mjs";
|
||||
import {
|
||||
camelCase,
|
||||
kebabCase,
|
||||
pascalCase
|
||||
} from "./chunk-L2JFDMEX.mjs";
|
||||
import "./chunk-T2FESLJY.mjs";
|
||||
import "./chunk-WBQAMGXK.mjs";
|
||||
export {
|
||||
camelCase,
|
||||
unplugin_default as default,
|
||||
kebabCase,
|
||||
pascalCase
|
||||
};
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
import * as _nuxt_schema from '@nuxt/schema';
|
||||
import { Options } from './types.mjs';
|
||||
import '@rollup/pluginutils';
|
||||
import 'unplugin';
|
||||
import '@antfu/utils';
|
||||
|
||||
declare const _default: _nuxt_schema.NuxtModule<Options>;
|
||||
|
||||
export { _default as default };
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
import * as _nuxt_schema from '@nuxt/schema';
|
||||
import { Options } from './types.js';
|
||||
import '@rollup/pluginutils';
|
||||
import 'unplugin';
|
||||
import '@antfu/utils';
|
||||
|
||||
declare const _default: _nuxt_schema.NuxtModule<Options>;
|
||||
|
||||
export { _default as default };
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
||||
|
||||
var _chunk5MUHROAQjs = require('./chunk-5MUHROAQ.js');
|
||||
require('./chunk-WRE7G5OD.js');
|
||||
require('./chunk-5JVO2UWC.js');
|
||||
require('./chunk-6F4PWJZI.js');
|
||||
|
||||
// src/nuxt.ts
|
||||
var _kit = require('@nuxt/kit');
|
||||
var nuxt_default = _kit.defineNuxtModule.call(void 0, {
|
||||
setup(options) {
|
||||
_kit.addWebpackPlugin.call(void 0, _chunk5MUHROAQjs.unplugin_default.webpack(options));
|
||||
_kit.addVitePlugin.call(void 0, _chunk5MUHROAQjs.unplugin_default.vite(options));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
module.exports = nuxt_default;
|
||||
exports.default = module.exports;
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
import {
|
||||
unplugin_default
|
||||
} from "./chunk-XR5T4LZ3.mjs";
|
||||
import "./chunk-L2JFDMEX.mjs";
|
||||
import "./chunk-T2FESLJY.mjs";
|
||||
import "./chunk-WBQAMGXK.mjs";
|
||||
|
||||
// src/nuxt.ts
|
||||
import { addVitePlugin, addWebpackPlugin, defineNuxtModule } from "@nuxt/kit";
|
||||
var nuxt_default = defineNuxtModule({
|
||||
setup(options) {
|
||||
addWebpackPlugin(unplugin_default.webpack(options));
|
||||
addVitePlugin(unplugin_default.vite(options));
|
||||
}
|
||||
});
|
||||
export {
|
||||
nuxt_default as default
|
||||
};
|
||||
+540
@@ -0,0 +1,540 @@
|
||||
import { ComponentResolver, ComponentResolveResult } from './types.mjs';
|
||||
import '@rollup/pluginutils';
|
||||
import 'unplugin';
|
||||
import '@antfu/utils';
|
||||
|
||||
interface AntDesignVueResolverOptions {
|
||||
/**
|
||||
* exclude components that do not require automatic import
|
||||
*
|
||||
* @default []
|
||||
*/
|
||||
exclude?: string[];
|
||||
/**
|
||||
* import style along with components
|
||||
*
|
||||
* @default 'css'
|
||||
*/
|
||||
importStyle?: boolean | 'css' | 'less';
|
||||
/**
|
||||
* resolve `ant-design-vue' icons
|
||||
*
|
||||
* requires package `@ant-design/icons-vue`
|
||||
*
|
||||
* @default false
|
||||
*/
|
||||
resolveIcons?: boolean;
|
||||
/**
|
||||
* @deprecated use `importStyle: 'css'` instead
|
||||
*/
|
||||
importCss?: boolean;
|
||||
/**
|
||||
* @deprecated use `importStyle: 'less'` instead
|
||||
*/
|
||||
importLess?: boolean;
|
||||
/**
|
||||
* use commonjs build default false
|
||||
*/
|
||||
cjs?: boolean;
|
||||
/**
|
||||
* rename package
|
||||
*
|
||||
* @default 'ant-design-vue'
|
||||
*/
|
||||
packageName?: string;
|
||||
/**
|
||||
* customize prefix of component
|
||||
* @default 'A'
|
||||
*/
|
||||
prefix?: string;
|
||||
}
|
||||
/**
|
||||
* Resolver for Ant Design Vue
|
||||
*
|
||||
* Requires ant-design-vue@v2.2.0-beta.6 or later
|
||||
*
|
||||
* See https://github.com/antfu/unplugin-vue-components/issues/26#issuecomment-789767941 for more details
|
||||
*
|
||||
* @author @yangss3
|
||||
* @link https://antdv.com/
|
||||
*/
|
||||
declare function AntDesignVueResolver(options?: AntDesignVueResolverOptions): ComponentResolver;
|
||||
|
||||
interface ElementPlusResolverOptions {
|
||||
/**
|
||||
* import style css or sass with components
|
||||
*
|
||||
* @default 'css'
|
||||
*/
|
||||
importStyle?: boolean | 'css' | 'sass';
|
||||
/**
|
||||
* use commonjs lib & source css or scss for ssr
|
||||
*/
|
||||
ssr?: boolean;
|
||||
/**
|
||||
* specify element-plus version to load style
|
||||
*
|
||||
* @default installed version
|
||||
*/
|
||||
version?: string;
|
||||
/**
|
||||
* auto import for directives
|
||||
*
|
||||
* @default true
|
||||
*/
|
||||
directives?: boolean;
|
||||
/**
|
||||
* exclude component name, if match do not resolve the name
|
||||
*/
|
||||
exclude?: RegExp;
|
||||
/**
|
||||
* a list of component names that have no styles, so resolving their styles file should be prevented
|
||||
*/
|
||||
noStylesComponents?: string[];
|
||||
/**
|
||||
* nightly version
|
||||
*/
|
||||
nightly?: boolean;
|
||||
}
|
||||
/**
|
||||
* Resolver for Element Plus
|
||||
*
|
||||
* See https://github.com/antfu/vite-plugin-components/pull/28 for more details
|
||||
* See https://github.com/antfu/vite-plugin-components/issues/117 for more details
|
||||
*
|
||||
* @author @develar @nabaonan @sxzz
|
||||
* @link https://element-plus.org/ for element-plus
|
||||
*
|
||||
*/
|
||||
declare function ElementPlusResolver(options?: ElementPlusResolverOptions): ComponentResolver[];
|
||||
|
||||
interface ElementUiResolverOptions {
|
||||
/**
|
||||
* import style css or sass with components
|
||||
*
|
||||
* @default 'css'
|
||||
*/
|
||||
importStyle?: boolean | 'css' | 'sass';
|
||||
/**
|
||||
* exclude component name, if match do not resolve the name
|
||||
*/
|
||||
exclude?: RegExp;
|
||||
}
|
||||
/**
|
||||
* Resolver for Element-UI
|
||||
* @link https://element.eleme.cn/#/zh-CN
|
||||
* @version @element-ui ^2.15.3, @vue ^2.6.14
|
||||
* @author @nabaonan
|
||||
*/
|
||||
declare function ElementUiResolver(options?: ElementUiResolverOptions): ComponentResolver;
|
||||
|
||||
interface HeadlessUiResolverOptions {
|
||||
/**
|
||||
* prefix for headless ui components used in templates
|
||||
*
|
||||
* @default ""
|
||||
*/
|
||||
prefix?: string;
|
||||
}
|
||||
/**
|
||||
* Resolver for headlessui
|
||||
*
|
||||
* @link https://github.com/tailwindlabs/headlessui
|
||||
*/
|
||||
declare function HeadlessUiResolver(options?: HeadlessUiResolverOptions): ComponentResolver;
|
||||
|
||||
interface IduxResolverOptions {
|
||||
/**
|
||||
* exclude components that do not require automatic import
|
||||
*
|
||||
* @default []
|
||||
*/
|
||||
exclude?: string[];
|
||||
/**
|
||||
* import style along with components
|
||||
*/
|
||||
importStyle?: 'css' | 'less';
|
||||
/**
|
||||
* theme for import style
|
||||
*
|
||||
* @default 'default'
|
||||
*/
|
||||
importStyleTheme?: string;
|
||||
/**
|
||||
* The scope of the packages.
|
||||
*
|
||||
* @default '@idux'
|
||||
*/
|
||||
scope?: string;
|
||||
}
|
||||
/**
|
||||
* Resolver for `@idux/cdk`, `@idux/components` and ``@idux/pro``
|
||||
*
|
||||
* @link https://idux.site
|
||||
*/
|
||||
declare function IduxResolver(options?: IduxResolverOptions): ComponentResolver;
|
||||
|
||||
/**
|
||||
* Resolver for Inkline
|
||||
*
|
||||
* @author @alexgrozav
|
||||
* @link https://github.com/inkline/inkline
|
||||
*/
|
||||
declare function InklineResolver(): ComponentResolver;
|
||||
|
||||
/**
|
||||
* Resolver for Naive UI
|
||||
*
|
||||
* @author @antfu
|
||||
* @link https://www.naiveui.com/
|
||||
*/
|
||||
declare function NaiveUiResolver(): ComponentResolver;
|
||||
|
||||
interface PrimeVueResolverOptions {
|
||||
/**
|
||||
* import style along with components
|
||||
*
|
||||
* @default true
|
||||
*/
|
||||
importStyle?: boolean;
|
||||
/**
|
||||
* import `primeicons' icons
|
||||
*
|
||||
* requires package `primeicons`
|
||||
*
|
||||
* @default true
|
||||
*/
|
||||
importIcons?: boolean;
|
||||
/**
|
||||
* imports a free theme - set theme name here (e.g. saga-blue)
|
||||
*
|
||||
* @default ''
|
||||
*/
|
||||
importTheme?: string;
|
||||
/**
|
||||
* prefix for components (e.g. 'P' to resolve Menu from PMenu)
|
||||
*
|
||||
* @default ''
|
||||
*/
|
||||
prefix?: string;
|
||||
}
|
||||
/**
|
||||
* Resolver for PrimeVue - If you're using a component with the same tag as an native HTML element (e.g. button) the component must be in uppercase
|
||||
*
|
||||
* @link https://github.com/primefaces/primevue
|
||||
*/
|
||||
declare function PrimeVueResolver(options?: PrimeVueResolverOptions): ComponentResolver;
|
||||
|
||||
interface VantResolverOptions {
|
||||
/**
|
||||
* import style css or less along with components
|
||||
*
|
||||
* @default true
|
||||
*/
|
||||
importStyle?: boolean | 'css' | 'less';
|
||||
}
|
||||
/**
|
||||
* Resolver for Vant
|
||||
*
|
||||
* @link https://github.com/youzan/vant
|
||||
*/
|
||||
declare function VantResolver(options?: VantResolverOptions): ComponentResolver;
|
||||
|
||||
interface VarletUIResolverOptions {
|
||||
/**
|
||||
* support vue version
|
||||
* vue3 use @varlet/ui, vue2 use @varlet-vue2/ui
|
||||
*
|
||||
* @default 'vue3'
|
||||
*/
|
||||
version?: 'vue3' | 'vue2';
|
||||
/**
|
||||
* import style along with components
|
||||
*
|
||||
* @default 'css'
|
||||
*/
|
||||
importStyle?: boolean | 'css' | 'less';
|
||||
/**
|
||||
* auto import for directives
|
||||
*
|
||||
* @default true
|
||||
*/
|
||||
directives?: boolean;
|
||||
/**
|
||||
* compatible with unplugin-auto-import
|
||||
*
|
||||
* @default false
|
||||
*/
|
||||
autoImport?: boolean;
|
||||
/**
|
||||
* @deprecated use `importStyle: 'css'` instead
|
||||
*/
|
||||
importCss?: boolean;
|
||||
/**
|
||||
* @deprecated use `importStyle: 'less'` instead
|
||||
*/
|
||||
importLess?: boolean;
|
||||
}
|
||||
declare function getResolved(name: string, options: VarletUIResolverOptions): ComponentResolveResult;
|
||||
/**
|
||||
* Resolver for VarletUI
|
||||
*
|
||||
* @link https://github.com/varletjs/varlet
|
||||
* @link https://github.com/varletjs/varlet-vue2
|
||||
*/
|
||||
declare function VarletUIResolver(options?: VarletUIResolverOptions): ComponentResolver[];
|
||||
|
||||
interface VeuiPeerConfig {
|
||||
/**
|
||||
* The package name of the peer module.
|
||||
*/
|
||||
package: string;
|
||||
/**
|
||||
* The directory path of the peer module.
|
||||
* @default 'components'
|
||||
*/
|
||||
path?: string;
|
||||
/**
|
||||
* The file name template for the peer module.
|
||||
* @default '{module}.css'
|
||||
*/
|
||||
fileName?: `${string}{module}${string}`;
|
||||
/**
|
||||
* The text transform to be applied to the '{module}' part of the file name.
|
||||
* @default 'kebab-case'
|
||||
*/
|
||||
transform?: 'kebab-case' | 'camelCase' | 'PascalCase' | false;
|
||||
}
|
||||
type SupportedLocale = 'en-US' | 'zh-Hans';
|
||||
interface VeuiResolverOptions {
|
||||
/**
|
||||
* The alias of 'veui` package.
|
||||
* @default 'veui'
|
||||
*/
|
||||
alias?: string;
|
||||
/**
|
||||
* Peer modules to be injected.
|
||||
*/
|
||||
modules?: VeuiPeerConfig[];
|
||||
/**
|
||||
* Locale modules to be injected.
|
||||
* @default 'zh-Hans'
|
||||
*/
|
||||
locale?: SupportedLocale | SupportedLocale[] | false;
|
||||
/**
|
||||
* Global modules to be injected to all components.
|
||||
* @default []
|
||||
*/
|
||||
global?: string[];
|
||||
}
|
||||
/**
|
||||
* Resolver for VEUI
|
||||
*
|
||||
* @link https://github.com/ecomfe/veui
|
||||
*/
|
||||
declare function VeuiResolver(options?: VeuiResolverOptions): ComponentResolver;
|
||||
|
||||
/**
|
||||
* Resolver for View UI
|
||||
* @requires @originjs/vite-plugin-commonjs
|
||||
* @author @nabaonan
|
||||
* @link https://www.iviewui.com/
|
||||
* @description has known problems list below
|
||||
* - select component render error PR: https://github.com/view-design/ViewUI/pull/944, choose can't display value,because click option trigger twice,at second time,select value turn into undefined.
|
||||
* - scroll component has a template syntax called lang='html',it is require html-loader,but vite plugin not support yet,remove it can run. relate pr: https://github.com/view-design/ViewUI/pull/985
|
||||
*/
|
||||
declare function ViewUiResolver(): ComponentResolver;
|
||||
|
||||
/**
|
||||
* Resolver for Vuetify
|
||||
*
|
||||
* @link https://github.com/vuetifyjs/vuetify
|
||||
*/
|
||||
declare function VuetifyResolver(): ComponentResolver;
|
||||
/**
|
||||
* Resolver for Vuetify 3 Beta
|
||||
*
|
||||
* @link https://github.com/vuetifyjs/vuetify
|
||||
*/
|
||||
declare function Vuetify3Resolver(): ComponentResolver;
|
||||
|
||||
/**
|
||||
* Resolver for VueUse
|
||||
*
|
||||
* @link https://github.com/vueuse/vueuse
|
||||
*/
|
||||
declare function VueUseComponentsResolver(): ComponentResolver;
|
||||
|
||||
/**
|
||||
* Resolver for VueUse
|
||||
*
|
||||
* @link https://github.com/vueuse/vueuse
|
||||
*/
|
||||
declare function VueUseDirectiveResolver(): ComponentResolver;
|
||||
|
||||
/**
|
||||
* Resolver for Quasar
|
||||
*
|
||||
* @link https://github.com/quasarframework/quasar
|
||||
*/
|
||||
declare function QuasarResolver(): ComponentResolver;
|
||||
|
||||
interface DevResolverOptions {
|
||||
/**
|
||||
* bring in components and styles
|
||||
*
|
||||
* @default true
|
||||
*/
|
||||
importStyle?: boolean;
|
||||
/**
|
||||
* auto import for directives
|
||||
*
|
||||
* @default true
|
||||
*/
|
||||
directives?: boolean;
|
||||
/**
|
||||
* use umd lib file
|
||||
*/
|
||||
ssr?: boolean;
|
||||
}
|
||||
declare function DevUiResolver(options?: DevResolverOptions): ComponentResolver[];
|
||||
|
||||
type DisallowResolveIconOption = undefined | false | {
|
||||
enable: false;
|
||||
};
|
||||
type AllowResolveIconOption = true | {
|
||||
enable: true;
|
||||
iconPrefix?: string;
|
||||
};
|
||||
type ResolveIconsOption = DisallowResolveIconOption | AllowResolveIconOption;
|
||||
interface ArcoResolverOptions {
|
||||
/**
|
||||
* exclude components that do not require automatic import
|
||||
*
|
||||
* @default []
|
||||
*/
|
||||
exclude?: string | RegExp | (string | RegExp)[];
|
||||
/**
|
||||
* import style css or less with components
|
||||
*
|
||||
* @default 'css'
|
||||
*/
|
||||
importStyle?: boolean | 'css' | 'less';
|
||||
/**
|
||||
* resolve icons
|
||||
*
|
||||
* @default false
|
||||
*/
|
||||
resolveIcons?: ResolveIconsOption;
|
||||
/**
|
||||
* Control style automatic import
|
||||
*
|
||||
* @default true
|
||||
*/
|
||||
sideEffect?: boolean;
|
||||
}
|
||||
/**
|
||||
* Resolver for Arco Design Vue
|
||||
*
|
||||
* Requires arco-design/web-vue@2.11.0 or later
|
||||
*
|
||||
* @author @flsion
|
||||
* @link https://arco.design/ for arco-design
|
||||
*
|
||||
*/
|
||||
declare function ArcoResolver(options?: ArcoResolverOptions): ComponentResolver;
|
||||
|
||||
interface TDesignResolverOptions {
|
||||
/**
|
||||
* select the specified library
|
||||
* @default 'vue'
|
||||
*/
|
||||
library?: 'vue' | 'vue-next' | 'react' | 'mobile-vue' | 'mobile-react';
|
||||
/**
|
||||
* resolve `tdesign-icons'
|
||||
* @default false
|
||||
*/
|
||||
resolveIcons?: boolean;
|
||||
/**
|
||||
* whether to import ESM version
|
||||
* @default false
|
||||
*/
|
||||
esm?: boolean;
|
||||
/**
|
||||
* exclude component name, if match do not resolve the name
|
||||
*
|
||||
*/
|
||||
exclude?: string | RegExp | (string | RegExp)[];
|
||||
}
|
||||
declare function TDesignResolver(options?: TDesignResolverOptions): ComponentResolver;
|
||||
|
||||
interface LayuiVueResolverOptions {
|
||||
/**
|
||||
* import style along with components
|
||||
*
|
||||
* @default 'css'
|
||||
*/
|
||||
importStyle?: boolean | 'css';
|
||||
/**
|
||||
* resolve '@layui/layui-vue' icons
|
||||
* requires package `@layui/icons-vue`
|
||||
*
|
||||
* @default false
|
||||
*/
|
||||
resolveIcons?: boolean;
|
||||
/**
|
||||
* exclude components that do not require automatic import
|
||||
*
|
||||
*/
|
||||
exclude?: Array<string | RegExp>;
|
||||
}
|
||||
/**
|
||||
* Resolver for layui-vue
|
||||
*
|
||||
* @link http://www.layui-vue.com/ for layui-vue
|
||||
*
|
||||
*/
|
||||
declare function LayuiVueResolver(options?: LayuiVueResolverOptions): ComponentResolver;
|
||||
|
||||
interface BootstrapVueResolverOptions {
|
||||
/**
|
||||
* Auto import for directives.
|
||||
*
|
||||
* @default true
|
||||
*/
|
||||
directives?: boolean;
|
||||
}
|
||||
/**
|
||||
* Resolver for BootstrapVue
|
||||
*
|
||||
* @link https://github.com/bootstrap-vue/bootstrap-vue
|
||||
*/
|
||||
declare function BootstrapVueResolver(_options?: BootstrapVueResolverOptions): ComponentResolver[];
|
||||
/**
|
||||
* Resolver for BootstrapVueNext
|
||||
*
|
||||
* @link https://github.com/bootstrap-vue/bootstrap-vue-next
|
||||
*/
|
||||
declare function BootstrapVueNextResolver(_options?: BootstrapVueResolverOptions): Array<ComponentResolver>;
|
||||
/**
|
||||
* Resolver for legacy BootstrapVue3 apps
|
||||
*
|
||||
* @deprecated use BootstrapVueNextResolver with https://github.com/bootstrap-vue/bootstrap-vue-next
|
||||
* @link https://www.npmjs.com/package/bootstrap-vue-3
|
||||
*/
|
||||
declare function BootstrapVue3Resolver(_options?: BootstrapVueResolverOptions): Array<ComponentResolver>;
|
||||
|
||||
/**
|
||||
* source: https://github.com/nuxt-modules/ionic/blob/main/src/imports.ts
|
||||
* @author @danielroe
|
||||
*/
|
||||
declare const IonicBuiltInComponents: string[];
|
||||
/**
|
||||
* Resolver for ionic framework
|
||||
*
|
||||
* @author @mathsgod @reslear
|
||||
* @link https://ionicframework.com/
|
||||
*/
|
||||
declare function IonicResolver(): ComponentResolver;
|
||||
|
||||
export { AllowResolveIconOption, AntDesignVueResolver, AntDesignVueResolverOptions, ArcoResolver, ArcoResolverOptions, BootstrapVue3Resolver, BootstrapVueNextResolver, BootstrapVueResolver, BootstrapVueResolverOptions, DevResolverOptions, DevUiResolver, DisallowResolveIconOption, ElementPlusResolver, ElementPlusResolverOptions, ElementUiResolver, ElementUiResolverOptions, HeadlessUiResolver, HeadlessUiResolverOptions, IduxResolver, IduxResolverOptions, InklineResolver, IonicBuiltInComponents, IonicResolver, LayuiVueResolver, LayuiVueResolverOptions, NaiveUiResolver, PrimeVueResolver, PrimeVueResolverOptions, QuasarResolver, ResolveIconsOption, TDesignResolver, TDesignResolverOptions, VantResolver, VantResolverOptions, VarletUIResolver, VarletUIResolverOptions, VeuiResolver, VeuiResolverOptions, ViewUiResolver, VueUseComponentsResolver, VueUseDirectiveResolver, Vuetify3Resolver, VuetifyResolver, getResolved };
|
||||
+540
@@ -0,0 +1,540 @@
|
||||
import { ComponentResolver, ComponentResolveResult } from './types.js';
|
||||
import '@rollup/pluginutils';
|
||||
import 'unplugin';
|
||||
import '@antfu/utils';
|
||||
|
||||
interface AntDesignVueResolverOptions {
|
||||
/**
|
||||
* exclude components that do not require automatic import
|
||||
*
|
||||
* @default []
|
||||
*/
|
||||
exclude?: string[];
|
||||
/**
|
||||
* import style along with components
|
||||
*
|
||||
* @default 'css'
|
||||
*/
|
||||
importStyle?: boolean | 'css' | 'less';
|
||||
/**
|
||||
* resolve `ant-design-vue' icons
|
||||
*
|
||||
* requires package `@ant-design/icons-vue`
|
||||
*
|
||||
* @default false
|
||||
*/
|
||||
resolveIcons?: boolean;
|
||||
/**
|
||||
* @deprecated use `importStyle: 'css'` instead
|
||||
*/
|
||||
importCss?: boolean;
|
||||
/**
|
||||
* @deprecated use `importStyle: 'less'` instead
|
||||
*/
|
||||
importLess?: boolean;
|
||||
/**
|
||||
* use commonjs build default false
|
||||
*/
|
||||
cjs?: boolean;
|
||||
/**
|
||||
* rename package
|
||||
*
|
||||
* @default 'ant-design-vue'
|
||||
*/
|
||||
packageName?: string;
|
||||
/**
|
||||
* customize prefix of component
|
||||
* @default 'A'
|
||||
*/
|
||||
prefix?: string;
|
||||
}
|
||||
/**
|
||||
* Resolver for Ant Design Vue
|
||||
*
|
||||
* Requires ant-design-vue@v2.2.0-beta.6 or later
|
||||
*
|
||||
* See https://github.com/antfu/unplugin-vue-components/issues/26#issuecomment-789767941 for more details
|
||||
*
|
||||
* @author @yangss3
|
||||
* @link https://antdv.com/
|
||||
*/
|
||||
declare function AntDesignVueResolver(options?: AntDesignVueResolverOptions): ComponentResolver;
|
||||
|
||||
interface ElementPlusResolverOptions {
|
||||
/**
|
||||
* import style css or sass with components
|
||||
*
|
||||
* @default 'css'
|
||||
*/
|
||||
importStyle?: boolean | 'css' | 'sass';
|
||||
/**
|
||||
* use commonjs lib & source css or scss for ssr
|
||||
*/
|
||||
ssr?: boolean;
|
||||
/**
|
||||
* specify element-plus version to load style
|
||||
*
|
||||
* @default installed version
|
||||
*/
|
||||
version?: string;
|
||||
/**
|
||||
* auto import for directives
|
||||
*
|
||||
* @default true
|
||||
*/
|
||||
directives?: boolean;
|
||||
/**
|
||||
* exclude component name, if match do not resolve the name
|
||||
*/
|
||||
exclude?: RegExp;
|
||||
/**
|
||||
* a list of component names that have no styles, so resolving their styles file should be prevented
|
||||
*/
|
||||
noStylesComponents?: string[];
|
||||
/**
|
||||
* nightly version
|
||||
*/
|
||||
nightly?: boolean;
|
||||
}
|
||||
/**
|
||||
* Resolver for Element Plus
|
||||
*
|
||||
* See https://github.com/antfu/vite-plugin-components/pull/28 for more details
|
||||
* See https://github.com/antfu/vite-plugin-components/issues/117 for more details
|
||||
*
|
||||
* @author @develar @nabaonan @sxzz
|
||||
* @link https://element-plus.org/ for element-plus
|
||||
*
|
||||
*/
|
||||
declare function ElementPlusResolver(options?: ElementPlusResolverOptions): ComponentResolver[];
|
||||
|
||||
interface ElementUiResolverOptions {
|
||||
/**
|
||||
* import style css or sass with components
|
||||
*
|
||||
* @default 'css'
|
||||
*/
|
||||
importStyle?: boolean | 'css' | 'sass';
|
||||
/**
|
||||
* exclude component name, if match do not resolve the name
|
||||
*/
|
||||
exclude?: RegExp;
|
||||
}
|
||||
/**
|
||||
* Resolver for Element-UI
|
||||
* @link https://element.eleme.cn/#/zh-CN
|
||||
* @version @element-ui ^2.15.3, @vue ^2.6.14
|
||||
* @author @nabaonan
|
||||
*/
|
||||
declare function ElementUiResolver(options?: ElementUiResolverOptions): ComponentResolver;
|
||||
|
||||
interface HeadlessUiResolverOptions {
|
||||
/**
|
||||
* prefix for headless ui components used in templates
|
||||
*
|
||||
* @default ""
|
||||
*/
|
||||
prefix?: string;
|
||||
}
|
||||
/**
|
||||
* Resolver for headlessui
|
||||
*
|
||||
* @link https://github.com/tailwindlabs/headlessui
|
||||
*/
|
||||
declare function HeadlessUiResolver(options?: HeadlessUiResolverOptions): ComponentResolver;
|
||||
|
||||
interface IduxResolverOptions {
|
||||
/**
|
||||
* exclude components that do not require automatic import
|
||||
*
|
||||
* @default []
|
||||
*/
|
||||
exclude?: string[];
|
||||
/**
|
||||
* import style along with components
|
||||
*/
|
||||
importStyle?: 'css' | 'less';
|
||||
/**
|
||||
* theme for import style
|
||||
*
|
||||
* @default 'default'
|
||||
*/
|
||||
importStyleTheme?: string;
|
||||
/**
|
||||
* The scope of the packages.
|
||||
*
|
||||
* @default '@idux'
|
||||
*/
|
||||
scope?: string;
|
||||
}
|
||||
/**
|
||||
* Resolver for `@idux/cdk`, `@idux/components` and ``@idux/pro``
|
||||
*
|
||||
* @link https://idux.site
|
||||
*/
|
||||
declare function IduxResolver(options?: IduxResolverOptions): ComponentResolver;
|
||||
|
||||
/**
|
||||
* Resolver for Inkline
|
||||
*
|
||||
* @author @alexgrozav
|
||||
* @link https://github.com/inkline/inkline
|
||||
*/
|
||||
declare function InklineResolver(): ComponentResolver;
|
||||
|
||||
/**
|
||||
* Resolver for Naive UI
|
||||
*
|
||||
* @author @antfu
|
||||
* @link https://www.naiveui.com/
|
||||
*/
|
||||
declare function NaiveUiResolver(): ComponentResolver;
|
||||
|
||||
interface PrimeVueResolverOptions {
|
||||
/**
|
||||
* import style along with components
|
||||
*
|
||||
* @default true
|
||||
*/
|
||||
importStyle?: boolean;
|
||||
/**
|
||||
* import `primeicons' icons
|
||||
*
|
||||
* requires package `primeicons`
|
||||
*
|
||||
* @default true
|
||||
*/
|
||||
importIcons?: boolean;
|
||||
/**
|
||||
* imports a free theme - set theme name here (e.g. saga-blue)
|
||||
*
|
||||
* @default ''
|
||||
*/
|
||||
importTheme?: string;
|
||||
/**
|
||||
* prefix for components (e.g. 'P' to resolve Menu from PMenu)
|
||||
*
|
||||
* @default ''
|
||||
*/
|
||||
prefix?: string;
|
||||
}
|
||||
/**
|
||||
* Resolver for PrimeVue - If you're using a component with the same tag as an native HTML element (e.g. button) the component must be in uppercase
|
||||
*
|
||||
* @link https://github.com/primefaces/primevue
|
||||
*/
|
||||
declare function PrimeVueResolver(options?: PrimeVueResolverOptions): ComponentResolver;
|
||||
|
||||
interface VantResolverOptions {
|
||||
/**
|
||||
* import style css or less along with components
|
||||
*
|
||||
* @default true
|
||||
*/
|
||||
importStyle?: boolean | 'css' | 'less';
|
||||
}
|
||||
/**
|
||||
* Resolver for Vant
|
||||
*
|
||||
* @link https://github.com/youzan/vant
|
||||
*/
|
||||
declare function VantResolver(options?: VantResolverOptions): ComponentResolver;
|
||||
|
||||
interface VarletUIResolverOptions {
|
||||
/**
|
||||
* support vue version
|
||||
* vue3 use @varlet/ui, vue2 use @varlet-vue2/ui
|
||||
*
|
||||
* @default 'vue3'
|
||||
*/
|
||||
version?: 'vue3' | 'vue2';
|
||||
/**
|
||||
* import style along with components
|
||||
*
|
||||
* @default 'css'
|
||||
*/
|
||||
importStyle?: boolean | 'css' | 'less';
|
||||
/**
|
||||
* auto import for directives
|
||||
*
|
||||
* @default true
|
||||
*/
|
||||
directives?: boolean;
|
||||
/**
|
||||
* compatible with unplugin-auto-import
|
||||
*
|
||||
* @default false
|
||||
*/
|
||||
autoImport?: boolean;
|
||||
/**
|
||||
* @deprecated use `importStyle: 'css'` instead
|
||||
*/
|
||||
importCss?: boolean;
|
||||
/**
|
||||
* @deprecated use `importStyle: 'less'` instead
|
||||
*/
|
||||
importLess?: boolean;
|
||||
}
|
||||
declare function getResolved(name: string, options: VarletUIResolverOptions): ComponentResolveResult;
|
||||
/**
|
||||
* Resolver for VarletUI
|
||||
*
|
||||
* @link https://github.com/varletjs/varlet
|
||||
* @link https://github.com/varletjs/varlet-vue2
|
||||
*/
|
||||
declare function VarletUIResolver(options?: VarletUIResolverOptions): ComponentResolver[];
|
||||
|
||||
interface VeuiPeerConfig {
|
||||
/**
|
||||
* The package name of the peer module.
|
||||
*/
|
||||
package: string;
|
||||
/**
|
||||
* The directory path of the peer module.
|
||||
* @default 'components'
|
||||
*/
|
||||
path?: string;
|
||||
/**
|
||||
* The file name template for the peer module.
|
||||
* @default '{module}.css'
|
||||
*/
|
||||
fileName?: `${string}{module}${string}`;
|
||||
/**
|
||||
* The text transform to be applied to the '{module}' part of the file name.
|
||||
* @default 'kebab-case'
|
||||
*/
|
||||
transform?: 'kebab-case' | 'camelCase' | 'PascalCase' | false;
|
||||
}
|
||||
type SupportedLocale = 'en-US' | 'zh-Hans';
|
||||
interface VeuiResolverOptions {
|
||||
/**
|
||||
* The alias of 'veui` package.
|
||||
* @default 'veui'
|
||||
*/
|
||||
alias?: string;
|
||||
/**
|
||||
* Peer modules to be injected.
|
||||
*/
|
||||
modules?: VeuiPeerConfig[];
|
||||
/**
|
||||
* Locale modules to be injected.
|
||||
* @default 'zh-Hans'
|
||||
*/
|
||||
locale?: SupportedLocale | SupportedLocale[] | false;
|
||||
/**
|
||||
* Global modules to be injected to all components.
|
||||
* @default []
|
||||
*/
|
||||
global?: string[];
|
||||
}
|
||||
/**
|
||||
* Resolver for VEUI
|
||||
*
|
||||
* @link https://github.com/ecomfe/veui
|
||||
*/
|
||||
declare function VeuiResolver(options?: VeuiResolverOptions): ComponentResolver;
|
||||
|
||||
/**
|
||||
* Resolver for View UI
|
||||
* @requires @originjs/vite-plugin-commonjs
|
||||
* @author @nabaonan
|
||||
* @link https://www.iviewui.com/
|
||||
* @description has known problems list below
|
||||
* - select component render error PR: https://github.com/view-design/ViewUI/pull/944, choose can't display value,because click option trigger twice,at second time,select value turn into undefined.
|
||||
* - scroll component has a template syntax called lang='html',it is require html-loader,but vite plugin not support yet,remove it can run. relate pr: https://github.com/view-design/ViewUI/pull/985
|
||||
*/
|
||||
declare function ViewUiResolver(): ComponentResolver;
|
||||
|
||||
/**
|
||||
* Resolver for Vuetify
|
||||
*
|
||||
* @link https://github.com/vuetifyjs/vuetify
|
||||
*/
|
||||
declare function VuetifyResolver(): ComponentResolver;
|
||||
/**
|
||||
* Resolver for Vuetify 3 Beta
|
||||
*
|
||||
* @link https://github.com/vuetifyjs/vuetify
|
||||
*/
|
||||
declare function Vuetify3Resolver(): ComponentResolver;
|
||||
|
||||
/**
|
||||
* Resolver for VueUse
|
||||
*
|
||||
* @link https://github.com/vueuse/vueuse
|
||||
*/
|
||||
declare function VueUseComponentsResolver(): ComponentResolver;
|
||||
|
||||
/**
|
||||
* Resolver for VueUse
|
||||
*
|
||||
* @link https://github.com/vueuse/vueuse
|
||||
*/
|
||||
declare function VueUseDirectiveResolver(): ComponentResolver;
|
||||
|
||||
/**
|
||||
* Resolver for Quasar
|
||||
*
|
||||
* @link https://github.com/quasarframework/quasar
|
||||
*/
|
||||
declare function QuasarResolver(): ComponentResolver;
|
||||
|
||||
interface DevResolverOptions {
|
||||
/**
|
||||
* bring in components and styles
|
||||
*
|
||||
* @default true
|
||||
*/
|
||||
importStyle?: boolean;
|
||||
/**
|
||||
* auto import for directives
|
||||
*
|
||||
* @default true
|
||||
*/
|
||||
directives?: boolean;
|
||||
/**
|
||||
* use umd lib file
|
||||
*/
|
||||
ssr?: boolean;
|
||||
}
|
||||
declare function DevUiResolver(options?: DevResolverOptions): ComponentResolver[];
|
||||
|
||||
type DisallowResolveIconOption = undefined | false | {
|
||||
enable: false;
|
||||
};
|
||||
type AllowResolveIconOption = true | {
|
||||
enable: true;
|
||||
iconPrefix?: string;
|
||||
};
|
||||
type ResolveIconsOption = DisallowResolveIconOption | AllowResolveIconOption;
|
||||
interface ArcoResolverOptions {
|
||||
/**
|
||||
* exclude components that do not require automatic import
|
||||
*
|
||||
* @default []
|
||||
*/
|
||||
exclude?: string | RegExp | (string | RegExp)[];
|
||||
/**
|
||||
* import style css or less with components
|
||||
*
|
||||
* @default 'css'
|
||||
*/
|
||||
importStyle?: boolean | 'css' | 'less';
|
||||
/**
|
||||
* resolve icons
|
||||
*
|
||||
* @default false
|
||||
*/
|
||||
resolveIcons?: ResolveIconsOption;
|
||||
/**
|
||||
* Control style automatic import
|
||||
*
|
||||
* @default true
|
||||
*/
|
||||
sideEffect?: boolean;
|
||||
}
|
||||
/**
|
||||
* Resolver for Arco Design Vue
|
||||
*
|
||||
* Requires arco-design/web-vue@2.11.0 or later
|
||||
*
|
||||
* @author @flsion
|
||||
* @link https://arco.design/ for arco-design
|
||||
*
|
||||
*/
|
||||
declare function ArcoResolver(options?: ArcoResolverOptions): ComponentResolver;
|
||||
|
||||
interface TDesignResolverOptions {
|
||||
/**
|
||||
* select the specified library
|
||||
* @default 'vue'
|
||||
*/
|
||||
library?: 'vue' | 'vue-next' | 'react' | 'mobile-vue' | 'mobile-react';
|
||||
/**
|
||||
* resolve `tdesign-icons'
|
||||
* @default false
|
||||
*/
|
||||
resolveIcons?: boolean;
|
||||
/**
|
||||
* whether to import ESM version
|
||||
* @default false
|
||||
*/
|
||||
esm?: boolean;
|
||||
/**
|
||||
* exclude component name, if match do not resolve the name
|
||||
*
|
||||
*/
|
||||
exclude?: string | RegExp | (string | RegExp)[];
|
||||
}
|
||||
declare function TDesignResolver(options?: TDesignResolverOptions): ComponentResolver;
|
||||
|
||||
interface LayuiVueResolverOptions {
|
||||
/**
|
||||
* import style along with components
|
||||
*
|
||||
* @default 'css'
|
||||
*/
|
||||
importStyle?: boolean | 'css';
|
||||
/**
|
||||
* resolve '@layui/layui-vue' icons
|
||||
* requires package `@layui/icons-vue`
|
||||
*
|
||||
* @default false
|
||||
*/
|
||||
resolveIcons?: boolean;
|
||||
/**
|
||||
* exclude components that do not require automatic import
|
||||
*
|
||||
*/
|
||||
exclude?: Array<string | RegExp>;
|
||||
}
|
||||
/**
|
||||
* Resolver for layui-vue
|
||||
*
|
||||
* @link http://www.layui-vue.com/ for layui-vue
|
||||
*
|
||||
*/
|
||||
declare function LayuiVueResolver(options?: LayuiVueResolverOptions): ComponentResolver;
|
||||
|
||||
interface BootstrapVueResolverOptions {
|
||||
/**
|
||||
* Auto import for directives.
|
||||
*
|
||||
* @default true
|
||||
*/
|
||||
directives?: boolean;
|
||||
}
|
||||
/**
|
||||
* Resolver for BootstrapVue
|
||||
*
|
||||
* @link https://github.com/bootstrap-vue/bootstrap-vue
|
||||
*/
|
||||
declare function BootstrapVueResolver(_options?: BootstrapVueResolverOptions): ComponentResolver[];
|
||||
/**
|
||||
* Resolver for BootstrapVueNext
|
||||
*
|
||||
* @link https://github.com/bootstrap-vue/bootstrap-vue-next
|
||||
*/
|
||||
declare function BootstrapVueNextResolver(_options?: BootstrapVueResolverOptions): Array<ComponentResolver>;
|
||||
/**
|
||||
* Resolver for legacy BootstrapVue3 apps
|
||||
*
|
||||
* @deprecated use BootstrapVueNextResolver with https://github.com/bootstrap-vue/bootstrap-vue-next
|
||||
* @link https://www.npmjs.com/package/bootstrap-vue-3
|
||||
*/
|
||||
declare function BootstrapVue3Resolver(_options?: BootstrapVueResolverOptions): Array<ComponentResolver>;
|
||||
|
||||
/**
|
||||
* source: https://github.com/nuxt-modules/ionic/blob/main/src/imports.ts
|
||||
* @author @danielroe
|
||||
*/
|
||||
declare const IonicBuiltInComponents: string[];
|
||||
/**
|
||||
* Resolver for ionic framework
|
||||
*
|
||||
* @author @mathsgod @reslear
|
||||
* @link https://ionicframework.com/
|
||||
*/
|
||||
declare function IonicResolver(): ComponentResolver;
|
||||
|
||||
export { AllowResolveIconOption, AntDesignVueResolver, AntDesignVueResolverOptions, ArcoResolver, ArcoResolverOptions, BootstrapVue3Resolver, BootstrapVueNextResolver, BootstrapVueResolver, BootstrapVueResolverOptions, DevResolverOptions, DevUiResolver, DisallowResolveIconOption, ElementPlusResolver, ElementPlusResolverOptions, ElementUiResolver, ElementUiResolverOptions, HeadlessUiResolver, HeadlessUiResolverOptions, IduxResolver, IduxResolverOptions, InklineResolver, IonicBuiltInComponents, IonicResolver, LayuiVueResolver, LayuiVueResolverOptions, NaiveUiResolver, PrimeVueResolver, PrimeVueResolverOptions, QuasarResolver, ResolveIconsOption, TDesignResolver, TDesignResolverOptions, VantResolver, VantResolverOptions, VarletUIResolver, VarletUIResolverOptions, VeuiResolver, VeuiResolverOptions, ViewUiResolver, VueUseComponentsResolver, VueUseDirectiveResolver, Vuetify3Resolver, VuetifyResolver, getResolved };
|
||||
+1730
File diff suppressed because it is too large
Load Diff
+1729
File diff suppressed because it is too large
Load Diff
+9
@@ -0,0 +1,9 @@
|
||||
import * as rollup from 'rollup';
|
||||
import { Options } from './types.mjs';
|
||||
import '@rollup/pluginutils';
|
||||
import 'unplugin';
|
||||
import '@antfu/utils';
|
||||
|
||||
declare const _default: (options: Options) => rollup.Plugin | rollup.Plugin[];
|
||||
|
||||
export { _default as default };
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
import * as rollup from 'rollup';
|
||||
import { Options } from './types.js';
|
||||
import '@rollup/pluginutils';
|
||||
import 'unplugin';
|
||||
import '@antfu/utils';
|
||||
|
||||
declare const _default: (options: Options) => rollup.Plugin | rollup.Plugin[];
|
||||
|
||||
export { _default as default };
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
||||
|
||||
var _chunk5MUHROAQjs = require('./chunk-5MUHROAQ.js');
|
||||
require('./chunk-WRE7G5OD.js');
|
||||
require('./chunk-5JVO2UWC.js');
|
||||
require('./chunk-6F4PWJZI.js');
|
||||
|
||||
// src/rollup.ts
|
||||
var rollup_default = _chunk5MUHROAQjs.unplugin_default.rollup;
|
||||
|
||||
|
||||
module.exports = rollup_default;
|
||||
exports.default = module.exports;
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
import {
|
||||
unplugin_default
|
||||
} from "./chunk-XR5T4LZ3.mjs";
|
||||
import "./chunk-L2JFDMEX.mjs";
|
||||
import "./chunk-T2FESLJY.mjs";
|
||||
import "./chunk-WBQAMGXK.mjs";
|
||||
|
||||
// src/rollup.ts
|
||||
var rollup_default = unplugin_default.rollup;
|
||||
export {
|
||||
rollup_default as default
|
||||
};
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
import { Options } from './types.mjs';
|
||||
import '@rollup/pluginutils';
|
||||
import 'unplugin';
|
||||
import '@antfu/utils';
|
||||
|
||||
declare const _default: (options: Options) => RspackPluginInstance;
|
||||
|
||||
export { _default as default };
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
import { Options } from './types.js';
|
||||
import '@rollup/pluginutils';
|
||||
import 'unplugin';
|
||||
import '@antfu/utils';
|
||||
|
||||
declare const _default: (options: Options) => RspackPluginInstance;
|
||||
|
||||
export { _default as default };
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
||||
|
||||
var _chunk5MUHROAQjs = require('./chunk-5MUHROAQ.js');
|
||||
require('./chunk-WRE7G5OD.js');
|
||||
require('./chunk-5JVO2UWC.js');
|
||||
require('./chunk-6F4PWJZI.js');
|
||||
|
||||
// src/rspack.ts
|
||||
var rspack_default = _chunk5MUHROAQjs.unplugin_default.rspack;
|
||||
|
||||
|
||||
module.exports = rspack_default;
|
||||
exports.default = module.exports;
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
import {
|
||||
unplugin_default
|
||||
} from "./chunk-XR5T4LZ3.mjs";
|
||||
import "./chunk-L2JFDMEX.mjs";
|
||||
import "./chunk-T2FESLJY.mjs";
|
||||
import "./chunk-WBQAMGXK.mjs";
|
||||
|
||||
// src/rspack.ts
|
||||
var rspack_default = unplugin_default.rspack;
|
||||
export {
|
||||
rspack_default as default
|
||||
};
|
||||
+268
@@ -0,0 +1,268 @@
|
||||
import "./chunk-T2FESLJY.mjs";
|
||||
|
||||
// node_modules/.pnpm/estree-walker@3.0.3/node_modules/estree-walker/src/walker.js
|
||||
var WalkerBase = class {
|
||||
constructor() {
|
||||
this.should_skip = false;
|
||||
this.should_remove = false;
|
||||
this.replacement = null;
|
||||
this.context = {
|
||||
skip: () => this.should_skip = true,
|
||||
remove: () => this.should_remove = true,
|
||||
replace: (node) => this.replacement = node
|
||||
};
|
||||
}
|
||||
/**
|
||||
* @template {Node} Parent
|
||||
* @param {Parent | null | undefined} parent
|
||||
* @param {keyof Parent | null | undefined} prop
|
||||
* @param {number | null | undefined} index
|
||||
* @param {Node} node
|
||||
*/
|
||||
replace(parent, prop, index, node) {
|
||||
if (parent && prop) {
|
||||
if (index != null) {
|
||||
parent[prop][index] = node;
|
||||
} else {
|
||||
parent[prop] = node;
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @template {Node} Parent
|
||||
* @param {Parent | null | undefined} parent
|
||||
* @param {keyof Parent | null | undefined} prop
|
||||
* @param {number | null | undefined} index
|
||||
*/
|
||||
remove(parent, prop, index) {
|
||||
if (parent && prop) {
|
||||
if (index !== null && index !== void 0) {
|
||||
parent[prop].splice(index, 1);
|
||||
} else {
|
||||
delete parent[prop];
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// node_modules/.pnpm/estree-walker@3.0.3/node_modules/estree-walker/src/sync.js
|
||||
var SyncWalker = class extends WalkerBase {
|
||||
/**
|
||||
*
|
||||
* @param {SyncHandler} [enter]
|
||||
* @param {SyncHandler} [leave]
|
||||
*/
|
||||
constructor(enter, leave) {
|
||||
super();
|
||||
this.should_skip = false;
|
||||
this.should_remove = false;
|
||||
this.replacement = null;
|
||||
this.context = {
|
||||
skip: () => this.should_skip = true,
|
||||
remove: () => this.should_remove = true,
|
||||
replace: (node) => this.replacement = node
|
||||
};
|
||||
this.enter = enter;
|
||||
this.leave = leave;
|
||||
}
|
||||
/**
|
||||
* @template {Node} Parent
|
||||
* @param {Node} node
|
||||
* @param {Parent | null} parent
|
||||
* @param {keyof Parent} [prop]
|
||||
* @param {number | null} [index]
|
||||
* @returns {Node | null}
|
||||
*/
|
||||
visit(node, parent, prop, index) {
|
||||
if (node) {
|
||||
if (this.enter) {
|
||||
const _should_skip = this.should_skip;
|
||||
const _should_remove = this.should_remove;
|
||||
const _replacement = this.replacement;
|
||||
this.should_skip = false;
|
||||
this.should_remove = false;
|
||||
this.replacement = null;
|
||||
this.enter.call(this.context, node, parent, prop, index);
|
||||
if (this.replacement) {
|
||||
node = this.replacement;
|
||||
this.replace(parent, prop, index, node);
|
||||
}
|
||||
if (this.should_remove) {
|
||||
this.remove(parent, prop, index);
|
||||
}
|
||||
const skipped = this.should_skip;
|
||||
const removed = this.should_remove;
|
||||
this.should_skip = _should_skip;
|
||||
this.should_remove = _should_remove;
|
||||
this.replacement = _replacement;
|
||||
if (skipped)
|
||||
return node;
|
||||
if (removed)
|
||||
return null;
|
||||
}
|
||||
let key;
|
||||
for (key in node) {
|
||||
const value = node[key];
|
||||
if (value && typeof value === "object") {
|
||||
if (Array.isArray(value)) {
|
||||
const nodes = (
|
||||
/** @type {Array<unknown>} */
|
||||
value
|
||||
);
|
||||
for (let i = 0; i < nodes.length; i += 1) {
|
||||
const item = nodes[i];
|
||||
if (isNode(item)) {
|
||||
if (!this.visit(item, node, key, i)) {
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (isNode(value)) {
|
||||
this.visit(value, node, key, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.leave) {
|
||||
const _replacement = this.replacement;
|
||||
const _should_remove = this.should_remove;
|
||||
this.replacement = null;
|
||||
this.should_remove = false;
|
||||
this.leave.call(this.context, node, parent, prop, index);
|
||||
if (this.replacement) {
|
||||
node = this.replacement;
|
||||
this.replace(parent, prop, index, node);
|
||||
}
|
||||
if (this.should_remove) {
|
||||
this.remove(parent, prop, index);
|
||||
}
|
||||
const removed = this.should_remove;
|
||||
this.replacement = _replacement;
|
||||
this.should_remove = _should_remove;
|
||||
if (removed)
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return node;
|
||||
}
|
||||
};
|
||||
function isNode(value) {
|
||||
return value !== null && typeof value === "object" && "type" in value && typeof value.type === "string";
|
||||
}
|
||||
|
||||
// node_modules/.pnpm/estree-walker@3.0.3/node_modules/estree-walker/src/async.js
|
||||
var AsyncWalker = class extends WalkerBase {
|
||||
/**
|
||||
*
|
||||
* @param {AsyncHandler} [enter]
|
||||
* @param {AsyncHandler} [leave]
|
||||
*/
|
||||
constructor(enter, leave) {
|
||||
super();
|
||||
this.should_skip = false;
|
||||
this.should_remove = false;
|
||||
this.replacement = null;
|
||||
this.context = {
|
||||
skip: () => this.should_skip = true,
|
||||
remove: () => this.should_remove = true,
|
||||
replace: (node) => this.replacement = node
|
||||
};
|
||||
this.enter = enter;
|
||||
this.leave = leave;
|
||||
}
|
||||
/**
|
||||
* @template {Node} Parent
|
||||
* @param {Node} node
|
||||
* @param {Parent | null} parent
|
||||
* @param {keyof Parent} [prop]
|
||||
* @param {number | null} [index]
|
||||
* @returns {Promise<Node | null>}
|
||||
*/
|
||||
async visit(node, parent, prop, index) {
|
||||
if (node) {
|
||||
if (this.enter) {
|
||||
const _should_skip = this.should_skip;
|
||||
const _should_remove = this.should_remove;
|
||||
const _replacement = this.replacement;
|
||||
this.should_skip = false;
|
||||
this.should_remove = false;
|
||||
this.replacement = null;
|
||||
await this.enter.call(this.context, node, parent, prop, index);
|
||||
if (this.replacement) {
|
||||
node = this.replacement;
|
||||
this.replace(parent, prop, index, node);
|
||||
}
|
||||
if (this.should_remove) {
|
||||
this.remove(parent, prop, index);
|
||||
}
|
||||
const skipped = this.should_skip;
|
||||
const removed = this.should_remove;
|
||||
this.should_skip = _should_skip;
|
||||
this.should_remove = _should_remove;
|
||||
this.replacement = _replacement;
|
||||
if (skipped)
|
||||
return node;
|
||||
if (removed)
|
||||
return null;
|
||||
}
|
||||
let key;
|
||||
for (key in node) {
|
||||
const value = node[key];
|
||||
if (value && typeof value === "object") {
|
||||
if (Array.isArray(value)) {
|
||||
const nodes = (
|
||||
/** @type {Array<unknown>} */
|
||||
value
|
||||
);
|
||||
for (let i = 0; i < nodes.length; i += 1) {
|
||||
const item = nodes[i];
|
||||
if (isNode2(item)) {
|
||||
if (!await this.visit(item, node, key, i)) {
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (isNode2(value)) {
|
||||
await this.visit(value, node, key, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.leave) {
|
||||
const _replacement = this.replacement;
|
||||
const _should_remove = this.should_remove;
|
||||
this.replacement = null;
|
||||
this.should_remove = false;
|
||||
await this.leave.call(this.context, node, parent, prop, index);
|
||||
if (this.replacement) {
|
||||
node = this.replacement;
|
||||
this.replace(parent, prop, index, node);
|
||||
}
|
||||
if (this.should_remove) {
|
||||
this.remove(parent, prop, index);
|
||||
}
|
||||
const removed = this.should_remove;
|
||||
this.replacement = _replacement;
|
||||
this.should_remove = _should_remove;
|
||||
if (removed)
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return node;
|
||||
}
|
||||
};
|
||||
function isNode2(value) {
|
||||
return value !== null && typeof value === "object" && "type" in value && typeof value.type === "string";
|
||||
}
|
||||
|
||||
// node_modules/.pnpm/estree-walker@3.0.3/node_modules/estree-walker/src/index.js
|
||||
function walk(ast, { enter, leave }) {
|
||||
const instance = new SyncWalker(enter, leave);
|
||||
return instance.visit(ast, null);
|
||||
}
|
||||
async function asyncWalk(ast, { enter, leave }) {
|
||||
const instance = new AsyncWalker(enter, leave);
|
||||
return await instance.visit(ast, null);
|
||||
}
|
||||
export {
|
||||
asyncWalk,
|
||||
walk
|
||||
};
|
||||
+269
@@ -0,0 +1,269 @@
|
||||
"use strict";Object.defineProperty(exports, "__esModule", {value: true});require('./chunk-5JVO2UWC.js');
|
||||
|
||||
// node_modules/.pnpm/estree-walker@3.0.3/node_modules/estree-walker/src/walker.js
|
||||
var WalkerBase = class {
|
||||
constructor() {
|
||||
this.should_skip = false;
|
||||
this.should_remove = false;
|
||||
this.replacement = null;
|
||||
this.context = {
|
||||
skip: () => this.should_skip = true,
|
||||
remove: () => this.should_remove = true,
|
||||
replace: (node) => this.replacement = node
|
||||
};
|
||||
}
|
||||
/**
|
||||
* @template {Node} Parent
|
||||
* @param {Parent | null | undefined} parent
|
||||
* @param {keyof Parent | null | undefined} prop
|
||||
* @param {number | null | undefined} index
|
||||
* @param {Node} node
|
||||
*/
|
||||
replace(parent, prop, index, node) {
|
||||
if (parent && prop) {
|
||||
if (index != null) {
|
||||
parent[prop][index] = node;
|
||||
} else {
|
||||
parent[prop] = node;
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @template {Node} Parent
|
||||
* @param {Parent | null | undefined} parent
|
||||
* @param {keyof Parent | null | undefined} prop
|
||||
* @param {number | null | undefined} index
|
||||
*/
|
||||
remove(parent, prop, index) {
|
||||
if (parent && prop) {
|
||||
if (index !== null && index !== void 0) {
|
||||
parent[prop].splice(index, 1);
|
||||
} else {
|
||||
delete parent[prop];
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// node_modules/.pnpm/estree-walker@3.0.3/node_modules/estree-walker/src/sync.js
|
||||
var SyncWalker = class extends WalkerBase {
|
||||
/**
|
||||
*
|
||||
* @param {SyncHandler} [enter]
|
||||
* @param {SyncHandler} [leave]
|
||||
*/
|
||||
constructor(enter, leave) {
|
||||
super();
|
||||
this.should_skip = false;
|
||||
this.should_remove = false;
|
||||
this.replacement = null;
|
||||
this.context = {
|
||||
skip: () => this.should_skip = true,
|
||||
remove: () => this.should_remove = true,
|
||||
replace: (node) => this.replacement = node
|
||||
};
|
||||
this.enter = enter;
|
||||
this.leave = leave;
|
||||
}
|
||||
/**
|
||||
* @template {Node} Parent
|
||||
* @param {Node} node
|
||||
* @param {Parent | null} parent
|
||||
* @param {keyof Parent} [prop]
|
||||
* @param {number | null} [index]
|
||||
* @returns {Node | null}
|
||||
*/
|
||||
visit(node, parent, prop, index) {
|
||||
if (node) {
|
||||
if (this.enter) {
|
||||
const _should_skip = this.should_skip;
|
||||
const _should_remove = this.should_remove;
|
||||
const _replacement = this.replacement;
|
||||
this.should_skip = false;
|
||||
this.should_remove = false;
|
||||
this.replacement = null;
|
||||
this.enter.call(this.context, node, parent, prop, index);
|
||||
if (this.replacement) {
|
||||
node = this.replacement;
|
||||
this.replace(parent, prop, index, node);
|
||||
}
|
||||
if (this.should_remove) {
|
||||
this.remove(parent, prop, index);
|
||||
}
|
||||
const skipped = this.should_skip;
|
||||
const removed = this.should_remove;
|
||||
this.should_skip = _should_skip;
|
||||
this.should_remove = _should_remove;
|
||||
this.replacement = _replacement;
|
||||
if (skipped)
|
||||
return node;
|
||||
if (removed)
|
||||
return null;
|
||||
}
|
||||
let key;
|
||||
for (key in node) {
|
||||
const value = node[key];
|
||||
if (value && typeof value === "object") {
|
||||
if (Array.isArray(value)) {
|
||||
const nodes = (
|
||||
/** @type {Array<unknown>} */
|
||||
value
|
||||
);
|
||||
for (let i = 0; i < nodes.length; i += 1) {
|
||||
const item = nodes[i];
|
||||
if (isNode(item)) {
|
||||
if (!this.visit(item, node, key, i)) {
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (isNode(value)) {
|
||||
this.visit(value, node, key, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.leave) {
|
||||
const _replacement = this.replacement;
|
||||
const _should_remove = this.should_remove;
|
||||
this.replacement = null;
|
||||
this.should_remove = false;
|
||||
this.leave.call(this.context, node, parent, prop, index);
|
||||
if (this.replacement) {
|
||||
node = this.replacement;
|
||||
this.replace(parent, prop, index, node);
|
||||
}
|
||||
if (this.should_remove) {
|
||||
this.remove(parent, prop, index);
|
||||
}
|
||||
const removed = this.should_remove;
|
||||
this.replacement = _replacement;
|
||||
this.should_remove = _should_remove;
|
||||
if (removed)
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return node;
|
||||
}
|
||||
};
|
||||
function isNode(value) {
|
||||
return value !== null && typeof value === "object" && "type" in value && typeof value.type === "string";
|
||||
}
|
||||
|
||||
// node_modules/.pnpm/estree-walker@3.0.3/node_modules/estree-walker/src/async.js
|
||||
var AsyncWalker = class extends WalkerBase {
|
||||
/**
|
||||
*
|
||||
* @param {AsyncHandler} [enter]
|
||||
* @param {AsyncHandler} [leave]
|
||||
*/
|
||||
constructor(enter, leave) {
|
||||
super();
|
||||
this.should_skip = false;
|
||||
this.should_remove = false;
|
||||
this.replacement = null;
|
||||
this.context = {
|
||||
skip: () => this.should_skip = true,
|
||||
remove: () => this.should_remove = true,
|
||||
replace: (node) => this.replacement = node
|
||||
};
|
||||
this.enter = enter;
|
||||
this.leave = leave;
|
||||
}
|
||||
/**
|
||||
* @template {Node} Parent
|
||||
* @param {Node} node
|
||||
* @param {Parent | null} parent
|
||||
* @param {keyof Parent} [prop]
|
||||
* @param {number | null} [index]
|
||||
* @returns {Promise<Node | null>}
|
||||
*/
|
||||
async visit(node, parent, prop, index) {
|
||||
if (node) {
|
||||
if (this.enter) {
|
||||
const _should_skip = this.should_skip;
|
||||
const _should_remove = this.should_remove;
|
||||
const _replacement = this.replacement;
|
||||
this.should_skip = false;
|
||||
this.should_remove = false;
|
||||
this.replacement = null;
|
||||
await this.enter.call(this.context, node, parent, prop, index);
|
||||
if (this.replacement) {
|
||||
node = this.replacement;
|
||||
this.replace(parent, prop, index, node);
|
||||
}
|
||||
if (this.should_remove) {
|
||||
this.remove(parent, prop, index);
|
||||
}
|
||||
const skipped = this.should_skip;
|
||||
const removed = this.should_remove;
|
||||
this.should_skip = _should_skip;
|
||||
this.should_remove = _should_remove;
|
||||
this.replacement = _replacement;
|
||||
if (skipped)
|
||||
return node;
|
||||
if (removed)
|
||||
return null;
|
||||
}
|
||||
let key;
|
||||
for (key in node) {
|
||||
const value = node[key];
|
||||
if (value && typeof value === "object") {
|
||||
if (Array.isArray(value)) {
|
||||
const nodes = (
|
||||
/** @type {Array<unknown>} */
|
||||
value
|
||||
);
|
||||
for (let i = 0; i < nodes.length; i += 1) {
|
||||
const item = nodes[i];
|
||||
if (isNode2(item)) {
|
||||
if (!await this.visit(item, node, key, i)) {
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (isNode2(value)) {
|
||||
await this.visit(value, node, key, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.leave) {
|
||||
const _replacement = this.replacement;
|
||||
const _should_remove = this.should_remove;
|
||||
this.replacement = null;
|
||||
this.should_remove = false;
|
||||
await this.leave.call(this.context, node, parent, prop, index);
|
||||
if (this.replacement) {
|
||||
node = this.replacement;
|
||||
this.replace(parent, prop, index, node);
|
||||
}
|
||||
if (this.should_remove) {
|
||||
this.remove(parent, prop, index);
|
||||
}
|
||||
const removed = this.should_remove;
|
||||
this.replacement = _replacement;
|
||||
this.should_remove = _should_remove;
|
||||
if (removed)
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return node;
|
||||
}
|
||||
};
|
||||
function isNode2(value) {
|
||||
return value !== null && typeof value === "object" && "type" in value && typeof value.type === "string";
|
||||
}
|
||||
|
||||
// node_modules/.pnpm/estree-walker@3.0.3/node_modules/estree-walker/src/index.js
|
||||
function walk(ast, { enter, leave }) {
|
||||
const instance = new SyncWalker(enter, leave);
|
||||
return instance.visit(ast, null);
|
||||
}
|
||||
async function asyncWalk(ast, { enter, leave }) {
|
||||
const instance = new AsyncWalker(enter, leave);
|
||||
return await instance.visit(ast, null);
|
||||
}
|
||||
|
||||
|
||||
|
||||
exports.asyncWalk = asyncWalk; exports.walk = walk;
|
||||
exports.default = module.exports;
|
||||
+168
@@ -0,0 +1,168 @@
|
||||
import { FilterPattern } from '@rollup/pluginutils';
|
||||
import { TransformResult } from 'unplugin';
|
||||
import { Awaitable } from '@antfu/utils';
|
||||
|
||||
interface ImportInfoLegacy {
|
||||
/**
|
||||
* @deprecated renamed to `as`
|
||||
*/
|
||||
name?: string;
|
||||
/**
|
||||
* @deprecated renamed to `name`
|
||||
*/
|
||||
importName?: string;
|
||||
/**
|
||||
* @deprecated renamed to `from`
|
||||
*/
|
||||
path: string;
|
||||
sideEffects?: SideEffectsInfo;
|
||||
}
|
||||
interface ImportInfo {
|
||||
as?: string;
|
||||
name?: string;
|
||||
from: string;
|
||||
}
|
||||
type SideEffectsInfo = (ImportInfo | string)[] | ImportInfo | string | undefined;
|
||||
interface ComponentInfo extends ImportInfo {
|
||||
sideEffects?: SideEffectsInfo;
|
||||
}
|
||||
type ComponentResolveResult = Awaitable<string | ComponentInfo | null | undefined | void>;
|
||||
type ComponentResolverFunction = (name: string) => ComponentResolveResult;
|
||||
interface ComponentResolverObject {
|
||||
type: 'component' | 'directive';
|
||||
resolve: ComponentResolverFunction;
|
||||
}
|
||||
type ComponentResolver = ComponentResolverFunction | ComponentResolverObject;
|
||||
type Matcher = (id: string) => boolean | null | undefined;
|
||||
type Transformer = (code: string, id: string, path: string, query: Record<string, string>) => Awaitable<TransformResult | null>;
|
||||
type SupportedTransformer = 'vue3' | 'vue2';
|
||||
interface PublicPluginAPI {
|
||||
/**
|
||||
* Resolves a component using the configured resolvers.
|
||||
*/
|
||||
findComponent: (name: string, filename?: string) => Promise<ComponentInfo | undefined>;
|
||||
/**
|
||||
* Obtain an import statement for a resolved component.
|
||||
*/
|
||||
stringifyImport: (info: ComponentInfo) => string;
|
||||
}
|
||||
/**
|
||||
* Plugin options.
|
||||
*/
|
||||
interface Options {
|
||||
/**
|
||||
* RegExp or glob to match files to be transformed
|
||||
*/
|
||||
include?: FilterPattern;
|
||||
/**
|
||||
* RegExp or glob to match files to NOT be transformed
|
||||
*/
|
||||
exclude?: FilterPattern;
|
||||
/**
|
||||
* Relative paths to the directory to search for components.
|
||||
* @default 'src/components'
|
||||
*/
|
||||
dirs?: string | string[];
|
||||
/**
|
||||
* Valid file extensions for components.
|
||||
* @default ['vue']
|
||||
*/
|
||||
extensions?: string | string[];
|
||||
/**
|
||||
* Glob patterns to match file names to be detected as components.
|
||||
*
|
||||
* When specified, the `dirs` and `extensions` options will be ignored.
|
||||
*/
|
||||
globs?: string | string[];
|
||||
/**
|
||||
* Search for subdirectories
|
||||
* @default true
|
||||
*/
|
||||
deep?: boolean;
|
||||
/**
|
||||
* Allow subdirectories as namespace prefix for components
|
||||
* @default false
|
||||
*/
|
||||
directoryAsNamespace?: boolean;
|
||||
/**
|
||||
* Collapse same prefixes (camel-sensitive) of folders and components
|
||||
* to prevent duplication inside namespaced component name.
|
||||
*
|
||||
* Works when `directoryAsNamespace: true`
|
||||
* @default false
|
||||
*/
|
||||
collapseSamePrefixes?: boolean;
|
||||
/**
|
||||
* Subdirectory paths for ignoring namespace prefixes
|
||||
*
|
||||
* Works when `directoryAsNamespace: true`
|
||||
* @default "[]"
|
||||
*/
|
||||
globalNamespaces?: string[];
|
||||
/**
|
||||
* Pass a custom function to resolve the component importing path from the component name.
|
||||
*
|
||||
* The component names are always in PascalCase
|
||||
*/
|
||||
resolvers?: (ComponentResolver | ComponentResolver[])[];
|
||||
/**
|
||||
* Apply custom transform over the path for importing
|
||||
*/
|
||||
importPathTransform?: (path: string) => string | undefined;
|
||||
/**
|
||||
* Transformer to apply
|
||||
*
|
||||
* @default 'vue3'
|
||||
*/
|
||||
transformer?: SupportedTransformer;
|
||||
/**
|
||||
* Generate TypeScript declaration for global components
|
||||
*
|
||||
* Accept boolean or a path related to project root
|
||||
*
|
||||
* @see https://github.com/vuejs/core/pull/3399
|
||||
* @see https://github.com/johnsoncodehk/volar#using
|
||||
* @default true
|
||||
*/
|
||||
dts?: boolean | string;
|
||||
/**
|
||||
* Do not emit warning on component overriding
|
||||
*
|
||||
* @default false
|
||||
*/
|
||||
allowOverrides?: boolean;
|
||||
/**
|
||||
* auto import for directives.
|
||||
*
|
||||
* default: `true` for Vue 3, `false` for Vue 2
|
||||
*
|
||||
* Babel is needed to do the transformation for Vue 2, it's disabled by default for performance concerns.
|
||||
* To install Babel, run: `npm install -D @babel/parser`
|
||||
* @default undefined
|
||||
*/
|
||||
directives?: boolean;
|
||||
/**
|
||||
* Only provide types of components in library (registered globally)
|
||||
**/
|
||||
types?: TypeImport[];
|
||||
/**
|
||||
* Vue version of project. It will detect automatically if not specified.
|
||||
*/
|
||||
version?: 2 | 2.7 | 3;
|
||||
}
|
||||
type ResolvedOptions = Omit<Required<Options>, 'resolvers' | 'extensions' | 'dirs' | 'globalComponentsDeclaration'> & {
|
||||
resolvers: ComponentResolverObject[];
|
||||
extensions: string[];
|
||||
dirs: string[];
|
||||
resolvedDirs: string[];
|
||||
globs: string[];
|
||||
dts: string | false;
|
||||
root: string;
|
||||
};
|
||||
type ComponentsImportMap = Record<string, string[] | undefined>;
|
||||
interface TypeImport {
|
||||
from: string;
|
||||
names: string[];
|
||||
}
|
||||
|
||||
export { ComponentInfo, ComponentResolveResult, ComponentResolver, ComponentResolverFunction, ComponentResolverObject, ComponentsImportMap, ImportInfo, ImportInfoLegacy, Matcher, Options, PublicPluginAPI, ResolvedOptions, SideEffectsInfo, SupportedTransformer, Transformer, TypeImport };
|
||||
+168
@@ -0,0 +1,168 @@
|
||||
import { FilterPattern } from '@rollup/pluginutils';
|
||||
import { TransformResult } from 'unplugin';
|
||||
import { Awaitable } from '@antfu/utils';
|
||||
|
||||
interface ImportInfoLegacy {
|
||||
/**
|
||||
* @deprecated renamed to `as`
|
||||
*/
|
||||
name?: string;
|
||||
/**
|
||||
* @deprecated renamed to `name`
|
||||
*/
|
||||
importName?: string;
|
||||
/**
|
||||
* @deprecated renamed to `from`
|
||||
*/
|
||||
path: string;
|
||||
sideEffects?: SideEffectsInfo;
|
||||
}
|
||||
interface ImportInfo {
|
||||
as?: string;
|
||||
name?: string;
|
||||
from: string;
|
||||
}
|
||||
type SideEffectsInfo = (ImportInfo | string)[] | ImportInfo | string | undefined;
|
||||
interface ComponentInfo extends ImportInfo {
|
||||
sideEffects?: SideEffectsInfo;
|
||||
}
|
||||
type ComponentResolveResult = Awaitable<string | ComponentInfo | null | undefined | void>;
|
||||
type ComponentResolverFunction = (name: string) => ComponentResolveResult;
|
||||
interface ComponentResolverObject {
|
||||
type: 'component' | 'directive';
|
||||
resolve: ComponentResolverFunction;
|
||||
}
|
||||
type ComponentResolver = ComponentResolverFunction | ComponentResolverObject;
|
||||
type Matcher = (id: string) => boolean | null | undefined;
|
||||
type Transformer = (code: string, id: string, path: string, query: Record<string, string>) => Awaitable<TransformResult | null>;
|
||||
type SupportedTransformer = 'vue3' | 'vue2';
|
||||
interface PublicPluginAPI {
|
||||
/**
|
||||
* Resolves a component using the configured resolvers.
|
||||
*/
|
||||
findComponent: (name: string, filename?: string) => Promise<ComponentInfo | undefined>;
|
||||
/**
|
||||
* Obtain an import statement for a resolved component.
|
||||
*/
|
||||
stringifyImport: (info: ComponentInfo) => string;
|
||||
}
|
||||
/**
|
||||
* Plugin options.
|
||||
*/
|
||||
interface Options {
|
||||
/**
|
||||
* RegExp or glob to match files to be transformed
|
||||
*/
|
||||
include?: FilterPattern;
|
||||
/**
|
||||
* RegExp or glob to match files to NOT be transformed
|
||||
*/
|
||||
exclude?: FilterPattern;
|
||||
/**
|
||||
* Relative paths to the directory to search for components.
|
||||
* @default 'src/components'
|
||||
*/
|
||||
dirs?: string | string[];
|
||||
/**
|
||||
* Valid file extensions for components.
|
||||
* @default ['vue']
|
||||
*/
|
||||
extensions?: string | string[];
|
||||
/**
|
||||
* Glob patterns to match file names to be detected as components.
|
||||
*
|
||||
* When specified, the `dirs` and `extensions` options will be ignored.
|
||||
*/
|
||||
globs?: string | string[];
|
||||
/**
|
||||
* Search for subdirectories
|
||||
* @default true
|
||||
*/
|
||||
deep?: boolean;
|
||||
/**
|
||||
* Allow subdirectories as namespace prefix for components
|
||||
* @default false
|
||||
*/
|
||||
directoryAsNamespace?: boolean;
|
||||
/**
|
||||
* Collapse same prefixes (camel-sensitive) of folders and components
|
||||
* to prevent duplication inside namespaced component name.
|
||||
*
|
||||
* Works when `directoryAsNamespace: true`
|
||||
* @default false
|
||||
*/
|
||||
collapseSamePrefixes?: boolean;
|
||||
/**
|
||||
* Subdirectory paths for ignoring namespace prefixes
|
||||
*
|
||||
* Works when `directoryAsNamespace: true`
|
||||
* @default "[]"
|
||||
*/
|
||||
globalNamespaces?: string[];
|
||||
/**
|
||||
* Pass a custom function to resolve the component importing path from the component name.
|
||||
*
|
||||
* The component names are always in PascalCase
|
||||
*/
|
||||
resolvers?: (ComponentResolver | ComponentResolver[])[];
|
||||
/**
|
||||
* Apply custom transform over the path for importing
|
||||
*/
|
||||
importPathTransform?: (path: string) => string | undefined;
|
||||
/**
|
||||
* Transformer to apply
|
||||
*
|
||||
* @default 'vue3'
|
||||
*/
|
||||
transformer?: SupportedTransformer;
|
||||
/**
|
||||
* Generate TypeScript declaration for global components
|
||||
*
|
||||
* Accept boolean or a path related to project root
|
||||
*
|
||||
* @see https://github.com/vuejs/core/pull/3399
|
||||
* @see https://github.com/johnsoncodehk/volar#using
|
||||
* @default true
|
||||
*/
|
||||
dts?: boolean | string;
|
||||
/**
|
||||
* Do not emit warning on component overriding
|
||||
*
|
||||
* @default false
|
||||
*/
|
||||
allowOverrides?: boolean;
|
||||
/**
|
||||
* auto import for directives.
|
||||
*
|
||||
* default: `true` for Vue 3, `false` for Vue 2
|
||||
*
|
||||
* Babel is needed to do the transformation for Vue 2, it's disabled by default for performance concerns.
|
||||
* To install Babel, run: `npm install -D @babel/parser`
|
||||
* @default undefined
|
||||
*/
|
||||
directives?: boolean;
|
||||
/**
|
||||
* Only provide types of components in library (registered globally)
|
||||
**/
|
||||
types?: TypeImport[];
|
||||
/**
|
||||
* Vue version of project. It will detect automatically if not specified.
|
||||
*/
|
||||
version?: 2 | 2.7 | 3;
|
||||
}
|
||||
type ResolvedOptions = Omit<Required<Options>, 'resolvers' | 'extensions' | 'dirs' | 'globalComponentsDeclaration'> & {
|
||||
resolvers: ComponentResolverObject[];
|
||||
extensions: string[];
|
||||
dirs: string[];
|
||||
resolvedDirs: string[];
|
||||
globs: string[];
|
||||
dts: string | false;
|
||||
root: string;
|
||||
};
|
||||
type ComponentsImportMap = Record<string, string[] | undefined>;
|
||||
interface TypeImport {
|
||||
from: string;
|
||||
names: string[];
|
||||
}
|
||||
|
||||
export { ComponentInfo, ComponentResolveResult, ComponentResolver, ComponentResolverFunction, ComponentResolverObject, ComponentsImportMap, ImportInfo, ImportInfoLegacy, Matcher, Options, PublicPluginAPI, ResolvedOptions, SideEffectsInfo, SupportedTransformer, Transformer, TypeImport };
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
"use strict";require('./chunk-6F4PWJZI.js');
|
||||
exports.default = module.exports;
|
||||
+1
@@ -0,0 +1 @@
|
||||
import "./chunk-WBQAMGXK.mjs";
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
import { Plugin } from 'vite';
|
||||
import { Options, PublicPluginAPI } from './types.mjs';
|
||||
import '@rollup/pluginutils';
|
||||
import 'unplugin';
|
||||
import '@antfu/utils';
|
||||
|
||||
declare const _default: (options?: Options | undefined) => Plugin & {
|
||||
api: PublicPluginAPI;
|
||||
};
|
||||
|
||||
export { _default as default };
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
import { Plugin } from 'vite';
|
||||
import { Options, PublicPluginAPI } from './types.js';
|
||||
import '@rollup/pluginutils';
|
||||
import 'unplugin';
|
||||
import '@antfu/utils';
|
||||
|
||||
declare const _default: (options?: Options | undefined) => Plugin & {
|
||||
api: PublicPluginAPI;
|
||||
};
|
||||
|
||||
export { _default as default };
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
||||
|
||||
var _chunk5MUHROAQjs = require('./chunk-5MUHROAQ.js');
|
||||
require('./chunk-WRE7G5OD.js');
|
||||
require('./chunk-5JVO2UWC.js');
|
||||
require('./chunk-6F4PWJZI.js');
|
||||
|
||||
// src/vite.ts
|
||||
var vite_default = _chunk5MUHROAQjs.unplugin_default.vite;
|
||||
|
||||
|
||||
module.exports = vite_default;
|
||||
exports.default = module.exports;
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
import {
|
||||
unplugin_default
|
||||
} from "./chunk-XR5T4LZ3.mjs";
|
||||
import "./chunk-L2JFDMEX.mjs";
|
||||
import "./chunk-T2FESLJY.mjs";
|
||||
import "./chunk-WBQAMGXK.mjs";
|
||||
|
||||
// src/vite.ts
|
||||
var vite_default = unplugin_default.vite;
|
||||
export {
|
||||
vite_default as default
|
||||
};
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
import * as webpack from 'webpack';
|
||||
import { Options } from './types.mjs';
|
||||
import '@rollup/pluginutils';
|
||||
import 'unplugin';
|
||||
import '@antfu/utils';
|
||||
|
||||
declare const _default: (options: Options) => webpack.WebpackPluginInstance;
|
||||
|
||||
export { _default as default };
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
import * as webpack from 'webpack';
|
||||
import { Options } from './types.js';
|
||||
import '@rollup/pluginutils';
|
||||
import 'unplugin';
|
||||
import '@antfu/utils';
|
||||
|
||||
declare const _default: (options: Options) => webpack.WebpackPluginInstance;
|
||||
|
||||
export { _default as default };
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
||||
|
||||
var _chunk5MUHROAQjs = require('./chunk-5MUHROAQ.js');
|
||||
require('./chunk-WRE7G5OD.js');
|
||||
require('./chunk-5JVO2UWC.js');
|
||||
require('./chunk-6F4PWJZI.js');
|
||||
|
||||
// src/webpack.ts
|
||||
var webpack_default = _chunk5MUHROAQjs.unplugin_default.webpack;
|
||||
|
||||
|
||||
module.exports = webpack_default;
|
||||
exports.default = module.exports;
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
import {
|
||||
unplugin_default
|
||||
} from "./chunk-XR5T4LZ3.mjs";
|
||||
import "./chunk-L2JFDMEX.mjs";
|
||||
import "./chunk-T2FESLJY.mjs";
|
||||
import "./chunk-WBQAMGXK.mjs";
|
||||
|
||||
// src/webpack.ts
|
||||
var webpack_default = unplugin_default.webpack;
|
||||
export {
|
||||
webpack_default as default
|
||||
};
|
||||
Generated
Vendored
+21
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2021 Anthony Fu <https://github.com/antfu>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
Generated
Vendored
+56
@@ -0,0 +1,56 @@
|
||||
# local-pkg
|
||||
|
||||
[](https://www.npmjs.com/package/local-pkg)
|
||||
|
||||
Get information on local packages. Works on both CJS and ESM.
|
||||
|
||||
## Install
|
||||
|
||||
```bash
|
||||
npm i local-pkg
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```ts
|
||||
import {
|
||||
getPackageInfo,
|
||||
importModule,
|
||||
isPackageExists,
|
||||
resolveModule,
|
||||
} from 'local-pkg'
|
||||
|
||||
isPackageExists('local-pkg') // true
|
||||
isPackageExists('foo') // false
|
||||
|
||||
await getPackageInfo('local-pkg')
|
||||
/* {
|
||||
* name: "local-pkg",
|
||||
* version: "0.1.0",
|
||||
* rootPath: "/path/to/node_modules/local-pkg",
|
||||
* packageJson: {
|
||||
* ...
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
|
||||
// similar to `require.resolve` but works also in ESM
|
||||
resolveModule('local-pkg')
|
||||
// '/path/to/node_modules/local-pkg/dist/index.cjs'
|
||||
|
||||
// similar to `await import()` but works also in CJS
|
||||
const { importModule } = await importModule('local-pkg')
|
||||
```
|
||||
|
||||
|
||||
## Sponsors
|
||||
|
||||
<p align="center">
|
||||
<a href="https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg">
|
||||
<img src='https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg'/>
|
||||
</a>
|
||||
</p>
|
||||
|
||||
## License
|
||||
|
||||
[MIT](./LICENSE) License © 2021 [Anthony Fu](https://github.com/antfu)
|
||||
Generated
Vendored
+322
@@ -0,0 +1,322 @@
|
||||
"use strict";
|
||||
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;
|
||||
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 __spreadValues = (a, b) => {
|
||||
for (var prop in b || (b = {}))
|
||||
if (__hasOwnProp.call(b, prop))
|
||||
__defNormalProp(a, prop, b[prop]);
|
||||
if (__getOwnPropSymbols)
|
||||
for (var prop of __getOwnPropSymbols(b)) {
|
||||
if (__propIsEnum.call(b, prop))
|
||||
__defNormalProp(a, prop, b[prop]);
|
||||
}
|
||||
return a;
|
||||
};
|
||||
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
||||
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
||||
mod
|
||||
));
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
var __publicField = (obj, key, value) => {
|
||||
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
||||
return value;
|
||||
};
|
||||
var __accessCheck = (obj, member, msg) => {
|
||||
if (!member.has(obj))
|
||||
throw TypeError("Cannot " + msg);
|
||||
};
|
||||
var __privateGet = (obj, member, getter) => {
|
||||
__accessCheck(obj, member, "read from private field");
|
||||
return getter ? getter.call(obj) : member.get(obj);
|
||||
};
|
||||
var __privateAdd = (obj, member, value) => {
|
||||
if (member.has(obj))
|
||||
throw TypeError("Cannot add the same private member more than once");
|
||||
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
||||
};
|
||||
var __privateSet = (obj, member, value, setter) => {
|
||||
__accessCheck(obj, member, "write to private field");
|
||||
setter ? setter.call(obj, value) : member.set(obj, value);
|
||||
return value;
|
||||
};
|
||||
var __privateWrapper = (obj, member, setter, getter) => ({
|
||||
set _(value) {
|
||||
__privateSet(obj, member, value, setter);
|
||||
},
|
||||
get _() {
|
||||
return __privateGet(obj, member, getter);
|
||||
}
|
||||
});
|
||||
|
||||
// shared.ts
|
||||
var shared_exports = {};
|
||||
__export(shared_exports, {
|
||||
isPackageListed: () => isPackageListed,
|
||||
loadPackageJSON: () => loadPackageJSON
|
||||
});
|
||||
module.exports = __toCommonJS(shared_exports);
|
||||
var import_fs = require("fs");
|
||||
|
||||
// node_modules/.pnpm/find-up@6.3.0/node_modules/find-up/index.js
|
||||
var import_node_path2 = __toESM(require("path"), 1);
|
||||
var import_node_url2 = require("url");
|
||||
|
||||
// node_modules/.pnpm/locate-path@7.1.1/node_modules/locate-path/index.js
|
||||
var import_node_process = __toESM(require("process"), 1);
|
||||
var import_node_path = __toESM(require("path"), 1);
|
||||
var import_node_fs = __toESM(require("fs"), 1);
|
||||
var import_node_url = require("url");
|
||||
|
||||
// node_modules/.pnpm/yocto-queue@1.0.0/node_modules/yocto-queue/index.js
|
||||
var Node = class {
|
||||
constructor(value) {
|
||||
__publicField(this, "value");
|
||||
__publicField(this, "next");
|
||||
this.value = value;
|
||||
}
|
||||
};
|
||||
var _head, _tail, _size;
|
||||
var Queue = class {
|
||||
constructor() {
|
||||
__privateAdd(this, _head, void 0);
|
||||
__privateAdd(this, _tail, void 0);
|
||||
__privateAdd(this, _size, void 0);
|
||||
this.clear();
|
||||
}
|
||||
enqueue(value) {
|
||||
const node = new Node(value);
|
||||
if (__privateGet(this, _head)) {
|
||||
__privateGet(this, _tail).next = node;
|
||||
__privateSet(this, _tail, node);
|
||||
} else {
|
||||
__privateSet(this, _head, node);
|
||||
__privateSet(this, _tail, node);
|
||||
}
|
||||
__privateWrapper(this, _size)._++;
|
||||
}
|
||||
dequeue() {
|
||||
const current = __privateGet(this, _head);
|
||||
if (!current) {
|
||||
return;
|
||||
}
|
||||
__privateSet(this, _head, __privateGet(this, _head).next);
|
||||
__privateWrapper(this, _size)._--;
|
||||
return current.value;
|
||||
}
|
||||
clear() {
|
||||
__privateSet(this, _head, void 0);
|
||||
__privateSet(this, _tail, void 0);
|
||||
__privateSet(this, _size, 0);
|
||||
}
|
||||
get size() {
|
||||
return __privateGet(this, _size);
|
||||
}
|
||||
*[Symbol.iterator]() {
|
||||
let current = __privateGet(this, _head);
|
||||
while (current) {
|
||||
yield current.value;
|
||||
current = current.next;
|
||||
}
|
||||
}
|
||||
};
|
||||
_head = new WeakMap();
|
||||
_tail = new WeakMap();
|
||||
_size = new WeakMap();
|
||||
|
||||
// node_modules/.pnpm/p-limit@4.0.0/node_modules/p-limit/index.js
|
||||
function pLimit(concurrency) {
|
||||
if (!((Number.isInteger(concurrency) || concurrency === Number.POSITIVE_INFINITY) && concurrency > 0)) {
|
||||
throw new TypeError("Expected `concurrency` to be a number from 1 and up");
|
||||
}
|
||||
const queue = new Queue();
|
||||
let activeCount = 0;
|
||||
const next = () => {
|
||||
activeCount--;
|
||||
if (queue.size > 0) {
|
||||
queue.dequeue()();
|
||||
}
|
||||
};
|
||||
const run = async (fn, resolve, args) => {
|
||||
activeCount++;
|
||||
const result = (async () => fn(...args))();
|
||||
resolve(result);
|
||||
try {
|
||||
await result;
|
||||
} catch (e) {
|
||||
}
|
||||
next();
|
||||
};
|
||||
const enqueue = (fn, resolve, args) => {
|
||||
queue.enqueue(run.bind(void 0, fn, resolve, args));
|
||||
(async () => {
|
||||
await Promise.resolve();
|
||||
if (activeCount < concurrency && queue.size > 0) {
|
||||
queue.dequeue()();
|
||||
}
|
||||
})();
|
||||
};
|
||||
const generator = (fn, ...args) => new Promise((resolve) => {
|
||||
enqueue(fn, resolve, args);
|
||||
});
|
||||
Object.defineProperties(generator, {
|
||||
activeCount: {
|
||||
get: () => activeCount
|
||||
},
|
||||
pendingCount: {
|
||||
get: () => queue.size
|
||||
},
|
||||
clearQueue: {
|
||||
value: () => {
|
||||
queue.clear();
|
||||
}
|
||||
}
|
||||
});
|
||||
return generator;
|
||||
}
|
||||
|
||||
// node_modules/.pnpm/p-locate@6.0.0/node_modules/p-locate/index.js
|
||||
var EndError = class extends Error {
|
||||
constructor(value) {
|
||||
super();
|
||||
this.value = value;
|
||||
}
|
||||
};
|
||||
var testElement = async (element, tester) => tester(await element);
|
||||
var finder = async (element) => {
|
||||
const values = await Promise.all(element);
|
||||
if (values[1] === true) {
|
||||
throw new EndError(values[0]);
|
||||
}
|
||||
return false;
|
||||
};
|
||||
async function pLocate(iterable, tester, {
|
||||
concurrency = Number.POSITIVE_INFINITY,
|
||||
preserveOrder = true
|
||||
} = {}) {
|
||||
const limit = pLimit(concurrency);
|
||||
const items = [...iterable].map((element) => [element, limit(testElement, element, tester)]);
|
||||
const checkLimit = pLimit(preserveOrder ? 1 : Number.POSITIVE_INFINITY);
|
||||
try {
|
||||
await Promise.all(items.map((element) => checkLimit(finder, element)));
|
||||
} catch (error) {
|
||||
if (error instanceof EndError) {
|
||||
return error.value;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
// node_modules/.pnpm/locate-path@7.1.1/node_modules/locate-path/index.js
|
||||
var typeMappings = {
|
||||
directory: "isDirectory",
|
||||
file: "isFile"
|
||||
};
|
||||
function checkType(type) {
|
||||
if (Object.hasOwnProperty.call(typeMappings, type)) {
|
||||
return;
|
||||
}
|
||||
throw new Error(`Invalid type specified: ${type}`);
|
||||
}
|
||||
var matchType = (type, stat) => stat[typeMappings[type]]();
|
||||
var toPath = (urlOrPath) => urlOrPath instanceof URL ? (0, import_node_url.fileURLToPath)(urlOrPath) : urlOrPath;
|
||||
async function locatePath(paths, {
|
||||
cwd = import_node_process.default.cwd(),
|
||||
type = "file",
|
||||
allowSymlinks = true,
|
||||
concurrency,
|
||||
preserveOrder
|
||||
} = {}) {
|
||||
checkType(type);
|
||||
cwd = toPath(cwd);
|
||||
const statFunction = allowSymlinks ? import_node_fs.promises.stat : import_node_fs.promises.lstat;
|
||||
return pLocate(paths, async (path_) => {
|
||||
try {
|
||||
const stat = await statFunction(import_node_path.default.resolve(cwd, path_));
|
||||
return matchType(type, stat);
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}, { concurrency, preserveOrder });
|
||||
}
|
||||
|
||||
// node_modules/.pnpm/path-exists@5.0.0/node_modules/path-exists/index.js
|
||||
var import_node_fs2 = __toESM(require("fs"), 1);
|
||||
|
||||
// node_modules/.pnpm/find-up@6.3.0/node_modules/find-up/index.js
|
||||
var toPath2 = (urlOrPath) => urlOrPath instanceof URL ? (0, import_node_url2.fileURLToPath)(urlOrPath) : urlOrPath;
|
||||
var findUpStop = Symbol("findUpStop");
|
||||
async function findUpMultiple(name, options = {}) {
|
||||
let directory = import_node_path2.default.resolve(toPath2(options.cwd) || "");
|
||||
const { root } = import_node_path2.default.parse(directory);
|
||||
const stopAt = import_node_path2.default.resolve(directory, options.stopAt || root);
|
||||
const limit = options.limit || Number.POSITIVE_INFINITY;
|
||||
const paths = [name].flat();
|
||||
const runMatcher = async (locateOptions) => {
|
||||
if (typeof name !== "function") {
|
||||
return locatePath(paths, locateOptions);
|
||||
}
|
||||
const foundPath = await name(locateOptions.cwd);
|
||||
if (typeof foundPath === "string") {
|
||||
return locatePath([foundPath], locateOptions);
|
||||
}
|
||||
return foundPath;
|
||||
};
|
||||
const matches = [];
|
||||
while (true) {
|
||||
const foundPath = await runMatcher(__spreadProps(__spreadValues({}, options), { cwd: directory }));
|
||||
if (foundPath === findUpStop) {
|
||||
break;
|
||||
}
|
||||
if (foundPath) {
|
||||
matches.push(import_node_path2.default.resolve(directory, foundPath));
|
||||
}
|
||||
if (directory === stopAt || matches.length >= limit) {
|
||||
break;
|
||||
}
|
||||
directory = import_node_path2.default.dirname(directory);
|
||||
}
|
||||
return matches;
|
||||
}
|
||||
async function findUp(name, options = {}) {
|
||||
const matches = await findUpMultiple(name, __spreadProps(__spreadValues({}, options), { limit: 1 }));
|
||||
return matches[0];
|
||||
}
|
||||
|
||||
// shared.ts
|
||||
async function loadPackageJSON(cwd = process.cwd()) {
|
||||
const path3 = await findUp("package.json", { cwd });
|
||||
if (!path3 || !(0, import_fs.existsSync)(path3))
|
||||
return null;
|
||||
return JSON.parse(await import_fs.promises.readFile(path3, "utf-8"));
|
||||
}
|
||||
async function isPackageListed(name, cwd) {
|
||||
const pkg = await loadPackageJSON(cwd) || {};
|
||||
return name in (pkg.dependencies || {}) || name in (pkg.devDependencies || {});
|
||||
}
|
||||
// Annotate the CommonJS export names for ESM import in node:
|
||||
0 && (module.exports = {
|
||||
isPackageListed,
|
||||
loadPackageJSON
|
||||
});
|
||||
Generated
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
declare function loadPackageJSON(cwd?: string): Promise<Record<string, any> | null>;
|
||||
declare function isPackageListed(name: string, cwd?: string): Promise<boolean>;
|
||||
|
||||
export { isPackageListed, loadPackageJSON };
|
||||
Generated
Vendored
+290
@@ -0,0 +1,290 @@
|
||||
var __defProp = Object.defineProperty;
|
||||
var __defProps = Object.defineProperties;
|
||||
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
||||
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
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 __spreadValues = (a, b) => {
|
||||
for (var prop in b || (b = {}))
|
||||
if (__hasOwnProp.call(b, prop))
|
||||
__defNormalProp(a, prop, b[prop]);
|
||||
if (__getOwnPropSymbols)
|
||||
for (var prop of __getOwnPropSymbols(b)) {
|
||||
if (__propIsEnum.call(b, prop))
|
||||
__defNormalProp(a, prop, b[prop]);
|
||||
}
|
||||
return a;
|
||||
};
|
||||
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
||||
var __publicField = (obj, key, value) => {
|
||||
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
||||
return value;
|
||||
};
|
||||
var __accessCheck = (obj, member, msg) => {
|
||||
if (!member.has(obj))
|
||||
throw TypeError("Cannot " + msg);
|
||||
};
|
||||
var __privateGet = (obj, member, getter) => {
|
||||
__accessCheck(obj, member, "read from private field");
|
||||
return getter ? getter.call(obj) : member.get(obj);
|
||||
};
|
||||
var __privateAdd = (obj, member, value) => {
|
||||
if (member.has(obj))
|
||||
throw TypeError("Cannot add the same private member more than once");
|
||||
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
||||
};
|
||||
var __privateSet = (obj, member, value, setter) => {
|
||||
__accessCheck(obj, member, "write to private field");
|
||||
setter ? setter.call(obj, value) : member.set(obj, value);
|
||||
return value;
|
||||
};
|
||||
var __privateWrapper = (obj, member, setter, getter) => ({
|
||||
set _(value) {
|
||||
__privateSet(obj, member, value, setter);
|
||||
},
|
||||
get _() {
|
||||
return __privateGet(obj, member, getter);
|
||||
}
|
||||
});
|
||||
|
||||
// shared.ts
|
||||
import { existsSync, promises as fs2 } from "fs";
|
||||
|
||||
// node_modules/.pnpm/find-up@6.3.0/node_modules/find-up/index.js
|
||||
import path2 from "path";
|
||||
import { fileURLToPath as fileURLToPath2 } from "url";
|
||||
|
||||
// node_modules/.pnpm/locate-path@7.1.1/node_modules/locate-path/index.js
|
||||
import process2 from "process";
|
||||
import path from "path";
|
||||
import fs, { promises as fsPromises } from "fs";
|
||||
import { fileURLToPath } from "url";
|
||||
|
||||
// node_modules/.pnpm/yocto-queue@1.0.0/node_modules/yocto-queue/index.js
|
||||
var Node = class {
|
||||
constructor(value) {
|
||||
__publicField(this, "value");
|
||||
__publicField(this, "next");
|
||||
this.value = value;
|
||||
}
|
||||
};
|
||||
var _head, _tail, _size;
|
||||
var Queue = class {
|
||||
constructor() {
|
||||
__privateAdd(this, _head, void 0);
|
||||
__privateAdd(this, _tail, void 0);
|
||||
__privateAdd(this, _size, void 0);
|
||||
this.clear();
|
||||
}
|
||||
enqueue(value) {
|
||||
const node = new Node(value);
|
||||
if (__privateGet(this, _head)) {
|
||||
__privateGet(this, _tail).next = node;
|
||||
__privateSet(this, _tail, node);
|
||||
} else {
|
||||
__privateSet(this, _head, node);
|
||||
__privateSet(this, _tail, node);
|
||||
}
|
||||
__privateWrapper(this, _size)._++;
|
||||
}
|
||||
dequeue() {
|
||||
const current = __privateGet(this, _head);
|
||||
if (!current) {
|
||||
return;
|
||||
}
|
||||
__privateSet(this, _head, __privateGet(this, _head).next);
|
||||
__privateWrapper(this, _size)._--;
|
||||
return current.value;
|
||||
}
|
||||
clear() {
|
||||
__privateSet(this, _head, void 0);
|
||||
__privateSet(this, _tail, void 0);
|
||||
__privateSet(this, _size, 0);
|
||||
}
|
||||
get size() {
|
||||
return __privateGet(this, _size);
|
||||
}
|
||||
*[Symbol.iterator]() {
|
||||
let current = __privateGet(this, _head);
|
||||
while (current) {
|
||||
yield current.value;
|
||||
current = current.next;
|
||||
}
|
||||
}
|
||||
};
|
||||
_head = new WeakMap();
|
||||
_tail = new WeakMap();
|
||||
_size = new WeakMap();
|
||||
|
||||
// node_modules/.pnpm/p-limit@4.0.0/node_modules/p-limit/index.js
|
||||
function pLimit(concurrency) {
|
||||
if (!((Number.isInteger(concurrency) || concurrency === Number.POSITIVE_INFINITY) && concurrency > 0)) {
|
||||
throw new TypeError("Expected `concurrency` to be a number from 1 and up");
|
||||
}
|
||||
const queue = new Queue();
|
||||
let activeCount = 0;
|
||||
const next = () => {
|
||||
activeCount--;
|
||||
if (queue.size > 0) {
|
||||
queue.dequeue()();
|
||||
}
|
||||
};
|
||||
const run = async (fn, resolve, args) => {
|
||||
activeCount++;
|
||||
const result = (async () => fn(...args))();
|
||||
resolve(result);
|
||||
try {
|
||||
await result;
|
||||
} catch (e) {
|
||||
}
|
||||
next();
|
||||
};
|
||||
const enqueue = (fn, resolve, args) => {
|
||||
queue.enqueue(run.bind(void 0, fn, resolve, args));
|
||||
(async () => {
|
||||
await Promise.resolve();
|
||||
if (activeCount < concurrency && queue.size > 0) {
|
||||
queue.dequeue()();
|
||||
}
|
||||
})();
|
||||
};
|
||||
const generator = (fn, ...args) => new Promise((resolve) => {
|
||||
enqueue(fn, resolve, args);
|
||||
});
|
||||
Object.defineProperties(generator, {
|
||||
activeCount: {
|
||||
get: () => activeCount
|
||||
},
|
||||
pendingCount: {
|
||||
get: () => queue.size
|
||||
},
|
||||
clearQueue: {
|
||||
value: () => {
|
||||
queue.clear();
|
||||
}
|
||||
}
|
||||
});
|
||||
return generator;
|
||||
}
|
||||
|
||||
// node_modules/.pnpm/p-locate@6.0.0/node_modules/p-locate/index.js
|
||||
var EndError = class extends Error {
|
||||
constructor(value) {
|
||||
super();
|
||||
this.value = value;
|
||||
}
|
||||
};
|
||||
var testElement = async (element, tester) => tester(await element);
|
||||
var finder = async (element) => {
|
||||
const values = await Promise.all(element);
|
||||
if (values[1] === true) {
|
||||
throw new EndError(values[0]);
|
||||
}
|
||||
return false;
|
||||
};
|
||||
async function pLocate(iterable, tester, {
|
||||
concurrency = Number.POSITIVE_INFINITY,
|
||||
preserveOrder = true
|
||||
} = {}) {
|
||||
const limit = pLimit(concurrency);
|
||||
const items = [...iterable].map((element) => [element, limit(testElement, element, tester)]);
|
||||
const checkLimit = pLimit(preserveOrder ? 1 : Number.POSITIVE_INFINITY);
|
||||
try {
|
||||
await Promise.all(items.map((element) => checkLimit(finder, element)));
|
||||
} catch (error) {
|
||||
if (error instanceof EndError) {
|
||||
return error.value;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
// node_modules/.pnpm/locate-path@7.1.1/node_modules/locate-path/index.js
|
||||
var typeMappings = {
|
||||
directory: "isDirectory",
|
||||
file: "isFile"
|
||||
};
|
||||
function checkType(type) {
|
||||
if (Object.hasOwnProperty.call(typeMappings, type)) {
|
||||
return;
|
||||
}
|
||||
throw new Error(`Invalid type specified: ${type}`);
|
||||
}
|
||||
var matchType = (type, stat) => stat[typeMappings[type]]();
|
||||
var toPath = (urlOrPath) => urlOrPath instanceof URL ? fileURLToPath(urlOrPath) : urlOrPath;
|
||||
async function locatePath(paths, {
|
||||
cwd = process2.cwd(),
|
||||
type = "file",
|
||||
allowSymlinks = true,
|
||||
concurrency,
|
||||
preserveOrder
|
||||
} = {}) {
|
||||
checkType(type);
|
||||
cwd = toPath(cwd);
|
||||
const statFunction = allowSymlinks ? fsPromises.stat : fsPromises.lstat;
|
||||
return pLocate(paths, async (path_) => {
|
||||
try {
|
||||
const stat = await statFunction(path.resolve(cwd, path_));
|
||||
return matchType(type, stat);
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}, { concurrency, preserveOrder });
|
||||
}
|
||||
|
||||
// node_modules/.pnpm/find-up@6.3.0/node_modules/find-up/index.js
|
||||
var toPath2 = (urlOrPath) => urlOrPath instanceof URL ? fileURLToPath2(urlOrPath) : urlOrPath;
|
||||
var findUpStop = Symbol("findUpStop");
|
||||
async function findUpMultiple(name, options = {}) {
|
||||
let directory = path2.resolve(toPath2(options.cwd) || "");
|
||||
const { root } = path2.parse(directory);
|
||||
const stopAt = path2.resolve(directory, options.stopAt || root);
|
||||
const limit = options.limit || Number.POSITIVE_INFINITY;
|
||||
const paths = [name].flat();
|
||||
const runMatcher = async (locateOptions) => {
|
||||
if (typeof name !== "function") {
|
||||
return locatePath(paths, locateOptions);
|
||||
}
|
||||
const foundPath = await name(locateOptions.cwd);
|
||||
if (typeof foundPath === "string") {
|
||||
return locatePath([foundPath], locateOptions);
|
||||
}
|
||||
return foundPath;
|
||||
};
|
||||
const matches = [];
|
||||
while (true) {
|
||||
const foundPath = await runMatcher(__spreadProps(__spreadValues({}, options), { cwd: directory }));
|
||||
if (foundPath === findUpStop) {
|
||||
break;
|
||||
}
|
||||
if (foundPath) {
|
||||
matches.push(path2.resolve(directory, foundPath));
|
||||
}
|
||||
if (directory === stopAt || matches.length >= limit) {
|
||||
break;
|
||||
}
|
||||
directory = path2.dirname(directory);
|
||||
}
|
||||
return matches;
|
||||
}
|
||||
async function findUp(name, options = {}) {
|
||||
const matches = await findUpMultiple(name, __spreadProps(__spreadValues({}, options), { limit: 1 }));
|
||||
return matches[0];
|
||||
}
|
||||
|
||||
// shared.ts
|
||||
async function loadPackageJSON(cwd = process.cwd()) {
|
||||
const path3 = await findUp("package.json", { cwd });
|
||||
if (!path3 || !existsSync(path3))
|
||||
return null;
|
||||
return JSON.parse(await fs2.readFile(path3, "utf-8"));
|
||||
}
|
||||
async function isPackageListed(name, cwd) {
|
||||
const pkg = await loadPackageJSON(cwd) || {};
|
||||
return name in (pkg.dependencies || {}) || name in (pkg.devDependencies || {});
|
||||
}
|
||||
export {
|
||||
isPackageListed,
|
||||
loadPackageJSON
|
||||
};
|
||||
Generated
Vendored
+109
@@ -0,0 +1,109 @@
|
||||
const { dirname, join } = require('path')
|
||||
const { existsSync, readFileSync } = require('fs')
|
||||
const fs = require('fs').promises
|
||||
const { loadPackageJSON, isPackageListed } = require('./dist/shared.cjs')
|
||||
|
||||
function resolveModule(name, options) {
|
||||
try {
|
||||
return require.resolve(name, options)
|
||||
}
|
||||
catch (e) {
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
function importModule(path) {
|
||||
const mod = require(path)
|
||||
if (mod.__esModule)
|
||||
return Promise.resolve(mod)
|
||||
else
|
||||
return Promise.resolve({ default: mod })
|
||||
}
|
||||
|
||||
function isPackageExists(name, options) {
|
||||
return !!resolvePackage(name, options)
|
||||
}
|
||||
|
||||
function getPackageJsonPath(name, options) {
|
||||
const entry = resolvePackage(name, options)
|
||||
if (!entry)
|
||||
return
|
||||
return searchPackageJSON(entry)
|
||||
}
|
||||
|
||||
async function getPackageInfo(name, options) {
|
||||
const packageJsonPath = getPackageJsonPath(name, options)
|
||||
if (!packageJsonPath)
|
||||
return
|
||||
|
||||
const pkg = JSON.parse(await fs.readFile(packageJsonPath, 'utf8'))
|
||||
|
||||
return {
|
||||
name,
|
||||
version: pkg.version,
|
||||
rootPath: dirname(packageJsonPath),
|
||||
packageJsonPath,
|
||||
packageJson: pkg,
|
||||
}
|
||||
}
|
||||
|
||||
function getPackageInfoSync(name, options) {
|
||||
const packageJsonPath = getPackageJsonPath(name, options)
|
||||
if (!packageJsonPath)
|
||||
return
|
||||
|
||||
const pkg = JSON.parse(readFileSync(packageJsonPath, 'utf8'))
|
||||
|
||||
return {
|
||||
name,
|
||||
version: pkg.version,
|
||||
rootPath: dirname(packageJsonPath),
|
||||
packageJsonPath,
|
||||
packageJson: pkg,
|
||||
}
|
||||
}
|
||||
|
||||
function resolvePackage(name, options = {}) {
|
||||
try {
|
||||
return require.resolve(`${name}/package.json`, options)
|
||||
}
|
||||
catch {
|
||||
}
|
||||
try {
|
||||
return require.resolve(name, options)
|
||||
}
|
||||
catch (e) {
|
||||
if (e.code !== 'MODULE_NOT_FOUND')
|
||||
throw e
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
function searchPackageJSON(dir) {
|
||||
let packageJsonPath
|
||||
while (true) {
|
||||
if (!dir)
|
||||
return
|
||||
const newDir = dirname(dir)
|
||||
if (newDir === dir)
|
||||
return
|
||||
dir = newDir
|
||||
packageJsonPath = join(dir, 'package.json')
|
||||
if (existsSync(packageJsonPath))
|
||||
break
|
||||
}
|
||||
|
||||
return packageJsonPath
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
resolveModule,
|
||||
importModule,
|
||||
isPackageExists,
|
||||
getPackageInfo,
|
||||
getPackageInfoSync,
|
||||
loadPackageJSON,
|
||||
isPackageListed,
|
||||
}
|
||||
|
||||
Object.defineProperty(module.exports, '__esModule', { value: true, enumerable: false })
|
||||
Generated
Vendored
+29
@@ -0,0 +1,29 @@
|
||||
export * from './dist/shared'
|
||||
|
||||
export interface PackageInfo {
|
||||
name: string
|
||||
rootPath: string
|
||||
packageJsonPath: string
|
||||
version: string
|
||||
packageJson: {
|
||||
name: string
|
||||
version: string
|
||||
dependencies?: Record<string, string>
|
||||
devDependencies?: Record<string, string>
|
||||
[key: string]: any
|
||||
}
|
||||
}
|
||||
|
||||
export interface PackageResolvingOptions {
|
||||
paths?: string[]
|
||||
}
|
||||
|
||||
export function isPackageExists(name: string, options?: PackageResolvingOptions): boolean
|
||||
|
||||
export function getPackageInfo(name: string, options?: PackageResolvingOptions): Promise<PackageInfo | undefined>
|
||||
|
||||
export function getPackageInfoSync(name: string, options?: PackageResolvingOptions): PackageInfo | undefined
|
||||
|
||||
export function resolveModule(path: string, options?: PackageResolvingOptions): string | undefined
|
||||
|
||||
export function importModule<T = any>(path: string): Promise<T>
|
||||
Generated
Vendored
+101
@@ -0,0 +1,101 @@
|
||||
import { dirname, join } from 'path'
|
||||
import { existsSync, promises as fs, readFileSync } from 'fs'
|
||||
import { createRequire } from 'module'
|
||||
|
||||
export { loadPackageJSON, isPackageListed } from './dist/shared.mjs'
|
||||
|
||||
const _require = createRequire(import.meta.url)
|
||||
|
||||
export function resolveModule(name, options) {
|
||||
try {
|
||||
return _require.resolve(name, options)
|
||||
}
|
||||
catch (e) {
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
export function importModule(path) {
|
||||
return import(path).then((i) => {
|
||||
if (i && i.default && i.default.__esModule)
|
||||
return i.default
|
||||
return i
|
||||
})
|
||||
}
|
||||
|
||||
export function isPackageExists(name, options) {
|
||||
return !!resolvePackage(name, options)
|
||||
}
|
||||
|
||||
function getPackageJsonPath(name, options) {
|
||||
const entry = resolvePackage(name, options)
|
||||
if (!entry)
|
||||
return
|
||||
|
||||
return searchPackageJSON(entry)
|
||||
}
|
||||
|
||||
export async function getPackageInfo(name, options) {
|
||||
const packageJsonPath = getPackageJsonPath(name, options)
|
||||
if (!packageJsonPath)
|
||||
return
|
||||
|
||||
const pkg = JSON.parse(await fs.readFile(packageJsonPath, 'utf8'))
|
||||
|
||||
return {
|
||||
name,
|
||||
version: pkg.version,
|
||||
rootPath: dirname(packageJsonPath),
|
||||
packageJsonPath,
|
||||
packageJson: pkg,
|
||||
}
|
||||
}
|
||||
|
||||
export function getPackageInfoSync(name, options) {
|
||||
const packageJsonPath = getPackageJsonPath(name, options)
|
||||
if (!packageJsonPath)
|
||||
return
|
||||
|
||||
const pkg = JSON.parse(readFileSync(packageJsonPath, 'utf8'))
|
||||
|
||||
return {
|
||||
name,
|
||||
version: pkg.version,
|
||||
rootPath: dirname(packageJsonPath),
|
||||
packageJsonPath,
|
||||
packageJson: pkg,
|
||||
}
|
||||
}
|
||||
|
||||
function resolvePackage(name, options = {}) {
|
||||
try {
|
||||
return _require.resolve(`${name}/package.json`, options)
|
||||
}
|
||||
catch {
|
||||
}
|
||||
try {
|
||||
return _require.resolve(name, options)
|
||||
}
|
||||
catch (e) {
|
||||
if (e.code !== 'MODULE_NOT_FOUND')
|
||||
console.error(e)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
function searchPackageJSON(dir) {
|
||||
let packageJsonPath
|
||||
while (true) {
|
||||
if (!dir)
|
||||
return
|
||||
const newDir = dirname(dir)
|
||||
if (newDir === dir)
|
||||
return
|
||||
dir = newDir
|
||||
packageJsonPath = join(dir, 'package.json')
|
||||
if (existsSync(packageJsonPath))
|
||||
break
|
||||
}
|
||||
|
||||
return packageJsonPath
|
||||
}
|
||||
Generated
Vendored
+61
@@ -0,0 +1,61 @@
|
||||
{
|
||||
"name": "local-pkg",
|
||||
"version": "0.4.3",
|
||||
"packageManager": "pnpm@7.5.0",
|
||||
"description": "Get information on local packages.",
|
||||
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
||||
"license": "MIT",
|
||||
"funding": "https://github.com/sponsors/antfu",
|
||||
"homepage": "https://github.com/antfu/local-pkg#readme",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/antfu/local-pkg.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/antfu/local-pkg/issues"
|
||||
},
|
||||
"keywords": [
|
||||
"package"
|
||||
],
|
||||
"sideEffects": false,
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./index.d.ts",
|
||||
"require": "./index.cjs",
|
||||
"import": "./index.mjs"
|
||||
}
|
||||
},
|
||||
"main": "index.cjs",
|
||||
"module": "index.mjs",
|
||||
"types": "index.d.ts",
|
||||
"files": [
|
||||
"dist",
|
||||
"index.cjs",
|
||||
"index.mjs",
|
||||
"index.d.ts"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=14"
|
||||
},
|
||||
"scripts": {
|
||||
"prepublishOnly": "nr build",
|
||||
"build": "tsup shared.ts --format esm,cjs --dts && esno scripts/postbuild.ts",
|
||||
"lint": "eslint .",
|
||||
"release": "bumpp && npm publish",
|
||||
"test": "node test/cjs.cjs && node test/esm.mjs"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@antfu/eslint-config": "^0.34.1",
|
||||
"@antfu/ni": "^0.18.8",
|
||||
"@antfu/utils": "^0.7.2",
|
||||
"@types/chai": "^4.3.4",
|
||||
"@types/node": "^18.11.18",
|
||||
"bumpp": "^8.2.1",
|
||||
"chai": "^4.3.7",
|
||||
"eslint": "^8.32.0",
|
||||
"esno": "^0.16.3",
|
||||
"find-up": "^6.3.0",
|
||||
"tsup": "^6.5.0",
|
||||
"typescript": "^4.9.4"
|
||||
}
|
||||
}
|
||||
+139
@@ -0,0 +1,139 @@
|
||||
{
|
||||
"name": "unplugin-vue-components",
|
||||
"version": "0.25.2",
|
||||
"packageManager": "pnpm@8.6.8",
|
||||
"description": "Components auto importing for Vue",
|
||||
"author": "antfu <anthonyfu117@hotmail.com>",
|
||||
"license": "MIT",
|
||||
"funding": "https://github.com/sponsors/antfu",
|
||||
"homepage": "https://github.com/antfu/unplugin-vue-components",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/antfu/unplugin-vue-components"
|
||||
},
|
||||
"bugs": "https://github.com/antfu/unplugin-vue-components/issues",
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./dist/index.d.ts",
|
||||
"require": "./dist/index.js",
|
||||
"import": "./dist/index.mjs"
|
||||
},
|
||||
"./nuxt": {
|
||||
"types": "./dist/nuxt.d.ts",
|
||||
"require": "./dist/nuxt.js",
|
||||
"import": "./dist/nuxt.mjs"
|
||||
},
|
||||
"./resolvers": {
|
||||
"types": "./dist/resolvers.d.ts",
|
||||
"require": "./dist/resolvers.js",
|
||||
"import": "./dist/resolvers.mjs"
|
||||
},
|
||||
"./rollup": {
|
||||
"types": "./dist/rollup.d.ts",
|
||||
"require": "./dist/rollup.js",
|
||||
"import": "./dist/rollup.mjs"
|
||||
},
|
||||
"./types": {
|
||||
"types": "./dist/types.d.ts",
|
||||
"require": "./dist/types.js",
|
||||
"import": "./dist/types.mjs"
|
||||
},
|
||||
"./vite": {
|
||||
"types": "./dist/vite.d.ts",
|
||||
"require": "./dist/vite.js",
|
||||
"import": "./dist/vite.mjs"
|
||||
},
|
||||
"./webpack": {
|
||||
"types": "./dist/webpack.d.ts",
|
||||
"require": "./dist/webpack.js",
|
||||
"import": "./dist/webpack.mjs"
|
||||
},
|
||||
"./rspack": {
|
||||
"types": "./dist/rspack.d.ts",
|
||||
"require": "./dist/rspack.js",
|
||||
"import": "./dist/rspack.mjs"
|
||||
},
|
||||
"./esbuild": {
|
||||
"types": "./dist/esbuild.d.ts",
|
||||
"require": "./dist/esbuild.js",
|
||||
"import": "./dist/esbuild.mjs"
|
||||
},
|
||||
"./*": "./*"
|
||||
},
|
||||
"main": "dist/index.js",
|
||||
"module": "dist/index.mjs",
|
||||
"types": "index.d.ts",
|
||||
"typesVersions": {
|
||||
"*": {
|
||||
"*": [
|
||||
"./dist/*"
|
||||
]
|
||||
}
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=14"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsup && esno scripts/postbuild.ts",
|
||||
"dev": "tsup --watch src",
|
||||
"example:build": "npm -C examples/vite-vue3 run build",
|
||||
"example:dev": "npm -C examples/vite-vue3 run dev",
|
||||
"prepublishOnly": "npm run build",
|
||||
"lint": "eslint .",
|
||||
"release": "bumpp && npm publish",
|
||||
"test": "vitest",
|
||||
"test:update": "vitest --u"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@babel/parser": "^7.15.8",
|
||||
"@nuxt/kit": "^3.2.2",
|
||||
"vue": "2 || 3"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"@babel/parser": {
|
||||
"optional": true
|
||||
},
|
||||
"@nuxt/kit": {
|
||||
"optional": true
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"@antfu/utils": "^0.7.5",
|
||||
"@rollup/pluginutils": "^5.0.2",
|
||||
"chokidar": "^3.5.3",
|
||||
"debug": "^4.3.4",
|
||||
"fast-glob": "^3.3.0",
|
||||
"local-pkg": "^0.4.3",
|
||||
"magic-string": "^0.30.1",
|
||||
"minimatch": "^9.0.3",
|
||||
"resolve": "^1.22.2",
|
||||
"unplugin": "^1.4.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@antfu/eslint-config": "^0.39.8",
|
||||
"@babel/parser": "^7.22.7",
|
||||
"@babel/types": "^7.22.5",
|
||||
"@nuxt/kit": "^3.6.3",
|
||||
"@types/debug": "^4.1.8",
|
||||
"@types/minimatch": "^5.1.2",
|
||||
"@types/node": "^20.4.2",
|
||||
"@types/resolve": "^1.20.2",
|
||||
"@typescript-eslint/eslint-plugin": "^6.1.0",
|
||||
"bumpp": "^9.1.1",
|
||||
"compare-versions": "^6.0.0",
|
||||
"element-plus": "^2.3.8",
|
||||
"eslint": "^8.45.0",
|
||||
"esno": "^0.17.0",
|
||||
"estree-walker": "^3.0.3",
|
||||
"pathe": "^1.1.1",
|
||||
"rollup": "^3.26.3",
|
||||
"tsup": "^7.1.0",
|
||||
"typescript": "^5.1.6",
|
||||
"vite": "^4.4.4",
|
||||
"vitest": "^0.33.0",
|
||||
"vue": "3.2.45"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user