From e618b395932b4196f770caa0620557046406003d Mon Sep 17 00:00:00 2001 From: Adam Dierkens Date: Thu, 14 Jul 2022 14:13:36 -0700 Subject: [PATCH 1/6] Add version prop to generated package.json --- javascript/package_json/create_package_json.js | 1 + 1 file changed, 1 insertion(+) diff --git a/javascript/package_json/create_package_json.js b/javascript/package_json/create_package_json.js index 43378eb..8853125 100644 --- a/javascript/package_json/create_package_json.js +++ b/javascript/package_json/create_package_json.js @@ -50,6 +50,7 @@ const main = ([config]) => { fs.writeFileSync(output_file, JSON.stringify({ name, + version: placeholder_version, peerDependencies: createDependencyObject(peer_dependencies), dependencies: createDependencyObject(dependencies), main: path.join(out_dir, 'index.cjs.js'), From f217dbcf7e1e3a1482064a09a4e579f511cc8147 Mon Sep 17 00:00:00 2001 From: Adam Dierkens Date: Thu, 14 Jul 2022 14:25:16 -0700 Subject: [PATCH 2/6] Change version substitution --- javascript/js_library_pipeline.bzl | 17 +++++++++++------ javascript/npm.bzl | 15 --------------- 2 files changed, 11 insertions(+), 21 deletions(-) delete mode 100644 javascript/npm.bzl diff --git a/javascript/js_library_pipeline.bzl b/javascript/js_library_pipeline.bzl index 633d98c..0c3fc48 100644 --- a/javascript/js_library_pipeline.bzl +++ b/javascript/js_library_pipeline.bzl @@ -1,9 +1,8 @@ load("//javascript/package_json:package_json.bzl", "create_package_json") load("//javascript/rollup:rollup_build.bzl", "rollup_bin_build", "rollup_build") -load("@build_bazel_rules_nodejs//:index.bzl", "js_library") +load("@build_bazel_rules_nodejs//:index.bzl", "js_library", "pkg_npm") load("@npm//jest-cli:index.bzl", "jest_test") load("@npm//eslint:index.bzl", "eslint_test") -load(":npm.bzl", "publish_npm") load(":utils.bzl", "filter_empty", "without_tests", "remove_duplicates", "include_exts") BUILD_DATA = [ @@ -125,8 +124,14 @@ def js_library_pipeline( data = remove_duplicates(filter_empty([jest_config] + data + test_data + dependencies + peer_dependencies + srcs)), ) - publish_npm( - name = "%s-publish", - version = version_file, - bundle = [":%s" % name], + pkg_npm( + name = "pkg_npm", + package_name = name, + deps = [":%s" % name], + substitutions = { + "__VERSION__": "{STABLE_VERSION}", + "0.0.0-PLACEHOLDER": "{STABLE_VERSION}", + "__GIT_COMMIT__": "{STABLE_GIT_COMMIT}", + }, + validate = False, ) diff --git a/javascript/npm.bzl b/javascript/npm.bzl deleted file mode 100644 index 96feeb7..0000000 --- a/javascript/npm.bzl +++ /dev/null @@ -1,15 +0,0 @@ -load("@vaticle_bazel_distribution//npm:rules.bzl", "assemble_npm", "deploy_npm") -load("@build_bazel_rules_nodejs//:index.bzl", "pkg_npm") - -def publish_npm(name, version, bundle): - pkg_npm( - name = "pkg_npm", - package_name = name, - deps = bundle, - substitutions = { - "__VERSION__": "{VERSION}", - "0.0.0-PLACEHOLDER": "{VERSION}", - "__GIT_COMMIT__": "{STABLE_GIT_COMMIT}", - }, - validate = False, - ) \ No newline at end of file From 0e60e94fd6b8d3366afa7591c7d7b2031dd8f0ff Mon Sep 17 00:00:00 2001 From: Adam Dierkens Date: Thu, 14 Jul 2022 14:44:00 -0700 Subject: [PATCH 3/6] Add tag for private npm packages --- javascript/js_library_pipeline.bzl | 5 +++++ javascript/package_json/create_package_json.js | 4 +++- javascript/package_json/package_json.bzl | 4 ++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/javascript/js_library_pipeline.bzl b/javascript/js_library_pipeline.bzl index 0c3fc48..271b227 100644 --- a/javascript/js_library_pipeline.bzl +++ b/javascript/js_library_pipeline.bzl @@ -36,6 +36,7 @@ def js_library_pipeline( version_file = "//:VERSION", root_package_json = "//:package.json", typings = [], + private = False, test_file_pattern = [ "_tests_", ".test.", @@ -51,6 +52,7 @@ def js_library_pipeline( name = create_package_json_name, package_name = name, entry = entry, + private = private, bin_entry = bin_entry, bin_name = bin_name, out_dir = out_dir, @@ -128,6 +130,9 @@ def js_library_pipeline( name = "pkg_npm", package_name = name, deps = [":%s" % name], + tags = filter_empty([ + "do-not-publish" if private else None + ]), substitutions = { "__VERSION__": "{STABLE_VERSION}", "0.0.0-PLACEHOLDER": "{STABLE_VERSION}", diff --git a/javascript/package_json/create_package_json.js b/javascript/package_json/create_package_json.js index 8853125..22113e8 100644 --- a/javascript/package_json/create_package_json.js +++ b/javascript/package_json/create_package_json.js @@ -15,7 +15,8 @@ const main = ([config]) => { root_package_json, base_package_json, additional_properties, - out_dir + out_dir, + private } = JSON.parse(config); const rootPackageJson = JSON.parse(fs.readFileSync(root_package_json, 'utf-8')); @@ -51,6 +52,7 @@ const main = ([config]) => { fs.writeFileSync(output_file, JSON.stringify({ name, version: placeholder_version, + private, peerDependencies: createDependencyObject(peer_dependencies), dependencies: createDependencyObject(dependencies), main: path.join(out_dir, 'index.cjs.js'), diff --git a/javascript/package_json/package_json.bzl b/javascript/package_json/package_json.bzl index 1adf808..e618db2 100644 --- a/javascript/package_json/package_json.bzl +++ b/javascript/package_json/package_json.bzl @@ -20,6 +20,9 @@ PACKGE_JSON_ATTRS = { # The name for a bin entry "bin_name": attr.string(), + # If the package should skipped being published to npm + "private": attr.bool(default = False), + # A .json file to use to add additional properties to the generated package. # This can often be a 'package.json' and the entries/outputs/dependencies will be filled in later on "base_package_json": attr.label(allow_single_file = ["*.json"]), @@ -96,6 +99,7 @@ def _create_package_json_impl(ctx): "peer_dependencies": [_get_pkg_name(dep) for dep in ctx.attr.peer_dependencies], "dependencies": [_get_pkg_name(dep) for dep in ctx.attr.dependencies], "local_deps": local_deps, + "private": ctx.attr.private, })], executable = "_create_pkg_json", ) From 0be1596eb93957954ddb12bb744e9ec63d198478 Mon Sep 17 00:00:00 2001 From: Adam Dierkens Date: Fri, 15 Jul 2022 11:51:48 -0700 Subject: [PATCH 4/6] Add publish registry to package generation --- javascript/js_library_pipeline.bzl | 4 ++++ javascript/package_json/create_package_json.js | 10 ++++++++++ javascript/package_json/package_json.bzl | 4 ++++ 3 files changed, 18 insertions(+) diff --git a/javascript/js_library_pipeline.bzl b/javascript/js_library_pipeline.bzl index 271b227..5d9689e 100644 --- a/javascript/js_library_pipeline.bzl +++ b/javascript/js_library_pipeline.bzl @@ -31,8 +31,10 @@ def js_library_pipeline( lint_data = [], lint_exts = [".ts", ".js", ".tsx", ".jsx"], js_library_data = [], + publish_data = [], test_env = {}, placeholder_version = PLACEHOLDER_VERSION, + registry = "https://registry.npmjs.org", version_file = "//:VERSION", root_package_json = "//:package.json", typings = [], @@ -56,6 +58,7 @@ def js_library_pipeline( bin_entry = bin_entry, bin_name = bin_name, out_dir = out_dir, + registry = registry, placeholder_version = placeholder_version, dependencies = dependencies, peer_dependencies = peer_dependencies, @@ -130,6 +133,7 @@ def js_library_pipeline( name = "pkg_npm", package_name = name, deps = [":%s" % name], + data = publish_data, tags = filter_empty([ "do-not-publish" if private else None ]), diff --git a/javascript/package_json/create_package_json.js b/javascript/package_json/create_package_json.js index 22113e8..c0abee1 100644 --- a/javascript/package_json/create_package_json.js +++ b/javascript/package_json/create_package_json.js @@ -16,6 +16,7 @@ const main = ([config]) => { base_package_json, additional_properties, out_dir, + registry, private } = JSON.parse(config); @@ -49,10 +50,19 @@ const main = ([config]) => { } } + let publishConfig = undefined; + + if (registry) { + publishConfig = { + "registry": registry, + } + } + fs.writeFileSync(output_file, JSON.stringify({ name, version: placeholder_version, private, + publishConfig, peerDependencies: createDependencyObject(peer_dependencies), dependencies: createDependencyObject(dependencies), main: path.join(out_dir, 'index.cjs.js'), diff --git a/javascript/package_json/package_json.bzl b/javascript/package_json/package_json.bzl index e618db2..78d7bce 100644 --- a/javascript/package_json/package_json.bzl +++ b/javascript/package_json/package_json.bzl @@ -23,6 +23,9 @@ PACKGE_JSON_ATTRS = { # If the package should skipped being published to npm "private": attr.bool(default = False), + # The npm registry to publish to + "registry": attr.string(), + # A .json file to use to add additional properties to the generated package. # This can often be a 'package.json' and the entries/outputs/dependencies will be filled in later on "base_package_json": attr.label(allow_single_file = ["*.json"]), @@ -100,6 +103,7 @@ def _create_package_json_impl(ctx): "dependencies": [_get_pkg_name(dep) for dep in ctx.attr.dependencies], "local_deps": local_deps, "private": ctx.attr.private, + "registry": ctx.attr.registry, })], executable = "_create_pkg_json", ) From 847683f19091152b183295cb5822351d14c66ce3 Mon Sep 17 00:00:00 2001 From: Adam Dierkens Date: Fri, 15 Jul 2022 16:07:46 -0700 Subject: [PATCH 5/6] remove publish data --- javascript/js_library_pipeline.bzl | 2 -- 1 file changed, 2 deletions(-) diff --git a/javascript/js_library_pipeline.bzl b/javascript/js_library_pipeline.bzl index 5d9689e..9c34346 100644 --- a/javascript/js_library_pipeline.bzl +++ b/javascript/js_library_pipeline.bzl @@ -31,7 +31,6 @@ def js_library_pipeline( lint_data = [], lint_exts = [".ts", ".js", ".tsx", ".jsx"], js_library_data = [], - publish_data = [], test_env = {}, placeholder_version = PLACEHOLDER_VERSION, registry = "https://registry.npmjs.org", @@ -133,7 +132,6 @@ def js_library_pipeline( name = "pkg_npm", package_name = name, deps = [":%s" % name], - data = publish_data, tags = filter_empty([ "do-not-publish" if private else None ]), From 3975e4810f81719d6197e0440ea5065852a3ede2 Mon Sep 17 00:00:00 2001 From: Adam Dierkens Date: Fri, 15 Jul 2022 16:26:57 -0700 Subject: [PATCH 6/6] Update tests --- .../examples/ts-monorepo/packages/module-a/package.test.json | 5 +++++ .../examples/ts-monorepo/packages/module-b/package.test.json | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/javascript/examples/ts-monorepo/packages/module-a/package.test.json b/javascript/examples/ts-monorepo/packages/module-a/package.test.json index aba277c..76916e6 100644 --- a/javascript/examples/ts-monorepo/packages/module-a/package.test.json +++ b/javascript/examples/ts-monorepo/packages/module-a/package.test.json @@ -1,5 +1,10 @@ { "name": "@test/module-a", + "version": "0.0.0-PLACEHOLDER", + "private": false, + "publishConfig": { + "registry": "https://registry.npmjs.org" + }, "peerDependencies": { "typescript": "^4.5.2" }, diff --git a/javascript/examples/ts-monorepo/packages/module-b/package.test.json b/javascript/examples/ts-monorepo/packages/module-b/package.test.json index 41f8a00..98f8b42 100644 --- a/javascript/examples/ts-monorepo/packages/module-b/package.test.json +++ b/javascript/examples/ts-monorepo/packages/module-b/package.test.json @@ -1,5 +1,10 @@ { "name": "@test/module-b", + "version": "0.0.0-PLACEHOLDER", + "private": false, + "publishConfig": { + "registry": "https://registry.npmjs.org" + }, "peerDependencies": {}, "dependencies": { "@test/module-a": "0.0.0-PLACEHOLDER"