Skip to content

Commit 4c40812

Browse files
committed
fix(bazel): fixes for ng_package on Windows (#22597)
PR Close #22597
1 parent fa974c7 commit 4c40812

File tree

7 files changed

+22
-16
lines changed

7 files changed

+22
-16
lines changed

WORKSPACE

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ node_repositories(package_json = [
1717

1818
http_archive(
1919
name = "build_bazel_rules_typescript",
20-
url = "https://github.com/bazelbuild/rules_typescript/archive/0.11.0.zip",
21-
strip_prefix = "rules_typescript-0.11.0",
22-
sha256 = "ce7bac7b5287d5162fcbe4f7c14ff507ae7d506ceb44626ad09f6b7e27d3260b",
20+
url = "https://github.com/bazelbuild/rules_typescript/archive/0.11.1.zip",
21+
strip_prefix = "rules_typescript-0.11.1",
22+
sha256 = "7406bea7954e1c906f075115dfa176551a881119f6820b126ea1eacb09f34a1a",
2323
)
2424

2525
load("@build_bazel_rules_typescript//:defs.bzl", "ts_setup_workspace")

integration/bazel/WORKSPACE

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@ http_archive(
1010
load("@build_bazel_rules_nodejs//:defs.bzl", "node_repositories")
1111
node_repositories(package_json = ["//:package.json"])
1212

13-
http_archive(
13+
local_repository(
1414
name = "build_bazel_rules_typescript",
15-
url = "https://github.com/bazelbuild/rules_typescript/archive/0.11.0.zip",
16-
strip_prefix = "rules_typescript-0.11.0",
17-
sha256 = "ce7bac7b5287d5162fcbe4f7c14ff507ae7d506ceb44626ad09f6b7e27d3260b",
15+
path = "node_modules/@bazel/typescript",
1816
)
1917

2018
load("@build_bazel_rules_typescript//:defs.bzl", "ts_setup_workspace")

packages/bazel/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"author": "angular",
66
"license": "MIT",
77
"dependencies": {
8+
"@bazel/typescript": "^0.11.1",
89
"@types/node": "6.0.84",
910
"@types/shelljs": "0.7.7",
1011
"shelljs": "0.7.8",

packages/bazel/src/modify_tsconfig.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ function main(args) {
2424
data['compilerOptions']['target'] = 'es5';
2525
data['bazelOptions']['es5Mode'] = true;
2626
data['bazelOptions']['tsickle'] = false;
27+
data['bazelOptions']['tsickleExternsPath'] = '';
2728
data['compilerOptions']['outDir'] = path.join(data['compilerOptions']['outDir'], newRoot);
2829
if (data['angularCompilerOptions']) {
2930
data['angularCompilerOptions']['expectedOut'] =

packages/bazel/src/ng_package/ng_package.bzl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,8 @@ def _ng_package_impl(ctx):
144144
for dep in ctx.attr.deps
145145
if hasattr(dep, "angular")])
146146

147-
# TODO: the args look long, maybe need to spill to a params file:
148-
# https://docs.bazel.build/versions/master/skylark/lib/Args.html#use_param_file
149147
args = ctx.actions.args()
148+
args.use_param_file("%s", use_always = True)
150149
args.add(npm_package_directory.path)
151150
args.add(ctx.label.package)
152151
args.add([ctx.bin_dir.path, ctx.label.package], join_with="/")

packages/bazel/src/ng_package/packager.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ function filter(ext: string): (path: string) => boolean {
1616

1717
function main(args: string[]): number {
1818
shx.set('-e');
19+
args = fs.readFileSync(args[0], {encoding: 'utf-8'}).split('\n').map(s => s === '\'\'' ? '' : s);
1920
const
2021
[out, srcDir, binDir, readmeMd, fesms2015Arg, fesms5Arg, bundlesArg, srcsArg, stampData,
2122
licenseFile] = args;
@@ -32,7 +33,13 @@ function main(args: string[]): number {
3233
function replaceVersionPlaceholders(filePath: string, content: string) {
3334
if (stampData) {
3435
const version = shx.grep('BUILD_SCM_VERSION', stampData).split(' ')[1].trim();
35-
return content.replace(/0.0.0-PLACEHOLDER/g, version);
36+
// Split the replacement into separate strings so we don't match it while publishing
37+
return content.replace(
38+
new RegExp(
39+
'0.0.0' +
40+
'-PLACEHOLDER',
41+
'g'),
42+
version);
3643
}
3744
return content;
3845
}

packages/bazel/src/ngc-wrapped/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import * as ng from '@angular/compiler-cli';
10-
import {BazelOptions, CachedFileLoader, CompilerHost, FileCache, FileLoader, UncachedFileLoader, constructManifest, debug, fixUmdModuleDeclarations, parseTsconfig, runAsWorker, runWorkerLoop} from '@bazel/typescript';
10+
import {BazelOptions, CachedFileLoader, CompilerHost, FileCache, FileLoader, UncachedFileLoader, constructManifest, debug, fixUmdModuleDeclarations, parseTsconfig, resolveNormalizedPath, runAsWorker, runWorkerLoop} from '@bazel/typescript';
1111
import * as fs from 'fs';
1212
import * as path from 'path';
1313
import * as tsickle from 'tsickle';
@@ -77,7 +77,7 @@ export function relativeToRootDirs(filePath: string, rootDirs: string[]): string
7777
if (!filePath) return filePath;
7878
// NB: the rootDirs should have been sorted longest-first
7979
for (const dir of rootDirs || []) {
80-
const rel = path.relative(dir, filePath);
80+
const rel = path.posix.relative(dir, filePath);
8181
if (rel.indexOf('.') != 0) return rel;
8282
}
8383
return filePath;
@@ -107,7 +107,7 @@ export function compile({allowNonHermeticReads, allDepsCompiledWithBazel = true,
107107
// Resolve the inputs to absolute paths to match TypeScript internals
108108
const resolvedInputs: {[path: string]: string} = {};
109109
for (const key of Object.keys(inputs)) {
110-
resolvedInputs[path.resolve(key)] = inputs[key];
110+
resolvedInputs[resolveNormalizedPath(key)] = inputs[key];
111111
}
112112
fileCache.updateCache(resolvedInputs);
113113
} else {
@@ -133,7 +133,7 @@ export function compile({allowNonHermeticReads, allDepsCompiledWithBazel = true,
133133
tsHost.writeFile =
134134
(fileName: string, content: string, writeByteOrderMark: boolean,
135135
onError?: (message: string) => void, sourceFiles?: ts.SourceFile[]) => {
136-
const relative = relativeToRootDirs(fileName, [compilerOpts.rootDir]);
136+
const relative = relativeToRootDirs(fileName.replace(/\\/g, '/'), [compilerOpts.rootDir]);
137137
const expectedIdx = writtenExpectedOuts.findIndex(o => o === relative);
138138
if (expectedIdx >= 0) {
139139
writtenExpectedOuts.splice(expectedIdx, 1);
@@ -196,7 +196,7 @@ export function compile({allowNonHermeticReads, allDepsCompiledWithBazel = true,
196196
}
197197
return bazelOpts.workspaceName + '/' + result;
198198
};
199-
ngHost.toSummaryFileName = (fileName: string, referringSrcFileName: string) => path.join(
199+
ngHost.toSummaryFileName = (fileName: string, referringSrcFileName: string) => path.posix.join(
200200
bazelOpts.workspaceName,
201201
relativeToRootDirs(fileName, compilerOpts.rootDirs).replace(EXT, ''));
202202
if (allDepsCompiledWithBazel) {
@@ -206,7 +206,7 @@ export function compile({allowNonHermeticReads, allDepsCompiledWithBazel = true,
206206
// as that has a different implementation of fromSummaryFileName / toSummaryFileName
207207
ngHost.fromSummaryFileName = (fileName: string, referringLibFileName: string) => {
208208
const workspaceRelative = fileName.split('/').splice(1).join('/');
209-
return path.resolve(bazelBin, workspaceRelative) + '.d.ts';
209+
return resolveNormalizedPath(bazelBin, workspaceRelative) + '.d.ts';
210210
};
211211
}
212212
// Patch a property on the ngHost that allows the resourceNameToModuleName function to

0 commit comments

Comments
 (0)