Skip to content

make work with pnpm and git, use pnpm-lock.yaml #302

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

Closed
wants to merge 16 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
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

exports[`Test delete-scripts: a patch file got produced 1`] = `
"SNAPSHOT: a patch file got produced
# generated by patch-package 0.0.0 on 1980-01-01 00:00:00
#
# command:
# npx patch-package left-pad
#
# declared package:
# left-pad: file:/mocked/path/to/left-pad-1.3.0.tgz#5b8a3a7765dfe001261dde915589e782f8c94d1e
#
diff --git a/node_modules/left-pad/index.js b/node_modules/left-pad/index.js
index e90aec3..f2b8b0a 100644
--- a/node_modules/left-pad/index.js
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

exports[`Test file-mode-changes: the patch file 1`] = `
"SNAPSHOT: the patch file
# generated by patch-package 0.0.0 on 1980-01-01 00:00:00
#
# command:
# npx patch-package prettier
#
# declared package:
# prettier: file:/mocked/path/to/prettier-1.16.0.tgz#104dd25f5ee3d0c9d0a6ce4bb40ced8481d51219
#
diff --git a/node_modules/prettier/bin-prettier.js b/node_modules/prettier/bin-prettier.js
old mode 100755
new mode 100644
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ END SNAPSHOT"

exports[`Test happy-path-npm: the patch looks like this 1`] = `
"SNAPSHOT: the patch looks like this
# generated by patch-package 0.0.0 on 1980-01-01 00:00:00
#
# command:
# npx patch-package left-pad
#
# declared package:
# left-pad: file:/mocked/path/to/left-pad-1.1.3.tgz
#
diff --git a/node_modules/left-pad/index.js b/node_modules/left-pad/index.js
index 26f73ff..d4cc4af 100644
--- a/node_modules/left-pad/index.js
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ END SNAPSHOT"

exports[`Test happy-path-yarn: the patch looks like this 1`] = `
"SNAPSHOT: the patch looks like this
# generated by patch-package 0.0.0 on 1980-01-01 00:00:00
#
# command:
# npx patch-package left-pad
#
# declared package:
# left-pad: file:/mocked/path/to/left-pad-1.1.3.tgz#612f61c033f3a9e08e939f1caebeea41b6f3199a
#
diff --git a/node_modules/left-pad/index.js b/node_modules/left-pad/index.js
index 26f73ff..b083802 100644
--- a/node_modules/left-pad/index.js
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ END SNAPSHOT"

exports[`Test ignore-whitespace: line a changed 1`] = `
"SNAPSHOT: line a changed
# generated by patch-package 0.0.0 on 1980-01-01 00:00:00
#
# command:
# npx patch-package alphabet
#
# declared package:
# alphabet: file:/mocked/path/to/alphabet
#
diff --git a/node_modules/alphabet/index.js b/node_modules/alphabet/index.js
index 7811d3b..454414b 100644
--- a/node_modules/alphabet/index.js
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

exports[`Test ignores-scripts-when-making-patch: a patch file got produced 1`] = `
"SNAPSHOT: a patch file got produced
# generated by patch-package 0.0.0 on 1980-01-01 00:00:00
#
# command:
# npx patch-package naughty-package
#
# declared package:
# naughty-package: file:/mocked/path/to/naughty-package
#
diff --git a/node_modules/naughty-package/postinstall.sh b/node_modules/naughty-package/postinstall.sh
index 3784520..c4af29c 100755
--- a/node_modules/naughty-package/postinstall.sh
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

exports[`Test include-exclude-paths: exclude all but flip 1`] = `
"SNAPSHOT: exclude all but flip
# generated by patch-package 0.0.0 on 1980-01-01 00:00:00
#
# command:
# npx patch-package lodash --exclude '^(?!.*flip)'
#
# declared package:
# lodash: file:/mocked/path/to/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae
#
diff --git a/node_modules/lodash/flip.js b/node_modules/lodash/flip.js
index c28dd78..584b377 100644
--- a/node_modules/lodash/flip.js
Expand All @@ -17,6 +25,14 @@ END SNAPSHOT"

exports[`Test include-exclude-paths: modified package.json 1`] = `
"SNAPSHOT: modified package.json
# generated by patch-package 0.0.0 on 1980-01-01 00:00:00
#
# command:
# npx patch-package lodash --exclude '^$'
#
# declared package:
# lodash: file:/mocked/path/to/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae
#
diff --git a/node_modules/lodash/package.json b/node_modules/lodash/package.json
index 028960d..7d346f3 100644
--- a/node_modules/lodash/package.json
Expand All @@ -35,6 +51,14 @@ END SNAPSHOT"

exports[`Test include-exclude-paths: no base files 1`] = `
"SNAPSHOT: no base files
# generated by patch-package 0.0.0 on 1980-01-01 00:00:00
#
# command:
# npx patch-package lodash --exclude base
#
# declared package:
# lodash: file:/mocked/path/to/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae
#
diff --git a/node_modules/lodash/flip.js b/node_modules/lodash/flip.js
index c28dd78..584b377 100644
--- a/node_modules/lodash/flip.js
Expand Down Expand Up @@ -64,6 +88,14 @@ END SNAPSHOT"

exports[`Test include-exclude-paths: only __.js being deleted 1`] = `
"SNAPSHOT: only __.js being deleted
# generated by patch-package 0.0.0 on 1980-01-01 00:00:00
#
# command:
# npx patch-package lodash --include __
#
# declared package:
# lodash: file:/mocked/path/to/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae
#
diff --git a/node_modules/lodash/fp/__.js b/node_modules/lodash/fp/__.js
deleted file mode 100644
index 4af98de..0000000
Expand All @@ -76,6 +108,14 @@ END SNAPSHOT"

exports[`Test include-exclude-paths: only base files, no clone files 1`] = `
"SNAPSHOT: only base files, no clone files
# generated by patch-package 0.0.0 on 1980-01-01 00:00:00
#
# command:
# npx patch-package lodash --include base --exclude clone
#
# declared package:
# lodash: file:/mocked/path/to/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae
#
diff --git a/node_modules/lodash/_baseClamp.js b/node_modules/lodash/_baseClamp.js
index a1c5692..c52e38e 100644
--- a/node_modules/lodash/_baseClamp.js
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ END SNAPSHOT"

exports[`Test lerna-canary: the patch looks like this 1`] = `
"SNAPSHOT: the patch looks like this
# generated by patch-package 0.0.0 on 1980-01-01 00:00:00
#
# command:
# npx patch-package @parcel/codeframe
#
# declared package:
# @parcel/codeframe: file:/mocked/path/to/codeframe-2.0.0-nightly.137.tgz#b8bfc2ccf223d6a26eaad193fc26c029f7e14d4f
#
diff --git a/node_modules/@parcel/codeframe/src/codeframe.js b/node_modules/@parcel/codeframe/src/codeframe.js
index 2bf2c1c..ef0695b 100644
--- a/node_modules/@parcel/codeframe/src/codeframe.js
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ END SNAPSHOT"

exports[`Test nested-packages: the patch file contents 1`] = `
"SNAPSHOT: the patch file contents
# generated by patch-package 0.0.0 on 1980-01-01 00:00:00
#
# command:
# npx patch-package wrap-ansi/string-width
#
# declared package:
# string-width: file:/mocked/path/to/string-width-2.1.1.tgz#ab93f27a8dc13d28cac815c462143a6d9012ae9e
#
diff --git a/node_modules/wrap-ansi/node_modules/string-width/index.js b/node_modules/wrap-ansi/node_modules/string-width/index.js
index bbc49d2..6407f49 100644
--- a/node_modules/wrap-ansi/node_modules/string-width/index.js
Expand Down
11 changes: 8 additions & 3 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 All @@ -18,7 +18,10 @@ export function runIntegrationTest({
shouldProduceSnapshots: boolean
}) {
describe(`Test ${projectName}:`, () => {
const tmpDir = tmp.dirSync({ unsafeCleanup: true })
const tmpDir = tmp.dirSync({
unsafeCleanup: true,
prefix: "patch-package.test-integration.",
})
fs.copySync(join(__dirname, projectName), tmpDir.name, {
recursive: true,
})
Expand Down Expand Up @@ -64,7 +67,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 All @@ -80,5 +83,7 @@ export function runIntegrationTest({
expect(snapshots && snapshots.length).toBeFalsy()
})
}

tmpDir.removeCallback()
})
}
15 changes: 9 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "patch-package",
"version": "6.4.7",
"name": "@milahu/patch-package-with-pnpm-support",
"version": "6.4.8",
"description": "Fix broken node modules with no fuss",
"main": "dist/index.js",
"repository": "github:ds300/patch-package",
Expand All @@ -13,13 +13,14 @@
"patch-package": "./index.js"
},
"scripts": {
"prepublishOnly": "yarn run clean && yarn run build",
"prepublishOnly": "npm run clean && npm run build",
"build": "tsc --project tsconfig.build.json",
"new-integration-test": "ts-node integration-tests/newIntegrationTest.ts",
"clean": "rimraf dist patch-package.test*.tgz",
"format": "prettier --no-semi --write --trailing-comma=all src{/**,}/*.ts integration-tests{/**,}/*.ts property-based-tests{/**,}/*.ts",
"prepack": "rimraf dist/**/*.test.js",
"test": "./run-tests.sh --runInBand"
"test": "./run-tests.sh --runInBand",
"prepare": "npm run build"
},
"husky": {
"hooks": {
Expand Down Expand Up @@ -54,13 +55,13 @@
"@types/fs-extra": "^5.0.5",
"@types/is-ci": "^1.1.0",
"@types/jest": "^24.0.11",
"@types/minimist": "^1.2.0",
"@types/node": "^11.11.6",
"@types/rimraf": "^2.0.2",
"@types/semver": "^5.5.0",
"@types/tmp": "^0.0.34",
"husky": "^1.3.1",
"jest": "^24.5.0",
"js-yaml": "^4.0.0",
"lint-staged": "^8.1.5",
"np": "^7.4.0",
"prettier": "^2.2.1",
Expand All @@ -71,17 +72,19 @@
"typescript": "^4.2.2"
},
"dependencies": {
"@types/dashdash": "^1.14.0",
"@yarnpkg/lockfile": "^1.1.0",
"chalk": "^2.4.2",
"cross-spawn": "^6.0.5",
"dashdash": "^2.0.0",
"find-yarn-workspace-root": "^2.0.0",
"fs-extra": "^7.0.1",
"is-ci": "^2.0.0",
"klaw-sync": "^6.0.0",
"minimist": "^1.2.0",
"open": "^7.4.2",
"rimraf": "^2.6.3",
"semver": "^5.6.0",
"shlex": "^2.0.2",
"slash": "^2.0.0",
"tmp": "^0.0.33"
},
Expand Down
29 changes: 17 additions & 12 deletions property-based-tests/executeTestCase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,31 @@ jest.mock("fs-extra", () => {
setWorkingFiles,
getWorkingFiles,
ensureDirSync: jest.fn(),
readFileSync: jest.fn(path => getWorkingFiles()[path].contents),
readFileSync: jest.fn((filePath) => getWorkingFiles()[filePath].contents),
writeFileSync: jest.fn(
(path: string, contents: string, opts?: { mode?: number }) => {
getWorkingFiles()[path] = {
(filePath: string, contents: string, opts?: { mode?: number }) => {
getWorkingFiles()[filePath] = {
contents,
mode: opts && typeof opts.mode === "number" ? opts.mode : 0o644,
}
},
),
unlinkSync: jest.fn(path => delete getWorkingFiles()[path]),
unlinkSync: jest.fn((filePath) => delete getWorkingFiles()[filePath]),
moveSync: jest.fn((from, to) => {
getWorkingFiles()[to] = getWorkingFiles()[from]
delete getWorkingFiles()[from]
}),
statSync: jest.fn(path => getWorkingFiles()[path]),
chmodSync: jest.fn((path, mode) => {
const { contents } = getWorkingFiles()[path]
getWorkingFiles()[path] = { contents, mode }
statSync: jest.fn((filePath) => getWorkingFiles()[filePath]),
chmodSync: jest.fn((filePath, mode) => {
const { contents } = getWorkingFiles()[filePath]
getWorkingFiles()[filePath] = { contents, mode }
}),
}
})

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, {
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 All @@ -83,7 +82,11 @@ export function executeTestCase(testCase: TestCase) {
}
}

const tmpDir = tmp.dirSync({ unsafeCleanup: true, mode: 0o100777 })
const tmpDir = tmp.dirSync({
unsafeCleanup: true,
mode: 0o100777,
prefix: "patch-package.test-property.",
})

spawnSafeSync("git", ["init"], { cwd: tmpDir.name })

Expand Down Expand Up @@ -145,4 +148,6 @@ export function executeTestCase(testCase: TestCase) {
expect(fs.getWorkingFiles()).toEqual(testCase.cleanFiles)
})
})

tmpDir.removeCallback()
}
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
3 changes: 3 additions & 0 deletions run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ yarn version --new-version 0.0.0 --no-git-tag-version --no-commit-hooks
yarn pack --filename patch-package.test.$(date +%s).tgz
yarn version --new-version $version --no-git-tag-version --no-commit-hooks
yarn jest "$@"

# workaround for https://github.com/yarnpkg/yarn/issues/6685
rm -rf /tmp/yarn--* || true
Loading