Skip to content

Commit f7c14ed

Browse files
committed
refactor: replace globby with fs.glob
1 parent 7cd61b1 commit f7c14ed

6 files changed

+11
-16
lines changed

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@
7575
"eslint-plugin-prettier": "^5.2.1",
7676
"eslint-plugin-react": "^7.28.0",
7777
"execa": "^5.0.0",
78-
"globby": "^11.0.3",
7978
"gray-matter": "^4.0.3",
8079
"gunzip-maybe": "^1.4.2",
8180
"hast-util-from-html": "^2.0.1",

scripts/tasks/add-frontmatter.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import fs from 'node:fs/promises';
22
import path from 'node:path';
33

4-
import globby from 'globby';
5-
64
/*
75
To make `/docs/latest` have content we need to set the
86
slug of a particular page to `/latest/`. `START_PAGE` is how we
@@ -16,10 +14,10 @@ const START_PAGE = 'tutorial/introduction.md';
1614
* @returns A Map of file paths and their corresponding file contents
1715
*/
1816
const getMarkdownFiles = async (startPath: string) => {
19-
const filesPaths = await globby(path.posix.join(startPath, '**/*.md'));
17+
const filesPaths = fs.glob(path.posix.join(startPath, '**/*.md'));
2018

2119
const files = new Map();
22-
for (const filePath of filesPaths) {
20+
for await (const filePath of filesPaths) {
2321
const content = await fs.readFile(filePath, 'utf-8');
2422
files.set(filePath, content);
2523
}

scripts/tasks/download-docs.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import stream from 'node:stream';
44
import type { ReadableStream } from 'node:stream/web';
55

66
import tar from 'tar-stream';
7-
import globby from 'globby';
87

98
interface DownloadOptions {
109
/** The GitHub organization to download the contents from */
@@ -144,13 +143,13 @@ export const copy = async ({
144143
destination,
145144
copyMatch = '.',
146145
}: CopyOptions) => {
147-
const filesPaths = await globby(`${copyMatch}/**/*`, {
146+
const filesPaths = fs.glob(`${copyMatch}/**/*`, {
148147
cwd: target,
149148
});
150149

151150
const contents = [];
152151

153-
for (const filePath of filesPaths) {
152+
for await (const filePath of filesPaths) {
154153
const content = {
155154
filename: filePath.replace(`${copyMatch}/`, ''),
156155
content: await fs.readFile(path.join(target, filePath)),

scripts/tasks/md-fixers.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import fs from 'node:fs/promises';
22
import path from 'node:path';
33

4-
import globby from 'globby';
5-
64
const fiddlePathFixRegex = /```fiddle docs\//;
75

86
const fiddleTransformer = (line: string) => {
@@ -122,11 +120,11 @@ const fixReturnLines = (content: string) => {
122120
* @param version
123121
*/
124122
export const fixContent = async (root: string, version = 'latest') => {
125-
const files = await globby(`${version}/**/*.md`, {
123+
const files = fs.glob(`${version}/**/*.md`, {
126124
cwd: root,
127125
});
128126

129-
for (const filePath of files) {
127+
for await (const filePath of files) {
130128
const fullFilePath = path.join(root, filePath);
131129
const content = await fs.readFile(fullFilePath, 'utf-8');
132130

scripts/tasks/preprocess-api-history.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
import fs from 'node:fs/promises';
2+
13
import logger from '@docusaurus/logger';
24
import Ajv, { JSONSchemaType, ValidateFunction } from 'ajv';
35
import { readFile, writeFile } from 'fs/promises';
46
import { fromHtml } from 'hast-util-from-html';
5-
import globby from 'globby';
67
import type { Html, Root } from 'mdast';
78
import { fromMarkdown } from 'mdast-util-from-markdown';
89
import path from 'path';
@@ -32,10 +33,10 @@ let hasWarned = false;
3233

3334
// Copied from here: <https://github.com/electron/website/blob/feat/api-history/scripts/tasks/add-frontmatter.ts#L16-L23>
3435
const getMarkdownFiles = async (startPath: string) => {
35-
const filesPaths = await globby(path.posix.join(startPath, 'api', '/*.md'));
36+
const filesPaths = fs.glob(path.posix.join(startPath, 'api', '/*.md'));
3637

3738
const files: Map<string, string> = new Map();
38-
for (const filePath of filesPaths) {
39+
for await (const filePath of filesPaths) {
3940
const content = await readFile(filePath, 'utf-8');
4041
files.set(filePath, content);
4142
}

yarn.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -8380,7 +8380,7 @@ [email protected]:
83808380
slash "^5.1.0"
83818381
unicorn-magic "^0.1.0"
83828382

8383-
globby@^11.0.1, globby@^11.0.3, globby@^11.0.4, globby@^11.1.0:
8383+
globby@^11.0.1, globby@^11.0.4, globby@^11.1.0:
83848384
version "11.1.0"
83858385
resolved "https://registry.yarnpkg.com/globby/-/globby-11.1.0.tgz#bd4be98bb042f83d796f7e3811991fbe82a0d34b"
83868386
integrity sha512-jhIXaOzy1sb8IyocaruWSn1TjmnBVs8Ayhcy83rmxNJ8q2uWKCAj3CnJY+KpGSXCueAPc0i05kVvVKtP1t9S3g==

0 commit comments

Comments
 (0)