@nx/angular 20.4.0-canary.20250115-0ae8665 → 20.4.0-canary.20250116-a127177

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (13) hide show
  1. package/package.json +8 -8
  2. package/src/executors/ng-packagr-lite/ng-packagr-adjustments/ng-package/entry-point/entry-point.d.ts +7 -0
  3. package/src/executors/ng-packagr-lite/ng-packagr-adjustments/ng-package/entry-point/entry-point.js +17 -0
  4. package/src/executors/ng-packagr-lite/ng-packagr-adjustments/{pre-v19/ng-package → ng-package}/entry-point/write-bundles.transform.d.ts +3 -1
  5. package/src/executors/ng-packagr-lite/ng-packagr-adjustments/ng-package/entry-point/write-bundles.transform.js +44 -0
  6. package/src/executors/ng-packagr-lite/ng-packagr-adjustments/ng-packagr.js +2 -15
  7. package/src/executors/ng-packagr-lite/ng-packagr-adjustments/pre-v19/ng-package/entry-point/write-bundles.transform.js +0 -12
  8. package/src/executors/ng-packagr-lite/ng-packagr-adjustments/pre-v19/ng-package/entry-point/write-package.di.d.ts +0 -8
  9. package/src/executors/ng-packagr-lite/ng-packagr-adjustments/pre-v19/ng-package/entry-point/write-package.di.js +0 -18
  10. package/src/executors/ng-packagr-lite/ng-packagr-adjustments/pre-v19/ng-package/entry-point/write-package.transform.d.ts +0 -8
  11. package/src/executors/ng-packagr-lite/ng-packagr-adjustments/pre-v19/ng-package/entry-point/write-package.transform.js +0 -286
  12. /package/src/executors/ng-packagr-lite/ng-packagr-adjustments/{pre-v19/ng-package → ng-package}/entry-point/write-bundles.di.d.ts +0 -0
  13. /package/src/executors/ng-packagr-lite/ng-packagr-adjustments/{pre-v19/ng-package → ng-package}/entry-point/write-bundles.di.js +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/angular",
3
- "version": "20.4.0-canary.20250115-0ae8665",
3
+ "version": "20.4.0-canary.20250116-a127177",
4
4
  "private": false,
5
5
  "description": "The Nx Plugin for Angular contains executors, generators, and utilities for managing Angular applications and libraries within an Nx workspace. It provides: \n\n- Integration with libraries such as Storybook, Jest, ESLint, Tailwind CSS, Playwright and Cypress. \n\n- Generators to help scaffold code quickly (like: Micro Frontends, Libraries, both internal to your codebase and publishable to npm) \n\n- Single Component Application Modules (SCAMs) \n\n- NgRx helpers. \n\n- Utilities for automatic workspace refactoring.",
6
6
  "repository": {
@@ -71,13 +71,13 @@
71
71
  "semver": "^7.5.3",
72
72
  "tslib": "^2.3.0",
73
73
  "webpack-merge": "^5.8.0",
74
- "@nx/devkit": "20.4.0-canary.20250115-0ae8665",
75
- "@nx/js": "20.4.0-canary.20250115-0ae8665",
76
- "@nx/eslint": "20.4.0-canary.20250115-0ae8665",
77
- "@nx/webpack": "20.4.0-canary.20250115-0ae8665",
78
- "@nx/module-federation": "20.4.0-canary.20250115-0ae8665",
79
- "@nx/web": "20.4.0-canary.20250115-0ae8665",
80
- "@nx/workspace": "20.4.0-canary.20250115-0ae8665",
74
+ "@nx/devkit": "20.4.0-canary.20250116-a127177",
75
+ "@nx/js": "20.4.0-canary.20250116-a127177",
76
+ "@nx/eslint": "20.4.0-canary.20250116-a127177",
77
+ "@nx/webpack": "20.4.0-canary.20250116-a127177",
78
+ "@nx/module-federation": "20.4.0-canary.20250116-a127177",
79
+ "@nx/web": "20.4.0-canary.20250116-a127177",
80
+ "@nx/workspace": "20.4.0-canary.20250116-a127177",
81
81
  "piscina": "^4.4.0"
82
82
  },
83
83
  "peerDependencies": {
@@ -0,0 +1,7 @@
1
+ import { type DestinationFiles, NgEntryPoint as NgEntryPointBase } from 'ng-packagr/lib/ng-package/entry-point/entry-point';
2
+ export declare class NgEntryPoint extends NgEntryPointBase {
3
+ /**
4
+ * Point the FESM2022 files to the ESM2022 files.
5
+ */
6
+ get destinationFiles(): DestinationFiles;
7
+ }
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NgEntryPoint = void 0;
4
+ const entry_point_1 = require("ng-packagr/lib/ng-package/entry-point/entry-point");
5
+ const node_path_1 = require("node:path");
6
+ class NgEntryPoint extends entry_point_1.NgEntryPoint {
7
+ /**
8
+ * Point the FESM2022 files to the ESM2022 files.
9
+ */
10
+ get destinationFiles() {
11
+ const result = super.destinationFiles;
12
+ result.fesm2022 = result.esm2022;
13
+ result.fesm2022Dir = (0, node_path_1.dirname)(result.esm2022);
14
+ return result;
15
+ }
16
+ }
17
+ exports.NgEntryPoint = NgEntryPoint;
@@ -3,6 +3,8 @@
3
3
  *
4
4
  * Changes made:
5
5
  * - Removed bundling altogether.
6
+ * - Write the ESM2022 outputs to the file system.
7
+ * - Fake the FESM2022 outputs pointing them to the ESM2022 outputs.
6
8
  */
7
- import { NgPackagrOptions } from 'ng-packagr/lib/ng-package/options.di';
9
+ import type { NgPackagrOptions } from 'ng-packagr/lib/ng-package/options.di';
8
10
  export declare const writeBundlesTransform: (_options: NgPackagrOptions) => import("ng-packagr/lib/graph/transform").Transform;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ /**
3
+ * Adapted from the original ng-packagr.
4
+ *
5
+ * Changes made:
6
+ * - Removed bundling altogether.
7
+ * - Write the ESM2022 outputs to the file system.
8
+ * - Fake the FESM2022 outputs pointing them to the ESM2022 outputs.
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.writeBundlesTransform = void 0;
12
+ const build_graph_1 = require("ng-packagr/lib/graph/build-graph");
13
+ const transform_1 = require("ng-packagr/lib/graph/transform");
14
+ const nodes_1 = require("ng-packagr/lib/ng-package/nodes");
15
+ const package_1 = require("ng-packagr/lib/ng-package/package");
16
+ const promises_1 = require("node:fs/promises");
17
+ const node_path_1 = require("node:path");
18
+ const entry_point_1 = require("./entry-point");
19
+ const writeBundlesTransform = (_options) => (0, transform_1.transformFromPromise)(async (graph) => {
20
+ const updatedGraph = new build_graph_1.BuildGraph();
21
+ for (const entry of graph.entries()) {
22
+ if ((0, nodes_1.isEntryPoint)(entry)) {
23
+ const entryPoint = toCustomNgEntryPoint(entry.data.entryPoint);
24
+ entry.data.entryPoint = entryPoint;
25
+ entry.data.destinationFiles = entryPoint.destinationFiles;
26
+ for (const [path, outputCache] of entry.cache.outputCache.entries()) {
27
+ // write the outputs to the file system
28
+ await (0, promises_1.mkdir)((0, node_path_1.dirname)(path), { recursive: true });
29
+ await (0, promises_1.writeFile)(path, outputCache.content);
30
+ }
31
+ }
32
+ else if ((0, nodes_1.isPackage)(entry)) {
33
+ entry.data = new package_1.NgPackage(entry.data.src, toCustomNgEntryPoint(entry.data.primary), entry.data.secondaries.map((secondary) => toCustomNgEntryPoint(secondary)));
34
+ }
35
+ updatedGraph.put(entry);
36
+ }
37
+ return updatedGraph;
38
+ });
39
+ exports.writeBundlesTransform = writeBundlesTransform;
40
+ function toCustomNgEntryPoint(entryPoint) {
41
+ return new entry_point_1.NgEntryPoint(entryPoint.packageJson, entryPoint.ngPackageJson, entryPoint.basePath,
42
+ // @ts-expect-error this is a TS private property, but it can be accessed at runtime
43
+ entryPoint.secondaryData);
44
+ }
@@ -2,23 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getNgPackagrInstance = getNgPackagrInstance;
4
4
  const ng_packagr_1 = require("ng-packagr");
5
- const angular_version_utils_1 = require("../../utilities/angular-version-utils");
6
5
  async function getNgPackagrInstance() {
7
- const { major: angularMajorVersion } = (0, angular_version_utils_1.getInstalledAngularVersionInfo)();
8
- if (angularMajorVersion >= 19) {
9
- const { STYLESHEET_PROCESSOR } = await import('../../utilities/ng-packagr/stylesheet-processor.di.js');
10
- const packagr = (0, ng_packagr_1.ngPackagr)();
11
- packagr.withProviders([STYLESHEET_PROCESSOR]);
12
- return packagr;
13
- }
14
- const { WRITE_BUNDLES_TRANSFORM } = await import('./pre-v19/ng-package/entry-point/write-bundles.di.js');
15
- const { WRITE_PACKAGE_TRANSFORM } = await import('./pre-v19/ng-package/entry-point/write-package.di.js');
6
+ const { WRITE_BUNDLES_TRANSFORM } = await import('./ng-package/entry-point/write-bundles.di.js');
16
7
  const { STYLESHEET_PROCESSOR } = await import('../../utilities/ng-packagr/stylesheet-processor.di.js');
17
8
  const packagr = (0, ng_packagr_1.ngPackagr)();
18
- packagr.withProviders([
19
- WRITE_BUNDLES_TRANSFORM,
20
- WRITE_PACKAGE_TRANSFORM,
21
- STYLESHEET_PROCESSOR,
22
- ]);
9
+ packagr.withProviders([WRITE_BUNDLES_TRANSFORM, STYLESHEET_PROCESSOR]);
23
10
  return packagr;
24
11
  }
@@ -1,12 +0,0 @@
1
- "use strict";
2
- /**
3
- * Adapted from the original ng-packagr.
4
- *
5
- * Changes made:
6
- * - Removed bundling altogether.
7
- */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.writeBundlesTransform = void 0;
10
- const transform_1 = require("ng-packagr/lib/graph/transform");
11
- const writeBundlesTransform = (_options) => (0, transform_1.transformFromPromise)(async (graph) => graph);
12
- exports.writeBundlesTransform = writeBundlesTransform;
@@ -1,8 +0,0 @@
1
- /**
2
- * Adapted from the original ng-packagr source.
3
- *
4
- * Changes made:
5
- * - Provide our own writePackageTransform function.
6
- */
7
- import { TransformProvider } from 'ng-packagr/lib/graph/transform.di';
8
- export declare const WRITE_PACKAGE_TRANSFORM: TransformProvider;
@@ -1,18 +0,0 @@
1
- "use strict";
2
- /**
3
- * Adapted from the original ng-packagr source.
4
- *
5
- * Changes made:
6
- * - Provide our own writePackageTransform function.
7
- */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.WRITE_PACKAGE_TRANSFORM = void 0;
10
- const transform_di_1 = require("ng-packagr/lib/graph/transform.di");
11
- const write_package_di_1 = require("ng-packagr/lib/ng-package/entry-point/write-package.di");
12
- const options_di_1 = require("ng-packagr/lib/ng-package/options.di");
13
- const write_package_transform_1 = require("./write-package.transform");
14
- exports.WRITE_PACKAGE_TRANSFORM = (0, transform_di_1.provideTransform)({
15
- provide: write_package_di_1.WRITE_PACKAGE_TRANSFORM_TOKEN,
16
- useFactory: write_package_transform_1.nxWritePackageTransform,
17
- deps: [options_di_1.OPTIONS_TOKEN],
18
- });
@@ -1,8 +0,0 @@
1
- /**
2
- * Adapted from the original ng-packagr.
3
- *
4
- * Changes made:
5
- * - Change the package.json metadata to only use the ESM2022 output.
6
- */
7
- import { NgPackagrOptions } from 'ng-packagr/lib/ng-package/options.di';
8
- export declare const nxWritePackageTransform: (options: NgPackagrOptions) => import("ng-packagr/lib/graph/transform").Transform;
@@ -1,286 +0,0 @@
1
- "use strict";
2
- /**
3
- * Adapted from the original ng-packagr.
4
- *
5
- * Changes made:
6
- * - Change the package.json metadata to only use the ESM2022 output.
7
- */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.nxWritePackageTransform = void 0;
10
- const tslib_1 = require("tslib");
11
- const devkit_1 = require("@nx/devkit");
12
- const node_1 = require("ng-packagr/lib/graph/node");
13
- const transform_1 = require("ng-packagr/lib/graph/transform");
14
- const nodes_1 = require("ng-packagr/lib/ng-package/nodes");
15
- const fs_1 = require("ng-packagr/lib/utils/fs");
16
- const glob_1 = require("ng-packagr/lib/utils/glob");
17
- const path_1 = require("ng-packagr/lib/utils/path");
18
- const path = tslib_1.__importStar(require("path"));
19
- const nxWritePackageTransform = (options) => (0, transform_1.transformFromPromise)(async (graph) => {
20
- const entryPoint = graph.find((0, nodes_1.isEntryPointInProgress)());
21
- const ngEntryPoint = entryPoint.data.entryPoint;
22
- const ngPackageNode = graph.find(nodes_1.isPackage);
23
- const ngPackage = ngPackageNode.data;
24
- const { destinationFiles } = entryPoint.data;
25
- if (!ngEntryPoint.isSecondaryEntryPoint) {
26
- devkit_1.logger.log('Copying assets');
27
- try {
28
- await copyAssets(graph, entryPoint, ngPackageNode);
29
- }
30
- catch (error) {
31
- throw error;
32
- }
33
- }
34
- // 6. WRITE PACKAGE.JSON
35
- const relativeUnixFromDestPath = (filePath) => (0, path_1.ensureUnixPath)(path.relative(ngEntryPoint.destinationPath, filePath));
36
- if (!ngEntryPoint.isSecondaryEntryPoint) {
37
- try {
38
- devkit_1.logger.info('Writing package manifest');
39
- if (!options.watch) {
40
- const primary = ngPackageNode.data.primary;
41
- await (0, fs_1.writeFile)(path.join(primary.destinationPath, '.npmignore'), `# Nested package.json's are only needed for development.\n**/package.json`);
42
- }
43
- await writePackageJson(ngEntryPoint, ngPackage, {
44
- module: relativeUnixFromDestPath(destinationFiles.esm2022),
45
- typings: relativeUnixFromDestPath(destinationFiles.declarations),
46
- exports: generatePackageExports(ngEntryPoint, graph),
47
- // webpack v4+ specific flag to enable advanced optimizations and code splitting
48
- sideEffects: ngEntryPoint.packageJson.sideEffects ?? false,
49
- }, !!options.watch);
50
- }
51
- catch (error) {
52
- throw error;
53
- }
54
- }
55
- else if (ngEntryPoint.isSecondaryEntryPoint) {
56
- if (options.watch) {
57
- // Update the watch version of the primary entry point `package.json` file.
58
- // this is needed because of Webpack's 5 `cachemanagedpaths`
59
- // https://github.com/ng-packagr/ng-packagr/issues/2069
60
- const primary = ngPackageNode.data.primary;
61
- const packageJsonPath = path.join(primary.destinationPath, 'package.json');
62
- if (await (0, fs_1.exists)(packageJsonPath)) {
63
- const packageJson = JSON.parse(await (0, fs_1.readFile)(packageJsonPath, { encoding: 'utf8' }));
64
- packageJson.version = generateWatchVersion();
65
- await (0, fs_1.writeFile)(path.join(primary.destinationPath, 'package.json'), JSON.stringify(packageJson, undefined, 2));
66
- }
67
- }
68
- // Write a package.json in each secondary entry-point
69
- // This is need for esbuild to secondary entry-points in dist correctly.
70
- await (0, fs_1.writeFile)(path.join(ngEntryPoint.destinationPath, 'package.json'), JSON.stringify({ module: relativeUnixFromDestPath(destinationFiles.esm2022) }, undefined, 2));
71
- }
72
- devkit_1.logger.info(`Built ${ngEntryPoint.moduleId}`);
73
- return graph;
74
- });
75
- exports.nxWritePackageTransform = nxWritePackageTransform;
76
- async function copyAssets(graph, entryPointNode, ngPackageNode) {
77
- const ngPackage = ngPackageNode.data;
78
- const globsForceIgnored = [
79
- '.gitkeep',
80
- '**/.DS_Store',
81
- '**/Thumbs.db',
82
- `${ngPackage.dest}/**`,
83
- ];
84
- const assets = [];
85
- for (const assetPath of ngPackage.assets) {
86
- let asset;
87
- if (typeof assetPath === 'object') {
88
- asset = { ...assetPath };
89
- }
90
- else {
91
- const [isDir, isFile] = await (0, fs_1.stat)(path.join(ngPackage.src, assetPath))
92
- .then((stats) => [stats.isDirectory(), stats.isFile()])
93
- .catch(() => [false, false]);
94
- if (isDir) {
95
- asset = { glob: '**/*', input: assetPath, output: assetPath };
96
- }
97
- else if (isFile) {
98
- // filenames are their own glob
99
- asset = {
100
- glob: path.basename(assetPath),
101
- input: path.dirname(assetPath),
102
- output: path.dirname(assetPath),
103
- };
104
- }
105
- else {
106
- asset = { glob: assetPath, input: '/', output: '/' };
107
- }
108
- }
109
- asset.input = path.join(ngPackage.src, asset.input);
110
- asset.output = path.join(ngPackage.dest, asset.output);
111
- const isAncestorPath = (target, datum) => path.relative(datum, target).startsWith('..');
112
- if (isAncestorPath(asset.input, ngPackage.src)) {
113
- throw new Error('Cannot read assets from a location outside of the project root.');
114
- }
115
- if (isAncestorPath(asset.output, ngPackage.dest)) {
116
- throw new Error('Cannot write assets to a location outside of the output path.');
117
- }
118
- assets.push(asset);
119
- }
120
- for (const asset of assets) {
121
- const filePaths = await (0, glob_1.globFiles)(asset.glob, {
122
- cwd: asset.input,
123
- ignore: [...(asset.ignore ?? []), ...globsForceIgnored],
124
- dot: true,
125
- onlyFiles: true,
126
- followSymbolicLinks: asset.followSymlinks,
127
- });
128
- for (const filePath of filePaths) {
129
- const fileSrcFullPath = path.join(asset.input, filePath);
130
- const fileDestFullPath = path.join(asset.output, filePath);
131
- const nodeUri = (0, nodes_1.fileUrl)((0, path_1.ensureUnixPath)(fileSrcFullPath));
132
- let node = graph.get(nodeUri);
133
- if (!node) {
134
- node = new node_1.Node(nodeUri);
135
- graph.put(node);
136
- }
137
- entryPointNode.dependsOn(node);
138
- await (0, fs_1.copyFile)(fileSrcFullPath, fileDestFullPath);
139
- }
140
- }
141
- }
142
- /**
143
- * Creates and writes a `package.json` file of the entry point used by the `node_module`
144
- * resolution strategies.
145
- *
146
- * #### Example
147
- *
148
- * A consumer of the entry point depends on it by `import {..} from '@my/module/id';`.
149
- * The module id `@my/module/id` will be resolved to the `package.json` file that is written by
150
- * this build step.
151
- * The properties `main`, `module`, `typings` (and so on) in the `package.json` point to the
152
- * flattened JavaScript bundles, type definitions, (...).
153
- *
154
- * @param entryPoint An entry point of an Angular package / library
155
- * @param additionalProperties Additional properties, e.g. binary artefacts (bundle files), to merge into `package.json`
156
- */
157
- async function writePackageJson(entryPoint, pkg, additionalProperties, isWatchMode) {
158
- // set additional properties
159
- const packageJson = { ...entryPoint.packageJson, ...additionalProperties };
160
- // read tslib version from `@angular/compiler` so that our tslib
161
- // version at least matches that of angular if we use require('tslib').version
162
- // it will get what installed and not the minimum version nor if it is a `~` or `^`
163
- // this is only required for primary
164
- if (isWatchMode) {
165
- // Needed because of Webpack's 5 `cachemanagedpaths`
166
- // https://github.com/angular/angular-cli/issues/20962
167
- packageJson.version = generateWatchVersion();
168
- }
169
- if (!packageJson.peerDependencies?.tslib &&
170
- !packageJson.dependencies?.tslib) {
171
- const { peerDependencies: angularPeerDependencies = {}, dependencies: angularDependencies = {}, } = require('@angular/compiler/package.json');
172
- const tsLibVersion = angularPeerDependencies.tslib || angularDependencies.tslib;
173
- if (tsLibVersion) {
174
- packageJson.dependencies = {
175
- ...packageJson.dependencies,
176
- tslib: tsLibVersion,
177
- };
178
- }
179
- }
180
- else if (packageJson.peerDependencies?.tslib) {
181
- devkit_1.logger.warn(`'tslib' is no longer recommended to be used as a 'peerDependencies'. Moving it to 'dependencies'.`);
182
- packageJson.dependencies = {
183
- ...(packageJson.dependencies || {}),
184
- tslib: packageJson.peerDependencies.tslib,
185
- };
186
- delete packageJson.peerDependencies.tslib;
187
- }
188
- // Verify non-peerDependencies as they can easily lead to duplicate installs or version conflicts
189
- // in the node_modules folder of an application
190
- const allowedList = pkg.allowedNonPeerDependencies.map((value) => new RegExp(value));
191
- try {
192
- checkNonPeerDependencies(packageJson, 'dependencies', allowedList);
193
- }
194
- catch (e) {
195
- await (0, fs_1.rmdir)(entryPoint.destinationPath, { recursive: true });
196
- throw e;
197
- }
198
- // Removes scripts from package.json after build
199
- if (packageJson.scripts) {
200
- if (pkg.keepLifecycleScripts !== true) {
201
- devkit_1.logger.info(`Removing scripts section in package.json as it's considered a potential security vulnerability.`);
202
- delete packageJson.scripts;
203
- }
204
- else {
205
- devkit_1.logger.warn(`You enabled keepLifecycleScripts explicitly. The scripts section in package.json will be published to npm.`);
206
- }
207
- }
208
- // keep the dist package.json clean
209
- // this will not throw if ngPackage field does not exist
210
- delete packageJson.ngPackage;
211
- const packageJsonPropertiesToDelete = [
212
- 'stylelint',
213
- 'prettier',
214
- 'browserslist',
215
- 'devDependencies',
216
- 'jest',
217
- 'workspaces',
218
- 'husky',
219
- ];
220
- for (const prop of packageJsonPropertiesToDelete) {
221
- if (prop in packageJson) {
222
- delete packageJson[prop];
223
- devkit_1.logger.info(`Removing ${prop} section in package.json.`);
224
- }
225
- }
226
- packageJson.name = entryPoint.moduleId;
227
- await (0, fs_1.writeFile)(path.join(entryPoint.destinationPath, 'package.json'), JSON.stringify(packageJson, undefined, 2));
228
- }
229
- function checkNonPeerDependencies(packageJson, property, allowed) {
230
- if (!packageJson[property]) {
231
- return;
232
- }
233
- for (const dep of Object.keys(packageJson[property])) {
234
- if (!allowed.some((regex) => regex.test(dep))) {
235
- devkit_1.logger.warn(`Distributing npm packages with '${property}' is not recommended. Please consider adding ${dep} to 'peerDependencies' or remove it from '${property}'.`);
236
- throw new Error(`Dependency ${dep} must be explicitly allowed using the "allowedNonPeerDependencies" option.`);
237
- }
238
- }
239
- }
240
- /**
241
- * Generates the `package.json` package exports following APF v13.
242
- * This is supposed to match with: https://github.com/angular/angular/blob/e0667efa6eada64d1fb8b143840689090fc82e52/packages/bazel/src/ng_package/packager.ts#L415.
243
- */
244
- function generatePackageExports({ destinationPath, packageJson }, graph) {
245
- const exports = packageJson.exports
246
- ? JSON.parse(JSON.stringify(packageJson.exports))
247
- : {};
248
- const insertMappingOrError = (subpath, mapping) => {
249
- exports[subpath] ??= {};
250
- const subpathExport = exports[subpath];
251
- // Go through all conditions that should be inserted. If the condition is already
252
- // manually set of the subpath export, we throw an error. In general, we allow for
253
- // additional conditions to be set. These will always precede the generated ones.
254
- for (const conditionName of Object.keys(mapping)) {
255
- if (subpathExport[conditionName] !== undefined) {
256
- devkit_1.logger.warn(`Found a conflicting export condition for "${subpath}". The "${conditionName}" ` +
257
- `condition would be overridden by ng-packagr. Please unset it.`);
258
- }
259
- // **Note**: The order of the conditions is preserved even though we are setting
260
- // the conditions once at a time (the latest assignment will be at the end).
261
- subpathExport[conditionName] = mapping[conditionName];
262
- }
263
- };
264
- const relativeUnixFromDestPath = (filePath) => './' + (0, path_1.ensureUnixPath)(path.relative(destinationPath, filePath));
265
- insertMappingOrError('./package.json', { default: './package.json' });
266
- const entryPoints = graph.filter(nodes_1.isEntryPoint);
267
- for (const entryPoint of entryPoints) {
268
- const { destinationFiles, isSecondaryEntryPoint } = entryPoint.data.entryPoint;
269
- const subpath = isSecondaryEntryPoint
270
- ? `./${destinationFiles.directory}`
271
- : '.';
272
- insertMappingOrError(subpath, {
273
- types: relativeUnixFromDestPath(destinationFiles.declarations),
274
- esm2022: relativeUnixFromDestPath(destinationFiles.esm2022),
275
- esm: relativeUnixFromDestPath(destinationFiles.esm2022),
276
- default: relativeUnixFromDestPath(destinationFiles.esm2022),
277
- });
278
- }
279
- return exports;
280
- }
281
- /**
282
- * Generates a new version for the package `package.json` when runing in watch mode.
283
- */
284
- function generateWatchVersion() {
285
- return `0.0.0-watch+${Date.now()}`;
286
- }