dreamteamer 0.48.1 → 0.49.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/README.md +41 -39
- package/collections/modules.collection.yaml +11 -0
- package/package.json +1 -1
- package/skills/using-dreamteamer/SKILL.md +8 -6
- package/skills/using-dreamteamer/references/before-you-build.md +8 -6
- package/skills/using-dreamteamer/references/collections.md +16 -7
- package/skills/using-dreamteamer/references/commands.md +4 -3
- package/skills/using-dreamteamer/references/data-modeling.md +3 -2
- package/skills/using-dreamteamer/references/extensions.md +13 -12
- package/skills/using-dreamteamer/references/getting-started.md +4 -3
- package/skills/using-dreamteamer/references/records.md +4 -4
- package/skills/using-dreamteamer/references/setup.md +7 -5
- package/skills/using-dreamteamer/references/ui-components.md +1 -1
- package/skills/using-dreamteamer/references/ui-views.md +39 -1
- package/skills/using-dreamteamer/references/writing-a-module.md +3 -2
- package/src/api.d.ts +18 -0
- package/src/api.js +7 -0
- package/src/check-alone.js +58 -8
- package/src/check.js +10 -0
- package/src/cli.js +36 -18
- package/src/collections-cli.js +9 -41
- package/src/compile-collections.js +20 -3
- package/src/compile.js +59 -8
- package/src/extensions.js +1 -1
- package/src/init.js +1 -1
- package/src/install-modules.js +113 -46
- package/src/nav-fragments.js +190 -0
- package/src/nav.js +185 -0
- package/src/schema-ops.js +4 -4
- package/src/semver.js +4 -0
- package/src/setup.js +6 -3
- package/src/store.js +35 -11
- package/src/unread-data.js +74 -0
- package/src/update-setup.js +6 -5
- package/src/update.js +43 -12
- package/src/workspace.js +52 -13
package/src/update.js
CHANGED
|
@@ -13,6 +13,8 @@ import { spawnSync, execFileSync } from 'node:child_process';
|
|
|
13
13
|
import { resolveNpm, childEnv } from './checkout.js';
|
|
14
14
|
import { readSpecManifest, resolveClosure, installedModules, compareVersions, InstallRefusal, npmFloor, npmAndCompile, printUnitResults } from './install-modules.js';
|
|
15
15
|
import { EXIT } from './setup.js';
|
|
16
|
+
import { moduleIdOf } from './compile.js';
|
|
17
|
+
import { navGuard, navDocGuard, shipsFragment, NAV_SETTINGS_LINE, NAV_GUARD_LINE } from './nav-fragments.js';
|
|
16
18
|
|
|
17
19
|
const gitOk = (root, args) => { try { execFileSync('git', args, { cwd: root, stdio: 'ignore' }); return true; } catch { return false; } };
|
|
18
20
|
|
|
@@ -61,43 +63,72 @@ export async function updateModules(ws, { name = null, version = null, engine =
|
|
|
61
63
|
// being asked for), then install's steps 2–6 on the WHOLE resolved list: a version that adds a
|
|
62
64
|
// dreamteamer.dependencies entry brings the dependency in, compiled and committed with it, and a
|
|
63
65
|
// version that adds a setup unit runs its safe part
|
|
64
|
-
|
|
66
|
+
//
|
|
67
|
+
// A MODULE PRESET (CR-dt-008): each installed member at another version than the new pin leaves the
|
|
68
|
+
// installed map too, so it is re-walked at that pin instead of refusing as "installed at another
|
|
69
|
+
// version"; a member the INSTALLED version listed and the operator uninstalled is skipped (removed
|
|
70
|
+
// on purpose); a member new to this version — and every member on a first expansion, when the
|
|
71
|
+
// installed version was no preset — is walked and installed.
|
|
72
|
+
// the nav guard (cr-dt-008), for every module target, plain or preset — never the engine's: old nav
|
|
73
|
+
// settings and no nav.yaml refuse before npm unless --allow nav-reset
|
|
74
|
+
if (!allow.has('nav-reset') && navGuard(ws.root)) { console.error(`✖ ${NAV_GUARD_LINE}`); return EXIT.failed; }
|
|
75
|
+
const installedMap = here.manifest?.dreamteamer?.preset;
|
|
76
|
+
const newMap = entry.manifest.dreamteamer?.preset ?? {};
|
|
77
|
+
const moving = new Set(Object.entries(newMap).filter(([n, v]) => installed.has(n) && installed.get(n).version !== v).map(([n]) => n));
|
|
78
|
+
const skipMembers = new Set(Object.keys(newMap).filter((n) => !installed.has(n) && installedMap && n in installedMap));
|
|
79
|
+
const others = new Map([...installed].filter(([n]) => n !== target && !moving.has(n)));
|
|
65
80
|
let plan;
|
|
66
|
-
try { plan = resolveClosure([entry.spec], { installed: others, from, npm, cwd: ws.root }); } catch (e) { if (e instanceof InstallRefusal) { console.error(`✖ ${e.message}`); return EXIT.failed; } throw e; }
|
|
81
|
+
try { plan = resolveClosure([entry.spec], { installed: others, skipMembers, from, npm, cwd: ws.root }); } catch (e) { if (e instanceof InstallRefusal) { console.error(`✖ ${e.message}`); return EXIT.failed; } throw e; }
|
|
82
|
+
// a member moved below what is installed is a downgrade, said on purpose like the target's own
|
|
83
|
+
for (const e of plan.list) {
|
|
84
|
+
const n = e.manifest.name, was = installed.get(n)?.version;
|
|
85
|
+
if (n === target || !was || compareVersions(e.manifest.version, was) >= 0 || allow.has('downgrade')) continue;
|
|
86
|
+
console.error(`✖ ${n} ${was} → ${e.manifest.version} is a downgrade (module preset ${moduleIdOf(target)} names ${e.manifest.version}) — say so: dt update ${target}@${next} --allow downgrade`);
|
|
87
|
+
return EXIT.failed;
|
|
88
|
+
}
|
|
89
|
+
// a fragment merges into the workspace's nav.yaml: one that does not read refuses before npm writes
|
|
90
|
+
const navBad = shipsFragment(plan.list) ? navDocGuard(ws.root) : null;
|
|
91
|
+
if (navBad) { console.error(`✖ update refused: ${navBad} — dt check names what is wrong; fix it, then run this again`); return EXIT.failed; }
|
|
67
92
|
const names = plan.list.map((e) => e.manifest.name);
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
const
|
|
93
|
+
const moved = plan.list.filter((e) => e.manifest.name !== target && installed.has(e.manifest.name)).map((e) => `${e.manifest.name} ${installed.get(e.manifest.name).version} → ${e.manifest.version}`);
|
|
94
|
+
const extra = names.filter((n) => n !== target && !installed.has(n));
|
|
95
|
+
const tail = `${moved.length ? ` — members: ${moved.join(', ')}` : ''}${extra.length ? ` — with ${extra.join(', ')}` : ''}`;
|
|
96
|
+
log(`▶ update: ${target} ${here.version} → ${next}${tail}`);
|
|
97
|
+
// the compile in a fresh process too: this one cached the versions npm is about to replace
|
|
98
|
+
const step = await npmAndCompile(ws, plan.list, { npm, open, log, what: 'update', ignoreSettings: allow.has('nav-reset'), childCompile: true });
|
|
71
99
|
if (step.code !== undefined) return step.code;
|
|
72
|
-
|
|
73
|
-
|
|
100
|
+
if (step.nav.skipped === 'settings') log(NAV_SETTINGS_LINE);
|
|
101
|
+
// the setup half in a fresh process: this one imported the version npm just replaced (ESM caches it).
|
|
102
|
+
// The nav merge already ran here, inside the restore; the child is handed the merged document and
|
|
103
|
+
// only writes it with the commit.
|
|
104
|
+
const out = setupInChild(ws.root, names, { subject, processEnv, noCommit, nav: step.nav });
|
|
74
105
|
if (!out) {
|
|
75
106
|
console.error(`✖ ${target} ${here.version} → ${next}: npm and compile ran, but the setup half did not finish — run dt install ${target} to finish it (it commits the re-pin and runs the setup)`);
|
|
76
107
|
return EXIT.failed;
|
|
77
108
|
}
|
|
78
|
-
log(`✔ ${target} ${here.version} → ${next}${
|
|
109
|
+
log(`✔ ${target} ${here.version} → ${next}${tail} — compiled${out.committed ? `, committed (${out.committed.join(', ')})` : ', not committed'}`);
|
|
79
110
|
printUnitResults(out.results, out.ignored, log);
|
|
80
111
|
return out.code;
|
|
81
112
|
}
|
|
82
113
|
|
|
83
114
|
const CHILD = path.join(path.dirname(fileURLToPath(import.meta.url)), 'update-setup.js');
|
|
84
115
|
/** Run setupAndCommit in src/update-setup.js; its result, or null when the child did not leave one. */
|
|
85
|
-
function setupInChild(root, names, { subject, processEnv, noCommit }) {
|
|
116
|
+
function setupInChild(root, names, { subject, processEnv, noCommit, nav = null }) {
|
|
86
117
|
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'dt-update-'));
|
|
87
118
|
const out = path.join(dir, 'result.json');
|
|
88
119
|
try {
|
|
89
|
-
const r = spawnSync(process.execPath, [CHILD, JSON.stringify({ root, names, subject, noCommit, out })], { cwd: root, stdio: ['ignore', 'inherit', 'inherit'], env: processEnv });
|
|
120
|
+
const r = spawnSync(process.execPath, [CHILD, JSON.stringify({ root, names, subject, noCommit, out, nav })], { cwd: root, stdio: ['ignore', 'inherit', 'inherit'], env: processEnv });
|
|
90
121
|
if (r.status !== 0) return null;
|
|
91
122
|
try { return JSON.parse(fs.readFileSync(out, 'utf8')); } catch { return null; }
|
|
92
123
|
} finally { fs.rmSync(dir, { recursive: true, force: true }); }
|
|
93
124
|
}
|
|
94
125
|
|
|
95
|
-
/** The `dt update` argv: a target (`name`, `name@version`), `--engine`, `--allow downgrade`, `--from <dir>`, `--no-commit`. */
|
|
126
|
+
/** The `dt update` argv: a target (`name`, `name@version`), `--engine`, `--allow downgrade|nav-reset`, `--from <dir>`, `--no-commit`. */
|
|
96
127
|
export function parseUpdateArgs(argv) {
|
|
97
128
|
const out = { name: null, version: null, engine: argv.includes('--engine'), allow: new Set(), from: null, noCommit: argv.includes('--no-commit') };
|
|
98
129
|
for (let i = 0; i < argv.length; i++) {
|
|
99
130
|
const a = argv[i];
|
|
100
|
-
if (a === '--allow') { const k = argv[++i]; if (k !== 'downgrade') throw new Error(`dt update --allow takes downgrade (got ${JSON.stringify(k)})`); out.allow.add(k); }
|
|
131
|
+
if (a === '--allow') { const k = argv[++i]; if (k !== 'downgrade' && k !== 'nav-reset') throw new Error(`dt update --allow takes downgrade or nav-reset (got ${JSON.stringify(k)})`); out.allow.add(k); }
|
|
101
132
|
else if (a === '--from') out.from = argv[++i] ?? null;
|
|
102
133
|
else if (!a.startsWith('--') && !['--allow', '--from'].includes(argv[i - 1])) {
|
|
103
134
|
const at = a.startsWith('@') ? a.indexOf('@', 1) : a.indexOf('@');
|
package/src/workspace.js
CHANGED
|
@@ -180,23 +180,62 @@ export function ensureEditorRecommendation(root, warn = console.warn) {
|
|
|
180
180
|
|
|
181
181
|
/** `.env.example` lists every env key the installed modules declare — the file the missing-key
|
|
182
182
|
* warning points at, which used to carry two comment lines and none of the keys it was cited for.
|
|
183
|
-
*
|
|
184
|
-
*
|
|
185
|
-
|
|
186
|
-
|
|
183
|
+
* A key already named in the file (as `KEY=` or `# KEY`) is not added again, and nothing an operator
|
|
184
|
+
* wrote is touched. Values never appear here — an example does.
|
|
185
|
+
*
|
|
186
|
+
* The blocks THIS function wrote follow the declarations (rnd/issues …env-example-keeps-a-key-under-
|
|
187
|
+
* its-old-package…): an engine block is a `KEY=` line directly under `# declared by <packages>` or
|
|
188
|
+
* `# <description> (module <packages>)`. Its comment is rewritten when what declares the key changed
|
|
189
|
+
* (`moved`; the `KEY=` line, whose example may be the operator's, stays), and the block goes when no
|
|
190
|
+
* installed package declares the key (`dropped`) — unless `keep` names it (the workspace's own
|
|
191
|
+
* declaration) or the module set is not `complete` (a declared module not on disk yet: its keys would
|
|
192
|
+
* go and come back). A repeated engine block for one key goes with the first one's rewrite. Every
|
|
193
|
+
* other line is kept byte for byte, its line ending included. Returns `{ added, moved, dropped }`. */
|
|
194
|
+
export function ensureEnvExample(root, entries, header = '', { keep = [], complete = true } = {}) {
|
|
187
195
|
const file = path.join(root, '.env.example');
|
|
188
|
-
const
|
|
189
|
-
const
|
|
190
|
-
|
|
191
|
-
|
|
196
|
+
const exists = fs.existsSync(file);
|
|
197
|
+
const result = { added: [], moved: [], dropped: [] };
|
|
198
|
+
if (!entries.length && !exists) return result;
|
|
199
|
+
const existing = exists ? fs.readFileSync(file, 'utf8') : header;
|
|
200
|
+
const declared = new Map(entries.map((e) => [e.key, e]));
|
|
201
|
+
const commentFor = (e) => `# ${e.description ?? `declared by ${e.modules.join(', ')}`}${e.description && e.modules?.length ? ` (module ${e.modules.join(', ')})` : ''}`;
|
|
202
|
+
const lines = existing.split(/(?<=\n)/); // each line keeps its own ending
|
|
203
|
+
const text = (l) => l.replace(/\r?\n$/, '');
|
|
204
|
+
const ENGINE = /^# (?:declared by .+|.* \(module .+\))$/;
|
|
205
|
+
const seen = new Set();
|
|
206
|
+
const out = [];
|
|
207
|
+
for (let i = 0; i < lines.length; i++) {
|
|
208
|
+
const key = /^([A-Za-z_][A-Za-z0-9_]*)=/.exec(text(lines[i]))?.[1];
|
|
209
|
+
const prev = out.length - 1;
|
|
210
|
+
if (!key || prev < 0 || !ENGINE.test(text(out[prev])) || !complete) { out.push(lines[i]); continue; }
|
|
211
|
+
const e = declared.get(key);
|
|
212
|
+
if (e && !seen.has(key)) {
|
|
213
|
+
seen.add(key);
|
|
214
|
+
const want = commentFor(e);
|
|
215
|
+
if (text(out[prev]) !== want) { out[prev] = want + out[prev].slice(text(out[prev]).length); result.moved.push(key); }
|
|
216
|
+
out.push(lines[i]);
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
if (!e && keep.includes(key)) { out.push(lines[i]); continue; }
|
|
220
|
+
// a key nothing declares, or a second engine block for one: the comment, the key and the blank line before them go
|
|
221
|
+
out.pop();
|
|
222
|
+
if (out.length && text(out[out.length - 1]) === '') out.pop();
|
|
223
|
+
else if (!out.length && i + 1 < lines.length && text(lines[i + 1]) === '') i++; // at the top of the file: the blank line after
|
|
224
|
+
if (!e && !result.dropped.includes(key)) result.dropped.push(key);
|
|
225
|
+
}
|
|
226
|
+
let next = out.join('');
|
|
227
|
+
// what is named after the drops: a dropped key is no longer named, so it is never added back here
|
|
228
|
+
const named = new Set([...next.matchAll(/^\s*#?\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=/gm)].map((m) => m[1]));
|
|
229
|
+
const eol = existing.includes('\r\n') ? '\r\n' : '\n';
|
|
192
230
|
for (const e of entries) {
|
|
193
231
|
if (named.has(e.key)) continue;
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
added.push(e.key);
|
|
232
|
+
next = next.trimEnd() + `${eol}${eol}${commentFor(e)}${eol}${e.key}=${e.example ?? ''}${eol}`;
|
|
233
|
+
named.add(e.key);
|
|
234
|
+
result.added.push(e.key);
|
|
197
235
|
}
|
|
198
|
-
if (added.length)
|
|
199
|
-
|
|
236
|
+
if (result.added.length) next = next.replace(/^(?:\r?\n)+/, '');
|
|
237
|
+
if (next !== existing) fs.writeFileSync(file, next);
|
|
238
|
+
return result;
|
|
200
239
|
}
|
|
201
240
|
|
|
202
241
|
/**
|