farseer-cli 1.16.0 → 1.17.0
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 +328 -0
- package/dist/commands/code.js +104 -0
- package/dist/commands/code.js.map +7 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +2 -2
- package/dist/pipeline/service.js +1 -1
- package/dist/pipeline/service.js.map +2 -2
- package/dist/services/codefirst/api.js +269 -0
- package/dist/services/codefirst/api.js.map +7 -0
- package/dist/services/codefirst/binaryDisk.js +67 -0
- package/dist/services/codefirst/binaryDisk.js.map +7 -0
- package/dist/services/codefirst/byteHashes.js +129 -0
- package/dist/services/codefirst/byteHashes.js.map +7 -0
- package/dist/services/codefirst/documents.js +563 -0
- package/dist/services/codefirst/documents.js.map +7 -0
- package/dist/services/codefirst/layoutBinaryProjection.js +974 -0
- package/dist/services/codefirst/layoutBinaryProjection.js.map +7 -0
- package/dist/services/codefirst/layoutCompose.js +593 -0
- package/dist/services/codefirst/layoutCompose.js.map +7 -0
- package/dist/services/codefirst/layoutCore.js +260 -0
- package/dist/services/codefirst/layoutCore.js.map +7 -0
- package/dist/services/codefirst/layoutPaths.js +492 -0
- package/dist/services/codefirst/layoutPaths.js.map +7 -0
- package/dist/services/codefirst/layoutProjection.js +995 -0
- package/dist/services/codefirst/layoutProjection.js.map +7 -0
- package/dist/services/codefirst/layoutReadback.js +2552 -0
- package/dist/services/codefirst/layoutReadback.js.map +7 -0
- package/dist/services/codefirst/layoutReadbackPlacement.js +1517 -0
- package/dist/services/codefirst/layoutReadbackPlacement.js.map +7 -0
- package/dist/services/codefirst/layoutReceipt.js +1592 -0
- package/dist/services/codefirst/layoutReceipt.js.map +7 -0
- package/dist/services/codefirst/layoutScan.js +882 -0
- package/dist/services/codefirst/layoutScan.js.map +7 -0
- package/dist/services/codefirst/output.js +179 -0
- package/dist/services/codefirst/output.js.map +7 -0
- package/dist/services/codefirst/types.js +17 -0
- package/dist/services/codefirst/types.js.map +7 -0
- package/dist/services/codefirst/workflow.js +581 -0
- package/dist/services/codefirst/workflow.js.map +7 -0
- package/dist/services/codefirst/workspace.js +310 -0
- package/dist/services/codefirst/workspace.js.map +7 -0
- package/dist/services/codefirst/workspaceLock.js +148 -0
- package/dist/services/codefirst/workspaceLock.js.map +7 -0
- package/dist/services/codefirst/workspaceRoot.js +147 -0
- package/dist/services/codefirst/workspaceRoot.js.map +7 -0
- package/dist/utils/logger.js +9 -3
- package/dist/utils/logger.js.map +2 -2
- package/package.json +3 -2
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/services/codefirst/workspaceLock.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * One `farseer code` command per workspace at a time, enforced with `.fscode/lock`, as git does with\n * `index.lock`. Two commands in one workspace would each save `state.json` over the other's save,\n * and the loser's final-save check fails after its files are written.\n *\n * The lock is its own file because the writer replaces `state.json` by a temporary file and a\n * rename, which would drop a lock held on it. Node has no portable OS file lock, so the lock is an\n * exclusive create (`wx`, atomic on every platform) holding `{ pid, hostname, command, startedAt }`.\n * A lock whose holder ran on this host and whose pid no longer exists is stale and taken over; any\n * other lock refuses the command and names its holder, because a live pid may be a reused one and a\n * pid from another host (a shared drive) cannot be checked. Staleness never reads mtimes: the writer\n * runs synchronously for long stretches and could not refresh one.\n *\n * The lock is released when the command ends, when it throws, and on every `process.exit`, through\n * an `exit` listener. Ctrl-C reaches `exit` too: the lock installs the writer's SIGINT listener\n * (`exitAfterWrites`), which exits only after the synchronous writes, so a command interrupted\n * before its writes also releases the lock instead of being killed by Node's default handler.\n */\nimport * as fs from 'fs';\nimport * as os from 'os';\nimport * as path from 'path';\nimport { exitAfterWrites } from './layoutReceipt';\nimport { STATE_DIR } from './workspaceRoot';\n\nexport const LOCK_FILE = `${STATE_DIR}/lock`;\n\ninterface LockHolder {\n pid: number;\n hostname: string;\n command: string;\n startedAt: string;\n}\n\nconst deleteAdvice = `If no such command is running, delete ${LOCK_FILE}.`;\n\nfunction lockPath(root: string): string {\n return path.join(root, ...LOCK_FILE.split('/'));\n}\n\nfunction readLock(file: string): { text: string; holder?: LockHolder } | undefined {\n let text: string;\n try {\n text = fs.readFileSync(file, 'utf8');\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') return undefined;\n return { text: '' };\n }\n try {\n const value = JSON.parse(text) as Partial<LockHolder>;\n const valid =\n Number.isSafeInteger(value.pid) &&\n (value.pid as number) > 0 &&\n typeof value.hostname === 'string' &&\n typeof value.command === 'string' &&\n typeof value.startedAt === 'string' &&\n !Number.isNaN(Date.parse(value.startedAt));\n return { text, holder: valid ? (value as LockHolder) : undefined };\n } catch {\n return { text };\n }\n}\n\n/** Whether `pid` names a running process. Only `ESRCH` proves it gone; `EPERM` means it exists. */\nfunction running(pid: number): boolean {\n try {\n process.kill(pid, 0);\n return true;\n } catch (error) {\n return (error as NodeJS.ErrnoException).code !== 'ESRCH';\n }\n}\n\nfunction startedLabel(startedAt: string): string {\n const started = new Date(startedAt);\n const pad = (value: number) => String(value).padStart(2, '0');\n const time = `${pad(started.getHours())}:${pad(started.getMinutes())}`;\n if (started.toDateString() === new Date().toDateString()) return time;\n return `${started.getFullYear()}-${pad(started.getMonth() + 1)}-${pad(started.getDate())} ${time}`;\n}\n\nfunction refusal(holder: LockHolder | undefined): Error {\n if (!holder)\n return new Error(\n `The workspace lock ${LOCK_FILE} cannot be read, so another farseer code command may be running ` +\n `in this workspace. ${deleteAdvice}`,\n );\n const host = holder.hostname === os.hostname() ? '' : ` on ${holder.hostname}`;\n return new Error(\n `Another farseer code command is running in this workspace: ${holder.command}, pid ${holder.pid}${host}, ` +\n `started ${startedLabel(holder.startedAt)}. ${deleteAdvice}`,\n );\n}\n\n/** Create the lock file with `content`; false when it already exists. */\nfunction create(file: string, content: string): boolean {\n let descriptor: number;\n try {\n descriptor = fs.openSync(file, 'wx');\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === 'EEXIST') return false;\n throw error;\n }\n try {\n fs.writeSync(descriptor, content);\n } catch (error) {\n fs.closeSync(descriptor);\n fs.rmSync(file, { force: true });\n throw error;\n }\n fs.closeSync(descriptor);\n return true;\n}\n\n/**\n * Take the workspace lock for `command` (as the user typed it, e.g. `code pull`) or throw the\n * refusal. Returns the release, which removes the lock only while it still holds this command's\n * content and is safe to call more than once.\n */\nexport function acquireWorkspaceLock(root: string, command: string): () => void {\n const file = lockPath(root);\n const content = JSON.stringify({\n pid: process.pid,\n hostname: os.hostname(),\n command,\n startedAt: new Date().toISOString(),\n } satisfies LockHolder);\n if (!create(file, content)) {\n const found = readLock(file);\n const stale = found?.holder && found.holder.hostname === os.hostname() && !running(found.holder.pid);\n if (found && !stale) throw refusal(found.holder);\n // Removed only while it is still the stale lock just read; a lost race below is refused.\n if (found && readLock(file)?.text === found.text) fs.rmSync(file, { force: true });\n if (!create(file, content)) throw refusal(readLock(file)?.holder);\n }\n let held = true;\n const release = () => {\n if (!held) return;\n held = false;\n process.removeListener('exit', release);\n try {\n if (fs.readFileSync(file, 'utf8') === content) fs.unlinkSync(file);\n } catch {\n // Already gone, or unreadable: the next command names it if it is still there.\n }\n };\n process.on('exit', release);\n if (!process.listeners('SIGINT').includes(exitAfterWrites)) process.on('SIGINT', exitAfterWrites);\n return release;\n}\n\n/** Run `action` holding the workspace lock, and release it however the action ends. */\nexport async function withWorkspaceLock<T>(root: string, command: string, action: () => Promise<T>): Promise<T> {\n const release = acquireWorkspaceLock(root, command);\n try {\n return await action();\n } finally {\n release();\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAkBA,SAAoB;AACpB,SAAoB;AACpB,WAAsB;AACtB,2BAAgC;AAChC,2BAA0B;AAEnB,MAAM,YAAY,GAAG,8BAAS;AASrC,MAAM,eAAe,yCAAyC,SAAS;AAEvE,SAAS,SAAS,MAAsB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MAAM,OAAO,EAAG,OAAM,QAAQ,SAAS,IAAI,GAAG,MAAM;AAAA,EACpE;AACA,MAAI,OAAO;AACX,QAAM,UAAU,MAAM;AAClB,QAAI,CAAC,KAAM;AACX,WAAO;AACP,YAAQ,eAAe,QAAQ,OAAO;AACtC,QAAI;AACA,UAAI,GAAG,aAAa,MAAM,MAAM,MAAM,QAAS,IAAG,WAAW,IAAI;AAAA,IACrE,QAAQ;AAAA,IAER;AAAA,EACJ;AACA,UAAQ,GAAG,QAAQ,OAAO;AAC1B,MAAI,CAAC,QAAQ,UAAU,QAAQ,EAAE,SAAS,oCAAe,EAAG,SAAQ,GAAG,UAAU,oCAAe;AAChG,SAAO;AACX;AAGA,eAAsB,kBAAqB,MAAc,SAAiB,QAAsC;AAC5G,QAAM,UAAU,qBAAqB,MAAM,OAAO;AAClD,MAAI;AACA,WAAO,MAAM,OAAO;AAAA,EACxB,UAAE;AACE,YAAQ;AAAA,EACZ;AACJ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var workspaceRoot_exports = {};
|
|
30
|
+
__export(workspaceRoot_exports, {
|
|
31
|
+
LEGACY_CODEFIRST_STATE: () => LEGACY_CODEFIRST_STATE,
|
|
32
|
+
LEGACY_SYNC_DIR: () => LEGACY_SYNC_DIR,
|
|
33
|
+
NO_CODE_WORKSPACE: () => NO_CODE_WORKSPACE,
|
|
34
|
+
PRE_SPLIT_WORKSPACE: () => PRE_SPLIT_WORKSPACE,
|
|
35
|
+
STATE_DIR: () => STATE_DIR,
|
|
36
|
+
STATE_FILE: () => STATE_FILE,
|
|
37
|
+
WORKSPACE_GITIGNORE: () => WORKSPACE_GITIGNORE,
|
|
38
|
+
createCodeWorkspace: () => createCodeWorkspace,
|
|
39
|
+
locateCodeWorkspace: () => locateCodeWorkspace,
|
|
40
|
+
resolveCodeWorkspace: () => resolveCodeWorkspace
|
|
41
|
+
});
|
|
42
|
+
module.exports = __toCommonJS(workspaceRoot_exports);
|
|
43
|
+
var fs = __toESM(require("fs"));
|
|
44
|
+
var path = __toESM(require("path"));
|
|
45
|
+
var import_documents = require("./documents");
|
|
46
|
+
const STATE_DIR = ".fscode";
|
|
47
|
+
const STATE_FILE = `${STATE_DIR}/state.json`;
|
|
48
|
+
const LEGACY_SYNC_DIR = "farseer-apps";
|
|
49
|
+
const WORKSPACE_GITIGNORE = `# Farseer code workspace state: baseline, physical routes and apply receipts.
|
|
50
|
+
# It is per-machine tool state, not authored work.
|
|
51
|
+
${STATE_DIR}/
|
|
52
|
+
# Operating-system and tool files, which the workspace ignores too.
|
|
53
|
+
.DS_Store
|
|
54
|
+
Thumbs.db
|
|
55
|
+
desktop.ini
|
|
56
|
+
__pycache__/
|
|
57
|
+
._*
|
|
58
|
+
# Temporaries a writer leaves when it is killed mid-write.
|
|
59
|
+
*.tmp-????????-????-????-????-????????????
|
|
60
|
+
`;
|
|
61
|
+
const NO_CODE_WORKSPACE = "Not inside a Farseer code workspace; run farseer code checkout <tenant> first";
|
|
62
|
+
const LEGACY_CODEFIRST_STATE = ".farseer-codefirst.json";
|
|
63
|
+
const PRE_SPLIT_WORKSPACE = `This directory holds a workspace from before farseer code; delete farseer-apps/<tenant>/{tree,access,definitions,detached,${LEGACY_CODEFIRST_STATE}} and run farseer code checkout <tenant> in the directory where the workspace should live`;
|
|
64
|
+
function stateFile(root) {
|
|
65
|
+
return path.join(root, ...STATE_FILE.split("/"));
|
|
66
|
+
}
|
|
67
|
+
function rejectSymlink(target) {
|
|
68
|
+
try {
|
|
69
|
+
if (fs.lstatSync(target).isSymbolicLink()) throw new Error(`Refusing symlink: ${target}`);
|
|
70
|
+
} catch (error) {
|
|
71
|
+
if (error.code !== "ENOENT") throw error;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function locateCodeWorkspace(cwd) {
|
|
75
|
+
let current = path.resolve(cwd);
|
|
76
|
+
for (; ; ) {
|
|
77
|
+
if (fs.existsSync(stateFile(current))) return current;
|
|
78
|
+
const parent = path.dirname(current);
|
|
79
|
+
if (parent === current) return void 0;
|
|
80
|
+
current = parent;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function locatePreSplitWorkspace(cwd) {
|
|
84
|
+
let current = path.resolve(cwd);
|
|
85
|
+
for (; ; ) {
|
|
86
|
+
if (fs.existsSync(path.join(current, LEGACY_CODEFIRST_STATE))) return true;
|
|
87
|
+
const parent = path.dirname(current);
|
|
88
|
+
if (parent === current) return false;
|
|
89
|
+
current = parent;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
function resolveCodeWorkspace(cwd) {
|
|
93
|
+
const root = locateCodeWorkspace(cwd);
|
|
94
|
+
if (!root) throw new Error(locatePreSplitWorkspace(cwd) ? PRE_SPLIT_WORKSPACE : NO_CODE_WORKSPACE);
|
|
95
|
+
rejectSymlink(root);
|
|
96
|
+
const inside = path.relative(root, path.resolve(cwd));
|
|
97
|
+
let current = root;
|
|
98
|
+
for (const part of inside ? inside.split(path.sep) : []) {
|
|
99
|
+
current = path.join(current, part);
|
|
100
|
+
rejectSymlink(current);
|
|
101
|
+
}
|
|
102
|
+
rejectSymlink(path.join(root, STATE_DIR));
|
|
103
|
+
rejectSymlink(stateFile(root));
|
|
104
|
+
return { root, state: (0, import_documents.parseState)(fs.readFileSync(stateFile(root), "utf8")) };
|
|
105
|
+
}
|
|
106
|
+
function assertPortableTenant(tenant) {
|
|
107
|
+
const control = [...tenant].some((character) => (character.codePointAt(0) ?? 0) < 32);
|
|
108
|
+
if (!tenant || tenant === "." || tenant === ".." || /[\\/]/.test(tenant) || control)
|
|
109
|
+
throw new Error(`Unsafe workspace directory name: ${JSON.stringify(tenant)}`);
|
|
110
|
+
if (tenant === LEGACY_SYNC_DIR)
|
|
111
|
+
throw new Error(`A code workspace cannot be named ${LEGACY_SYNC_DIR}; that name belongs to the legacy sync`);
|
|
112
|
+
}
|
|
113
|
+
function createCodeWorkspace(cwd, tenant, meta) {
|
|
114
|
+
assertPortableTenant(tenant);
|
|
115
|
+
const base = path.resolve(cwd);
|
|
116
|
+
if (base.split(path.sep).includes(LEGACY_SYNC_DIR))
|
|
117
|
+
throw new Error(
|
|
118
|
+
`Refusing to create a code workspace inside ${LEGACY_SYNC_DIR}/; run farseer code checkout outside the legacy sync directory`
|
|
119
|
+
);
|
|
120
|
+
const enclosing = locateCodeWorkspace(base);
|
|
121
|
+
if (enclosing)
|
|
122
|
+
throw new Error(`Already inside the code workspace ${enclosing}; check ${tenant} out outside that workspace`);
|
|
123
|
+
const root = path.join(base, tenant);
|
|
124
|
+
rejectSymlink(root);
|
|
125
|
+
if (fs.existsSync(root) && fs.readdirSync(root).length)
|
|
126
|
+
throw new Error(
|
|
127
|
+
`${root} already exists and is not empty; check out into an empty directory; or run farseer code pull inside it to finish an interrupted checkout`
|
|
128
|
+
);
|
|
129
|
+
fs.mkdirSync(path.join(root, STATE_DIR), { recursive: true });
|
|
130
|
+
fs.writeFileSync(stateFile(root), (0, import_documents.serializeState)((0, import_documents.emptyState)({ tenant, ...meta })), "utf8");
|
|
131
|
+
fs.writeFileSync(path.join(root, ".gitignore"), WORKSPACE_GITIGNORE, "utf8");
|
|
132
|
+
return root;
|
|
133
|
+
}
|
|
134
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
135
|
+
0 && (module.exports = {
|
|
136
|
+
LEGACY_CODEFIRST_STATE,
|
|
137
|
+
LEGACY_SYNC_DIR,
|
|
138
|
+
NO_CODE_WORKSPACE,
|
|
139
|
+
PRE_SPLIT_WORKSPACE,
|
|
140
|
+
STATE_DIR,
|
|
141
|
+
STATE_FILE,
|
|
142
|
+
WORKSPACE_GITIGNORE,
|
|
143
|
+
createCodeWorkspace,
|
|
144
|
+
locateCodeWorkspace,
|
|
145
|
+
resolveCodeWorkspace
|
|
146
|
+
});
|
|
147
|
+
//# sourceMappingURL=workspaceRoot.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/services/codefirst/workspaceRoot.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Where a code workspace lives and how a command finds the one it runs in.\n *\n * A checkout creates `<cwd>/<tenant>/` and records the target in `.fscode/state.json`. Every other\n * `farseer code` command walks up from the current directory to the nearest such file, the way git\n * finds `.git`, and reads the tenant, the organisation and the server from it. The legacy\n * `farseer-apps/` sync tree is a separate workspace: a code workspace is never created inside it.\n */\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport { emptyState, parseState, serializeState } from './documents';\nimport { State, WorkspaceIdentity } from './types';\n\nexport const STATE_DIR = '.fscode';\nexport const STATE_FILE = `${STATE_DIR}/state.json`;\n/** The legacy files/apps sync directory. It is not a code workspace and never contains one. */\nexport const LEGACY_SYNC_DIR = 'farseer-apps';\nexport const WORKSPACE_GITIGNORE =\n '# Farseer code workspace state: baseline, physical routes and apply receipts.\\n' +\n '# It is per-machine tool state, not authored work.\\n' +\n `${STATE_DIR}/\\n` +\n '# Operating-system and tool files, which the workspace ignores too.\\n' +\n '.DS_Store\\n' +\n 'Thumbs.db\\n' +\n 'desktop.ini\\n' +\n '__pycache__/\\n' +\n '._*\\n' +\n '# Temporaries a writer leaves when it is killed mid-write.\\n' +\n '*.tmp-????????-????-????-????-????????????\\n';\nexport const NO_CODE_WORKSPACE = 'Not inside a Farseer code workspace; run farseer code checkout <tenant> first';\n/** The state file of the pre-split workspace, which lived inside the legacy sync tree. */\nexport const LEGACY_CODEFIRST_STATE = '.farseer-codefirst.json';\nexport const PRE_SPLIT_WORKSPACE =\n 'This directory holds a workspace from before farseer code; delete ' +\n `farseer-apps/<tenant>/{tree,access,definitions,detached,${LEGACY_CODEFIRST_STATE}} and run farseer code ` +\n 'checkout <tenant> in the directory where the workspace should live';\n\nexport interface CodeWorkspace {\n root: string;\n state: State;\n}\n\nfunction stateFile(root: string): string {\n return path.join(root, ...STATE_FILE.split('/'));\n}\n\nfunction rejectSymlink(target: string): void {\n try {\n if (fs.lstatSync(target).isSymbolicLink()) throw new Error(`Refusing symlink: ${target}`);\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== 'ENOENT') throw error;\n }\n}\n\n/** The nearest ancestor that holds a state file, or undefined. Ancestors above it are not read. */\nexport function locateCodeWorkspace(cwd: string): string | undefined {\n let current = path.resolve(cwd);\n for (;;) {\n if (fs.existsSync(stateFile(current))) return current;\n const parent = path.dirname(current);\n if (parent === current) return undefined;\n current = parent;\n }\n}\n\n/**\n * A pre-split workspace at the current directory or above it. Its state file cannot be upgraded, so\n * the caller needs the delete-and-check-out instruction rather than the generic refusal.\n */\nfunction locatePreSplitWorkspace(cwd: string): boolean {\n let current = path.resolve(cwd);\n for (;;) {\n if (fs.existsSync(path.join(current, LEGACY_CODEFIRST_STATE))) return true;\n const parent = path.dirname(current);\n if (parent === current) return false;\n current = parent;\n }\n}\n\n/** The workspace the command runs in, with every path from its root down to the caller proven real. */\nexport function resolveCodeWorkspace(cwd: string): CodeWorkspace {\n const root = locateCodeWorkspace(cwd);\n if (!root) throw new Error(locatePreSplitWorkspace(cwd) ? PRE_SPLIT_WORKSPACE : NO_CODE_WORKSPACE);\n rejectSymlink(root);\n const inside = path.relative(root, path.resolve(cwd));\n let current = root;\n for (const part of inside ? inside.split(path.sep) : []) {\n current = path.join(current, part);\n rejectSymlink(current);\n }\n rejectSymlink(path.join(root, STATE_DIR));\n rejectSymlink(stateFile(root));\n return { root, state: parseState(fs.readFileSync(stateFile(root), 'utf8')) };\n}\n\nfunction assertPortableTenant(tenant: string): void {\n const control = [...tenant].some((character) => (character.codePointAt(0) ?? 0) < 0x20);\n if (!tenant || tenant === '.' || tenant === '..' || /[\\\\/]/.test(tenant) || control)\n throw new Error(`Unsafe workspace directory name: ${JSON.stringify(tenant)}`);\n if (tenant === LEGACY_SYNC_DIR)\n throw new Error(`A code workspace cannot be named ${LEGACY_SYNC_DIR}; that name belongs to the legacy sync`);\n}\n\n/** Create `<cwd>/<tenant>/` for a fresh checkout and return its root. It writes no model files. */\nexport function createCodeWorkspace(cwd: string, tenant: string, meta: Omit<WorkspaceIdentity, 'tenant'>): string {\n assertPortableTenant(tenant);\n const base = path.resolve(cwd);\n if (base.split(path.sep).includes(LEGACY_SYNC_DIR))\n throw new Error(\n `Refusing to create a code workspace inside ${LEGACY_SYNC_DIR}/; run farseer code checkout outside the legacy sync directory`,\n );\n const enclosing = locateCodeWorkspace(base);\n if (enclosing)\n throw new Error(`Already inside the code workspace ${enclosing}; check ${tenant} out outside that workspace`);\n const root = path.join(base, tenant);\n rejectSymlink(root);\n if (fs.existsSync(root) && fs.readdirSync(root).length)\n throw new Error(\n `${root} already exists and is not empty; check out into an empty directory; ` +\n 'or run farseer code pull inside it to finish an interrupted checkout',\n );\n fs.mkdirSync(path.join(root, STATE_DIR), { recursive: true });\n fs.writeFileSync(stateFile(root), serializeState(emptyState({ tenant, ...meta })), 'utf8');\n fs.writeFileSync(path.join(root, '.gitignore'), WORKSPACE_GITIGNORE, 'utf8');\n return root;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,SAAoB;AACpB,WAAsB;AACtB,uBAAuD;AAGhD,MAAM,YAAY;AAClB,MAAM,aAAa,GAAG,SAAS;AAE/B,MAAM,kBAAkB;AACxB,MAAM,sBACT;AAAA;AAAA,EAEG,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAST,MAAM,oBAAoB;AAE1B,MAAM,yBAAyB;AAC/B,MAAM,sBACT,6HAC2D,sBAAsB;AAQrF,SAAS,UAAU,MAAsB;AACrC,SAAO,KAAK,KAAK,MAAM,GAAG,WAAW,MAAM,GAAG,CAAC;AACnD;AAEA,SAAS,cAAc,QAAsB;AACzC,MAAI;AACA,QAAI,GAAG,UAAU,MAAM,EAAE,eAAe,EAAG,OAAM,IAAI,MAAM,qBAAqB,MAAM,EAAE;AAAA,EAC5F,SAAS,OAAO;AACZ,QAAK,MAAgC,SAAS,SAAU,OAAM;AAAA,EAClE;AACJ;AAGO,SAAS,oBAAoB,KAAiC;AACjE,MAAI,UAAU,KAAK,QAAQ,GAAG;AAC9B,aAAS;AACL,QAAI,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C,eAAe,wCAAwC;AACnH;AAGO,SAAS,oBAAoB,KAAa,QAAgB,MAAiD;AAC9G,uBAAqB,MAAM;AAC3B,QAAM,OAAO,KAAK,QAAQ,GAAG;AAC7B,MAAI,KAAK,MAAM,KAAK,GAAG,EAAE,SAAS,eAAe;AAC7C,UAAM,IAAI;AAAA,MACN,8CAA8C,eAAe;AAAA,IACjE;AACJ,QAAM,YAAY,oBAAoB,IAAI;AAC1C,MAAI;AACA,UAAM,IAAI,MAAM,qCAAqC,SAAS,WAAW,MAAM,6BAA6B;AAChH,QAAM,OAAO,KAAK,KAAK,MAAM,MAAM;AACnC,gBAAc,IAAI;AAClB,MAAI,GAAG,WAAW,IAAI,KAAK,GAAG,YAAY,IAAI,EAAE;AAC5C,UAAM,IAAI;AAAA,MACN,GAAG,IAAI;AAAA,IAEX;AACJ,KAAG,UAAU,KAAK,KAAK,MAAM,SAAS,GAAG,EAAE,WAAW,KAAK,CAAC;AAC5D,KAAG,cAAc,UAAU,IAAI,OAAG,qCAAe,6BAAW,EAAE,QAAQ,GAAG,KAAK,CAAC,CAAC,GAAG,MAAM;AACzF,KAAG,cAAc,KAAK,KAAK,MAAM,YAAY,GAAG,qBAAqB,MAAM;AAC3E,SAAO;AACX;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/dist/utils/logger.js
CHANGED
|
@@ -28,12 +28,17 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
var logger_exports = {};
|
|
30
30
|
__export(logger_exports, {
|
|
31
|
-
logger: () => logger
|
|
31
|
+
logger: () => logger,
|
|
32
|
+
reserveStdout: () => reserveStdout
|
|
32
33
|
});
|
|
33
34
|
module.exports = __toCommonJS(logger_exports);
|
|
34
35
|
var import_chalk = __toESM(require("chalk"));
|
|
36
|
+
let stdoutReserved = false;
|
|
37
|
+
function reserveStdout() {
|
|
38
|
+
stdoutReserved = true;
|
|
39
|
+
}
|
|
35
40
|
function log(...args) {
|
|
36
|
-
if (process.env.FARSEER_MCP === "1") {
|
|
41
|
+
if (stdoutReserved || process.env.FARSEER_MCP === "1") {
|
|
37
42
|
console.error(...args);
|
|
38
43
|
} else {
|
|
39
44
|
console.log(...args);
|
|
@@ -79,6 +84,7 @@ const logger = {
|
|
|
79
84
|
};
|
|
80
85
|
// Annotate the CommonJS export names for ESM import in node:
|
|
81
86
|
0 && (module.exports = {
|
|
82
|
-
logger
|
|
87
|
+
logger,
|
|
88
|
+
reserveStdout
|
|
83
89
|
});
|
|
84
90
|
//# sourceMappingURL=logger.js.map
|
package/dist/utils/logger.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/utils/logger.ts"],
|
|
4
|
-
"sourcesContent": ["import chalk from 'chalk';\n\nfunction log(...args: unknown[]) {\n if (process.env.FARSEER_MCP === '1') {\n console.error(...args);\n } else {\n console.log(...args);\n }\n}\n\nexport const logger = {\n info: (message: string) => {\n log(chalk.blue('\u2139'), message);\n },\n\n success: (message: string) => {\n log(chalk.green('\u2713'), message);\n },\n\n warning: (message: string) => {\n log(chalk.yellow('\u26A0'), message);\n },\n\n error: (message: string) => {\n log(chalk.red('\u2717'), message);\n },\n\n log: (message: string) => {\n log(message);\n },\n\n dim: (message: string) => {\n log(chalk.dim(message));\n },\n\n header: (message: string) => {\n log();\n log(chalk.bold.underline(message));\n log();\n },\n\n list: (items: string[], indent: number = 2) => {\n const prefix = ' '.repeat(indent);\n items.forEach((item) => {\n log(`${prefix}${item}`);\n });\n },\n\n table: (rows: { label: string; value: string }[]) => {\n const maxLabelLength = Math.max(...rows.map((r) => r.label.length));\n rows.forEach((row) => {\n const paddedLabel = row.label.padEnd(maxLabelLength);\n log(` ${chalk.dim(paddedLabel)} ${row.value}`);\n });\n },\n};\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkB;AAElB,SAAS,OAAO,MAAiB;AAC7B,MAAI,QAAQ,IAAI,gBAAgB,KAAK;
|
|
4
|
+
"sourcesContent": ["import chalk from 'chalk';\n\nlet stdoutReserved = false;\n\n/** Sends every log line to stderr, for a command whose stdout carries machine-readable output. */\nexport function reserveStdout(): void {\n stdoutReserved = true;\n}\n\nfunction log(...args: unknown[]) {\n if (stdoutReserved || process.env.FARSEER_MCP === '1') {\n console.error(...args);\n } else {\n console.log(...args);\n }\n}\n\nexport const logger = {\n info: (message: string) => {\n log(chalk.blue('\u2139'), message);\n },\n\n success: (message: string) => {\n log(chalk.green('\u2713'), message);\n },\n\n warning: (message: string) => {\n log(chalk.yellow('\u26A0'), message);\n },\n\n error: (message: string) => {\n log(chalk.red('\u2717'), message);\n },\n\n log: (message: string) => {\n log(message);\n },\n\n dim: (message: string) => {\n log(chalk.dim(message));\n },\n\n header: (message: string) => {\n log();\n log(chalk.bold.underline(message));\n log();\n },\n\n list: (items: string[], indent: number = 2) => {\n const prefix = ' '.repeat(indent);\n items.forEach((item) => {\n log(`${prefix}${item}`);\n });\n },\n\n table: (rows: { label: string; value: string }[]) => {\n const maxLabelLength = Math.max(...rows.map((r) => r.label.length));\n rows.forEach((row) => {\n const paddedLabel = row.label.padEnd(maxLabelLength);\n log(` ${chalk.dim(paddedLabel)} ${row.value}`);\n });\n },\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkB;AAElB,IAAI,iBAAiB;AAGd,SAAS,gBAAsB;AAClC,mBAAiB;AACrB;AAEA,SAAS,OAAO,MAAiB;AAC7B,MAAI,kBAAkB,QAAQ,IAAI,gBAAgB,KAAK;AACnD,YAAQ,MAAM,GAAG,IAAI;AAAA,EACzB,OAAO;AACH,YAAQ,IAAI,GAAG,IAAI;AAAA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 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "farseer-cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.17.0",
|
|
4
4
|
"description": "CLI tool for syncing Farseer App scripts between local folder and Farseer instances",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
"build": "node build.js",
|
|
18
18
|
"docs:check": "node scripts/check-pipeline-docs.js",
|
|
19
19
|
"typecheck": "tsc --noEmit",
|
|
20
|
+
"typecheck:codefirst-tests": "tsc -p tsconfig.codefirst-tests.json",
|
|
20
21
|
"build:tsc": "tsc",
|
|
21
22
|
"lint": "eslint src --ext .ts",
|
|
22
23
|
"format:check": "prettier --check src",
|
|
@@ -54,7 +55,7 @@
|
|
|
54
55
|
"chalk": "^4.1.2",
|
|
55
56
|
"commander": "^11.1.0",
|
|
56
57
|
"diff": "^5.1.0",
|
|
57
|
-
"farseer-client": "npm:@farseerdev/farseer-client@1.
|
|
58
|
+
"farseer-client": "npm:@farseerdev/farseer-client@1.22.0",
|
|
58
59
|
"inquirer": "^8.2.6",
|
|
59
60
|
"js-yaml": "4.1.1",
|
|
60
61
|
"zod": "^3.25.0"
|