Skip to content

Commit

Permalink
Merge pull request #56 from sfc-gh-jlai/main
Browse files Browse the repository at this point in the history
Add support for scoped packages within monorepos
  • Loading branch information
ewianda authored Apr 23, 2024
2 parents 5cad13d + a8097fc commit 6542264
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 0 deletions.
9 changes: 9 additions & 0 deletions gazelle/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,10 +413,19 @@ func (lang *JS) isNpmDependency(imp string, jsConfig *JsConfig) (bool, string, b
return true, npmLabel, false
}

// Is the original package found in package.json ?
if npmLabel, ok := jsConfig.NpmDependencies.Dependencies[imp]; ok {
return true, npmLabel, false
}

if npmLabel, ok := jsConfig.NpmDependencies.DevDependencies[packageRoot]; ok {
return true, npmLabel, true
}

if npmLabel, ok := jsConfig.NpmDependencies.DevDependencies[imp]; ok {
return true, npmLabel, true
}

// Assume all @ imports are npm dependencies
if strings.HasPrefix(imp, "@types/") {
// Need to ignore @types/, since these are checked greedily
Expand Down
1 change: 1 addition & 0 deletions tests/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,6 @@ go_binary(
"ts_conversion",
"visibility",
"web_assets_module",
"monorepo",
]
]
Empty file added tests/monorepo/BUILD.in
Empty file.
Empty file added tests/monorepo/WORKSPACE
Empty file.
7 changes: 7 additions & 0 deletions tests/monorepo/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "monorepo",
"description": "A test case",
"version": "0.0.0",
"dependencies": {
}
}
2 changes: 2 additions & 0 deletions tests/monorepo/project_a/BUILD.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# gazelle:js_package_file package.json :node_modules
# gazelle:js_collect_all
17 changes: 17 additions & 0 deletions tests/monorepo/project_a/BUILD.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
load("@aspect_rules_js//js:defs.bzl", "js_library")
load("@aspect_rules_ts//ts:defs.bzl", "ts_project")

# gazelle:js_package_file package.json :node_modules
# gazelle:js_collect_all

js_library(
name = "package_json",
srcs = ["package.json"],
)

ts_project(
name = "project_a",
srcs = ["a.ts"],
data = ["//project_a:node_modules/@emotion/react"],
deps = ["//project_a:node_modules/@emotion/react"],
)
1 change: 1 addition & 0 deletions tests/monorepo/project_a/a.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import '@emotion/react'
8 changes: 8 additions & 0 deletions tests/monorepo/project_a/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "monorepo_project_a",
"description": "A test case",
"version": "0.0.0",
"dependencies": {
"@emotion/react": "11.11.4"
}
}

0 comments on commit 6542264

Please sign in to comment.