@rspack/core 1.0.5 → 1.0.6

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.
Files changed (37) hide show
  1. package/dist/Chunk.d.ts +5 -0
  2. package/dist/Chunk.js +28 -0
  3. package/dist/Compilation.d.ts +15 -7
  4. package/dist/Compilation.js +25 -8
  5. package/dist/Compiler.js +9 -21
  6. package/dist/Module.d.ts +20 -8
  7. package/dist/Module.js +66 -7
  8. package/dist/Resolver.d.ts +2 -4
  9. package/dist/RspackError.d.ts +2 -2
  10. package/dist/RspackError.js +3 -3
  11. package/dist/RuntimeModule.d.ts +32 -0
  12. package/dist/RuntimeModule.js +58 -0
  13. package/dist/builtin-plugin/ContextReplacementPlugin.d.ts +10 -0
  14. package/dist/builtin-plugin/ContextReplacementPlugin.js +43 -0
  15. package/dist/builtin-plugin/ProgressPlugin.d.ts +1 -1
  16. package/dist/builtin-plugin/ProgressPlugin.js +10 -8
  17. package/dist/builtin-plugin/index.d.ts +1 -0
  18. package/dist/builtin-plugin/index.js +1 -0
  19. package/dist/config/adapter.js +10 -14
  20. package/dist/config/adapterRuleUse.d.ts +40 -3
  21. package/dist/config/defaults.js +0 -4
  22. package/dist/config/zod.d.ts +16 -16
  23. package/dist/exports.d.ts +2 -0
  24. package/dist/exports.js +6 -2
  25. package/dist/loader-runner/index.js +30 -28
  26. package/dist/node/NodeEnvironmentPlugin.js +1 -1
  27. package/dist/stats/DefaultStatsFactoryPlugin.js +18 -29
  28. package/dist/stats/DefaultStatsPrinterPlugin.js +3 -5
  29. package/dist/stats/StatsFactory.d.ts +1 -1
  30. package/dist/stats/StatsFactory.js +1 -4
  31. package/dist/stats/statsFactoryUtils.d.ts +7 -3
  32. package/dist/stats/statsFactoryUtils.js +5 -6
  33. package/dist/util/comparators.d.ts +2 -2
  34. package/dist/util/smartGrouping.d.ts +4 -4
  35. package/dist/util/source.d.ts +1 -12
  36. package/dist/util/source.js +19 -43
  37. package/package.json +2 -2
@@ -468,18 +468,14 @@ function getRawParserOptions(parser, type) {
468
468
  }
469
469
  function getRawJavascriptParserOptions(parser) {
470
470
  return {
471
- dynamicImportMode: parser.dynamicImportMode ?? "lazy",
472
- dynamicImportPreload: parser.dynamicImportPreload?.toString() ?? "false",
473
- dynamicImportPrefetch: parser.dynamicImportPrefetch?.toString() ?? "false",
474
- dynamicImportFetchPriority: parser.dynamicImportFetchPriority?.toString(),
475
- importMeta: parser.importMeta ?? true,
476
- url: parser.url === false
477
- ? "false"
478
- : parser.url === "relative"
479
- ? parser.url
480
- : "true",
481
- exprContextCritical: parser.exprContextCritical ?? true,
482
- wrappedContextCritical: parser.wrappedContextCritical ?? false,
471
+ dynamicImportMode: parser.dynamicImportMode,
472
+ dynamicImportPreload: parser.dynamicImportPreload?.toString(),
473
+ dynamicImportPrefetch: parser.dynamicImportPrefetch?.toString(),
474
+ dynamicImportFetchPriority: parser.dynamicImportFetchPriority,
475
+ importMeta: parser.importMeta,
476
+ url: parser.url?.toString(),
477
+ exprContextCritical: parser.exprContextCritical,
478
+ wrappedContextCritical: parser.wrappedContextCritical,
483
479
  exportsPresence: parser.exportsPresence === false ? "false" : parser.exportsPresence,
484
480
  importExportsPresence: parser.importExportsPresence === false
485
481
  ? "false"
@@ -487,12 +483,12 @@ function getRawJavascriptParserOptions(parser) {
487
483
  reexportExportsPresence: parser.reexportExportsPresence === false
488
484
  ? "false"
489
485
  : parser.reexportExportsPresence,
490
- strictExportPresence: parser.strictExportPresence ?? false,
486
+ strictExportPresence: parser.strictExportPresence,
491
487
  worker: typeof parser.worker === "boolean"
492
488
  ? parser.worker
493
489
  ? ["..."]
494
490
  : []
495
- : parser.worker ?? ["..."],
491
+ : parser.worker,
496
492
  overrideStrict: parser.overrideStrict
497
493
  };
498
494
  }
@@ -28,14 +28,45 @@ export interface SourceMap {
28
28
  export interface AdditionalData {
29
29
  [index: string]: any;
30
30
  }
31
+ export type LoaderContextCallback = (err?: Error | null, content?: string | Buffer, sourceMap?: string | SourceMap, additionalData?: AdditionalData) => void;
32
+ export type ErrorWithDetails = Error & {
33
+ details?: string;
34
+ };
35
+ export type ResolveCallback = (err: null | ErrorWithDetails, res?: string | false, req?: ResolveRequest) => void;
36
+ export interface DiagnosticLocation {
37
+ /** Text for highlighting the location */
38
+ text?: string;
39
+ /** 1-based line */
40
+ line: number;
41
+ /** 0-based column in bytes */
42
+ column: number;
43
+ /** Length in bytes */
44
+ length: number;
45
+ }
46
+ export interface Diagnostic {
47
+ message: string;
48
+ help?: string;
49
+ sourceCode?: string;
50
+ /**
51
+ * Location to the source code.
52
+ *
53
+ * If `sourceCode` is not provided, location will be omitted.
54
+ */
55
+ location?: DiagnosticLocation;
56
+ file?: string;
57
+ severity: "error" | "warning";
58
+ }
59
+ interface LoaderExperiments {
60
+ emitDiagnostic(diagnostic: Diagnostic): void;
61
+ }
31
62
  export interface LoaderContext<OptionsType = {}> {
32
63
  version: 2;
33
64
  resource: string;
34
65
  resourcePath: string;
35
66
  resourceQuery: string;
36
67
  resourceFragment: string;
37
- async(): (err?: Error | null, content?: string | Buffer, sourceMap?: string | SourceMap, additionalData?: AdditionalData) => void;
38
- callback(err?: Error | null, content?: string | Buffer, sourceMap?: string | SourceMap, additionalData?: AdditionalData): void;
68
+ async(): LoaderContextCallback;
69
+ callback: LoaderContextCallback;
39
70
  cacheable(cacheable?: boolean): void;
40
71
  sourceMap: boolean;
41
72
  rootContext: string;
@@ -72,7 +103,7 @@ export interface LoaderContext<OptionsType = {}> {
72
103
  */
73
104
  getOptions(schema?: any): OptionsType;
74
105
  resolve(context: string, request: string, callback: (arg0: null | Error, arg1?: string | false, arg2?: ResolveRequest) => void): void;
75
- getResolve(options: Resolve): (context: any, request: any, callback: any) => Promise<any>;
106
+ getResolve(options: Resolve): ((context: string, request: string, callback: ResolveCallback) => void) | ((context: string, request: string) => Promise<string | false | undefined>);
76
107
  getLogger(name: string): Logger;
77
108
  emitError(error: Error): void;
78
109
  emitWarning(warning: Error): void;
@@ -92,6 +123,11 @@ export interface LoaderContext<OptionsType = {}> {
92
123
  baseUri?: string;
93
124
  }, callback: (err?: Error, res?: any) => void): void;
94
125
  fs: any;
126
+ /**
127
+ * This is an experimental API and maybe subject to change.
128
+ * @experimental
129
+ */
130
+ experiments: LoaderExperiments;
95
131
  utils: {
96
132
  absolutify: (context: string, request: string) => string;
97
133
  contextify: (context: string, request: string) => string;
@@ -119,3 +155,4 @@ export type LoaderDefinition<OptionsType = {}, ContextAdditions = {}> = LoaderDe
119
155
  export declare function createRawModuleRuleUses(uses: RuleSetUseItem | RuleSetUseItem[], path: string, options: ComposeJsUseOptions): RawModuleRuleUse[];
120
156
  export declare function isUseSourceMap(devtool: RawOptions["devtool"]): boolean;
121
157
  export declare function isUseSimpleSourceMap(devtool: RawOptions["devtool"]): boolean;
158
+ export {};
@@ -159,12 +159,8 @@ const applyJavascriptParserOptionsDefaults = (parserOptions) => {
159
159
  D(parserOptions, "url", true);
160
160
  D(parserOptions, "exprContextCritical", true);
161
161
  D(parserOptions, "wrappedContextCritical", false);
162
- D(parserOptions, "exportsPresence", undefined);
163
- D(parserOptions, "importExportsPresence", undefined);
164
- D(parserOptions, "reexportExportsPresence", undefined);
165
162
  D(parserOptions, "strictExportPresence", false);
166
163
  D(parserOptions, "worker", ["..."]);
167
- D(parserOptions, "overrideStrict", undefined);
168
164
  D(parserOptions, "importMeta", true);
169
165
  };
170
166
  const applyModuleDefaults = (module, { asyncWebAssembly, css, targetProperties }) => {
@@ -2103,11 +2103,11 @@ declare const baseRuleSetRule: z.ZodObject<{
2103
2103
  layer?: string | undefined;
2104
2104
  enforce?: "pre" | "post" | undefined;
2105
2105
  sideEffects?: boolean | undefined;
2106
- resource?: RuleSetCondition | undefined;
2107
2106
  loader?: string | undefined;
2108
2107
  issuer?: RuleSetCondition | undefined;
2109
2108
  issuerLayer?: RuleSetCondition | undefined;
2110
2109
  dependency?: RuleSetCondition | undefined;
2110
+ resource?: RuleSetCondition | undefined;
2111
2111
  resourceFragment?: RuleSetCondition | undefined;
2112
2112
  resourceQuery?: RuleSetCondition | undefined;
2113
2113
  scheme?: RuleSetCondition | undefined;
@@ -2139,11 +2139,11 @@ declare const baseRuleSetRule: z.ZodObject<{
2139
2139
  layer?: string | undefined;
2140
2140
  enforce?: "pre" | "post" | undefined;
2141
2141
  sideEffects?: boolean | undefined;
2142
- resource?: RuleSetCondition | undefined;
2143
2142
  loader?: string | undefined;
2144
2143
  issuer?: RuleSetCondition | undefined;
2145
2144
  issuerLayer?: RuleSetCondition | undefined;
2146
2145
  dependency?: RuleSetCondition | undefined;
2146
+ resource?: RuleSetCondition | undefined;
2147
2147
  resourceFragment?: RuleSetCondition | undefined;
2148
2148
  resourceQuery?: RuleSetCondition | undefined;
2149
2149
  scheme?: RuleSetCondition | undefined;
@@ -4933,6 +4933,7 @@ declare const statsOptions: z.ZodObject<{
4933
4933
  errorsSpace: z.ZodOptional<z.ZodNumber>;
4934
4934
  warningsSpace: z.ZodOptional<z.ZodNumber>;
4935
4935
  }, "strict", z.ZodTypeAny, {
4936
+ source?: boolean | undefined;
4936
4937
  publicPath?: boolean | undefined;
4937
4938
  hash?: boolean | undefined;
4938
4939
  all?: boolean | undefined;
@@ -4959,7 +4960,6 @@ declare const statsOptions: z.ZodObject<{
4959
4960
  builtAt?: boolean | undefined;
4960
4961
  moduleAssets?: boolean | undefined;
4961
4962
  nestedModules?: boolean | undefined;
4962
- source?: boolean | undefined;
4963
4963
  logging?: boolean | "log" | "info" | "verbose" | "none" | "error" | "warn" | undefined;
4964
4964
  loggingDebug?: string | boolean | RegExp | ((args_0: string, ...args_1: unknown[]) => boolean) | (string | RegExp | ((args_0: string, ...args_1: unknown[]) => boolean))[] | undefined;
4965
4965
  loggingTrace?: boolean | undefined;
@@ -5010,6 +5010,7 @@ declare const statsOptions: z.ZodObject<{
5010
5010
  errorsSpace?: number | undefined;
5011
5011
  warningsSpace?: number | undefined;
5012
5012
  }, {
5013
+ source?: boolean | undefined;
5013
5014
  publicPath?: boolean | undefined;
5014
5015
  hash?: boolean | undefined;
5015
5016
  all?: boolean | undefined;
@@ -5036,7 +5037,6 @@ declare const statsOptions: z.ZodObject<{
5036
5037
  builtAt?: boolean | undefined;
5037
5038
  moduleAssets?: boolean | undefined;
5038
5039
  nestedModules?: boolean | undefined;
5039
- source?: boolean | undefined;
5040
5040
  logging?: boolean | "log" | "info" | "verbose" | "none" | "error" | "warn" | undefined;
5041
5041
  loggingDebug?: string | boolean | RegExp | ((args_0: string, ...args_1: unknown[]) => boolean) | (string | RegExp | ((args_0: string, ...args_1: unknown[]) => boolean))[] | undefined;
5042
5042
  loggingTrace?: boolean | undefined;
@@ -5166,6 +5166,7 @@ declare const statsValue: z.ZodUnion<[z.ZodUnion<[z.ZodBoolean, z.ZodEnum<["norm
5166
5166
  errorsSpace: z.ZodOptional<z.ZodNumber>;
5167
5167
  warningsSpace: z.ZodOptional<z.ZodNumber>;
5168
5168
  }, "strict", z.ZodTypeAny, {
5169
+ source?: boolean | undefined;
5169
5170
  publicPath?: boolean | undefined;
5170
5171
  hash?: boolean | undefined;
5171
5172
  all?: boolean | undefined;
@@ -5192,7 +5193,6 @@ declare const statsValue: z.ZodUnion<[z.ZodUnion<[z.ZodBoolean, z.ZodEnum<["norm
5192
5193
  builtAt?: boolean | undefined;
5193
5194
  moduleAssets?: boolean | undefined;
5194
5195
  nestedModules?: boolean | undefined;
5195
- source?: boolean | undefined;
5196
5196
  logging?: boolean | "log" | "info" | "verbose" | "none" | "error" | "warn" | undefined;
5197
5197
  loggingDebug?: string | boolean | RegExp | ((args_0: string, ...args_1: unknown[]) => boolean) | (string | RegExp | ((args_0: string, ...args_1: unknown[]) => boolean))[] | undefined;
5198
5198
  loggingTrace?: boolean | undefined;
@@ -5243,6 +5243,7 @@ declare const statsValue: z.ZodUnion<[z.ZodUnion<[z.ZodBoolean, z.ZodEnum<["norm
5243
5243
  errorsSpace?: number | undefined;
5244
5244
  warningsSpace?: number | undefined;
5245
5245
  }, {
5246
+ source?: boolean | undefined;
5246
5247
  publicPath?: boolean | undefined;
5247
5248
  hash?: boolean | undefined;
5248
5249
  all?: boolean | undefined;
@@ -5269,7 +5270,6 @@ declare const statsValue: z.ZodUnion<[z.ZodUnion<[z.ZodBoolean, z.ZodEnum<["norm
5269
5270
  builtAt?: boolean | undefined;
5270
5271
  moduleAssets?: boolean | undefined;
5271
5272
  nestedModules?: boolean | undefined;
5272
- source?: boolean | undefined;
5273
5273
  logging?: boolean | "log" | "info" | "verbose" | "none" | "error" | "warn" | undefined;
5274
5274
  loggingDebug?: string | boolean | RegExp | ((args_0: string, ...args_1: unknown[]) => boolean) | (string | RegExp | ((args_0: string, ...args_1: unknown[]) => boolean))[] | undefined;
5275
5275
  loggingTrace?: boolean | undefined;
@@ -5882,7 +5882,7 @@ declare const optimization: z.ZodObject<{
5882
5882
  providedExports?: boolean | undefined;
5883
5883
  concatenateModules?: boolean | undefined;
5884
5884
  innerGraph?: boolean | undefined;
5885
- mangleExports?: boolean | "deterministic" | "size" | undefined;
5885
+ mangleExports?: boolean | "size" | "deterministic" | undefined;
5886
5886
  nodeEnv?: string | false | undefined;
5887
5887
  emitOnErrors?: boolean | undefined;
5888
5888
  }, {
@@ -5948,7 +5948,7 @@ declare const optimization: z.ZodObject<{
5948
5948
  providedExports?: boolean | undefined;
5949
5949
  concatenateModules?: boolean | undefined;
5950
5950
  innerGraph?: boolean | undefined;
5951
- mangleExports?: boolean | "deterministic" | "size" | undefined;
5951
+ mangleExports?: boolean | "size" | "deterministic" | undefined;
5952
5952
  nodeEnv?: string | false | undefined;
5953
5953
  emitOnErrors?: boolean | undefined;
5954
5954
  }>;
@@ -7606,6 +7606,7 @@ export declare const rspackOptions: z.ZodObject<{
7606
7606
  errorsSpace: z.ZodOptional<z.ZodNumber>;
7607
7607
  warningsSpace: z.ZodOptional<z.ZodNumber>;
7608
7608
  }, "strict", z.ZodTypeAny, {
7609
+ source?: boolean | undefined;
7609
7610
  publicPath?: boolean | undefined;
7610
7611
  hash?: boolean | undefined;
7611
7612
  all?: boolean | undefined;
@@ -7632,7 +7633,6 @@ export declare const rspackOptions: z.ZodObject<{
7632
7633
  builtAt?: boolean | undefined;
7633
7634
  moduleAssets?: boolean | undefined;
7634
7635
  nestedModules?: boolean | undefined;
7635
- source?: boolean | undefined;
7636
7636
  logging?: boolean | "log" | "info" | "verbose" | "none" | "error" | "warn" | undefined;
7637
7637
  loggingDebug?: string | boolean | RegExp | ((args_0: string, ...args_1: unknown[]) => boolean) | (string | RegExp | ((args_0: string, ...args_1: unknown[]) => boolean))[] | undefined;
7638
7638
  loggingTrace?: boolean | undefined;
@@ -7683,6 +7683,7 @@ export declare const rspackOptions: z.ZodObject<{
7683
7683
  errorsSpace?: number | undefined;
7684
7684
  warningsSpace?: number | undefined;
7685
7685
  }, {
7686
+ source?: boolean | undefined;
7686
7687
  publicPath?: boolean | undefined;
7687
7688
  hash?: boolean | undefined;
7688
7689
  all?: boolean | undefined;
@@ -7709,7 +7710,6 @@ export declare const rspackOptions: z.ZodObject<{
7709
7710
  builtAt?: boolean | undefined;
7710
7711
  moduleAssets?: boolean | undefined;
7711
7712
  nestedModules?: boolean | undefined;
7712
- source?: boolean | undefined;
7713
7713
  logging?: boolean | "log" | "info" | "verbose" | "none" | "error" | "warn" | undefined;
7714
7714
  loggingDebug?: string | boolean | RegExp | ((args_0: string, ...args_1: unknown[]) => boolean) | (string | RegExp | ((args_0: string, ...args_1: unknown[]) => boolean))[] | undefined;
7715
7715
  loggingTrace?: boolean | undefined;
@@ -8042,7 +8042,7 @@ export declare const rspackOptions: z.ZodObject<{
8042
8042
  providedExports?: boolean | undefined;
8043
8043
  concatenateModules?: boolean | undefined;
8044
8044
  innerGraph?: boolean | undefined;
8045
- mangleExports?: boolean | "deterministic" | "size" | undefined;
8045
+ mangleExports?: boolean | "size" | "deterministic" | undefined;
8046
8046
  nodeEnv?: string | false | undefined;
8047
8047
  emitOnErrors?: boolean | undefined;
8048
8048
  }, {
@@ -8108,7 +8108,7 @@ export declare const rspackOptions: z.ZodObject<{
8108
8108
  providedExports?: boolean | undefined;
8109
8109
  concatenateModules?: boolean | undefined;
8110
8110
  innerGraph?: boolean | undefined;
8111
- mangleExports?: boolean | "deterministic" | "size" | undefined;
8111
+ mangleExports?: boolean | "size" | "deterministic" | undefined;
8112
8112
  nodeEnv?: string | false | undefined;
8113
8113
  emitOnErrors?: boolean | undefined;
8114
8114
  }>>;
@@ -9429,6 +9429,7 @@ export declare const rspackOptions: z.ZodObject<{
9429
9429
  } | undefined;
9430
9430
  watch?: boolean | undefined;
9431
9431
  stats?: boolean | "verbose" | "normal" | "none" | "errors-only" | "errors-warnings" | "minimal" | "detailed" | "summary" | {
9432
+ source?: boolean | undefined;
9432
9433
  publicPath?: boolean | undefined;
9433
9434
  hash?: boolean | undefined;
9434
9435
  all?: boolean | undefined;
@@ -9455,7 +9456,6 @@ export declare const rspackOptions: z.ZodObject<{
9455
9456
  builtAt?: boolean | undefined;
9456
9457
  moduleAssets?: boolean | undefined;
9457
9458
  nestedModules?: boolean | undefined;
9458
- source?: boolean | undefined;
9459
9459
  logging?: boolean | "log" | "info" | "verbose" | "none" | "error" | "warn" | undefined;
9460
9460
  loggingDebug?: string | boolean | RegExp | ((args_0: string, ...args_1: unknown[]) => boolean) | (string | RegExp | ((args_0: string, ...args_1: unknown[]) => boolean))[] | undefined;
9461
9461
  loggingTrace?: boolean | undefined;
@@ -9570,7 +9570,7 @@ export declare const rspackOptions: z.ZodObject<{
9570
9570
  providedExports?: boolean | undefined;
9571
9571
  concatenateModules?: boolean | undefined;
9572
9572
  innerGraph?: boolean | undefined;
9573
- mangleExports?: boolean | "deterministic" | "size" | undefined;
9573
+ mangleExports?: boolean | "size" | "deterministic" | undefined;
9574
9574
  nodeEnv?: string | false | undefined;
9575
9575
  emitOnErrors?: boolean | undefined;
9576
9576
  } | undefined;
@@ -10003,6 +10003,7 @@ export declare const rspackOptions: z.ZodObject<{
10003
10003
  } | undefined;
10004
10004
  watch?: boolean | undefined;
10005
10005
  stats?: boolean | "verbose" | "normal" | "none" | "errors-only" | "errors-warnings" | "minimal" | "detailed" | "summary" | {
10006
+ source?: boolean | undefined;
10006
10007
  publicPath?: boolean | undefined;
10007
10008
  hash?: boolean | undefined;
10008
10009
  all?: boolean | undefined;
@@ -10029,7 +10030,6 @@ export declare const rspackOptions: z.ZodObject<{
10029
10030
  builtAt?: boolean | undefined;
10030
10031
  moduleAssets?: boolean | undefined;
10031
10032
  nestedModules?: boolean | undefined;
10032
- source?: boolean | undefined;
10033
10033
  logging?: boolean | "log" | "info" | "verbose" | "none" | "error" | "warn" | undefined;
10034
10034
  loggingDebug?: string | boolean | RegExp | ((args_0: string, ...args_1: unknown[]) => boolean) | (string | RegExp | ((args_0: string, ...args_1: unknown[]) => boolean))[] | undefined;
10035
10035
  loggingTrace?: boolean | undefined;
@@ -10144,7 +10144,7 @@ export declare const rspackOptions: z.ZodObject<{
10144
10144
  providedExports?: boolean | undefined;
10145
10145
  concatenateModules?: boolean | undefined;
10146
10146
  innerGraph?: boolean | undefined;
10147
- mangleExports?: boolean | "deterministic" | "size" | undefined;
10147
+ mangleExports?: boolean | "size" | "deterministic" | undefined;
10148
10148
  nodeEnv?: string | false | undefined;
10149
10149
  emitOnErrors?: boolean | undefined;
10150
10150
  } | undefined;
package/dist/exports.d.ts CHANGED
@@ -17,6 +17,7 @@ export type { NormalModuleFactory } from "./NormalModuleFactory";
17
17
  export { RuntimeGlobals } from "./RuntimeGlobals";
18
18
  export type { StatsAsset, StatsChunk, StatsCompilation, StatsError, StatsModule } from "./Stats";
19
19
  export { Stats } from "./Stats";
20
+ export { RuntimeModule } from "./RuntimeModule";
20
21
  import * as ModuleFilenameHelpers from "./lib/ModuleFilenameHelpers";
21
22
  export { ModuleFilenameHelpers };
22
23
  export { Template } from "./Template";
@@ -149,6 +150,7 @@ export { SourceMapDevToolPlugin } from "./builtin-plugin";
149
150
  export { EvalSourceMapDevToolPlugin } from "./builtin-plugin";
150
151
  export { EvalDevToolModulePlugin } from "./builtin-plugin";
151
152
  export { CssExtractRspackPlugin } from "./builtin-plugin";
153
+ export { ContextReplacementPlugin } from "./builtin-plugin";
152
154
  export type { SwcLoaderEnvConfig, SwcLoaderEsParserConfig, SwcLoaderJscConfig, SwcLoaderModuleConfig, SwcLoaderOptions, SwcLoaderParserConfig, SwcLoaderTransformConfig, SwcLoaderTsParserConfig } from "./builtin-loader/swc/index";
153
155
  export { type LoaderOptions as LightningcssLoaderOptions, type FeatureOptions as LightningcssFeatureOptions } from "./builtin-loader/lightningcss/index";
154
156
  import { cleanupGlobalTrace, registerGlobalTrace } from "@rspack/binding";
package/dist/exports.js CHANGED
@@ -26,8 +26,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.EvalDevToolModulePlugin = exports.EvalSourceMapDevToolPlugin = exports.SourceMapDevToolPlugin = exports.CopyRspackPlugin = exports.LightningCssMinimizerRspackPlugin = exports.SwcJsMinimizerRspackPlugin = exports.HtmlRspackPlugin = exports.sharing = exports.container = exports.optimize = exports.webworker = exports.javascript = exports.wasm = exports.library = exports.electron = exports.node = exports.web = exports.NormalModuleReplacementPlugin = exports.LoaderTargetPlugin = exports.LoaderOptionsPlugin = exports.EnvironmentPlugin = exports.NoEmitOnErrorsPlugin = exports.HotModuleReplacementPlugin = exports.ExternalsPlugin = exports.DynamicEntryPlugin = exports.EntryPlugin = exports.ProgressPlugin = exports.DefinePlugin = exports.ProvidePlugin = exports.IgnorePlugin = exports.BannerPlugin = exports.EntryOptionPlugin = exports.util = exports.ValidationError = exports.config = exports.sources = exports.WebpackError = exports.Template = exports.ModuleFilenameHelpers = exports.Stats = exports.RuntimeGlobals = exports.NormalModule = exports.MultiStats = exports.WebpackOptionsApply = exports.RspackOptionsApply = exports.MultiCompiler = exports.Compiler = exports.Compilation = exports.version = exports.rspackVersion = void 0;
30
- exports.experiments = exports.CssExtractRspackPlugin = void 0;
29
+ exports.EvalSourceMapDevToolPlugin = exports.SourceMapDevToolPlugin = exports.CopyRspackPlugin = exports.LightningCssMinimizerRspackPlugin = exports.SwcJsMinimizerRspackPlugin = exports.HtmlRspackPlugin = exports.sharing = exports.container = exports.optimize = exports.webworker = exports.javascript = exports.wasm = exports.library = exports.electron = exports.node = exports.web = exports.NormalModuleReplacementPlugin = exports.LoaderTargetPlugin = exports.LoaderOptionsPlugin = exports.EnvironmentPlugin = exports.NoEmitOnErrorsPlugin = exports.HotModuleReplacementPlugin = exports.ExternalsPlugin = exports.DynamicEntryPlugin = exports.EntryPlugin = exports.ProgressPlugin = exports.DefinePlugin = exports.ProvidePlugin = exports.IgnorePlugin = exports.BannerPlugin = exports.EntryOptionPlugin = exports.util = exports.ValidationError = exports.config = exports.sources = exports.WebpackError = exports.Template = exports.ModuleFilenameHelpers = exports.RuntimeModule = exports.Stats = exports.RuntimeGlobals = exports.NormalModule = exports.MultiStats = exports.WebpackOptionsApply = exports.RspackOptionsApply = exports.MultiCompiler = exports.Compiler = exports.Compilation = exports.version = exports.rspackVersion = void 0;
30
+ exports.experiments = exports.ContextReplacementPlugin = exports.CssExtractRspackPlugin = exports.EvalDevToolModulePlugin = void 0;
31
31
  const package_json_1 = require("../package.json");
32
32
  // this is a hack to be compatible with plugin which detect webpack's version
33
33
  const rspackVersion = package_json_1.version;
@@ -51,6 +51,8 @@ var RuntimeGlobals_1 = require("./RuntimeGlobals");
51
51
  Object.defineProperty(exports, "RuntimeGlobals", { enumerable: true, get: function () { return RuntimeGlobals_1.RuntimeGlobals; } });
52
52
  var Stats_1 = require("./Stats");
53
53
  Object.defineProperty(exports, "Stats", { enumerable: true, get: function () { return Stats_1.Stats; } });
54
+ var RuntimeModule_1 = require("./RuntimeModule");
55
+ Object.defineProperty(exports, "RuntimeModule", { enumerable: true, get: function () { return RuntimeModule_1.RuntimeModule; } });
54
56
  // API extractor not working with some re-exports, see: https://github.com/microsoft/fluentui/issues/20694
55
57
  const ModuleFilenameHelpers = __importStar(require("./lib/ModuleFilenameHelpers"));
56
58
  exports.ModuleFilenameHelpers = ModuleFilenameHelpers;
@@ -169,6 +171,8 @@ var builtin_plugin_27 = require("./builtin-plugin");
169
171
  Object.defineProperty(exports, "EvalDevToolModulePlugin", { enumerable: true, get: function () { return builtin_plugin_27.EvalDevToolModulePlugin; } });
170
172
  var builtin_plugin_28 = require("./builtin-plugin");
171
173
  Object.defineProperty(exports, "CssExtractRspackPlugin", { enumerable: true, get: function () { return builtin_plugin_28.CssExtractRspackPlugin; } });
174
+ var builtin_plugin_29 = require("./builtin-plugin");
175
+ Object.defineProperty(exports, "ContextReplacementPlugin", { enumerable: true, get: function () { return builtin_plugin_29.ContextReplacementPlugin; } });
172
176
  ///// Experiments Stuff /////
173
177
  const binding_1 = require("@rspack/binding");
174
178
  exports.experiments = {
@@ -181,17 +181,16 @@ const runSyncOrAsync = (0, node_util_1.promisify)(function runSyncOrAsync(fn, co
181
181
  let isDone = false;
182
182
  let isError = false; // internal error
183
183
  let reportedError = false;
184
- // @ts-expect-error loader-runner leverages `arguments` to achieve the same functionality.
185
184
  context.async = function async() {
186
185
  if (isDone) {
187
186
  if (reportedError)
188
- return; // ignore
187
+ return undefined; // ignore
189
188
  throw new Error("async(): The callback was already called.");
190
189
  }
191
190
  isSync = false;
192
191
  return innerCallback;
193
192
  };
194
- const innerCallback = (context.callback = (err, ...args) => {
193
+ const innerCallback = (err, ...args) => {
195
194
  if (isDone) {
196
195
  if (reportedError)
197
196
  return; // ignore
@@ -200,14 +199,14 @@ const runSyncOrAsync = (0, node_util_1.promisify)(function runSyncOrAsync(fn, co
200
199
  isDone = true;
201
200
  isSync = false;
202
201
  try {
203
- // @ts-expect-error
204
202
  callback(err, args);
205
203
  }
206
204
  catch (e) {
207
205
  isError = true;
208
206
  throw e;
209
207
  }
210
- });
208
+ };
209
+ context.callback = innerCallback;
211
210
  try {
212
211
  const result = (function LOADER_EXECUTION() {
213
212
  return fn.apply(context, args);
@@ -215,8 +214,7 @@ const runSyncOrAsync = (0, node_util_1.promisify)(function runSyncOrAsync(fn, co
215
214
  if (isSync) {
216
215
  isDone = true;
217
216
  if (result === undefined) {
218
- // @ts-expect-error
219
- callback();
217
+ callback(null, []);
220
218
  return;
221
219
  }
222
220
  if (result &&
@@ -250,8 +248,7 @@ const runSyncOrAsync = (0, node_util_1.promisify)(function runSyncOrAsync(fn, co
250
248
  }
251
249
  isDone = true;
252
250
  reportedError = true;
253
- // @ts-expect-error
254
- callback(e);
251
+ callback(e, []);
255
252
  }
256
253
  });
257
254
  function dirname(path) {
@@ -485,23 +482,22 @@ async function runLoaders(compiler, context) {
485
482
  loaderContext.resolve = function resolve(context, request, callback) {
486
483
  resolver.resolve({}, context, request, getResolveContext(), callback);
487
484
  };
488
- // @ts-expect-error TODO
489
485
  loaderContext.getResolve = function getResolve(options) {
490
486
  const child = options ? resolver.withOptions(options) : resolver;
491
487
  return (context, request, callback) => {
492
488
  if (callback) {
493
489
  child.resolve({}, context, request, getResolveContext(), callback);
490
+ return;
494
491
  }
495
- else {
496
- return new Promise((resolve, reject) => {
497
- child.resolve({}, context, request, getResolveContext(), (err, result) => {
498
- if (err)
499
- reject(err);
500
- else
501
- resolve(result);
502
- });
492
+ // TODO: (type) our native resolver return value is "string | false" but webpack type is "string"
493
+ return new Promise((resolve, reject) => {
494
+ child.resolve({}, context, request, getResolveContext(), (err, result) => {
495
+ if (err)
496
+ reject(err);
497
+ else
498
+ resolve(result);
503
499
  });
504
- }
500
+ });
505
501
  };
506
502
  };
507
503
  loaderContext.getLogger = function getLogger(name) {
@@ -517,7 +513,7 @@ async function runLoaders(compiler, context) {
517
513
  error.message = `${error.message} (from: ${(0, util_1.stringifyLoaderObject)(loaderContext.loaders[loaderContext.loaderIndex])})`;
518
514
  error = (0, util_1.concatErrorMsgAndStack)(error);
519
515
  error.moduleIdentifier = this._module.identifier();
520
- compiler._lastCompilation.__internal__pushDiagnostic({
516
+ compiler._lastCompilation.__internal__pushRspackDiagnostic({
521
517
  error,
522
518
  severity: binding_1.JsRspackSeverity.Error
523
519
  });
@@ -531,13 +527,13 @@ async function runLoaders(compiler, context) {
531
527
  warning.message = `${warning.message} (from: ${(0, util_1.stringifyLoaderObject)(loaderContext.loaders[loaderContext.loaderIndex])})`;
532
528
  warning = (0, util_1.concatErrorMsgAndStack)(warning);
533
529
  warning.moduleIdentifier = this._module.identifier();
534
- compiler._lastCompilation.__internal__pushDiagnostic({
530
+ compiler._lastCompilation.__internal__pushRspackDiagnostic({
535
531
  error: warning,
536
532
  severity: binding_1.JsRspackSeverity.Warn
537
533
  });
538
534
  };
539
535
  loaderContext.emitFile = function emitFile(name, content, sourceMap, assetInfo) {
540
- let source;
536
+ let source = undefined;
541
537
  if (sourceMap) {
542
538
  if (typeof sourceMap === "string" &&
543
539
  (loaderContext.sourceMap ||
@@ -556,14 +552,20 @@ async function runLoaders(compiler, context) {
556
552
  // @ts-expect-error webpack-sources type declaration is wrong
557
553
  content);
558
554
  }
559
- // @ts-expect-error
560
- compiler._lastCompilation.__internal__emit_asset_from_loader(name,
561
- // @ts-expect-error
562
- source,
563
- // @ts-expect-error
564
- assetInfo, context._moduleIdentifier);
555
+ compiler._lastCompilation.__internal__emit_asset_from_loader(name, source, assetInfo, context._moduleIdentifier);
565
556
  };
566
557
  loaderContext.fs = compiler.inputFileSystem;
558
+ loaderContext.experiments = {
559
+ emitDiagnostic: (diagnostic) => {
560
+ const d = Object.assign({}, diagnostic, {
561
+ message: diagnostic.severity === "warning"
562
+ ? `ModuleWarning: ${diagnostic.message}`
563
+ : `ModuleError: ${diagnostic.message}`,
564
+ moduleIdentifier: context._module.moduleIdentifier
565
+ });
566
+ compiler._lastCompilation.__internal__pushDiagnostic((0, binding_1.formatDiagnostic)(d));
567
+ }
568
+ };
567
569
  const getAbsolutify = (0, memoize_1.memoize)(() => identifier_1.absolutify.bindCache(compiler.root));
568
570
  const getAbsolutifyInContext = (0, memoize_1.memoize)(() => identifier_1.absolutify.bindContextCache(contextDirectory, compiler.root));
569
571
  const getContextify = (0, memoize_1.memoize)(() => identifier_1.contextify.bindCache(compiler.root));
@@ -12,7 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  * Copyright (c) JS Foundation and other contributors
13
13
  * https://github.com/webpack/webpack/blob/main/LICENSE
14
14
  */
15
- // @ts-expect-error
15
+ // @ts-expect-error we directly import from enhanced-resolve inner js file to improve performance
16
16
  const CachedInputFileSystem_1 = __importDefault(require("../../compiled/enhanced-resolve/CachedInputFileSystem"));
17
17
  const graceful_fs_1 = __importDefault(require("../../compiled/graceful-fs"));
18
18
  const createConsoleLogger_1 = require("../logging/createConsoleLogger");