Skip to content
Open
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ Jupytext, nbstripout and Papermill are detected from dependencies or their proje

JSON when piped, human-readable on a TTY. Force either with `--json` or `--human`. Use `--category test` to filter to a single category.

In `languages`, a TypeScript entry has `declarations_only: true` when every TypeScript file matching the scan is a declaration (`.d.ts`, `.d.mts`, or `.d.cts`). It is `false` if the scan found a TypeScript implementation file and omitted when TypeScript was detected without matching files, for example from `tsconfig.json`. This uses the same scan bounds and language evidence filters as detection.

JSON reports include a `manifests` array with the path, kind, and package ecosystem of every parsed manifest or lockfile. The `dependencies` array includes constraints from manifests and pinned packages from lockfiles, preserving directness and scope when the source records them. For Cargo, direct constraints come from `Cargo.toml`; pinned `Cargo.lock` entries are reported with `direct` set to `false`.

```
Expand Down
2 changes: 2 additions & 0 deletions brief.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ type Detection struct {
Repo string `json:"repo,omitempty"`
Description string `json:"description,omitempty"`
Taxonomy *Taxonomy `json:"taxonomy,omitempty"`
// DeclarationsOnly describes TypeScript file evidence when available.
DeclarationsOnly *bool `json:"declarations_only,omitempty"`
}

// Taxonomy holds oss-taxonomy facet classifications carried through from
Expand Down
90 changes: 90 additions & 0 deletions cmd/brief/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,96 @@ func TestScanUsesPathRoles(t *testing.T) {
}
}

func TestScanReportsTypeScriptDeclarationOnly(t *testing.T) {
const helperEnv = "BRIEF_TYPESCRIPT_FILES_HELPER_ROOT"
if root := os.Getenv(helperEnv); root != "" {
cmdScan([]string{"-json", root})
return
}

tests := []struct {
name string
files []string
want string
}{
{
name: "declarations with JavaScript",
files: []string{"index.d.ts", "dist/ignored.ts", "testdata/ignored.mts"},
want: "true",
},
{
name: "declarations and implementation",
files: []string{"index.d.ts", "src/index.ts"},
want: "false",
},
{
name: "ES module declarations",
files: []string{"types/index.d.mts"},
want: "true",
},
{
name: "CommonJS declarations",
files: []string{"types/index.d.cts"},
want: "true",
},
{
name: "CommonJS implementation",
files: []string{"types/index.d.cts", "src/index.cts"},
want: "false",
},
{
name: "nested JSX implementation",
files: []string{"src/view.tsx"},
want: "false",
},
{
name: "configuration only",
files: []string{"tsconfig.json"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
root := t.TempDir()
writeScanFixture(t, root, "index.js", "exports.answer = () => 42;\n")
for _, file := range tt.files {
writeScanFixture(t, root, file, "{}\n")
}
cmd := exec.Command(os.Args[0], "-test.run=^TestScanReportsTypeScriptDeclarationOnly$")
cmd.Env = append(os.Environ(), helperEnv+"="+root, "PATH=")
out, err := cmd.Output()
if err != nil {
t.Fatalf("scan command failed: %v", err)
}
var report struct {
Languages []struct {
Name string `json:"name"`
DeclarationsOnly json.RawMessage `json:"declarations_only"`
} `json:"languages"`
}
if err := json.Unmarshal(out, &report); err != nil {
t.Fatalf("parsing scan output: %v\n%s", err, out)
}
found := false
for _, language := range report.Languages {
got := string(language.DeclarationsOnly)
if language.Name != "TypeScript" {
if got != "" {
t.Errorf("%s has unexpected declarations_only metadata", language.Name)
}
continue
}
found = true
if got != tt.want {
t.Errorf("declarations_only = %q, want %q (empty means omitted)", got, tt.want)
}
}
if !found {
t.Fatal("TypeScript language missing")
}
})
}
}

func TestScanDefaultsBoundRecursiveDetection(t *testing.T) {
if root := os.Getenv(scanHelperRootEnv); root != "" {
cmdScan([]string{"-json", root})
Expand Down
3 changes: 3 additions & 0 deletions detect/detect.go
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,9 @@ func (e *Engine) detectDefinitions(tools []*kb.ToolDef) []brief.Detection {
d.ConfigFiles = e.findExisting(tool.Config.Files)
if tool.Tool.Category == categoryLanguage {
d.ConfigFiles = append(d.ConfigFiles, e.notebookLanguagePaths(tool.Tool.Name)...)
if d.Name == "TypeScript" {
d.DeclarationsOnly = e.typeScriptDeclarationsOnly()
}
}

d.Lockfile = e.detectLockfile(tool)
Expand Down
22 changes: 22 additions & 0 deletions detect/roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,25 @@ func (e *Engine) languageFileExists(pattern string) bool {
}
return false
}

func (e *Engine) typeScriptDeclarationsOnly() *bool {
e.loadProjectFiles()
var hasDeclaration bool
for _, rel := range e.projectFiles {
ext := filepath.Ext(rel)
switch ext {
case ".ts", ".tsx", ".mts", ".cts":
if !e.languageEvidence(rel) {
continue
}
if ext == ".tsx" || !strings.HasSuffix(rel, ".d"+ext) {
return new(false)
}
hasDeclaration = true
}
}
if hasDeclaration {
return new(true)
}
return nil
}
2 changes: 1 addition & 1 deletion knowledge/node/typescript.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ repo = "https://github.com/microsoft/TypeScript"
description = "Typed superset of JavaScript"

[detect]
files = ["tsconfig.json", "**/tsconfig.json", "*.ts", "**/*.ts", "*.tsx"]
files = ["tsconfig.json", "**/tsconfig.json", "**/*.ts", "**/*.tsx", "**/*.mts", "**/*.cts"]
dependencies = ["typescript"]
dev_dependencies = ["typescript"]
ecosystems = ["node"]
Expand Down
Loading