Skip to content

Commit

Permalink
Test CI
Browse files Browse the repository at this point in the history
  • Loading branch information
gregmagolan committed May 20, 2019
1 parent 14f7030 commit e1df9b5
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 86 deletions.
124 changes: 79 additions & 45 deletions internal/npm_install/generate_build_file.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,28 @@ function handleBazelFiles(pkg) {
*/
function generateRootBuildFile(pkgs) {
const srcs = pkgs.filter(pkg => !pkg._isNested);
const srcsStarlark =
srcs.map(pkg => `"//node_modules/${pkg._dir}:${pkg._name}__files",`).join('\n ');
const depsStarlark =
srcs.map(pkg => `"//node_modules/${pkg._dir}:${pkg._name}__contents",`).join('\n ');

let srcsStarlark = '';
if (srcs.length) {
const srcsList =
srcs.map(pkg => `"//node_modules/${pkg._dir}:${pkg._name}__files",`).join('\n ');
srcsStarlark = `
# direct sources listed for strict deps support
srcs = [
${srcsList}
],`;
}

let depsStarlark = '';
if (srcs.length) {
const depsList =
srcs.map(pkg => `"//node_modules/${pkg._dir}:${pkg._name}__contents",`).join('\n ');
srcsStarlark = `
# flattened list of direct and transitive dependencies hoisted to root by the package manager
deps = [
${depsList}
],`;
}

let buildFile = BUILD_FILE_HEADER +
`load("@build_bazel_rules_nodejs//internal/npm_install:node_module_library.bzl", "node_module_library")
Expand All @@ -168,15 +186,7 @@ function generateRootBuildFile(pkgs) {
# there are many files in target.
# See https://github.com/bazelbuild/bazel/issues/5153.
node_module_library(
name = "node_modules",
# direct sources listed for strict deps support
srcs = [
${srcsStarlark}
],
# flattened list of direct and transitive dependencies hoisted to root by the package manager
deps = [
${depsStarlark}
],
name = "node_modules",${srcsStarlark}${depsStarlark}
)
`
Expand Down Expand Up @@ -818,39 +828,57 @@ function printPackage(pkg) {
],`;
}

let srcsStarlark = '';
if (sources.length) {
const srcsList = sources.map(f => `":${f}",`).join('\n ');
srcsStarlark = `
# ${pkg._dir} package files (and files in nested node_modules)
srcs = [
${srcsList}
],`;
}

let depsStarlark = '';
if (deps.length) {
const depsList =
deps.map(dep => `"//node_modules/${dep._dir}:${dep._name}__contents",`).join('\n ');
depsStarlark = `
# flattened list of direct and transitive dependencies hoisted to root by the package manager
deps = [
${depsList}
],`;
}

let dtsStarlark = '';
if (dtsSources.length) {
const dtsList = dtsSources.map(f => `":${f}",`).join('\n ');
dtsStarlark = `
# ${pkg._dir} package declaration files (and declaration files in nested node_modules)
srcs = [
${dtsList}
],`;
}

let result = '';
if (isValidBinPath(pkg.bin)) {
// load the nodejs_binary definition only for non-empty bin paths
result = 'load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary")';
}

const srcsStarlark = sources.map(f => `":${f}",`).join('\n ');
const depsStarlark =
deps.map(dep => `"//node_modules/${dep._dir}:${dep._name}__contents",`).join('\n ');
const dtsStarlark = dtsSources.map(f => `":${f}",`).join('\n ');

result = `${result}
load("@build_bazel_rules_nodejs//internal/npm_install:node_module_library.bzl", "node_module_library")
# Generated targets for npm package "${pkg._dir}"
${printJson(pkg)}
filegroup(
name = "${pkg._name}__files",
# ${pkg._dir} package files (and files in nested node_modules)
srcs = [
${srcsStarlark}
],
name = "${pkg._name}__files",${srcsStarlark}
)
node_module_library(
name = "${pkg._name}__pkg",
# direct sources listed for strict deps support
srcs = [":${pkg._name}__files"],
# flattened list of direct and transitive dependencies hoisted to root by the package manager
deps = [
${depsStarlark}
],
srcs = [":${pkg._name}__files"],${depsStarlark}
)
# ${pkg._name}__contents target is used as dep for __pkg targets to prevent
Expand All @@ -862,10 +890,7 @@ node_module_library(
# ${pkg._name}__typings is the subset of ${pkg._name}__contents that are declarations
node_module_library(
name = "${pkg._name}__typings",
srcs = [
${dtsStarlark}
],
name = "${pkg._name}__typings",${dtsStarlark}
)
`;
Expand Down Expand Up @@ -999,24 +1024,33 @@ function printScope(scope, pkgs) {
// filter out duplicate deps
deps = [...pkgs, ...new Set(deps)];

const srcsStarlark =
deps.map(dep => `"//node_modules/${dep._dir}:${dep._name}__files",`).join('\n ');
const depsStarlark =
deps.map(dep => `"//node_modules/${dep._dir}:${dep._name}__contents",`).join('\n ');
let srcsStarlark = '';
if (deps.length) {
const srcsList =
deps.map(dep => `"//node_modules/${dep._dir}:${dep._name}__files",`).join('\n ');
srcsStarlark = `
# direct sources listed for strict deps support
srcs = [
${srcsList}
],`;
}

let depsStarlark = '';
if (deps.length) {
const depsList =
deps.map(dep => `"//node_modules/${dep._dir}:${dep._name}__contents",`).join('\n ');
depsStarlark = `
# flattened list of direct and transitive dependencies hoisted to root by the package manager
deps = [
${depsList}
],`;
}

return `load("@build_bazel_rules_nodejs//internal/npm_install:node_module_library.bzl", "node_module_library")
# Generated target for npm scope ${scope}
node_module_library(
name = "${scope}",
# direct sources listed for strict deps support
srcs = [
${srcsStarlark}
],
# flattened list of direct and transitive dependencies hoisted to root by the package manager
deps = [
${depsStarlark}
],
name = "${scope}",${srcsStarlark}${depsStarlark}
)
`;
Expand Down
29 changes: 0 additions & 29 deletions internal/npm_install/test/golden/BUILD.bazel.golden
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,6 @@ package(default_visibility = ["//visibility:public"])
load("@build_bazel_rules_nodejs//internal/npm_install:node_module_library.bzl", "node_module_library")
node_module_library(
name = "node_modules",
srcs = [
"//node_modules/.bin:.bin__files",
"//node_modules/ajv:ajv__files",
"//node_modules/balanced-match:balanced-match__files",
"//node_modules/brace-expansion:brace-expansion__files",
"//node_modules/co:co__files",
"//node_modules/concat-map:concat-map__files",
"//node_modules/diff:diff__files",
"//node_modules/fast-deep-equal:fast-deep-equal__files",
"//node_modules/fast-json-stable-stringify:fast-json-stable-stringify__files",
"//node_modules/fs.realpath:fs.realpath__files",
"//node_modules/glob:glob__files",
"//node_modules/inflight:inflight__files",
"//node_modules/inherits:inherits__files",
"//node_modules/jasmine:jasmine__files",
"//node_modules/jasmine-core:jasmine-core__files",
"//node_modules/json-schema-traverse:json-schema-traverse__files",
"//node_modules/minimatch:minimatch__files",
"//node_modules/once:once__files",
"//node_modules/path-is-absolute:path-is-absolute__files",
"//node_modules/rxjs:rxjs__files",
"//node_modules/tslib:tslib__files",
"//node_modules/unidiff:unidiff__files",
"//node_modules/wrappy:wrappy__files",
"//node_modules/zone.js:zone.js__files",
"//node_modules/@angular/core:core__files",
"//node_modules/@gregmagolan/test-a:test-a__files",
"//node_modules/@gregmagolan/test-b:test-b__files",
],
deps = [
"//node_modules/.bin:.bin__contents",
"//node_modules/ajv:ajv__contents",
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e1df9b5

Please sign in to comment.