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
This commit is contained in:
Paul Gschwendtner 2018-12-25 15:59:31 +01:00 committed by Kara Erickson
parent a75c734471
commit 4caf6540d1
1 changed files with 10 additions and 4 deletions

View File

@ -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 * @param file path to a file under the binDir, like bazel-bin/core/testing/generated.js
*/ */
function srcDirRelative(from: string, file: string) { function srcDirRelative(from: string, file: string) {
const result = const result = normalizeSeparators(
path.relative(path.dirname(from), path.join(srcDir, path.relative(binDir, file))); path.relative(path.dirname(from), path.join(srcDir, path.relative(binDir, file))));
if (result.startsWith('..')) return result; if (result.startsWith('..')) return result;
return `./${result}`; return `./${result}`;
} }
@ -346,8 +346,8 @@ function main(args: string[]): number {
function createTypingsReexportFile(entryPointName: string, license: string, typingsFile: string) { function createTypingsReexportFile(entryPointName: string, license: string, typingsFile: string) {
const inputPath = path.join(srcDir, `${entryPointName}.d.ts`); const inputPath = path.join(srcDir, `${entryPointName}.d.ts`);
const content = `${license} const content = `${license}
export * from '${srcDirRelative(inputPath, typingsFile.replace(/\.d\.tsx?$/, ''))}'; export * from '${srcDirRelative(inputPath, typingsFile.replace(/\.d\.tsx?$/, ''))}';
`; `;
writeFileFromInputPath(inputPath, content); writeFileFromInputPath(inputPath, content);
} }
@ -362,6 +362,12 @@ function main(args: string[]): number {
const content = amendPackageJson(pkgJson, {name: entryPointPackageName}); const content = amendPackageJson(pkgJson, {name: entryPointPackageName});
writeFileFromInputPath(pkgJson, content); 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) { if (require.main === module) {