Skip to content

Commit

Permalink
fix(patch): ignore No newline at end of file
Browse files Browse the repository at this point in the history
  • Loading branch information
await-ovo committed Sep 8, 2022
1 parent b83d51e commit 139c48e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/plugin-commands-patching/src/patchCommit.ts
Expand Up @@ -95,4 +95,5 @@ async function diffFolders (folderA: string, folderB: string) {
.replace(new RegExp(`(a|b)${escapeStringRegexp(`/${normalizePath(folderBN)}/`)}`, 'g'), '$1/')
.replace(new RegExp(escapeStringRegexp(`${folderAN}/`), 'g'), '')
.replace(new RegExp(escapeStringRegexp(`${folderBN}/`), 'g'), '')
.replace(/.*No newline at end of file.*$/, '')
}
29 changes: 29 additions & 0 deletions packages/plugin-commands-patching/test/patch.test.ts
Expand Up @@ -16,6 +16,7 @@ describe('patch and commit', () => {
prepare({
dependencies: {
'is-positive': '1.0.0',
'safe-execa': '0.1.2',
},
})

Expand Down Expand Up @@ -83,4 +84,32 @@ describe('patch and commit', () => {
// If editDir already exists, it should throw an error
await expect(patchFn()).rejects.toThrow(`The target directory already exists: '${editDir}'`)
})

test('should work when there is a no eol error', async () => {
const output = await patch.handler(defaultPatchOption, ['safe-execa@0.1.2'])
const userPatchDir = output.substring(output.indexOf(':') + 1).trim()
const tempDir = os.tmpdir()

expect(userPatchDir).toContain(tempDir)
expect(fs.existsSync(userPatchDir)).toBe(true)
expect(fs.existsSync(userPatchDir.replace('/user', '/source'))).toBe(true)

expect(fs.existsSync(path.join(userPatchDir, 'lib/index.js'))).toBe(true)

fs.appendFileSync(path.join(userPatchDir, 'lib/index.js'), '\n// test patching', 'utf8')

await patchCommit.handler({
...DEFAULT_OPTS,
dir: process.cwd(),
}, [userPatchDir])

const { manifest } = await readProjectManifest(process.cwd())
expect(manifest.pnpm?.patchedDependencies).toStrictEqual({
'safe-execa@0.1.2': 'patches/safe-execa@0.1.2.patch',
})
const patchContent = fs.readFileSync('patches/safe-execa@0.1.2.patch', 'utf8')
expect(patchContent).toContain('diff --git')
expect(patchContent).toContain('// test patching')
expect(fs.readFileSync('node_modules/safe-execa/lib/index.js', 'utf8')).toContain('// test patching')
})
})

0 comments on commit 139c48e

Please sign in to comment.