Skip to content
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

fix: only fall back to deprecated browserTarget attribute on older an… #104

Merged
merged 6 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ jobs:

strategy:
matrix:
node-version: [14.x, 16.x, 18.x]
angular-version: [13.1.4, 14.0.2, 15.0.3, 16.2.1, 17.0.0]
node-version: [14.x, 16.x, 18.x, 20.x]
angular-version: [13.2.6, 14.0.2, 15.0.3, 16.2.1, 17.0.0]
exclude:
- node-version: 18.x
- node-version: 20.x
- angular-version: 17.0.0
include:
- angular-version: 13.1.4
devkit-version: 0.1301.4
- angular-version: 13.2.6
devkit-version: 0.1302.6
- angular-version: 14.0.2
devkit-version: 0.1400.2
- angular-version: 15.0.3
Expand All @@ -35,6 +36,9 @@ jobs:
- angular-version: 17.0.0
devkit-version: 0.1700.0
node-version: 18.x
- angular-version: 17.0.0
devkit-version: 0.1700.0
node-version: 20.x

steps:
- uses: actions/checkout@v2
Expand All @@ -43,7 +47,7 @@ jobs:
with:
node-version: ${{ matrix.node-version }}
- run: rm package-lock.json # otherwise we cannot overwrite the peerDependencies version of @angular-devkit/build-angular below
- run: npm i --save-exact "@angular-devkit/architect@${{ matrix.devkit-version }}" "@angular-devkit/core@${{ matrix.angular-version }}" "@angular-devkit/schematics@${{ matrix.angular-version }}" "@schematics/angular@${{ matrix.angular-version }}" "@angular-devkit/build-angular@${{ matrix.angular-version }}"
- run: npm i --save-exact "@angular-devkit/architect@${{ matrix.devkit-version }}" "@angular-devkit/core@${{ matrix.angular-version }}" "@angular-devkit/schematics@${{ matrix.angular-version }}" "@schematics/angular@${{ matrix.angular-version }}" "@angular-devkit/build-angular@${{ matrix.angular-version }}" "@angular/core@${{ matrix.angular-version }}" "@angular/compiler-cli@${{ matrix.angular-version }}"
- run: npm i
- run: npm ls || true
- run: npm run build
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ In your `angular.json` the target `extract-i18n` that can be configured with the

| Name | Default | Description |
|--------------------------------|----------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `browserTarget` | Inferred from current setup by `ng add` | A browser builder target to extract i18n messages in the format of `project:target[:configuration]`. See https://angular.io/cli/extract-i18n#options |
| ~~`browserTarget`~~ | Inferred from current setup by `ng add` | _Deprecated_: Use `buildTarget`. A browser builder target to extract i18n messages in the format of `project:target[:configuration]`. See https://angular.io/cli/extract-i18n#options |
| `buildTarget` | Inferred from current setup by `ng add` | A build builder target to extract i18n messages in the format of `project:target[:configuration]`. See https://angular.io/cli/extract-i18n#options |
| `format` | Inferred from current setup by `ng add` | Any of `xlf`, `xlif`, `xliff`, `xlf2`, `xliff2` |
| `outputPath` | Inferred from current setup by `ng add` | Path to folder containing all (source and target) translation files. |
| `targetFiles` | Inferred from current setup by `ng add` | Filenames (relative to `outputPath` of all target translation files (e.g. `["messages.fr.xlf", "messages.de.xlf"]`). |
Expand All @@ -59,7 +60,7 @@ In your `angular.json` the target `extract-i18n` that can be configured with the
| `includeMeaningAndDescription` | `true` | Whether to include the meaning and description information in the translation files. |
| `newTranslationTargetsBlank` | `false` | When `false` (default) the "target" of new translation units is set to the "source" value. When `true`, an empty string is used. When `'omit'`, no target element is created. |
| `sort` | `"stableAppendNew"` (will change to `stableAlphabetNew` with v3.0.0) | Sorting of all translation units in source and target translation files. Supported: <br>`"idAsc"` (sort by translation IDs), <br>`"stableAppendNew"` (keep existing sorting, append new translations at the end), <br>`"stableAlphabetNew"` (keep existing sorting, sort new translations next to alphabetical close IDs). |
| `builderI18n` | `"@angular-devkit/build-angular:extract-i18n"` | The builder to use for i18n extraction. Any custom builder should handle the same options as the default angular builder (browserTarget, outputPath, outFile, format, progress). |
| `builderI18n` | `"@angular-devkit/build-angular:extract-i18n"` | The builder to use for i18n extraction. Any custom builder should handle the same options as the default angular builder (buildTarget, outputPath, outFile, format, progress). |
| `verbose` | `false` | Extended/debug output - it is recommended to use this only for manual debugging. |

## Contribute
Expand Down
5 changes: 2 additions & 3 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import type {Config} from '@jest/types';
import {JestConfigWithTsJest} from 'ts-jest';

// Sync object
const config: Config.InitialOptions = {
const config: JestConfigWithTsJest = {
preset: 'ts-jest',
testEnvironment: 'node',
verbose: false,
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'],

};
export default config;
60 changes: 55 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ng-extract-i18n-merge",
"version": "2.10.0",
"version": "2.11.0-1",
"description": "Extract and merge i18n xliff translation files for angular projects.",
"main": "index.js",
"builders": "builders.json",
Expand Down
5 changes: 3 additions & 2 deletions schematics/migrations/2_0_0/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function updateNpmScript(tree: Tree, logger: SchematicContext['logger']) {
export default function (): Rule {
return (tree: Tree, context: SchematicContext) => {
updateNpmScript(tree, context.logger);
return updateWorkspace((workspace) => {
return updateWorkspace(async (workspace) => {
workspace.projects.forEach((project, projectName) => {
const i18nMergeTarget = project.targets.get('extract-i18n-merge');
if (i18nMergeTarget) {
Expand All @@ -32,8 +32,9 @@ export default function (): Rule {
i18nTarget.builder = 'ng-extract-i18n-merge:ng-extract-i18n-merge';
i18nTarget.options = {
...i18nMergeTarget.options,
browserTarget: i18nTarget.options?.browserTarget ?? `${projectName}:build`
buildTarget: i18nTarget.options?.browserTarget ?? i18nTarget.options?.buildTarget ?? `${projectName}:build`
}
delete i18nTarget.options.browserTarget;
project.targets.delete('extract-i18n'); // 'project.targets.set' not working!?
project.targets.add({name: 'extract-i18n', ...i18nTarget});
project.targets.delete('extract-i18n-merge');
Expand Down
20 changes: 7 additions & 13 deletions schematics/ng-add/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('ngAdd', () => {
expect(norm(tree.readContent('/angular.json'))).toContain(norm('"extract-i18n": {\n' +
' "builder": "ng-extract-i18n-merge:ng-extract-i18n-merge",\n' +
' "options": {\n' +
' "browserTarget": "bar:build",\n' +
' "buildTarget": "bar:build",\n' +
' "format": "xlf2",\n' +
' "outputPath": "src/locales",\n' +
' "targetFiles": []\n' +
Expand All @@ -72,11 +72,10 @@ describe('ngAdd', () => {
appTree.overwrite('/angular.json', JSON.stringify(angularJson));

const tree = await runSchematic(runner, 'ng-add', {}, appTree);

expect(norm(tree.readContent('/angular.json'))).toContain(norm('"extract-i18n": {\n' +
' "builder": "ng-extract-i18n-merge:ng-extract-i18n-merge",\n' +
' "options": {\n' +
' "browserTarget": "bar:build",\n' +
' "buildTarget": "bar:build",\n' +
' "format": "xlf",\n' +
' "outputPath": "src/other-path",\n' +
' "targetFiles": [ "messages.fr.xlf" ]\n' +
Expand Down Expand Up @@ -105,11 +104,10 @@ describe('ngAdd', () => {
appTree.create('/src/some-path/my-messages.xlf', '<>');

const tree = await runSchematic(runner, 'ng-add', {}, appTree);

expect(norm(tree.readContent('/angular.json'))).toContain(norm('"extract-i18n": {\n' +
' "builder": "ng-extract-i18n-merge:ng-extract-i18n-merge",\n' +
' "options": {\n' +
' "browserTarget": "bar:build",\n' +
' "buildTarget": "bar:build",\n' +
' "format": "xlf",\n' +
' "outputPath": "src/some-path",\n' +
' "targetFiles": [ "../other-path/messages.fr.xlf" ],\n' +
Expand All @@ -131,11 +129,10 @@ describe('ngAdd', () => {
appTree.overwrite('/angular.json', JSON.stringify(angularJson));

const tree = await runSchematic(runner, 'ng-add', {}, appTree);

expect(norm(tree.readContent('/angular.json'))).toContain(norm('"extract-i18n": {\n' +
' "builder": "ng-extract-i18n-merge:ng-extract-i18n-merge",\n' +
' "options": {\n' +
' "browserTarget": "bar:build",\n' +
' "buildTarget": "bar:build",\n' +
' "format": "xlf",\n' +
' "outputPath": "src/other-path",\n' +
' "targetFiles": [ "messages.fr.xlf" ]\n' +
Expand All @@ -153,11 +150,10 @@ describe('ngAdd', () => {
appTree.overwrite('/angular.json', JSON.stringify(angularJson));

const tree = await runSchematic(runner, 'ng-add', {}, appTree);

expect(norm(tree.readContent('/angular.json'))).toContain(norm('"extract-i18n": {\n' +
' "builder": "ng-extract-i18n-merge:ng-extract-i18n-merge",\n' +
' "options": {\n' +
' "browserTarget": "bar:build",\n' +
' "buildTarget": "bar:build",\n' +
' "format": "xlf",\n' +
' "outputPath": "src/other-path",\n' +
' "targetFiles": [ "messages.fr.xlf" ]\n' +
Expand All @@ -181,11 +177,10 @@ describe('ngAdd', () => {
appTree.overwrite('/angular.json', JSON.stringify(angularJson));

const tree = await runSchematic(runner, 'ng-add', {}, appTree);

expect(norm(tree.readContent('/angular.json'))).toContain(norm('"extract-i18n": {\n' +
' "builder": "ng-extract-i18n-merge:ng-extract-i18n-merge",\n' +
' "options": {\n' +
' "browserTarget": "bar:build",\n' +
' "buildTarget": "bar:build",\n' +
' "format": "xlf",\n' +
' "outputPath": "src/other-path",\n' +
' "targetFiles": [ "messages.fr.xlf" ]\n' +
Expand All @@ -210,11 +205,10 @@ describe('ngAdd', () => {
appTree.overwrite('/angular.json', JSON.stringify(angularJson));

const tree = await runSchematic(runner, 'ng-add', {}, appTree);

expect(norm(tree.readContent('/angular.json'))).toContain(norm('"extract-i18n": {\n' +
' "builder": "ng-extract-i18n-merge:ng-extract-i18n-merge",\n' +
' "options": {\n' +
' "browserTarget": "bar:build",\n' +
' "buildTarget": "bar:build",\n' +
' "format": "xlf2",\n' +
' "outputPath": "src/other-path",\n' +
' "targetFiles": [ "messages.fr.xlf" ]\n' +
Expand Down
Loading
Loading