Skip to content

Commit

Permalink
Merge pull request #6266 from alibaba/release/next
Browse files Browse the repository at this point in the history
Release/3.2.2
  • Loading branch information
ClarkXia authored May 24, 2023
2 parents 390a0ce + 4d19b91 commit 7cec998
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 9 deletions.
1 change: 1 addition & 0 deletions examples/routes-generate/ice.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export default defineConfig(() => ({
ignoreFiles: ['about.tsx', 'products.tsx'],
defineRoutes: (route) => {
route('/about-me', 'about.tsx');
route('/about.html', 'about.tsx');

route('/', 'layout.tsx', () => {
route('/product', 'products.tsx');
Expand Down
6 changes: 5 additions & 1 deletion examples/routes-generate/src/pages/about.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import * as React from 'react';
import { Link } from 'ice';
import { Link, definePageConfig } from 'ice';

export default function About() {
return <><h2>About</h2><Link to="/">home</Link></>;
}

export const pageConfig = definePageConfig(() => ({

}));
8 changes: 8 additions & 0 deletions packages/ice/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## 3.2.2

### Patch Changes

- f652be72: fix: import identifier is invalid in route config
- Updated dependencies [a4b85144]
- @ice/webpack-config@1.0.15

## 3.2.1

### Patch Changes
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.2.1",
"version": "3.2.2",
"description": "provide scripts and configuration used by web framework ice",
"type": "module",
"main": "./esm/index.js",
Expand Down Expand Up @@ -39,7 +39,7 @@
"@ice/bundles": "0.1.10",
"@ice/route-manifest": "1.2.0",
"@ice/runtime": "^1.2.1",
"@ice/webpack-config": "1.0.14",
"@ice/webpack-config": "1.0.15",
"@swc/helpers": "0.5.1",
"@types/express": "^4.17.14",
"address": "^1.1.2",
Expand Down
8 changes: 6 additions & 2 deletions packages/ice/src/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export function getRoutesDefinition(nestRouteManifest: NestedRouteManifest[], la
if (lazy) {
loadStatement = `import(/* webpackChunkName: "p_${componentName}" */ '${formatPath(componentPath)}')`;
} else {
const routeSpecifier = id.replace(/[./-]/g, '_').replace(/[:*]/g, '$');
const routeSpecifier = formatRouteSpecifier(id);
routeImports.push(`import * as ${routeSpecifier} from '${formatPath(componentPath)}';`);
loadStatement = routeSpecifier;
}
Expand Down Expand Up @@ -145,7 +145,7 @@ function generateRouteConfig(
const componentFile = file.replace(new RegExp(`${fileExtname}$`), '');
const componentPath = path.isAbsolute(componentFile) ? componentFile : `@/pages/${componentFile}`;

const loaderName = `${exportKey}_${id}`.replace(/[-/]/g, '_');
const loaderName = formatRouteSpecifier(`${exportKey}_${id}`);
const fullPath = path.join(parentPath, routePath);
imports.push([id, loaderName, fullPath]);
str = `import { ${exportKey} as ${loaderName} } from '${componentPath}';\n`;
Expand All @@ -162,3 +162,7 @@ function generateRouteConfig(
}
return template(importConfig(routes, ''), imports);
}

function formatRouteSpecifier(routeId: string) {
return routeId.replace(/[./-]/g, '_').replace(/[:*]/g, '$');
}
2 changes: 1 addition & 1 deletion packages/plugin-i18n/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"webpack-dev-server": "^4.13.2"
},
"peerDependencies": {
"@ice/app": "^3.2.1",
"@ice/app": "^3.2.2",
"@ice/runtime": "^1.2.1"
},
"publishConfig": {
Expand Down
6 changes: 6 additions & 0 deletions packages/webpack-config/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 1.0.15

### Patch Changes

- a4b85144: fix: compatible with code has import.meta

## 1.0.14

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/webpack-config/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ice/webpack-config",
"version": "1.0.14",
"version": "1.0.15",
"repository": "alibaba/ice",
"bugs": "https://github.com/alibaba/ice/issues",
"homepage": "https://v3.ice.work",
Expand Down
3 changes: 2 additions & 1 deletion packages/webpack-config/src/utils/transformImport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ const transformImport = async (source: string, coreJsPath: string) => {
const str = () => s || (s = new MagicString(source));
const isESM = exports.length > 0 || imports.some((targetImport) => {
const importString = targetImport.n;
return !importString.includes('core-js') && !importString.includes('@swc/helpers');
// `targetImport.n` get undefined when code has `import.meta.*`.
return importString && !importString.includes('core-js') && !importString.includes('@swc/helpers');
});
imports.forEach((targetImport) => {
if (!targetImport.n) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
if (import.meta.rerender === 'client') console.log(true);
5 changes: 5 additions & 0 deletions packages/webpack-config/tests/transformImport.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,9 @@ describe('transform core js path', () => {
expect(await transformImport(orignalCode, coreJsPath))
.toBe('var _object_spread = require(\'@swc/helpers/cjs/_object_spread.cjs\')._;module.exports = {};');
});
it('with import.meta', async () => {
const orignalCode = fs.readFileSync(path.join(__dirname, './fixtures/transformImport/importMeta.js'), 'utf-8');
expect(await transformImport(orignalCode, coreJsPath))
.toBe('if (import.meta.rerender === \'client\') console.log(true);');
});
});
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 7cec998

Please sign in to comment.