diff --git a/packages/create/index.js b/packages/create/index.js index 263e3c6e26..a4082aa9b8 100644 --- a/packages/create/index.js +++ b/packages/create/index.js @@ -140,6 +140,20 @@ npm_install( package_lock_json = "//:package-lock.json", )`; + let bazelDepsContent = `# Third-party dependencies fetched by Bazel +# Unlike WORKSPACE, the content of this file is unordered. +# We keep them separate to make the WORKSPACE file more maintainable. + +# Install the nodejs "bootstrap" package +# This provides the basic tools for running and packaging nodejs programs in Bazel +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +def fetch_dependencies(): + http_archive( + name = "build_bazel_rules_nodejs", + sha256 = "65067dcad93a61deb593be7d3d9a32a4577d09665536d8da536d731da5cd15e2", + urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/3.4.2/rules_nodejs-3.4.2.tar.gz"], + ) +` let workspaceContent = `# Bazel workspace created by @bazel/create 0.0.0-PLACEHOLDER # Declares that this directory is the root of a Bazel workspace. @@ -152,19 +166,21 @@ workspace( managed_directories = {"@npm": ["node_modules"]}, ) -# Install the nodejs "bootstrap" package -# This provides the basic tools for running and packaging nodejs programs in Bazel -load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") -http_archive( - name = "build_bazel_rules_nodejs", - sha256 = "65067dcad93a61deb593be7d3d9a32a4577d09665536d8da536d731da5cd15e2", - urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/3.4.2/rules_nodejs-3.4.2.tar.gz"], -) +load("//tools:bazel_deps.bzl", "fetch_dependencies") + +fetch_dependencies() ${pkgMgr === 'yarn' ? yarnInstallCmd : npmInstallCmd}`; - write('WORKSPACE.bazel', workspaceContent); - write('.bazelignore', `node_modules + write('tools/BUILD.bazel', '# No targets in this Bazel package\n') + write('tools/bazel_deps.bzl', bazelDepsContent); + // Don't name it WORKSPACE.bazel since there's a bug with managed_directories + write('WORKSPACE', workspaceContent); + write('.bazelignore', `\ +# NB: sematics here are not the same as .gitignore +# see https://github.com/bazelbuild/bazel/issues/8106 +# For example, every nested node_modules directory needs to be listed here. +node_modules dist bazel-out `); @@ -182,7 +198,8 @@ bazel-out } }, null, 4)); - write('.gitignore', ` + write('.gitignore', `\ +.bazelrc.user dist bazel-out node_modules`);