Skip to content

Commit

Permalink
refactor: switch from commonjs to esm
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-sc committed Feb 5, 2024
1 parent 880db44 commit 99c03df
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 6 deletions.
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"version": "2.10.0-1",
"description": "Extract and merge i18n xliff translation files for angular projects.",
"main": "index.js",
"type": "module",
"exports": {
".": "./index.js"
},
"builders": "builders.json",
"schematics": "./schematics/collection.json",
"ng-add": {
Expand Down
2 changes: 1 addition & 1 deletion 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 {VERSION} from '@angular/core';

function updateNpmScript(tree: Tree, logger: SchematicContext['logger']) {
const pkgPath = '/package.json';
Expand All @@ -24,7 +25,6 @@ export default function (): Rule {
return (tree: Tree, context: SchematicContext) => {
updateNpmScript(tree, context.logger);
return updateWorkspace(async (workspace) => {
const {VERSION} = await import('@angular/core');
workspace.projects.forEach((project, projectName) => {
const i18nMergeTarget = project.targets.get('extract-i18n-merge');
if (i18nMergeTarget) {
Expand Down
3 changes: 1 addition & 2 deletions schematics/ng-add/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import {Rule, SchematicContext, SchematicsException, Tree} from '@angular-devkit
import {updateWorkspace} from '@schematics/angular/utility/workspace';
import {Schema} from './schema';
import {JsonArray, JsonObject, normalize, Path, relative} from '@angular-devkit/core';

import {Options} from '../../src/options';
import {VERSION} from '@angular/core';

function getTargetFiles(i18nExtension: JsonObject | undefined): string[] {
const locales = i18nExtension?.locales ? (Object.values(i18nExtension?.locales) as JsonArray | string[] | undefined) : undefined;
Expand Down Expand Up @@ -93,7 +93,6 @@ export function ngAdd(_options: Schema): Rule {
const filesWithoutOutputPath = files?.map(f => relative(`/${outputPath}` as Path, `/${f}` as Path));

const target = projectWorkspace.targets.get('extract-i18n');
const {VERSION} = await import('@angular/core');
const angularMajorVersion = parseInt(VERSION.major);
const buildTargetAttribute = angularMajorVersion >= 17 ? 'buildTarget' : 'browserTarget';
const builderOptions: Partial<Options> = {
Expand Down
2 changes: 1 addition & 1 deletion src/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {TranslationFile, TranslationUnit} from './model/translationFileModels';
import {Merger} from './merger';
import {Options} from './options';
import {doCollapseWhitespace} from './stringUtils';
import {VERSION} from '@angular/core';


const STATE_INITIAL_XLF_2_0 = 'initial';
Expand Down Expand Up @@ -106,7 +107,6 @@ async function extractI18nMergeBuilder(options: Options, context: BuilderContext
const sourcePath = join(normalize(outputPath), options.sourceFile ?? 'messages.xlf');
const translationSourceFileOriginal = fromXlf(await readFileIfExists(sourcePath));

const {VERSION} = await import('@angular/core');
const angularMajorVersion = parseInt(VERSION.major);
const buildTargetAttribute = angularMajorVersion >= 17 ? 'buildTarget' : 'browserTarget';
const extractI18nRun = await context.scheduleBuilder(options.builderI18n ?? '@angular-devkit/build-angular:extract-i18n', {
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
"module": "ES2015", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
// "lib": [], /* Specify library files to be included in the compilation. */
"allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
Expand Down Expand Up @@ -44,7 +44,7 @@
// "noPropertyAccessFromIndexSignature": true, /* Require undeclared properties from index signatures to use element accesses. */

/* Module Resolution Options */
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
Expand Down

0 comments on commit 99c03df

Please sign in to comment.