-
-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: consuming linked js_library vs npm_package (#1852)
Aligning with rules_ts tests https://github.com/aspect-build/rules_ts/tree/main/examples/linked_consumer
- Loading branch information
Showing
18 changed files
with
5,436 additions
and
4,897 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,10 @@ | |
# This file should be checked into version control along with the pnpm-lock.yaml file. | ||
.npmrc=-2065072158 | ||
examples/js_binary/package.json=-41174383 | ||
examples/linked_consumer/package.json=-1109186228 | ||
examples/linked_empty_node_modules/package.json=-1039372825 | ||
examples/linked_lib/package.json=1590632845 | ||
examples/linked_pkg/package.json=-726181961 | ||
examples/macro/package.json=857146175 | ||
examples/npm_deps/package.json=-929156430 | ||
examples/npm_deps/patches/[email protected]=-442666336 | ||
|
@@ -24,5 +27,5 @@ npm/private/test/vendored/is-odd/package.json=1041695223 | |
npm/private/test/vendored/lodash-4.17.21.tgz=-1206623349 | ||
npm/private/test/vendored/semver-max/package.json=578664053 | ||
package.json=-275319675 | ||
pnpm-lock.yaml=2129089772 | ||
pnpm-workspace.yaml=-1282513813 | ||
pnpm-lock.yaml=76490674 | ||
pnpm-workspace.yaml=-884103165 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
load("@aspect_rules_js//js:defs.bzl", "js_test") | ||
load("@npm//:defs.bzl", "npm_link_all_packages") | ||
|
||
npm_link_all_packages(name = "node_modules") | ||
|
||
# Exposed by js_library() | ||
js_test( | ||
name = "direct", | ||
data = [ | ||
"//examples/linked_lib:lib", | ||
"//examples/linked_pkg:lib", | ||
], | ||
entry_point = "test_file_all_linked.js", | ||
) | ||
|
||
# Exposed by linked npm deps | ||
js_test( | ||
name = "pkg", | ||
data = [ | ||
":node_modules/@lib/test", | ||
":node_modules/@lib/test2", | ||
], | ||
entry_point = "test_pkg_deps_linked.js", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "tests", | ||
"private": true, | ||
"dependencies": { | ||
"@lib/test": "workspace:*", | ||
"@lib/test2": "workspace:*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Asserts all dependencies are available directly from the file | ||
|
||
const testLib = require('../linked_pkg/index') | ||
const testLib2 = require('../linked_lib/index') | ||
|
||
console.log( | ||
'loaded dependency', | ||
testLib.importDep().id(), | ||
testLib2.importDep().id() | ||
) | ||
console.log( | ||
'loaded devDependency', | ||
testLib.importDevDep().id(), | ||
testLib2.importDevDep().id() | ||
) | ||
console.log( | ||
'loaded aliased dependency', | ||
testLib.importAliasedDep().id(), | ||
testLib2.importAliasedDep().id() | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Asserts *only non-dev* dependencies are available from the npm package | ||
|
||
const testLib = require('@lib/test') | ||
const testLib2 = require('@lib/test2') | ||
|
||
console.log( | ||
'loaded dependency', | ||
testLib.importDep().id(), | ||
testLib2.importDep().id() | ||
) | ||
console.log( | ||
'loaded aliased dependency', | ||
testLib.importAliasedDep().id(), | ||
testLib2.importAliasedDep().id() | ||
) | ||
|
||
let e = null | ||
try { | ||
testLib.importDevDep() | ||
} catch (ex) { | ||
e = ex | ||
} | ||
if (e == null) { | ||
throw new Error('devDependency should NOT be available') | ||
} | ||
|
||
let e2 = null | ||
try { | ||
testLib2.importDevDep() | ||
} catch (ex) { | ||
e2 = ex | ||
} | ||
if (e2 == null) { | ||
console.error( | ||
'BUG: devDependency should NOT be available when linking js_library()' | ||
) | ||
} | ||
|
||
console.log('devDependency not available') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
load("@aspect_rules_js//js:defs.bzl", "js_library") | ||
load("@npm//:defs.bzl", "npm_link_all_packages") | ||
|
||
npm_link_all_packages(name = "node_modules") | ||
|
||
# A basic package with 2 simple dependencies (packages with no dependencies) | ||
# Exposed via js_library() | ||
js_library( | ||
name = "pkg", | ||
srcs = [ | ||
"index.js", | ||
"package.json", | ||
], | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
":node_modules/@aspect-test/e", | ||
":node_modules/@aspect-test/f", | ||
":node_modules/@types/node", | ||
":node_modules/alias-e", | ||
], | ||
) | ||
|
||
# When using js_library() as a package it can also serve as a "lib". | ||
# Use an alias so both linked_lib and linked_pkg have the same target names. | ||
alias( | ||
name = "lib", | ||
actual = ":pkg", | ||
visibility = ["//visibility:public"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
exports.importDep = () => require('@aspect-test/e') | ||
exports.importDevDep = () => require('@aspect-test/f') | ||
exports.importAliasedDep = () => require('alias-e') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "@lib/test2", | ||
"private": true, | ||
"dependencies": { | ||
"@aspect-test/e": "1.0.0", | ||
"alias-e": "npm:@aspect-test/e" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "18.13.0", | ||
"@aspect-test/f": "1.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
load("@aspect_rules_js//js:defs.bzl", "js_library") | ||
load("@aspect_rules_js//npm:defs.bzl", "npm_package") | ||
load("@npm//:defs.bzl", "npm_link_all_packages") | ||
|
||
npm_link_all_packages(name = "node_modules") | ||
|
||
# A basic library with 2 simple dependencies (packages with no dependencies) | ||
js_library( | ||
name = "lib", | ||
srcs = ["index.js"], | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
":node_modules/@aspect-test/e", | ||
":node_modules/@aspect-test/f", | ||
":node_modules/@types/node", | ||
":node_modules/alias-e", | ||
], | ||
) | ||
|
||
# Exposed via npm_package() | ||
npm_package( | ||
name = "pkg", | ||
srcs = [ | ||
":lib", | ||
], | ||
visibility = ["//visibility:public"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
exports.importDep = () => require('@aspect-test/e') | ||
exports.importDevDep = () => require('@aspect-test/f') | ||
exports.importAliasedDep = () => require('alias-e') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "@lib/test", | ||
"private": true, | ||
"dependencies": { | ||
"@aspect-test/e": "1.0.0", | ||
"alias-e": "npm:@aspect-test/e" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "18.13.0", | ||
"@aspect-test/f": "1.0.0" | ||
} | ||
} |
Oops, something went wrong.