@fudanda/create-arcbase 2.20261026.1-beta.1 → 2.20261107.1-beta.1
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/.runtime/npm/index.json +18 -18
- package/.runtime/sdk.json +3 -3
- package/LICENSE +21 -21
- package/README.md +99 -91
- package/cli.mjs +42 -39
- package/package.json +10 -5
- package/src/assistant.mjs +76 -0
- package/src/delivery.mjs +20 -20
- package/src/enhance.mjs +103 -104
- package/src/evolve.mjs +66 -66
- package/src/fields.mjs +73 -73
- package/src/goa-contracts.mjs +331 -331
- package/src/goa.mjs +202 -202
- package/src/history.mjs +16 -16
- package/src/layout.mjs +1 -1
- package/src/module.mjs +439 -477
- package/src/packages.mjs +12 -4
- package/src/page-antd.mjs +98 -77
- package/src/page-webmcp.mjs +51 -0
- package/src/project.mjs +112 -105
- package/src/records.mjs +15 -15
- package/src/release-vite.mjs +1 -0
- package/src/release.mjs +455 -0
- package/src/templates.mjs +20 -20
- package/src/upgrade.mjs +415 -249
- package/templates/module/02-migrations.go.txt +10 -10
- package/templates/module/03-service.go.txt +52 -52
- package/templates/module/04-module.go.txt +12 -12
- package/templates/module/06-queries.ts.txt +15 -15
- package/templates/module/08-service_test.go.txt +9 -9
- package/templates/module/09-TransferPanel.tsx.txt +16 -0
- package/templates/module-runtime-test.go.txt +86 -86
- package/templates/module-transfer.go.txt +74 -74
- package/templates/project-v2/.agents/skills/arcbase/SKILL.md +32 -0
- package/templates/project-v2/.agents/skills/goa-service-designer/SKILL.md +31 -0
- package/templates/project-v2/AGENTS.md +38 -0
- package/templates/project-v2/DEVELOPMENT.md +115 -84
- package/templates/project-v2/README.md +76 -74
- package/templates/project-v2/RELEASE.md +88 -0
- package/templates/project-v2/TEAM-TRIAL.md +32 -32
- package/templates/project-v2/arcbase.release.json +23 -0
- package/templates/project-v2/cmd/server/main.go +62 -36
- package/templates/project-v2/cmd/server/modules.gen.go +6 -6
- package/templates/project-v2/eslint.config.mjs +9 -9
- package/templates/project-v2/internal/dashboard/dist/README.txt +1 -1
- package/templates/project-v2/internal/dashboard/embed.go +11 -11
- package/templates/project-v2/package.json +11 -4
- package/templates/project-v2/scripts/application-version.mjs +138 -0
- package/templates/project-v2/scripts/assets.mjs +13 -14
- package/templates/project-v2/scripts/build-backend.mjs +11 -9
- package/templates/project-v2/scripts/build.mjs +12 -0
- package/templates/project-v2/scripts/check-generated.mjs +79 -48
- package/templates/project-v2/scripts/config.mjs +55 -54
- package/templates/project-v2/scripts/dev-watch.mjs +78 -78
- package/templates/project-v2/scripts/dev.mjs +50 -49
- package/templates/project-v2/scripts/doctor.mjs +94 -94
- package/templates/project-v2/scripts/generate-contracts.mjs +88 -88
- package/templates/project-v2/scripts/go-build-identity/main.go +210 -0
- package/templates/project-v2/scripts/go.mjs +17 -15
- package/templates/project-v2/scripts/layout.mjs +10 -10
- package/templates/project-v2/scripts/lifecycle.mjs +245 -245
- package/templates/project-v2/scripts/openobserve-build.mjs +115 -0
- package/templates/project-v2/scripts/project-info.mjs +105 -0
- package/templates/project-v2/scripts/release-metadata.mjs +13 -0
- package/templates/project-v2/scripts/release-vite.mjs +23 -0
- package/templates/project-v2/scripts/release.mjs +3 -0
- package/templates/project-v2/scripts/run.mjs +11 -11
- package/templates/project-v2/scripts/sdk-integrity.mjs +39 -39
- package/templates/project-v2/scripts/setup.mjs +44 -44
- package/templates/project-v2/web/admin/index.html +5 -5
- package/templates/project-v2/web/admin/package.json +3 -2
- package/templates/project-v2/web/admin/src/brand.json +1 -1
- package/templates/project-v2/web/admin/src/extensions.gen.ts +6 -6
- package/templates/project-v2/web/admin/src/extensions.ts +1 -1
- package/templates/project-v2/web/admin/src/main.tsx +20 -14
- package/templates/project-v2/web/admin/tsconfig.json +17 -17
- package/templates/project-v2/web/admin/vite.config.ts +47 -27
- package/src/page.mjs +0 -66
- package/templates/module/07-Page.tsx.txt +0 -20
package/src/upgrade.mjs
CHANGED
|
@@ -1,249 +1,415 @@
|
|
|
1
|
-
import { cpSync, existsSync, globSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs';
|
|
2
|
-
import { dirname, resolve } from 'node:path';
|
|
3
|
-
import { execFileSync } from 'node:child_process';
|
|
4
|
-
import { randomUUID } from 'node:crypto';
|
|
5
|
-
import { checkedOutput, checkedProject, toolRoot } from './project.mjs';
|
|
6
|
-
import { readDelivery, sha256, verifySDK } from './delivery.mjs';
|
|
7
|
-
import { hostPackageNames } from '../templates/project-v2/scripts/sdk-integrity.mjs';
|
|
8
|
-
import { retiredPackages, rewritePublicImports } from './packages.mjs';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const
|
|
43
|
-
if (!
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
if (
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
manifest
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
const
|
|
179
|
-
const
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
for(const [
|
|
235
|
-
|
|
236
|
-
if(
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
}
|
|
1
|
+
import { cpSync, existsSync, globSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { dirname, resolve } from 'node:path';
|
|
3
|
+
import { execFileSync } from 'node:child_process';
|
|
4
|
+
import { randomUUID } from 'node:crypto';
|
|
5
|
+
import { checkedOutput, checkedProject, toolRoot } from './project.mjs';
|
|
6
|
+
import { readDelivery, sha256, verifySDK } from './delivery.mjs';
|
|
7
|
+
import { hostPackageNames } from '../templates/project-v2/scripts/sdk-integrity.mjs';
|
|
8
|
+
import { retiredPackages, rewritePublicImports } from './packages.mjs';
|
|
9
|
+
import { planAssistantGuidance, renderAssistantGuidance } from './assistant.mjs';
|
|
10
|
+
import { parseApplicationVersion } from '../templates/project-v2/scripts/application-version.mjs';
|
|
11
|
+
import { sourceDigest } from './history.mjs';
|
|
12
|
+
|
|
13
|
+
const moduleName = 'github.com/fudanda/arcbase/backend/v2';
|
|
14
|
+
export function upgradeNpmCLI({ npmExecPath = process.env.npm_execpath, node = process.execPath, exists = existsSync } = {}) {
|
|
15
|
+
const candidates = [npmExecPath, resolve(dirname(node), 'node_modules/npm/bin/npm-cli.js'), resolve(dirname(node), '../lib/node_modules/npm/bin/npm-cli.js')];
|
|
16
|
+
const npm = candidates.find(file => typeof file === 'string' && /(?:^|[\\/])npm-cli\.[cm]?js$/i.test(file) && exists(file));
|
|
17
|
+
if (!npm) throw new Error('Official npm CLI was not found; run upgrade through npm exec so package-lock.json is refreshed by npm');
|
|
18
|
+
return npm;
|
|
19
|
+
}
|
|
20
|
+
function prepareRegistryLock(root, path, names) {
|
|
21
|
+
const lock = existsSync(path) ? JSON.parse(readFileSync(path, 'utf8')) : { lockfileVersion: 3, requires: true, packages: {} };
|
|
22
|
+
if (!lock.packages || typeof lock.packages !== 'object' || Array.isArray(lock.packages)) throw new Error('Upgrade requires a modern npm lockfile');
|
|
23
|
+
// Resolve SDK peers together, without reusing their old archive/installed tree.
|
|
24
|
+
// Keep unrelated locked dependencies and let npm validate all peer constraints.
|
|
25
|
+
for (const entry of Object.keys(lock.packages)) if (names.some(name => entry === `node_modules/${name}` || entry.endsWith(`/node_modules/${name}`))) delete lock.packages[entry];
|
|
26
|
+
for (const name of names) if (lock.dependencies) delete lock.dependencies[name];
|
|
27
|
+
const pkg = JSON.parse(readFileSync(resolve(root, 'package.json'), 'utf8'));
|
|
28
|
+
if (pkg.version !== undefined) lock.version = pkg.version;
|
|
29
|
+
lock.packages[''] ??= {};
|
|
30
|
+
for (const key of ['name', 'version', 'workspaces', 'dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies']) {
|
|
31
|
+
if (pkg[key] === undefined) delete lock.packages[''][key]; else lock.packages[''][key] = pkg[key];
|
|
32
|
+
}
|
|
33
|
+
writeFileSync(path, JSON.stringify(lock, null, 2) + '\n');
|
|
34
|
+
}
|
|
35
|
+
function semver(value) {
|
|
36
|
+
const match = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-(alpha|beta|rc)\.(0|[1-9]\d*))?$/.exec(value);
|
|
37
|
+
if (!match) throw new Error('Upgrade requires an exact supported SDK version');
|
|
38
|
+
return [Number(match[1]), Number(match[2]), Number(match[3]), match[4] ? ['alpha', 'beta', 'rc'].indexOf(match[4]) : 3, Number(match[5] ?? 0)];
|
|
39
|
+
}
|
|
40
|
+
function compare(a, b) { const left = semver(a), right = semver(b); for (let i = 0; i < left.length; i++) if (left[i] !== right[i]) return Math.sign(left[i] - right[i]); return 0; }
|
|
41
|
+
function running(root) {
|
|
42
|
+
const path = checkedOutput(root, '.arcbase/runtime/processes.json');
|
|
43
|
+
if (!existsSync(path)) return false;
|
|
44
|
+
const value = JSON.parse(readFileSync(path, 'utf8'));
|
|
45
|
+
if (!Array.isArray(value.processes)) throw new Error('Invalid managed process state');
|
|
46
|
+
return value.processes.some(record => { if (!Number.isInteger(record.pid) || record.pid < 1) throw new Error('Invalid managed PID'); try { process.kill(record.pid, 0); return true; } catch (error) { if (error.code === 'ESRCH') return false; throw error; } });
|
|
47
|
+
}
|
|
48
|
+
function replaceSDKRequirement(source, version, layout) {
|
|
49
|
+
const required = new RegExp(`(^|\\n)(\\s*(?:require\\s+)?${moduleName.replaceAll('.', '\\.')}\\s+)v[^\\s]+`);
|
|
50
|
+
if (!required.test(source)) throw new Error('Go SDK requirement is missing or customized');
|
|
51
|
+
const expectedReplace = new RegExp(`replace\\s+${moduleName.replaceAll('.', '\\.')}\\s*=>\\s*(?:\\./)?${layout.sdk.replaceAll('.', '\\.')}\\s*(?:\\n|$)`);
|
|
52
|
+
const goRelative = layout.sdk;
|
|
53
|
+
if (!expectedReplace.test(source) && !source.includes(`replace ${moduleName} => ${goRelative}`)) throw new Error('Go SDK replace must reference the project-owned SDK');
|
|
54
|
+
return source.replace(required, (_all, line, prefix) => `${line}${prefix}v${version}`);
|
|
55
|
+
}
|
|
56
|
+
function migrationReview(root, manifest, layout, current, installed, target) {
|
|
57
|
+
const dialect = ['postgres', 'sqlite'].includes(manifest.database) ? manifest.database : 'unknown';
|
|
58
|
+
const sqlPath = path => /^migrations\/(?:sqlite\/)?[^/]+\.sql$/.test(path)
|
|
59
|
+
&& (dialect === 'unknown' || (dialect === 'sqlite') === path.startsWith('migrations/sqlite/'));
|
|
60
|
+
const snapshot = (metadata, backend) => {
|
|
61
|
+
const files = metadata.files.filter(file => sqlPath(file.path)).map(file => ({path: file.path, sha256: sourceDigest(readFileSync(resolve(backend, file.path)))})).sort((a, b) => a.path.localeCompare(b.path));
|
|
62
|
+
const versionFile = metadata.files.find(file => file.path === 'migrations/assets.go');
|
|
63
|
+
const version = versionFile ? Number(readFileSync(resolve(backend, versionFile.path), 'utf8').match(/\bconst\s+SchemaVersion\s*=\s*(\d+)/)?.[1]) : undefined;
|
|
64
|
+
const schemaVersion = Number.isSafeInteger(version) ? version : null;
|
|
65
|
+
return {schemaVersion, files, fingerprint: sha256(JSON.stringify({schemaVersion, files}))};
|
|
66
|
+
};
|
|
67
|
+
const before = snapshot(current, installed), after = snapshot(target.sdk, target.backend);
|
|
68
|
+
const prior = new Map(before.files.map(file => [file.path, file.sha256])), next = new Map(after.files.map(file => [file.path, file.sha256]));
|
|
69
|
+
const changes = [...new Set([...prior.keys(), ...next.keys()])].sort().flatMap(path => prior.get(path) === next.get(path) ? [] : [{path, kind: !prior.has(path) ? 'added' : !next.has(path) ? 'removed' : 'modified'}]);
|
|
70
|
+
const changed = before.fingerprint !== after.fingerprint;
|
|
71
|
+
const appendOnly = dialect !== 'unknown' && changes.length > 0 && changes.every(change => change.kind === 'added')
|
|
72
|
+
&& before.schemaVersion !== null && after.schemaVersion !== null && after.schemaVersion > before.schemaVersion;
|
|
73
|
+
const hostPaths = globSync([`${layout.domains}/**/migrations*.go`, `${layout.domains}/**/migrations/**/*.sql`, 'migrations/**/*.sql'], {cwd: root}).map(path => path.replaceAll('\\', '/')).sort();
|
|
74
|
+
const baseline = new Map();
|
|
75
|
+
for (const module of manifest.modules) {
|
|
76
|
+
if (!/^[a-z][a-z0-9_-]*$/.test(module.id ?? '')) throw new Error('Invalid module in project manifest');
|
|
77
|
+
for (const path of globSync([`.arcbase/module-history/${module.id}/v*.json`], {cwd: root}).sort()) {
|
|
78
|
+
const history = JSON.parse(readFileSync(checkedOutput(root, path), 'utf8'));
|
|
79
|
+
if (history.spec?.id !== module.id || !Number.isSafeInteger(history.version) || !Array.isArray(history.files)) throw new Error('Invalid host migration history');
|
|
80
|
+
if (history.version > (module.version ?? 1)) continue;
|
|
81
|
+
for (const file of history.files) if (typeof file.path === 'string' && file.path.startsWith(`${layout.domains}/${module.id}/`)
|
|
82
|
+
&& /(?:^|\/)migrations(?:_[^/]+)?\.go$|\/migrations\/.*\.sql$/.test(file.path) && /^[a-f0-9]{64}$/.test(file.sha256 ?? '')) baseline.set(file.path, file.sha256);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
const hostFiles = hostPaths.map(path => ({path, sha256: sourceDigest(readFileSync(checkedOutput(root, path)))}));
|
|
86
|
+
const hostCurrent = new Map(hostFiles.map(file => [file.path, file.sha256]));
|
|
87
|
+
const hostReview = [...new Set([...baseline.keys(), ...hostCurrent.keys()])].sort().flatMap(path => baseline.get(path) === hostCurrent.get(path) ? [] : [{path,
|
|
88
|
+
reason: !hostCurrent.has(path) ? 'missing' : baseline.has(path) ? 'changed' : 'baseline-unavailable'}]);
|
|
89
|
+
const reviewRequired = hostReview.length > 0 || changed && !appendOnly;
|
|
90
|
+
return {dialect, action: reviewRequired ? 'review' : changed ? 'migrate' : 'none',
|
|
91
|
+
sdk: {changed, before, after, changes},
|
|
92
|
+
host: {fingerprint: sha256(JSON.stringify(hostFiles)), files: hostFiles, review: hostReview},
|
|
93
|
+
databaseInspected: false,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
function nativeMigrationReport(root, manifest, layout, current, target) {
|
|
97
|
+
if (!target.files.some(file => file.path === 'gen/arcbase/policies.go')) return null;
|
|
98
|
+
const manualChanges = [];
|
|
99
|
+
const paths = globSync(['cmd/**/*.go', 'internal/**/*.go', 'scripts/**/*.mjs', 'web/**/*.ts', 'web/**/*.tsx'], {
|
|
100
|
+
cwd: root, exclude: ['**/node_modules/**', '**/dist/**', '**/generated/**', '**/gen/**', '**/ent/**'],
|
|
101
|
+
}).map(path => path.replaceAll('\\', '/'));
|
|
102
|
+
const add = (path, code, reason, steps) => {
|
|
103
|
+
const file = checkedOutput(root, path);
|
|
104
|
+
manualChanges.push({ path, sha256: sha256(readFileSync(file)), code, reason, steps });
|
|
105
|
+
};
|
|
106
|
+
if (manifest.ui !== 'antd') add('arcbase.project.json', 'GOA_ADMIN_UI',
|
|
107
|
+
'旧 Semi 管理台不在当前交付范围内,必须显式迁移到 Ant 后才能升级。',
|
|
108
|
+
['保留旧宿主、业务页面和备份;需要维护 Semi 时使用 codex/archive-node-semi-20261106 分支。',
|
|
109
|
+
'在隔离宿主迁移至 Ant Design 公开 SDK,并完成页面、权限、业务数据和备份恢复验收后,再同步项目 UI 标记。']);
|
|
110
|
+
if (semver(current.version)[0] !== semver(target.version)[0]) add('go.mod', 'GOA_MODULE_PATH',
|
|
111
|
+
'v2 是独立的 Go module,旧宿主必须显式迁移公开 API 和 imports。',
|
|
112
|
+
['将 requirement、replace 和宿主 imports 改为 github.com/fudanda/arcbase/backend/v2,使用同次归档的精确版本与 SDK。',
|
|
113
|
+
'按 Goa v2 迁移指南审阅宿主和业务模块,完成双数据库、页面与备份恢复验收后再升级。']);
|
|
114
|
+
if (/"(?:@fddarcbase\/[^"\s]+|create-arcbase)"\s*:/.test(readFileSync(checkedOutput(root, 'package.json'), 'utf8'))) add('package.json', 'GOA_NPM_SCOPE',
|
|
115
|
+
'v2 npm 包统一使用当前发布账号的 @fudanda 命名空间。',
|
|
116
|
+
['将公开依赖、浏览器 imports 和嵌套 workspace 改为 @fudanda/*,生成器依赖改为 @fudanda/create-arcbase。',
|
|
117
|
+
'create-arcbase 可执行命令保持不变;使用同次归档的精确版本,重新安装并核验 lockfile 与独立构建。']);
|
|
118
|
+
if (manifest.sdk && (manifest.sdk.version !== current.version || manifest.sdk.sha256 !== current.sha256)) add('arcbase.project.json', 'GOA_SDK_METADATA',
|
|
119
|
+
'项目记录的 SDK 元数据与已校验的安装源码不同,不能自动覆盖该边界。',
|
|
120
|
+
['核对 arcbase.project.json、.arcbase/sdk.json 和安装源码的 SHA256,保留原版本快照。', '完成旧宿主 Goa 迁移后,审阅并同步单一 SDK 目录及对应元数据,再重新预检。']);
|
|
121
|
+
for (const path of paths.sort()) {
|
|
122
|
+
const source = readFileSync(checkedOutput(root, path), 'utf8');
|
|
123
|
+
const imports = [...source.matchAll(/(?:(\w+)\s+)?["']github\.com\/fudanda\/arcbase\/backend\/v2["']/g)].map(match => match[1] && match[1] !== 'import' ? match[1] : 'arcbase');
|
|
124
|
+
const removedSDKCall = imports.some(alias => new RegExp('\\b' + alias + '\\.(?:Route|Respond|Fail|DecodeJSON)\\b').test(source));
|
|
125
|
+
if (removedSDKCall || /\b(?:HostContract|RunGoFr|MountGoFr)\b|["']gofr\.dev(?:\/|["'])/.test(source)) add(path, 'GOA_HOST_API',
|
|
126
|
+
'目标 SDK 已移除旧宿主和契约兼容 API;原模块需要显式迁移到 Goa。',
|
|
127
|
+
['在该模块的 design/design.go 中定义唯一 Goa DSL,保留 operationId、路径、权限、API Key scope 和事务审计。', '生成 Go 服务、HTTP transport、嵌入 PolicySet 与 TypeScript descriptor;Initialize 接收 *arcbase.Registrar。', '将生成的 typed payload 逐字段传入领域方法;保留显式 Ent 事务、数据范围和审计失败回滚。', '使用 Framework.Run(ctx) 或标准 net/http Host;BeginDrain 后结束流、排空请求并 Shutdown。']);
|
|
128
|
+
else if (/oapi-codegen|generate-automation-contracts|generate-foundation-contracts/.test(source)) add(path, 'GOA_GENERATION',
|
|
129
|
+
'旧生成入口创建第二份 HTTP 契约。', ['移除旧 Zod/OpenAPI/DTO 正向生成,改用 Goa DSL → Go/OpenAPI/嵌入策略 → create-arcbase/goa-contracts。', '在隔离目录完成 Go 和严格 TypeScript 编译后发布生成结果;普通 build/check 不重写业务源码。']);
|
|
130
|
+
else if (/\bnew Client\s*\(/.test(source) && source.includes('@fudanda/client')) add(path, 'GOA_CLIENT',
|
|
131
|
+
'默认宿主需要消费 Goa 原生响应和错误。', ['从 @fudanda/client 导入 GoaClient 并使用生成的 Goa operations。', '将登录结果改为 outcome.type/session 与 outcome.value;更新创建 201、删除/撤销 204 及原生错误断言。']);
|
|
132
|
+
}
|
|
133
|
+
for (const module of manifest.modules) {
|
|
134
|
+
if (!/^[a-z][a-z0-9_-]*$/.test(module.id ?? '')) throw new Error('Invalid module in project manifest');
|
|
135
|
+
const path = `${layout.domains}/${module.id}/contract.gen.json`;
|
|
136
|
+
if (existsSync(checkedOutput(root, path))) add(path, 'GOA_LEGACY_CONTRACT', '旧 HTTP 契约产物不能与 Goa 并存为活动源。',
|
|
137
|
+
['先将其操作、校验、权限、Key scope 和审计逐项对账到 Goa DSL。', '验证生成客户端与真实 HTTP 后,删除旧 contract.gen.json/OpenAPI/DTO 及旧 handler;保持领域规则、版本迁移和数据不变。']);
|
|
138
|
+
}
|
|
139
|
+
const legacyEnv = '.env';
|
|
140
|
+
if (existsSync(checkedOutput(root, legacyEnv)) && !existsSync(checkedOutput(root, 'configs/.local.env'))) add(legacyEnv, 'GOA_CONFIGURATION',
|
|
141
|
+
'目标宿主仅使用系统环境和选定 configs/.APP_ENV.env、configs/.env 层级。',
|
|
142
|
+
['人工迁移既有配置到受保护的 configs/.local.env,保留数据库、加密密钥、身份模式和文件目录原值。', '只使用 ARCBASE_ADDR;清理 HTTP_PORT/METRICS_PORT/GOFR_*,启动前用 doctor 检查,禁止重新初始化既有数据。']);
|
|
143
|
+
const legacySDK = `${layout.sdk}/backend/go.mod`;
|
|
144
|
+
if (existsSync(checkedOutput(root, legacySDK))) add(legacySDK, 'GOA_SDK_LAYOUT', '旧示例使用嵌套 SDK 目录,目标宿主要求项目自有的单一 SDK 源码树。',
|
|
145
|
+
['备份并校验原 SDK 元数据,人工审阅 go.mod replace 和脚本路径,迁移为 .arcbase/sdk 与 .arcbase/sdk.json。', '新 SDK 来自同版本 @fudanda/go-sdk 的校验源码;不得 replace 到 ArcBase 主仓库源码。']);
|
|
146
|
+
if (!manualChanges.length) return null;
|
|
147
|
+
return {
|
|
148
|
+
project: root, code: 'GOA_MIGRATION_REQUIRED', from: current.version, to: target.version, changed: false, canApply: false,
|
|
149
|
+
databaseChanges: false, templateChanges: false, sdkBoundary: { fromSha256: current.sha256, toSha256: target.sha256 }, manualChanges,
|
|
150
|
+
next: ['在独立分支按上述文件和 SHA256 审阅迁移;保持业务数据和配置原值。', '完成 Goa 契约、原生 Host/Client 和生成链迁移后,再运行 upgrade --check。', '升级后显式 generate/build/check、双库权限/事务审计/流测试,并验证备份恢复。'],
|
|
151
|
+
warnings: ['SDK、包清单、lockfile、业务源码、配置和数据库均未修改。旧 HostContract API 不提供运行兼容层。'],
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
export function upgradeProject(project, { check = false, runtime = resolve(toolRoot, '.runtime'), sdkRoot, refreshLock } = {}) {
|
|
155
|
+
const { root, manifest, marker, layout } = checkedProject(project, { legacyMigrationReview: true });
|
|
156
|
+
const delivery = readDelivery(runtime, { sdkRoot });
|
|
157
|
+
const metadataPath = checkedOutput(root, layout.sdkMetadata);
|
|
158
|
+
const sdkPath = checkedOutput(root, layout.sdk);
|
|
159
|
+
const current = JSON.parse(readFileSync(metadataPath, 'utf8'));
|
|
160
|
+
const nestedSDK = checkedOutput(root, `${layout.sdk}/backend`);
|
|
161
|
+
const installedSDK = !existsSync(resolve(sdkPath, 'go.mod')) && existsSync(resolve(nestedSDK, 'go.mod')) ? nestedSDK : sdkPath;
|
|
162
|
+
verifySDK(installedSDK, current);
|
|
163
|
+
const migration = nativeMigrationReport(root, manifest, layout, current, delivery.sdk);
|
|
164
|
+
if (migration) return migration;
|
|
165
|
+
// Legacy UI recognition is limited to the read-only native migration report.
|
|
166
|
+
if (manifest.ui !== 'antd') checkedProject(root);
|
|
167
|
+
if (manifest.sdk && (manifest.sdk.version !== current.version || manifest.sdk.sha256 !== current.sha256)) throw new Error('Project and installed SDK metadata differ');
|
|
168
|
+
if (semver(current.version)[0] !== semver(delivery.sdk.version)[0]) throw new Error('Major SDK upgrades require a reviewed migration');
|
|
169
|
+
if (compare(delivery.sdk.version, current.version) < 0) throw new Error('SDK downgrade is not supported');
|
|
170
|
+
if (delivery.sdk.version === current.version && delivery.sdk.sha256 !== current.sha256) throw new Error('An immutable SDK version cannot change its bytes');
|
|
171
|
+
const packageFile = checkedOutput(root, 'package.json');
|
|
172
|
+
const packageJSON = JSON.parse(readFileSync(packageFile, 'utf8'));
|
|
173
|
+
if (packageJSON.version !== undefined) parseApplicationVersion(packageJSON.version);
|
|
174
|
+
const toolVersion = JSON.parse(readFileSync(resolve(toolRoot, 'package.json'), 'utf8')).version;
|
|
175
|
+
const previousVersions = manifest.packages ?? {};
|
|
176
|
+
const previousToolVersion = manifest.toolVersion ?? current.version;
|
|
177
|
+
let packageChanges = false;
|
|
178
|
+
const selectedNames=new Set(hostPackageNames(manifest.ui));
|
|
179
|
+
const dependencyGroups = ['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies'];
|
|
180
|
+
const installedPackages = delivery.packages.filter(pkg => selectedNames.has(pkg.name) || dependencyGroups.some(group => Object.hasOwn(packageJSON[group] ?? {}, pkg.name)));
|
|
181
|
+
const files = new Map();
|
|
182
|
+
const versioningChanges = [];
|
|
183
|
+
for (const helper of ['scripts/application-version.mjs', 'scripts/project-info.mjs', 'scripts/go-build-identity/main.go']) {
|
|
184
|
+
if (existsSync(checkedOutput(root, helper))) continue;
|
|
185
|
+
files.set(checkedOutput(root, helper), readFileSync(resolve(toolRoot, 'templates/project-v2', helper)));
|
|
186
|
+
versioningChanges.push(helper);
|
|
187
|
+
}
|
|
188
|
+
packageJSON.scripts ??= {};
|
|
189
|
+
if (!packageJSON.scripts['version:bump']) {
|
|
190
|
+
packageJSON.scripts['version:bump'] = 'node scripts/application-version.mjs';
|
|
191
|
+
versioningChanges.push('package.json#scripts.version:bump');
|
|
192
|
+
}
|
|
193
|
+
packageJSON.dependencies ??= {};
|
|
194
|
+
for (const pkg of installedPackages) {
|
|
195
|
+
const groups = dependencyGroups.filter(group => Object.hasOwn(packageJSON[group] ?? {}, pkg.name));
|
|
196
|
+
for (const group of groups.length ? groups : ['dependencies']) {
|
|
197
|
+
const installed = packageJSON[group][pkg.name];
|
|
198
|
+
const archive = installed?.startsWith('file:');
|
|
199
|
+
const previous = previousVersions[pkg.name] ?? current.version;
|
|
200
|
+
const expected = `file:./.arcbase/npm/${pkg.name.slice(1).replace('/', '-')}-${previous}.tgz`;
|
|
201
|
+
if (installed !== undefined && installed !== (archive ? expected : previous) && installed !== pkg.version) throw new Error('SDK package versions are mixed or customized');
|
|
202
|
+
packageChanges ||= installed !== pkg.version || previousVersions[pkg.name] !== pkg.version;
|
|
203
|
+
packageJSON[group][pkg.name] = pkg.version;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
for(const group of ['dependencies','devDependencies','optionalDependencies'])if (packageJSON[group]?.['@fudanda/create-arcbase']) {
|
|
207
|
+
if (packageJSON[group]['@fudanda/create-arcbase'] !== previousToolVersion) throw new Error('Generator dependency differs from the project manifest');
|
|
208
|
+
packageChanges ||= previousToolVersion !== toolVersion;
|
|
209
|
+
packageJSON[group]['@fudanda/create-arcbase'] = toolVersion;
|
|
210
|
+
}
|
|
211
|
+
function removeRetired(pkg) {
|
|
212
|
+
for (const group of dependencyGroups) for (const name of retiredPackages) {
|
|
213
|
+
const value = pkg[group]?.[name]; if (!value) continue;
|
|
214
|
+
const canonical = `file:./.arcbase/npm/${name.slice(1).replace('/', '-')}-${current.version}.tgz`;
|
|
215
|
+
if (value !== current.version && value !== canonical) throw new Error('Retired SDK dependency is customized; review its migration first: '+name);
|
|
216
|
+
delete pkg[group][name]; packageChanges = true;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
removeRetired(packageJSON);
|
|
220
|
+
const goFile = checkedOutput(root, 'go.mod');
|
|
221
|
+
files.set(goFile, Buffer.from(replaceSDKRequirement(readFileSync(goFile, 'utf8'), delivery.sdk.version, layout)));
|
|
222
|
+
manifest.sdk = { version: delivery.sdk.version, commit: delivery.sdk.commit, sha256: delivery.sdk.sha256 };
|
|
223
|
+
manifest.packages = Object.fromEntries(installedPackages.map(pkg=>[pkg.name,pkg.version]));
|
|
224
|
+
manifest.toolVersion = toolVersion;
|
|
225
|
+
const guidance = planAssistantGuidance(root, manifest, renderAssistantGuidance(manifest, toolVersion), checkedOutput);
|
|
226
|
+
manifest.assistantGuidance = guidance.state;
|
|
227
|
+
for (const [path, bytes] of guidance.writes) files.set(path, bytes);
|
|
228
|
+
files.set(marker, Buffer.from(JSON.stringify(manifest, null, 2) + '\n'));
|
|
229
|
+
files.set(packageFile, Buffer.from(JSON.stringify(packageJSON, null, 2) + '\n'));
|
|
230
|
+
const workspaces=packageJSON.workspaces??[];
|
|
231
|
+
if(!Array.isArray(workspaces)||workspaces.some(pattern=>typeof pattern!=='string'||pattern.includes('..')||pattern.startsWith('/')||pattern.includes('\\')))throw new Error('Workspace declarations require reviewed relative package paths');
|
|
232
|
+
for(const workspace of globSync(workspaces.map(pattern=>pattern+'/package.json'),{cwd:root,exclude:['node_modules/**','.arcbase/**','.git/**']})){
|
|
233
|
+
const path=checkedOutput(root,workspace),pkg=JSON.parse(readFileSync(path,'utf8'));let changed=false;
|
|
234
|
+
for(const group of ['dependencies','devDependencies','peerDependencies','optionalDependencies'])for(const name of [...delivery.packages.map(pkg=>pkg.name),'@fudanda/create-arcbase']){
|
|
235
|
+
if(!pkg[group]?.[name])continue;
|
|
236
|
+
if(pkg[group][name]!==(name==='@fudanda/create-arcbase'?previousToolVersion:previousVersions[name]??current.version))throw new Error(`Workspace ${workspace} mixes or customizes SDK versions`);
|
|
237
|
+
const target=name==='@fudanda/create-arcbase'?toolVersion:delivery.packages.find(pkg=>pkg.name===name).version;
|
|
238
|
+
packageChanges ||= pkg[group][name]!==target;
|
|
239
|
+
pkg[group][name]=target;changed=true;
|
|
240
|
+
}
|
|
241
|
+
const before=JSON.stringify(pkg);removeRetired(pkg);changed ||= JSON.stringify(pkg)!==before;
|
|
242
|
+
if(changed)files.set(path,Buffer.from(JSON.stringify(pkg,null,2)+'\n'));
|
|
243
|
+
}
|
|
244
|
+
files.set(metadataPath, Buffer.from(JSON.stringify(delivery.sdk, null, 2) + '\n'));
|
|
245
|
+
const importChanges=[];
|
|
246
|
+
for(const name of globSync(['web/**/*.{ts,tsx,js,mjs}','scripts/**/*.{ts,js,mjs}'],{cwd:root,exclude:['**/node_modules/**','**/dist/**','**/generated/**']})){
|
|
247
|
+
const path=checkedOutput(root,name),source=readFileSync(path,'utf8'),next=rewritePublicImports(source);
|
|
248
|
+
if(source!==next){files.set(path,Buffer.from(next));importChanges.push({path:name.replaceAll('\\','/'),sha256:sha256(source)});}
|
|
249
|
+
}
|
|
250
|
+
const lockFile = checkedOutput(root, 'package-lock.json');
|
|
251
|
+
const manualChanges = [];
|
|
252
|
+
const migrations = migrationReview(root, manifest, layout, current, installedSDK, delivery);
|
|
253
|
+
if (migrations.action === 'review') manualChanges.push({
|
|
254
|
+
path: 'go.mod', code: 'DATABASE_MIGRATION_REVIEW', reason: '迁移历史发生变化,或业务迁移缺少可验证基线;代码指纹不能证明数据库已应用的版本。',
|
|
255
|
+
steps: ['审阅 migrationReview 的 SDK SQL、schemaVersion 与业务迁移文件;禁止修改或删除已发布迁移。',
|
|
256
|
+
'在隔离数据库验证升级和回退,并核对实际数据库版本;明确升级目标和备份后再单独执行 db:migrate。SDK 升级命令不会执行迁移。',
|
|
257
|
+
'保留现有账号、业务记录、配置和菜单授权,不运行 setup 或 db:seed 来准备升级。'],
|
|
258
|
+
});
|
|
259
|
+
const menuFile = 'internal/contracts/menus.json';
|
|
260
|
+
const menuDigest = (metadata, backend) => metadata.files.some(file => file.path === menuFile) ? sourceDigest(readFileSync(resolve(backend, menuFile))) : null;
|
|
261
|
+
if (menuDigest(current, installedSDK) !== menuDigest(delivery.sdk, delivery.backend)) manualChanges.push({
|
|
262
|
+
path: 'arcbase.project.json', code: 'BUILTIN_MENU_PERMISSIONS', reason: '目标 SDK 的默认菜单或权限有变化;既有菜单和角色授权由业务项目维护。',
|
|
263
|
+
steps: ['对比 SDK 升级快照与目标 .arcbase/sdk/internal/contracts/menus.json,仅通过菜单管理补充需要的新菜单和查看权限。',
|
|
264
|
+
'按现有流程为角色授予权限,保留用户自定义菜单、已有菜单 ID 和原授权;不要通过 db:seed 或 setup 合并导航。',
|
|
265
|
+
'若包含项目信息,使用 /system/project-info、组件 system/project-info/ProjectInfoPage 及 system:project-info:view,并验证无权限访问被拒绝。'],
|
|
266
|
+
});
|
|
267
|
+
const versionWiring = [
|
|
268
|
+
['cmd/server/main.go', 'cli.ApplicationInfo'], ['scripts/build-backend.mjs', 'applicationGoFlags'],
|
|
269
|
+
['scripts/go.mjs', 'applicationGoFlags'], ['scripts/dev.mjs', 'applicationBuildInfo'],
|
|
270
|
+
['scripts/build.mjs', 'ARCBASE_APPLICATION_BUILD_INFO'], ['web/admin/vite.config.ts', 'applicationBuildInfo'],
|
|
271
|
+
['RELEASE.md', '应用版本与构建身份'],
|
|
272
|
+
];
|
|
273
|
+
const incompleteVersionWiring = versionWiring.filter(([path, marker]) => !existsSync(checkedOutput(root, path)) || !readFileSync(checkedOutput(root, path), 'utf8').includes(marker));
|
|
274
|
+
if (packageJSON.version === undefined || incompleteVersionWiring.length || packageJSON.scripts.build !== 'node scripts/build.mjs') manualChanges.push({
|
|
275
|
+
path: 'package.json', code: 'APPLICATION_VERSION_PIPELINE', reason: '业务版本与 SDK 版本独立;升级保留现有入口及构建脚本,不能覆盖用户定制。',
|
|
276
|
+
steps: [
|
|
277
|
+
'根 package.json.version 是业务版本唯一来源;已有版本保持原值,缺失时显式设置 0.1.0。使用 version:bump -- patch|minor|major|精确 SemVer;构建和部署不得自动改版本或打 Git 标签。',
|
|
278
|
+
'审阅新项目 scripts/application-version.mjs、build.mjs、build-backend.mjs、go.mjs、dev.mjs:构建和开发子进程共享 ARCBASE_APPLICATION_BUILD_INFO;applicationGoFlags 单独注入 main.application* 和 SDK 自身 Version/Commit。',
|
|
279
|
+
'在 cmd/server/main.go 增加可注入的 applicationName/Version/Commit/BuildTime/ReleaseID,传入 cli.Options.Application;version 在读取配置和 DashboardFS 前返回,并将 config.Observability.ServiceVersion 设为业务版本。',
|
|
280
|
+
'在 web/admin/vite.config.ts 从 applicationBuildInfo 生成 arcbase-app-version、sdk-version、app-commit、app-build-time 元数据;仅发布构建追加 release-id。OpenObserve 前端和 Source Map 使用业务版本,不再用 VITE_APP_VERSION 覆盖。',
|
|
281
|
+
'将新项目 RELEASE.md 的“应用版本与构建身份”节合并到既有发布文档,保留用户修改,补齐新 Skill 的版本规则链接。',
|
|
282
|
+
'发布脚本使用当前 create-arcbase/release;维护独立发布脚本时合并对应版本的 scripts/go-build-identity/main.go 与核验调用。跨平台读取二进制实际字符串,保留 Go 符号表(不使用 -s),不能依赖 trimpath 下可能省略的 -ldflags 记录;原有定制脚本保持原值并人工审阅。',
|
|
283
|
+
`需人工对照的新模板文件:${incompleteVersionWiring.map(([path]) => path).join('、') || 'package.json#scripts.build'}。使用同版本 create-arcbase 新建隔离项目后比较合并,保留业务入口、代理和自定义命令;执行 version、build 和相关 Ant 验收。`,
|
|
284
|
+
],
|
|
285
|
+
});
|
|
286
|
+
const ignorePath = checkedOutput(root, '.gitignore');
|
|
287
|
+
const ignoreRules = existsSync(ignorePath) ? readFileSync(ignorePath, 'utf8').split(/\r?\n/).map(line => line.trim()) : [];
|
|
288
|
+
if (!ignoreRules.some(rule => ['.arcbase/', '/.arcbase/', '.arcbase/releases/', '/.arcbase/releases/'].includes(rule))) manualChanges.push({
|
|
289
|
+
path: '.gitignore', code: 'RELEASE_ARTIFACT_IGNORE', reason: '发布锁和候选归档是构建产物,不应使已提交的业务源码持续标为 dirty。',
|
|
290
|
+
steps: ['保留现有 .gitignore 及自定义否定规则,审阅后加入 /.arcbase/releases/;先用 git check-ignore 核对发布目录,不自动覆盖用户文件。',
|
|
291
|
+
'确认源码干净且发布目录被忽略,再执行 release:build;只忽略构建产物,不忽略真实业务源码或 SDK 修改。'],
|
|
292
|
+
});
|
|
293
|
+
const projectInfoWiring = [['cmd/server/main.go', 'applicationDirectDependencies'], ['cmd/server/main.go', 'config.Application'],
|
|
294
|
+
['scripts/build-backend.mjs', 'directGoDependencies'], ['scripts/go.mjs', 'directGoDependencies'],
|
|
295
|
+
['scripts/dev.mjs', 'directGoDependencies'], ['web/admin/vite.config.ts', 'projectInfoVite']];
|
|
296
|
+
if (projectInfoWiring.some(([path, marker]) => !existsSync(checkedOutput(root, path)) || !readFileSync(checkedOutput(root, path), 'utf8').includes(marker))) manualChanges.push({
|
|
297
|
+
path: 'web/admin/vite.config.ts', code: 'PROJECT_INFO_METADATA', reason: '项目信息读取当前构建与实际运行身份,升级保留用户入口和 Vite 配置。',
|
|
298
|
+
steps: [
|
|
299
|
+
'比较同版本隔离新项目的 scripts/project-info.mjs 和 application-version.mjs,合并到本地定制脚本;读取实际已安装 npm 依赖版本,仅输出名称、版本与直接/开发依赖标记,不公开路径、Registry 地址或配置。',
|
|
300
|
+
'在 Vite 接入 projectInfoVite({project:root,identity:applicationBuildInfo(root),source:构建或源码模式}),随最终 base 输出 project-info.json 与 arcbase-project-info-url 元数据,兼容发布使用对应 release 资源路径。',
|
|
301
|
+
'将业务身份传给 config.Application;通过 directGoDependencies 与 applicationGoFlags 的第三个参数注入 applicationDirectDependencies,主程序区分 unknown 和已知空列表,再设置 config.DirectDependencies。不要用 go.mod 声明范围伪造二进制实际模块版本。',
|
|
302
|
+
'升级对应 Go/Ant SDK,并验证系统设置下项目信息的页面权限、前后端版本比较、依赖搜索和旧宿主数据缺失状态;保留原菜单授权、账号与数据。',
|
|
303
|
+
],
|
|
304
|
+
});
|
|
305
|
+
if (manifest.ui === 'antd') {
|
|
306
|
+
const path = 'web/admin/src/main.tsx', file = checkedOutput(root, path);
|
|
307
|
+
if (existsSync(file) && !readFileSync(file, 'utf8').includes('@fudanda/admin-antd/webmcp')) manualChanges.push({
|
|
308
|
+
path, code: 'WEBMCP_OPT_IN', reason: 'WebMCP 为可选宿主能力;升级保留现有启动文件和业务页面。',
|
|
309
|
+
steps: [
|
|
310
|
+
'确认目标 Ant SDK 导出 /webmcp 后,在 ArcBaseAdmin 增加 webmcp={{load:()=>import(\'@fudanda/admin-antd/webmcp\'),relay:{widgetUrl:new URL(\'arcbase-assets/webmcp/widget.html\',new URL(\'/dash/\',location.origin)).href}}};自定义 basePath 时同步调整同源 URL。',
|
|
311
|
+
'继续复制 SDK public 资源;个人中心只在用户启用后加载运行时,刷新、退出或锁屏后关闭。',
|
|
312
|
+
'旧业务 Page.tsx 不自动改写;在独立空项目生成同一模块,将新 Page.tsx 作为候选与本项目手写页面比较合并。evolve 不会仅因模板变化更新旧页面。',
|
|
313
|
+
'逐项验证权限、原表单保存、详情失败不写入、删除确认、关闭和重复请求;保留既有账号、配置和业务数据。',
|
|
314
|
+
],
|
|
315
|
+
});
|
|
316
|
+
const vitePath='web/admin/vite.config.ts',viteFile=checkedOutput(root,vitePath);
|
|
317
|
+
if(existsSync(viteFile)){
|
|
318
|
+
const source=readFileSync(viteFile,'utf8');
|
|
319
|
+
const peers=['antd','@ant-design/pro-components','@rc-component/form','rc-field-form'];
|
|
320
|
+
if(peers.some(peer=>!source.includes("'"+peer+"'")&&!source.includes('"'+peer+'"')))manualChanges.push({
|
|
321
|
+
path:vitePath,code:'WEBMCP_FORM_PEERS',reason:'宿主、SDK 与业务页需要共享同一套 Ant / Pro / Form 上下文;现有 Vite 配置保持原样。',
|
|
322
|
+
steps:['审阅 resolve.dedupe,保留现有设置并加入 antd、@ant-design/pro-components、@rc-component/form、rc-field-form 和 dayjs。',
|
|
323
|
+
'使用本项目实际 peer 版本;开发源码或本地 SDK alias 也必须解析到同一套依赖,不能同时装配 ESM / CJS 或其他目录中的 Form 实例。',
|
|
324
|
+
'验证 OverlayForm 的 getFieldInstance、实际输入回填、校验及保存;不能以 TypeScript 编译通过代替表单连接验收。'],
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
for (const module of manifest.modules) {
|
|
329
|
+
if (!/^[a-z][a-z0-9_-]*$/.test(module.id ?? '')) throw new Error('Invalid module in project manifest');
|
|
330
|
+
const path = `${layout.domains}/${module.id}/runtime_test.go`, file = checkedOutput(root, path);
|
|
331
|
+
if (!existsSync(file)) continue;
|
|
332
|
+
const source = readFileSync(file, 'utf8');
|
|
333
|
+
if (source.includes('string(answer[1])') && source.includes('data["image"]') && !source.includes('data["enabled"]')) manualChanges.push({
|
|
334
|
+
path, code: 'CAPTCHA_TEST_OPTIONAL', reason: '旧测试直接读取验证码图片;当前验证码默认关闭,新建测试数据库会返回 enabled=false。',
|
|
335
|
+
steps: ['先构造只含 username/password 的登录 body。', '只在 data["enabled"] == true 时解码图片,检查答案存在并填写 captchaId/captchaAnswer。', '用 body 调用登录;分别验证验证码开启和关闭,保留原权限、范围和审计断言。'],
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
const report = {
|
|
339
|
+
project: root, from: current.version, to: delivery.sdk.version, changed: delivery.sdk.version !== current.version || packageChanges || importChanges.length>0 || guidance.metadataChanged || guidance.writes.size>0 || guidance.proposals.size>0 || versioningChanges.length>0,
|
|
340
|
+
importChanges,
|
|
341
|
+
sdkFiles: delivery.sdk.files.length, packages: installedPackages.map(pkg => pkg.name), databaseChanges: false,
|
|
342
|
+
migrationReview: migrations,
|
|
343
|
+
before: ['提交业务代码、生成结果和 lockfile', 'npm run stop', 'npm run backup -- PATH'],
|
|
344
|
+
next: ['npm ci', 'npm run generate', 'npm run build', 'npm run check', 'npm test',
|
|
345
|
+
...(migrations.action === 'migrate' ? ['确认升级前备份可恢复,在隔离数据库验收 migrationReview 后显式迁移。', 'npm run db:migrate']
|
|
346
|
+
: migrations.action === 'review' ? ['先完成 DATABASE_MIGRATION_REVIEW;未确认迁移历史和实际库版本前,不部署新二进制。'] : []),
|
|
347
|
+
'npm run check:database', 'npm start'],
|
|
348
|
+
rollback: { code: '从升级快照恢复整套 SDK、代码和 lockfile;npm ci 后重新生成和构建。', data: '迁移后需要回退时,将升级前备份恢复到新的空库和文件目录,配套使用旧代码和二进制。' },
|
|
349
|
+
templateChanges: guidance.writes.size>0 || versioningChanges.length>0,
|
|
350
|
+
versioningChanges,
|
|
351
|
+
guidanceChanges: guidance.changes,
|
|
352
|
+
manualChanges,
|
|
353
|
+
warnings: [
|
|
354
|
+
'migrationReview 仅比较当前所选数据库的 SDK/业务迁移源码指纹,不读取数据库,不代表线上迁移已经完成。升级不会执行 setup、db:seed 或迁移。',
|
|
355
|
+
...(!packageJSON.scripts?.['release:deploy'] && manifest.ui === 'antd' ? ['兼容发布需要一次性接入 arcbase.release.json、Vite 发布插件和宿主排空;既有脚本与业务页面保持原样,按日常兼容发布文档人工合并,不自动改代理或数据库。'] : []),
|
|
356
|
+
...(!packageJSON.scripts?.doctor ? ['宿主脚本保持原样;新诊断可通过目标版本的 create-arcbase doctor --project . 使用。'] : []),
|
|
357
|
+
...(packageJSON.scripts?.build?.includes('npm run generate') ? ['现有 build 仍隐式生成源码;按团队指南显式执行 generate,并审阅后调整宿主构建脚本。'] : []),
|
|
358
|
+
...(manualChanges.some(change=>change.code==='CAPTCHA_TEST_OPTIONAL') ? ['旧生成测试需要审阅验证码可选分支;具体文件和步骤见 manualChanges。'] : []),
|
|
359
|
+
...(manualChanges.some(change=>change.code==='WEBMCP_OPT_IN') ? ['WebMCP 不自动改写业务启动文件和页面;按 manualChanges 手工启用和合并。'] : []),
|
|
360
|
+
...(manualChanges.some(change=>change.code==='WEBMCP_FORM_PEERS') ? ['Ant / Pro / Form peer 依赖需要保持单一上下文;按 manualChanges 审阅现有 Vite 配置。'] : []),
|
|
361
|
+
...(manualChanges.some(change=>change.code==='APPLICATION_VERSION_PIPELINE') ? ['业务版本保持原值;新版本命令及缺失的独立 helper 已纳入安全升级计划,构建/开发/Go/Vite 定制入口按 manualChanges 人工合并。'] : []),
|
|
362
|
+
...(guidance.proposals.size ? ['用户修改的开发指引保持原样;执行升级后在返回的 guidanceCandidates 中审阅候选文件。'] : []),
|
|
363
|
+
],
|
|
364
|
+
};
|
|
365
|
+
if (check || !report.changed) return report;
|
|
366
|
+
if (running(root)) throw new Error('Stop the project before upgrading its SDK');
|
|
367
|
+
guidance.verifyUnchanged();
|
|
368
|
+
const transaction = checkedOutput(root, `.arcbase/upgrades/${new Date().toISOString().replaceAll(/[:.]/g, '-')}-${randomUUID()}`);
|
|
369
|
+
mkdirSync(transaction, { recursive: true });
|
|
370
|
+
const backup = new Map();
|
|
371
|
+
for (const path of [...files.keys(), lockFile]) backup.set(path, existsSync(path) ? readFileSync(path) : null);
|
|
372
|
+
const priorSDK = resolve(transaction, 'sdk-before');
|
|
373
|
+
const stagedSDK = resolve(transaction, 'sdk-after');
|
|
374
|
+
cpSync(sdkPath, priorSDK, { recursive: true });
|
|
375
|
+
cpSync(delivery.backend, stagedSDK, { recursive: true });
|
|
376
|
+
// Keep only code/manifest snapshots. Configuration, credentials and database bytes are untouched.
|
|
377
|
+
writeFileSync(resolve(transaction, 'files.json'), JSON.stringify([...backup].map(([path, bytes]) => ({ path, content: bytes?.toString('base64') ?? null })), null, 2));
|
|
378
|
+
const guidanceCandidates = [];
|
|
379
|
+
for (const [path, bytes] of guidance.proposals) {
|
|
380
|
+
const target = checkedOutput(transaction, `guidance-next/${path}`);
|
|
381
|
+
mkdirSync(dirname(target), {recursive: true}); writeFileSync(target, bytes);
|
|
382
|
+
guidanceCandidates.push({path, candidate: target});
|
|
383
|
+
}
|
|
384
|
+
writeFileSync(resolve(transaction, 'upgrade.json'), JSON.stringify({...report, guidanceCandidates}, null, 2));
|
|
385
|
+
let moved = false;
|
|
386
|
+
let swapped = false;
|
|
387
|
+
try {
|
|
388
|
+
renameSync(sdkPath, resolve(transaction, 'sdk-replaced'));
|
|
389
|
+
moved = true;
|
|
390
|
+
renameSync(stagedSDK, sdkPath); swapped = true;
|
|
391
|
+
for (const [path, bytes] of files) { mkdirSync(dirname(path), { recursive: true }); writeFileSync(path, bytes); }
|
|
392
|
+
prepareRegistryLock(root, lockFile, [...delivery.packages.map(pkg => pkg.name), ...retiredPackages, '@fudanda/create-arcbase', '@fudanda/go-sdk']);
|
|
393
|
+
if (refreshLock) refreshLock(root);
|
|
394
|
+
else {
|
|
395
|
+
const npm = upgradeNpmCLI();
|
|
396
|
+
execFileSync(process.execPath, [npm, 'install', '--package-lock-only', '--ignore-scripts', '--no-audit', '--no-fund', '--prefer-online'], { cwd: root, env: {...process.env, npm_execpath: npm}, stdio: ['ignore', 'pipe', 'pipe'], maxBuffer: 2 << 20, windowsHide: true, timeout: 300000 });
|
|
397
|
+
}
|
|
398
|
+
const lock = JSON.parse(readFileSync(lockFile, 'utf8'));
|
|
399
|
+
for (const pkg of installedPackages) if (lock.packages?.[`node_modules/${pkg.name}`]?.version !== pkg.version) throw new Error('Refreshed lockfile does not match the upgraded SDK');
|
|
400
|
+
for(const [path,pkg] of Object.entries(lock.packages??{})){
|
|
401
|
+
const expected=delivery.packages.find(item=>path.endsWith('node_modules/'+item.name));
|
|
402
|
+
if(!expected)continue;
|
|
403
|
+
if(pkg.version!==expected.version)throw new Error('A nested workspace retained an older SDK version');
|
|
404
|
+
if(pkg.integrity!==expected.integrity)throw new Error('Lockfile package bytes differ from the target SDK archive');
|
|
405
|
+
if(!pkg.resolved?.startsWith('http://')&&!pkg.resolved?.startsWith('https://'))throw new Error('Upgraded SDK must resolve from the configured Registry');
|
|
406
|
+
}
|
|
407
|
+
writeFileSync(resolve(transaction, 'complete.json'), JSON.stringify({ from: current.version, to: delivery.sdk.version, sdk: sha256(JSON.stringify(delivery.sdk.files)) }));
|
|
408
|
+
return { ...report, backup: transaction, guidanceCandidates };
|
|
409
|
+
} catch (error) {
|
|
410
|
+
if (swapped) rmSync(sdkPath, { recursive: true });
|
|
411
|
+
if (moved) renameSync(resolve(transaction, 'sdk-replaced'), sdkPath);
|
|
412
|
+
for (const [path, bytes] of backup) { if (bytes === null) { if (existsSync(path)) rmSync(path); } else writeFileSync(path, bytes); }
|
|
413
|
+
throw new Error(`SDK upgrade rolled back: ${error.message}`, {cause: error});
|
|
414
|
+
}
|
|
415
|
+
}
|