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 3462ebb commit 12dec4a
Showing 1 changed file with 79 additions and 45 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 (srcs.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 (srcs.length) {
const depsList =
deps.map(dep => `"//node_modules/${dep._dir}:${dep._name}__contents",`).join('\n ');
srcsStarlark = `
# 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

0 comments on commit 12dec4a

Please sign in to comment.