jazz-run 0.8.7 → 0.8.11
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/CHANGELOG.md +17 -0
- package/dist/accountCreate.js +88 -0
- package/dist/accountCreate.js.map +1 -0
- package/dist/index.js +3 -52
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/src/accountCreate.ts +125 -0
- package/src/index.ts +3 -83
- package/.turbo/turbo-build.log +0 -8
- package/.turbo/turbo-lint.log +0 -4
- package/.turbo/turbo-test.log +0 -13
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,22 @@
|
|
1
1
|
# jazz-run
|
2
2
|
|
3
|
+
## 0.8.11
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- 1ed4ab5: Improve the jazz-run create command by subscribing to the peer sync state
|
8
|
+
- Updated dependencies [1ed4ab5]
|
9
|
+
- cojson@0.8.11
|
10
|
+
- cojson-storage-sqlite@0.8.11
|
11
|
+
- cojson-transport-ws@0.8.11
|
12
|
+
- jazz-tools@0.8.11
|
13
|
+
|
14
|
+
## 0.8.10
|
15
|
+
|
16
|
+
### Patch Changes
|
17
|
+
|
18
|
+
- a818462: Temporary fix for account create
|
19
|
+
|
3
20
|
## 0.8.7
|
4
21
|
|
5
22
|
### Patch Changes
|
@@ -0,0 +1,88 @@
|
|
1
|
+
import { Command, Options } from "@effect/cli";
|
2
|
+
import { Console, Effect } from "effect";
|
3
|
+
import { createWebSocketPeer } from "cojson-transport-ws";
|
4
|
+
import { WebSocket } from "ws";
|
5
|
+
import { Account, WasmCrypto, createJazzContext, isControlledAccount, } from "jazz-tools";
|
6
|
+
import { fixedCredentialsAuth, randomSessionProvider } from "jazz-tools";
|
7
|
+
const name = Options.text("name").pipe(Options.withAlias("n"));
|
8
|
+
const peer = Options.text("peer")
|
9
|
+
.pipe(Options.withAlias("p"))
|
10
|
+
.pipe(Options.withDefault("wss://cloud.jazz.tools"));
|
11
|
+
const accountCreate = Command.make("create", { name, peer }, ({ name, peer: peerAddr }) => {
|
12
|
+
return Effect.gen(function* () {
|
13
|
+
const crypto = yield* Effect.promise(() => WasmCrypto.create());
|
14
|
+
const peer = createWebSocketPeer({
|
15
|
+
id: "upstream",
|
16
|
+
websocket: new WebSocket(peerAddr),
|
17
|
+
role: "server",
|
18
|
+
});
|
19
|
+
const account = yield* Effect.promise(async () => Account.create({
|
20
|
+
creationProps: { name },
|
21
|
+
peersToLoadFrom: [peer],
|
22
|
+
crypto,
|
23
|
+
}));
|
24
|
+
if (!isControlledAccount(account)) {
|
25
|
+
throw new Error("account is not a controlled account");
|
26
|
+
}
|
27
|
+
const accountCoValue = account._raw.core;
|
28
|
+
const accountProfileCoValue = account.profile._raw.core;
|
29
|
+
const syncManager = account._raw.core.node.syncManager;
|
30
|
+
yield* Effect.promise(() => syncManager.syncCoValue(accountCoValue));
|
31
|
+
yield* Effect.promise(() => syncManager.syncCoValue(accountProfileCoValue));
|
32
|
+
yield* Effect.promise(() => Promise.all([
|
33
|
+
waitForSync(account, peer, accountCoValue),
|
34
|
+
waitForSync(account, peer, accountProfileCoValue),
|
35
|
+
]));
|
36
|
+
// Spawn a second peer to double check that the account is fully synced
|
37
|
+
const peer2 = createWebSocketPeer({
|
38
|
+
id: "upstream2",
|
39
|
+
websocket: new WebSocket(peerAddr),
|
40
|
+
role: "server",
|
41
|
+
});
|
42
|
+
yield* Effect.promise(async () => createJazzContext({
|
43
|
+
auth: fixedCredentialsAuth({
|
44
|
+
accountID: account.id,
|
45
|
+
secret: account._raw.agentSecret,
|
46
|
+
}),
|
47
|
+
sessionProvider: randomSessionProvider,
|
48
|
+
peersToLoadFrom: [peer2],
|
49
|
+
crypto,
|
50
|
+
}));
|
51
|
+
yield* Console.log(`# Credentials for Jazz account "${name}":
|
52
|
+
JAZZ_WORKER_ACCOUNT=${account.id}
|
53
|
+
JAZZ_WORKER_SECRET=${account._raw.agentSecret}
|
54
|
+
`);
|
55
|
+
});
|
56
|
+
});
|
57
|
+
const accountBase = Command.make("account");
|
58
|
+
export const account = accountBase.pipe(Command.withSubcommands([accountCreate]));
|
59
|
+
function waitForSync(account, peer, coValue) {
|
60
|
+
const syncManager = account._raw.core.node.syncManager;
|
61
|
+
const peerState = syncManager.peers[peer.id];
|
62
|
+
return new Promise((resolve) => {
|
63
|
+
const unsubscribe = peerState?.optimisticKnownStates.subscribe((id, peerKnownState) => {
|
64
|
+
if (id !== coValue.id)
|
65
|
+
return;
|
66
|
+
const knownState = coValue.knownState();
|
67
|
+
const synced = isEqualSession(knownState.sessions, peerKnownState.sessions);
|
68
|
+
if (synced) {
|
69
|
+
resolve(true);
|
70
|
+
unsubscribe?.();
|
71
|
+
}
|
72
|
+
});
|
73
|
+
});
|
74
|
+
}
|
75
|
+
function isEqualSession(a, b) {
|
76
|
+
const keysA = Object.keys(a);
|
77
|
+
const keysB = Object.keys(b);
|
78
|
+
if (keysA.length !== keysB.length) {
|
79
|
+
return false;
|
80
|
+
}
|
81
|
+
for (const sessionId of keysA) {
|
82
|
+
if (a[sessionId] !== b[sessionId]) {
|
83
|
+
return false;
|
84
|
+
}
|
85
|
+
}
|
86
|
+
return true;
|
87
|
+
}
|
88
|
+
//# sourceMappingURL=accountCreate.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"accountCreate.js","sourceRoot":"","sources":["../src/accountCreate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACzC,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAC/B,OAAO,EACH,OAAO,EAEP,UAAU,EACV,iBAAiB,EACjB,mBAAmB,GACtB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,M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,KAAK,CAAC;IACjB,CAAC;IAED,KAAK,MAAM,SAAS,IAAI,KAAK,EAAE,CAAC;QAC5B,IAAI,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,SAAS,CAAC,EAAE,CAAC;YAChC,OAAO,KAAK,CAAC;QACjB,CAAC;IACL,CAAC;IAED,OAAO,IAAI,CAAC;AAChB,CAAC"}
|
package/dist/index.js
CHANGED
@@ -1,60 +1,11 @@
|
|
1
1
|
#!/usr/bin/env node
|
2
2
|
/* istanbul ignore file -- @preserve */
|
3
|
-
import { Command
|
3
|
+
import { Command } from "@effect/cli";
|
4
4
|
import { NodeContext, NodeRuntime } from "@effect/platform-node";
|
5
|
-
import {
|
6
|
-
import {
|
7
|
-
import { WebSocket } from "ws";
|
8
|
-
import { Account, WasmCrypto, createJazzContext, isControlledAccount, } from "jazz-tools";
|
9
|
-
import { fixedCredentialsAuth, randomSessionProvider } from "jazz-tools";
|
5
|
+
import { Effect } from "effect";
|
6
|
+
import { account } from "./accountCreate.js";
|
10
7
|
import { startSync } from "./startSync.js";
|
11
8
|
const jazzTools = Command.make("jazz-tools");
|
12
|
-
const name = Options.text("name").pipe(Options.withAlias("n"));
|
13
|
-
const peer = Options.text("peer")
|
14
|
-
.pipe(Options.withAlias("p"))
|
15
|
-
.pipe(Options.withDefault("wss://mesh.jazz.tools"));
|
16
|
-
const accountCreate = Command.make("create", { name, peer }, ({ name, peer: peerAddr }) => {
|
17
|
-
return Effect.gen(function* () {
|
18
|
-
const crypto = yield* Effect.promise(() => WasmCrypto.create());
|
19
|
-
const peer = createWebSocketPeer({
|
20
|
-
id: "upstream",
|
21
|
-
websocket: new WebSocket(peerAddr),
|
22
|
-
role: "server",
|
23
|
-
});
|
24
|
-
const account = yield* Effect.promise(async () => Account.create({
|
25
|
-
creationProps: { name },
|
26
|
-
peersToLoadFrom: [peer],
|
27
|
-
crypto,
|
28
|
-
}));
|
29
|
-
if (!isControlledAccount(account)) {
|
30
|
-
throw new Error("account is not a controlled account");
|
31
|
-
}
|
32
|
-
yield* Effect.promise(() => account._raw.core.node.syncManager.syncCoValue(account._raw.core));
|
33
|
-
yield* Effect.promise(() => account._raw.core.node.syncManager.syncCoValue(account.profile._raw.core));
|
34
|
-
// TODO: remove this once we have a better way to wait for the sync
|
35
|
-
yield* Effect.sleep(500);
|
36
|
-
const peer2 = createWebSocketPeer({
|
37
|
-
id: "upstream2",
|
38
|
-
websocket: new WebSocket(peerAddr),
|
39
|
-
role: "server",
|
40
|
-
});
|
41
|
-
yield* Effect.promise(async () => createJazzContext({
|
42
|
-
auth: fixedCredentialsAuth({
|
43
|
-
accountID: account.id,
|
44
|
-
secret: account._raw.agentSecret,
|
45
|
-
}),
|
46
|
-
sessionProvider: randomSessionProvider,
|
47
|
-
peersToLoadFrom: [peer2],
|
48
|
-
crypto,
|
49
|
-
}));
|
50
|
-
yield* Console.log(`# Credentials for Jazz account "${name}":
|
51
|
-
JAZZ_WORKER_ACCOUNT=${account.id}
|
52
|
-
JAZZ_WORKER_SECRET=${account._raw.agentSecret}
|
53
|
-
`);
|
54
|
-
});
|
55
|
-
});
|
56
|
-
const accountBase = Command.make("account");
|
57
|
-
const account = accountBase.pipe(Command.withSubcommands([accountCreate]));
|
58
9
|
const command = jazzTools.pipe(Command.withSubcommands([account, startSync]));
|
59
10
|
const cli = Command.run(command, {
|
60
11
|
name: "Jazz CLI Tools",
|
package/dist/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,uCAAuC;AACvC,OAAO,EAAE,OAAO,EAAE,
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,uCAAuC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACjE,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,MAAM,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;AAE7C,MAAM,OAAO,GAAG,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;AAE9E,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE;IAC7B,IAAI,EAAE,gBAAgB;IACtB,OAAO,EAAE,QAAQ;CACpB,CAAC,CAAC;AAEH,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CACxC,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,KAAK,CAAC,EACjC,WAAW,CAAC,OAAO,CACtB,CAAC"}
|
package/package.json
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
"bin": "./dist/index.js",
|
4
4
|
"type": "module",
|
5
5
|
"license": "MIT",
|
6
|
-
"version": "0.8.
|
6
|
+
"version": "0.8.11",
|
7
7
|
"dependencies": {
|
8
8
|
"@effect/cli": "^0.41.2",
|
9
9
|
"@effect/platform-node": "^0.57.2",
|
@@ -11,11 +11,11 @@
|
|
11
11
|
"@effect/printer-ansi": "^0.34.5",
|
12
12
|
"@effect/schema": "^0.71.1",
|
13
13
|
"@effect/typeclass": "^0.25.5",
|
14
|
-
"cojson": "0.8.
|
15
|
-
"cojson-storage-sqlite": "0.8.
|
16
|
-
"cojson-transport-ws": "0.8.
|
14
|
+
"cojson": "0.8.11",
|
15
|
+
"cojson-storage-sqlite": "0.8.11",
|
16
|
+
"cojson-transport-ws": "0.8.11",
|
17
17
|
"effect": "^3.6.5",
|
18
|
-
"jazz-tools": "0.8.
|
18
|
+
"jazz-tools": "0.8.11",
|
19
19
|
"ws": "^8.14.2"
|
20
20
|
},
|
21
21
|
"devDependencies": {
|
@@ -0,0 +1,125 @@
|
|
1
|
+
import { Command, Options } from "@effect/cli";
|
2
|
+
import { Console, Effect } from "effect";
|
3
|
+
import { createWebSocketPeer } from "cojson-transport-ws";
|
4
|
+
import { WebSocket } from "ws";
|
5
|
+
import {
|
6
|
+
Account,
|
7
|
+
Peer,
|
8
|
+
WasmCrypto,
|
9
|
+
createJazzContext,
|
10
|
+
isControlledAccount,
|
11
|
+
} from "jazz-tools";
|
12
|
+
import { fixedCredentialsAuth, randomSessionProvider } from "jazz-tools";
|
13
|
+
import { CoValueCore } from "cojson";
|
14
|
+
|
15
|
+
const name = Options.text("name").pipe(Options.withAlias("n"));
|
16
|
+
const peer = Options.text("peer")
|
17
|
+
.pipe(Options.withAlias("p"))
|
18
|
+
.pipe(Options.withDefault("wss://cloud.jazz.tools"));
|
19
|
+
|
20
|
+
const accountCreate = Command.make(
|
21
|
+
"create",
|
22
|
+
{ name, peer },
|
23
|
+
({ name, peer: peerAddr }) => {
|
24
|
+
return Effect.gen(function* () {
|
25
|
+
const crypto = yield* Effect.promise(() => WasmCrypto.create());
|
26
|
+
|
27
|
+
const peer = createWebSocketPeer({
|
28
|
+
id: "upstream",
|
29
|
+
websocket: new WebSocket(peerAddr),
|
30
|
+
role: "server",
|
31
|
+
});
|
32
|
+
|
33
|
+
const account: Account = yield* Effect.promise(async () =>
|
34
|
+
Account.create({
|
35
|
+
creationProps: { name },
|
36
|
+
peersToLoadFrom: [peer],
|
37
|
+
crypto,
|
38
|
+
}),
|
39
|
+
);
|
40
|
+
if (!isControlledAccount(account)) {
|
41
|
+
throw new Error("account is not a controlled account");
|
42
|
+
}
|
43
|
+
|
44
|
+
const accountCoValue = account._raw.core;
|
45
|
+
const accountProfileCoValue = account.profile!._raw.core;
|
46
|
+
const syncManager = account._raw.core.node.syncManager;
|
47
|
+
|
48
|
+
yield* Effect.promise(() =>
|
49
|
+
syncManager.syncCoValue(accountCoValue),
|
50
|
+
);
|
51
|
+
yield* Effect.promise(() =>
|
52
|
+
syncManager.syncCoValue(accountProfileCoValue),
|
53
|
+
);
|
54
|
+
|
55
|
+
yield* Effect.promise(() => Promise.all([
|
56
|
+
waitForSync(account, peer, accountCoValue),
|
57
|
+
waitForSync(account, peer, accountProfileCoValue),
|
58
|
+
]));
|
59
|
+
|
60
|
+
// Spawn a second peer to double check that the account is fully synced
|
61
|
+
const peer2 = createWebSocketPeer({
|
62
|
+
id: "upstream2",
|
63
|
+
websocket: new WebSocket(peerAddr),
|
64
|
+
role: "server",
|
65
|
+
});
|
66
|
+
|
67
|
+
yield* Effect.promise(async () =>
|
68
|
+
createJazzContext({
|
69
|
+
auth: fixedCredentialsAuth({
|
70
|
+
accountID: account.id,
|
71
|
+
secret: account._raw.agentSecret,
|
72
|
+
}),
|
73
|
+
sessionProvider: randomSessionProvider,
|
74
|
+
peersToLoadFrom: [peer2],
|
75
|
+
crypto,
|
76
|
+
}),
|
77
|
+
);
|
78
|
+
|
79
|
+
yield* Console.log(`# Credentials for Jazz account "${name}":
|
80
|
+
JAZZ_WORKER_ACCOUNT=${account.id}
|
81
|
+
JAZZ_WORKER_SECRET=${account._raw.agentSecret}
|
82
|
+
`);
|
83
|
+
});
|
84
|
+
},
|
85
|
+
);
|
86
|
+
|
87
|
+
const accountBase = Command.make("account");
|
88
|
+
|
89
|
+
export const account = accountBase.pipe(Command.withSubcommands([accountCreate]));
|
90
|
+
|
91
|
+
function waitForSync(account: Account, peer: Peer, coValue: CoValueCore) {
|
92
|
+
const syncManager = account._raw.core.node.syncManager;
|
93
|
+
const peerState = syncManager.peers[peer.id];
|
94
|
+
|
95
|
+
return new Promise((resolve) => {
|
96
|
+
const unsubscribe = peerState?.optimisticKnownStates.subscribe((id, peerKnownState) => {
|
97
|
+
if (id !== coValue.id) return;
|
98
|
+
|
99
|
+
const knownState = coValue.knownState();
|
100
|
+
|
101
|
+
const synced = isEqualSession(knownState.sessions, peerKnownState.sessions);
|
102
|
+
if (synced) {
|
103
|
+
resolve(true);
|
104
|
+
unsubscribe?.();
|
105
|
+
}
|
106
|
+
});
|
107
|
+
});
|
108
|
+
}
|
109
|
+
|
110
|
+
function isEqualSession(a: Record<string, number>, b: Record<string, number>) {
|
111
|
+
const keysA = Object.keys(a);
|
112
|
+
const keysB = Object.keys(b);
|
113
|
+
|
114
|
+
if (keysA.length !== keysB.length) {
|
115
|
+
return false;
|
116
|
+
}
|
117
|
+
|
118
|
+
for (const sessionId of keysA) {
|
119
|
+
if (a[sessionId] !== b[sessionId]) {
|
120
|
+
return false;
|
121
|
+
}
|
122
|
+
}
|
123
|
+
|
124
|
+
return true;
|
125
|
+
}
|
package/src/index.ts
CHANGED
@@ -1,93 +1,13 @@
|
|
1
1
|
#!/usr/bin/env node
|
2
2
|
/* istanbul ignore file -- @preserve */
|
3
|
-
import { Command
|
3
|
+
import { Command } from "@effect/cli";
|
4
4
|
import { NodeContext, NodeRuntime } from "@effect/platform-node";
|
5
|
-
import {
|
6
|
-
import {
|
7
|
-
import { WebSocket } from "ws";
|
8
|
-
import {
|
9
|
-
Account,
|
10
|
-
WasmCrypto,
|
11
|
-
createJazzContext,
|
12
|
-
isControlledAccount,
|
13
|
-
} from "jazz-tools";
|
14
|
-
import { fixedCredentialsAuth, randomSessionProvider } from "jazz-tools";
|
5
|
+
import { Effect } from "effect";
|
6
|
+
import { account } from "./accountCreate.js";
|
15
7
|
import { startSync } from "./startSync.js";
|
16
8
|
|
17
9
|
const jazzTools = Command.make("jazz-tools");
|
18
10
|
|
19
|
-
const name = Options.text("name").pipe(Options.withAlias("n"));
|
20
|
-
const peer = Options.text("peer")
|
21
|
-
.pipe(Options.withAlias("p"))
|
22
|
-
.pipe(Options.withDefault("wss://mesh.jazz.tools"));
|
23
|
-
const accountCreate = Command.make(
|
24
|
-
"create",
|
25
|
-
{ name, peer },
|
26
|
-
({ name, peer: peerAddr }) => {
|
27
|
-
return Effect.gen(function* () {
|
28
|
-
const crypto = yield* Effect.promise(() => WasmCrypto.create());
|
29
|
-
|
30
|
-
const peer = createWebSocketPeer({
|
31
|
-
id: "upstream",
|
32
|
-
websocket: new WebSocket(peerAddr),
|
33
|
-
role: "server",
|
34
|
-
});
|
35
|
-
|
36
|
-
const account: Account = yield* Effect.promise(async () =>
|
37
|
-
Account.create({
|
38
|
-
creationProps: { name },
|
39
|
-
peersToLoadFrom: [peer],
|
40
|
-
crypto,
|
41
|
-
}),
|
42
|
-
);
|
43
|
-
if (!isControlledAccount(account)) {
|
44
|
-
throw new Error("account is not a controlled account");
|
45
|
-
}
|
46
|
-
|
47
|
-
yield* Effect.promise(() =>
|
48
|
-
account._raw.core.node.syncManager.syncCoValue(
|
49
|
-
account._raw.core,
|
50
|
-
),
|
51
|
-
);
|
52
|
-
yield* Effect.promise(() =>
|
53
|
-
account._raw.core.node.syncManager.syncCoValue(
|
54
|
-
account.profile!._raw.core,
|
55
|
-
),
|
56
|
-
);
|
57
|
-
|
58
|
-
// TODO: remove this once we have a better way to wait for the sync
|
59
|
-
yield* Effect.sleep(500);
|
60
|
-
|
61
|
-
const peer2 = createWebSocketPeer({
|
62
|
-
id: "upstream2",
|
63
|
-
websocket: new WebSocket(peerAddr),
|
64
|
-
role: "server",
|
65
|
-
});
|
66
|
-
|
67
|
-
yield* Effect.promise(async () =>
|
68
|
-
createJazzContext({
|
69
|
-
auth: fixedCredentialsAuth({
|
70
|
-
accountID: account.id,
|
71
|
-
secret: account._raw.agentSecret,
|
72
|
-
}),
|
73
|
-
sessionProvider: randomSessionProvider,
|
74
|
-
peersToLoadFrom: [peer2],
|
75
|
-
crypto,
|
76
|
-
}),
|
77
|
-
);
|
78
|
-
|
79
|
-
yield* Console.log(`# Credentials for Jazz account "${name}":
|
80
|
-
JAZZ_WORKER_ACCOUNT=${account.id}
|
81
|
-
JAZZ_WORKER_SECRET=${account._raw.agentSecret}
|
82
|
-
`);
|
83
|
-
});
|
84
|
-
},
|
85
|
-
);
|
86
|
-
|
87
|
-
const accountBase = Command.make("account");
|
88
|
-
|
89
|
-
const account = accountBase.pipe(Command.withSubcommands([accountCreate]));
|
90
|
-
|
91
11
|
const command = jazzTools.pipe(Command.withSubcommands([account, startSync]));
|
92
12
|
|
93
13
|
const cli = Command.run(command, {
|
package/.turbo/turbo-build.log
DELETED
package/.turbo/turbo-lint.log
DELETED
package/.turbo/turbo-test.log
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
|
2
|
-
> jazz-run@0.7.0-alpha.37 test /Users/anselm/jazz/jazz/packages/jazz-run
|
3
|
-
> vitest
|
4
|
-
|
5
|
-
|
6
|
-
DEV v0.34.6 /Users/anselm/jazz/jazz/packages/jazz-run
|
7
|
-
|
8
|
-
include: **/*.{test,spec}.?(c|m)[jt]s?(x)
|
9
|
-
exclude: **/node_modules/**, **/dist/**, **/cypress/**, **/.{idea,git,cache,output,temp}/**, **/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build}.config.*
|
10
|
-
watch exclude: **/node_modules/**, **/dist/**
|
11
|
-
|
12
|
-
No test files found, exiting with code 1
|
13
|
-
ELIFECYCLE Test failed. See above for more details.
|