From 4caf6540d12c3dbaed73defe909578221bf14862 Mon Sep 17 00:00:00 2001 From: Paul Gschwendtner Date: Tue, 25 Dec 2018 15:59:31 +0100 Subject: [PATCH] fix(bazel): ng_package creates invalid typings reexport on windows (#27829) Currently when building a package on Windows, the typings re-export for secondary entry-points is not valid TypeScript. Similarly the metadata and the "package.json" files use non-posix paths and cause inconsistency within the NPM package. For example: _package.json_ ``` "esm5": "./esm5\\core.js", "esm2015": "./esm2015\\core.js", ``` _testing.d.t.s_ (of the `core` package) ``` export * from './testing\testing'; ``` PR Close #27829 --- packages/bazel/src/ng_package/packager.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/bazel/src/ng_package/packager.ts b/packages/bazel/src/ng_package/packager.ts index b9d7692a3d..86bce27612 100644 --- a/packages/bazel/src/ng_package/packager.ts +++ b/packages/bazel/src/ng_package/packager.ts @@ -235,8 +235,8 @@ function main(args: string[]): number { * @param file path to a file under the binDir, like bazel-bin/core/testing/generated.js */ function srcDirRelative(from: string, file: string) { - const result = - path.relative(path.dirname(from), path.join(srcDir, path.relative(binDir, file))); + const result = normalizeSeparators( + path.relative(path.dirname(from), path.join(srcDir, path.relative(binDir, file)))); if (result.startsWith('..')) return result; return `./${result}`; } @@ -346,8 +346,8 @@ function main(args: string[]): number { function createTypingsReexportFile(entryPointName: string, license: string, typingsFile: string) { const inputPath = path.join(srcDir, `${entryPointName}.d.ts`); const content = `${license} - export * from '${srcDirRelative(inputPath, typingsFile.replace(/\.d\.tsx?$/, ''))}'; - `; +export * from '${srcDirRelative(inputPath, typingsFile.replace(/\.d\.tsx?$/, ''))}'; +`; writeFileFromInputPath(inputPath, content); } @@ -362,6 +362,12 @@ function main(args: string[]): number { const content = amendPackageJson(pkgJson, {name: entryPointPackageName}); writeFileFromInputPath(pkgJson, content); } + + /** + * Normalizes the specified path by replacing backslash separators with Posix + * forward slash separators. + */ + function normalizeSeparators(path: string): string { return path.replace(/\\/g, '/'); } } if (require.main === module) {