Skip to content

Commit

Permalink
Merge pull request #6249 from alibaba/release/next
Browse files Browse the repository at this point in the history
* fix: import store source before swc compiler (#6248)

* Feat/support sourcemap (#6158)

* feat: add generateSourceMap

* feat: generate souce map

* chore: add changeset

* feat: add data-sourcemap

* feat: add with-entry-type example

* feat: add sourcemap info

* fix: modify toJson to toString

* chore: rename generate sourcemap

* feat: modify line of child map

* feat: add base line

* chore: modify BASE_COLUMN

* chore: modify pnpm lock

* feat: data-sourcemap should be delete

* chore: update lock

* chore: add changeset

* chore: modify lock

* chore: remove app worker and data loader

* chore: if sourceMapFileList is empty, return empty string

* feat: support sourcemap meta

* feat: dealwith style

* feat: add prependCode

* chore: modify package

* chore: modify if

* fix: use api history to navigate (#6251)

* fix: use api history to navigate

* fix: params

* feat: support api of addEntryImportAhead (#6256)

* feat: support api of addEntryImportAhead

* fix: ts type

* fix: jsx comment (#6239)

* fix: jsx comment

* chore: add changelog

* fix: set source with jsx comment to classic mode

* fix: jsx pragma

* fix: compatible with hmr when data get undefined (#6259)

* fix: use data (#6254)

* fix: use data

* fix: test

* chore: changeset

* fix: test

* chore: update lock

* chore: update versions (#6250)

* chore: update versions

* Update CHANGELOG.md

---------

Co-authored-by: 染陌同学 <[email protected]>
Co-authored-by: 水澜 <[email protected]>
  • Loading branch information
3 people authored May 24, 2023
2 parents 6c62576 + 542d86c commit 390a0ce
Show file tree
Hide file tree
Showing 47 changed files with 500 additions and 59 deletions.
1 change: 0 additions & 1 deletion examples/rax-inline-style/src/document.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* @jsx createElement */
import { Meta, Title, Links, Main, Scripts } from 'ice';

function Document() {
Expand Down
1 change: 1 addition & 0 deletions examples/with-entry-type/.browserslistrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
chrome 55
18 changes: 18 additions & 0 deletions examples/with-entry-type/ice.config.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { defineConfig } from '@ice/app';

export default defineConfig({
plugins: [],
server: {
onDemand: true,
format: 'esm',
},
output: {
distType: 'javascript'
},
sourceMap: true,
routes: {
defineRoutes: (route) => {
route('/custom', 'Custom/index.tsx');
},
},
});
24 changes: 24 additions & 0 deletions examples/with-entry-type/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "@examples/with-entry-type",
"private": true,
"version": "1.0.0",
"scripts": {
"start": "ice start",
"build": "ice build"
},
"description": "",
"author": "",
"license": "MIT",
"dependencies": {
"@ice/app": "workspace:*",
"@ice/runtime": "workspace:*",
"react": "^18.0.0",
"react-dom": "^18.0.0"
},
"devDependencies": {
"fs-extra": "^10.0.0",
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.2",
"webpack": "^5.73.0"
}
}
Binary file added examples/with-entry-type/public/favicon.ico
Binary file not shown.
3 changes: 3 additions & 0 deletions examples/with-entry-type/src/app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { defineAppConfig } from 'ice';

export default defineAppConfig(() => ({}));
42 changes: 42 additions & 0 deletions examples/with-entry-type/src/document.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import path from 'path';
import { fileURLToPath } from 'url';
import { Meta, Title, Links, Main, Scripts } from 'ice';
import fse from 'fs-extra';

let dirname;
if (typeof __dirname === 'string') {
dirname = __dirname;
} else {
dirname = path.dirname(fileURLToPath(import.meta.url));
}

function Document() {
return (
<html>
<head>
<meta charSet="utf-8" />
<meta name="description" content="ICE Demo" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<Meta />
<Title />
<Links />
</head>
<body>
<Main />
<Scripts ScriptElement={(props) => {
if (props.src && !props.src.startsWith('http')) {
const filePath = path.join(dirname, `..${props.src}`);
const sourceMapFilePath = path.join(dirname, `..${props.src}.map`);
const res = fse.readFileSync(filePath, 'utf-8');
return <script data-sourcemap={sourceMapFilePath} dangerouslySetInnerHTML={{ __html: res }} {...props} />;
} else {
return <script {...props} />;
}
}}
/>
</body>
</html>
);
}

export default Document;
19 changes: 19 additions & 0 deletions examples/with-entry-type/src/pages/Custom/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Link, useData } from 'ice';

export default function Custom() {
const data = useData();

return (
<>
<h2>Custom Page</h2>
<Link to="/home">home</Link>
{data}
</>
);
}

export function pageConfig() {
return {
title: 'Custom',
};
}
30 changes: 30 additions & 0 deletions examples/with-entry-type/src/pages/about.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Link } from 'ice';

export default function About() {
return (
<>
<h2>About Page</h2>
<Link to="/">home</Link>
<span className="mark">new</span>
</>
);
}

export function pageConfig() {
return {
title: 'About',
meta: [
{
name: 'theme-color',
content: '#eee',
},
],
links: [{
href: 'https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css',
rel: 'stylesheet',
}],
scripts: [{
src: 'https://cdn.jsdelivr.net/npm/[email protected]/dist/lodash.min.js',
}],
};
}
21 changes: 21 additions & 0 deletions examples/with-entry-type/src/pages/blog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Link, useData, useConfig } from 'ice';

export default function Blog() {
const data = useData();
const config = useConfig();

console.log('render Blog', 'data', data, 'config', config);

return (
<>
<h2>Blog Page</h2>
<Link to="/home">home</Link>
</>
);
}

export function pageConfig() {
return {
title: 'Blog',
};
}
20 changes: 20 additions & 0 deletions examples/with-entry-type/src/pages/home.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { definePageConfig } from 'ice';

export default function Home() {
return (
<>
<h2>Home Page</h2>
</>
);
}

export const pageConfig = definePageConfig(() => {
return {
queryParamsPassKeys: [
'questionId',
'source',
'disableNav',
],
title: 'Home',
};
});
25 changes: 25 additions & 0 deletions examples/with-entry-type/src/pages/index.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
.title {
color: red;
margin-left: 10rpx;
}

.data {
margin-top: 10px;
}

.homeContainer {
align-items: center;
margin-top: 200rpx;
}

.homeTitle {
font-size: 45rpx;
font-weight: bold;
margin: 20rpx 0;
}

.homeInfo {
font-size: 36rpx;
margin: 8rpx 0;
color: #555;
}
22 changes: 22 additions & 0 deletions examples/with-entry-type/src/pages/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Outlet } from 'ice';

export default () => {
return (
<div>
<h1>ICE 3.0 Layout</h1>
<Outlet />
</div>
);
};

export function pageConfig() {
return {
title: 'Layout',
meta: [
{
name: 'layout-color',
content: '#f00',
},
],
};
}
1 change: 1 addition & 0 deletions examples/with-entry-type/src/typings.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="@ice/app/types" />
32 changes: 32 additions & 0 deletions examples/with-entry-type/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"compileOnSave": false,
"buildOnSave": false,
"compilerOptions": {
"baseUrl": ".",
"outDir": "build",
"module": "esnext",
"target": "es6",
"jsx": "react-jsx",
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"lib": ["es6", "dom"],
"sourceMap": true,
"allowJs": true,
"rootDir": "./",
"forceConsistentCasingInFileNames": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noImplicitAny": false,
"importHelpers": true,
"strictNullChecks": true,
"suppressImplicitAnyIndexErrors": true,
"noUnusedLocals": true,
"skipLibCheck": true,
"paths": {
"@/*": ["./src/*"],
"ice": [".ice"]
}
},
"include": ["src", ".ice", "ice.config.*"],
"exclude": ["build", "public"]
}
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

## 3.2.1

### Patch Changes

- f24b045d: feat: supprot sourmap for distType
- 8b1b237: feat: support api of addEntryImportAhead
- Updated dependencies [f24b045d]
- @ice/runtime@1.2.1

## 3.2.0

### Minor 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.0",
"version": "3.2.1",
"description": "provide scripts and configuration used by web framework ice",
"type": "module",
"main": "./esm/index.js",
Expand Down Expand Up @@ -38,7 +38,7 @@
"dependencies": {
"@ice/bundles": "0.1.10",
"@ice/route-manifest": "1.2.0",
"@ice/runtime": "^1.2.0",
"@ice/runtime": "^1.2.1",
"@ice/webpack-config": "1.0.14",
"@swc/helpers": "0.5.1",
"@types/express": "^4.17.14",
Expand Down
2 changes: 2 additions & 0 deletions packages/ice/src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ const build = async (
ssg,
output: {
distType,
prependCode,
},
} = userConfig;
let renderMode: RenderMode;
Expand All @@ -159,6 +160,7 @@ const build = async (
renderMode,
routeType: appConfig?.router?.type,
distType,
prependCode,
routeManifest,
});
// This depends on orders.
Expand Down
6 changes: 6 additions & 0 deletions packages/ice/src/createService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ async function createService({ rootDir, command, commandArgs }: CreateServiceOpt
addEntryCode: (callback: (originalCode: string) => string) => {
entryCode = callback(entryCode);
},
addEntryImportAhead: (declarationData: Pick<DeclarationData, 'source'>) => {
generator.addDeclaration('entry', {
...declarationData,
declarationType: DeclarationType.NORMAL,
});
},
modifyRenderData: generator.modifyRenderData,
addDataLoaderImport: (declarationData: DeclarationData) => {
generator.addDeclaration('dataLoaderImport', {
Expand Down
28 changes: 16 additions & 12 deletions packages/ice/src/service/runtimeGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,21 @@ export function generateDeclaration(exportList: Array<TargetDeclarationData | De
const specifiers = isDefaultImport ? [specifier] : specifier;
const symbol = type ? ';' : ',';

importDeclarations.push(`import ${type ? 'type ' : ''}${isDefaultImport ? specifier : `{ ${specifiers.map(specifierStr => ((alias && alias[specifierStr]) ? `${specifierStr} as ${alias[specifierStr]}` : specifierStr)).join(', ')} }`} from '${source}';`);

specifiers.forEach((specifierStr) => {
if (alias && alias[specifierStr]) {
exportDeclarations.push(`${alias[specifierStr]}: ${specifierStr}${symbol}`);
exportNames.push(alias[specifierStr]);
} else {
exportDeclarations.push(`${specifierStr}${symbol}`);
exportNames.push(specifierStr);
}
});
if (specifier) {
importDeclarations.push(`import ${type ? 'type ' : ''}${isDefaultImport ? specifier : `{ ${specifiers.map(specifierStr => ((alias && alias[specifierStr]) ? `${specifierStr} as ${alias[specifierStr]}` : specifierStr)).join(', ')} }`} from '${source}';`);

specifiers.forEach((specifierStr) => {
if (alias && alias[specifierStr]) {
exportDeclarations.push(`${alias[specifierStr]}: ${specifierStr}${symbol}`);
exportNames.push(alias[specifierStr]);
} else {
exportDeclarations.push(`${specifierStr}${symbol}`);
exportNames.push(specifierStr);
}
});
} else {
importDeclarations.push(`import '${source}';`);
}
}
});

Expand Down Expand Up @@ -187,7 +191,7 @@ export default class Generator {
this.rerender = false;
this.renderTemplates = [];
this.renderDataRegistration = [];
this.contentTypes = ['framework', 'frameworkTypes', 'routeConfigTypes', 'dataLoaderImport', 'runtimeOptions'];
this.contentTypes = ['framework', 'frameworkTypes', 'routeConfigTypes', 'dataLoaderImport', 'runtimeOptions', 'entry'];
// empty .ice before render
fse.emptyDirSync(path.join(rootDir, targetDir));
// add initial templates
Expand Down
2 changes: 1 addition & 1 deletion packages/ice/src/types/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export enum DeclarationType {
}

export interface DeclarationData {
specifier: string | string[];
specifier?: string | string[];
source: string;
type?: boolean;
alias?: Record<string, string>;
Expand Down
Loading

0 comments on commit 390a0ce

Please sign in to comment.