Skip to content

Commit

Permalink
Merge pull request #6541 from alibaba/release/next
Browse files Browse the repository at this point in the history
Release 3.3.3
  • Loading branch information
ClarkXia authored Sep 21, 2023
2 parents 6926c47 + 40f1071 commit adf1fa4
Show file tree
Hide file tree
Showing 33 changed files with 254 additions and 46 deletions.
3 changes: 3 additions & 0 deletions examples/basic-project/ice.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,7 @@ export default defineConfig(() => ({
customPlugin(),
],
eslint: true,
cssModules: {
localIdentName: '[hash:8]',
},
}));
12 changes: 12 additions & 0 deletions packages/ice/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Changelog

## 3.3.3

### Patch Changes

- c3a9c20a: chore: modify output
- 82702258: feat: compat no document
- 78f850fa: feat: support hash only class name for css modules
- Updated dependencies [78f850fa]
- @ice/webpack-config@1.1.3
- @ice/shared-config@1.0.4
- @ice/rspack-config@1.0.4

## 3.3.2

### Patch Changes
Expand Down
8 changes: 4 additions & 4 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.2",
"version": "3.3.3",
"description": "provide scripts and configuration used by web framework ice",
"type": "module",
"main": "./esm/index.js",
Expand Down Expand Up @@ -40,9 +40,9 @@
"@ice/bundles": "0.1.16",
"@ice/route-manifest": "1.2.2",
"@ice/runtime": "^1.2.9",
"@ice/shared-config": "1.0.3",
"@ice/webpack-config": "1.1.2",
"@ice/rspack-config": "1.0.3",
"@ice/shared-config": "1.0.4",
"@ice/webpack-config": "1.1.3",
"@ice/rspack-config": "1.0.4",
"@swc/helpers": "0.5.1",
"@types/express": "^4.17.14",
"address": "^1.1.2",
Expand Down
4 changes: 2 additions & 2 deletions packages/ice/src/bundler/config/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export async function getOutputPaths(options: {
}
}
if (serverEntry && userConfig.htmlGenerating) {
outputPaths = await buildCustomOuputs(rootDir, outputDir, serverEntry, bundleOptions);
outputPaths = await buildCustomOutputs(rootDir, outputDir, serverEntry, bundleOptions);
}
return outputPaths;
}
Expand All @@ -32,7 +32,7 @@ export async function removeServerOutput(outputDir: string, ssr: boolean) {
}
}
// Build custom outputs such html and js file for weex.
async function buildCustomOuputs(
async function buildCustomOutputs(
rootDir: string,
outputDir: string,
serverEntry: string,
Expand Down
8 changes: 8 additions & 0 deletions packages/ice/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,14 @@ const userConfig = [
return mergeDefaultValue(config, 'postcss', postcss);
},
},
{
name: 'cssModules',
validation: 'object',
defaultValue: {},
setConfig(config: Config, postcss: UserConfig['cssModules']) {
return mergeDefaultValue(config, 'cssModules', postcss);
},
},
{
name: 'webpack',
validation: 'function',
Expand Down
2 changes: 2 additions & 0 deletions packages/ice/src/createService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Context } from 'build-scripts';
import type { CommandArgs, CommandName } from 'build-scripts';
import type { Config } from '@ice/shared-config/types';
import type { AppConfig } from '@ice/runtime/types';
import fse from 'fs-extra';
import webpack from '@ice/bundles/compiled/webpack/index.js';
import type {
DeclarationData,
Expand Down Expand Up @@ -274,6 +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')),
dataLoader: userConfig.dataLoader,
routeImports,
routeDefinition,
Expand Down
9 changes: 6 additions & 3 deletions packages/ice/src/service/ServerRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,16 @@ class ServerRunner extends Runner {
},
},
}, 'esbuild', { isServer: true });
const { alias, ignores } = filterAlias(task.config.alias || {});
const define = getRuntimeDefination(task.config.define || {});
const taskConfig = task.config;
const { alias, ignores } = filterAlias(taskConfig.alias || {});
const define = getRuntimeDefination(taskConfig.define || {});
const runtimeMeta = new RuntimeMeta({
rootDir,
alias,
ignores,
external: server.externals || [],
define,
taskConfig,
speedup,
});

Expand All @@ -140,8 +142,9 @@ class ServerRunner extends Runner {
// ServerRunner only works in development mode.
mode: 'development',
fileName,
localIdentName: name,
localName: name,
rule: speedup ? 'native' : 'loader',
localIdentName: taskConfig.cssModules?.localIdentName,
});
},
}),
Expand Down
8 changes: 7 additions & 1 deletion packages/ice/src/service/onDemandPreBundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { createRequire } from 'module';
import fse from 'fs-extra';
import findUp from 'find-up';
import type { Plugin } from 'esbuild';
import type { Config } from '@ice/shared-config/types';
import { logger } from '../utils/logger.js';
import { CACHE_DIR } from '../constant.js';
import { bundleDeps, resolvePackageESEntry, getDepsCacheDir } from './preBundleDeps.js';
Expand All @@ -24,6 +25,7 @@ interface PreBundleOptions {
plugins?: Plugin[];
external?: string[];
define?: Record<string, string>;
taskConfig?: Config;
speedup?: boolean;
}

Expand All @@ -36,6 +38,7 @@ export class RuntimeMeta {
private cachePath: string;
private external: string[];
private define: Record<string, string>;
private taskConfig: Config;
private speedup: boolean;

constructor(options: Omit<PreBundleOptions, 'pkgName' | 'resolveId'>) {
Expand All @@ -47,6 +50,7 @@ export class RuntimeMeta {
this.define = options.define;
this.speedup = options.speedup;
this.cachePath = path.join(getDepsCacheDir(path.join(this.rootDir, CACHE_DIR)), 'metadata.json');
this.taskConfig = options.taskConfig;
}

async getDepsCache() {
Expand Down Expand Up @@ -100,6 +104,7 @@ export class RuntimeMeta {
define: this.define,
pkgName: pkgName,
resolveId,
taskConfig: this.taskConfig,
speedup: this.speedup,
});
await this.setDepsCache(pkgName, resolveId, bundlePath);
Expand All @@ -111,7 +116,7 @@ export class RuntimeMeta {
}

export default async function preBundleDeps(options: PreBundleOptions): Promise<PreBundleResult> {
const { rootDir, pkgName, alias, ignores, plugins, resolveId, external, define, speedup } = options;
const { rootDir, pkgName, alias, ignores, plugins, resolveId, external, define, speedup, taskConfig } = options;
const depsCacheDir = getDepsCacheDir(path.join(rootDir, CACHE_DIR));
try {
await bundleDeps({
Expand All @@ -122,6 +127,7 @@ export default async function preBundleDeps(options: PreBundleOptions): Promise<
plugins: plugins || [],
external,
define,
taskConfig,
speedup,
rootDir,
});
Expand Down
7 changes: 5 additions & 2 deletions packages/ice/src/service/preBundleDeps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export default async function preBundleDeps(
alias,
external,
define,
taskConfig,
speedup,
});

Expand All @@ -129,9 +130,10 @@ export async function bundleDeps(options:
plugins: Plugin[];
external: string[];
define: BuildOptions['define'];
taskConfig: Config;
speedup?: boolean;
}) {
const { entryPoints, outdir, alias, ignores, plugins, external, define, speedup, rootDir } = options;
const { entryPoints, outdir, alias, ignores, plugins, external, define, speedup, rootDir, taskConfig } = options;
return await esbuild.build({
absWorkingDir: process.cwd(),
entryPoints,
Expand Down Expand Up @@ -162,8 +164,9 @@ export async function bundleDeps(options:
// Prebundle only works in development mode.
mode: 'development',
fileName,
localIdentName: name,
localName: name,
rule: speedup ? 'native' : 'loader',
localIdentName: taskConfig.cssModules?.localIdentName,
});
},
}),
Expand Down
3 changes: 2 additions & 1 deletion packages/ice/src/service/serverCompiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,9 @@ export function createServerCompiler(options: Options) {
rootDir,
mode: dev ? 'development' : 'production',
fileName,
localIdentName: name,
localName: name,
rule: speedup ? 'native' : 'loader',
localIdentName: task.config.cssModules?.localIdentName,
});
},
}),
Expand Down
1 change: 1 addition & 0 deletions packages/ice/src/types/userConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export interface UserConfig {
postcss?: ProcessOptions & {
plugins?: (string | [string, Record<string, any>?])[];
};
cssModules?: Config['cssModules'];
/**
* Custom file-system based route rules.
* @see https://v3.ice.work/docs/guide/basic/config#routes
Expand Down
8 changes: 5 additions & 3 deletions packages/ice/src/utils/getCSSModuleIdent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@ interface Options {
rule?: string;
mode?: 'development' | 'production';
fileName: string;
localName: string;
localIdentName: string;
}

// TODO: move this logic to getCSSModuleLocalIdent.
const getCSSModuleIdent = (options: Options) => {
const { rootDir, fileName, localIdentName, rule, mode } = options;
const { rootDir, fileName, localName, localIdentName, rule, mode } = options;
if (rule === 'native') {
const template = mode === 'development' ? CSS_MODULES_LOCAL_IDENT_NAME_DEV : CSS_MODULES_LOCAL_IDENT_NAME;
const relativePath = path.isAbsolute(fileName) ? path.relative(rootDir, fileName) : fileName;
return getIdentByRust(relativePath, localIdentName, template);
return getIdentByRust(relativePath, localName, localIdentName || template);
} else {
return escapeLocalIdent(getCSSModuleLocalIdent(fileName, localIdentName));
return escapeLocalIdent(getCSSModuleLocalIdent(fileName, localName, localIdentName));
}
};

Expand Down
4 changes: 2 additions & 2 deletions packages/ice/templates/core/entry.client.tsx.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as app from '@/app';
import createRoutes from './routes';
<% } -%>
<%- runtimeOptions.imports %>
<% if(dataLoaderImport.imports) {-%><%-dataLoaderImport.imports%><% } -%>
<% if (dataLoaderImport.imports) {-%><%-dataLoaderImport.imports%><% } -%>
import type { RunClientAppOptions } from '@ice/runtime';

const getRouterBasename = () => {
Expand All @@ -19,7 +19,7 @@ const getRouterBasename = () => {
// Otherwise chunk of route component will pack @ice/jsx-runtime and depend on framework bundle.
const App = <></>;

<% if(!dataLoaderImport.imports) {-%>
<% if (!dataLoaderImport.imports) {-%>
let dataLoaderFetcher = (options) => {
return window.fetch(options.url, options);
}
Expand Down
16 changes: 10 additions & 6 deletions packages/ice/templates/core/entry.server.ts.ejs
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
import './env.server';
import * as runtime from '@ice/runtime/server';
<% if(hydrate) {-%>
<% if (hydrate) {-%>
import { commons, statics } from './runtime-modules';
<% }-%>
import * as app from '@/app';
<% if (hasDocument) {-%>
import * as Document from '@/document';
<% }-%>
import type { RenderMode, DistType } from '@ice/runtime';
import type { RenderToPipeableStreamOptions } from 'react-dom/server';
// @ts-ignore
import assetsManifest from 'virtual:assets-manifest.json';
<% if(hydrate) {-%>
<% if (hydrate) {-%>
import createRoutes from './routes';
<% } else { -%>
import routesManifest from './route-manifest.json';
<% } -%>
import routesConfig from './routes-config.bundle.mjs';
<% if(dataLoaderImport.imports) {-%><%-dataLoaderImport.imports%><% } -%>
<% if(hydrate) {-%><%- runtimeOptions.imports %><% } -%>
<% if(!hydrate) {-%>
<% if (dataLoaderImport.imports) {-%><%-dataLoaderImport.imports%><% } -%>
<% if (hydrate) {-%><%- runtimeOptions.imports %><% } -%>
<% if (!hydrate) {-%>
// Do not inject runtime modules when render mode is document only.
const commons = [];
const statics = [];
Expand Down Expand Up @@ -90,12 +92,14 @@ function mergeOptions(options) {
assetsManifest,
createRoutes,
runtimeModules,
<% if (hasDocument) {-%>
documentDataLoader: Document.dataLoader,
Document: Document.default,
<% }-%>
basename: basename || getRouterBasename(),
renderMode,
routesConfig,
<% if(hydrate) {-%>
<% if (hydrate) {-%>
runtimeOptions: {
<% if (runtimeOptions.exports) { -%>
<%- runtimeOptions.exports %>
Expand Down
6 changes: 3 additions & 3 deletions packages/ice/templates/exports/data-loader.ts.ejs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { dataLoader } from '@ice/runtime';
import * as app from '@/app';
import dataloaderConfig from './dataloader-config'
<% if(dataLoaderImport.imports) {-%><%-dataLoaderImport.imports%><% } -%>
<% if (dataLoaderImport.imports) {-%><%-dataLoaderImport.imports%><% } -%>
<% const staticModuleNames = []; -%>
<% if (runtimeModules.length) { -%>
<% runtimeModules.forEach((runtimeModule, index) => { -%>
Expand All @@ -14,10 +14,10 @@ import dataloaderConfig from './dataloader-config'

const loaders = {
...dataloaderConfig,
<% if(hasExportAppData) {-%>__app: app.dataLoader,<% } -%>
<% if (hasExportAppData) {-%>__app: app.dataLoader,<% } -%>
}

<% if(!dataLoaderImport.imports) {-%>
<% if (!dataLoaderImport.imports) {-%>
let dataLoaderFetcher = (options) => {
return window.fetch(options.url, options);
}
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.2",
"@ice/app": "^3.3.3",
"@ice/runtime": "^1.2.9"
},
"publishConfig": {
Expand Down
7 changes: 7 additions & 0 deletions packages/plugin-stream-error/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# @ice/plugin-stream-error

## 1.0.0

### Major Changes

- f2c7df96: feat: plugin deal with stream error
18 changes: 18 additions & 0 deletions packages/plugin-stream-error/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# @ice/plugin-stream-error

A plugin for re-render app when stream error.

## Usage

```ts
import { defineConfig } from '@ice/app';
import streamError from '@ice/plugin-stream-error';

export default defineConfig(() => ({
plugins: [
streamError(),
],
}));
```

> Causion: This plugin only works when stream content ends with javascripts which triggered an custom event of `stream_end`
Loading

0 comments on commit adf1fa4

Please sign in to comment.