@joripspace/cli 0.5.0 → 0.5.2

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.
@@ -1,245 +1,245 @@
1
- const fs = require('node:fs');
2
- const path = require('node:path');
3
- const { safeProjectRelativePath } = require('./project-paths');
4
-
5
- const INLINE_FILE_LIMIT = 16_000;
6
- const INLINE_TOTAL_LIMIT = 64_000;
7
- const IGNORED_DIRS = new Set([
8
- '.git',
9
- '.joripspace',
10
- '.wrangler',
11
- '.cache',
12
- '.agents',
13
- '.claude',
14
- '.codex',
15
- '.cursor',
16
- '.gemini',
17
- '.opencode',
18
- 'coverage',
19
- 'node_modules',
20
- 'tmp',
21
- 'temp',
22
- ]);
23
- const PROTECTED_FILE_NAMES = new Set(['agents.md', 'claude.md']);
24
- const PROTECTED_SOURCE_DIRS = new Set([
25
- '.agents',
26
- '.claude',
27
- '.codex',
28
- '.cursor',
29
- '.gemini',
30
- '.git',
31
- '.joripspace',
32
- '.opencode',
33
- '.wrangler',
34
- 'node_modules',
35
- ]);
36
-
37
- function buildDeployPayload(flags) {
38
- const source = stringFlag(flags, 'source');
39
- if (source) {
40
- const fileName = safeProjectRelativePath(stringFlag(flags, 'entrypoint') || path.basename(source));
41
- assertDeployableProjectPath(fileName);
42
- const resolved = resolveDeploySourceFile(source, stringFlag(flags, 'cwd'));
43
- return buildInlineDeployPayload(fileName, new Map([[fileName, resolved]]));
44
- }
45
- const directory = stringFlag(flags, 'dir');
46
- if (directory) {
47
- const rawEntrypoint = stringFlag(flags, 'entrypoint');
48
- if (!rawEntrypoint) throw new Error('deploy --dir requires --entrypoint');
49
- const entrypoint = safeProjectRelativePath(rawEntrypoint);
50
- const resolvedDirectory = resolveDeploySourceDirectory(directory, stringFlag(flags, 'cwd'));
51
- const files = new Map();
52
- for (const file of walkFiles(resolvedDirectory.path)) {
53
- const relative = safeProjectRelativePath(toPosix(path.relative(resolvedDirectory.path, file.path)));
54
- files.set(relative, file);
55
- }
56
- if (!files.has(entrypoint)) {
57
- throw new Error(`entrypoint not found in --dir: ${entrypoint}`);
58
- }
59
- return buildInlineDeployPayload(entrypoint, files);
60
- }
61
- const mappings = arrayFlag(flags, 'file');
62
- if (mappings.length) {
63
- const rawEntrypoint = stringFlag(flags, 'entrypoint');
64
- if (!rawEntrypoint) throw new Error('deploy --file requires --entrypoint');
65
- const entrypoint = safeProjectRelativePath(rawEntrypoint);
66
- const files = new Map();
67
- for (const mapping of mappings) {
68
- const [name, filePath] = splitFileMapping(mapping);
69
- const relative = safeProjectRelativePath(name);
70
- assertDeployableProjectPath(relative);
71
- files.set(relative, resolveDeploySourceFile(filePath, stringFlag(flags, 'cwd')));
72
- }
73
- if (!files.has(entrypoint)) {
74
- throw new Error(`entrypoint not found in --file mappings: ${entrypoint}`);
75
- }
76
- return buildInlineDeployPayload(entrypoint, files);
77
- }
78
- throw new Error('deploy requires --source, --dir, or --file');
79
- }
80
-
81
- function buildInlineDeployPayload(entrypoint, sources) {
82
- let expectedTotal = 0;
83
- for (const [fileName, source] of sources) {
84
- if (source.size > INLINE_FILE_LIMIT) {
85
- throw archiveRequired(`deploy source exceeds the inline file limit (${fileName})`);
86
- }
87
- expectedTotal += source.size;
88
- }
89
- if (expectedTotal > INLINE_TOTAL_LIMIT) {
90
- throw archiveRequired('deploy source exceeds the inline total limit');
91
- }
92
-
93
- const buffered = [];
94
- let actualTotal = 0;
95
- for (const [fileName, source] of sources) {
96
- const bytes = fs.readFileSync(source.path);
97
- if (bytes.byteLength > INLINE_FILE_LIMIT) {
98
- throw archiveRequired(`deploy source exceeds the inline file limit (${fileName})`);
99
- }
100
- actualTotal += bytes.byteLength;
101
- if (actualTotal > INLINE_TOTAL_LIMIT) {
102
- throw archiveRequired('deploy source exceeds the inline total limit');
103
- }
104
- if (bytes.includes(0)) {
105
- throw archiveRequired(`deploy source contains binary data (${fileName})`);
106
- }
107
- buffered.push([fileName, bytes]);
108
- }
109
-
110
- const files = {};
111
- for (const [fileName, bytes] of buffered) {
112
- const text = bytes.toString('utf8');
113
- if (!Buffer.from(text, 'utf8').equals(bytes)) {
114
- throw archiveRequired(`deploy source contains binary data (${fileName})`);
115
- }
116
- files[fileName] = text;
117
- }
118
- return { entrypoint, files };
119
- }
120
-
121
- function walkFiles(root, base = path.resolve(root)) {
122
- const files = [];
123
- for (const entry of fs.readdirSync(root, { withFileTypes: true })) {
124
- const fullPath = path.join(root, entry.name);
125
- const relative = toPosix(path.relative(base, fullPath));
126
- if (entry.isDirectory() && IGNORED_DIRS.has(entry.name.toLowerCase())) continue;
127
- if (isProtectedProjectPath(relative)) continue;
128
- if (entry.isDirectory()) files.push(...walkFiles(fullPath, base));
129
- else if (entry.isFile()) files.push(resolveDeploySourceFile(fullPath, base));
130
- }
131
- return files;
132
- }
133
-
134
- function assertDeployableProjectPath(value) {
135
- const relative = safeProjectRelativePath(value);
136
- if (isProtectedProjectPath(relative)) throw new Error(`protected file cannot be deployed: ${relative}`);
137
- }
138
-
139
- function assertDeployableSourceFilePath(value, workspaceDir = '') {
140
- resolveDeploySourceFile(value, workspaceDir);
141
- }
142
-
143
- function resolveDeploySourceFile(value, workspaceDir = '') {
144
- return resolveDeploySource(value, workspaceDir, 'file');
145
- }
146
-
147
- function resolveDeploySourceDirectory(value, workspaceDir = '') {
148
- return resolveDeploySource(value, workspaceDir, 'directory');
149
- }
150
-
151
- function resolveDeploySource(value, workspaceDir, expectedType) {
152
- const source = path.resolve(value);
153
- const stat = fs.lstatSync(source);
154
- if (stat.isSymbolicLink()) {
155
- throw new Error(`protected deploy source cannot be a symbolic link or junction: ${value}`);
156
- }
157
- if (expectedType === 'file' ? !stat.isFile() : !stat.isDirectory()) {
158
- throw new Error(`deploy source must be a regular ${expectedType}: ${value}`);
159
- }
160
-
161
- const realSource = fs.realpathSync.native(source);
162
- const realStat = fs.lstatSync(realSource);
163
- if (realStat.isSymbolicLink() || (expectedType === 'file' ? !realStat.isFile() : !realStat.isDirectory())) {
164
- throw new Error(`deploy source must be a regular ${expectedType}: ${value}`);
165
- }
166
-
167
- if (workspaceDir) {
168
- const workspace = path.resolve(workspaceDir);
169
- const realWorkspace = fs.realpathSync.native(workspace);
170
- if (isContainedPath(workspace, source) && !isContainedPath(realWorkspace, realSource)) {
171
- throw new Error(`deploy source escapes the workspace through a symbolic link or junction: ${value}`);
172
- }
173
- }
174
-
175
- if (isProtectedSourcePath(source) || isProtectedSourcePath(realSource)) {
176
- throw new Error(`protected file cannot be used as deploy source: ${value}`);
177
- }
178
- return { path: realSource, size: realStat.size, type: expectedType };
179
- }
180
-
181
- function isProtectedSourcePath(value) {
182
- const resolved = path.resolve(value);
183
- const baseName = path.basename(resolved);
184
- const parts = resolved.replace(/\\/g, '/').toLowerCase().split('/');
185
- return isProtectedProjectPath(baseName) || parts.some((part) => PROTECTED_SOURCE_DIRS.has(part));
186
- }
187
-
188
- function isContainedPath(root, target) {
189
- const relative = path.relative(root, target);
190
- return (
191
- relative === '' ||
192
- (relative !== '..' && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative))
193
- );
194
- }
195
-
196
- function isProtectedProjectPath(value) {
197
- const normalized = String(value || '')
198
- .replace(/\\/g, '/')
199
- .replace(/^\.\//, '')
200
- .toLowerCase();
201
- const parts = normalized.split('/');
202
- const baseName = parts.at(-1) || '';
203
- return (
204
- parts.some((part) => IGNORED_DIRS.has(part)) ||
205
- baseName === '.env.joripspace' ||
206
- PROTECTED_FILE_NAMES.has(baseName) ||
207
- baseName.endsWith('.log')
208
- );
209
- }
210
-
211
- function archiveRequired(message) {
212
- const error = new Error(message);
213
- error.code = 'archive_required';
214
- return error;
215
- }
216
-
217
- function stringFlag(flags, name) {
218
- const value = flags[name];
219
- return Array.isArray(value) ? String(value.at(-1)) : typeof value === 'string' ? value : '';
220
- }
221
-
222
- function arrayFlag(flags, name) {
223
- const value = flags[name];
224
- if (value === undefined) return [];
225
- return Array.isArray(value) ? value.map(String) : [String(value)];
226
- }
227
-
228
- function splitFileMapping(value) {
229
- const separator = value.indexOf('=');
230
- if (separator <= 0 || separator === value.length - 1) throw new Error('--file must use name=path');
231
- return [value.slice(0, separator), value.slice(separator + 1)];
232
- }
233
-
234
- function toPosix(value) {
235
- return value.split(path.sep).join('/');
236
- }
237
-
238
- module.exports = {
239
- assertDeployableProjectPath,
240
- assertDeployableSourceFilePath,
241
- buildDeployPayload,
242
- isProtectedProjectPath,
243
- resolveDeploySourceDirectory,
244
- resolveDeploySourceFile,
245
- };
1
+ const fs = require('node:fs');
2
+ const path = require('node:path');
3
+ const { safeProjectRelativePath } = require('./project-paths');
4
+
5
+ const INLINE_FILE_LIMIT = 16_000;
6
+ const INLINE_TOTAL_LIMIT = 64_000;
7
+ const IGNORED_DIRS = new Set([
8
+ '.git',
9
+ '.joripspace',
10
+ '.wrangler',
11
+ '.cache',
12
+ '.agents',
13
+ '.claude',
14
+ '.codex',
15
+ '.cursor',
16
+ '.gemini',
17
+ '.opencode',
18
+ 'coverage',
19
+ 'node_modules',
20
+ 'tmp',
21
+ 'temp',
22
+ ]);
23
+ const PROTECTED_FILE_NAMES = new Set(['agents.md', 'claude.md']);
24
+ const PROTECTED_SOURCE_DIRS = new Set([
25
+ '.agents',
26
+ '.claude',
27
+ '.codex',
28
+ '.cursor',
29
+ '.gemini',
30
+ '.git',
31
+ '.joripspace',
32
+ '.opencode',
33
+ '.wrangler',
34
+ 'node_modules',
35
+ ]);
36
+
37
+ function buildDeployPayload(flags) {
38
+ const source = stringFlag(flags, 'source');
39
+ if (source) {
40
+ const fileName = safeProjectRelativePath(stringFlag(flags, 'entrypoint') || path.basename(source));
41
+ assertDeployableProjectPath(fileName);
42
+ const resolved = resolveDeploySourceFile(source, stringFlag(flags, 'cwd'));
43
+ return buildInlineDeployPayload(fileName, new Map([[fileName, resolved]]));
44
+ }
45
+ const directory = stringFlag(flags, 'dir');
46
+ if (directory) {
47
+ const rawEntrypoint = stringFlag(flags, 'entrypoint');
48
+ if (!rawEntrypoint) throw new Error('deploy --dir requires --entrypoint');
49
+ const entrypoint = safeProjectRelativePath(rawEntrypoint);
50
+ const resolvedDirectory = resolveDeploySourceDirectory(directory, stringFlag(flags, 'cwd'));
51
+ const files = new Map();
52
+ for (const file of walkFiles(resolvedDirectory.path)) {
53
+ const relative = safeProjectRelativePath(toPosix(path.relative(resolvedDirectory.path, file.path)));
54
+ files.set(relative, file);
55
+ }
56
+ if (!files.has(entrypoint)) {
57
+ throw new Error(`entrypoint not found in --dir: ${entrypoint}`);
58
+ }
59
+ return buildInlineDeployPayload(entrypoint, files);
60
+ }
61
+ const mappings = arrayFlag(flags, 'file');
62
+ if (mappings.length) {
63
+ const rawEntrypoint = stringFlag(flags, 'entrypoint');
64
+ if (!rawEntrypoint) throw new Error('deploy --file requires --entrypoint');
65
+ const entrypoint = safeProjectRelativePath(rawEntrypoint);
66
+ const files = new Map();
67
+ for (const mapping of mappings) {
68
+ const [name, filePath] = splitFileMapping(mapping);
69
+ const relative = safeProjectRelativePath(name);
70
+ assertDeployableProjectPath(relative);
71
+ files.set(relative, resolveDeploySourceFile(filePath, stringFlag(flags, 'cwd')));
72
+ }
73
+ if (!files.has(entrypoint)) {
74
+ throw new Error(`entrypoint not found in --file mappings: ${entrypoint}`);
75
+ }
76
+ return buildInlineDeployPayload(entrypoint, files);
77
+ }
78
+ throw new Error('deploy requires --source, --dir, or --file');
79
+ }
80
+
81
+ function buildInlineDeployPayload(entrypoint, sources) {
82
+ let expectedTotal = 0;
83
+ for (const [fileName, source] of sources) {
84
+ if (source.size > INLINE_FILE_LIMIT) {
85
+ throw archiveRequired(`deploy source exceeds the inline file limit (${fileName})`);
86
+ }
87
+ expectedTotal += source.size;
88
+ }
89
+ if (expectedTotal > INLINE_TOTAL_LIMIT) {
90
+ throw archiveRequired('deploy source exceeds the inline total limit');
91
+ }
92
+
93
+ const buffered = [];
94
+ let actualTotal = 0;
95
+ for (const [fileName, source] of sources) {
96
+ const bytes = fs.readFileSync(source.path);
97
+ if (bytes.byteLength > INLINE_FILE_LIMIT) {
98
+ throw archiveRequired(`deploy source exceeds the inline file limit (${fileName})`);
99
+ }
100
+ actualTotal += bytes.byteLength;
101
+ if (actualTotal > INLINE_TOTAL_LIMIT) {
102
+ throw archiveRequired('deploy source exceeds the inline total limit');
103
+ }
104
+ if (bytes.includes(0)) {
105
+ throw archiveRequired(`deploy source contains binary data (${fileName})`);
106
+ }
107
+ buffered.push([fileName, bytes]);
108
+ }
109
+
110
+ const files = {};
111
+ for (const [fileName, bytes] of buffered) {
112
+ const text = bytes.toString('utf8');
113
+ if (!Buffer.from(text, 'utf8').equals(bytes)) {
114
+ throw archiveRequired(`deploy source contains binary data (${fileName})`);
115
+ }
116
+ files[fileName] = text;
117
+ }
118
+ return { entrypoint, files };
119
+ }
120
+
121
+ function walkFiles(root, base = path.resolve(root)) {
122
+ const files = [];
123
+ for (const entry of fs.readdirSync(root, { withFileTypes: true })) {
124
+ const fullPath = path.join(root, entry.name);
125
+ const relative = toPosix(path.relative(base, fullPath));
126
+ if (entry.isDirectory() && IGNORED_DIRS.has(entry.name.toLowerCase())) continue;
127
+ if (isProtectedProjectPath(relative)) continue;
128
+ if (entry.isDirectory()) files.push(...walkFiles(fullPath, base));
129
+ else if (entry.isFile()) files.push(resolveDeploySourceFile(fullPath, base));
130
+ }
131
+ return files;
132
+ }
133
+
134
+ function assertDeployableProjectPath(value) {
135
+ const relative = safeProjectRelativePath(value);
136
+ if (isProtectedProjectPath(relative)) throw new Error(`protected file cannot be deployed: ${relative}`);
137
+ }
138
+
139
+ function assertDeployableSourceFilePath(value, workspaceDir = '') {
140
+ resolveDeploySourceFile(value, workspaceDir);
141
+ }
142
+
143
+ function resolveDeploySourceFile(value, workspaceDir = '') {
144
+ return resolveDeploySource(value, workspaceDir, 'file');
145
+ }
146
+
147
+ function resolveDeploySourceDirectory(value, workspaceDir = '') {
148
+ return resolveDeploySource(value, workspaceDir, 'directory');
149
+ }
150
+
151
+ function resolveDeploySource(value, workspaceDir, expectedType) {
152
+ const source = path.resolve(value);
153
+ const stat = fs.lstatSync(source);
154
+ if (stat.isSymbolicLink()) {
155
+ throw new Error(`protected deploy source cannot be a symbolic link or junction: ${value}`);
156
+ }
157
+ if (expectedType === 'file' ? !stat.isFile() : !stat.isDirectory()) {
158
+ throw new Error(`deploy source must be a regular ${expectedType}: ${value}`);
159
+ }
160
+
161
+ const realSource = fs.realpathSync.native(source);
162
+ const realStat = fs.lstatSync(realSource);
163
+ if (realStat.isSymbolicLink() || (expectedType === 'file' ? !realStat.isFile() : !realStat.isDirectory())) {
164
+ throw new Error(`deploy source must be a regular ${expectedType}: ${value}`);
165
+ }
166
+
167
+ if (workspaceDir) {
168
+ const workspace = path.resolve(workspaceDir);
169
+ const realWorkspace = fs.realpathSync.native(workspace);
170
+ if (isContainedPath(workspace, source) && !isContainedPath(realWorkspace, realSource)) {
171
+ throw new Error(`deploy source escapes the workspace through a symbolic link or junction: ${value}`);
172
+ }
173
+ }
174
+
175
+ if (isProtectedSourcePath(source) || isProtectedSourcePath(realSource)) {
176
+ throw new Error(`protected file cannot be used as deploy source: ${value}`);
177
+ }
178
+ return { path: realSource, size: realStat.size, type: expectedType };
179
+ }
180
+
181
+ function isProtectedSourcePath(value) {
182
+ const resolved = path.resolve(value);
183
+ const baseName = path.basename(resolved);
184
+ const parts = resolved.replace(/\\/g, '/').toLowerCase().split('/');
185
+ return isProtectedProjectPath(baseName) || parts.some((part) => PROTECTED_SOURCE_DIRS.has(part));
186
+ }
187
+
188
+ function isContainedPath(root, target) {
189
+ const relative = path.relative(root, target);
190
+ return (
191
+ relative === '' ||
192
+ (relative !== '..' && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative))
193
+ );
194
+ }
195
+
196
+ function isProtectedProjectPath(value) {
197
+ const normalized = String(value || '')
198
+ .replace(/\\/g, '/')
199
+ .replace(/^\.\//, '')
200
+ .toLowerCase();
201
+ const parts = normalized.split('/');
202
+ const baseName = parts.at(-1) || '';
203
+ return (
204
+ parts.some((part) => IGNORED_DIRS.has(part)) ||
205
+ baseName === '.env.joripspace' ||
206
+ PROTECTED_FILE_NAMES.has(baseName) ||
207
+ baseName.endsWith('.log')
208
+ );
209
+ }
210
+
211
+ function archiveRequired(message) {
212
+ const error = new Error(message);
213
+ error.code = 'archive_required';
214
+ return error;
215
+ }
216
+
217
+ function stringFlag(flags, name) {
218
+ const value = flags[name];
219
+ return Array.isArray(value) ? String(value.at(-1)) : typeof value === 'string' ? value : '';
220
+ }
221
+
222
+ function arrayFlag(flags, name) {
223
+ const value = flags[name];
224
+ if (value === undefined) return [];
225
+ return Array.isArray(value) ? value.map(String) : [String(value)];
226
+ }
227
+
228
+ function splitFileMapping(value) {
229
+ const separator = value.indexOf('=');
230
+ if (separator <= 0 || separator === value.length - 1) throw new Error('--file must use name=path');
231
+ return [value.slice(0, separator), value.slice(separator + 1)];
232
+ }
233
+
234
+ function toPosix(value) {
235
+ return value.split(path.sep).join('/');
236
+ }
237
+
238
+ module.exports = {
239
+ assertDeployableProjectPath,
240
+ assertDeployableSourceFilePath,
241
+ buildDeployPayload,
242
+ isProtectedProjectPath,
243
+ resolveDeploySourceDirectory,
244
+ resolveDeploySourceFile,
245
+ };
@@ -1,14 +1,14 @@
1
- 'use strict';
2
-
3
- function formatDeploymentFailure(message, details) {
4
- if (!details || typeof details !== 'object' || !details.deployment_id) return message;
5
- const lines = [message, `Deployment: ${details.deployment_id}`];
6
- if (details.error_stage) lines.push(`Stage: ${details.error_stage}`);
7
- if (details.error_code) lines.push(`Error code: ${details.error_code}`);
8
- if (details.error_details && details.error_details !== message) {
9
- lines.push(`Details: ${details.error_details}`);
10
- }
11
- return lines.join('\n');
12
- }
13
-
14
- module.exports = { formatDeploymentFailure };
1
+ 'use strict';
2
+
3
+ function formatDeploymentFailure(message, details) {
4
+ if (!details || typeof details !== 'object' || !details.deployment_id) return message;
5
+ const lines = [message, `Deployment: ${details.deployment_id}`];
6
+ if (details.error_stage) lines.push(`Stage: ${details.error_stage}`);
7
+ if (details.error_code) lines.push(`Error code: ${details.error_code}`);
8
+ if (details.error_details && details.error_details !== message) {
9
+ lines.push(`Details: ${details.error_details}`);
10
+ }
11
+ return lines.join('\n');
12
+ }
13
+
14
+ module.exports = { formatDeploymentFailure };