From ea599a55b2850090d279b45c51c352d4af4528ad Mon Sep 17 00:00:00 2001
From: Tiago Costa
Date: Thu, 26 Nov 2020 19:22:16 +0000
Subject: [PATCH 1/9] feat(builtin): create symlink for build files present on
node modules installed with relative paths
test(builtin): test setup attempt for support local linked packages
chore(builtin): format fix
chore(builtin): format fix
chore(builtin): format fix
chore(builtin): put back unintended changes
test(builtin): correct test implementation
feat(builtin): include warning log about not found build file
chore(builtin): use specific workspace on local-module one for each package manager
fix(builtin): only symlink package if it is inside the workspace
chore(builtin): add note about corner case as suggested in the pr review
docs(builtin): add docs for new behaviour on npm_install and yarn_install rules
---
WORKSPACE | 6 +++
docs/Built-ins.md | 36 ++++++++++++++
internal/npm_install/generate_build_file.ts | 48 +++++++++++++++++--
internal/npm_install/index.js | 19 +++++++-
internal/npm_install/test/BUILD.bazel | 1 +
internal/npm_install/test/common.spec.js | 4 ++
tools/fine_grained_deps_npm/package-lock.json | 3 ++
tools/fine_grained_deps_npm/package.json | 1 +
tools/fine_grained_deps_yarn/package.json | 1 +
tools/fine_grained_deps_yarn/yarn.lock | 4 ++
.../npm_packages/local_module/npm/BUILD.bazel | 35 ++++++++++++++
tools/npm_packages/local_module/npm/index.js | 1 +
.../local_module/npm/package.json | 4 ++
.../local_module/yarn/BUILD.bazel | 35 ++++++++++++++
tools/npm_packages/local_module/yarn/index.js | 1 +
.../local_module/yarn/package.json | 4 ++
16 files changed, 199 insertions(+), 4 deletions(-)
create mode 100644 tools/npm_packages/local_module/npm/BUILD.bazel
create mode 100644 tools/npm_packages/local_module/npm/index.js
create mode 100644 tools/npm_packages/local_module/npm/package.json
create mode 100644 tools/npm_packages/local_module/yarn/BUILD.bazel
create mode 100644 tools/npm_packages/local_module/yarn/index.js
create mode 100644 tools/npm_packages/local_module/yarn/package.json
diff --git a/WORKSPACE b/WORKSPACE
index d5a91f6441..81cae65280 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -189,6 +189,9 @@ local_repository(
yarn_install(
name = "fine_grained_deps_yarn",
data = [
+ "//:tools/npm_packages/local_module/yarn/BUILD.bazel",
+ "//:tools/npm_packages/local_module/yarn/index.js",
+ "//:tools/npm_packages/local_module/yarn/package.json",
"//internal/npm_install/test:postinstall.js",
],
environment = {
@@ -209,6 +212,9 @@ yarn_install(
npm_install(
name = "fine_grained_deps_npm",
data = [
+ "//:tools/npm_packages/local_module/npm/BUILD.bazel",
+ "//:tools/npm_packages/local_module/npm/index.js",
+ "//:tools/npm_packages/local_module/npm/package.json",
"//internal/npm_install/test:postinstall.js",
],
environment = {
diff --git a/docs/Built-ins.md b/docs/Built-ins.md
index beec2815e3..09d79b3f8c 100755
--- a/docs/Built-ins.md
+++ b/docs/Built-ins.md
@@ -947,6 +947,24 @@ Defaults to `True`
Defaults to `3600`
+**LOCAL MODULES**
+
+When using a monorepo is common to have locally written modules that we both
+want to use locally while publicly publishing them. To achieve it, we need
+to declare the package with `file:` in the monorepo `package.json` and
+define a `BUILD` file for that local package with a `js_library` rule
+defining its `package_name` argument.
+
+Doing what is mentioned above will be creating a link to the previous
+created `BUILD` file from the npm external Bazel repository, which require
+us to complete a last step which writing the expected targets on that
+same `BUILD` file to be later used by the `npm_install` rule, which
+are: ``, ``,
+``, `` and the last
+one just ``.
+
+If you doubt what those targets should look like, check the
+generated `BUILD` file for a given node module.
## pkg_npm
@@ -1314,6 +1332,24 @@ Defaults to `True`
(*Label, mandatory*)
+**LOCAL MODULES**
+
+When using a monorepo is common to have locally written modules that we both
+want to use locally while publicly publishing them. To achieve it, we need
+to declare the package with `link:` in the monorepo `package.json` and
+define a `BUILD` file for that local package with a `js_library` rule
+defining its `package_name` argument.
+
+Doing what is mentioned above will be creating a link to the previous
+created `BUILD` file from the npm external Bazel repository, which require
+us to complete a last step which writing the expected targets on that
+same `BUILD` file to be later used by the `yarn_install` rule, which
+are: ``, ``,
+``, `` and the last
+one just ``.
+
+If you doubt what those targets should look like, check the
+generated `BUILD` file for a given node module.
## check_bazel_version
diff --git a/internal/npm_install/generate_build_file.ts b/internal/npm_install/generate_build_file.ts
index e81991f07a..56d080d025 100644
--- a/internal/npm_install/generate_build_file.ts
+++ b/internal/npm_install/generate_build_file.ts
@@ -93,6 +93,15 @@ function writeFileSync(p: string, content: string) {
fs.writeFileSync(p, content);
}
+/**
+ * Creates a file symlink, first ensuring that the directory to
+ * create it into exists.
+ */
+function createFileSymlinkSync(target: string, p: string) {
+ mkdirp(path.dirname(p));
+ fs.symlinkSync(target, p, 'file');
+}
+
/**
* Main entrypoint.
*/
@@ -194,11 +203,37 @@ js_library(
* Generates all BUILD & bzl files for a package.
*/
function generatePackageBuildFiles(pkg: Dep) {
- // If a BUILD file was shipped with the package, append its contents to the end of
- // what we generate for the package.
+ // If a BUILD file was shipped with the package we should symlink the generated BUILD file
+ // instead of append its contents to the end of the one we were going to generate.
+ // https://github.com/bazelbuild/rules_nodejs/issues/2131
let buildFilePath: string|undefined;
if (pkg._files.includes('BUILD')) buildFilePath = 'BUILD';
if (pkg._files.includes('BUILD.bazel')) buildFilePath = 'BUILD.bazel';
+
+ // Recreate the pkg dir inside the node_modules folder
+ const nodeModulesPkgDir = `node_modules/${pkg._dir}`;
+ // Check if the current package dep dir is a symlink (which happens when we
+ // install a node_module with link:)
+ const isPkgDirASymlink =
+ fs.existsSync(nodeModulesPkgDir) && fs.lstatSync(nodeModulesPkgDir).isSymbolicLink();
+ // Check if the current package is also written inside the workspace
+ // NOTE: It's a corner case but fs.realpathSync(.) will not be the root of
+ // the workspace if symlink_node_modules = False as yarn & npm are run in the root of the
+ // external repository and anything linked with a relative path would have to be copied
+ // over via that data attribute
+ const isPkgInsideWorkspace = fs.realpathSync(nodeModulesPkgDir).includes(fs.realpathSync(`.`));
+ // Mark build file as one to symlink instead of generate as the package dir is a symlink, we
+ // have a BUILD file and the pkg is written inside the workspace
+ const symlinkBuildFile = isPkgDirASymlink && buildFilePath && isPkgInsideWorkspace;
+
+ // Log if a BUILD file was expected but was not found
+ if (!symlinkBuildFile && isPkgDirASymlink) {
+ console.log(`[yarn_install/npm_install]: package ${
+ nodeModulesPkgDir} is local symlink and as such a BUILD file for it is expected but none was found. Please add one at ${
+ fs.realpathSync(nodeModulesPkgDir)}`)
+ }
+
+ // The following won't be used in a symlink build file case
let buildFile = printPackage(pkg);
if (buildFilePath) {
buildFile = buildFile + '\n' +
@@ -256,7 +291,14 @@ exports_files(["index.bzl"])
}
}
- writeFileSync(path.posix.join(pkg._dir, buildFilePath), generateBuildFileHeader(visibility) + buildFile);
+ if (!symlinkBuildFile) {
+ writeFileSync(
+ path.posix.join(pkg._dir, buildFilePath), generateBuildFileHeader(visibility) + buildFile);
+ } else {
+ const realPathBuildFileForPkg =
+ fs.realpathSync(path.posix.join(nodeModulesPkgDir, buildFilePath));
+ createFileSymlinkSync(realPathBuildFileForPkg, path.posix.join(pkg._dir, buildFilePath));
+ }
}
/**
diff --git a/internal/npm_install/index.js b/internal/npm_install/index.js
index c0a025b923..df341d8f5a 100644
--- a/internal/npm_install/index.js
+++ b/internal/npm_install/index.js
@@ -39,6 +39,10 @@ function writeFileSync(p, content) {
mkdirp(path.dirname(p));
fs.writeFileSync(p, content);
}
+function createFileSymlinkSync(target, p) {
+ mkdirp(path.dirname(p));
+ fs.symlinkSync(target, p, 'file');
+}
function main() {
const deps = getDirectDependencySet(PKG_JSON_FILE_PATH);
const pkgs = findPackages('node_modules', deps);
@@ -113,6 +117,13 @@ function generatePackageBuildFiles(pkg) {
buildFilePath = 'BUILD';
if (pkg._files.includes('BUILD.bazel'))
buildFilePath = 'BUILD.bazel';
+ const nodeModulesPkgDir = `node_modules/${pkg._dir}`;
+ const isPkgDirASymlink = fs.existsSync(nodeModulesPkgDir) && fs.lstatSync(nodeModulesPkgDir).isSymbolicLink();
+ const isPkgInsideWorkspace = fs.realpathSync(nodeModulesPkgDir).includes(fs.realpathSync(`.`));
+ const symlinkBuildFile = isPkgDirASymlink && buildFilePath && isPkgInsideWorkspace;
+ if (!symlinkBuildFile && isPkgDirASymlink) {
+ console.log(`[yarn_install/npm_install]: package ${nodeModulesPkgDir} is local symlink and as such a BUILD file for it is expected but none was found. Please add one at ${fs.realpathSync(nodeModulesPkgDir)}`);
+ }
let buildFile = printPackage(pkg);
if (buildFilePath) {
buildFile = buildFile + '\n' +
@@ -154,7 +165,13 @@ exports_files(["index.bzl"])
`;
}
}
- writeFileSync(path.posix.join(pkg._dir, buildFilePath), generateBuildFileHeader(visibility) + buildFile);
+ if (!symlinkBuildFile) {
+ writeFileSync(path.posix.join(pkg._dir, buildFilePath), generateBuildFileHeader(visibility) + buildFile);
+ }
+ else {
+ const realPathBuildFileForPkg = fs.realpathSync(path.posix.join(nodeModulesPkgDir, buildFilePath));
+ createFileSymlinkSync(realPathBuildFileForPkg, path.posix.join(pkg._dir, buildFilePath));
+ }
}
function generateBazelWorkspaces(pkgs) {
const workspaces = {};
diff --git a/internal/npm_install/test/BUILD.bazel b/internal/npm_install/test/BUILD.bazel
index 286295f9f9..3af37da108 100644
--- a/internal/npm_install/test/BUILD.bazel
+++ b/internal/npm_install/test/BUILD.bazel
@@ -126,6 +126,7 @@ sh_test(
"@fine_grained_deps_%s//jasmine" % pkgmgr,
"@fine_grained_deps_%s//jasmine-core" % pkgmgr,
"@fine_grained_deps_%s//ajv" % pkgmgr,
+ "@fine_grained_deps_%s//local-module" % pkgmgr,
"@fine_grained_deps_%s//typescript" % pkgmgr,
"@fine_grained_deps_%s//rxjs" % pkgmgr,
# Note, test-b depends on test-a@0.0.1 which should be
diff --git a/internal/npm_install/test/common.spec.js b/internal/npm_install/test/common.spec.js
index a82d6832ff..b731df71f7 100644
--- a/internal/npm_install/test/common.spec.js
+++ b/internal/npm_install/test/common.spec.js
@@ -15,6 +15,10 @@ describe('dependencies', () => {
require('ajv/lib/$data');
});
+ it(`should resolve local-module`, () => {
+ require('local-module');
+ });
+
it(`should resolve rxjs/src/tsconfig.json`, () => {
// the BUILD.bazel file in rxjs/src should have been
// deleted by fine grained deps and rxjs/src/tsconfig.json
diff --git a/tools/fine_grained_deps_npm/package-lock.json b/tools/fine_grained_deps_npm/package-lock.json
index 65038156e4..e5c85d553c 100644
--- a/tools/fine_grained_deps_npm/package-lock.json
+++ b/tools/fine_grained_deps_npm/package-lock.json
@@ -1288,6 +1288,9 @@
"graceful-fs": "^4.1.9"
}
},
+ "local-module": {
+ "version": "file:tools/npm_packages/local_module/npm"
+ },
"lodash.debounce": {
"version": "4.0.8",
"resolved": "https://registry.npmjs.org/lodash.debounce/-/lodash.debounce-4.0.8.tgz",
diff --git a/tools/fine_grained_deps_npm/package.json b/tools/fine_grained_deps_npm/package.json
index 756fce271b..77d8e903e1 100644
--- a/tools/fine_grained_deps_npm/package.json
+++ b/tools/fine_grained_deps_npm/package.json
@@ -12,6 +12,7 @@
"chokidar": "2.0.4",
"http-server": "github:alexeagle/http-server#97205e945b69091606ed83aa0c8489e9ce65d282",
"klaw": "1.3.1",
+ "local-module": "file:tools/npm_packages/local_module/npm",
"rxjs": "6.5.0"
},
"scripts": {
diff --git a/tools/fine_grained_deps_yarn/package.json b/tools/fine_grained_deps_yarn/package.json
index 756fce271b..54be5a1e9e 100644
--- a/tools/fine_grained_deps_yarn/package.json
+++ b/tools/fine_grained_deps_yarn/package.json
@@ -12,6 +12,7 @@
"chokidar": "2.0.4",
"http-server": "github:alexeagle/http-server#97205e945b69091606ed83aa0c8489e9ce65d282",
"klaw": "1.3.1",
+ "local-module": "link:tools/npm_packages/local_module/yarn",
"rxjs": "6.5.0"
},
"scripts": {
diff --git a/tools/fine_grained_deps_yarn/yarn.lock b/tools/fine_grained_deps_yarn/yarn.lock
index babc1065b2..03752e0a23 100644
--- a/tools/fine_grained_deps_yarn/yarn.lock
+++ b/tools/fine_grained_deps_yarn/yarn.lock
@@ -751,6 +751,10 @@ klaw@1.3.1:
optionalDependencies:
graceful-fs "^4.1.9"
+"local-module@link:tools/npm_packages/local_module/yarn":
+ version "0.0.0"
+ uid ""
+
lodash.debounce@^4.0.8:
version "4.0.8"
resolved "https://registry.yarnpkg.com/lodash.debounce/-/lodash.debounce-4.0.8.tgz#82d79bff30a67c4005ffd5e2515300ad9ca4d7af"
diff --git a/tools/npm_packages/local_module/npm/BUILD.bazel b/tools/npm_packages/local_module/npm/BUILD.bazel
new file mode 100644
index 0000000000..7ede7d5b33
--- /dev/null
+++ b/tools/npm_packages/local_module/npm/BUILD.bazel
@@ -0,0 +1,35 @@
+load("@build_bazel_rules_nodejs//:index.bzl", "js_library")
+
+package(default_visibility = ["//visibility:public"])
+
+SRCS = [
+ "index.js",
+ "package.json",
+]
+
+filegroup(
+ name = "local-module__files",
+ srcs = ["@fine_grained_deps_npm//:node_modules/local-module/%s" % file for file in SRCS],
+)
+
+js_library(
+ name = "local-module",
+ srcs = [":local-module__files"],
+ deps = [
+ ":local-module__contents",
+ ],
+)
+
+js_library(
+ name = "local-module__contents",
+ srcs = [
+ ":local-module__files",
+ ":local-module__nested_node_modules",
+ ],
+ visibility = ["//:__subpackages__"],
+)
+
+filegroup(
+ name = "local-module__nested_node_modules",
+ visibility = ["//:__subpackages__"],
+)
diff --git a/tools/npm_packages/local_module/npm/index.js b/tools/npm_packages/local_module/npm/index.js
new file mode 100644
index 0000000000..e8e15eefe1
--- /dev/null
+++ b/tools/npm_packages/local_module/npm/index.js
@@ -0,0 +1 @@
+module.exports = 'local_module';
diff --git a/tools/npm_packages/local_module/npm/package.json b/tools/npm_packages/local_module/npm/package.json
new file mode 100644
index 0000000000..870f1ba6e6
--- /dev/null
+++ b/tools/npm_packages/local_module/npm/package.json
@@ -0,0 +1,4 @@
+{
+ "version": "0.0.1",
+ "main": "index.js"
+}
diff --git a/tools/npm_packages/local_module/yarn/BUILD.bazel b/tools/npm_packages/local_module/yarn/BUILD.bazel
new file mode 100644
index 0000000000..a899ea4269
--- /dev/null
+++ b/tools/npm_packages/local_module/yarn/BUILD.bazel
@@ -0,0 +1,35 @@
+load("@build_bazel_rules_nodejs//:index.bzl", "js_library")
+
+package(default_visibility = ["//visibility:public"])
+
+SRCS = [
+ "index.js",
+ "package.json",
+]
+
+filegroup(
+ name = "local-module__files",
+ srcs = ["@fine_grained_deps_yarn//:node_modules/local-module/%s" % file for file in SRCS],
+)
+
+js_library(
+ name = "local-module",
+ srcs = [":local-module__files"],
+ deps = [
+ ":local-module__contents",
+ ],
+)
+
+js_library(
+ name = "local-module__contents",
+ srcs = [
+ ":local-module__files",
+ ":local-module__nested_node_modules",
+ ],
+ visibility = ["//:__subpackages__"],
+)
+
+filegroup(
+ name = "local-module__nested_node_modules",
+ visibility = ["//:__subpackages__"],
+)
diff --git a/tools/npm_packages/local_module/yarn/index.js b/tools/npm_packages/local_module/yarn/index.js
new file mode 100644
index 0000000000..e8e15eefe1
--- /dev/null
+++ b/tools/npm_packages/local_module/yarn/index.js
@@ -0,0 +1 @@
+module.exports = 'local_module';
diff --git a/tools/npm_packages/local_module/yarn/package.json b/tools/npm_packages/local_module/yarn/package.json
new file mode 100644
index 0000000000..870f1ba6e6
--- /dev/null
+++ b/tools/npm_packages/local_module/yarn/package.json
@@ -0,0 +1,4 @@
+{
+ "version": "0.0.1",
+ "main": "index.js"
+}
From dca6cb0a393a1c1f48902917e34bfa7b9eccaa66 Mon Sep 17 00:00:00 2001
From: Tiago Costa
Date: Wed, 16 Dec 2020 05:12:52 +0000
Subject: [PATCH 2/9] docs(builtin): update docs with details from that change
---
docs/Built-ins.html | 87 +++++++++++++------
docs/Built-ins.md | 121 ++++++++++++++-------------
internal/npm_install/npm_install.bzl | 46 +++++++++-
3 files changed, 168 insertions(+), 86 deletions(-)
diff --git a/docs/Built-ins.html b/docs/Built-ins.html
index 53624b2b71..e999218da6 100755
--- a/docs/Built-ins.html
+++ b/docs/Built-ins.html
@@ -109,10 +109,6 @@
set to another value in the environment attribute). Scripts may use to this to
check if yarn is being run by the npm_install repository rule.
+
LOCAL MODULES WITH THE NEED TO BE USED BOTH INSIDE AND OUTSIDE BAZEL
+
+
When using a monorepo is common to have locally written modules that we both
+want to use locally while publicly publishing them. That is not much of a problem
+as we can use a js_library rule with a package_name attribute defined inside the
+local package BUILD file. However, if we are in the middle of transition into bazel,
+or we have any other requirement to use that local package outside bazel we will also
+have to declare and install the local package with file: in the monorepo package.json
+dependencies, which could introduce a race condition within the npm_install rule.
+
+
In order to overcome it, a link will be created to the package BUILD file from the
+npm external Bazel repository, which require us to complete a last step which is writing
+the expected targets on that same BUILD file to be later used by the npm_install
+rule, which are: <package_name__files>, <package_name__nested_node_modules>,
+<package_name__contents>, <package_name__typings> and the last
+one just <package_name>.
+
+
If you doubt what those targets should look like, check the
+generated BUILD file for a given node module.
+
ATTRIBUTES
name
@@ -1034,9 +1064,7 @@
strict_visibility
All transitive dependencies are given limited visibility, enforcing that all direct dependencies are
listed in the package.json file.
-
Currently the default is set False, but will likely be flipped True in rules_nodejs 3.0.0
The pkg_npm rule creates a directory containing a publishable npm artifact.
@@ -1164,17 +1192,6 @@
package_name
Defaults to ""
-
replace_with_version
-
-
(String): DEPRECATED: use substitutions instead.
-
-
replace_with_version = "my_version_placeholder" is just syntax sugar for
-substitutions = {"my_version_placeholder": "{BUILD_SCM_VERSION}"}.
-
-
Follow this deprecation at https://github.com/bazelbuild/rules_nodejs/issues/2158
-
-
Defaults to "0.0.0-PLACEHOLDER"
-
srcs
(List of labels): Files inside this directory which are simply copied into the package.
@@ -1264,6 +1281,26 @@
yarn_install
set to another value in the environment attribute). Scripts may use to this to
check if yarn is being run by the yarn_install repository rule.
+
LOCAL MODULES WITH THE NEED TO BE USED BOTH INSIDE AND OUTSIDE BAZEL
+
+
When using a monorepo is common to have locally written modules that we both
+want to use locally while publicly publishing them. That is not much of a problem
+as we can use a js_library rule with a package_name attribute defined inside the
+local package BUILD file. However, if we are in the middle of transition into bazel,
+or we have any other requirement to use that local package outside bazel we will also
+have to declare and install the local package with link: in the monorepo package.json
+dependencies, which could introduce a race condition within the yarn_install rule.
+
+
In order to overcome it, a link will be created to the package BUILD file from the
+npm external Bazel repository, which require us to complete a last step which is writing
+the expected targets on that same BUILD file to be later used by the yarn_install
+rule, which are: <package_name__files>, <package_name__nested_node_modules>,
+<package_name__contents>, <package_name__typings> and the last
+one just <package_name>.
+
+
If you doubt what those targets should look like, check the
+generated BUILD file for a given node module.
+
ATTRIBUTES
name
@@ -1355,9 +1392,7 @@
strict_visibility
All transitive dependencies are given limited visibility, enforcing that all direct dependencies are
listed in the package.json file.
-
Currently the default is set False, but will likely be flipped True in rules_nodejs 3.0.0
-
-
Defaults to False
+
Defaults to True
symlink_node_modules
diff --git a/docs/Built-ins.md b/docs/Built-ins.md
index 09d79b3f8c..f52aa50e62 100755
--- a/docs/Built-ins.md
+++ b/docs/Built-ins.md
@@ -22,9 +22,9 @@ These rules are available without any npm installation, via the `WORKSPACE` inst
**USAGE**
To be run in user's WORKSPACE to install rules_nodejs dependencies.
@@ -142,6 +142,13 @@ Note that the dependency installation scripts will run in each subpackage indica
(*Name, mandatory*): A unique name for this repository.
+
node_download_auth
+
+(*Dictionary: String -> String*): auth to use for all url requests
+Example: {"type": "basic", "login": "", "password": "" }
+
+Defaults to `{}`
+
+
+(*Dictionary: String -> String*): auth to use for all url requests
+Example: {"type": "basic", "login": "", "password": "" }
+
+Defaults to `{}`
+
yarn_repositories
(*Dictionary: String -> List of strings*): Custom list of yarn repositories to use.
@@ -819,6 +833,27 @@ This rule will set the environment variable `BAZEL_NPM_INSTALL` to '1' (unless i
set to another value in the environment attribute). Scripts may use to this to
check if yarn is being run by the `npm_install` repository rule.
+
+**LOCAL MODULES WITH THE NEED TO BE USED BOTH INSIDE AND OUTSIDE BAZEL**
+
+When using a monorepo is common to have locally written modules that we both
+want to use locally while publicly publishing them. That is not much of a problem
+as we can use a `js_library` rule with a `package_name` attribute defined inside the
+local package `BUILD` file. However, if we are in the middle of transition into bazel,
+or we have any other requirement to use that local package outside bazel we will also
+have to declare and install the local package with `file:` in the monorepo `package.json`
+dependencies, which could introduce a race condition within the `npm_install rule`.
+
+In order to overcome it, a link will be created to the package `BUILD` file from the
+npm external Bazel repository, which require us to complete a last step which is writing
+the expected targets on that same `BUILD` file to be later used by the `npm_install`
+rule, which are: ``, ``,
+``, `` and the last
+one just ``.
+
+If you doubt what those targets should look like, check the
+generated `BUILD` file for a given node module.
+
**ATTRIBUTES**
@@ -919,9 +954,7 @@ When enabled, only dependencies within the given `package.json` file are given p
All transitive dependencies are given limited visibility, enforcing that all direct dependencies are
listed in the `package.json` file.
-Currently the default is set `False`, but will likely be flipped `True` in rules_nodejs 3.0.0
-
-Defaults to `False`
+Defaults to `True`
symlink_node_modules
@@ -947,24 +980,6 @@ Defaults to `True`
Defaults to `3600`
-**LOCAL MODULES**
-
-When using a monorepo is common to have locally written modules that we both
-want to use locally while publicly publishing them. To achieve it, we need
-to declare the package with `file:` in the monorepo `package.json` and
-define a `BUILD` file for that local package with a `js_library` rule
-defining its `package_name` argument.
-
-Doing what is mentioned above will be creating a link to the previous
-created `BUILD` file from the npm external Bazel repository, which require
-us to complete a last step which writing the expected targets on that
-same `BUILD` file to be later used by the `npm_install` rule, which
-are: ``, ``,
-``, `` and the last
-one just ``.
-
-If you doubt what those targets should look like, check the
-generated `BUILD` file for a given node module.
## pkg_npm
@@ -972,8 +987,8 @@ generated `BUILD` file for a given node module.
**USAGE**
The pkg_npm rule creates a directory containing a publishable npm artifact.
@@ -1078,17 +1093,6 @@ Defaults to `@build_bazel_rules_nodejs//internal:node_context_data`
Defaults to `""`
-
replace_with_version
-
-(*String*): DEPRECATED: use substitutions instead.
-
-`replace_with_version = "my_version_placeholder"` is just syntax sugar for
-`substitutions = {"my_version_placeholder": "{BUILD_SCM_VERSION}"}`.
-
-Follow this deprecation at https://github.com/bazelbuild/rules_nodejs/issues/2158
-
-Defaults to `"0.0.0-PLACEHOLDER"`
-
srcs
(*List of labels*): Files inside this directory which are simply copied into the package.
@@ -1185,6 +1189,27 @@ This rule will set the environment variable `BAZEL_YARN_INSTALL` to '1' (unless
set to another value in the environment attribute). Scripts may use to this to
check if yarn is being run by the `yarn_install` repository rule.
+
+**LOCAL MODULES WITH THE NEED TO BE USED BOTH INSIDE AND OUTSIDE BAZEL**
+
+When using a monorepo is common to have locally written modules that we both
+want to use locally while publicly publishing them. That is not much of a problem
+as we can use a `js_library` rule with a `package_name` attribute defined inside the
+local package `BUILD` file. However, if we are in the middle of transition into bazel,
+or we have any other requirement to use that local package outside bazel we will also
+have to declare and install the local package with `link:` in the monorepo `package.json`
+dependencies, which could introduce a race condition within the `yarn_install rule`.
+
+In order to overcome it, a link will be created to the package `BUILD` file from the
+npm external Bazel repository, which require us to complete a last step which is writing
+the expected targets on that same `BUILD` file to be later used by the `yarn_install`
+rule, which are: ``, ``,
+``, `` and the last
+one just ``.
+
+If you doubt what those targets should look like, check the
+generated `BUILD` file for a given node module.
+
**ATTRIBUTES**
@@ -1280,9 +1305,7 @@ When enabled, only dependencies within the given `package.json` file are given p
All transitive dependencies are given limited visibility, enforcing that all direct dependencies are
listed in the `package.json` file.
-Currently the default is set `False`, but will likely be flipped `True` in rules_nodejs 3.0.0
-
-Defaults to `False`
+Defaults to `True`
symlink_node_modules
@@ -1332,24 +1355,6 @@ Defaults to `True`
(*Label, mandatory*)
-**LOCAL MODULES**
-
-When using a monorepo is common to have locally written modules that we both
-want to use locally while publicly publishing them. To achieve it, we need
-to declare the package with `link:` in the monorepo `package.json` and
-define a `BUILD` file for that local package with a `js_library` rule
-defining its `package_name` argument.
-
-Doing what is mentioned above will be creating a link to the previous
-created `BUILD` file from the npm external Bazel repository, which require
-us to complete a last step which writing the expected targets on that
-same `BUILD` file to be later used by the `yarn_install` rule, which
-are: ``, ``,
-``, `` and the last
-one just ``.
-
-If you doubt what those targets should look like, check the
-generated `BUILD` file for a given node module.
## check_bazel_version
diff --git a/internal/npm_install/npm_install.bzl b/internal/npm_install/npm_install.bzl
index c74b9533e7..dda67d3daf 100644
--- a/internal/npm_install/npm_install.bzl
+++ b/internal/npm_install/npm_install.bzl
@@ -312,7 +312,28 @@ See npm CLI docs https://docs.npmjs.com/cli/install.html for complete list of su
This rule will set the environment variable `BAZEL_NPM_INSTALL` to '1' (unless it
set to another value in the environment attribute). Scripts may use to this to
-check if yarn is being run by the `npm_install` repository rule.""",
+check if yarn is being run by the `npm_install` repository rule.
+
+
+**LOCAL MODULES WITH THE NEED TO BE USED BOTH INSIDE AND OUTSIDE BAZEL**
+
+When using a monorepo is common to have locally written modules that we both
+want to use locally while publicly publishing them. That is not much of a problem
+as we can use a `js_library` rule with a `package_name` attribute defined inside the
+local package `BUILD` file. However, if we are in the middle of transition into bazel,
+or we have any other requirement to use that local package outside bazel we will also
+have to declare and install the local package with `file:` in the monorepo `package.json`
+dependencies, which could introduce a race condition within the `npm_install rule`.
+
+In order to overcome it, a link will be created to the package `BUILD` file from the
+npm external Bazel repository, which require us to complete a last step which is writing
+the expected targets on that same `BUILD` file to be later used by the `npm_install`
+rule, which are: ``, ``,
+``, `` and the last
+one just ``.
+
+If you doubt what those targets should look like, check the
+generated `BUILD` file for a given node module.""",
implementation = _npm_install_impl,
)
@@ -454,6 +475,27 @@ to yarn so that the local cache is contained within the external repository.
This rule will set the environment variable `BAZEL_YARN_INSTALL` to '1' (unless it
set to another value in the environment attribute). Scripts may use to this to
-check if yarn is being run by the `yarn_install` repository rule.""",
+check if yarn is being run by the `yarn_install` repository rule.
+
+
+**LOCAL MODULES WITH THE NEED TO BE USED BOTH INSIDE AND OUTSIDE BAZEL**
+
+When using a monorepo is common to have locally written modules that we both
+want to use locally while publicly publishing them. That is not much of a problem
+as we can use a `js_library` rule with a `package_name` attribute defined inside the
+local package `BUILD` file. However, if we are in the middle of transition into bazel,
+or we have any other requirement to use that local package outside bazel we will also
+have to declare and install the local package with `link:` in the monorepo `package.json`
+dependencies, which could introduce a race condition within the `yarn_install rule`.
+
+In order to overcome it, a link will be created to the package `BUILD` file from the
+npm external Bazel repository, which require us to complete a last step which is writing
+the expected targets on that same `BUILD` file to be later used by the `yarn_install`
+rule, which are: ``, ``,
+``, `` and the last
+one just ``.
+
+If you doubt what those targets should look like, check the
+generated `BUILD` file for a given node module.""",
implementation = _yarn_install_impl,
)
From 6c2b41f3b8ccc2f6a59c758be81cadad900f3d8c Mon Sep 17 00:00:00 2001
From: Tiago Costa
Date: Wed, 16 Dec 2020 05:24:22 +0000
Subject: [PATCH 3/9] docs(builtin): restore old source for builtin doc
generated files
---
docs/Built-ins.html | 2617 +++++++++++++++++++++----------------------
docs/Built-ins.md | 43 -
2 files changed, 1288 insertions(+), 1372 deletions(-)
diff --git a/docs/Built-ins.html b/docs/Built-ins.html
index e999218da6..5f0397209d 100755
--- a/docs/Built-ins.html
+++ b/docs/Built-ins.html
@@ -1,212 +1,212 @@
-
-
-
-
-
+
+
+
+
+
- rules_nodejs - Built-ins
+ rules_nodejs - Built-ins
-
-
+
+
-
-
+
+
-
-
+
+
-
-
-
+
+
+
-
-
+
+
-
-
-
+
+
+