diff --git a/package.json b/package.json index 9900ee72..6e79fc00 100644 --- a/package.json +++ b/package.json @@ -6,28 +6,20 @@ "bugs": "https://github.com/anycli/config/issues", "dependencies": { "debug": "^3.1.0", - "fs-extra": "^5.0.0", - "fs-extra-debug": "^1.0.4", - "globby": "^7.1.1", - "load-json-file": "^4.0.0", - "read-pkg": "^3.0.0" + "globby": "^7.1.1" }, "devDependencies": { "@anycli/parser": "^3.2.2", "@anycli/tslint": "^0.2.5", "@types/chai": "^4.1.2", - "@types/fs-extra": "^5.0.0", "@types/globby": "^6.1.0", - "@types/load-json-file": "^2.0.7", "@types/mocha": "^2.2.48", - "@types/nock": "^9.1.2", "@types/node": "^9.4.0", - "@types/read-pkg": "^3.0.0", "chai": "^4.1.2", "concurrently": "^3.5.1", "eslint": "^4.17.0", "eslint-config-anycli": "^1.3.2", - "fancy-test": "^0.6.10", + "fancy-test": "^1.0.1", "mocha": "^5.0.0", "ts-node": "^4.1.0", "typescript": "^2.7.1" diff --git a/src/config.ts b/src/config.ts index 3133db60..c1be4f17 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,10 +1,10 @@ import * as os from 'os' import * as path from 'path' -import * as readPkg from 'read-pkg' import {Hooks} from './hooks' import {PJSON} from './pjson' import * as Plugin from './plugin' +import {loadJSONSync} from './util' export type PlatformTypes = 'darwin' | 'linux' | 'win32' | 'aix' | 'freebsd' | 'openbsd' | 'sunos' export type ArchTypes = 'arm' | 'arm64' | 'mips' | 'mipsel' | 'ppc' | 'ppc64' | 's390' | 's390x' | 'x32' | 'x64' | 'x86' @@ -137,7 +137,7 @@ export class Config extends Plugin.Plugin implements IConfig { try { const userPJSONPath = path.join(this.dataDir, 'package.json') - const pjson = this.userPJSON = readPkg.sync(userPJSONPath) as any + const pjson = this.userPJSON = loadJSONSync(userPJSONPath) if (!pjson.anycli) pjson.anycli = {schema: 1} this.loadPlugins(userPJSONPath, pjson.anycli.plugins) } catch (err) { diff --git a/src/index.ts b/src/index.ts index 9af96457..877a7fc3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,5 @@ -import 'fs-extra-debug' +// tslint:disable no-implicit-dependencies +try { require('fs-extra-debug') } catch {} export {IConfig, Config, Options, load} from './config' export {Command} from './command' diff --git a/src/pjson.ts b/src/pjson.ts index 63d232f0..68840d9d 100644 --- a/src/pjson.ts +++ b/src/pjson.ts @@ -1,6 +1,5 @@ -import {Package} from 'read-pkg' - export interface PJSON { + [k: string]: any dependencies?: {[name: string]: string} anycli: { schema?: number @@ -8,7 +7,7 @@ export interface PJSON { } export namespace PJSON { - export interface Plugin extends PJSON, Package { + export interface Plugin extends PJSON { name: string version: string anycli: PJSON['anycli'] & { diff --git a/src/plugin.ts b/src/plugin.ts index e386c47e..116de264 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -1,7 +1,5 @@ -import * as fs from 'fs-extra' -import * as loadJSON from 'load-json-file' +import * as fs from 'fs' import * as path from 'path' -import * as readPkg from 'read-pkg' import {inspect} from 'util' import {Command} from './command' @@ -10,7 +8,7 @@ import {Manifest} from './manifest' import {PJSON} from './pjson' import {Topic} from './topic' import {tsPath} from './ts_node' -import {flatMap, mapValues} from './util' +import {flatMap, loadJSONSync, mapValues} from './util' export interface Options { root: string @@ -108,7 +106,7 @@ export class Plugin implements IPlugin { Plugin.loadedPlugins[root] = this this.root = root debug('reading plugin %s', root) - this.pjson = readPkg.sync(path.join(root, 'package.json')) as any + this.pjson = loadJSONSync(path.join(root, 'package.json')) as any this.name = this.pjson.name this.version = this.pjson.version if (!this.pjson.anycli) { @@ -222,7 +220,7 @@ export class Plugin implements IPlugin { const readManifest = () => { try { const p = path.join(this.root, '.anycli.manifest.json') - const manifest: Manifest = loadJSON.sync(p) + const manifest: Manifest = loadJSONSync(p) if (manifest.version !== this.version) { process.emitWarning(`Mismatched version in ${this.name} plugin manifest. Expected: ${this.version} Received: ${manifest.version}`) } else { @@ -299,6 +297,6 @@ function findRoot(name: string | undefined, root: string) { } else { cur = path.join(next, 'package.json') } - if (fs.pathExistsSync(cur)) return path.dirname(cur) + if (fs.existsSync(cur)) return path.dirname(cur) } } diff --git a/src/ts_node.ts b/src/ts_node.ts index f2f5207f..71e0ce6f 100644 --- a/src/ts_node.ts +++ b/src/ts_node.ts @@ -1,8 +1,9 @@ -import * as fs from 'fs-extra' -import * as loadJSON from 'load-json-file' +import * as fs from 'fs' import * as path from 'path' import * as TSNode from 'ts-node' +import {loadJSONSync} from './util' + const tsconfigs: {[root: string]: TSConfig} = {} const rootDirs: string[] = [] const typeRoots = [`${__dirname}/../node_modules/@types`] @@ -49,7 +50,7 @@ function loadTSConfig(root: string): TSConfig | undefined { // if (!await fs.pathExists(path.join(this.root, '.git'))) return const tsconfigPath = path.join(root, 'tsconfig.json') - const tsconfig = loadJSON.sync(tsconfigPath) + const tsconfig = loadJSONSync(tsconfigPath) if (!tsconfig || !tsconfig.compilerOptions) return return tsconfig } catch (err) { @@ -84,7 +85,7 @@ export function tsPath(root: string, orig: string | undefined): string | undefin // For hooks, it might point to a module, not a file. Something like "./hooks/myhook" // That file doesn't exist, and the real file is "./hooks/myhook.ts" // In that case we attempt to resolve to the filename. If it fails it will revert back to the lib path - if (fs.pathExistsSync(out) || fs.pathExistsSync(out + '.ts')) return out + if (fs.existsSync(out) || fs.existsSync(out + '.ts')) return out else return orig } catch (err) { debug(err) diff --git a/src/util.ts b/src/util.ts index d822b95b..b2903f95 100644 --- a/src/util.ts +++ b/src/util.ts @@ -1,3 +1,6 @@ +// tslint:disable no-implicit-dependencies +import * as fs from 'fs' + export function flatMap(arr: T[], fn: (i: T) => U[]): U[] { return arr.reduce((arr, i) => arr.concat(fn(i)), [] as U[]) } @@ -9,3 +12,10 @@ export function mapValues(obj: {[P in keyof T]: T[P]} return o }, {} as any) } + +export function loadJSONSync(path: string): any { + let loadJSON + try { loadJSON = require('load-json-file') } catch {} + if (loadJSON) return loadJSON.sync(path) + return JSON.parse(fs.readFileSync(path, 'utf8')) +} diff --git a/test/test.ts b/test/test.ts index a52d6a6f..9b26d093 100644 --- a/test/test.ts +++ b/test/test.ts @@ -1,4 +1,4 @@ -import {expect, fancy as base, FancyTypes, NockScope} from 'fancy-test' +import {expect, fancy as base, FancyTypes} from 'fancy-test' import * as Config from '../src' @@ -13,5 +13,4 @@ export const fancy = base export { expect, FancyTypes, - NockScope, } diff --git a/yarn.lock b/yarn.lock index 71fe9c09..66e417ae 100644 --- a/yarn.lock +++ b/yarn.lock @@ -29,12 +29,6 @@ version "1.1.0" resolved "https://registry.yarnpkg.com/@types/events/-/events-1.1.0.tgz#93b1be91f63c184450385272c47b6496fd028e02" -"@types/fs-extra@^5.0.0": - version "5.0.0" - resolved "https://registry.npmjs.org/@types/fs-extra/-/fs-extra-5.0.0.tgz#d3e225b35eb5c6d3a5a782c28219df365c781413" - dependencies: - "@types/node" "*" - "@types/glob@*": version "5.0.35" resolved "https://registry.yarnpkg.com/@types/glob/-/glob-5.0.35.tgz#1ae151c802cece940443b5ac246925c85189f32a" @@ -49,10 +43,6 @@ dependencies: "@types/glob" "*" -"@types/load-json-file@^2.0.7": - version "2.0.7" - resolved "https://registry.npmjs.org/@types/load-json-file/-/load-json-file-2.0.7.tgz#c887826f5230b7507d5230994d26315c6776be06" - "@types/minimatch@*": version "3.0.3" resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.3.tgz#3dca0e3f33b200fc7d1139c0cd96c1268cadfd9d" @@ -61,26 +51,10 @@ version "2.2.48" resolved "https://registry.npmjs.org/@types/mocha/-/mocha-2.2.48.tgz#3523b126a0b049482e1c3c11877460f76622ffab" -"@types/nock@^9.1.2": - version "9.1.2" - resolved "https://registry.npmjs.org/@types/nock/-/nock-9.1.2.tgz#0515b27e3f6bbc11834d22508ad02e2921dd376a" - dependencies: - "@types/node" "*" - "@types/node@*", "@types/node@^9.4.0": version "9.4.0" resolved "https://registry.npmjs.org/@types/node/-/node-9.4.0.tgz#b85a0bcf1e1cc84eb4901b7e96966aedc6f078d1" -"@types/normalize-package-data@*": - version "2.4.0" - resolved "https://registry.npmjs.org/@types/normalize-package-data/-/normalize-package-data-2.4.0.tgz#e486d0d97396d79beedd0a6e33f4534ff6b4973e" - -"@types/read-pkg@^3.0.0": - version "3.0.0" - resolved "https://registry.npmjs.org/@types/read-pkg/-/read-pkg-3.0.0.tgz#17ab6f0b396a58a5567ee387f558f2caedc8ae53" - dependencies: - "@types/normalize-package-data" "*" - "@types/strip-bom@^3.0.0": version "3.0.0" resolved "https://registry.yarnpkg.com/@types/strip-bom/-/strip-bom-3.0.0.tgz#14a8ec3956c2e81edb7520790aecf21c290aebd2" @@ -193,7 +167,7 @@ browser-stdout@1.3.0: version "1.3.0" resolved "https://registry.yarnpkg.com/browser-stdout/-/browser-stdout-1.3.0.tgz#f351d32969d32fa5d7a5567154263d928ae3bd1f" -builtin-modules@^1.0.0, builtin-modules@^1.1.1: +builtin-modules@^1.1.1: version "1.1.1" resolved "https://registry.yarnpkg.com/builtin-modules/-/builtin-modules-1.1.1.tgz#270f076c5a72c02f5b65a47df94c5fe3a278892f" @@ -397,12 +371,6 @@ doctrine@^2.1.0: dependencies: esutils "^2.0.2" -error-ex@^1.3.1: - version "1.3.1" - resolved "https://registry.yarnpkg.com/error-ex/-/error-ex-1.3.1.tgz#f855a86ce61adc4e8621c3cda21e7a7612c3a8dc" - dependencies: - is-arrayish "^0.2.1" - escape-string-regexp@1.0.5, escape-string-regexp@^1.0.0, escape-string-regexp@^1.0.2, escape-string-regexp@^1.0.5: version "1.0.5" resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4" @@ -557,9 +525,9 @@ external-editor@^2.0.4: iconv-lite "^0.4.17" tmp "^0.0.33" -fancy-test@^0.6.10: - version "0.6.10" - resolved "https://registry.yarnpkg.com/fancy-test/-/fancy-test-0.6.10.tgz#39001bcb117b7067c851dc58da6236a08a49e267" +fancy-test@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/fancy-test/-/fancy-test-1.0.1.tgz#28eb801dffc341d7202ed90b6944019922b08b5b" dependencies: lodash "^4.17.4" stdout-stderr "^0.1.6" @@ -598,20 +566,6 @@ flat-cache@^1.2.1: graceful-fs "^4.1.2" write "^0.2.1" -fs-extra-debug@^1.0.4: - version "1.0.4" - resolved "https://registry.yarnpkg.com/fs-extra-debug/-/fs-extra-debug-1.0.4.tgz#5efa3bd2a7ef6753fa79cfd810aab36445fa4788" - dependencies: - debug "^3.1.0" - -fs-extra@^5.0.0: - version "5.0.0" - resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-5.0.0.tgz#414d0110cdd06705734d055652c5411260c31abd" - dependencies: - graceful-fs "^4.1.2" - jsonfile "^4.0.0" - universalify "^0.1.0" - fs.realpath@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f" @@ -661,7 +615,7 @@ globby@^7.1.1: pify "^3.0.0" slash "^1.0.0" -graceful-fs@^4.1.2, graceful-fs@^4.1.6: +graceful-fs@^4.1.2: version "4.1.11" resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.11.tgz#0e8bdfe4d1ddb8854d64e04ea7c00e2a026e5658" @@ -699,10 +653,6 @@ homedir-polyfill@^1.0.1: dependencies: parse-passwd "^1.0.0" -hosted-git-info@^2.1.4: - version "2.5.0" - resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.5.0.tgz#6d60e34b3abbc8313062c3b798ef8d901a07af3c" - iconv-lite@^0.4.17: version "0.4.19" resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.19.tgz#f7468f60135f5e5dad3399c0a81be9a1603a082b" @@ -749,16 +699,6 @@ inquirer@^3.0.6: strip-ansi "^4.0.0" through "^2.3.6" -is-arrayish@^0.2.1: - version "0.2.1" - resolved "https://registry.yarnpkg.com/is-arrayish/-/is-arrayish-0.2.1.tgz#77c99840527aa8ecb1a8ba697b80645a7a926a9d" - -is-builtin-module@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/is-builtin-module/-/is-builtin-module-1.0.0.tgz#540572d34f7ac3119f8f76c30cbc1b1e037affbe" - dependencies: - builtin-modules "^1.0.0" - is-fullwidth-code-point@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz#a3b30a5c4f199183167aaab93beefae3ddfb654f" @@ -810,10 +750,6 @@ js-yaml@^3.7.0, js-yaml@^3.9.1: argparse "^1.0.7" esprima "^4.0.0" -json-parse-better-errors@^1.0.1: - version "1.0.1" - resolved "https://registry.yarnpkg.com/json-parse-better-errors/-/json-parse-better-errors-1.0.1.tgz#50183cd1b2d25275de069e9e71b467ac9eab973a" - json-schema-traverse@^0.3.0: version "0.3.1" resolved "https://registry.yarnpkg.com/json-schema-traverse/-/json-schema-traverse-0.3.1.tgz#349a6d44c53a51de89b40805c5d5e59b417d3340" @@ -822,12 +758,6 @@ json-stable-stringify-without-jsonify@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz#9db7b59496ad3f3cfef30a75142d2d930ad72651" -jsonfile@^4.0.0: - version "4.0.0" - resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-4.0.0.tgz#8771aae0799b64076b76640fca058f9c10e33ecb" - optionalDependencies: - graceful-fs "^4.1.6" - levn@^0.3.0, levn@~0.3.0: version "0.3.0" resolved "https://registry.yarnpkg.com/levn/-/levn-0.3.0.tgz#3b09924edf9f083c0490fdd4c0bc4421e04764ee" @@ -835,15 +765,6 @@ levn@^0.3.0, levn@~0.3.0: prelude-ls "~1.1.2" type-check "~0.3.2" -load-json-file@^4.0.0: - version "4.0.0" - resolved "https://registry.yarnpkg.com/load-json-file/-/load-json-file-4.0.0.tgz#2f5f45ab91e33216234fd53adab668eb4ec0993b" - dependencies: - graceful-fs "^4.1.2" - parse-json "^4.0.0" - pify "^3.0.0" - strip-bom "^3.0.0" - lodash.camelcase@^4.1.1: version "4.3.0" resolved "https://registry.yarnpkg.com/lodash.camelcase/-/lodash.camelcase-4.3.0.tgz#b28aa6288a2b9fc651035c7711f65ab6190331a6" @@ -934,15 +855,6 @@ natural-compare@^1.4.0: version "1.4.0" resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7" -normalize-package-data@^2.3.2: - version "2.4.0" - resolved "https://registry.yarnpkg.com/normalize-package-data/-/normalize-package-data-2.4.0.tgz#12f95a307d58352075a04907b84ac8be98ac012f" - dependencies: - hosted-git-info "^2.1.4" - is-builtin-module "^1.0.0" - semver "2 || 3 || 4 || 5" - validate-npm-package-license "^3.0.1" - object-assign@^4.0.1: version "4.1.1" resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863" @@ -974,13 +886,6 @@ os-tmpdir@~1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/os-tmpdir/-/os-tmpdir-1.0.2.tgz#bbe67406c79aa85c5cfec766fe5734555dfa1274" -parse-json@^4.0.0: - version "4.0.0" - resolved "https://registry.yarnpkg.com/parse-json/-/parse-json-4.0.0.tgz#be35f5425be1f7f6c747184f98a788cb99477ee0" - dependencies: - error-ex "^1.3.1" - json-parse-better-errors "^1.0.1" - parse-passwd@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/parse-passwd/-/parse-passwd-1.0.0.tgz#6d5b934a456993b23d37f40a382d6f1666a8e5c6" @@ -1049,14 +954,6 @@ ramda@^0.24.1: version "0.24.1" resolved "https://registry.yarnpkg.com/ramda/-/ramda-0.24.1.tgz#c3b7755197f35b8dc3502228262c4c91ddb6b857" -read-pkg@^3.0.0: - version "3.0.0" - resolved "https://registry.yarnpkg.com/read-pkg/-/read-pkg-3.0.0.tgz#9cbc686978fee65d16c00e2b19c237fcf6e38389" - dependencies: - load-json-file "^4.0.0" - normalize-package-data "^2.3.2" - path-type "^3.0.0" - readable-stream@^2.2.2: version "2.3.3" resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.3.3.tgz#368f2512d79f9d46fdfc71349ae7878bbc1eb95c" @@ -1123,14 +1020,14 @@ safe-buffer@~5.1.0, safe-buffer@~5.1.1: version "5.1.1" resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.1.tgz#893312af69b2123def71f57889001671eeb2c853" -"semver@2 || 3 || 4 || 5", semver@^5.3.0: - version "5.5.0" - resolved "https://registry.yarnpkg.com/semver/-/semver-5.5.0.tgz#dc4bbc7a6ca9d916dee5d43516f0092b58f7b8ab" - semver@5.3.0: version "5.3.0" resolved "https://registry.yarnpkg.com/semver/-/semver-5.3.0.tgz#9b2ce5d3de02d17c6012ad326aa6b4d0cf54f94f" +semver@^5.3.0: + version "5.5.0" + resolved "https://registry.yarnpkg.com/semver/-/semver-5.5.0.tgz#dc4bbc7a6ca9d916dee5d43516f0092b58f7b8ab" + shebang-command@^1.2.0: version "1.2.0" resolved "https://registry.yarnpkg.com/shebang-command/-/shebang-command-1.2.0.tgz#44aac65b695b03398968c39f363fee5deafdf1ea" @@ -1169,20 +1066,6 @@ spawn-command@^0.0.2-1: version "0.0.2-1" resolved "https://registry.yarnpkg.com/spawn-command/-/spawn-command-0.0.2-1.tgz#62f5e9466981c1b796dc5929937e11c9c6921bd0" -spdx-correct@~1.0.0: - version "1.0.2" - resolved "https://registry.yarnpkg.com/spdx-correct/-/spdx-correct-1.0.2.tgz#4b3073d933ff51f3912f03ac5519498a4150db40" - dependencies: - spdx-license-ids "^1.0.2" - -spdx-expression-parse@~1.0.0: - version "1.0.4" - resolved "https://registry.yarnpkg.com/spdx-expression-parse/-/spdx-expression-parse-1.0.4.tgz#9bdf2f20e1f40ed447fbe273266191fced51626c" - -spdx-license-ids@^1.0.2: - version "1.2.2" - resolved "https://registry.yarnpkg.com/spdx-license-ids/-/spdx-license-ids-1.2.2.tgz#c9df7a3424594ade6bd11900d596696dc06bac57" - sprintf-js@~1.0.2: version "1.0.3" resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c" @@ -1390,10 +1273,6 @@ typescript@^2.7.1: version "2.7.1" resolved "https://registry.npmjs.org/typescript/-/typescript-2.7.1.tgz#bb3682c2c791ac90e7c6210b26478a8da085c359" -universalify@^0.1.0: - version "0.1.1" - resolved "https://registry.yarnpkg.com/universalify/-/universalify-0.1.1.tgz#fa71badd4437af4c148841e3b3b165f9e9e590b7" - util-deprecate@~1.0.1: version "1.0.2" resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf" @@ -1404,13 +1283,6 @@ v8flags@^3.0.0: dependencies: homedir-polyfill "^1.0.1" -validate-npm-package-license@^3.0.1: - version "3.0.1" - resolved "https://registry.yarnpkg.com/validate-npm-package-license/-/validate-npm-package-license-3.0.1.tgz#2804babe712ad3379459acfbe24746ab2c303fbc" - dependencies: - spdx-correct "~1.0.0" - spdx-expression-parse "~1.0.0" - which@^1.2.9: version "1.3.0" resolved "https://registry.yarnpkg.com/which/-/which-1.3.0.tgz#ff04bdfc010ee547d780bec38e1ac1c2777d253a"