@gytx/unplugin 3.1.0-patch.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021-PRESENT Nuxt Contrib
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # Unplugin
2
+
3
+ [![npm version][npm-version-src]][npm-version-href]
4
+ [![npm downloads][npm-downloads-src]][npm-downloads-href]
5
+ [![License][license-src]][license-href]
6
+
7
+ Unified plugin system for build tools.
8
+
9
+ Currently supports:
10
+
11
+ - [Vite](https://vite.dev/)
12
+ - [Rollup](https://rollupjs.org/)
13
+ - [Webpack](https://webpack.js.org/)
14
+ - [esbuild](https://esbuild.github.io/)
15
+ - [Rspack](https://www.rspack.dev/)
16
+ - [Rolldown](https://rolldown.rs/)
17
+ - [Farm](https://www.farmfe.org/)
18
+ - [Bun](https://bun.com/)
19
+ - And every framework built on top of them.
20
+
21
+ ## Documentations
22
+
23
+ Learn more on the [Documentation](https://unplugin.unjs.io/)
24
+
25
+ ## License
26
+
27
+ [MIT](./LICENSE) License © 2021-PRESENT Nuxt Contrib
28
+
29
+ <!-- Badges -->
30
+
31
+ [npm-version-src]: https://img.shields.io/npm/v/unplugin?style=flat&colorA=18181B&colorB=F0DB4F
32
+ [npm-version-href]: https://npmjs.com/package/unplugin
33
+ [npm-downloads-src]: https://img.shields.io/npm/dm/unplugin?style=flat&colorA=18181B&colorB=F0DB4F
34
+ [npm-downloads-href]: https://npmjs.com/package/unplugin
35
+ [license-src]: https://img.shields.io/github/license/unjs/unplugin.svg?style=flat&colorA=18181B&colorB=F0DB4F
36
+ [license-href]: https://github.com/unjs/unplugin/blob/main/LICENSE
@@ -0,0 +1,64 @@
1
+ import { r as createBuildContextFs, t as parse } from "./parse-C8UGVJ_5.mjs";
2
+ import { createRequire } from "node:module";
3
+ import { resolve } from "node:path";
4
+ import { Buffer } from "node:buffer";
5
+ import process from "node:process";
6
+ //#region src/webpack/context.ts
7
+ function contextOptionsFromCompilation(compilation) {
8
+ return {
9
+ addWatchFile(file) {
10
+ (compilation.fileDependencies ?? compilation.compilationDependencies).add(file);
11
+ },
12
+ getWatchFiles() {
13
+ return Array.from(compilation.fileDependencies ?? compilation.compilationDependencies);
14
+ }
15
+ };
16
+ }
17
+ const require = createRequire(import.meta.url);
18
+ function getSource(fileSource) {
19
+ return new (require("webpack")).sources.RawSource(typeof fileSource === "string" ? fileSource : Buffer.from(fileSource.buffer));
20
+ }
21
+ function createBuildContext(options, compiler, compilation, loaderContext, inputSourceMap) {
22
+ return {
23
+ fs: createBuildContextFs(loaderContext?.fs ?? compiler.inputFileSystem),
24
+ parse,
25
+ addWatchFile(id) {
26
+ options.addWatchFile(resolve(process.cwd(), id));
27
+ },
28
+ emitFile(emittedFile) {
29
+ const outFileName = emittedFile.fileName || emittedFile.name;
30
+ if (emittedFile.source && outFileName) {
31
+ if (!compilation) throw new Error("unplugin/webpack: emitFile outside supported hooks (buildStart, buildEnd, load, transform, watchChange)");
32
+ compilation.emitAsset(outFileName, getSource(emittedFile.source));
33
+ }
34
+ },
35
+ getWatchFiles() {
36
+ return options.getWatchFiles();
37
+ },
38
+ getNativeBuildContext() {
39
+ return {
40
+ framework: "webpack",
41
+ compiler,
42
+ compilation,
43
+ loaderContext,
44
+ inputSourceMap
45
+ };
46
+ }
47
+ };
48
+ }
49
+ function createContext(loader) {
50
+ return {
51
+ error: (error) => loader.emitError(normalizeMessage(error)),
52
+ warn: (message) => loader.emitWarning(normalizeMessage(message))
53
+ };
54
+ }
55
+ function normalizeMessage(error) {
56
+ const err = new Error(typeof error === "string" ? error : error.message);
57
+ if (typeof error === "object") {
58
+ err.stack = error.stack;
59
+ err.cause = error.meta;
60
+ }
61
+ return err;
62
+ }
63
+ //#endregion
64
+ export { normalizeMessage as i, createBuildContext as n, createContext as r, contextOptionsFromCompilation as t };
@@ -0,0 +1,50 @@
1
+ import { r as createBuildContextFs, t as parse } from "./parse-C8UGVJ_5.mjs";
2
+ import { resolve } from "node:path";
3
+ import { Buffer } from "node:buffer";
4
+ //#region src/rspack/context.ts
5
+ function createBuildContext(compiler, compilation, loaderContext, inputSourceMap) {
6
+ return {
7
+ fs: createBuildContextFs(loaderContext?.fs ?? compiler.inputFileSystem),
8
+ getNativeBuildContext() {
9
+ return {
10
+ framework: "rspack",
11
+ compiler,
12
+ compilation,
13
+ loaderContext,
14
+ inputSourceMap
15
+ };
16
+ },
17
+ addWatchFile(file) {
18
+ const resolvedPath = resolve(process.cwd(), file);
19
+ compilation.fileDependencies.add(resolvedPath);
20
+ loaderContext?.addDependency(resolvedPath);
21
+ },
22
+ getWatchFiles() {
23
+ return Array.from(compilation.fileDependencies);
24
+ },
25
+ parse,
26
+ emitFile(emittedFile) {
27
+ const outFileName = emittedFile.fileName || emittedFile.name;
28
+ if (emittedFile.source && outFileName) {
29
+ const { sources } = compilation.compiler.webpack;
30
+ compilation.emitAsset(outFileName, new sources.RawSource(typeof emittedFile.source === "string" ? emittedFile.source : Buffer.from(emittedFile.source)));
31
+ }
32
+ }
33
+ };
34
+ }
35
+ function createContext(loader) {
36
+ return {
37
+ error: (error) => loader.emitError(normalizeMessage(error)),
38
+ warn: (message) => loader.emitWarning(normalizeMessage(message))
39
+ };
40
+ }
41
+ function normalizeMessage(error) {
42
+ const err = new Error(typeof error === "string" ? error : error.message);
43
+ if (typeof error === "object") {
44
+ err.stack = error.stack;
45
+ err.cause = error.meta;
46
+ }
47
+ return err;
48
+ }
49
+ //#endregion
50
+ export { createContext as n, normalizeMessage as r, createBuildContext as t };
@@ -0,0 +1,233 @@
1
+ import { PathLike, Stats } from "node:fs";
2
+ import VirtualModulesPlugin from "webpack-virtual-modules";
3
+ import { CompilationContext, JsPlugin } from "@farmfe/core";
4
+ import { Compilation, Compiler as RspackCompiler, LoaderContext, RspackPluginInstance } from "@rspack/core";
5
+ import { BunPlugin, PluginBuilder } from "bun";
6
+ import { BuildOptions, Loader, Plugin as EsbuildPlugin, PluginBuild } from "esbuild";
7
+ import { Plugin as RolldownPlugin } from "rolldown";
8
+ import { EmittedAsset, Plugin as RollupPlugin, PluginContextMeta, SourceMapInput } from "rollup";
9
+ import { Plugin as UnloaderPlugin } from "unloader";
10
+ import { Plugin as VitePlugin } from "vite";
11
+ import { Compilation as Compilation$1, Compiler as WebpackCompiler, LoaderContext as LoaderContext$1, WebpackPluginInstance } from "webpack";
12
+
13
+ //#region src/types.d.ts
14
+ type Thenable<T> = T | Promise<T>;
15
+ /**
16
+ * Null or whatever
17
+ */
18
+ type Nullable<T> = T | null | undefined;
19
+ /**
20
+ * Array, or not yet
21
+ */
22
+ type Arrayable<T> = T | Array<T>;
23
+ interface SourceMapCompact {
24
+ file?: string | undefined;
25
+ mappings: string;
26
+ names: string[];
27
+ sourceRoot?: string | undefined;
28
+ sources: string[];
29
+ sourcesContent?: (string | null)[] | undefined;
30
+ version: number;
31
+ }
32
+ type TransformResult = string | {
33
+ code: string;
34
+ map?: SourceMapInput | SourceMapCompact | null | undefined;
35
+ } | null | undefined | void;
36
+ interface ExternalIdResult {
37
+ id: string;
38
+ external?: boolean | undefined;
39
+ }
40
+ type NativeBuildContext = {
41
+ framework: "webpack";
42
+ compiler: WebpackCompiler;
43
+ compilation?: Compilation$1 | undefined;
44
+ loaderContext?: LoaderContext$1<{
45
+ unpluginName: string;
46
+ }> | undefined;
47
+ inputSourceMap?: any;
48
+ } | {
49
+ framework: "esbuild";
50
+ build: PluginBuild;
51
+ } | {
52
+ framework: "rspack";
53
+ compiler: RspackCompiler;
54
+ compilation: Compilation;
55
+ loaderContext?: LoaderContext | undefined;
56
+ inputSourceMap?: any;
57
+ } | {
58
+ framework: "farm";
59
+ context: CompilationContext;
60
+ } | {
61
+ framework: "bun";
62
+ build: PluginBuilder;
63
+ };
64
+ interface UnpluginBuildContext {
65
+ fs: UnpluginContextFs;
66
+ addWatchFile: (id: string) => void;
67
+ emitFile: (emittedFile: EmittedAsset) => void;
68
+ getWatchFiles: () => string[];
69
+ parse: (input: string, options?: any) => any;
70
+ getNativeBuildContext?: (() => NativeBuildContext) | undefined;
71
+ }
72
+ interface UnpluginContextFs {
73
+ readFile: (path: PathLike, options?: any) => Promise<string | Uint8Array>;
74
+ stat: (path: PathLike, options?: any) => Promise<Stats>;
75
+ lstat: (path: PathLike, options?: any) => Promise<Stats>;
76
+ }
77
+ type StringOrRegExp = string | RegExp;
78
+ type FilterPattern = Arrayable<StringOrRegExp>;
79
+ type StringFilter = FilterPattern | {
80
+ include?: FilterPattern | undefined;
81
+ exclude?: FilterPattern | undefined;
82
+ };
83
+ interface HookFilter {
84
+ id?: StringFilter | undefined;
85
+ code?: StringFilter | undefined;
86
+ }
87
+ interface ObjectHook<T extends HookFnMap[keyof HookFnMap], F extends keyof HookFilter> {
88
+ filter?: Pick<HookFilter, F> | undefined;
89
+ handler: T;
90
+ }
91
+ type Hook<T extends HookFnMap[keyof HookFnMap], F extends keyof HookFilter> = T | ObjectHook<T, F>;
92
+ interface HookFnMap {
93
+ buildStart: (this: UnpluginBuildContext) => Thenable<void>;
94
+ buildEnd: (this: UnpluginBuildContext) => Thenable<void>;
95
+ transform: (this: UnpluginBuildContext & UnpluginContext, code: string, id: string) => Thenable<TransformResult>;
96
+ load: (this: UnpluginBuildContext & UnpluginContext, id: string) => Thenable<TransformResult>;
97
+ resolveId: (this: UnpluginBuildContext & UnpluginContext, id: string, importer: string | undefined, options: {
98
+ isEntry: boolean;
99
+ }) => Thenable<string | ExternalIdResult | null | undefined>;
100
+ writeBundle: (this: void) => Thenable<void>;
101
+ }
102
+ interface UnpluginOptions {
103
+ name: string;
104
+ enforce?: "post" | "pre" | undefined;
105
+ buildStart?: HookFnMap["buildStart"] | undefined;
106
+ buildEnd?: HookFnMap["buildEnd"] | undefined;
107
+ transform?: Hook<HookFnMap["transform"], "code" | "id"> | undefined;
108
+ load?: Hook<HookFnMap["load"], "id"> | undefined;
109
+ resolveId?: Hook<HookFnMap["resolveId"], "id"> | undefined;
110
+ writeBundle?: HookFnMap["writeBundle"] | undefined;
111
+ watchChange?: ((this: UnpluginBuildContext, id: string, change: {
112
+ event: "create" | "update" | "delete";
113
+ }) => void) | undefined;
114
+ /**
115
+ * Custom predicate function to filter modules to be loaded.
116
+ * When omitted, all modules will be included (might have potential perf impact on Webpack).
117
+ *
118
+ * @deprecated Use `load.filter` instead.
119
+ */
120
+ loadInclude?: ((id: string) => boolean | null | undefined) | undefined;
121
+ /**
122
+ * Custom predicate function to filter modules to be transformed.
123
+ * When omitted, all modules will be included (might have potential perf impact on Webpack).
124
+ *
125
+ * @deprecated Use `transform.filter` instead.
126
+ */
127
+ transformInclude?: ((id: string) => boolean | null | undefined) | undefined;
128
+ rollup?: Partial<RollupPlugin> | undefined;
129
+ webpack?: ((compiler: WebpackCompiler) => void) | undefined;
130
+ rspack?: ((compiler: RspackCompiler) => void) | undefined;
131
+ vite?: Partial<VitePlugin> | undefined;
132
+ unloader?: Partial<UnloaderPlugin> | undefined;
133
+ rolldown?: Partial<RolldownPlugin> | undefined;
134
+ esbuild?: {
135
+ onResolveFilter?: RegExp | undefined;
136
+ onLoadFilter?: RegExp | undefined;
137
+ loader?: Loader | ((code: string, id: string) => Loader) | undefined;
138
+ setup?: ((build: PluginBuild) => void | Promise<void>) | undefined;
139
+ config?: ((options: BuildOptions) => void) | undefined;
140
+ } | undefined;
141
+ farm?: Partial<JsPlugin> | undefined;
142
+ bun?: Partial<BunPlugin> | undefined;
143
+ }
144
+ interface ResolvedUnpluginOptions extends UnpluginOptions {
145
+ __vfs?: VirtualModulesPlugin | undefined;
146
+ __vfsModules?: Map<string, Promise<unknown>> | Set<string> | undefined;
147
+ __virtualModulePrefix: string;
148
+ }
149
+ type UnpluginFactory<UserOptions, Nested extends boolean = boolean> = (options: UserOptions, meta: UnpluginContextMeta) => Nested extends true ? Array<UnpluginOptions> : UnpluginOptions;
150
+ type UnpluginFactoryOutput<UserOptions, Return> = undefined extends UserOptions ? (options?: UserOptions | undefined) => Return : (options: UserOptions) => Return;
151
+ interface UnpluginInstance<UserOptions, Nested extends boolean = boolean> {
152
+ rollup: UnpluginFactoryOutput<UserOptions, Nested extends true ? Array<RollupPlugin> : RollupPlugin>;
153
+ vite: UnpluginFactoryOutput<UserOptions, Nested extends true ? Array<VitePlugin> : VitePlugin>;
154
+ rolldown: UnpluginFactoryOutput<UserOptions, Nested extends true ? Array<RolldownPlugin> : RolldownPlugin>;
155
+ webpack: UnpluginFactoryOutput<UserOptions, WebpackPluginInstance>;
156
+ rspack: UnpluginFactoryOutput<UserOptions, RspackPluginInstance>;
157
+ esbuild: UnpluginFactoryOutput<UserOptions, EsbuildPlugin>;
158
+ unloader: UnpluginFactoryOutput<UserOptions, Nested extends true ? Array<UnloaderPlugin> : UnloaderPlugin>;
159
+ farm: UnpluginFactoryOutput<UserOptions, JsPlugin>;
160
+ bun: UnpluginFactoryOutput<UserOptions, BunPlugin>;
161
+ raw: UnpluginFactory<UserOptions, Nested>;
162
+ }
163
+ type SupportedFramework = "rollup" | "vite" | "rolldown" | "farm" | "unloader" | "webpack" | "rspack" | "esbuild" | "bun";
164
+ type UnpluginContextMeta = Partial<PluginContextMeta> & {
165
+ /**
166
+ * Version information for frameworks.
167
+ * Access the current framework version via: `meta.versions[meta.framework]`
168
+ *
169
+ * For Vite, includes both Vite's version and the underlying bundler (Rollup/Rolldown).
170
+ * For Rollup-compatible frameworks (vite, rollup, rolldown, unloader),
171
+ * versions are only available after the `buildStart` hook.
172
+ *
173
+ * The `unplugin` version is always available for all frameworks.
174
+ */
175
+ versions: Partial<Record<SupportedFramework | "unplugin", string>>;
176
+ } & ({
177
+ framework: "rollup" | "vite" | "rolldown" | "farm" | "unloader";
178
+ } | {
179
+ framework: "webpack";
180
+ webpack: {
181
+ compiler: WebpackCompiler;
182
+ };
183
+ } | {
184
+ framework: "esbuild"; /** Set the host plugin name of esbuild when returning multiple plugins */
185
+ esbuildHostName?: string | undefined;
186
+ } | {
187
+ framework: "bun"; /** Set the host plugin name of bun when returning multiple plugins */
188
+ bunHostName?: string | undefined;
189
+ } | {
190
+ framework: "rspack";
191
+ rspack: {
192
+ compiler: RspackCompiler;
193
+ };
194
+ });
195
+ interface UnpluginMessage {
196
+ name?: string | undefined;
197
+ id?: string | undefined;
198
+ message: string;
199
+ stack?: string | undefined;
200
+ code?: string | undefined;
201
+ plugin?: string | undefined;
202
+ pluginCode?: unknown | undefined;
203
+ loc?: {
204
+ column: number;
205
+ file?: string | undefined;
206
+ line: number;
207
+ } | undefined;
208
+ meta?: any;
209
+ }
210
+ interface UnpluginContext {
211
+ error: (message: string | UnpluginMessage) => void;
212
+ warn: (message: string | UnpluginMessage) => void;
213
+ }
214
+ //#endregion
215
+ //#region src/define.d.ts
216
+ declare function createUnplugin<UserOptions, Nested extends boolean = boolean>(factory: UnpluginFactory<UserOptions, Nested>): UnpluginInstance<UserOptions, Nested>;
217
+ declare function createEsbuildPlugin<UserOptions, Nested extends boolean = boolean>(factory: UnpluginFactory<UserOptions, Nested>): UnpluginInstance<UserOptions>["esbuild"];
218
+ declare function createRollupPlugin<UserOptions, Nested extends boolean = boolean>(factory: UnpluginFactory<UserOptions, Nested>): UnpluginInstance<UserOptions>["rollup"];
219
+ declare function createVitePlugin<UserOptions, Nested extends boolean = boolean>(factory: UnpluginFactory<UserOptions, Nested>): UnpluginInstance<UserOptions>["vite"];
220
+ declare function createRolldownPlugin<UserOptions, Nested extends boolean = boolean>(factory: UnpluginFactory<UserOptions, Nested>): UnpluginInstance<UserOptions>["rolldown"];
221
+ declare function createWebpackPlugin<UserOptions, Nested extends boolean = boolean>(factory: UnpluginFactory<UserOptions, Nested>): UnpluginInstance<UserOptions>["webpack"];
222
+ declare function createRspackPlugin<UserOptions, Nested extends boolean = boolean>(factory: UnpluginFactory<UserOptions, Nested>): UnpluginInstance<UserOptions>["rspack"];
223
+ declare function createFarmPlugin<UserOptions, Nested extends boolean = boolean>(factory: UnpluginFactory<UserOptions, Nested>): UnpluginInstance<UserOptions>["farm"];
224
+ declare function createUnloaderPlugin<UserOptions, Nested extends boolean = boolean>(factory: UnpluginFactory<UserOptions, Nested>): UnpluginInstance<UserOptions>["unloader"];
225
+ declare function createBunPlugin<UserOptions, Nested extends boolean = boolean>(factory: UnpluginFactory<UserOptions, Nested>): UnpluginInstance<UserOptions>["bun"];
226
+ //#endregion
227
+ //#region src/utils/parse.d.ts
228
+ declare function setParseImpl(customParse: (code: string, opts?: any) => any): void;
229
+ //#endregion
230
+ //#region src/index.d.ts
231
+ declare const version: string;
232
+ //#endregion
233
+ export { Arrayable, type BunPlugin, type EsbuildPlugin, ExternalIdResult, FilterPattern, Hook, HookFilter, HookFnMap, NativeBuildContext, Nullable, ObjectHook, ResolvedUnpluginOptions, type RolldownPlugin, type RollupPlugin, type RspackCompiler, type RspackPluginInstance, SourceMapCompact, StringFilter, StringOrRegExp, SupportedFramework, Thenable, TransformResult, type UnloaderPlugin, UnpluginBuildContext, UnpluginContext, UnpluginContextFs, UnpluginContextMeta, UnpluginFactory, UnpluginFactoryOutput, UnpluginInstance, UnpluginMessage, UnpluginOptions, type VitePlugin, type WebpackCompiler, type WebpackPluginInstance, createBunPlugin, createEsbuildPlugin, createFarmPlugin, createRolldownPlugin, createRollupPlugin, createRspackPlugin, createUnloaderPlugin, createUnplugin, createVitePlugin, createWebpackPlugin, setParseImpl, version };