Skip to content

Commit

Permalink
chore: add 1p linked deps to e2e/js_image_oci (#1710)
Browse files Browse the repository at this point in the history
  • Loading branch information
gregmagolan committed May 20, 2024
1 parent 2791a25 commit 419fe96
Show file tree
Hide file tree
Showing 14 changed files with 167 additions and 21 deletions.
2 changes: 2 additions & 0 deletions e2e/js_image_oci/.bazelignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
node_modules
pkg/a/node_modules
pkg/b/node_modules
repo
14 changes: 3 additions & 11 deletions e2e/js_image_oci/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ bazel_dep(name = "platforms", version = "0.0.10", dev_dependency = True)
bazel_dep(name = "rules_nodejs", version = "5.8.2", dev_dependency = True)
bazel_dep(name = "rules_oci", version = "1.7.5", dev_dependency = True)

npm = use_extension(
"@aspect_rules_js//npm:extensions.bzl",
"npm",
dev_dependency = True,
)
npm = use_extension("@aspect_rules_js//npm:extensions.bzl", "npm", dev_dependency = True)
npm.npm_translate_lock(
name = "npm",
npmrc = "//:.npmrc",
Expand All @@ -23,7 +19,7 @@ npm.npm_translate_lock(
)
use_repo(npm, "npm")

oci = use_extension("@rules_oci//oci:extensions.bzl", "oci")
oci = use_extension("@rules_oci//oci:extensions.bzl", "oci", dev_dependency = True)
oci.pull(
name = "debian",
digest = "sha256:3d868b5eb908155f3784317b3dda2941df87bbbbaa4608f84881de66d9bb297b",
Expand All @@ -41,9 +37,5 @@ oci.pull(
)
use_repo(oci, "debian")

node = use_extension(
"@rules_nodejs//nodejs:extensions.bzl",
"node",
dev_dependency = True,
)
node = use_extension("@rules_nodejs//nodejs:extensions.bzl", "node", dev_dependency = True)
use_repo(node, "nodejs_toolchains")
5 changes: 4 additions & 1 deletion e2e/js_image_oci/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"name": "image",
"dependencies": {
"chalk": "^4.0.0"
"acorn": "8.7.1",
"chalk": "^4.0.0",
"@mycorp/pkg-a": "workspace:*",
"@mycorp/pkg-b": "workspace:*"
}
}
16 changes: 16 additions & 0 deletions e2e/js_image_oci/pkg/a/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
load("@aspect_rules_js//npm:defs.bzl", "npm_package")
load("@npm//:defs.bzl", "npm_link_all_packages")

npm_link_all_packages(name = "node_modules")

npm_package(
name = "pkg",
srcs = [
"index.js",
"package.json",
],
data = [
":node_modules",
],
visibility = ["//visibility:public"],
)
17 changes: 17 additions & 0 deletions e2e/js_image_oci/pkg/a/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* @fileoverview minimal test program that requires third-party packages from npm
*/
const acorn = require('acorn')

function getAcornVersion() {
return acorn.version
}

function getUuidVersion() {
return require('uuid/package.json').version
}

module.exports = {
getAcornVersion,
getUuidVersion,
}
10 changes: 10 additions & 0 deletions e2e/js_image_oci/pkg/a/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "@mycorp/pkg-a",
"private": true,
"dependencies": {
"uuid": "9.0.1"
},
"peerDependencies": {
"acorn": "8.x.x"
}
}
19 changes: 19 additions & 0 deletions e2e/js_image_oci/pkg/b/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
load("@aspect_rules_js//js:defs.bzl", "js_library")
load("@npm//:defs.bzl", "npm_link_all_packages")

npm_link_all_packages(name = "node_modules")

js_library(
name = "pkg",
srcs = [
"index.js",
"package.json",
],
visibility = ["//visibility:public"],
# because we're linking this js_library, we must explictly add our npm dependendies to `deps` so
# they are picked up my the linker. npm dependendies in `data` are not propogated through the
# linker when linking a js_libary.
deps = [
":node_modules",
],
)
17 changes: 17 additions & 0 deletions e2e/js_image_oci/pkg/b/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* @fileoverview minimal test program that requires third-party packages from npm
*/
const acorn = require('acorn')

function getAcornVersion() {
return acorn.version
}

function getUuidVersion() {
return require('uuid/package.json').version
}

module.exports = {
getAcornVersion,
getUuidVersion,
}
10 changes: 10 additions & 0 deletions e2e/js_image_oci/pkg/b/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "@mycorp/pkg-b",
"private": true,
"dependencies": {
"uuid": "8.3.2"
},
"peerDependencies": {
"acorn": "8.x.x"
}
}
62 changes: 57 additions & 5 deletions e2e/js_image_oci/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion e2e/js_image_oci/pnpm-workspace.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
packages:
- '.'
- 'pkg/a'
- 'pkg/b'
1 change: 1 addition & 0 deletions e2e/js_image_oci/src/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ js_binary(
data = [
"ascii.art",
":proto",
"//:node_modules/@mycorp/pkg-a",
"//:node_modules/chalk",
"@repo//:dir",
"@repo//:source_txt",
Expand Down
8 changes: 5 additions & 3 deletions e2e/js_image_oci/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ console.log(
)
console.log('')

const pkgA = require('@mycorp/pkg-a')
console.log(`@mycorp/pkg-a acorn@${pkgA.getAcornVersion()}`)
console.log(`@mycorp/pkg-a uuid@${pkgA.getUuidVersion()}`)
console.log('')

console.log(
chalk.bold.bgYellow(' SOURCE CHECK '),
space,
Expand All @@ -48,7 +53,6 @@ console.log(
)
)
)

console.log(
chalk.bold.bgMagenta(' DIRECTORY CHECK '),
space,
Expand All @@ -58,7 +62,6 @@ console.log(
)
)
)

console.log(
chalk.bold.bgMagenta(' SOURCE DIRECTORY CHECK '),
space,
Expand All @@ -68,7 +71,6 @@ console.log(
)
)
)

console.log(
chalk.bold.bgWhite(' PROTO CHECK '),
space,
Expand Down
4 changes: 4 additions & 0 deletions e2e/js_image_oci/src/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ commandTests:
' TARGET //src:bin',
' CWD /app/src/bin.runfiles/',
' JS_BINARY__RUNFILES /app/src/bin.runfiles',
'@mycorp/pkg-a acorn@7.4.0',
'@mycorp/pkg-a uuid@9.0.1',
' SOURCE CHECK true',
' DIRECTORY CHECK true',
' PROTO CHECK true',
Expand All @@ -27,6 +29,8 @@ commandTests:
' TARGET //src:bin',
' CWD /app/src/bin.runfiles/',
' JS_BINARY__RUNFILES /app/src/bin.runfiles',
'@mycorp/pkg-a acorn@7.4.0',
'@mycorp/pkg-a uuid@9.0.1',
' SOURCE CHECK true',
' DIRECTORY CHECK true',
' PROTO CHECK true',
Expand Down

0 comments on commit 419fe96

Please sign in to comment.