@nexapp/code-map 0.1.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/bin/code-map ADDED
Binary file
package/bin.js ADDED
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ const { execFileSync } = require('child_process');
5
+ const path = require('path');
6
+ const fs = require('fs');
7
+
8
+ const ext = process.platform === 'win32' ? '.exe' : '';
9
+ const binaryName = `code-map${ext}`;
10
+
11
+ // 1. Co-located binary — present when installed via `npm install -g /local/path`
12
+ const localBin = path.join(__dirname, 'bin', binaryName);
13
+ if (fs.existsSync(localBin)) {
14
+ try {
15
+ execFileSync(localBin, process.argv.slice(2), { stdio: 'inherit' });
16
+ } catch (err) {
17
+ process.exit(err.status ?? 1);
18
+ }
19
+ process.exit(0);
20
+ }
21
+
22
+ // 2. Platform package — present when installed from the npm registry
23
+ const PLATFORMS = {
24
+ 'darwin-arm64': '@nexapp/code-map-darwin-arm64',
25
+ 'darwin-x64': '@nexapp/code-map-darwin-x64',
26
+ 'linux-arm64': '@nexapp/code-map-linux-arm64',
27
+ 'linux-x64': '@nexapp/code-map-linux-x64',
28
+ 'win32-x64': '@nexapp/code-map-win32-x64',
29
+ };
30
+
31
+ const key = `${process.platform}-${process.arch}`;
32
+ const pkg = PLATFORMS[key];
33
+
34
+ if (!pkg) {
35
+ console.error(`code-map: unsupported platform ${key}`);
36
+ process.exit(1);
37
+ }
38
+
39
+ let binPath;
40
+ try {
41
+ binPath = require.resolve(`${pkg}/bin/${binaryName}`);
42
+ } catch {
43
+ console.error(
44
+ `code-map: could not find binary for ${key}.\n` +
45
+ `Try reinstalling: npm install ${pkg}`
46
+ );
47
+ process.exit(1);
48
+ }
49
+
50
+ try {
51
+ execFileSync(binPath, process.argv.slice(2), { stdio: 'inherit' });
52
+ } catch (err) {
53
+ process.exit(err.status ?? 1);
54
+ }
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "@nexapp/code-map",
3
+ "version": "0.1.0",
4
+ "description": "TypeScript dependency analyzer and visualizer — analyze imports, find unused exports, and explore project graphs.",
5
+ "keywords": [
6
+ "typescript",
7
+ "dependencies",
8
+ "imports",
9
+ "visualization",
10
+ "analysis"
11
+ ],
12
+ "homepage": "https://git.nexapptech.com/internal/code-map",
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+ssh://git@git.nexapptech.com/internal/code-map.git"
16
+ },
17
+ "license": "MIT",
18
+ "bin": {
19
+ "code-map": "./bin.js"
20
+ },
21
+ "files": [
22
+ "bin.js",
23
+ "bin/",
24
+ "plugin/"
25
+ ],
26
+ "optionalDependencies": {
27
+ "@nexapp/code-map-darwin-arm64": "0.1.0",
28
+ "@nexapp/code-map-darwin-x64": "0.1.0",
29
+ "@nexapp/code-map-linux-x64": "0.1.0",
30
+ "@nexapp/code-map-linux-arm64": "0.1.0",
31
+ "@nexapp/code-map-win32-x64": "0.1.0"
32
+ }
33
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "name": "code-map",
3
+ "description": "TypeScript dependency analysis. Answers questions about file dependencies, unused exports, and project-wide import cycles using the code-map tool.",
4
+ "version": "1.0.0",
5
+ "author": {
6
+ "name": "spaceparanoids"
7
+ },
8
+ "skills": [
9
+ "skills/analyze-file",
10
+ "skills/find-unused-exports",
11
+ "skills/project-overview"
12
+ ]
13
+ }
@@ -0,0 +1,39 @@
1
+ ---
2
+
3
+ name: analyze-file
4
+ description: Show what a specific TypeScript file imports and what imports it. Use when asked about a file's dependencies, dependents, or role in the project.
5
+
6
+ ---
7
+
8
+ Analyze a single file's dependencies from a code-map snapshot.
9
+
10
+ ## Step 1: Locate the snapshot
11
+
12
+ Look for `code-map.json` in the project root. If it does not exist, tell the user:
13
+
14
+ > No code-map snapshot found. Run:
15
+ > `npx code-map index .`
16
+ > Then run this skill again.
17
+
18
+ If it is more than a day old (check `meta.indexed_at`), suggest re-indexing before continuing.
19
+
20
+ ## Step 2: Identify the file
21
+
22
+ Ask the user which file to analyze if not already specified. Match against `files[].id` in the snapshot.
23
+
24
+ ## Step 3: Find dependencies
25
+
26
+ From `dependencies[]`:
27
+
28
+ - **Outgoing** (`from` starts with the file path): what this file imports
29
+ - **Incoming** (`to` starts with the file path): what imports this file
30
+ - **Cycles**: any entry in `cycles[]` that involves this file
31
+
32
+ Decode the entity ref format:
33
+ - `path/to/file.ts[file]` — file-level import
34
+ - `path/to/file.ts:Name[class|function|interface|enum|type]` — named entity
35
+ - `lib:react` — external library
36
+
37
+ ## Step 4: Report
38
+
39
+ List outgoing imports grouped by target file, incoming imports grouped by source file, and any cycles. Keep it factual.
@@ -0,0 +1,56 @@
1
+ ---
2
+
3
+ name: find-unused-exports
4
+ description: Find exported symbols in the TypeScript project that nothing imports. Use when asked about dead code, unused exports, or cleanup opportunities.
5
+
6
+ ---
7
+
8
+ Find unused exports from a code-map snapshot.
9
+
10
+ ## Step 1: Locate the snapshot
11
+
12
+ Look for `code-map.json` in the project root. If it does not exist, tell the user:
13
+
14
+ > No code-map snapshot found. Run:
15
+ > `npx code-map index .`
16
+ > Then run this skill again.
17
+
18
+ If `meta.schema_version` is less than 2, the snapshot was built with an older
19
+ version of code-map that did not record exports. Tell the user:
20
+
21
+ > This snapshot was built with an older version of code-map and does not contain
22
+ > export data. Re-index the project to enable unused-export analysis:
23
+ > `npx code-map index .`
24
+
25
+ ## Step 2: Build the used-symbol set
26
+
27
+ Collect every `to` value from the `dependencies` array that is not a `lib:` entry
28
+ and does not end with `:*` (namespace imports). These are all symbols that are
29
+ explicitly imported somewhere in the project.
30
+
31
+ Also collect the set of files that are namespace-imported (files whose path
32
+ appears in a `to` ending with `:*`). Exports from these files cannot be reliably
33
+ checked — they will be skipped.
34
+
35
+ ## Step 3: Find unused exports
36
+
37
+ For each entry in `files[].exports`:
38
+
39
+ - Skip the file entirely if it is in the namespace-imported set.
40
+ - An export `{ name, kind }` from file `F` is **used** if any entry in the
41
+ used-symbol set starts with `F:name[`.
42
+ - Otherwise it is **unused**.
43
+
44
+ ## Step 4: Report
45
+
46
+ 1. **Summary**: "X unused exports found across Y files (Z files skipped due to
47
+ namespace imports)."
48
+ 2. **Grouped by file**: for each file with unused exports, list the symbol name
49
+ and kind.
50
+ 3. **Skipped files**: if any files were skipped due to namespace imports, list
51
+ them and explain why (a `import * as X` elsewhere means all exports of that
52
+ file are potentially reachable).
53
+ 4. Remind the user to verify before deleting — the analysis is static and cannot
54
+ detect dynamic access patterns or consumers outside the indexed project root.
55
+
56
+ If there are zero unused exports, say so and stop.
@@ -0,0 +1,49 @@
1
+ ---
2
+
3
+ name: project-overview
4
+ description: Get a high-level view of the TypeScript project's import graph — file count, dependency edges, entry points, and import cycles. Use when asked about project structure, architecture, or circular dependencies.
5
+
6
+ ---
7
+
8
+ Generate a project-wide dependency overview from a code-map snapshot.
9
+
10
+ ## Step 1: Locate the snapshot
11
+
12
+ Look for `code-map.json` in the project root. If it does not exist, tell the user:
13
+
14
+ > No code-map snapshot found. Run:
15
+ > `npx code-map index .`
16
+ > Then run this skill again.
17
+
18
+ If it is more than a day old (check `meta.indexed_at`), suggest re-indexing before continuing.
19
+
20
+ ## Step 2: Derive the graph
21
+
22
+ From `code-map.json`:
23
+
24
+ - **Files**: the `files` array (`id` field is the path)
25
+ - **Edges**: strip entity detail from `from`/`to` in `dependencies` — take the part before the first `:` or `[`, skip `lib:` entries, deduplicate
26
+ - **Cycles**: the `cycles` array
27
+ - **Entry points**: files whose `id` does not appear in any stripped `to` value
28
+
29
+ ## Step 3: Report
30
+
31
+ **Stats**: total files, total file-level dependency edges, number of cycles.
32
+
33
+ **Entry points**: files that nothing else imports — the roots of the dependency tree. List up to 10; if more, state the count.
34
+
35
+ **Cycles**: if any, this is the most important finding. List every pair:
36
+
37
+ ```
38
+ CYCLE: src/a.ts <-> src/b.ts
39
+ ```
40
+
41
+ Note that circular imports can cause initialization-order bugs at runtime.
42
+
43
+ **Snapshot age**: read `meta.indexed_at` and report how old the snapshot is. If more than a day old, recommend re-indexing:
44
+
45
+ ```bash
46
+ npx code-map index .
47
+ ```
48
+
49
+ Keep the report factual. Do not speculate about architecture beyond what the data shows.