Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update prettier and tslint #260

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions integration-tests/runIntegrationTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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], () => {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
17 changes: 8 additions & 9 deletions property-based-tests/executeTestCase.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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] = {
Expand All @@ -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 }
Expand All @@ -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 => {
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,
})
}
Expand All @@ -62,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")
}

Expand Down
2 changes: 1 addition & 1 deletion property-based-tests/testCases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/applyPatches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export function applyPatchesForApp({
return
}

files.forEach(filename => {
files.forEach((filename) => {
const packageDetails = getPackageDetailsFromPatchFilename(filename)

if (!packageDetails) {
Expand Down
6 changes: 3 additions & 3 deletions src/filterFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
}
3 changes: 2 additions & 1 deletion src/getPackageResolution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/makePatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand Down
4 changes: 3 additions & 1 deletion src/packageIsDevDependency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]],
)
}
2 changes: 1 addition & 1 deletion src/patch/apply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/patchFs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 []
}
Expand Down
68 changes: 34 additions & 34 deletions src/spawnSafe.ts
Original file line number Diff line number Diff line change
@@ -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
}
1 change: 1 addition & 0 deletions tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"extends": ["tslint:recommended"],
"jsRules": {},
"rules": {
"array-type": false,
"prefer-for-of": false,
"trailing-comma": [false],
"ordered-imports": [false],
Expand Down
Loading