Skip to content

Commit

Permalink
Merge pull request #6590 from alibaba/release/next
Browse files Browse the repository at this point in the history
Release 3.3.5
  • Loading branch information
ClarkXia authored Oct 19, 2023
2 parents a393ae9 + 6167358 commit 9585d65
Show file tree
Hide file tree
Showing 13 changed files with 107 additions and 21 deletions.
7 changes: 7 additions & 0 deletions packages/ice/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/ice/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/ice/src/service/onDemandPreBundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {};
}
Expand Down
2 changes: 1 addition & 1 deletion packages/ice/src/service/preBundleDeps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {};
}
Expand Down
6 changes: 5 additions & 1 deletion packages/ice/src/service/serverCompiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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];
}
}
Expand Down
21 changes: 21 additions & 0 deletions packages/ice/templates/core/document.tsx.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Meta, Title, Links, Main, Scripts } from 'ice';

function Document() {
return (
<html>
<head>
<meta charSet="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<Meta />
<Title />
<Links />
</head>
<body>
<Main />
<Scripts />
</body>
</html>
);
}

export default Document;
6 changes: 3 additions & 3 deletions packages/ice/templates/core/entry.server.ts.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -92,10 +94,8 @@ function mergeOptions(options) {
assetsManifest,
createRoutes,
runtimeModules,
<% if (hasDocument) {-%>
documentDataLoader: Document.dataLoader,
Document: Document.default,
<% }-%>
basename: basename || getRouterBasename(),
renderMode,
routesConfig,
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-i18n/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
7 changes: 7 additions & 0 deletions packages/plugin-rax-compat/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
10 changes: 6 additions & 4 deletions packages/plugin-rax-compat/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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"
},
Expand All @@ -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"
}
}
}
39 changes: 31 additions & 8 deletions packages/plugin-rax-compat/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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,
);
},
Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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,
};
2 changes: 1 addition & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9585d65

Please sign in to comment.