castle-web-cli 0.4.188 → 0.4.189
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/dist/castleJson.d.ts +1 -0
- package/dist/castleJson.js +6 -0
- package/dist/forks.js +5 -3
- package/dist/ide.js +9 -2
- package/dist/imports.d.ts +8 -2
- package/dist/imports.js +67 -7
- package/dist/init.js +12 -2
- package/package.json +2 -2
package/dist/castleJson.d.ts
CHANGED
package/dist/castleJson.js
CHANGED
|
@@ -20,6 +20,12 @@ import picomatch from 'picomatch';
|
|
|
20
20
|
// renders in the fallback while claiming otherwise.
|
|
21
21
|
export const STARTER_THEME_FILES = ['theme.style', 'fonts.generated.js'];
|
|
22
22
|
export const IMPORTS_DIR = 'imports';
|
|
23
|
+
// Written into every placed import (`imports/<alias>/`) naming the deck and
|
|
24
|
+
// version whose files these are. Derived state like the tree it sits in: it
|
|
25
|
+
// is never deck content, so the files API hides it and forking refuses it.
|
|
26
|
+
// Defined here rather than in imports.ts so forks.ts can name it without a
|
|
27
|
+
// cycle.
|
|
28
|
+
export const IMPORT_VERSION_FILE = '.castle-import-version.json';
|
|
23
29
|
export const DEFAULT_STARTER_SCENE = 'scenes/main.scene';
|
|
24
30
|
export const DEFAULT_SERVER_TICK_RATE = 20;
|
|
25
31
|
export const DEFAULT_SERVER_MAX_PLAYERS = 8;
|
package/dist/forks.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as crypto from 'crypto';
|
|
2
2
|
import * as fs from 'fs';
|
|
3
3
|
import * as path from 'path';
|
|
4
|
-
import { IMPORTS_DIR, readCastleJson } from './castleJson.js';
|
|
4
|
+
import { IMPORTS_DIR, IMPORT_VERSION_FILE, readCastleJson, } from './castleJson.js';
|
|
5
5
|
// A fork is this deck's own version of one file from an import, kept at the same
|
|
6
6
|
// path under `forks/` and substituted for the imported file wherever it is
|
|
7
7
|
// loaded. Same path, not a copy elsewhere, so every existing reference to it --
|
|
@@ -91,8 +91,10 @@ export function resolveForkedFile(deckDir, relPosix) {
|
|
|
91
91
|
// honest answer until forking one of these means something.
|
|
92
92
|
//
|
|
93
93
|
// Matched against the path INSIDE the import, so this is the import's own root
|
|
94
|
-
// manifest and not some `scenes/castle.json` a deck happens to have.
|
|
95
|
-
|
|
94
|
+
// manifest and not some `scenes/castle.json` a deck happens to have. The
|
|
95
|
+
// version marker is the same kind of thing: a record about the import, and
|
|
96
|
+
// forking it would copy that record into forks/, which IS archived.
|
|
97
|
+
const NON_FORKABLE = new Set(['castle.json', IMPORT_VERSION_FILE]);
|
|
96
98
|
/** Whether a path inside an import may be forked. */
|
|
97
99
|
export function isForkable(inner) {
|
|
98
100
|
return !NON_FORKABLE.has(inner);
|
package/dist/ide.js
CHANGED
|
@@ -17,7 +17,7 @@ import headlessPkg from '@xterm/headless';
|
|
|
17
17
|
import { SerializeAddon } from '@xterm/addon-serialize';
|
|
18
18
|
import { WebSocketServer } from 'ws';
|
|
19
19
|
import { rawDataToString } from './rawData.js';
|
|
20
|
-
import { IMPORTS_DIR, importStatuses, updateImport } from './imports.js';
|
|
20
|
+
import { IMPORTS_DIR, IMPORT_VERSION_FILE, importStatuses, updateImport, } from './imports.js';
|
|
21
21
|
import { FORKS_DIR, forkImportFile, forkStateOf, listOwnForks, ownForkFile, resolveForkedFile, revertImportFile, } from './forks.js';
|
|
22
22
|
import { ensureVisibleGlob, ensureVisiblePath } from './castleJson.js';
|
|
23
23
|
import { readEditorConfig, resolveFileTypes, } from './editorConfig.js';
|
|
@@ -263,6 +263,11 @@ export function resolveDeckPath(deckDir, requestedPath, opts = {}) {
|
|
|
263
263
|
return { ok: false, error: `Path outside the deck: ${requestedPath}` };
|
|
264
264
|
}
|
|
265
265
|
const relPosix = rel.split(path.sep).join('/');
|
|
266
|
+
// The marker describes derived import state, not deck content, so the files
|
|
267
|
+
// API must not expose it even to a client that guesses its hidden name.
|
|
268
|
+
if (isImportPath(relPosix) && parts.includes(IMPORT_VERSION_FILE)) {
|
|
269
|
+
return { ok: false, error: `Protected deck path: ${requestedPath}` };
|
|
270
|
+
}
|
|
266
271
|
// An imported path answers with whatever overrides it, keeping `rel` as the
|
|
267
272
|
// imports path -- that is what the deck calls this file everywhere else, and
|
|
268
273
|
// only the file on disk changes.
|
|
@@ -297,7 +302,9 @@ function listDeckFiles(deckDir) {
|
|
|
297
302
|
return;
|
|
298
303
|
}
|
|
299
304
|
for (const entry of entries) {
|
|
300
|
-
|
|
305
|
+
// The version marker is derived import state, not a deck file; every
|
|
306
|
+
// other dotfile (.gitignore, .prettierrc) stays listed as before.
|
|
307
|
+
if (entry.name === '.DS_Store' || entry.name === IMPORT_VERSION_FILE)
|
|
301
308
|
continue;
|
|
302
309
|
const rel = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
303
310
|
if (entry.isDirectory()) {
|
package/dist/imports.d.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
import { IMPORTS_DIR } from './castleJson.js';
|
|
2
|
-
export { IMPORTS_DIR };
|
|
1
|
+
import { IMPORTS_DIR, IMPORT_VERSION_FILE } from './castleJson.js';
|
|
2
|
+
export { IMPORTS_DIR, IMPORT_VERSION_FILE };
|
|
3
|
+
export interface ImportVersion {
|
|
4
|
+
deckId: string;
|
|
5
|
+
version: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function writeImportVersion(importDir: string, value: ImportVersion): void;
|
|
8
|
+
export declare function readImportVersion(deckDir: string, alias: string): ImportVersion | null;
|
|
3
9
|
export type ImportErrorCode = 'no-deck-ref' | 'bad-deck-ref' | 'no-such-dir' | 'self-import' | 'no-source' | 'bad-alias';
|
|
4
10
|
export declare class ImportError extends Error {
|
|
5
11
|
code: ImportErrorCode;
|
package/dist/imports.js
CHANGED
|
@@ -5,8 +5,9 @@ import * as api from './api.js';
|
|
|
5
5
|
import { runTar } from './save-deck.js';
|
|
6
6
|
import { normalizeDeckPackageJson } from './normalize.js';
|
|
7
7
|
import { getKitsDir } from './localPaths.js';
|
|
8
|
+
import { SDK_PACKAGE } from './sdkResolve.js';
|
|
8
9
|
import { writePlatformDocs } from './platformDoc.js';
|
|
9
|
-
import { ensureVisibleGlob, IMPORTS_DIR, STARTER_THEME_FILES, readCastleJson as tryReadCastleJson, readCastleJsonOrThrow as readCastleJson, } from './castleJson.js';
|
|
10
|
+
import { ensureVisibleGlob, IMPORTS_DIR, IMPORT_VERSION_FILE, STARTER_THEME_FILES, readCastleJson as tryReadCastleJson, readCastleJsonOrThrow as readCastleJson, } from './castleJson.js';
|
|
10
11
|
// Adding another deck as a dependency (`castle-web add-import`; removing one is a
|
|
11
12
|
// later command). Deliberately NOT `get-deck`: that one
|
|
12
13
|
// replaces THIS deck's own source from the server (and carries guards for the
|
|
@@ -25,7 +26,31 @@ import { ensureVisibleGlob, IMPORTS_DIR, STARTER_THEME_FILES, readCastleJson as
|
|
|
25
26
|
// dependency, and the files are re-fetchable from them -- same treatment
|
|
26
27
|
// node_modules gets. That also means `get-deck` leaves an existing `imports/`
|
|
27
28
|
// alone when it refreshes a deck.
|
|
28
|
-
export { IMPORTS_DIR };
|
|
29
|
+
export { IMPORTS_DIR, IMPORT_VERSION_FILE };
|
|
30
|
+
// The marker (IMPORT_VERSION_FILE, see castleJson.ts) stays with the placed
|
|
31
|
+
// files so their provenance can be checked. The separate .castle-import-pin.json
|
|
32
|
+
// remains backup-only rollback state and is removed when that backup is restored.
|
|
33
|
+
export function writeImportVersion(importDir, value) {
|
|
34
|
+
fs.writeFileSync(path.join(importDir, IMPORT_VERSION_FILE), JSON.stringify(value, null, 2) + '\n', 'utf-8');
|
|
35
|
+
}
|
|
36
|
+
export function readImportVersion(deckDir, alias) {
|
|
37
|
+
try {
|
|
38
|
+
const value = JSON.parse(fs.readFileSync(path.join(deckDir, IMPORTS_DIR, alias, IMPORT_VERSION_FILE), 'utf-8'));
|
|
39
|
+
return typeof value.deckId === 'string' && typeof value.version === 'string'
|
|
40
|
+
? { deckId: value.deckId, version: value.version }
|
|
41
|
+
: null;
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
// A match proves the files on disk are the ones the pin names -- same deck, same
|
|
48
|
+
// version. No marker, or one that disagrees, proves nothing about them, so the
|
|
49
|
+
// only way to be sure of what is there is to fetch it again.
|
|
50
|
+
function importFilesMatchPin(deckDir, alias, pin) {
|
|
51
|
+
const recorded = readImportVersion(deckDir, alias);
|
|
52
|
+
return !!pin.deckId && recorded?.deckId === pin.deckId && recorded?.version === pin.version;
|
|
53
|
+
}
|
|
29
54
|
export class ImportError extends Error {
|
|
30
55
|
code;
|
|
31
56
|
constructor(code, message) {
|
|
@@ -226,6 +251,11 @@ export function syncImportDependencies(deckDir) {
|
|
|
226
251
|
continue; // an import without a package.json declares nothing
|
|
227
252
|
}
|
|
228
253
|
for (const [name, range] of Object.entries(importPkg.dependencies ?? {})) {
|
|
254
|
+
// The SDK is a file of the base kit every deck imports, resolved by
|
|
255
|
+
// sdkResolve. A kit declaration is either a devDependency for its own
|
|
256
|
+
// check or a mistake, and neither belongs in the deck.
|
|
257
|
+
if (name === SDK_PACKAGE)
|
|
258
|
+
continue;
|
|
229
259
|
if (deps[name] !== undefined)
|
|
230
260
|
continue;
|
|
231
261
|
deps[name] = range;
|
|
@@ -260,6 +290,11 @@ export async function restoreMissingImports(deckDir) {
|
|
|
260
290
|
continue;
|
|
261
291
|
}
|
|
262
292
|
await fetchDeckSourceInto(source.archiveUrl, destDir);
|
|
293
|
+
// The server only serves its latest archive, so what landed here is
|
|
294
|
+
// `source.updatedAt`, not necessarily what the pin says. Record the
|
|
295
|
+
// truth: the pin stays as committed, and publish-kits compares the two
|
|
296
|
+
// to refuse bundling against files no pin describes.
|
|
297
|
+
writeImportVersion(destDir, { deckId: pin.deckId, version: source.updatedAt });
|
|
263
298
|
}
|
|
264
299
|
else if (pin?.source === 'builtin') {
|
|
265
300
|
// Scaffolded from the kit shipped with the CLI: the same copy is still
|
|
@@ -353,10 +388,13 @@ export async function importStatuses(deckDir) {
|
|
|
353
388
|
const source = await api.webDeckSource(pin.deckId).catch(() => null);
|
|
354
389
|
if (!source)
|
|
355
390
|
return base;
|
|
391
|
+
// Files that can't prove they are the pinned version are an update too,
|
|
392
|
+
// even at the same version: refetching is how such a tree gets a marker,
|
|
393
|
+
// and until it has one the deck can't be published.
|
|
356
394
|
return {
|
|
357
395
|
...base,
|
|
358
396
|
latest: source.updatedAt,
|
|
359
|
-
updateAvailable: source.updatedAt !== pin.version,
|
|
397
|
+
updateAvailable: source.updatedAt !== pin.version || !importFilesMatchPin(deckDir, alias, pin),
|
|
360
398
|
};
|
|
361
399
|
}));
|
|
362
400
|
statusCache.set(deckDir, { at: Date.now(), value });
|
|
@@ -408,6 +446,7 @@ async function placeImport(deckDir, alias, deckId, source, via) {
|
|
|
408
446
|
if (replaced)
|
|
409
447
|
backupImport(deckDir, alias);
|
|
410
448
|
await fetchDeckSourceInto(source.archiveUrl, destDir);
|
|
449
|
+
writeImportVersion(destDir, { deckId, version: source.updatedAt });
|
|
411
450
|
lockImportTree(destDir);
|
|
412
451
|
clearStatusCache(deckDir);
|
|
413
452
|
writeImportPin(deckDir, alias, {
|
|
@@ -716,7 +755,12 @@ export async function autoUpdateImports(deckDir) {
|
|
|
716
755
|
if (!(await importIsOnTrustedAccount(pin.deckId)))
|
|
717
756
|
continue;
|
|
718
757
|
const source = await api.webDeckSource(pin.deckId);
|
|
719
|
-
if (!source
|
|
758
|
+
if (!source)
|
|
759
|
+
continue;
|
|
760
|
+
// A pin moved without the files -- get-deck replaces castle.json and
|
|
761
|
+
// leaves `imports/` alone -- leaves the tree stale at what looks like the
|
|
762
|
+
// current version, so a marker that doesn't match is reason to refetch.
|
|
763
|
+
if (source.updatedAt === pin.version && importFilesMatchPin(deckDir, alias, pin))
|
|
720
764
|
continue;
|
|
721
765
|
await applyImportUpdate(deckDir, alias, { deckId: pin.deckId, from: pin.version, via: pin.via }, source, (message) => console.log(`auto-update: ${message}`));
|
|
722
766
|
updated.push({ alias, from: pin.version, to: source.updatedAt });
|
|
@@ -774,12 +818,19 @@ export async function updateImport(dir, options = {}) {
|
|
|
774
818
|
console.warn(`Could not check "${alias}" (${pin.deckId}); it has no source on the server.`);
|
|
775
819
|
continue;
|
|
776
820
|
}
|
|
777
|
-
|
|
821
|
+
// Up to date means the pin is current AND the files on disk say they are
|
|
822
|
+
// that version. A tree placed before markers existed, or left behind by a
|
|
823
|
+
// pull that moved the pin, has no way to prove what it is, so it is
|
|
824
|
+
// refetched even when the pin needs no change -- that is how such a tree
|
|
825
|
+
// ever gets a marker, and what publish-kits sends people here for.
|
|
826
|
+
if (source.updatedAt === pin.version && importFilesMatchPin(deckDir, alias, pin)) {
|
|
778
827
|
console.log(`${alias} is up to date.`);
|
|
779
828
|
continue;
|
|
780
829
|
}
|
|
781
830
|
if (options.check) {
|
|
782
|
-
console.log(
|
|
831
|
+
console.log(source.updatedAt === pin.version
|
|
832
|
+
? `${alias}: the files on disk do not record version ${pin.version}; an update refetches them`
|
|
833
|
+
: `${alias}: update available (have ${pin.version}, latest ${source.updatedAt})`);
|
|
783
834
|
changed = true;
|
|
784
835
|
continue;
|
|
785
836
|
}
|
|
@@ -812,10 +863,16 @@ function revertImport(deckDir, alias) {
|
|
|
812
863
|
fs.rmSync(destDir, { recursive: true, force: true });
|
|
813
864
|
}
|
|
814
865
|
fs.cpSync(backup, destDir, { recursive: true, verbatimSymlinks: true });
|
|
866
|
+
// The backup carries the old version marker with the old files. Restoring its
|
|
867
|
+
// saved pin below therefore puts both records back on the same version. A
|
|
868
|
+
// backup taken before markers existed carries no marker, and nothing here can
|
|
869
|
+
// supply one: the saved pin says what the deck believed, not what these files
|
|
870
|
+
// are, so writing it would invent provenance the publish guard then trusts.
|
|
815
871
|
const pinFile = path.join(destDir, '.castle-import-pin.json');
|
|
816
872
|
if (fs.existsSync(pinFile)) {
|
|
817
873
|
try {
|
|
818
|
-
|
|
874
|
+
const saved = JSON.parse(fs.readFileSync(pinFile, 'utf-8'));
|
|
875
|
+
writeImportPin(deckDir, alias, saved);
|
|
819
876
|
}
|
|
820
877
|
catch {
|
|
821
878
|
/* an unreadable pin file just means the version stays as recorded */
|
|
@@ -827,4 +884,7 @@ function revertImport(deckDir, alias) {
|
|
|
827
884
|
lockImportTree(destDir);
|
|
828
885
|
clearStatusCache(deckDir);
|
|
829
886
|
console.log(`Reverted ${alias} to its previous version.`);
|
|
887
|
+
if (!fs.existsSync(path.join(destDir, IMPORT_VERSION_FILE))) {
|
|
888
|
+
console.log(`That copy predates version records; run \`castle-web update-import ${alias}\` to refetch it before it can be published.`);
|
|
889
|
+
}
|
|
830
890
|
}
|
package/dist/init.js
CHANGED
|
@@ -3,9 +3,10 @@ import * as path from 'path';
|
|
|
3
3
|
import { CLAUDE_MD_PLATFORM_SECTION } from './platformDoc.js';
|
|
4
4
|
import { installDeps } from './install.js';
|
|
5
5
|
import { deckMainFile, deckStarterScene, STARTER_THEME_FILES } from './castleJson.js';
|
|
6
|
-
import { addImportTo, IMPORTS_DIR, lockImportTree, restoreMissingImports, syncImportDependencies, } from './imports.js';
|
|
6
|
+
import { addImportTo, IMPORTS_DIR, lockImportTree, restoreMissingImports, syncImportDependencies, writeImportVersion, } from './imports.js';
|
|
7
7
|
import { discardParentSource, fetchParentSource, unpackParentSource, writeRemixIdentity, } from './remix.js';
|
|
8
8
|
import { getCliEntryPath, getKitsDir, getSdkPackagePath, toPosixPath } from './localPaths.js';
|
|
9
|
+
import { SDK_PACKAGE } from './sdkResolve.js';
|
|
9
10
|
import { serve } from './serve.js';
|
|
10
11
|
import { createVersion } from './versions.js';
|
|
11
12
|
// Default kit imported by `init` when no --kit is given. `none`/`bare` skips the
|
|
@@ -480,7 +481,11 @@ function copyKitImport(projectDir, kitDir, kit, alias, pins, copied) {
|
|
|
480
481
|
filter: (src) => src === kitDir || (src !== nestedImports && !KIT_COPY_EXCLUDE.has(path.basename(src))),
|
|
481
482
|
});
|
|
482
483
|
const kitConfig = readJsonFile(path.join(kitDir, 'castle.json')) ?? {};
|
|
483
|
-
|
|
484
|
+
const pin = makeKitPin(kitConfig, kit);
|
|
485
|
+
pins[alias] = pin;
|
|
486
|
+
if (typeof pin.deckId === 'string') {
|
|
487
|
+
writeImportVersion(importDir, { deckId: pin.deckId, version: pin.version });
|
|
488
|
+
}
|
|
484
489
|
const kitPins = (kitConfig.imports ?? {});
|
|
485
490
|
for (const [depAlias, depPin] of Object.entries(kitPins)) {
|
|
486
491
|
if (copied.has(depAlias) || pins[depAlias])
|
|
@@ -550,6 +555,11 @@ function scaffoldFromKitImport(kit, projectDir) {
|
|
|
550
555
|
for (const depKitDir of copied.values()) {
|
|
551
556
|
const depPkg = readJsonFile(path.join(depKitDir, 'package.json')) ?? {};
|
|
552
557
|
for (const [name, range] of Object.entries(depPkg.dependencies ?? {})) {
|
|
558
|
+
// The SDK is a file of the base kit every deck imports, resolved by
|
|
559
|
+
// sdkResolve. A kit declaration is either a devDependency for its own
|
|
560
|
+
// check or a mistake, and neither belongs in the deck.
|
|
561
|
+
if (name === SDK_PACKAGE)
|
|
562
|
+
continue;
|
|
553
563
|
if (dependencies[name] !== undefined)
|
|
554
564
|
continue;
|
|
555
565
|
dependencies[name] = String(range);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "castle-web-cli",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.189",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/castle-xyz/castle-experimental-web.git"
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"scripts": {
|
|
13
13
|
"build": "rm -rf dist && tsc && chmod +x dist/index.js && vite build && cp -R src/castle-host dist/castle-host && chmod -R u+w kits 2>/dev/null; rm -rf kits && cp -R ../kits kits && chmod -R u+w kits && rm -rf kits/*/imports",
|
|
14
14
|
"dev": "tsc --watch",
|
|
15
|
-
"check": "node ../scripts/sync-shared.mjs --check && node ../scripts/tests/icon-registry.mjs && node ../scripts/tests/sandbox-graphql-fields.mjs && eslint . && jscpd && tsc --noEmit && tsc --noEmit -p src/shell/tsconfig.json"
|
|
15
|
+
"check": "node ../scripts/sync-shared.mjs --check && node ../scripts/tests/icon-registry.mjs && node ../scripts/tests/sandbox-graphql-fields.mjs && node ../scripts/tests/kit-package-json.mjs && eslint . && jscpd && tsc --noEmit && tsc --noEmit -p src/shell/tsconfig.json"
|
|
16
16
|
},
|
|
17
17
|
"jscpd": {
|
|
18
18
|
"path": [
|