context-PvRDlMNZ.cjs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. const require_context = require('./context-DwbtaXxf.cjs');
  2. const node_path = require_context.__toESM(require("node:path"));
  3. const node_buffer = require_context.__toESM(require("node:buffer"));
  4. //#region src/rspack/context.ts
  5. function createBuildContext(compiler, compilation, loaderContext) {
  6. return {
  7. getNativeBuildContext() {
  8. return {
  9. framework: "rspack",
  10. compiler,
  11. compilation,
  12. loaderContext
  13. };
  14. },
  15. addWatchFile(file) {
  16. const cwd = process.cwd();
  17. compilation.fileDependencies.add((0, node_path.resolve)(cwd, file));
  18. },
  19. getWatchFiles() {
  20. return Array.from(compilation.fileDependencies);
  21. },
  22. parse: require_context.parse,
  23. emitFile(emittedFile) {
  24. const outFileName = emittedFile.fileName || emittedFile.name;
  25. if (emittedFile.source && outFileName) {
  26. const { sources } = compilation.compiler.webpack;
  27. compilation.emitAsset(outFileName, new sources.RawSource(typeof emittedFile.source === "string" ? emittedFile.source : node_buffer.Buffer.from(emittedFile.source)));
  28. }
  29. }
  30. };
  31. }
  32. function createContext(loader) {
  33. return {
  34. error: (error) => loader.emitError(normalizeMessage(error)),
  35. warn: (message) => loader.emitWarning(normalizeMessage(message))
  36. };
  37. }
  38. function normalizeMessage(error) {
  39. const err = new Error(typeof error === "string" ? error : error.message);
  40. if (typeof error === "object") {
  41. err.stack = error.stack;
  42. err.cause = error.meta;
  43. }
  44. return err;
  45. }
  46. //#endregion
  47. Object.defineProperty(exports, 'createBuildContext', {
  48. enumerable: true,
  49. get: function () {
  50. return createBuildContext;
  51. }
  52. });
  53. Object.defineProperty(exports, 'createContext', {
  54. enumerable: true,
  55. get: function () {
  56. return createContext;
  57. }
  58. });
  59. Object.defineProperty(exports, 'normalizeMessage', {
  60. enumerable: true,
  61. get: function () {
  62. return normalizeMessage;
  63. }
  64. });