Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .config/husky/commit-msg
Original file line number Diff line number Diff line change
@@ -1 +1 @@
yarn commit message lint
yarn commit message lint
2 changes: 1 addition & 1 deletion .config/husky/prepare-commit-msg
Original file line number Diff line number Diff line change
@@ -1 +1 @@
yarn commit message $@
yarn commit message $@
1,215 changes: 608 additions & 607 deletions .yarn/releases/yarn.mjs

Large diffs are not rendered by default.

1,215 changes: 608 additions & 607 deletions yarn/cli/dist/yarn.mjs

Large diffs are not rendered by default.

49 changes: 48 additions & 1 deletion yarn/plugin-tools/sources/current-yarn-executable.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { ppath } from '@yarnpkg/fslib'
import { xfs } from '@yarnpkg/fslib'

import { makeCurrentYarnExecutable } from './current-yarn-executable.js'
import { afterAllInstalled } from './hooks/after-all-installed.hook.js'
import { setupScriptEnvironment } from './hooks/setup-script-environment.hook.js'

const repoRoot = npath.toPortablePath(resolve(dirname(fileURLToPath(import.meta.url)), '../../..'))
Expand All @@ -27,7 +28,7 @@ const yarnExecutableNames: Array<Filename> =
const execFileAsync = async (
file: string,
args: Array<string>,
options: { env: NodeJS.ProcessEnv }
options: { cwd?: string; env?: NodeJS.ProcessEnv } = {}
): Promise<{ stdout: string; stderr: string }> =>
new Promise((resolvePromise, rejectPromise) => {
execFile(file, args, options, (error, stdout, stderr) => {
Expand Down Expand Up @@ -221,3 +222,49 @@ test('should forward node flags from managed node wrapper', async () => {

assert.ok(execArgv.includes('--conditions=raijin-managed-wrapper-test'))
})

test('should materialize Husky hooks as newline-terminated text files', async () => {
const cwd = await xfs.mktempPromise()
const hooksPath = ppath.join(cwd, '.config/husky')
const previousGitHubActions = process.env.GITHUB_ACTIONS
const previousImagePack = process.env.IMAGE_PACK

await execFileAsync('git', ['init'], { cwd: npath.fromPortablePath(cwd) })

delete process.env.GITHUB_ACTIONS
delete process.env.IMAGE_PACK

try {
await afterAllInstalled({ cwd } as Project)
} finally {
if (previousGitHubActions === undefined) {
delete process.env.GITHUB_ACTIONS
} else {
process.env.GITHUB_ACTIONS = previousGitHubActions
}

if (previousImagePack === undefined) {
delete process.env.IMAGE_PACK
} else {
process.env.IMAGE_PACK = previousImagePack
}
}

const hookNames: Array<Filename> = [
'commit-msg' as Filename,
'pre-commit' as Filename,
'prepare-commit-msg' as Filename,
]
const hooks = await Promise.all(
hookNames.map(async (name) => xfs.readFilePromise(ppath.join(hooksPath, name), 'utf-8'))
)
const { stdout } = await execFileAsync('git', ['config', 'core.hooksPath'], {
cwd: npath.fromPortablePath(cwd),
})

for (const hookContent of hooks) {
assert.match(hookContent, /\n$/)
}

assert.equal(stdout.trim(), npath.fromPortablePath(hooksPath))
})
9 changes: 5 additions & 4 deletions yarn/plugin-tools/sources/hooks/after-all-installed.hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ import type { SpawnSyncReturns } from 'node:child_process'

import { spawnSync } from 'node:child_process'

import { npath } from '@yarnpkg/fslib'
import { ppath } from '@yarnpkg/fslib'
import { xfs } from '@yarnpkg/fslib'

const hook = (command: string): string => `${command}`
const hook = (command: string): string => `${command}\n`
const preCommitHook = (): string => hook('yarn commit staged')

const git = (args: Array<string>): SpawnSyncReturns<string> =>
const git = (args: Array<string>, cwd?: string): SpawnSyncReturns<string> =>
// eslint-disable-next-line n/no-sync
spawnSync('git', args, { encoding: 'utf-8' })
spawnSync('git', args, { cwd, encoding: 'utf-8' })

export const afterAllInstalled = async (project: Project): Promise<void> => {
if (process.env.GITHUB_ACTIONS) {
Expand Down Expand Up @@ -51,7 +52,7 @@ export const afterAllInstalled = async (project: Project): Promise<void> => {
{ mode: 0o755 }
)

const { error } = git(['config', 'core.hooksPath', target])
const { error } = git(['config', 'core.hooksPath', target], npath.fromPortablePath(project.cwd))

if (error) throw error
}
Loading