Skip to content

Commit 8993b44

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

File tree

3 files changed

+17
-296
lines changed

3 files changed

+17
-296
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 & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
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
9-
*
10-
* @default [".git", "node_modules", "dist", "out"]
1112
*/
1213
excludeFolders?: string[];
1314
/**
1415
* A list of files to include (following glob matcher)
15-
*
16-
* @default **\/*\/!(test|stories|*.test|*.stories).?(m){j,t}s?(x)
1716
*/
1817
includeFiles?: string[];
1918
};
@@ -29,7 +28,17 @@ export const scan = (options: ScannerOptions = {}) => {
2928
.crawl(CWD)
3029
.sync()
3130
.map((path) => {
32-
return { metadata: path, folder: dirname(path) };
31+
const metadata = require(path) as {
32+
name: string;
33+
version: string;
34+
description: string;
35+
dependencies?: Record<string, string>;
36+
devDependencies?: Record<string, string>;
37+
peerDependencies?: Record<string, string>;
38+
optionalDependencies?: Record<string, string>;
39+
};
40+
41+
return { metadata, folder: dirname(path) };
3342
});
3443

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

0 commit comments

Comments
 (0)