time-analytics-webpack-plugin
Advanced tools
Comparing version
@@ -124,3 +124,3 @@ import { groupBy, path, prop } from 'ramda'; | ||
initilize() { | ||
assert(this._isInitilized === false, '${PACKAGE_NAME} is initialized twice, why do you do this? Please submit an issue.'); | ||
assert(this._isInitilized === false, '${PACKAGE_NAME} is initialized twice. This should be a bug if it is not intentional. Please submit an issue.'); | ||
this._isInitilized = true; | ||
@@ -161,3 +161,3 @@ } | ||
Writer.foo(tmp1, tmp2, tmp3, option); | ||
Writer.writeResult(tmp1, tmp2, tmp3, option); | ||
@@ -164,0 +164,0 @@ this.clear(); |
@@ -52,3 +52,3 @@ "use strict"; | ||
initilize() { | ||
(0, utils_1.assert)(this._isInitilized === false, '${PACKAGE_NAME} is initialized twice, why do you do this? Please submit an issue.'); | ||
(0, utils_1.assert)(this._isInitilized === false, '${PACKAGE_NAME} is initialized twice. This should be a bug if it is not intentional. Please submit an issue.'); | ||
this._isInitilized = true; | ||
@@ -77,3 +77,3 @@ } | ||
const tmp3 = analyticsOutputLoaderInfos(this.loaderData, { ignoredLoaders: option.ignoredLoaders }); | ||
writer_1.Writer.foo(tmp1, tmp2, tmp3, option); | ||
writer_1.Writer.writeResult(tmp1, tmp2, tmp3, option); | ||
this.clear(); | ||
@@ -80,0 +80,0 @@ } |
@@ -151,3 +151,3 @@ "use strict"; | ||
if (typeof module !== 'function' && typeof module !== 'object') { | ||
throw new Error('Bad loader, time analytics plugin is using the same checek as webpack. However, it does not provide more info, disable it to see error from webpack itself.'); | ||
throw new Error('Time analytics plugin tries to use the same checek as webpack, you see this error because Time analytics plugin think it should be a bug which should also be existed in webpack.'); | ||
} | ||
@@ -154,0 +154,0 @@ // get normal loader function according to module is mjs or cjs |
@@ -29,3 +29,3 @@ "use strict"; | ||
exports.getLoaderName = getLoaderName; | ||
function normalizeRuleCore(rule) { | ||
function normalizeRule(rule) { | ||
if (rule.loader) { | ||
@@ -57,8 +57,2 @@ rule.use = [rule.loader]; | ||
} | ||
function normalizeRule(rule) { | ||
if (!rule) { | ||
return rule; | ||
} | ||
return normalizeRuleCore(rule); | ||
} | ||
function normalizeRules(rules) { | ||
@@ -69,3 +63,3 @@ if (!rules) { | ||
if (Array.isArray(rules)) | ||
return rules.map(normalizeRuleCore); | ||
return rules.map(normalizeRule); | ||
return rules; | ||
@@ -72,0 +66,0 @@ } |
@@ -14,2 +14,11 @@ "use strict"; | ||
class ProxyPlugin { | ||
validatePluginIsUsedOnce(plugin) { | ||
const pluginName = plugin.constructor.name; | ||
if (this.injectedPluginNames.has(pluginName)) { | ||
utils_1.ConsoleHelper.warn(`${pluginName} is used twice, are you sure you really want to do this?`); | ||
} | ||
else { | ||
this.injectedPluginNames.add(pluginName); | ||
} | ||
} | ||
constructor(proxiedPlugin) { | ||
@@ -19,2 +28,3 @@ this.injectedPluginNames = new Set(); | ||
this.cachedProxyForHooksProvider = new Map(); | ||
this.cachedUnfrozenHooks = new Map(); | ||
this.cachedProxyForHooks = new Map(); | ||
@@ -32,21 +42,8 @@ this.cachedProxyForHookMap = new Map(); | ||
} | ||
validatePluginIsUsedOnce(plugin) { | ||
const pluginName = plugin.constructor.name; | ||
if (this.injectedPluginNames.has(pluginName)) { | ||
utils_1.ConsoleHelper.warn(`${pluginName} is used twice, are you sure you really want to do this?`); | ||
} | ||
else { | ||
this.injectedPluginNames.add(pluginName); | ||
} | ||
} | ||
apply(compiler) { | ||
const proxiedCompiler = this._proxyForHookProviderCandidates(compiler); | ||
if ((0, TimeAnalyticsPlugin_1.isWebpackPlugin)(this._proxiedPlugin)) { | ||
// @ts-ignore, here is tricky, TS could not distinguish apply intertaged from Object and a function called apply | ||
// Here is WebpackPlugin instance | ||
this._proxiedPlugin.apply(proxiedCompiler); | ||
} | ||
else { | ||
// @ts-ignore, here is tricky, TS could not distinguish apply intertaged from Object and a function called apply | ||
// Here is function | ||
this._proxiedPlugin.apply(proxiedCompiler, proxiedCompiler); | ||
@@ -77,15 +74,4 @@ } | ||
(0, utils_1.assert)(originHooks.constructor.name === 'Object', '`Hooks` should just be plain object'); | ||
let hookObject; | ||
if (Object.isFrozen(originHooks)) { | ||
hookObject = { ...originHooks }; | ||
} | ||
else { | ||
// TODO: remove this support | ||
if (!isWebpack4WarnLogged) { | ||
utils_1.ConsoleHelper.warn('It seems you are using Webpack 4. However, this plugin is designed for Webpack 5.'); | ||
isWebpack4WarnLogged = true; | ||
} | ||
hookObject = originHooks; | ||
} | ||
return that._proxyForHooks(hookObject, [hooksProvider.constructor.name, property]); | ||
const unfrozenHooks = getOrCreate(that.cachedUnfrozenHooks, originHooks, _createUnfrozenHooks); | ||
return that._proxyForHooks(unfrozenHooks, originHooks); | ||
} | ||
@@ -96,4 +82,28 @@ return target[property]; | ||
} | ||
/** | ||
* If we use a proxy on frozen object, it's invalid to return a different object with the origin object. | ||
* So we need to `Unfrozen` it firstly. | ||
*/ | ||
function _createUnfrozenHooks(originHooks) { | ||
let hooks; | ||
if (Object.isFrozen(originHooks)) { | ||
// TODO: try to remove in webpack 6 | ||
hooks = { | ||
// Add this lazily to avoid a warnning: | ||
// DeprecationWarning: Compilation.hooks.normalModuleLoader was moved to NormalModule.getCompilationHooks(compilation).loader | ||
// ...originHooks | ||
}; | ||
} | ||
else { | ||
// TODO: remove this support | ||
if (!isWebpack4WarnLogged) { | ||
utils_1.ConsoleHelper.warn('It seems you are using Webpack 4. However, this plugin is designed for Webpack 5.'); | ||
isWebpack4WarnLogged = true; | ||
} | ||
hooks = originHooks; | ||
} | ||
return hooks; | ||
} | ||
} | ||
_proxyForHooks(hooks, propertyTrackPaths) { | ||
_proxyForHooks(hooks, originHooks) { | ||
const that = this; | ||
@@ -104,2 +114,9 @@ return getOrCreate(this.cachedProxyForHooks, hooks, _proxyForHooksWorker); | ||
get: function (target, property) { | ||
/** | ||
* hooks is frozen in webpak 5, we need to unfrozen it firstly, @see {@link _createUnfrozenHooks} for more background. | ||
* Add the property lazily | ||
*/ | ||
if (!(property in target)) { | ||
target[property] = originHooks[property]; | ||
} | ||
(0, utils_1.assert)(typeof property !== 'symbol', 'Getting Symbol property from "hooks", it should never happen, right?'); | ||
@@ -109,7 +126,7 @@ const method = target[property]; | ||
case isHook(method): | ||
return that._proxyForHook(method, [...propertyTrackPaths, property]); | ||
return that._proxyForHook(method); | ||
case isFakeHook(method): { | ||
(0, utils_1.assert)(Object.isFrozen(method), 'fake hook should be frozen'); | ||
const unfrozenFakeHook = { ...method }; | ||
return that._proxyForHook(unfrozenFakeHook, [...propertyTrackPaths, property]); | ||
return that._proxyForHook(unfrozenFakeHook); | ||
} | ||
@@ -148,3 +165,3 @@ case isHookMap(method): | ||
(0, utils_1.assert)(isHook(originHook)); | ||
return that._proxyForHook(originHook, []); // FIXME: use the real call path rather than the array | ||
return that._proxyForHook(originHook); | ||
}, | ||
@@ -154,3 +171,3 @@ }); | ||
} | ||
_proxyForHook(hook, propertyTrackPaths) { | ||
_proxyForHook(hook) { | ||
const that = this; | ||
@@ -294,3 +311,3 @@ return getOrCreate(this.cachedProxyForHook, hook, _proxyForHookWorker); | ||
const proxyForHookProviderCandidates = this._proxyForHookProviderCandidates.bind(this); | ||
return function (...args) { | ||
return async function (...args) { | ||
const wrapedArgs = args.map(proxyForHookProviderCandidates); | ||
@@ -306,14 +323,12 @@ const uuid = (0, crypto_1.randomUUID)(); | ||
}); | ||
const originPromise = tapCallback(...wrapedArgs); | ||
const ret = originPromise.then(() => { | ||
analyzer_1.analyzer.collectPluginInfo({ | ||
eventType: analyzer_1.PluginEventType.end, | ||
kind: analyzer_1.AnalyzeInfoKind.plugin, | ||
pluginName, | ||
time: (0, utils_1.now)(), | ||
tapCallId: uuid, | ||
tapType: analyzer_1.TapType.promise, | ||
}); | ||
await tapCallback(...wrapedArgs); | ||
analyzer_1.analyzer.collectPluginInfo({ | ||
eventType: analyzer_1.PluginEventType.end, | ||
kind: analyzer_1.AnalyzeInfoKind.plugin, | ||
pluginName, | ||
time: (0, utils_1.now)(), | ||
tapCallId: uuid, | ||
tapType: analyzer_1.TapType.promise, | ||
}); | ||
return ret; | ||
return; | ||
}; | ||
@@ -320,0 +335,0 @@ } |
@@ -16,3 +16,3 @@ "use strict"; | ||
} | ||
(0, utils_1.assert)(WeakMap, 'WeakMap must be existed.'); | ||
(0, utils_1.assert)(WeakMap, 'WeakMap must be existed in current runtime.'); | ||
const originSet = WeakMap.prototype.set; | ||
@@ -19,0 +19,0 @@ const originGet = WeakMap.prototype.get; |
@@ -10,30 +10,3 @@ "use strict"; | ||
class TimeAnalyticsPlugin { | ||
constructor(option) { | ||
this.option = option; | ||
this.option = option; | ||
} | ||
apply(compiler) { | ||
// Here is already too late, webpack uses weakMap internally in the constructor of Compiler. | ||
// Do this hack in WeakMap hack now. | ||
// #region Custom_Hooks | ||
// Prepare for custom hooks, which use `compiler` as key | ||
// Maybe `environment` or `afterEnvironment` hook? Or wrap the parametere directly? | ||
// compiler.hooks.initialize.tap({ | ||
// name: TimeAnalyticsPlugin.name, | ||
// // Make sure to be called fistly | ||
// stage: -100, | ||
// }, () => { | ||
// assert(!(compiler as any)[WEBPACK_WEAK_MAP_ID_KEY], 'add unique id to compilation only once!'); | ||
// (compiler as any)[WEBPACK_WEAK_MAP_ID_KEY] = new WebpackWeakMapId(); | ||
// }); | ||
// Prepare for custom hook, which use `compilation` as key | ||
// compiler.hooks.thisCompilation.tap({ | ||
// name: TimeAnalyticsPlugin.name, | ||
// // Make sure to be called fistly | ||
// stage: -100, | ||
// }, (compilation) => { | ||
// assert(!(compilation as any)[WEBPACK_WEAK_MAP_ID_KEY], 'add unique id to compilation only once!'); | ||
// (compilation as any)[WEBPACK_WEAK_MAP_ID_KEY] = new WebpackWeakMapId(); | ||
// }); | ||
// #endregion Custom_Hooks | ||
compiler.hooks.compile.tap(TimeAnalyticsPlugin.name, () => { | ||
@@ -62,2 +35,6 @@ analyzer_1.analyzer.initilize(); | ||
} | ||
constructor(option) { | ||
this.option = option; | ||
this.option = option; | ||
} | ||
static wrap(webpackConfigOrFactory, options) { | ||
@@ -127,6 +104,6 @@ if (options?.enable === false) { | ||
/** | ||
* Not accurate | ||
* Fancy hack to judge whether an object is a Webpack plugin or function. | ||
*/ | ||
function isWebpackPlugin(a) { | ||
return typeof a.apply === 'function' && a.apply !== Object.apply; | ||
function isWebpackPlugin(p) { | ||
return typeof p.apply === 'function' && p.apply !== Object.apply; | ||
} | ||
@@ -138,3 +115,3 @@ exports.isWebpackPlugin = isWebpackPlugin; | ||
} | ||
utils_1.ConsoleHelper.warn('meet one minimizer which is a function, Time Analytics plugin could not analyze such situration.'); | ||
utils_1.ConsoleHelper.warn(`could not handle function-like minimizer, please convert it to the plugin-like form.`); | ||
return minimizer; | ||
@@ -149,3 +126,3 @@ } | ||
if (!isRuleObjectArray(newModuleOptions.rules)) { | ||
(0, utils_1.fail)('There are plain string "..." in "module.rules", why do you need this? Please submit an issue.'); | ||
(0, utils_1.fail)('There is plain string "..." in "module.rules", why do you need this? Please submit an issue.'); | ||
} | ||
@@ -152,0 +129,0 @@ newModuleOptions.rules = (0, loaderHelper_1.normalizeRules)(newModuleOptions.rules); |
@@ -37,3 +37,3 @@ "use strict"; | ||
class Writer { | ||
static foo(a, b, c, option) { | ||
static writeResult(a, b, c, option) { | ||
const messages = ['', headerText]; | ||
@@ -40,0 +40,0 @@ // #region meta |
@@ -166,3 +166,3 @@ /* eslint-disable prefer-rest-params */ | ||
if (typeof module !== 'function' && typeof module !== 'object') { | ||
throw new Error('Bad loader, time analytics plugin is using the same checek as webpack. However, it does not provide more info, disable it to see error from webpack itself.'); | ||
throw new Error('Time analytics plugin tries to use the same checek as webpack, you see this error because Time analytics plugin think it should be a bug which should also be existed in webpack.'); | ||
} | ||
@@ -169,0 +169,0 @@ // get normal loader function according to module is mjs or cjs |
@@ -27,3 +27,3 @@ import type { RuleSetRule } from 'webpack'; | ||
function normalizeRuleCore(rule: RuleSetRule) { | ||
function normalizeRule(rule: RuleSetRule) { | ||
if (rule.loader) { | ||
@@ -59,9 +59,2 @@ rule.use = [rule.loader]; | ||
function normalizeRule(rule: RuleSetRule | undefined) { | ||
if (!rule) { | ||
return rule; | ||
} | ||
return normalizeRuleCore(rule); | ||
} | ||
export function normalizeRules(rules: RuleSetRule[] | undefined): RuleSetRule[] | undefined { | ||
@@ -72,5 +65,5 @@ if (!rules) { | ||
if (Array.isArray(rules)) return rules.map(normalizeRuleCore); | ||
if (Array.isArray(rules)) return rules.map(normalizeRule); | ||
return rules; | ||
} |
{ | ||
"name": "time-analytics-webpack-plugin", | ||
"version": "0.1.19", | ||
"version": "0.1.20", | ||
"description": "analytize the time of loaders and plugins", | ||
"main": "./dist/index.js", | ||
"types": "./types", | ||
"keywords": [ | ||
"webpack", | ||
"profiling", | ||
"time", | ||
"speed" | ||
], | ||
"scripts": { | ||
"build": "tsc -p ./tsconfig.json" | ||
}, | ||
"author": "Song Gao", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/ShuiRuTian/time-analytics-webpack-plugin.git" | ||
}, | ||
"author": { | ||
"name": "Song Gao", | ||
"email": "158983297@qq.com" | ||
}, | ||
"license": "BSD", | ||
@@ -12,0 +25,0 @@ "peerDependencies": { |
@@ -21,3 +21,3 @@ /* eslint-disable @typescript-eslint/no-this-alias */ // use function, so that we could put logic firstly | ||
* How to access currect object from first proxied object | ||
* For example, in `a.b.c.d`, `b` is the first proxied object, then for d, it's | ||
* For example, in `a.b.c.d`, `b` is the first proxied object, then for d, it's ['c', 'd'] | ||
*/ | ||
@@ -29,3 +29,2 @@ type PropertyTrackPaths = string[]; | ||
export class ProxyPlugin implements WebpackPlugin { | ||
@@ -56,9 +55,5 @@ private _proxiedPlugin: WebpackPlugin | WebpackPluginLikeFunction; | ||
if (isWebpackPlugin(this._proxiedPlugin)) { | ||
// @ts-ignore, here is tricky, TS could not distinguish apply intertaged from Object and a function called apply | ||
// Here is WebpackPlugin instance | ||
this._proxiedPlugin.apply(proxiedCompiler); | ||
(this._proxiedPlugin as WebpackPlugin).apply(proxiedCompiler); | ||
} else { | ||
// @ts-ignore, here is tricky, TS could not distinguish apply intertaged from Object and a function called apply | ||
// Here is function | ||
this._proxiedPlugin.apply(proxiedCompiler, proxiedCompiler); | ||
(this._proxiedPlugin as WebpackPluginLikeFunction).apply(proxiedCompiler, proxiedCompiler); | ||
} | ||
@@ -77,2 +72,4 @@ } | ||
private cachedUnfrozenHooks = new Map(); | ||
_proxyForHookProviderCandidates( | ||
@@ -100,14 +97,4 @@ candidate: any, // @types/webpack does not export all the types. Use `any` for now. | ||
assert(originHooks.constructor.name === 'Object', '`Hooks` should just be plain object'); | ||
let hookObject; | ||
if (Object.isFrozen(originHooks)) { | ||
hookObject = { ...originHooks }; | ||
} else { | ||
// TODO: remove this support | ||
if (!isWebpack4WarnLogged) { | ||
ConsoleHelper.warn('It seems you are using Webpack 4. However, this plugin is designed for Webpack 5.'); | ||
isWebpack4WarnLogged = true; | ||
} | ||
hookObject = originHooks; | ||
} | ||
return that._proxyForHooks(hookObject, [hooksProvider.constructor.name, property]); | ||
const unfrozenHooks = getOrCreate(that.cachedUnfrozenHooks, originHooks, _createUnfrozenHooks); | ||
return that._proxyForHooks(unfrozenHooks, originHooks); | ||
} | ||
@@ -118,2 +105,26 @@ return target[property]; | ||
} | ||
/** | ||
* If we use a proxy on frozen object, it's invalid to return a different object with the origin object. | ||
* So we need to `Unfrozen` it firstly. | ||
*/ | ||
function _createUnfrozenHooks(originHooks: any) { | ||
let hooks; | ||
if (Object.isFrozen(originHooks)) { | ||
// TODO: try to remove in webpack 6 | ||
hooks = { | ||
// Add this lazily to avoid a warnning: | ||
// DeprecationWarning: Compilation.hooks.normalModuleLoader was moved to NormalModule.getCompilationHooks(compilation).loader | ||
// ...originHooks | ||
}; | ||
} else { | ||
// TODO: remove this support | ||
if (!isWebpack4WarnLogged) { | ||
ConsoleHelper.warn('It seems you are using Webpack 4. However, this plugin is designed for Webpack 5.'); | ||
isWebpack4WarnLogged = true; | ||
} | ||
hooks = originHooks; | ||
} | ||
return hooks; | ||
} | ||
} | ||
@@ -123,3 +134,3 @@ | ||
private _proxyForHooks(hooks: any, propertyTrackPaths: PropertyTrackPaths) { | ||
private _proxyForHooks(hooks: any, originHooks: any) { | ||
const that = this; | ||
@@ -131,2 +142,9 @@ return getOrCreate(this.cachedProxyForHooks, hooks, _proxyForHooksWorker); | ||
get: function (target, property) { | ||
/** | ||
* hooks is frozen in webpak 5, we need to unfrozen it firstly, @see {@link _createUnfrozenHooks} for more background. | ||
* Add the property lazily | ||
*/ | ||
if (!(property in target)) { | ||
target[property] = originHooks[property]; | ||
} | ||
assert(typeof property !== 'symbol', 'Getting Symbol property from "hooks", it should never happen, right?'); | ||
@@ -136,7 +154,7 @@ const method = target[property]; | ||
case isHook(method): | ||
return that._proxyForHook(method, [...propertyTrackPaths, property]); | ||
return that._proxyForHook(method); | ||
case isFakeHook(method): { | ||
assert(Object.isFrozen(method), 'fake hook should be frozen'); | ||
const unfrozenFakeHook = { ...method }; | ||
return that._proxyForHook(unfrozenFakeHook, [...propertyTrackPaths, property]); | ||
return that._proxyForHook(unfrozenFakeHook); | ||
} | ||
@@ -183,3 +201,3 @@ case isHookMap(method): | ||
assert(isHook(originHook)); | ||
return that._proxyForHook(originHook, []); // FIXME: use the real call path rather than the array | ||
return that._proxyForHook(originHook); | ||
}, | ||
@@ -192,3 +210,3 @@ }); | ||
private _proxyForHook(hook: any, propertyTrackPaths: PropertyTrackPaths) { | ||
private _proxyForHook(hook: any) { | ||
const that = this; | ||
@@ -349,3 +367,3 @@ return getOrCreate(this.cachedProxyForHook, hook, _proxyForHookWorker); | ||
const proxyForHookProviderCandidates = this._proxyForHookProviderCandidates.bind(this); | ||
return function (...args: any[]) { | ||
return async function (...args: any[]) { | ||
const wrapedArgs = args.map(proxyForHookProviderCandidates); | ||
@@ -361,14 +379,12 @@ const uuid = randomUUID(); | ||
}); | ||
const originPromise = tapCallback(...wrapedArgs); | ||
const ret = originPromise.then(() => { | ||
analyzer.collectPluginInfo({ | ||
eventType: PluginEventType.end, | ||
kind: AnalyzeInfoKind.plugin, | ||
pluginName, | ||
time: now(), | ||
tapCallId: uuid, | ||
tapType: TapType.promise, | ||
}); | ||
await tapCallback(...wrapedArgs); | ||
analyzer.collectPluginInfo({ | ||
eventType: PluginEventType.end, | ||
kind: AnalyzeInfoKind.plugin, | ||
pluginName, | ||
time: now(), | ||
tapCallId: uuid, | ||
tapType: TapType.promise, | ||
}); | ||
return ret; | ||
return; | ||
}; | ||
@@ -375,0 +391,0 @@ } |
@@ -14,3 +14,3 @@ import { randomUUID } from 'crypto'; | ||
assert(WeakMap, 'WeakMap must be existed.'); | ||
assert(WeakMap, 'WeakMap must be existed in current runtime.'); | ||
@@ -17,0 +17,0 @@ const originSet = WeakMap.prototype.set; |
@@ -7,2 +7,3 @@ import type { Compiler, Configuration, ModuleOptions, RuleSetRule } from 'webpack'; | ||
import './sideEffects/hackWeakMap'; | ||
import { PACKAGE_NAME } from './const'; | ||
@@ -109,28 +110,2 @@ export declare class WebpackPlugin { | ||
public apply(compiler: Compiler) { | ||
// Here is already too late, webpack uses weakMap internally in the constructor of Compiler. | ||
// Do this hack in WeakMap hack now. | ||
// #region Custom_Hooks | ||
// Prepare for custom hooks, which use `compiler` as key | ||
// Maybe `environment` or `afterEnvironment` hook? Or wrap the parametere directly? | ||
// compiler.hooks.initialize.tap({ | ||
// name: TimeAnalyticsPlugin.name, | ||
// // Make sure to be called fistly | ||
// stage: -100, | ||
// }, () => { | ||
// assert(!(compiler as any)[WEBPACK_WEAK_MAP_ID_KEY], 'add unique id to compilation only once!'); | ||
// (compiler as any)[WEBPACK_WEAK_MAP_ID_KEY] = new WebpackWeakMapId(); | ||
// }); | ||
// Prepare for custom hook, which use `compilation` as key | ||
// compiler.hooks.thisCompilation.tap({ | ||
// name: TimeAnalyticsPlugin.name, | ||
// // Make sure to be called fistly | ||
// stage: -100, | ||
// }, (compilation) => { | ||
// assert(!(compilation as any)[WEBPACK_WEAK_MAP_ID_KEY], 'add unique id to compilation only once!'); | ||
// (compilation as any)[WEBPACK_WEAK_MAP_ID_KEY] = new WebpackWeakMapId(); | ||
// }); | ||
// #endregion Custom_Hooks | ||
compiler.hooks.compile.tap(TimeAnalyticsPlugin.name, () => { | ||
@@ -168,3 +143,3 @@ analyzer.initilize(); | ||
public static wrap(webpackConfigOrFactory: Configuration, options?: TimeAnalyticsPluginOptions): Configuration; | ||
public static wrap(webpackConfigOrFactory: Configuration, options?: TimeAnalyticsPluginOptions): WebpackConfigFactory; | ||
public static wrap(webpackConfigOrFactory: WebpackConfigFactory, options?: TimeAnalyticsPluginOptions): WebpackConfigFactory; | ||
public static wrap(webpackConfigOrFactory: Configuration | WebpackConfigFactory, options?: TimeAnalyticsPluginOptions) { | ||
@@ -210,2 +185,3 @@ if (options?.enable === false) { | ||
const newConfig = { ...config }; | ||
if (this.isPluginEnabled && newConfig.plugins) { | ||
@@ -221,2 +197,3 @@ newConfig.plugins = newConfig.plugins.map((plugin) => { | ||
} | ||
if (this.isPluginEnabled && newConfig.optimization?.minimizer) { | ||
@@ -232,5 +209,7 @@ newConfig.optimization.minimizer = newConfig.optimization.minimizer | ||
} | ||
if (this.isLoaderEnabled && newConfig.module) { | ||
newConfig.module = injectModule(newConfig.module); | ||
} | ||
return newConfig; | ||
@@ -240,6 +219,6 @@ } | ||
/** | ||
* Not accurate | ||
* Fancy hack to judge whether an object is a Webpack plugin or function. | ||
*/ | ||
export function isWebpackPlugin(a: any): a is WebpackPlugin { | ||
return typeof a.apply === 'function' && a.apply !== Object.apply; | ||
export function isWebpackPlugin(p: any): p is WebpackPlugin { | ||
return typeof p.apply === 'function' && p.apply !== Object.apply; | ||
} | ||
@@ -254,3 +233,3 @@ | ||
} | ||
ConsoleHelper.warn('meet one minimizer which is a function, Time Analytics plugin could not analyze such situration.'); | ||
ConsoleHelper.warn(`could not handle function-like minimizer, please convert it to the plugin-like form.`); | ||
return minimizer; | ||
@@ -267,3 +246,3 @@ } | ||
if (!isRuleObjectArray(newModuleOptions.rules)) { | ||
fail('There are plain string "..." in "module.rules", why do you need this? Please submit an issue.'); | ||
fail('There is plain string "..." in "module.rules", why do you need this? Please submit an issue.'); | ||
} | ||
@@ -270,0 +249,0 @@ |
@@ -13,2 +13,3 @@ import type { Compiler } from 'webpack'; | ||
private cachedProxyForHooksProvider; | ||
private cachedUnfrozenHooks; | ||
_proxyForHookProviderCandidates(candidate: any): any; | ||
@@ -15,0 +16,0 @@ private _proxyForHooksProvider; |
@@ -9,3 +9,3 @@ import type { Compiler, Configuration } from 'webpack'; | ||
} | ||
export declare type WebpackPluginLikeFunction = (this: Compiler, compiler: Compiler) => void; | ||
export type WebpackPluginLikeFunction = (this: Compiler, compiler: Compiler) => void; | ||
interface TimeAnalyticsPluginOptions { | ||
@@ -102,3 +102,3 @@ /** | ||
static wrap(webpackConfigOrFactory: Configuration, options?: TimeAnalyticsPluginOptions): Configuration; | ||
static wrap(webpackConfigOrFactory: Configuration, options?: TimeAnalyticsPluginOptions): WebpackConfigFactory; | ||
static wrap(webpackConfigOrFactory: WebpackConfigFactory, options?: TimeAnalyticsPluginOptions): WebpackConfigFactory; | ||
get isLoaderEnabled(): boolean; | ||
@@ -108,5 +108,5 @@ get isPluginEnabled(): boolean; | ||
/** | ||
* Not accurate | ||
* Fancy hack to judge whether an object is a Webpack plugin or function. | ||
*/ | ||
export declare function isWebpackPlugin(a: any): a is WebpackPlugin; | ||
export declare function isWebpackPlugin(p: any): p is WebpackPlugin; | ||
export {}; |
import { LoaderAnalyticsResult, MetaAnalyticsResult, OutputOption, PluginAnalyticsResult } from './analyzer'; | ||
export declare abstract class Writer { | ||
static foo(a: MetaAnalyticsResult, b: PluginAnalyticsResult, c: LoaderAnalyticsResult, option: OutputOption): void; | ||
static writeResult(a: MetaAnalyticsResult, b: PluginAnalyticsResult, c: LoaderAnalyticsResult, option: OutputOption): void; | ||
} |
@@ -40,3 +40,3 @@ import { writeFileSync } from 'fs'; | ||
export abstract class Writer { | ||
static foo(a: MetaAnalyticsResult, b: PluginAnalyticsResult, c: LoaderAnalyticsResult, option: OutputOption) { | ||
static writeResult(a: MetaAnalyticsResult, b: PluginAnalyticsResult, c: LoaderAnalyticsResult, option: OutputOption) { | ||
const messages = ['', headerText]; | ||
@@ -43,0 +43,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
44
2.33%4
-20%156266
-0.71%2647
-0.97%