Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for scoped packages within monorepos #56

Merged
merged 1 commit into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
}
}
Loading