fix(bazel): fixes for ng_package on Windows (#22597)

PR Close #22597
This commit is contained in:
Alex Eagle 2018-03-05 16:47:43 -08:00 committed by Alex Eagle
parent fa974c7d4e
commit 4c40812b71
7 changed files with 22 additions and 16 deletions

View File

@ -17,9 +17,9 @@ node_repositories(package_json = [
http_archive(
name = "build_bazel_rules_typescript",
url = "https://github.com/bazelbuild/rules_typescript/archive/0.11.0.zip",
strip_prefix = "rules_typescript-0.11.0",
sha256 = "ce7bac7b5287d5162fcbe4f7c14ff507ae7d506ceb44626ad09f6b7e27d3260b",
url = "https://github.com/bazelbuild/rules_typescript/archive/0.11.1.zip",
strip_prefix = "rules_typescript-0.11.1",
sha256 = "7406bea7954e1c906f075115dfa176551a881119f6820b126ea1eacb09f34a1a",
)
load("@build_bazel_rules_typescript//:defs.bzl", "ts_setup_workspace")

View File

@ -10,11 +10,9 @@ http_archive(
load("@build_bazel_rules_nodejs//:defs.bzl", "node_repositories")
node_repositories(package_json = ["//:package.json"])
http_archive(
local_repository(
name = "build_bazel_rules_typescript",
url = "https://github.com/bazelbuild/rules_typescript/archive/0.11.0.zip",
strip_prefix = "rules_typescript-0.11.0",
sha256 = "ce7bac7b5287d5162fcbe4f7c14ff507ae7d506ceb44626ad09f6b7e27d3260b",
path = "node_modules/@bazel/typescript",
)
load("@build_bazel_rules_typescript//:defs.bzl", "ts_setup_workspace")

View File

@ -5,6 +5,7 @@
"author": "angular",
"license": "MIT",
"dependencies": {
"@bazel/typescript": "^0.11.1",
"@types/node": "6.0.84",
"@types/shelljs": "0.7.7",
"shelljs": "0.7.8",

View File

@ -24,6 +24,7 @@ function main(args) {
data['compilerOptions']['target'] = 'es5';
data['bazelOptions']['es5Mode'] = true;
data['bazelOptions']['tsickle'] = false;
data['bazelOptions']['tsickleExternsPath'] = '';
data['compilerOptions']['outDir'] = path.join(data['compilerOptions']['outDir'], newRoot);
if (data['angularCompilerOptions']) {
data['angularCompilerOptions']['expectedOut'] =

View File

@ -144,9 +144,8 @@ def _ng_package_impl(ctx):
for dep in ctx.attr.deps
if hasattr(dep, "angular")])
# TODO: the args look long, maybe need to spill to a params file:
# https://docs.bazel.build/versions/master/skylark/lib/Args.html#use_param_file
args = ctx.actions.args()
args.use_param_file("%s", use_always = True)
args.add(npm_package_directory.path)
args.add(ctx.label.package)
args.add([ctx.bin_dir.path, ctx.label.package], join_with="/")

View File

@ -16,6 +16,7 @@ function filter(ext: string): (path: string) => boolean {
function main(args: string[]): number {
shx.set('-e');
args = fs.readFileSync(args[0], {encoding: 'utf-8'}).split('\n').map(s => s === '\'\'' ? '' : s);
const
[out, srcDir, binDir, readmeMd, fesms2015Arg, fesms5Arg, bundlesArg, srcsArg, stampData,
licenseFile] = args;
@ -32,7 +33,13 @@ function main(args: string[]): number {
function replaceVersionPlaceholders(filePath: string, content: string) {
if (stampData) {
const version = shx.grep('BUILD_SCM_VERSION', stampData).split(' ')[1].trim();
return content.replace(/0.0.0-PLACEHOLDER/g, version);
// Split the replacement into separate strings so we don't match it while publishing
return content.replace(
new RegExp(
'0.0.0' +
'-PLACEHOLDER',
'g'),
version);
}
return content;
}

View File

@ -7,7 +7,7 @@
*/
import * as ng from '@angular/compiler-cli';
import {BazelOptions, CachedFileLoader, CompilerHost, FileCache, FileLoader, UncachedFileLoader, constructManifest, debug, fixUmdModuleDeclarations, parseTsconfig, runAsWorker, runWorkerLoop} from '@bazel/typescript';
import {BazelOptions, CachedFileLoader, CompilerHost, FileCache, FileLoader, UncachedFileLoader, constructManifest, debug, fixUmdModuleDeclarations, parseTsconfig, resolveNormalizedPath, runAsWorker, runWorkerLoop} from '@bazel/typescript';
import * as fs from 'fs';
import * as path from 'path';
import * as tsickle from 'tsickle';
@ -77,7 +77,7 @@ export function relativeToRootDirs(filePath: string, rootDirs: string[]): string
if (!filePath) return filePath;
// NB: the rootDirs should have been sorted longest-first
for (const dir of rootDirs || []) {
const rel = path.relative(dir, filePath);
const rel = path.posix.relative(dir, filePath);
if (rel.indexOf('.') != 0) return rel;
}
return filePath;
@ -107,7 +107,7 @@ export function compile({allowNonHermeticReads, allDepsCompiledWithBazel = true,
// Resolve the inputs to absolute paths to match TypeScript internals
const resolvedInputs: {[path: string]: string} = {};
for (const key of Object.keys(inputs)) {
resolvedInputs[path.resolve(key)] = inputs[key];
resolvedInputs[resolveNormalizedPath(key)] = inputs[key];
}
fileCache.updateCache(resolvedInputs);
} else {
@ -133,7 +133,7 @@ export function compile({allowNonHermeticReads, allDepsCompiledWithBazel = true,
tsHost.writeFile =
(fileName: string, content: string, writeByteOrderMark: boolean,
onError?: (message: string) => void, sourceFiles?: ts.SourceFile[]) => {
const relative = relativeToRootDirs(fileName, [compilerOpts.rootDir]);
const relative = relativeToRootDirs(fileName.replace(/\\/g, '/'), [compilerOpts.rootDir]);
const expectedIdx = writtenExpectedOuts.findIndex(o => o === relative);
if (expectedIdx >= 0) {
writtenExpectedOuts.splice(expectedIdx, 1);
@ -196,7 +196,7 @@ export function compile({allowNonHermeticReads, allDepsCompiledWithBazel = true,
}
return bazelOpts.workspaceName + '/' + result;
};
ngHost.toSummaryFileName = (fileName: string, referringSrcFileName: string) => path.join(
ngHost.toSummaryFileName = (fileName: string, referringSrcFileName: string) => path.posix.join(
bazelOpts.workspaceName,
relativeToRootDirs(fileName, compilerOpts.rootDirs).replace(EXT, ''));
if (allDepsCompiledWithBazel) {
@ -206,7 +206,7 @@ export function compile({allowNonHermeticReads, allDepsCompiledWithBazel = true,
// as that has a different implementation of fromSummaryFileName / toSummaryFileName
ngHost.fromSummaryFileName = (fileName: string, referringLibFileName: string) => {
const workspaceRelative = fileName.split('/').splice(1).join('/');
return path.resolve(bazelBin, workspaceRelative) + '.d.ts';
return resolveNormalizedPath(bazelBin, workspaceRelative) + '.d.ts';
};
}
// Patch a property on the ngHost that allows the resourceNameToModuleName function to