Skip to content

Commit

Permalink
fix(bazel): ng_package creates invalid typings reexport on windows (a…
Browse files Browse the repository at this point in the history
…ngular#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 angular#27829
  • Loading branch information
devversion authored and kara committed Jan 7, 2019
1 parent a75c734 commit 4caf654
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions packages/bazel/src/ng_package/packager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
}
Expand Down Expand Up @@ -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);
}

Expand All @@ -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) {
Expand Down

0 comments on commit 4caf654

Please sign in to comment.