UNPKG

ng-packagr

Version:

Compile and package Angular libraries in Angular Package Format (APF)

88 lines 4.43 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.generatePackageExports = generatePackageExports; exports.generateWatchVersion = generateWatchVersion; const path = __importStar(require("path")); const log = __importStar(require("./log")); const path_1 = require("./path"); /** * Generates the `package.json` package exports following APF v13. * This is supposed to match with: https://github.com/angular/angular/blob/e0667efa6eada64d1fb8b143840689090fc82e52/packages/bazel/src/ng_package/packager.ts#L415. */ function generatePackageExports({ destinationPath, packageJson }, entryPoints) { const exports = packageJson.exports ? JSON.parse(JSON.stringify(packageJson.exports)) : {}; const insertMappingOrError = (subpath, mapping) => { exports[subpath] ??= {}; if (typeof exports[subpath] === 'string') { log.warn(`Found an existing subpath export for "${subpath}". The export would be overridden by ng-packagr. Please unset it.`); exports[subpath] = {}; } const subpathExport = exports[subpath]; // Go through all conditions that should be inserted. If the condition is already // manually set of the subpath export, we throw an error. In general, we allow for // additional conditions to be set. These will always precede the generated ones. for (const conditionName of Object.keys(mapping)) { if (subpathExport[conditionName] !== undefined) { log.warn(`Found a conflicting export condition for "${subpath}". The "${conditionName}" ` + `condition would be overridden by ng-packagr. Please unset it.`); // Must delete existing subpath export to ensure that order matches mapping delete subpathExport[conditionName]; } // **Note**: The order of the conditions is preserved even though we are setting // the conditions once at a time (the latest assignment will be at the end). subpathExport[conditionName] = mapping[conditionName]; } }; const relativeUnixFromDestPath = (filePath) => './' + (0, path_1.ensureUnixPath)(path.relative(destinationPath, filePath)); insertMappingOrError('./package.json', { default: './package.json' }); const entryPointsSorted = entryPoints.sort((a, b) => a.url.localeCompare(b.url)); for (const entryPoint of entryPointsSorted) { const { destinationFiles, isSecondaryEntryPoint } = entryPoint.data.entryPoint; const subpath = isSecondaryEntryPoint ? `./${destinationFiles.directory}` : '.'; insertMappingOrError(subpath, { types: relativeUnixFromDestPath(destinationFiles.declarationsBundled), default: relativeUnixFromDestPath(destinationFiles.fesm2022), }); } return exports; } /** * Generates a new version for the package `package.json` when runing in watch mode. */ function generateWatchVersion() { return `0.0.0-watch+${Date.now()}`; } //# sourceMappingURL=package-json.js.map