@rspack/core 1.0.0-rc.0 → 1.0.0-rc.2

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.
@@ -1,22 +1,41 @@
1
1
  import * as zod from 'zod';
2
2
 
3
+ interface ErrorOptions {
4
+ cause?: unknown;
5
+ }
3
6
  declare class ValidationError extends Error {
4
- details: Array<zod.ZodIssue>;
5
7
  name: 'ZodValidationError';
6
- constructor(message: string, details?: Array<zod.ZodIssue> | undefined);
8
+ details: Array<zod.ZodIssue>;
9
+ constructor(message?: string, options?: ErrorOptions);
7
10
  toString(): string;
8
11
  }
9
- type ZodError = zod.ZodError;
10
- type FromZodErrorOptions = {
11
- maxIssuesInMessage?: number;
12
+
13
+ declare function isValidationError(err: unknown): err is ValidationError;
14
+
15
+ declare function isValidationErrorLike(err: unknown): err is ValidationError;
16
+
17
+ declare function isZodErrorLike(err: unknown): err is zod.ZodError;
18
+
19
+ declare const errorMap: zod.ZodErrorMap;
20
+
21
+ type ZodIssue = zod.ZodIssue;
22
+ type FromZodIssueOptions = {
12
23
  issueSeparator?: string;
13
24
  unionSeparator?: string;
25
+ prefix?: string | null;
14
26
  prefixSeparator?: string;
15
- prefix?: string;
27
+ includePath?: boolean;
28
+ };
29
+ declare function fromZodIssue(issue: ZodIssue, options?: FromZodIssueOptions): ValidationError;
30
+
31
+ type ZodError = zod.ZodError;
32
+ type FromZodErrorOptions = FromZodIssueOptions & {
33
+ maxIssuesInMessage?: number;
16
34
  };
17
35
  declare function fromZodError(zodError: ZodError, options?: FromZodErrorOptions): ValidationError;
18
- declare const toValidationError: (options?: Parameters<typeof fromZodError>[1]) => (err: unknown) => ValidationError | Error;
19
- declare function isValidationError(err: unknown): err is ValidationError;
20
- declare function isValidationErrorLike(err: unknown): err is ValidationError;
21
36
 
22
- export { type FromZodErrorOptions, ValidationError, type ZodError, fromZodError, isValidationError, isValidationErrorLike, toValidationError };
37
+ declare function fromError(err: unknown, options?: FromZodErrorOptions): ValidationError;
38
+
39
+ declare const toValidationError: (options?: Parameters<typeof fromZodError>[1]) => (err: unknown) => ValidationError;
40
+
41
+ export { type ErrorOptions, type FromZodErrorOptions, type FromZodIssueOptions, ValidationError, type ZodError, type ZodIssue, errorMap, fromError, fromZodError, fromZodIssue, isValidationError, isValidationErrorLike, isZodErrorLike, toValidationError };
@@ -2,152 +2,280 @@
2
2
  /******/ "use strict";
3
3
  /******/ var __webpack_modules__ = ({
4
4
 
5
- /***/ 381:
6
- /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
5
+ /***/ 172:
6
+ /***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
7
7
 
8
8
 
9
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- var desc = Object.getOwnPropertyDescriptor(m, k);
12
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
13
- desc = { enumerable: true, get: function() { return m[k]; } };
14
- }
15
- Object.defineProperty(o, k2, desc);
16
- }) : (function(o, m, k, k2) {
17
- if (k2 === undefined) k2 = k;
18
- o[k2] = m[k];
19
- }));
20
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
21
- Object.defineProperty(o, "default", { enumerable: true, value: v });
22
- }) : function(o, v) {
23
- o["default"] = v;
24
- });
25
- var __importStar = (this && this.__importStar) || function (mod) {
26
- if (mod && mod.__esModule) return mod;
27
- var result = {};
28
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
29
- __setModuleDefault(result, mod);
30
- return result;
9
+ var __create = Object.create;
10
+ var __defProp = Object.defineProperty;
11
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
+ var __getOwnPropNames = Object.getOwnPropertyNames;
13
+ var __getProtoOf = Object.getPrototypeOf;
14
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
15
+ var __export = (target, all) => {
16
+ for (var name in all)
17
+ __defProp(target, name, { get: all[name], enumerable: true });
31
18
  };
32
- Object.defineProperty(exports, "__esModule", ({ value: true }));
33
- exports.isValidationErrorLike = exports.isValidationError = exports.toValidationError = exports.fromZodError = exports.ValidationError = void 0;
34
- const zod = __importStar(__nccwpck_require__(934));
35
- const joinPath_1 = __nccwpck_require__(954);
36
- const NonEmptyArray_1 = __nccwpck_require__(978);
37
- class ValidationError extends Error {
38
- details;
39
- name;
40
- constructor(message, details = []) {
41
- super(message);
42
- this.details = details;
43
- this.name = 'ZodValidationError';
44
- }
45
- toString() {
46
- return this.message;
47
- }
19
+ var __copyProps = (to, from, except, desc) => {
20
+ if (from && typeof from === "object" || typeof from === "function") {
21
+ for (let key of __getOwnPropNames(from))
22
+ if (!__hasOwnProp.call(to, key) && key !== except)
23
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
24
+ }
25
+ return to;
26
+ };
27
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
28
+ // If the importer is in node compatibility mode or this is not an ESM
29
+ // file that has been converted to a CommonJS file using a Babel-
30
+ // compatible transform (i.e. "__esModule" has not been set), then set
31
+ // "default" to the CommonJS "module.exports" for node compatibility.
32
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
33
+ mod
34
+ ));
35
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
36
+
37
+ // lib/index.ts
38
+ var lib_exports = {};
39
+ __export(lib_exports, {
40
+ ValidationError: () => ValidationError,
41
+ errorMap: () => errorMap,
42
+ fromError: () => fromError,
43
+ fromZodError: () => fromZodError,
44
+ fromZodIssue: () => fromZodIssue,
45
+ isValidationError: () => isValidationError,
46
+ isValidationErrorLike: () => isValidationErrorLike,
47
+ isZodErrorLike: () => isZodErrorLike,
48
+ toValidationError: () => toValidationError
49
+ });
50
+ module.exports = __toCommonJS(lib_exports);
51
+
52
+ // lib/isZodErrorLike.ts
53
+ function isZodErrorLike(err) {
54
+ return err instanceof Error && err.name === "ZodError" && "issues" in err && Array.isArray(err.issues);
48
55
  }
49
- exports.ValidationError = ValidationError;
50
- function fromZodIssue(issue, issueSeparator, unionSeparator) {
51
- if (issue.code === 'invalid_union') {
52
- return issue.unionErrors
53
- .reduce((acc, zodError) => {
54
- const newIssues = zodError.issues
55
- .map((issue) => fromZodIssue(issue, issueSeparator, unionSeparator))
56
- .join(issueSeparator);
57
- if (!acc.includes(newIssues)) {
58
- acc.push(newIssues);
59
- }
60
- return acc;
61
- }, [])
62
- .join(unionSeparator);
63
- }
64
- if ((0, NonEmptyArray_1.isNonEmptyArray)(issue.path)) {
65
- if (issue.path.length === 1) {
66
- const identifier = issue.path[0];
67
- if (typeof identifier === 'number') {
68
- return `${issue.message} at index ${identifier}`;
69
- }
70
- }
71
- return `${issue.message} at "${(0, joinPath_1.joinPath)(issue.path)}"`;
56
+
57
+ // lib/ValidationError.ts
58
+ var ValidationError = class extends Error {
59
+ name;
60
+ details;
61
+ constructor(message, options) {
62
+ super(message, options);
63
+ this.name = "ZodValidationError";
64
+ this.details = getIssuesFromErrorOptions(options);
65
+ }
66
+ toString() {
67
+ return this.message;
68
+ }
69
+ };
70
+ function getIssuesFromErrorOptions(options) {
71
+ if (options) {
72
+ const cause = options.cause;
73
+ if (isZodErrorLike(cause)) {
74
+ return cause.issues;
72
75
  }
73
- return issue.message;
76
+ }
77
+ return [];
74
78
  }
75
- function fromZodError(zodError, options = {}) {
76
- const { maxIssuesInMessage = 99, issueSeparator = '; ', unionSeparator = ', or ', prefixSeparator = ': ', prefix = 'Validation error', } = options;
77
- const reason = zodError.errors
78
- .slice(0, maxIssuesInMessage)
79
- .map((issue) => fromZodIssue(issue, issueSeparator, unionSeparator))
80
- .join(issueSeparator);
81
- const message = reason ? [prefix, reason].join(prefixSeparator) : prefix;
82
- return new ValidationError(message, zodError.errors);
83
- }
84
- exports.fromZodError = fromZodError;
85
- const toValidationError = (options = {}) => (err) => {
86
- if (err instanceof zod.ZodError) {
87
- return fromZodError(err, options);
88
- }
89
- if (err instanceof Error) {
90
- return err;
91
- }
92
- return new Error('Unknown error');
93
- };
94
- exports.toValidationError = toValidationError;
79
+
80
+ // lib/isValidationError.ts
95
81
  function isValidationError(err) {
96
- return err instanceof ValidationError;
82
+ return err instanceof ValidationError;
97
83
  }
98
- exports.isValidationError = isValidationError;
84
+
85
+ // lib/isValidationErrorLike.ts
99
86
  function isValidationErrorLike(err) {
100
- return err instanceof Error && err.name === 'ZodValidationError';
87
+ return err instanceof Error && err.name === "ZodValidationError";
101
88
  }
102
- exports.isValidationErrorLike = isValidationErrorLike;
103
89
 
90
+ // lib/fromZodIssue.ts
91
+ var zod = __toESM(__nccwpck_require__(934));
104
92
 
105
- /***/ }),
93
+ // lib/config.ts
94
+ var ISSUE_SEPARATOR = "; ";
95
+ var MAX_ISSUES_IN_MESSAGE = 99;
96
+ var PREFIX = "Validation error";
97
+ var PREFIX_SEPARATOR = ": ";
98
+ var UNION_SEPARATOR = ", or ";
106
99
 
107
- /***/ 978:
108
- /***/ ((__unused_webpack_module, exports) => {
100
+ // lib/prefixMessage.ts
101
+ function prefixMessage(message, prefix, prefixSeparator) {
102
+ if (prefix !== null) {
103
+ if (message.length > 0) {
104
+ return [prefix, message].join(prefixSeparator);
105
+ }
106
+ return prefix;
107
+ }
108
+ if (message.length > 0) {
109
+ return message;
110
+ }
111
+ return PREFIX;
112
+ }
109
113
 
114
+ // lib/utils/joinPath.ts
115
+ var identifierRegex = /[$_\p{ID_Start}][$\u200c\u200d\p{ID_Continue}]*/u;
116
+ function joinPath(path) {
117
+ if (path.length === 1) {
118
+ return path[0].toString();
119
+ }
120
+ return path.reduce((acc, item) => {
121
+ if (typeof item === "number") {
122
+ return acc + "[" + item.toString() + "]";
123
+ }
124
+ if (item.includes('"')) {
125
+ return acc + '["' + escapeQuotes(item) + '"]';
126
+ }
127
+ if (!identifierRegex.test(item)) {
128
+ return acc + '["' + item + '"]';
129
+ }
130
+ const separator = acc.length === 0 ? "" : ".";
131
+ return acc + separator + item;
132
+ }, "");
133
+ }
134
+ function escapeQuotes(str) {
135
+ return str.replace(/"/g, '\\"');
136
+ }
110
137
 
111
- Object.defineProperty(exports, "__esModule", ({ value: true }));
112
- exports.isNonEmptyArray = void 0;
138
+ // lib/utils/NonEmptyArray.ts
113
139
  function isNonEmptyArray(value) {
114
- return value.length !== 0;
140
+ return value.length !== 0;
115
141
  }
116
- exports.isNonEmptyArray = isNonEmptyArray;
117
142
 
143
+ // lib/fromZodIssue.ts
144
+ function getMessageFromZodIssue(props) {
145
+ const { issue, issueSeparator, unionSeparator, includePath } = props;
146
+ if (issue.code === "invalid_union") {
147
+ return issue.unionErrors.reduce((acc, zodError) => {
148
+ const newIssues = zodError.issues.map(
149
+ (issue2) => getMessageFromZodIssue({
150
+ issue: issue2,
151
+ issueSeparator,
152
+ unionSeparator,
153
+ includePath
154
+ })
155
+ ).join(issueSeparator);
156
+ if (!acc.includes(newIssues)) {
157
+ acc.push(newIssues);
158
+ }
159
+ return acc;
160
+ }, []).join(unionSeparator);
161
+ }
162
+ if (issue.code === "invalid_arguments") {
163
+ return [
164
+ issue.message,
165
+ ...issue.argumentsError.issues.map(
166
+ (issue2) => getMessageFromZodIssue({
167
+ issue: issue2,
168
+ issueSeparator,
169
+ unionSeparator,
170
+ includePath
171
+ })
172
+ )
173
+ ].join(issueSeparator);
174
+ }
175
+ if (issue.code === "invalid_return_type") {
176
+ return [
177
+ issue.message,
178
+ ...issue.returnTypeError.issues.map(
179
+ (issue2) => getMessageFromZodIssue({
180
+ issue: issue2,
181
+ issueSeparator,
182
+ unionSeparator,
183
+ includePath
184
+ })
185
+ )
186
+ ].join(issueSeparator);
187
+ }
188
+ if (includePath && isNonEmptyArray(issue.path)) {
189
+ if (issue.path.length === 1) {
190
+ const identifier = issue.path[0];
191
+ if (typeof identifier === "number") {
192
+ return `${issue.message} at index ${identifier}`;
193
+ }
194
+ }
195
+ return `${issue.message} at "${joinPath(issue.path)}"`;
196
+ }
197
+ return issue.message;
198
+ }
199
+ function fromZodIssue(issue, options = {}) {
200
+ const {
201
+ issueSeparator = ISSUE_SEPARATOR,
202
+ unionSeparator = UNION_SEPARATOR,
203
+ prefixSeparator = PREFIX_SEPARATOR,
204
+ prefix = PREFIX,
205
+ includePath = true
206
+ } = options;
207
+ const reason = getMessageFromZodIssue({
208
+ issue,
209
+ issueSeparator,
210
+ unionSeparator,
211
+ includePath
212
+ });
213
+ const message = prefixMessage(reason, prefix, prefixSeparator);
214
+ return new ValidationError(message, { cause: new zod.ZodError([issue]) });
215
+ }
118
216
 
119
- /***/ }),
120
-
121
- /***/ 954:
122
- /***/ ((__unused_webpack_module, exports) => {
123
-
217
+ // lib/errorMap.ts
218
+ var errorMap = (issue, ctx) => {
219
+ const error = fromZodIssue({
220
+ ...issue,
221
+ // fallback to the default error message
222
+ // when issue does not have a message
223
+ message: issue.message ?? ctx.defaultError
224
+ });
225
+ return {
226
+ message: error.message
227
+ };
228
+ };
124
229
 
125
- Object.defineProperty(exports, "__esModule", ({ value: true }));
126
- exports.joinPath = void 0;
127
- const identifierRegex = /[$_\p{ID_Start}][$\u200c\u200d\p{ID_Continue}]*/u;
128
- function joinPath(path) {
129
- if (path.length === 1) {
130
- return path[0].toString();
131
- }
132
- return path.reduce((acc, item) => {
133
- if (typeof item === 'number') {
134
- return acc + '[' + item.toString() + ']';
135
- }
136
- if (item.includes('"')) {
137
- return acc + '["' + escapeQuotes(item) + '"]';
138
- }
139
- if (!identifierRegex.test(item)) {
140
- return acc + '["' + item + '"]';
141
- }
142
- const separator = acc.length === 0 ? '' : '.';
143
- return acc + separator + item;
144
- }, '');
230
+ // lib/fromZodError.ts
231
+ function fromZodError(zodError, options = {}) {
232
+ if (!isZodErrorLike(zodError)) {
233
+ throw new TypeError(
234
+ `Invalid zodError param; expected instance of ZodError. Did you mean to use the "${fromError.name}" method instead?`
235
+ );
236
+ }
237
+ return fromZodErrorWithoutRuntimeCheck(zodError, options);
145
238
  }
146
- exports.joinPath = joinPath;
147
- function escapeQuotes(str) {
148
- return str.replace(/"/g, '\\"');
239
+ function fromZodErrorWithoutRuntimeCheck(zodError, options = {}) {
240
+ const {
241
+ maxIssuesInMessage = MAX_ISSUES_IN_MESSAGE,
242
+ issueSeparator = ISSUE_SEPARATOR,
243
+ unionSeparator = UNION_SEPARATOR,
244
+ prefixSeparator = PREFIX_SEPARATOR,
245
+ prefix = PREFIX,
246
+ includePath = true
247
+ } = options;
248
+ const zodIssues = zodError.errors;
249
+ const reason = zodIssues.length === 0 ? zodError.message : zodIssues.slice(0, maxIssuesInMessage).map(
250
+ (issue) => getMessageFromZodIssue({
251
+ issue,
252
+ issueSeparator,
253
+ unionSeparator,
254
+ includePath
255
+ })
256
+ ).join(issueSeparator);
257
+ const message = prefixMessage(reason, prefix, prefixSeparator);
258
+ return new ValidationError(message, { cause: zodError });
149
259
  }
150
260
 
261
+ // lib/toValidationError.ts
262
+ var toValidationError = (options = {}) => (err) => {
263
+ if (isZodErrorLike(err)) {
264
+ return fromZodErrorWithoutRuntimeCheck(err, options);
265
+ }
266
+ if (err instanceof Error) {
267
+ return new ValidationError(err.message, { cause: err });
268
+ }
269
+ return new ValidationError("Unknown error");
270
+ };
271
+
272
+ // lib/fromError.ts
273
+ function fromError(err, options = {}) {
274
+ return toValidationError(options)(err);
275
+ }
276
+ // Annotate the CommonJS export names for ESM import in node:
277
+ 0 && (0);
278
+ //# sourceMappingURL=index.js.map
151
279
 
152
280
  /***/ }),
153
281
 
@@ -180,7 +308,7 @@ module.exports = require("../zod");
180
308
  /******/ // Execute the module function
181
309
  /******/ var threw = true;
182
310
  /******/ try {
183
- /******/ __webpack_modules__[moduleId].call(module.exports, module, module.exports, __nccwpck_require__);
311
+ /******/ __webpack_modules__[moduleId](module, module.exports, __nccwpck_require__);
184
312
  /******/ threw = false;
185
313
  /******/ } finally {
186
314
  /******/ if(threw) delete __webpack_module_cache__[moduleId];
@@ -196,22 +324,12 @@ module.exports = require("../zod");
196
324
  /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/";
197
325
  /******/
198
326
  /************************************************************************/
199
- var __webpack_exports__ = {};
200
- // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
201
- (() => {
202
- var exports = __webpack_exports__;
203
-
204
- Object.defineProperty(exports, "__esModule", ({ value: true }));
205
- exports.fromZodError = exports.isValidationErrorLike = exports.isValidationError = exports.toValidationError = exports.ValidationError = void 0;
206
- var ValidationError_1 = __nccwpck_require__(381);
207
- Object.defineProperty(exports, "ValidationError", ({ enumerable: true, get: function () { return ValidationError_1.ValidationError; } }));
208
- Object.defineProperty(exports, "toValidationError", ({ enumerable: true, get: function () { return ValidationError_1.toValidationError; } }));
209
- Object.defineProperty(exports, "isValidationError", ({ enumerable: true, get: function () { return ValidationError_1.isValidationError; } }));
210
- Object.defineProperty(exports, "isValidationErrorLike", ({ enumerable: true, get: function () { return ValidationError_1.isValidationErrorLike; } }));
211
- Object.defineProperty(exports, "fromZodError", ({ enumerable: true, get: function () { return ValidationError_1.fromZodError; } }));
212
-
213
- })();
214
-
215
- module.exports = __webpack_exports__;
327
+ /******/
328
+ /******/ // startup
329
+ /******/ // Load entry module and return exports
330
+ /******/ // This entry module is referenced by other modules so it can't be inlined
331
+ /******/ var __webpack_exports__ = __nccwpck_require__(172);
332
+ /******/ module.exports = __webpack_exports__;
333
+ /******/
216
334
  /******/ })()
217
335
  ;
@@ -1 +1 @@
1
- {"name":"zod-validation-error","author":{"name":"Causaly Team","email":"front-end@causaly.com","url":"https://www.causaly.com"},"version":"1.3.1","license":"MIT","types":"index.d.ts","type":"commonjs"}
1
+ {"name":"zod-validation-error","author":{"name":"Dimitrios C. Michalakos","email":"dimitris@jmike.gr","url":"https://github.com/jmike"},"version":"3.3.1","license":"MIT","types":"index.d.ts","type":"commonjs"}
@@ -650,8 +650,10 @@ function getRawExperiments(experiments) {
650
650
  rspackFuture: getRawRspackFutureOptions(rspackFuture)
651
651
  };
652
652
  }
653
- function getRawRspackFutureOptions(_future) {
654
- return {};
653
+ function getRawRspackFutureOptions(future) {
654
+ return {
655
+ newIncremental: future.newIncremental
656
+ };
655
657
  }
656
658
  function getRawNode(node) {
657
659
  if (node === false) {
@@ -136,6 +136,9 @@ const applyExperimentsDefaults = (experiments) => {
136
136
  // IGNORE(experiments.rspackFuture): Rspack specific configuration
137
137
  D(experiments, "rspackFuture", {});
138
138
  // rspackFuture.bundlerInfo default value is applied after applyDefaults
139
+ if (typeof experiments.rspackFuture === "object") {
140
+ D(experiments.rspackFuture, "newIncremental", false);
141
+ }
139
142
  };
140
143
  const applybundlerInfoDefaults = (rspackFuture, library) => {
141
144
  if (typeof rspackFuture === "object") {
@@ -597,7 +600,7 @@ const applyOutputDefaults = (output, { context, outputModule, targetProperties:
597
600
  const optimistic = (v) => v || v === undefined;
598
601
  const conditionallyOptimistic = (v, c) => (v === undefined && c) || v;
599
602
  F(environment, "globalThis", () => tp?.globalThis);
600
- F(environment, "bigIntLiteral", () => tp?.bigIntLiteral);
603
+ F(environment, "bigIntLiteral", () => tp && optimistic(tp.bigIntLiteral));
601
604
  F(environment, "const", () => tp && optimistic(tp.const));
602
605
  F(environment, "arrowFunction", () => tp && optimistic(tp.arrowFunction));
603
606
  F(environment, "asyncFunction", () => tp && optimistic(tp.asyncFunction));
@@ -13,7 +13,7 @@ declare const name: z.ZodString;
13
13
  export type Name = z.infer<typeof name>;
14
14
  declare const dependencies: z.ZodArray<z.ZodString, "many">;
15
15
  export type Dependencies = z.infer<typeof dependencies>;
16
- declare const context: z.ZodString;
16
+ declare const context: z.ZodEffects<z.ZodString, string, string>;
17
17
  export type Context = z.infer<typeof context>;
18
18
  declare const mode: z.ZodEnum<["development", "production", "none"]>;
19
19
  export type Mode = z.infer<typeof mode>;
@@ -5967,18 +5967,21 @@ declare const rspackFutureOptions: z.ZodObject<{
5967
5967
  version?: string | undefined;
5968
5968
  bundler?: string | undefined;
5969
5969
  }>>;
5970
+ newIncremental: z.ZodOptional<z.ZodBoolean>;
5970
5971
  }, "strict", z.ZodTypeAny, {
5971
5972
  bundlerInfo?: {
5972
5973
  force?: boolean | ("version" | "uniqueId")[] | undefined;
5973
5974
  version?: string | undefined;
5974
5975
  bundler?: string | undefined;
5975
5976
  } | undefined;
5977
+ newIncremental?: boolean | undefined;
5976
5978
  }, {
5977
5979
  bundlerInfo?: {
5978
5980
  force?: boolean | ("version" | "uniqueId")[] | undefined;
5979
5981
  version?: string | undefined;
5980
5982
  bundler?: string | undefined;
5981
5983
  } | undefined;
5984
+ newIncremental?: boolean | undefined;
5982
5985
  }>;
5983
5986
  export type RspackFutureOptions = z.infer<typeof rspackFutureOptions>;
5984
5987
  declare const lazyCompilationOptions: z.ZodObject<{
@@ -6201,18 +6204,21 @@ declare const experiments: z.ZodObject<{
6201
6204
  version?: string | undefined;
6202
6205
  bundler?: string | undefined;
6203
6206
  }>>;
6207
+ newIncremental: z.ZodOptional<z.ZodBoolean>;
6204
6208
  }, "strict", z.ZodTypeAny, {
6205
6209
  bundlerInfo?: {
6206
6210
  force?: boolean | ("version" | "uniqueId")[] | undefined;
6207
6211
  version?: string | undefined;
6208
6212
  bundler?: string | undefined;
6209
6213
  } | undefined;
6214
+ newIncremental?: boolean | undefined;
6210
6215
  }, {
6211
6216
  bundlerInfo?: {
6212
6217
  force?: boolean | ("version" | "uniqueId")[] | undefined;
6213
6218
  version?: string | undefined;
6214
6219
  bundler?: string | undefined;
6215
6220
  } | undefined;
6221
+ newIncremental?: boolean | undefined;
6216
6222
  }>>;
6217
6223
  }, "strict", z.ZodTypeAny, {
6218
6224
  css?: boolean | undefined;
@@ -6246,6 +6252,7 @@ declare const experiments: z.ZodObject<{
6246
6252
  version?: string | undefined;
6247
6253
  bundler?: string | undefined;
6248
6254
  } | undefined;
6255
+ newIncremental?: boolean | undefined;
6249
6256
  } | undefined;
6250
6257
  }, {
6251
6258
  css?: boolean | undefined;
@@ -6279,6 +6286,7 @@ declare const experiments: z.ZodObject<{
6279
6286
  version?: string | undefined;
6280
6287
  bundler?: string | undefined;
6281
6288
  } | undefined;
6289
+ newIncremental?: boolean | undefined;
6282
6290
  } | undefined;
6283
6291
  }>;
6284
6292
  export type Experiments = z.infer<typeof experiments>;
@@ -7245,18 +7253,21 @@ export declare const rspackOptions: z.ZodObject<{
7245
7253
  version?: string | undefined;
7246
7254
  bundler?: string | undefined;
7247
7255
  }>>;
7256
+ newIncremental: z.ZodOptional<z.ZodBoolean>;
7248
7257
  }, "strict", z.ZodTypeAny, {
7249
7258
  bundlerInfo?: {
7250
7259
  force?: boolean | ("version" | "uniqueId")[] | undefined;
7251
7260
  version?: string | undefined;
7252
7261
  bundler?: string | undefined;
7253
7262
  } | undefined;
7263
+ newIncremental?: boolean | undefined;
7254
7264
  }, {
7255
7265
  bundlerInfo?: {
7256
7266
  force?: boolean | ("version" | "uniqueId")[] | undefined;
7257
7267
  version?: string | undefined;
7258
7268
  bundler?: string | undefined;
7259
7269
  } | undefined;
7270
+ newIncremental?: boolean | undefined;
7260
7271
  }>>;
7261
7272
  }, "strict", z.ZodTypeAny, {
7262
7273
  css?: boolean | undefined;
@@ -7290,6 +7301,7 @@ export declare const rspackOptions: z.ZodObject<{
7290
7301
  version?: string | undefined;
7291
7302
  bundler?: string | undefined;
7292
7303
  } | undefined;
7304
+ newIncremental?: boolean | undefined;
7293
7305
  } | undefined;
7294
7306
  }, {
7295
7307
  css?: boolean | undefined;
@@ -7323,6 +7335,7 @@ export declare const rspackOptions: z.ZodObject<{
7323
7335
  version?: string | undefined;
7324
7336
  bundler?: string | undefined;
7325
7337
  } | undefined;
7338
+ newIncremental?: boolean | undefined;
7326
7339
  } | undefined;
7327
7340
  }>>;
7328
7341
  externals: z.ZodOptional<z.ZodUnion<[z.ZodArray<z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodString, z.ZodType<RegExp, z.ZodTypeDef, RegExp>]>, z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodString, z.ZodBoolean]>, z.ZodArray<z.ZodString, "many">]>, z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>]>>]>, z.ZodFunction<z.ZodTuple<[z.ZodObject<{
@@ -7478,7 +7491,7 @@ export declare const rspackOptions: z.ZodObject<{
7478
7491
  stream?: NodeJS.WritableStream | undefined;
7479
7492
  }>>;
7480
7493
  cache: z.ZodOptional<z.ZodBoolean>;
7481
- context: z.ZodOptional<z.ZodString>;
7494
+ context: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
7482
7495
  devtool: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<false>, z.ZodEnum<["eval", "cheap-source-map", "cheap-module-source-map", "source-map", "inline-cheap-source-map", "inline-cheap-module-source-map", "inline-source-map", "inline-nosources-cheap-source-map", "inline-nosources-cheap-module-source-map", "inline-nosources-source-map", "nosources-cheap-source-map", "nosources-cheap-module-source-map", "nosources-source-map", "hidden-nosources-cheap-source-map", "hidden-nosources-cheap-module-source-map", "hidden-nosources-source-map", "hidden-cheap-source-map", "hidden-cheap-module-source-map", "hidden-source-map", "eval-cheap-source-map", "eval-cheap-module-source-map", "eval-source-map", "eval-nosources-cheap-source-map", "eval-nosources-cheap-module-source-map", "eval-nosources-source-map"]>]>>;
7483
7496
  node: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<false>, z.ZodObject<{
7484
7497
  __dirname: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodEnum<["warn-mock", "mock", "eval-only", "node-module"]>]>>;
@@ -9354,6 +9367,7 @@ export declare const rspackOptions: z.ZodObject<{
9354
9367
  version?: string | undefined;
9355
9368
  bundler?: string | undefined;
9356
9369
  } | undefined;
9370
+ newIncremental?: boolean | undefined;
9357
9371
  } | undefined;
9358
9372
  } | undefined;
9359
9373
  externals?: string | RegExp | Record<string, string | boolean | string[] | Record<string, string | string[]>> | ((args_0: {
@@ -9927,6 +9941,7 @@ export declare const rspackOptions: z.ZodObject<{
9927
9941
  version?: string | undefined;
9928
9942
  bundler?: string | undefined;
9929
9943
  } | undefined;
9944
+ newIncremental?: boolean | undefined;
9930
9945
  } | undefined;
9931
9946
  } | undefined;
9932
9947
  externals?: string | RegExp | Record<string, string | boolean | string[] | Record<string, string | string[]>> | ((args_0: {
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.rspackOptions = exports.externalsType = void 0;
7
+ const node_path_1 = __importDefault(require("node:path"));
4
8
  const zod_1 = require("../../compiled/zod");
5
9
  const Chunk_1 = require("../Chunk");
6
10
  const Module_1 = require("../Module");
@@ -16,7 +20,9 @@ const name = zod_1.z.string();
16
20
  const dependencies = zod_1.z.array(name);
17
21
  //#endregion
18
22
  //#region Context
19
- const context = zod_1.z.string();
23
+ const context = zod_1.z.string().refine(val => node_path_1.default.isAbsolute(val), val => ({
24
+ message: `The provided value ${JSON.stringify(val)} must be an absolute path.`
25
+ }));
20
26
  //#endregion
21
27
  //#region Mode
22
28
  const mode = zod_1.z.enum(["development", "production", "none"]);
@@ -861,7 +867,8 @@ const rspackFutureOptions = zod_1.z.strictObject({
861
867
  .or(zod_1.z.array(zod_1.z.enum(["version", "uniqueId"])))
862
868
  .optional()
863
869
  })
864
- .optional()
870
+ .optional(),
871
+ newIncremental: zod_1.z.boolean().optional()
865
872
  });
866
873
  const listenOptions = zod_1.z.object({
867
874
  port: zod_1.z.number().optional(),
package/dist/exports.d.ts CHANGED
@@ -33,6 +33,8 @@ type Config = {
33
33
  };
34
34
  export declare const config: Config;
35
35
  export type * from "./config";
36
+ import { ValidationError } from "./util/validate";
37
+ export { ValidationError };
36
38
  export declare const util: {
37
39
  createHash: (algorithm: (string & {}) | "debug" | "xxhash64" | "md4" | "native-md4" | (new () => import("./util/hash").default)) => import("./util/hash").default;
38
40
  cleverMerge: <First, Second>(first: First, second: Second) => First | Second | (First & Second);
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.CssExtractRspackPlugin = 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.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 = void 0;
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;
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;
@@ -67,6 +67,8 @@ exports.config = {
67
67
  getNormalizedWebpackOptions: config_1.getNormalizedRspackOptions,
68
68
  applyWebpackOptionsDefaults: config_1.applyRspackOptionsDefaults
69
69
  };
70
+ const validate_1 = require("./util/validate");
71
+ Object.defineProperty(exports, "ValidationError", { enumerable: true, get: function () { return validate_1.ValidationError; } });
70
72
  const cleverMerge_1 = require("./util/cleverMerge");
71
73
  const createHash_1 = require("./util/createHash");
72
74
  exports.util = { createHash: createHash_1.createHash, cleverMerge: cleverMerge_1.cachedCleverMerge };
@@ -82,7 +82,9 @@ function createLoaderObject(loader, compiler) {
82
82
  }
83
83
  obj.ident = ident;
84
84
  }
85
- obj.type = value.type;
85
+ // CHANGE: `rspack_core` returns empty string for `undefined` type.
86
+ // Comply to webpack test case: tests/webpack-test/cases/loaders/cjs-loader-type/index.js
87
+ obj.type = value.type === "" ? undefined : value.type;
86
88
  if (obj.options === null)
87
89
  obj.query = "";
88
90
  else if (obj.options === undefined)
@@ -1,3 +1,6 @@
1
1
  import type { z } from "../../compiled/zod";
2
+ export declare class ValidationError extends Error {
3
+ constructor(message: string);
4
+ }
2
5
  export declare function validate<T extends z.ZodType>(opts: any, schema: T): void;
3
6
  export declare function isValidate<T extends z.ZodType>(opts: any, schema: T): boolean;
@@ -1,34 +1,70 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isValidate = exports.validate = void 0;
3
+ exports.isValidate = exports.validate = exports.ValidationError = void 0;
4
4
  const zod_validation_error_1 = require("../../compiled/zod-validation-error");
5
+ class ValidationError extends Error {
6
+ constructor(message) {
7
+ super(message);
8
+ this.name = "ValidationError";
9
+ }
10
+ }
11
+ exports.ValidationError = ValidationError;
5
12
  function validate(opts, schema) {
6
13
  const res = schema.safeParse(opts);
7
14
  if (!res.success) {
8
15
  const strategy = process.env.RSPACK_CONFIG_VALIDATE ?? "strict";
9
16
  if (strategy === "loose-silent")
10
17
  return;
11
- const issueSeparator = "$issue$";
12
- const prefixSeparator = "$prefix$";
13
- const validationErr = (0, zod_validation_error_1.fromZodError)(res.error, {
14
- prefix: "Configuration error",
15
- prefixSeparator,
16
- issueSeparator
17
- });
18
- // The output validationErr.message looks like
19
- // `Configuration error$prefix$xxxx error$issue$yyy error$issue$zzz error`
20
- const [prefix, reason] = validationErr.message.split(prefixSeparator);
21
- const reasonItem = reason.split(issueSeparator);
22
- const friendlyErr = new Error(`${prefix}:\n${reasonItem.map(item => `- ${item}`).join("\n")}`);
23
- if (strategy === "loose") {
24
- console.error(friendlyErr.message);
18
+ let friendlyErr;
19
+ const originalIssues = res.error.issues;
20
+ // Issues with code `unrecognized_keys` are ignored. Other issues are thrown.
21
+ // This does not work when `zodError.issues` is empty so we need to check the length of `zodError.issues`.
22
+ // See: https://github.com/causaly/zod-validation-error/blob/62684ba47cba9cbd84e2a75dfd5fd06dcd0e1ad5/lib/fromZodError.ts#L53
23
+ if (strategy === "loose-unrecognized-keys" && res.error.issues.length > 0) {
24
+ // This is based on the invariant that `fromZodError` always reads `zodError.errors` first and
25
+ // `zodError.errors` always returns `zodError.issues`:
26
+ // See: https://github.com/causaly/zod-validation-error/blob/62684ba47cba9cbd84e2a75dfd5fd06dcd0e1ad5/lib/fromZodError.ts#L55
27
+ // Also see: https://github.com/colinhacks/zod/blob/8552233c77426f77d3586cc877f7aec1aa0aa45b/src/ZodError.ts#L200
28
+ const unrecognizedKeys = originalIssues.filter(issue => issue.code === "unrecognized_keys");
29
+ if (unrecognizedKeys.length > 0) {
30
+ res.error.issues = unrecognizedKeys;
31
+ friendlyErr = toValidationError(res.error);
32
+ console.error(friendlyErr.message);
33
+ res.error.issues = originalIssues;
34
+ }
35
+ res.error.issues = originalIssues.filter(issue => issue.code !== "unrecognized_keys");
36
+ if (res.error.issues.length > 0) {
37
+ throw toValidationError(res.error);
38
+ }
39
+ return;
25
40
  }
26
- else {
27
- throw friendlyErr;
41
+ if (strategy === "loose-unrecognized-keys" || strategy === "loose") {
42
+ friendlyErr = toValidationError(res.error);
43
+ console.error(friendlyErr.message);
44
+ return;
28
45
  }
46
+ // strict
47
+ friendlyErr = toValidationError(res.error);
48
+ throw friendlyErr;
29
49
  }
30
50
  }
31
51
  exports.validate = validate;
52
+ function toValidationError(error) {
53
+ const issueSeparator = "$issue$";
54
+ const prefixSeparator = "$prefix$";
55
+ const validationErr = (0, zod_validation_error_1.fromZodError)(error, {
56
+ prefix: "Invalid configuration object. Rspack has been initialized using a configuration object that does not match the API schema.",
57
+ prefixSeparator,
58
+ issueSeparator
59
+ });
60
+ // The output validationErr.message looks like
61
+ // `Configuration error$prefix$xxxx error$issue$yyy error$issue$zzz error`
62
+ const [prefix, reason] = validationErr.message.split(prefixSeparator);
63
+ const reasonItem = reason.split(issueSeparator);
64
+ const message = `${prefix}\n${reasonItem.map(item => `- ${item}`).join("\n")}`;
65
+ const friendlyErr = new ValidationError(message);
66
+ return friendlyErr;
67
+ }
32
68
  function isValidate(opts, schema) {
33
69
  try {
34
70
  validate(opts, schema);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspack/core",
3
- "version": "1.0.0-rc.0",
3
+ "version": "1.0.0-rc.2",
4
4
  "webpackVersion": "5.75.0",
5
5
  "license": "MIT",
6
6
  "description": "The fast Rust-based web bundler with webpack-compatible API",
@@ -54,13 +54,13 @@
54
54
  "webpack-sources": "3.2.3",
55
55
  "webpack-dev-server": "^5.0.4",
56
56
  "zod": "^3.23.8",
57
- "zod-validation-error": "1.3.1"
57
+ "zod-validation-error": "3.3.1"
58
58
  },
59
59
  "dependencies": {
60
60
  "@module-federation/runtime-tools": "0.5.1",
61
61
  "@rspack/lite-tapable": "1.0.0",
62
62
  "caniuse-lite": "^1.0.30001616",
63
- "@rspack/binding": "1.0.0-rc.0"
63
+ "@rspack/binding": "1.0.0-rc.2"
64
64
  },
65
65
  "peerDependencies": {
66
66
  "@swc/helpers": ">=0.5.1"