Skip to content

Commit 6cfb36a

Browse files
committed
feat: inline project metadata into scanning output
1 parent 8b7d148 commit 6cfb36a

File tree

3 files changed

+17
-292
lines changed

3 files changed

+17
-292
lines changed

esonar/src/constants.ts

Lines changed: 0 additions & 282 deletions
This file was deleted.

esonar/src/index.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
import { parse } from "@esonar/core";
2-
3-
import { EXAMPLE_SOLID } from "./constants";
1+
import { parse, scan } from "@esonar/core";
42

53
const main = async () => {
64
// @todo: make output file configurable
7-
const output = await parse(EXAMPLE_SOLID, {
5+
await parse("console.log('hello')", {
86
root: process.cwd(),
97
file: "./test.tsx",
108
pkg: {
@@ -17,9 +15,7 @@ const main = async () => {
1715
},
1816
});
1917

20-
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
21-
output;
22-
// console.log(JSON.stringify(output, null, 2));
18+
console.log(scan());
2319
};
2420

2521
main().catch((error) => {

packages/core/src/scanner/index.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import { fdir } from "fdir";
22
import { dirname } from "node:path";
3+
import { createRequire } from "node:module";
34

45
import { CWD } from "../constants";
56

7+
const require = createRequire(import.meta.url);
8+
69
export type ScannerOptions = {
710
/**
811
* A list of folders to ignore
@@ -29,7 +32,17 @@ export const scan = (options: ScannerOptions = {}) => {
2932
.crawl(CWD)
3033
.sync()
3134
.map((path) => {
32-
return { metadata: path, folder: dirname(path) };
35+
const metadata = require(path) as {
36+
name: string;
37+
version: string;
38+
description: string;
39+
dependencies?: Record<string, string>;
40+
devDependencies?: Record<string, string>;
41+
peerDependencies?: Record<string, string>;
42+
optionalDependencies?: Record<string, string>;
43+
};
44+
45+
return { metadata, folder: dirname(path) };
3346
});
3447

3548
return projects.map((project) => {
@@ -49,5 +62,3 @@ const DEFAULT_EXCLUDED_FOLDERS = [".git", "node_modules", "dist", "out"];
4962
const DEFAULT_INCLUDED_FILES = [
5063
"**/*/!(test|*.test|stories|*.stories).?(m){j,t}s?(x)", // js|jsx|ts|tsx|cjs|mjs|cjsx|mjsx excluding test-like and story-like files
5164
];
52-
53-
console.log(scan());

0 commit comments

Comments
 (0)