From 4c40812b71cbfc9d51a41913629f9b447623bbee Mon Sep 17 00:00:00 2001 From: Alex Eagle Date: Mon, 5 Mar 2018 16:47:43 -0800 Subject: [PATCH] fix(bazel): fixes for ng_package on Windows (#22597) PR Close #22597 --- WORKSPACE | 6 +++--- integration/bazel/WORKSPACE | 6 ++---- packages/bazel/package.json | 1 + packages/bazel/src/modify_tsconfig.js | 1 + packages/bazel/src/ng_package/ng_package.bzl | 3 +-- packages/bazel/src/ng_package/packager.ts | 9 ++++++++- packages/bazel/src/ngc-wrapped/index.ts | 12 ++++++------ 7 files changed, 22 insertions(+), 16 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index 49e6c208ce..088edb56e2 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -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") diff --git a/integration/bazel/WORKSPACE b/integration/bazel/WORKSPACE index 06ca4806eb..301a0cb52e 100644 --- a/integration/bazel/WORKSPACE +++ b/integration/bazel/WORKSPACE @@ -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") diff --git a/packages/bazel/package.json b/packages/bazel/package.json index c92d00df30..cb59349c09 100644 --- a/packages/bazel/package.json +++ b/packages/bazel/package.json @@ -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", diff --git a/packages/bazel/src/modify_tsconfig.js b/packages/bazel/src/modify_tsconfig.js index 37ff67c06f..a4a9e28713 100644 --- a/packages/bazel/src/modify_tsconfig.js +++ b/packages/bazel/src/modify_tsconfig.js @@ -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'] = diff --git a/packages/bazel/src/ng_package/ng_package.bzl b/packages/bazel/src/ng_package/ng_package.bzl index 83f6fff158..e4dcb5c4c7 100644 --- a/packages/bazel/src/ng_package/ng_package.bzl +++ b/packages/bazel/src/ng_package/ng_package.bzl @@ -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="/") diff --git a/packages/bazel/src/ng_package/packager.ts b/packages/bazel/src/ng_package/packager.ts index 4c5a3c89b6..b43e360891 100644 --- a/packages/bazel/src/ng_package/packager.ts +++ b/packages/bazel/src/ng_package/packager.ts @@ -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; } diff --git a/packages/bazel/src/ngc-wrapped/index.ts b/packages/bazel/src/ngc-wrapped/index.ts index 99b3e1ef12..b5a482d8f9 100644 --- a/packages/bazel/src/ngc-wrapped/index.ts +++ b/packages/bazel/src/ngc-wrapped/index.ts @@ -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