bump fs-extra types

Summary: `recursive` was dropped in when [dropping](https://github.com/jprichardson/node-fs-extra/issues/886) node v10

Reviewed By: aigoncharov

Differential Revision: D48780242

fbshipit-source-id: 29349590a7f14da85fe8df28b20d9b418e7a8b1d
This commit is contained in:
Anton Kastritskiy
2023-09-05 07:17:06 -07:00
committed by Facebook GitHub Bot
parent d04abff530
commit f2ef26cd9a
13 changed files with 132 additions and 83 deletions

View File

@@ -29,7 +29,7 @@
},
"devDependencies": {
"@oclif/dev-cli": "^1",
"@types/fs-extra": "^9.0.13",
"@types/fs-extra": "^11.0.0",
"@types/inquirer": "^7.3.3",
"@types/node": "^17.0.31",
"@types/recursive-readdir": "^2.2.1",

View File

@@ -30,21 +30,28 @@ const validPackageJson = {
},
};
beforeEach(() => {
jest.mock('fs-extra', () => jest.fn());
fs.pathExists = jest.fn().mockResolvedValue(true);
fs.pathExistsSync = jest.fn().mockReturnValue(true);
// Required by some inconsistent node types for rw access.
(fs.lstatSync as any) = jest.fn().mockReturnValue({
isFile: function () {
return true;
},
});
jest.mock('fs-extra', () => {
const mod = {
...jest.requireActual('fs-extra'),
readFile: jest.fn(),
pathExists: jest.fn().mockResolvedValue(true),
pathExistsSync: jest.fn().mockResolvedValue(true),
lstatSync: jest.fn().mockReturnValue({
isFile: function () {
return true;
},
}),
};
return {
...mod,
default: mod,
};
});
test('valid package json', async () => {
const json = JSON.stringify(validPackageJson);
fs.readFile = jest.fn().mockResolvedValue(new Buffer(json));
(fs.readFile as any as jest.Mock).mockReturnValueOnce(new Buffer(json));
const result = await runLint('dir');
expect(result).toBe(null);
});
@@ -53,7 +60,7 @@ test('valid scoped package json', async () => {
const testPackageJson = Object.assign({}, validPackageJson);
testPackageJson.name = '@test/flipper-plugin-package';
const json = JSON.stringify(testPackageJson);
fs.readFile = jest.fn().mockResolvedValue(new Buffer(json));
(fs.readFile as any as jest.Mock).mockReturnValueOnce(new Buffer(json));
const result = await runLint('dir');
expect(result).toBe(null);
});
@@ -63,7 +70,7 @@ test('$schema field is required', async () => {
// @ts-ignore cannot delete non-optional fields
delete testPackageJson.$schema;
const json = JSON.stringify(testPackageJson);
fs.readFile = jest.fn().mockResolvedValue(new Buffer(json));
(fs.readFile as any as jest.Mock).mockReturnValueOnce(new Buffer(json));
const result = await runLint('dir');
expect(result).toMatchInlineSnapshot(`
[
@@ -82,7 +89,7 @@ test('supported schema is required', async () => {
testPackageJson.$schema =
'https://fbflipper.com/schemas/plugin-package/v1.json';
const json = JSON.stringify(testPackageJson);
fs.readFile = jest.fn().mockResolvedValue(new Buffer(json));
(fs.readFile as any as jest.Mock).mockReturnValueOnce(new Buffer(json));
const result = await runLint('dir');
expect(result).toMatchInlineSnapshot(`
[
@@ -97,7 +104,7 @@ test('name is required', async () => {
// @ts-ignore cannot delete non-optional fields
delete testPackageJson.name;
const json = JSON.stringify(testPackageJson);
fs.readFile = jest.fn().mockResolvedValue(new Buffer(json));
(fs.readFile as any as jest.Mock).mockReturnValueOnce(new Buffer(json));
const result = await runLint('dir');
expect(result).toMatchInlineSnapshot(`
[
@@ -110,7 +117,7 @@ test('name must start with "flipper-plugin-"', async () => {
const testPackageJson = Object.assign({}, validPackageJson);
testPackageJson.name = 'test-plugin';
const json = JSON.stringify(testPackageJson);
fs.readFile = jest.fn().mockResolvedValue(new Buffer(json));
(fs.readFile as any as jest.Mock).mockReturnValueOnce(new Buffer(json));
const result = await runLint('dir');
expect(result).toMatchInlineSnapshot(`
[
@@ -123,7 +130,7 @@ test('keywords must contain "flipper-plugin"', async () => {
const testPackageJson = Object.assign({}, validPackageJson);
testPackageJson.keywords = ['flipper', 'network'];
const json = JSON.stringify(testPackageJson);
fs.readFile = jest.fn().mockResolvedValue(new Buffer(json));
(fs.readFile as any as jest.Mock).mockReturnValueOnce(new Buffer(json));
const result = await runLint('dir');
expect(result).toMatchInlineSnapshot(`
[
@@ -135,13 +142,11 @@ test('keywords must contain "flipper-plugin"', async () => {
test('flippeBundlerEntry must point to an existing file', async () => {
const testPackageJson = Object.assign({}, validPackageJson);
testPackageJson.flipperBundlerEntry = 'unexisting/file';
fs.pathExistsSync = jest
.fn()
.mockImplementation(
(filePath) => !filePath.includes(path.join('unexisting', 'file')),
);
(fs.pathExistsSync as any as jest.Mock).mockImplementation(
(filePath) => !filePath.includes(path.join('unexisting', 'file')),
);
const json = JSON.stringify(testPackageJson);
fs.readFile = jest.fn().mockResolvedValue(new Buffer(json));
(fs.readFile as any as jest.Mock).mockReturnValueOnce(new Buffer(json));
const result = await runLint('dir');
expect(result).toMatchInlineSnapshot(`
[
@@ -156,7 +161,7 @@ test('multiple validation errors reported', async () => {
// @ts-ignore cannot delete non-optional fields
delete testPackageJson.flipperBundlerEntry;
const json = JSON.stringify(testPackageJson);
fs.readFile = jest.fn().mockResolvedValue(new Buffer(json));
(fs.readFile as any as jest.Mock).mockReturnValueOnce(new Buffer(json));
const result = await runLint('dir');
expect(result).toMatchInlineSnapshot(`
[

View File

@@ -10,25 +10,6 @@
import runMigrate from '../utils/runMigrate';
import fs from 'fs-extra';
const packageJsonV1 = {
name: 'Fresco',
version: '1.0.0',
main: 'index.tsx',
license: 'MIT',
keywords: ['images'],
dependencies: {
flipper: 'latest',
},
scripts: {
prepack: 'yarn reset && yarn build',
},
title: 'Images',
icon: 'profile',
bugs: {
email: 'example@test.com',
},
};
const packageJsonV2 = {
$schema: 'https://fbflipper.com/schemas/plugin-package/v2.json',
name: 'flipper-plugin-network',
@@ -53,18 +34,52 @@ const packageJsonV2 = {
let convertedPackageJsonString: string | undefined;
jest.mock('fs-extra', () => {
const packageJsonV1 = {
name: 'Fresco',
version: '1.0.0',
main: 'index.tsx',
license: 'MIT',
keywords: ['images'],
dependencies: {
flipper: 'latest',
},
scripts: {
prepack: 'yarn reset && yarn build',
},
title: 'Images',
icon: 'profile',
bugs: {
email: 'example@test.com',
},
};
const mod = {
...jest.requireActual('fs-extra'),
readFile: jest
.fn()
.mockResolvedValue(new Buffer(JSON.stringify(packageJsonV1))),
pathExists: jest.fn().mockResolvedValue(true),
pathExistsSync: jest.fn().mockResolvedValue(true),
readJson: jest.fn().mockResolvedValue(packageJsonV1),
writeFile: jest.fn(async (_path, content) => {
convertedPackageJsonString = content;
}),
lstatSync: jest.fn().mockReturnValue({
isFile: function () {
return true;
},
}),
};
return {
...mod,
default: mod,
};
});
beforeEach(() => {
jest.mock('fs-extra', () => jest.fn());
fs.pathExists = jest.fn().mockResolvedValue(true);
fs.pathExistsSync = jest.fn().mockReturnValue(true);
fs.readJson = jest.fn().mockResolvedValue(packageJsonV1);
fs.readFile = jest
.fn()
.mockResolvedValue(new Buffer(JSON.stringify(packageJsonV1)));
convertedPackageJsonString = undefined;
fs.writeFile = jest.fn().mockImplementation(async (_path, content) => {
convertedPackageJsonString = content;
});
});
test('converts package.json and adds dependencies', async () => {
@@ -134,10 +149,9 @@ test('converts package.json without changing dependencies', async () => {
});
test('does not migrate already migrated packages', async () => {
fs.readJson = jest.fn().mockResolvedValue(packageJsonV2);
fs.readFile = jest
.fn()
.mockResolvedValue(new Buffer(JSON.stringify(packageJsonV2)));
(fs.readFile as any as jest.Mock).mockResolvedValue(
new Buffer(JSON.stringify(packageJsonV2)),
);
const error = await runMigrate('dir');
expect(error).toBeUndefined();
expect(convertedPackageJsonString).toBeUndefined();