Skip to content

Commit

Permalink
fix: set nitropack as a peer dep of the env for v16+
Browse files Browse the repository at this point in the history
  • Loading branch information
ocombe committed Feb 19, 2024
1 parent 6f6b61a commit 9280aed
Show file tree
Hide file tree
Showing 16 changed files with 85 additions and 87 deletions.
3 changes: 2 additions & 1 deletion angular/app-types/angular-app-type/application.bundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
ApplicationOptions,
dedupPaths,
getLoggerApi,
loadEsmModule,
normalizePath
} from '@bitdev/angular.dev-services.common';
import {
Expand All @@ -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<ApplicationOptions>;
Expand Down
8 changes: 6 additions & 2 deletions angular/app-types/angular-app-type/application.dev-server.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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<ApplicationBuilderOptions & DevServerBuilderOptions>;
Expand Down
21 changes: 0 additions & 21 deletions angular/app-types/angular-app-type/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(modulePath: string): Promise<T> {
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<T>;
}
}
30 changes: 7 additions & 23 deletions angular/devkit/compiler/ng-packagr/ng-packagr.compiler.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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<T>(modulePath: string): Promise<T> {
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<T>;
}
}

export async function createDiagnosticsReporter(logger: Logger): Promise<DiagnosticsReporter> {
const { formatDiagnostics } = await loadEsmModule(`@angular/compiler-cli`);
const formatter = (diagnostic: Diagnostic) => formatDiagnostics([diagnostic]);
Expand Down
11 changes: 8 additions & 3 deletions angular/envs/angular-env/env.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions angular/envs/angular-v13-env/env.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -78,7 +78,7 @@
{
"name": "jest",
"version": "^27.4.4",
"supportedRange": "^27.4.0",
"supportedRange": "^27.4.0"
},
{
"name": "rxjs",
Expand Down
6 changes: 3 additions & 3 deletions angular/envs/angular-v14-env/env.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -78,7 +78,7 @@
{
"name": "jest",
"version": "^28.0.0",
"supportedRange": "^28.0.0",
"supportedRange": "^28.0.0"
},
{
"name": "rxjs",
Expand Down
6 changes: 3 additions & 3 deletions angular/envs/angular-v15-env/env.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -78,7 +78,7 @@
{
"name": "jest",
"version": "^29.3.1",
"supportedRange": "~29.3.0",
"supportedRange": "~29.3.0"
},
{
"name": "rxjs",
Expand Down
13 changes: 9 additions & 4 deletions angular/envs/angular-v16-env/env.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -116,6 +121,6 @@
"patterns": {
"compositions": ["**/*.composition.*", "**/*.preview.*"],
"docs": ["**/*.docs.*"],
"tests": ["**/*.spec.*", "**/*.test.*", "**/*.cy.*"],
"tests": ["**/*.spec.*", "**/*.test.*", "**/*.cy.*"]
}
}
13 changes: 9 additions & 4 deletions angular/envs/angular-v17-env/env.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -116,6 +121,6 @@
"patterns": {
"compositions": ["**/*.composition.*", "**/*.preview.*"],
"docs": ["**/*.docs.*"],
"tests": ["**/*.spec.*", "**/*.test.*", "**/*.cy.*"],
"tests": ["**/*.spec.*", "**/*.test.*", "**/*.cy.*"]
}
}
11 changes: 8 additions & 3 deletions angular/examples/my-angular-env/env.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions angular/examples/my-angular-v13-env/env.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -73,7 +73,7 @@
{
"name": "jest",
"version": "^27.4.4",
"supportedRange": "^27.4.0",
"supportedRange": "^27.4.0"
},
{
"name": "rxjs",
Expand Down
6 changes: 3 additions & 3 deletions angular/examples/my-angular-v14-env/env.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -73,7 +73,7 @@
{
"name": "jest",
"version": "^28.0.0",
"supportedRange": "^28.0.0",
"supportedRange": "^28.0.0"
},
{
"name": "rxjs",
Expand Down
6 changes: 3 additions & 3 deletions angular/examples/my-angular-v15-env/env.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -73,7 +73,7 @@
{
"name": "jest",
"version": "^29.3.1",
"supportedRange": "~29.3.0",
"supportedRange": "~29.3.0"
},
{
"name": "rxjs",
Expand Down
Loading

0 comments on commit 9280aed

Please sign in to comment.