-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Option "browserTarget" is deprecated. Option "buildTarget" should be used instead. #89
Comments
@jordimarimon thanks for this detailed input (and sorry for letting this slide for some time..)! There are some relatively independent points to address:
There are imho two ways to proceed: I'm not totally sure if a) or b) would be the smart move - any input? |
Reading https://angular.io/guide/releases#deprecation-practices I'd rather go for a) - at least if it does not induce too much overhead.. (inputs still welcome!) |
commented on your commit with some ideas, @daniel-sc -- thanks for your work! |
This is a mess - anyone an expert with "jest commonjs + esm dynamic imports"? See https://stackoverflow.com/questions/77962982/testing-commonjs-with-dynamic-imports-of-esm-with-ts-jest |
Hi Daniel! Sorry for not answering before. When I saw the answer, it was already too late and a PR had already started. I have made a fork of the project and the following commit to fix it: I have been able to successfully execute both the build and the test scripts. This a fix I made with just a few minutes, probably you will want to organize things better. Also feel free to remove the These are the changes I have made to make it work:
import {JestConfigWithTsJest} from 'ts-jest';
// Sync object
const config: JestConfigWithTsJest = {
preset: 'ts-jest/presets/default-esm', // -> This will need to be removed
testEnvironment: 'node',
verbose: false,
maxWorkers: 100, // -> maybe we don't need this large value anymore?
maxConcurrency: 1,
testTimeout: 30_000,
testMatch: undefined,
testRegex: '.*\.spec\.ts$',
collectCoverageFrom: ['src/**/*.ts'], // exclude coverage from schematic as it only collects from js (instead of ts)..
coveragePathIgnorePatterns: ['src/rmSafe.ts'],
// HERE PROVIDE THE TSCONFIG OPTIONS SO MODULE IS NOT COMMONJS
transform: {
'^.+\\.tsx?$': [
'ts-jest',
{
useESM: true,
tsconfig: {
// Provide the same that right now is in `tsconfig.json`
// https://kulshekhar.github.io/ts-jest/docs/getting-started/options#options
},
},
],
},
};
export default config; |
Also If you would like to disable Node warnings (due to the use of experimental features) when executing tests, we can change (probably won't work in Windows as I think it has another way of setting environment variables):
with:
|
@jordimarimon thanks very much for picking this up! |
Like you said in your comment, this is a mess due to the fact that we have to build for CommonJS but test with ESM... This shouldn't be the case. I would only support Node 18 and Node 20. I wouldn't support older versions of Node or Angular versions that are no longer mantained. This would make easier to move to ESM entirely and stop using CommonJS as I think it's time to move on. The changes would be the following:
With all theses changes we would have a modern project with TypeScript and ESM and we could even stop using Jest and all the hacks that make it work with TypeScript + ESM and just use Vitest (which it's 100% compatible with Jest). You wouldn't need presets or transforms. I have already tested Vitest with this project and it just works out of the box and you have support for coverage as well. The only problem that right now makes it impossible to migrate to TypeScript and ESM is this line of code in the Angular CLI repo: Because AngularCLI is still using |
The above comment is more a suggestion for the future, not for right now as it's not possible to stop supporting CommonJS sadly... |
Yes, you're right. Probably we would need a major version just to "notify" people. I wil open an issue in the Angular CLI asking what it would take to stop using code that makes it not possible for third party builders to distribute ESM modules. I want to know if it's possible for the Angular CLI to support ESM third party builders or maybe I'm missing something. For example if the Angular CLI loads builders dynamically using I thinks this is the same that it's being done here although I'm not entirely sure. I have to do a little bit of research and also see the source code of the Angular CLI to understand better how everything works right now. Everything I'm saying right now comes from my ignorance and my lack of understanding of how the Angular CLI works internally. |
@jordimarimon there is already an open issue: angular/angular-cli/issues/22786 |
I might have found a cleaner way: import the schema.json of the angular-devkit i18n-builder and check for the attribute existence there. This way, we don't need to import the angular version and problems with CommonJS/ESM interop go away.. (of course, when/if angular allows for ESM schematics/builders we should migrate eventually) - see #104 |
It seems the other approach works well - can some of you please check out the beta version 2.11.0-1 and report if anything is broken? |
This is resolved with v2.11.0 |
Angular CLI v17 deprected in the
@angular-devkit/build-angular:extract-i18n
builder thebrowserTarget
in favor of the newbuildTarget
option.If one executes the
ng extract-i18n
command using theng-extract-i18n-merge:ng-extract-i18n-merge
builder with Angular CLI version 17, they will get the following warning:If one changes in the
angular.json
in theextract-i18n
architect the optionbrowserTarget
tobuildTarget
, they will get the following error:I have never written a custom builder for Angular but I suppose that the warning comes because of this line:
https://github.com/daniel-sc/ng-extract-i18n-merge/blob/master/src/builder.ts#L110
And the error comes because of the
schema.json
:https://github.com/daniel-sc/ng-extract-i18n-merge/blob/master/src/schema.json#L113-L117
One can still use the
ng-extract-i18n-merge:ng-extract-i18n-merge
builder with Angular CLI v17 as the option has only been deprecated, not removed.It's only to give a heads up, for when Angular removes it completely.
Maybe in the future one cool thing would be to have an schematic for this builder that could be executed with
ng update
and it would internally call the update schematic of@angular-devkit/build-angular:extract-i18n
to make sure that all users have the builder options updated. But this would required a lot of work. I would be open to help though.The text was updated successfully, but these errors were encountered: