Skip to content

Commit

Permalink
Merge pull request #6550 from alibaba/release/next
Browse files Browse the repository at this point in the history
Release 3.3.4
  • Loading branch information
ClarkXia authored Oct 12, 2023
2 parents 7a70372 + c6386d9 commit 99635bc
Show file tree
Hide file tree
Showing 49 changed files with 390 additions and 61 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ node_modules/
dist/
out/
compiled/
public/

# node 覆盖率文件
coverage/
Expand Down
6 changes: 3 additions & 3 deletions examples/basic-project/src/app.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineAppConfig, defineDataLoader } from 'ice';
import { defineAppConfig, defineDataLoader, defineRunApp } from 'ice';
import { isWeb, isNode } from '@uni/env';

if (process.env.ICE_CORE_ERROR_BOUNDARY === 'true') {
Expand Down Expand Up @@ -43,6 +43,6 @@ export const dataLoader = defineDataLoader(() => {
});
});

export const runApp = (render) => {
export const runApp = defineRunApp((render) => {
render();
};
});
4 changes: 4 additions & 0 deletions examples/csr-project/ice.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ export default defineConfig(() => ({
}
return webpackConfig;
},
server: {
onDemand: true,
format: 'esm',
},
dropLogLevel: 'warn',
plugins: [
auth(),
Expand Down
4 changes: 3 additions & 1 deletion examples/hash-router/src/pages/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { Outlet } from 'ice';
import { Outlet, useConfig } from 'ice';

export default () => {
const config = useConfig();
return (
<div>
<h1>Layout</h1>
<h3>{config.title}</h3>
<Outlet />
</div>
);
Expand Down
13 changes: 13 additions & 0 deletions examples/icestark-layout/ice.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,18 @@ export default defineConfig(() => ({
icestark({
type: 'framework',
}),
{
setup({ onGetConfig }) {
// Enable option `enableCopyPlugin`, so devserver can access public folder when run test.
if (process.env.NODE_ENV === 'test') {
onGetConfig((config) => {
return {
...config,
enableCopyPlugin: true,
}
});
}
}
}
]
}));

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions examples/icestark-layout/public/page-seller/assets/index.js

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions examples/icestark-layout/public/page-seller/assets/vendor.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions examples/icestark-layout/public/page-seller/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!DOCTYPE html><html><head><meta charset="utf-8"><meta http-equiv="x-ua-compatible" content="ie=edge,chrome=1"><meta name="viewport" content="width=device-width"><title>icestark</title><link rel="stylesheet" href="/page-seller/assets/index.css"></head><body><div id="ice-container"></div><script type="module" src="/page-seller/assets/index.js"></script><script type="module" src="/page-seller/assets/vendor.js"></script></body></html>

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

1 change: 1 addition & 0 deletions examples/icestark-layout/public/page-waiter/assets/main.js

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

5 changes: 5 additions & 0 deletions examples/icestark-layout/public/page-waiter/assets/vendor.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions examples/icestark-layout/public/page-waiter/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!doctype html><html lang="en"><head><meta charset="UTF-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><title>Vite App</title><link rel="stylesheet" href="/page-waiter/assets/main.css"></head><body><div id="app"></div><script type="module" src="/page-waiter/assets/main.js"></script></body></html>
4 changes: 2 additions & 2 deletions examples/icestark-layout/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ export const icestark = defineFrameworkConfig(() => ({
path: '/seller',
title: '商家平台',
loadScriptMode: 'import',
entry: 'https://iceworks.oss-cn-hangzhou.aliyuncs.com/icestark/child-seller-ice-vite/index.html',
entry: '/page-seller/index.html',
}, {
path: '/waiter',
title: '小二平台',
loadScriptMode: 'import',
entry: 'https://iceworks.oss-cn-hangzhou.aliyuncs.com/icestark/child-vue3-vite/index.html',
entry: '/page-waiter/index.html',
}]),
}));

Expand Down
21 changes: 21 additions & 0 deletions packages/ice/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
# Changelog

## 3.3.4

### Patch Changes

- ca14f6d3: fix: compatible with configureWebpack in speedup mode
- 244bb17f: add typesVersions for export fields support
- 6f18c3db: fix: deal with json file when use on-demand compile
- 1de19371: feat: add type definition of runApp
- 7924f2d1: fix: return render root
- 93e868d3: fix: hasDocument should check jsx
- aa29b37b: fix: get flatten routes which nested level more than 3
- Updated dependencies [ca14f6d3]
- Updated dependencies [df854102]
- Updated dependencies [50efd1ee]
- Updated dependencies [4d256e30]
- Updated dependencies [50efd1ee]
- @ice/webpack-config@1.1.4
- @ice/rspack-config@1.0.5
- @ice/shared-config@1.1.0
- @ice/runtime@1.3.0

## 3.3.3

### Patch Changes
Expand Down
25 changes: 19 additions & 6 deletions packages/ice/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ice/app",
"version": "3.3.3",
"version": "3.3.4",
"description": "provide scripts and configuration used by web framework ice",
"type": "module",
"main": "./esm/index.js",
Expand All @@ -10,6 +10,19 @@
"./analyze": "./esm/service/analyze.js",
"./service": "./esm/createService.js"
},
"typesVersions": {
"*": {
"types": [
"./esm/types/index.d.ts"
],
"analyze": [
"./esm/service/analyze.d.ts"
],
"service": [
"./esm/createService.d.ts"
]
}
},
"bin": {
"ice": "./bin/ice-cli.mjs"
},
Expand Down Expand Up @@ -39,10 +52,10 @@
"dependencies": {
"@ice/bundles": "0.1.16",
"@ice/route-manifest": "1.2.2",
"@ice/runtime": "^1.2.9",
"@ice/shared-config": "1.0.4",
"@ice/webpack-config": "1.1.3",
"@ice/rspack-config": "1.0.4",
"@ice/runtime": "^1.3.0",
"@ice/shared-config": "1.1.0",
"@ice/webpack-config": "1.1.4",
"@ice/rspack-config": "1.0.5",
"@swc/helpers": "0.5.1",
"@types/express": "^4.17.14",
"address": "^1.1.2",
Expand Down Expand Up @@ -98,4 +111,4 @@
"publishConfig": {
"access": "public"
}
}
}
7 changes: 5 additions & 2 deletions packages/ice/src/bundler/rspack/getConfig.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import getRspackConfig from '@ice/rspack-config';
import type { Configuration } from '@rspack/core';
import type { rspack as Rspack } from '@ice/bundles/esm/rspack.js';
import type { Config } from '@ice/shared-config/types';
import { getRouteExportConfig } from '../../service/config.js';
import {
Expand All @@ -16,10 +17,11 @@ import type { BundlerOptions, Context } from '../types.js';

type GetConfig = (
context: Context,
options: BundlerOptions
options: BundlerOptions,
rspack: typeof Rspack,
) => Promise<Configuration[]>;

const getConfig: GetConfig = async (context, options) => {
const getConfig: GetConfig = async (context, options, rspack) => {
const {
taskConfigs,
spinner,
Expand Down Expand Up @@ -73,6 +75,7 @@ const getConfig: GetConfig = async (context, options) => {
const plugins = getPlugins(config);
return getRspackConfig({
rootDir,
rspack,
runtimeTmpDir: RUNTIME_TMP_DIR,
runtimeDefineVars: {
[IMPORT_META_TARGET]: JSON.stringify(config.target),
Expand Down
5 changes: 2 additions & 3 deletions packages/ice/src/bundler/rspack/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@ async function bundler(
routeManifest,
appConfig,
} = options;
const rspackConfigs = await getConfig(context, options);

let compiler: MultiCompiler;
let devServer: RspackDevServer;
const { rspack } = await import('@ice/bundles/esm/rspack.js');
const rspackConfigs = await getConfig(context, options, rspack);
try {
const { rspack } = await import('@ice/bundles/esm/rspack.js');
compiler = rspack(rspackConfigs);
} catch (error) {
logger.error('Webpack compile error.');
Expand Down
2 changes: 1 addition & 1 deletion packages/ice/src/createService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ async function createService({ rootDir, command, commandArgs }: CreateServiceOpt
enableRoutes: true,
entryCode,
jsOutput: distType.includes('javascript'),
hasDocument: fse.existsSync(path.join(rootDir, 'src/document.tsx')),
hasDocument: fse.existsSync(path.join(rootDir, 'src/document.tsx')) || fse.existsSync(path.join(rootDir, 'src/document.jsx')) || fse.existsSync(path.join(rootDir, 'src/document.js')),
dataLoader: userConfig.dataLoader,
routeImports,
routeDefinition,
Expand Down
21 changes: 18 additions & 3 deletions packages/ice/src/service/ServerRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ interface InitOptions {
type ResolveCallback = Parameters<PluginBuild['onResolve']>[1];
type LoadCallback = Parameters<PluginBuild['onLoad']>[1];

const FALLBACK_LOADERS = {
'.json': 'json',
'.txt': 'text',
};

function getPluginLifecycle(plugin: Plugin, compiler: 'onLoad'): [OnResolveOptions, LoadCallback][];
function getPluginLifecycle(plugin: Plugin, compiler: 'onResolve'): [OnResolveOptions, ResolveCallback][];
function getPluginLifecycle(plugin: Plugin, hookKey: 'onResolve' | 'onLoad') {
Expand Down Expand Up @@ -67,7 +72,7 @@ async function transformJsxRuntime(source: string) {
}
// JSX runtime is added after swc plugins
// use es-module-lexer to replace the import statement.
if (imp.n === '@ice/runtime/jsx-dev-runtime') {
if (imp.n === '@ice/runtime/jsx-dev-runtime' || imp.n === '@ice/runtime/react/jsx-dev-runtime') {
str().overwrite(
imp.ss,
imp.se,
Expand Down Expand Up @@ -263,11 +268,21 @@ class ServerRunner extends Runner {
...args,
path: formatedId,
});

// If res is undefined, it means the plugin does not handle the file, fallback to default handler.
if (!res && FALLBACK_LOADERS[path.extname(formatedId)]) {
res = {
loader: FALLBACK_LOADERS[path.extname(formatedId)],
};
}
if (res) {
const { contents, loader } = res;
if (['json', 'text'].includes(loader)) {
code = `__ice_exports__.default = ${contents || JSON.stringify(await fse.readFile(formatedId, 'utf-8'))}`;
if (contents) {
code = `__ice_exports__.default = ${contents}`;
} else {
const contents = await fse.readFile(formatedId, 'utf-8');
code = `__ice_exports__.default = ${loader === 'text' ? JSON.stringify(contents) : contents}`;
}
} else {
code = typeof contents === 'string' ? contents : contents.toString();
}
Expand Down
6 changes: 3 additions & 3 deletions packages/ice/src/utils/getRoutePaths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import formatPath from './formatPath.js';
*/
export default function getRoutePaths(routes: NestedRouteManifest[], parentPath = ''): string[] {
let pathList = [];

routes.forEach(route => {
const routePath = formatPath(path.join('/', parentPath.replace(/^\//, ''), route.path || ''));
if (route.children) {
pathList = pathList.concat(getRoutePaths(route.children, route.path));
pathList = pathList.concat(getRoutePaths(route.children, routePath));
} else {
pathList.push(formatPath(path.join('/', parentPath, route.path || '')));
pathList.push(routePath);
}
});

Expand Down
2 changes: 1 addition & 1 deletion packages/ice/templates/core/entry.client.tsx.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const renderApp = (appExport: any, customOptions: Partial<RunClientAppOptions>)
};

const render = (customOptions: Partial<RunClientAppOptions> = {}) => {
renderApp(app, customOptions);
return renderApp(app, customOptions);
};

<%- entryCode %>
Expand Down
3 changes: 2 additions & 1 deletion packages/ice/templates/core/index.ts.ejs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<% if (globalStyle) {-%>
import '<%= globalStyle %>'
<% } -%>
import { definePageConfig } from './type-defines';
import { definePageConfig, defineRunApp } from './type-defines';
<%- framework.imports %>

<%- framework.variablesStr %>
<%- framework.targetImport %>

export {
definePageConfig,
defineRunApp,
<% if (framework.exports) { -%><%- framework.exports %><% } -%>
<% if (framework.targetExports) { -%><%- framework.targetExports %><% } -%>

Expand Down
10 changes: 9 additions & 1 deletion packages/ice/templates/core/type-defines.ts.ejs
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import type ReactDOM from 'react-dom/client';
import type { RunClientAppOptions } from '@ice/runtime';
import type { PageConfig, PageConfigDefinition } from './types';

// Only used for type defination.
// Only used for type defination of pageConfig.
export function definePageConfig(pageConfig: PageConfig | PageConfigDefinition): PageConfigDefinition {
if (typeof pageConfig !== 'function') {
return () => pageConfig;
} else {
return pageConfig;
}
}

// Only used for type defination of runApp.
type RunApp = (render: (customOptions?: Partial<RunClientAppOptions>) => Promise<ReactDOM.Root>, options?: RunClientAppOptions) => void;
export function defineRunApp(runApp: RunApp): RunApp {
return runApp;
}
Loading

0 comments on commit 99635bc

Please sign in to comment.