| 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 }; |
+2
-0
@@ -46,2 +46,3 @@ import VirtualModulesPlugin from "webpack-virtual-modules"; | ||
| }> | undefined; | ||
| inputSourceMap?: any; | ||
| } | { | ||
@@ -55,2 +56,3 @@ framework: "esbuild"; | ||
| loaderContext?: LoaderContext | undefined; | ||
| inputSourceMap?: any; | ||
| } | { | ||
@@ -57,0 +59,0 @@ framework: "farm"; |
+5
-6
@@ -1,6 +0,6 @@ | ||
| import { i as toArray, n as setParseImpl, r as normalizeObjectHook, t as parse } from "./parse-Xb0Lbkhb.mjs"; | ||
| import { n as transformUse, t as normalizeAbsolutePath } from "./webpack-like-CCJuUXyc.mjs"; | ||
| import { r as normalizeMessage$1, t as createBuildContext$1 } from "./context-adONQ5VG.mjs"; | ||
| import { i as isVirtualModuleId, n as decodeVirtualModuleId, r as encodeVirtualModuleId, t as FakeVirtualModulesPlugin } from "./utils-C0A28-Cs.mjs"; | ||
| import { i as normalizeMessage, n as createBuildContext, t as contextOptionsFromCompilation } from "./context-CkXKhHEh.mjs"; | ||
| 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 path, { extname, isAbsolute, resolve } from "node:path"; | ||
@@ -848,3 +848,2 @@ import fs from "node:fs"; | ||
| function supportNativeFilter(context, framework) { | ||
| if (framework === "unloader") return false; | ||
| if (framework === "vite") return !!context?.meta?.viteVersion; | ||
@@ -851,0 +850,0 @@ if (framework === "rolldown") return true; |
@@ -1,5 +0,5 @@ | ||
| import { r as normalizeObjectHook } from "../../parse-Xb0Lbkhb.mjs"; | ||
| import { t as normalizeAbsolutePath } from "../../webpack-like-CCJuUXyc.mjs"; | ||
| import { n as createContext, t as createBuildContext } from "../../context-adONQ5VG.mjs"; | ||
| import { i as isVirtualModuleId, n as decodeVirtualModuleId } from "../../utils-C0A28-Cs.mjs"; | ||
| 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"; | ||
@@ -6,0 +6,0 @@ //#region src/rspack/loaders/load.ts |
@@ -1,3 +0,3 @@ | ||
| import { r as normalizeObjectHook } from "../../parse-Xb0Lbkhb.mjs"; | ||
| import { n as createContext, t as createBuildContext } from "../../context-adONQ5VG.mjs"; | ||
| import { r as normalizeObjectHook } from "../../parse-CRORloGP.mjs"; | ||
| import { n as createContext, t as createBuildContext } from "../../context-CehLHpzV.mjs"; | ||
@@ -14,3 +14,3 @@ //#region src/rspack/loaders/transform.ts | ||
| try { | ||
| const res = await handler.call(Object.assign({}, this._compilation && createBuildContext(this._compiler, this._compilation, this), context), source, id); | ||
| const res = await handler.call(Object.assign({}, this._compilation && createBuildContext(this._compiler, this._compilation, this, map), context), source, id); | ||
| if (res == null) callback(null, source, map); | ||
@@ -17,0 +17,0 @@ else if (typeof res !== "string") callback(null, res.code, map == null ? map : res.map || map); |
@@ -1,4 +0,4 @@ | ||
| import { r as normalizeObjectHook } from "../../parse-Xb0Lbkhb.mjs"; | ||
| import { t as normalizeAbsolutePath } from "../../webpack-like-CCJuUXyc.mjs"; | ||
| import { n as createBuildContext, r as createContext } from "../../context-CkXKhHEh.mjs"; | ||
| 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"; | ||
@@ -5,0 +5,0 @@ //#region src/webpack/loaders/load.ts |
@@ -1,3 +0,3 @@ | ||
| import { r as normalizeObjectHook } from "../../parse-Xb0Lbkhb.mjs"; | ||
| import { n as createBuildContext, r as createContext } from "../../context-CkXKhHEh.mjs"; | ||
| import { r as normalizeObjectHook } from "../../parse-CRORloGP.mjs"; | ||
| import { n as createBuildContext, r as createContext } from "../../context-CY6F6zw6.mjs"; | ||
@@ -20,3 +20,3 @@ //#region src/webpack/loaders/transform.ts | ||
| } | ||
| }, this._compiler, this._compilation, this), context), source, this.resource); | ||
| }, this._compiler, this._compilation, this, map), context), source, this.resource); | ||
| if (res == null) callback(null, source, map); | ||
@@ -23,0 +23,0 @@ else if (typeof res !== "string") callback(null, res.code, map == null ? map : res.map || map); |
+17
-17
| { | ||
| "name": "unplugin", | ||
| "type": "module", | ||
| "version": "3.0.0-beta.2", | ||
| "version": "3.0.0-beta.3", | ||
| "description": "Unified plugin system for build tools", | ||
@@ -43,27 +43,27 @@ "license": "MIT", | ||
| "@farmfe/core": "^1.7.11", | ||
| "@rspack/cli": "^1.6.0", | ||
| "@rspack/core": "^1.6.0", | ||
| "@types/node": "^24.10.0", | ||
| "@rspack/cli": "^1.6.4", | ||
| "@rspack/core": "^1.6.4", | ||
| "@types/node": "^24.10.1", | ||
| "@types/picomatch": "^4.0.2", | ||
| "ansis": "^4.2.0", | ||
| "bumpp": "^10.3.1", | ||
| "bun-types-no-globals": "^1.2.22", | ||
| "esbuild": "^0.25.12", | ||
| "eslint": "^9.39.0", | ||
| "bun-types-no-globals": "^1.3.2", | ||
| "esbuild": "^0.27.0", | ||
| "eslint": "^9.39.1", | ||
| "eslint-plugin-format": "^1.0.2", | ||
| "jiti": "^2.6.1", | ||
| "lint-staged": "^16.2.6", | ||
| "lint-staged": "^16.2.7", | ||
| "magic-string": "^0.30.21", | ||
| "rolldown": "^1.0.0-beta.46", | ||
| "rollup": "^4.52.5", | ||
| "rolldown": "^1.0.0-beta.51", | ||
| "rollup": "^4.53.3", | ||
| "simple-git-hooks": "^2.13.1", | ||
| "tsdown": "^0.15.12", | ||
| "tsdown": "^0.16.6", | ||
| "typescript": "~5.9.3", | ||
| "unloader": "^0.5.0", | ||
| "unplugin-unused": "^0.5.5", | ||
| "vite": "^7.1.12", | ||
| "vitest": "^4.0.6", | ||
| "webpack": "^5.102.1", | ||
| "unloader": "^0.8.0", | ||
| "unplugin-unused": "^0.5.6", | ||
| "vite": "^7.2.4", | ||
| "vitest": "^4.0.12", | ||
| "webpack": "^5.103.0", | ||
| "webpack-cli": "^6.0.1", | ||
| "unplugin": "3.0.0-beta.2" | ||
| "unplugin": "3.0.0-beta.3" | ||
| }, | ||
@@ -70,0 +70,0 @@ "resolutions": { |
| import { t as parse } from "./parse-Xb0Lbkhb.mjs"; | ||
| import { resolve } from "node:path"; | ||
| import { Buffer } from "node:buffer"; | ||
| //#region src/rspack/context.ts | ||
| function createBuildContext(compiler, compilation, loaderContext) { | ||
| return { | ||
| getNativeBuildContext() { | ||
| return { | ||
| framework: "rspack", | ||
| compiler, | ||
| compilation, | ||
| loaderContext | ||
| }; | ||
| }, | ||
| 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-Xb0Lbkhb.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) { | ||
| 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 | ||
| }; | ||
| } | ||
| }; | ||
| } | ||
| 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-Xb0Lbkhb.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 }; |
74158
0.11%1592
0.06%