importy 0.0.1
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/.github/workflows/publish.yml +33 -0
- package/LICENSE +21 -0
- package/README.md +1 -0
- package/bin/index.js +86 -0
- package/package.json +23 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
name: Publish to npm (pnpm)
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- "v*" # triggers on tags like v1.0.0
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
publish:
|
|
10
|
+
name: Publish package
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
environment:
|
|
13
|
+
name: releases
|
|
14
|
+
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v3
|
|
17
|
+
|
|
18
|
+
- name: Setup Node.js
|
|
19
|
+
uses: actions/setup-node@v4
|
|
20
|
+
with:
|
|
21
|
+
node-version: "20"
|
|
22
|
+
registry-url: "https://registry.npmjs.org/"
|
|
23
|
+
|
|
24
|
+
- name: Install pnpm
|
|
25
|
+
run: npm install -g pnpm
|
|
26
|
+
|
|
27
|
+
- name: Install dependencies
|
|
28
|
+
run: pnpm install
|
|
29
|
+
|
|
30
|
+
- name: Publish to npm
|
|
31
|
+
run: pnpm publish --no-git-checks
|
|
32
|
+
env:
|
|
33
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Taras Shevchuk
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Importy
|
package/bin/index.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import fs from "fs";
|
|
4
|
+
import path from "path";
|
|
5
|
+
import { program } from "commander";
|
|
6
|
+
import * as parser from "@babel/parser";
|
|
7
|
+
import traverse from "@babel/traverse";
|
|
8
|
+
|
|
9
|
+
program
|
|
10
|
+
.requiredOption("-d, --dir <directory>", "Directory to scan")
|
|
11
|
+
.requiredOption("-l, --lib <library>", "Library name to match")
|
|
12
|
+
.parse(process.argv);
|
|
13
|
+
|
|
14
|
+
const { dir, lib } = program.opts();
|
|
15
|
+
|
|
16
|
+
function isJavaScriptFile(file) {
|
|
17
|
+
return /\.(js|ts|jsx|tsx)$/.test(file);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function getAllFiles(dirPath, arrayOfFiles = []) {
|
|
21
|
+
const files = fs.readdirSync(dirPath);
|
|
22
|
+
for (const file of files) {
|
|
23
|
+
const fullPath = path.join(dirPath, file);
|
|
24
|
+
if (fs.statSync(fullPath).isDirectory()) {
|
|
25
|
+
getAllFiles(fullPath, arrayOfFiles);
|
|
26
|
+
} else if (isJavaScriptFile(fullPath)) {
|
|
27
|
+
arrayOfFiles.push(fullPath);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return arrayOfFiles;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function extractImportsFromFile(filePath, targetLib) {
|
|
34
|
+
const code = fs.readFileSync(filePath, "utf8");
|
|
35
|
+
let ast;
|
|
36
|
+
try {
|
|
37
|
+
ast = parser.parse(code, {
|
|
38
|
+
sourceType: "module",
|
|
39
|
+
plugins: ["typescript", "jsx"],
|
|
40
|
+
});
|
|
41
|
+
} catch (err) {
|
|
42
|
+
console.warn(`Skipping ${filePath}: Parse error`);
|
|
43
|
+
return [];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const matches = [];
|
|
47
|
+
|
|
48
|
+
traverse(ast, {
|
|
49
|
+
ImportDeclaration({ node }) {
|
|
50
|
+
if (node.source.value === targetLib) {
|
|
51
|
+
for (const specifier of node.specifiers) {
|
|
52
|
+
let importedName = specifier.imported?.name || "default";
|
|
53
|
+
let localName = specifier.local.name;
|
|
54
|
+
|
|
55
|
+
matches.push({
|
|
56
|
+
importedName,
|
|
57
|
+
localName,
|
|
58
|
+
file: filePath,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
return matches;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const files = getAllFiles(dir);
|
|
69
|
+
const componentMap = {};
|
|
70
|
+
|
|
71
|
+
for (const file of files) {
|
|
72
|
+
const imports = extractImportsFromFile(file, lib);
|
|
73
|
+
for (const { importedName, file: filePath } of imports) {
|
|
74
|
+
if (!componentMap[importedName]) {
|
|
75
|
+
componentMap[importedName] = new Set();
|
|
76
|
+
}
|
|
77
|
+
componentMap[importedName].add(filePath);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Convert Set to array for output
|
|
82
|
+
const output = Object.fromEntries(
|
|
83
|
+
Object.entries(componentMap).map(([name, paths]) => [name, [...paths]]),
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
console.log(JSON.stringify(output, null, 2));
|
package/package.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "importy",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"inspect-imports": "./bin/index.js"
|
|
8
|
+
},
|
|
9
|
+
"keywords": [],
|
|
10
|
+
"author": "Taras Shevchuk",
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"registry": "https://registry.npmjs.org/"
|
|
14
|
+
},
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"@types/node": "^22.15.29"
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@babel/parser": "^7.27.5",
|
|
20
|
+
"@babel/traverse": "^7.27.4",
|
|
21
|
+
"commander": "^14.0.0"
|
|
22
|
+
}
|
|
23
|
+
}
|