|
9 | 9 | import type { BuilderContext } from '@angular-devkit/architect';
|
10 | 10 | import type { Plugin } from 'esbuild';
|
11 | 11 | import { realpathSync } from 'node:fs';
|
12 |
| -import { access, constants } from 'node:fs/promises'; |
| 12 | +import { access, constants, readFile } from 'node:fs/promises'; |
13 | 13 | import { createRequire } from 'node:module';
|
14 | 14 | import path from 'node:path';
|
15 | 15 | import { normalizeAssetPatterns, normalizeOptimization, normalizeSourceMaps } from '../../utils';
|
@@ -499,6 +499,7 @@ export async function normalizeOptions(
|
499 | 499 | templateUpdates: !!options.templateUpdates,
|
500 | 500 | incrementalResults: !!options.incrementalResults,
|
501 | 501 | customConditions: options.conditions,
|
| 502 | + frameworkVersion: await findFrameworkVersion(projectRoot), |
502 | 503 | };
|
503 | 504 | }
|
504 | 505 |
|
@@ -706,3 +707,22 @@ function normalizeExternals(value: string[] | undefined): string[] | undefined {
|
706 | 707 |
|
707 | 708 | return [...new Set(value.map((d) => (d.endsWith('/*') ? d.slice(0, -2) : d)))];
|
708 | 709 | }
|
| 710 | + |
| 711 | +async function findFrameworkVersion(projectRoot: string): Promise<string> { |
| 712 | + // Create a custom require function for ESM compliance. |
| 713 | + // NOTE: The trailing slash is significant. |
| 714 | + const projectResolve = createRequire(projectRoot + '/').resolve; |
| 715 | + |
| 716 | + try { |
| 717 | + const manifestPath = projectResolve('@angular/core/package.json'); |
| 718 | + const manifestData = await readFile(manifestPath, 'utf-8'); |
| 719 | + const manifestObject = JSON.parse(manifestData) as { version: string }; |
| 720 | + const version = manifestObject.version; |
| 721 | + |
| 722 | + return version; |
| 723 | + } catch { |
| 724 | + throw new Error( |
| 725 | + 'Error: It appears that "@angular/core" is missing as a dependency. Please ensure it is included in your project.', |
| 726 | + ); |
| 727 | + } |
| 728 | +} |
0 commit comments