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

sync(yarn-plugin-tools): dependencies, hooks adjustment #393

Merged
merged 1 commit into from
Aug 21, 2024
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 code/code-commit/src/lint/commitlint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,6 @@ export async function lint(
valid,
errors,
warnings,
input: buildCommitMesage(parsed),
input: buildCommitMessage(parsed),
}
}
24 changes: 12 additions & 12 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1369,15 +1369,15 @@ __metadata:
dependencies:
"@atls/code-runtime": "workspace:*"
"@atls/config-typescript": "workspace:*"
"@types/semver": "npm:^7.5.0"
"@yarnpkg/builder": "npm:^4.1.1"
"@yarnpkg/cli": "npm:^4.2.2"
"@yarnpkg/core": "npm:^4.0.5"
"@yarnpkg/fslib": "npm:^3.1.0"
clipanion: "npm:^4.0.0-rc.3"
deepmerge: "npm:^4.3.1"
husky: "npm:^8.0.3"
semver: "npm:^7.5.3"
"@types/semver": "npm:7.5.8"
"@yarnpkg/builder": "npm:4.1.2"
"@yarnpkg/cli": "npm:4.4.0"
"@yarnpkg/core": "npm:4.1.2"
"@yarnpkg/fslib": "npm:3.1.0"
clipanion: "npm:4.0.0-rc.3"
deepmerge: "npm:4.3.1"
husky: "npm:8.0.3"
semver: "npm:7.6.3"
languageName: unknown
linkType: soft

Expand Down Expand Up @@ -4270,7 +4270,7 @@ __metadata:
languageName: node
linkType: hard

"@types/semver@npm:7.5.8, @types/semver@npm:^7.1.0, @types/semver@npm:^7.5.0":
"@types/semver@npm:7.5.8, @types/semver@npm:^7.1.0":
version: 7.5.8
resolution: "@types/semver@npm:7.5.8"
checksum: 10/3496808818ddb36deabfe4974fd343a78101fa242c4690044ccdc3b95dcf8785b494f5d628f2f47f38a702f8db9c53c67f47d7818f2be1b79f2efb09692e1178
Expand Down Expand Up @@ -6851,7 +6851,7 @@ __metadata:
languageName: node
linkType: hard

"deepmerge@npm:*, deepmerge@npm:4.3.1, deepmerge@npm:^4.2.2, deepmerge@npm:^4.3.1":
"deepmerge@npm:*, deepmerge@npm:4.3.1, deepmerge@npm:^4.2.2":
version: 4.3.1
resolution: "deepmerge@npm:4.3.1"
checksum: 10/058d9e1b0ff1a154468bf3837aea436abcfea1ba1d165ddaaf48ca93765fdd01a30d33c36173da8fbbed951dd0a267602bc782fe288b0fc4b7e1e7091afc4529
Expand Down Expand Up @@ -9080,7 +9080,7 @@ __metadata:
languageName: node
linkType: hard

"husky@npm:^8.0.3":
"husky@npm:8.0.3":
version: 8.0.3
resolution: "husky@npm:8.0.3"
bin:
Expand Down
18 changes: 9 additions & 9 deletions yarn/plugin-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@
"dependencies": {
"@atls/code-runtime": "workspace:*",
"@atls/config-typescript": "workspace:*",
"clipanion": "^4.0.0-rc.3",
"deepmerge": "^4.3.1",
"husky": "^8.0.3",
"semver": "^7.5.3"
"clipanion": "4.0.0-rc.3",
"deepmerge": "4.3.1",
"husky": "8.0.3",
"semver": "7.6.3"
},
"devDependencies": {
"@types/semver": "^7.5.0",
"@yarnpkg/builder": "^4.1.1",
"@yarnpkg/cli": "^4.2.2",
"@yarnpkg/core": "^4.0.5",
"@yarnpkg/fslib": "^3.1.0"
"@types/semver": "7.5.8",
"@yarnpkg/builder": "4.1.2",
"@yarnpkg/cli": "4.4.0",
"@yarnpkg/core": "4.1.2",
"@yarnpkg/fslib": "3.1.0"
},
"publishConfig": {
"access": "public",
Expand Down
6 changes: 4 additions & 2 deletions yarn/plugin-tools/src/hooks/after-all-installed.hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ const hook = (command: string): string =>
${command}
`

const git = (args: Array<string>): SpawnSyncReturns<Buffer> =>
spawnSync('git', args, { stdio: 'inherit' })
const git = (args: Array<string>): SpawnSyncReturns<string> =>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TorinAsakura подсвечиваю момент для ревью - не понимаю в чем разница двух подходов

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. В первой версии spawnSync возвращает результат в виде Buffer, а во второй версии указываем encoding: 'utf-8', что автоматически конвертирует вывод команды в строку (string), поэтому возвращаемое значение будет уже строкой - короче, рассматривай это как perf(plugin-tools)

  2. В первой версии мы юзали опцию { stdio: 'inherit' }. Это означает, что spawnSync будет напрямую перенаправлять вывод (stdout, stderr) и ввод (stdin) процесса в консоль, а результат функции spawnSync будет содержать только status и signal, но не stdout и stderr (они будут undefined), а - во второй версии Андрюха убрал stdio: 'inherit' и добавил encoding: 'utf-8', что заставляет spawnSync возвращать строки в stdout и stderr, которые можно использовать для дальнейшей обработки в коде, короче, опять перф

  3. В первой версии мы просто передавали вывод команды напрямую в консоль, и не было возможности явно обрабатывать его результат, а во второй версии можно обрабатывать строки, возвращаемые командой git, внутри своего кода (анализировать вывод команды, проверять ошибки нуитд)

spawnSync('git', args, { encoding: 'utf-8' })

const hooksExists = (): boolean => {
const { error, output } = git(['config', 'core.hooksPath'])
Expand All @@ -87,9 +87,11 @@ export const afterAllInstalled = async (project: Project): Promise<void> => {
hook('yarn commit message lint'),
{ mode: 0o755 }
)

await xfs.writeFilePromise(ppath.join(target, 'pre-commit'), hook('yarn commit staged'), {
mode: 0o755,
})

await xfs.writeFilePromise(
ppath.join(target, 'prepare-commit-msg'),
hook('yarn commit message $@'),
Expand Down
2 changes: 1 addition & 1 deletion yarn/plugin-tools/src/hooks/after-yarn-version-set.hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { CommandContext } from '@yarnpkg/core'
import { execUtils } from '@yarnpkg/core'

export const afterYarnVersionSet = async (
configuration: Configuration,
_: Configuration,
context: CommandContext
): Promise<void> => {
await execUtils.pipevp('yarn', ['tools', 'sync'], {
Expand Down
Loading