Skip to content

Commit 6a2d0a1

Browse files
committed
fix(ivy): exactly match file/directory names in findAllPackageJsonFiles()
1 parent 40c1d90 commit 6a2d0a1

2 files changed

Lines changed: 42 additions & 8 deletions

File tree

packages/compiler-cli/src/ngcc/src/parser/parser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ export function findAllPackageJsonFiles(rootDirectory: string) {
8585
// them and filtering out the results later) makes a noticeable difference.
8686
const paths = Array.from(find(rootDirectory));
8787
return paths.filter(path =>
88-
/package\.json$/.test(path) &&
89-
!/node_modules\//.test(path.slice(rootDirectory.length)));
88+
/\/package\.json$/.test(path) &&
89+
!/(?:^|\/)node_modules\//.test(path.slice(rootDirectory.length)));
9090
}
9191

9292
/**

packages/compiler-cli/src/ngcc/test/parser/parser_spec.ts

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,38 @@ function createMockFileSystem() {
2323
'package.json': '{ "fesm2015": "../fesm2015/http.js", "fesm5": "../fesm5/http.js" }',
2424
'testing': {
2525
'package.json': '{ "fesm2015": "../../fesm2015/http/testing.js", "fesm5": "../../fesm5/http/testing.js" }',
26-
}
26+
},
2727
},
2828
'testing': {
2929
'package.json': '{ "fesm2015": "../fesm2015/testing.js", "fesm5": "../fesm5/testing.js" }',
3030
},
3131
'node_modules': {
3232
'tslib': {
3333
'package.json': '{ }',
34-
}
35-
}
34+
'node_modules': {
35+
'other-lib': {
36+
'package.json': '{ }',
37+
},
38+
},
39+
},
40+
},
41+
},
42+
'/node_modules/@angular/other': {
43+
'not-package.json': '{ "fesm2015": "./fesm2015/other.js" }',
44+
'package.jsonot': '{ "fesm5": "./fesm5/other.js" }',
45+
},
46+
'/node_modules/@angular/other2': {
47+
'node_modules_not': {
48+
'lib1': {
49+
'package.json': '{ }',
50+
},
51+
},
52+
'not_node_modules': {
53+
'lib2': {
54+
'package.json': '{ }',
55+
},
56+
},
3657
},
37-
'/node_modules/@angular/other': {}
3858
});
3959
}
4060

@@ -46,7 +66,7 @@ describe('findAllPackageJsonFiles()', () => {
4666
beforeEach(createMockFileSystem);
4767
afterEach(restoreRealFileSystem);
4868

49-
it('should find the package.json files below the specified directory', () => {
69+
it('should find the `package.json` files below the specified directory', () => {
5070
const paths = findAllPackageJsonFiles('/node_modules/@angular/common');
5171
expect(paths.sort()).toEqual([
5272
'/node_modules/@angular/common/http/package.json',
@@ -56,9 +76,23 @@ describe('findAllPackageJsonFiles()', () => {
5676
]);
5777
});
5878

59-
it('should not find package.json files under node_modules', () => {
79+
it('should not find `package.json` files under `node_modules/`', () => {
6080
const paths = findAllPackageJsonFiles('/node_modules/@angular/common');
6181
expect(paths).not.toContain('/node_modules/@angular/common/node_modules/tslib/package.json');
82+
expect(paths).not.toContain('/node_modules/@angular/common/node_modules/tslib/node_modules/other-lib/package.json');
83+
});
84+
85+
it('should exactly match the name of `package.json` files', () => {
86+
const paths = findAllPackageJsonFiles('/node_modules/@angular/other');
87+
expect(paths).toEqual([]);
88+
});
89+
90+
it('should exactly match the name of `node_modules/` directory', () => {
91+
const paths = findAllPackageJsonFiles('/node_modules/@angular/other2');
92+
expect(paths).toEqual([
93+
'/node_modules/@angular/other2/node_modules_not/lib1/package.json',
94+
'/node_modules/@angular/other2/not_node_modules/lib2/package.json',
95+
]);
6296
});
6397
});
6498

0 commit comments

Comments
 (0)