| import { t as parse } from "./parse-DN2jPtpt.mjs"; | ||
| import { resolve } from "node:path"; | ||
| import { Buffer } from "node:buffer"; | ||
| //#region src/rspack/context.ts | ||
| function createBuildContext(compiler, compilation, loaderContext, inputSourceMap) { | ||
| return { | ||
| getNativeBuildContext() { | ||
| return { | ||
| framework: "rspack", | ||
| compiler, | ||
| compilation, | ||
| loaderContext, | ||
| inputSourceMap | ||
| }; | ||
| }, | ||
| addWatchFile(file) { | ||
| const resolvedPath = resolve(process.cwd(), file); | ||
| compilation.fileDependencies.add(resolvedPath); | ||
| loaderContext?.addDependency(resolvedPath); | ||
| }, | ||
| getWatchFiles() { | ||
| return Array.from(compilation.fileDependencies); | ||
| }, | ||
| parse, | ||
| emitFile(emittedFile) { | ||
| const outFileName = emittedFile.fileName || emittedFile.name; | ||
| if (emittedFile.source && outFileName) { | ||
| const { sources } = compilation.compiler.webpack; | ||
| compilation.emitAsset(outFileName, new sources.RawSource(typeof emittedFile.source === "string" ? emittedFile.source : Buffer.from(emittedFile.source))); | ||
| } | ||
| } | ||
| }; | ||
| } | ||
| function createContext(loader) { | ||
| return { | ||
| error: (error) => loader.emitError(normalizeMessage(error)), | ||
| warn: (message) => loader.emitWarning(normalizeMessage(message)) | ||
| }; | ||
| } | ||
| function normalizeMessage(error) { | ||
| const err = new Error(typeof error === "string" ? error : error.message); | ||
| if (typeof error === "object") { | ||
| err.stack = error.stack; | ||
| err.cause = error.meta; | ||
| } | ||
| return err; | ||
| } | ||
| //#endregion | ||
| export { createContext as n, normalizeMessage as r, createBuildContext as t }; |
| import { t as parse } from "./parse-DN2jPtpt.mjs"; | ||
| import { createRequire } from "node:module"; | ||
| import { resolve } from "node:path"; | ||
| import { Buffer } from "node:buffer"; | ||
| import process from "node:process"; | ||
| //#region src/webpack/context.ts | ||
| function contextOptionsFromCompilation(compilation) { | ||
| return { | ||
| addWatchFile(file) { | ||
| (compilation.fileDependencies ?? compilation.compilationDependencies).add(file); | ||
| }, | ||
| getWatchFiles() { | ||
| return Array.from(compilation.fileDependencies ?? compilation.compilationDependencies); | ||
| } | ||
| }; | ||
| } | ||
| const require = createRequire(import.meta.url); | ||
| function getSource(fileSource) { | ||
| return new (require("webpack")).sources.RawSource(typeof fileSource === "string" ? fileSource : Buffer.from(fileSource.buffer)); | ||
| } | ||
| function createBuildContext(options, compiler, compilation, loaderContext, inputSourceMap) { | ||
| return { | ||
| parse, | ||
| addWatchFile(id) { | ||
| options.addWatchFile(resolve(process.cwd(), id)); | ||
| }, | ||
| emitFile(emittedFile) { | ||
| const outFileName = emittedFile.fileName || emittedFile.name; | ||
| if (emittedFile.source && outFileName) { | ||
| if (!compilation) throw new Error("unplugin/webpack: emitFile outside supported hooks (buildStart, buildEnd, load, transform, watchChange)"); | ||
| compilation.emitAsset(outFileName, getSource(emittedFile.source)); | ||
| } | ||
| }, | ||
| getWatchFiles() { | ||
| return options.getWatchFiles(); | ||
| }, | ||
| getNativeBuildContext() { | ||
| return { | ||
| framework: "webpack", | ||
| compiler, | ||
| compilation, | ||
| loaderContext, | ||
| inputSourceMap | ||
| }; | ||
| } | ||
| }; | ||
| } | ||
| function createContext(loader) { | ||
| return { | ||
| error: (error) => loader.emitError(normalizeMessage(error)), | ||
| warn: (message) => loader.emitWarning(normalizeMessage(message)) | ||
| }; | ||
| } | ||
| function normalizeMessage(error) { | ||
| const err = new Error(typeof error === "string" ? error : error.message); | ||
| if (typeof error === "object") { | ||
| err.stack = error.stack; | ||
| err.cause = error.meta; | ||
| } | ||
| return err; | ||
| } | ||
| //#endregion | ||
| export { normalizeMessage as i, createBuildContext as n, createContext as r, contextOptionsFromCompilation as t }; |
| import { resolve } from "node:path"; | ||
| import picomatch from "picomatch"; | ||
| //#region src/utils/general.ts | ||
| function toArray(array) { | ||
| array = array || []; | ||
| if (Array.isArray(array)) return array; | ||
| return [array]; | ||
| } | ||
| //#endregion | ||
| //#region src/utils/filter.ts | ||
| const BACKSLASH_REGEX = /\\/g; | ||
| function normalize$1(path) { | ||
| return path.replace(BACKSLASH_REGEX, "/"); | ||
| } | ||
| const ABSOLUTE_PATH_REGEX = /^(?:\/|(?:[A-Z]:)?[/\\|])/i; | ||
| function isAbsolute$1(path) { | ||
| return ABSOLUTE_PATH_REGEX.test(path); | ||
| } | ||
| function getMatcherString(glob, cwd) { | ||
| if (glob.startsWith("**") || isAbsolute$1(glob)) return normalize$1(glob); | ||
| return normalize$1(resolve(cwd, glob)); | ||
| } | ||
| function patternToIdFilter(pattern) { | ||
| if (pattern instanceof RegExp) return (id) => { | ||
| const normalizedId = normalize$1(id); | ||
| const result = pattern.test(normalizedId); | ||
| pattern.lastIndex = 0; | ||
| return result; | ||
| }; | ||
| const matcher = picomatch(getMatcherString(pattern, process.cwd()), { dot: true }); | ||
| return (id) => { | ||
| return matcher(normalize$1(id)); | ||
| }; | ||
| } | ||
| function patternToCodeFilter(pattern) { | ||
| if (pattern instanceof RegExp) return (code) => { | ||
| const result = pattern.test(code); | ||
| pattern.lastIndex = 0; | ||
| return result; | ||
| }; | ||
| return (code) => code.includes(pattern); | ||
| } | ||
| function createFilter(exclude, include) { | ||
| if (!exclude && !include) return; | ||
| return (input) => { | ||
| if (exclude?.some((filter) => filter(input))) return false; | ||
| if (include?.some((filter) => filter(input))) return true; | ||
| return !(include && include.length > 0); | ||
| }; | ||
| } | ||
| function normalizeFilter(filter) { | ||
| if (typeof filter === "string" || filter instanceof RegExp) return { include: [filter] }; | ||
| if (Array.isArray(filter)) return { include: filter }; | ||
| return { | ||
| exclude: filter.exclude ? toArray(filter.exclude) : void 0, | ||
| include: filter.include ? toArray(filter.include) : void 0 | ||
| }; | ||
| } | ||
| function createIdFilter(filter) { | ||
| if (!filter) return; | ||
| const { exclude, include } = normalizeFilter(filter); | ||
| const excludeFilter = exclude?.map(patternToIdFilter); | ||
| const includeFilter = include?.map(patternToIdFilter); | ||
| return createFilter(excludeFilter, includeFilter); | ||
| } | ||
| function createCodeFilter(filter) { | ||
| if (!filter) return; | ||
| const { exclude, include } = normalizeFilter(filter); | ||
| const excludeFilter = exclude?.map(patternToCodeFilter); | ||
| const includeFilter = include?.map(patternToCodeFilter); | ||
| return createFilter(excludeFilter, includeFilter); | ||
| } | ||
| function createFilterForId(filter) { | ||
| const filterFunction = createIdFilter(filter); | ||
| return filterFunction ? (id) => !!filterFunction(id) : void 0; | ||
| } | ||
| function createFilterForTransform(idFilter, codeFilter) { | ||
| if (!idFilter && !codeFilter) return; | ||
| const idFilterFunction = createIdFilter(idFilter); | ||
| const codeFilterFunction = createCodeFilter(codeFilter); | ||
| return (id, code) => { | ||
| let fallback = true; | ||
| if (idFilterFunction) fallback &&= idFilterFunction(id); | ||
| if (!fallback) return false; | ||
| if (codeFilterFunction) fallback &&= codeFilterFunction(code); | ||
| return fallback; | ||
| }; | ||
| } | ||
| function normalizeObjectHook(name, hook) { | ||
| let handler; | ||
| let filter; | ||
| if (typeof hook === "function") handler = hook; | ||
| else { | ||
| handler = hook.handler; | ||
| const hookFilter = hook.filter; | ||
| if (name === "resolveId" || name === "load") filter = createFilterForId(hookFilter?.id); | ||
| else filter = createFilterForTransform(hookFilter?.id, hookFilter?.code); | ||
| } | ||
| return { | ||
| handler, | ||
| filter: filter || (() => true) | ||
| }; | ||
| } | ||
| //#endregion | ||
| //#region src/utils/parse.ts | ||
| let parseImpl; | ||
| function parse(code, opts = {}) { | ||
| if (!parseImpl) throw new Error("Parse implementation is not set. Please call setParseImpl first."); | ||
| return parseImpl(code, opts); | ||
| } | ||
| function setParseImpl(customParse) { | ||
| parseImpl = customParse; | ||
| } | ||
| //#endregion | ||
| export { toArray as i, setParseImpl as n, normalizeObjectHook as r, parse as t }; |
| import { basename, dirname, resolve } from "node:path"; | ||
| import fs from "node:fs"; | ||
| //#region src/rspack/utils.ts | ||
| function encodeVirtualModuleId(id, plugin) { | ||
| return resolve(plugin.__virtualModulePrefix, encodeURIComponent(id)); | ||
| } | ||
| function decodeVirtualModuleId(encoded, _plugin) { | ||
| return decodeURIComponent(basename(encoded)); | ||
| } | ||
| function isVirtualModuleId(encoded, plugin) { | ||
| return dirname(encoded) === plugin.__virtualModulePrefix; | ||
| } | ||
| var FakeVirtualModulesPlugin = class FakeVirtualModulesPlugin { | ||
| name = "FakeVirtualModulesPlugin"; | ||
| static counters = /* @__PURE__ */ new Map(); | ||
| static initCleanup = false; | ||
| constructor(plugin) { | ||
| this.plugin = plugin; | ||
| if (!FakeVirtualModulesPlugin.initCleanup) { | ||
| FakeVirtualModulesPlugin.initCleanup = true; | ||
| process.once("exit", () => { | ||
| FakeVirtualModulesPlugin.counters.forEach((_, dir) => { | ||
| fs.rmSync(dir, { | ||
| recursive: true, | ||
| force: true | ||
| }); | ||
| }); | ||
| }); | ||
| } | ||
| } | ||
| apply(compiler) { | ||
| const dir = this.plugin.__virtualModulePrefix; | ||
| if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true }); | ||
| const counter = FakeVirtualModulesPlugin.counters.get(dir) ?? 0; | ||
| FakeVirtualModulesPlugin.counters.set(dir, counter + 1); | ||
| compiler.hooks.shutdown.tap(this.name, () => { | ||
| const counter = (FakeVirtualModulesPlugin.counters.get(dir) ?? 1) - 1; | ||
| if (counter === 0) { | ||
| FakeVirtualModulesPlugin.counters.delete(dir); | ||
| fs.rmSync(dir, { | ||
| recursive: true, | ||
| force: true | ||
| }); | ||
| } else FakeVirtualModulesPlugin.counters.set(dir, counter); | ||
| }); | ||
| } | ||
| async writeModule(file) { | ||
| return fs.promises.writeFile(file, ""); | ||
| } | ||
| }; | ||
| //#endregion | ||
| export { isVirtualModuleId as i, decodeVirtualModuleId as n, encodeVirtualModuleId as r, FakeVirtualModulesPlugin as t }; |
| import { r as normalizeObjectHook } from "./parse-DN2jPtpt.mjs"; | ||
| import { isAbsolute, normalize } from "node:path"; | ||
| //#region src/utils/webpack-like.ts | ||
| function transformUse(data, plugin, transformLoader) { | ||
| if (data.resource == null) return []; | ||
| const id = normalizeAbsolutePath(data.resource + (data.resourceQuery || "")); | ||
| if (plugin.transformInclude && !plugin.transformInclude(id)) return []; | ||
| const { filter } = normalizeObjectHook("load", plugin.transform); | ||
| if (!filter(id)) return []; | ||
| return [{ | ||
| loader: transformLoader, | ||
| options: { plugin }, | ||
| ident: plugin.name | ||
| }]; | ||
| } | ||
| /** | ||
| * Normalizes a given path when it's absolute. Normalizing means returning a new path by converting | ||
| * the input path to the native os format. This is useful in cases where we want to normalize | ||
| * the `id` argument of a hook. Any absolute ids should be in the default format | ||
| * of the operating system. Any relative imports or node_module imports should remain | ||
| * untouched. | ||
| * | ||
| * @param path - Path to normalize. | ||
| * @returns a new normalized path. | ||
| */ | ||
| function normalizeAbsolutePath(path) { | ||
| if (isAbsolute(path)) return normalize(path); | ||
| else return path; | ||
| } | ||
| //#endregion | ||
| export { transformUse as n, normalizeAbsolutePath as t }; |
+2
-4
@@ -164,8 +164,6 @@ import VirtualModulesPlugin from "webpack-virtual-modules"; | ||
| } | { | ||
| framework: "esbuild"; | ||
| /** Set the host plugin name of esbuild when returning multiple plugins */ | ||
| framework: "esbuild"; /** Set the host plugin name of esbuild when returning multiple plugins */ | ||
| esbuildHostName?: string | undefined; | ||
| } | { | ||
| framework: "bun"; | ||
| /** Set the host plugin name of bun when returning multiple plugins */ | ||
| framework: "bun"; /** Set the host plugin name of bun when returning multiple plugins */ | ||
| bunHostName?: string | undefined; | ||
@@ -172,0 +170,0 @@ } | { |
+31
-26
@@ -1,14 +0,18 @@ | ||
| import { i as toArray, n as setParseImpl, r as normalizeObjectHook, t as parse } from "./parse-CRORloGP.mjs"; | ||
| import { n as transformUse, t as normalizeAbsolutePath } from "./webpack-like-BU9ULG6P.mjs"; | ||
| import { r as normalizeMessage$1, t as createBuildContext$1 } from "./context-CehLHpzV.mjs"; | ||
| import { i as isVirtualModuleId, n as decodeVirtualModuleId, r as encodeVirtualModuleId, t as FakeVirtualModulesPlugin } from "./utils-CuyC8gTr.mjs"; | ||
| import { i as normalizeMessage, n as createBuildContext, t as contextOptionsFromCompilation } from "./context-CY6F6zw6.mjs"; | ||
| import { i as toArray, n as setParseImpl, r as normalizeObjectHook, t as parse } from "./parse-DN2jPtpt.mjs"; | ||
| import { n as transformUse, t as normalizeAbsolutePath } from "./webpack-like-Djrmy9eu.mjs"; | ||
| import { r as normalizeMessage$1, t as createBuildContext$2 } from "./context-CKhLGGrj.mjs"; | ||
| import { i as isVirtualModuleId, n as decodeVirtualModuleId, r as encodeVirtualModuleId, t as FakeVirtualModulesPlugin } from "./utils-BMHLEWml.mjs"; | ||
| import { i as normalizeMessage$2, n as createBuildContext$3, t as contextOptionsFromCompilation } from "./context-MD-xQmYI.mjs"; | ||
| import { createRequire } from "node:module"; | ||
| import path, { extname, isAbsolute, resolve } from "node:path"; | ||
| import fs from "node:fs"; | ||
| import { Buffer } from "node:buffer"; | ||
| import { Buffer as Buffer$1 } from "node:buffer"; | ||
| import remapping from "@jridgewell/remapping"; | ||
| import * as querystring from "node:querystring"; | ||
| import process$1 from "node:process"; | ||
| import VirtualModulesPlugin from "webpack-virtual-modules"; | ||
| //#region rolldown:runtime | ||
| var __require = /* @__PURE__ */ createRequire(import.meta.url); | ||
| //#endregion | ||
| //#region src/bun/utils.ts | ||
@@ -35,3 +39,3 @@ const ExtToLoader$1 = { | ||
| } | ||
| function createBuildContext$3(build) { | ||
| function createBuildContext$1(build) { | ||
| const watchFiles = []; | ||
@@ -93,3 +97,3 @@ return { | ||
| async setup(build) { | ||
| const context = createBuildContext$3(build); | ||
| const context = createBuildContext$1(build); | ||
| if (plugins.some((plugin) => plugin.buildStart)) build.onStart(async () => { | ||
@@ -253,3 +257,3 @@ for (const plugin of plugins) if (plugin.buildStart) await plugin.buildStart.call(context); | ||
| value: function toUrl() { | ||
| return `data:application/json;charset=utf-8;base64,${Buffer.from(this.toString()).toString("base64")}`; | ||
| return `data:application/json;charset=utf-8;base64,${Buffer$1.from(this.toString()).toString("base64")}`; | ||
| } | ||
@@ -278,3 +282,3 @@ }); | ||
| } | ||
| function createBuildContext$2(build) { | ||
| function createBuildContext(build) { | ||
| const watchFiles = []; | ||
@@ -312,6 +316,6 @@ const { initialOptions } = build; | ||
| error(message) { | ||
| errors.push(normalizeMessage$2(message)); | ||
| errors.push(normalizeMessage(message)); | ||
| }, | ||
| warn(message) { | ||
| warnings.push(normalizeMessage$2(message)); | ||
| warnings.push(normalizeMessage(message)); | ||
| } | ||
@@ -331,3 +335,3 @@ }; | ||
| } | ||
| function normalizeMessage$2(message) { | ||
| function normalizeMessage(message) { | ||
| if (typeof message === "string") message = { message }; | ||
@@ -418,3 +422,3 @@ return { | ||
| return (build, rawBuild) => { | ||
| const context = createBuildContext$2(rawBuild); | ||
| const context = createBuildContext(rawBuild); | ||
| const { onStart, onEnd, onResolve, onLoad, onTransform, initialOptions } = build; | ||
@@ -527,3 +531,3 @@ const onResolveFilter = plugin.esbuild?.onResolveFilter ?? /.*/; | ||
| name: outFileName, | ||
| content: [...Buffer.from(emittedFile.source)], | ||
| content: [...Buffer$1.from(emittedFile.source)], | ||
| resourceType: extname(outFileName) | ||
@@ -605,3 +609,3 @@ }); | ||
| let pos = 0; | ||
| for (let i$1 = 0; i$1 < firstIndex; i$1++) result[pos++] = str[i$1]; | ||
| for (let i = 0; i < firstIndex; i++) result[pos++] = str[i]; | ||
| let i = firstIndex; | ||
@@ -896,5 +900,5 @@ while (i < len) if (str[i] === "\\" && str[i + 1] === "0") { | ||
| if (plugin.resolveId) { | ||
| const createPlugin = (plugin$1) => { | ||
| const createPlugin = (plugin) => { | ||
| if (compiler.rspack.experiments.VirtualModulesPlugin) return new compiler.rspack.experiments.VirtualModulesPlugin(); | ||
| return new FakeVirtualModulesPlugin(plugin$1); | ||
| return new FakeVirtualModulesPlugin(plugin); | ||
| }; | ||
@@ -913,3 +917,3 @@ const vfs = createPlugin(plugin); | ||
| if (importer?.startsWith(plugin.__virtualModulePrefix)) importer = decodeURIComponent(importer.slice(plugin.__virtualModulePrefix.length)); | ||
| const context = createBuildContext$1(compiler, compilation); | ||
| const context = createBuildContext$2(compiler, compilation); | ||
| let error; | ||
@@ -978,3 +982,3 @@ const pluginContext = { | ||
| if (plugin.watchChange || plugin.buildStart) compiler.hooks.make.tapPromise(plugin.name, async (compilation) => { | ||
| const context = createBuildContext$1(compiler, compilation); | ||
| const context = createBuildContext$2(compiler, compilation); | ||
| if (plugin.watchChange && (compiler.modifiedFiles || compiler.removedFiles)) { | ||
@@ -989,3 +993,3 @@ const promises = []; | ||
| if (plugin.buildEnd) compiler.hooks.emit.tapPromise(plugin.name, async (compilation) => { | ||
| await plugin.buildEnd.call(createBuildContext$1(compiler, compilation)); | ||
| await plugin.buildEnd.call(createBuildContext$2(compiler, compilation)); | ||
| }); | ||
@@ -1028,2 +1032,3 @@ if (plugin.writeBundle) compiler.hooks.afterEmit.tapPromise(plugin.name, async () => { | ||
| return (userOptions) => { | ||
| const VirtualModulesPlugin = __require("webpack-virtual-modules"); | ||
| return { apply(compiler) { | ||
@@ -1062,3 +1067,3 @@ const VIRTUAL_MODULE_PREFIX = resolve(compiler.options.context ?? process$1.cwd(), "_virtual_"); | ||
| const fileDependencies = /* @__PURE__ */ new Set(); | ||
| const context = createBuildContext({ | ||
| const context = createBuildContext$3({ | ||
| addWatchFile(file) { | ||
@@ -1075,3 +1080,3 @@ fileDependencies.add(file); | ||
| error(msg) { | ||
| if (error == null) error = normalizeMessage(msg); | ||
| if (error == null) error = normalizeMessage$2(msg); | ||
| else console.error(`unplugin/webpack: multiple errors returned from resolveId hook: ${msg}`); | ||
@@ -1129,3 +1134,3 @@ }, | ||
| if (plugin.watchChange || plugin.buildStart) compiler.hooks.make.tapPromise(plugin.name, async (compilation) => { | ||
| const context = createBuildContext(contextOptionsFromCompilation(compilation), compiler, compilation); | ||
| const context = createBuildContext$3(contextOptionsFromCompilation(compilation), compiler, compilation); | ||
| if (plugin.watchChange && (compiler.modifiedFiles || compiler.removedFiles)) { | ||
@@ -1140,3 +1145,3 @@ const promises = []; | ||
| if (plugin.buildEnd) compiler.hooks.emit.tapPromise(plugin.name, async (compilation) => { | ||
| await plugin.buildEnd.call(createBuildContext(contextOptionsFromCompilation(compilation), compiler, compilation)); | ||
| await plugin.buildEnd.call(createBuildContext$3(contextOptionsFromCompilation(compilation), compiler, compilation)); | ||
| }); | ||
@@ -1143,0 +1148,0 @@ if (plugin.writeBundle) compiler.hooks.afterEmit.tapPromise(plugin.name, async () => { |
@@ -1,5 +0,5 @@ | ||
| import { r as normalizeObjectHook } from "../../parse-CRORloGP.mjs"; | ||
| import { t as normalizeAbsolutePath } from "../../webpack-like-BU9ULG6P.mjs"; | ||
| import { n as createContext, t as createBuildContext } from "../../context-CehLHpzV.mjs"; | ||
| import { i as isVirtualModuleId, n as decodeVirtualModuleId } from "../../utils-CuyC8gTr.mjs"; | ||
| import { r as normalizeObjectHook } from "../../parse-DN2jPtpt.mjs"; | ||
| import { t as normalizeAbsolutePath } from "../../webpack-like-Djrmy9eu.mjs"; | ||
| import { n as createContext, t as createBuildContext } from "../../context-CKhLGGrj.mjs"; | ||
| import { i as isVirtualModuleId, n as decodeVirtualModuleId } from "../../utils-BMHLEWml.mjs"; | ||
@@ -6,0 +6,0 @@ //#region src/rspack/loaders/load.ts |
@@ -1,3 +0,3 @@ | ||
| import { r as normalizeObjectHook } from "../../parse-CRORloGP.mjs"; | ||
| import { n as createContext, t as createBuildContext } from "../../context-CehLHpzV.mjs"; | ||
| import { r as normalizeObjectHook } from "../../parse-DN2jPtpt.mjs"; | ||
| import { n as createContext, t as createBuildContext } from "../../context-CKhLGGrj.mjs"; | ||
@@ -4,0 +4,0 @@ //#region src/rspack/loaders/transform.ts |
@@ -1,4 +0,4 @@ | ||
| import { r as normalizeObjectHook } from "../../parse-CRORloGP.mjs"; | ||
| import { t as normalizeAbsolutePath } from "../../webpack-like-BU9ULG6P.mjs"; | ||
| import { n as createBuildContext, r as createContext } from "../../context-CY6F6zw6.mjs"; | ||
| import { r as normalizeObjectHook } from "../../parse-DN2jPtpt.mjs"; | ||
| import { t as normalizeAbsolutePath } from "../../webpack-like-Djrmy9eu.mjs"; | ||
| import { n as createBuildContext, r as createContext } from "../../context-MD-xQmYI.mjs"; | ||
@@ -5,0 +5,0 @@ //#region src/webpack/loaders/load.ts |
@@ -1,3 +0,3 @@ | ||
| import { r as normalizeObjectHook } from "../../parse-CRORloGP.mjs"; | ||
| import { n as createBuildContext, r as createContext } from "../../context-CY6F6zw6.mjs"; | ||
| import { r as normalizeObjectHook } from "../../parse-DN2jPtpt.mjs"; | ||
| import { n as createBuildContext, r as createContext } from "../../context-MD-xQmYI.mjs"; | ||
@@ -4,0 +4,0 @@ //#region src/webpack/loaders/transform.ts |
+21
-22
| { | ||
| "name": "unplugin", | ||
| "type": "module", | ||
| "version": "3.0.0-beta.3", | ||
| "version": "3.0.0", | ||
| "description": "Unified plugin system for build tools", | ||
@@ -21,4 +21,2 @@ "license": "MIT", | ||
| }, | ||
| "main": "./dist/index.mjs", | ||
| "module": "./dist/index.mjs", | ||
| "types": "./dist/index.d.mts", | ||
@@ -40,31 +38,32 @@ "files": [ | ||
| "devDependencies": { | ||
| "@antfu/eslint-config": "^6.2.0", | ||
| "@antfu/ni": "^27.0.1", | ||
| "@antfu/eslint-config": "^7.2.0", | ||
| "@antfu/ni": "^28.2.0", | ||
| "@farmfe/cli": "^1.0.5", | ||
| "@farmfe/core": "^1.7.11", | ||
| "@rspack/cli": "^1.6.4", | ||
| "@rspack/core": "^1.6.4", | ||
| "@types/node": "^24.10.1", | ||
| "@rspack/cli": "^1.7.3", | ||
| "@rspack/core": "^1.7.3", | ||
| "@types/node": "^25.0.10", | ||
| "@types/picomatch": "^4.0.2", | ||
| "@typescript/native-preview": "7.0.0-dev.20260122.3", | ||
| "ansis": "^4.2.0", | ||
| "bumpp": "^10.3.1", | ||
| "bun-types-no-globals": "^1.3.2", | ||
| "esbuild": "^0.27.0", | ||
| "eslint": "^9.39.1", | ||
| "eslint-plugin-format": "^1.0.2", | ||
| "bumpp": "^10.4.0", | ||
| "bun-types-no-globals": "^1.3.6", | ||
| "esbuild": "^0.27.2", | ||
| "eslint": "^9.39.2", | ||
| "eslint-plugin-format": "^1.3.1", | ||
| "jiti": "^2.6.1", | ||
| "lint-staged": "^16.2.7", | ||
| "magic-string": "^0.30.21", | ||
| "rolldown": "^1.0.0-beta.51", | ||
| "rollup": "^4.53.3", | ||
| "rolldown": "^1.0.0-rc.1", | ||
| "rollup": "^4.56.0", | ||
| "simple-git-hooks": "^2.13.1", | ||
| "tsdown": "^0.16.6", | ||
| "tsdown": "^0.20.0", | ||
| "typescript": "~5.9.3", | ||
| "unloader": "^0.8.0", | ||
| "unloader": "^0.8.3", | ||
| "unplugin-unused": "^0.5.6", | ||
| "vite": "^7.2.4", | ||
| "vitest": "^4.0.12", | ||
| "webpack": "^5.103.0", | ||
| "vite": "^7.3.1", | ||
| "vitest": "^4.0.17", | ||
| "webpack": "^5.104.1", | ||
| "webpack-cli": "^6.0.1", | ||
| "unplugin": "3.0.0-beta.3" | ||
| "unplugin": "3.0.0" | ||
| }, | ||
@@ -85,3 +84,3 @@ "resolutions": { | ||
| "lint:fix": "nr lint --fix", | ||
| "typecheck": "tsc --noEmit", | ||
| "typecheck": "tsgo --noEmit", | ||
| "docs:dev": "pnpm -C docs run dev", | ||
@@ -88,0 +87,0 @@ "docs:build": "pnpm -C docs run build", |
| import { t as parse } from "./parse-CRORloGP.mjs"; | ||
| import { resolve } from "node:path"; | ||
| import { Buffer } from "node:buffer"; | ||
| //#region src/rspack/context.ts | ||
| function createBuildContext(compiler, compilation, loaderContext, inputSourceMap) { | ||
| return { | ||
| getNativeBuildContext() { | ||
| return { | ||
| framework: "rspack", | ||
| compiler, | ||
| compilation, | ||
| loaderContext, | ||
| inputSourceMap | ||
| }; | ||
| }, | ||
| addWatchFile(file) { | ||
| const cwd = process.cwd(); | ||
| compilation.fileDependencies.add(resolve(cwd, file)); | ||
| }, | ||
| getWatchFiles() { | ||
| return Array.from(compilation.fileDependencies); | ||
| }, | ||
| parse, | ||
| emitFile(emittedFile) { | ||
| const outFileName = emittedFile.fileName || emittedFile.name; | ||
| if (emittedFile.source && outFileName) { | ||
| const { sources } = compilation.compiler.webpack; | ||
| compilation.emitAsset(outFileName, new sources.RawSource(typeof emittedFile.source === "string" ? emittedFile.source : Buffer.from(emittedFile.source))); | ||
| } | ||
| } | ||
| }; | ||
| } | ||
| function createContext(loader) { | ||
| return { | ||
| error: (error) => loader.emitError(normalizeMessage(error)), | ||
| warn: (message) => loader.emitWarning(normalizeMessage(message)) | ||
| }; | ||
| } | ||
| function normalizeMessage(error) { | ||
| const err = new Error(typeof error === "string" ? error : error.message); | ||
| if (typeof error === "object") { | ||
| err.stack = error.stack; | ||
| err.cause = error.meta; | ||
| } | ||
| return err; | ||
| } | ||
| //#endregion | ||
| export { createContext as n, normalizeMessage as r, createBuildContext as t }; |
| import { t as parse } from "./parse-CRORloGP.mjs"; | ||
| import { createRequire } from "node:module"; | ||
| import { resolve } from "node:path"; | ||
| import { Buffer } from "node:buffer"; | ||
| import process from "node:process"; | ||
| //#region src/webpack/context.ts | ||
| function contextOptionsFromCompilation(compilation) { | ||
| return { | ||
| addWatchFile(file) { | ||
| (compilation.fileDependencies ?? compilation.compilationDependencies).add(file); | ||
| }, | ||
| getWatchFiles() { | ||
| return Array.from(compilation.fileDependencies ?? compilation.compilationDependencies); | ||
| } | ||
| }; | ||
| } | ||
| const require = createRequire(import.meta.url); | ||
| function getSource(fileSource) { | ||
| return new (require("webpack")).sources.RawSource(typeof fileSource === "string" ? fileSource : Buffer.from(fileSource.buffer)); | ||
| } | ||
| function createBuildContext(options, compiler, compilation, loaderContext, inputSourceMap) { | ||
| return { | ||
| parse, | ||
| addWatchFile(id) { | ||
| options.addWatchFile(resolve(process.cwd(), id)); | ||
| }, | ||
| emitFile(emittedFile) { | ||
| const outFileName = emittedFile.fileName || emittedFile.name; | ||
| if (emittedFile.source && outFileName) { | ||
| if (!compilation) throw new Error("unplugin/webpack: emitFile outside supported hooks (buildStart, buildEnd, load, transform, watchChange)"); | ||
| compilation.emitAsset(outFileName, getSource(emittedFile.source)); | ||
| } | ||
| }, | ||
| getWatchFiles() { | ||
| return options.getWatchFiles(); | ||
| }, | ||
| getNativeBuildContext() { | ||
| return { | ||
| framework: "webpack", | ||
| compiler, | ||
| compilation, | ||
| loaderContext, | ||
| inputSourceMap | ||
| }; | ||
| } | ||
| }; | ||
| } | ||
| function createContext(loader) { | ||
| return { | ||
| error: (error) => loader.emitError(normalizeMessage(error)), | ||
| warn: (message) => loader.emitWarning(normalizeMessage(message)) | ||
| }; | ||
| } | ||
| function normalizeMessage(error) { | ||
| const err = new Error(typeof error === "string" ? error : error.message); | ||
| if (typeof error === "object") { | ||
| err.stack = error.stack; | ||
| err.cause = error.meta; | ||
| } | ||
| return err; | ||
| } | ||
| //#endregion | ||
| export { normalizeMessage as i, createBuildContext as n, createContext as r, contextOptionsFromCompilation as t }; |
| import { resolve } from "node:path"; | ||
| import picomatch from "picomatch"; | ||
| //#region src/utils/general.ts | ||
| function toArray(array) { | ||
| array = array || []; | ||
| if (Array.isArray(array)) return array; | ||
| return [array]; | ||
| } | ||
| //#endregion | ||
| //#region src/utils/filter.ts | ||
| const BACKSLASH_REGEX = /\\/g; | ||
| function normalize$1(path$1) { | ||
| return path$1.replace(BACKSLASH_REGEX, "/"); | ||
| } | ||
| const ABSOLUTE_PATH_REGEX = /^(?:\/|(?:[A-Z]:)?[/\\|])/i; | ||
| function isAbsolute$1(path$1) { | ||
| return ABSOLUTE_PATH_REGEX.test(path$1); | ||
| } | ||
| function getMatcherString(glob, cwd) { | ||
| if (glob.startsWith("**") || isAbsolute$1(glob)) return normalize$1(glob); | ||
| return normalize$1(resolve(cwd, glob)); | ||
| } | ||
| function patternToIdFilter(pattern) { | ||
| if (pattern instanceof RegExp) return (id) => { | ||
| const normalizedId = normalize$1(id); | ||
| const result = pattern.test(normalizedId); | ||
| pattern.lastIndex = 0; | ||
| return result; | ||
| }; | ||
| const matcher = picomatch(getMatcherString(pattern, process.cwd()), { dot: true }); | ||
| return (id) => { | ||
| return matcher(normalize$1(id)); | ||
| }; | ||
| } | ||
| function patternToCodeFilter(pattern) { | ||
| if (pattern instanceof RegExp) return (code) => { | ||
| const result = pattern.test(code); | ||
| pattern.lastIndex = 0; | ||
| return result; | ||
| }; | ||
| return (code) => code.includes(pattern); | ||
| } | ||
| function createFilter(exclude, include) { | ||
| if (!exclude && !include) return; | ||
| return (input) => { | ||
| if (exclude?.some((filter) => filter(input))) return false; | ||
| if (include?.some((filter) => filter(input))) return true; | ||
| return !(include && include.length > 0); | ||
| }; | ||
| } | ||
| function normalizeFilter(filter) { | ||
| if (typeof filter === "string" || filter instanceof RegExp) return { include: [filter] }; | ||
| if (Array.isArray(filter)) return { include: filter }; | ||
| return { | ||
| exclude: filter.exclude ? toArray(filter.exclude) : void 0, | ||
| include: filter.include ? toArray(filter.include) : void 0 | ||
| }; | ||
| } | ||
| function createIdFilter(filter) { | ||
| if (!filter) return; | ||
| const { exclude, include } = normalizeFilter(filter); | ||
| const excludeFilter = exclude?.map(patternToIdFilter); | ||
| const includeFilter = include?.map(patternToIdFilter); | ||
| return createFilter(excludeFilter, includeFilter); | ||
| } | ||
| function createCodeFilter(filter) { | ||
| if (!filter) return; | ||
| const { exclude, include } = normalizeFilter(filter); | ||
| const excludeFilter = exclude?.map(patternToCodeFilter); | ||
| const includeFilter = include?.map(patternToCodeFilter); | ||
| return createFilter(excludeFilter, includeFilter); | ||
| } | ||
| function createFilterForId(filter) { | ||
| const filterFunction = createIdFilter(filter); | ||
| return filterFunction ? (id) => !!filterFunction(id) : void 0; | ||
| } | ||
| function createFilterForTransform(idFilter, codeFilter) { | ||
| if (!idFilter && !codeFilter) return; | ||
| const idFilterFunction = createIdFilter(idFilter); | ||
| const codeFilterFunction = createCodeFilter(codeFilter); | ||
| return (id, code) => { | ||
| let fallback = true; | ||
| if (idFilterFunction) fallback &&= idFilterFunction(id); | ||
| if (!fallback) return false; | ||
| if (codeFilterFunction) fallback &&= codeFilterFunction(code); | ||
| return fallback; | ||
| }; | ||
| } | ||
| function normalizeObjectHook(name, hook) { | ||
| let handler; | ||
| let filter; | ||
| if (typeof hook === "function") handler = hook; | ||
| else { | ||
| handler = hook.handler; | ||
| const hookFilter = hook.filter; | ||
| if (name === "resolveId" || name === "load") filter = createFilterForId(hookFilter?.id); | ||
| else filter = createFilterForTransform(hookFilter?.id, hookFilter?.code); | ||
| } | ||
| return { | ||
| handler, | ||
| filter: filter || (() => true) | ||
| }; | ||
| } | ||
| //#endregion | ||
| //#region src/utils/parse.ts | ||
| let parseImpl; | ||
| function parse(code, opts = {}) { | ||
| if (!parseImpl) throw new Error("Parse implementation is not set. Please call setParseImpl first."); | ||
| return parseImpl(code, opts); | ||
| } | ||
| function setParseImpl(customParse) { | ||
| parseImpl = customParse; | ||
| } | ||
| //#endregion | ||
| export { toArray as i, setParseImpl as n, normalizeObjectHook as r, parse as t }; |
| import { basename, dirname, resolve } from "node:path"; | ||
| import fs from "node:fs"; | ||
| //#region src/rspack/utils.ts | ||
| function encodeVirtualModuleId(id, plugin) { | ||
| return resolve(plugin.__virtualModulePrefix, encodeURIComponent(id)); | ||
| } | ||
| function decodeVirtualModuleId(encoded, _plugin) { | ||
| return decodeURIComponent(basename(encoded)); | ||
| } | ||
| function isVirtualModuleId(encoded, plugin) { | ||
| return dirname(encoded) === plugin.__virtualModulePrefix; | ||
| } | ||
| var FakeVirtualModulesPlugin = class FakeVirtualModulesPlugin { | ||
| name = "FakeVirtualModulesPlugin"; | ||
| static counters = /* @__PURE__ */ new Map(); | ||
| static initCleanup = false; | ||
| constructor(plugin) { | ||
| this.plugin = plugin; | ||
| if (!FakeVirtualModulesPlugin.initCleanup) { | ||
| FakeVirtualModulesPlugin.initCleanup = true; | ||
| process.once("exit", () => { | ||
| FakeVirtualModulesPlugin.counters.forEach((_, dir) => { | ||
| fs.rmSync(dir, { | ||
| recursive: true, | ||
| force: true | ||
| }); | ||
| }); | ||
| }); | ||
| } | ||
| } | ||
| apply(compiler) { | ||
| const dir = this.plugin.__virtualModulePrefix; | ||
| if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true }); | ||
| const counter = FakeVirtualModulesPlugin.counters.get(dir) ?? 0; | ||
| FakeVirtualModulesPlugin.counters.set(dir, counter + 1); | ||
| compiler.hooks.shutdown.tap(this.name, () => { | ||
| const counter$1 = (FakeVirtualModulesPlugin.counters.get(dir) ?? 1) - 1; | ||
| if (counter$1 === 0) { | ||
| FakeVirtualModulesPlugin.counters.delete(dir); | ||
| fs.rmSync(dir, { | ||
| recursive: true, | ||
| force: true | ||
| }); | ||
| } else FakeVirtualModulesPlugin.counters.set(dir, counter$1); | ||
| }); | ||
| } | ||
| async writeModule(file) { | ||
| return fs.promises.writeFile(file, ""); | ||
| } | ||
| }; | ||
| //#endregion | ||
| export { isVirtualModuleId as i, decodeVirtualModuleId as n, encodeVirtualModuleId as r, FakeVirtualModulesPlugin as t }; |
| import { r as normalizeObjectHook } from "./parse-CRORloGP.mjs"; | ||
| import { isAbsolute, normalize } from "node:path"; | ||
| //#region src/utils/webpack-like.ts | ||
| function transformUse(data, plugin, transformLoader) { | ||
| if (data.resource == null) return []; | ||
| const id = normalizeAbsolutePath(data.resource + (data.resourceQuery || "")); | ||
| if (plugin.transformInclude && !plugin.transformInclude(id)) return []; | ||
| const { filter } = normalizeObjectHook("load", plugin.transform); | ||
| if (!filter(id)) return []; | ||
| return [{ | ||
| loader: transformLoader, | ||
| options: { plugin }, | ||
| ident: plugin.name | ||
| }]; | ||
| } | ||
| /** | ||
| * Normalizes a given path when it's absolute. Normalizing means returning a new path by converting | ||
| * the input path to the native os format. This is useful in cases where we want to normalize | ||
| * the `id` argument of a hook. Any absolute ids should be in the default format | ||
| * of the operating system. Any relative imports or node_module imports should remain | ||
| * untouched. | ||
| * | ||
| * @param path - Path to normalize. | ||
| * @returns a new normalized path. | ||
| */ | ||
| function normalizeAbsolutePath(path$1) { | ||
| if (isAbsolute(path$1)) return normalize(path$1); | ||
| else return path$1; | ||
| } | ||
| //#endregion | ||
| export { transformUse as n, normalizeAbsolutePath as t }; |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
74342
0.25%1597
0.31%0
-100%30
3.45%