fix(@angular/build): Ensure disposal of close-javascript-transformer#32085
Conversation
packages/angular/build/src/tools/esbuild/angular/compiler-plugin.ts
Outdated
Show resolved
Hide resolved
|
on it! |
The onDispose callback doesn't close the javascriptTransformer correctly yet. This ensures that all worker pools are cleaned after a disposal.
37d67f6 to
267aa6b
Compare
alan-agius4
left a comment
There was a problem hiding this comment.
LGTM, thanks for this.
|
Quick question to @hybrist and @alan-agius4 Would it be possible to also publish this fix in ng v20.3.x? |
|
Version 20 is in LTS and only security fixes are applied. |
|
I have created a patch that works for angular 19, 20 etc. create a file called angular-patch-compiler.js in the project root /**
* Angular 19 esbuild cleanup patch
*
* Fixes a known issue where JavaScriptTransformer and related
* resources are not always disposed during ng serve shutdowns,
* especially in Native Federation + Windows environments.
*
* Safe to remove once Angular fixes this upstream.
*/
const path = require('path');
try {
const compilerPath = path.join(
process.cwd(),
'node_modules',
'@angular',
'build',
'src',
'tools',
'esbuild',
'angular',
'compiler-plugin.js',
);
const compilerModule = require(compilerPath);
const originalCreate = compilerModule.createCompilerPlugin;
compilerModule.createCompilerPlugin = function (...args) {
const plugin = originalCreate(...args);
const originalSetup = plugin.setup;
plugin.setup = function (build) {
originalSetup.call(this, build);
build.onDispose(() => {
try {
const { javascriptTransformer, cacheStore, compilation, sharedTSCompilationState } = compilerModule;
javascriptTransformer?.close?.();
cacheStore?.close?.();
compilation?.close?.();
sharedTSCompilationState?.dispose?.();
} catch (e) {
console.error('[Angular Cleanup Patch] dispose failed:', e);
}
});
};
return plugin;
};
console.log('✔ Angular compiler cleanup patch applied');
} catch (e) {
console.warn('⚠ Angular cleanup patch skipped:', e?.message ?? e);
}Then use a start command like: Angular.json make sure you have serve and serve-original with targets: "serve": {
"builder": "@angular-architects/native-federation:build",
"options": {
"rebuildDelay": 100,
"dev": true
},
"configurations": {
"local": {
"target": "<mfe-name>:serve-original:local"
},
"deployed": {
"target": "<mfe-name>:serve-original:deployed"
}
},
"defaultConfiguration": "local"
},
"serve-original": {
"builder": "@angular-devkit/build-angular:dev-server",
"configurations": {
"deployed": {
"buildTarget": "<mfe-name>:esbuild:deployed"
},
"local": {
"buildTarget": "<mfe-name>:esbuild:local"
}
},
"defaultConfiguration": "local",
"options": {
"port": 4210,
"open": true
}
}, |
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
The onDispose callback doesn't close the javascriptTransformer correctly yet. This ensures that all worker pools are cleaned after a disposal.
PR Checklist
Please check to confirm your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Currently the javascriptTransformer is not closed explicitly.
Issue Number: N/A
What is the new behavior?
Like all other parts (compilation and cache), the javascriptTransformer is now closed explicitly.
Does this PR introduce a breaking change?
Other information