@almadar/workspace 0.4.1 → 0.5.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/dist/__tests__/open-create-false.test.d.ts +1 -0
- package/dist/index.js +15 -2
- package/dist/index.js.map +1 -1
- package/dist/open-workspace.d.ts +3 -0
- package/dist/types.d.ts +10 -0
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.js
CHANGED
|
@@ -2183,13 +2183,18 @@ function openWorkspaceCacheKey(opts) {
|
|
|
2183
2183
|
return `${backendTag}:${opts.userId}:${opts.appId}`;
|
|
2184
2184
|
}
|
|
2185
2185
|
async function openWorkspace(opts) {
|
|
2186
|
+
if (opts.create === false) {
|
|
2187
|
+
return openWorkspaceInternal(opts);
|
|
2188
|
+
}
|
|
2186
2189
|
const key = openWorkspaceCacheKey(opts);
|
|
2187
2190
|
if (key !== null) {
|
|
2188
2191
|
const cached = openWorkspaceInFlight.get(key);
|
|
2189
2192
|
if (cached) return cached;
|
|
2190
2193
|
const pending = (async () => {
|
|
2191
2194
|
try {
|
|
2192
|
-
|
|
2195
|
+
const ws = await openWorkspaceInternal(opts);
|
|
2196
|
+
if (ws === null) throw new Error("openWorkspace: null resolution without create:false");
|
|
2197
|
+
return ws;
|
|
2193
2198
|
} catch (err) {
|
|
2194
2199
|
openWorkspaceInFlight.delete(key);
|
|
2195
2200
|
throw err;
|
|
@@ -2204,6 +2209,7 @@ async function openWorkspaceInternal(opts) {
|
|
|
2204
2209
|
const backend = opts.backend === "memory" ? new MemoryBackend() : new LocalBackend();
|
|
2205
2210
|
const sinks = new SinkManager();
|
|
2206
2211
|
const resolved = await resolveLifecycle(backend, opts);
|
|
2212
|
+
if (resolved === null) return null;
|
|
2207
2213
|
const bare = opts.bare === true && opts.adopt !== void 0;
|
|
2208
2214
|
if (!bare) {
|
|
2209
2215
|
await ensureSkeleton(backend, resolved.workDir);
|
|
@@ -2246,6 +2252,7 @@ async function openWorkspaceInternal(opts) {
|
|
|
2246
2252
|
return service;
|
|
2247
2253
|
}
|
|
2248
2254
|
async function resolveLifecycle(backend, opts) {
|
|
2255
|
+
const noCreate = opts.create === false;
|
|
2249
2256
|
if (opts.adopt) {
|
|
2250
2257
|
const workDir2 = path2.resolve(opts.adopt);
|
|
2251
2258
|
const marker = readAppMarker(backend, workDir2);
|
|
@@ -2263,14 +2270,20 @@ async function resolveLifecycle(backend, opts) {
|
|
|
2263
2270
|
if (opts.appId && opts.restore) {
|
|
2264
2271
|
const workDir2 = mintSessionDir(opts.root, opts.userId);
|
|
2265
2272
|
await backend.mkdir(workDir2, { recursive: true });
|
|
2266
|
-
await restoreWorkspace(backend, workDir2, opts.restore);
|
|
2273
|
+
const result = await restoreWorkspace(backend, workDir2, opts.restore);
|
|
2274
|
+
if (noCreate && result.filesRestored === 0) {
|
|
2275
|
+
await backend.rm(workDir2, { recursive: true });
|
|
2276
|
+
return null;
|
|
2277
|
+
}
|
|
2267
2278
|
return { workDir: workDir2, appId: opts.appId };
|
|
2268
2279
|
}
|
|
2269
2280
|
if (opts.appId && opts.github && opts.github.repoUrl) {
|
|
2281
|
+
if (noCreate) return null;
|
|
2270
2282
|
const workDir2 = mintSessionDir(opts.root, opts.userId);
|
|
2271
2283
|
await backend.mkdir(workDir2, { recursive: true });
|
|
2272
2284
|
return { workDir: workDir2, appId: opts.appId };
|
|
2273
2285
|
}
|
|
2286
|
+
if (noCreate) return null;
|
|
2274
2287
|
const workDir = mintSessionDir(opts.root, opts.userId);
|
|
2275
2288
|
return { workDir, appId: opts.appId };
|
|
2276
2289
|
}
|