123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215 |
- "use strict";
- const { RawSource } = require("webpack-sources");
- const OriginalSource = require("webpack-sources").OriginalSource;
- const Module = require("./Module");
- const { WEBPACK_MODULE_TYPE_RUNTIME } = require("./ModuleTypeConstants");
- const TYPES = new Set([WEBPACK_MODULE_TYPE_RUNTIME]);
- class RuntimeModule extends Module {
-
- constructor(name, stage = 0) {
- super(WEBPACK_MODULE_TYPE_RUNTIME);
- this.name = name;
- this.stage = stage;
- this.buildMeta = {};
- this.buildInfo = {};
-
- this.compilation = undefined;
-
- this.chunk = undefined;
-
- this.chunkGraph = undefined;
- this.fullHash = false;
- this.dependentHash = false;
-
- this._cachedGeneratedCode = undefined;
- }
-
- attach(compilation, chunk, chunkGraph = compilation.chunkGraph) {
- this.compilation = compilation;
- this.chunk = chunk;
- this.chunkGraph = chunkGraph;
- }
-
- identifier() {
- return `webpack/runtime/${this.name}`;
- }
-
- readableIdentifier(requestShortener) {
- return `webpack/runtime/${this.name}`;
- }
-
- needBuild(context, callback) {
- return callback(null, false);
- }
-
- build(options, compilation, resolver, fs, callback) {
-
-
- callback();
- }
-
- updateHash(hash, context) {
- hash.update(this.name);
- hash.update(`${this.stage}`);
- try {
- if (this.fullHash || this.dependentHash) {
-
-
- hash.update( (this.generate()));
- } else {
- hash.update( (this.getGeneratedCode()));
- }
- } catch (err) {
- hash.update( (err).message);
- }
- super.updateHash(hash, context);
- }
-
- getSourceTypes() {
- return TYPES;
- }
-
- codeGeneration(context) {
- const sources = new Map();
- const generatedCode = this.getGeneratedCode();
- if (generatedCode) {
- sources.set(
- WEBPACK_MODULE_TYPE_RUNTIME,
- this.useSourceMap || this.useSimpleSourceMap
- ? new OriginalSource(generatedCode, this.identifier())
- : new RawSource(generatedCode)
- );
- }
- return {
- sources,
- runtimeRequirements: null
- };
- }
-
- size(type) {
- try {
- const source = this.getGeneratedCode();
- return source ? source.length : 0;
- } catch (e) {
- return 0;
- }
- }
-
-
- generate() {
- const AbstractMethodError = require("./AbstractMethodError");
- throw new AbstractMethodError();
- }
-
- getGeneratedCode() {
- if (this._cachedGeneratedCode) {
- return this._cachedGeneratedCode;
- }
- return (this._cachedGeneratedCode = this.generate());
- }
-
- shouldIsolate() {
- return true;
- }
- }
- RuntimeModule.STAGE_NORMAL = 0;
- RuntimeModule.STAGE_BASIC = 5;
- RuntimeModule.STAGE_ATTACH = 10;
- RuntimeModule.STAGE_TRIGGER = 20;
- module.exports = RuntimeModule;
|