Skip to content

Commit be2a154

Browse files
committed
feat: simplify interfaces
1 parent eab563c commit be2a154

File tree

21 files changed

+67
-198
lines changed

21 files changed

+67
-198
lines changed

.changeset/silver-phones-tap.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
"@sdk-usage/cli": minor
3+
"@sdk-usage/core": minor
4+
"@sdk-usage/plugin-jsx": minor
5+
"@sdk-usage/plugin-typescript": minor
6+
---
7+
8+
This release refines and simplifies the interfaces (considered as breaking changes but listed as minor prior to the stable major release).
9+
The following modifications have been introduced:
10+
11+
- `@sdk-usage/core`: `createContext` has been renamed to `createInstance`.
12+
- `@sdk-usage/core`: `createSyntaxPlugin` has been renamed to `createPlugin`.
13+
- `@sdk-usage/core`: `plugins` accepts now directly an array of plugins.
14+
- `@sdk-usage/plugin-jsx`: `@sdk-usage/plugin-syntax-jsx` is deprecated (will be removed soon from the registry) and renamed to `@sdk-usage/plugin-jsx`.
15+
- `@sdk-usage/plugin-typescript`: `@sdk-usage/plugin-syntax-typescript` is deprecated (will be removed soon from the registry) and renamed to `@sdk-usage/plugin-typescript`.

.changeset/welcome.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
22
"@sdk-usage/cli": minor
33
"@sdk-usage/core": minor
4-
"@sdk-usage/plugin-syntax-jsx": minor
5-
"@sdk-usage/plugin-syntax-typescript": minor
4+
"@sdk-usage/plugin-jsx": minor
5+
"@sdk-usage/plugin-typescript": minor
66
---
77

88
v0.1.0 release 🚀

applications/cli/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
},
3636
"dependencies": {
3737
"@sdk-usage/core": "workspace:^",
38-
"@sdk-usage/plugin-syntax-jsx": "workspace:^",
39-
"@sdk-usage/plugin-syntax-typescript": "workspace:^"
38+
"@sdk-usage/plugin-jsx": "workspace:^",
39+
"@sdk-usage/plugin-typescript": "workspace:^"
4040
},
4141
"devDependencies": {
4242
"@types/node": "22.10.6",

applications/cli/src/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import process from "node:process";
22

3-
import typescriptSyntaxPlugin from "@sdk-usage/plugin-syntax-typescript";
4-
import jsxSyntaxPlugin from "@sdk-usage/plugin-syntax-jsx";
5-
import { createContext } from "@sdk-usage/core";
3+
import typescriptSyntaxPlugin from "@sdk-usage/plugin-typescript";
4+
import jsxSyntaxPlugin from "@sdk-usage/plugin-jsx";
5+
import { createInstance } from "@sdk-usage/core";
66

7-
const context = createContext(process.cwd(), {
8-
plugins: { syntax: [jsxSyntaxPlugin, typescriptSyntaxPlugin] },
7+
const instance = createInstance(process.cwd(), {
8+
plugins: [jsxSyntaxPlugin, typescriptSyntaxPlugin],
99
});
1010

1111
const main = async () => {
12-
const items = await context.getItems();
12+
const items = await instance.getItems();
1313

1414
console.log(JSON.stringify(items, null, 2), items.length);
1515
};

libraries/core/src/createContext.ts renamed to libraries/core/src/createInstance.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { readFileSync } from "node:fs";
33
import type { Package } from "./types";
44
import { scan } from "./modules/scanner";
55
import type { ScanOptions } from "./modules/scanner";
6+
import type { Plugin } from "./modules/plugin";
67
import { parse } from "./modules/parser";
7-
import type { ParseOptions } from "./modules/parser";
88
import { require, resolvePackageJson } from "./helpers";
99
import { createItem } from "./entities/item";
1010
import type { Item } from "./entities/item";
@@ -15,16 +15,19 @@ type Options = Partial<
1515
* Only analyze components imported from the specificied module list.
1616
*/
1717
includeModules: string[];
18+
/**
19+
* A list of plugins to enable.
20+
*/
21+
plugins: Plugin[];
1822
/**
1923
* Attempt to resolve installed versions of modules. If false or not possible, the specified version from the package.json will be used.
2024
* @default false
2125
*/
2226
resolveInstalledVersions: boolean;
2327
}
24-
> &
25-
Pick<ParseOptions, "plugins">;
28+
>;
2629

27-
export const createContext = (path: string, options: Options) => {
30+
export const createInstance = (path: string, options: Options) => {
2831
return {
2932
async getItems() {
3033
const projects = await scan(path);
@@ -87,7 +90,7 @@ export const createContext = (path: string, options: Options) => {
8790
}),
8891
);
8992
},
90-
plugins: options.plugins,
93+
plugins: options.plugins ?? [],
9194
});
9295
}
9396
}

libraries/core/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export { createContext } from "./createContext";
2-
export { createSyntaxPlugin } from "./modules/plugin";
1+
export { createInstance } from "./createInstance";
2+
export { createPlugin } from "./modules/plugin";

libraries/core/src/modules/parser/parse.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,13 @@ import { parse as swcParse } from "@swc/core";
22
import type { Module } from "@swc/core";
33
import { visit } from "@open-vanilla/visitor";
44

5-
import type { Plugins } from "../plugin";
5+
import type { Plugin } from "../plugin";
66
import type { Import, Nodes, Primitive } from "../../types";
77
import type { ItemDTO } from "../../entities/item";
88

99
export type ParseOptions = {
1010
onAdd: (item: ItemDTO) => void;
11-
/**
12-
* A list of plugins to enable.
13-
*/
14-
plugins: Plugins;
11+
plugins: Plugin[];
1512
};
1613

1714
export const parse = async (code: string, { onAdd, plugins }: ParseOptions) => {
@@ -54,7 +51,7 @@ export const parse = async (code: string, { onAdd, plugins }: ParseOptions) => {
5451
},
5552
};
5653

57-
for (const plugin of plugins.syntax) {
54+
for (const plugin of plugins) {
5855
const pluginOutput = plugin(context, {
5956
getJSXAttributeValue,
6057
});

libraries/core/src/modules/plugin/createSyntaxPlugin.ts renamed to libraries/core/src/modules/plugin/createPlugin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import type { Import, Nodes, Primitive } from "../../types";
22
import type { ItemDTO } from "../../entities/item";
33

4-
export const createSyntaxPlugin = (input: SyntaxPlugin) => {
4+
export const createPlugin = (input: Plugin) => {
55
return input;
66
};
77

8-
export type SyntaxPlugin = (
8+
export type Plugin = (
99
context: {
1010
// TODO: do not expose setters (read-only context for getter purposes)
1111
imports: Map<Import["alias"], Import>;
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export type { Plugins } from "./types";
2-
export { createSyntaxPlugin } from "./createSyntaxPlugin";
1+
export type { Plugin } from "./createPlugin";
2+
export { createPlugin } from "./createPlugin";

libraries/core/src/modules/plugin/types.ts

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

0 commit comments

Comments
 (0)