-
-
Notifications
You must be signed in to change notification settings - Fork 9.9k
Core: Replace fs-extra with the native APIs
#29126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 30 commits
247efff
2ac99b3
ce73ddb
5ed3ab4
2e89262
b080e71
b9c600a
67dbe11
cf80eaa
ef33853
353dfb1
08c6eef
a09abbc
93b866b
7c14a13
7816541
fb2455b
2dcc7b7
ca39982
a42ff7e
174868a
643acbf
89cdff3
0d10b95
f5b1525
8346b85
f0593f9
ea609bf
b034203
8ac3e53
8115974
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import { vi } from 'vitest'; | ||
|
|
||
| // This is a custom function that our tests can use during setup to specify | ||
| // what the files on the "mock" filesystem should look like when any of the | ||
| // `fs` APIs are used. | ||
| let mockFiles = Object.create(null); | ||
|
|
||
| // eslint-disable-next-line no-underscore-dangle, @typescript-eslint/naming-convention | ||
| export function __setMockFiles(newMockFiles: Record<string, string | null>) { | ||
| mockFiles = newMockFiles; | ||
| } | ||
|
|
||
| export const readFileSync = (filePath = '') => mockFiles[filePath]; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic: Default parameter value '' might cause unexpected behavior if undefined is passed |
||
| export const existsSync = (filePath: string) => !!mockFiles[filePath]; | ||
| export const lstatSync = (filePath: string) => ({ | ||
| isFile: () => !!mockFiles[filePath], | ||
| }); | ||
| export const realpathSync = vi.fn(); | ||
| export const readdir = vi.fn(); | ||
| export const readdirSync = vi.fn(); | ||
| export const readlinkSync = vi.fn(); | ||
|
|
||
| export default { | ||
| __setMockFiles, | ||
| readFileSync, | ||
| existsSync, | ||
| lstatSync, | ||
| realpathSync, | ||
| readdir, | ||
| readdirSync, | ||
| readlinkSync, | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import { vi } from 'vitest'; | ||
|
|
||
| // This is a custom function that our tests can use during setup to specify | ||
| // what the files on the "mock" filesystem should look like when any of the | ||
| // `fs` APIs are used. | ||
| let mockFiles = Object.create(null); | ||
JReinhold marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // eslint-disable-next-line no-underscore-dangle, @typescript-eslint/naming-convention | ||
| export function __setMockFiles(newMockFiles: Record<string, string | null>) { | ||
| mockFiles = newMockFiles; | ||
| } | ||
|
|
||
| export const writeFile = vi.fn(async (filePath: string, content: string) => { | ||
| mockFiles[filePath] = content; | ||
| }); | ||
| export const readFile = vi.fn(async (filePath: string) => mockFiles[filePath]); | ||
pralkarz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| export const lstat = vi.fn(async (filePath: string) => ({ | ||
| isFile: () => !!mockFiles[filePath], | ||
| })); | ||
| export const readdir = vi.fn(); | ||
| export const readlink = vi.fn(); | ||
| export const realpath = vi.fn(); | ||
|
|
||
| export default { | ||
| __setMockFiles, | ||
| writeFile, | ||
| readFile, | ||
| lstat, | ||
| readdir, | ||
| readlink, | ||
| realpath, | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,6 @@ | ||
| import { readFile } from 'node:fs/promises'; | ||
| import { join } from 'node:path'; | ||
|
|
||
| import { readJson } from 'fs-extra'; | ||
|
|
||
| export async function flattenDependencies( | ||
| list: string[], | ||
| output: string[] = [], | ||
|
|
@@ -18,7 +17,9 @@ export async function flattenDependencies( | |
| console.log(dep + ' not found'); | ||
| return; | ||
| } | ||
| const { dependencies = {}, peerDependencies = {} } = await readJson(path); | ||
| const { dependencies = {}, peerDependencies = {} } = JSON.parse( | ||
| await readFile(path, { encoding: 'utf8' }) | ||
| ); | ||
|
Comment on lines
+20
to
+22
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: Consider wrapping JSON.parse in a try-catch block to handle potential JSON parsing errors |
||
| const all: string[] = [ | ||
| ...new Set([...Object.keys(dependencies), ...Object.keys(peerDependencies)]), | ||
| ] | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.