| 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 { 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 }; |
+6
-4
@@ -1,2 +0,1 @@ | ||
| import { Options } from "acorn"; | ||
| import VirtualModulesPlugin from "webpack-virtual-modules"; | ||
@@ -8,3 +7,3 @@ import { CompilationContext, JsPlugin } from "@farmfe/core"; | ||
| import { Plugin as RolldownPlugin } from "rolldown"; | ||
| import { AstNode, EmittedAsset, Plugin as RollupPlugin, PluginContextMeta, SourceMapInput } from "rollup"; | ||
| import { EmittedAsset, Plugin as RollupPlugin, PluginContextMeta, SourceMapInput } from "rollup"; | ||
| import { Plugin as UnloaderPlugin } from "unloader"; | ||
@@ -67,3 +66,3 @@ import { Plugin as VitePlugin } from "vite"; | ||
| getWatchFiles: () => string[]; | ||
| parse: (input: string, options?: Partial<Options>) => AstNode; | ||
| parse: (input: string, options?: any) => any; | ||
| getNativeBuildContext?: (() => NativeBuildContext) | undefined; | ||
@@ -210,2 +209,5 @@ } | ||
| //#endregion | ||
| 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, Thenable, TransformResult, type UnloaderPlugin, UnpluginBuildContext, UnpluginContext, UnpluginContextMeta, UnpluginFactory, UnpluginFactoryOutput, UnpluginInstance, UnpluginMessage, UnpluginOptions, type VitePlugin, type WebpackCompiler, type WebpackPluginInstance, createBunPlugin, createEsbuildPlugin, createFarmPlugin, createRolldownPlugin, createRollupPlugin, createRspackPlugin, createUnloaderPlugin, createUnplugin, createVitePlugin, createWebpackPlugin }; | ||
| //#region src/utils/parse.d.ts | ||
| declare function setParseImpl(customParse: (code: string, opts?: any) => any): void; | ||
| //#endregion | ||
| 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, Thenable, TransformResult, type UnloaderPlugin, UnpluginBuildContext, UnpluginContext, UnpluginContextMeta, UnpluginFactory, UnpluginFactoryOutput, UnpluginInstance, UnpluginMessage, UnpluginOptions, type VitePlugin, type WebpackCompiler, type WebpackPluginInstance, createBunPlugin, createEsbuildPlugin, createFarmPlugin, createRolldownPlugin, createRollupPlugin, createRspackPlugin, createUnloaderPlugin, createUnplugin, createVitePlugin, createWebpackPlugin, setParseImpl }; |
+6
-14
@@ -1,9 +0,8 @@ | ||
| import { n as normalizeObjectHook, r as toArray, t as parse } from "./context-BA9Bk3zk.mjs"; | ||
| import { n as transformUse, t as normalizeAbsolutePath } from "./webpack-like-BEGRU-K6.mjs"; | ||
| import { r as normalizeMessage$1, t as createBuildContext$1 } from "./context-DTC5O8j3.mjs"; | ||
| 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-DCMwCoy8.mjs"; | ||
| import { i as normalizeMessage, n as createBuildContext, t as contextOptionsFromCompilation } from "./context-CkXKhHEh.mjs"; | ||
| import path, { extname, isAbsolute, resolve } from "node:path"; | ||
| import fs from "node:fs"; | ||
| import * as acorn from "acorn"; | ||
| import { Buffer } from "node:buffer"; | ||
@@ -55,10 +54,3 @@ import remapping from "@jridgewell/remapping"; | ||
| }, | ||
| parse(code, opts = {}) { | ||
| return acorn.parse(code, { | ||
| sourceType: "module", | ||
| ecmaVersion: "latest", | ||
| locations: true, | ||
| ...opts | ||
| }); | ||
| }, | ||
| parse, | ||
| getNativeBuildContext() { | ||
@@ -1215,2 +1207,2 @@ return { | ||
| //#endregion | ||
| export { createBunPlugin, createEsbuildPlugin, createFarmPlugin, createRolldownPlugin, createRollupPlugin, createRspackPlugin, createUnloaderPlugin, createUnplugin, createVitePlugin, createWebpackPlugin }; | ||
| export { createBunPlugin, createEsbuildPlugin, createFarmPlugin, createRolldownPlugin, createRollupPlugin, createRspackPlugin, createUnloaderPlugin, createUnplugin, createVitePlugin, createWebpackPlugin, setParseImpl }; |
@@ -1,4 +0,4 @@ | ||
| import { n as normalizeObjectHook } from "../../context-BA9Bk3zk.mjs"; | ||
| import { t as normalizeAbsolutePath } from "../../webpack-like-BEGRU-K6.mjs"; | ||
| import { n as createContext, t as createBuildContext } from "../../context-DTC5O8j3.mjs"; | ||
| 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"; | ||
@@ -5,0 +5,0 @@ |
@@ -1,3 +0,3 @@ | ||
| import { n as normalizeObjectHook } from "../../context-BA9Bk3zk.mjs"; | ||
| import { n as createContext, t as createBuildContext } from "../../context-DTC5O8j3.mjs"; | ||
| import { r as normalizeObjectHook } from "../../parse-Xb0Lbkhb.mjs"; | ||
| import { n as createContext, t as createBuildContext } from "../../context-adONQ5VG.mjs"; | ||
@@ -4,0 +4,0 @@ //#region src/rspack/loaders/transform.ts |
@@ -1,4 +0,4 @@ | ||
| import { n as normalizeObjectHook } from "../../context-BA9Bk3zk.mjs"; | ||
| import { t as normalizeAbsolutePath } from "../../webpack-like-BEGRU-K6.mjs"; | ||
| import { n as createBuildContext, r as createContext } from "../../context-DCMwCoy8.mjs"; | ||
| 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"; | ||
@@ -5,0 +5,0 @@ //#region src/webpack/loaders/load.ts |
@@ -1,3 +0,3 @@ | ||
| import { n as normalizeObjectHook } from "../../context-BA9Bk3zk.mjs"; | ||
| import { n as createBuildContext, r as createContext } from "../../context-DCMwCoy8.mjs"; | ||
| import { r as normalizeObjectHook } from "../../parse-Xb0Lbkhb.mjs"; | ||
| import { n as createBuildContext, r as createContext } from "../../context-CkXKhHEh.mjs"; | ||
@@ -4,0 +4,0 @@ //#region src/webpack/loaders/transform.ts |
+2
-3
| { | ||
| "name": "unplugin", | ||
| "type": "module", | ||
| "version": "3.0.0-beta.1", | ||
| "version": "3.0.0-beta.2", | ||
| "description": "Unified plugin system for build tools", | ||
@@ -35,3 +35,2 @@ "license": "MIT", | ||
| "@jridgewell/remapping": "^2.3.5", | ||
| "acorn": "^8.15.0", | ||
| "picomatch": "^4.0.3", | ||
@@ -69,3 +68,3 @@ "webpack-virtual-modules": "^0.6.2" | ||
| "webpack-cli": "^6.0.1", | ||
| "unplugin": "3.0.0-beta.1" | ||
| "unplugin": "3.0.0-beta.2" | ||
| }, | ||
@@ -72,0 +71,0 @@ "resolutions": { |
| import { resolve } from "node:path"; | ||
| import picomatch from "picomatch"; | ||
| import { Parser } from "acorn"; | ||
| //#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/context.ts | ||
| function parse(code, opts = {}) { | ||
| return Parser.parse(code, { | ||
| sourceType: "module", | ||
| ecmaVersion: "latest", | ||
| locations: true, | ||
| ...opts | ||
| }); | ||
| } | ||
| //#endregion | ||
| export { normalizeObjectHook as n, toArray as r, parse as t }; |
| import { t as parse } from "./context-BA9Bk3zk.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 { t as parse } from "./context-BA9Bk3zk.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 { n as normalizeObjectHook } from "./context-BA9Bk3zk.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 }; |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
3
-25%0
-100%74076
-0.02%1591
-0.56%- Removed
- Removed