| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- import { parse } from "./context-D49cMElb.js";
- 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 { createBuildContext as createBuildContext$1, createContext as createContext$1, normalizeMessage as normalizeMessage$1 };
|