@icebreakers/monorepo 5.5.10 → 5.7.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/README.md +2 -0
- package/dist/baseline-DPfotf4y.mjs +146 -0
- package/dist/bundle-B9vRch4R.mjs +49 -0
- package/dist/catalog-CDEyc1uA.mjs +299 -0
- package/dist/cli.mjs +1487 -156
- package/dist/commands-TS8ABFdP.mjs +13820 -0
- package/dist/config-C38c_Q8L.mjs +66 -0
- package/dist/{create-flow-C811m80z.mjs → create-flow-CCr2hfSY.mjs} +103 -40
- package/dist/deps-CUdI2DaB.mjs +47 -0
- package/dist/execute-PX1hT0qv.mjs +68 -0
- package/dist/execute-Vi4qHe-D.mjs +663 -0
- package/dist/format-DZ7L34rf.mjs +28 -0
- package/dist/index-CoCTFWZJ.d.mts +2150 -0
- package/dist/index.d.mts +1741 -111
- package/dist/index.mjs +60 -6
- package/dist/inputs-_xIVONmB.mjs +50 -0
- package/dist/npm-B25nrSyz.mjs +82 -0
- package/dist/plan-B5aE_WNF.mjs +75 -0
- package/dist/run-Lu7y1bNf.mjs +165 -0
- package/dist/save-CdCf630Z.mjs +79 -0
- package/dist/scan-4nboHNXP.mjs +293 -0
- package/dist/template-drift-BBhnrHY1.mjs +2740 -0
- package/dist/tooling-entry.d.mts +1 -1
- package/dist/tooling-entry.mjs +2 -1
- package/dist/transaction-DAhY8EpG.mjs +168 -0
- package/dist/tsconfig-CGntrzBM.mjs +1483 -0
- package/dist/{tooling-BfXlmCi-.mjs → vitest-DkGh4Ygo.mjs} +108 -167
- package/dist/workspace-tasks-CnB8kkS0.mjs +4435 -0
- package/package.json +25 -7
- package/resources/api-report/runner.cjs +76 -0
- package/resources/devcontainer/setup.mjs +36 -0
- package/resources/knip/reporter.mjs +46 -0
- package/resources/maintenance/migration-lanes.mjs +141 -0
- package/resources/maintenance/migration-lock.mjs +119 -0
- package/resources/maintenance/migrations.mjs +215 -0
- package/resources/maintenance/presets.mjs +130 -0
- package/resources/maintenance/validate.mjs +233 -0
- package/resources/maintenance/workflow.yml +151 -0
- package/resources/skills/repoctl/SKILL.md +4 -2
- package/resources/skills/repoctl/references/commands.md +224 -13
- package/resources/skills/repoctl/references/config.md +70 -6
- package/resources/skills/repoctl/references/dependencies.md +37 -0
- package/resources/skills/repoctl/references/knip.md +34 -0
- package/resources/skills/repoctl/references/templates.md +26 -2
- package/dist/commands-CIzCAxyY.mjs +0 -5672
- package/dist/config-p842Knhq.mjs +0 -114
- package/dist/index-DDQKKYet.d.mts +0 -1025
- package/dist/types-m8JLwKzl.mjs +0 -499
- package/dist/workspace-MCKewElu.mjs +0 -123
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@icebreakers/monorepo",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "5.
|
|
4
|
+
"version": "5.7.0",
|
|
5
5
|
"description": "Core engine and programmatic APIs for repoctl",
|
|
6
6
|
"author": "ice breaker <hi@sonofmagic.top>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"peerDependencies": {
|
|
59
59
|
"@commitlint/cli": "^21.2.3",
|
|
60
60
|
"eslint": "^9.0.0 || ^10.0.0",
|
|
61
|
-
"stylelint": "^17.
|
|
61
|
+
"stylelint": "^17.16.0",
|
|
62
62
|
"typescript": "^5.0.0 || ^6.0.0"
|
|
63
63
|
},
|
|
64
64
|
"peerDependenciesMeta": {
|
|
@@ -76,38 +76,56 @@
|
|
|
76
76
|
}
|
|
77
77
|
},
|
|
78
78
|
"dependencies": {
|
|
79
|
+
"@arethetypeswrong/core": "0.18.5",
|
|
80
|
+
"@babel/parser": "^7.29.8",
|
|
79
81
|
"@icebreakers/commitlint-config": "4.1.1",
|
|
80
|
-
"@icebreakers/eslint-config": "8.0.
|
|
81
|
-
"@icebreakers/monorepo-templates": "2.0
|
|
82
|
+
"@icebreakers/eslint-config": "8.0.7",
|
|
83
|
+
"@icebreakers/monorepo-templates": "2.2.0",
|
|
82
84
|
"@icebreakers/stylelint-config": "5.1.3",
|
|
85
|
+
"@npmcli/config": "10.14.0",
|
|
83
86
|
"@pnpm/find-workspace-dir": "^1000.1.5",
|
|
84
87
|
"@pnpm/logger": "^1100.0.0",
|
|
85
88
|
"@pnpm/types": "^1102.1.1",
|
|
86
|
-
"@pnpm/worker": "^1100.4.
|
|
89
|
+
"@pnpm/worker": "^1100.4.6",
|
|
87
90
|
"@pnpm/workspace.find-packages": "^1000.0.65",
|
|
88
91
|
"@pnpm/workspace.read-manifest": "^1000.3.1",
|
|
89
92
|
"c12": "^3.3.4",
|
|
90
93
|
"commander": "^15.0.0",
|
|
91
94
|
"comment-json": "^5.0.0",
|
|
92
95
|
"consola": "^3.4.2",
|
|
96
|
+
"cross-spawn": "^7.0.6",
|
|
97
|
+
"esbuild": "^0.28.2",
|
|
93
98
|
"git-url-parse": "^16.1.0",
|
|
99
|
+
"json5": "^2.2.3",
|
|
94
100
|
"klaw": "^4.1.0",
|
|
95
101
|
"lint-staged": "^17.6.0",
|
|
102
|
+
"micromatch": "^4.0.8",
|
|
103
|
+
"node-diff3": "~3.1.2",
|
|
96
104
|
"p-queue": "^9.3.3",
|
|
105
|
+
"pacote": "21.5.1",
|
|
97
106
|
"pathe": "^2.0.3",
|
|
98
107
|
"picocolors": "^1.1.1",
|
|
108
|
+
"publint": "0.3.25",
|
|
99
109
|
"semver": "^7.8.5",
|
|
100
110
|
"simple-git": "^3.36.0",
|
|
101
|
-
"
|
|
111
|
+
"tar": "7.5.22",
|
|
112
|
+
"tinyglobby": "^0.2.17",
|
|
113
|
+
"validate-npm-package-name": "^7.0.2",
|
|
114
|
+
"vitest": "^5.0.3",
|
|
102
115
|
"yaml": "^2.9.1"
|
|
103
116
|
},
|
|
104
117
|
"devDependencies": {
|
|
118
|
+
"@microsoft/api-extractor": "7.52.12",
|
|
119
|
+
"@types/cross-spawn": "^6.0.6",
|
|
105
120
|
"@types/klaw": "^3.0.8",
|
|
106
121
|
"@types/micromatch": "^4.0.10",
|
|
122
|
+
"@types/npmcli__config": "^6.0.4",
|
|
123
|
+
"@types/pacote": "^11.1.8",
|
|
107
124
|
"@types/semver": "^7.8.0",
|
|
125
|
+
"@types/validate-npm-package-name": "^4.0.2",
|
|
108
126
|
"ci-info": "^4.4.0",
|
|
109
127
|
"fdir": "^6.5.0",
|
|
110
|
-
"
|
|
128
|
+
"knip": "6.39.0"
|
|
111
129
|
},
|
|
112
130
|
"publishConfig": {
|
|
113
131
|
"access": "public",
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
const { createHash } = require('node:crypto')
|
|
2
|
+
const fs = require('node:fs/promises')
|
|
3
|
+
const { createRequire } = require('node:module')
|
|
4
|
+
const path = require('node:path')
|
|
5
|
+
const process = require('node:process')
|
|
6
|
+
|
|
7
|
+
async function run() {
|
|
8
|
+
const job = JSON.parse(await fs.readFile(process.argv[2], 'utf8'))
|
|
9
|
+
const { Extractor, ExtractorConfig } = require(job.tool)
|
|
10
|
+
const ts = createRequire(job.tool)('typescript')
|
|
11
|
+
const observed = new Map()
|
|
12
|
+
const parsed = ts.getParsedCommandLineOfConfigFile(job.tsconfig, {}, {
|
|
13
|
+
...ts.sys,
|
|
14
|
+
onUnRecoverableConfigFileDiagnostic() {
|
|
15
|
+
throw new Error('Invalid TypeScript configuration')
|
|
16
|
+
},
|
|
17
|
+
readFile(filename) {
|
|
18
|
+
const content = ts.sys.readFile(filename)
|
|
19
|
+
if (content !== undefined) {
|
|
20
|
+
observed.set(filename, content)
|
|
21
|
+
}
|
|
22
|
+
return content
|
|
23
|
+
},
|
|
24
|
+
})
|
|
25
|
+
if (!parsed || parsed.errors.length) {
|
|
26
|
+
throw new Error('Invalid TypeScript configuration')
|
|
27
|
+
}
|
|
28
|
+
const manifestText = await fs.readFile(job.packageJson, 'utf8')
|
|
29
|
+
observed.set(job.packageJson, manifestText)
|
|
30
|
+
const packageJson = JSON.parse(manifestText)
|
|
31
|
+
const config = ExtractorConfig.prepare({
|
|
32
|
+
configObject: {
|
|
33
|
+
projectFolder: path.dirname(job.packageJson),
|
|
34
|
+
mainEntryPointFilePath: job.entryPoint,
|
|
35
|
+
compiler: { tsconfigFilePath: job.tsconfig },
|
|
36
|
+
apiReport: { enabled: true, reportFileName: 'entry.api.md', reportFolder: job.temporary, reportTempFolder: job.temporary },
|
|
37
|
+
docModel: { enabled: false },
|
|
38
|
+
dtsRollup: { enabled: false },
|
|
39
|
+
tsdocMetadata: { enabled: false },
|
|
40
|
+
},
|
|
41
|
+
configObjectFullPath: undefined,
|
|
42
|
+
packageJsonFullPath: job.packageJson,
|
|
43
|
+
packageJson,
|
|
44
|
+
})
|
|
45
|
+
const diagnostics = []
|
|
46
|
+
const clean = text => text.split(job.temporary).join('<temporary>').split(job.root).join('<workspace>')
|
|
47
|
+
const result = Extractor.invoke(config, {
|
|
48
|
+
localBuild: true,
|
|
49
|
+
messageCallback(message) {
|
|
50
|
+
message.handled = true
|
|
51
|
+
if (['error', 'warning'].includes(message.logLevel)) {
|
|
52
|
+
diagnostics.push({ code: message.messageId, severity: message.logLevel, message: clean(message.text), ...(message.sourceFilePath ? { file: path.relative(job.root, message.sourceFilePath).split(path.sep).join('/') } : {}), ...(message.sourceFileLine ? { line: message.sourceFileLine } : {}) })
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
})
|
|
56
|
+
for (const file of result.compilerState.program.getSourceFiles()) {
|
|
57
|
+
observed.set(file.fileName, file.text)
|
|
58
|
+
}
|
|
59
|
+
const inputs = []
|
|
60
|
+
for (const [filename, content] of observed) {
|
|
61
|
+
const current = await fs.readFile(filename, 'utf8')
|
|
62
|
+
if (current.replace(/^\uFEFF/u, '') !== content.replace(/^\uFEFF/u, '')) {
|
|
63
|
+
throw new Error('Compiler input changed during analysis')
|
|
64
|
+
}
|
|
65
|
+
inputs.push({ path: path.resolve(filename), hash: createHash('sha256').update(current).digest('hex') })
|
|
66
|
+
}
|
|
67
|
+
inputs.sort((a, b) => a.path.localeCompare(b.path))
|
|
68
|
+
const inputHash = createHash('sha256').update(JSON.stringify(inputs)).digest('hex')
|
|
69
|
+
const report = result.succeeded ? (await fs.readFile(path.join(job.temporary, 'entry.api.md'), 'utf8')).replaceAll('\r\n', '\n') : null
|
|
70
|
+
process.stdout.write(JSON.stringify({ succeeded: result.succeeded, diagnostics, report, inputHash, inputs }))
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
run().catch(() => {
|
|
74
|
+
process.stdout.write(JSON.stringify({ succeeded: false, diagnostics: [{ code: 'extractor-failed', severity: 'error', message: 'API Extractor could not analyze the declared entrypoint. Verify the declaration output and TypeScript configuration.' }], report: null }))
|
|
75
|
+
process.exitCode = 1
|
|
76
|
+
})
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process'
|
|
2
|
+
import { existsSync, readFileSync } from 'node:fs'
|
|
3
|
+
import process from 'node:process'
|
|
4
|
+
|
|
5
|
+
const expectedNode = process.env.REPOCTL_CONTAINER_NODE_VERSION
|
|
6
|
+
if (!expectedNode || process.versions.node !== expectedNode) {
|
|
7
|
+
throw new Error(`Expected the reviewed Node ${expectedNode ?? '(missing)'} image; observed ${process.versions.node}. Regenerate the Dev Container preset after changing its Node version.`)
|
|
8
|
+
}
|
|
9
|
+
if (!existsSync('pnpm-workspace.yaml')) {
|
|
10
|
+
throw new Error('Run the Dev Container setup from the pnpm workspace root.')
|
|
11
|
+
}
|
|
12
|
+
const manifest = JSON.parse(readFileSync('package.json', 'utf8'))
|
|
13
|
+
const manager = /^pnpm@(\d+\.\d+\.\d+)(?:\+sha(?:224|256|384|512)\.[a-f\d]+)?$/u.exec(manifest.packageManager ?? '')
|
|
14
|
+
if (!manager) {
|
|
15
|
+
throw new Error('packageManager must pin an exact stable pnpm version, optionally with a Corepack integrity hash.')
|
|
16
|
+
}
|
|
17
|
+
const env = {
|
|
18
|
+
...process.env,
|
|
19
|
+
COREPACK_ENABLE_AUTO_PIN: '0',
|
|
20
|
+
COREPACK_ENABLE_PROJECT_SPEC: '1',
|
|
21
|
+
COREPACK_DEFAULT_TO_LATEST: '0',
|
|
22
|
+
COREPACK_ENABLE_DOWNLOAD_PROMPT: '0',
|
|
23
|
+
}
|
|
24
|
+
// A first pnpm invocation can create manager metadata in the lockfile. Decide
|
|
25
|
+
// whether dependencies are locked before asking pnpm to activate or inspect itself.
|
|
26
|
+
const lockfile = existsSync('pnpm-lock.yaml') ? '--frozen-lockfile' : '--no-frozen-lockfile'
|
|
27
|
+
const managerGuards = ['--config.manage-package-manager-versions=false', '--config.pm-on-fail=ignore']
|
|
28
|
+
const observed = spawnSync('corepack', ['pnpm', ...managerGuards, '--version'], { env, encoding: 'utf8' })
|
|
29
|
+
if (observed.error || observed.status !== 0 || observed.stdout.trim() !== manager[1]) {
|
|
30
|
+
throw new Error(`Corepack must activate pnpm ${manager[1]}. ${observed.error?.message ?? observed.stderr ?? observed.stdout}`)
|
|
31
|
+
}
|
|
32
|
+
const installed = spawnSync('corepack', ['pnpm', ...managerGuards, 'install', lockfile, '--config.engine-strict=true'], { env, stdio: 'inherit' })
|
|
33
|
+
if (installed.error || installed.status !== 0) {
|
|
34
|
+
throw new Error(`Workspace installation failed (${installed.error?.message ?? installed.status}); fix the error before using this container.`)
|
|
35
|
+
}
|
|
36
|
+
console.log(`Dev Container ready: Node ${process.versions.node}, pnpm ${manager[1]}.`)
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import process from 'node:process'
|
|
2
|
+
|
|
3
|
+
// Keep Knip's native metadata; its built-in JSON reporter drops severity/workspace.
|
|
4
|
+
export default function report(data) {
|
|
5
|
+
const findings = []
|
|
6
|
+
for (const [type, enabled] of Object.entries(data.report)) {
|
|
7
|
+
if (!enabled) {
|
|
8
|
+
continue
|
|
9
|
+
}
|
|
10
|
+
for (const issues of Object.values(data.issues[type])) {
|
|
11
|
+
for (const issue of Object.values(issues)) {
|
|
12
|
+
const { type, severity, filePath, workspace, symbol, symbols, parentSymbol, symbolType, specifier, pos, line, col } = issue
|
|
13
|
+
findings.push({ type, severity, filePath, workspace, symbol, symbols, parentSymbol, symbolType, specifier, pos, line, col })
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
if (!data.isDisableConfigHints) {
|
|
18
|
+
for (const hint of data.configurationHints) {
|
|
19
|
+
findings.push({
|
|
20
|
+
type: 'configurationHint',
|
|
21
|
+
severity: data.isTreatConfigHintsAsErrors ? 'error' : 'warn',
|
|
22
|
+
filePath: hint.filePath ?? data.configFilePath ?? data.cwd,
|
|
23
|
+
workspace: hint.workspaceName ?? '.',
|
|
24
|
+
symbol: `${hint.type}: ${hint.identifier}`,
|
|
25
|
+
hint: { ...hint, identifier: String(hint.identifier) },
|
|
26
|
+
})
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (!data.isDisableTagHints) {
|
|
30
|
+
for (const hint of data.tagHints) {
|
|
31
|
+
findings.push({ type: 'tagHint', severity: data.isTreatTagHintsAsErrors ? 'error' : 'warn', filePath: hint.filePath, workspace: '', symbol: `${hint.tagName}: ${hint.identifier}`, hint })
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
const output = {
|
|
35
|
+
schemaVersion: 1,
|
|
36
|
+
kind: 'repoctl-knip-native',
|
|
37
|
+
cwd: data.cwd,
|
|
38
|
+
findings,
|
|
39
|
+
hasConfigLoadErrors: data.hasConfigLoadErrors,
|
|
40
|
+
configFilePath: data.configFilePath ?? null,
|
|
41
|
+
workspaces: data.includedWorkspaceDirs,
|
|
42
|
+
report: data.report,
|
|
43
|
+
plugins: data.enabledPlugins,
|
|
44
|
+
}
|
|
45
|
+
process.stdout.write(`\n__REPOCTL_KNIP_REPORT_V1__${JSON.stringify(output)}\n`)
|
|
46
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/** Verify the built-in prerelease migration against committed workspace membership. */
|
|
2
|
+
export function validateMaintenanceLanes({ read, sourcePaths, operation, tag, Buffer, fail }) {
|
|
3
|
+
const reject = () => fail('migration prerelease lanes require canonical workspace evidence and every public package tag')
|
|
4
|
+
const scalar = (value) => {
|
|
5
|
+
const text = value.trim()
|
|
6
|
+
if (/^'[^']*'$/u.test(text)) {
|
|
7
|
+
return text.slice(1, -1)
|
|
8
|
+
}
|
|
9
|
+
if (text.startsWith('"')) {
|
|
10
|
+
try {
|
|
11
|
+
const parsed = JSON.parse(text)
|
|
12
|
+
if (typeof parsed === 'string') {
|
|
13
|
+
return parsed
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
reject()
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
if (!text || /[\s#&*!|>{}[\]]/u.test(text) || /^(?:null|true|false|~|[-+]?(?:\d|\.\d)|[-+]?\.inf|\.nan)/iu.test(text)) {
|
|
21
|
+
reject()
|
|
22
|
+
}
|
|
23
|
+
return text
|
|
24
|
+
}
|
|
25
|
+
const original = read('pnpm-workspace.yaml')
|
|
26
|
+
if (!original || !operation || !['add', 'modify', 'identical'].includes(operation.status)) {
|
|
27
|
+
reject()
|
|
28
|
+
}
|
|
29
|
+
const lines = original.toString().split('\n').filter(line => line.trim() && !line.trimStart().startsWith('#'))
|
|
30
|
+
const declarations = lines.map((line, index) => ({ line, index })).filter(item => /^(?:packages|'packages'|"packages"):/u.test(item.line))
|
|
31
|
+
if (declarations.length !== 1) {
|
|
32
|
+
reject()
|
|
33
|
+
}
|
|
34
|
+
const declaration = declarations[0]
|
|
35
|
+
const inline = declaration.line.slice(declaration.line.indexOf(':') + 1).trim()
|
|
36
|
+
const patterns = []
|
|
37
|
+
if (inline !== '[]') {
|
|
38
|
+
if (inline) {
|
|
39
|
+
reject()
|
|
40
|
+
}
|
|
41
|
+
for (let index = declaration.index + 1; index < lines.length && /^\s/u.test(lines[index]); index++) {
|
|
42
|
+
const match = /^ {2}- (.+)$/u.exec(lines[index])
|
|
43
|
+
if (!match) {
|
|
44
|
+
reject()
|
|
45
|
+
}
|
|
46
|
+
patterns.push(scalar(match[1]))
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
const pattern = (value) => {
|
|
50
|
+
if (!/^[!\w@./*?-]+$/u.test(value) || value.startsWith('/') || value.split('/').some(part => part === '..' || part === '.')) {
|
|
51
|
+
reject()
|
|
52
|
+
}
|
|
53
|
+
let source = ''
|
|
54
|
+
for (let index = 0; index < value.length; index++) {
|
|
55
|
+
const char = value[index]
|
|
56
|
+
if (char === '*' && value[index + 1] === '*') {
|
|
57
|
+
index++
|
|
58
|
+
if (value[index + 1] === '/') {
|
|
59
|
+
index++
|
|
60
|
+
source += '(?:.*/)?'
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
source += '.*'
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
else if (char === '*') {
|
|
67
|
+
source += '[^/]*'
|
|
68
|
+
}
|
|
69
|
+
else if (char === '?') {
|
|
70
|
+
source += '[^/]'
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
source += char.replace(/[.+^$()|[\]{}\\]/gu, '\\$&')
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return new RegExp(`^${source}$`, 'u')
|
|
77
|
+
}
|
|
78
|
+
const include = patterns.filter(value => !value.startsWith('!')).map(pattern)
|
|
79
|
+
const exclude = patterns.filter(value => value.startsWith('!')).map(value => pattern(value.slice(1)))
|
|
80
|
+
const names = []
|
|
81
|
+
for (const filename of sourcePaths) {
|
|
82
|
+
const manifestPath = /^(.*)\/package\.(json|json5|yaml)$/u.exec(filename)
|
|
83
|
+
if (!manifestPath || filename.split('/').some(part => ['node_modules', 'bower_components'].includes(part))) {
|
|
84
|
+
continue
|
|
85
|
+
}
|
|
86
|
+
const directory = manifestPath[1]
|
|
87
|
+
if (!include.some(regex => regex.test(directory)) || exclude.some(regex => regex.test(directory))) {
|
|
88
|
+
continue
|
|
89
|
+
}
|
|
90
|
+
if (manifestPath[2] !== 'json') {
|
|
91
|
+
reject()
|
|
92
|
+
}
|
|
93
|
+
let manifest
|
|
94
|
+
try {
|
|
95
|
+
manifest = JSON.parse(read(filename).toString())
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
reject()
|
|
99
|
+
}
|
|
100
|
+
if (manifest && !manifest.private && typeof manifest.name === 'string' && manifest.name) {
|
|
101
|
+
names.push(manifest.name)
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (new Set(names).size !== names.length) {
|
|
105
|
+
reject()
|
|
106
|
+
}
|
|
107
|
+
const output = operation.content === null ? original : Buffer.from(operation.content, 'base64')
|
|
108
|
+
const outputLines = output.toString().split('\n').filter(line => line.trim() && !line.trimStart().startsWith('#'))
|
|
109
|
+
const versioning = outputLines.map((line, index) => ({ line, index })).filter(item => /^(?:versioning|'versioning'|"versioning"):/u.test(item.line))
|
|
110
|
+
if (versioning.length !== 1 || !/^versioning:\s*$/u.test(versioning[0].line)) {
|
|
111
|
+
reject()
|
|
112
|
+
}
|
|
113
|
+
const section = []
|
|
114
|
+
for (let index = versioning[0].index + 1; index < outputLines.length && /^\s/u.test(outputLines[index]); index++) {
|
|
115
|
+
section.push(outputLines[index])
|
|
116
|
+
}
|
|
117
|
+
const lanes = section.map((line, index) => ({ line, index })).filter(item => /^ {2}(?:lanes|'lanes'|"lanes"):/u.test(item.line))
|
|
118
|
+
if (lanes.length !== 1) {
|
|
119
|
+
reject()
|
|
120
|
+
}
|
|
121
|
+
const laneLine = lanes[0]
|
|
122
|
+
const empty = /^ {2}lanes: \{\}\s*$/u.test(laneLine.line)
|
|
123
|
+
if (!empty && !/^ {2}lanes:\s*$/u.test(laneLine.line)) {
|
|
124
|
+
reject()
|
|
125
|
+
}
|
|
126
|
+
const tags = new Map()
|
|
127
|
+
for (let index = empty ? section.length : laneLine.index + 1; index < section.length && /^ {4}/u.test(section[index]); index++) {
|
|
128
|
+
const match = /^ {4}("[^"]+"|'[^']+'|[^:'"\s][^:]*): (.+)$/u.exec(section[index])
|
|
129
|
+
if (!match) {
|
|
130
|
+
reject()
|
|
131
|
+
}
|
|
132
|
+
const name = scalar(match[1])
|
|
133
|
+
if (tags.has(name)) {
|
|
134
|
+
reject()
|
|
135
|
+
}
|
|
136
|
+
tags.set(name, scalar(match[2]))
|
|
137
|
+
}
|
|
138
|
+
if (names.some(name => tags.get(name) !== tag)) {
|
|
139
|
+
reject()
|
|
140
|
+
}
|
|
141
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/** Read only canonical pnpm block mappings on the installed repoctl dependency chain. */
|
|
2
|
+
export function maintenanceTemplateVersion({ lock, toolVersion, fail }) {
|
|
3
|
+
const reject = () => fail('migration target requires an unambiguous locked repoctl template dependency chain')
|
|
4
|
+
const documents = lock.toString().split(/^---\s*$/mu).filter(document => document.trim())
|
|
5
|
+
if (!documents.length || documents.length > 2 || documents.some(document => /\t/u.test(document))) {
|
|
6
|
+
reject()
|
|
7
|
+
}
|
|
8
|
+
const scalar = (text) => {
|
|
9
|
+
const value = text.replace(/\s+#.*$/u, '').trim()
|
|
10
|
+
if (value.startsWith('"')) {
|
|
11
|
+
try {
|
|
12
|
+
return JSON.parse(value)
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
reject()
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
if (value.startsWith('\'')) {
|
|
19
|
+
if (!/^'[^']*'$/u.test(value)) {
|
|
20
|
+
reject()
|
|
21
|
+
}
|
|
22
|
+
return value.slice(1, -1)
|
|
23
|
+
}
|
|
24
|
+
if (!value || /[\s[\]{}&*!|>#]/u.test(value)) {
|
|
25
|
+
reject()
|
|
26
|
+
}
|
|
27
|
+
return value
|
|
28
|
+
}
|
|
29
|
+
const entry = (block, indent, name, required = true) => {
|
|
30
|
+
const found = []
|
|
31
|
+
for (let index = 0; index < block.length; index++) {
|
|
32
|
+
const line = block[index]
|
|
33
|
+
const width = line.length - line.trimStart().length
|
|
34
|
+
if (width < indent) {
|
|
35
|
+
reject()
|
|
36
|
+
}
|
|
37
|
+
if (width !== indent) {
|
|
38
|
+
continue
|
|
39
|
+
}
|
|
40
|
+
const match = /^\s*("[^"]+"|'[^']+'|[^:'"\s][^:]*):(?: (.*))?$/u.exec(line)
|
|
41
|
+
if (!match) {
|
|
42
|
+
reject()
|
|
43
|
+
}
|
|
44
|
+
if (scalar(match[1]) !== name) {
|
|
45
|
+
continue
|
|
46
|
+
}
|
|
47
|
+
let end = index + 1
|
|
48
|
+
while (end < block.length && block[end].length - block[end].trimStart().length > indent) {
|
|
49
|
+
end++
|
|
50
|
+
}
|
|
51
|
+
found.push({ value: match[2]?.trim() ?? '', lines: block.slice(index + 1, end) })
|
|
52
|
+
}
|
|
53
|
+
if (found.length > 1 || (required && found.length !== 1)) {
|
|
54
|
+
reject()
|
|
55
|
+
}
|
|
56
|
+
return found[0]
|
|
57
|
+
}
|
|
58
|
+
const mapping = (parent, indent, name, required = true) => {
|
|
59
|
+
const item = entry(parent, indent, name, required)
|
|
60
|
+
if (!item) {
|
|
61
|
+
return null
|
|
62
|
+
}
|
|
63
|
+
if (item.value && !item.value.startsWith('#')) {
|
|
64
|
+
reject()
|
|
65
|
+
}
|
|
66
|
+
return item.lines
|
|
67
|
+
}
|
|
68
|
+
const value = (parent, indent, name) => {
|
|
69
|
+
const item = entry(parent, indent, name)
|
|
70
|
+
if (item.lines.length) {
|
|
71
|
+
reject()
|
|
72
|
+
}
|
|
73
|
+
return scalar(item.value)
|
|
74
|
+
}
|
|
75
|
+
const resolution = (text) => {
|
|
76
|
+
if (typeof text !== 'string' || !/^(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-[\dA-Z.-]+)?(?:\+[\dA-Z.-]+)?(?:\([^\r\n]+\))?$/iu.test(text)) {
|
|
77
|
+
reject()
|
|
78
|
+
}
|
|
79
|
+
return text.split('(')[0]
|
|
80
|
+
}
|
|
81
|
+
const candidates = []
|
|
82
|
+
for (const document of documents) {
|
|
83
|
+
const lines = document.split('\n').filter(line => line.trim() && !line.trimStart().startsWith('#'))
|
|
84
|
+
if (value(lines, 0, 'lockfileVersion') !== '9.0') {
|
|
85
|
+
reject()
|
|
86
|
+
}
|
|
87
|
+
const importer = mapping(mapping(lines, 0, 'importers'), 2, '.')
|
|
88
|
+
if (!entry(importer, 4, 'packageManagerDependencies', false) && !entry(importer, 4, 'configDependencies', false)) {
|
|
89
|
+
candidates.push({ lines, importer })
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (candidates.length !== 1) {
|
|
93
|
+
reject()
|
|
94
|
+
}
|
|
95
|
+
const { lines, importer } = candidates[0]
|
|
96
|
+
const roots = []
|
|
97
|
+
for (const group of ['dependencies', 'devDependencies', 'optionalDependencies']) {
|
|
98
|
+
const dependencies = mapping(importer, 4, group, false)
|
|
99
|
+
if (!dependencies) {
|
|
100
|
+
continue
|
|
101
|
+
}
|
|
102
|
+
const tool = mapping(dependencies, 6, 'repoctl', false)
|
|
103
|
+
if (tool) {
|
|
104
|
+
roots.push(value(tool, 8, 'version'))
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (roots.length !== 1 || resolution(roots[0]) !== toolVersion) {
|
|
108
|
+
reject()
|
|
109
|
+
}
|
|
110
|
+
const snapshots = mapping(lines, 0, 'snapshots')
|
|
111
|
+
const dependency = (name, resolved, child) => {
|
|
112
|
+
resolution(resolved)
|
|
113
|
+
const snapshot = mapping(snapshots, 2, `${name}@${resolved}`)
|
|
114
|
+
return value(mapping(snapshot, 4, 'dependencies'), 6, child)
|
|
115
|
+
}
|
|
116
|
+
const engine = dependency('repoctl', roots[0], '@icebreakers/monorepo')
|
|
117
|
+
const templates = dependency('@icebreakers/monorepo', engine, '@icebreakers/monorepo-templates')
|
|
118
|
+
return resolution(templates)
|
|
119
|
+
}
|