@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.
@@ -345,6 +345,7 @@ const reexportExportsPresence = zod_1.z
345
345
  .enum(["error", "warn", "auto"])
346
346
  .or(zod_1.z.literal(false));
347
347
  const strictExportPresence = zod_1.z.boolean();
348
+ const worker = zod_1.z.array(zod_1.z.string()).or(zod_1.z.boolean());
348
349
  const javascriptParserOptions = zod_1.z.strictObject({
349
350
  dynamicImportMode: dynamicImportMode.optional(),
350
351
  dynamicImportPreload: dynamicImportPreload.optional(),
@@ -355,7 +356,8 @@ const javascriptParserOptions = zod_1.z.strictObject({
355
356
  exportsPresence: exportsPresence.optional(),
356
357
  importExportsPresence: importExportsPresence.optional(),
357
358
  reexportExportsPresence: reexportExportsPresence.optional(),
358
- strictExportPresence: strictExportPresence.optional()
359
+ strictExportPresence: strictExportPresence.optional(),
360
+ worker: worker.optional()
359
361
  });
360
362
  const parserOptionsByModuleTypeKnown = zod_1.z.strictObject({
361
363
  asset: assetParserOptions.optional(),
@@ -32,6 +32,7 @@ const binding_1 = require("@rspack/binding");
32
32
  const webpack_sources_1 = require("webpack-sources");
33
33
  const Module_1 = require("../Module");
34
34
  const NormalModule_1 = require("../NormalModule");
35
+ const RspackError_1 = require("../RspackError");
35
36
  const adapterRuleUse_1 = require("../config/adapterRuleUse");
36
37
  const util_2 = require("../util");
37
38
  const createHash_1 = require("../util/createHash");
@@ -517,14 +518,34 @@ async function runLoaders(compiler, context) {
517
518
  };
518
519
  loaderContext.rootContext = compiler.context;
519
520
  loaderContext.emitError = function emitError(error) {
520
- const title = "Module Error";
521
- const message = error instanceof Error ? (0, util_2.concatErrorMsgAndStack)(error) : error;
522
- compiler._lastCompilation.__internal__pushDiagnostic("error", title, `${message}\n(from: ${(0, util_2.stringifyLoaderObject)(loaderContext.loaders[loaderContext.loaderIndex])})`);
521
+ if (!(error instanceof Error)) {
522
+ error = new RspackError_1.NonErrorEmittedError(error);
523
+ }
524
+ let hasStack = !!error.stack;
525
+ error.name = "ModuleError";
526
+ error.message = `${error.message} (from: ${(0, util_2.stringifyLoaderObject)(loaderContext.loaders[loaderContext.loaderIndex])})`;
527
+ hasStack && Error.captureStackTrace(error);
528
+ error = (0, util_2.concatErrorMsgAndStack)(error);
529
+ error.moduleIdentifier = this._module.identifier();
530
+ compiler._lastCompilation.__internal__pushDiagnostic({
531
+ error,
532
+ severity: binding_1.JsRspackSeverity.Error
533
+ });
523
534
  };
524
535
  loaderContext.emitWarning = function emitWarning(warning) {
525
- const title = "Module Warning";
526
- const message = warning instanceof Error ? (0, util_2.concatErrorMsgAndStack)(warning) : warning;
527
- compiler._lastCompilation.__internal__pushDiagnostic("warning", title, `${message}\n(from: ${(0, util_2.stringifyLoaderObject)(loaderContext.loaders[loaderContext.loaderIndex])})`);
536
+ if (!(warning instanceof Error)) {
537
+ warning = new RspackError_1.NonErrorEmittedError(warning);
538
+ }
539
+ let hasStack = !!warning.stack;
540
+ warning.name = "ModuleWarning";
541
+ warning.message = `${warning.message} (from: ${(0, util_2.stringifyLoaderObject)(loaderContext.loaders[loaderContext.loaderIndex])})`;
542
+ hasStack && Error.captureStackTrace(warning);
543
+ warning = (0, util_2.concatErrorMsgAndStack)(warning);
544
+ warning.moduleIdentifier = this._module.identifier();
545
+ compiler._lastCompilation.__internal__pushDiagnostic({
546
+ error: warning,
547
+ severity: binding_1.JsRspackSeverity.Warn
548
+ });
528
549
  };
529
550
  loaderContext.emitFile = function emitFile(name, content, sourceMap, assetInfo) {
530
551
  let source;
@@ -277,13 +277,23 @@ const SORTERS = {
277
277
  _: comparators => {
278
278
  comparators.push((0, comparators_1.compareSelect)((c) => c.id, compareIds));
279
279
  }
280
- }
280
+ },
281
281
  // "compilation.modules": MODULES_SORTER,
282
282
  // "chunk.rootModules": MODULES_SORTER,
283
283
  // "chunk.modules": MODULES_SORTER,
284
284
  // "module.modules": MODULES_SORTER,
285
285
  // not support module.reasons (missing Module.identifier())
286
- // not support chunk.origins (missing compilation.chunkGraph)
286
+ "chunk.origins": {
287
+ _: comparators => {
288
+ comparators.push(
289
+ // compareSelect(
290
+ // origin =>
291
+ // origin.module ? chunkGraph.getModuleId(origin.module) : undefined,
292
+ // compareIds
293
+ // ),
294
+ (0, comparators_1.compareSelect)((origin) => origin.loc, compareIds), (0, comparators_1.compareSelect)((origin) => origin.request, compareIds));
295
+ }
296
+ }
287
297
  };
288
298
  const SIMPLE_EXTRACTORS = {
289
299
  compilation: {
@@ -708,6 +718,10 @@ const SIMPLE_EXTRACTORS = {
708
718
  object.files = chunk.files;
709
719
  object.auxiliaryFiles = chunk.auxiliaryFiles;
710
720
  object.childrenByOrder = chunk.childrenByOrder;
721
+ object.runtime = chunk.runtime;
722
+ object.sizes = Object.fromEntries(chunk.sizes.map(({ sourceType, size }) => [sourceType, size]));
723
+ object.reason = chunk.reason;
724
+ object.rendered = chunk.rendered;
711
725
  },
712
726
  ids: (object, chunk) => {
713
727
  object.id = chunk.id;
@@ -720,6 +734,9 @@ const SIMPLE_EXTRACTORS = {
720
734
  chunkModules: (object, chunk, context, options, factory) => {
721
735
  const { type } = context;
722
736
  object.modules = factory.create(`${type}.modules`, chunk.modules, context);
737
+ },
738
+ chunkOrigins: (object, chunk, context, options, factory) => {
739
+ object.origins = chunk.origins;
723
740
  }
724
741
  }
725
742
  };
@@ -357,13 +357,13 @@ const SIMPLE_PRINTERS = {
357
357
  // chunkEntry ? formatFlag("entry") : undefined,
358
358
  // "error.chunkInitial": (chunkInitial, { formatFlag }) =>
359
359
  // chunkInitial ? formatFlag("initial") : undefined,
360
- // "error.file": (file, { bold }) => bold(file),
360
+ "error.file": (file, { bold }) => bold(file),
361
361
  "error.moduleName": (moduleName, { bold }) => {
362
362
  return moduleName.includes("!")
363
363
  ? `${bold(moduleName.replace(/^(\s|\S)*!/, ""))} (${moduleName})`
364
364
  : `${bold(moduleName)}`;
365
365
  },
366
- // "error.loc": (loc, { green }) => green(loc),
366
+ "error.loc": (loc, { green }) => green(loc),
367
367
  "error.message": (message, { bold, formatError }) => message.includes("\u001b[") ? message : bold(formatError(message)),
368
368
  // "error.details": (details, { formatError }) => formatError(details),
369
369
  // "error.stack": stack => stack,
@@ -3,7 +3,9 @@ import type { Compilation, NormalizedStatsOptions } from "../Compilation";
3
3
  import { type Comparator } from "../util/comparators";
4
4
  import type { StatsFactory, StatsFactoryContext } from "./StatsFactory";
5
5
  export type KnownStatsChunkGroup = binding.JsStatsChunkGroup;
6
- export type KnownStatsChunk = binding.JsStatsChunk;
6
+ export type KnownStatsChunk = Omit<binding.JsStatsChunk, "sizes"> & {
7
+ sizes: Record<string, number>;
8
+ };
7
9
  export type StatsChunkGroup = binding.JsStatsChunkGroup & Record<string, any>;
8
10
  export type KnownStatsAsset = binding.JsStatsAsset;
9
11
  export type StatsAsset = KnownStatsAsset & Record<string, any>;
@@ -95,7 +97,7 @@ export type SimpleExtractors = {
95
97
  moduleIssuer: ExtractorsByOption<binding.JsStatsModuleIssuer, StatsModuleIssuer>;
96
98
  profile: ExtractorsByOption<binding.JsStatsModuleProfile, StatsProfile>;
97
99
  moduleReason: ExtractorsByOption<binding.JsStatsModuleReason, StatsModuleReason>;
98
- chunk: ExtractorsByOption<StatsChunk, KnownStatsChunk>;
100
+ chunk: ExtractorsByOption<binding.JsStatsChunk, KnownStatsChunk>;
99
101
  };
100
102
  export declare const uniqueArray: <T, I>(items: Iterable<T>, selector: (arg: T) => Iterable<I>) => I[];
101
103
  export declare const uniqueOrderedArray: <T, I>(items: Iterable<T>, selector: (arg: T) => Iterable<I>, comparator: Comparator) => I[];
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import type { JsStatsError } from "@rspack/binding";
2
+ import type { JsRspackError, JsStatsError } from "@rspack/binding";
3
3
  import { LoaderObject } from "../loader-runner";
4
4
  export declare function mapValues(record: Record<string, string>, fn: (key: string) => string): {
5
5
  [k: string]: string;
@@ -10,7 +10,7 @@ export declare const toObject: (input: string | Buffer | object) => object;
10
10
  export declare function serializeObject(map: string | object | undefined | null): Buffer | undefined;
11
11
  export declare function isPromiseLike(value: unknown): value is Promise<any>;
12
12
  export declare function isJsStatsError(err: any): err is JsStatsError;
13
- export declare function concatErrorMsgAndStack(err: Error | JsStatsError | string): string;
13
+ export declare function concatErrorMsgAndStack(err: Error | JsRspackError | string): JsRspackError;
14
14
  export declare function indent(str: string, prefix: string): string;
15
15
  export declare function stringifyLoaderObject(o: LoaderObject): string;
16
16
  export declare function asArray<T>(item: T[]): T[];
@@ -61,12 +61,13 @@ function isJsStatsError(err) {
61
61
  exports.isJsStatsError = isJsStatsError;
62
62
  function concatErrorMsgAndStack(err) {
63
63
  if (typeof err === "string") {
64
- return err;
64
+ return new Error(err);
65
65
  }
66
66
  if ("stack" in err) {
67
- return err.stack || err.message;
67
+ err.message = err.stack || err.message;
68
+ return err;
68
69
  }
69
- return err.message;
70
+ return err;
70
71
  }
71
72
  exports.concatErrorMsgAndStack = concatErrorMsgAndStack;
72
73
  function indent(str, prefix) {
package/package.json CHANGED
@@ -1,11 +1,15 @@
1
1
  {
2
2
  "name": "@rspack/core",
3
- "version": "0.7.5-canary-910259c-20240624004455",
3
+ "version": "0.7.5-canary-0d03907-20240624125011",
4
4
  "webpackVersion": "5.75.0",
5
5
  "license": "MIT",
6
6
  "description": "The fast Rust-based web bundler with webpack-compatible API",
7
7
  "main": "./dist/index.js",
8
8
  "types": "./dist/index.d.ts",
9
+ "publishConfig": {
10
+ "access": "public",
11
+ "provenance": true
12
+ },
9
13
  "exports": {
10
14
  ".": {
11
15
  "default": "./dist/index.js"
@@ -74,15 +78,15 @@
74
78
  "watchpack": "^2.4.0",
75
79
  "zod": "^3.21.4",
76
80
  "zod-validation-error": "1.3.1",
77
- "@rspack/core": "0.7.5-canary-910259c-20240624004455",
78
- "@rspack/plugin-minify": "^0.7.5-canary-910259c-20240624004455"
81
+ "@rspack/plugin-minify": "^0.7.5-canary-0d03907-20240624125011",
82
+ "@rspack/core": "0.7.5-canary-0d03907-20240624125011"
79
83
  },
80
84
  "dependencies": {
81
85
  "@module-federation/runtime-tools": "0.1.6",
82
86
  "caniuse-lite": "^1.0.30001616",
83
87
  "tapable": "2.2.1",
84
88
  "webpack-sources": "3.2.3",
85
- "@rspack/binding": "0.7.5-canary-910259c-20240624004455"
89
+ "@rspack/binding": "0.7.5-canary-0d03907-20240624125011"
86
90
  },
87
91
  "peerDependencies": {
88
92
  "@swc/helpers": ">=0.5.1"
@@ -1,17 +0,0 @@
1
- type EmotionConfigImportMap = {
2
- [packageName: string]: {
3
- [exportName: string]: {
4
- canonicalImport?: [string, string];
5
- };
6
- };
7
- };
8
- type EmotionConfig = {
9
- sourceMap?: boolean;
10
- autoLabel?: "never" | "dev-only" | "always";
11
- labelFormat?: string;
12
- importMap?: EmotionConfigImportMap;
13
- };
14
- type EmotionOptions = boolean | EmotionConfig | undefined;
15
- declare function resolveEmotion(emotion: EmotionOptions, isProduction: boolean): EmotionConfig | undefined;
16
- export { resolveEmotion };
17
- export type { EmotionOptions };
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resolveEmotion = void 0;
4
- function resolveEmotion(emotion, isProduction) {
5
- if (!emotion) {
6
- return undefined;
7
- }
8
- if (emotion === true) {
9
- emotion = {};
10
- }
11
- const autoLabel = emotion?.autoLabel ?? "dev-only";
12
- const emotionConfig = {
13
- enabled: true,
14
- // @ts-expect-error autoLabel is string for JavaScript interface, however is boolean for Rust interface
15
- autoLabel: autoLabel === "dev-only" ? !isProduction : autoLabel === "always",
16
- importMap: emotion?.importMap,
17
- labelFormat: emotion?.labelFormat ?? "[local]",
18
- sourcemap: isProduction ? false : emotion?.sourceMap ?? true
19
- };
20
- return emotionConfig;
21
- }
22
- exports.resolveEmotion = resolveEmotion;
@@ -1,5 +0,0 @@
1
- import type { RawRelayConfig } from "@rspack/binding";
2
- type RelayOptions = boolean | RawRelayConfig | undefined;
3
- declare function resolveRelay(relay: RelayOptions, rootDir: string): RawRelayConfig | undefined;
4
- export { resolveRelay };
5
- export type { RelayOptions };
@@ -1,48 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.resolveRelay = void 0;
7
- const path_1 = __importDefault(require("path"));
8
- function getRelayConfigFromProject(rootDir) {
9
- for (const configName of [
10
- "relay.config.json",
11
- "relay.config.js",
12
- "package.json"
13
- ]) {
14
- const configPath = path_1.default.join(rootDir, configName);
15
- try {
16
- let config = require(configPath);
17
- let finalConfig;
18
- if (configName === "package.json") {
19
- finalConfig = config?.relay;
20
- }
21
- else {
22
- finalConfig = config;
23
- }
24
- if (finalConfig) {
25
- return {
26
- language: finalConfig.language,
27
- artifactDirectory: finalConfig.artifactDirectory
28
- };
29
- }
30
- }
31
- catch (_) { }
32
- }
33
- }
34
- function resolveRelay(relay, rootDir) {
35
- if (!relay) {
36
- return undefined;
37
- }
38
- // Search relay config based on
39
- if (relay === true) {
40
- return (getRelayConfigFromProject(rootDir) || {
41
- language: "javascript"
42
- });
43
- }
44
- else {
45
- return relay;
46
- }
47
- }
48
- exports.resolveRelay = resolveRelay;