@rsdoctor/webpack-plugin 1.3.11-beta.0 → 1.3.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -37,108 +37,6 @@ const build_utils_namespaceObject = require("@rsdoctor/core/build-utils"), plugi
37
37
  stage: 1000
38
38
  }), external_path_namespaceObject = require("path");
39
39
  var external_path_default = __webpack_require__.n(external_path_namespaceObject);
40
- class RsdoctorResolverPlugin {
41
- options;
42
- sdk;
43
- tapOptions = {
44
- name: 'RsdoctorResolverPlugin'
45
- };
46
- contextMap = new Map();
47
- constructor(options, sdk){
48
- this.options = options, this.sdk = sdk;
49
- }
50
- getResolverData(context, params) {
51
- let ctx = this.contextMap.get(context.issuer);
52
- if (!ctx) return;
53
- let { request, query, result, error, stacks } = params, [start, startHRTime] = ctx, data = {
54
- isEntry: !!context.issuer,
55
- issuerPath: context.issuer || '',
56
- request,
57
- startAt: start,
58
- endAt: common_namespaceObject.Time.getCurrentTimestamp(start, startHRTime),
59
- pid: process.pid,
60
- ppid: process.ppid
61
- };
62
- return query && (data.query = query), result && (data.result = result), error && (data.error = error, data.stacks = stacks || []), data;
63
- }
64
- getResolveStackData(request, path, name = 'anonymous') {
65
- let data = {
66
- name,
67
- path
68
- };
69
- return [
70
- 'request',
71
- 'query',
72
- 'fragment',
73
- 'file',
74
- 'module',
75
- 'directory',
76
- 'internal'
77
- ].forEach((key)=>{
78
- request[key] && (data[key] = request[key]);
79
- }), data;
80
- }
81
- getResolveRequest(request, ctx) {
82
- if (request) return request;
83
- if (ctx?.stack) {
84
- let [target] = [
85
- ...ctx.stack
86
- ].map((e)=>e.split(' ').map((e)=>e.trim())).filter((e)=>e.length > 2);
87
- if (target) return target[target.length - 1];
88
- }
89
- return '';
90
- }
91
- apply(resolver) {
92
- resolver.hooks.result.tap(this.tapOptions, (request, resolveCtx)=>{
93
- let { context } = request;
94
- if (this.contextMap.get(context.issuer)) {
95
- let data = this.getResolverData(context, {
96
- request: this.getResolveRequest(request.request, resolveCtx),
97
- query: request.query,
98
- result: request.path
99
- });
100
- data && this.sdk.reportResolver([
101
- data
102
- ]);
103
- }
104
- }), resolver.hooks.noResolve.tap(this.tapOptions, (request, error)=>{
105
- let { context } = request;
106
- if (context.issuer) {
107
- let resolvedPaths = new Set(error.details.split('\n').map((e)=>e.trim().split(' ')[0]).filter((e)=>external_path_default().isAbsolute(e)));
108
- if (resolvedPaths.size && this.contextMap.has(context.issuer)) {
109
- let stacks = [
110
- ...resolvedPaths
111
- ].map((e)=>this.getResolveStackData(request, e, 'noResolve')), data = this.getResolverData(context, {
112
- request: this.getResolveRequest(request.request),
113
- query: request.query,
114
- error,
115
- stacks
116
- });
117
- data && this.sdk.reportResolver([
118
- data
119
- ]);
120
- }
121
- }
122
- }), resolver.hooks.resolveStep.tap(this.tapOptions, (_, request)=>{
123
- let { context } = request;
124
- context.issuer && !this.contextMap.has(context.issuer) && this.contextMap.set(context.issuer, [
125
- Date.now(),
126
- process.hrtime()
127
- ]);
128
- });
129
- }
130
- }
131
- class InternalResolverPlugin extends plugins_namespaceObject.InternalBasePlugin {
132
- name = 'resolver';
133
- apply(compiler) {
134
- this.scheduler.ensureModulesChunksGraphApplied(compiler), compiler.hooks.afterPlugins.tap(this.tapPostOptions, this.afterPlugins);
135
- }
136
- afterPlugins = (compiler)=>{
137
- compiler.isChild() || (compiler.options.resolve.plugins = (compiler.options.resolve.plugins ?? []).concat(new RsdoctorResolverPlugin({}, this.sdk)), this.sdk.addClientRoutes([
138
- types_namespaceObject.Manifest.RsdoctorManifestClientRoutes.ModuleResolve
139
- ]));
140
- };
141
- }
142
40
  class RsdoctorWebpackPlugin {
143
41
  name = pluginTapName;
144
42
  options;
@@ -168,7 +66,7 @@ class RsdoctorWebpackPlugin {
168
66
  apply(compiler) {
169
67
  this._bootstrapTask || (this._bootstrapTask = this.sdk.bootstrap()), (0, plugins_namespaceObject.setSDK)(this.sdk), new plugins_namespaceObject.InternalSummaryPlugin(this).apply(compiler), this.options.features.loader && (new build_utils_namespaceObject.Loader.ProbeLoaderPlugin().apply(compiler), this.sdk.addClientRoutes([
170
68
  types_namespaceObject.Manifest.RsdoctorManifestClientRoutes.WebpackLoaders
171
- ]), common_namespaceObject.Loader.isVue(compiler) || new plugins_namespaceObject.InternalLoaderPlugin(this).apply(compiler)), this.options.features.resolver && new InternalResolverPlugin(this).apply(compiler), this.options.features.plugins && new plugins_namespaceObject.InternalPluginsPlugin(this).apply(compiler), this.options.features.bundle && (new plugins_namespaceObject.InternalBundlePlugin(this).apply(compiler), new plugins_namespaceObject.InternalBundleTagPlugin(this).apply(compiler)), new plugins_namespaceObject.InternalErrorReporterPlugin(this).apply(compiler), new plugins_namespaceObject.InternalRulesPlugin(this).apply(compiler), new plugins_namespaceObject.InternalProgressPlugin(this).apply(compiler), compiler.hooks.afterPlugins.tap(pluginTapPostOptions, this.afterPlugins), compiler.hooks.watchRun.tapPromise(pluginTapPostOptions, this.beforeRun), compiler.hooks.beforeRun.tapPromise(pluginTapPostOptions, this.beforeRun), compiler.hooks.done.tapPromise({
69
+ ]), common_namespaceObject.Loader.isVue(compiler) || new plugins_namespaceObject.InternalLoaderPlugin(this).apply(compiler)), this.options.features.resolver && new plugins_namespaceObject.InternalResolverPlugin(this).apply(compiler), this.options.features.plugins && new plugins_namespaceObject.InternalPluginsPlugin(this).apply(compiler), this.options.features.bundle && (new plugins_namespaceObject.InternalBundlePlugin(this).apply(compiler), new plugins_namespaceObject.InternalBundleTagPlugin(this).apply(compiler)), new plugins_namespaceObject.InternalErrorReporterPlugin(this).apply(compiler), new plugins_namespaceObject.InternalRulesPlugin(this).apply(compiler), new plugins_namespaceObject.InternalProgressPlugin(this).apply(compiler), compiler.hooks.afterPlugins.tap(pluginTapPostOptions, this.afterPlugins), compiler.hooks.watchRun.tapPromise(pluginTapPostOptions, this.beforeRun), compiler.hooks.beforeRun.tapPromise(pluginTapPostOptions, this.beforeRun), compiler.hooks.done.tapPromise({
172
70
  ...pluginTapPostOptions,
173
71
  stage: pluginTapPostOptions.stage + 100
174
72
  }, this.done.bind(this, compiler));
package/dist/index.js CHANGED
@@ -1,120 +1,18 @@
1
1
  let globalController;
2
2
  import { Loader } from "@rsdoctor/core/build-utils";
3
- import { InternalBasePlugin, InternalBundlePlugin, InternalBundleTagPlugin, InternalErrorReporterPlugin, InternalLoaderPlugin, InternalPluginsPlugin, InternalProgressPlugin, InternalRulesPlugin, InternalSummaryPlugin, ensureModulesChunksGraphFn, handleBriefModeReport, normalizeUserConfig, processCompilerConfig, setSDK } from "@rsdoctor/core/plugins";
3
+ import { InternalBundlePlugin, InternalBundleTagPlugin, InternalErrorReporterPlugin, InternalLoaderPlugin, InternalPluginsPlugin, InternalProgressPlugin, InternalResolverPlugin, InternalRulesPlugin, InternalSummaryPlugin, ensureModulesChunksGraphFn, handleBriefModeReport, normalizeUserConfig, processCompilerConfig, setSDK } from "@rsdoctor/core/plugins";
4
4
  import { ChunkGraph, ModuleGraph } from "@rsdoctor/graph";
5
5
  import { RsdoctorSDK, RsdoctorSDKController, findRoot } from "@rsdoctor/sdk";
6
6
  import { Constants, Manifest, SDK } from "@rsdoctor/types";
7
7
  import { Process } from "@rsdoctor/utils/build";
8
- import { Loader as common_Loader, Time } from "@rsdoctor/utils/common";
8
+ import { Loader as common_Loader } from "@rsdoctor/utils/common";
9
9
  import { logger } from "@rsdoctor/utils/logger";
10
- import path_0 from "path";
10
+ import path from "path";
11
11
  import { LinterType, defineRule } from "@rsdoctor/core/rules";
12
12
  let pluginTapName = 'RsdoctorWebpackPlugin', pluginTapPostOptions = {
13
13
  name: pluginTapName,
14
14
  stage: 999
15
15
  };
16
- class RsdoctorResolverPlugin {
17
- options;
18
- sdk;
19
- tapOptions = {
20
- name: 'RsdoctorResolverPlugin'
21
- };
22
- contextMap = new Map();
23
- constructor(options, sdk){
24
- this.options = options, this.sdk = sdk;
25
- }
26
- getResolverData(context, params) {
27
- let ctx = this.contextMap.get(context.issuer);
28
- if (!ctx) return;
29
- let { request, query, result, error, stacks } = params, [start, startHRTime] = ctx, data = {
30
- isEntry: !!context.issuer,
31
- issuerPath: context.issuer || '',
32
- request,
33
- startAt: start,
34
- endAt: Time.getCurrentTimestamp(start, startHRTime),
35
- pid: process.pid,
36
- ppid: process.ppid
37
- };
38
- return query && (data.query = query), result && (data.result = result), error && (data.error = error, data.stacks = stacks || []), data;
39
- }
40
- getResolveStackData(request, path, name = 'anonymous') {
41
- let data = {
42
- name,
43
- path
44
- };
45
- return [
46
- 'request',
47
- 'query',
48
- 'fragment',
49
- 'file',
50
- 'module',
51
- 'directory',
52
- 'internal'
53
- ].forEach((key)=>{
54
- request[key] && (data[key] = request[key]);
55
- }), data;
56
- }
57
- getResolveRequest(request, ctx) {
58
- if (request) return request;
59
- if (ctx?.stack) {
60
- let [target] = [
61
- ...ctx.stack
62
- ].map((e)=>e.split(' ').map((e)=>e.trim())).filter((e)=>e.length > 2);
63
- if (target) return target[target.length - 1];
64
- }
65
- return '';
66
- }
67
- apply(resolver) {
68
- resolver.hooks.result.tap(this.tapOptions, (request, resolveCtx)=>{
69
- let { context } = request;
70
- if (this.contextMap.get(context.issuer)) {
71
- let data = this.getResolverData(context, {
72
- request: this.getResolveRequest(request.request, resolveCtx),
73
- query: request.query,
74
- result: request.path
75
- });
76
- data && this.sdk.reportResolver([
77
- data
78
- ]);
79
- }
80
- }), resolver.hooks.noResolve.tap(this.tapOptions, (request, error)=>{
81
- let { context } = request;
82
- if (context.issuer) {
83
- let resolvedPaths = new Set(error.details.split('\n').map((e)=>e.trim().split(' ')[0]).filter((e)=>path_0.isAbsolute(e)));
84
- if (resolvedPaths.size && this.contextMap.has(context.issuer)) {
85
- let stacks = [
86
- ...resolvedPaths
87
- ].map((e)=>this.getResolveStackData(request, e, 'noResolve')), data = this.getResolverData(context, {
88
- request: this.getResolveRequest(request.request),
89
- query: request.query,
90
- error,
91
- stacks
92
- });
93
- data && this.sdk.reportResolver([
94
- data
95
- ]);
96
- }
97
- }
98
- }), resolver.hooks.resolveStep.tap(this.tapOptions, (_, request)=>{
99
- let { context } = request;
100
- context.issuer && !this.contextMap.has(context.issuer) && this.contextMap.set(context.issuer, [
101
- Date.now(),
102
- process.hrtime()
103
- ]);
104
- });
105
- }
106
- }
107
- class InternalResolverPlugin extends InternalBasePlugin {
108
- name = 'resolver';
109
- apply(compiler) {
110
- this.scheduler.ensureModulesChunksGraphApplied(compiler), compiler.hooks.afterPlugins.tap(this.tapPostOptions, this.afterPlugins);
111
- }
112
- afterPlugins = (compiler)=>{
113
- compiler.isChild() || (compiler.options.resolve.plugins = (compiler.options.resolve.plugins ?? []).concat(new RsdoctorResolverPlugin({}, this.sdk)), this.sdk.addClientRoutes([
114
- Manifest.RsdoctorManifestClientRoutes.ModuleResolve
115
- ]));
116
- };
117
- }
118
16
  class RsdoctorWebpackPlugin {
119
17
  name = pluginTapName;
120
18
  options;
@@ -169,7 +67,7 @@ class RsdoctorWebpackPlugin {
169
67
  }
170
68
  done = async (compiler)=>{
171
69
  try {
172
- this.sdk.server.broadcast(), logger.debug(`${Process.getMemoryUsageMessage()}, '[Before Write Manifest]'`), this.outsideInstance && 'parent' in this.sdk && this.sdk.parent.master.setOutputDir(path_0.resolve(this.options.output.reportDir || compiler.outputPath, this.options.output.mode === SDK.IMode[SDK.IMode.brief] ? '' : `./${Constants.RsdoctorOutputFolder}`)), this.sdk.setOutputDir(path_0.resolve(this.options.output.reportDir || compiler.outputPath, this.options.output.mode === SDK.IMode[SDK.IMode.brief] ? '' : `./${Constants.RsdoctorOutputFolder}`)), await this.sdk.writeStore(), logger.debug(`${Process.getMemoryUsageMessage()}, '[After Write Manifest]'`), this.options.disableClientServer ? (await this.sdk.dispose(), logger.debug(`${Process.getMemoryUsageMessage()}, '[After SDK Dispose]'`)) : this.options.output.mode !== SDK.IMode[SDK.IMode.brief] || this.options.disableClientServer || handleBriefModeReport(this.sdk, this.options, this.options.disableClientServer);
70
+ this.sdk.server.broadcast(), logger.debug(`${Process.getMemoryUsageMessage()}, '[Before Write Manifest]'`), this.outsideInstance && 'parent' in this.sdk && this.sdk.parent.master.setOutputDir(path.resolve(this.options.output.reportDir || compiler.outputPath, this.options.output.mode === SDK.IMode[SDK.IMode.brief] ? '' : `./${Constants.RsdoctorOutputFolder}`)), this.sdk.setOutputDir(path.resolve(this.options.output.reportDir || compiler.outputPath, this.options.output.mode === SDK.IMode[SDK.IMode.brief] ? '' : `./${Constants.RsdoctorOutputFolder}`)), await this.sdk.writeStore(), logger.debug(`${Process.getMemoryUsageMessage()}, '[After Write Manifest]'`), this.options.disableClientServer ? (await this.sdk.dispose(), logger.debug(`${Process.getMemoryUsageMessage()}, '[After SDK Dispose]'`)) : this.options.output.mode !== SDK.IMode[SDK.IMode.brief] || this.options.disableClientServer || handleBriefModeReport(this.sdk, this.options, this.options.disableClientServer);
173
71
  } catch (e) {
174
72
  console.error("[Rsdoctor] Webpack plugin this.done error", e);
175
73
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsdoctor/webpack-plugin",
3
- "version": "1.3.11-beta.0",
3
+ "version": "1.3.12",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/web-infra-dev/rsdoctor",
@@ -21,11 +21,11 @@
21
21
  }
22
22
  },
23
23
  "dependencies": {
24
- "@rsdoctor/core": "1.3.11-beta.0",
25
- "@rsdoctor/types": "1.3.11-beta.0",
26
- "@rsdoctor/utils": "1.3.11-beta.0",
27
- "@rsdoctor/sdk": "1.3.11-beta.0",
28
- "@rsdoctor/graph": "1.3.11-beta.0"
24
+ "@rsdoctor/core": "1.3.12",
25
+ "@rsdoctor/sdk": "1.3.12",
26
+ "@rsdoctor/graph": "1.3.12",
27
+ "@rsdoctor/types": "1.3.12",
28
+ "@rsdoctor/utils": "1.3.12"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@types/node": "^22.8.1",
@@ -1,47 +0,0 @@
1
- import { InternalBasePlugin } from '@rsdoctor/core/plugins';
2
- import { SDK } from '@rsdoctor/types';
3
- import type { Compiler, Resolver } from 'webpack';
4
- interface RsdoctorResolverPluginOptions {
5
- }
6
- interface ResolveRequestContext {
7
- issuer: string;
8
- }
9
- interface ResolveRequestWithContext {
10
- [key: string]: unknown;
11
- context: ResolveRequestContext;
12
- }
13
- /**
14
- * Plugin instance. ResolvePluginInstance in webpack@5.90 is not the interface, it's a type.
15
- */
16
- declare interface ResolvePluginInstance {
17
- [index: string]: any;
18
- /**
19
- * The run point of the plugin, required method.
20
- */
21
- apply: (resolver: Resolver) => void;
22
- }
23
- export declare class RsdoctorResolverPlugin implements ResolvePluginInstance {
24
- protected options: RsdoctorResolverPluginOptions;
25
- protected sdk: SDK.RsdoctorBuilderSDKInstance;
26
- protected tapOptions: {
27
- name: string;
28
- };
29
- protected contextMap: Map<string, [number, [number, number]]>;
30
- constructor(options: RsdoctorResolverPluginOptions, sdk: SDK.RsdoctorBuilderSDKInstance);
31
- protected getResolverData(context: ResolveRequestContext, params: {
32
- request: string;
33
- query?: string;
34
- result?: string;
35
- error?: Error;
36
- stacks?: SDK.ResolveStackData[];
37
- }): SDK.PathResolverData | undefined;
38
- protected getResolveStackData(request: ResolveRequestWithContext, path: string, name?: string): SDK.ResolveStackData;
39
- protected getResolveRequest(request: string | undefined, ctx?: Parameters<Resolver['resolve']>[3]): string;
40
- apply(resolver: Resolver): void;
41
- }
42
- export declare class InternalResolverPlugin extends InternalBasePlugin<Compiler> {
43
- readonly name = "resolver";
44
- apply(compiler: Compiler): void;
45
- afterPlugins: (compiler: Compiler) => void;
46
- }
47
- export {};