版博士V2.0程序
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 

108 líneas
3.5 KiB

  1. "use strict";
  2. var __create = Object.create;
  3. var __defProp = Object.defineProperty;
  4. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  5. var __getOwnPropNames = Object.getOwnPropertyNames;
  6. var __getProtoOf = Object.getPrototypeOf;
  7. var __hasOwnProp = Object.prototype.hasOwnProperty;
  8. var __export = (target, all) => {
  9. for (var name in all)
  10. __defProp(target, name, { get: all[name], enumerable: true });
  11. };
  12. var __copyProps = (to, from, except, desc) => {
  13. if (from && typeof from === "object" || typeof from === "function") {
  14. for (let key of __getOwnPropNames(from))
  15. if (!__hasOwnProp.call(to, key) && key !== except)
  16. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  17. }
  18. return to;
  19. };
  20. var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  21. // If the importer is in node compatibility mode or this is not an ESM
  22. // file that has been converted to a CommonJS file using a Babel-
  23. // compatible transform (i.e. "__esModule" has not been set), then set
  24. // "default" to the CommonJS "module.exports" for node compatibility.
  25. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  26. mod
  27. ));
  28. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  29. // src/rspack/loaders/load.ts
  30. var load_exports = {};
  31. __export(load_exports, {
  32. default: () => load
  33. });
  34. module.exports = __toCommonJS(load_exports);
  35. // src/rspack/context.ts
  36. var import_webpack_sources = __toESM(require("webpack-sources"));
  37. var import_acorn = require("acorn");
  38. function createRspackContext(compilation) {
  39. return {
  40. parse(code, opts = {}) {
  41. return import_acorn.Parser.parse(code, {
  42. sourceType: "module",
  43. ecmaVersion: "latest",
  44. locations: true,
  45. ...opts
  46. });
  47. },
  48. addWatchFile() {
  49. },
  50. emitFile(emittedFile) {
  51. const outFileName = emittedFile.fileName || emittedFile.name;
  52. if (emittedFile.source && outFileName) {
  53. compilation.emitAsset(
  54. outFileName,
  55. new import_webpack_sources.default.RawSource(
  56. // @ts-expect-error types mismatch
  57. typeof emittedFile.source === "string" ? emittedFile.source : Buffer.from(emittedFile.source)
  58. )
  59. );
  60. }
  61. },
  62. getWatchFiles() {
  63. return [];
  64. }
  65. };
  66. }
  67. // src/utils.ts
  68. var import_path = require("path");
  69. function normalizeAbsolutePath(path) {
  70. if ((0, import_path.isAbsolute)(path))
  71. return (0, import_path.normalize)(path);
  72. else
  73. return path;
  74. }
  75. // src/rspack/loaders/load.ts
  76. async function load(source, map) {
  77. const callback = this.async();
  78. const id = this.resource;
  79. const { plugin } = this.getOptions();
  80. if (!plugin?.load || !id)
  81. return callback(null, source, map);
  82. if (plugin.loadInclude && !plugin.loadInclude(id))
  83. return callback(null, source, map);
  84. const context = {
  85. error: (error) => this.emitError(typeof error === "string" ? new Error(error) : error),
  86. warn: (error) => this.emitWarning(typeof error === "string" ? new Error(error) : error)
  87. };
  88. const res = await plugin.load.call(
  89. Object.assign(
  90. this._compilation && createRspackContext(this._compilation),
  91. context
  92. ),
  93. normalizeAbsolutePath(id)
  94. );
  95. if (res == null)
  96. callback(null, source, map);
  97. else if (typeof res !== "string")
  98. callback(null, res.code, res.map ?? map);
  99. else
  100. callback(null, res, map);
  101. }
  102. // Annotate the CommonJS export names for ESM import in node:
  103. 0 && (module.exports = {});