版博士V2.0程序
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

115 строки
4.0 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/webpack/loaders/load.ts
  30. var load_exports = {};
  31. __export(load_exports, {
  32. default: () => load
  33. });
  34. module.exports = __toCommonJS(load_exports);
  35. // src/webpack/context.ts
  36. var import_path = require("path");
  37. var import_webpack_sources = __toESM(require("webpack-sources"));
  38. var import_acorn = require("acorn");
  39. function createContext(compilation) {
  40. return {
  41. parse(code, opts = {}) {
  42. return import_acorn.Parser.parse(code, {
  43. sourceType: "module",
  44. ecmaVersion: "latest",
  45. locations: true,
  46. ...opts
  47. });
  48. },
  49. addWatchFile(id) {
  50. (compilation.fileDependencies ?? compilation.compilationDependencies).add(
  51. (0, import_path.resolve)(process.cwd(), id)
  52. );
  53. },
  54. emitFile(emittedFile) {
  55. const outFileName = emittedFile.fileName || emittedFile.name;
  56. if (emittedFile.source && outFileName) {
  57. compilation.emitAsset(
  58. outFileName,
  59. import_webpack_sources.default ? new import_webpack_sources.default.RawSource(
  60. // @ts-expect-error types mismatch
  61. typeof emittedFile.source === "string" ? emittedFile.source : Buffer.from(emittedFile.source)
  62. ) : {
  63. source: () => emittedFile.source,
  64. size: () => emittedFile.source.length
  65. }
  66. );
  67. }
  68. },
  69. getWatchFiles() {
  70. return Array.from(
  71. compilation.fileDependencies ?? compilation.compilationDependencies
  72. );
  73. }
  74. };
  75. }
  76. // src/utils.ts
  77. var import_path2 = require("path");
  78. function normalizeAbsolutePath(path) {
  79. if ((0, import_path2.isAbsolute)(path))
  80. return (0, import_path2.normalize)(path);
  81. else
  82. return path;
  83. }
  84. // src/webpack/loaders/load.ts
  85. async function load(source, map) {
  86. const callback = this.async();
  87. const { unpluginName } = this.query;
  88. const plugin = this._compiler?.$unpluginContext[unpluginName];
  89. let id = this.resource;
  90. if (!plugin?.load || !id)
  91. return callback(null, source, map);
  92. const context = {
  93. error: (error) => this.emitError(typeof error === "string" ? new Error(error) : error),
  94. warn: (error) => this.emitWarning(typeof error === "string" ? new Error(error) : error)
  95. };
  96. if (id.startsWith(plugin.__virtualModulePrefix))
  97. id = decodeURIComponent(id.slice(plugin.__virtualModulePrefix.length));
  98. const res = await plugin.load.call(
  99. Object.assign(this._compilation && createContext(this._compilation), context),
  100. normalizeAbsolutePath(id)
  101. );
  102. if (res == null)
  103. callback(null, source, map);
  104. else if (typeof res !== "string")
  105. callback(null, res.code, res.map ?? map);
  106. else
  107. callback(null, res, map);
  108. }
  109. // Annotate the CommonJS export names for ESM import in node:
  110. 0 && (module.exports = {});