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/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) { 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]; } } 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, 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 5dbeb054cf..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" }, @@ -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..d3ea8aca51 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<CompatRaxOptions> = (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,13 +103,30 @@ const plugin: Plugin<CompatRaxOptions> = (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' - ? 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 +159,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, ); }, @@ -147,7 +170,7 @@ const plugin: Plugin<CompatRaxOptions> = (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, +}; 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