@rspack/core 0.7.5-canary-910259c-20240624004455 → 0.7.5-canary-0d03907-20240624125011

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/Chunk.d.ts CHANGED
@@ -14,7 +14,7 @@ export declare class Chunk {
14
14
  hash?: Readonly<string>;
15
15
  contentHash: Readonly<Record<string, string>>;
16
16
  renderedHash?: Readonly<string>;
17
- chunkReason: ReadonlyArray<string>;
17
+ chunkReason?: Readonly<string>;
18
18
  auxiliaryFiles: ReadonlySet<string>;
19
19
  static __from_binding(chunk: JsChunk, compilation: Compilation): Chunk;
20
20
  static __from_binding(chunk: JsChunk, compilation: JsCompilation): Chunk;
@@ -7,7 +7,8 @@
7
7
  * Copyright (c) JS Foundation and other contributors
8
8
  * https://github.com/webpack/webpack/blob/main/LICENSE
9
9
  */
10
- import type { ExternalObject, JsCompilation, JsModule, JsPathData, JsRuntimeModule, JsStatsError, JsStatsWarning } from "@rspack/binding";
10
+ import type * as binding from "@rspack/binding";
11
+ import { type ExternalObject, type JsCompilation, type JsModule, type JsPathData, type JsRuntimeModule } from "@rspack/binding";
11
12
  import * as tapable from "tapable";
12
13
  import { Source } from "webpack-sources";
13
14
  import { ContextModuleFactory } from "./ContextModuleFactory";
@@ -26,6 +27,7 @@ import { StatsFactory } from "./stats/StatsFactory";
26
27
  import { StatsPrinter } from "./stats/StatsPrinter";
27
28
  import { type AssetInfo } from "./util/AssetInfo";
28
29
  import Hash = require("./util/hash");
30
+ import { RspackError } from "./RspackError";
29
31
  export { type AssetInfo } from "./util/AssetInfo";
30
32
  export type Assets = Record<string, Source>;
31
33
  export interface Asset {
@@ -215,19 +217,19 @@ export declare class Compilation {
215
217
  *
216
218
  * @internal
217
219
  */
218
- __internal__pushDiagnostic(severity: "error" | "warning", title: string, message: string): void;
220
+ __internal__pushDiagnostic(diagnostic: binding.JsDiagnostic): void;
219
221
  /**
220
222
  * Note: This is not a webpack public API, maybe removed in future.
221
223
  *
222
224
  * @internal
223
225
  */
224
226
  __internal__pushNativeDiagnostics(diagnostics: ExternalObject<"Diagnostic[]">): void;
225
- get errors(): JsStatsError[];
226
- get warnings(): JsStatsWarning[];
227
+ get errors(): RspackError[];
228
+ get warnings(): RspackError[];
227
229
  getPath(filename: Filename, data?: PathData): string;
228
- getPathWithInfo(filename: Filename, data?: PathData): import("@rspack/binding").PathWithInfo;
230
+ getPathWithInfo(filename: Filename, data?: PathData): binding.PathWithInfo;
229
231
  getAssetPath(filename: Filename, data?: PathData): string;
230
- getAssetPathWithInfo(filename: Filename, data?: PathData): import("@rspack/binding").PathWithInfo;
232
+ getAssetPathWithInfo(filename: Filename, data?: PathData): binding.PathWithInfo;
231
233
  getLogger(name: string | (() => string)): Logger;
232
234
  fileDependencies: {
233
235
  [Symbol.iterator](): Generator<string, void, unknown>;
@@ -313,7 +315,7 @@ export declare class Compilation {
313
315
  *
314
316
  * @internal
315
317
  */
316
- __internal_getInner(): JsCompilation;
318
+ __internal_getInner(): binding.JsCompilation;
317
319
  seal(): void;
318
320
  unseal(): void;
319
321
  static PROCESS_ASSETS_STAGE_ADDITIONAL: number;
@@ -39,6 +39,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
39
39
  var _Compilation_instances, _Compilation_inner, _Compilation_cachedAssets, _Compilation_customModules, _Compilation_createCachedAssets, _Compilation_rebuildModuleCaller;
40
40
  Object.defineProperty(exports, "__esModule", { value: true });
41
41
  exports.Compilation = void 0;
42
+ const binding_1 = require("@rspack/binding");
42
43
  const tapable = __importStar(require("tapable"));
43
44
  const liteTapable = __importStar(require("./lite-tapable"));
44
45
  const Chunk_1 = require("./Chunk");
@@ -50,12 +51,12 @@ const Stats_1 = require("./Stats");
50
51
  const Logger_1 = require("./logging/Logger");
51
52
  const StatsFactory_1 = require("./stats/StatsFactory");
52
53
  const StatsPrinter_1 = require("./stats/StatsPrinter");
53
- const util_1 = require("./util");
54
54
  const AssetInfo_1 = require("./util/AssetInfo");
55
55
  const MergeCaller_1 = __importDefault(require("./util/MergeCaller"));
56
56
  const fake_1 = require("./util/fake");
57
57
  const memoize_1 = require("./util/memoize");
58
58
  const source_1 = require("./util/source");
59
+ const RspackError_1 = require("./RspackError");
59
60
  class Compilation {
60
61
  constructor(compiler, inner) {
61
62
  _Compilation_instances.add(this);
@@ -339,8 +340,8 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
339
340
  *
340
341
  * @internal
341
342
  */
342
- __internal__pushDiagnostic(severity, title, message) {
343
- __classPrivateFieldGet(this, _Compilation_inner, "f").pushDiagnostic(severity, title, message);
343
+ __internal__pushDiagnostic(diagnostic) {
344
+ __classPrivateFieldGet(this, _Compilation_inner, "f").pushDiagnostic(diagnostic);
344
345
  }
345
346
  /**
346
347
  * Note: This is not a webpack public API, maybe removed in future.
@@ -352,14 +353,14 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
352
353
  }
353
354
  get errors() {
354
355
  const inner = __classPrivateFieldGet(this, _Compilation_inner, "f");
355
- const errors = inner.getStats().getErrors();
356
+ const errors = inner.getErrors();
356
357
  const proxyMethod = [
357
358
  {
358
359
  method: "push",
359
360
  handler(target, thisArg, errs) {
360
361
  for (let i = 0; i < errs.length; i++) {
361
362
  const error = errs[i];
362
- inner.pushDiagnostic("error", error instanceof Error ? error.name : "Error", (0, util_1.concatErrorMsgAndStack)(error));
363
+ inner.pushDiagnostic(RspackError_1.JsDiagnostic.__to_binding(error, binding_1.JsRspackSeverity.Error));
363
364
  }
364
365
  return Reflect.apply(target, thisArg, errs);
365
366
  }
@@ -382,11 +383,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
382
383
  method: "unshift",
383
384
  handler(target, thisArg, errs) {
384
385
  const errList = errs.map(error => {
385
- return {
386
- severity: "error",
387
- title: error instanceof Error ? error.name : "Error",
388
- message: (0, util_1.concatErrorMsgAndStack)(error)
389
- };
386
+ return RspackError_1.JsDiagnostic.__to_binding(error, binding_1.JsRspackSeverity.Error);
390
387
  });
391
388
  inner.spliceDiagnostic(0, 0, errList);
392
389
  return Reflect.apply(target, thisArg, errs);
@@ -396,11 +393,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
396
393
  method: "splice",
397
394
  handler(target, thisArg, [startIdx, delCount, ...errors]) {
398
395
  const errList = errors.map(error => {
399
- return {
400
- severity: "error",
401
- title: error instanceof Error ? error.name : "Error",
402
- message: (0, util_1.concatErrorMsgAndStack)(error)
403
- };
396
+ return RspackError_1.JsDiagnostic.__to_binding(error, binding_1.JsRspackSeverity.Error);
404
397
  });
405
398
  inner.spliceDiagnostic(startIdx, startIdx + delCount, errList);
406
399
  return Reflect.apply(target, thisArg, [
@@ -422,7 +415,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
422
415
  get warnings() {
423
416
  const inner = __classPrivateFieldGet(this, _Compilation_inner, "f");
424
417
  const processWarningsHook = this.hooks.processWarnings;
425
- const warnings = inner.getStats().getWarnings();
418
+ const warnings = inner.getWarnings();
426
419
  const proxyMethod = [
427
420
  {
428
421
  method: "push",
@@ -430,7 +423,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
430
423
  warns = processWarningsHook.call(warns);
431
424
  for (let i = 0; i < warns.length; i++) {
432
425
  const warn = warns[i];
433
- inner.pushDiagnostic("warning", warn instanceof Error ? warn.name : "Warning", (0, util_1.concatErrorMsgAndStack)(warn));
426
+ inner.pushDiagnostic(RspackError_1.JsDiagnostic.__to_binding(warn, binding_1.JsRspackSeverity.Warn));
434
427
  }
435
428
  return Reflect.apply(target, thisArg, warns);
436
429
  }
@@ -454,11 +447,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
454
447
  handler(target, thisArg, warns) {
455
448
  warns = processWarningsHook.call(warns);
456
449
  const warnList = warns.map(warn => {
457
- return {
458
- severity: "warning",
459
- title: warn instanceof Error ? warn.name : "Warning",
460
- message: (0, util_1.concatErrorMsgAndStack)(warn)
461
- };
450
+ return RspackError_1.JsDiagnostic.__to_binding(warn, binding_1.JsRspackSeverity.Warn);
462
451
  });
463
452
  inner.spliceDiagnostic(0, 0, warnList);
464
453
  return Reflect.apply(target, thisArg, warns);
@@ -469,11 +458,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
469
458
  handler(target, thisArg, [startIdx, delCount, ...warns]) {
470
459
  warns = processWarningsHook.call(warns);
471
460
  const warnList = warns.map(warn => {
472
- return {
473
- severity: "warning",
474
- title: warn instanceof Error ? warn.name : "Warning",
475
- message: (0, util_1.concatErrorMsgAndStack)(warn)
476
- };
461
+ return RspackError_1.JsDiagnostic.__to_binding(warn, binding_1.JsRspackSeverity.Warn);
477
462
  });
478
463
  inner.spliceDiagnostic(startIdx, startIdx + delCount, warnList);
479
464
  return Reflect.apply(target, thisArg, [
package/dist/Module.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { JsCodegenerationResult, JsCodegenerationResults, JsCreateData, JsModule } from "@rspack/binding";
1
+ import { JsCodegenerationResult, JsCodegenerationResults, JsCreateData, JsFactoryMeta, JsModule } from "@rspack/binding";
2
2
  import { Source } from "webpack-sources";
3
3
  import { Compilation } from "./Compilation";
4
4
  export type ResourceData = {
@@ -37,6 +37,7 @@ export declare class Module {
37
37
  request?: Readonly<string>;
38
38
  userRequest?: Readonly<string>;
39
39
  rawRequest?: Readonly<string>;
40
+ factoryMeta?: Readonly<JsFactoryMeta>;
40
41
  /**
41
42
  * Records the dynamically added fields for Module on the JavaScript side.
42
43
  * These fields are generally used within a plugin, so they do not need to be passed back to the Rust side.
package/dist/Module.js CHANGED
@@ -27,6 +27,7 @@ class Module {
27
27
  this.request = module.request;
28
28
  this.userRequest = module.userRequest;
29
29
  this.rawRequest = module.rawRequest;
30
+ this.factoryMeta = module.factoryMeta;
30
31
  const customModule = compilation?.__internal__getCustomModule(module.moduleIdentifier);
31
32
  this.buildInfo = customModule?.buildInfo || {};
32
33
  this.buildMeta = customModule?.buildMeta || {};
@@ -0,0 +1,8 @@
1
+ import * as binding from "@rspack/binding";
2
+ export type RspackError = binding.JsRspackError;
3
+ export declare class JsDiagnostic {
4
+ static __to_binding(error: Error | RspackError, severity: binding.JsRspackSeverity): binding.JsDiagnostic;
5
+ }
6
+ export declare class NonErrorEmittedError extends Error {
7
+ constructor(error: Error);
8
+ }
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NonErrorEmittedError = exports.JsDiagnostic = void 0;
4
+ const util_1 = require("./util");
5
+ class JsDiagnostic {
6
+ static __to_binding(error, severity) {
7
+ return {
8
+ error: (0, util_1.concatErrorMsgAndStack)(error),
9
+ severity
10
+ };
11
+ }
12
+ }
13
+ exports.JsDiagnostic = JsDiagnostic;
14
+ class NonErrorEmittedError extends Error {
15
+ constructor(error) {
16
+ super();
17
+ this.name = "NonErrorEmittedError";
18
+ this.message = "(Emitted value instead of an instance of Error) " + error;
19
+ }
20
+ }
21
+ exports.NonErrorEmittedError = NonErrorEmittedError;
@@ -1,11 +1,7 @@
1
- export type { EmotionOptions } from "./emotion";
2
- export { resolveEmotion } from "./emotion";
3
1
  export { resolvePluginImport } from "./pluginImport";
4
2
  export type { PluginImportOptions } from "./pluginImport";
5
3
  export type { ReactOptions } from "./react";
6
4
  export { resolveReact } from "./react";
7
5
  export { resolvePreact } from "./preact";
8
6
  export type { PreactOptions } from "./preact";
9
- export type { RelayOptions } from "./relay";
10
- export { resolveRelay } from "./relay";
11
7
  export type { SwcLoaderEnvConfig, SwcLoaderEsParserConfig, SwcLoaderJscConfig, SwcLoaderModuleConfig, SwcLoaderOptions, SwcLoaderParserConfig, SwcLoaderTransformConfig, SwcLoaderTsParserConfig } from "./types";
@@ -1,13 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resolveRelay = exports.resolvePreact = exports.resolveReact = exports.resolvePluginImport = exports.resolveEmotion = void 0;
4
- var emotion_1 = require("./emotion");
5
- Object.defineProperty(exports, "resolveEmotion", { enumerable: true, get: function () { return emotion_1.resolveEmotion; } });
3
+ exports.resolvePreact = exports.resolveReact = exports.resolvePluginImport = void 0;
6
4
  var pluginImport_1 = require("./pluginImport");
7
5
  Object.defineProperty(exports, "resolvePluginImport", { enumerable: true, get: function () { return pluginImport_1.resolvePluginImport; } });
8
6
  var react_1 = require("./react");
9
7
  Object.defineProperty(exports, "resolveReact", { enumerable: true, get: function () { return react_1.resolveReact; } });
10
8
  var preact_1 = require("./preact");
11
9
  Object.defineProperty(exports, "resolvePreact", { enumerable: true, get: function () { return preact_1.resolvePreact; } });
12
- var relay_1 = require("./relay");
13
- Object.defineProperty(exports, "resolveRelay", { enumerable: true, get: function () { return relay_1.resolveRelay; } });
@@ -1,7 +1,6 @@
1
1
  type RawPreactOptions = {
2
2
  library?: string;
3
3
  };
4
- type PreactOptions = RawPreactOptions | boolean | undefined;
5
- declare function resolvePreact(preact: PreactOptions): RawPreactOptions | undefined;
6
- export { resolvePreact };
7
- export type { PreactOptions };
4
+ export type PreactOptions = RawPreactOptions | boolean | undefined;
5
+ export declare function resolvePreact(preact: PreactOptions): RawPreactOptions | undefined;
6
+ export {};
@@ -2,22 +2,9 @@
2
2
  * Some types are modified from https://github.com/swc-project/swc/blob/16a38851/packages/types/index.ts#L647
3
3
  * license at https://github.com/swc-project/swc/blob/main/LICENSE
4
4
  */
5
- import type { EmotionOptions } from "./emotion";
6
5
  import type { PluginImportOptions } from "./pluginImport";
6
+ import type { PreactOptions } from "./preact";
7
7
  import type { ReactOptions } from "./react";
8
- import type { RelayOptions } from "./relay";
9
- export type StyledComponentsOptions = {
10
- displayName?: boolean;
11
- ssr?: boolean;
12
- fileName?: boolean;
13
- meaninglessFileNames?: string[];
14
- namespace?: string;
15
- topLevelImportPaths?: string[];
16
- transpileTemplateLiterals?: boolean;
17
- minify?: boolean;
18
- pure?: boolean;
19
- cssProps?: boolean;
20
- };
21
8
  export type JscTarget = "es3" | "es5" | "es2015" | "es2016" | "es2017" | "es2018" | "es2019" | "es2020" | "es2021" | "es2022" | "esnext";
22
9
  export type SwcLoaderParserConfig = SwcLoaderTsParserConfig | SwcLoaderEsParserConfig;
23
10
  export interface SwcLoaderTsParserConfig {
@@ -454,9 +441,7 @@ export type SwcLoaderOptions = {
454
441
  * @experimental
455
442
  */
456
443
  rspackExperiments?: {
457
- relay?: RelayOptions;
458
- emotion?: EmotionOptions;
459
444
  import?: PluginImportOptions;
460
- styledComponents?: StyledComponentsOptions;
445
+ preact?: PreactOptions;
461
446
  };
462
447
  };
@@ -3,8 +3,8 @@ import { Compiler } from "../..";
3
3
  export * from "./loader";
4
4
  export type { CssExtractRspackLoaderOptions } from "./loader";
5
5
  export interface CssExtractRspackPluginOptions {
6
- filename?: string;
7
- chunkFilename?: string;
6
+ filename?: RawCssExtractPluginOption["filename"];
7
+ chunkFilename?: RawCssExtractPluginOption["chunkFilename"];
8
8
  ignoreOrder?: boolean;
9
9
  insert?: string | ((linkTag: HTMLLinkElement) => void);
10
10
  attributes?: Record<string, string>;
@@ -467,9 +467,19 @@ function getRawJavascriptParserOptions(parser) {
467
467
  reexportExportsPresence: parser.reexportExportsPresence === false
468
468
  ? "false"
469
469
  : parser.reexportExportsPresence,
470
- strictExportPresence: parser.strictExportPresence ?? false
470
+ strictExportPresence: parser.strictExportPresence ?? false,
471
+ worker: getRawJavascriptParserOptionsWorker(parser.worker)
471
472
  };
472
473
  }
474
+ function getRawJavascriptParserOptionsWorker(worker) {
475
+ const DEFAULT_SYNTAX = [
476
+ "Worker",
477
+ "SharedWorker",
478
+ // "navigator.serviceWorker.register()",
479
+ "Worker from worker_threads"
480
+ ];
481
+ return (worker === false ? [] : Array.isArray(worker) ? worker : ["..."]).flatMap(item => (item === "..." ? DEFAULT_SYNTAX : item));
482
+ }
473
483
  function getRawAssetParserOptions(parser) {
474
484
  return {
475
485
  dataUrlCondition: parser.dataUrlCondition
@@ -155,6 +155,7 @@ const applyJavascriptParserOptionsDefaults = (parserOptions, fallback) => {
155
155
  D(parserOptions, "importExportsPresence", fallback?.importExportsPresence);
156
156
  D(parserOptions, "reexportExportsPresence", fallback?.reexportExportsPresence);
157
157
  D(parserOptions, "strictExportPresence", fallback?.strictExportPresence ?? false);
158
+ D(parserOptions, "worker", fallback?.worker ?? ["..."]);
158
159
  };
159
160
  const applyModuleDefaults = (module, { asyncWebAssembly, css, targetProperties }) => {
160
161
  (0, assertNotNil_1.assertNotNill)(module.parser);