@rsdoctor/core 0.2.2 → 0.2.3

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.
@@ -14,5 +14,5 @@ export declare function loadLoaderModule(loaderPath: string, cwd?: string): {
14
14
  export declare function getLoaderOptions<T>(loaderContext: Plugin.LoaderContext<T>): T;
15
15
  export declare function extractLoaderName(loaderPath: string, cwd?: string): string;
16
16
  export declare function mapEachRules<T extends Plugin.BuildRuleSetRule>(rules: T[], callback: (rule: T) => T): T[];
17
- export declare function changeBuiltinLoader<T extends Plugin.BuildRuleSetRule>(rules: T[], loaderName: string, appendRules: (rule: T, index: number) => T): T[];
17
+ export declare function addProbeLoader2Rules<T extends Plugin.BuildRuleSetRule>(rules: T[], loaderName: string, appendRules: (rule: T, index: number) => T, strict?: boolean): T[];
18
18
  export declare function createLoaderContextTrap(this: Plugin.LoaderContext<Common.PlainObject>, final: (err: Error | null | undefined, res: string | Buffer | null, sourceMap?: WebpackSourceMapInput) => void): Plugin.LoaderContext<Common.PlainObject<any>>;
@@ -28,7 +28,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
  var loader_exports = {};
30
30
  __export(loader_exports, {
31
- changeBuiltinLoader: () => changeBuiltinLoader,
31
+ addProbeLoader2Rules: () => addProbeLoader2Rules,
32
32
  createLoaderContextTrap: () => createLoaderContextTrap,
33
33
  extractLoaderName: () => extractLoaderName,
34
34
  getLoaderOptions: () => getLoaderOptions,
@@ -153,14 +153,17 @@ function mapEachRules(rules, callback) {
153
153
  return rule;
154
154
  });
155
155
  }
156
- function getLoaderNameMatch(_r, loaderName) {
156
+ function getLoaderNameMatch(_r, loaderName, strict = true) {
157
+ if (!strict) {
158
+ return typeof _r === "object" && typeof _r?.loader === "string" && _r.loader.includes(loaderName) || typeof _r === "string" && _r.includes(loaderName);
159
+ }
157
160
  return typeof _r === "object" && typeof _r?.loader === "string" && _r.loader === loaderName || typeof _r === "string" && _r === loaderName;
158
161
  }
159
- function changeBuiltinLoader(rules, loaderName, appendRules) {
162
+ function addProbeLoader2Rules(rules, loaderName, appendRules, strict) {
160
163
  return rules.map((rule) => {
161
164
  if (!rule || typeof rule === "string")
162
165
  return rule;
163
- if (getLoaderNameMatch(rule, loaderName)) {
166
+ if (getLoaderNameMatch(rule, loaderName, strict)) {
164
167
  const _rule = {
165
168
  ...rule,
166
169
  use: [
@@ -178,7 +181,7 @@ function changeBuiltinLoader(rules, loaderName, appendRules) {
178
181
  if (Array.isArray(rule.use)) {
179
182
  const _index = (0, import_lodash.findIndex)(
180
183
  rule.use,
181
- (_r) => getLoaderNameMatch(_r, loaderName)
184
+ (_r) => getLoaderNameMatch(_r, loaderName, strict)
182
185
  );
183
186
  if (_index > -1) {
184
187
  return appendRules(rule, _index);
@@ -195,7 +198,7 @@ function changeBuiltinLoader(rules, loaderName, appendRules) {
195
198
  if ("oneOf" in rule && rule.oneOf) {
196
199
  return {
197
200
  ...rule,
198
- oneOf: changeBuiltinLoader(
201
+ oneOf: addProbeLoader2Rules(
199
202
  rule.oneOf,
200
203
  loaderName,
201
204
  appendRules
@@ -205,7 +208,7 @@ function changeBuiltinLoader(rules, loaderName, appendRules) {
205
208
  if ("rules" in rule && rule.rules) {
206
209
  return {
207
210
  ...rule,
208
- rules: changeBuiltinLoader(
211
+ rules: addProbeLoader2Rules(
209
212
  rule.rules,
210
213
  loaderName,
211
214
  appendRules
@@ -286,7 +289,7 @@ function createLoaderContextTrap(final) {
286
289
  }
287
290
  // Annotate the CommonJS export names for ESM import in node:
288
291
  0 && (module.exports = {
289
- changeBuiltinLoader,
292
+ addProbeLoader2Rules,
290
293
  createLoaderContextTrap,
291
294
  extractLoaderName,
292
295
  getLoaderOptions,
@@ -2,9 +2,9 @@ import type { RsdoctorWebpackSDK } from '@rsdoctor/sdk';
2
2
  import type { Linter, Plugin } from '@rsdoctor/types';
3
3
  import type { InternalPlugin, RsdoctorPluginInstance } from '../../types';
4
4
  export declare abstract class InternalBasePlugin<T extends Plugin.BaseCompiler> implements InternalPlugin<T, Linter.ExtendRuleData[]> {
5
- readonly scheduler: RsdoctorPluginInstance<Plugin.BaseCompiler, Linter.ExtendRuleData[]>;
5
+ readonly scheduler: RsdoctorPluginInstance<T, Linter.ExtendRuleData[]>;
6
6
  abstract name: string;
7
- constructor(scheduler: RsdoctorPluginInstance<Plugin.BaseCompiler, Linter.ExtendRuleData[]>);
7
+ constructor(scheduler: RsdoctorPluginInstance<T, Linter.ExtendRuleData[]>);
8
8
  abstract apply(compiler: T): void;
9
9
  get options(): import("@/types").RsdoctorPluginOptionsNormalized<Linter.ExtendRuleData<any, string>[]>;
10
10
  get sdk(): RsdoctorWebpackSDK;
@@ -107,7 +107,7 @@ function interceptLoader(rules, loaderPath, options, cwd = process.cwd(), resolv
107
107
  return target;
108
108
  };
109
109
  return import_build.Utils.mapEachRules(rules, (rule) => {
110
- if (rule.loader?.startsWith("builtin:")) {
110
+ if (rule.loader?.startsWith("builtin:") || rule.loader?.endsWith(".mjs")) {
111
111
  return rule;
112
112
  }
113
113
  const opts = {
@@ -2,8 +2,7 @@ import type { Linter as LinterType, Common, Plugin, SDK } from '@rsdoctor/types'
2
2
  import type { RsdoctorSlaveSDK, RsdoctorWebpackSDK } from '@rsdoctor/sdk';
3
3
  import { ChunkGraph, ModuleGraph } from '@rsdoctor/graph';
4
4
  import { rules } from '../rules/rules';
5
- import { RuleData } from '@rsdoctor/types/dist/linter';
6
- type InternalRules = (typeof rules)[number] & RuleData[];
5
+ type InternalRules = Common.UnionToTuple<(typeof rules)[number]>;
7
6
  export interface RsdoctorWebpackPluginOptions<Rules extends LinterType.ExtendRuleData[]> {
8
7
  /** Checker configuration */
9
8
  linter?: LinterType.Options<Rules, InternalRules>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsdoctor/core",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/web-infra-dev/rsdoctor",
@@ -72,9 +72,10 @@
72
72
  "semver": "^7.5.4",
73
73
  "source-map": "^0.7.4",
74
74
  "webpack-bundle-analyzer": "^4.9.1",
75
- "@rsdoctor/graph": "0.2.2",
76
- "@rsdoctor/sdk": "0.2.2",
77
- "@rsdoctor/utils": "0.2.2"
75
+ "@rsdoctor/graph": "0.2.3",
76
+ "@rsdoctor/sdk": "0.2.3",
77
+ "@rsdoctor/types": "0.2.3",
78
+ "@rsdoctor/utils": "0.2.3"
78
79
  },
79
80
  "devDependencies": {
80
81
  "@rspack/core": "0.5.1",
@@ -94,7 +95,6 @@
94
95
  "tslib": "2.4.1",
95
96
  "typescript": "^5.2.2",
96
97
  "webpack": "^5.89.0",
97
- "@rsdoctor/types": "0.2.2",
98
98
  "@scripts/test-helper": "0.1.1"
99
99
  },
100
100
  "publishConfig": {