From 4816afb55803f289dd59cad524b0e21afd12b937 Mon Sep 17 00:00:00 2001 From: linbudu599 Date: Thu, 12 Oct 2023 15:35:25 +0800 Subject: [PATCH 1/6] fix: provide missing export for rax-compat --- .changeset/empty-islands-unite.md | 5 ++++ packages/plugin-rax-compat/package.json | 6 ++-- packages/plugin-rax-compat/src/index.ts | 28 +++++++++++++++++-- .../src/rax-compat-legacy-exports.ts.template | 22 +++++++++++++++ 4 files changed, 56 insertions(+), 5 deletions(-) create mode 100644 .changeset/empty-islands-unite.md create mode 100644 packages/plugin-rax-compat/src/rax-compat-legacy-exports.ts.template diff --git a/.changeset/empty-islands-unite.md b/.changeset/empty-islands-unite.md new file mode 100644 index 0000000000..b5b91ea170 --- /dev/null +++ b/.changeset/empty-islands-unite.md @@ -0,0 +1,5 @@ +--- +'@ice/plugin-rax-compat': minor +--- + +support legacy option for legacy rax compat diff --git a/packages/plugin-rax-compat/package.json b/packages/plugin-rax-compat/package.json index 5dbeb054cf..4d5e1b6f19 100644 --- a/packages/plugin-rax-compat/package.json +++ b/packages/plugin-rax-compat/package.json @@ -40,9 +40,11 @@ }, "scripts": { "watch": "tsc -w --sourceMap", - "build": "tsc && cp src/rax-compat.d.ts esm/rax-compat.d.ts" + "copy:dts": "cp src/rax-compat.d.ts esm/rax-compat.d.ts", + "copy:legacy": "cp src/rax-compat-legacy-exports.ts.template esm/rax-compat-legacy-exports.ts.template", + "build": "tsc && npm run copy:dts && npm run copy:legacy" }, "publishConfig": { "access": "public" } -} +} \ No newline at end of file diff --git a/packages/plugin-rax-compat/src/index.ts b/packages/plugin-rax-compat/src/index.ts index 76e1e1f0ee..5fc9fd844c 100644 --- a/packages/plugin-rax-compat/src/index.ts +++ b/packages/plugin-rax-compat/src/index.ts @@ -4,7 +4,6 @@ import { fileURLToPath } from 'url'; import { createRequire } from 'module'; import type { Plugin } from '@ice/app/types'; import type { RuleSetRule } from 'webpack'; -import consola from 'consola'; import { merge, cloneDeep } from 'lodash-es'; import { transformSync } from '@babel/core'; import styleSheetLoader from './transform-styles.js'; @@ -78,12 +77,19 @@ export interface CompatRaxOptions { * @default true */ cssModule?: boolean; + /** + * Compat for legacy rax version(`v 0.6.x`), add `PropTypes` as exports. + * + * @default false + */ + legacy?: boolean; } const plugin: Plugin = (options = {}) => ({ name: '@ice/plugin-rax-compat', - setup: ({ onGetConfig, context, generator }) => { + setup: ({ onGetConfig, context, generator, createLogger }) => { const { userConfig } = context; + const logger = createLogger('plugin-rax-compat'); onGetConfig((config) => { // Inject rax-compat type fix in .ice/rax-compat.d.ts @@ -97,6 +103,22 @@ const plugin: Plugin = (options = {}) => ({ type: false, }); + if (options.legacy) { + logger.warn('Legacy mode should only be used for compatibility with rax v0.6.x.'); + + const legacyEntryFile = 'rax-compat-legacy-exports.ts'; + + // Create .ice/rax-compat-legacy-exports.ts as rax entry in legacy mode. + generator.addRenderFile( + path.join(__dirname, './', `${legacyEntryFile}.template`), + legacyEntryFile, + {}, + ); + + // Update alias to use rax-compat-legacy-exports.ts as rax entry. + alias.rax = path.join(context.rootDir, '.ice', legacyEntryFile); + } + // TODO: optimize the logic, support deep merge in plugin API. // Must create a variable to store the original compilationConfig. const originalSwcCompilationConfig = typeof config.swcOptions?.compilationConfig === 'object' @@ -147,7 +169,7 @@ const plugin: Plugin = (options = {}) => ({ if (options.inlineStyle) { if (!warnOnce) { - consola.warn('Enabling inline style is not recommended.\n It is recommended to use CSS modules (as default). Only allow old projects to migrate and use.'); + logger.warn('Enabling inline style is not recommended.\n It is recommended to use CSS modules (as default). Only allow old projects to migrate and use.'); warnOnce = true; } diff --git a/packages/plugin-rax-compat/src/rax-compat-legacy-exports.ts.template b/packages/plugin-rax-compat/src/rax-compat-legacy-exports.ts.template new file mode 100644 index 0000000000..eea9b75e18 --- /dev/null +++ b/packages/plugin-rax-compat/src/rax-compat-legacy-exports.ts.template @@ -0,0 +1,22 @@ +export * from 'rax-compat'; + +const typeChecker = () => {}; + +export const PropTypes = { + array: typeChecker, + bool: typeChecker, + func: typeChecker, + number: typeChecker, + object: typeChecker, + string: typeChecker, + symbol: typeChecker, + element: typeChecker, + node: typeChecker, + any: typeChecker, + arrayOf: typeChecker, + instanceOf: typeChecker, + objectOf: typeChecker, + oneOf: typeChecker, + oneOfType: typeChecker, + shape: typeChecker, +}; From 3896cbeabb7023589f40597ac6a3cc4fd94d12d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9F=93=E9=99=8C=E5=90=8C=E5=AD=A6?= Date: Tue, 17 Oct 2023 00:23:18 -0700 Subject: [PATCH 2/6] Feat/support defult document (#6580) * feat: support default document * chore: add changeset --- .changeset/swift-cobras-shop.md | 5 +++++ packages/ice/templates/core/document.tsx.ejs | 21 +++++++++++++++++++ .../ice/templates/core/entry.server.ts.ejs | 6 +++--- 3 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 .changeset/swift-cobras-shop.md create mode 100644 packages/ice/templates/core/document.tsx.ejs diff --git a/.changeset/swift-cobras-shop.md b/.changeset/swift-cobras-shop.md new file mode 100644 index 0000000000..033aa8c391 --- /dev/null +++ b/.changeset/swift-cobras-shop.md @@ -0,0 +1,5 @@ +--- +'@ice/app': patch +--- + +feat: support default document diff --git a/packages/ice/templates/core/document.tsx.ejs b/packages/ice/templates/core/document.tsx.ejs new file mode 100644 index 0000000000..41aa063900 --- /dev/null +++ b/packages/ice/templates/core/document.tsx.ejs @@ -0,0 +1,21 @@ +import { Meta, Title, Links, Main, Scripts } from 'ice'; + +function Document() { + return ( + + + + + + + <Links /> + </head> + <body> + <Main /> + <Scripts /> + </body> + </html> + ); +} + +export default Document; diff --git a/packages/ice/templates/core/entry.server.ts.ejs b/packages/ice/templates/core/entry.server.ts.ejs index bbdead1638..00d0322ebf 100644 --- a/packages/ice/templates/core/entry.server.ts.ejs +++ b/packages/ice/templates/core/entry.server.ts.ejs @@ -6,7 +6,9 @@ import { commons, statics } from './runtime-modules'; import * as app from '@/app'; <% if (hasDocument) {-%> import * as Document from '@/document'; -<% }-%> +<% } else { -%> +import * as Document from './document'; +<% } -%> import type { RenderMode, DistType } from '@ice/runtime'; import type { RenderToPipeableStreamOptions } from 'react-dom/server'; // @ts-ignore @@ -92,10 +94,8 @@ function mergeOptions(options) { assetsManifest, createRoutes, runtimeModules, - <% if (hasDocument) {-%> documentDataLoader: Document.dataLoader, Document: Document.default, - <% }-%> basename: basename || getRouterBasename(), renderMode, routesConfig, From 042b49b1776c2b6c9b9eb9687ec48ab8f708618b Mon Sep 17 00:00:00 2001 From: luhc228 <luhengchang228@126.com> Date: Tue, 17 Oct 2023 16:22:06 +0800 Subject: [PATCH 3/6] refactor: remove cloneDeep (#6576) * refactor: remove cloneDeep * fix: ci fail * fix: remove deepClone * chore: changeset --- .changeset/sixty-olives-shake.md | 5 +++++ packages/plugin-rax-compat/src/index.ts | 11 ++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) create mode 100644 .changeset/sixty-olives-shake.md diff --git a/.changeset/sixty-olives-shake.md b/.changeset/sixty-olives-shake.md new file mode 100644 index 0000000000..ca80244d45 --- /dev/null +++ b/.changeset/sixty-olives-shake.md @@ -0,0 +1,5 @@ +--- +'@ice/plugin-rax-compat': patch +--- + +refactor: remove cloneDeep for performance diff --git a/packages/plugin-rax-compat/src/index.ts b/packages/plugin-rax-compat/src/index.ts index 76e1e1f0ee..43af1af2a2 100644 --- a/packages/plugin-rax-compat/src/index.ts +++ b/packages/plugin-rax-compat/src/index.ts @@ -100,10 +100,11 @@ const plugin: Plugin<CompatRaxOptions> = (options = {}) => ({ // TODO: optimize the logic, support deep merge in plugin API. // Must create a variable to store the original compilationConfig. const originalSwcCompilationConfig = typeof config.swcOptions?.compilationConfig === 'object' - ? cloneDeep(config.swcOptions?.compilationConfig || {}) + ? cloneDeep(config.swcOptions.compilationConfig) : {}; - const compilationConfigFunc = typeof config.swcOptions?.compilationConfig === 'function' - ? config.swcOptions?.compilationConfig + + const originalSwcCompilationConfigFunc = typeof config.swcOptions?.compilationConfig === 'function' + ? config.swcOptions.compilationConfig : () => originalSwcCompilationConfig; // Reset jsc.transform.react.runtime to classic. @@ -136,8 +137,8 @@ const plugin: Plugin<CompatRaxOptions> = (options = {}) => ({ } return merge( - // Clone config object to avoid Maximum call stack size exceeded error. - cloneDeep(compilationConfigFunc(source, id)), + {}, + originalSwcCompilationConfigFunc(source, id), swcCompilationConfig, ); }, From d72753e271abc372453e14e67ea9da06c6b28c5d Mon Sep 17 00:00:00 2001 From: ClarkXia <xiawenwu41@gmail.com> Date: Tue, 17 Oct 2023 19:59:54 +0800 Subject: [PATCH 4/6] fix: do not prebundle node built-in module (#6581) --- .changeset/early-rings-develop.md | 5 +++++ packages/ice/src/service/onDemandPreBundle.ts | 2 +- packages/ice/src/service/preBundleDeps.ts | 2 +- packages/ice/src/service/serverCompiler.ts | 6 +++++- 4 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 .changeset/early-rings-develop.md diff --git a/.changeset/early-rings-develop.md b/.changeset/early-rings-develop.md new file mode 100644 index 0000000000..78669028a4 --- /dev/null +++ b/.changeset/early-rings-develop.md @@ -0,0 +1,5 @@ +--- +'@ice/app': patch +--- + +fix: do not prebundle node built-in module diff --git a/packages/ice/src/service/onDemandPreBundle.ts b/packages/ice/src/service/onDemandPreBundle.ts index 121562ca51..fa1b3be856 100644 --- a/packages/ice/src/service/onDemandPreBundle.ts +++ b/packages/ice/src/service/onDemandPreBundle.ts @@ -132,7 +132,7 @@ export default async function preBundleDeps(options: PreBundleOptions): Promise< rootDir, }); } catch (err) { - logger.error('Failed to bundle dependencies.'); + logger.error('Failed to bundle dependencies.', { [pkgName]: resolveId }); logger.error(err); return {}; } diff --git a/packages/ice/src/service/preBundleDeps.ts b/packages/ice/src/service/preBundleDeps.ts index fb4c4783c8..fe1d8c9f21 100644 --- a/packages/ice/src/service/preBundleDeps.ts +++ b/packages/ice/src/service/preBundleDeps.ts @@ -114,7 +114,7 @@ export default async function preBundleDeps( metadata, }; } catch (error) { - logger.briefError('Failed to bundle dependencies.'); + logger.briefError('Failed to bundle dependencies.', flatIdDeps); logger.debug(error); return {}; } diff --git a/packages/ice/src/service/serverCompiler.ts b/packages/ice/src/service/serverCompiler.ts index fd40727ea7..fe6c667176 100644 --- a/packages/ice/src/service/serverCompiler.ts +++ b/packages/ice/src/service/serverCompiler.ts @@ -2,6 +2,7 @@ import * as path from 'path'; import { esbuild } from '@ice/bundles'; import fse from 'fs-extra'; import fg from 'fast-glob'; +import { isNodeBuiltin } from 'mlly'; import type { Config } from '@ice/shared-config/types'; import lodash from '@ice/bundles/compiled/lodash/index.js'; import type { TaskConfig } from 'build-scripts'; @@ -303,7 +304,10 @@ async function createPreBundleDepsMetadata( function filterPreBundleDeps(deps: Record<string, DepScanData>) { const preBundleDepsInfo = {}; for (const dep in deps) { - if (!isExternalBuiltinDep(dep)) { + const { name } = deps[dep]; + // Filter the deps which do not aliased and is node builtin module. + const isNodeBuiltinDep = name === dep && isNodeBuiltin(dep); + if (!isExternalBuiltinDep(dep) && !isNodeBuiltinDep) { preBundleDepsInfo[dep] = deps[dep]; } } From 1234c257b6d03f993ab6b0b4fc75213cf29eb3b5 Mon Sep 17 00:00:00 2001 From: Linbudu <48507806+linbudu599@users.noreply.github.com> Date: Thu, 19 Oct 2023 11:54:16 +0800 Subject: [PATCH 5/6] chore: use patch release for rax-compat (#6594) --- .changeset/empty-islands-unite.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/empty-islands-unite.md b/.changeset/empty-islands-unite.md index b5b91ea170..01c632ad42 100644 --- a/.changeset/empty-islands-unite.md +++ b/.changeset/empty-islands-unite.md @@ -1,5 +1,5 @@ --- -'@ice/plugin-rax-compat': minor +'@ice/plugin-rax-compat': patch --- support legacy option for legacy rax compat From 6167358aff96dcec126e61402b2f4eff967e1f82 Mon Sep 17 00:00:00 2001 From: ClarkXia <xiawenwu41@gmail.com> Date: Thu, 19 Oct 2023 14:13:14 +0800 Subject: [PATCH 6/6] chore: update versions (#6587) --- .changeset/early-rings-develop.md | 5 ----- .changeset/empty-islands-unite.md | 5 ----- .changeset/sixty-olives-shake.md | 5 ----- .changeset/swift-cobras-shop.md | 5 ----- packages/ice/CHANGELOG.md | 7 +++++++ packages/ice/package.json | 2 +- packages/plugin-i18n/package.json | 2 +- packages/plugin-rax-compat/CHANGELOG.md | 7 +++++++ packages/plugin-rax-compat/package.json | 4 ++-- pnpm-lock.yaml | 2 +- 10 files changed, 19 insertions(+), 25 deletions(-) delete mode 100644 .changeset/early-rings-develop.md delete mode 100644 .changeset/empty-islands-unite.md delete mode 100644 .changeset/sixty-olives-shake.md delete mode 100644 .changeset/swift-cobras-shop.md diff --git a/.changeset/early-rings-develop.md b/.changeset/early-rings-develop.md deleted file mode 100644 index 78669028a4..0000000000 --- a/.changeset/early-rings-develop.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'@ice/app': patch ---- - -fix: do not prebundle node built-in module diff --git a/.changeset/empty-islands-unite.md b/.changeset/empty-islands-unite.md deleted file mode 100644 index 01c632ad42..0000000000 --- a/.changeset/empty-islands-unite.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'@ice/plugin-rax-compat': patch ---- - -support legacy option for legacy rax compat diff --git a/.changeset/sixty-olives-shake.md b/.changeset/sixty-olives-shake.md deleted file mode 100644 index ca80244d45..0000000000 --- a/.changeset/sixty-olives-shake.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'@ice/plugin-rax-compat': patch ---- - -refactor: remove cloneDeep for performance diff --git a/.changeset/swift-cobras-shop.md b/.changeset/swift-cobras-shop.md deleted file mode 100644 index 033aa8c391..0000000000 --- a/.changeset/swift-cobras-shop.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'@ice/app': patch ---- - -feat: support default document diff --git a/packages/ice/CHANGELOG.md b/packages/ice/CHANGELOG.md index bf07b0e5c2..21b39e2bac 100644 --- a/packages/ice/CHANGELOG.md +++ b/packages/ice/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## 3.3.5 + +### Patch Changes + +- d72753e2: fix: do not prebundle node built-in module +- 3896cbea: feat: support default document + ## 3.3.4 ### Patch Changes diff --git a/packages/ice/package.json b/packages/ice/package.json index 895f85cd78..c2218462e8 100644 --- a/packages/ice/package.json +++ b/packages/ice/package.json @@ -1,6 +1,6 @@ { "name": "@ice/app", - "version": "3.3.4", + "version": "3.3.5", "description": "provide scripts and configuration used by web framework ice", "type": "module", "main": "./esm/index.js", diff --git a/packages/plugin-i18n/package.json b/packages/plugin-i18n/package.json index a55cff0f2c..aad9cf7586 100644 --- a/packages/plugin-i18n/package.json +++ b/packages/plugin-i18n/package.json @@ -56,7 +56,7 @@ "webpack-dev-server": "^4.13.2" }, "peerDependencies": { - "@ice/app": "^3.3.4", + "@ice/app": "^3.3.5", "@ice/runtime": "^1.3.1" }, "publishConfig": { diff --git a/packages/plugin-rax-compat/CHANGELOG.md b/packages/plugin-rax-compat/CHANGELOG.md index d2010d077e..6068894273 100644 --- a/packages/plugin-rax-compat/CHANGELOG.md +++ b/packages/plugin-rax-compat/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## 0.2.9 + +### Patch Changes + +- 4816afb5: support legacy option for legacy rax compat +- 042b49b1: refactor: remove cloneDeep for performance + ## 0.2.8 ### Patch Changes diff --git a/packages/plugin-rax-compat/package.json b/packages/plugin-rax-compat/package.json index 4d5e1b6f19..a7149707d7 100644 --- a/packages/plugin-rax-compat/package.json +++ b/packages/plugin-rax-compat/package.json @@ -1,6 +1,6 @@ { "name": "@ice/plugin-rax-compat", - "version": "0.2.8", + "version": "0.2.9", "description": "Provide rax compat support for ice.js", "license": "MIT", "type": "module", @@ -30,7 +30,7 @@ "stylesheet-loader": "^0.9.1" }, "devDependencies": { - "@ice/app": "^3.3.4", + "@ice/app": "^3.3.5", "@types/lodash-es": "^4.17.7", "webpack": "^5.88.0" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 28a555ca3b..6cbe7c4efc 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1468,7 +1468,7 @@ importers: specifiers: '@babel/core': ^7.0.0 '@babel/plugin-proposal-export-default-from': ^7.18.9 - '@ice/app': ^3.3.4 + '@ice/app': ^3.3.5 '@ice/bundles': ^0.1.16 '@types/lodash-es': ^4.17.7 babel-plugin-transform-jsx-stylesheet: 1.0.6