Skip to content

Commit

Permalink
discovery: Recognize .mjs/.cjs for Node.js (DataDog#31477)
Browse files Browse the repository at this point in the history
Co-authored-by: Guy Arbitman <[email protected]>
  • Loading branch information
vitkyrka and guyarb authored Nov 26, 2024
1 parent 30698d8 commit 04a7d9a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pkg/collector/corechecks/servicediscovery/usm/nodejs.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ func newNodeDetector(ctx DetectionContext) detector {
return &nodeDetector{ctx: ctx}
}

func isJs(path string) bool {
return strings.HasSuffix(strings.ToLower(path), ".js")
func isJs(filepath string) bool {
ext := strings.ToLower(path.Ext(filepath))
return ext == ".js" || ext == ".mjs" || ext == ".cjs"
}

func (n nodeDetector) detect(args []string) (ServiceMetadata, bool) {
Expand Down
20 changes: 20 additions & 0 deletions pkg/collector/corechecks/servicediscovery/usm/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,26 @@ func TestExtractServiceMetadata(t *testing.T) {
expectedGeneratedName: "my-awesome-package",
fs: &subUsmTestData,
},
{
name: "nodejs .cjs with a valid package.json",
cmdline: []string{
"/usr/bin/node",
"./testdata/foo.cjs",
},
lang: language.Node,
expectedGeneratedName: "my-awesome-package",
fs: &subUsmTestData,
},
{
name: "nodejs .mjs with a valid package.json",
cmdline: []string{
"/usr/bin/node",
"./testdata/bar.mjs",
},
lang: language.Node,
expectedGeneratedName: "my-awesome-package",
fs: &subUsmTestData,
},
{
name: "node js with a symlink to a .js file and valid package.json",
cmdline: []string{
Expand Down
Empty file.
Empty file.

0 comments on commit 04a7d9a

Please sign in to comment.