From 9280aed1715534d6b362941e8e32e9d4f1c8da94 Mon Sep 17 00:00:00 2001 From: Olivier Combe Date: Mon, 19 Feb 2024 16:11:43 +0100 Subject: [PATCH] fix: set nitropack as a peer dep of the env for v16+ --- .../angular-app-type/application.bundler.ts | 3 +- .../application.dev-server.ts | 8 +++-- angular/app-types/angular-app-type/utils.ts | 21 ------------- .../ng-packagr/ng-packagr.compiler.ts | 30 +++++-------------- angular/envs/angular-env/env.jsonc | 11 +++++-- angular/envs/angular-v13-env/env.jsonc | 6 ++-- angular/envs/angular-v14-env/env.jsonc | 6 ++-- angular/envs/angular-v15-env/env.jsonc | 6 ++-- angular/envs/angular-v16-env/env.jsonc | 13 +++++--- angular/envs/angular-v17-env/env.jsonc | 13 +++++--- angular/examples/my-angular-env/env.jsonc | 11 +++++-- angular/examples/my-angular-v13-env/env.jsonc | 6 ++-- angular/examples/my-angular-v14-env/env.jsonc | 6 ++-- angular/examples/my-angular-v15-env/env.jsonc | 6 ++-- angular/examples/my-angular-v16-env/env.jsonc | 13 +++++--- angular/examples/my-angular-v17-env/env.jsonc | 13 +++++--- 16 files changed, 85 insertions(+), 87 deletions(-) diff --git a/angular/app-types/angular-app-type/application.bundler.ts b/angular/app-types/angular-app-type/application.bundler.ts index bce6370a..209191b7 100644 --- a/angular/app-types/angular-app-type/application.bundler.ts +++ b/angular/app-types/angular-app-type/application.bundler.ts @@ -5,6 +5,7 @@ import { ApplicationOptions, dedupPaths, getLoggerApi, + loadEsmModule, normalizePath } from '@bitdev/angular.dev-services.common'; import { @@ -18,7 +19,7 @@ import { outputFileSync, removeSync } from 'fs-extra'; import type { NitroConfig } from 'nitropack'; import { basename, extname, join, posix, relative, resolve } from 'path'; import definePlugin from './plugins/define.plugin'; -import { getIndexInputFile, loadEsmModule } from './utils'; +import { getIndexInputFile } from './utils'; export type BuildApplicationOptions = { angularOptions: Partial; diff --git a/angular/app-types/angular-app-type/application.dev-server.ts b/angular/app-types/angular-app-type/application.dev-server.ts index beec70b0..bc7aa074 100644 --- a/angular/app-types/angular-app-type/application.dev-server.ts +++ b/angular/app-types/angular-app-type/application.dev-server.ts @@ -1,7 +1,12 @@ /* eslint-disable no-param-reassign */ import { executeDevServerBuilder, OutputHashing } from '@angular-devkit/build-angular'; import { VERSION } from '@angular/cli'; -import { dedupPaths, getLoggerApi, normalizePath } from '@bitdev/angular.dev-services.common'; +import { + dedupPaths, + getLoggerApi, + loadEsmModule, + normalizePath +} from '@bitdev/angular.dev-services.common'; import { type ApplicationBuilderOptions, type DevServerBuilderOptions @@ -15,7 +20,6 @@ import { join, posix, relative, resolve } from 'path'; // @ts-ignore import type { Connect } from 'vite'; import definePlugin from './plugins/define.plugin'; -import { loadEsmModule } from './utils'; export type ServeApplicationOptions = { angularOptions: Partial; diff --git a/angular/app-types/angular-app-type/utils.ts b/angular/app-types/angular-app-type/utils.ts index e43765dd..d6c2b1f3 100644 --- a/angular/app-types/angular-app-type/utils.ts +++ b/angular/app-types/angular-app-type/utils.ts @@ -63,24 +63,3 @@ export function getIndexInputFile(index: ApplicationOptions['index']): string { } return (index as any).input; } - -/** - * This uses a dynamic import to load a module which may be ESM. - * CommonJS code can load ESM code via a dynamic import. Unfortunately, TypeScript - * will currently, unconditionally downlevel dynamic import into a require call. - * require calls cannot load ESM code and will result in a runtime error. To work around - * this, a Function constructor is used to prevent TypeScript from changing the dynamic import. - * Once TypeScript provides support for keeping the dynamic import, this workaround can - * be dropped. - * - * @param modulePath The path of the module to load. - * @returns A Promise that resolves to the dynamically imported module. - */ -export async function loadEsmModule(modulePath: string): Promise { - try { - return await import(modulePath); - } catch (e) { - // eslint-disable-next-line @typescript-eslint/no-implied-eval - return new Function('modulePath', `return import(modulePath)`)(modulePath) as Promise; - } -} diff --git a/angular/devkit/compiler/ng-packagr/ng-packagr.compiler.ts b/angular/devkit/compiler/ng-packagr/ng-packagr.compiler.ts index 66d2166f..8ffe276a 100644 --- a/angular/devkit/compiler/ng-packagr/ng-packagr.compiler.ts +++ b/angular/devkit/compiler/ng-packagr/ng-packagr.compiler.ts @@ -1,9 +1,14 @@ -import type { AngularCompilerOptions, ParsedConfiguration, CompilerOptions } from '@angular/compiler-cli'; +import type { + AngularCompilerOptions, + CompilerOptions, + ParsedConfiguration +} from '@angular/compiler-cli'; import { AngularEnvOptions, componentIsApp, getNodeModulesPaths, - getWorkspace + getWorkspace, + loadEsmModule } from '@bitdev/angular.dev-services.common'; import { ApplicationAspect, ApplicationMain } from '@teambit/application'; import { @@ -43,27 +48,6 @@ export function isFatalDiagnosticError(err: any): err is FatalDiagnosticError { return err._isFatalDiagnosticError === true; } -/** - * This uses a dynamic import to load a module which may be ESM. - * CommonJS code can load ESM code via a dynamic import. Unfortunately, TypeScript - * will currently, unconditionally downlevel dynamic import into a require call. - * require calls cannot load ESM code and will result in a runtime error. To work around - * this, a Function constructor is used to prevent TypeScript from changing the dynamic import. - * Once TypeScript provides support for keeping the dynamic import, this workaround can - * be dropped. - * - * @param modulePath The path of the module to load. - * @returns A Promise that resolves to the dynamically imported module. - */ -export async function loadEsmModule(modulePath: string): Promise { - try { - return await import(modulePath); - } catch (e) { - // eslint-disable-next-line @typescript-eslint/no-implied-eval - return new Function('modulePath', `return import(modulePath)`)(modulePath) as Promise; - } -} - export async function createDiagnosticsReporter(logger: Logger): Promise { const { formatDiagnostics } = await loadEsmModule(`@angular/compiler-cli`); const formatter = (diagnostic: Diagnostic) => formatDiagnostics([diagnostic]); diff --git a/angular/envs/angular-env/env.jsonc b/angular/envs/angular-env/env.jsonc index 4aecd9ec..091ee6a3 100644 --- a/angular/envs/angular-env/env.jsonc +++ b/angular/envs/angular-env/env.jsonc @@ -48,12 +48,12 @@ { "name": "@angular/compiler", "version": "^17.0.0", - "supportedRange": "^17.0.0", + "supportedRange": "^17.0.0" }, { "name": "@angular/compiler-cli", "version": "^17.0.0", - "supportedRange": "^17.0.0", + "supportedRange": "^17.0.0" }, { "name": "@angular/core", @@ -83,7 +83,12 @@ { "name": "jest", "version": "^29.5.0", - "supportedRange": "^29.5.0", + "supportedRange": "^29.5.0" + }, + { + "name": "nitropack", + "version": "^2.8.0", + "supportedRange": "^2.8.0" }, { "name": "rxjs", diff --git a/angular/envs/angular-v13-env/env.jsonc b/angular/envs/angular-v13-env/env.jsonc index d6b87c4c..aa2b4f84 100644 --- a/angular/envs/angular-v13-env/env.jsonc +++ b/angular/envs/angular-v13-env/env.jsonc @@ -48,12 +48,12 @@ { "name": "@angular/compiler", "version": "~13.2.0", - "supportedRange": "^13.0.0", + "supportedRange": "^13.0.0" }, { "name": "@angular/compiler-cli", "version": "~13.2.0", - "supportedRange": "^13.0.0", + "supportedRange": "^13.0.0" }, { "name": "@angular/core", @@ -78,7 +78,7 @@ { "name": "jest", "version": "^27.4.4", - "supportedRange": "^27.4.0", + "supportedRange": "^27.4.0" }, { "name": "rxjs", diff --git a/angular/envs/angular-v14-env/env.jsonc b/angular/envs/angular-v14-env/env.jsonc index b10bc0c1..215e0e37 100644 --- a/angular/envs/angular-v14-env/env.jsonc +++ b/angular/envs/angular-v14-env/env.jsonc @@ -48,12 +48,12 @@ { "name": "@angular/compiler", "version": "~14.0.2", - "supportedRange": "^14.0.0", + "supportedRange": "^14.0.0" }, { "name": "@angular/compiler-cli", "version": "~14.0.2", - "supportedRange": "^14.0.0", + "supportedRange": "^14.0.0" }, { "name": "@angular/core", @@ -78,7 +78,7 @@ { "name": "jest", "version": "^28.0.0", - "supportedRange": "^28.0.0", + "supportedRange": "^28.0.0" }, { "name": "rxjs", diff --git a/angular/envs/angular-v15-env/env.jsonc b/angular/envs/angular-v15-env/env.jsonc index 1bdbf7e7..ce7f79f2 100644 --- a/angular/envs/angular-v15-env/env.jsonc +++ b/angular/envs/angular-v15-env/env.jsonc @@ -48,12 +48,12 @@ { "name": "@angular/compiler", "version": "~15.0.4", - "supportedRange": "^15.0.0", + "supportedRange": "^15.0.0" }, { "name": "@angular/compiler-cli", "version": "~15.0.4", - "supportedRange": "^15.0.0", + "supportedRange": "^15.0.0" }, { "name": "@angular/core", @@ -78,7 +78,7 @@ { "name": "jest", "version": "^29.3.1", - "supportedRange": "~29.3.0", + "supportedRange": "~29.3.0" }, { "name": "rxjs", diff --git a/angular/envs/angular-v16-env/env.jsonc b/angular/envs/angular-v16-env/env.jsonc index 30930fd2..2d2f5a59 100644 --- a/angular/envs/angular-v16-env/env.jsonc +++ b/angular/envs/angular-v16-env/env.jsonc @@ -48,12 +48,12 @@ { "name": "@angular/compiler", "version": "~16.2.0", - "supportedRange": "^16.2.0", + "supportedRange": "^16.2.0" }, { "name": "@angular/compiler-cli", "version": "~16.2.0", - "supportedRange": "^16.2.0", + "supportedRange": "^16.2.0" }, { "name": "@angular/core", @@ -83,7 +83,12 @@ { "name": "jest", "version": "^29.5.0", - "supportedRange": "^29.5.0", + "supportedRange": "^29.5.0" + }, + { + "name": "nitropack", + "version": "^2.8.0", + "supportedRange": "^2.8.0" }, { "name": "rxjs", @@ -116,6 +121,6 @@ "patterns": { "compositions": ["**/*.composition.*", "**/*.preview.*"], "docs": ["**/*.docs.*"], - "tests": ["**/*.spec.*", "**/*.test.*", "**/*.cy.*"], + "tests": ["**/*.spec.*", "**/*.test.*", "**/*.cy.*"] } } diff --git a/angular/envs/angular-v17-env/env.jsonc b/angular/envs/angular-v17-env/env.jsonc index d0cf9158..091ee6a3 100644 --- a/angular/envs/angular-v17-env/env.jsonc +++ b/angular/envs/angular-v17-env/env.jsonc @@ -48,12 +48,12 @@ { "name": "@angular/compiler", "version": "^17.0.0", - "supportedRange": "^17.0.0", + "supportedRange": "^17.0.0" }, { "name": "@angular/compiler-cli", "version": "^17.0.0", - "supportedRange": "^17.0.0", + "supportedRange": "^17.0.0" }, { "name": "@angular/core", @@ -83,7 +83,12 @@ { "name": "jest", "version": "^29.5.0", - "supportedRange": "^29.5.0", + "supportedRange": "^29.5.0" + }, + { + "name": "nitropack", + "version": "^2.8.0", + "supportedRange": "^2.8.0" }, { "name": "rxjs", @@ -116,6 +121,6 @@ "patterns": { "compositions": ["**/*.composition.*", "**/*.preview.*"], "docs": ["**/*.docs.*"], - "tests": ["**/*.spec.*", "**/*.test.*", "**/*.cy.*"], + "tests": ["**/*.spec.*", "**/*.test.*", "**/*.cy.*"] } } diff --git a/angular/examples/my-angular-env/env.jsonc b/angular/examples/my-angular-env/env.jsonc index 4aecd9ec..091ee6a3 100644 --- a/angular/examples/my-angular-env/env.jsonc +++ b/angular/examples/my-angular-env/env.jsonc @@ -48,12 +48,12 @@ { "name": "@angular/compiler", "version": "^17.0.0", - "supportedRange": "^17.0.0", + "supportedRange": "^17.0.0" }, { "name": "@angular/compiler-cli", "version": "^17.0.0", - "supportedRange": "^17.0.0", + "supportedRange": "^17.0.0" }, { "name": "@angular/core", @@ -83,7 +83,12 @@ { "name": "jest", "version": "^29.5.0", - "supportedRange": "^29.5.0", + "supportedRange": "^29.5.0" + }, + { + "name": "nitropack", + "version": "^2.8.0", + "supportedRange": "^2.8.0" }, { "name": "rxjs", diff --git a/angular/examples/my-angular-v13-env/env.jsonc b/angular/examples/my-angular-v13-env/env.jsonc index af657c08..a0dcc770 100644 --- a/angular/examples/my-angular-v13-env/env.jsonc +++ b/angular/examples/my-angular-v13-env/env.jsonc @@ -48,12 +48,12 @@ { "name": "@angular/compiler", "version": "~13.2.0", - "supportedRange": "^13.0.0", + "supportedRange": "^13.0.0" }, { "name": "@angular/compiler-cli", "version": "~13.2.0", - "supportedRange": "^13.0.0", + "supportedRange": "^13.0.0" }, { "name": "@angular/core", @@ -73,7 +73,7 @@ { "name": "jest", "version": "^27.4.4", - "supportedRange": "^27.4.0", + "supportedRange": "^27.4.0" }, { "name": "rxjs", diff --git a/angular/examples/my-angular-v14-env/env.jsonc b/angular/examples/my-angular-v14-env/env.jsonc index ec6bf75b..b2c9f51b 100644 --- a/angular/examples/my-angular-v14-env/env.jsonc +++ b/angular/examples/my-angular-v14-env/env.jsonc @@ -48,12 +48,12 @@ { "name": "@angular/compiler", "version": "~14.0.2", - "supportedRange": "^14.0.0", + "supportedRange": "^14.0.0" }, { "name": "@angular/compiler-cli", "version": "~14.0.2", - "supportedRange": "^14.0.0", + "supportedRange": "^14.0.0" }, { "name": "@angular/core", @@ -73,7 +73,7 @@ { "name": "jest", "version": "^28.0.0", - "supportedRange": "^28.0.0", + "supportedRange": "^28.0.0" }, { "name": "rxjs", diff --git a/angular/examples/my-angular-v15-env/env.jsonc b/angular/examples/my-angular-v15-env/env.jsonc index 0f4d544a..1e117c93 100644 --- a/angular/examples/my-angular-v15-env/env.jsonc +++ b/angular/examples/my-angular-v15-env/env.jsonc @@ -48,12 +48,12 @@ { "name": "@angular/compiler", "version": "~15.0.4", - "supportedRange": "^15.0.0", + "supportedRange": "^15.0.0" }, { "name": "@angular/compiler-cli", "version": "~15.0.4", - "supportedRange": "^15.0.0", + "supportedRange": "^15.0.0" }, { "name": "@angular/core", @@ -73,7 +73,7 @@ { "name": "jest", "version": "^29.3.1", - "supportedRange": "~29.3.0", + "supportedRange": "~29.3.0" }, { "name": "rxjs", diff --git a/angular/examples/my-angular-v16-env/env.jsonc b/angular/examples/my-angular-v16-env/env.jsonc index b53502c9..f14e0dbb 100644 --- a/angular/examples/my-angular-v16-env/env.jsonc +++ b/angular/examples/my-angular-v16-env/env.jsonc @@ -48,12 +48,12 @@ { "name": "@angular/compiler", "version": "~16.2.0", - "supportedRange": "^16.2.0", + "supportedRange": "^16.2.0" }, { "name": "@angular/compiler-cli", "version": "~16.2.0", - "supportedRange": "^16.2.0", + "supportedRange": "^16.2.0" }, { "name": "@angular/core", @@ -73,7 +73,12 @@ { "name": "jest", "version": "^29.5.0", - "supportedRange": "^29.5.0", + "supportedRange": "^29.5.0" + }, + { + "name": "nitropack", + "version": "^2.8.0", + "supportedRange": "^2.8.0" }, { "name": "rxjs", @@ -106,6 +111,6 @@ "patterns": { "compositions": ["**/*.composition.*", "**/*.preview.*"], "docs": ["**/*.docs.*"], - "tests": ["**/*.spec.*", "**/*.test.*", "**/*.cy.*"], + "tests": ["**/*.spec.*", "**/*.test.*", "**/*.cy.*"] } } diff --git a/angular/examples/my-angular-v17-env/env.jsonc b/angular/examples/my-angular-v17-env/env.jsonc index d0cf9158..091ee6a3 100644 --- a/angular/examples/my-angular-v17-env/env.jsonc +++ b/angular/examples/my-angular-v17-env/env.jsonc @@ -48,12 +48,12 @@ { "name": "@angular/compiler", "version": "^17.0.0", - "supportedRange": "^17.0.0", + "supportedRange": "^17.0.0" }, { "name": "@angular/compiler-cli", "version": "^17.0.0", - "supportedRange": "^17.0.0", + "supportedRange": "^17.0.0" }, { "name": "@angular/core", @@ -83,7 +83,12 @@ { "name": "jest", "version": "^29.5.0", - "supportedRange": "^29.5.0", + "supportedRange": "^29.5.0" + }, + { + "name": "nitropack", + "version": "^2.8.0", + "supportedRange": "^2.8.0" }, { "name": "rxjs", @@ -116,6 +121,6 @@ "patterns": { "compositions": ["**/*.composition.*", "**/*.preview.*"], "docs": ["**/*.docs.*"], - "tests": ["**/*.spec.*", "**/*.test.*", "**/*.cy.*"], + "tests": ["**/*.spec.*", "**/*.test.*", "**/*.cy.*"] } }