初始化fy

This commit is contained in:
yziiy
2025-08-11 11:51:38 +08:00
parent 98ce20e897
commit 7e21160e13
19770 changed files with 3108698 additions and 0 deletions

21
uni_modules/UniDevTools/node_modules/unplugin/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2021-PRESENT Nuxt Contrib
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.

313
uni_modules/UniDevTools/node_modules/unplugin/README.md generated vendored Normal file
View File

@@ -0,0 +1,313 @@
# unplugin
[![npm version][npm-version-src]][npm-version-href]
[![npm downloads][npm-downloads-src]][npm-downloads-href]
[![License][license-src]][license-href]
Unified plugin system for build tools.
Currently supports:
- [Vite](https://vitejs.dev/)
- [Rollup](https://rollupjs.org/)
- [Webpack](https://webpack.js.org/)
- [esbuild](https://esbuild.github.io/)
- [Rspack](https://www.rspack.dev/) (⚠️ experimental)
## Hooks
`unplugin` extends the excellent [Rollup plugin API](https://rollupjs.org/guide/en/#plugins-overview) as the unified plugin interface and provides a compatible layer base on the build tools used with.
###### Supported
| Hook | Rollup | Vite | Webpack 4 | Webpack 5 | esbuild | Rspack |
| ----------------------------------------------------------------------- | :-------------: | :--: | :-------: | :-------: | :-------------: | :----: |
| [`enforce`](https://rollupjs.org/guide/en/#enforce) | ❌ <sup>1</sup> | ✅ | ✅ | ✅ | ❌ <sup>1</sup> | ✅ |
| [`buildStart`](https://rollupjs.org/guide/en/#buildstart) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| [`resolveId`](https://rollupjs.org/guide/en/#resolveid) | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ |
| `loadInclude`<sup>2</sup> | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| [`load`](https://rollupjs.org/guide/en/#load) | ✅ | ✅ | ✅ | ✅ | ✅ <sup>3</sup> | ✅ |
| `transformInclude`<sup>2</sup> | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| [`transform`](https://rollupjs.org/guide/en/#transformers) | ✅ | ✅ | ✅ | ✅ | ✅ <sup>3</sup> | ✅ |
| [`watchChange`](https://rollupjs.org/guide/en/#watchchange) | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ |
| [`buildEnd`](https://rollupjs.org/guide/en/#buildend) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| [`writeBundle`](https://rollupjs.org/guide/en/#writebundle)<sup>4</sup> | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
1. Rollup and esbuild do not support using `enforce` to control the order of plugins. Users need to maintain the order manually.
2. Webpack's id filter is outside of loader logic; an additional hook is needed for better perf on Webpack. In Rollup and Vite, this hook has been polyfilled to match the behaviors. See for following usage examples.
3. Although esbuild can handle both JavaScript and CSS and many other file formats, you can only return JavaScript in `load` and `transform` results.
4. Currently, `writeBundle` is only serves as a hook for the timing. It doesn't pass any arguments.
> **Warning**: The [Rspack](https://www.rspack.dev/) support is experimental. Future changes to Rspack integrations might not follow semver, please pin `unplugin` in your dependency when using. It's not recommended to use in production.
### Hook Context
###### Supported
| Hook | Rollup | Vite | Webpack 4 | Webpack 5 | esbuild | Rspack |
| -------------------------------------------------------------------------- | :----: | :--: | :-------: | :-------: | :-----: | :----: |
| [`this.parse`](https://rollupjs.org/guide/en/#thisparse) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| [`this.addWatchFile`](https://rollupjs.org/guide/en/#thisaddwatchfile) | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ |
| [`this.emitFile`](https://rollupjs.org/guide/en/#thisemitfile)<sup>5</sup> | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| [`this.getWatchFiles`](https://rollupjs.org/guide/en/#thisgetwatchfiles) | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ |
| [`this.warn`](https://rollupjs.org/guide/en/#thiswarn) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| [`this.error`](https://rollupjs.org/guide/en/#thiserror) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
5. Currently, [`this.emitFile`](https://rollupjs.org/guide/en/#thisemitfile) only supports the `EmittedAsset` variant.
## Usage
```ts
import { createUnplugin } from 'unplugin'
export const unplugin = createUnplugin((options: UserOptions) => {
return {
name: 'unplugin-prefixed-name',
// webpack's id filter is outside of loader logic,
// an additional hook is needed for better perf on webpack
transformInclude(id) {
return id.endsWith('.vue')
},
// just like rollup transform
transform(code) {
return code.replace(/<template>/, '<template><div>Injected</div>')
},
// more hooks coming
}
})
export const vitePlugin = unplugin.vite
export const rollupPlugin = unplugin.rollup
export const webpackPlugin = unplugin.webpack
export const rspackPlugin = unplugin.rspack
export const esbuildPlugin = unplugin.esbuild
```
## Nested Plugins
Since `v0.10.0`, unplugin supports constructing multiple nested plugins to behave like a single one. For example:
###### Supported
| Rollup | Vite | Webpack 4 | Webpack 5 | Rspack | esbuild |
| :--------------------: | :--: | :-------: | :-------: | :----: | :------------: |
| ✅ `>=3.1`<sup>6</sup> | ✅ | ✅ | ✅ | ✅ | ⚠️<sup>7</sup> |
6. Rollup supports nested plugins since [v3.1.0](https://github.com/rollup/rollup/releases/tag/v3.1.0). Plugin aurthor should ask users to a have a Rollup version of `>=3.1.0` when using nested plugins. For singe plugin format, unplugin works for any versions of Rollup.
7. Since esbuild does not have a built-in transform phase, the `transform` hook of nested plugin will not work on esbuild yet. Other hooks like `load` or `resolveId` work fine. We will try to find a way to support it in the future.
###### Usage
```ts
import { createUnplugin } from 'unplugin'
export const unplugin = createUnplugin((options: UserOptions) => {
return [
{
name: 'plugin-a',
transform(code) {
// ...
},
},
{
name: 'plugin-b',
resolveId(id) {
// ...
},
},
]
})
```
## Plugin Installation
###### Vite
```ts
// vite.config.ts
import UnpluginFeature from './unplugin-feature'
export default {
plugins: [
UnpluginFeature.vite({ /* options */ }),
],
}
```
###### Rollup
```ts
// rollup.config.js
import UnpluginFeature from './unplugin-feature'
export default {
plugins: [
UnpluginFeature.rollup({ /* options */ }),
],
}
```
###### Webpack
```ts
// webpack.config.js
module.exports = {
plugins: [
require('./unplugin-feature').webpack({ /* options */ }),
],
}
```
###### esbuild
```ts
// esbuild.config.js
import { build } from 'esbuild'
build({
plugins: [
require('./unplugin-feature').esbuild({ /* options */ }),
],
})
```
###### Rspack
```ts
// rspack.config.js
module.exports = {
plugins: [
require('./unplugin-feature').rspack({ /* options */ }),
],
}
```
### Framework-specific Logic
While `unplugin` provides compatible layers for some hooks, the functionality of it is limited to the common subset of the build's plugins capability. For more advanced framework-specific usages, `unplugin` provides an escape hatch for that.
```ts
export const unplugin = createUnplugin((options: UserOptions, meta) => {
console.log(meta.framework) // 'vite' | 'rollup' | 'webpack' | 'rspack' | 'esbuild'
return {
// common unplugin hooks
name: 'unplugin-prefixed-name',
transformInclude(id) { /* ... */ },
transform(code) { /* ... */ },
// framework specific hooks
vite: {
// Vite plugin
configureServer(server) {
// configure Vite server
},
// ...
},
rollup: {
// Rollup plugin
},
webpack(compiler) {
// configure Webpack compiler
},
rspack(compiler) {
// configure Rspack compiler
},
esbuild: {
// change the filter of onResolve and onLoad
onResolveFilter?: RegExp,
onLoadFilter?: RegExp,
// or you can completely replace the setup logic
setup?: EsbuildPlugin.setup,
},
}
})
```
### Creating platform specific plugins
The package exports a set of functions in place of `createUnplugin` that allow for the creation of plugins for specific bundlers.
Each of the function takes the same generic factory argument as `createUnplugin`.
```ts
import {
creteEsbuildPlugin,
getRollupPlugin,
getRspackPlugin,
getVitePlugin,
getWebpackPlugin
} from 'unplugin'
const vitePlugin = getVitePlugin({ /* options */ })
const rollupPlugin = getRollupPlugin({ /* options */ })
const esbuildPlugin = creteEsbuildPlugin({ /* options */ })
const webpackPlugin = getWebpackPlugin({ /* options */ })
const rspackPlugin = getRspackPlugin({ /* options */ })
```
## Conventions
- Plugins powered by unplugin should have a clear name with `unplugin-` prefix.
- Include `unplugin` keyword in `package.json`.
- To provide better DX, packages could export 2 kinds of entry points:
- Default export: the returned value of `createUnplugin` function
```ts
import UnpluginFeature from 'unplugin-feature'
```
- Subpath exports: properties of the returned value of `createUnplugin` function for each framework users
```ts
import VitePlugin from 'unplugin-feature/vite'
```
- Refer to [unplugin-starter](https://github.com/antfu/unplugin-starter) for more details about this setup.
## Starter Templates
- [antfu/unplugin-starter](https://github.com/antfu/unplugin-starter)
- [jwr12135/create-unplugin](https://github.com/jwr12135/create-unplugin)
- [sxzz/unplugin-starter](https://github.com/sxzz/unplugin-starter)
## Community Showcases
- [unplugin-auto-import](https://github.com/antfu/unplugin-auto-import)
- [unplugin-vue2-script-setup](https://github.com/antfu/unplugin-vue2-script-setup)
- [unplugin-icons](https://github.com/antfu/unplugin-icons)
- [unplugin-vue-components](https://github.com/antfu/unplugin-vue-components)
- [unplugin-upload-cdn](https://github.com/zenotsai/unplugin-upload-cdn)
- [unplugin-web-ext](https://github.com/jwr12135/unplugin-web-ext)
- [unplugin-properties](https://github.com/pd4d10/unplugin-properties)
- [unplugin-moment-to-dayjs](https://github.com/1247748612/unplugin-moment-to-dayjs)
- [unplugin-object-3d](https://github.com/m0ksem/unplugin-object-3d)
- [unplugin-parcel-css](https://github.com/ssssota/unplugin-parcel-css)
- [unplugin-vue](https://github.com/sxzz/unplugin-vue)
- [unplugin-vue-macros](https://github.com/sxzz/unplugin-vue-macros)
- [unplugin-vue-define-options](https://github.com/sxzz/unplugin-vue-macros/tree/main/packages/define-options)
- [unplugin-jsx-string](https://github.com/sxzz/unplugin-jsx-string)
- [unplugin-ast](https://github.com/sxzz/unplugin-ast)
- [unplugin-element-plus](https://github.com/element-plus/unplugin-element-plus)
- [unplugin-glob](https://github.com/sxzz/unplugin-glob)
- [unplugin-sentry](https://github.com/kricsleo/unplugin-sentry)
- [unplugin-imagemin](https://github.com/ErKeLost/unplugin-imagemin)
- [unplugin-typedotenv](https://github.com/ssssota/typedotenv)
- [unplugin-fonts](https://github.com/cssninjaStudio/unplugin-fonts)
- [sentry-javascript-bundler-plugins](https://github.com/getsentry/sentry-javascript-bundler-plugins)
- [unplugin-svg-component](https://github.com/Jevon617/unplugin-svg-component)
- [unplugin-vue-cssvars](https://github.com/baiwusanyu-c/unplugin-vue-cssvars)
## License
[MIT](./LICENSE) License © 2021-PRESENT Nuxt Contrib
<!-- Badges -->
[npm-version-src]: https://img.shields.io/npm/v/unplugin?style=flat&colorA=18181B&colorB=F0DB4F
[npm-version-href]: https://npmjs.com/package/unplugin
[npm-downloads-src]: https://img.shields.io/npm/dm/unplugin?style=flat&colorA=18181B&colorB=F0DB4F
[npm-downloads-href]: https://npmjs.com/package/unplugin
[license-src]: https://img.shields.io/github/license/unjs/unplugin.svg?style=flat&colorA=18181B&colorB=F0DB4F
[license-href]: https://github.com/unjs/unplugin/blob/main/LICENSE

View File

@@ -0,0 +1,126 @@
import * as _rspack_core_dist_config_types from '@rspack/core/dist/config/types';
import * as webpack from 'webpack';
import { Compiler, WebpackPluginInstance } from 'webpack';
export { Compiler as WebpackCompiler, WebpackPluginInstance } from 'webpack';
import * as vite from 'vite';
import { Plugin as Plugin$1 } from 'vite';
export { Plugin as VitePlugin } from 'vite';
import * as rollup from 'rollup';
import { SourceMapInput, EmittedAsset, AcornNode, Plugin, PluginContextMeta } from 'rollup';
export { Plugin as RollupPlugin } from 'rollup';
import * as esbuild from 'esbuild';
import { Plugin as Plugin$2, PluginBuild } from 'esbuild';
export { Plugin as EsbuildPlugin } from 'esbuild';
import { Compiler as Compiler$1, RspackPluginInstance } from '@rspack/core';
export { Compiler as RspackCompiler, RspackPluginInstance } from '@rspack/core';
import VirtualModulesPlugin from 'webpack-virtual-modules';
type Thenable<T> = T | Promise<T>;
interface SourceMapCompact {
file?: string;
mappings: string;
names: string[];
sourceRoot?: string;
sources: string[];
sourcesContent?: (string | null)[];
version: number;
}
type TransformResult = string | {
code: string;
map?: SourceMapInput | SourceMapCompact | null;
} | null | undefined;
interface ExternalIdResult {
id: string;
external?: boolean;
}
interface UnpluginBuildContext {
addWatchFile: (id: string) => void;
emitFile: (emittedFile: EmittedAsset) => void;
getWatchFiles: () => string[];
parse: (input: string, options?: any) => AcornNode;
}
interface UnpluginOptions {
name: string;
enforce?: 'post' | 'pre' | undefined;
buildStart?: (this: UnpluginBuildContext) => Promise<void> | void;
buildEnd?: (this: UnpluginBuildContext) => Promise<void> | void;
transform?: (this: UnpluginBuildContext & UnpluginContext, code: string, id: string) => Thenable<TransformResult>;
load?: (this: UnpluginBuildContext & UnpluginContext, id: string) => Thenable<TransformResult>;
resolveId?: (id: string, importer: string | undefined, options: {
isEntry: boolean;
}) => Thenable<string | ExternalIdResult | null | undefined>;
watchChange?: (this: UnpluginBuildContext, id: string, change: {
event: 'create' | 'update' | 'delete';
}) => void;
writeBundle?: (this: void) => Promise<void> | void;
/**
* Custom predicate function to filter modules to be loaded.
* When omitted, all modules will be included (might have potential perf impact on Webpack).
*/
loadInclude?: (id: string) => boolean | null | undefined;
/**
* Custom predicate function to filter modules to be transformed.
* When omitted, all modules will be included (might have potential perf impact on Webpack).
*/
transformInclude?: (id: string) => boolean | null | undefined;
rollup?: Partial<Plugin>;
webpack?: (compiler: Compiler) => void;
rspack?: (compiler: Compiler$1) => void;
vite?: Partial<Plugin$1>;
esbuild?: {
onResolveFilter?: RegExp;
onLoadFilter?: RegExp;
setup?: Plugin$2['setup'];
};
}
interface ResolvedUnpluginOptions extends UnpluginOptions {
__vfs?: VirtualModulesPlugin;
__vfsModules?: Set<string>;
__virtualModulePrefix: string;
}
type UnpluginFactory<UserOptions, Nested extends boolean = boolean> = (options: UserOptions, meta: UnpluginContextMeta) => Nested extends true ? Array<UnpluginOptions> : UnpluginOptions;
type UnpluginFactoryOutput<UserOptions, Return> = undefined extends UserOptions ? (options?: UserOptions) => Return : (options: UserOptions) => Return;
interface UnpluginInstance<UserOptions, Nested extends boolean = boolean> {
rollup: UnpluginFactoryOutput<UserOptions, Nested extends true ? Array<Plugin> : Plugin>;
vite: UnpluginFactoryOutput<UserOptions, Nested extends true ? Array<Plugin$1> : Plugin$1>;
webpack: UnpluginFactoryOutput<UserOptions, WebpackPluginInstance>;
rspack: UnpluginFactoryOutput<UserOptions, RspackPluginInstance>;
esbuild: UnpluginFactoryOutput<UserOptions, Plugin$2>;
raw: UnpluginFactory<UserOptions, Nested>;
}
type UnpluginContextMeta = Partial<PluginContextMeta> & ({
framework: 'rollup' | 'vite';
} | {
framework: 'webpack';
webpack: {
compiler: Compiler;
};
} | {
framework: 'esbuild';
build?: PluginBuild;
/** Set the host plugin name of esbuild when returning multiple plugins */
esbuildHostName?: string;
} | {
framework: 'rspack';
rspack: {
compiler: Compiler$1;
};
});
interface UnpluginContext {
error(message: any): void;
warn(message: any): void;
}
declare module 'webpack' {
interface Compiler {
$unpluginContext: Record<string, ResolvedUnpluginOptions>;
}
}
declare function createUnplugin<UserOptions, Nested extends boolean = boolean>(factory: UnpluginFactory<UserOptions, Nested>): UnpluginInstance<UserOptions, Nested>;
declare function creteEsbuildPlugin<UserOptions, Nested extends boolean = boolean>(factory: UnpluginFactory<UserOptions, Nested>): UnpluginFactoryOutput<UserOptions, esbuild.Plugin>;
declare function creteRollupPlugin<UserOptions, Nested extends boolean = boolean>(factory: UnpluginFactory<UserOptions, Nested>): UnpluginFactoryOutput<UserOptions, Nested extends true ? rollup.Plugin[] : rollup.Plugin>;
declare function creteVitePlugin<UserOptions, Nested extends boolean = boolean>(factory: UnpluginFactory<UserOptions, Nested>): UnpluginFactoryOutput<UserOptions, Nested extends true ? vite.Plugin[] : vite.Plugin>;
declare function creteWebpackPlugin<UserOptions, Nested extends boolean = boolean>(factory: UnpluginFactory<UserOptions, Nested>): UnpluginFactoryOutput<UserOptions, webpack.WebpackPluginInstance>;
declare function creteRspackPlugin<UserOptions, Nested extends boolean = boolean>(factory: UnpluginFactory<UserOptions, Nested>): UnpluginFactoryOutput<UserOptions, _rspack_core_dist_config_types.RspackPluginInstance>;
export { ExternalIdResult, ResolvedUnpluginOptions, SourceMapCompact, Thenable, TransformResult, UnpluginBuildContext, UnpluginContext, UnpluginContextMeta, UnpluginFactory, UnpluginFactoryOutput, UnpluginInstance, UnpluginOptions, createUnplugin, creteEsbuildPlugin, creteRollupPlugin, creteRspackPlugin, creteVitePlugin, creteWebpackPlugin };

View File

@@ -0,0 +1,126 @@
import * as _rspack_core_dist_config_types from '@rspack/core/dist/config/types';
import * as webpack from 'webpack';
import { Compiler, WebpackPluginInstance } from 'webpack';
export { Compiler as WebpackCompiler, WebpackPluginInstance } from 'webpack';
import * as vite from 'vite';
import { Plugin as Plugin$1 } from 'vite';
export { Plugin as VitePlugin } from 'vite';
import * as rollup from 'rollup';
import { SourceMapInput, EmittedAsset, AcornNode, Plugin, PluginContextMeta } from 'rollup';
export { Plugin as RollupPlugin } from 'rollup';
import * as esbuild from 'esbuild';
import { Plugin as Plugin$2, PluginBuild } from 'esbuild';
export { Plugin as EsbuildPlugin } from 'esbuild';
import { Compiler as Compiler$1, RspackPluginInstance } from '@rspack/core';
export { Compiler as RspackCompiler, RspackPluginInstance } from '@rspack/core';
import VirtualModulesPlugin from 'webpack-virtual-modules';
type Thenable<T> = T | Promise<T>;
interface SourceMapCompact {
file?: string;
mappings: string;
names: string[];
sourceRoot?: string;
sources: string[];
sourcesContent?: (string | null)[];
version: number;
}
type TransformResult = string | {
code: string;
map?: SourceMapInput | SourceMapCompact | null;
} | null | undefined;
interface ExternalIdResult {
id: string;
external?: boolean;
}
interface UnpluginBuildContext {
addWatchFile: (id: string) => void;
emitFile: (emittedFile: EmittedAsset) => void;
getWatchFiles: () => string[];
parse: (input: string, options?: any) => AcornNode;
}
interface UnpluginOptions {
name: string;
enforce?: 'post' | 'pre' | undefined;
buildStart?: (this: UnpluginBuildContext) => Promise<void> | void;
buildEnd?: (this: UnpluginBuildContext) => Promise<void> | void;
transform?: (this: UnpluginBuildContext & UnpluginContext, code: string, id: string) => Thenable<TransformResult>;
load?: (this: UnpluginBuildContext & UnpluginContext, id: string) => Thenable<TransformResult>;
resolveId?: (id: string, importer: string | undefined, options: {
isEntry: boolean;
}) => Thenable<string | ExternalIdResult | null | undefined>;
watchChange?: (this: UnpluginBuildContext, id: string, change: {
event: 'create' | 'update' | 'delete';
}) => void;
writeBundle?: (this: void) => Promise<void> | void;
/**
* Custom predicate function to filter modules to be loaded.
* When omitted, all modules will be included (might have potential perf impact on Webpack).
*/
loadInclude?: (id: string) => boolean | null | undefined;
/**
* Custom predicate function to filter modules to be transformed.
* When omitted, all modules will be included (might have potential perf impact on Webpack).
*/
transformInclude?: (id: string) => boolean | null | undefined;
rollup?: Partial<Plugin>;
webpack?: (compiler: Compiler) => void;
rspack?: (compiler: Compiler$1) => void;
vite?: Partial<Plugin$1>;
esbuild?: {
onResolveFilter?: RegExp;
onLoadFilter?: RegExp;
setup?: Plugin$2['setup'];
};
}
interface ResolvedUnpluginOptions extends UnpluginOptions {
__vfs?: VirtualModulesPlugin;
__vfsModules?: Set<string>;
__virtualModulePrefix: string;
}
type UnpluginFactory<UserOptions, Nested extends boolean = boolean> = (options: UserOptions, meta: UnpluginContextMeta) => Nested extends true ? Array<UnpluginOptions> : UnpluginOptions;
type UnpluginFactoryOutput<UserOptions, Return> = undefined extends UserOptions ? (options?: UserOptions) => Return : (options: UserOptions) => Return;
interface UnpluginInstance<UserOptions, Nested extends boolean = boolean> {
rollup: UnpluginFactoryOutput<UserOptions, Nested extends true ? Array<Plugin> : Plugin>;
vite: UnpluginFactoryOutput<UserOptions, Nested extends true ? Array<Plugin$1> : Plugin$1>;
webpack: UnpluginFactoryOutput<UserOptions, WebpackPluginInstance>;
rspack: UnpluginFactoryOutput<UserOptions, RspackPluginInstance>;
esbuild: UnpluginFactoryOutput<UserOptions, Plugin$2>;
raw: UnpluginFactory<UserOptions, Nested>;
}
type UnpluginContextMeta = Partial<PluginContextMeta> & ({
framework: 'rollup' | 'vite';
} | {
framework: 'webpack';
webpack: {
compiler: Compiler;
};
} | {
framework: 'esbuild';
build?: PluginBuild;
/** Set the host plugin name of esbuild when returning multiple plugins */
esbuildHostName?: string;
} | {
framework: 'rspack';
rspack: {
compiler: Compiler$1;
};
});
interface UnpluginContext {
error(message: any): void;
warn(message: any): void;
}
declare module 'webpack' {
interface Compiler {
$unpluginContext: Record<string, ResolvedUnpluginOptions>;
}
}
declare function createUnplugin<UserOptions, Nested extends boolean = boolean>(factory: UnpluginFactory<UserOptions, Nested>): UnpluginInstance<UserOptions, Nested>;
declare function creteEsbuildPlugin<UserOptions, Nested extends boolean = boolean>(factory: UnpluginFactory<UserOptions, Nested>): UnpluginFactoryOutput<UserOptions, esbuild.Plugin>;
declare function creteRollupPlugin<UserOptions, Nested extends boolean = boolean>(factory: UnpluginFactory<UserOptions, Nested>): UnpluginFactoryOutput<UserOptions, Nested extends true ? rollup.Plugin[] : rollup.Plugin>;
declare function creteVitePlugin<UserOptions, Nested extends boolean = boolean>(factory: UnpluginFactory<UserOptions, Nested>): UnpluginFactoryOutput<UserOptions, Nested extends true ? vite.Plugin[] : vite.Plugin>;
declare function creteWebpackPlugin<UserOptions, Nested extends boolean = boolean>(factory: UnpluginFactory<UserOptions, Nested>): UnpluginFactoryOutput<UserOptions, webpack.WebpackPluginInstance>;
declare function creteRspackPlugin<UserOptions, Nested extends boolean = boolean>(factory: UnpluginFactory<UserOptions, Nested>): UnpluginFactoryOutput<UserOptions, _rspack_core_dist_config_types.RspackPluginInstance>;
export { ExternalIdResult, ResolvedUnpluginOptions, SourceMapCompact, Thenable, TransformResult, UnpluginBuildContext, UnpluginContext, UnpluginContextMeta, UnpluginFactory, UnpluginFactoryOutput, UnpluginInstance, UnpluginOptions, createUnplugin, creteEsbuildPlugin, creteRollupPlugin, creteRspackPlugin, creteVitePlugin, creteWebpackPlugin };

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,5 @@
import { LoaderContext } from '@rspack/core';
declare function load(this: LoaderContext, source: string, map: any): Promise<void>;
export { load as default };

View File

@@ -0,0 +1,5 @@
import { LoaderContext } from '@rspack/core';
declare function load(this: LoaderContext, source: string, map: any): Promise<void>;
export { load as default };

View File

@@ -0,0 +1,106 @@
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
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(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/rspack/loaders/load.ts
var load_exports = {};
__export(load_exports, {
default: () => load
});
module.exports = __toCommonJS(load_exports);
// src/rspack/context.ts
var import_buffer = require("buffer");
var import_webpack_sources = __toESM(require("webpack-sources"));
var import_acorn = require("acorn");
function createRspackContext(compilation) {
return {
parse(code, opts = {}) {
return import_acorn.Parser.parse(code, {
sourceType: "module",
ecmaVersion: "latest",
locations: true,
...opts
});
},
addWatchFile() {
},
emitFile(emittedFile) {
const outFileName = emittedFile.fileName || emittedFile.name;
if (emittedFile.source && outFileName) {
compilation.emitAsset(
outFileName,
new import_webpack_sources.default.RawSource(
// @ts-expect-error types mismatch
typeof emittedFile.source === "string" ? emittedFile.source : import_buffer.Buffer.from(emittedFile.source)
)
);
}
},
getWatchFiles() {
return [];
}
};
}
// src/utils.ts
var import_path = require("path");
function normalizeAbsolutePath(path) {
if ((0, import_path.isAbsolute)(path))
return (0, import_path.normalize)(path);
else
return path;
}
// src/rspack/loaders/load.ts
async function load(source, map) {
const callback = this.async();
const id = this.resource;
const { plugin } = this.getOptions();
if (!plugin?.load || !id)
return callback(null, source, map);
if (plugin.loadInclude && !plugin.loadInclude(id))
return callback(null, source, map);
const context = {
error: (error) => this.emitError(typeof error === "string" ? new Error(error) : error),
warn: (error) => this.emitWarning(typeof error === "string" ? new Error(error) : error)
};
const res = await plugin.load.call(
Object.assign(
this._compilation && createRspackContext(this._compilation),
context
),
normalizeAbsolutePath(id)
);
if (res == null)
callback(null, source, map);
else if (typeof res !== "string")
callback(null, res.code, res.map ?? map);
else
callback(null, res, map);
}

View File

@@ -0,0 +1,73 @@
// src/rspack/context.ts
import { Buffer } from "buffer";
import sources from "webpack-sources";
import { Parser } from "acorn";
function createRspackContext(compilation) {
return {
parse(code, opts = {}) {
return Parser.parse(code, {
sourceType: "module",
ecmaVersion: "latest",
locations: true,
...opts
});
},
addWatchFile() {
},
emitFile(emittedFile) {
const outFileName = emittedFile.fileName || emittedFile.name;
if (emittedFile.source && outFileName) {
compilation.emitAsset(
outFileName,
new sources.RawSource(
// @ts-expect-error types mismatch
typeof emittedFile.source === "string" ? emittedFile.source : Buffer.from(emittedFile.source)
)
);
}
},
getWatchFiles() {
return [];
}
};
}
// src/utils.ts
import { isAbsolute, normalize } from "path";
function normalizeAbsolutePath(path) {
if (isAbsolute(path))
return normalize(path);
else
return path;
}
// src/rspack/loaders/load.ts
async function load(source, map) {
const callback = this.async();
const id = this.resource;
const { plugin } = this.getOptions();
if (!plugin?.load || !id)
return callback(null, source, map);
if (plugin.loadInclude && !plugin.loadInclude(id))
return callback(null, source, map);
const context = {
error: (error) => this.emitError(typeof error === "string" ? new Error(error) : error),
warn: (error) => this.emitWarning(typeof error === "string" ? new Error(error) : error)
};
const res = await plugin.load.call(
Object.assign(
this._compilation && createRspackContext(this._compilation),
context
),
normalizeAbsolutePath(id)
);
if (res == null)
callback(null, source, map);
else if (typeof res !== "string")
callback(null, res.code, res.map ?? map);
else
callback(null, res, map);
}
export {
load as default
};

View File

@@ -0,0 +1,5 @@
import { LoaderContext } from '@rspack/core';
declare function transform(this: LoaderContext, source: string, map: any): Promise<void>;
export { transform as default };

View File

@@ -0,0 +1,5 @@
import { LoaderContext } from '@rspack/core';
declare function transform(this: LoaderContext, source: string, map: any): Promise<void>;
export { transform as default };

View File

@@ -0,0 +1,98 @@
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
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(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/rspack/loaders/transform.ts
var transform_exports = {};
__export(transform_exports, {
default: () => transform
});
module.exports = __toCommonJS(transform_exports);
// src/rspack/context.ts
var import_buffer = require("buffer");
var import_webpack_sources = __toESM(require("webpack-sources"));
var import_acorn = require("acorn");
function createRspackContext(compilation) {
return {
parse(code, opts = {}) {
return import_acorn.Parser.parse(code, {
sourceType: "module",
ecmaVersion: "latest",
locations: true,
...opts
});
},
addWatchFile() {
},
emitFile(emittedFile) {
const outFileName = emittedFile.fileName || emittedFile.name;
if (emittedFile.source && outFileName) {
compilation.emitAsset(
outFileName,
new import_webpack_sources.default.RawSource(
// @ts-expect-error types mismatch
typeof emittedFile.source === "string" ? emittedFile.source : import_buffer.Buffer.from(emittedFile.source)
)
);
}
},
getWatchFiles() {
return [];
}
};
}
// src/rspack/loaders/transform.ts
async function transform(source, map) {
const callback = this.async();
const id = this.resource;
const { plugin } = this.getOptions();
if (!plugin?.transform)
return callback(null, source, map);
if (plugin.transformInclude && !plugin.transformInclude(id))
return callback(null, source, map);
const context = {
error: (error) => this.emitError(typeof error === "string" ? new Error(error) : error),
warn: (error) => this.emitWarning(typeof error === "string" ? new Error(error) : error)
};
const res = await plugin.transform.call(
Object.assign(
this._compilation && createRspackContext(this._compilation),
context
),
source,
id
);
if (res == null)
callback(null, source, map);
else if (typeof res !== "string")
callback(null, res.code, map == null ? map : res.map || map);
else
callback(null, res, map);
}

View File

@@ -0,0 +1,65 @@
// src/rspack/context.ts
import { Buffer } from "buffer";
import sources from "webpack-sources";
import { Parser } from "acorn";
function createRspackContext(compilation) {
return {
parse(code, opts = {}) {
return Parser.parse(code, {
sourceType: "module",
ecmaVersion: "latest",
locations: true,
...opts
});
},
addWatchFile() {
},
emitFile(emittedFile) {
const outFileName = emittedFile.fileName || emittedFile.name;
if (emittedFile.source && outFileName) {
compilation.emitAsset(
outFileName,
new sources.RawSource(
// @ts-expect-error types mismatch
typeof emittedFile.source === "string" ? emittedFile.source : Buffer.from(emittedFile.source)
)
);
}
},
getWatchFiles() {
return [];
}
};
}
// src/rspack/loaders/transform.ts
async function transform(source, map) {
const callback = this.async();
const id = this.resource;
const { plugin } = this.getOptions();
if (!plugin?.transform)
return callback(null, source, map);
if (plugin.transformInclude && !plugin.transformInclude(id))
return callback(null, source, map);
const context = {
error: (error) => this.emitError(typeof error === "string" ? new Error(error) : error),
warn: (error) => this.emitWarning(typeof error === "string" ? new Error(error) : error)
};
const res = await plugin.transform.call(
Object.assign(
this._compilation && createRspackContext(this._compilation),
context
),
source,
id
);
if (res == null)
callback(null, source, map);
else if (typeof res !== "string")
callback(null, res.code, map == null ? map : res.map || map);
else
callback(null, res, map);
}
export {
transform as default
};

View File

@@ -0,0 +1,5 @@
import { LoaderContext } from 'webpack';
declare function load(this: LoaderContext<any>, source: string, map: any): Promise<void>;
export { load as default };

View File

@@ -0,0 +1,5 @@
import { LoaderContext } from 'webpack';
declare function load(this: LoaderContext<any>, source: string, map: any): Promise<void>;
export { load as default };

View File

@@ -0,0 +1,113 @@
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
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(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/webpack/loaders/load.ts
var load_exports = {};
__export(load_exports, {
default: () => load
});
module.exports = __toCommonJS(load_exports);
// src/webpack/context.ts
var import_path = require("path");
var import_buffer = require("buffer");
var import_webpack_sources = __toESM(require("webpack-sources"));
var import_acorn = require("acorn");
function createContext(compilation) {
return {
parse(code, opts = {}) {
return import_acorn.Parser.parse(code, {
sourceType: "module",
ecmaVersion: "latest",
locations: true,
...opts
});
},
addWatchFile(id) {
(compilation.fileDependencies ?? compilation.compilationDependencies).add(
(0, import_path.resolve)(process.cwd(), id)
);
},
emitFile(emittedFile) {
const outFileName = emittedFile.fileName || emittedFile.name;
if (emittedFile.source && outFileName) {
compilation.emitAsset(
outFileName,
import_webpack_sources.default ? new import_webpack_sources.default.RawSource(
// @ts-expect-error types mismatch
typeof emittedFile.source === "string" ? emittedFile.source : import_buffer.Buffer.from(emittedFile.source)
) : {
source: () => emittedFile.source,
size: () => emittedFile.source.length
}
);
}
},
getWatchFiles() {
return Array.from(
compilation.fileDependencies ?? compilation.compilationDependencies
);
}
};
}
// src/utils.ts
var import_path2 = require("path");
function normalizeAbsolutePath(path) {
if ((0, import_path2.isAbsolute)(path))
return (0, import_path2.normalize)(path);
else
return path;
}
// src/webpack/loaders/load.ts
async function load(source, map) {
const callback = this.async();
const { unpluginName } = this.query;
const plugin = this._compiler?.$unpluginContext[unpluginName];
let id = this.resource;
if (!plugin?.load || !id)
return callback(null, source, map);
const context = {
error: (error) => this.emitError(typeof error === "string" ? new Error(error) : error),
warn: (error) => this.emitWarning(typeof error === "string" ? new Error(error) : error)
};
if (id.startsWith(plugin.__virtualModulePrefix))
id = decodeURIComponent(id.slice(plugin.__virtualModulePrefix.length));
const res = await plugin.load.call(
Object.assign(this._compilation && createContext(this._compilation), context),
normalizeAbsolutePath(id)
);
if (res == null)
callback(null, source, map);
else if (typeof res !== "string")
callback(null, res.code, res.map ?? map);
else
callback(null, res, map);
}

View File

@@ -0,0 +1,80 @@
// src/webpack/context.ts
import { resolve } from "path";
import { Buffer } from "buffer";
import sources from "webpack-sources";
import { Parser } from "acorn";
function createContext(compilation) {
return {
parse(code, opts = {}) {
return Parser.parse(code, {
sourceType: "module",
ecmaVersion: "latest",
locations: true,
...opts
});
},
addWatchFile(id) {
(compilation.fileDependencies ?? compilation.compilationDependencies).add(
resolve(process.cwd(), id)
);
},
emitFile(emittedFile) {
const outFileName = emittedFile.fileName || emittedFile.name;
if (emittedFile.source && outFileName) {
compilation.emitAsset(
outFileName,
sources ? new sources.RawSource(
// @ts-expect-error types mismatch
typeof emittedFile.source === "string" ? emittedFile.source : Buffer.from(emittedFile.source)
) : {
source: () => emittedFile.source,
size: () => emittedFile.source.length
}
);
}
},
getWatchFiles() {
return Array.from(
compilation.fileDependencies ?? compilation.compilationDependencies
);
}
};
}
// src/utils.ts
import { isAbsolute, normalize } from "path";
function normalizeAbsolutePath(path) {
if (isAbsolute(path))
return normalize(path);
else
return path;
}
// src/webpack/loaders/load.ts
async function load(source, map) {
const callback = this.async();
const { unpluginName } = this.query;
const plugin = this._compiler?.$unpluginContext[unpluginName];
let id = this.resource;
if (!plugin?.load || !id)
return callback(null, source, map);
const context = {
error: (error) => this.emitError(typeof error === "string" ? new Error(error) : error),
warn: (error) => this.emitWarning(typeof error === "string" ? new Error(error) : error)
};
if (id.startsWith(plugin.__virtualModulePrefix))
id = decodeURIComponent(id.slice(plugin.__virtualModulePrefix.length));
const res = await plugin.load.call(
Object.assign(this._compilation && createContext(this._compilation), context),
normalizeAbsolutePath(id)
);
if (res == null)
callback(null, source, map);
else if (typeof res !== "string")
callback(null, res.code, res.map ?? map);
else
callback(null, res, map);
}
export {
load as default
};

View File

@@ -0,0 +1,7 @@
import { LoaderContext } from 'webpack';
declare function transform(this: LoaderContext<{
unpluginName: string;
}>, source: string, map: any): Promise<void>;
export { transform as default };

View File

@@ -0,0 +1,7 @@
import { LoaderContext } from 'webpack';
declare function transform(this: LoaderContext<{
unpluginName: string;
}>, source: string, map: any): Promise<void>;
export { transform as default };

View File

@@ -0,0 +1,104 @@
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
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(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/webpack/loaders/transform.ts
var transform_exports = {};
__export(transform_exports, {
default: () => transform
});
module.exports = __toCommonJS(transform_exports);
// src/webpack/context.ts
var import_path = require("path");
var import_buffer = require("buffer");
var import_webpack_sources = __toESM(require("webpack-sources"));
var import_acorn = require("acorn");
function createContext(compilation) {
return {
parse(code, opts = {}) {
return import_acorn.Parser.parse(code, {
sourceType: "module",
ecmaVersion: "latest",
locations: true,
...opts
});
},
addWatchFile(id) {
(compilation.fileDependencies ?? compilation.compilationDependencies).add(
(0, import_path.resolve)(process.cwd(), id)
);
},
emitFile(emittedFile) {
const outFileName = emittedFile.fileName || emittedFile.name;
if (emittedFile.source && outFileName) {
compilation.emitAsset(
outFileName,
import_webpack_sources.default ? new import_webpack_sources.default.RawSource(
// @ts-expect-error types mismatch
typeof emittedFile.source === "string" ? emittedFile.source : import_buffer.Buffer.from(emittedFile.source)
) : {
source: () => emittedFile.source,
size: () => emittedFile.source.length
}
);
}
},
getWatchFiles() {
return Array.from(
compilation.fileDependencies ?? compilation.compilationDependencies
);
}
};
}
// src/webpack/loaders/transform.ts
async function transform(source, map) {
const callback = this.async();
let unpluginName;
if (typeof this.query === "string") {
const query = new URLSearchParams(this.query);
unpluginName = query.get("unpluginName");
} else {
unpluginName = this.query.unpluginName;
}
const plugin = this._compiler?.$unpluginContext[unpluginName];
if (!plugin?.transform)
return callback(null, source, map);
const context = {
error: (error) => this.emitError(typeof error === "string" ? new Error(error) : error),
warn: (error) => this.emitWarning(typeof error === "string" ? new Error(error) : error)
};
const res = await plugin.transform.call(Object.assign(this._compilation && createContext(this._compilation), context), source, this.resource);
if (res == null)
callback(null, source, map);
else if (typeof res !== "string")
callback(null, res.code, map == null ? map : res.map || map);
else
callback(null, res, map);
}

View File

@@ -0,0 +1,71 @@
// src/webpack/context.ts
import { resolve } from "path";
import { Buffer } from "buffer";
import sources from "webpack-sources";
import { Parser } from "acorn";
function createContext(compilation) {
return {
parse(code, opts = {}) {
return Parser.parse(code, {
sourceType: "module",
ecmaVersion: "latest",
locations: true,
...opts
});
},
addWatchFile(id) {
(compilation.fileDependencies ?? compilation.compilationDependencies).add(
resolve(process.cwd(), id)
);
},
emitFile(emittedFile) {
const outFileName = emittedFile.fileName || emittedFile.name;
if (emittedFile.source && outFileName) {
compilation.emitAsset(
outFileName,
sources ? new sources.RawSource(
// @ts-expect-error types mismatch
typeof emittedFile.source === "string" ? emittedFile.source : Buffer.from(emittedFile.source)
) : {
source: () => emittedFile.source,
size: () => emittedFile.source.length
}
);
}
},
getWatchFiles() {
return Array.from(
compilation.fileDependencies ?? compilation.compilationDependencies
);
}
};
}
// src/webpack/loaders/transform.ts
async function transform(source, map) {
const callback = this.async();
let unpluginName;
if (typeof this.query === "string") {
const query = new URLSearchParams(this.query);
unpluginName = query.get("unpluginName");
} else {
unpluginName = this.query.unpluginName;
}
const plugin = this._compiler?.$unpluginContext[unpluginName];
if (!plugin?.transform)
return callback(null, source, map);
const context = {
error: (error) => this.emitError(typeof error === "string" ? new Error(error) : error),
warn: (error) => this.emitWarning(typeof error === "string" ? new Error(error) : error)
};
const res = await plugin.transform.call(Object.assign(this._compilation && createContext(this._compilation), context), source, this.resource);
if (res == null)
callback(null, source, map);
else if (typeof res !== "string")
callback(null, res.code, map == null ? map : res.map || map);
else
callback(null, res, map);
}
export {
transform as default
};

View File

@@ -0,0 +1,73 @@
{
"name": "unplugin",
"version": "1.3.2",
"packageManager": "pnpm@8.6.5",
"description": "Unified plugin system for build tools",
"license": "MIT",
"repository": "unjs/unplugin",
"sideEffects": false,
"exports": {
".": {
"types": "./dist/index.d.ts",
"require": "./dist/index.js",
"import": "./dist/index.mjs"
},
"./dist/webpack/loaders/*": "./dist/webpack/loaders/*.js",
"./dist/rspack/loaders/*": "./dist/rspack/loaders/*.js"
},
"main": "dist/index.js",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"files": [
"dist"
],
"dependencies": {
"acorn": "^8.9.0",
"chokidar": "^3.5.3",
"webpack-sources": "^3.2.3",
"webpack-virtual-modules": "^0.5.0"
},
"devDependencies": {
"@ampproject/remapping": "^2.2.1",
"@antfu/eslint-config": "^0.39.6",
"@antfu/ni": "^0.21.4",
"@rspack/cli": "^0.2.4",
"@rspack/core": "^0.2.4",
"@types/fs-extra": "^11.0.1",
"@types/node": "^20.3.3",
"@types/webpack-sources": "^3.2.0",
"bumpp": "^9.1.1",
"conventional-changelog-cli": "^3.0.0",
"esbuild": "^0.18.11",
"eslint": "^8.44.0",
"fast-glob": "^3.3.0",
"fs-extra": "^11.1.1",
"jiti": "^1.18.2",
"lint-staged": "^13.2.3",
"magic-string": "^0.30.0",
"picocolors": "^1.0.0",
"rollup": "^3.26.0",
"simple-git-hooks": "^2.8.1",
"tsup": "^7.1.0",
"typescript": "^5.1.6",
"vite": "^4.3.9",
"vitest": "^0.32.2",
"webpack": "^5.88.1",
"webpack-cli": "4.10.0"
},
"simple-git-hooks": {
"pre-commit": "pnpm lint-staged"
},
"lint-staged": {
"*": "eslint --fix"
},
"scripts": {
"build": "tsup",
"dev": "tsup --watch src",
"lint": "eslint --cache .",
"lint:fix": "nr lint --fix",
"release": "bumpp --all -x 'npx conventional-changelog -p angular -i CHANGELOG.md -s' && npm publish",
"test": "nr lint && nr test:build && vitest run",
"test:build": "jiti scripts/buildFixtures.ts"
}
}