gatelight 0.0.0-stage → 0.17.9
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/.antigravity-plugin/plugin.json +9 -0
- package/.claude-plugin/plugin.json +11 -0
- package/.codex-plugin/plugin.json +18 -0
- package/.mcp.json +8 -0
- package/bin/modwall +8 -0
- package/bin/node.sh +14 -0
- package/bin/testcraft +8 -0
- package/bin/testpace +8 -0
- package/entry/command +44 -0
- package/hooks/antigravity.sh +24 -0
- package/hooks/codex.json +50 -0
- package/hooks/codex.sh +7 -0
- package/hooks/hooks.json +43 -0
- package/hooks/testpace.ts +25 -0
- package/hooks.json +16 -0
- package/mcp_config.json +8 -0
- package/package.json +21 -4
- package/setup.mjs +99 -0
- package/skills/merge/SKILL.md +42 -0
- package/skills/modular/SKILL.md +75 -0
- package/skills/setup/SKILL.md +101 -0
- package/skills/setup-modwall/SKILL.md +112 -0
- package/skills/setup-testcraft/SKILL.md +23 -0
- package/skills/setup-testcraft/checklist/dev-login.md +20 -0
- package/skills/write-tests/SKILL.md +153 -0
- package/src/base/agent.ts +100 -0
- package/src/base/baseline.ts +54 -0
- package/src/base/commandline.ts +40 -0
- package/src/base/commands.ts +94 -0
- package/src/base/confirm.ts +161 -0
- package/src/base/contract.ts +94 -0
- package/src/base/coverage.ts +46 -0
- package/src/base/entry.ts +90 -0
- package/src/base/excerpt.ts +46 -0
- package/src/base/execute.ts +70 -0
- package/src/base/exit.ts +6 -0
- package/src/base/format.ts +27 -0
- package/src/base/full.ts +160 -0
- package/src/base/gate.ts +251 -0
- package/src/base/git.ts +361 -0
- package/src/base/glob.ts +38 -0
- package/src/base/hook.ts +297 -0
- package/src/base/hookformat.ts +257 -0
- package/src/base/judging.ts +27 -0
- package/src/base/layermap.ts +69 -0
- package/src/base/module.ts +88 -0
- package/src/base/process-group.ts +101 -0
- package/src/base/records.ts +66 -0
- package/src/base/repo.ts +155 -0
- package/src/base/sessions.ts +55 -0
- package/src/base/shell.ts +176 -0
- package/src/base/stop.ts +100 -0
- package/src/base/store.ts +348 -0
- package/src/base/version.ts +24 -0
- package/src/cli.ts +186 -0
- package/src/craft/change.ts +24 -0
- package/src/craft/checklist.ts +157 -0
- package/src/craft/commands.ts +111 -0
- package/src/craft/config.ts +15 -0
- package/src/craft/full.ts +30 -0
- package/src/craft/index.ts +12 -0
- package/src/craft/session.ts +21 -0
- package/src/mcp.ts +79 -0
- package/src/modules.ts +10 -0
- package/src/modwall.ts +8 -0
- package/src/pace/commands.ts +281 -0
- package/src/pace/config.ts +103 -0
- package/src/pace/consent.ts +81 -0
- package/src/pace/focused.ts +208 -0
- package/src/pace/full.ts +38 -0
- package/src/pace/index.ts +16 -0
- package/src/pace/record.ts +84 -0
- package/src/pace/report.ts +335 -0
- package/src/pace/results.ts +243 -0
- package/src/pace/run/node-test-reporter.mjs +34 -0
- package/src/pace/run/node-test.ts +26 -0
- package/src/pace/run/playwright-reporter.mjs +48 -0
- package/src/pace/run/playwright.ts +34 -0
- package/src/pace/run/runner.ts +157 -0
- package/src/pace/run/targets.ts +130 -0
- package/src/pace/run/vitest-launcher.mjs +101 -0
- package/src/pace/run/vitest.ts +22 -0
- package/src/pace/session.ts +35 -0
- package/src/pace/testlist.ts +91 -0
- package/src/pace/tests.ts +22 -0
- package/src/pace/verify.ts +95 -0
- package/src/testcraft.ts +9 -0
- package/src/wall/check.ts +258 -0
- package/src/wall/commands.ts +279 -0
- package/src/wall/config.ts +394 -0
- package/src/wall/database.ts +136 -0
- package/src/wall/dbcheck.ts +389 -0
- package/src/wall/dbrules.ts +213 -0
- package/src/wall/edit.ts +64 -0
- package/src/wall/files.ts +35 -0
- package/src/wall/full.ts +30 -0
- package/src/wall/index.ts +15 -0
- package/src/wall/init.ts +149 -0
- package/src/wall/layermap.ts +124 -0
- package/src/wall/layout.ts +231 -0
- package/src/wall/loosen.ts +157 -0
- package/src/wall/miniprogram.ts +80 -0
- package/src/wall/project.ts +88 -0
- package/src/wall/rules.ts +400 -0
- package/src/wall/session.ts +198 -0
- package/src/wall/sql.ts +510 -0
- package/src/wall/store.ts +39 -0
- package/README.md +0 -3
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
// 放宽项:和分叉点的配置比,这次放宽了哪些规则。放宽要用户在确认工具的弹窗里同意(底座的用户确认,base/confirm.ts),收紧不用。
|
|
2
|
+
// 往 allow 加条目;扩大 shared、app、map、outside 的范围;删掉或缩小 roots;往 entry 加文件名;删掉 database 或改它的目录、账号名;
|
|
3
|
+
// 给 database 加上或改运行角色模板(运行角色能用模块的内部 schema);删掉配置或整个 .modwall/。加上 database 是收紧,删掉运行角色模板也是。
|
|
4
|
+
// 首次接入(分叉点上还没有配置):整份配置算一项。
|
|
5
|
+
// 有几个应用时,每个应用和分叉点上同名的应用比,项里写明是哪个应用(apps.<应用名>.<字段>):
|
|
6
|
+
// 新加的应用和一个空的应用比(roots 是收紧,shared、app、map、entry 按扩大算);删掉或改名的应用按删掉它的 roots 算;
|
|
7
|
+
// 外面一层的 shared、outside、allow 和单应用时一样比;单应用的写法和按应用分组的写法之间切换,整份配置算一项。
|
|
8
|
+
// 路径规则新加的一条,被分叉点上的某条盖住(一样,或在它 /** 的目录里面)才算没扩大;判断不了的都当扩大。
|
|
9
|
+
//
|
|
10
|
+
// 每一项除了给用户看的文字,还带着它具体改了什么(改之前、改成什么):同意按这三样记,不只按文字记。
|
|
11
|
+
// 文字里已经写全了改动的(新增一条例外、新增一条路径规则、删掉一个模块根目录),改之前、改成什么就是那一条本身,
|
|
12
|
+
// 哪个分支上做同一项放宽都是同一个决定,共用一次同意;配置别处再怎么变,这一项不用重新问。
|
|
13
|
+
// 文字是固定的、或没写全的(删掉配置、删掉 database、换写法、首次接入),改之前、改成什么是被删掉或换掉的那份内容:
|
|
14
|
+
// 删的是另一份配置,就是另一项,要重新同意。
|
|
15
|
+
|
|
16
|
+
import { type App, type AppConfig, type Config, CONFIG_PATH, field, MODWALL_DIR, schemeOf } from './config.ts'
|
|
17
|
+
|
|
18
|
+
/** 一项放宽。 */
|
|
19
|
+
export interface LoosenItem {
|
|
20
|
+
/** 给用户看的文字。 */
|
|
21
|
+
text: string
|
|
22
|
+
/** 这一项改之前是什么、改成了什么(没有的一边是空的)。 */
|
|
23
|
+
before: string
|
|
24
|
+
after: string
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** 工作区这一侧。 */
|
|
28
|
+
export interface ConfigSide {
|
|
29
|
+
/** 能用的配置(文件在、校验通过)。 */
|
|
30
|
+
config?: Config
|
|
31
|
+
/** 有 .modwall/ 目录。 */
|
|
32
|
+
hasDir: boolean
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** old 盖住了 rule:rule 认的路径都在 old 里面。 */
|
|
36
|
+
function covers(old: string, rule: string): boolean {
|
|
37
|
+
if (old === rule || old === '**' || old === '**/') return true
|
|
38
|
+
if (old.endsWith('/**')) return rule.startsWith(old.slice(0, -2))
|
|
39
|
+
if (old.endsWith('/')) return rule.startsWith(old)
|
|
40
|
+
return false
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const databaseFields = (database: NonNullable<AppConfig['database']>): NonNullable<AppConfig['database']> => ({
|
|
44
|
+
migrations: database.migrations,
|
|
45
|
+
shared: database.shared,
|
|
46
|
+
login: database.login,
|
|
47
|
+
migrator: database.migrator,
|
|
48
|
+
...(database.runtime === undefined ? {} : { runtime: database.runtime }),
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
const appFields = (app: AppConfig): AppConfig => ({
|
|
52
|
+
roots: app.roots,
|
|
53
|
+
shared: app.shared,
|
|
54
|
+
app: app.app,
|
|
55
|
+
entry: app.entry,
|
|
56
|
+
map: app.map,
|
|
57
|
+
...(app.database ? { database: databaseFields(app.database) } : {}),
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
/** 整份配置的文字:字段按固定顺序,弹窗里给用户看。 */
|
|
61
|
+
export function configText(config: Config): string {
|
|
62
|
+
if ('apps' in config) {
|
|
63
|
+
const apps = Object.fromEntries(Object.entries(config.apps).map(([name, app]) => [name, appFields(app)]))
|
|
64
|
+
return JSON.stringify({ apps, shared: config.shared, outside: config.outside, allow: config.allow })
|
|
65
|
+
}
|
|
66
|
+
return JSON.stringify({ ...appFields(config), outside: config.outside, allow: config.allow })
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const EMPTY: AppConfig = { roots: [], shared: [], app: [], entry: [], map: {} }
|
|
70
|
+
|
|
71
|
+
/** 新加的路径规则里,没被 old 的哪一条盖住的。 */
|
|
72
|
+
const widened = (old: readonly string[], now: readonly string[]): string[] => now.filter(rule => !old.some(previous => covers(previous, rule)))
|
|
73
|
+
|
|
74
|
+
const databaseText = (database: NonNullable<AppConfig['database']>): string => JSON.stringify(databaseFields(database))
|
|
75
|
+
|
|
76
|
+
/** before:分叉点上能用的配置。 */
|
|
77
|
+
export function looseningItems(before: Config | undefined, now: ConfigSide): LoosenItem[] {
|
|
78
|
+
if (!before) return now.config ? [{ text: `首次接入 modwall(分叉点上还没有配置),整份配置:${configText(now.config)}`, before: '', after: configText(now.config) }] : []
|
|
79
|
+
if (!now.config) {
|
|
80
|
+
return [{ text: now.hasDir ? `删掉了配置文件 ${CONFIG_PATH}` : `删掉了整个 ${MODWALL_DIR}/ 目录`, before: configText(before), after: '' }]
|
|
81
|
+
}
|
|
82
|
+
const old = schemeOf(before)
|
|
83
|
+
const scheme = schemeOf(now.config)
|
|
84
|
+
if (old.grouped !== scheme.grouped) {
|
|
85
|
+
const form = (grouped: boolean): string => (grouped ? '按应用分组的写法' : '单应用的写法')
|
|
86
|
+
return [
|
|
87
|
+
{
|
|
88
|
+
text: `配置从${form(old.grouped)}换成了${form(scheme.grouped)},和首次接入一样,整份配置:${configText(now.config)}`,
|
|
89
|
+
before: configText(before),
|
|
90
|
+
after: configText(now.config),
|
|
91
|
+
},
|
|
92
|
+
]
|
|
93
|
+
}
|
|
94
|
+
// 每个应用和分叉点上同名的应用比:新加的和空的应用比,删掉(或改名)的和空的应用比
|
|
95
|
+
const pairs: Array<{ before: App; now: App; gone?: true }> = [
|
|
96
|
+
...scheme.apps.map(app => ({ before: old.apps.find(previous => previous.name === app.name) ?? { ...EMPTY, ...(app.name === undefined ? {} : { name: app.name }) }, now: app })),
|
|
97
|
+
...old.apps
|
|
98
|
+
.filter(previous => !scheme.apps.some(app => app.name === previous.name))
|
|
99
|
+
.map(previous => ({ before: previous, now: { ...EMPTY, ...(previous.name === undefined ? {} : { name: previous.name }) }, gone: true as const })),
|
|
100
|
+
]
|
|
101
|
+
const items: LoosenItem[] = []
|
|
102
|
+
const add = (text: string, was: string, is: string): void => void items.push({ text, before: was, after: is })
|
|
103
|
+
for (const { before: was, now: app, gone } of pairs) {
|
|
104
|
+
for (const root of was.roots) {
|
|
105
|
+
if (app.roots.includes(root)) continue
|
|
106
|
+
add(gone ? `删掉了应用 ${was.name}(改名也算删掉):${field(was, 'roots')} 的模块根目录 "${root}" 不再管` : `${field(app, 'roots')} 删掉了模块根目录 "${root}"`, root, '')
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
for (const key of ['shared', 'app'] as const) {
|
|
110
|
+
for (const { before: was, now: app } of pairs) {
|
|
111
|
+
for (const rule of widened(was[key], app[key])) add(`${field(app, key)} 扩大:新增 "${rule}"`, '', rule)
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
for (const rule of widened(old.shared, scheme.shared)) add(`shared 扩大:新增 "${rule}"`, '', rule)
|
|
115
|
+
for (const rule of widened(old.outside, scheme.outside)) add(`outside 扩大:新增 "${rule}"`, '', rule)
|
|
116
|
+
for (const { before: was, now: app } of pairs) {
|
|
117
|
+
for (const [rule, name] of Object.entries(app.map)) {
|
|
118
|
+
if (Object.entries(was.map).some(([previous, module]) => module === name && covers(previous, rule))) continue
|
|
119
|
+
const previous = was.map[rule]
|
|
120
|
+
const key = field(app, 'map')
|
|
121
|
+
add(previous === undefined ? `${key} 新增:"${rule}" 归到 ${name} 模块` : `${key} 改了:"${rule}" 从 ${previous} 模块改归 ${name} 模块`, previous ?? '', name)
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
for (const { before: was, now: app, gone } of pairs) {
|
|
125
|
+
// 删掉的应用已经按删掉 roots 算了
|
|
126
|
+
if (!was.database || gone) continue
|
|
127
|
+
const key = field(app, 'database')
|
|
128
|
+
if (!app.database) {
|
|
129
|
+
add(`删掉了 ${key}:数据库不再按模块检查`, databaseText(was.database), '')
|
|
130
|
+
continue
|
|
131
|
+
}
|
|
132
|
+
for (const part of ['migrations', 'shared', 'login', 'migrator'] as const) {
|
|
133
|
+
if (was.database[part] !== app.database[part]) add(`${key}.${part} 改了:"${was.database[part]}" 改成 "${app.database[part]}"`, was.database[part], app.database[part])
|
|
134
|
+
}
|
|
135
|
+
const { runtime } = app.database
|
|
136
|
+
if (runtime !== undefined && runtime !== was.database.runtime) {
|
|
137
|
+
const previous = was.database.runtime
|
|
138
|
+
add(
|
|
139
|
+
previous === undefined
|
|
140
|
+
? `${key}.runtime 加上了模块运行角色 "${runtime}":它能用本模块的内部 schema`
|
|
141
|
+
: `${key}.runtime 改了:"${previous}" 改成 "${runtime}"(模块运行角色能用本模块的内部 schema)`,
|
|
142
|
+
previous ?? '',
|
|
143
|
+
runtime,
|
|
144
|
+
)
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
for (const { before: was, now: app } of pairs) {
|
|
148
|
+
for (const name of app.entry) {
|
|
149
|
+
if (!was.entry.includes(name)) add(`${field(app, 'entry')} 新增入口文件名 "${name}"`, '', name)
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
for (const entry of scheme.allow) {
|
|
153
|
+
const same = old.allow.some(previous => previous.rule === entry.rule && previous.from === entry.from && previous.to === entry.to && previous.reason === entry.reason)
|
|
154
|
+
if (!same) add(`allow 新增例外:${entry.rule} ${entry.from} → ${entry.to},理由:${entry.reason}`, '', JSON.stringify([entry.rule, entry.from, entry.to, entry.reason]))
|
|
155
|
+
}
|
|
156
|
+
return items
|
|
157
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// 小程序里代码以外的引用:LayerMap 不读 .json、.wxml、.wxss,modwall 自己读出来,当成 import 照 R1、R2、R3 判。
|
|
2
|
+
// 页面、组件的 .json 里 usingComponents 的组件路径(组件的 .ts/.js/.json/.wxml 之一)
|
|
3
|
+
// .wxml 里 <import src>、<include src>、<wxs src>
|
|
4
|
+
// .wxss 里 @import
|
|
5
|
+
// 以 / 开头的路径从小程序根目录(有 app.json 的目录)算,以 . 开头的从文件所在目录算;别的写法(npm 包、plugin://)不管。
|
|
6
|
+
// 对上项目里的文件的给出 import;以 / 或 . 开头、却对不上文件的列为"没检查到"。
|
|
7
|
+
|
|
8
|
+
import { posix } from 'node:path'
|
|
9
|
+
import type { ImportFact } from './layermap.ts'
|
|
10
|
+
|
|
11
|
+
/** 读出来的小程序引用:对上文件的(imports)和对不上的(unresolved,"文件:行 写的路径")。 */
|
|
12
|
+
export interface MiniprogramRefs {
|
|
13
|
+
imports: ImportFact[]
|
|
14
|
+
unresolved: string[]
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const COMPONENT_FILES = ['.ts', '.js', '.json', '.wxml']
|
|
18
|
+
const TEMPLATE = /<(?:import|include|wxs)\b[^>]*?\bsrc\s*=\s*["']([^"']+)["']/g
|
|
19
|
+
const STYLE_IMPORT = /@import\s+(?:url\(\s*)?["']([^"']+)["']/g
|
|
20
|
+
|
|
21
|
+
/** 文件里第几行(从 1 开始)。 */
|
|
22
|
+
const lineAt = (text: string, index: number): number => text.slice(0, index).split('\n').length
|
|
23
|
+
|
|
24
|
+
/** 小程序根目录:有 app.json 的目录,取离文件最近的那个。 */
|
|
25
|
+
function rootOf(roots: readonly string[], path: string): string | undefined {
|
|
26
|
+
return roots.filter(root => root === '' || path.startsWith(`${root}/`)).sort((a, b) => b.length - a.length)[0]
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function miniprogramRefs(files: readonly string[], read: (path: string) => string): MiniprogramRefs {
|
|
30
|
+
const roots = files.filter(path => path === 'app.json' || path.endsWith('/app.json')).map(path => posix.dirname(path).replace(/^\.$/, ''))
|
|
31
|
+
const result: MiniprogramRefs = { imports: [], unresolved: [] }
|
|
32
|
+
if (roots.length === 0) return result
|
|
33
|
+
const present = new Set(files)
|
|
34
|
+
|
|
35
|
+
for (const from of files) {
|
|
36
|
+
if (!/\.(?:json|wxml|wxss)$/.test(from)) continue
|
|
37
|
+
const root = rootOf(roots, from)
|
|
38
|
+
if (root === undefined) continue
|
|
39
|
+
const found: Array<{ specifier: string; index: number; candidates: (path: string) => string[] }> = []
|
|
40
|
+
let text: string
|
|
41
|
+
try {
|
|
42
|
+
text = read(from)
|
|
43
|
+
} catch {
|
|
44
|
+
continue
|
|
45
|
+
}
|
|
46
|
+
if (from.endsWith('.json')) {
|
|
47
|
+
let usingComponents: unknown
|
|
48
|
+
try {
|
|
49
|
+
usingComponents = (JSON.parse(text) as { usingComponents?: unknown }).usingComponents
|
|
50
|
+
} catch {
|
|
51
|
+
continue
|
|
52
|
+
}
|
|
53
|
+
if (typeof usingComponents !== 'object' || usingComponents === null) continue
|
|
54
|
+
for (const value of Object.values(usingComponents)) {
|
|
55
|
+
if (typeof value !== 'string') continue
|
|
56
|
+
found.push({ specifier: value, index: text.indexOf(JSON.stringify(value)), candidates: path => COMPONENT_FILES.map(ext => `${path}${ext}`) })
|
|
57
|
+
}
|
|
58
|
+
} else if (from.endsWith('.wxml')) {
|
|
59
|
+
for (const match of text.matchAll(TEMPLATE)) {
|
|
60
|
+
const specifier = match[1] as string
|
|
61
|
+
const ext = /<wxs\b/.test(match[0]) ? '.wxs' : '.wxml'
|
|
62
|
+
found.push({ specifier, index: match.index, candidates: path => (posix.extname(path) ? [path] : [`${path}${ext}`]) })
|
|
63
|
+
}
|
|
64
|
+
} else if (from.endsWith('.wxss')) {
|
|
65
|
+
for (const match of text.matchAll(STYLE_IMPORT)) {
|
|
66
|
+
found.push({ specifier: match[1] as string, index: match.index, candidates: path => (posix.extname(path) ? [path] : [`${path}.wxss`]) })
|
|
67
|
+
}
|
|
68
|
+
} else continue
|
|
69
|
+
|
|
70
|
+
for (const { specifier, index, candidates } of found) {
|
|
71
|
+
const base = specifier.startsWith('/') ? posix.join(root, specifier.slice(1)) : specifier.startsWith('.') ? posix.join(posix.dirname(from), specifier) : undefined
|
|
72
|
+
if (base === undefined) continue
|
|
73
|
+
const line = lineAt(text, Math.max(index, 0))
|
|
74
|
+
const to = base.startsWith('../') ? undefined : candidates(posix.normalize(base)).find(path => present.has(path))
|
|
75
|
+
if (to === undefined) result.unresolved.push(`${from}:${line} 写的 "${specifier}"`)
|
|
76
|
+
else if (to !== from) result.imports.push({ from, line, to, specifier })
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return result
|
|
80
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// 打开一个仓库:是否接入、分叉点、工作区和分叉点上的配置、工作区里的文件。check、status、会话说明、停止门、改文件前的检查共用。
|
|
2
|
+
// 分叉点、两版配置都向底座要(base/git.ts 的 forkPoint、base/judging.ts):.modwall/config.json 是评判用的配置,
|
|
3
|
+
// 走"用户同意后生效"那条路——和分叉点那一版比,放宽的列出来让用户确认(loosen.ts)。
|
|
4
|
+
|
|
5
|
+
import { existsSync, readFileSync } from 'node:fs'
|
|
6
|
+
import { join } from 'node:path'
|
|
7
|
+
import { currentBranch, fileNow, filesNow, forkPoint } from '../base/git.ts'
|
|
8
|
+
import { judgingFile } from '../base/judging.ts'
|
|
9
|
+
import { hash } from '../base/records.ts'
|
|
10
|
+
import { type Config, CONFIG_PATH, joined, MODWALL_DIR, parseConfig, readConfig } from './config.ts'
|
|
11
|
+
import { isCode } from './files.ts'
|
|
12
|
+
import { Layout } from './layout.ts'
|
|
13
|
+
import { type ConfigSide, configText } from './loosen.ts'
|
|
14
|
+
|
|
15
|
+
export interface Project {
|
|
16
|
+
root: string
|
|
17
|
+
/** 和默认分支的分叉点;找不到时 baseProblem 说明原因。 */
|
|
18
|
+
base?: { commit: string; branch: string }
|
|
19
|
+
baseProblem?: string
|
|
20
|
+
/** 当前分支名(日志用)。 */
|
|
21
|
+
branch: string
|
|
22
|
+
now: ConfigSide & { exists: boolean; problems: string[] }
|
|
23
|
+
/** 分叉点上能用的配置(文件在、校验通过)。 */
|
|
24
|
+
before: { config?: Config }
|
|
25
|
+
/** 工作区里现有的文件(被 git 忽略的不算;LayerMap 不读的目录里的也算)。 */
|
|
26
|
+
files: string[]
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export type Opened = { project: Project } | { notJoined: true }
|
|
30
|
+
|
|
31
|
+
export function openProject(root: string): Opened {
|
|
32
|
+
const found = forkPoint(root)
|
|
33
|
+
const base = found.commit === undefined ? undefined : { commit: found.commit, branch: found.branch }
|
|
34
|
+
if (!joined(root, found.commit)) return { notJoined: true }
|
|
35
|
+
// 算不出分叉点时没有改之前那一版可比:check 说没法检查,这里只给工作区现在这一版
|
|
36
|
+
const judging = base ? judgingFile(root, base.commit, CONFIG_PATH) : { before: undefined, now: fileNow(root, CONFIG_PATH) }
|
|
37
|
+
const loaded = readConfig(judging.now)
|
|
38
|
+
const beforeConfig = judging.before === undefined ? undefined : parseConfig(judging.before).config
|
|
39
|
+
return {
|
|
40
|
+
project: {
|
|
41
|
+
root,
|
|
42
|
+
...(found.commit === undefined ? { baseProblem: found.problem } : { base }),
|
|
43
|
+
branch: currentBranch(root) ?? 'HEAD',
|
|
44
|
+
now: {
|
|
45
|
+
exists: loaded.exists,
|
|
46
|
+
problems: loaded.problems,
|
|
47
|
+
hasDir: existsSync(join(root, MODWALL_DIR)),
|
|
48
|
+
...(loaded.config ? { config: loaded.config } : {}),
|
|
49
|
+
},
|
|
50
|
+
before: beforeConfig ? { config: beforeConfig } : {},
|
|
51
|
+
files: filesNow(root),
|
|
52
|
+
},
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function layoutOf(project: Project, config: Config): Layout {
|
|
57
|
+
return new Layout(config, project.files)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** 影响检查结果的文件:代码文件(含测试),JSON(配置、路径别名、包清单、小程序页面配置),Python 和 Go 的项目文件,SQL(迁移),小程序的模板和样式。 */
|
|
61
|
+
const MATTERS = (path: string): boolean => isCode(path) || /\.(?:json|toml|sql|wxml|wxss)$/.test(path) || /(?:^|\/)go\.(?:mod|work)$/.test(path)
|
|
62
|
+
|
|
63
|
+
/** contentKey 的算法的名字:算法变了要改它,会话起点里以前记的样子就不算了(见 base/baseline.ts)。 */
|
|
64
|
+
export const CONTENT_FORMAT = 'content-1'
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* 当前内容的摘要:分叉点上的配置加上影响检查结果的文件。通过记录、会话起点都按它记。
|
|
68
|
+
* 检查能不能过,和分叉点有关的只有那里的配置(放宽项和它比;R4、入口清单只是提示),所以不记分叉点的提交号:
|
|
69
|
+
* 在默认分支上提交、默认分支往前走,都不让通过记录失效;分叉点上的配置变了才失效。
|
|
70
|
+
*/
|
|
71
|
+
export function contentKey(project: Project): string {
|
|
72
|
+
const parts: string[] = [project.base ? (project.before.config ? configText(project.before.config) : 'no-config') : 'no-base']
|
|
73
|
+
for (const path of project.files.filter(MATTERS).sort()) {
|
|
74
|
+
parts.push(path)
|
|
75
|
+
try {
|
|
76
|
+
parts.push(readFileSync(join(project.root, path), 'utf8'))
|
|
77
|
+
} catch {
|
|
78
|
+
parts.push('\u0000unreadable')
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return hash(...parts)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** 这个仓库现在的内容摘要(重新打开一遍);没接入时为 undefined。写通过记录前用它核对内容没变。 */
|
|
85
|
+
export function currentKey(root: string): string | undefined {
|
|
86
|
+
const opened = openProject(root)
|
|
87
|
+
return 'project' in opened ? contentKey(opened.project) : undefined
|
|
88
|
+
}
|