From 0ae0a1f9442827a7ed557a6e342264ba2419a90d Mon Sep 17 00:00:00 2001 From: Shogo Sensui Date: Sun, 12 Sep 2021 12:37:08 +0900 Subject: [PATCH] Remove `fs-extra` dependency (#597) Co-authored-by: Sindre Sorhus +conflict resolution by Devin Rhode --- lib/options-manager.js | 7 ++++--- package.json | 1 - test/options-manager.js | 7 +++---- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/options-manager.js b/lib/options-manager.js index bd7d0147..590ebf96 100644 --- a/lib/options-manager.js +++ b/lib/options-manager.js @@ -1,7 +1,7 @@ +import {promises as fs} from 'node:fs'; import process from 'node:process'; import os from 'node:os'; import path from 'node:path'; -import fsExtra from 'fs-extra'; import arrify from 'arrify'; import {mergeWith, groupBy, flow, pick} from 'lodash-es'; import pathExists from 'path-exists'; @@ -33,7 +33,6 @@ import { const {__dirname, json, require} = createEsmUtils(import.meta); const pkg = json.loadSync('../package.json'); -const {outputJson, outputJsonSync} = fsExtra; const {normalizePackageName} = Legacy.naming; const resolveModule = Legacy.ModuleResolver.resolve; @@ -132,7 +131,9 @@ const mergeWithFileConfig = options => { options.tsConfigPath = getTsConfigCachePath([options.filePath], options.tsConfigPath, options.cwd); options.ts = true; - outputJsonSync(options.tsConfigPath, makeTSConfig(tsConfig, tsConfigPath, [options.filePath])); + const config = makeTSConfig(tsConfig, tsConfigPath, [options.filePath]); + await fs.mkdir(path.dirname(options.tsConfigPath), {recursive: true}); + await fs.writeFile(options.tsConfigPath, JSON.stringify(config), 'utf8'); } return {options, prettierOptions}; diff --git a/package.json b/package.json index 6684da74..af1d78eb 100644 --- a/package.json +++ b/package.json @@ -76,7 +76,6 @@ "esm-utils": "^1.1.0", "find-cache-dir": "^3.3.1", "find-up": "^5.0.0", - "fs-extra": "^10.0.0", "get-stdin": "^9.0.0", "globby": "^12.0.0", "imurmurhash": "^0.1.4", diff --git a/test/options-manager.js b/test/options-manager.js index 251b5ee2..17a147a2 100644 --- a/test/options-manager.js +++ b/test/options-manager.js @@ -1,14 +1,13 @@ +import {promises as fs} from 'node:fs'; import process from 'node:process'; import path from 'node:path'; import test from 'ava'; import {omit} from 'lodash-es'; -import fsExtra from 'fs-extra'; import slash from 'slash'; import createEsmUtils from 'esm-utils'; import {DEFAULT_EXTENSION, DEFAULT_IGNORES} from '../lib/constants.js'; import * as manager from '../lib/options-manager.js'; -const {readJson} = fsExtra; const {__dirname, require, json} = createEsmUtils(import.meta); const parentConfig = json.loadSync('./fixtures/nested/package.json'); const childConfig = json.loadSync('./fixtures/nested/child/package.json'); @@ -557,7 +556,7 @@ test('mergeWithFileConfig: typescript files', async t => { const expectedConfigPath = new RegExp(`${slash(cwd)}/node_modules/.cache/xo-linter/tsconfig\\..*\\.json[\\/]?$`, 'u'); t.regex(slash(options.tsConfigPath), expectedConfigPath); t.deepEqual(omit(options, 'tsConfigPath'), expected); - t.deepEqual(await readJson(options.tsConfigPath), { + t.deepEqual(JSON.parse(await fs.readFile(options.tsConfigPath, 'utf8')), { extends: path.resolve(cwd, 'tsconfig.json'), files: [path.resolve(cwd, 'file.ts')], include: [slash(path.resolve(cwd, '**/*.ts')), slash(path.resolve(cwd, '**/*.tsx'))], @@ -579,7 +578,7 @@ test('mergeWithFileConfig: tsx files', async t => { const expectedConfigPath = new RegExp(`${slash(cwd)}/node_modules/.cache/xo-linter/tsconfig\\..*\\.json[\\/]?$`, 'u'); t.regex(slash(options.tsConfigPath), expectedConfigPath); t.deepEqual(omit(options, 'tsConfigPath'), expected); - t.deepEqual(await readJson(options.tsConfigPath), { + t.deepEqual(JSON.parse(await fs.readFile(options.tsConfigPath, 'utf8')), { extends: path.resolve(cwd, 'tsconfig.json'), files: [path.resolve(cwd, 'file.tsx')], include: [slash(path.resolve(cwd, '**/*.ts')), slash(path.resolve(cwd, '**/*.tsx'))],