diff --git a/examples/with-keep-alive/README.md b/examples/with-keep-alive/README.md index 55dab7d82d..deab322b7a 100644 --- a/examples/with-keep-alive/README.md +++ b/examples/with-keep-alive/README.md @@ -1,6 +1,6 @@ # with-keep-alive -Experimental keep-alive with React 18 ``. +Experimental keep-alive with React 18 ``. ## How to debug @@ -15,9 +15,11 @@ $ cd packages/runtime && yalc publish --push Then, install the example dependencies. ```bash -$ cd examples/with-keep-alive && yarn install +$ cd examples/with-keep-alive $ yalc add @ice/app @ice/runtime +$ yarn install + $ npm run start ``` diff --git a/examples/with-keep-alive/package.json b/examples/with-keep-alive/package.json index cceb02e949..6a4359d954 100644 --- a/examples/with-keep-alive/package.json +++ b/examples/with-keep-alive/package.json @@ -7,13 +7,15 @@ "build": "ice build" }, "dependencies": { - "@ice/runtime": "alpha", - "react": "experimental", - "react-dom": "experimental" + "react": "0.0.0-experimental-0cdfef19b-20231211", + "react-dom": "0.0.0-experimental-0cdfef19b-20231211" }, "devDependencies": { - "@ice/app": "alpha", "@types/react": "^18.0.0", "@types/react-dom": "^18.0.2" + }, + "resolutions": { + "react": "0.0.0-experimental-0cdfef19b-20231211", + "react-dom": "0.0.0-experimental-0cdfef19b-20231211" } } diff --git a/package.json b/package.json index 63a439e836..bb4c565f88 100644 --- a/package.json +++ b/package.json @@ -71,7 +71,8 @@ "packageManager": "pnpm@8.9.2", "pnpm": { "patchedDependencies": { - "unplugin@1.5.1": "patches/unplugin@1.5.1.patch" + "unplugin@1.5.1": "patches/unplugin@1.5.1.patch", + "@rspack/core@0.4.5": "patches/@rspack__core@0.4.5.patch" } } } diff --git a/packages/bundles/CHANGELOG.md b/packages/bundles/CHANGELOG.md index 52154d331e..37cb262201 100644 --- a/packages/bundles/CHANGELOG.md +++ b/packages/bundles/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 0.2.1 + +### Patch Changes + +- 420fec85: fix: update binding version for packing error, resolve error when disable code splitting + ## 0.2.0 ### Minor Changes diff --git a/packages/bundles/override/rspack/adapter.js b/packages/bundles/override/rspack/adapter.js deleted file mode 100644 index 5e378ec28f..0000000000 --- a/packages/bundles/override/rspack/adapter.js +++ /dev/null @@ -1,669 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.getRawChunkLoading = exports.getRawEntryRuntime = exports.toRawSplitChunksOptions = exports.getRawLibrary = exports.getRawOptions = void 0; -const assert_1 = __importDefault(require("assert")); -const Stats_1 = require("../Stats"); -const util_1 = require("../util"); -const identifier_1 = require("../util/identifier"); -const adapterRuleUse_1 = require("./adapterRuleUse"); -const Module_1 = require("../Module"); -const getRawOptions = (options, compiler, processResource) => { - var _a, _b; - (0, assert_1.default)(!(0, util_1.isNil)(options.context) && !(0, util_1.isNil)(options.devtool) && !(0, util_1.isNil)(options.cache), "context, devtool, cache should not be nil after defaults"); - const devtool = options.devtool === false ? "" : options.devtool; - const mode = options.mode; - const experiments = getRawExperiments(options.experiments); - return { - // CUSTOM: add options of features. - features: options.features, - mode, - target: getRawTarget(options.target), - context: options.context, - output: getRawOutput(options.output), - resolve: getRawResolve(options.resolve), - resolveLoader: getRawResolve(options.resolveLoader), - module: getRawModule(options.module, { - compiler, - devtool, - mode, - context: options.context, - experiments - }), - devtool, - optimization: getRawOptimization(options.optimization), - stats: getRawStats(options.stats), - devServer: { - hot: (_b = (_a = options.devServer) === null || _a === void 0 ? void 0 : _a.hot) !== null && _b !== void 0 ? _b : false - }, - snapshot: getRawSnapshotOptions(options.snapshot), - cache: { - type: options.cache ? "memory" : "disable", - // TODO: implement below cache options - maxGenerations: 0, - maxAge: 0, - profile: false, - buildDependencies: [], - cacheDirectory: "", - cacheLocation: "", - name: "", - version: "" - }, - experiments, - node: getRawNode(options.node), - profile: options.profile, - // TODO: remove this - builtins: options.builtins - }; -}; -exports.getRawOptions = getRawOptions; -function getRawTarget(target) { - if (!target) { - return []; - } - if (typeof target === "string") { - return [target]; - } - return target; -} -function getRawAlias(alias = {}) { - const entires = Object.entries(alias).map(([key, value]) => { - if (Array.isArray(value)) { - return [key, value]; - } - else { - return [key, [value]]; - } - }); - return Object.fromEntries(entires); -} -function getRawResolveByDependency(byDependency) { - if (byDependency === undefined) - return byDependency; - return Object.fromEntries(Object.entries(byDependency).map(([k, v]) => [k, getRawResolve(v)])); -} -function getRawResolve(resolve) { - var _a, _b, _c; - let references = (_a = resolve.tsConfig) === null || _a === void 0 ? void 0 : _a.references; - let tsconfigConfigFile = (_b = resolve.tsConfigPath) !== null && _b !== void 0 ? _b : (_c = resolve.tsConfig) === null || _c === void 0 ? void 0 : _c.configFile; - return { - ...resolve, - alias: getRawAlias(resolve.alias), - fallback: getRawAlias(resolve.fallback), - extensionAlias: getRawAlias(resolve.extensionAlias), - tsconfig: tsconfigConfigFile - ? { - configFile: tsconfigConfigFile, - referencesType: references == "auto" ? "auto" : references ? "manual" : "disabled", - references: references == "auto" ? undefined : references - } - : undefined, - byDependency: getRawResolveByDependency(resolve.byDependency) - }; -} -function getRawCrossOriginLoading(crossOriginLoading) { - if (typeof crossOriginLoading === "boolean") { - return { type: "bool", boolPayload: crossOriginLoading }; - } - return { type: "string", stringPayload: crossOriginLoading }; -} -function getRawOutput(output) { - const chunkLoading = output.chunkLoading; - const wasmLoading = output.wasmLoading; - const workerChunkLoading = output.workerChunkLoading; - const workerWasmLoading = output.workerWasmLoading; - return { - path: output.path, - publicPath: output.publicPath, - clean: output.clean, - assetModuleFilename: output.assetModuleFilename, - filename: output.filename, - chunkFilename: output.chunkFilename, - chunkLoading: getRawChunkLoading(chunkLoading), - crossOriginLoading: getRawCrossOriginLoading(output.crossOriginLoading), - cssFilename: output.cssFilename, - cssChunkFilename: output.cssChunkFilename, - hotUpdateChunkFilename: output.hotUpdateChunkFilename, - hotUpdateMainFilename: output.hotUpdateMainFilename, - hotUpdateGlobal: output.hotUpdateGlobal, - uniqueName: output.uniqueName, - chunkLoadingGlobal: output.chunkLoadingGlobal, - enabledLibraryTypes: output.enabledLibraryTypes, - library: output.library && getRawLibrary(output.library), - strictModuleErrorHandling: output.strictModuleErrorHandling, - globalObject: output.globalObject, - importFunctionName: output.importFunctionName, - iife: output.iife, - module: output.module, - wasmLoading: wasmLoading === false ? "false" : wasmLoading, - enabledWasmLoadingTypes: output.enabledWasmLoadingTypes, - enabledChunkLoadingTypes: output.enabledChunkLoadingTypes, - webassemblyModuleFilename: output.webassemblyModuleFilename, - trustedTypes: output.trustedTypes, - sourceMapFilename: output.sourceMapFilename, - hashFunction: output.hashFunction, - hashDigest: output.hashDigest, - hashDigestLength: output.hashDigestLength, - hashSalt: output.hashSalt, - asyncChunks: output.asyncChunks, - workerChunkLoading: workerChunkLoading === false ? "false" : workerChunkLoading, - workerWasmLoading: workerWasmLoading === false ? "false" : workerWasmLoading, - workerPublicPath: output.workerPublicPath, - scriptType: output.scriptType === false ? "false" : output.scriptType - }; -} -function getRawLibrary(library) { - const { type, name, export: libraryExport, umdNamedDefine, auxiliaryComment, amdContainer } = library; - return { - amdContainer, - auxiliaryComment: typeof auxiliaryComment === "string" - ? { - commonjs: auxiliaryComment, - commonjs2: auxiliaryComment, - amd: auxiliaryComment, - root: auxiliaryComment - } - : auxiliaryComment, - libraryType: type, - name: (0, util_1.isNil)(name) ? name : getRawLibraryName(name), - export: Array.isArray(libraryExport) || libraryExport == null - ? libraryExport - : [libraryExport], - umdNamedDefine - }; -} -exports.getRawLibrary = getRawLibrary; -function getRawLibraryName(name) { - if (typeof name === "string") { - return { - type: "string", - stringPayload: name - }; - } - if (Array.isArray(name)) { - return { - type: "array", - arrayPayload: name - }; - } - if (typeof name === "object" && !Array.isArray(name)) { - return { - type: "umdObject", - umdObjectPayload: { - commonjs: name.commonjs, - root: Array.isArray(name.root) || (0, util_1.isNil)(name.root) - ? name.root - : [name.root], - amd: name.amd - } - }; - } - throw new Error("unreachable"); -} -function getRawModule(module, options) { - (0, assert_1.default)(!(0, util_1.isNil)(module.defaultRules), "module.defaultRules should not be nil after defaults"); - // "..." in defaultRules will be flatten in `applyModuleDefaults`, and "..." in rules is empty, so it's safe to use `as RuleSetRule[]` at here - const ruleSet = [ - { rules: module.defaultRules }, - { rules: module.rules } - ]; - const rules = ruleSet.map((rule, index) => getRawModuleRule(rule, `ruleSet[${index}]`, options)); - return { - rules, - parser: getRawParserOptionsByModuleType(module.parser), - generator: getRawGeneratorOptionsByModuleType(module.generator) - }; -} -function tryMatch(payload, condition) { - if (typeof condition === "string") { - return payload.startsWith(condition); - } - if (condition instanceof RegExp) { - return condition.test(payload); - } - if (typeof condition === "function") { - return condition(payload); - } - if (Array.isArray(condition)) { - return condition.some(c => tryMatch(payload, c)); - } - if (condition && typeof condition === "object") { - if (condition.and) { - return condition.and.every(c => tryMatch(payload, c)); - } - if (condition.or) { - return condition.or.some(c => tryMatch(payload, c)); - } - if (condition.not) { - return condition.not.every(c => !tryMatch(payload, c)); - } - } - return false; -} -const deprecatedRuleType = (type) => { - type !== null && type !== void 0 ? type : (type = "javascript/auto"); - if (/ts|typescript|tsx|typescriptx|jsx|javascriptx/.test(type)) { - (0, util_1.deprecatedWarn)(`'Rule.type: ${type}' has been deprecated, please migrate to builtin:swc-loader with type 'javascript/auto'`); - } -}; -const getRawModuleRule = (rule, path, options) => { - var _a, _b, _c; - // Rule.loader is a shortcut to Rule.use: [ { loader } ]. - // See: https://webpack.js.org/configuration/module/#ruleloader - if (rule.loader) { - rule.use = [ - { - loader: rule.loader, - options: rule.options - } - ]; - } - let funcUse; - if (typeof rule.use === "function") { - funcUse = (rawContext) => { - const context = { - ...rawContext, - compiler: options.compiler - }; - const uses = rule.use(context); - return (0, adapterRuleUse_1.createRawModuleRuleUses)(uses !== null && uses !== void 0 ? uses : [], `${path}.use`, options); - }; - } - let rawModuleRule = { - test: rule.test ? getRawRuleSetCondition(rule.test) : undefined, - include: rule.include ? getRawRuleSetCondition(rule.include) : undefined, - exclude: rule.exclude ? getRawRuleSetCondition(rule.exclude) : undefined, - issuer: rule.issuer ? getRawRuleSetCondition(rule.issuer) : undefined, - dependency: rule.dependency - ? getRawRuleSetCondition(rule.dependency) - : undefined, - descriptionData: rule.descriptionData - ? Object.fromEntries(Object.entries(rule.descriptionData).map(([k, v]) => [ - k, - getRawRuleSetCondition(v) - ])) - : undefined, - resource: rule.resource ? getRawRuleSetCondition(rule.resource) : undefined, - resourceQuery: rule.resourceQuery - ? getRawRuleSetCondition(rule.resourceQuery) - : undefined, - resourceFragment: rule.resourceFragment - ? getRawRuleSetCondition(rule.resourceFragment) - : undefined, - scheme: rule.scheme ? getRawRuleSetCondition(rule.scheme) : undefined, - mimetype: rule.mimetype ? getRawRuleSetCondition(rule.mimetype) : undefined, - sideEffects: rule.sideEffects, - use: typeof rule.use === "function" - ? { type: "function", funcUse } - : { - type: "array", - arrayUse: (0, adapterRuleUse_1.createRawModuleRuleUses)((_a = rule.use) !== null && _a !== void 0 ? _a : [], `${path}.use`, options) - }, - type: rule.type, - parser: rule.parser - ? getRawParserOptions(rule.parser, (_b = rule.type) !== null && _b !== void 0 ? _b : "javascript/auto") - : undefined, - generator: rule.generator - ? getRawGeneratorOptions(rule.generator, (_c = rule.type) !== null && _c !== void 0 ? _c : "javascript/auto") - : undefined, - resolve: rule.resolve ? getRawResolve(rule.resolve) : undefined, - oneOf: rule.oneOf - ? rule.oneOf.map((rule, index) => getRawModuleRule(rule, `${path}.oneOf[${index}]`, options)) - : undefined, - rules: rule.rules - ? rule.rules.map((rule, index) => getRawModuleRule(rule, `${path}.rules[${index}]`, options)) - : undefined, - enforce: rule.enforce - }; - // Function calls may contain side-effects when interoperating with single-threaded environment. - // In order to mitigate the issue, Rspack tries to merge these calls together. - // See: https://github.com/web-infra-dev/rspack/issues/4003#issuecomment-1689662380 - if (typeof rule.test === "function" || - typeof rule.resource === "function" || - typeof rule.resourceQuery === "function" || - typeof rule.resourceFragment === "function") { - delete rawModuleRule.test; - delete rawModuleRule.resource; - delete rawModuleRule.resourceQuery; - delete rawModuleRule.resourceFragment; - rawModuleRule.rspackResource = getRawRuleSetCondition(function (resourceQueryFragment) { - const { path, query, fragment } = (0, identifier_1.parseResource)(resourceQueryFragment); - if (rule.test && !tryMatch(path, rule.test)) { - return false; - } - else if (rule.resource && !tryMatch(path, rule.resource)) { - return false; - } - if (rule.resourceQuery && !tryMatch(query, rule.resourceQuery)) { - return false; - } - if (rule.resourceFragment && !tryMatch(fragment, rule.resourceFragment)) { - return false; - } - return true; - }); - } - if (options.experiments.rspackFuture.disableTransformByDefault) { - deprecatedRuleType(rule.type); - } - return rawModuleRule; -}; -function getRawRuleSetCondition(condition) { - if (typeof condition === "string") { - return { - type: "string", - stringMatcher: condition - }; - } - if (condition instanceof RegExp) { - return { - type: "regexp", - regexpMatcher: { - source: condition.source, - flags: condition.flags - } - }; - } - if (typeof condition === "function") { - return { - type: "function", - funcMatcher: condition - }; - } - if (Array.isArray(condition)) { - return { - type: "array", - arrayMatcher: condition.map(i => getRawRuleSetCondition(i)) - }; - } - if (typeof condition === "object" && condition !== null) { - return { - type: "logical", - logicalMatcher: [getRawRuleSetLogicalConditions(condition)] - }; - } - throw new Error("unreachable: condition should be one of string, RegExp, Array, Object"); -} -function getRawRuleSetLogicalConditions(logical) { - return { - and: logical.and - ? logical.and.map(i => getRawRuleSetCondition(i)) - : undefined, - or: logical.or ? logical.or.map(i => getRawRuleSetCondition(i)) : undefined, - not: logical.not ? getRawRuleSetCondition(logical.not) : undefined - }; -} -function getRawParserOptionsByModuleType(parser) { - return Object.fromEntries(Object.entries(parser).map(([k, v]) => [k, getRawParserOptions(v, k)])); -} -function getRawGeneratorOptionsByModuleType(parser) { - return Object.fromEntries(Object.entries(parser).map(([k, v]) => [k, getRawGeneratorOptions(v, k)])); -} -function getRawParserOptions(parser, type) { - if (type === "asset") { - return { - type: "asset", - asset: getRawAssetParserOptions(parser) - }; - } - else if (type === "javascript") { - return { - type: "javascript", - javascript: getRawJavascriptParserOptions(parser) - }; - } - return { - type: "unknown" - }; -} -function getRawJavascriptParserOptions(parser) { - var _a; - return { - dynamicImportMode: (_a = parser.dynamicImportMode) !== null && _a !== void 0 ? _a : "lazy" - }; -} -function getRawAssetParserOptions(parser) { - return { - dataUrlCondition: parser.dataUrlCondition - ? getRawAssetParserDataUrl(parser.dataUrlCondition) - : undefined - }; -} -function getRawAssetParserDataUrl(dataUrlCondition) { - if (typeof dataUrlCondition === "object" && dataUrlCondition !== null) { - return { - type: "options", - options: { - maxSize: dataUrlCondition.maxSize - } - }; - } - throw new Error(`unreachable: AssetParserDataUrl type should be one of "options", but got ${dataUrlCondition}`); -} -function getRawGeneratorOptions(generator, type) { - if (type === "asset") { - return { - type: "asset", - asset: generator ? getRawAssetGeneratorOptions(generator) : undefined - }; - } - if (type === "asset/inline") { - return { - type: "asset/inline", - assetInline: generator - ? getRawAssetInlineGeneratorOptions(generator) - : undefined - }; - } - if (type === "asset/resource") { - return { - type: "asset/resource", - assetResource: generator - ? getRawAssetResourceGeneratorOptions(generator) - : undefined - }; - } - return { - type: "unknown" - }; -} -function getRawAssetGeneratorOptions(options) { - return { - ...getRawAssetInlineGeneratorOptions(options), - ...getRawAssetResourceGeneratorOptions(options) - }; -} -function getRawAssetInlineGeneratorOptions(options) { - return { - dataUrl: options.dataUrl - ? getRawAssetGeneratorDaraUrl(options.dataUrl) - : undefined - }; -} -function getRawAssetResourceGeneratorOptions(options) { - return { - filename: options.filename, - publicPath: options.publicPath - }; -} -function getRawAssetGeneratorDaraUrl(dataUrl) { - if (typeof dataUrl === "object" && dataUrl !== null) { - return { - type: "options", - options: { - encoding: dataUrl.encoding === false ? "false" : dataUrl.encoding, - mimetype: dataUrl.mimetype - } - }; - } - throw new Error(`unreachable: AssetGeneratorDataUrl type should be one of "options", but got ${dataUrl}`); -} -function getRawOptimization(optimization) { - (0, assert_1.default)(!(0, util_1.isNil)(optimization.moduleIds) && - !(0, util_1.isNil)(optimization.chunkIds) && - !(0, util_1.isNil)(optimization.removeAvailableModules) && - !(0, util_1.isNil)(optimization.removeEmptyChunks) && - !(0, util_1.isNil)(optimization.sideEffects) && - !(0, util_1.isNil)(optimization.realContentHash) && - !(0, util_1.isNil)(optimization.providedExports) && - !(0, util_1.isNil)(optimization.usedExports) && - !(0, util_1.isNil)(optimization.innerGraph), "optimization.moduleIds, optimization.removeAvailableModules, optimization.removeEmptyChunks, optimization.sideEffects, optimization.realContentHash, optimization.providedExports, optimization.usedExports, optimization.innerGraph should not be nil after defaults"); - return { - chunkIds: optimization.chunkIds, - splitChunks: toRawSplitChunksOptions(optimization.splitChunks), - moduleIds: optimization.moduleIds, - removeAvailableModules: optimization.removeAvailableModules, - removeEmptyChunks: optimization.removeEmptyChunks, - sideEffects: String(optimization.sideEffects), - realContentHash: optimization.realContentHash, - usedExports: String(optimization.usedExports), - providedExports: optimization.providedExports, - innerGraph: optimization.innerGraph, - mangleExports: String(optimization.mangleExports) - }; -} -function toRawSplitChunksOptions(sc) { - if (!sc) { - return; - } - function getName(name) { - if (typeof name === "function") { - return (ctx) => { - if (typeof ctx.module === "undefined") { - return name(undefined); - } - else { - return name(Module_1.Module.__from_binding(ctx.module)); - } - }; - } - else { - return name; - } - } - function getTest(test) { - if (typeof test === "function") { - return (ctx) => { - if (typeof ctx.module === "undefined") { - return test(undefined); - } - else { - return test(Module_1.Module.__from_binding(ctx.module)); - } - }; - } - else { - return test; - } - } - const { name, cacheGroups = {}, ...passThrough } = sc; - return { - name: getName(name), - cacheGroups: Object.entries(cacheGroups) - .filter(([_key, group]) => group !== false) - .map(([key, group]) => { - group = group; - const { test, name, ...passThrough } = group; - const rawGroup = { - key, - test: getTest(test), - name: getName(name), - ...passThrough - }; - return rawGroup; - }), - ...passThrough - }; -} -exports.toRawSplitChunksOptions = toRawSplitChunksOptions; -function getRawSnapshotOptions(snapshot) { - const { resolve, module } = snapshot; - (0, assert_1.default)(!(0, util_1.isNil)(resolve) && !(0, util_1.isNil)(module)); - const { timestamp: resolveTimestamp, hash: resolveHash } = resolve; - const { timestamp: moduleTimestamp, hash: moduleHash } = module; - (0, assert_1.default)(!(0, util_1.isNil)(resolveTimestamp) && - !(0, util_1.isNil)(resolveHash) && - !(0, util_1.isNil)(moduleTimestamp) && - !(0, util_1.isNil)(moduleHash)); - return { - resolve: { - timestamp: resolveTimestamp, - hash: resolveHash - }, - module: { - timestamp: moduleTimestamp, - hash: moduleHash - } - }; -} -function getRawExperiments(experiments) { - const { lazyCompilation, incrementalRebuild, asyncWebAssembly, newSplitChunks, topLevelAwait, css, rspackFuture } = experiments; - (0, assert_1.default)(!(0, util_1.isNil)(lazyCompilation) && - !(0, util_1.isNil)(incrementalRebuild) && - !(0, util_1.isNil)(asyncWebAssembly) && - !(0, util_1.isNil)(newSplitChunks) && - !(0, util_1.isNil)(topLevelAwait) && - !(0, util_1.isNil)(css) && - !(0, util_1.isNil)(rspackFuture)); - return { - lazyCompilation, - incrementalRebuild: getRawIncrementalRebuild(incrementalRebuild), - asyncWebAssembly, - newSplitChunks, - topLevelAwait, - css, - rspackFuture: getRawRspackFutureOptions(rspackFuture) - }; -} -function getRawRspackFutureOptions(future) { - (0, assert_1.default)(!(0, util_1.isNil)(future.newResolver)); - (0, assert_1.default)(!(0, util_1.isNil)(future.newTreeshaking)); - (0, assert_1.default)(!(0, util_1.isNil)(future.disableTransformByDefault)); - return { - newResolver: future.newResolver, - newTreeshaking: future.newTreeshaking, - disableTransformByDefault: future.disableTransformByDefault - }; -} -function getRawIncrementalRebuild(inc) { - if (inc === false) { - return { - make: false, - emitAsset: false - }; - } - const { make, emitAsset } = inc; - (0, assert_1.default)(!(0, util_1.isNil)(make) && !(0, util_1.isNil)(emitAsset)); - return { - make, - emitAsset - }; -} -function getRawNode(node) { - if (node === false) { - return undefined; - } - (0, assert_1.default)(!(0, util_1.isNil)(node.__dirname) && !(0, util_1.isNil)(node.global) && !(0, util_1.isNil)(node.__filename)); - return { - dirname: String(node.__dirname), - filename: String(node.__filename), - global: String(node.global) - }; -} -function getRawStats(stats) { - var _a; - const statsOptions = (0, Stats_1.normalizeStatsPreset)(stats); - return { - colors: (_a = statsOptions.colors) !== null && _a !== void 0 ? _a : false - }; -} -function getRawEntryRuntime(runtime) { - return runtime === false ? undefined : runtime; -} -exports.getRawEntryRuntime = getRawEntryRuntime; -function getRawChunkLoading(chunkLoading) { - return chunkLoading === false ? "false" : chunkLoading; -} -exports.getRawChunkLoading = getRawChunkLoading; diff --git a/packages/bundles/override/rspack/defaults.js b/packages/bundles/override/rspack/defaults.js deleted file mode 100644 index 68db4c167b..0000000000 --- a/packages/bundles/override/rspack/defaults.js +++ /dev/null @@ -1,763 +0,0 @@ -"use strict"; -/** - * The following code is modified based on - * https://github.com/webpack/webpack/blob/4b4ca3b/lib/config/defaults.js - * - * MIT Licensed - * Author Tobias Koppers @sokra - * Copyright (c) JS Foundation and other contributors - * https://github.com/webpack/webpack/blob/main/LICENSE - */ -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.applyRspackOptionsBaseDefaults = exports.applyRspackOptionsDefaults = void 0; -const assert_1 = __importDefault(require("assert")); -const fs_1 = __importDefault(require("fs")); -const path_1 = __importDefault(require("path")); -const util_1 = require("../util"); -const cleverMerge_1 = require("../util/cleverMerge"); -const target_1 = require("./target"); -const Template_1 = __importDefault(require("../Template")); -const assertNotNil_1 = require("../util/assertNotNil"); -const ModuleTypeConstants_1 = require("../ModuleTypeConstants"); -const applyRspackOptionsDefaults = (options) => { - var _a; - F(options, "context", () => process.cwd()); - F(options, "target", () => { - return (0, target_1.getDefaultTarget)(options.context); - }); - const { mode, target } = options; - (0, assert_1.default)(!(0, util_1.isNil)(target)); - let targetProperties = target === false - ? false - : typeof target === "string" - ? (0, target_1.getTargetProperties)(target, options.context) - : (0, target_1.getTargetsProperties)(target, options.context); - const development = mode === "development"; - const production = mode === "production" || !mode; - if (typeof options.entry !== "function") { - for (const key of Object.keys(options.entry)) { - F(options.entry[key], "import", () => ["./src"]); - } - } - F(options, "devtool", () => false); - D(options, "watch", false); - D(options, "profile", false); - const futureDefaults = (_a = options.experiments.futureDefaults) !== null && _a !== void 0 ? _a : false; - F(options, "cache", () => development); - applyExperimentsDefaults(options.experiments, { - cache: options.cache - }); - // CUSTOM: add default rules for features options. - if (options.features) { - applyFeaturesDefaults(options.features); - } else { - D(options, 'features', {}); - } - applySnapshotDefaults(options.snapshot, { production }); - applyModuleDefaults(options.module, { - // syncWebAssembly: options.experiments.syncWebAssembly, - asyncWebAssembly: options.experiments.asyncWebAssembly, - disableTransformByDefault: options.experiments.rspackFuture.disableTransformByDefault, - css: options.experiments.css - }); - applyOutputDefaults(options.output, { - context: options.context, - targetProperties, - isAffectedByBrowserslist: target === undefined || - (typeof target === "string" && target.startsWith("browserslist")) || - (Array.isArray(target) && - target.some(target => target.startsWith("browserslist"))), - outputModule: options.experiments.outputModule, - entry: options.entry, - futureDefaults - }); - applyExternalsPresetsDefaults(options.externalsPresets, { - targetProperties - }); - // @ts-expect-error - F(options, "externalsType", () => { - return options.output.library - ? options.output.library.type - : options.output.module - ? "module" - : "var"; - }); - applyNodeDefaults(options.node, { targetProperties }); - applyOptimizationDefaults(options.optimization, { production, development }); - options.resolve = (0, cleverMerge_1.cleverMerge)(getResolveDefaults({ - targetProperties, - mode: options.mode - }), options.resolve); - options.resolveLoader = (0, cleverMerge_1.cleverMerge)(getResolveLoaderDefaults(), options.resolveLoader); -}; -exports.applyRspackOptionsDefaults = applyRspackOptionsDefaults; -const applyRspackOptionsBaseDefaults = (options) => { - F(options, "context", () => process.cwd()); - applyInfrastructureLoggingDefaults(options.infrastructureLogging); -}; -exports.applyRspackOptionsBaseDefaults = applyRspackOptionsBaseDefaults; -const applyInfrastructureLoggingDefaults = (infrastructureLogging) => { - F(infrastructureLogging, "stream", () => process.stderr); - const tty = infrastructureLogging.stream.isTTY && process.env.TERM !== "dumb"; - D(infrastructureLogging, "level", "info"); - D(infrastructureLogging, "debug", false); - D(infrastructureLogging, "colors", tty); - D(infrastructureLogging, "appendOnly", !tty); -}; -const applyExperimentsDefaults = (experiments, { cache }) => { - D(experiments, "lazyCompilation", false); - D(experiments, "asyncWebAssembly", false); - D(experiments, "newSplitChunks", true); - D(experiments, "css", true); // we not align with webpack about the default value for better DX - D(experiments, "topLevelAwait", true); - D(experiments, "incrementalRebuild", {}); - if (typeof experiments.incrementalRebuild === "object") { - D(experiments.incrementalRebuild, "make", true); - D(experiments.incrementalRebuild, "emitAsset", true); - } - if (cache === false && - experiments.incrementalRebuild && - experiments.incrementalRebuild.make) { - experiments.incrementalRebuild.make = false; - // TODO: use logger to warn user enable cache for incrementalRebuild.make - } - D(experiments, "rspackFuture", {}); - if (typeof experiments.rspackFuture === "object") { - D(experiments.rspackFuture, "newResolver", true); - D(experiments.rspackFuture, "newTreeshaking", false); - D(experiments.rspackFuture, "disableTransformByDefault", true); - } -}; -const applyFeaturesDefaults = (features) => { - D(features, 'split_chunks_strategy', {}); - if (typeof features.split_chunks_strategy === 'object') { - D(features.split_chunks_strategy, 'name', ''); - D(features.split_chunks_strategy, 'topLevelFrameworks', []); - } -}; -const applySnapshotDefaults = (snapshot, { production }) => { - F(snapshot, "module", () => production - ? { timestamp: true, hash: true } - : { timestamp: true, hash: false }); - F(snapshot, "resolve", () => production - ? { timestamp: true, hash: true } - : { timestamp: true, hash: false }); -}; -const applyJavascriptParserOptionsDefaults = (parserOptions) => { - D(parserOptions, "dynamicImportMode", "lazy"); -}; -const applyModuleDefaults = (module, { asyncWebAssembly, css, disableTransformByDefault }) => { - (0, assertNotNil_1.assertNotNill)(module.parser); - F(module.parser, ModuleTypeConstants_1.ASSET_MODULE_TYPE, () => ({})); - (0, assertNotNil_1.assertNotNill)(module.parser.asset); - F(module.parser.asset, "dataUrlCondition", () => ({})); - if (typeof module.parser.asset.dataUrlCondition === "object") { - D(module.parser.asset.dataUrlCondition, "maxSize", 8096); - } - F(module.parser, "javascript", () => ({})); - (0, assertNotNil_1.assertNotNill)(module.parser.javascript); - applyJavascriptParserOptionsDefaults(module.parser.javascript); - A(module, "defaultRules", () => { - const esm = { - type: "javascript/esm", - resolve: { - byDependency: { - esm: { - fullySpecified: true - } - } - } - }; - const commonjs = { - type: "javascript/dynamic" - }; - const rules = [ - { - mimetype: "application/node", - type: "javascript/auto" - }, - { - test: /\.json$/i, - type: "json" - }, - { - mimetype: "application/json", - type: "json" - }, - { - test: /\.mjs$/i, - ...esm - }, - { - test: /\.js$/i, - descriptionData: { - type: "module" - }, - ...esm - }, - { - test: /\.cjs$/i, - ...commonjs - }, - { - test: /\.js$/i, - descriptionData: { - type: "commonjs" - }, - ...commonjs - }, - { - mimetype: { - or: ["text/javascript", "application/javascript"] - }, - ...esm - } - ]; - // TODO: remove in 0.5.0 - if (!disableTransformByDefault) { - rules.push({ - test: /\.jsx$/i, - type: "jsx" - }, { - test: /\.ts$/i, - type: "ts" - }, { - test: /\.tsx$/i, - type: "tsx" - }); - } - if (asyncWebAssembly) { - const wasm = { - type: "webassembly/async", - rules: [ - { - descriptionData: { - type: "module" - }, - resolve: { - fullySpecified: true - } - } - ] - }; - rules.push({ - test: /\.wasm$/i, - ...wasm - }); - rules.push({ - mimetype: "application/wasm", - ...wasm - }); - } - if (css) { - const cssRule = { - type: "css", - resolve: { - fullySpecified: true, - preferRelative: true - } - }; - const cssModulesRule = { - type: "css/module", - resolve: { - fullySpecified: true - } - }; - rules.push({ - test: /\.css$/i, - oneOf: [ - { - test: /\.module\.css$/i, - ...cssModulesRule - }, - { - ...cssRule - } - ] - }); - rules.push({ - mimetype: "text/css+module", - ...cssModulesRule - }); - rules.push({ - mimetype: "text/css", - ...cssRule - }); - } - rules.push({ - dependency: "url", - oneOf: [ - { - scheme: /^data$/, - type: "asset/inline" - }, - { - type: "asset/resource" - } - ] - }); - return rules; - }); -}; -const applyOutputDefaults = (output, { context, outputModule, targetProperties: tp, isAffectedByBrowserslist, entry, futureDefaults }) => { - const getLibraryName = (library) => { - const libraryName = typeof library === "object" && - library && - !Array.isArray(library) && - "type" in library - ? library.name - : library; - if (Array.isArray(libraryName)) { - return libraryName.join("."); - } - else if (typeof libraryName === "object") { - return getLibraryName(libraryName.root); - } - else if (typeof libraryName === "string") { - return libraryName; - } - return ""; - }; - F(output, "uniqueName", () => { - const libraryName = getLibraryName(output.library).replace(/^\[(\\*[\w:]+\\*)\](\.)|(\.)\[(\\*[\w:]+\\*)\](?=\.|$)|\[(\\*[\w:]+\\*)\]/g, (m, a, d1, d2, b, c) => { - const content = a || b || c; - return content.startsWith("\\") && content.endsWith("\\") - ? `${d2 || ""}[${content.slice(1, -1)}]${d1 || ""}` - : ""; - }); - if (libraryName) - return libraryName; - const pkgPath = path_1.default.resolve(context, "package.json"); - try { - const packageInfo = JSON.parse(fs_1.default.readFileSync(pkgPath, "utf-8")); - return packageInfo.name || ""; - } - catch (e) { - if (e.code !== "ENOENT") { - e.message += `\nwhile determining default 'output.uniqueName' from 'name' in ${pkgPath}`; - throw e; - } - return ""; - } - }); - F(output, "chunkLoadingGlobal", () => Template_1.default.toIdentifier("webpackChunk" + Template_1.default.toIdentifier(output.uniqueName))); - F(output, "module", () => !!outputModule); - D(output, "filename", output.module ? "[name].mjs" : "[name].js"); - F(output, "iife", () => !output.module); - F(output, "chunkFilename", () => { - const filename = output.filename; - if (typeof filename !== "function") { - const hasName = filename.includes("[name]"); - const hasId = filename.includes("[id]"); - const hasChunkHash = filename.includes("[chunkhash]"); - const hasContentHash = filename.includes("[contenthash]"); - // Anything changing depending on chunk is fine - if (hasChunkHash || hasContentHash || hasName || hasId) - return filename; - // Otherwise prefix "[id]." in front of the basename to make it changing - return filename.replace(/(^|\/)([^/]*(?:\?|$))/, "$1[id].$2"); - } - return "[id].js"; - }); - F(output, "cssFilename", () => { - const filename = output.filename; - if (typeof filename !== "function") { - return filename.replace(/\.[mc]?js(\?|$)/, ".css$1"); - } - return "[id].css"; - }); - F(output, "cssChunkFilename", () => { - const chunkFilename = output.chunkFilename; - if (typeof chunkFilename !== "function") { - return chunkFilename.replace(/\.[mc]?js(\?|$)/, ".css$1"); - } - return "[id].css"; - }); - D(output, "hotUpdateChunkFilename", `[id].[fullhash].hot-update.${output.module ? "mjs" : "js"}`); - D(output, "hotUpdateMainFilename", "[runtime].[fullhash].hot-update.json"); - F(output, "hotUpdateGlobal", () => Template_1.default.toIdentifier("webpackHotUpdate" + Template_1.default.toIdentifier(output.uniqueName))); - D(output, "assetModuleFilename", "[hash][ext][query]"); - D(output, "webassemblyModuleFilename", "[hash].module.wasm"); - F(output, "path", () => path_1.default.join(process.cwd(), "dist")); - D(output, "publicPath", tp && (tp.document || tp.importScripts) ? "auto" : ""); - D(output, "hashFunction", futureDefaults ? "xxhash64" : "md4"); - D(output, "hashDigest", "hex"); - D(output, "hashDigestLength", futureDefaults ? 16 : 20); - D(output, "strictModuleErrorHandling", false); - if (output.library) { - F(output.library, "type", () => (output.module ? "module" : "var")); - } - F(output, "chunkFormat", () => { - if (tp) { - const helpMessage = isAffectedByBrowserslist - ? "Make sure that your 'browserslist' includes only platforms that support these features or select an appropriate 'target' to allow selecting a chunk format by default. Alternatively specify the 'output.chunkFormat' directly." - : "Select an appropriate 'target' to allow selecting one by default, or specify the 'output.chunkFormat' directly."; - if (output.module) { - if (tp.dynamicImport) - return "module"; - if (tp.document) - return "array-push"; - throw new Error("For the selected environment is no default ESM chunk format available:\n" + - "ESM exports can be chosen when 'import()' is available.\n" + - "JSONP Array push can be chosen when 'document' is available.\n" + - helpMessage); - } - else { - if (tp.document) - return "array-push"; - if (tp.require) - return "commonjs"; - if (tp.nodeBuiltins) - return "commonjs"; - if (tp.importScripts) - return "array-push"; - throw new Error("For the selected environment is no default script chunk format available:\n" + - "JSONP Array push can be chosen when 'document' or 'importScripts' is available.\n" + - "CommonJs exports can be chosen when 'require' or node builtins are available.\n" + - helpMessage); - } - } - throw new Error("Chunk format can't be selected by default when no target is specified"); - }); - D(output, "asyncChunks", true); - F(output, "chunkLoading", () => { - if (tp) { - switch (output.chunkFormat) { - case "array-push": - if (tp.document) - return "jsonp"; - if (tp.importScripts) - return "import-scripts"; - break; - case "commonjs": - if (tp.require) - return "require"; - if (tp.nodeBuiltins) - return "async-node"; - break; - case "module": - if (tp.dynamicImport) - return "import"; - break; - } - if (tp.require === null || - tp.nodeBuiltins === null || - tp.document === null || - tp.importScripts === null) { - return "universal"; - } - } - return false; - }); - F(output, "workerChunkLoading", () => { - if (tp) { - switch (output.chunkFormat) { - case "array-push": - if (tp.importScriptsInWorker) - return "import-scripts"; - break; - case "commonjs": - if (tp.require) - return "require"; - if (tp.nodeBuiltins) - return "async-node"; - break; - case "module": - if (tp.dynamicImportInWorker) - return "import"; - break; - } - if (tp.require === null || - tp.nodeBuiltins === null || - tp.importScriptsInWorker === null) { - return "universal"; - } - } - return false; - }); - F(output, "wasmLoading", () => { - if (tp) { - if (tp.fetchWasm) - return "fetch"; - if (tp.nodeBuiltins) - return output.module ? "async-node-module" : "async-node"; - if (tp.nodeBuiltins === null || tp.fetchWasm === null) { - return "universal"; - } - } - return false; - }); - F(output, "workerWasmLoading", () => output.wasmLoading); - F(output, "globalObject", () => { - if (tp) { - if (tp.global) - return "global"; - if (tp.globalThis) - return "globalThis"; - } - return "self"; - }); - D(output, "importFunctionName", "import"); - F(output, "clean", () => !!output.clean); - D(output, "crossOriginLoading", false); - D(output, "workerPublicPath", ""); - F(output, "sourceMapFilename", () => { - return "[file].map"; - }); - F(output, "scriptType", () => (output.module ? "module" : false)); - const { trustedTypes } = output; - if (trustedTypes) { - F(trustedTypes, "policyName", () => output.uniqueName.replace(/[^a-zA-Z0-9\-#=_/@.%]+/g, "_") || "webpack"); - } - const forEachEntry = (fn) => { - for (const name of Object.keys(entry)) { - fn(entry[name]); - } - }; - A(output, "enabledLibraryTypes", () => { - const enabledLibraryTypes = []; - if (output.library) { - enabledLibraryTypes.push(output.library.type); - } - forEachEntry(desc => { - if (desc.library) { - enabledLibraryTypes.push(desc.library.type); - } - }); - return enabledLibraryTypes; - }); - A(output, "enabledChunkLoadingTypes", () => { - const enabledChunkLoadingTypes = new Set(); - if (output.chunkLoading) { - enabledChunkLoadingTypes.add(output.chunkLoading); - } - if (output.workerChunkLoading) { - enabledChunkLoadingTypes.add(output.workerChunkLoading); - } - forEachEntry(desc => { - if (desc.chunkLoading) { - enabledChunkLoadingTypes.add(desc.chunkLoading); - } - }); - return Array.from(enabledChunkLoadingTypes); - }); - A(output, "enabledWasmLoadingTypes", () => { - const enabledWasmLoadingTypes = new Set(); - if (output.wasmLoading) { - enabledWasmLoadingTypes.add(output.wasmLoading); - } - if (output.workerWasmLoading) { - enabledWasmLoadingTypes.add(output.workerWasmLoading); - } - // forEachEntry(desc => { - // if (desc.wasmLoading) { - // enabledWasmLoadingTypes.add(desc.wasmLoading); - // } - // }); - return Array.from(enabledWasmLoadingTypes); - }); -}; -const applyExternalsPresetsDefaults = (externalsPresets, { targetProperties }) => { - D(externalsPresets, "web", targetProperties && targetProperties.web); - D(externalsPresets, "node", targetProperties && targetProperties.node); - D(externalsPresets, "electron", targetProperties && targetProperties.electron); - D(externalsPresets, "electronMain", targetProperties && - targetProperties.electron && - targetProperties.electronMain); - D(externalsPresets, "electronPreload", targetProperties && - targetProperties.electron && - targetProperties.electronPreload); - D(externalsPresets, "electronRenderer", targetProperties && - targetProperties.electron && - targetProperties.electronRenderer); -}; -const applyNodeDefaults = (node, { targetProperties }) => { - if (node === false) - return; - F(node, "global", () => { - if (targetProperties && targetProperties.global) - return false; - return "warn"; - }); - F(node, "__dirname", () => { - if (targetProperties && targetProperties.node) - return "eval-only"; - return "warn-mock"; - }); - F(node, "__filename", () => { - if (targetProperties && targetProperties.node) - return "eval-only"; - return "warn-mock"; - }); -}; -const applyOptimizationDefaults = (optimization, { production, development }) => { - D(optimization, "removeAvailableModules", true); - D(optimization, "removeEmptyChunks", true); - D(optimization, "mergeDuplicateChunks", true); - F(optimization, "moduleIds", () => { - if (production) - return "deterministic"; - return "named"; - }); - F(optimization, "chunkIds", () => "named"); - F(optimization, "sideEffects", () => (production ? true : "flag")); - D(optimization, "mangleExports", production); - D(optimization, "providedExports", true); - D(optimization, "usedExports", production); - D(optimization, "innerGraph", production); - D(optimization, "runtimeChunk", false); - D(optimization, "realContentHash", production); - D(optimization, "minimize", production); - A(optimization, "minimizer", () => [ - // TODO: enable this when drop support for builtins options - // new SwcJsMinimizerPlugin(), - // new SwcCssMinimizerPlugin() - ]); - F(optimization, "nodeEnv", () => { - if (production) - return "production"; - if (development) - return "development"; - return false; - }); - const { splitChunks } = optimization; - if (splitChunks) { - // A(splitChunks, "defaultSizeTypes", () => - // css ? ["javascript", "css", "unknown"] : ["javascript", "unknown"] - // ); - D(splitChunks, "hidePathInfo", production); - D(splitChunks, "chunks", "async"); - // D(splitChunks, "usedExports", optimization.usedExports === true); - D(splitChunks, "minChunks", 1); - F(splitChunks, "minSize", () => (production ? 20000 : 10000)); - // F(splitChunks, "minRemainingSize", () => (development ? 0 : undefined)); - // F(splitChunks, "enforceSizeThreshold", () => (production ? 50000 : 30000)); - F(splitChunks, "maxAsyncRequests", () => (production ? 30 : Infinity)); - F(splitChunks, "maxInitialRequests", () => (production ? 30 : Infinity)); - D(splitChunks, "automaticNameDelimiter", "-"); - const { cacheGroups } = splitChunks; - if (cacheGroups) { - F(cacheGroups, "default", () => ({ - idHint: "", - reuseExistingChunk: true, - minChunks: 2, - priority: -20 - })); - F(cacheGroups, "defaultVendors", () => ({ - idHint: "vendors", - reuseExistingChunk: true, - test: /[\\/]node_modules[\\/]/i, - priority: -10 - })); - } - } -}; -const getResolveLoaderDefaults = () => { - const resolveOptions = { - conditionNames: ["loader", "require", "node"], - exportsFields: ["exports"], - mainFields: ["loader", "main"], - extensions: [".js"], - mainFiles: ["index"] - }; - return resolveOptions; -}; -const getResolveDefaults = ({ targetProperties, mode }) => { - const conditions = ["webpack"]; - conditions.push(mode === "development" ? "development" : "production"); - if (targetProperties) { - if (targetProperties.webworker) - conditions.push("worker"); - if (targetProperties.node) - conditions.push("node"); - if (targetProperties.web) - conditions.push("browser"); - if (targetProperties.electron) - conditions.push("electron"); - if (targetProperties.nwjs) - conditions.push("nwjs"); - } - const jsExtensions = [".js", ".json", ".wasm", ".tsx", ".ts", ".jsx"]; - const tp = targetProperties; - const browserField = tp && tp.web && (!tp.node || (tp.electron && tp.electronRenderer)); - const cjsDeps = () => ({ - browserField, - mainFields: browserField ? ["browser", "module", "..."] : ["module", "..."], - conditionNames: ["require", "module", "..."], - extensions: [...jsExtensions] - }); - const esmDeps = () => ({ - browserField, - mainFields: browserField ? ["browser", "module", "..."] : ["module", "..."], - conditionNames: ["import", "module", "..."], - extensions: [...jsExtensions] - }); - const resolveOptions = { - modules: ["node_modules"], - conditionNames: conditions, - mainFiles: ["index"], - extensions: [], - browserField, - mainFields: ["main"].filter(Boolean), - exportsFields: ["exports"], - byDependency: { - wasm: esmDeps(), - esm: esmDeps(), - url: { - preferRelative: true - }, - worker: { - ...esmDeps(), - preferRelative: true - }, - commonjs: cjsDeps(), - // amd: cjsDeps(), - // for backward-compat: loadModule - // loader: cjsDeps(), - // for backward-compat: Custom Dependency and getResolve without dependencyType - unknown: cjsDeps() - } - }; - return resolveOptions; -}; -const D = (obj, prop, value) => { - if (obj[prop] === undefined) { - obj[prop] = value; - } -}; -const F = (obj, prop, factory) => { - if (obj[prop] === undefined) { - obj[prop] = factory(); - } -}; -const A = (obj, prop, factory) => { - const value = obj[prop]; - if (value === undefined) { - obj[prop] = factory(); - } - else if (Array.isArray(value)) { - let newArray = undefined; - for (let i = 0; i < value.length; i++) { - const item = value[i]; - if (item === "...") { - if (newArray === undefined) { - newArray = value.slice(0, i); - // @ts-expect-error - obj[prop] = newArray; - } - const items = factory(); - if (items !== undefined) { - for (const item of items) { - newArray.push(item); - } - } - } - else if (newArray !== undefined) { - newArray.push(item); - } - } - } -}; diff --git a/packages/bundles/override/rspack/normalization.js b/packages/bundles/override/rspack/normalization.js deleted file mode 100644 index 942bfc8684..0000000000 --- a/packages/bundles/override/rspack/normalization.js +++ /dev/null @@ -1,299 +0,0 @@ -"use strict"; -/** - * The following code is modified based on - * https://github.com/webpack/webpack/blob/4b4ca3b/lib/config/normalization.js - * - * MIT Licensed - * Author Tobias Koppers @sokra - * Copyright (c) JS Foundation and other contributors - * https://github.com/webpack/webpack/blob/main/LICENSE - */ -Object.defineProperty(exports, "__esModule", { value: true }); -exports.getNormalizedRspackOptions = void 0; -const util_1 = require("../util"); -const getNormalizedRspackOptions = (config) => { - return { - features: config.features, - ignoreWarnings: config.ignoreWarnings !== undefined - ? config.ignoreWarnings.map(ignore => { - if (typeof ignore === "function") { - return ignore; - } - else { - return (warning) => { - return ignore.test(warning.message); - }; - } - }) - : undefined, - name: config.name, - dependencies: config.dependencies, - context: config.context, - mode: config.mode, - entry: config.entry === undefined - ? { main: {} } - : getNormalizedEntryStatic(config.entry), - output: nestedConfig(config.output, output => { - var _a; - const { library } = output; - const libraryAsName = library; - const libraryBase = typeof library === "object" && - library && - !Array.isArray(library) && - "type" in library - ? library - : libraryAsName || output.libraryTarget - ? { - name: libraryAsName - } - : undefined; - // DEPRECATE: remove this in after version - { - const ext = "[ext]"; - const filenames = [ - "filename", - "chunkFilename", - "cssFilename", - "cssChunkFilename" - ]; - const checkFilename = (prop) => { - const oldFilename = output[prop]; - if (typeof oldFilename === "string" && oldFilename.endsWith(ext)) { - const newFilename = oldFilename.slice(0, -ext.length) + - (prop.includes("css") ? ".css" : ".js"); - (0, util_1.deprecatedWarn)(`Deprecated: output.${prop} ends with [ext] is now deprecated, please use ${newFilename} instead.`); - output[prop] = newFilename; - } - }; - filenames.forEach(checkFilename); - } - return { - path: output.path, - publicPath: output.publicPath, - filename: output.filename, - clean: output.clean, - chunkFormat: output.chunkFormat, - chunkLoading: output.chunkLoading, - chunkFilename: output.chunkFilename, - crossOriginLoading: output.crossOriginLoading, - cssFilename: output.cssFilename, - cssChunkFilename: output.cssChunkFilename, - hotUpdateMainFilename: output.hotUpdateMainFilename, - hotUpdateChunkFilename: output.hotUpdateChunkFilename, - hotUpdateGlobal: output.hotUpdateGlobal, - assetModuleFilename: output.assetModuleFilename, - wasmLoading: output.wasmLoading, - enabledChunkLoadingTypes: output.enabledChunkLoadingTypes - ? [...output.enabledChunkLoadingTypes] - : ["..."], - enabledWasmLoadingTypes: output.enabledWasmLoadingTypes - ? [...output.enabledWasmLoadingTypes] - : ["..."], - webassemblyModuleFilename: output.webassemblyModuleFilename, - uniqueName: output.uniqueName, - chunkLoadingGlobal: output.chunkLoadingGlobal, - enabledLibraryTypes: output.enabledLibraryTypes - ? [...output.enabledLibraryTypes] - : ["..."], - globalObject: output.globalObject, - importFunctionName: output.importFunctionName, - iife: output.iife, - module: output.module, - sourceMapFilename: output.sourceMapFilename, - library: libraryBase && { - type: output.libraryTarget !== undefined - ? output.libraryTarget - : libraryBase.type, - auxiliaryComment: output.auxiliaryComment !== undefined - ? output.auxiliaryComment - : libraryBase.auxiliaryComment, - amdContainer: output.amdContainer !== undefined - ? output.amdContainer - : libraryBase.amdContainer, - export: output.libraryExport !== undefined - ? output.libraryExport - : libraryBase.export, - name: libraryBase.name, - umdNamedDefine: output.umdNamedDefine !== undefined - ? output.umdNamedDefine - : libraryBase.umdNamedDefine - }, - strictModuleErrorHandling: (_a = output.strictModuleErrorHandling) !== null && _a !== void 0 ? _a : output.strictModuleExceptionHandling, - trustedTypes: optionalNestedConfig(output.trustedTypes, trustedTypes => { - if (trustedTypes === true) - return {}; - if (typeof trustedTypes === "string") - return { policyName: trustedTypes }; - return { ...trustedTypes }; - }), - hashDigest: output.hashDigest, - hashDigestLength: output.hashDigestLength, - hashFunction: output.hashFunction, - hashSalt: output.hashSalt, - asyncChunks: output.asyncChunks, - workerChunkLoading: output.workerChunkLoading, - workerWasmLoading: output.workerWasmLoading, - workerPublicPath: output.workerPublicPath, - scriptType: output.scriptType - }; - }), - resolve: nestedConfig(config.resolve, resolve => ({ - ...resolve - })), - resolveLoader: nestedConfig(config.resolveLoader, resolve => ({ - ...resolve - })), - module: nestedConfig(config.module, module => ({ - parser: keyedNestedConfig(module.parser, cloneObject, {}), - generator: keyedNestedConfig(module.generator, cloneObject, {}), - defaultRules: optionalNestedArray(module.defaultRules, r => [...r]), - rules: nestedArray(module.rules, r => [...r]) - })), - target: config.target, - externals: config.externals, - externalsType: config.externalsType, - externalsPresets: cloneObject(config.externalsPresets), - infrastructureLogging: cloneObject(config.infrastructureLogging), - devtool: config.devtool, - node: nestedConfig(config.node, node => node && { - ...node - }), - snapshot: nestedConfig(config.snapshot, snapshot => ({ - resolve: optionalNestedConfig(snapshot.resolve, resolve => ({ - timestamp: resolve.timestamp, - hash: resolve.hash - })), - module: optionalNestedConfig(snapshot.module, module => ({ - timestamp: module.timestamp, - hash: module.hash - })) - })), - cache: optionalNestedConfig(config.cache, cache => cache), - stats: nestedConfig(config.stats, stats => { - if (stats === false) { - return { - preset: "none" - }; - } - if (stats === true) { - return { - preset: "normal" - }; - } - if (typeof stats === "string") { - return { - preset: stats - }; - } - return { - ...stats - }; - }), - optimization: nestedConfig(config.optimization, optimization => { - return { - ...optimization, - runtimeChunk: getNormalizedOptimizationRuntimeChunk(optimization.runtimeChunk), - splitChunks: nestedConfig(optimization.splitChunks, splitChunks => splitChunks && { - ...splitChunks, - cacheGroups: cloneObject(splitChunks.cacheGroups) - }) - }; - }), - plugins: nestedArray(config.plugins, p => [...p]), - experiments: nestedConfig(config.experiments, experiments => ({ - ...experiments, - incrementalRebuild: optionalNestedConfig(experiments.incrementalRebuild, options => (options === true ? {} : options)) - })), - watch: config.watch, - watchOptions: cloneObject(config.watchOptions), - devServer: config.devServer, - profile: config.profile, - builtins: nestedConfig(config.builtins, builtins => ({ - ...builtins - })) - }; -}; -exports.getNormalizedRspackOptions = getNormalizedRspackOptions; -const getNormalizedEntryStatic = (entry) => { - if (typeof entry === "string") { - return { - main: { - import: [entry] - } - }; - } - if (Array.isArray(entry)) { - return { - main: { - import: entry - } - }; - } - const result = {}; - for (const key of Object.keys(entry)) { - const value = entry[key]; - if (typeof value === "string") { - result[key] = { - import: [value] - }; - } - else if (Array.isArray(value)) { - result[key] = { - import: value - }; - } - else { - result[key] = { - import: Array.isArray(value.import) ? value.import : [value.import], - runtime: value.runtime, - publicPath: value.publicPath, - baseUri: value.baseUri, - chunkLoading: value.chunkLoading, - asyncChunks: value.asyncChunks, - filename: value.filename, - library: value.library - }; - } - } - return result; -}; -const getNormalizedOptimizationRuntimeChunk = (runtimeChunk) => { - if (runtimeChunk === undefined) - return undefined; - if (runtimeChunk === false) - return false; - if (runtimeChunk === "single") { - return { - name: () => "runtime" - }; - } - if (runtimeChunk === true || runtimeChunk === "multiple") { - return { - name: (entrypoint) => `runtime~${entrypoint.name}` - }; - } - const { name } = runtimeChunk; - const opts = { - name: typeof name === "function" ? name : () => name - }; - return opts; -}; -const nestedConfig = (value, fn) => value === undefined ? fn({}) : fn(value); -const optionalNestedConfig = (value, fn) => (value === undefined ? undefined : fn(value)); -const nestedArray = (value, fn) => Array.isArray(value) ? fn(value) : fn([]); -const optionalNestedArray = (value, fn) => (Array.isArray(value) ? fn(value) : undefined); -const cloneObject = (value) => ({ ...value }); -const keyedNestedConfig = (value, fn, customKeys) => { - const result = value === undefined - ? {} - : Object.keys(value).reduce((obj, key) => ((obj[key] = (customKeys && key in customKeys ? customKeys[key] : fn)(value[key])), - obj), {}); - if (customKeys) { - for (const key of Object.keys(customKeys)) { - if (!(key in result)) { - result[key] = customKeys[key]({}); - } - } - } - return result; -}; diff --git a/packages/bundles/override/rspack/zod.js b/packages/bundles/override/rspack/zod.js deleted file mode 100644 index 0364b4c919..0000000000 --- a/packages/bundles/override/rspack/zod.js +++ /dev/null @@ -1,738 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.rspackOptions = exports.externalsType = void 0; -const zod_1 = require("zod"); -const util_1 = require("../util"); -const Module_1 = require("../Module"); -//#region Name -const name = zod_1.z.string(); -//#endregion -//#region Dependencies -const dependencies = zod_1.z.array(name); -//#endregion -//#region Context -const context = zod_1.z.string(); -//#endregion -//#region Mode -const mode = zod_1.z.enum(["development", "production", "none"]); -//#endregion -//#region Entry -const rawPublicPath = zod_1.z.string(); -const publicPath = zod_1.z.literal("auto").or(rawPublicPath); -const baseUri = zod_1.z.string(); -const chunkLoadingType = zod_1.z - .enum(["jsonp", "import-scripts", "require", "async-node", "import"]) - .or(zod_1.z.string()); -const chunkLoading = zod_1.z.literal(false).or(chunkLoadingType); -const asyncChunks = zod_1.z.boolean(); -const wasmLoadingType = zod_1.z - .enum(["fetch-streaming", "fetch", "async-node"]) - .or(zod_1.z.string()); -const wasmLoading = zod_1.z.literal(false).or(wasmLoadingType); -const scriptType = zod_1.z.enum(["text/javascript", "module"]).or(zod_1.z.literal(false)); -const libraryCustomUmdObject = zod_1.z.strictObject({ - amd: zod_1.z.string().optional(), - commonjs: zod_1.z.string().optional(), - root: zod_1.z.string().or(zod_1.z.array(zod_1.z.string())).optional() -}); -const libraryName = zod_1.z - .string() - .or(zod_1.z.array(zod_1.z.string())) - .or(libraryCustomUmdObject); -const libraryCustomUmdCommentObject = zod_1.z.strictObject({ - amd: zod_1.z.string().optional(), - commonjs: zod_1.z.string().optional(), - commonjs2: zod_1.z.string().optional(), - root: zod_1.z.string().optional() -}); -const amdContainer = zod_1.z.string(); -const auxiliaryComment = zod_1.z.string().or(libraryCustomUmdCommentObject); -const libraryExport = zod_1.z.string().or(zod_1.z.array(zod_1.z.string())); -const libraryType = zod_1.z - .enum([ - "var", - "module", - "assign", - "assign-properties", - "this", - "window", - "self", - "global", - "commonjs", - "commonjs2", - "commonjs-module", - "commonjs-static", - "amd", - "amd-require", - "umd", - "umd2", - "jsonp", - "system" -]) - .or(zod_1.z.string()); -const umdNamedDefine = zod_1.z.boolean(); -const libraryOptions = zod_1.z.strictObject({ - amdContainer: amdContainer.optional(), - auxiliaryComment: auxiliaryComment.optional(), - export: libraryExport.optional(), - name: libraryName.optional(), - type: libraryType, - umdNamedDefine: umdNamedDefine.optional() -}); -const library = libraryName.or(libraryOptions).optional(); -const filenameTemplate = zod_1.z.string(); -const filename = filenameTemplate; -const entryFilename = filenameTemplate; -const entryRuntime = zod_1.z.literal(false).or(zod_1.z.string()); -const entryItem = zod_1.z.string().or(zod_1.z.array(zod_1.z.string())); -const entryDescription = zod_1.z.strictObject({ - import: entryItem, - runtime: entryRuntime.optional(), - publicPath: publicPath.optional(), - baseUri: baseUri.optional(), - chunkLoading: chunkLoading.optional(), - asyncChunks: asyncChunks.optional(), - wasmLoading: wasmLoading.optional(), - filename: entryFilename.optional(), - library: libraryOptions.optional() -}); -const entryUnnamed = entryItem; -const entryObject = zod_1.z.record(entryItem.or(entryDescription)); -const entryStatic = entryObject.or(entryUnnamed); -const entry = entryStatic; -//#endregion -//#region Output -const path = zod_1.z.string(); -const assetModuleFilename = zod_1.z.string(); -const webassemblyModuleFilename = zod_1.z.string(); -const chunkFilename = filenameTemplate; -const crossOriginLoading = zod_1.z - .literal(false) - .or(zod_1.z.enum(["anonymous", "use-credentials"])); -const cssFilename = filenameTemplate; -const cssChunkFilename = filenameTemplate; -const hotUpdateChunkFilename = filenameTemplate; -const hotUpdateMainFilename = filenameTemplate; -const hotUpdateGlobal = zod_1.z.string(); -const uniqueName = zod_1.z.string(); -const chunkLoadingGlobal = zod_1.z.string(); -const enabledLibraryTypes = zod_1.z.array(libraryType); -const clean = zod_1.z.boolean(); -const outputModule = zod_1.z.boolean(); -const strictModuleExceptionHandling = zod_1.z.boolean(); -const strictModuleErrorHandling = zod_1.z.boolean(); -const globalObject = zod_1.z.string(); -const enabledWasmLoadingTypes = zod_1.z.array(wasmLoadingType); -const importFunctionName = zod_1.z.string(); -const iife = zod_1.z.boolean(); -const enabledChunkLoadingTypes = zod_1.z.array(chunkLoadingType); -const chunkFormat = zod_1.z.literal(false).or(zod_1.z.string()); -const workerPublicPath = zod_1.z.string(); -const trustedTypes = zod_1.z.strictObject({ - policyName: zod_1.z.string().optional() -}); -const hashDigest = zod_1.z.string(); -const hashDigestLength = zod_1.z.number(); -const hashFunction = zod_1.z.string(); -const hashSalt = zod_1.z.string(); -const sourceMapFilename = zod_1.z.string(); -const output = zod_1.z.strictObject({ - path: path.optional(), - clean: clean.optional(), - publicPath: publicPath.optional(), - filename: filename.optional(), - chunkFilename: chunkFilename.optional(), - crossOriginLoading: crossOriginLoading.optional(), - cssFilename: cssFilename.optional(), - cssChunkFilename: cssChunkFilename.optional(), - hotUpdateMainFilename: hotUpdateMainFilename.optional(), - hotUpdateChunkFilename: hotUpdateChunkFilename.optional(), - hotUpdateGlobal: hotUpdateGlobal.optional(), - assetModuleFilename: assetModuleFilename.optional(), - uniqueName: uniqueName.optional(), - chunkLoadingGlobal: chunkLoadingGlobal.optional(), - enabledLibraryTypes: enabledLibraryTypes.optional(), - library: library.optional(), - libraryExport: libraryExport.optional(), - libraryTarget: libraryType.optional(), - umdNamedDefine: umdNamedDefine.optional(), - amdContainer: amdContainer.optional(), - auxiliaryComment: auxiliaryComment.optional(), - module: outputModule.optional(), - strictModuleExceptionHandling: strictModuleExceptionHandling.optional(), - strictModuleErrorHandling: strictModuleErrorHandling.optional(), - globalObject: globalObject.optional(), - importFunctionName: importFunctionName.optional(), - iife: iife.optional(), - wasmLoading: wasmLoading.optional(), - enabledWasmLoadingTypes: enabledWasmLoadingTypes.optional(), - webassemblyModuleFilename: webassemblyModuleFilename.optional(), - chunkFormat: chunkFormat.optional(), - chunkLoading: chunkLoading.optional(), - enabledChunkLoadingTypes: enabledChunkLoadingTypes.optional(), - trustedTypes: zod_1.z.literal(true).or(zod_1.z.string()).or(trustedTypes).optional(), - sourceMapFilename: sourceMapFilename.optional(), - hashDigest: hashDigest.optional(), - hashDigestLength: hashDigestLength.optional(), - hashFunction: hashFunction.optional(), - hashSalt: hashSalt.optional(), - asyncChunks: asyncChunks.optional(), - workerChunkLoading: chunkLoading.optional(), - workerWasmLoading: wasmLoading.optional(), - workerPublicPath: workerPublicPath.optional(), - scriptType: scriptType.optional() -}); -//#endregion -//#region Resolve -const resolveAlias = zod_1.z.record(zod_1.z - .literal(false) - .or(zod_1.z.string()) - .or(zod_1.z.array(zod_1.z.string().or(zod_1.z.literal(false))))); -const resolveTsconfig = zod_1.z.strictObject({ - configFile: zod_1.z.string(), - references: zod_1.z.array(zod_1.z.string()).or(zod_1.z.literal("auto")).optional() -}); -const baseResolveOptions = zod_1.z.strictObject({ - alias: resolveAlias.optional(), - /** - * This is `aliasField: ["browser"]` in webpack, because no one - * uses aliasField other than "browser". ---@bvanjoi - */ - browserField: zod_1.z.boolean().optional(), - conditionNames: zod_1.z.array(zod_1.z.string()).optional(), - extensions: zod_1.z.array(zod_1.z.string()).optional(), - fallback: resolveAlias.optional(), - mainFields: zod_1.z.array(zod_1.z.string()).optional(), - mainFiles: zod_1.z.array(zod_1.z.string()).optional(), - modules: zod_1.z.array(zod_1.z.string()).optional(), - preferRelative: zod_1.z.boolean().optional(), - tsConfigPath: zod_1.z.string().optional(), - tsConfig: resolveTsconfig.optional(), - fullySpecified: zod_1.z.boolean().optional(), - exportsFields: zod_1.z.array(zod_1.z.string()).optional(), - extensionAlias: zod_1.z.record(zod_1.z.string().or(zod_1.z.array(zod_1.z.string()))).optional() -}); -const resolveOptions = baseResolveOptions.extend({ - byDependency: zod_1.z.lazy(() => zod_1.z.record(resolveOptions)).optional() -}); -const resolve = resolveOptions; -//#endregion -//#region Module -const baseRuleSetCondition = zod_1.z - .instanceof(RegExp) - .or(zod_1.z.string()) - .or(zod_1.z.function().args(zod_1.z.string()).returns(zod_1.z.boolean())); -const ruleSetCondition = baseRuleSetCondition - .or(zod_1.z.lazy(() => ruleSetConditions)) - .or(zod_1.z.lazy(() => ruleSetLogicalConditions)); -const ruleSetConditions = zod_1.z.lazy(() => zod_1.z.array(ruleSetCondition)); -const ruleSetLogicalConditions = zod_1.z.strictObject({ - and: ruleSetConditions.optional(), - or: ruleSetConditions.optional(), - not: ruleSetConditions.optional() -}); -const ruleSetLoader = zod_1.z.string(); -const ruleSetLoaderOptions = zod_1.z.string().or(zod_1.z.record(zod_1.z.any())); -const ruleSetLoaderWithOptions = zod_1.z.strictObject({ - ident: zod_1.z.string().optional(), - loader: ruleSetLoader, - options: ruleSetLoaderOptions.optional() -}); -const ruleSetUseItem = ruleSetLoader.or(ruleSetLoaderWithOptions); -const ruleSetUse = ruleSetUseItem - .or(ruleSetUseItem.array()) - .or(zod_1.z.function().args(zod_1.z.custom()).returns(ruleSetUseItem.array())); -const baseRuleSetRule = zod_1.z.strictObject({ - test: ruleSetCondition.optional(), - exclude: ruleSetCondition.optional(), - include: ruleSetCondition.optional(), - issuer: ruleSetCondition.optional(), - dependency: ruleSetCondition.optional(), - resource: ruleSetCondition.optional(), - resourceFragment: ruleSetCondition.optional(), - resourceQuery: ruleSetCondition.optional(), - scheme: ruleSetCondition.optional(), - mimetype: ruleSetCondition.optional(), - descriptionData: zod_1.z.record(ruleSetCondition).optional(), - type: zod_1.z.string().optional(), - loader: ruleSetLoader.optional(), - options: ruleSetLoaderOptions.optional(), - use: ruleSetUse.optional(), - parser: zod_1.z.record(zod_1.z.any()).optional(), - generator: zod_1.z.record(zod_1.z.any()).optional(), - resolve: resolveOptions.optional(), - sideEffects: zod_1.z.boolean().optional(), - enforce: zod_1.z.literal("pre").or(zod_1.z.literal("post")).optional() -}); -const ruleSetRule = baseRuleSetRule.extend({ - oneOf: zod_1.z.lazy(() => ruleSetRule.array()).optional(), - rules: zod_1.z.lazy(() => ruleSetRule.array()).optional() -}); -const ruleSetRules = zod_1.z.array(zod_1.z.literal("...").or(ruleSetRule)); -const assetParserDataUrlOptions = zod_1.z.strictObject({ - maxSize: zod_1.z.number().optional() -}); -const assetParserDataUrl = assetParserDataUrlOptions; -const assetParserOptions = zod_1.z.strictObject({ - dataUrlCondition: assetParserDataUrl.optional() -}); -//TODO: "weak", "lazy-once" -const dynamicImportMode = zod_1.z.enum(["eager", "lazy"]); -const javascriptParserOptions = zod_1.z.strictObject({ - dynamicImportMode: dynamicImportMode.optional() -}); -const parserOptionsByModuleTypeKnown = zod_1.z.strictObject({ - asset: assetParserOptions.optional(), - javascript: javascriptParserOptions.optional() -}); -const parserOptionsByModuleTypeUnknown = zod_1.z.record(zod_1.z.record(zod_1.z.any())); -const parserOptionsByModuleType = parserOptionsByModuleTypeKnown.or(parserOptionsByModuleTypeUnknown); -const assetGeneratorDataUrlOptions = zod_1.z.strictObject({ - encoding: zod_1.z.literal(false).or(zod_1.z.literal("base64")).optional(), - mimetype: zod_1.z.string().optional() -}); -const assetGeneratorDataUrl = assetGeneratorDataUrlOptions; -const assetInlineGeneratorOptions = zod_1.z.strictObject({ - dataUrl: assetGeneratorDataUrl.optional() -}); -const assetResourceGeneratorOptions = zod_1.z.strictObject({ - filename: filenameTemplate.optional(), - publicPath: publicPath.optional() -}); -const assetGeneratorOptions = assetInlineGeneratorOptions.merge(assetResourceGeneratorOptions); -const generatorOptionsByModuleTypeKnown = zod_1.z.strictObject({ - asset: assetGeneratorOptions.optional(), - "asset/inline": assetInlineGeneratorOptions.optional(), - "asset/resource": assetResourceGeneratorOptions.optional() -}); -const generatorOptionsByModuleTypeUnknown = zod_1.z.record(zod_1.z.record(zod_1.z.any())); -const generatorOptionsByModuleType = generatorOptionsByModuleTypeKnown.or(generatorOptionsByModuleTypeUnknown); -const moduleOptions = zod_1.z.strictObject({ - defaultRules: ruleSetRules.optional(), - rules: ruleSetRules.optional(), - parser: parserOptionsByModuleType.optional(), - generator: generatorOptionsByModuleType.optional() -}); -//#endregion -//#region Target -const allowTarget = zod_1.z - .enum([ - "web", - "webworker", - "es3", - "es5", - "es2015", - "es2016", - "es2017", - "es2018", - "es2019", - "es2020", - "es2021", - "es2022", - "browserslist" -]) - .or(zod_1.z.literal("node")) - .or(zod_1.z.literal("async-node")) - .or(zod_1.z.custom(value => typeof value === "string" && /^node\d+$/.test(value))) - .or(zod_1.z.custom(value => typeof value === "string" && /^async-node\d+$/.test(value))) - .or(zod_1.z.custom(value => typeof value === "string" && /^node\d+\.\d+$/.test(value))) - .or(zod_1.z.custom(value => typeof value === "string" && /^async-node\d+\.\d+$/.test(value))) - .or(zod_1.z.literal("electron-main")) - .or(zod_1.z.custom(value => typeof value === "string" && /^electron\d+-main$/.test(value))) - .or(zod_1.z.custom(value => typeof value === "string" && /^electron\d+\.\d+-main$/.test(value))) - .or(zod_1.z.literal("electron-renderer")) - .or(zod_1.z.custom(value => typeof value === "string" && /^electron\d+-renderer$/.test(value))) - .or(zod_1.z.custom(value => typeof value === "string" && /^electron\d+\.\d+-renderer$/.test(value))) - .or(zod_1.z.literal("electron-preload")) - .or(zod_1.z.custom(value => typeof value === "string" && /^electron\d+-preload$/.test(value))) - .or(zod_1.z.custom(value => typeof value === "string" && /^electron\d+\.\d+-preload$/.test(value))); -const target = zod_1.z.literal(false).or(allowTarget).or(allowTarget.array()); -//#endregion -//#region ExternalsType -exports.externalsType = zod_1.z.enum([ - "var", - "module", - "assign", - "this", - "window", - "self", - "global", - "commonjs", - "commonjs2", - "commonjs-module", - "commonjs-static", - "amd", - "amd-require", - "umd", - "umd2", - "jsonp", - "system", - "promise", - "import", - "script", - "node-commonjs" -]); -//#endregion -//#region Externals -const externalItemValue = zod_1.z - .string() - .or(zod_1.z.boolean()) - .or(zod_1.z.string().array().min(1)) - .or(zod_1.z.record(zod_1.z.string().or(zod_1.z.string().array()))); -const externalItemObjectUnknown = zod_1.z.record(externalItemValue); -const externalItemFunctionData = zod_1.z.strictObject({ - context: zod_1.z.string().optional(), - dependencyType: zod_1.z.string().optional(), - request: zod_1.z.string().optional() -}); -const externalItem = zod_1.z - .string() - .or(zod_1.z.instanceof(RegExp)) - .or(externalItemObjectUnknown) - .or(zod_1.z - .function() - .args(externalItemFunctionData, zod_1.z - .function() - .args(zod_1.z.instanceof(Error).optional(), externalItemValue.optional(), exports.externalsType.optional()) - .returns(zod_1.z.void()))) - .or(zod_1.z - .function() - .args(externalItemFunctionData) - .returns(zod_1.z.promise(externalItemValue))); -const externals = externalItem.array().or(externalItem); -//#endregion -//#region ExternalsPresets -const externalsPresets = zod_1.z.strictObject({ - node: zod_1.z.boolean().optional(), - web: zod_1.z.boolean().optional(), - webAsync: zod_1.z.boolean().optional(), - electron: zod_1.z.boolean().optional(), - electronMain: zod_1.z.boolean().optional(), - electronPreload: zod_1.z.boolean().optional(), - electronRenderer: zod_1.z.boolean().optional() -}); -//#endregion -//#region InfrastructureLogging -const filterItemTypes = zod_1.z - .instanceof(RegExp) - .or(zod_1.z.string()) - .or(zod_1.z.function().args(zod_1.z.string()).returns(zod_1.z.boolean())); -const filterTypes = filterItemTypes.array().or(filterItemTypes); -const infrastructureLogging = zod_1.z.strictObject({ - appendOnly: zod_1.z.boolean().optional(), - colors: zod_1.z.boolean().optional(), - console: zod_1.z.custom().optional(), - debug: zod_1.z.boolean().or(filterTypes).optional(), - level: zod_1.z.enum(["none", "error", "warn", "info", "log", "verbose"]).optional(), - stream: zod_1.z.custom().optional() -}); -//#endregion -//#region DevTool -const devTool = zod_1.z - .literal(false) - .or(zod_1.z.enum([ - "cheap-source-map", - "cheap-module-source-map", - "source-map", - "inline-cheap-source-map", - "inline-cheap-module-source-map", - "inline-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" -])); -//#endregion -//#region Node -const nodeOptions = zod_1.z.strictObject({ - __dirname: zod_1.z - .boolean() - .or(zod_1.z.enum(["warn-mock", "mock", "eval-only"])) - .optional(), - __filename: zod_1.z - .boolean() - .or(zod_1.z.enum(["warn-mock", "mock", "eval-only"])) - .optional(), - global: zod_1.z.boolean().or(zod_1.z.literal("warn")).optional() -}); -const node = zod_1.z.literal(false).or(nodeOptions); -//#endregion -//#region Snapshot -const snapshotOptions = zod_1.z.strictObject({ - module: zod_1.z - .strictObject({ - hash: zod_1.z.boolean().optional(), - timestamp: zod_1.z.boolean().optional() - }) - .optional(), - resolve: zod_1.z - .strictObject({ - hash: zod_1.z.boolean().optional(), - timestamp: zod_1.z.boolean().optional() - }) - .optional() -}); -//#endregion -//#region Cache -const cacheOptions = zod_1.z.boolean(); -//#endregion -//#region Stats -const statsOptions = zod_1.z.strictObject({ - all: zod_1.z.boolean().optional(), - preset: zod_1.z - .enum(["normal", "none", "verbose", "errors-only", "errors-warnings"]) - .optional(), - assets: zod_1.z.boolean().optional(), - chunks: zod_1.z.boolean().optional(), - modules: zod_1.z.boolean().optional(), - entrypoints: zod_1.z.boolean().optional(), - chunkGroups: zod_1.z.boolean().optional(), - warnings: zod_1.z.boolean().optional(), - warningsCount: zod_1.z.boolean().optional(), - errors: zod_1.z.boolean().optional(), - errorsCount: zod_1.z.boolean().optional(), - colors: zod_1.z.boolean().optional(), - hash: zod_1.z.boolean().optional(), - version: zod_1.z.boolean().optional(), - reasons: zod_1.z.boolean().optional(), - publicPath: zod_1.z.boolean().optional(), - outputPath: zod_1.z.boolean().optional(), - chunkModules: zod_1.z.boolean().optional(), - chunkRelations: zod_1.z.boolean().optional(), - ids: zod_1.z.boolean().optional(), - timings: zod_1.z.boolean().optional(), - builtAt: zod_1.z.boolean().optional(), - moduleAssets: zod_1.z.boolean().optional(), - modulesSpace: zod_1.z.number().optional(), - nestedModules: zod_1.z.boolean().optional(), - source: zod_1.z.boolean().optional(), - logging: zod_1.z - .enum(["none", "error", "warn", "info", "log", "verbose"]) - .or(zod_1.z.boolean()) - .optional(), - loggingDebug: zod_1.z.boolean().or(filterTypes).optional(), - loggingTrace: zod_1.z.boolean().optional(), - runtimeModules: zod_1.z.boolean().optional() -}); -const statsValue = zod_1.z - .enum(["none", "errors-only", "errors-warnings", "normal", "verbose"]) - .or(zod_1.z.boolean()) - .or(statsOptions); -const plugin = zod_1.z.union([ - zod_1.z.custom(), - zod_1.z.custom() -]); -const plugins = plugin.array(); -//#endregion -//#region Optimization -const optimizationRuntimeChunk = zod_1.z - .enum(["single", "multiple"]) - .or(zod_1.z.boolean()) - .or(zod_1.z.strictObject({ - name: zod_1.z - .string() - .or(zod_1.z.function().returns(zod_1.z.string().or(zod_1.z.undefined()))) - .optional() -})); -const optimizationSplitChunksNameFunction = zod_1.z.function().args(zod_1.z.instanceof(Module_1.Module).optional() -// FIXME: z.array(z.instanceof(Chunk)).optional(), z.string() -// FIXME: Chunk[], cacheChunkKey -); -const optimizationSplitChunksName = zod_1.z - .string() - .or(zod_1.z.literal(false)) - .or(optimizationSplitChunksNameFunction); -const optimizationSplitChunksChunks = zod_1.z - .enum(["initial", "async", "all"]) - .or(zod_1.z.instanceof(RegExp)); -const optimizationSplitChunksSizes = zod_1.z.number(); -const sharedOptimizationSplitChunksCacheGroup = { - chunks: optimizationSplitChunksChunks.optional(), - minChunks: zod_1.z.number().optional(), - name: optimizationSplitChunksName.optional(), - minSize: optimizationSplitChunksSizes.optional(), - maxSize: optimizationSplitChunksSizes.optional(), - maxAsyncSize: optimizationSplitChunksSizes.optional(), - maxInitialSize: optimizationSplitChunksSizes.optional(), - automaticNameDelimiter: zod_1.z.string().optional() -}; -const optimizationSplitChunksCacheGroup = zod_1.z.strictObject({ - test: zod_1.z - .string() - .or(zod_1.z.instanceof(RegExp)) - .or(zod_1.z - .function() - .args(zod_1.z.instanceof(Module_1.Module) /** FIXME: lack of CacheGroupContext */)) - .optional(), - priority: zod_1.z.number().optional(), - enforce: zod_1.z.boolean().optional(), - filename: zod_1.z.string().optional(), - reuseExistingChunk: zod_1.z.boolean().optional(), - type: zod_1.z.string().or(zod_1.z.instanceof(RegExp)).optional(), - idHint: zod_1.z.string().optional(), - ...sharedOptimizationSplitChunksCacheGroup -}); -const optimizationSplitChunksOptions = zod_1.z.strictObject({ - cacheGroups: zod_1.z - .record(zod_1.z.literal(false).or(optimizationSplitChunksCacheGroup)) - .optional(), - maxAsyncRequests: zod_1.z.number().optional(), - maxInitialRequests: zod_1.z.number().optional(), - fallbackCacheGroup: zod_1.z - .strictObject({ - chunks: optimizationSplitChunksChunks.optional(), - minSize: zod_1.z.number().optional(), - maxSize: zod_1.z.number().optional(), - maxAsyncSize: zod_1.z.number().optional(), - maxInitialSize: zod_1.z.number().optional(), - automaticNameDelimiter: zod_1.z.string().optional() - }) - .optional(), - hidePathInfo: zod_1.z.boolean().optional(), - ...sharedOptimizationSplitChunksCacheGroup -}); -const optimization = zod_1.z.strictObject({ - moduleIds: zod_1.z.enum(["named", "deterministic"]).optional(), - chunkIds: zod_1.z.enum(["named", "deterministic"]).optional(), - minimize: zod_1.z.boolean().optional(), - minimizer: zod_1.z.literal("...").or(plugin).array().optional(), - mergeDuplicateChunks: zod_1.z.boolean().optional(), - splitChunks: zod_1.z.literal(false).or(optimizationSplitChunksOptions).optional(), - runtimeChunk: optimizationRuntimeChunk.optional(), - removeAvailableModules: zod_1.z.boolean().optional(), - removeEmptyChunks: zod_1.z.boolean().optional(), - realContentHash: zod_1.z.boolean().optional(), - sideEffects: zod_1.z.enum(["flag"]).or(zod_1.z.boolean()).optional(), - providedExports: zod_1.z.boolean().optional(), - innerGraph: zod_1.z.boolean().optional(), - usedExports: zod_1.z.enum(["global"]).or(zod_1.z.boolean()).optional(), - mangleExports: zod_1.z.enum(["size", "deterministic"]).or(zod_1.z.boolean()).optional(), - nodeEnv: zod_1.z.union([zod_1.z.string(), zod_1.z.literal(false)]).optional() -}); -//#endregion -//#region Experiments -const incrementalRebuildOptions = zod_1.z.strictObject({ - make: zod_1.z.boolean().optional(), - emitAsset: zod_1.z.boolean().optional() -}); -const rspackFutureOptions = zod_1.z.strictObject({ - newResolver: zod_1.z - .boolean() - .optional() - .refine(val => { - if (val === false) { - (0, util_1.deprecatedWarn)(`'experiments.rspackFuture.newResolver = ${JSON.stringify(val)}' has been deprecated, and will be drop support in 0.5.0, please switch 'experiments.rspackFuture.newResolver = true' to use new resolver, See the discussion ${(0, util_1.termlink)("here", "https://github.com/web-infra-dev/rspack/issues/4825")}`); - } - return true; - }), - newTreeshaking: zod_1.z.boolean().optional(), - disableTransformByDefault: zod_1.z.boolean().optional() -}); -const experiments = zod_1.z.strictObject({ - lazyCompilation: zod_1.z.boolean().optional(), - incrementalRebuild: zod_1.z - .boolean() - .or(incrementalRebuildOptions) - .optional() - .refine(val => { - if (val !== undefined) { - (0, util_1.deprecatedWarn)(`'experiments.incrementalRebuild' has been deprecated, and will be drop support in 0.5.0. See the discussion ${(0, util_1.termlink)("here", "https://github.com/web-infra-dev/rspack/issues/4708")}`); - } - return true; - }), - asyncWebAssembly: zod_1.z.boolean().optional(), - outputModule: zod_1.z.boolean().optional(), - topLevelAwait: zod_1.z.boolean().optional(), - newSplitChunks: zod_1.z - .boolean() - .optional() - .refine(val => { - if (val === false) { - (0, util_1.deprecatedWarn)(`'experiments.newSplitChunks = ${JSON.stringify(val)}' has been deprecated, please switch to 'experiments.newSplitChunks = true' to use webpack's behavior. - See the discussion ${(0, util_1.termlink)("here", "https://github.com/web-infra-dev/rspack/discussions/4168")}`); - } - return true; - }), - css: zod_1.z.boolean().optional(), - futureDefaults: zod_1.z.boolean().optional(), - rspackFuture: rspackFutureOptions.optional() -}); -//#endregion -//#region Watch -const watch = zod_1.z.boolean(); -//#endregion -//#region WatchOptions -const watchOptions = zod_1.z.strictObject({ - aggregateTimeout: zod_1.z.number().optional(), - followSymlinks: zod_1.z.boolean().optional(), - ignored: zod_1.z - .string() - .array() - .or(zod_1.z.instanceof(RegExp)) - .or(zod_1.z.string()) - .optional(), - poll: zod_1.z.number().or(zod_1.z.boolean()).optional(), - stdin: zod_1.z.boolean().optional() -}); -const devServer = zod_1.z.custom(); -//#endregion -//#region IgnoreWarnings -const ignoreWarnings = zod_1.z - .instanceof(RegExp) - .or(zod_1.z - .function() - .args(zod_1.z.instanceof(Error), zod_1.z.custom()) - .returns(zod_1.z.boolean())) - .array(); -//#endregion -//#region Profile -const profile = zod_1.z.boolean(); -//#endregion -//#region Builtins (deprecated) -const builtins = zod_1.z.custom(); -const features = zod_1.z.custom(); -// #endregion -exports.rspackOptions = zod_1.z.strictObject({ - name: name.optional(), - dependencies: dependencies.optional(), - entry: entry.optional(), - output: output.optional(), - target: target.optional(), - mode: mode.optional(), - experiments: experiments.optional(), - externals: externals.optional(), - externalsType: exports.externalsType.optional(), - externalsPresets: externalsPresets.optional(), - infrastructureLogging: infrastructureLogging.optional(), - cache: cacheOptions.optional(), - context: context.optional(), - devtool: devTool.optional(), - node: node.optional(), - ignoreWarnings: ignoreWarnings.optional(), - watchOptions: watchOptions.optional(), - watch: watch.optional(), - stats: statsValue.optional(), - snapshot: snapshotOptions.optional(), - optimization: optimization.optional(), - resolve: resolve.optional(), - resolveLoader: resolve.optional(), - plugins: plugins.optional(), - devServer: devServer.optional(), - builtins: builtins.optional(), - module: moduleOptions.optional(), - profile: profile.optional(), - features: features.optional(), -}); diff --git a/packages/bundles/package.json b/packages/bundles/package.json index 014a665484..72d04deff7 100644 --- a/packages/bundles/package.json +++ b/packages/bundles/package.json @@ -1,6 +1,6 @@ { "name": "@ice/bundles", - "version": "0.2.0", + "version": "0.2.1", "license": "MIT", "author": "ICE", "description": "Basic dependencies for ice.", @@ -45,13 +45,13 @@ "zod": "^3.22.3", "zod-validation-error": "1.2.0", "terminal-link": "^2.1.1", - "@ice/pack-binding": "0.0.4", + "@ice/pack-binding": "0.0.6", "mime-types": "2.1.35" }, "devDependencies": { "@rspack/plugin-react-refresh": "0.4.3", - "@rspack/dev-server": "0.4.3", - "@rspack/core": "0.4.3", + "@rspack/dev-server": "0.4.5", + "@rspack/core": "0.4.5", "@types/less": "^3.0.3", "@types/lodash": "^4.14.181", "@types/webpack-bundle-analyzer": "^4.4.1", diff --git a/packages/bundles/scripts/tasks.ts b/packages/bundles/scripts/tasks.ts index 5555d665db..f3f89b2ba5 100644 --- a/packages/bundles/scripts/tasks.ts +++ b/packages/bundles/scripts/tasks.ts @@ -231,10 +231,6 @@ const tasks = [ // filter out js files and replace with compiled files. const filePaths = globbySync(['**/*'], { cwd: pkgPath, ignore: ['node_modules'] }); const filesAddOverwrite = [ - 'dist/config/adapter.js', - 'dist/config/defaults.js', - 'dist/config/zod.js', - 'dist/config/normalization.js', 'dist/util/bindingVersionCheck.js', ]; filePaths.forEach((filePath) => { diff --git a/packages/ice/CHANGELOG.md b/packages/ice/CHANGELOG.md index 749e2a2ba2..c70bfeb151 100644 --- a/packages/ice/CHANGELOG.md +++ b/packages/ice/CHANGELOG.md @@ -1,5 +1,19 @@ # Changelog +## 3.4.1 + +### Patch Changes + +- ebc8ae08: fix: add assets plugin to deal with thrid-party dependencies import assets direactly +- 420fec85: fix: update binding version for packing error, resolve error when disable code splitting +- Updated dependencies [23811c82] +- Updated dependencies [420fec85] + - @ice/runtime@1.3.4 + - @ice/rspack-config@1.1.1 + - @ice/bundles@0.2.1 + - @ice/shared-config@1.2.1 + - @ice/webpack-config@1.1.8 + ## 3.4.0 ### Minor Changes diff --git a/packages/ice/bin/ice-cli.mjs b/packages/ice/bin/ice-cli.mjs index a098feeeac..72b3c1ede2 100755 --- a/packages/ice/bin/ice-cli.mjs +++ b/packages/ice/bin/ice-cli.mjs @@ -1,9 +1,9 @@ #!/usr/bin/env node import path from 'path'; +import { fileURLToPath } from 'url'; import chalk from 'chalk'; import semver from 'semver'; import fse from 'fs-extra'; -import { fileURLToPath } from 'url'; import { program, Option } from 'commander'; import yargsParser from 'yargs-parser'; import createService from '../esm/createService.js'; @@ -32,10 +32,14 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url)); .action(async ({ rootDir, ...commandArgs }, ctx) => { renamePlatformToTarget(commandArgs); process.env.NODE_ENV = 'production'; - const service = await createService({ rootDir, command: 'build', commandArgs: { - ...parseUnknownOptions(ctx.args), - ...commandArgs, - } }); + const service = await createService({ + rootDir, + command: 'build', + commandArgs: { + ...parseUnknownOptions(ctx.args), + ...commandArgs, + }, + }); service.run().catch((error) => { console.log(chalk.red('Build Error'), error); // Set exit code to 1 to exit process with failure code, otherwise CI may regard build as success. @@ -63,10 +67,14 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url)); .action(async ({ rootDir, ...commandArgs }, ctx) => { renamePlatformToTarget(commandArgs); process.env.NODE_ENV = 'development'; - const service = await createService({ rootDir, command: 'start', commandArgs: { - ...parseUnknownOptions(ctx.args), - ...commandArgs - } }); + const service = await createService({ + rootDir, + command: 'start', + commandArgs: { + ...parseUnknownOptions(ctx.args), + ...commandArgs, + }, + }); service.run(); }); @@ -105,13 +113,13 @@ function parseUnknownOptions(args) { // For ice.js <3.0.3, using --platform to set build target. function renamePlatformToTarget(commandArgs) { // Rename `platform` to `target`. - if (commandArgs.hasOwnProperty('platform')) { + if (Object.prototype.hasOwnProperty.call(commandArgs, 'platform')) { commandArgs.target = commandArgs.platform; delete commandArgs.platform; } } -function checkNodeVersion (requireNodeVersion, frameworkName = 'ice') { +function checkNodeVersion(requireNodeVersion, frameworkName = 'ice') { if (!semver.satisfies(process.version, requireNodeVersion)) { console.log(); console.log(chalk.red(` You are using Node ${process.version}`)); diff --git a/packages/ice/package.json b/packages/ice/package.json index f4cc6c3bb6..9bc89a8907 100644 --- a/packages/ice/package.json +++ b/packages/ice/package.json @@ -1,6 +1,6 @@ { "name": "@ice/app", - "version": "3.4.0", + "version": "3.4.1", "description": "provide scripts and configuration used by web framework ice", "type": "module", "main": "./esm/index.js", @@ -47,12 +47,12 @@ "bugs": "https://github.com/alibaba/ice/issues", "homepage": "https://v3.ice.work", "dependencies": { - "@ice/bundles": "0.2.0", + "@ice/bundles": "0.2.1", "@ice/route-manifest": "1.2.2", - "@ice/runtime": "^1.3.3", - "@ice/shared-config": "1.2.0", - "@ice/webpack-config": "1.1.7", - "@ice/rspack-config": "1.1.0", + "@ice/runtime": "^1.3.4", + "@ice/shared-config": "1.2.1", + "@ice/webpack-config": "1.1.8", + "@ice/rspack-config": "1.1.1", "@swc/helpers": "0.5.1", "@types/express": "^4.17.14", "address": "^1.1.2", @@ -98,7 +98,7 @@ "unplugin": "^1.5.1", "webpack": "^5.88.0", "webpack-dev-server": "4.15.0", - "@rspack/core": "0.4.3", + "@rspack/core": "0.4.5", "@rspack/dev-server": "0.4.3" }, "peerDependencies": { diff --git a/packages/ice/src/config.ts b/packages/ice/src/config.ts index ee9ec028e5..eebd72bfcd 100644 --- a/packages/ice/src/config.ts +++ b/packages/ice/src/config.ts @@ -241,20 +241,24 @@ const userConfig = [ { name: 'compileDependencies', validation: 'array|boolean', - getDefaultValue: () => (process.env.NODE_ENV === 'development' ? false : [/node_modules\/*/]), - setConfig: (config: Config, customValue: UserConfig['compileDependencies']) => { - let compileRegex: RegExp | false; + getDefaultValue: () => (process.env.NODE_ENV !== 'development'), + setConfig: (config: Config, customValue: UserConfig['compileDependencies'], context: UserConfigContext) => { + const speedupMode = context.commandArgs.speedup; + let compileRegex: RegExp | string | false; if (customValue === true) { - compileRegex = /node_modules\/*/; + compileRegex = speedupMode ? 'node_modules' : /node_modules\/*/; } else if (customValue && customValue.length > 0) { compileRegex = new RegExp( customValue .map((dep: string | RegExp) => { if (dep instanceof RegExp) { + if (speedupMode) { + throw new Error('speedup mode does not support config compileDependencies as RegExp'); + } return dep.source; } else if (typeof dep === 'string') { // add default prefix of node_modules - const matchStr = `node_modules/?.+${dep}/`; + const matchStr = speedupMode ? dep : `node_modules/?.+${dep}/`; return matchStr; } return false; diff --git a/packages/ice/src/service/ServerRunner.ts b/packages/ice/src/service/ServerRunner.ts index b873458a2f..40f64fe1bc 100644 --- a/packages/ice/src/service/ServerRunner.ts +++ b/packages/ice/src/service/ServerRunner.ts @@ -128,6 +128,11 @@ class ServerRunner extends Runner { define, taskConfig, speedup, + plugins: [ + createAssetsPlugin(() => { + return this.compilationInfo; + }, rootDir), + ], }); const esbuildPlugins = [ diff --git a/packages/ice/src/service/serverCompiler.ts b/packages/ice/src/service/serverCompiler.ts index fe6c667176..b5ef06a3c4 100644 --- a/packages/ice/src/service/serverCompiler.ts +++ b/packages/ice/src/service/serverCompiler.ts @@ -145,8 +145,18 @@ export function createServerCompiler(options: Options) { getRoutesFile, }, 'esbuild', { isServer }); const define = getRuntimeDefination(task.config?.define || {}, runtimeDefineVars, transformEnv); - if (preBundle) { + const plugins = [ + // Add assets plugin for pre-bundle in case of third-party library requires assets. + compilationInfo && createAssetsPlugin(compilationInfo, rootDir), + ]; + if (enableSyntaxFeatures) { + plugins.push( + transformPipePlugin({ + plugins: transformPlugins, + }), + ); + } preBundleDepsMetadata = await createPreBundleDepsMetadata({ task, alias, @@ -156,11 +166,7 @@ export function createServerCompiler(options: Options) { speedup, external: Object.keys(externals), // Pass transformPlugins only if syntaxFeatures is enabled - plugins: enableSyntaxFeatures ? [ - transformPipePlugin({ - plugins: transformPlugins, - }), - ] : [], + plugins, }); } diff --git a/packages/plugin-i18n/package.json b/packages/plugin-i18n/package.json index b2b2b4c53b..1838df87c8 100644 --- a/packages/plugin-i18n/package.json +++ b/packages/plugin-i18n/package.json @@ -56,8 +56,8 @@ "webpack-dev-server": "4.15.0" }, "peerDependencies": { - "@ice/app": "^3.4.0", - "@ice/runtime": "^1.3.3" + "@ice/app": "^3.4.1", + "@ice/runtime": "^1.3.4" }, "publishConfig": { "access": "public" diff --git a/packages/rspack-config/CHANGELOG.md b/packages/rspack-config/CHANGELOG.md index ec9b29d085..4590e4cd5c 100644 --- a/packages/rspack-config/CHANGELOG.md +++ b/packages/rspack-config/CHANGELOG.md @@ -1,5 +1,14 @@ # @ice/rspack-config +## 1.1.1 + +### Patch Changes + +- 420fec85: fix: update binding version for packing error, resolve error when disable code splitting +- Updated dependencies [420fec85] + - @ice/bundles@0.2.1 + - @ice/shared-config@1.2.1 + ## 1.1.0 ### Minor Changes diff --git a/packages/rspack-config/package.json b/packages/rspack-config/package.json index 2854fa8057..1011bc3d09 100644 --- a/packages/rspack-config/package.json +++ b/packages/rspack-config/package.json @@ -1,6 +1,6 @@ { "name": "@ice/rspack-config", - "version": "1.1.0", + "version": "1.1.1", "repository": "alibaba/ice", "bugs": "https://github.com/alibaba/ice/issues", "homepage": "https://v3.ice.work", @@ -15,11 +15,11 @@ "*.d.ts" ], "dependencies": { - "@ice/bundles": "0.2.0", - "@ice/shared-config": "1.2.0" + "@ice/bundles": "0.2.1", + "@ice/shared-config": "1.2.1" }, "devDependencies": { - "@rspack/core": "0.4.3" + "@rspack/core": "0.4.5" }, "scripts": { "watch": "tsc -w --sourceMap", diff --git a/packages/rspack-config/src/index.ts b/packages/rspack-config/src/index.ts index 451c918166..57b54046e3 100644 --- a/packages/rspack-config/src/index.ts +++ b/packages/rspack-config/src/index.ts @@ -1,6 +1,6 @@ import * as path from 'path'; import { createRequire } from 'module'; -import { compilationPlugin, compileExcludes, getDefineVars, getCompilerPlugins, getJsxTransformOptions, getAliasWithRoot } from '@ice/shared-config'; +import { getDefineVars, getCompilerPlugins, getJsxTransformOptions, getAliasWithRoot, skipCompilePackages } from '@ice/shared-config'; import type { Config, ModifyWebpackConfig } from '@ice/shared-config/types'; import type { Configuration, rspack as Rspack } from '@rspack/core'; import lodash from '@ice/bundles/compiled/lodash/index.js'; @@ -43,7 +43,6 @@ const getConfig: GetConfig = async (options) => { runtimeTmpDir, getExpandedEnvs, runtimeDefineVars, - getRoutesFile, localIdentName, rspack, } = options; @@ -52,9 +51,7 @@ const getConfig: GetConfig = async (options) => { mode, minify, publicPath = '/', - cacheDir, outputDir = 'build', - sourceMap, externals = {}, alias = {}, compileIncludes, @@ -75,19 +72,6 @@ const getConfig: GetConfig = async (options) => { const isDev = mode === 'development'; const absoluteOutputDir = path.isAbsolute(outputDir) ? outputDir : path.join(rootDir, outputDir); const hashKey = hash === true ? 'hash:8' : (hash || ''); - const compilation = compilationPlugin({ - rootDir, - cacheDir, - sourceMap, - fastRefresh: false, - mode, - compileIncludes, - compileExcludes, - swcOptions, - polyfill, - enableEnv: true, - getRoutesFile, - }); const { rspack: { DefinePlugin, ProvidePlugin, SwcJsMinimizerRspackPlugin } } = await import('@ice/bundles/esm/rspack.js'); const cssFilename = `css/${hashKey ? `[name]-[${hashKey}].css` : '[name].css'}`; @@ -128,6 +112,19 @@ const getConfig: GetConfig = async (options) => { ? splitChunks : getSplitChunks(rootDir, splitChunks); } + // Get built-in exclude packages. + const compileExclude = skipCompilePackages.map((pkg) => { + return `node_modules[\\/](${pkg}[\\/]|_${pkg.replace('/', '_')}@[^/]+[\\/])`; + }); + let excludeRule: string; + + if (!compileIncludes || compileIncludes?.length === 0) { + excludeRule = 'node_modules'; + } else if (!compileIncludes?.includes('node_modules') && compileIncludes?.length > 0) { + excludeRule = `node_modules[\\/](?!${compileIncludes.map((pkg: string) => { + return `${pkg}[\\/]|_${pkg.replace('/', '_')}@[^/]+[\\/]`; + }).join('|')}).*`; + } const config: Configuration = { entry: { main: [path.join(rootDir, runtimeTmpDir, 'entry.client.tsx')], @@ -148,8 +145,8 @@ const getConfig: GetConfig = async (options) => { module: { rules: [ { - // TODO: use regexp to improve performance. - test: compilation.transformInclude, + test: /\.(jsx?|tsx?|mjs)$/, + ...(excludeRule ? { exclude: new RegExp(excludeRule) } : {}), use: { loader: 'builtin:compilation-loader', options: { @@ -158,6 +155,10 @@ const getConfig: GetConfig = async (options) => { removeExport: swcOptions.removeExportExprs, keepExport: swcOptions.keepExports, }, + compileRules: { + // "bundles/compiled" is the path when using @ice/bundles. + exclude: [...compileExclude, 'bundles/compiled'], + }, }, }, }, @@ -204,6 +205,8 @@ const getConfig: GetConfig = async (options) => { experiments: { rspackFuture: { disableTransformByDefault: true, + // This configuration is make the same behaior with webpack 5. + disableApplyEntryLazily: true, }, }, stats: 'none', diff --git a/packages/rspack-config/src/splitChunks.ts b/packages/rspack-config/src/splitChunks.ts index 5224596212..b186bfb769 100644 --- a/packages/rspack-config/src/splitChunks.ts +++ b/packages/rspack-config/src/splitChunks.ts @@ -87,7 +87,8 @@ export const getVendorStrategy = (options: Configuration['splitChunks']) => { const getSplitChunks = (_: string, strategy: string | boolean) => { if (strategy === false) { - return { minChunks: Infinity, cacheGroups: { default: false } }; + // Empty splitChunks configuration if strategy is false. + return {}; } else if (typeof strategy === 'string' && ['page-vendors', 'vendors'].includes(strategy)) { const splitChunksOptions = strategy === 'page-vendors' ? { chunks: 'all' } : {}; return getVendorStrategy(splitChunksOptions); diff --git a/packages/runtime/CHANGELOG.md b/packages/runtime/CHANGELOG.md index b558ca8d13..596f2d5abf 100644 --- a/packages/runtime/CHANGELOG.md +++ b/packages/runtime/CHANGELOG.md @@ -1,5 +1,11 @@ # @ice/runtime +## 1.3.4 + +### Patch Changes + +- 23811c82: fix: `unstable_OffScreen` to `unstable_Activity`. For https://github.com/facebook/react/pull/27640 + ## 1.3.3 ### Patch Changes diff --git a/packages/runtime/package.json b/packages/runtime/package.json index f777e59f08..6f15eff9cd 100644 --- a/packages/runtime/package.json +++ b/packages/runtime/package.json @@ -1,6 +1,6 @@ { "name": "@ice/runtime", - "version": "1.3.3", + "version": "1.3.4", "description": "Runtime module for ice.js", "type": "module", "types": "./esm/index.d.ts", diff --git a/packages/runtime/src/KeepAliveOutlet.tsx b/packages/runtime/src/KeepAliveOutlet.tsx index f8a7a43eea..a69a7081f4 100644 --- a/packages/runtime/src/KeepAliveOutlet.tsx +++ b/packages/runtime/src/KeepAliveOutlet.tsx @@ -2,11 +2,11 @@ import React, { useState, useEffect } from 'react'; import { useOutlet, useLocation } from 'react-router-dom'; // @ts-ignore -const Offscreen = React.unstable_Offscreen; +const Activity = React.unstable_Activity; // ref: https://leomyili.github.io/react-stillness-component/docs/examples/react-router/v6 export default function KeepAliveOutlet() { - if (!Offscreen) { + if (!Activity) { throw new Error('`` now requires react experimental version. Please install it first.'); } const [outlets, setOutlets] = useState([]); @@ -32,9 +32,9 @@ export default function KeepAliveOutlet() { { outlets.map((o) => { return ( - + {o.outlet} - + ); }) } diff --git a/packages/shared-config/CHANGELOG.md b/packages/shared-config/CHANGELOG.md index 2a916f5b98..43cd45837e 100644 --- a/packages/shared-config/CHANGELOG.md +++ b/packages/shared-config/CHANGELOG.md @@ -1,5 +1,12 @@ # @ice/shared-config +## 1.2.1 + +### Patch Changes + +- Updated dependencies [420fec85] + - @ice/bundles@0.2.1 + ## 1.2.0 ### Minor Changes diff --git a/packages/shared-config/package.json b/packages/shared-config/package.json index 88949bbc5b..aa16706703 100644 --- a/packages/shared-config/package.json +++ b/packages/shared-config/package.json @@ -1,6 +1,6 @@ { "name": "@ice/shared-config", - "version": "1.2.0", + "version": "1.2.1", "repository": "alibaba/ice", "bugs": "https://github.com/alibaba/ice/issues", "homepage": "https://v3.ice.work", @@ -17,7 +17,7 @@ "*.d.ts" ], "dependencies": { - "@ice/bundles": "0.2.0", + "@ice/bundles": "0.2.1", "@rollup/pluginutils": "^4.2.0", "browserslist": "^4.22.1", "consola": "^2.15.3", diff --git a/packages/webpack-config/CHANGELOG.md b/packages/webpack-config/CHANGELOG.md index 2525e98d2c..61e698bf09 100644 --- a/packages/webpack-config/CHANGELOG.md +++ b/packages/webpack-config/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## 1.1.8 + +### Patch Changes + +- Updated dependencies [420fec85] + - @ice/bundles@0.2.1 + - @ice/shared-config@1.2.1 + ## 1.1.7 ### Patch Changes diff --git a/packages/webpack-config/package.json b/packages/webpack-config/package.json index 4e0d0a8abf..ae73e3f960 100644 --- a/packages/webpack-config/package.json +++ b/packages/webpack-config/package.json @@ -1,6 +1,6 @@ { "name": "@ice/webpack-config", - "version": "1.1.7", + "version": "1.1.8", "repository": "alibaba/ice", "bugs": "https://github.com/alibaba/ice/issues", "homepage": "https://v3.ice.work", @@ -15,8 +15,8 @@ "*.d.ts" ], "dependencies": { - "@ice/shared-config": "1.2.0", - "@ice/bundles": "0.2.0", + "@ice/shared-config": "1.2.1", + "@ice/bundles": "0.2.1", "fast-glob": "^3.2.11", "process": "^0.11.10" }, diff --git a/patches/@rspack__core@0.4.5.patch b/patches/@rspack__core@0.4.5.patch new file mode 100644 index 0000000000..666be14d94 --- /dev/null +++ b/patches/@rspack__core@0.4.5.patch @@ -0,0 +1,67 @@ +diff --git a/dist/config/adapter.js b/dist/config/adapter.js +index ea1d21db02d413de0d25367c646cd9773fb41223..42aed198ffb18752a7a245e1f8a0f2bf845b80d5 100644 +--- a/dist/config/adapter.js ++++ b/dist/config/adapter.js +@@ -16,6 +16,7 @@ const getRawOptions = (options, compiler, processResource) => { + const mode = options.mode; + const experiments = getRawExperiments(options.experiments); + return { ++ features: options.features, + mode, + target: getRawTarget(options.target), + context: options.context, +diff --git a/dist/config/defaults.js b/dist/config/defaults.js +index b413bb21a053a161a64056664354a50ee6429283..9983bc69e39d031ca49fa04bcad0aea093e4b996 100644 +--- a/dist/config/defaults.js ++++ b/dist/config/defaults.js +@@ -53,6 +53,11 @@ const applyRspackOptionsDefaults = (options) => { + applyExperimentsDefaults(options.experiments, { + cache: options.cache + }); ++ if (options.features) { ++ applyFeaturesDefaults(options.features); ++ } else { ++ D(options, 'features', {}); ++ } + applySnapshotDefaults(options.snapshot, { production }); + applyModuleDefaults(options.module, { + // syncWebAssembly: options.experiments.syncWebAssembly, +@@ -129,6 +134,13 @@ const applyExperimentsDefaults = (experiments, { cache }) => { + D(experiments.rspackFuture, "disableApplyEntryLazily", false); + } + }; ++const applyFeaturesDefaults = (features) => { ++ D(features, 'split_chunks_strategy', {}); ++ if (typeof features.split_chunks_strategy === 'object') { ++ D(features.split_chunks_strategy, 'name', ''); ++ D(features.split_chunks_strategy, 'topLevelFrameworks', []); ++ } ++}; + const applySnapshotDefaults = (snapshot, { production }) => { + F(snapshot, "module", () => production + ? { timestamp: true, hash: true } +diff --git a/dist/config/normalization.js b/dist/config/normalization.js +index 7769ba679c50a63a60961cfe87f5b7b950593e85..d159573dacd63aec503be254366eea94cdddf826 100644 +--- a/dist/config/normalization.js ++++ b/dist/config/normalization.js +@@ -13,6 +13,7 @@ exports.getNormalizedRspackOptions = void 0; + const util_1 = require("../util"); + const getNormalizedRspackOptions = (config) => { + return { ++ features: config.features, + ignoreWarnings: config.ignoreWarnings !== undefined + ? config.ignoreWarnings.map(ignore => { + if (typeof ignore === "function") { +diff --git a/dist/config/zod.js b/dist/config/zod.js +index 9efb9502f22278229c9c5798b7ae5eee2dbd0915..348b9528161995d65d462279f74960d1b00e195f 100644 +--- a/dist/config/zod.js ++++ b/dist/config/zod.js +@@ -759,6 +759,7 @@ exports.rspackOptions = zod_1.z.strictObject({ + builtins: builtins.optional(), + module: moduleOptions.optional(), + profile: profile.optional(), +- bail: bail.optional() ++ bail: bail.optional(), ++ features: zod_1.z.custom().optional(), + }); + //# sourceMappingURL=zod.js.map diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d477baff7d..18732317d3 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -5,6 +5,9 @@ settings: excludeLinksFromLockfile: false patchedDependencies: + '@rspack/core@0.4.5': + hash: vl6m5tsr4v2bh4wx2ltp22ktf4 + path: patches/@rspack__core@0.4.5.patch unplugin@1.5.1: hash: eanypstkeladyqkfllfbryx6lu path: patches/unplugin@1.5.1.patch @@ -1273,8 +1276,8 @@ importers: specifier: 0.0.6 version: 0.0.6 '@ice/pack-binding': - specifier: 0.0.4 - version: 0.0.4 + specifier: 0.0.6 + version: 0.0.6 '@ice/swc-plugin-keep-export': specifier: 0.2.0 version: 0.2.0 @@ -1370,11 +1373,11 @@ importers: specifier: 0.5.10 version: 0.5.10(react-refresh@0.14.0)(webpack-dev-server@4.15.0)(webpack@5.88.2) '@rspack/core': - specifier: 0.4.3 - version: 0.4.3 + specifier: 0.4.5 + version: 0.4.5(patch_hash=vl6m5tsr4v2bh4wx2ltp22ktf4) '@rspack/dev-server': - specifier: 0.4.3 - version: 0.4.3(@rspack/core@0.4.3)(@swc/core@1.3.80)(esbuild@0.17.16)(react-refresh@0.14.0) + specifier: 0.4.5 + version: 0.4.5(@rspack/core@0.4.5)(@swc/core@1.3.80)(esbuild@0.17.16)(react-refresh@0.14.0) '@rspack/plugin-react-refresh': specifier: 0.4.3 version: 0.4.3(react-refresh@0.14.0) @@ -1597,22 +1600,22 @@ importers: packages/ice: dependencies: '@ice/bundles': - specifier: 0.2.0 + specifier: 0.2.1 version: link:../bundles '@ice/route-manifest': specifier: 1.2.2 version: link:../route-manifest '@ice/rspack-config': - specifier: 1.1.0 + specifier: 1.1.1 version: link:../rspack-config '@ice/runtime': - specifier: ^1.3.3 + specifier: ^1.3.4 version: link:../runtime '@ice/shared-config': - specifier: 1.2.0 + specifier: 1.2.1 version: link:../shared-config '@ice/webpack-config': - specifier: 1.1.7 + specifier: 1.1.8 version: link:../webpack-config '@swc/helpers': specifier: 0.5.1 @@ -1697,11 +1700,11 @@ importers: version: 21.1.1 devDependencies: '@rspack/core': - specifier: 0.4.3 - version: 0.4.3 + specifier: 0.4.5 + version: 0.4.5(patch_hash=vl6m5tsr4v2bh4wx2ltp22ktf4) '@rspack/dev-server': specifier: 0.4.3 - version: 0.4.3(@rspack/core@0.4.3)(@types/express@4.17.17)(esbuild@0.17.16) + version: 0.4.3(@rspack/core@0.4.5)(@types/express@4.17.17)(esbuild@0.17.16) '@types/babel__generator': specifier: ^7.6.4 version: 7.6.4 @@ -2291,15 +2294,15 @@ importers: packages/rspack-config: dependencies: '@ice/bundles': - specifier: 0.2.0 + specifier: 0.2.1 version: link:../bundles '@ice/shared-config': - specifier: 1.2.0 + specifier: 1.2.1 version: link:../shared-config devDependencies: '@rspack/core': - specifier: 0.4.3 - version: 0.4.3 + specifier: 0.4.5 + version: 0.4.5(patch_hash=vl6m5tsr4v2bh4wx2ltp22ktf4) packages/runtime: dependencies: @@ -2365,7 +2368,7 @@ importers: packages/shared-config: dependencies: '@ice/bundles': - specifier: 0.2.0 + specifier: 0.2.1 version: link:../bundles '@rollup/pluginutils': specifier: ^4.2.0 @@ -2408,10 +2411,10 @@ importers: packages/webpack-config: dependencies: '@ice/bundles': - specifier: 0.2.0 + specifier: 0.2.1 version: link:../bundles '@ice/shared-config': - specifier: 1.2.0 + specifier: 1.2.1 version: link:../shared-config fast-glob: specifier: ^3.2.11 @@ -6655,8 +6658,8 @@ packages: '@ice/css-modules-hash-win32-x64-msvc': 0.0.6 dev: false - /@ice/pack-binding-darwin-arm64@0.0.4: - resolution: {integrity: sha512-OtzGietfQqrE24l+fq4Zt3azY/ZN9GYMfqtFIPmD4OhHdZdBsMj15ycQAu8U35kVI3nRiirYaXkRpysE5Gq98Q==} + /@ice/pack-binding-darwin-arm64@0.0.6: + resolution: {integrity: sha512-vJNdd1rvAA+3l2wlZvZKoOaz+ti7RG4MaHM/T+fEgt9lDpxhY3X+/4MNKdJnzMGsBsX5vMjvifRXS4UFFSg5oQ==} engines: {node: '>= 10'} cpu: [arm64] os: [darwin] @@ -6664,16 +6667,16 @@ packages: dev: false optional: true - /@ice/pack-binding-darwin-universal@0.0.4: - resolution: {integrity: sha512-M6Hf6YyEIEQ6h6ZyX7XsKafnmnch+o4yb4pgRjZFFvdwqToeNj8jHnPSQdnlWXE9vbdGmhAZopJvNPnljDNRmg==} + /@ice/pack-binding-darwin-universal@0.0.6: + resolution: {integrity: sha512-Y/eDuy667DvUAWl9hpg4D8YCFogW6eCCdOIEMVhxHQOBCMa9QbXCg6TKsI+xKfudUCNCsqg+dQTdRUMCazNjxQ==} engines: {node: '>= 10'} os: [darwin] requiresBuild: true dev: false optional: true - /@ice/pack-binding-darwin-x64@0.0.4: - resolution: {integrity: sha512-CrnjirRVTng69R5/xgLLETxkH3Vp5wbTWY5BRxQZf3Cd5lIOfsQao4R1Z7tYn5eJ5Huqp20C7ZB/r4By1EgcSg==} + /@ice/pack-binding-darwin-x64@0.0.6: + resolution: {integrity: sha512-QEWYkPtzIYLvw9h5K9NjwXjB+XFVRUnpaEjQPoO3xGC/0l0xABOtdl4kbo/ya1ucIwq8hM530fi/STBUy8UaEg==} engines: {node: '>= 10'} cpu: [x64] os: [darwin] @@ -6681,8 +6684,8 @@ packages: dev: false optional: true - /@ice/pack-binding-linux-x64-gnu@0.0.4: - resolution: {integrity: sha512-WghzIXix7a1k+z3gPqbIf3S/I9PZXMgFiIvQ409IB8VFwI3pzY3OLqlRISkXZMWIB4u0J1qU+h4Ka/V11HLmzA==} + /@ice/pack-binding-linux-x64-gnu@0.0.6: + resolution: {integrity: sha512-Ol6E62HxLhCPAeTJ7e6vaC1UsKJNt5mCngQVlUAut5QIFccQw6m+ZFGHu/OZfvmtTYwCo4d3m8OlBoTvIyIY5w==} engines: {node: '>= 10'} cpu: [x64] os: [linux] @@ -6690,8 +6693,8 @@ packages: dev: false optional: true - /@ice/pack-binding-linux-x64-musl@0.0.4: - resolution: {integrity: sha512-8hkrcS1uicN3JLKS15ODmFxiveSLnHGt2bWjoXTEUmQDxjPZXyevS9oys/WvO8a2Cew5UadI/lgzFGmYZbm9mQ==} + /@ice/pack-binding-linux-x64-musl@0.0.6: + resolution: {integrity: sha512-koCI4HhBJk/MhMdeAJiMMza1Y0+HRexl2YsAsgZZLTAuOPhPCqFrofiIAJ1hBJhQpwWdK4Dfi13szeoWp2HIlA==} engines: {node: '>= 10'} cpu: [x64] os: [linux] @@ -6699,8 +6702,8 @@ packages: dev: false optional: true - /@ice/pack-binding-win32-arm64-msvc@0.0.4: - resolution: {integrity: sha512-lIl+h3jUHp8DXxPy0U+abM6+uWeIshUNNebBpRUpUqO3TtUcbgfwFU4HkAeQv/ef/xAUY/XzRvotJgtt4SZjPQ==} + /@ice/pack-binding-win32-arm64-msvc@0.0.6: + resolution: {integrity: sha512-4xyVffE2wzI1TAaJhXj3SYGEgPSlg5qwDJxu+8S77sMrFmqGFOkTbo3Jg/wI1FUFsvWCEJZz4ly4AY4CF7dxhA==} engines: {node: '>= 10'} cpu: [arm64] os: [win32] @@ -6708,8 +6711,8 @@ packages: dev: false optional: true - /@ice/pack-binding-win32-x64-msvc@0.0.4: - resolution: {integrity: sha512-4N9dMY1bD4k7uTABHKgb0ylZeo6grJU3QHXxBxJMwHyXtGsC6mKzsVWyuTr8rOPm+nEGyy699Zv53YWNLdv8dw==} + /@ice/pack-binding-win32-x64-msvc@0.0.6: + resolution: {integrity: sha512-7rJF5RMzg2vdyBoSAS9nBSGKHUqWB9S5TN4oAqssrTWbBeCT5Sf8GHUfwzRKBc0a/3muSUPzRxOIKh6yCT859g==} engines: {node: '>= 10'} cpu: [x64] os: [win32] @@ -6717,17 +6720,17 @@ packages: dev: false optional: true - /@ice/pack-binding@0.0.4: - resolution: {integrity: sha512-JKt4IcsqdIF2TuWFHh99fdQWoC55z+WgID9Psa+8fYexVAsArpQhXkxAGweiw6ilFTOFqUcRBwQG91oJxGZ3eQ==} + /@ice/pack-binding@0.0.6: + resolution: {integrity: sha512-nH2oBXgSOQfLILVBWDgxvmf2+UbibGGzNaynAxlSM+v1keQqGcy/me//wvwKDFlk/dWYvHQSv2vGZ3AUYshh5g==} engines: {node: '>= 10'} optionalDependencies: - '@ice/pack-binding-darwin-arm64': 0.0.4 - '@ice/pack-binding-darwin-universal': 0.0.4 - '@ice/pack-binding-darwin-x64': 0.0.4 - '@ice/pack-binding-linux-x64-gnu': 0.0.4 - '@ice/pack-binding-linux-x64-musl': 0.0.4 - '@ice/pack-binding-win32-arm64-msvc': 0.0.4 - '@ice/pack-binding-win32-x64-msvc': 0.0.4 + '@ice/pack-binding-darwin-arm64': 0.0.6 + '@ice/pack-binding-darwin-universal': 0.0.6 + '@ice/pack-binding-darwin-x64': 0.0.6 + '@ice/pack-binding-linux-x64-gnu': 0.0.6 + '@ice/pack-binding-linux-x64-musl': 0.0.6 + '@ice/pack-binding-win32-arm64-msvc': 0.0.6 + '@ice/pack-binding-win32-x64-msvc': 0.0.6 dev: false /@ice/pkg@1.5.5: @@ -7401,6 +7404,30 @@ packages: /@mdx-js/util@1.6.22: resolution: {integrity: sha512-H1rQc1ZOHANWBvPcW+JpGwr+juXSxM8Q8YCkm3GhZd8REu1fHR3z99CErO1p9pkcfcxZnMdIZdIsXkOHY0NilA==} + /@module-federation/runtime-tools@0.0.0-next-20231225095220: + resolution: {integrity: sha512-Rn4ntKEWR5FdT3IA2gd5vw71GhXiYbNev2F54iBiWHsF0z+J41lHQhNDXDAoTeNmJs64e9dsPhBM2U0VZKo8uA==} + dependencies: + '@module-federation/runtime': 0.0.0-next-20231225095220 + '@module-federation/webpack-bundler-runtime': 0.0.0-next-20231225095220 + dev: true + + /@module-federation/runtime@0.0.0-next-20231225095220: + resolution: {integrity: sha512-tsST3igVpXKclGpqq2NNm1wzROks29PGte7GCgSPhoaFVNg076Nl8XzFNPGflCF6g/z13oFw/vahYpBAHkEZgQ==} + dependencies: + '@module-federation/sdk': 0.0.0-next-20231225095220 + dev: true + + /@module-federation/sdk@0.0.0-next-20231225095220: + resolution: {integrity: sha512-0vS5UXCkbKyotZIXAsF+mrL8PQ+xKmKfaDYHdBxXR4kyGSRjSRRokSKkXZNVfPEhy1f1z/oAgUo5AZoOisrrQA==} + dev: true + + /@module-federation/webpack-bundler-runtime@0.0.0-next-20231225095220: + resolution: {integrity: sha512-xzz2FUvj+/TMl2ua/EcFaiYmH54XedH5fU7zQ1/EBZDrt26uJR4vabmvPx3Eb06KfDEcGB2/zkzZNzcT8572CQ==} + dependencies: + '@module-federation/runtime': 0.0.0-next-20231225095220 + '@module-federation/sdk': 0.0.0-next-20231225095220 + dev: true + /@nicolo-ribaudo/eslint-scope-5-internals@5.1.1-v1: resolution: {integrity: sha512-54/JRvkLIzzDWshCWfuhadfrfZVPiElY8Fcgmg1HroEly/EDSszzhBAsarCux+D/kOslTRquNzuyGSmUSTTHGg==} dependencies: @@ -7925,102 +7952,102 @@ packages: estree-walker: 2.0.2 picomatch: 2.3.1 - /@rspack/binding-darwin-arm64@0.4.3: - resolution: {integrity: sha512-H/MW5oWawFY45OM+ePRELBueDlAusAMTaztn54AB1CRXyhLteyeX9luQv6+Fe1TDHeDfv27NL+eNTfO0+YJeZg==} + /@rspack/binding-darwin-arm64@0.4.5: + resolution: {integrity: sha512-H7RaSPN9VEzZf4URZpVV0Is4I1mgOHCzYVxDUZ/9G5vMkTW5baktCxFwbmBPYKcZ8Zoj/hy/DE8fmt1L200NmQ==} cpu: [arm64] os: [darwin] requiresBuild: true dev: true optional: true - /@rspack/binding-darwin-x64@0.4.3: - resolution: {integrity: sha512-m/XiTWbsrJ45sFTD+I3P9V7OT9sNx4+RW6PbS28n9yvPflrx5TX6r9WjFnFD6RJcPnt81hvO6oOE3LDO5LPvAw==} + /@rspack/binding-darwin-x64@0.4.5: + resolution: {integrity: sha512-K5HgE4nHwVWizCr2pBLA8N3LXfn1lQCSV5sR+6xQQrVdvRJ5zBhPMwjPOzP+AdmGhrD14zz1j9mktzCvA7FUtg==} cpu: [x64] os: [darwin] requiresBuild: true dev: true optional: true - /@rspack/binding-linux-arm64-gnu@0.4.3: - resolution: {integrity: sha512-t7wbd5NbZ5H3LeiUGZey0CKJdJWluu/iqdecnoPDEbXRdF7caev9OAJuQ9fKEsK4uQHQLvQ0/pjFDyDbJbPG5w==} + /@rspack/binding-linux-arm64-gnu@0.4.5: + resolution: {integrity: sha512-JvESc3imqKbqwal5WesxlV3ix8eIO/07XCj+pkaZWaf4nj/ui02NGtLaeLVxwc1fxHekdLc+ROQrxpdOLhQ1jw==} cpu: [arm64] os: [linux] requiresBuild: true dev: true optional: true - /@rspack/binding-linux-arm64-musl@0.4.3: - resolution: {integrity: sha512-VlqXmsgft9LeYxWm8bZB16f/SZE7xLaHgDwFR6KCFLhubPRnF7gvxLf/y8FAtZzV+9XDi7mhfLWHMyJJDqwFBQ==} + /@rspack/binding-linux-arm64-musl@0.4.5: + resolution: {integrity: sha512-ziYGYEoLsPEyC0pEAj5clU8XOFr3+r7IExm9/sq2gp+M1as/yTzouEuzO3D8kI0xVfub1WmiEktTBlgjS13CSA==} cpu: [arm64] os: [linux] requiresBuild: true dev: true optional: true - /@rspack/binding-linux-x64-gnu@0.4.3: - resolution: {integrity: sha512-7eGymsvYsHz/P1mvUo1O+UJqrFzlMXY41599UWRiX4M3tX/pvDtLvxxjZ3JHVvNzEaBCiQ5xyRzqhhRDzcj4ww==} + /@rspack/binding-linux-x64-gnu@0.4.5: + resolution: {integrity: sha512-9cXOIswpSZYhEXeuIWdsQNrgpjHTD4I3v0NPm75cL6cdBtJMHOa/qejO5mdTLzoDdE7waGZAb4uSMfrJOEkwqQ==} cpu: [x64] os: [linux] requiresBuild: true dev: true optional: true - /@rspack/binding-linux-x64-musl@0.4.3: - resolution: {integrity: sha512-16PptmbtvpGHtEfbLoQjWjhBXOykdQRHXxn3RUTpkEXFbmhLnvnXbfmfSRoBuVNR+j0BqCrGiwweO43VBceJPg==} + /@rspack/binding-linux-x64-musl@0.4.5: + resolution: {integrity: sha512-wClTj9mbVKprHIWsLEVJg+ZXT5slF93JsyAALIhAFkNMmn5z0B2NPD7+Oaii62edKMk2nS3dpoHu1JCLDmP0cw==} cpu: [x64] os: [linux] requiresBuild: true dev: true optional: true - /@rspack/binding-win32-arm64-msvc@0.4.3: - resolution: {integrity: sha512-q9Vsn9Glj6m24UQfXpxcirk5S8r1RmAShXxjF+yRrKqpOtq1IodLWWRZ85kQfJyfk9deAfVkpiqHdsoK54uqQQ==} + /@rspack/binding-win32-arm64-msvc@0.4.5: + resolution: {integrity: sha512-8LNITZqPMKO69nc8hwdcweBXcAS4yAL5W/kZ6zKeb6Ly+X5SBZk7l0WPL7lPMib/vHFkjJjp1buGhzymLU0bzA==} cpu: [arm64] os: [win32] requiresBuild: true dev: true optional: true - /@rspack/binding-win32-ia32-msvc@0.4.3: - resolution: {integrity: sha512-jY6RiFwKQQjX3QR28K7boydBIhWKgAcGlDR+p4KnDSciF0H19ImT9QAf31Wcj2+XjN0wRev58cHRI2tgRw2+cw==} + /@rspack/binding-win32-ia32-msvc@0.4.5: + resolution: {integrity: sha512-dndiXygG1ZmSO3unuZ9Mc+7IvqBtFqwvjFZGKUdIcufFr2CjZDL/KR1zJGTmFIzwHKMV2hEH4cZpa2TwisXvGQ==} cpu: [ia32] os: [win32] requiresBuild: true dev: true optional: true - /@rspack/binding-win32-x64-msvc@0.4.3: - resolution: {integrity: sha512-tZySo3ZZptxjuR0DDYQWQATUf5ApdDH7lQBezum/q5kzKVFFHN963JnInPHEO1wUtNXaTWXcx31habZTBrse/A==} + /@rspack/binding-win32-x64-msvc@0.4.5: + resolution: {integrity: sha512-SEu8+pQsnGP7A0/XX5vawsccR825UCOzK5phJ8INSC7Mse8FKzkZpv2Af3PsHl2+N17M0PRgBxTghXR35PXkiw==} cpu: [x64] os: [win32] requiresBuild: true dev: true optional: true - /@rspack/binding@0.4.3: - resolution: {integrity: sha512-cw7Sca7YL9FeSTWdYahxr6HgWXnboOgPiM5SJai2Nfj6c/PWJV+ntBZbIW0LRY1fFDL7dYz3GUCXj4Dv3QYc8A==} + /@rspack/binding@0.4.5: + resolution: {integrity: sha512-XmSlt9ucpfebhkWI4guPEym0F+8JZGr8UyBVAtHN2/7SQRI8TL8G1BUQGVgmc7+UKA5RM1Qfps1QmtHYzjARBQ==} optionalDependencies: - '@rspack/binding-darwin-arm64': 0.4.3 - '@rspack/binding-darwin-x64': 0.4.3 - '@rspack/binding-linux-arm64-gnu': 0.4.3 - '@rspack/binding-linux-arm64-musl': 0.4.3 - '@rspack/binding-linux-x64-gnu': 0.4.3 - '@rspack/binding-linux-x64-musl': 0.4.3 - '@rspack/binding-win32-arm64-msvc': 0.4.3 - '@rspack/binding-win32-ia32-msvc': 0.4.3 - '@rspack/binding-win32-x64-msvc': 0.4.3 - dev: true - - /@rspack/core@0.4.3: - resolution: {integrity: sha512-YKzOOt6v6vZZH15+HdwWbd7DdXdXIJLlYQdQ6jgrAK7/X+5qg99MUgsfra3k+MXXX0vWROOy8mM6/dBaaDb7tg==} + '@rspack/binding-darwin-arm64': 0.4.5 + '@rspack/binding-darwin-x64': 0.4.5 + '@rspack/binding-linux-arm64-gnu': 0.4.5 + '@rspack/binding-linux-arm64-musl': 0.4.5 + '@rspack/binding-linux-x64-gnu': 0.4.5 + '@rspack/binding-linux-x64-musl': 0.4.5 + '@rspack/binding-win32-arm64-msvc': 0.4.5 + '@rspack/binding-win32-ia32-msvc': 0.4.5 + '@rspack/binding-win32-x64-msvc': 0.4.5 + dev: true + + /@rspack/core@0.4.5(patch_hash=vl6m5tsr4v2bh4wx2ltp22ktf4): + resolution: {integrity: sha512-X29fvCqTJH9OYN5pqa2lYP9hBLGICGVugtpTIAyLtMxC7gqvjvZkG/qisaVsjPyg4p2eB0NvmosnHkRv0GJ4sg==} engines: {node: '>=16.0.0'} dependencies: - '@rspack/binding': 0.4.3 + '@module-federation/runtime-tools': 0.0.0-next-20231225095220 + '@rspack/binding': 0.4.5 '@swc/helpers': 0.5.1 browserslist: 4.22.1 compare-versions: 6.0.0-rc.1 enhanced-resolve: 5.12.0 - fast-querystring: 1.1.2 graceful-fs: 4.2.10 json-parse-even-better-errors: 3.0.0 neo-async: 2.6.2 @@ -8032,20 +8059,21 @@ packages: zod: 3.22.3 zod-validation-error: 1.3.1(zod@3.22.3) dev: true + patched: true - /@rspack/dev-server@0.4.3(@rspack/core@0.4.3)(@swc/core@1.3.80)(esbuild@0.17.16)(react-refresh@0.14.0): + /@rspack/dev-server@0.4.3(@rspack/core@0.4.5)(@types/express@4.17.17)(esbuild@0.17.16): resolution: {integrity: sha512-qbggWEySoWdCrbWxqV+HX7nXgyT6qE3DqGtdYKzX9RLPp+RilXtnPlXtwY1AXNh8e0gYe1dMpvTcHYxeSglZSg==} peerDependencies: '@rspack/core': '*' dependencies: - '@rspack/core': 0.4.3 + '@rspack/core': 0.4.5(patch_hash=vl6m5tsr4v2bh4wx2ltp22ktf4) '@rspack/plugin-react-refresh': 0.4.3(react-refresh@0.14.0) chokidar: 3.5.3 connect-history-api-fallback: 2.0.0 express: 4.18.1 http-proxy-middleware: 2.0.6(@types/express@4.17.17) mime-types: 2.1.35 - webpack: 5.76.0(@swc/core@1.3.80)(esbuild@0.17.16) + webpack: 5.76.0(esbuild@0.17.16) webpack-dev-middleware: 6.0.2(webpack@5.76.0) webpack-dev-server: 4.13.1(webpack@5.76.0) ws: 8.8.1 @@ -8062,19 +8090,19 @@ packages: - webpack-cli dev: true - /@rspack/dev-server@0.4.3(@rspack/core@0.4.3)(@types/express@4.17.17)(esbuild@0.17.16): - resolution: {integrity: sha512-qbggWEySoWdCrbWxqV+HX7nXgyT6qE3DqGtdYKzX9RLPp+RilXtnPlXtwY1AXNh8e0gYe1dMpvTcHYxeSglZSg==} + /@rspack/dev-server@0.4.5(@rspack/core@0.4.5)(@swc/core@1.3.80)(esbuild@0.17.16)(react-refresh@0.14.0): + resolution: {integrity: sha512-g9FxWfII5gr/Z6Tav235RMYeqbJiTS89dBmD+CE5xedJ1EmOiAV5jlDQnpaTpecwwjjDV8Bq+rk7wtOOHzstSg==} peerDependencies: '@rspack/core': '*' dependencies: - '@rspack/core': 0.4.3 - '@rspack/plugin-react-refresh': 0.4.3(react-refresh@0.14.0) + '@rspack/core': 0.4.5(patch_hash=vl6m5tsr4v2bh4wx2ltp22ktf4) + '@rspack/plugin-react-refresh': 0.4.5(react-refresh@0.14.0) chokidar: 3.5.3 connect-history-api-fallback: 2.0.0 express: 4.18.1 http-proxy-middleware: 2.0.6(@types/express@4.17.17) mime-types: 2.1.35 - webpack: 5.76.0(esbuild@0.17.16) + webpack: 5.76.0(@swc/core@1.3.80)(esbuild@0.17.16) webpack-dev-middleware: 6.0.2(webpack@5.76.0) webpack-dev-server: 4.13.1(webpack@5.76.0) ws: 8.8.1 @@ -8102,6 +8130,17 @@ packages: react-refresh: 0.14.0 dev: true + /@rspack/plugin-react-refresh@0.4.5(react-refresh@0.14.0): + resolution: {integrity: sha512-VGauW5J2r8zX+y2DlX1oPHPlruEHM9O+8faLfWWOJF0Gylra+WGD9STWbR+XcYJsCnDzbTzIL5gOq4cQbINcYg==} + peerDependencies: + react-refresh: '>=0.10.0 <1.0.0' + peerDependenciesMeta: + react-refresh: + optional: true + dependencies: + react-refresh: 0.14.0 + dev: true + /@sideway/address@4.1.4: resolution: {integrity: sha512-7vwq+rOHVWjyXxVlR76Agnvhy8I9rpzjosTESvmhNeXOXdZZB15Fl+TI9x1SiHZH5Jv2wTGduSxFDIaq0m3DUw==} dependencies: @@ -13968,6 +14007,7 @@ packages: /fast-decode-uri-component@1.0.1: resolution: {integrity: sha512-WKgKWg5eUxvRZGwW8FvfbaH7AXSh2cL+3j5fMGzUMCxWBJ3dV3a7Wz8y2f/uQ0e3B6WmodD3oS54jTQ9HVTIIg==} + dev: false /fast-deep-equal@3.1.3: resolution: {integrity: sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==} @@ -14012,6 +14052,7 @@ packages: resolution: {integrity: sha512-g6KuKWmFXc0fID8WWH0jit4g0AGBoJhCkJMb1RmbsSEUNvQ+ZC8D6CUZ+GtF8nMzSPXnhiePyyqqipzNNEnHjg==} dependencies: fast-decode-uri-component: 1.0.1 + dev: false /fast-url-parser@1.1.3: resolution: {integrity: sha512-5jOCVXADYNuRkKFzNJ0dCCewsZiYo0dz8QNYljkOpFC6r2U4OBmKtvm/Tsuh4w1YYdDqDb31a8TVhBJ2OJKdqQ==} diff --git a/website/docs/guide/advanced/keep-alive.md b/website/docs/guide/advanced/keep-alive.md index adca65784c..65c08257db 100644 --- a/website/docs/guide/advanced/keep-alive.md +++ b/website/docs/guide/advanced/keep-alive.md @@ -47,13 +47,13 @@ export default function Layout() { ## 缓存其他组件 -除了缓存路由组件,还可以直接使用 React 18 提供的实验特性 `` 组件,进一步缓存更细粒度的组件。 +除了缓存路由组件,还可以直接使用 React 18 提供的实验特性 `` 组件,进一步缓存更细粒度的组件。 ```tsx import React from 'react'; // @ts-ignore -const Offscreen = React.unstable_Offscreen; +const Activity = React.unstable_Activity; export default function Home() { const [auth, setAuth] = React.useState('admin'); @@ -65,12 +65,12 @@ export default function Home() { <> - + Admin Name: - - + + User Name: - + )