@voxgig/sdkgen 4.38.0 → 4.39.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/bin/voxgig-sdkgen +13 -2
- package/dist/action/copies.d.ts +6 -1
- package/dist/action/copies.js +43 -1
- package/dist/action/copies.js.map +1 -1
- package/dist/action/doctor.d.ts +2 -0
- package/dist/action/doctor.js +30 -7
- package/dist/action/doctor.js.map +1 -1
- package/dist/action/edition.js +3 -0
- package/dist/action/edition.js.map +1 -1
- package/dist/action/feature.js +3 -0
- package/dist/action/feature.js.map +1 -1
- package/dist/action/package.js +15 -0
- package/dist/action/package.js.map +1 -1
- package/dist/action/target.js +3 -0
- package/dist/action/target.js.map +1 -1
- package/dist/helpers/copymerge.d.ts +35 -0
- package/dist/helpers/copymerge.js +513 -0
- package/dist/helpers/copymerge.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types.d.ts +1 -0
- package/model/sdkgen.aontu +4 -0
- package/package.json +1 -1
- package/project/sdkgen-package.json +1 -1
- package/src/action/copies.ts +54 -0
- package/src/action/doctor.ts +41 -8
- package/src/action/edition.ts +9 -1
- package/src/action/feature.ts +7 -1
- package/src/action/package.ts +28 -1
- package/src/action/target.ts +7 -1
- package/src/helpers/copymerge.ts +712 -0
- package/src/types.ts +2 -0
package/package.json
CHANGED
package/src/action/copies.ts
CHANGED
|
@@ -2,8 +2,14 @@ import Path from 'node:path'
|
|
|
2
2
|
|
|
3
3
|
import { createHash } from 'node:crypto'
|
|
4
4
|
|
|
5
|
+
import { KIT } from '../types'
|
|
5
6
|
import type { ActionContext } from '../types'
|
|
6
7
|
|
|
8
|
+
import { SdkGenError } from '../utility'
|
|
9
|
+
|
|
10
|
+
import { copyMode, gitVersions, withCopyMerge } from '../helpers/copymerge'
|
|
11
|
+
import type { CopyMode } from '../helpers/copymerge'
|
|
12
|
+
|
|
7
13
|
import {
|
|
8
14
|
definitionFileName, definitionFolder, indexName,
|
|
9
15
|
} from '../helpers/definition'
|
|
@@ -19,6 +25,11 @@ import type { Source } from './resolve'
|
|
|
19
25
|
// add or remove that changed the record, holding just the change.
|
|
20
26
|
const COPY_LOG = 'log/copies.jsonl'
|
|
21
27
|
|
|
28
|
+
// The base of each copy the project changed, and the incoming copies of a
|
|
29
|
+
// merge that stopped on a conflict.
|
|
30
|
+
const BASE_DIR = 'log/base'
|
|
31
|
+
const CONFLICT_DIR = 'log/conflict'
|
|
32
|
+
|
|
22
33
|
// Where 4.34.0 kept the whole record, until the next write moves it.
|
|
23
34
|
const LEGACY = 'sdkgen-copies.json'
|
|
24
35
|
|
|
@@ -317,6 +328,45 @@ function gone(
|
|
|
317
328
|
}
|
|
318
329
|
|
|
319
330
|
|
|
331
|
+
// `main.kit.copies` in the project's model.
|
|
332
|
+
function projectCopyMode(actx: ActionContext): CopyMode {
|
|
333
|
+
return copyMode((actx.model as any)?.main?.[KIT]?.copies)
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
// Runs an add so that a copy the project changed is merged rather than
|
|
338
|
+
// replaced. An add nested in another runs inside the outer guard.
|
|
339
|
+
async function guardCopies<T>(
|
|
340
|
+
actx: ActionContext, what: string, run: (actx: ActionContext) => Promise<T>,
|
|
341
|
+
): Promise<T> {
|
|
342
|
+
if (true === actx.copyGuarded) {
|
|
343
|
+
return run(actx)
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
const fs = actx.fs()
|
|
347
|
+
const files = readCopies(fs, actx.folder).files
|
|
348
|
+
const flags = actx.flags ?? {}
|
|
349
|
+
|
|
350
|
+
return withCopyMerge({
|
|
351
|
+
fs,
|
|
352
|
+
folder: actx.folder,
|
|
353
|
+
log: actx.log,
|
|
354
|
+
what,
|
|
355
|
+
mode: projectCopyMode(actx),
|
|
356
|
+
force: true === flags.force,
|
|
357
|
+
keep: true === flags.keep,
|
|
358
|
+
dryrun: true === actx.opts?.dryrun,
|
|
359
|
+
manage: isCopy,
|
|
360
|
+
recorded: (rel: string) => files[rel],
|
|
361
|
+
fingerprint,
|
|
362
|
+
basedir: BASE_DIR,
|
|
363
|
+
conflictdir: CONFLICT_DIR,
|
|
364
|
+
versions: gitVersions,
|
|
365
|
+
error: (msg: string) => new SdkGenError(msg),
|
|
366
|
+
}, (gfs: any) => run({ ...actx, fs: () => gfs, copyGuarded: true }))
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
|
|
320
370
|
// Was this project file left exactly as an add wrote it?
|
|
321
371
|
function untouched(
|
|
322
372
|
fs: any, folder: string, record: CopyRecord, rel: string,
|
|
@@ -339,6 +389,8 @@ export type {
|
|
|
339
389
|
}
|
|
340
390
|
|
|
341
391
|
export {
|
|
392
|
+
BASE_DIR,
|
|
393
|
+
CONFLICT_DIR,
|
|
342
394
|
COPY_LOG,
|
|
343
395
|
IGNORED_LOG,
|
|
344
396
|
ignoredLog,
|
|
@@ -347,6 +399,8 @@ export {
|
|
|
347
399
|
readCopies,
|
|
348
400
|
recordCopies,
|
|
349
401
|
forgetCopies,
|
|
402
|
+
guardCopies,
|
|
403
|
+
projectCopyMode,
|
|
350
404
|
untouched,
|
|
351
405
|
isCopy,
|
|
352
406
|
}
|
package/src/action/doctor.ts
CHANGED
|
@@ -38,10 +38,12 @@ import { findFeatureSources, featureExcludes } from '../helpers/featureSource'
|
|
|
38
38
|
import { isJunk } from '../helpers/junk'
|
|
39
39
|
|
|
40
40
|
import {
|
|
41
|
-
readCopies, untouched, itemKey, ignoredLog, IGNORED_LOG,
|
|
41
|
+
readCopies, untouched, itemKey, ignoredLog, IGNORED_LOG, projectCopyMode,
|
|
42
42
|
} from './copies'
|
|
43
43
|
import type { CopyRecord } from './copies'
|
|
44
44
|
|
|
45
|
+
import { MERGE } from '../helpers/copymerge'
|
|
46
|
+
|
|
45
47
|
|
|
46
48
|
const IGNORED_RE = /(~|-jostraca-off)$/
|
|
47
49
|
|
|
@@ -110,6 +112,11 @@ type DoctorReport = {
|
|
|
110
112
|
// nothing shows whether the project changed them.
|
|
111
113
|
unrecorded: string[]
|
|
112
114
|
|
|
115
|
+
// In merge mode, the forked and edited copies the record shows the project
|
|
116
|
+
// changed after an add wrote them. An add merges into these, so they are
|
|
117
|
+
// the project's own, not drift.
|
|
118
|
+
customized: string[]
|
|
119
|
+
|
|
113
120
|
// Declared items whose source is not installed; their copies are kept.
|
|
114
121
|
unresolved: string[]
|
|
115
122
|
|
|
@@ -136,6 +143,8 @@ type ItemDrift = {
|
|
|
136
143
|
// Forked, edited, missing and stale files.
|
|
137
144
|
changed: number
|
|
138
145
|
|
|
146
|
+
customized: number
|
|
147
|
+
|
|
139
148
|
unresolved?: string
|
|
140
149
|
}
|
|
141
150
|
|
|
@@ -288,7 +297,7 @@ async function doctor(
|
|
|
288
297
|
forked: [], edited: [], stale: [], missing: [], additive: [],
|
|
289
298
|
superseded: [], unwired: [], orphanModel: [],
|
|
290
299
|
resyncPending: [], aliasedDiff: [],
|
|
291
|
-
outdated: [], unrecorded: [], unresolved: [], byItem: {},
|
|
300
|
+
outdated: [], unrecorded: [], customized: [], unresolved: [], byItem: {},
|
|
292
301
|
ignoredLog: false, ok: true,
|
|
293
302
|
}
|
|
294
303
|
|
|
@@ -378,12 +387,16 @@ async function doctor(
|
|
|
378
387
|
// model file nothing reads is never a choice - it is either a file that
|
|
379
388
|
// should be included, or one that should be deleted, and it reads as
|
|
380
389
|
// authoritative either way.
|
|
381
|
-
report.ok = 0 === report.forked.length + report.edited.length
|
|
382
|
-
report.stale.length + report.missing.length + report.superseded.length +
|
|
390
|
+
report.ok = 0 === report.forked.length + report.edited.length -
|
|
391
|
+
report.customized.length + report.stale.length + report.missing.length + report.superseded.length +
|
|
383
392
|
report.orphanModel.length + report.outdated.length +
|
|
384
393
|
report.unresolved.length
|
|
385
394
|
|
|
395
|
+
const customized = new Set(report.customized)
|
|
396
|
+
const unmergeable = MERGE === projectCopyMode(actx) ? new Set(report.unrecorded) : new Set()
|
|
397
|
+
|
|
386
398
|
for (const [kind, note] of [
|
|
399
|
+
['customized', 'CUSTOMIZED (an add merges its updates into it)'],
|
|
387
400
|
['forked', 'FORKED (will be reverted by `target add`)'],
|
|
388
401
|
['edited', 'EDITED template master'],
|
|
389
402
|
['stale', 'STALE (no longer written by `target add`)'],
|
|
@@ -398,7 +411,13 @@ async function doctor(
|
|
|
398
411
|
['unresolved', 'UNRESOLVED (declared, but its source is not installed; install it)'],
|
|
399
412
|
] as [keyof DoctorReport, string][]) {
|
|
400
413
|
for (const file of (report[kind] as string[])) {
|
|
401
|
-
|
|
414
|
+
if (('forked' === kind || 'edited' === kind) && customized.has(file)) {
|
|
415
|
+
continue
|
|
416
|
+
}
|
|
417
|
+
const said = unmergeable.has(file) ?
|
|
418
|
+
kind.toUpperCase() + ' (no copy record, so an add stops on it; --force takes the source copy)' :
|
|
419
|
+
note
|
|
420
|
+
log.info({ point: 'doctor-finding', kind, file, note: said + ': ' + file })
|
|
402
421
|
}
|
|
403
422
|
}
|
|
404
423
|
|
|
@@ -428,8 +447,10 @@ async function doctor(
|
|
|
428
447
|
aliasedDiff: report.aliasedDiff.length,
|
|
429
448
|
outdated: report.outdated.length,
|
|
430
449
|
unresolved: report.unresolved.length,
|
|
450
|
+
customized: report.customized.length,
|
|
431
451
|
note: report.ok ?
|
|
432
|
-
('.sdk matches the scaffold (' + report.additive.length + ' additive
|
|
452
|
+
('.sdk matches the scaffold (' + report.additive.length + ' additive, ' +
|
|
453
|
+
report.customized.length + ' customized)') :
|
|
433
454
|
('.sdk has drifted: ' + report.forked.length + ' forked, ' +
|
|
434
455
|
report.edited.length + ' edited, ' + report.stale.length + ' stale, ' +
|
|
435
456
|
report.missing.length + ' missing, ' + report.outdated.length +
|
|
@@ -505,6 +526,7 @@ function noteUnresolved(
|
|
|
505
526
|
...pkgOf(declared.package),
|
|
506
527
|
outdated: 0,
|
|
507
528
|
changed: 0,
|
|
529
|
+
customized: 0,
|
|
508
530
|
unresolved: from,
|
|
509
531
|
}
|
|
510
532
|
|
|
@@ -886,9 +908,11 @@ function noteDrift(
|
|
|
886
908
|
const fs = actx.fs()
|
|
887
909
|
const item = itemKey(kind, source.name)
|
|
888
910
|
const copied = copies.items[item]
|
|
911
|
+
const merging = MERGE === projectCopyMode(actx)
|
|
889
912
|
|
|
890
913
|
return (category: Category, label: string) => {
|
|
891
914
|
let into: Category | 'outdated' = category
|
|
915
|
+
let custom = false
|
|
892
916
|
|
|
893
917
|
if ('forked' === category || 'edited' === category) {
|
|
894
918
|
const same = untouched(fs, actx.folder, copies, label)
|
|
@@ -899,6 +923,10 @@ function noteDrift(
|
|
|
899
923
|
else if (undefined === same) {
|
|
900
924
|
report.unrecorded.push(label)
|
|
901
925
|
}
|
|
926
|
+
else if (merging) {
|
|
927
|
+
custom = true
|
|
928
|
+
report.customized.push(label)
|
|
929
|
+
}
|
|
902
930
|
}
|
|
903
931
|
|
|
904
932
|
report[into].push(label)
|
|
@@ -909,6 +937,7 @@ function noteDrift(
|
|
|
909
937
|
...(null == source.version ? {} : { to: source.version }),
|
|
910
938
|
outdated: 0,
|
|
911
939
|
changed: 0,
|
|
940
|
+
customized: 0,
|
|
912
941
|
}
|
|
913
942
|
|
|
914
943
|
if ('outdated' === into) {
|
|
@@ -917,6 +946,10 @@ function noteDrift(
|
|
|
917
946
|
else {
|
|
918
947
|
drift.changed++
|
|
919
948
|
}
|
|
949
|
+
|
|
950
|
+
if (custom) {
|
|
951
|
+
drift.customized++
|
|
952
|
+
}
|
|
920
953
|
}
|
|
921
954
|
}
|
|
922
955
|
|
|
@@ -1141,8 +1174,8 @@ function copyWarnings(report: DoctorReport): string[] {
|
|
|
1141
1174
|
add('outdated\n' + command, item, drift.outdated, drift)
|
|
1142
1175
|
}
|
|
1143
1176
|
|
|
1144
|
-
if (0 < drift.changed) {
|
|
1145
|
-
add('changed\n' + command, item, drift.changed, drift)
|
|
1177
|
+
if (0 < drift.changed - drift.customized) {
|
|
1178
|
+
add('changed\n' + command, item, drift.changed - drift.customized, drift)
|
|
1146
1179
|
}
|
|
1147
1180
|
}
|
|
1148
1181
|
|
package/src/action/edition.ts
CHANGED
|
@@ -19,7 +19,7 @@ import type { TreeDef } from './kind'
|
|
|
19
19
|
import { registerInstalled } from './resolve'
|
|
20
20
|
import type { Source } from './resolve'
|
|
21
21
|
|
|
22
|
-
import { recordCopies } from './copies'
|
|
22
|
+
import { recordCopies, guardCopies } from './copies'
|
|
23
23
|
|
|
24
24
|
import { aliasCmpTree, pruneStaleTemplates } from './target'
|
|
25
25
|
|
|
@@ -78,6 +78,14 @@ async function cmd_edition_remove(
|
|
|
78
78
|
|
|
79
79
|
async function edition_add(
|
|
80
80
|
edition: string[], actx: ActionContext,
|
|
81
|
+
): Promise<ActionResult> {
|
|
82
|
+
return guardCopies(actx, 'edition add ' + edition.join(' '),
|
|
83
|
+
(gctx: ActionContext) => addEditions(edition, gctx))
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
async function addEditions(
|
|
88
|
+
edition: string[], actx: ActionContext,
|
|
81
89
|
): Promise<ActionResult> {
|
|
82
90
|
edition = edition.map(ref => !ref.includes('/') && !ref.includes('\\') &&
|
|
83
91
|
!kindCollection(actx.model, 'edition')[ref.split('~')[0]] ? '@voxgig/docgen/project/' + ref : ref)
|
package/src/action/feature.ts
CHANGED
|
@@ -34,7 +34,7 @@ import { copyOpts } from '../helpers/junk'
|
|
|
34
34
|
import { resolveKind, kindModel, kindIndex } from './kind'
|
|
35
35
|
import type { Source } from './resolve'
|
|
36
36
|
|
|
37
|
-
import { recordCopies } from './copies'
|
|
37
|
+
import { recordCopies, guardCopies } from './copies'
|
|
38
38
|
|
|
39
39
|
|
|
40
40
|
import {
|
|
@@ -84,6 +84,12 @@ async function cmd_feature_remove(args: string[], actx: ActionContext): Promise<
|
|
|
84
84
|
|
|
85
85
|
|
|
86
86
|
async function feature_add(features: string[], actx: ActionContext): Promise<ActionResult> {
|
|
87
|
+
return guardCopies(actx, 'feature add ' + features.join(' '),
|
|
88
|
+
(gctx: ActionContext) => addFeatures(features, gctx))
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
async function addFeatures(features: string[], actx: ActionContext): Promise<ActionResult> {
|
|
87
93
|
|
|
88
94
|
// Reuse the caller's Jostraca instance so feature generation honours the
|
|
89
95
|
// shared controls (notably `dryrun`). A fresh Jostraca() defaults dryrun
|
package/src/action/package.ts
CHANGED
|
@@ -32,7 +32,9 @@ import { cmd_package_check } from './check'
|
|
|
32
32
|
|
|
33
33
|
import { doctor } from './doctor'
|
|
34
34
|
|
|
35
|
-
import { COPY_LOG } from './copies'
|
|
35
|
+
import { COPY_LOG, guardCopies, projectCopyMode } from './copies'
|
|
36
|
+
|
|
37
|
+
import { MERGE } from '../helpers/copymerge'
|
|
36
38
|
|
|
37
39
|
import { resolveSource, registerInstalled, nameConflict } from './resolve'
|
|
38
40
|
import type { Source } from './resolve'
|
|
@@ -301,6 +303,14 @@ async function cmd_package_add(
|
|
|
301
303
|
|
|
302
304
|
async function package_add(
|
|
303
305
|
refs: string[], actx: ActionContext,
|
|
306
|
+
): Promise<ActionResult> {
|
|
307
|
+
return guardCopies(actx, 'package add ' + refs.join(' '),
|
|
308
|
+
(gctx: ActionContext) => addPackages(refs, gctx))
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
async function addPackages(
|
|
313
|
+
refs: string[], actx: ActionContext,
|
|
304
314
|
): Promise<ActionResult> {
|
|
305
315
|
const log = actx.log
|
|
306
316
|
const flags = actx.flags ?? {}
|
|
@@ -547,6 +557,14 @@ function installedFrom(pkgname: string, actx: ActionContext): Installed[] {
|
|
|
547
557
|
|
|
548
558
|
async function package_update(
|
|
549
559
|
names: string[], actx: ActionContext,
|
|
560
|
+
): Promise<ActionResult> {
|
|
561
|
+
return guardCopies(actx, 'package update ' + names.join(' '),
|
|
562
|
+
(gctx: ActionContext) => updatePackages(names, gctx))
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
|
|
566
|
+
async function updatePackages(
|
|
567
|
+
names: string[], actx: ActionContext,
|
|
550
568
|
): Promise<ActionResult> {
|
|
551
569
|
const log = actx.log
|
|
552
570
|
const flags = actx.flags ?? {}
|
|
@@ -661,6 +679,15 @@ async function preCheck(
|
|
|
661
679
|
return
|
|
662
680
|
}
|
|
663
681
|
|
|
682
|
+
if (MERGE === projectCopyMode(actx) && true !== flags.force) {
|
|
683
|
+
actx.log.info({
|
|
684
|
+
point: 'package-update-merge', package: pkgname, files: changed,
|
|
685
|
+
note: pkgname + ': ' + changed.length + ' locally-changed file(s) ' +
|
|
686
|
+
'will take the update by merge: ' + changed.join(', ')
|
|
687
|
+
})
|
|
688
|
+
return
|
|
689
|
+
}
|
|
690
|
+
|
|
664
691
|
if (true === flags.force) {
|
|
665
692
|
actx.log.warn({
|
|
666
693
|
point: 'package-update-forced', package: pkgname, files: changed,
|
package/src/action/target.ts
CHANGED
|
@@ -58,7 +58,7 @@ import { kindModel, kindIndex, resolveKind, escapeRe } from './kind'
|
|
|
58
58
|
import { BUNDLED, resolveSource, registerInstalled } from './resolve'
|
|
59
59
|
import type { Source } from './resolve'
|
|
60
60
|
|
|
61
|
-
import { recordCopies } from './copies'
|
|
61
|
+
import { recordCopies, guardCopies } from './copies'
|
|
62
62
|
|
|
63
63
|
|
|
64
64
|
const CMD_MAP: any = {
|
|
@@ -94,6 +94,12 @@ async function cmd_target_remove(args: string[], actx: ActionContext): Promise<A
|
|
|
94
94
|
|
|
95
95
|
// Code API
|
|
96
96
|
async function target_add(targets: string[], actx: ActionContext): Promise<ActionResult> {
|
|
97
|
+
return guardCopies(actx, 'target add ' + targets.join(' '),
|
|
98
|
+
(gctx: ActionContext) => addTargets(targets, gctx))
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
async function addTargets(targets: string[], actx: ActionContext): Promise<ActionResult> {
|
|
97
103
|
const jostraca = actx.jostraca
|
|
98
104
|
|
|
99
105
|
const opts = {
|