Skip to content

Commit 6878a37

Browse files
committed
fixup! fix(@angular/build): re-analyze exports on package.json change in library builder
1 parent 7532ec5 commit 6878a37

12 files changed

Lines changed: 176 additions & 153 deletions

File tree

‎packages/angular/build/src/builders/library/builder.ts‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,11 @@ import { purgeStaleBuildCache } from '../../utils/purge-cache';
2424
import { getSupportedBrowsers } from '../../utils/supported-browsers';
2525
import { assertCompatibleAngularVersion } from '../../utils/version';
2626
import type { BuildWatcher } from '../../utils/watcher';
27-
import {
28-
type NormalizedLibraryOptions,
29-
type PackageJsonData,
30-
normalizeLibraryOptions,
31-
} from './options';
32-
import type { SingleBuildState } from './pipeline/build-action';
27+
import { normalizeLibraryOptions } from './options';
3328
import { updateWatchedEntryPoints } from './pipeline/entry-points';
3429
import type { createComponentStylesheetBundlerForLibrary } from './pipeline/stylesheet-bundler';
3530
import type { Schema as LibraryBuilderOptions } from './schema';
31+
import type { NormalizedLibraryOptions, PackageJsonData, SingleBuildState } from './types';
3632

3733
/**
3834
* Executes the library builder to compile, bundle, and package an Angular library into the Angular Package Format (APF).

‎packages/angular/build/src/builders/library/options.ts‎

Lines changed: 2 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -16,64 +16,14 @@ import { assertIsError } from '../../utils/error';
1616
import { normalizeCacheOptions } from '../../utils/normalize-cache';
1717
import { isSubDirectory } from '../../utils/path';
1818
import {
19-
type PostcssConfiguration,
2019
generateSearchDirectories,
2120
getTailwindConfig,
2221
loadPostcssConfiguration,
2322
} from '../../utils/postcss-configuration';
2423
import { getProjectRootPaths } from '../../utils/project-metadata';
25-
import { type NormalizedEntryPoint, normalizeEntryPoints } from './pipeline/entry-points';
24+
import { normalizeEntryPoints } from './pipeline/entry-points';
2625
import type { Schema as LibraryBuilderOptions } from './schema';
27-
28-
export type { NormalizedEntryPoint } from './pipeline/entry-points';
29-
30-
export interface PackageJsonData {
31-
name: string;
32-
version?: string;
33-
type?: string;
34-
main?: string;
35-
module?: string;
36-
typings?: string;
37-
types?: string;
38-
sideEffects?: boolean | string[];
39-
exports?: string | Record<string, unknown>;
40-
scripts?: Record<string, string>;
41-
workspaces?: unknown;
42-
dependencies?: Record<string, string>;
43-
optionalDependencies?: Record<string, string>;
44-
peerDependencies?: Record<string, string>;
45-
peerDependenciesMeta?: Record<string, { optional?: boolean }>;
46-
[key: string]: unknown;
47-
}
48-
49-
export interface NormalizedLibraryOptions {
50-
workspaceRoot: string;
51-
projectRoot: string;
52-
packageName: string;
53-
packageJson: PackageJsonData;
54-
outputPath: string;
55-
deleteOutputPath: boolean;
56-
packageJsonPath: string;
57-
tsConfigPath: string;
58-
entryPoints: Map<string, NormalizedEntryPoint>;
59-
inlineStyleLanguage: 'css' | 'less' | 'sass' | 'scss';
60-
styleIncludePaths: string[];
61-
sass?: StylesheetPluginsass;
62-
assets: ReturnType<typeof normalizeAssetPatterns>;
63-
compilationMode: 'partial' | 'full';
64-
declarationMap: boolean;
65-
allowedNonPeerDependencies: RegExp[];
66-
keepLifecycleScripts: boolean;
67-
watch: boolean;
68-
poll?: number;
69-
preserveSymlinks: boolean;
70-
progress: boolean;
71-
clearScreen?: boolean;
72-
cacheOptions: ReturnType<typeof normalizeCacheOptions>;
73-
postcssConfiguration?: { config: PostcssConfiguration; configPath: string };
74-
tailwindConfiguration?: { file: string; package: string };
75-
colors: boolean;
76-
}
26+
import type { NormalizedLibraryOptions, PackageJsonData } from './types';
7727

7828
export async function normalizeLibraryOptions(
7929
context: BuilderContext,

‎packages/angular/build/src/builders/library/pipeline/assets.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import path from 'node:path';
1111
import picomatch from 'picomatch';
1212
import { toPosixPath } from '../../../utils/path';
1313
import { DEFAULT_ASSET_IGNORE, resolveAssets } from '../../../utils/resolve-assets';
14-
import type { NormalizedLibraryOptions } from '../options';
14+
import type { NormalizedLibraryOptions } from '../types';
1515
import { type DiskOutputFile, createDiskOutputFile } from './utils';
1616

1717
/**

‎packages/angular/build/src/builders/library/pipeline/build-action.ts‎

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,14 @@ import { constants, copyFile, mkdir, writeFile } from 'node:fs/promises';
1111
import path from 'node:path';
1212
import { emitFilesToDisk } from '../../../tools/esbuild/utils';
1313
import { toPosixPath } from '../../../utils/path';
14-
import type { NormalizedLibraryOptions } from '../options';
14+
import type { NormalizedLibraryOptions, SingleBuildState } from '../types';
1515
import { collectAssetsToEmit } from './assets';
16-
import { type BundleEntryPointInput, type BundleResult, bundleEntryPoints } from './bundler';
17-
import { type SingleProgramCache, compileLibrary } from './compilation';
16+
import { type BundleEntryPointInput, bundleEntryPoints } from './bundler';
17+
import { compileLibrary } from './compilation';
1818
import { generatePackageManifests } from './package-manifests';
1919
import type { createComponentStylesheetBundlerForLibrary } from './stylesheet-bundler';
2020
import type { OutputFile } from './utils';
2121

22-
/**
23-
* State preserved across incremental builds in watch mode.
24-
*/
25-
export interface SingleBuildState {
26-
singleProgramCache?: SingleProgramCache;
27-
previousBundleResults: Map<string, BundleResult>;
28-
pendingChangedEsmFiles: Set<string>;
29-
pendingChangedDtsFiles: Set<string>;
30-
hasCompilationError?: boolean;
31-
hasEmittedManifests?: boolean;
32-
hasEmittedAssets?: boolean;
33-
hasEntryPointsChanges?: boolean;
34-
directoryExists: Set<string>;
35-
}
36-
3722
/**
3823
* Creates a fresh {@link SingleBuildState} instance.
3924
*/

‎packages/angular/build/src/builders/library/pipeline/bundler.ts‎

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,14 @@ import {
1717
} from 'rolldown';
1818
import { dts } from 'rolldown-plugin-dts';
1919
import { toPosixPath } from '../../../utils/path';
20-
import type { NormalizedEntryPoint, NormalizedLibraryOptions } from '../options';
20+
import type { BundleResult, NormalizedEntryPoint, NormalizedLibraryOptions } from '../types';
2121
import {
2222
FESM_OUTPUT_DIR,
2323
type MemoryOutputFile,
2424
TYPES_OUTPUT_DIR,
2525
createMemoryOutputFile,
2626
} from './utils';
2727

28-
/**
29-
* Cached module ID sets for a bundled entry point.
30-
*/
31-
export interface BundleResult {
32-
/** Exact set of virtual ESM module IDs bundled into this entry point. */
33-
esmModuleIds: ReadonlySet<string>;
34-
35-
/** Exact set of virtual DTS module IDs bundled into this entry point. */
36-
dtsModuleIds: ReadonlySet<string>;
37-
}
38-
3928
/**
4029
* Output of the entry point bundling process.
4130
*/

‎packages/angular/build/src/builders/library/pipeline/compilation.ts‎

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,11 @@ import {
1515
import type { ComponentStylesheetBundler } from '../../../tools/esbuild/angular/component-stylesheets';
1616
import { useTypeChecking } from '../../../utils/environment-options';
1717
import { toPosixPath } from '../../../utils/path';
18-
import type { NormalizedEntryPoint, NormalizedLibraryOptions } from '../options';
18+
import type { NormalizedEntryPoint, NormalizedLibraryOptions, SingleProgramCache } from '../types';
1919
import { isDeclarationFile, isDeclarationSourceMapFile } from './utils';
2020

2121
const EMITTED_EXTENSIONS = ['.js', '.mjs', '.cjs', '.d.ts', '.d.mts', '.d.cts'];
2222

23-
/**
24-
* Cached state for the single unified library compilation.
25-
*/
26-
export interface SingleProgramCache {
27-
/** The active Angular compilation instance. */
28-
readonly compilationInstance: AngularCompilation;
29-
30-
/** In-memory map of emitted JavaScript files keyed by relative output path. */
31-
readonly esmFiles: Map<string, string>;
32-
33-
/** In-memory map of emitted TypeScript declaration files keyed by relative output path. */
34-
readonly dtsFiles: Map<string, string>;
35-
36-
/** Set of file paths that failed during stylesheet bundling or compilation. */
37-
readonly failedFiles?: ReadonlySet<string>;
38-
}
39-
4023
/**
4124
* Output of the unified library compilation step.
4225
*/

‎packages/angular/build/src/builders/library/pipeline/entry-points.ts‎

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,12 @@
88

99
import path from 'node:path';
1010
import { toPosixPath } from '../../../utils/path';
11-
12-
export interface NormalizedEntryPoint {
13-
/** The subpath in package.json exports (e.g. '.' or './testing'). */
14-
subpath: string;
15-
16-
/** Subpath name without leading './' (e.g. '.' or 'testing'). */
17-
name: string;
18-
19-
/** Display name of the entry point (e.g. '@my/lib' or '@my/lib/testing'). */
20-
displayName: string;
21-
22-
/** Base name of the output bundle (e.g. 'my-lib' or 'my-lib-testing'). */
23-
bundleName: string;
24-
25-
/** Absolute path to entry file. */
26-
entryFilePath: string;
27-
28-
/** Is this the primary entry point ('.')? */
29-
isPrimary: boolean;
30-
}
11+
import type {
12+
NormalizedEntryPoint,
13+
NormalizedLibraryOptions,
14+
PackageJsonData,
15+
SingleBuildState,
16+
} from '../types';
3117

3218
/**
3319
* Computes the base bundle file name for an entry point.
@@ -213,16 +199,9 @@ export function haveEntryPointsChanged(
213199
* Updates watched files, entry points in options, and cached bundle results when package.json entry points change.
214200
*/
215201
export function updateWatchedEntryPoints(
216-
packageJson: { exports?: unknown; name?: string },
217-
options: {
218-
entryPoints: Map<string, NormalizedEntryPoint>;
219-
projectRoot: string;
220-
packageName: string;
221-
},
222-
buildState: {
223-
previousBundleResults: Map<string, unknown>;
224-
hasEntryPointsChanges?: boolean;
225-
},
202+
packageJson: PackageJsonData,
203+
options: NormalizedLibraryOptions,
204+
buildState: SingleBuildState,
226205
allWatchedFiles: Set<string>,
227206
packageJsonPath: string,
228207
): void {

‎packages/angular/build/src/builders/library/pipeline/entry-points_spec.ts‎

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,14 @@
88

99
import { join, resolve } from 'node:path';
1010
import { toPosixPath } from '../../../utils/path';
11+
import type {
12+
BundleResult,
13+
NormalizedEntryPoint,
14+
NormalizedLibraryOptions,
15+
PackageJsonData,
16+
SingleBuildState,
17+
} from '../types';
1118
import {
12-
type NormalizedEntryPoint,
1319
getEntryPointBundleName,
1420
haveEntryPointsChanged,
1521
normalizeEntryPoints,
@@ -349,19 +355,20 @@ describe('entry-points pipeline', () => {
349355
entryPoints: initialEntryPoints,
350356
projectRoot,
351357
packageName,
352-
};
358+
} as unknown as NormalizedLibraryOptions;
353359

354360
const buildState = {
355-
previousBundleResults: new Map<string, unknown>([
356-
['.', { result: 'primary' }],
357-
['old-feature', { result: 'old' }],
361+
previousBundleResults: new Map<string, BundleResult>([
362+
['.', { esmModuleIds: new Set(), dtsModuleIds: new Set() }],
363+
['old-feature', { esmModuleIds: new Set(), dtsModuleIds: new Set() }],
358364
]),
359365
hasEntryPointsChanges: false,
360-
};
366+
} as unknown as SingleBuildState;
361367

362368
const allWatchedFiles = new Set<string>();
363369

364-
const newPackageJson = {
370+
const newPackageJson: PackageJsonData = {
371+
name: packageName,
365372
exports: {
366373
'.': './src/public-api.ts',
367374
'./new-feature': './new-feature/src/public-api.ts',
@@ -402,19 +409,20 @@ describe('entry-points pipeline', () => {
402409
entryPoints: initialEntryPoints,
403410
projectRoot,
404411
packageName,
405-
};
412+
} as unknown as NormalizedLibraryOptions;
406413

407414
const buildState = {
408-
previousBundleResults: new Map<string, unknown>([
409-
['.', { result: 'primary' }],
410-
['feature', { result: 'feature' }],
415+
previousBundleResults: new Map<string, BundleResult>([
416+
['.', { esmModuleIds: new Set(), dtsModuleIds: new Set() }],
417+
['feature', { esmModuleIds: new Set(), dtsModuleIds: new Set() }],
411418
]),
412419
hasEntryPointsChanges: false,
413-
};
420+
} as unknown as SingleBuildState;
414421

415422
const allWatchedFiles = new Set<string>();
416423

417-
const samePackageJson = {
424+
const samePackageJson: PackageJsonData = {
425+
name: packageName,
418426
exports: {
419427
'.': './src/public-api.ts',
420428
'./feature': './feature/src/public-api.ts',

‎packages/angular/build/src/builders/library/pipeline/package-manifests.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import path from 'node:path';
10-
import type { NormalizedLibraryOptions, PackageJsonData } from '../options';
10+
import type { NormalizedLibraryOptions, PackageJsonData } from '../types';
1111
import {
1212
FESM_OUTPUT_DIR,
1313
type MemoryOutputFile,

‎packages/angular/build/src/builders/library/pipeline/package-manifests_spec.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import assert from 'node:assert';
1010
import { join } from 'node:path';
11-
import type { NormalizedEntryPoint, NormalizedLibraryOptions, PackageJsonData } from '../options';
11+
import type { NormalizedEntryPoint, NormalizedLibraryOptions, PackageJsonData } from '../types';
1212
import { getEntryPointBundleName } from './entry-points';
1313
import { generatePackageManifests } from './package-manifests';
1414
import type { MemoryOutputFile } from './utils';

0 commit comments

Comments
 (0)