Skip to content

Commit 3facdeb

Browse files
alexeaglematsko
authored andcommittedMar 15, 2019
fix(bazel): don't produce self-references in metadata (#29317)
Fixes #29315 PR Close #29317
1 parent 1db8bf3 commit 3facdeb

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed
 

‎packages/bazel/src/ng_package/packager.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ export * from '${srcDirRelative(inputPath, typingsFile.replace(/\.d\.tsx?$/, '')
399399
* @param typingsPath the typings bundle entrypoint
400400
*/
401401
function rewireMetadata(metadataPath: string, typingsPath: string): string {
402-
const metadata = fs.readFileSync(metadataPath, 'utf-8');
402+
const metadata = JSON.parse(fs.readFileSync(metadataPath, 'utf-8'));
403403

404404
let typingsRelativePath =
405405
normalizeSeparators(path.relative(path.dirname(metadataPath), typingsPath));
@@ -411,7 +411,13 @@ export * from '${srcDirRelative(inputPath, typingsFile.replace(/\.d\.tsx?$/, '')
411411

412412
// the regexp here catches all relative paths such as:
413413
// ./src/core/foo.d.ts and ../src/core/foo.d.ts
414-
return metadata.replace(/\.?\.\/[\w\.\-_\/]+/g, typingsRelativePath);
414+
const relativePathRegex = /\.?\.\/[\w\.\-_\/]+/g;
415+
if (metadata.exports) {
416+
// Strip re-exports which are now self-references
417+
metadata.exports =
418+
metadata.exports.filter((e: {from: string}) => !relativePathRegex.test(e.from));
419+
}
420+
return JSON.stringify(metadata).replace(relativePathRegex, typingsRelativePath);
415421
}
416422

417423
/**

0 commit comments

Comments
 (0)
Please sign in to comment.