Skip to content

Commit e6e3f43

Browse files
authored
chore: reduce dependency count (#522)
* chore: reduce dependency count * fixup!
1 parent 5a53779 commit e6e3f43

File tree

7 files changed

+238
-241
lines changed

7 files changed

+238
-241
lines changed

npm-shrinkwrap.json

Lines changed: 210 additions & 194 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"eslint-import-resolver-node": "^0.3.9",
3434
"eslint-plugin-import-x": "^4.16.1",
3535
"eslint-plugin-jsdoc": "^61.4.1",
36+
"eslint-plugin-react-x": "^2.3.13",
3637
"husky": "^9.1.7",
3738
"lint-staged": "^16.2.7",
3839
"prettier": "3.7.4"
@@ -50,11 +51,9 @@
5051
"acorn": "^8.15.0",
5152
"commander": "^14.0.2",
5253
"dedent": "^1.7.0",
53-
"eslint-plugin-react-x": "^2.3.12",
5454
"estree-util-to-js": "^2.0.0",
5555
"estree-util-visit": "^2.0.0",
5656
"github-slugger": "^2.0.0",
57-
"glob": "^13.0.0",
5857
"globals": "^16.5.0",
5958
"hast-util-to-string": "^3.0.1",
6059
"hastscript": "^9.0.1",
@@ -75,7 +74,7 @@
7574
"rolldown": "^1.0.0-beta.53",
7675
"semver": "^7.7.3",
7776
"shiki": "^3.19.0",
78-
"to-vfile": "^8.0.0",
77+
"tinyglobby": "^0.2.15",
7978
"unified": "^11.0.5",
8079
"unist-builder": "^4.0.0",
8180
"unist-util-find-after": "^5.0.0",

src/generators/ast-js/index.mjs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1+
import { readFile } from 'node:fs/promises';
12
import { extname } from 'node:path';
23

3-
import { globSync } from 'glob';
4-
import { read } from 'to-vfile';
5-
6-
import { parseJsSource } from '../../parsers/javascript.mjs';
4+
import { parse } from 'acorn';
5+
import { globSync } from 'tinyglobby';
76

87
/**
98
* This generator parses Javascript sources passed into the generator's input
@@ -39,11 +38,17 @@ export default {
3938
const results = [];
4039

4140
for (const path of filePaths) {
42-
const vfile = await read(path, 'utf-8');
41+
const value = await readFile(path, 'utf-8');
42+
43+
const parsed = parse(value, {
44+
allowReturnOutsideFunction: true,
45+
ecmaVersion: 'latest',
46+
locations: true,
47+
});
4348

44-
const parsedJS = await parseJsSource(vfile);
49+
parsed.path = path;
4550

46-
results.push(parsedJS);
51+
results.push(parsed);
4752
}
4853

4954
return results;

src/generators/ast/index.mjs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
'use strict';
22

3+
import { readFile } from 'node:fs/promises';
34
import { extname } from 'node:path';
45

5-
import { globSync } from 'glob';
6-
import { read } from 'to-vfile';
6+
import { globSync } from 'tinyglobby';
7+
import { VFile } from 'vfile';
78

89
import createQueries from '../../utils/queries/index.mjs';
910
import { getRemark } from '../../utils/remark.mjs';
@@ -41,7 +42,7 @@ export default {
4142
const results = [];
4243

4344
for (const path of filePaths) {
44-
const vfile = await read(path, 'utf-8');
45+
const vfile = new VFile({ path, value: await readFile(path, 'utf-8') });
4546

4647
updateStabilityPrefixToLink(vfile);
4748

src/generators/jsx-ast/utils/transformer.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ const transformer = tree => {
2929
const thead = node.children.find(el => el.tagName === 'thead');
3030

3131
if (thead) {
32+
// TODO(@avivkeller): These are only strings afaict, so a `toString` dependency
33+
// might not actually be needed.
3234
const headers = thead.children[0].children.map(toString);
3335
const tbody = node.children.find(el => el.tagName === 'tbody');
3436

src/parsers/javascript.mjs

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

src/utils/highlighter.mjs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict';
22

33
import createHighlighter from '@node-core/rehype-shiki';
4-
import { toString } from 'hast-util-to-string';
54
import { h as createElement } from 'hastscript';
65
import { SKIP, visit } from 'unist-util-visit';
76

@@ -84,18 +83,18 @@ export default function rehypeShikiji() {
8483
return;
8584
}
8685

87-
// Retrieve the whole <pre> contents as a parsed DOM string
88-
const preElementContents = toString(preElement);
89-
9086
// Grabs the relevant alias/name of the language
9187
const languageId = codeLanguage.slice(languagePrefix.length);
9288

9389
// Parses the <pre> contents and returns a HAST tree with the highlighted code
94-
const { children } = highlighter.shiki.codeToHast(preElementContents, {
95-
lang: languageId,
96-
// Allows support for dual themes (light, dark) for Shiki
97-
themes: { light: shikiConfig.themes[0], dark: shikiConfig.themes[1] },
98-
});
90+
const { children } = highlighter.shiki.codeToHast(
91+
preElement.children[0].value,
92+
{
93+
lang: languageId,
94+
// Allows support for dual themes (light, dark) for Shiki
95+
themes: { light: shikiConfig.themes[0], dark: shikiConfig.themes[1] },
96+
}
97+
);
9998

10099
// Adds the original language back to the <pre> element
101100
children[0].properties.class = `${children[0].properties.class} ${codeLanguage}`;

0 commit comments

Comments
 (0)