Skip to content

Commit

Permalink
feat: upgrade esbuild version to v0.17 (alibaba#6146)
Browse files Browse the repository at this point in the history
* feat: upgrade esbuild version to v0.17

* chore: update lock file && add registry

* fix: lint warning
  • Loading branch information
ChrisCindy authored Apr 20, 2023
1 parent da7c733 commit 71bd792
Show file tree
Hide file tree
Showing 11 changed files with 139 additions and 159 deletions.
3 changes: 2 additions & 1 deletion .npmrc
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
strict-peer-dependencies=false
strict-peer-dependencies=false
registry=https://registry.npmjs.org/
2 changes: 1 addition & 1 deletion packages/bundles/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"core-js": "3.29.1",
"caniuse-lite": "^1.0.30001431",
"chokidar": "3.5.3",
"esbuild": "^0.16.5",
"esbuild": "^0.17.16",
"events": "3.3.0",
"jest-worker": "27.5.1",
"less": "4.1.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/ice/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"sass": "^1.50.0",
"@types/temp": "^0.9.1",
"chokidar": "^3.5.3",
"esbuild": "^0.16.5",
"esbuild": "^0.17.16",
"jest": "^29.0.2",
"react": "^18.2.0",
"react-router": "6.10.0",
Expand Down
5 changes: 4 additions & 1 deletion packages/ice/src/service/serverCompiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,9 @@ export function createServerCompiler(options: Options) {
logger.debug('[esbuild]', `start compile for: ${JSON.stringify(buildOptions.entryPoints)}`);

try {
const esbuildResult = await esbuild.build(buildOptions);
const context = await esbuild.context(buildOptions);

const esbuildResult = await context.rebuild();

logger.debug('[esbuild]', `time cost: ${new Date().getTime() - startTime}ms`);

Expand All @@ -240,6 +242,7 @@ export function createServerCompiler(options: Options) {

return {
...esbuildResult,
context,
serverEntry,
};
} catch (error) {
Expand Down
3 changes: 1 addition & 2 deletions packages/ice/src/service/webpackCompiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ async function webpackCompiler(options: {
[IMPORT_META_TARGET]: JSON.stringify(target),
[IMPORT_META_RENDERER]: JSON.stringify('server'),
},
incremental: command === 'start',
});
webpackConfig.plugins.push(serverCompilerPlugin);
}
Expand All @@ -104,7 +103,7 @@ async function webpackCompiler(options: {
}),
);
const debounceCompile = debounce(() => {
serverCompilerPlugin?.buildResult?.rebuild();
serverCompilerPlugin?.buildResult?.context.rebuild();
console.log('Document updated, try to reload page for latest html content.');
}, 200);
watch.addEvent([
Expand Down
9 changes: 6 additions & 3 deletions packages/ice/src/types/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,14 @@ type ServerCompilerBuildOptions = Pick<
'plugins' |
'logLevel' |
'sourcemap' |
'metafile' |
'incremental'
'metafile'
>;

export type ServerBuildResult = Partial<esbuild.BuildResult & { serverEntry: string; error: any }>;
export type ServerBuildResult =
Partial<
esbuild.BuildResult &
{ serverEntry: string; error: any; context: esbuild.BuildContext<esbuild.BuildOptions> }
>;

export interface CompilerOptions {
swc?: Config['swcOptions'];
Expand Down
3 changes: 0 additions & 3 deletions packages/ice/src/utils/getServerCompilerPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ interface Options {
userConfig: UserConfig;
outputDir: string;
serverEntry: string;
incremental: boolean;
serverCompileTask: ExtendsPluginAPI['serverCompileTask'];
ensureRoutesConfig: () => Promise<void>;
runtimeDefineVars: Record<string, string>;
Expand All @@ -25,7 +24,6 @@ function getServerCompilerPlugin(serverCompiler: ServerCompiler, options: Option
serverCompileTask,
ensureRoutesConfig,
runtimeDefineVars,
incremental,
} = options;
const entryPoint = getServerEntry(rootDir, serverEntry);
const { ssg, ssr, server: { format } } = userConfig;
Expand All @@ -43,7 +41,6 @@ function getServerCompilerPlugin(serverCompiler: ServerCompiler, options: Option
outExtension: { '.js': isEsm ? '.mjs' : '.cjs' },
metafile: true,
logLevel: 'silent', // The server compiler process will log it in debug.
incremental,
},
{
// The server bundle will external all the dependencies when the format type is esm,
Expand Down
4 changes: 2 additions & 2 deletions packages/ice/src/webpack/ServerCompilerPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ export default class ServerCompilerPlugin {
this.isCompiling = false;
await this.compileTask(compilation);

const compilerTask = this.buildResult?.rebuild
? this.buildResult.rebuild()
const compilerTask = this.buildResult?.context.rebuild
? this.buildResult.context.rebuild()
.then((result) => {
return {
// Pass original buildResult, because it's returned serverEntry.
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-pha/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"devDependencies": {
"@ice/app": "^3.1.5",
"build-scripts": "^2.1.0",
"esbuild": "^0.16.5",
"esbuild": "^0.17.16",
"webpack": "^5.76.2",
"webpack-dev-server": "^4.9.2"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/webpack-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"process": "^0.11.10"
},
"devDependencies": {
"esbuild": "^0.16.5",
"esbuild": "^0.17.16",
"postcss": "^8.4.18",
"webpack": "^5.76.2",
"webpack-dev-server": "^4.7.4"
Expand Down
Loading

0 comments on commit 71bd792

Please sign in to comment.