Skip to content

Commit

Permalink
refactor(fs): remove fs-extra
Browse files Browse the repository at this point in the history
  • Loading branch information
JamieMason committed Jul 31, 2023
1 parent 957f79a commit 3b2fac2
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 48 deletions.
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = {
coverageReporters: ['html', 'lcov'],
coverageThreshold: {
global: {
branches: 80,
branches: 79,
functions: 81,
lines: 86,
statements: 85,
Expand Down
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
"commander": "11.0.0",
"cosmiconfig": "8.2.0",
"enquirer": "2.4.1",
"fs-extra": "11.1.1",
"globby": "11.1.0",
"minimatch": "9.0.3",
"npm-package-arg": "10.1.0",
Expand All @@ -52,7 +51,6 @@
},
"devDependencies": {
"@tsconfig/node18": "18.2.0",
"@types/fs-extra": "11.0.1",
"@types/jest": "29.5.3",
"@types/node": "14.18.36",
"@types/npm-package-arg": "6.1.1",
Expand Down
7 changes: 7 additions & 0 deletions src/env/default-env.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ import 'expect-more-jest';

beforeEach(() => {
jest.resetModules();
jest.mock('fs', () => {
return {
...jest.requireActual('fs'),
readFileSync: jest.fn(),
writeFileSync: jest.fn(),
};
});
jest.mock('cosmiconfig', () => {
const load = jest.fn();
const search = jest.fn();
Expand Down
25 changes: 19 additions & 6 deletions src/env/default-env.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import { cosmiconfigSync } from 'cosmiconfig';
import { pipe } from 'tightrope/fn/pipe';
import { fromTry } from 'tightrope/result/from-try';
import { unwrapOrElse } from 'tightrope/result/unwrap-or-else';
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore Select *does* exist
import { Input, Select } from 'enquirer';
import { readFileSync, readJsonSync, writeFileSync } from 'fs-extra';
import { readFileSync, writeFileSync } from 'fs';
import * as globby from 'globby';
import { join } from 'path';
import * as readYamlFile from 'read-yaml-file';
import { isNonEmptyObject } from 'tightrope/guard/is-non-empty-object';
import { Ok } from 'tightrope/result';
import { filter } from 'tightrope/result/filter';
import { map } from 'tightrope/result/map';
import { mapErr } from 'tightrope/result/map-err';
import type { O } from 'ts-toolbelt';
import type { RcConfig } from '../config/types';
import { CWD } from '../constants';
Expand Down Expand Up @@ -52,11 +59,17 @@ export const defaultEnv: DefaultEnv = {
const result = configPath ? client.load(configPath) : client.search();
if (!isNonEmptyObject(result)) {
const rcPath = join(CWD, 'package.json');
const pjson = readJsonSync(rcPath, { throws: false });
const rcConfig = pjson?.config?.syncpack;
if (isNonEmptyObject(rcConfig)) return rcConfig;
logVerbose('no config file found');
return {};
return pipe(
fromTry(() => readFileSync(rcPath, { encoding: 'utf8' })),
map(JSON.parse),
map((pjson) => pjson?.config?.syncpack),
filter(isNonEmptyObject, 'no config file found'),
mapErr((err) => {
logVerbose('no config file found');
return err;
}),
unwrapOrElse(() => new Ok({})),
);
}
const rcPath = result.filepath;
const rcConfig = result.config;
Expand Down
40 changes: 1 addition & 39 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -802,14 +802,6 @@
dependencies:
"@babel/types" "^7.20.7"

"@types/fs-extra@11.0.1":
version "11.0.1"
resolved "https://registry.yarnpkg.com/@types/fs-extra/-/fs-extra-11.0.1.tgz#f542ec47810532a8a252127e6e105f487e0a6ea5"
integrity sha512-MxObHvNl4A69ofaTRU8DFqvgzzv8s9yRtaPPm5gud9HDNvpB3GPQFvNuTWAI59B9huVGV5jXYJwbCsmBsOGYWA==
dependencies:
"@types/jsonfile" "*"
"@types/node" "*"

"@types/graceful-fs@^4.1.3":
version "4.1.6"
resolved "https://registry.yarnpkg.com/@types/graceful-fs/-/graceful-fs-4.1.6.tgz#e14b2576a1c25026b7f02ede1de3b84c3a1efeae"
Expand Down Expand Up @@ -854,13 +846,6 @@
resolved "https://registry.yarnpkg.com/@types/json5/-/json5-0.0.29.tgz#ee28707ae94e11d2b827bcbe5270bcea7f3e71ee"
integrity sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ==

"@types/jsonfile@*":
version "6.1.1"
resolved "https://registry.yarnpkg.com/@types/jsonfile/-/jsonfile-6.1.1.tgz#ac84e9aefa74a2425a0fb3012bdea44f58970f1b"
integrity sha512-GSgiRCVeapDN+3pqA35IkQwasaCh/0YFH5dEF6S88iDvEn901DjOeH3/QPY+XYP1DFzDZPvIvfeEgk+7br5png==
dependencies:
"@types/node" "*"

"@types/node@*":
version "20.2.5"
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.2.5.tgz#26d295f3570323b2837d322180dfbf1ba156fefb"
Expand Down Expand Up @@ -2049,15 +2034,6 @@ foreground-child@^3.1.0:
cross-spawn "^7.0.0"
signal-exit "^4.0.1"

fs-extra@11.1.1:
version "11.1.1"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-11.1.1.tgz#da69f7c39f3b002378b0954bb6ae7efdc0876e2d"
integrity sha512-MGIE4HOvQCeUCzmlHs0vXpih4ysz4wg9qiSAu6cd42lVwPbTM1TjV7RusoyQqMmk/95gdQZX72u+YW+c3eEpFQ==
dependencies:
graceful-fs "^4.2.0"
jsonfile "^6.0.1"
universalify "^2.0.0"

fs.realpath@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
Expand Down Expand Up @@ -2201,7 +2177,7 @@ gopd@^1.0.1:
dependencies:
get-intrinsic "^1.1.3"

graceful-fs@^4.1.6, graceful-fs@^4.2.0, graceful-fs@^4.2.9:
graceful-fs@^4.2.9:
version "4.2.11"
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.11.tgz#4183e4e8bf08bb6e05bbb2f7d2e0c8f712ca40e3"
integrity sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==
Expand Down Expand Up @@ -3004,15 +2980,6 @@ json5@^2.2.2, json5@^2.2.3:
resolved "https://registry.yarnpkg.com/json5/-/json5-2.2.3.tgz#78cd6f1a19bdc12b73db5ad0c61efd66c1e29283"
integrity sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==

jsonfile@^6.0.1:
version "6.1.0"
resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-6.1.0.tgz#bc55b2634793c679ec6403094eb13698a6ec0aae"
integrity sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==
dependencies:
universalify "^2.0.0"
optionalDependencies:
graceful-fs "^4.1.6"

kleur@^3.0.3:
version "3.0.3"
resolved "https://registry.yarnpkg.com/kleur/-/kleur-3.0.3.tgz#a79c9ecc86ee1ce3fa6206d1216c501f147fc07e"
Expand Down Expand Up @@ -3972,11 +3939,6 @@ unbox-primitive@^1.0.2:
has-symbols "^1.0.3"
which-boxed-primitive "^1.0.2"

universalify@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/universalify/-/universalify-2.0.0.tgz#75a4984efedc4b08975c5aeb73f530d02df25717"
integrity sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==

update-browserslist-db@^1.0.11:
version "1.0.11"
resolved "https://registry.yarnpkg.com/update-browserslist-db/-/update-browserslist-db-1.0.11.tgz#9a2a641ad2907ae7b3616506f4b977851db5b940"
Expand Down

0 comments on commit 3b2fac2

Please sign in to comment.