This commit is contained in:
Iliyan Angelov
2025-09-14 23:24:25 +03:00
commit c67067a2a4
71311 changed files with 6800714 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
import webpack, { AssetInfo, Chunk } from 'webpack';
import { InternalOptions, Manifest } from './';
export interface FileDescriptor {
chunk?: ProperChunk;
isAsset: Boolean;
isChunk: Boolean;
isInitial: Boolean;
isModuleAsset: Boolean;
name: string;
path: string;
}
export interface CompilationAssetInfo extends AssetInfo {
sourceFilename: string;
}
export interface CompilationAsset extends webpack.compilation.Asset {
chunks: any[];
info: CompilationAssetInfo;
}
export interface ProperChunk extends Chunk {
auxiliaryFiles: any[];
}
declare const generateManifest: (compilation: webpack.compilation.Compilation, files: FileDescriptor[], { generate, seed }: InternalOptions) => Manifest;
declare const reduceAssets: (files: FileDescriptor[], asset: CompilationAsset, moduleAssets: Record<any, any>) => FileDescriptor[];
declare const reduceChunk: (files: FileDescriptor[], chunk: ProperChunk, options: InternalOptions, auxiliaryFiles: Record<any, any>) => FileDescriptor[];
declare const transformFiles: (files: FileDescriptor[], options: InternalOptions) => FileDescriptor[];
export { generateManifest, reduceAssets, reduceChunk, transformFiles };

View File

@@ -0,0 +1,97 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.transformFiles = exports.reduceChunk = exports.reduceAssets = exports.generateManifest = void 0;
const path_1 = require("path");
const generateManifest = (compilation, files, { generate, seed = {} }) => {
let result;
if (generate) {
const entrypointsArray = Array.from(compilation.entrypoints.entries());
const entrypoints = entrypointsArray.reduce((e, [name, entrypoint]) => Object.assign(e, { [name]: entrypoint.getFiles() }), {});
result = generate(seed, files, entrypoints);
}
else {
result = files.reduce((manifest, file) => Object.assign(manifest, { [file.name]: file.path }), seed);
}
return result;
};
exports.generateManifest = generateManifest;
const getFileType = (fileName, { transformExtensions }) => {
const replaced = fileName.replace(/\?.*/, '');
const split = replaced.split('.');
const extension = split.pop();
return transformExtensions.test(extension) ? `${split.pop()}.${extension}` : extension;
};
const reduceAssets = (files, asset, moduleAssets) => {
let name;
if (moduleAssets[asset.name]) {
name = moduleAssets[asset.name];
}
else if (asset.info.sourceFilename) {
name = path_1.join(path_1.dirname(asset.name), path_1.basename(asset.info.sourceFilename));
}
if (name) {
return files.concat({
isAsset: true,
isChunk: false,
isInitial: false,
isModuleAsset: true,
name,
path: asset.name
});
}
const isEntryAsset = asset.chunks && asset.chunks.length > 0;
if (isEntryAsset) {
return files;
}
return files.concat({
isAsset: true,
isChunk: false,
isInitial: false,
isModuleAsset: false,
name: asset.name,
path: asset.name
});
};
exports.reduceAssets = reduceAssets;
const reduceChunk = (files, chunk, options, auxiliaryFiles) => {
Array.from(chunk.auxiliaryFiles || []).forEach((auxiliaryFile) => {
auxiliaryFiles[auxiliaryFile] = {
isAsset: true,
isChunk: false,
isInitial: false,
isModuleAsset: true,
name: path_1.basename(auxiliaryFile),
path: auxiliaryFile
};
});
return Array.from(chunk.files).reduce((prev, path) => {
let name = chunk.name ? chunk.name : null;
name = name
? options.useEntryKeys && !path.endsWith('.map')
? name
: `${name}.${getFileType(path, options)}`
: path;
return prev.concat({
chunk,
isAsset: false,
isChunk: true,
isInitial: chunk.isOnlyInitial(),
isModuleAsset: false,
name,
path
});
}, files);
};
exports.reduceChunk = reduceChunk;
const standardizeFilePaths = (file) => {
const result = Object.assign({}, file);
result.name = file.name.replace(/\\/g, '/');
result.path = file.path.replace(/\\/g, '/');
return result;
};
const transformFiles = (files, options) => ['filter', 'map', 'sort']
.filter((fname) => !!options[fname])
.reduce((prev, fname) => prev[fname](options[fname]), files)
.map(standardizeFilePaths);
exports.transformFiles = transformFiles;
//# sourceMappingURL=helpers.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":";;;AAAA,+BAA+C;AA+B/C,MAAM,gBAAgB,GAAG,CACvB,WAA4C,EAC5C,KAAuB,EACvB,EAAE,QAAQ,EAAE,IAAI,GAAG,EAAE,EAAmB,EACxC,EAA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AC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAC5C,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAEF,MAAM,cAAc,GAAG,CAAC,KAAuB,EAAE,OAAwB,EAAE,EAAE,CAC3E,CAAC,QAAQ,EAAE,KAAK,EAAE,MAAM,CAAC;KACtB,MAAM,CAAC,CAAC,KAAa,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;KAE3C,MAAM,CAGL,CAAC,IAAI,EAAE,KAAa,EAAE,EAAE,CAAE,IAA4C,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAC7F,KAAK,CACN;KACA,GAAG,CAAC,oBAAoB,CAAC,CAAC;AAEuB,wCAAc"}

View File

@@ -0,0 +1,24 @@
import webpack, { Compiler, Module } from 'webpack';
import { EmitCountMap, InternalOptions } from './';
interface BeforeRunHookArgs {
emitCountMap: EmitCountMap;
manifestFileName: string;
}
interface EmitHookArgs {
compiler: Compiler;
emitCountMap: EmitCountMap;
manifestAssetId: string;
manifestFileName: string;
moduleAssets: Record<any, any>;
options: InternalOptions;
}
declare const getCompilerHooks: (compiler: Compiler) => any;
declare const beforeRunHook: ({ emitCountMap, manifestFileName }: BeforeRunHookArgs, _: Compiler, callback: Function) => void;
declare const emitHook: ({ compiler, emitCountMap, manifestAssetId, manifestFileName, moduleAssets, options }: EmitHookArgs, compilation: webpack.compilation.Compilation) => void;
interface LegacyModule extends Module {
userRequest?: any;
}
declare const normalModuleLoaderHook: ({ moduleAssets }: {
moduleAssets: Record<any, any>;
}, loaderContext: webpack.loader.LoaderContext, module: LegacyModule) => void;
export { beforeRunHook, emitHook, getCompilerHooks, normalModuleLoaderHook };

View File

@@ -0,0 +1,96 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.normalModuleLoaderHook = exports.getCompilerHooks = exports.emitHook = exports.beforeRunHook = void 0;
const fs_1 = require("fs");
const path_1 = require("path");
const tapable_1 = require("tapable");
const webpack_sources_1 = require("webpack-sources");
const helpers_1 = require("./helpers");
const compilerHookMap = new WeakMap();
const getCompilerHooks = (compiler) => {
let hooks = compilerHookMap.get(compiler);
if (typeof hooks === 'undefined') {
hooks = {
afterEmit: new tapable_1.SyncWaterfallHook(['manifest']),
beforeEmit: new tapable_1.SyncWaterfallHook(['manifest'])
};
compilerHookMap.set(compiler, hooks);
}
return hooks;
};
exports.getCompilerHooks = getCompilerHooks;
const beforeRunHook = ({ emitCountMap, manifestFileName }, _, callback) => {
const emitCount = emitCountMap.get(manifestFileName) || 0;
emitCountMap.set(manifestFileName, emitCount + 1);
if (callback) {
callback();
}
};
exports.beforeRunHook = beforeRunHook;
const emitHook = function emit({ compiler, emitCountMap, manifestAssetId, manifestFileName, moduleAssets, options }, compilation) {
const emitCount = emitCountMap.get(manifestFileName) - 1;
const stats = compilation.getStats().toJson({
all: false,
assets: true,
cachedAssets: true,
ids: true,
publicPath: true
});
const publicPath = options.publicPath !== null ? options.publicPath : stats.publicPath;
const { basePath, removeKeyHash } = options;
emitCountMap.set(manifestFileName, emitCount);
const auxiliaryFiles = {};
let files = Array.from(compilation.chunks).reduce((prev, chunk) => helpers_1.reduceChunk(prev, chunk, options, auxiliaryFiles), []);
files = stats.assets.reduce((prev, asset) => helpers_1.reduceAssets(prev, asset, moduleAssets), files);
files = files.filter(({ name, path }) => {
var _a;
return !path.includes('hot-update') &&
typeof emitCountMap.get(path_1.join(((_a = compiler.options.output) === null || _a === void 0 ? void 0 : _a.path) || '<unknown>', name)) ===
'undefined';
});
files.forEach((file) => {
delete auxiliaryFiles[file.path];
});
Object.keys(auxiliaryFiles).forEach((auxiliaryFile) => {
files = files.concat(auxiliaryFiles[auxiliaryFile]);
});
files = files.map((file) => {
const normalizePath = (path) => {
if (!path.endsWith('/')) {
return `${path}/`;
}
return path;
};
const changes = {
name: basePath ? normalizePath(basePath) + file.name : file.name,
path: publicPath ? normalizePath(publicPath) + file.path : file.path
};
changes.name = removeKeyHash ? changes.name.replace(removeKeyHash, '') : changes.name;
return Object.assign(file, changes);
});
files = helpers_1.transformFiles(files, options);
let manifest = helpers_1.generateManifest(compilation, files, options);
const isLastEmit = emitCount === 0;
manifest = getCompilerHooks(compiler).beforeEmit.call(manifest);
if (isLastEmit) {
const output = options.serialize(manifest);
compilation.emitAsset(manifestAssetId, new webpack_sources_1.RawSource(output));
if (options.writeToFileEmit) {
fs_1.mkdirSync(path_1.dirname(manifestFileName), { recursive: true });
fs_1.writeFileSync(manifestFileName, output);
}
}
getCompilerHooks(compiler).afterEmit.call(manifest);
};
exports.emitHook = emitHook;
const normalModuleLoaderHook = ({ moduleAssets }, loaderContext, module) => {
const { emitFile } = loaderContext;
loaderContext.emitFile = (file, content, sourceMap) => {
if (module.userRequest && !moduleAssets[file]) {
Object.assign(moduleAssets, { [file]: path_1.join(path_1.dirname(file), path_1.basename(module.userRequest)) });
}
return emitFile.call(module, file, content, sourceMap);
};
};
exports.normalModuleLoaderHook = normalModuleLoaderHook;
//# sourceMappingURL=hooks.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":";;;AAAA,2BAA8C;AAC9C,+BAA+C;AAE/C,qCAA4C;AAI5C,qDAA4C;AAI5C,uCAOmB;AAwBnB,MAAM,eAAe,GAAG,IAAI,OAAO,EAAE,CAAC;AAEtC,MAAM,gBAAgB,GAAG,CAAC,QAAkB,EAAE,EAAE;IAC9C,IAAI,KAAK,GAAG,eAAe,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC1C,IAAI,OAAO,KAAK,KAAK,WAAW,EAAE;QAChC,KAAK,GAAG;YACN,SAAS,EAAE,IAAI,2BAAiB,CAAC,CAAC,UAAU,CAAC,CAAC;YAC9C,UAAU,EAAE,IAAI,2BAAiB,CAAC,CAAC,UAAU,CAAC,CAAC;SAChD,CAAC;QACF,eAAe,CAAC,GAAG,CAAC,QAAQ,EAAE,KAA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AAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AACtD,CAAC,CAAC;AAuBsB,4BAAQ;AAjBhC,MAAM,sBAAsB,GAAG,CAC7B,EAAE,YAAY,EAAsC,EACpD,aAA2C,EAC3C,MAAoB,EACpB,EAAE;IACF,MAAM,EAAE,QAAQ,EAAE,GAAG,aAAa,CAAC;IAGnC,aAAa,CAAC,QAAQ,GAAG,CAAC,IAAY,EAAE,OAAe,EAAE,SAAc,EAAE,EAAE;QACzE,IAAI,MAAM,CAAC,WAAW,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE;YAC7C,MAAM,CAAC,MAAM,CAAC,YAAY,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,WAAI,CAAC,cAAO,CAAC,IAAI,CAAC,EAAE,eAAQ,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC;SAC5F;QAED,OAAO,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;IACzD,CAAC,CAAC;AACJ,CAAC,CAAC;AAEkD,wDAAsB"}

View File

@@ -0,0 +1,30 @@
import { Compiler, WebpackPluginInstance } from 'webpack';
import { FileDescriptor } from './helpers';
import { getCompilerHooks } from './hooks';
export declare type Manifest = Record<string, any>;
export interface InternalOptions {
[key: string]: any;
assetHookStage: number;
basePath: string;
fileName: string;
filter: (file: FileDescriptor) => Boolean;
generate: (seed: Record<any, any>, files: FileDescriptor[], entries: Record<string, string[]>) => Manifest;
map: (file: FileDescriptor) => FileDescriptor;
publicPath: string;
removeKeyHash: RegExp | false;
seed: Record<any, any>;
serialize: (manifest: Manifest) => string;
sort: (fileA: FileDescriptor, fileB: FileDescriptor) => Number;
transformExtensions: RegExp;
useEntryKeys: Boolean;
useLegacyEmit: Boolean;
writeToFileEmit: Boolean;
}
export declare type ManifestPluginOptions = Partial<InternalOptions>;
export declare type EmitCountMap = Map<any, any>;
declare class WebpackManifestPlugin implements WebpackPluginInstance {
private options;
constructor(opts: ManifestPluginOptions);
apply(compiler: Compiler): void;
}
export { getCompilerHooks, WebpackManifestPlugin };

View File

@@ -0,0 +1,74 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.WebpackManifestPlugin = exports.getCompilerHooks = void 0;
const path_1 = require("path");
const webpack_1 = __importDefault(require("webpack"));
const NormalModule_1 = __importDefault(require("webpack/lib/NormalModule"));
const hooks_1 = require("./hooks");
Object.defineProperty(exports, "getCompilerHooks", { enumerable: true, get: function () { return hooks_1.getCompilerHooks; } });
const emitCountMap = new Map();
const defaults = {
assetHookStage: Infinity,
basePath: '',
fileName: 'manifest.json',
filter: null,
generate: void 0,
map: null,
publicPath: null,
removeKeyHash: /([a-f0-9]{16,32}\.?)/gi,
seed: void 0,
serialize(manifest) {
return JSON.stringify(manifest, null, 2);
},
sort: null,
transformExtensions: /^(gz|map)$/i,
useEntryKeys: false,
useLegacyEmit: false,
writeToFileEmit: false
};
class WebpackManifestPlugin {
constructor(opts) {
this.options = Object.assign({}, defaults, opts);
}
apply(compiler) {
var _a, _b, _c;
const moduleAssets = {};
const manifestFileName = path_1.resolve(((_a = compiler.options.output) === null || _a === void 0 ? void 0 : _a.path) || './', this.options.fileName);
const manifestAssetId = path_1.relative(((_b = compiler.options.output) === null || _b === void 0 ? void 0 : _b.path) || './', manifestFileName);
const beforeRun = hooks_1.beforeRunHook.bind(this, { emitCountMap, manifestFileName });
const emit = hooks_1.emitHook.bind(this, {
compiler,
emitCountMap,
manifestAssetId,
manifestFileName,
moduleAssets,
options: this.options
});
const normalModuleLoader = hooks_1.normalModuleLoaderHook.bind(this, { moduleAssets });
const hookOptions = {
name: 'WebpackManifestPlugin',
stage: this.options.assetHookStage
};
compiler.hooks.compilation.tap(hookOptions, (compilation) => {
const hook = !NormalModule_1.default.getCompilationHooks
? compilation.hooks.normalModuleLoader
: NormalModule_1.default.getCompilationHooks(compilation).loader;
hook.tap(hookOptions, normalModuleLoader);
});
if (((_c = webpack_1.default.version) === null || _c === void 0 ? void 0 : _c.startsWith('4')) || this.options.useLegacyEmit === true) {
compiler.hooks.emit.tap(hookOptions, emit);
}
else {
compiler.hooks.thisCompilation.tap(hookOptions, (compilation) => {
compilation.hooks.processAssets.tap(hookOptions, () => emit(compilation));
});
}
compiler.hooks.run.tap(hookOptions, beforeRun);
compiler.hooks.watchRun.tap(hookOptions, beforeRun);
}
}
exports.WebpackManifestPlugin = WebpackManifestPlugin;
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,+BAAyC;AAGzC,sDAAmE;AAEnE,4EAAoD;AAGpD,mCAA4F;AAyGnF,iGAzGyB,wBAAgB,OAyGzB;AAvGzB,MAAM,YAAY,GAAiB,IAAI,GAAG,EAAE,CAAC;AA6B7C,MAAM,QAAQ,GAAG;IACf,cAAc,EAAE,QAAQ;IACxB,QAAQ,EAAE,EAAE;IACZ,QAAQ,EAAE,eAAe;IACzB,MAAM,EAAE,IAAI;IACZ,QAAQ,EAAE,KAAK,CAAC;IAChB,GAAG,EAAE,IAAI;IACT,UAAU,EAAE,IAAI;IAChB,aAAa,EAAE,wBAAwB;IAEvC,IAAI,EAAE,KAAK,CAAC;IACZ,SAAS,CAAC,QAAa;QACrB,OAAO,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IAC3C,CAAC;IACD,IAAI,EAAE,IAAI;IACV,mBAAmB,EAAE,aAAa;IAClC,YAAY,EAAE,KAAK;IACnB,aAAa,EAAE,KAAK;IACpB,eAAe,EAAE,KAAK;CACvB,CAAC;AAQF,MAAM,qBAAqB;IAEzB,YAAY,IAA2B;QACrC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,QAAQ,E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