Add @plugins_npm for plugin dependencies
Change-Id: I0139febad10c8073bfab3fa324a2a8ac2a25d8d6
diff --git a/.gitignore b/.gitignore
index 3a5d28b..bcafbb4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -31,6 +31,8 @@
/node_modules/
/package-lock.json
/plugins/*
+!/plugins/package.json
+!/plugins/yarn.lock
!/plugins/BUILD
!/plugins/codemirror-editor
!/plugins/commit-message-length-validator
diff --git a/WORKSPACE b/WORKSPACE
index 91eef76..158a7cc 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -10,6 +10,8 @@
# @ui_npm folder must not have devDependencies. All dev dependencies must be placed in @ui_dev_npm
# 4. @ui_dev_npm (polygerrit-ui/node_modules) - devDependencies for polygerrit. The packages from these
# folder can be used for testing, but must not be included in the final bundle.
+# 5. @plugins_npm (plugins/node_modules) - plugin dependencies for polygerrit plugins.
+# The packages here are expected to be used in plugins.
# Note: separation between @ui_npm and @ui_dev_npm is necessary because with bazel we can't generate
# two managed directories from the same package.json. At the same time we want to avoid accidental
# usages of code from devDependencies in polygerrit bundle.
@@ -20,6 +22,7 @@
"@ui_npm": ["polygerrit-ui/app/node_modules"],
"@ui_dev_npm": ["polygerrit-ui/node_modules"],
"@tools_npm": ["tools/node_tools/node_modules"],
+ "@plugins_npm": ["plugins/node_modules"],
},
)
@@ -1208,6 +1211,13 @@
yarn_lock = "//:tools/node_tools/yarn.lock",
)
+yarn_install(
+ name = "plugins_npm",
+ args = ["--prod"],
+ package_json = "//:plugins/package.json",
+ yarn_lock = "//:plugins/yarn.lock",
+)
+
# Install all Bazel dependencies needed for npm packages that supply Bazel rules
load("@npm//:install_bazel_dependencies.bzl", "install_bazel_dependencies")
diff --git a/plugins/package.json b/plugins/package.json
new file mode 100644
index 0000000..e0227d1
--- /dev/null
+++ b/plugins/package.json
@@ -0,0 +1,8 @@
+{
+ "name": "polygerrit-plugin-dependencies-placeholder",
+ "description": "Gerrit Code Review - Polygerrit plugin dependencies placeholder, expected to be overriden by plugins",
+ "browser": true,
+ "dependencies": {},
+ "license": "Apache-2.0",
+ "private": true
+}
\ No newline at end of file
diff --git a/plugins/yarn.lock b/plugins/yarn.lock
new file mode 100644
index 0000000..a63f96e
--- /dev/null
+++ b/plugins/yarn.lock
@@ -0,0 +1,3 @@
+# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
+# yarn lockfile v1
+# This is an empty placeholder
\ No newline at end of file
diff --git a/polygerrit-ui/Polymer3.md b/polygerrit-ui/Polymer3.md
index 94750d8..186f0f4 100644
--- a/polygerrit-ui/Polymer3.md
+++ b/polygerrit-ui/Polymer3.md
@@ -14,6 +14,11 @@
To get inspirations, check out our [samples here](https://gerrit.googlesource.com/gerrit/+/master/polygerrit-ui/app/samples).
+### Plugin dependencies
+
+Since most of Gerrit plugins are treated as sub modules and part of the Gerrit workspace when develop, dependencies of plugins are also defined and installed from Gerrit WORKSPACE, currently most of them are `bower_archives`. When moving to npm, if your plugin requires dependencies, you can have them added to your plugin's `package.json` and then link that file to `plugins/package.json` in gerrit.
+Then use `@plugins_npm//:node_modules` to make sure `rollup_bundle` knows the right place to look for. More examples from `image-diff` plugin, [change 271672](https://gerrit-review.googlesource.com/c/plugins/image-diff/+/271672).
+
### Related resources
- [Polymer 3.0 upgrade guide](https://polymer-library.polymer-project.org/3.0/docs/upgrade)