@alxwlw/stack 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/canon/catalogs.json +50 -0
- package/canon/files/dependabot.template.yml +10 -0
- package/canon/files/dependency-cruiser.base.cjs +179 -0
- package/canon/files/editorconfig +13 -0
- package/canon/files/gitleaks-canon.toml +75 -0
- package/canon/files/gitleaks-local.template.toml +12 -0
- package/canon/files/knip.base.json +7 -0
- package/canon/files/markdownlint-cli2.jsonc +123 -0
- package/canon/files/markdownlintignore.template +4 -0
- package/canon/files/moon-tasks/bun-test.yml +17 -0
- package/canon/files/moon-tasks/oxfmt.yml +14 -0
- package/canon/files/moon-tasks/oxlint.yml +34 -0
- package/canon/files/moon-tasks/stack.yml +15 -0
- package/canon/files/moon-tasks/typescript.yml +32 -0
- package/canon/files/oxfmtrc.jsonc +23 -0
- package/canon/files/oxlintrc.template.json +6 -0
- package/canon/files/prettierignore.template +1 -0
- package/canon/files/proto-plugins/actionlint.toml +27 -0
- package/canon/files/proto-plugins/gitleaks.toml +27 -0
- package/canon/files/proto-plugins/shellcheck.toml +23 -0
- package/canon/files/prototools +18 -0
- package/canon/files/tsconfig.options.template.json +5 -0
- package/canon/files/workflow-stack-check-infra.yml +10 -0
- package/canon/files/workflow-stack-check.yml +8 -0
- package/canon/files/workflow-stack-sync.yml +16 -0
- package/canon/files/yamllint +66 -0
- package/canon/files/yamllint-canon-ignores +14 -0
- package/canon/files/yamllint-local-ignores.template +5 -0
- package/canon/manifest.json +158 -0
- package/package.json +27 -0
- package/schema.json +48 -0
- package/src/catalogs.ts +101 -0
- package/src/check.ts +27 -0
- package/src/cli.ts +75 -0
- package/src/config.ts +70 -0
- package/src/deps.ts +134 -0
- package/src/files.ts +75 -0
- package/src/findings.ts +19 -0
- package/src/init.ts +29 -0
- package/src/manifest.ts +33 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
name = "actionlint"
|
|
2
|
+
type = "cli"
|
|
3
|
+
|
|
4
|
+
[resolve]
|
|
5
|
+
git-url = "https://github.com/rhysd/actionlint"
|
|
6
|
+
|
|
7
|
+
[platform.linux]
|
|
8
|
+
download-file = "actionlint_{version}_linux_{arch}.tar.gz"
|
|
9
|
+
checksum-file = "actionlint_{version}_checksums.txt"
|
|
10
|
+
|
|
11
|
+
[platform.macos]
|
|
12
|
+
download-file = "actionlint_{version}_darwin_{arch}.tar.gz"
|
|
13
|
+
checksum-file = "actionlint_{version}_checksums.txt"
|
|
14
|
+
|
|
15
|
+
[platform.windows]
|
|
16
|
+
download-file = "actionlint_{version}_windows_{arch}.zip"
|
|
17
|
+
checksum-file = "actionlint_{version}_checksums.txt"
|
|
18
|
+
|
|
19
|
+
[install]
|
|
20
|
+
download-url = "https://github.com/rhysd/actionlint/releases/download/v{version}/{download_file}"
|
|
21
|
+
checksum-url = "https://github.com/rhysd/actionlint/releases/download/v{version}/{checksum_file}"
|
|
22
|
+
|
|
23
|
+
[install.arch]
|
|
24
|
+
arm = "armv6"
|
|
25
|
+
aarch64 = "arm64"
|
|
26
|
+
x86 = "386"
|
|
27
|
+
x86_64 = "amd64"
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
name = "Gitleaks"
|
|
2
|
+
type = "cli"
|
|
3
|
+
|
|
4
|
+
[resolve]
|
|
5
|
+
git-url = "https://github.com/gitleaks/gitleaks"
|
|
6
|
+
|
|
7
|
+
[platform.linux]
|
|
8
|
+
download-file = "gitleaks_{version}_linux_{arch}.tar.gz"
|
|
9
|
+
checksum-file = "gitleaks_{version}_checksums.txt"
|
|
10
|
+
|
|
11
|
+
[platform.macos]
|
|
12
|
+
download-file = "gitleaks_{version}_darwin_{arch}.tar.gz"
|
|
13
|
+
checksum-file = "gitleaks_{version}_checksums.txt"
|
|
14
|
+
|
|
15
|
+
[platform.windows]
|
|
16
|
+
download-file = "gitleaks_{version}_windows_{arch}.zip"
|
|
17
|
+
checksum-file = "gitleaks_{version}_checksums.txt"
|
|
18
|
+
|
|
19
|
+
[install]
|
|
20
|
+
download-url = "https://github.com/gitleaks/gitleaks/releases/download/v{version}/{download_file}"
|
|
21
|
+
checksum-url = "https://github.com/gitleaks/gitleaks/releases/download/v{version}/{checksum_file}"
|
|
22
|
+
|
|
23
|
+
[install.arch]
|
|
24
|
+
arm = "armv6"
|
|
25
|
+
aarch64 = "arm64"
|
|
26
|
+
x86 = "x32"
|
|
27
|
+
x86_64 = "x64"
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
name = "ShellCheck"
|
|
2
|
+
type = "cli"
|
|
3
|
+
|
|
4
|
+
[resolve]
|
|
5
|
+
git-url = "https://github.com/koalaman/shellcheck"
|
|
6
|
+
|
|
7
|
+
[platform.linux]
|
|
8
|
+
download-file = "shellcheck-v{version}.linux.{arch}.tar.xz"
|
|
9
|
+
archive-prefix = "shellcheck-v{version}"
|
|
10
|
+
|
|
11
|
+
[platform.macos]
|
|
12
|
+
download-file = "shellcheck-v{version}.darwin.{arch}.tar.xz"
|
|
13
|
+
archive-prefix = "shellcheck-v{version}"
|
|
14
|
+
|
|
15
|
+
[platform.windows]
|
|
16
|
+
download-file = "shellcheck-v{version}.zip"
|
|
17
|
+
archive-prefix = "shellcheck-v{version}"
|
|
18
|
+
|
|
19
|
+
[install]
|
|
20
|
+
download-url = "https://github.com/koalaman/shellcheck/releases/download/v{version}/{download_file}"
|
|
21
|
+
|
|
22
|
+
[install.arch]
|
|
23
|
+
arm = "armv6hf"
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Canon pins. This file is sync-managed: edits happen in alxwlw/stack, not here.
|
|
2
|
+
proto = "0.60.2"
|
|
3
|
+
node = "26.8.1"
|
|
4
|
+
pnpm = "11.15.0"
|
|
5
|
+
bun = "1.4.2"
|
|
6
|
+
moon = "2.5.5"
|
|
7
|
+
uv = "0.11.29"
|
|
8
|
+
|
|
9
|
+
# Guardrail binaries: versions pinned for reproducibility.
|
|
10
|
+
actionlint = "1.7.12"
|
|
11
|
+
shellcheck = "0.11.0"
|
|
12
|
+
gitleaks = "8.30.1"
|
|
13
|
+
|
|
14
|
+
[plugins]
|
|
15
|
+
# Vendored: upstream github.com/Phault/proto-toml-plugins was removed 2026-09-13, its URL now returns 404.
|
|
16
|
+
actionlint = "file://./.moon/proto-plugins/actionlint.toml"
|
|
17
|
+
shellcheck = "file://./.moon/proto-plugins/shellcheck.toml"
|
|
18
|
+
gitleaks = "file://./.moon/proto-plugins/gitleaks.toml"
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
name: stack sync
|
|
2
|
+
on:
|
|
3
|
+
workflow_dispatch:
|
|
4
|
+
inputs:
|
|
5
|
+
version:
|
|
6
|
+
required: true
|
|
7
|
+
type: string
|
|
8
|
+
jobs:
|
|
9
|
+
sync:
|
|
10
|
+
uses: alxwlw/stack/.github/workflows/sync.yml@v1
|
|
11
|
+
with:
|
|
12
|
+
version: ${{ inputs.version }}
|
|
13
|
+
install: ${{ vars.STACK_SYNC_INSTALL != 'false' }}
|
|
14
|
+
secrets:
|
|
15
|
+
app-id: ${{ secrets.STACK_BOT_APP_ID }}
|
|
16
|
+
app-private-key: ${{ secrets.STACK_BOT_PRIVATE_KEY }}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# yamllint config — stack canon (sync-managed verbatim; never edit in a repo).
|
|
2
|
+
#
|
|
3
|
+
# Focus: catch semantic bugs (duplicate keys, truthy gotchas, broken
|
|
4
|
+
# structure) that a formatter can't catch. oxfmt still handles indentation,
|
|
5
|
+
# line length, and trailing spaces — we disable those here to avoid fighting
|
|
6
|
+
# between the two tools.
|
|
7
|
+
#
|
|
8
|
+
# Scope: all *.yml / *.yaml files in the repo except build artifacts and
|
|
9
|
+
# vendored content (see ignore list below).
|
|
10
|
+
|
|
11
|
+
extends: default
|
|
12
|
+
|
|
13
|
+
yaml-files:
|
|
14
|
+
- '*.yaml'
|
|
15
|
+
- '*.yml'
|
|
16
|
+
|
|
17
|
+
# Canon-wide ignores live in the sync-managed .yamllint-canon-ignores;
|
|
18
|
+
# repo-local additions go in .yamllint-ignores (seeded by `stack sync`,
|
|
19
|
+
# repo-owned).
|
|
20
|
+
ignore-from-file: ['.yamllint-canon-ignores', '.yamllint-ignores']
|
|
21
|
+
|
|
22
|
+
rules:
|
|
23
|
+
# Formatting handled by oxfmt — don't duplicate
|
|
24
|
+
indentation: disable
|
|
25
|
+
line-length: disable
|
|
26
|
+
trailing-spaces: disable
|
|
27
|
+
new-line-at-end-of-file: disable
|
|
28
|
+
empty-lines: disable
|
|
29
|
+
commas: disable
|
|
30
|
+
hyphens: disable
|
|
31
|
+
brackets: disable
|
|
32
|
+
braces: disable
|
|
33
|
+
colons: disable
|
|
34
|
+
|
|
35
|
+
# Semantic checks — the real value
|
|
36
|
+
key-duplicates: enable
|
|
37
|
+
octal-values:
|
|
38
|
+
forbid-implicit-octal: true
|
|
39
|
+
forbid-explicit-octal: false
|
|
40
|
+
# empty-values: disabled — too strict for Docker Compose volumes:
|
|
41
|
+
# (auto-create volumes with `name:` and no body) and GitHub Actions
|
|
42
|
+
# workflow_dispatch: (valid trigger with no options).
|
|
43
|
+
empty-values: disable
|
|
44
|
+
|
|
45
|
+
# Truthy: allow only strict true/false in values. Allow top-level
|
|
46
|
+
# `on:` key for GitHub Actions workflows (very common pattern).
|
|
47
|
+
truthy:
|
|
48
|
+
allowed-values: ['true', 'false']
|
|
49
|
+
check-keys: false
|
|
50
|
+
|
|
51
|
+
# Comments: accept both `# comment` and `#comment` styles used
|
|
52
|
+
# throughout the repo; only require one space from content
|
|
53
|
+
comments:
|
|
54
|
+
require-starting-space: false
|
|
55
|
+
min-spaces-from-content: 1
|
|
56
|
+
comments-indentation: disable
|
|
57
|
+
|
|
58
|
+
# Document start/end markers are optional — repo doesn't use them
|
|
59
|
+
document-start: disable
|
|
60
|
+
document-end: disable
|
|
61
|
+
|
|
62
|
+
# Anchors/aliases: catch duplicates and unused
|
|
63
|
+
anchors:
|
|
64
|
+
forbid-undeclared-aliases: true
|
|
65
|
+
forbid-duplicated-anchors: true
|
|
66
|
+
forbid-unused-anchors: false
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Org-canon yamllint ignore patterns (sync-managed verbatim — do not edit;
|
|
2
|
+
# repo-local additions belong in .yamllint-ignores). gitignore-style.
|
|
3
|
+
node_modules/
|
|
4
|
+
**/node_modules/
|
|
5
|
+
dist/
|
|
6
|
+
**/dist/
|
|
7
|
+
.tsbuild/
|
|
8
|
+
**/.tsbuild/
|
|
9
|
+
coverage/
|
|
10
|
+
**/coverage/
|
|
11
|
+
.next/
|
|
12
|
+
**/.next/
|
|
13
|
+
.moon/cache/
|
|
14
|
+
**/.moon/cache/
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# Repo-local yamllint ignores — YOURS to edit (seeded once by
|
|
2
|
+
# `stack sync`, never overwritten). gitignore-style patterns.
|
|
3
|
+
# The rule set + canon-wide ignores live in the sync-managed .yamllint /
|
|
4
|
+
# .yamllint-canon-ignores — never edit those; add repo-specific paths HERE
|
|
5
|
+
# (vendored fixtures, generated YAML, state dirs, …).
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
{
|
|
2
|
+
"files": [
|
|
3
|
+
{
|
|
4
|
+
"src": "files/editorconfig",
|
|
5
|
+
"dest": ".editorconfig",
|
|
6
|
+
"appliesTo": ["node", "contracts", "infra"]
|
|
7
|
+
},
|
|
8
|
+
{
|
|
9
|
+
"src": "files/gitleaks-canon.toml",
|
|
10
|
+
"dest": ".gitleaks.canon.toml",
|
|
11
|
+
"appliesTo": ["node", "contracts", "infra"]
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"src": "files/gitleaks-local.template.toml",
|
|
15
|
+
"dest": ".gitleaks.toml",
|
|
16
|
+
"appliesTo": ["node", "contracts", "infra"],
|
|
17
|
+
"strategy": "create-if-absent"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"src": "files/markdownlint-cli2.jsonc",
|
|
21
|
+
"dest": ".markdownlint-cli2.jsonc",
|
|
22
|
+
"appliesTo": ["node", "contracts", "infra"]
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"src": "files/markdownlintignore.template",
|
|
26
|
+
"dest": ".markdownlintignore",
|
|
27
|
+
"appliesTo": ["node", "contracts", "infra"],
|
|
28
|
+
"strategy": "create-if-absent"
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"src": "files/yamllint",
|
|
32
|
+
"dest": ".yamllint",
|
|
33
|
+
"appliesTo": ["node", "contracts", "infra"]
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"src": "files/yamllint-canon-ignores",
|
|
37
|
+
"dest": ".yamllint-canon-ignores",
|
|
38
|
+
"appliesTo": ["node", "contracts", "infra"]
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"src": "files/yamllint-local-ignores.template",
|
|
42
|
+
"dest": ".yamllint-ignores",
|
|
43
|
+
"appliesTo": ["node", "contracts", "infra"],
|
|
44
|
+
"strategy": "create-if-absent"
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"src": "files/prototools",
|
|
48
|
+
"dest": ".prototools",
|
|
49
|
+
"appliesTo": ["node", "contracts", "infra"]
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
"src": "files/proto-plugins/actionlint.toml",
|
|
53
|
+
"dest": ".moon/proto-plugins/actionlint.toml",
|
|
54
|
+
"appliesTo": ["node", "contracts", "infra"]
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
"src": "files/proto-plugins/shellcheck.toml",
|
|
58
|
+
"dest": ".moon/proto-plugins/shellcheck.toml",
|
|
59
|
+
"appliesTo": ["node", "contracts", "infra"]
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
"src": "files/proto-plugins/gitleaks.toml",
|
|
63
|
+
"dest": ".moon/proto-plugins/gitleaks.toml",
|
|
64
|
+
"appliesTo": ["node", "contracts", "infra"]
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
"src": "files/oxfmtrc.jsonc",
|
|
68
|
+
"dest": ".oxfmtrc.jsonc",
|
|
69
|
+
"appliesTo": ["node", "contracts"]
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
"src": "files/prettierignore.template",
|
|
73
|
+
"dest": ".prettierignore",
|
|
74
|
+
"appliesTo": ["node", "contracts"],
|
|
75
|
+
"strategy": "create-if-absent"
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
"src": "files/dependabot.template.yml",
|
|
79
|
+
"dest": ".github/dependabot.yml",
|
|
80
|
+
"appliesTo": ["node", "contracts"],
|
|
81
|
+
"strategy": "create-if-absent"
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
"src": "files/oxlintrc.template.json",
|
|
85
|
+
"dest": ".oxlintrc.json",
|
|
86
|
+
"appliesTo": ["node", "contracts"],
|
|
87
|
+
"strategy": "create-if-absent"
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
"src": "files/tsconfig.options.template.json",
|
|
91
|
+
"dest": "tsconfig.options.json",
|
|
92
|
+
"appliesTo": ["node", "contracts"],
|
|
93
|
+
"strategy": "create-if-absent"
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
"src": "files/moon-tasks/typescript.yml",
|
|
97
|
+
"dest": ".moon/tasks/typescript.yml",
|
|
98
|
+
"appliesTo": ["node", "contracts"],
|
|
99
|
+
"strategy": "create-if-absent",
|
|
100
|
+
"group": "moon-tasks"
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
"src": "files/moon-tasks/oxlint.yml",
|
|
104
|
+
"dest": ".moon/tasks/oxlint.yml",
|
|
105
|
+
"appliesTo": ["node", "contracts"],
|
|
106
|
+
"strategy": "create-if-absent",
|
|
107
|
+
"group": "moon-tasks"
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
"src": "files/moon-tasks/oxfmt.yml",
|
|
111
|
+
"dest": ".moon/tasks/oxfmt.yml",
|
|
112
|
+
"appliesTo": ["node", "contracts"],
|
|
113
|
+
"strategy": "create-if-absent",
|
|
114
|
+
"group": "moon-tasks"
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
"src": "files/moon-tasks/bun-test.yml",
|
|
118
|
+
"dest": ".moon/tasks/bun-test.yml",
|
|
119
|
+
"appliesTo": ["node", "contracts"],
|
|
120
|
+
"strategy": "create-if-absent",
|
|
121
|
+
"group": "moon-tasks"
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
"src": "files/moon-tasks/stack.yml",
|
|
125
|
+
"dest": ".moon/tasks/stack.yml",
|
|
126
|
+
"appliesTo": ["node", "contracts", "infra"],
|
|
127
|
+
"strategy": "create-if-absent",
|
|
128
|
+
"group": "moon-tasks"
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
"src": "files/knip.base.json",
|
|
132
|
+
"dest": "knip.base.json",
|
|
133
|
+
"appliesTo": ["node"],
|
|
134
|
+
"group": "knip"
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
"src": "files/dependency-cruiser.base.cjs",
|
|
138
|
+
"dest": ".dependency-cruiser.base.cjs",
|
|
139
|
+
"appliesTo": ["node", "contracts"],
|
|
140
|
+
"group": "depcruise"
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
"src": "files/workflow-stack-check.yml",
|
|
144
|
+
"dest": ".github/workflows/stack-check.yml",
|
|
145
|
+
"appliesTo": ["node", "contracts"]
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
"src": "files/workflow-stack-check-infra.yml",
|
|
149
|
+
"dest": ".github/workflows/stack-check.yml",
|
|
150
|
+
"appliesTo": ["infra"]
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
"src": "files/workflow-stack-sync.yml",
|
|
154
|
+
"dest": ".github/workflows/stack-sync.yml",
|
|
155
|
+
"appliesTo": ["node", "contracts", "infra"]
|
|
156
|
+
}
|
|
157
|
+
]
|
|
158
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@alxwlw/stack",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/alxwlw/stack.git"
|
|
8
|
+
},
|
|
9
|
+
"bin": {
|
|
10
|
+
"stack": "src/cli.ts"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"src",
|
|
14
|
+
"!src/**/*.test.ts",
|
|
15
|
+
"canon",
|
|
16
|
+
"schema.json"
|
|
17
|
+
],
|
|
18
|
+
"type": "module",
|
|
19
|
+
"publishConfig": {
|
|
20
|
+
"access": "public",
|
|
21
|
+
"provenance": true
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"jsonc-parser": "^3.3.1",
|
|
25
|
+
"yaml": "^2.9.1"
|
|
26
|
+
}
|
|
27
|
+
}
|
package/schema.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
+
"title": "stack config (.stack.jsonc)",
|
|
4
|
+
"type": "object",
|
|
5
|
+
"properties": {
|
|
6
|
+
"$schema": { "type": "string" },
|
|
7
|
+
"profile": {
|
|
8
|
+
"type": "string",
|
|
9
|
+
"enum": ["node", "contracts", "infra"],
|
|
10
|
+
"description": "Repo profile: picks which canon verbatim files get synced."
|
|
11
|
+
},
|
|
12
|
+
"with": {
|
|
13
|
+
"type": "array",
|
|
14
|
+
"description": "Opt-in canon groups.",
|
|
15
|
+
"items": {
|
|
16
|
+
"type": "string",
|
|
17
|
+
"enum": ["moon-tasks", "libs", "knip", "depcruise"]
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"exceptions": {
|
|
21
|
+
"type": "array",
|
|
22
|
+
"description": "Suppressed `stack check` findings. Each exception addresses exactly one canon file or exactly one catalog entry.",
|
|
23
|
+
"items": {
|
|
24
|
+
"type": "object",
|
|
25
|
+
"additionalProperties": false,
|
|
26
|
+
"properties": {
|
|
27
|
+
"file": { "type": "string", "minLength": 1 },
|
|
28
|
+
"catalog": { "type": "string", "minLength": 1 },
|
|
29
|
+
"name": { "type": "string", "minLength": 1 },
|
|
30
|
+
"reason": { "type": "string", "minLength": 1 }
|
|
31
|
+
},
|
|
32
|
+
"required": ["reason"],
|
|
33
|
+
"oneOf": [
|
|
34
|
+
{
|
|
35
|
+
"required": ["file"],
|
|
36
|
+
"not": { "anyOf": [{ "required": ["catalog"] }, { "required": ["name"] }] }
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"required": ["catalog", "name"],
|
|
40
|
+
"not": { "required": ["file"] }
|
|
41
|
+
}
|
|
42
|
+
]
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"required": ["profile"],
|
|
47
|
+
"additionalProperties": false
|
|
48
|
+
}
|
package/src/catalogs.ts
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
|
|
4
|
+
import { parseDocument } from 'yaml';
|
|
5
|
+
|
|
6
|
+
import type { StackConfig } from './config.ts';
|
|
7
|
+
import type { Finding } from './findings.ts';
|
|
8
|
+
import { canonDir } from './manifest.ts';
|
|
9
|
+
|
|
10
|
+
export type CanonCatalogs = Record<string, Record<string, string>>;
|
|
11
|
+
|
|
12
|
+
export interface CatalogChange {
|
|
13
|
+
group: string;
|
|
14
|
+
name: string;
|
|
15
|
+
from: string | undefined;
|
|
16
|
+
to: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const WORKSPACE_FILE = 'pnpm-workspace.yaml';
|
|
20
|
+
|
|
21
|
+
// doc.getIn() возвращает unknown: скаляр (обычный случай) или узел yaml-коллекции,
|
|
22
|
+
// если запись каталога сломана (не скаляр). String() на объекте даёт "[object Object]" —
|
|
23
|
+
// JSON.stringify честно показывает, что там на самом деле.
|
|
24
|
+
function displayValue(v: unknown): string {
|
|
25
|
+
if (v == null) return String(v);
|
|
26
|
+
if (typeof v === 'string') return v;
|
|
27
|
+
if (typeof v === 'number' || typeof v === 'boolean' || typeof v === 'bigint') return v.toString();
|
|
28
|
+
return JSON.stringify(v);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function loadCatalogs(dir: string = canonDir()): CanonCatalogs {
|
|
32
|
+
return JSON.parse(readFileSync(join(dir, 'catalogs.json'), 'utf8')) as CanonCatalogs;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function catalogsFor(cfg: StackConfig, dir: string = canonDir()): CanonCatalogs {
|
|
36
|
+
const all = loadCatalogs(dir);
|
|
37
|
+
const groups = ['dev', ...cfg.with.filter((g) => g in all && g !== 'dev')];
|
|
38
|
+
return Object.fromEntries(
|
|
39
|
+
groups.filter((g) => all[g]).map((g) => [g, all[g] as Record<string, string>]),
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function syncCatalogs(
|
|
44
|
+
repoRoot: string,
|
|
45
|
+
cfg: StackConfig,
|
|
46
|
+
dir: string = canonDir(),
|
|
47
|
+
): CatalogChange[] {
|
|
48
|
+
const path = join(repoRoot, WORKSPACE_FILE);
|
|
49
|
+
if (!existsSync(path)) return [];
|
|
50
|
+
const doc = parseDocument(readFileSync(path, 'utf8'));
|
|
51
|
+
const changes: CatalogChange[] = [];
|
|
52
|
+
for (const [group, entries] of Object.entries(catalogsFor(cfg, dir))) {
|
|
53
|
+
for (const [name, version] of Object.entries(entries)) {
|
|
54
|
+
const current = doc.getIn(['catalogs', group, name]);
|
|
55
|
+
// YAML разбирает `typescript: 7` и `26.1` как числа — сравниваем строками.
|
|
56
|
+
if (current != null && displayValue(current) === version) continue;
|
|
57
|
+
// setIn создаёт недостающие узлы и не трогает соседей и их комментарии.
|
|
58
|
+
doc.setIn(['catalogs', group, name], version);
|
|
59
|
+
changes.push({
|
|
60
|
+
group,
|
|
61
|
+
name,
|
|
62
|
+
from: current == null ? undefined : displayValue(current),
|
|
63
|
+
to: version,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
// singleQuote: oxfmt (canon .oxfmtrc.jsonc) formats YAML with singleQuote:true, and this
|
|
68
|
+
// file's own pre-existing catalogs already use single quotes for scoped names. New
|
|
69
|
+
// scoped-package keys (@foo/bar isn't a plain-scalar-safe start char) default to double
|
|
70
|
+
// quotes otherwise, so a freshly-synced workspace fails `oxfmt --check` on its own output.
|
|
71
|
+
if (changes.length) writeFileSync(path, doc.toString({ singleQuote: true }));
|
|
72
|
+
return changes;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function checkCatalogs(
|
|
76
|
+
repoRoot: string,
|
|
77
|
+
cfg: StackConfig,
|
|
78
|
+
dir: string = canonDir(),
|
|
79
|
+
): Finding[] {
|
|
80
|
+
const path = join(repoRoot, WORKSPACE_FILE);
|
|
81
|
+
if (!existsSync(path)) return [];
|
|
82
|
+
const doc = parseDocument(readFileSync(path, 'utf8'));
|
|
83
|
+
const findings: Finding[] = [];
|
|
84
|
+
for (const [group, entries] of Object.entries(catalogsFor(cfg, dir))) {
|
|
85
|
+
for (const [name, version] of Object.entries(entries)) {
|
|
86
|
+
const current = doc.getIn(['catalogs', group, name]);
|
|
87
|
+
if (current != null && displayValue(current) === version) continue;
|
|
88
|
+
const exception = cfg.exceptions.find((e) => e.catalog === group && e.name === name);
|
|
89
|
+
findings.push({
|
|
90
|
+
code: current == null ? 'catalog-missing' : 'catalog-drift',
|
|
91
|
+
target: `catalogs.${group}.${name}`,
|
|
92
|
+
message:
|
|
93
|
+
current == null
|
|
94
|
+
? `catalog entry missing: expected ${version}`
|
|
95
|
+
: `${displayValue(current)} instead of ${version}`,
|
|
96
|
+
...(exception ? { suppressedBy: exception } : {}),
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return findings;
|
|
101
|
+
}
|
package/src/check.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { checkCatalogs } from './catalogs.ts';
|
|
2
|
+
import type { StackConfig } from './config.ts';
|
|
3
|
+
import { checkDependabotIgnore, checkEnginesNode, checkInlineVersions } from './deps.ts';
|
|
4
|
+
import { checkFiles } from './files.ts';
|
|
5
|
+
import type { Finding } from './findings.ts';
|
|
6
|
+
import { canonDir } from './manifest.ts';
|
|
7
|
+
|
|
8
|
+
export function checkRepo(repoRoot: string, cfg: StackConfig, dir: string = canonDir()): Finding[] {
|
|
9
|
+
const findings = [
|
|
10
|
+
...checkFiles(repoRoot, cfg, dir),
|
|
11
|
+
...checkCatalogs(repoRoot, cfg, dir),
|
|
12
|
+
...checkInlineVersions(repoRoot, cfg, dir),
|
|
13
|
+
...checkEnginesNode(repoRoot, cfg, dir),
|
|
14
|
+
...checkDependabotIgnore(repoRoot, cfg),
|
|
15
|
+
];
|
|
16
|
+
// Исключение без находки — мёртвая запись: канон уже изменился, а оправдание осталось.
|
|
17
|
+
const used = new Set(findings.map((f) => f.suppressedBy).filter(Boolean));
|
|
18
|
+
for (const e of cfg.exceptions) {
|
|
19
|
+
if (used.has(e)) continue;
|
|
20
|
+
findings.push({
|
|
21
|
+
code: 'stale-exception',
|
|
22
|
+
target: e.file ?? `catalogs.${e.catalog}.${e.name}`,
|
|
23
|
+
message: `exception no longer covers anything: ${e.reason}`,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
return findings;
|
|
27
|
+
}
|
package/src/cli.ts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
import { existsSync } from 'node:fs';
|
|
3
|
+
import { parseArgs } from 'node:util';
|
|
4
|
+
|
|
5
|
+
import { syncCatalogs } from './catalogs.ts';
|
|
6
|
+
import { checkRepo } from './check.ts';
|
|
7
|
+
import { type Profile, PROFILES, readStackConfig, StackConfigError } from './config.ts';
|
|
8
|
+
import { syncFiles } from './files.ts';
|
|
9
|
+
import { initConfig } from './init.ts';
|
|
10
|
+
|
|
11
|
+
function fail(message: string): never {
|
|
12
|
+
console.error(message);
|
|
13
|
+
process.exit(2);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function parseCliArgs() {
|
|
17
|
+
try {
|
|
18
|
+
return parseArgs({
|
|
19
|
+
args: Bun.argv.slice(2),
|
|
20
|
+
allowPositionals: true,
|
|
21
|
+
options: {
|
|
22
|
+
repo: { type: 'string' },
|
|
23
|
+
profile: { type: 'string' },
|
|
24
|
+
with: { type: 'string', multiple: true },
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
} catch (error) {
|
|
28
|
+
// Usage error, same bucket as an unknown command — code 2, never an unhandled crash.
|
|
29
|
+
fail(error instanceof Error ? error.message : String(error));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const { values, positionals } = parseCliArgs();
|
|
34
|
+
|
|
35
|
+
const repoRoot = values.repo ?? process.cwd();
|
|
36
|
+
const command = positionals[0];
|
|
37
|
+
|
|
38
|
+
try {
|
|
39
|
+
if (command === 'init') {
|
|
40
|
+
if (!existsSync(repoRoot)) fail(`--repo does not exist: ${repoRoot}`);
|
|
41
|
+
const profile = values.profile;
|
|
42
|
+
if (!profile) fail('--profile is required: <node|contracts|infra>');
|
|
43
|
+
if (!PROFILES.includes(profile as Profile)) {
|
|
44
|
+
fail(`unknown --profile "${profile}", expected one of: ${PROFILES.join(', ')}`);
|
|
45
|
+
}
|
|
46
|
+
const path = initConfig(repoRoot, { profile: profile as Profile, with: values.with ?? [] });
|
|
47
|
+
console.log(`created ${path}`);
|
|
48
|
+
} else if (command === 'sync') {
|
|
49
|
+
const cfg = readStackConfig(repoRoot);
|
|
50
|
+
const files = syncFiles(repoRoot, cfg).filter((c) => c.action !== 'unchanged');
|
|
51
|
+
const catalogs = syncCatalogs(repoRoot, cfg);
|
|
52
|
+
for (const c of files) console.log(`${c.action === 'seeded' ? 'seeded' : 'updated'} ${c.dest}`);
|
|
53
|
+
for (const c of catalogs)
|
|
54
|
+
console.log(`catalog ${c.group}.${c.name}: ${c.from ?? '—'} → ${c.to}`);
|
|
55
|
+
console.log(`canon ${files.length + catalogs.length === 0 ? 'already up to date' : 'applied'}`);
|
|
56
|
+
} else if (command === 'check') {
|
|
57
|
+
const cfg = readStackConfig(repoRoot);
|
|
58
|
+
const findings = checkRepo(repoRoot, cfg);
|
|
59
|
+
const blocking = findings.filter((f) => !f.suppressedBy);
|
|
60
|
+
for (const f of findings.filter((f) => f.suppressedBy)) {
|
|
61
|
+
console.warn(`allowed (${f.suppressedBy?.reason}): ${f.target} — ${f.message}`);
|
|
62
|
+
}
|
|
63
|
+
for (const f of blocking) console.error(`${f.code}: ${f.target} — ${f.message}`);
|
|
64
|
+
if (blocking.length) {
|
|
65
|
+
console.error(`\n${blocking.length} finding(s). Fix with: stack sync`);
|
|
66
|
+
process.exit(1);
|
|
67
|
+
}
|
|
68
|
+
console.log('canon: no drift');
|
|
69
|
+
} else {
|
|
70
|
+
fail(`unknown command "${command ?? ''}". Available: init, sync, check`);
|
|
71
|
+
}
|
|
72
|
+
} catch (error) {
|
|
73
|
+
if (error instanceof StackConfigError) fail(error.message);
|
|
74
|
+
throw error;
|
|
75
|
+
}
|