Initial commit

This commit is contained in:
Developer
2025-04-21 16:03:20 +02:00
commit 2832896157
22874 changed files with 3092801 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
'use strict';
module.exports = require('./index').default;

View File

@@ -0,0 +1,291 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _fs = require('fs');
var _fs2 = _interopRequireDefault(_fs);
var _path = require('path');
var _path2 = _interopRequireDefault(_path);
var _Chunk = require('webpack/lib/Chunk');
var _Chunk2 = _interopRequireDefault(_Chunk);
var _webpackSources = require('webpack-sources');
var _async = require('async');
var _async2 = _interopRequireDefault(_async);
var _loaderUtils = require('loader-utils');
var _loaderUtils2 = _interopRequireDefault(_loaderUtils);
var _schemaUtils = require('schema-utils');
var _schemaUtils2 = _interopRequireDefault(_schemaUtils);
var _ExtractTextPluginCompilation = require('./lib/ExtractTextPluginCompilation');
var _ExtractTextPluginCompilation2 = _interopRequireDefault(_ExtractTextPluginCompilation);
var _OrderUndefinedError = require('./lib/OrderUndefinedError');
var _OrderUndefinedError2 = _interopRequireDefault(_OrderUndefinedError);
var _helpers = require('./lib/helpers');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var NS = _path2.default.dirname(_fs2.default.realpathSync(__filename));
var nextId = 0;
var ExtractTextPlugin = function () {
function ExtractTextPlugin(options) {
_classCallCheck(this, ExtractTextPlugin);
if ((0, _helpers.isString)(options)) {
options = { filename: options };
} else {
(0, _schemaUtils2.default)(_path2.default.resolve(__dirname, '../schema/plugin.json'), options, 'Extract Text Plugin');
}
this.filename = options.filename;
this.id = options.id != null ? options.id : ++nextId;
this.options = {};
(0, _helpers.mergeOptions)(this.options, options);
delete this.options.filename;
delete this.options.id;
}
_createClass(ExtractTextPlugin, [{
key: 'applyAdditionalInformation',
value: function applyAdditionalInformation(source, info) {
if (info) {
return new _webpackSources.ConcatSource(`@media ${info[0]} {`, source, '}');
}
return source;
}
}, {
key: 'loader',
value: function loader(options) {
return ExtractTextPlugin.loader((0, _helpers.mergeOptions)({ id: this.id }, options));
}
}, {
key: 'mergeNonInitialChunks',
value: function mergeNonInitialChunks(chunk, intoChunk, checkedChunks) {
var _this = this;
if (!intoChunk) {
checkedChunks = [];
chunk.chunks.forEach(function (c) {
if ((0, _helpers.isInitialOrHasNoParents)(c)) return;
_this.mergeNonInitialChunks(c, chunk, checkedChunks);
}, this);
} else if (checkedChunks.indexOf(chunk) < 0) {
checkedChunks.push(chunk);
chunk.forEachModule(function (module) {
intoChunk.addModule(module);
module.addChunk(intoChunk);
});
chunk.chunks.forEach(function (c) {
if ((0, _helpers.isInitialOrHasNoParents)(c)) return;
_this.mergeNonInitialChunks(c, intoChunk, checkedChunks);
}, this);
}
}
}, {
key: 'renderExtractedChunk',
value: function renderExtractedChunk(chunk) {
var _this2 = this;
var source = new _webpackSources.ConcatSource();
chunk.forEachModule(function (module) {
var moduleSource = module.source();
source.add(_this2.applyAdditionalInformation(moduleSource, module.additionalInformation));
}, this);
return source;
}
}, {
key: 'extract',
value: function extract(options) {
if (Array.isArray(options) || (0, _helpers.isString)(options) || typeof options.options === 'object' || typeof options.query === 'object') {
options = { use: options };
} else {
(0, _schemaUtils2.default)(_path2.default.resolve(__dirname, '../schema/loader.json'), options, 'Extract Text Plugin (Loader)');
}
var loader = options.use;
var before = options.fallback || [];
if ((0, _helpers.isString)(loader)) {
loader = loader.split('!');
}
if ((0, _helpers.isString)(before)) {
before = before.split('!');
} else if (!Array.isArray(before)) {
before = [before];
}
options = (0, _helpers.mergeOptions)({ omit: before.length, remove: true }, options);
delete options.use;
delete options.fallback;
return [this.loader(options)].concat(before, loader).map(_helpers.getLoaderObject);
}
}, {
key: 'apply',
value: function apply(compiler) {
var _this3 = this;
var options = this.options;
compiler.plugin('this-compilation', function (compilation) {
var extractCompilation = new _ExtractTextPluginCompilation2.default();
compilation.plugin('normal-module-loader', function (loaderContext, module) {
loaderContext[NS] = function (content, opt) {
if (options.disable) {
return false;
}
if (!Array.isArray(content) && content != null) {
throw new Error(`Exported value was not extracted as an array: ${JSON.stringify(content)}`);
}
module[NS] = {
content,
options: opt || {}
};
return options.allChunks || module[`${NS}/extract`]; // eslint-disable-line no-path-concat
};
});
var filename = _this3.filename;
var id = _this3.id;
var extractedChunks = void 0;
compilation.plugin('optimize-tree', function (chunks, modules, callback) {
extractedChunks = chunks.map(function () {
return new _Chunk2.default();
});
chunks.forEach(function (chunk, i) {
var extractedChunk = extractedChunks[i];
extractedChunk.index = i;
extractedChunk.originalChunk = chunk;
extractedChunk.name = chunk.name;
extractedChunk.entrypoints = chunk.entrypoints;
chunk.chunks.forEach(function (c) {
extractedChunk.addChunk(extractedChunks[chunks.indexOf(c)]);
});
chunk.parents.forEach(function (c) {
extractedChunk.addParent(extractedChunks[chunks.indexOf(c)]);
});
});
_async2.default.forEach(chunks, function (chunk, callback) {
// eslint-disable-line no-shadow
var extractedChunk = extractedChunks[chunks.indexOf(chunk)];
var shouldExtract = !!(options.allChunks || (0, _helpers.isInitialOrHasNoParents)(chunk));
chunk.sortModules();
_async2.default.forEach(chunk.mapModules(function (c) {
return c;
}), function (module, callback) {
// eslint-disable-line no-shadow
var meta = module[NS];
if (meta && (!meta.options.id || meta.options.id === id)) {
var wasExtracted = Array.isArray(meta.content);
// A stricter `shouldExtract !== wasExtracted` check to guard against cases where a previously extracted
// module would be extracted twice. Happens when a module is a dependency of an initial and a non-initial
// chunk. See issue #604
if (shouldExtract && !wasExtracted) {
module[`${NS}/extract`] = shouldExtract; // eslint-disable-line no-path-concat
compilation.rebuildModule(module, function (err) {
if (err) {
compilation.errors.push(err);
return callback();
}
meta = module[NS];
// Error out if content is not an array and is not null
if (!Array.isArray(meta.content) && meta.content != null) {
err = new Error(`${module.identifier()} doesn't export content`);
compilation.errors.push(err);
return callback();
}
if (meta.content) {
extractCompilation.addResultToChunk(module.identifier(), meta.content, module, extractedChunk);
}
callback();
});
} else {
if (meta.content) {
extractCompilation.addResultToChunk(module.identifier(), meta.content, module, extractedChunk);
}
callback();
}
} else callback();
}, function (err) {
if (err) return callback(err);
callback();
});
}, function (err) {
if (err) return callback(err);
extractedChunks.forEach(function (extractedChunk) {
if ((0, _helpers.isInitialOrHasNoParents)(extractedChunk)) {
_this3.mergeNonInitialChunks(extractedChunk);
}
}, _this3);
extractedChunks.forEach(function (extractedChunk) {
if (!(0, _helpers.isInitialOrHasNoParents)(extractedChunk)) {
extractedChunk.forEachModule(function (module) {
extractedChunk.removeModule(module);
});
}
});
compilation.applyPlugins('optimize-extracted-chunks', extractedChunks);
callback();
});
});
compilation.plugin('additional-assets', function (callback) {
extractedChunks.forEach(function (extractedChunk) {
if (extractedChunk.getNumberOfModules()) {
extractedChunk.sortModules(function (a, b) {
if (!options.ignoreOrder && (0, _helpers.isInvalidOrder)(a, b)) {
compilation.errors.push(new _OrderUndefinedError2.default(a.getOriginalModule()));
compilation.errors.push(new _OrderUndefinedError2.default(b.getOriginalModule()));
}
return (0, _helpers.getOrder)(a, b);
});
var chunk = extractedChunk.originalChunk;
var source = _this3.renderExtractedChunk(extractedChunk);
var getPath = function getPath(format) {
return compilation.getPath(format, {
chunk
}).replace(/\[(?:(\w+):)?contenthash(?::([a-z]+\d*))?(?::(\d+))?\]/ig, function () {
// eslint-disable-line func-names
return _loaderUtils2.default.getHashDigest(source.source(), arguments[1], arguments[2], parseInt(arguments[3], 10));
});
};
var file = (0, _helpers.isFunction)(filename) ? filename(getPath) : getPath(filename);
compilation.assets[file] = source;
chunk.files.push(file);
}
}, _this3);
callback();
});
});
}
}], [{
key: 'loader',
value: function loader(options) {
return { loader: require.resolve('./loader'), options };
}
}]);
return ExtractTextPlugin;
}();
ExtractTextPlugin.extract = ExtractTextPlugin.prototype.extract.bind(ExtractTextPlugin);
exports.default = ExtractTextPlugin;

View File

@@ -0,0 +1,64 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); /* eslint-disable no-multi-assign */
var _ExtractedModule = require('./ExtractedModule');
var _ExtractedModule2 = _interopRequireDefault(_ExtractedModule);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var ExtractTextPluginCompilation = function () {
function ExtractTextPluginCompilation() {
_classCallCheck(this, ExtractTextPluginCompilation);
this.modulesByIdentifier = {};
}
_createClass(ExtractTextPluginCompilation, [{
key: 'addModule',
value: function addModule(identifier, originalModule, source, additionalInformation, sourceMap, prevModules) {
var m = void 0;
if (!this.modulesByIdentifier[identifier]) {
m = this.modulesByIdentifier[identifier] = new _ExtractedModule2.default(identifier, originalModule, source, sourceMap, additionalInformation, prevModules);
} else {
m = this.modulesByIdentifier[identifier];
m.addPrevModules(prevModules);
if (originalModule.index2 < m.getOriginalModule().index2) {
m.setOriginalModule(originalModule);
}
}
return m;
}
}, {
key: 'addResultToChunk',
value: function addResultToChunk(identifier, result, originalModule, extractedChunk) {
var _this = this;
if (!Array.isArray(result)) {
result = [[identifier, result]];
}
var counterMap = {};
var prevModules = [];
result.forEach(function (item) {
var c = counterMap[item[0]];
var module = _this.addModule.call(_this, item[0] + (c || ''), originalModule, item[1], item[2], item[3], prevModules.slice());
extractedChunk.addModule(module);
module.addChunk(extractedChunk);
counterMap[item[0]] = (c || 0) + 1;
prevModules.push(module);
}, this);
}
}]);
return ExtractTextPluginCompilation;
}();
exports.default = ExtractTextPluginCompilation;

View File

@@ -0,0 +1,100 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _webpackSources = require('webpack-sources');
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var ExtractedModule = function () {
function ExtractedModule(identifier, originalModule, source, sourceMap, addtitionalInformation, prevModules) {
_classCallCheck(this, ExtractedModule);
this._identifier = identifier;
this._originalModule = originalModule;
this._source = source;
this._sourceMap = sourceMap;
this._prevModules = prevModules;
this.addtitionalInformation = addtitionalInformation;
this.chunks = [];
}
_createClass(ExtractedModule, [{
key: 'getOrder',
value: function getOrder() {
// http://stackoverflow.com/a/14676665/1458162
return (/^@import url/.test(this._source) ? 0 : 1
);
}
}, {
key: 'addChunk',
value: function addChunk(chunk) {
var idx = this.chunks.indexOf(chunk);
if (idx < 0) {
this.chunks.push(chunk);
}
}
}, {
key: 'removeChunk',
value: function removeChunk(chunk) {
var idx = this.chunks.indexOf(chunk);
if (idx >= 0) {
this.chunks.splice(idx, 1);
chunk.removeModule(this);
return true;
}
return false;
}
}, {
key: 'rewriteChunkInReasons',
value: function rewriteChunkInReasons(oldChunk, newChunks) {} // eslint-disable-line
}, {
key: 'identifier',
value: function identifier() {
return this._identifier;
}
}, {
key: 'source',
value: function source() {
if (this._sourceMap) {
return new _webpackSources.SourceMapSource(this._source, null, this._sourceMap);
}
return new _webpackSources.RawSource(this._source);
}
}, {
key: 'getOriginalModule',
value: function getOriginalModule() {
return this._originalModule;
}
}, {
key: 'getPrevModules',
value: function getPrevModules() {
return this._prevModules;
}
}, {
key: 'addPrevModules',
value: function addPrevModules(prevModules) {
var _this = this;
prevModules.forEach(function (m) {
if (_this._prevModules.indexOf(m) < 0) {
_this._prevModules.push(m);
}
}, this);
}
}, {
key: 'setOriginalModule',
value: function setOriginalModule(originalModule) {
this._originalModule = originalModule;
}
}]);
return ExtractedModule;
}();
exports.default = ExtractedModule;

View File

@@ -0,0 +1,16 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
function OrderUndefinedError(module) {
Error.call(this);
Error.captureStackTrace(this, OrderUndefinedError);
this.name = 'OrderUndefinedError';
this.message = 'Order in extracted chunk undefined';
this.module = module;
}
exports.default = OrderUndefinedError;
OrderUndefinedError.prototype = Object.create(Error.prototype);

View File

@@ -0,0 +1,69 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.isInitialOrHasNoParents = isInitialOrHasNoParents;
exports.isInvalidOrder = isInvalidOrder;
exports.getOrder = getOrder;
exports.getLoaderObject = getLoaderObject;
exports.mergeOptions = mergeOptions;
exports.isString = isString;
exports.isFunction = isFunction;
exports.isType = isType;
function isInitialOrHasNoParents(chunk) {
return chunk.isInitial() || chunk.parents.length === 0;
}
function isInvalidOrder(a, b) {
var bBeforeA = a.getPrevModules().indexOf(b) >= 0;
var aBeforeB = b.getPrevModules().indexOf(a) >= 0;
return aBeforeB && bBeforeA;
}
function getOrder(a, b) {
var aOrder = a.getOrder();
var bOrder = b.getOrder();
if (aOrder < bOrder) return -1;
if (aOrder > bOrder) return 1;
var aIndex = a.getOriginalModule().index2;
var bIndex = b.getOriginalModule().index2;
if (aIndex < bIndex) return -1;
if (aIndex > bIndex) return 1;
var bBeforeA = a.getPrevModules().indexOf(b) >= 0;
var aBeforeB = b.getPrevModules().indexOf(a) >= 0;
if (aBeforeB && !bBeforeA) return -1;
if (!aBeforeB && bBeforeA) return 1;
var ai = a.identifier();
var bi = b.identifier();
if (ai < bi) return -1;
if (ai > bi) return 1;
return 0;
}
function getLoaderObject(loader) {
if (isString(loader)) {
return { loader };
}
return loader;
}
function mergeOptions(a, b) {
if (!b) return a;
Object.keys(b).forEach(function (key) {
a[key] = b[key];
});
return a;
}
function isString(a) {
return typeof a === 'string';
}
function isFunction(a) {
return typeof a === 'function';
}
function isType(type, obj) {
return Object.prototype.toString.call(obj) === `[object ${type}]`;
}

View File

@@ -0,0 +1,158 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.pitch = pitch;
var _fs = require('fs');
var _fs2 = _interopRequireDefault(_fs);
var _path = require('path');
var _path2 = _interopRequireDefault(_path);
var _loaderUtils = require('loader-utils');
var _loaderUtils2 = _interopRequireDefault(_loaderUtils);
var _NodeTemplatePlugin = require('webpack/lib/node/NodeTemplatePlugin');
var _NodeTemplatePlugin2 = _interopRequireDefault(_NodeTemplatePlugin);
var _NodeTargetPlugin = require('webpack/lib/node/NodeTargetPlugin');
var _NodeTargetPlugin2 = _interopRequireDefault(_NodeTargetPlugin);
var _LibraryTemplatePlugin = require('webpack/lib/LibraryTemplatePlugin');
var _LibraryTemplatePlugin2 = _interopRequireDefault(_LibraryTemplatePlugin);
var _SingleEntryPlugin = require('webpack/lib/SingleEntryPlugin');
var _SingleEntryPlugin2 = _interopRequireDefault(_SingleEntryPlugin);
var _LimitChunkCountPlugin = require('webpack/lib/optimize/LimitChunkCountPlugin');
var _LimitChunkCountPlugin2 = _interopRequireDefault(_LimitChunkCountPlugin);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var NS = _path2.default.dirname(_fs2.default.realpathSync(__filename));
exports.default = function (source) {
return source;
};
function pitch(request) {
var _this = this;
var query = _loaderUtils2.default.getOptions(this) || {};
var loaders = this.loaders.slice(this.loaderIndex + 1);
this.addDependency(this.resourcePath);
// We already in child compiler, return empty bundle
if (this[NS] === undefined) {
// eslint-disable-line no-undefined
throw new Error('"extract-text-webpack-plugin" loader is used without the corresponding plugin, ' + 'refer to https://github.com/webpack/extract-text-webpack-plugin for the usage example');
} else if (this[NS] === false) {
return '';
} else if (this[NS](null, query)) {
if (query.omit) {
this.loaderIndex += +query.omit + 1;
request = request.split('!').slice(+query.omit).join('!');
loaders = loaders.slice(+query.omit);
}
var resultSource = void 0;
if (query.remove) {
resultSource = '// removed by extract-text-webpack-plugin';
} else {
resultSource = undefined; // eslint-disable-line no-undefined
}
var childFilename = 'extract-text-webpack-plugin-output-filename'; // eslint-disable-line no-path-concat
var publicPath = typeof query.publicPath === 'string' ? query.publicPath : this._compilation.outputOptions.publicPath;
var outputOptions = {
filename: childFilename,
publicPath
};
var childCompiler = this._compilation.createChildCompiler(`extract-text-webpack-plugin ${NS} ${request}`, outputOptions);
childCompiler.apply(new _NodeTemplatePlugin2.default(outputOptions));
childCompiler.apply(new _LibraryTemplatePlugin2.default(null, 'commonjs2'));
childCompiler.apply(new _NodeTargetPlugin2.default());
childCompiler.apply(new _SingleEntryPlugin2.default(this.context, `!!${request}`));
childCompiler.apply(new _LimitChunkCountPlugin2.default({ maxChunks: 1 }));
// We set loaderContext[NS] = false to indicate we already in
// a child compiler so we don't spawn another child compilers from there.
childCompiler.plugin('this-compilation', function (compilation) {
compilation.plugin('normal-module-loader', function (loaderContext, module) {
loaderContext[NS] = false;
if (module.request === request) {
module.loaders = loaders.map(function (loader) {
return {
loader: loader.path,
options: loader.options
};
});
}
});
});
var source = void 0;
childCompiler.plugin('after-compile', function (compilation, callback) {
source = compilation.assets[childFilename] && compilation.assets[childFilename].source();
// Remove all chunk assets
compilation.chunks.forEach(function (chunk) {
chunk.files.forEach(function (file) {
delete compilation.assets[file];
});
});
callback();
});
var callback = this.async();
childCompiler.runAsChild(function (err, entries, compilation) {
if (err) return callback(err);
if (compilation.errors.length > 0) {
return callback(compilation.errors[0]);
}
compilation.fileDependencies.forEach(function (dep) {
_this.addDependency(dep);
}, _this);
compilation.contextDependencies.forEach(function (dep) {
_this.addContextDependency(dep);
}, _this);
if (!source) {
return callback(new Error("Didn't get a result from child compiler"));
}
try {
var text = _this.exec(source, request);
if (typeof text === 'string') {
text = [[compilation.entries[0].identifier(), text]];
} else {
text.forEach(function (item) {
var id = item[0];
compilation.modules.forEach(function (module) {
if (module.id === id) {
item[0] = module.identifier();
}
});
});
}
_this[NS](text, query);
if (text.locals && typeof resultSource !== 'undefined') {
resultSource += `\nmodule.exports = ${JSON.stringify(text.locals)};`;
}
} catch (e) {
return callback(e);
}
if (resultSource) {
callback(null, resultSource);
} else {
callback();
}
});
}
}