From 6f30c46601d023f609fbd0b2c882f50c6c691fbb Mon Sep 17 00:00:00 2001 From: Joe Gomain Hoyes Date: Wed, 9 Sep 2020 14:44:24 +0700 Subject: [PATCH 1/2] refacter to satisfy tslint --- property-based-tests/executeTestCase.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/property-based-tests/executeTestCase.ts b/property-based-tests/executeTestCase.ts index 87d19a77..43bd2717 100644 --- a/property-based-tests/executeTestCase.ts +++ b/property-based-tests/executeTestCase.ts @@ -1,5 +1,5 @@ import * as tmp from "tmp" -import * as path from "path" +import { join, dirname } from "path" import { spawnSafeSync } from "../src/spawnSafe" import { executeEffects } from "../src/patch/apply" @@ -48,11 +48,10 @@ jest.mock("fs-extra", () => { function writeFiles(cwd: string, files: Files): void { const mkdirpSync = require("fs-extra/lib/mkdirs/index.js").mkdirpSync - const writeFileSync = require("fs").writeFileSync Object.keys(files).forEach(filePath => { if (!filePath.startsWith(".git/")) { - mkdirpSync(path.join(cwd, path.dirname(filePath))) - writeFileSync(path.join(cwd, filePath), files[filePath].contents, { + mkdirpSync(join(cwd, dirname(filePath))) + writeFileSync(join(cwd, filePath), files[filePath].contents, { mode: files[filePath].mode, }) } From 56a4e931ff8e55569beb5649b37defa9a0e98409 Mon Sep 17 00:00:00 2001 From: Joe Gomain Hoyes Date: Wed, 9 Sep 2020 23:35:22 +0700 Subject: [PATCH 2/2] update prettier and tslint --- integration-tests/runIntegrationTest.ts | 4 +- package.json | 4 +- property-based-tests/executeTestCase.ts | 10 ++-- property-based-tests/testCases.ts | 2 +- src/applyPatches.ts | 2 +- src/filterFiles.ts | 6 +- src/getPackageResolution.ts | 3 +- src/makePatch.ts | 6 +- src/packageIsDevDependency.ts | 4 +- src/patch/apply.ts | 2 +- src/patchFs.ts | 2 +- src/spawnSafe.ts | 68 +++++++++++------------ tslint.json | 1 + yarn.lock | 73 ++++++++++++++----------- 14 files changed, 101 insertions(+), 86 deletions(-) diff --git a/integration-tests/runIntegrationTest.ts b/integration-tests/runIntegrationTest.ts index 3e788a2a..26e86df6 100644 --- a/integration-tests/runIntegrationTest.ts +++ b/integration-tests/runIntegrationTest.ts @@ -7,7 +7,7 @@ import { resolveRelativeFileDependencies } from "../src/resolveRelativeFileDepen export const patchPackageTarballPath = resolve( fs .readdirSync(".") - .filter(nm => nm.match(/^patch-package\.test\.\d+\.tgz$/))[0], + .filter((nm) => nm.match(/^patch-package\.test\.\d+\.tgz$/))[0], ) export function runIntegrationTest({ @@ -64,7 +64,7 @@ export function runIntegrationTest({ expect(snapshots && snapshots.length).toBeTruthy() }) if (snapshots) { - snapshots.forEach(snapshot => { + snapshots.forEach((snapshot) => { const snapshotDescriptionMatch = snapshot.match(/SNAPSHOT: (.*)/) if (snapshotDescriptionMatch) { it(snapshotDescriptionMatch[1], () => { diff --git a/package.json b/package.json index ea94d9ab..17753ac0 100644 --- a/package.json +++ b/package.json @@ -59,11 +59,11 @@ "jest": "^24.5.0", "lint-staged": "^8.1.5", "np": "^6.2.0", - "prettier": "^1.18.2", + "prettier": "^2.1.1", "randomstring": "^1.1.5", "ts-jest": "^24.0.0", "ts-node": "8.0.3", - "tslint": "^5.14.0", + "tslint": "^6.1.3", "typescript": "^3.6.3" }, "dependencies": { diff --git a/property-based-tests/executeTestCase.ts b/property-based-tests/executeTestCase.ts index 43bd2717..c74b3438 100644 --- a/property-based-tests/executeTestCase.ts +++ b/property-based-tests/executeTestCase.ts @@ -24,7 +24,7 @@ jest.mock("fs-extra", () => { setWorkingFiles, getWorkingFiles, ensureDirSync: jest.fn(), - readFileSync: jest.fn(path => getWorkingFiles()[path].contents), + readFileSync: jest.fn((path) => getWorkingFiles()[path].contents), writeFileSync: jest.fn( (path: string, contents: string, opts?: { mode?: number }) => { getWorkingFiles()[path] = { @@ -33,12 +33,12 @@ jest.mock("fs-extra", () => { } }, ), - unlinkSync: jest.fn(path => delete getWorkingFiles()[path]), + unlinkSync: jest.fn((path) => delete getWorkingFiles()[path]), moveSync: jest.fn((from, to) => { getWorkingFiles()[to] = getWorkingFiles()[from] delete getWorkingFiles()[from] }), - statSync: jest.fn(path => getWorkingFiles()[path]), + statSync: jest.fn((path) => getWorkingFiles()[path]), chmodSync: jest.fn((path, mode) => { const { contents } = getWorkingFiles()[path] getWorkingFiles()[path] = { contents, mode } @@ -48,7 +48,7 @@ jest.mock("fs-extra", () => { function writeFiles(cwd: string, files: Files): void { const mkdirpSync = require("fs-extra/lib/mkdirs/index.js").mkdirpSync - Object.keys(files).forEach(filePath => { + Object.keys(files).forEach((filePath) => { if (!filePath.startsWith(".git/")) { mkdirpSync(join(cwd, dirname(filePath))) writeFileSync(join(cwd, filePath), files[filePath].contents, { @@ -61,7 +61,7 @@ function writeFiles(cwd: string, files: Files): void { function removeLeadingSpaceOnBlankLines(patchFileContents: string): string { return patchFileContents .split("\n") - .map(line => (line === " " ? "" : line)) + .map((line) => (line === " " ? "" : line)) .join("\n") } diff --git a/property-based-tests/testCases.ts b/property-based-tests/testCases.ts index 8fef3bb8..8875f754 100644 --- a/property-based-tests/testCases.ts +++ b/property-based-tests/testCases.ts @@ -121,7 +121,7 @@ function insertLinesIntoFile(file: File): File { function getUniqueFilename(files: Files) { let filename = makeFileName() const ks = Object.keys(files) - while (ks.some(k => k.startsWith(filename))) { + while (ks.some((k) => k.startsWith(filename))) { filename = makeFileName() } return filename diff --git a/src/applyPatches.ts b/src/applyPatches.ts index f8eddeeb..7037c61f 100644 --- a/src/applyPatches.ts +++ b/src/applyPatches.ts @@ -101,7 +101,7 @@ export function applyPatchesForApp({ return } - files.forEach(filename => { + files.forEach((filename) => { const packageDetails = getPackageDetailsFromPatchFilename(filename) if (!packageDetails) { diff --git a/src/filterFiles.ts b/src/filterFiles.ts index 60983b32..c707cd72 100644 --- a/src/filterFiles.ts +++ b/src/filterFiles.ts @@ -8,10 +8,10 @@ export function removeIgnoredFiles( excludePaths: RegExp, ) { klawSync(dir, { nodir: true }) - .map(item => item.path.slice(`${dir}/`.length)) + .map((item) => item.path.slice(`${dir}/`.length)) .filter( - relativePath => + (relativePath) => !relativePath.match(includePaths) || relativePath.match(excludePaths), ) - .forEach(relativePath => removeSync(join(dir, relativePath))) + .forEach((relativePath) => removeSync(join(dir, relativePath))) } diff --git a/src/getPackageResolution.ts b/src/getPackageResolution.ts index 08a952e6..2b1b2eff 100644 --- a/src/getPackageResolution.ts +++ b/src/getPackageResolution.ts @@ -87,7 +87,8 @@ export function getPackageResolution({ } lockFileStack.reverse() const relevantStackEntry = lockFileStack.find( - entry => entry.dependencies && packageDetails.name in entry.dependencies, + (entry) => + entry.dependencies && packageDetails.name in entry.dependencies, ) const pkg = relevantStackEntry.dependencies[packageDetails.name] return pkg.resolved || pkg.from || pkg.version diff --git a/src/makePatch.ts b/src/makePatch.ts index 8ebeab17..b8d1b969 100644 --- a/src/makePatch.ts +++ b/src/makePatch.ts @@ -103,7 +103,7 @@ export function makePatch({ )).version as string // copy .npmrc/.yarnrc in case packages are hosted in private registry - [".npmrc", ".yarnrc"].forEach(rcFile => { + ;[".npmrc", ".yarnrc"].forEach((rcFile) => { const rcPath = join(appPath, rcFile) if (existsSync(rcPath)) { copySync(rcPath, join(tmpRepo.name, rcFile)) @@ -264,11 +264,11 @@ export function makePatch({ } const packageNames = packageDetails.packageNames - .map(name => name.replace(/\//g, "+")) + .map((name) => name.replace(/\//g, "+")) .join("++") // maybe delete existing - getPatchFiles(patchDir).forEach(filename => { + getPatchFiles(patchDir).forEach((filename) => { const deets = getPackageDetailsFromPatchFilename(filename) if (deets && deets.path === packageDetails.path) { unlinkSync(join(patchDir, filename)) diff --git a/src/packageIsDevDependency.ts b/src/packageIsDevDependency.ts index 2719c9be..330cb83d 100644 --- a/src/packageIsDevDependency.ts +++ b/src/packageIsDevDependency.ts @@ -14,5 +14,7 @@ export function packageIsDevDependency({ return false } const { devDependencies } = require(packageJsonPath) - return Boolean(devDependencies && devDependencies[packageDetails.packageNames[0]]) + return Boolean( + devDependencies && devDependencies[packageDetails.packageNames[0]], + ) } diff --git a/src/patch/apply.ts b/src/patch/apply.ts index c2601bae..0c21b61f 100644 --- a/src/patch/apply.ts +++ b/src/patch/apply.ts @@ -7,7 +7,7 @@ export const executeEffects = ( effects: ParsedPatchFile, { dryRun }: { dryRun: boolean }, ) => { - effects.forEach(eff => { + effects.forEach((eff) => { switch (eff.type) { case "file deletion": if (dryRun) { diff --git a/src/patchFs.ts b/src/patchFs.ts index 9786365e..13d9d49c 100644 --- a/src/patchFs.ts +++ b/src/patchFs.ts @@ -5,7 +5,7 @@ export const getPatchFiles = (patchesDir: string) => { try { return klawSync(patchesDir, { nodir: true }) .map(({ path }) => relative(patchesDir, path)) - .filter(path => path.endsWith(".patch")) + .filter((path) => path.endsWith(".patch")) } catch (e) { return [] } diff --git a/src/spawnSafe.ts b/src/spawnSafe.ts index 665b10ad..0170c952 100644 --- a/src/spawnSafe.ts +++ b/src/spawnSafe.ts @@ -1,34 +1,34 @@ -import { sync as spawnSync } from "cross-spawn" -import { SpawnOptions } from "child_process" - -export interface SpawnSafeOptions extends SpawnOptions { - throwOnError?: boolean - logStdErrOnError?: boolean -} - -const defaultOptions: SpawnSafeOptions = { - logStdErrOnError: true, - throwOnError: true, -} - -export const spawnSafeSync = ( - command: string, - args?: string[], - options?: SpawnSafeOptions, -) => { - const mergedOptions = Object.assign({}, defaultOptions, options) - const result = spawnSync(command, args, options) - if (result.error || result.status !== 0) { - if (mergedOptions.logStdErrOnError) { - if (result.stderr) { - console.error(result.stderr.toString()) - } else if (result.error) { - console.error(result.error) - } - } - if (mergedOptions.throwOnError) { - throw result - } - } - return result -} +import { sync as spawnSync } from "cross-spawn" +import { SpawnOptions } from "child_process" + +export interface SpawnSafeOptions extends SpawnOptions { + throwOnError?: boolean + logStdErrOnError?: boolean +} + +const defaultOptions: SpawnSafeOptions = { + logStdErrOnError: true, + throwOnError: true, +} + +export const spawnSafeSync = ( + command: string, + args?: string[], + options?: SpawnSafeOptions, +) => { + const mergedOptions = Object.assign({}, defaultOptions, options) + const result = spawnSync(command, args, options) + if (result.error || result.status !== 0) { + if (mergedOptions.logStdErrOnError) { + if (result.stderr) { + console.error(result.stderr.toString()) + } else if (result.error) { + console.error(result.error) + } + } + if (mergedOptions.throwOnError) { + throw result + } + } + return result +} diff --git a/tslint.json b/tslint.json index ea76ddb6..422135e1 100644 --- a/tslint.json +++ b/tslint.json @@ -3,6 +3,7 @@ "extends": ["tslint:recommended"], "jsRules": {}, "rules": { + "array-type": false, "prefer-for-of": false, "trailing-comma": [false], "ordered-imports": [false], diff --git a/yarn.lock b/yarn.lock index 74e651db..6645b82c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -692,14 +692,6 @@ aws4@^1.8.0: resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.8.0.tgz#f0e003d9ca9e7f59c7a508945d7b2ef9a04a542f" integrity sha512-ReZxvNHIOv88FlT7rxcXIIC0fPt4KZqZbOlivyWtXLt8ESx84zd3kMC6iK5jVeS2qt+g7ftS7ye4fi06X5rtRQ== -babel-code-frame@^6.22.0: - version "6.22.0" - resolved "https://registry.yarnpkg.com/babel-code-frame/-/babel-code-frame-6.22.0.tgz#027620bee567a88c32561574e7fd0801d33118e4" - dependencies: - chalk "^1.1.0" - esutils "^2.0.2" - js-tokens "^3.0.0" - babel-jest@^24.5.0: version "24.5.0" resolved "https://registry.yarnpkg.com/babel-jest/-/babel-jest-24.5.0.tgz#0ea042789810c2bec9065f7c8ab4dc18e1d28559" @@ -925,7 +917,7 @@ caseless@~0.12.0: version "0.12.0" resolved "https://registry.yarnpkg.com/caseless/-/caseless-0.12.0.tgz#1b681c21ff84033c826543090689420d187151dc" -chalk@^1.0.0, chalk@^1.1.0, chalk@^1.1.3: +chalk@^1.0.0, chalk@^1.1.3: version "1.1.3" resolved "https://registry.yarnpkg.com/chalk/-/chalk-1.1.3.tgz#a8115c55e4a702fe4d150abd3872822a7e09fc98" dependencies: @@ -1348,9 +1340,10 @@ diff@^3.1.0: version "3.5.0" resolved "https://registry.yarnpkg.com/diff/-/diff-3.5.0.tgz#800c0dd1e0a8bfbc95835c202ad220fe317e5a12" -diff@^3.2.0: - version "3.2.0" - resolved "https://registry.yarnpkg.com/diff/-/diff-3.2.0.tgz#c9ce393a4b7cbd0b058a725c93df299027868ff9" +diff@^4.0.1: + version "4.0.2" + resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.2.tgz#60f3aecb89d5fae520c11aa19efc2bb982aade7d" + integrity sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A== domexception@^1.0.1: version "1.0.1" @@ -1456,7 +1449,7 @@ escodegen@^1.9.1: optionalDependencies: source-map "~0.6.1" -esprima@^3.1.1, esprima@^3.1.3: +esprima@^3.1.3: version "3.1.3" resolved "https://registry.yarnpkg.com/esprima/-/esprima-3.1.3.tgz#fdca51cee6133895e3c88d535ce49dbff62a4633" @@ -2899,12 +2892,13 @@ js-yaml@^3.12.0, js-yaml@^3.9.0: argparse "^1.0.7" esprima "^4.0.0" -js-yaml@^3.7.0: - version "3.8.4" - resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.8.4.tgz#520b4564f86573ba96662af85a8cafa7b4b5a6f6" +js-yaml@^3.13.1: + version "3.14.0" + resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.14.0.tgz#a7a34170f26a21bb162424d8adacb4113a69e482" + integrity sha512-/4IbIeHcD9VMHFqDR/gQ7EdZdLimOvW2DdcxFjdyyZ9NsbS+ccrXqVWDtab/lRl5AlUqmpBx8EhPaWR+OtY17A== dependencies: argparse "^1.0.7" - esprima "^3.1.1" + esprima "^4.0.0" jsbn@~0.1.0: version "0.1.1" @@ -3460,6 +3454,11 @@ minimist@^1.1.1, minimist@^1.2.0: version "1.2.0" resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.0.tgz#a35008b20f41383eec1fb914f4cd5df79a264284" +minimist@^1.2.5: + version "1.2.5" + resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.5.tgz#67d66014b66a6a8aaa0c083c5fd58df4e4e97602" + integrity sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw== + mixin-deep@^1.2.0: version "1.3.1" resolved "https://registry.yarnpkg.com/mixin-deep/-/mixin-deep-1.3.1.tgz#a49e7268dce1a0d9698e45326c5626df3543d0fe" @@ -3474,6 +3473,13 @@ mkdirp@0.x, mkdirp@^0.5.1: dependencies: minimist "0.0.8" +mkdirp@^0.5.3: + version "0.5.5" + resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.5.tgz#d91cefd62d1436ca0f41620e251288d420099def" + integrity sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ== + dependencies: + minimist "^1.2.5" + ms@0.7.3: version "0.7.3" resolved "https://registry.yarnpkg.com/ms/-/ms-0.7.3.tgz#708155a5e44e33f5fd0fc53e81d0d40a91be1fff" @@ -4042,10 +4048,10 @@ prepend-http@^2.0.0: resolved "https://registry.yarnpkg.com/prepend-http/-/prepend-http-2.0.0.tgz#e92434bfa5ea8c19f41cdfd401d741a3c819d897" integrity sha1-6SQ0v6XqjBn0HN/UAddBo8gZ2Jc= -prettier@^1.18.2: - version "1.18.2" - resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.18.2.tgz#6823e7c5900017b4bd3acf46fe9ac4b4d7bda9ea" - integrity sha512-OeHeMc0JhFE9idD4ZdtNibzY0+TPHSpSSb9h8FqtP+YnoZZ1sl8Vc9b1sasjfymH3SonAF4QcA2+mzHPhMvIiw== +prettier@^2.1.1: + version "2.1.1" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.1.1.tgz#d9485dd5e499daa6cb547023b87a6cf51bee37d6" + integrity sha512-9bY+5ZWCfqj3ghYBLxApy2zf6m+NJo5GzmLTpr9FsApsfjriNnS2dahWReHMi7qNPhhHl9SYHJs2cHZLgexNIw== pretty-format@^24.5.0: version "24.5.0" @@ -5028,28 +5034,33 @@ ts-node@8.0.3: source-map-support "^0.5.6" yn "^3.0.0" -tslib@^1.8.0, tslib@^1.8.1, tslib@^1.9.0: +tslib@^1.13.0: + version "1.13.0" + resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.13.0.tgz#c881e13cc7015894ed914862d276436fa9a47043" + integrity sha512-i/6DQjL8Xf3be4K/E6Wgpekn5Qasl1usyw++dAA35Ue5orEn65VIxOA+YvNNl9HV3qv70T7CNwjODHZrLwvd1Q== + +tslib@^1.8.1, tslib@^1.9.0: version "1.9.3" resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.3.tgz#d7e4dd79245d85428c4d7e4822a79917954ca286" integrity sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ== -tslint@^5.14.0: - version "5.14.0" - resolved "https://registry.yarnpkg.com/tslint/-/tslint-5.14.0.tgz#be62637135ac244fc9b37ed6ea5252c9eba1616e" - integrity sha512-IUla/ieHVnB8Le7LdQFRGlVJid2T/gaJe5VkjzRVSRR6pA2ODYrnfR1hmxi+5+au9l50jBwpbBL34txgv4NnTQ== +tslint@^6.1.3: + version "6.1.3" + resolved "https://registry.yarnpkg.com/tslint/-/tslint-6.1.3.tgz#5c23b2eccc32487d5523bd3a470e9aa31789d904" + integrity sha512-IbR4nkT96EQOvKE2PW/djGz8iGNeJ4rF2mBfiYaR/nvUWYKJhLwimoJKgjIFEIDibBtOevj7BqCRL4oHeWWUCg== dependencies: - babel-code-frame "^6.22.0" + "@babel/code-frame" "^7.0.0" builtin-modules "^1.1.1" chalk "^2.3.0" commander "^2.12.1" - diff "^3.2.0" + diff "^4.0.1" glob "^7.1.1" - js-yaml "^3.7.0" + js-yaml "^3.13.1" minimatch "^3.0.4" - mkdirp "^0.5.1" + mkdirp "^0.5.3" resolve "^1.3.2" semver "^5.3.0" - tslib "^1.8.0" + tslib "^1.13.0" tsutils "^2.29.0" tsutils@^2.29.0: