Skip to content

Commit 222e711

Browse files
clydinjosephperrott
authored andcommitted
build: add secondary entrypoint package.json files to packages
The new public API tooling searches for nested package.json files to determine the location of secondary entrypoints. All secondary entrypoints for the CLI related packages now contain a secondary entrypoint package.json file. The internal monorepo package discovery script was also updated to support the presence of the nested package.json files.
1 parent 4bcd1dc commit 222e711

File tree

9 files changed

+48
-15
lines changed

9 files changed

+48
-15
lines changed

lib/packages.ts

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -100,23 +100,32 @@ function loadPackageJson(p: string) {
100100
return pkg;
101101
}
102102

103-
function _findAllPackageJson(dir: string, exclude: RegExp): string[] {
104-
const result: string[] = [];
105-
fs.readdirSync(dir).forEach((fileName) => {
106-
const p = path.join(dir, fileName);
103+
function* _findPrimaryPackageJsonFiles(dir: string, exclude: RegExp): Iterable<string> {
104+
const subdirectories = [];
105+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
106+
const p = path.join(dir, entry.name);
107107

108108
if (exclude.test(p)) {
109+
continue;
110+
}
111+
112+
if (entry.isDirectory() && entry.name !== 'node_modules') {
113+
subdirectories.push(p);
114+
continue;
115+
}
116+
117+
if (entry.name === 'package.json') {
118+
yield p;
119+
120+
// First package.json found will be the package's root package.json
121+
// Secondary entrypoint package.json files should not be found here
109122
return;
110-
} else if (/[\/\\]node_modules[\/\\]/.test(p)) {
111-
return;
112-
} else if (fileName == 'package.json') {
113-
result.push(p);
114-
} else if (fs.statSync(p).isDirectory() && fileName != 'node_modules') {
115-
result.push(..._findAllPackageJson(p, exclude));
116123
}
117-
});
124+
}
118125

119-
return result;
126+
for (const directory of subdirectories) {
127+
yield* _findPrimaryPackageJsonFiles(directory, exclude);
128+
}
120129
}
121130

122131
const tsConfigPath = path.join(__dirname, '../tsconfig.json');
@@ -139,9 +148,9 @@ const pattern =
139148
const excludeRe = new RegExp(pattern);
140149

141150
// Find all the package.json that aren't excluded from tsconfig.
142-
const packageJsonPaths = _findAllPackageJson(path.join(__dirname, '..'), excludeRe)
143-
// Remove the root package.json.
144-
.filter((p) => p != path.join(__dirname, '../package.json'));
151+
const packageJsonPaths = [
152+
..._findPrimaryPackageJsonFiles(path.join(__dirname, '..', 'packages'), excludeRe),
153+
];
145154

146155
function _exec(cmd: string) {
147156
return execSync(cmd).toString().trim();

packages/angular_devkit/core/node/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ ts_library(
2020
"**/*_benchmark.ts",
2121
],
2222
),
23+
data = ["package.json"],
2324
module_name = "@angular-devkit/core/node",
2425
module_root = "index.d.ts",
2526
# The attribute below is needed in g3 to turn off strict typechecking
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "@angular-devkit/core/node",
3+
"main": "index.js",
4+
"typings": "index.d.ts"
5+
}

packages/angular_devkit/schematics/tasks/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ ts_library(
2020
"tslint-fix/test/**/*",
2121
],
2222
),
23+
data = ["package.json"],
2324
module_name = "@angular-devkit/schematics/tasks",
2425
module_root = "index.d.ts",
2526
# The attribute below is needed in g3 to turn off strict typechecking
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "@angular-devkit/schematics/tasks",
3+
"main": "index.js",
4+
"typings": "index.d.ts"
5+
}

packages/angular_devkit/schematics/testing/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ ts_library(
1313
srcs = glob(
1414
include = ["**/*.ts"],
1515
),
16+
data = ["package.json"],
1617
module_name = "@angular-devkit/schematics/testing",
1718
module_root = "index.d.ts",
1819
deps = [
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "@angular-devkit/schematics/testing",
3+
"main": "index.js",
4+
"typings": "index.d.ts"
5+
}

packages/angular_devkit/schematics/tools/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ ts_library(
1919
"test/**/*.ts",
2020
],
2121
),
22+
data = ["package.json"],
2223
module_name = "@angular-devkit/schematics/tools",
2324
module_root = "index.d.ts",
2425
# The attribute below is needed in g3 to turn off strict typechecking
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "@angular-devkit/schematics/tools",
3+
"main": "index.js",
4+
"typings": "index.d.ts"
5+
}

0 commit comments

Comments
 (0)