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

change browser target to build target #94

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
90bd053
fix: only fall back to deprecated browserTarget attribute on older an…
daniel-sc Jan 17, 2024
1998ee9
ci: adding ci for nodejs 20
daniel-sc Jan 17, 2024
0a0a410
ci: use angular 13.1.3 as 13.1.4 has no release for @angular/core
daniel-sc Jan 17, 2024
68daf2a
ci: lock compiler-cli dependency to prevent version conflicts
daniel-sc Jan 24, 2024
4d31525
fixup: remove superfluous comma
daniel-sc Jan 24, 2024
962f1b6
fixup: correct interpolation
daniel-sc Jan 24, 2024
f5c54c5
fix: correct ts-jest config for importing mjs
daniel-sc Jan 24, 2024
55e9a4a
fix: little newer angular 13 version
daniel-sc Jan 24, 2024
080fc59
feat: add new option 'buildTarget' and deprecate 'browserTarget' - se…
daniel-sc Jan 25, 2024
ac0a07f
2.10.0-0
daniel-sc Jan 26, 2024
2357c0e
fix: use dynamic import to prevent error on ng add
daniel-sc Jan 26, 2024
880db44
2.10.0-1
daniel-sc Jan 26, 2024
99c03df
refactor: switch from commonjs to esm
daniel-sc Feb 5, 2024
6a6d3db
2.10.0-2
daniel-sc Feb 5, 2024
2f3de4b
Revert "refactor: switch from commonjs to esm"
daniel-sc Feb 7, 2024
c58cfd9
fix: load angular version via dynamic import that is not removed by ts
daniel-sc Feb 7, 2024
4f56bbd
fix: copy loadEsmModule as not present in older angular versions (and…
daniel-sc Feb 7, 2024
56b0694
fixup: use new loadEsmModule in test as well
daniel-sc Feb 7, 2024
b29d654
fix: build error: A jest worker process was terminated by another pro…
daniel-sc Feb 7, 2024
4ecf3cd
fix: another try for successfully running CI pipeline..
daniel-sc Feb 8, 2024
538ed97
another try..
daniel-sc Feb 8, 2024
cd9b659
check existence of config attribute instead of reading angular version
daniel-sc Feb 21, 2024
9f3634a
revert allowJs option
daniel-sc Feb 21, 2024
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
16 changes: 10 additions & 6 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,11 +47,11 @@ 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
- run: npm run test-coverage
- run: NODE_OPTIONS=--experimental-vm-modules npm run test-coverage
- name: Coveralls
uses: coverallsapp/github-action@v1.1.2
with:
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 @@ -57,7 +58,7 @@ In your `angular.json` the target `extract-i18n` that can be configured with the
| `includeContext` | `false` | Whether to include the context information (like notes) in the translation files. This is useful for sending the target translation files to translation agencies/services. When `sourceFileOnly`, the context is retained only in the `sourceFile`. |
| `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
8 changes: 5 additions & 3 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
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,
maxWorkers: 100,
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'],

};
export default config;
59 changes: 53 additions & 6 deletions package-lock.json

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

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ng-extract-i18n-merge",
"version": "2.9.1",
"version": "2.10.0-2",
"description": "Extract and merge i18n xliff translation files for angular projects.",
"main": "index.js",
"builders": "builders.json",
Expand Down Expand Up @@ -43,7 +43,8 @@
"xmldoc": "^1.1.2"
},
"peerDependencies": {
"@angular-devkit/build-angular": "^13.0.0 || ^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0"
"@angular-devkit/build-angular": "^13.0.0 || ^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0",
"@angular/core": "^13.0.0 || ^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0"
},
"devDependencies": {
"@types/jest": "^28.1.8 || ^29.0.0",
Expand Down
6 changes: 4 additions & 2 deletions schematics/migrations/2_0_0/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {Rule, SchematicContext, SchematicsException, Tree} from '@angular-devkit/schematics';
import {updateWorkspace} from '@schematics/angular/utility/workspace';
import * as extractI18nSchema from '@angular-devkit/build-angular/src/builders/extract-i18n/schema.json';

function updateNpmScript(tree: Tree, logger: SchematicContext['logger']) {
const pkgPath = '/package.json';
Expand All @@ -23,16 +24,17 @@ 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) {
context.logger.info(`updating extract-i18n(-merge) targets for project ${projectName}..`)
const buildTargetAttribute = extractI18nSchema.properties.buildTarget ? 'buildTarget' : 'browserTarget';
const i18nTarget = {...(project.targets.get('extract-i18n') ?? {builder: 'ng-extract-i18n-merge:ng-extract-i18n-merge'})};
i18nTarget.builder = 'ng-extract-i18n-merge:ng-extract-i18n-merge';
i18nTarget.options = {
...i18nMergeTarget.options,
browserTarget: i18nTarget.options?.browserTarget ?? `${projectName}:build`
[buildTargetAttribute]: i18nTarget.options?.browserTarget ?? i18nTarget.options?.buildTarget ?? `${projectName}:build`
}
project.targets.delete('extract-i18n'); // 'project.targets.set' not working!?
project.targets.add({name: 'extract-i18n', ...i18nTarget});
Expand Down
Loading
Loading