metascope 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.DS_Store +0 -0
- package/dist/bin/cli.js +14 -14
- package/dist/lib/{chunk-DrSxFLj_.js → _virtual/_rolldown/runtime.js} +1 -1
- package/dist/lib/file-matching.js +152 -0
- package/dist/lib/index.d.ts +11 -1496
- package/dist/lib/index.js +6 -6215
- package/dist/lib/log.d.ts +11 -0
- package/dist/lib/log.js +20 -0
- package/dist/lib/metadata-types.d.ts +151 -0
- package/dist/lib/metadata-types.js +30 -0
- package/dist/lib/metadata.d.ts +16 -0
- package/dist/lib/metadata.js +235 -0
- package/dist/lib/package.js +5 -0
- package/dist/lib/parsers/configparser-parser.js +43 -0
- package/dist/lib/parsers/gemspec-parser.js +256 -0
- package/dist/lib/parsers/go-mod-parser.js +153 -0
- package/dist/lib/parsers/makefile-config-parser.js +102 -0
- package/dist/lib/parsers/properties-parser.js +31 -0
- package/dist/lib/parsers/rfc822-header-parser.js +48 -0
- package/dist/lib/parsers/setup-py-parser.js +173 -0
- package/dist/lib/source.d.ts +17 -0
- package/dist/lib/source.js +34 -0
- package/dist/lib/sources/arduino-library-properties.d.ts +45 -0
- package/dist/lib/sources/arduino-library-properties.js +208 -0
- package/dist/lib/sources/cinder-cinderblock-xml.d.ts +21 -0
- package/dist/lib/sources/cinder-cinderblock-xml.js +134 -0
- package/dist/lib/sources/code-stats.d.ts +14 -0
- package/dist/lib/sources/code-stats.js +40 -0
- package/dist/lib/sources/codemeta-json.d.ts +117 -0
- package/dist/lib/sources/codemeta-json.js +226 -0
- package/dist/lib/sources/dependency-updates.d.ts +22 -0
- package/dist/lib/sources/dependency-updates.js +132 -0
- package/dist/lib/sources/file-stats.d.ts +12 -0
- package/dist/lib/sources/file-stats.js +48 -0
- package/dist/lib/sources/git-config.d.ts +8 -0
- package/dist/lib/sources/git-config.js +21 -0
- package/dist/lib/sources/git-stats.d.ts +35 -0
- package/dist/lib/sources/git-stats.js +130 -0
- package/dist/lib/sources/github.d.ts +94 -0
- package/dist/lib/sources/github.js +399 -0
- package/dist/lib/sources/go-go-mod.d.ts +19 -0
- package/dist/lib/sources/go-go-mod.js +38 -0
- package/dist/lib/sources/go-goreleaser-yaml.d.ts +19 -0
- package/dist/lib/sources/go-goreleaser-yaml.js +152 -0
- package/dist/lib/sources/java-pom-xml.d.ts +52 -0
- package/dist/lib/sources/java-pom-xml.js +248 -0
- package/dist/lib/sources/license-file.d.ts +10 -0
- package/dist/lib/sources/license-file.js +26 -0
- package/dist/lib/sources/metadata-file.d.ts +14 -0
- package/dist/lib/sources/metadata-file.js +109 -0
- package/dist/lib/sources/metascope.d.ts +14 -0
- package/dist/lib/sources/metascope.js +35 -0
- package/dist/lib/sources/node-npm-registry.d.ts +19 -0
- package/dist/lib/sources/node-npm-registry.js +74 -0
- package/dist/lib/sources/node-package-json.d.ts +7 -0
- package/dist/lib/sources/node-package-json.js +27 -0
- package/dist/lib/sources/obsidian-plugin-manifest-json.d.ts +17 -0
- package/dist/lib/sources/obsidian-plugin-manifest-json.js +34 -0
- package/dist/lib/sources/obsidian-plugin-registry.d.ts +10 -0
- package/dist/lib/sources/obsidian-plugin-registry.js +44 -0
- package/dist/lib/sources/openframeworks-addon-config-mk.d.ts +17 -0
- package/dist/lib/sources/openframeworks-addon-config-mk.js +39 -0
- package/dist/lib/sources/openframeworks-install-xml.d.ts +20 -0
- package/dist/lib/sources/openframeworks-install-xml.js +153 -0
- package/dist/lib/sources/processing-library-properties.d.ts +44 -0
- package/dist/lib/sources/processing-library-properties.js +219 -0
- package/dist/lib/sources/processing-sketch-properties.d.ts +38 -0
- package/dist/lib/sources/processing-sketch-properties.js +185 -0
- package/dist/lib/sources/publiccode-yaml.d.ts +73 -0
- package/dist/lib/sources/publiccode-yaml.js +256 -0
- package/dist/lib/sources/python-pkg-info.d.ts +31 -0
- package/dist/lib/sources/python-pkg-info.js +115 -0
- package/dist/lib/sources/python-pypi-registry.d.ts +19 -0
- package/dist/lib/sources/python-pypi-registry.js +101 -0
- package/dist/lib/sources/python-pyproject-toml.d.ts +7 -0
- package/dist/lib/sources/python-pyproject-toml.js +30 -0
- package/dist/lib/sources/python-setup-cfg.d.ts +28 -0
- package/dist/lib/sources/python-setup-cfg.js +106 -0
- package/dist/lib/sources/python-setup-py.d.ts +28 -0
- package/dist/lib/sources/python-setup-py.js +48 -0
- package/dist/lib/sources/readme-file.d.ts +11 -0
- package/dist/lib/sources/readme-file.js +55 -0
- package/dist/lib/sources/ruby-gemspec.d.ts +44 -0
- package/dist/lib/sources/ruby-gemspec.js +62 -0
- package/dist/lib/sources/rust-cargo-toml.d.ts +40 -0
- package/dist/lib/sources/rust-cargo-toml.js +159 -0
- package/dist/lib/sources/xcode-info-plist.d.ts +22 -0
- package/dist/lib/sources/xcode-info-plist.js +199 -0
- package/dist/lib/sources/xcode-project-pbxproj.d.ts +21 -0
- package/dist/lib/sources/xcode-project-pbxproj.js +222 -0
- package/dist/lib/templates/codemeta.d.ts +47 -0
- package/dist/lib/templates/codemeta.js +494 -0
- package/dist/lib/templates/frontmatter.d.ts +87 -0
- package/dist/lib/templates/frontmatter.js +111 -0
- package/dist/lib/templates/index.d.ts +181 -0
- package/dist/lib/templates/index.js +22 -0
- package/dist/lib/templates/metadata.d.ts +17 -0
- package/dist/lib/templates/metadata.js +35 -0
- package/dist/lib/templates/project.d.ts +39 -0
- package/dist/lib/templates/project.js +51 -0
- package/dist/lib/utilities/codemeta-helpers.d.ts +39 -0
- package/dist/lib/utilities/codemeta-helpers.js +83 -0
- package/dist/lib/utilities/fetch.js +43 -0
- package/dist/lib/utilities/formatting.js +28 -0
- package/dist/lib/utilities/license-identification.js +141 -0
- package/dist/lib/utilities/schema-primitives.js +47 -0
- package/dist/lib/utilities/template-helpers.d.ts +135 -0
- package/dist/lib/utilities/template-helpers.js +310 -0
- package/dist/lib/utilities/tree-sitter-wasm.js +30 -0
- package/package.json +6 -6
- package/readme.md +62 -15
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { log } from "./log.js";
|
|
2
|
+
import { defu } from "defu";
|
|
3
|
+
import { dirname, relative, resolve } from "node:path";
|
|
4
|
+
import is from "@sindresorhus/is";
|
|
5
|
+
import { findWorkspaces } from "find-workspaces";
|
|
6
|
+
import { existsSync } from "node:fs";
|
|
7
|
+
import picomatch from "picomatch";
|
|
8
|
+
import { exec } from "tinyexec";
|
|
9
|
+
import { escapePath, glob } from "tinyglobby";
|
|
10
|
+
//#region src/lib/file-matching.ts
|
|
11
|
+
const matchCache = /* @__PURE__ */ new Map();
|
|
12
|
+
const workspaceCache = /* @__PURE__ */ new Map();
|
|
13
|
+
/**
|
|
14
|
+
* Clear the memoized file tree and workspace caches. Call between test runs
|
|
15
|
+
* or when the same path needs to be re-scanned.
|
|
16
|
+
*/
|
|
17
|
+
function resetMatchCache() {
|
|
18
|
+
matchCache.clear();
|
|
19
|
+
workspaceCache.clear();
|
|
20
|
+
}
|
|
21
|
+
const DEFAULT_IGNORE = [
|
|
22
|
+
"**/node_modules/**",
|
|
23
|
+
"**/dist/**",
|
|
24
|
+
"**/build/**",
|
|
25
|
+
"**/coverage/**",
|
|
26
|
+
"**/.DS_Store"
|
|
27
|
+
];
|
|
28
|
+
/**
|
|
29
|
+
* Get the full recursive file tree for a directory, memoized by path + respectIgnored.
|
|
30
|
+
* Returns relative POSIX paths (internal to tinyglobby; callers receive absolute paths via getMatches).
|
|
31
|
+
*/
|
|
32
|
+
async function getTree(path, respectIgnored) {
|
|
33
|
+
const key = `${path}\0${respectIgnored ? "1" : "0"}`;
|
|
34
|
+
let tree = matchCache.get(key);
|
|
35
|
+
if (!tree) {
|
|
36
|
+
let ignore = [];
|
|
37
|
+
if (respectIgnored) try {
|
|
38
|
+
const { stdout } = await exec("git", [
|
|
39
|
+
"ls-files",
|
|
40
|
+
"--others",
|
|
41
|
+
"--ignored",
|
|
42
|
+
"--exclude-standard",
|
|
43
|
+
"--directory"
|
|
44
|
+
], { nodeOptions: {
|
|
45
|
+
cwd: path,
|
|
46
|
+
stdio: [
|
|
47
|
+
"ignore",
|
|
48
|
+
"pipe",
|
|
49
|
+
"ignore"
|
|
50
|
+
]
|
|
51
|
+
} });
|
|
52
|
+
ignore = stdout.split("\n").filter(Boolean).map((p) => {
|
|
53
|
+
const escaped = escapePath(p);
|
|
54
|
+
return escaped.endsWith("/") ? `${escaped}**` : escaped;
|
|
55
|
+
});
|
|
56
|
+
} catch {
|
|
57
|
+
ignore = [...DEFAULT_IGNORE];
|
|
58
|
+
}
|
|
59
|
+
tree = await glob("**", {
|
|
60
|
+
cwd: path,
|
|
61
|
+
dot: true,
|
|
62
|
+
ignore
|
|
63
|
+
});
|
|
64
|
+
matchCache.set(key, tree);
|
|
65
|
+
}
|
|
66
|
+
return tree;
|
|
67
|
+
}
|
|
68
|
+
function validateWorkspaces(directory, workspaces) {
|
|
69
|
+
const seen = /* @__PURE__ */ new Set();
|
|
70
|
+
const validated = [];
|
|
71
|
+
for (const workspace of workspaces) {
|
|
72
|
+
if (!is.nonEmptyString(workspace)) {
|
|
73
|
+
log.warn(`Skipping invalid workspace: expected non-empty string, got ${is(workspace)}`);
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
const absolute = resolve(directory, workspace);
|
|
77
|
+
if (absolute === directory) continue;
|
|
78
|
+
if (!absolute.startsWith(directory)) {
|
|
79
|
+
log.warn(`Skipping workspace "${workspace}": must be a child of "${directory}"`);
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
if (!existsSync(absolute)) {
|
|
83
|
+
log.warn(`Skipping workspace "${workspace}": path does not exist`);
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
if (seen.has(absolute)) {
|
|
87
|
+
log.warn(`Skipping workspace "${workspace}": duplicate entry`);
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
seen.add(absolute);
|
|
91
|
+
validated.push(absolute);
|
|
92
|
+
}
|
|
93
|
+
return validated;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Get workspace locations for a directory, memoized by directory path.
|
|
97
|
+
* Returns all found workspace location paths as absolute paths.
|
|
98
|
+
*
|
|
99
|
+
* Directories to any monorepo workspaces... only supports yarn, npm, pnpm, lerna, and bolt at the moment.
|
|
100
|
+
* Never includes the root path!
|
|
101
|
+
* @param directory - The root directory to search from
|
|
102
|
+
* @param workspaces - `false` to disable, `true` to auto-discover, `string[]` for a manual list
|
|
103
|
+
*/
|
|
104
|
+
function getWorkspaces(directory, workspaces = true) {
|
|
105
|
+
if (workspaces === false) return [];
|
|
106
|
+
let locations = workspaceCache.get(directory);
|
|
107
|
+
if (!locations) {
|
|
108
|
+
locations = validateWorkspaces(directory, workspaces === true ? findWorkspaces(directory, { stopDir: dirname(directory) })?.map((value) => value.location) ?? [] : workspaces);
|
|
109
|
+
workspaceCache.set(directory, locations);
|
|
110
|
+
}
|
|
111
|
+
return locations;
|
|
112
|
+
}
|
|
113
|
+
const DEFAULT_MATCH_OPTIONS = {
|
|
114
|
+
path: ".",
|
|
115
|
+
recursive: false,
|
|
116
|
+
respectIgnored: true,
|
|
117
|
+
workspaces: true
|
|
118
|
+
};
|
|
119
|
+
/**
|
|
120
|
+
* Find files matching glob patterns in a directory's file tree.
|
|
121
|
+
*
|
|
122
|
+
* - Memoizes the file tree internally (keyed by path + respectIgnored)
|
|
123
|
+
* - Auto-prepends `**\/` to patterns when `options.recursive` is true
|
|
124
|
+
* - Always uses case-insensitive matching
|
|
125
|
+
* - When `options.workspaces` is set, also matches files in workspace directories dynamically.
|
|
126
|
+
* @param options - Must include `path`; optionally `recursive`, `respectIgnored`, and `workspaces`
|
|
127
|
+
* @param patterns - Root-relative glob patterns (e.g. `['package.json']`, `['*.gemspec']`)
|
|
128
|
+
* @param patternsRecursive - Optionally explicitly specify recursive pattern
|
|
129
|
+
* variation, otherwise `**\/` is prepended automatically
|
|
130
|
+
*/
|
|
131
|
+
async function getMatches(options, patterns, patternsRecursive) {
|
|
132
|
+
const resolved = defu(options, DEFAULT_MATCH_OPTIONS);
|
|
133
|
+
const tree = await getTree(resolved.path, resolved.respectIgnored);
|
|
134
|
+
let effectivePatterns;
|
|
135
|
+
if (resolved.recursive) effectivePatterns = patternsRecursive ?? patterns.map((p) => `**/${p}`);
|
|
136
|
+
else {
|
|
137
|
+
effectivePatterns = [...patterns];
|
|
138
|
+
if (resolved.workspaces) {
|
|
139
|
+
const workspacePaths = getWorkspaces(resolved.path, resolved.workspaces);
|
|
140
|
+
for (const workspace of workspacePaths) {
|
|
141
|
+
const relativeWorkspace = relative(resolved.path, workspace).replaceAll("\\", "/");
|
|
142
|
+
effectivePatterns.push(...patterns.map((p) => `${relativeWorkspace}/${p}`));
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
const isMatch = picomatch(effectivePatterns, { nocase: true });
|
|
147
|
+
const results = [];
|
|
148
|
+
for (const filePath of tree) if (isMatch(filePath)) results.push(resolve(resolved.path, filePath));
|
|
149
|
+
return results.toSorted((a, b) => a.split("/").length - b.split("/").length || a.localeCompare(b));
|
|
150
|
+
}
|
|
151
|
+
//#endregion
|
|
152
|
+
export { getMatches, getTree, getWorkspaces, resetMatchCache };
|