From c69e10f2ad1760c11bf440d13401061247090186 Mon Sep 17 00:00:00 2001 From: zemnmez Date: Wed, 3 Aug 2022 16:31:27 -0700 Subject: [PATCH 1/3] use API extractor --- js/npm/rules.bzl | 12 ++++++++++-- ts/cmd/svgshot/BUILD | 26 ++++++++++++-------------- ts/cmd/svgshot/index.ts | 20 ++------------------ ts/cmd/svgshot/package.template.json | 2 +- ts/cmd/svgshot/run.ts | 18 ++++++++++++++++++ ts/cmd/svgshot/svgshot_test.ts | 2 +- 6 files changed, 44 insertions(+), 36 deletions(-) create mode 100644 ts/cmd/svgshot/run.ts diff --git a/js/npm/rules.bzl b/js/npm/rules.bzl index e000e2ca13..f6f117361b 100644 --- a/js/npm/rules.bzl +++ b/js/npm/rules.bzl @@ -1,4 +1,5 @@ load("//bzl/versioning:rules.bzl", "bump_on_change_test", "semver_version") +load("@aspect_bazel_lib//lib:copy_to_directory.bzl", "copy_to_directory") load("//js/npm/yarn/lock:rules.bzl", "lockfile_minimize") load("@build_bazel_rules_nodejs//:index.bzl", "pkg_npm") load("//js/api-extractor:rules.bzl", "api_extractor") @@ -57,13 +58,20 @@ def npm_pkg( publicTrimmedRollup = "public.d.ts", ) + copy_to_directory( + name = name + "_dir", + srcs = srcs + deps + [pkg_json_name, lockfile_name, "public.d.ts"], + replace_prefixes = { + "public.d.ts": "index.d.ts", + }, + ) + pkg_srcs = srcs pkg_deps = deps + [pkg_json_name, lockfile_name] pkg_npm( name = name, package_name = package_name, - srcs = pkg_srcs, - deps = pkg_deps, + deps = [name + "_dir"], tgz = tgz, visibility = visibility, ) diff --git a/ts/cmd/svgshot/BUILD b/ts/cmd/svgshot/BUILD index b2e53aa18c..83e7fb4d22 100644 --- a/ts/cmd/svgshot/BUILD +++ b/ts/cmd/svgshot/BUILD @@ -1,4 +1,5 @@ load("//ts:rules.bzl", "jest_test", "ts_project") +load("@build_bazel_rules_nodejs//:index.bzl", "js_library") load("//:rules.bzl", "nodejs_binary") load("//js/npm:rules.bzl", "npm_pkg") @@ -12,11 +13,8 @@ ts_project( srcs = [ "index.ts", "lib.ts", - "svgshot_test.ts", ], deps = [ - "@npm//@bazel/runfiles", - "@npm//@types/jest", "@npm//@types/node", "@npm//@types/svgo", "@npm//@types/tmp", @@ -27,17 +25,17 @@ ts_project( ], ) -nodejs_binary( - name = "svgshot", - args = [ - "--inkscapeBin", - "$(location //cc/inkscape:bin)", - ], - data = [ +ts_project( + name = "tests_js", + srcs = ["svgshot_test.ts"], + deps = [ ":project", - "//cc/inkscape:bin", + "@npm//@bazel/runfiles", + "@npm//@types/jest", + "@npm//@types/node", + "@npm//@types/tmp", + "@npm//tmp", ], - entry_point = "index.ts", ) jest_test( @@ -46,7 +44,7 @@ jest_test( data = [ "//cc/inkscape:bin", ], - deps = [":project"], + deps = [":tests_js"], ) npm_pkg( @@ -54,7 +52,7 @@ npm_pkg( package_name = "svgshot", srcs = ["README.md"] + glob(["docs/**/*"]), api_lock = ".api.lock", - entry_point = "lib.ts", + entry_point = "index.ts", major_version = "version/MAJOR", minor_version = "version/MINOR", patch_version = "version/PATCH", diff --git a/ts/cmd/svgshot/index.ts b/ts/cmd/svgshot/index.ts index bdaa90f7b9..966a450010 100644 --- a/ts/cmd/svgshot/index.ts +++ b/ts/cmd/svgshot/index.ts @@ -1,18 +1,2 @@ -#!/usr/bin/env node - -/** - * @fileoverview The main entry point for svgshot. - * - * Svgshot is separated out into a lib to allow easier testing. - * - * I wouldn't worry about it too much. - */ - -import main from './lib'; - -main() - .catch(e => { - console.error(e); - process.exit(1); - }) - .then(() => process.exit(0)); +export * from './lib'; +export { default } from './lib'; diff --git a/ts/cmd/svgshot/package.template.json b/ts/cmd/svgshot/package.template.json index 716d9ee37d..f08cae8af4 100644 --- a/ts/cmd/svgshot/package.template.json +++ b/ts/cmd/svgshot/package.template.json @@ -2,7 +2,7 @@ "name": "svgshot", "main": "index.js", "bin": { - "svgshot": "index.js" + "svgshot": "run.js" }, "repository": { "type": "git", diff --git a/ts/cmd/svgshot/run.ts b/ts/cmd/svgshot/run.ts new file mode 100644 index 0000000000..bdaa90f7b9 --- /dev/null +++ b/ts/cmd/svgshot/run.ts @@ -0,0 +1,18 @@ +#!/usr/bin/env node + +/** + * @fileoverview The main entry point for svgshot. + * + * Svgshot is separated out into a lib to allow easier testing. + * + * I wouldn't worry about it too much. + */ + +import main from './lib'; + +main() + .catch(e => { + console.error(e); + process.exit(1); + }) + .then(() => process.exit(0)); diff --git a/ts/cmd/svgshot/svgshot_test.ts b/ts/cmd/svgshot/svgshot_test.ts index 7441e32d5e..8ba5afc918 100644 --- a/ts/cmd/svgshot/svgshot_test.ts +++ b/ts/cmd/svgshot/svgshot_test.ts @@ -1,4 +1,4 @@ -import main from './lib'; +import main from 'ts/cmd/svgshot/lib'; import tmp from 'tmp'; import fs from 'fs/promises'; import { runfiles } from '@bazel/runfiles'; From 2f629003115d050ad247f99d28bb9e435133b6ef Mon Sep 17 00:00:00 2001 From: zemnmez Date: Wed, 3 Aug 2022 16:37:12 -0700 Subject: [PATCH 2/3] oops forgot this --- ts/cmd/svgshot/BUILD | 1 + 1 file changed, 1 insertion(+) diff --git a/ts/cmd/svgshot/BUILD b/ts/cmd/svgshot/BUILD index 83e7fb4d22..b6b3fc0fb9 100644 --- a/ts/cmd/svgshot/BUILD +++ b/ts/cmd/svgshot/BUILD @@ -13,6 +13,7 @@ ts_project( srcs = [ "index.ts", "lib.ts", + "run.ts" ], deps = [ "@npm//@types/node", From fa13bf41a7138b03197b066f8fdb2c2a7bb20318 Mon Sep 17 00:00:00 2001 From: zemnmez Date: Thu, 4 Aug 2022 11:23:25 -0700 Subject: [PATCH 3/3] fixes versus master --- ts/cmd/svgshot/svgshot_test.ts | 2 +- ts/do-sync/testing/BUILD | 7 ++----- ts/do-sync/testing/doSync_test.ts | 2 +- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/ts/cmd/svgshot/svgshot_test.ts b/ts/cmd/svgshot/svgshot_test.ts index 8ba5afc918..0bc26e2d6c 100644 --- a/ts/cmd/svgshot/svgshot_test.ts +++ b/ts/cmd/svgshot/svgshot_test.ts @@ -1,4 +1,4 @@ -import main from 'ts/cmd/svgshot/lib'; +import main from 'monorepo/ts/cmd/svgshot/lib'; import tmp from 'tmp'; import fs from 'fs/promises'; import { runfiles } from '@bazel/runfiles'; diff --git a/ts/do-sync/testing/BUILD b/ts/do-sync/testing/BUILD index 5469a20b99..49a68fd2a2 100644 --- a/ts/do-sync/testing/BUILD +++ b/ts/do-sync/testing/BUILD @@ -8,18 +8,15 @@ package(default_visibility = [ ts_project( name = "project", - srcs = glob(["**/*.ts"]) + [":npm_pkg"], + srcs = glob(["**/*.ts"]), deps = [ "@npm//@types/jest", "@npm//@types/sharp", "@npm//sharp", + "//ts/do-sync" ], ) -js_library( - name = "npm_pkg", - deps = ["//ts/do-sync:npm_pkg"], -) jest_test( name = "tests", diff --git a/ts/do-sync/testing/doSync_test.ts b/ts/do-sync/testing/doSync_test.ts index 1ad8bd6a33..3adc87c264 100644 --- a/ts/do-sync/testing/doSync_test.ts +++ b/ts/do-sync/testing/doSync_test.ts @@ -1,4 +1,4 @@ -import { doSync, JSONObject } from 'monorepo/ts/do-sync/npm_pkg'; +import { doSync, JSONObject } from 'monorepo/ts/do-sync'; import sharpT from 'sharp'; const pixel =