Compare commits

...

3 Commits

Author SHA1 Message Date
ClarkXia 1499645303
Merge 39e2bd0e1a into ace5e1dd15 2025-07-24 16:30:07 +08:00
ClarkXia ace5e1dd15
Merge pull request #7127 from alibaba/hotfix/env
CI / build (16.x, ubuntu-latest) (push) Has been cancelled Details
CI / build (16.x, windows-latest) (push) Has been cancelled Details
CI / build (18.x, ubuntu-latest) (push) Has been cancelled Details
CI / build (18.x, windows-latest) (push) Has been cancelled Details
Coverage / coverage (16.x) (push) Has been cancelled Details
Release / Release (16) (push) Has been cancelled Details
hotfix: add isPHA and isKraken env for backward compatibility
2025-07-24 15:27:08 +08:00
ClarkXia 39e2bd0e1a fix: recompile server bundle when assets manifest changed 2025-07-14 11:59:37 +08:00
5 changed files with 44 additions and 8 deletions

View File

@ -0,0 +1,5 @@
---
'@ice/app': patch
---
fix: recompile server bundle when assets manifest changed

View File

@ -1,5 +1,9 @@
# Changelog
## 3.6.5
- hotfix: add isPHA and isKraken env for backward compatibility.
## 3.6.4
### Patch Changes

View File

@ -1,6 +1,6 @@
{
"name": "@ice/app",
"version": "3.6.4",
"version": "3.6.5",
"description": "provide scripts and configuration used by web framework ice",
"type": "module",
"main": "./esm/index.js",

View File

@ -14,7 +14,7 @@ export default class ServerCompilerPlugin {
private isCompiling: boolean;
private task: ReturnType<ServerCompiler>;
private compilerOptions: Parameters<ServerCompiler>[1];
public buildResult: ServerBuildResult;
public buildResult: ServerBuildResult & { assetsManifestChanged?: boolean };
public constructor(
serverCompiler: ServerCompiler,
@ -36,10 +36,17 @@ export default class ServerCompilerPlugin {
public compileTask = async (compilation?: Compilation) => {
const [buildOptions] = this.serverCompilerOptions;
if (!this.isCompiling) {
let assetsManifestChanged = false;
if (compilation) {
// Option of compilationInfo need to be object, while it may changed during multi-time compilation.
this.compilerOptions.compilationInfo.assetsManifest =
JSON.parse(compilation.getAsset('assets-manifest.json').source.source().toString());
const newAssetsManifest = JSON.parse(compilation.getAsset('assets-manifest.json').source.source().toString());
const oldAssetsManifest = this.compilerOptions.compilationInfo.assetsManifest;
// Check if assets manifest has changed
if (JSON.stringify(oldAssetsManifest) !== JSON.stringify(newAssetsManifest)) {
assetsManifestChanged = true;
this.compilerOptions.compilationInfo.assetsManifest = newAssetsManifest;
}
}
// For first time, we create a new task.
// The next time, we use incremental build so do not create task again.
@ -51,6 +58,9 @@ export default class ServerCompilerPlugin {
this.task = null;
}
});
} else if (assetsManifestChanged && this.buildResult?.context?.rebuild) {
// Force rebuild when assets manifest changes
this.buildResult.assetsManifestChanged = true;
}
}
};
@ -64,8 +74,9 @@ export default class ServerCompilerPlugin {
this.isCompiling = false;
await this.compileTask(compilation);
const compilerTask = this.buildResult?.context.rebuild
? this.buildResult.context.rebuild()
let compilerTask: Promise<ServerBuildResult>;
if (this.buildResult?.context.rebuild && !this.buildResult?.assetsManifestChanged) {
compilerTask = this.buildResult.context.rebuild()
.then((result) => {
return {
// Pass original buildResult, because it's returned serverEntry.
@ -75,8 +86,20 @@ export default class ServerCompilerPlugin {
})
.catch(({ errors }) => {
return { error: errors };
})
: this.task;
});
} else if (this.buildResult?.assetsManifestChanged) {
compilerTask = (async () => {
// When assets manifest changes, force full rebuild to get fresh document
this.buildResult.assetsManifestChanged = false;
this.task = this.serverCompiler(this.serverCompilerOptions[0], this.compilerOptions);
const newBuildResult = await this.task;
this.buildResult = newBuildResult;
return newBuildResult;
})();
} else {
compilerTask = this.task;
}
if (this.serverCompileTask) {
this.serverCompileTask.set(compilerTask);
} else {

View File

@ -11,9 +11,11 @@ export const isKuaiShouMiniProgram = isClient && import.meta.target === 'kuaisho
export const isWeChatMiniProgram = isClient && import.meta.target === 'wechat-miniprogram';
export const isQuickApp = false; // Now ice.js will not implement quick app target.
export const isMiniApp = isAliMiniApp; // in universal-env, isMiniApp is equals to isAliMiniApp
export const isKraken = isClient && import.meta.target === 'kraken';
// Following variables are runtime executed envs.
// See also @uni/env.
export const isPHA = isWeb && typeof pha === 'object';
const ua = typeof navigator === 'object' ? navigator.userAgent || navigator.swuserAgent : '';
export const isThemis = /Themis/.test(ua);
export const isWindVane = /WindVane/i.test(ua) && isWeb && typeof WindVane !== 'undefined' && typeof WindVane.call !== 'undefined';
@ -25,6 +27,8 @@ export default {
isWeb,
isNode,
isWeex,
isKraken,
isPHA,
isThemis,
isMiniApp,
isByteDanceMicroApp,