Skip to content

Commit

Permalink
Merge pull request #5638 from alibaba/release/3.0
Browse files Browse the repository at this point in the history
Release/3.0.2
  • Loading branch information
ClarkXia authored Dec 8, 2022
2 parents dbcde91 + ee145bc commit fbe25b8
Show file tree
Hide file tree
Showing 40 changed files with 365 additions and 103 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,5 @@ compiled
.docusaurus
.cache-loader

.env
*.local
.fleet/
1 change: 1 addition & 0 deletions examples/basic-project/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ICE_ENV=common
1 change: 1 addition & 0 deletions examples/basic-project/.env.development
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ICE_ENV=development
3 changes: 2 additions & 1 deletion examples/basic-project/ice.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import customPlugin from './plugin';

export default defineConfig(() => ({
publicPath: '/',
polyfill: 'entry',
syntaxFeatures: {
exportDefaultFrom: true,
},
Expand All @@ -23,7 +24,7 @@ export default defineConfig(() => ({
}
return webpackConfig;
},
dropLogLevel: 'warn',
dropLogLevel: process.env.ICE_ENV === 'common' ? 'warn' : 'error',
plugins: [
customPlugin(),
],
Expand Down
1 change: 1 addition & 0 deletions examples/with-antd-mobile/ice.config.mts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { defineConfig } from '@ice/app';

export default defineConfig(() => ({
polyfill: 'usage',
server: {
bundle: true,
format: 'cjs',
Expand Down
1 change: 0 additions & 1 deletion packages/bundles/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const swcPluginRemoveExport = require.resolve('@ice/swc-plugin-remove-export');
const swcPluginKeepExport = require.resolve('@ice/swc-plugin-keep-export');
const swcPluginKeepPlatform = require.resolve('@ice/swc-plugin-keep-platform');
const coreJsPath = dirname(require.resolve('core-js/package.json'));

export {
postcss,
less,
Expand Down
9 changes: 9 additions & 0 deletions packages/ice/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## v3.0.2

- [fix] rule of page chunk name
- [fix] load env before resolve user config
- [fix] change css module export to make it be compatible with cjs output
- [fix] change main fields order for ssr
- [feat] add fetcher config in dataLoader
- [feat]: force to use port which user set in commandArgs

## v3.0.1

- [fix] file resolve when use css module in server compiling
Expand Down
5 changes: 3 additions & 2 deletions packages/ice/bin/ice-cli.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
.option('--mode <mode>', 'set mode', 'development')
.option('--config <config>', 'custom config path')
.option('-h, --host <host>', 'dev server host', '0.0.0.0')
.option('-p, --port <port>', 'dev server port', 3000)
.option('-p, --port <port>', 'dev server port')
.option('--no-open', "don't open browser on startup")
.option('--no-mock', "don't start mock service")
.option('--rootDir <rootDir>', 'project root directory', cwd)
Expand All @@ -52,7 +52,8 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
.option('--force', 'force remove cache directory', false)
.action(async ({ rootDir, ...commandArgs }) => {
process.env.NODE_ENV = 'development';
commandArgs.port = await detectPort(commandArgs.port);
const DEFAULT_PORT = 3000;
commandArgs.port = typeof commandArgs.port === 'undefined' ? await detectPort(DEFAULT_PORT) : commandArgs.port;
const service = await createService({ rootDir, command: 'start', commandArgs });
service.run();
});
Expand Down
4 changes: 2 additions & 2 deletions packages/ice/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ice/app",
"version": "3.0.1",
"version": "3.0.2",
"description": "provide scripts and configuration used by web framework ice",
"type": "module",
"main": "./esm/index.js",
Expand Down Expand Up @@ -40,7 +40,7 @@
"@ice/bundles": "0.1.1",
"@ice/route-manifest": "1.0.0",
"@ice/runtime": "^1.0.0",
"@ice/webpack-config": "1.0.1",
"@ice/webpack-config": "1.0.2",
"@swc/helpers": "0.4.12",
"@types/express": "^4.17.14",
"address": "^1.1.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/ice/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const userConfig = [
},
{
name: 'dataLoader',
validation: 'boolean',
validation: 'boolean|object',
defaultValue: true,
},
{
Expand Down
23 changes: 21 additions & 2 deletions packages/ice/src/createService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ async function createService({ rootDir, command, commandArgs }: CreateServiceOpt
dataCache,
},
});
// Load .env before resolve user config, so we can access env variables defined in .env files.
await setEnv(rootDir, commandArgs);
// resolve userConfig from ice.config.ts before registerConfig
await ctx.resolveUserConfig();

Expand Down Expand Up @@ -140,7 +142,6 @@ async function createService({ rootDir, command, commandArgs }: CreateServiceOpt
const { routes: routesConfig, server, syntaxFeatures, polyfill } = userConfig;
const userConfigHash = await getFileHash(path.join(rootDir, fg.sync(configFile, { cwd: rootDir })[0]));

await setEnv(rootDir, commandArgs);
const coreEnvKeys = getCoreEnvKeys();

const routesInfo = await generateRoutesInfo(rootDir, routesConfig);
Expand Down Expand Up @@ -188,9 +189,27 @@ async function createService({ rootDir, command, commandArgs }: CreateServiceOpt
rootDir,
runtimeDir: RUNTIME_TMP_DIR,
templateDir: path.join(templateDir, 'exports'),
dataLoader: userConfig.dataLoader,
dataLoader: Boolean(userConfig.dataLoader),
});

if (typeof userConfig.dataLoader === 'object' && userConfig.dataLoader.fetcher) {
const {
packageName,
method,
} = userConfig.dataLoader.fetcher;

generatorAPI.addDataLoaderImport(method ? {
source: packageName,
alias: {
[method]: 'fetcher',
},
specifier: [method],
} : {
source: packageName,
specifier: '',
});
}

// render template before webpack compile
const renderStart = new Date().getTime();
generator.render();
Expand Down
2 changes: 1 addition & 1 deletion packages/ice/src/esbuild/cssModules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function onStyleLoad(options: PluginOptions) {
];
const result = await postcss(postcssPlugins).process(css, { from: args.path });
css = result.css;
contents += `export default ${data.exportedClasses};`;
contents += `module.exports = ${data.exportedClasses};`;

if (extract) {
const writestream = temp.createWriteStream({ suffix: '.css' });
Expand Down
2 changes: 1 addition & 1 deletion packages/ice/src/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function recurseRoutesStr(nestRouteManifest: NestedRouteManifest[], depth = 0) {
const componentPath = id.startsWith('__') ? file : `@/pages/${file}`.replace(new RegExp(`${path.extname(file)}$`), '');
const routeProperties: string[] = [
`path: '${formatPath(routePath || '')}',`,
`load: () => import(/* webpackChunkName: "${componentName}" */ '${formatPath(componentPath)}'),`,
`load: () => import(/* webpackChunkName: "p_${componentName}" */ '${formatPath(componentPath)}'),`,
`componentName: '${componentName}',`,
`index: ${index},`,
`id: '${id}',`,
Expand Down
1 change: 1 addition & 0 deletions packages/ice/src/types/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type ServerCompilerBuildOptions = Pick<
'outdir' |
'splitting' |
'platform' |
'mainFields' |
'outExtension' |
'plugins' |
'logLevel' |
Expand Down
9 changes: 8 additions & 1 deletion packages/ice/src/types/userConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ interface IgnorePattern {
contextRegExp?: RegExp;
}

interface Fetcher {
packageName: string;
method?: string;
}

export interface UserConfig {
alias?: Record<string, string | false>;
define?: Record<string, string | boolean>;
Expand Down Expand Up @@ -63,6 +68,8 @@ export interface UserConfig {
transform?: UnpluginOptions['transform'];
syntaxFeatures?: SyntaxFeatures;
splitChunks?: boolean;
dataLoader?: boolean;
dataLoader?: {
fetcher?: Fetcher;
} | Boolean;
crossOriginLoading?: Config['output']['crossOriginLoading'];
}
4 changes: 4 additions & 0 deletions packages/ice/src/utils/getServerCompilerPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ function getServerCompilerPlugin(serverCompiler: ServerCompiler, options: Option
outdir: path.join(outputDir, SERVER_OUTPUT_DIR),
splitting: isEsm,
format,
// When format set to esm and platform set to node,
// will cause error `Dynamic require of "XXX" is not supported`.
// https://github.com/evanw/esbuild/issues/1921
platform: isEsm ? 'browser' : 'node',
mainFields: ['module', 'main'],
outExtension: { '.js': isEsm ? '.mjs' : '.cjs' },
metafile: true,
},
Expand Down
2 changes: 1 addition & 1 deletion packages/ice/src/utils/runtimeEnv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export async function setEnv(

dotenvFiles.forEach(dotenvFile => {
const filepath = path.join(rootDir, dotenvFile);
if (fs.existsSync(dotenvFile)) {
if (fs.existsSync(filepath)) {
dotenvExpand(
dotenv.config({
path: filepath,
Expand Down
6 changes: 6 additions & 0 deletions packages/plugin-pha/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 1.0.2

- [fix] fix dev lanUrlForTerminal err
- [fix] add title of manifest
- [fix] add pha = true when dev

## 1.0.1

- [fix] failed to get route config when re-define route path
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-pha/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ice/plugin-pha",
"version": "1.0.1",
"version": "1.0.2",
"description": "ice.js plugin for PHA.",
"license": "MIT",
"type": "module",
Expand Down Expand Up @@ -32,4 +32,4 @@
"type": "http",
"url": "https://github.com/alibaba/ice/tree/master/packages/plugin-pha"
}
}
}
1 change: 1 addition & 0 deletions packages/plugin-pha/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Keys of appConfig need transform to manifest.
export const decamelizeKeys = [
'title',
'name',
'startUrl',
'shortName',
Expand Down
12 changes: 7 additions & 5 deletions packages/plugin-pha/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,13 @@ const plugin: Plugin<PluginOptions> = (options) => ({
getAppConfig = restAPI.getAppConfig;
getRoutesConfig = restAPI.getRoutesConfig;

const urlForTerminal = urls.lanUrlForTerminal || urls.localUrlForTerminal;

// Need absolute path for pha dev.
publicPath = command === 'start' ? getDevPath(urls.lanUrlForTerminal) : (taskConfig.publicPath || '/');
publicPath = command === 'start' ? getDevPath(urlForTerminal) : (taskConfig.publicPath || '/');

// process.env.DEPLOY_PATH is defined by cloud environment such as DEF plugin.
urlPrefix = command === 'start' ? urls.lanUrlForTerminal : process.env.DEPLOY_PATH;
urlPrefix = command === 'start' ? urlForTerminal : process.env.DEPLOY_PATH;

compiler = async (options) => {
const { entry, outfile, minify = false } = options;
Expand Down Expand Up @@ -94,13 +96,13 @@ const plugin: Plugin<PluginOptions> = (options) => ({
const { phaManifest } = appConfig || {};
const phaDevUrls = [];
if (phaManifest?.tabBar) {
phaDevUrls.push(`${lanUrl}manifest.json`);
phaDevUrls.push(`${lanUrl}manifest.json?pha=true`);
} else if (phaManifest?.routes?.length > 0) {
phaManifest.routes.forEach((route) => {
if (typeof route === 'string') {
phaDevUrls.push(`${lanUrl}${route}-manifest.json`);
phaDevUrls.push(`${lanUrl}${route}-manifest.json?pha=true`);
} else if (typeof route?.frames![0] === 'string') {
phaDevUrls.push(`${lanUrl}${route.frames[0]}-manifest.json`);
phaDevUrls.push(`${lanUrl}${route.frames[0]}-manifest.json?pha=true`);
}
});
}
Expand Down
6 changes: 5 additions & 1 deletion packages/plugin-pha/src/manifestHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,11 @@ function getPageUrl(routeId: string, options: ParseOptions) {
return `${urlPrefix}${splitCharacter}${routeId}${urlSuffix}`;
}

async function getPageConfig(routeId: string, routeManifest: string, routesConfig: Record<string, any>): Promise<MixedPage> {
async function getPageConfig(
routeId: string,
routeManifest: string,
routesConfig: Record<string, any>,
): Promise<MixedPage> {
const routes = fs.readFileSync(routeManifest, 'utf-8');
const matches = matchRoutes(JSON.parse(routes), routeId.startsWith('/') ? routeId : `/${routeId}`);
let routeConfig: MixedPage = {};
Expand Down
5 changes: 5 additions & 0 deletions packages/runtime/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# @ice/runtime

## v1.0.2

- [fix] window context merge order
- [feat] support custom document components

## v1.0.1

- [fix] merge window context
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ice/runtime",
"version": "1.0.1",
"version": "1.0.2",
"description": "",
"type": "module",
"types": "./esm/index.d.ts",
Expand Down
Loading

0 comments on commit fbe25b8

Please sign in to comment.