MCPcopy Create free account
hub / github.com/angular/dev-infra / findEntryPointsWithinNpmPackage

Function findEntryPointsWithinNpmPackage

bazel/api-golden/find_entry_points.ts:21–62  ·  view source on GitHub ↗
(
  dirPath: string,
  packageJson: PackageJson,
)

Source from the content-addressed store, hash-verified

19
20/** Finds all entry points within a given NPM package directory. */
21export function findEntryPointsWithinNpmPackage(
22 dirPath: string,
23 packageJson: PackageJson,
24): PackageEntryPoint[] {
25 // Legacy behavior to support Angular packages without the `exports` field.
26 // TODO: Remove when https://github.com/angular/angular-cli/issues/22889 is resolved.
27 if (packageJson.exports === undefined) {
28 return findEntryPointsThroughNestedPackageFiles(dirPath);
29 }
30
31 const entryPoints: PackageEntryPoint[] = [];
32 for (const [subpath, {types}] of Object.entries(packageJson.exports)) {
33 // Wildcard types mappings are supported.
34 if (types !== undefined && !types.includes('*')) {
35 if (isAbsolute(subpath) || subpath.split(/[/\\]/).includes('..')) {
36 throw new Error(`Invalid exports subpath: ${subpath}`);
37 }
38 if (isAbsolute(types) || types.split(/[/\\]/).includes('..')) {
39 throw new Error(`Invalid types entry point: ${types}`);
40 }
41
42 const resolvedSubpath = join(dirPath, subpath);
43 const relativeSubpath = relative(dirPath, resolvedSubpath);
44 if (relativeSubpath.startsWith('..') || isAbsolute(relativeSubpath)) {
45 throw new Error(`Subpath resolves outside package directory: ${subpath}`);
46 }
47
48 const resolvedTypesPath = join(dirPath, types);
49 const relativeTypes = relative(dirPath, resolvedTypesPath);
50 if (relativeTypes.startsWith('..') || isAbsolute(relativeTypes)) {
51 throw new Error(`Types entry point resolves outside package directory: ${types}`);
52 }
53
54 entryPoints.push({
55 subpath,
56 typesEntryPointPath: resolvedTypesPath,
57 });
58 }
59 }
60
61 return entryPoints;
62}
63
64/**
65 * Finds all entry points within a given NPM package directory by looking

Callers

nothing calls this directly

Calls 3

entriesMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected