@gadgetinc/ggt 0.1.4 → 0.1.6

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 CHANGED
@@ -119,7 +119,7 @@ EXAMPLES
119
119
  $ ggt sync --app https://my-app.gadget.app/edit
120
120
  ```
121
121
 
122
- _See code: [src/commands/sync.ts](https://github.com/gadget-inc/ggt/blob/v0.1.4/src/commands/sync.ts)_
122
+ _See code: [src/commands/sync.ts](https://github.com/gadget-inc/ggt/blob/v0.1.6/src/commands/sync.ts)_
123
123
 
124
124
  ### `ggt help [COMMAND]`
125
125
 
@@ -133,7 +133,7 @@ ARGUMENTS
133
133
  COMMAND The command to show help for.
134
134
  ```
135
135
 
136
- _See code: [src/commands/help.ts](https://github.com/gadget-inc/ggt/blob/v0.1.4/src/commands/help.ts)_
136
+ _See code: [src/commands/help.ts](https://github.com/gadget-inc/ggt/blob/v0.1.6/src/commands/help.ts)_
137
137
 
138
138
  ### `ggt login`
139
139
 
@@ -149,7 +149,7 @@ EXAMPLES
149
149
  Hello, Jane Doe (jane@example.com)
150
150
  ```
151
151
 
152
- _See code: [src/commands/login.ts](https://github.com/gadget-inc/ggt/blob/v0.1.4/src/commands/login.ts)_
152
+ _See code: [src/commands/login.ts](https://github.com/gadget-inc/ggt/blob/v0.1.6/src/commands/login.ts)_
153
153
 
154
154
  ### `ggt logout`
155
155
 
@@ -164,7 +164,7 @@ EXAMPLES
164
164
  Goodbye
165
165
  ```
166
166
 
167
- _See code: [src/commands/logout.ts](https://github.com/gadget-inc/ggt/blob/v0.1.4/src/commands/logout.ts)_
167
+ _See code: [src/commands/logout.ts](https://github.com/gadget-inc/ggt/blob/v0.1.6/src/commands/logout.ts)_
168
168
 
169
169
  ### `ggt whoami`
170
170
 
@@ -179,7 +179,7 @@ EXAMPLES
179
179
  You are logged in as Jane Doe (jane@example.com)
180
180
  ```
181
181
 
182
- _See code: [src/commands/whoami.ts](https://github.com/gadget-inc/ggt/blob/v0.1.4/src/commands/whoami.ts)_
182
+ _See code: [src/commands/whoami.ts](https://github.com/gadget-inc/ggt/blob/v0.1.6/src/commands/whoami.ts)_
183
183
 
184
184
  <!-- commandsstop -->
185
185
 
@@ -0,0 +1,245 @@
1
+ /**
2
+ * ======================================================
3
+ * THIS IS A GENERATED FILE! You shouldn't edit it manually. Regenerate it using `npm run generate-graphql`.
4
+ * ======================================================
5
+ */
6
+ export declare type Maybe<T> = T | null;
7
+ export declare type InputMaybe<T> = Maybe<T>;
8
+ export declare type Exact<T extends {
9
+ [key: string]: unknown;
10
+ }> = {
11
+ [K in keyof T]: T[K];
12
+ };
13
+ export declare type MakeOptional<T, K extends keyof T> = Omit<T, K> & {
14
+ [SubKey in K]?: Maybe<T[SubKey]>;
15
+ };
16
+ export declare type MakeMaybe<T, K extends keyof T> = Omit<T, K> & {
17
+ [SubKey in K]: Maybe<T[SubKey]>;
18
+ };
19
+ /** All built-in and custom scalars, mapped to their actual values */
20
+ export declare type Scalars = {
21
+ ID: string;
22
+ String: string;
23
+ Boolean: boolean;
24
+ Int: number;
25
+ Float: number;
26
+ Date: any;
27
+ DateTime: any;
28
+ JSON: {
29
+ [key: string]: any;
30
+ };
31
+ };
32
+ export declare type DeleteAppStatusResult = {
33
+ __typename?: 'DeleteAppStatusResult';
34
+ isNotCreator?: Maybe<Scalars['Boolean']>;
35
+ success: Scalars['Boolean'];
36
+ };
37
+ export declare type EnvironmentPatchResult = {
38
+ __typename?: 'EnvironmentPatchResult';
39
+ success: Scalars['Boolean'];
40
+ };
41
+ export declare type EnvironmentPublishResult = {
42
+ __typename?: 'EnvironmentPublishResult';
43
+ success: Scalars['Boolean'];
44
+ };
45
+ export declare type EnvironmentSubscriptionResult = {
46
+ __typename?: 'EnvironmentSubscriptionResult';
47
+ patches: Array<Scalars['JSON']>;
48
+ };
49
+ export declare type FileSyncChangedEvent = {
50
+ __typename?: 'FileSyncChangedEvent';
51
+ content: Scalars['String'];
52
+ encoding: FileSyncEncoding;
53
+ mode: Scalars['Float'];
54
+ path: Scalars['String'];
55
+ };
56
+ export declare type FileSyncChangedEventInput = {
57
+ content: Scalars['String'];
58
+ encoding?: InputMaybe<FileSyncEncoding>;
59
+ mode: Scalars['Float'];
60
+ path: Scalars['String'];
61
+ };
62
+ export declare type FileSyncDeletedEvent = {
63
+ __typename?: 'FileSyncDeletedEvent';
64
+ path: Scalars['String'];
65
+ };
66
+ export declare type FileSyncDeletedEventInput = {
67
+ path: Scalars['String'];
68
+ };
69
+ export declare enum FileSyncEncoding {
70
+ Base64 = "base64",
71
+ Utf8 = "utf8"
72
+ }
73
+ export declare type GadgetRole = {
74
+ __typename?: 'GadgetRole';
75
+ key: Scalars['String'];
76
+ name: Scalars['String'];
77
+ order: Scalars['Int'];
78
+ selectable: Scalars['Boolean'];
79
+ };
80
+ export declare type LogSearchResult = {
81
+ __typename?: 'LogSearchResult';
82
+ data: Scalars['JSON'];
83
+ status: Scalars['String'];
84
+ };
85
+ export declare type MigrateEnvironmentsResult = {
86
+ __typename?: 'MigrateEnvironmentsResult';
87
+ success: Scalars['Boolean'];
88
+ };
89
+ export declare type Mutation = {
90
+ __typename?: 'Mutation';
91
+ deleteApp?: Maybe<DeleteAppStatusResult>;
92
+ migrateEnvironments?: Maybe<MigrateEnvironmentsResult>;
93
+ patchEnvironmentTree?: Maybe<EnvironmentPatchResult>;
94
+ publish?: Maybe<EnvironmentPublishResult>;
95
+ publishFileSyncEvents: PublishFileSyncEventsResult;
96
+ refreshScopes?: Maybe<RefreshScopesResult>;
97
+ registerWebhooks?: Maybe<RegisterWebhooksResult>;
98
+ unregisterWebhooks?: Maybe<UnregisterWebhooksResult>;
99
+ };
100
+ export declare type MutationPatchEnvironmentTreeArgs = {
101
+ clientID: Scalars['String'];
102
+ patches: Array<Scalars['JSON']>;
103
+ };
104
+ export declare type MutationPublishFileSyncEventsArgs = {
105
+ input: PublishFileSyncEventsInput;
106
+ };
107
+ export declare type MutationRefreshScopesArgs = {
108
+ appConfigKey: Scalars['String'];
109
+ connectionKey: Scalars['String'];
110
+ shopId: Scalars['String'];
111
+ };
112
+ export declare type MutationRegisterWebhooksArgs = {
113
+ connectionKey: Scalars['String'];
114
+ keepExtraTopics?: InputMaybe<Scalars['Boolean']>;
115
+ modelKeys?: InputMaybe<Array<Scalars['String']>>;
116
+ shopIds: Array<Scalars['String']>;
117
+ };
118
+ export declare type MutationUnregisterWebhooksArgs = {
119
+ connectionKey: Scalars['String'];
120
+ modelKeys?: InputMaybe<Array<Scalars['String']>>;
121
+ shopIds?: InputMaybe<Array<Scalars['String']>>;
122
+ };
123
+ export declare type PublishFileSyncEventsInput = {
124
+ changed: Array<FileSyncChangedEventInput>;
125
+ deleted: Array<FileSyncDeletedEventInput>;
126
+ expectedRemoteFilesVersion: Scalars['String'];
127
+ };
128
+ export declare type PublishFileSyncEventsResult = {
129
+ __typename?: 'PublishFileSyncEventsResult';
130
+ remoteFilesVersion: Scalars['String'];
131
+ };
132
+ export declare type Query = {
133
+ __typename?: 'Query';
134
+ currentUser: User;
135
+ environmentTreePath?: Maybe<Scalars['JSON']>;
136
+ logsSearch: LogSearchResult;
137
+ remoteFilesVersion: Scalars['String'];
138
+ roles: Array<GadgetRole>;
139
+ runTestSupportFunction?: Maybe<Scalars['JSON']>;
140
+ typesManifest: TypesManifest;
141
+ };
142
+ export declare type QueryEnvironmentTreePathArgs = {
143
+ path: Scalars['String'];
144
+ };
145
+ export declare type QueryLogsSearchArgs = {
146
+ direction?: InputMaybe<Scalars['String']>;
147
+ end?: InputMaybe<Scalars['DateTime']>;
148
+ limit?: InputMaybe<Scalars['Int']>;
149
+ query: Scalars['String'];
150
+ start?: InputMaybe<Scalars['DateTime']>;
151
+ step?: InputMaybe<Scalars['Int']>;
152
+ };
153
+ export declare type RefreshScopesResult = {
154
+ __typename?: 'RefreshScopesResult';
155
+ success: Scalars['Boolean'];
156
+ };
157
+ export declare type RegisterWebhooksResult = {
158
+ __typename?: 'RegisterWebhooksResult';
159
+ success: Scalars['Boolean'];
160
+ };
161
+ export declare type RemoteFileSyncEvents = {
162
+ __typename?: 'RemoteFileSyncEvents';
163
+ changed: Array<FileSyncChangedEvent>;
164
+ deleted: Array<FileSyncDeletedEvent>;
165
+ remoteFilesVersion: Scalars['String'];
166
+ };
167
+ export declare type Subscription = {
168
+ __typename?: 'Subscription';
169
+ editorActive?: Maybe<Scalars['Boolean']>;
170
+ environmentTreePathPatches?: Maybe<EnvironmentSubscriptionResult>;
171
+ logsSearch: LogSearchResult;
172
+ remoteFileSyncEvents: RemoteFileSyncEvents;
173
+ typesManifestStream: TypesManifest;
174
+ };
175
+ export declare type SubscriptionEnvironmentTreePathPatchesArgs = {
176
+ clientID: Scalars['String'];
177
+ path: Scalars['String'];
178
+ };
179
+ export declare type SubscriptionLogsSearchArgs = {
180
+ limit?: InputMaybe<Scalars['Int']>;
181
+ query: Scalars['String'];
182
+ start?: InputMaybe<Scalars['DateTime']>;
183
+ };
184
+ export declare type SubscriptionRemoteFileSyncEventsArgs = {
185
+ encoding?: InputMaybe<FileSyncEncoding>;
186
+ localFilesVersion: Scalars['String'];
187
+ };
188
+ export declare type TypeManifestEntry = {
189
+ __typename?: 'TypeManifestEntry';
190
+ declaration: Scalars['String'];
191
+ path: Scalars['String'];
192
+ };
193
+ export declare type TypesManifest = {
194
+ __typename?: 'TypesManifest';
195
+ dependenciesHash: Scalars['String'];
196
+ entries: Array<TypeManifestEntry>;
197
+ environmentVersion: Scalars['Int'];
198
+ };
199
+ export declare type UnregisterWebhooksResult = {
200
+ __typename?: 'UnregisterWebhooksResult';
201
+ success: Scalars['Boolean'];
202
+ };
203
+ export declare type User = {
204
+ __typename?: 'User';
205
+ email: Scalars['String'];
206
+ name?: Maybe<Scalars['String']>;
207
+ };
208
+ export declare type RemoteFileSyncEventsSubscriptionVariables = Exact<{
209
+ localFilesVersion: Scalars['String'];
210
+ }>;
211
+ export declare type RemoteFileSyncEventsSubscription = {
212
+ __typename?: 'Subscription';
213
+ remoteFileSyncEvents: {
214
+ __typename?: 'RemoteFileSyncEvents';
215
+ remoteFilesVersion: string;
216
+ changed: Array<{
217
+ __typename?: 'FileSyncChangedEvent';
218
+ path: string;
219
+ mode: number;
220
+ content: string;
221
+ encoding: FileSyncEncoding;
222
+ }>;
223
+ deleted: Array<{
224
+ __typename?: 'FileSyncDeletedEvent';
225
+ path: string;
226
+ }>;
227
+ };
228
+ };
229
+ export declare type RemoteFilesVersionQueryVariables = Exact<{
230
+ [key: string]: never;
231
+ }>;
232
+ export declare type RemoteFilesVersionQuery = {
233
+ __typename?: 'Query';
234
+ remoteFilesVersion: string;
235
+ };
236
+ export declare type PublishFileSyncEventsMutationVariables = Exact<{
237
+ input: PublishFileSyncEventsInput;
238
+ }>;
239
+ export declare type PublishFileSyncEventsMutation = {
240
+ __typename?: 'Mutation';
241
+ publishFileSyncEvents: {
242
+ __typename?: 'PublishFileSyncEventsResult';
243
+ remoteFilesVersion: string;
244
+ };
245
+ };
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ /**
3
+ * ======================================================
4
+ * THIS IS A GENERATED FILE! You shouldn't edit it manually. Regenerate it using `npm run generate-graphql`.
5
+ * ======================================================
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.FileSyncEncoding = void 0;
9
+ var FileSyncEncoding;
10
+ (function (FileSyncEncoding) {
11
+ FileSyncEncoding["Base64"] = "base64";
12
+ FileSyncEncoding["Utf8"] = "utf8";
13
+ })(FileSyncEncoding = exports.FileSyncEncoding || (exports.FileSyncEncoding = {}));
14
+ //# sourceMappingURL=graphql.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graphql.js","sourceRoot":"","sources":["../../src/__generated__/graphql.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAgEH,IAAY,gBAGX;AAHD,WAAY,gBAAgB;IAC1B,qCAAiB,CAAA;IACjB,iCAAa,CAAA;AACf,CAAC,EAHW,gBAAgB,GAAhB,wBAAgB,KAAhB,wBAAgB,QAG3B","sourcesContent":["/**\n * ======================================================\n * THIS IS A GENERATED FILE! You shouldn't edit it manually. Regenerate it using `npm run generate-graphql`.\n * ======================================================\n */\n\nexport type Maybe<T> = T | null;\nexport type InputMaybe<T> = Maybe<T>;\nexport type Exact<T extends { [key: string]: unknown }> = { [K in keyof T]: T[K] };\nexport type MakeOptional<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]?: Maybe<T[SubKey]> };\nexport type MakeMaybe<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]: Maybe<T[SubKey]> };\n/** All built-in and custom scalars, mapped to their actual values */\nexport type Scalars = {\n ID: string;\n String: string;\n Boolean: boolean;\n Int: number;\n Float: number;\n Date: any;\n DateTime: any;\n JSON: { [key: string]: any };\n};\n\nexport type DeleteAppStatusResult = {\n __typename?: 'DeleteAppStatusResult';\n isNotCreator?: Maybe<Scalars['Boolean']>;\n success: Scalars['Boolean'];\n};\n\nexport type EnvironmentPatchResult = {\n __typename?: 'EnvironmentPatchResult';\n success: Scalars['Boolean'];\n};\n\nexport type EnvironmentPublishResult = {\n __typename?: 'EnvironmentPublishResult';\n success: Scalars['Boolean'];\n};\n\nexport type EnvironmentSubscriptionResult = {\n __typename?: 'EnvironmentSubscriptionResult';\n patches: Array<Scalars['JSON']>;\n};\n\nexport type FileSyncChangedEvent = {\n __typename?: 'FileSyncChangedEvent';\n content: Scalars['String'];\n encoding: FileSyncEncoding;\n mode: Scalars['Float'];\n path: Scalars['String'];\n};\n\nexport type FileSyncChangedEventInput = {\n content: Scalars['String'];\n encoding?: InputMaybe<FileSyncEncoding>;\n mode: Scalars['Float'];\n path: Scalars['String'];\n};\n\nexport type FileSyncDeletedEvent = {\n __typename?: 'FileSyncDeletedEvent';\n path: Scalars['String'];\n};\n\nexport type FileSyncDeletedEventInput = {\n path: Scalars['String'];\n};\n\nexport enum FileSyncEncoding {\n Base64 = 'base64',\n Utf8 = 'utf8'\n}\n\nexport type GadgetRole = {\n __typename?: 'GadgetRole';\n key: Scalars['String'];\n name: Scalars['String'];\n order: Scalars['Int'];\n selectable: Scalars['Boolean'];\n};\n\nexport type LogSearchResult = {\n __typename?: 'LogSearchResult';\n data: Scalars['JSON'];\n status: Scalars['String'];\n};\n\nexport type MigrateEnvironmentsResult = {\n __typename?: 'MigrateEnvironmentsResult';\n success: Scalars['Boolean'];\n};\n\nexport type Mutation = {\n __typename?: 'Mutation';\n deleteApp?: Maybe<DeleteAppStatusResult>;\n migrateEnvironments?: Maybe<MigrateEnvironmentsResult>;\n patchEnvironmentTree?: Maybe<EnvironmentPatchResult>;\n publish?: Maybe<EnvironmentPublishResult>;\n publishFileSyncEvents: PublishFileSyncEventsResult;\n refreshScopes?: Maybe<RefreshScopesResult>;\n registerWebhooks?: Maybe<RegisterWebhooksResult>;\n unregisterWebhooks?: Maybe<UnregisterWebhooksResult>;\n};\n\n\nexport type MutationPatchEnvironmentTreeArgs = {\n clientID: Scalars['String'];\n patches: Array<Scalars['JSON']>;\n};\n\n\nexport type MutationPublishFileSyncEventsArgs = {\n input: PublishFileSyncEventsInput;\n};\n\n\nexport type MutationRefreshScopesArgs = {\n appConfigKey: Scalars['String'];\n connectionKey: Scalars['String'];\n shopId: Scalars['String'];\n};\n\n\nexport type MutationRegisterWebhooksArgs = {\n connectionKey: Scalars['String'];\n keepExtraTopics?: InputMaybe<Scalars['Boolean']>;\n modelKeys?: InputMaybe<Array<Scalars['String']>>;\n shopIds: Array<Scalars['String']>;\n};\n\n\nexport type MutationUnregisterWebhooksArgs = {\n connectionKey: Scalars['String'];\n modelKeys?: InputMaybe<Array<Scalars['String']>>;\n shopIds?: InputMaybe<Array<Scalars['String']>>;\n};\n\nexport type PublishFileSyncEventsInput = {\n changed: Array<FileSyncChangedEventInput>;\n deleted: Array<FileSyncDeletedEventInput>;\n expectedRemoteFilesVersion: Scalars['String'];\n};\n\nexport type PublishFileSyncEventsResult = {\n __typename?: 'PublishFileSyncEventsResult';\n remoteFilesVersion: Scalars['String'];\n};\n\nexport type Query = {\n __typename?: 'Query';\n currentUser: User;\n environmentTreePath?: Maybe<Scalars['JSON']>;\n logsSearch: LogSearchResult;\n remoteFilesVersion: Scalars['String'];\n roles: Array<GadgetRole>;\n runTestSupportFunction?: Maybe<Scalars['JSON']>;\n typesManifest: TypesManifest;\n};\n\n\nexport type QueryEnvironmentTreePathArgs = {\n path: Scalars['String'];\n};\n\n\nexport type QueryLogsSearchArgs = {\n direction?: InputMaybe<Scalars['String']>;\n end?: InputMaybe<Scalars['DateTime']>;\n limit?: InputMaybe<Scalars['Int']>;\n query: Scalars['String'];\n start?: InputMaybe<Scalars['DateTime']>;\n step?: InputMaybe<Scalars['Int']>;\n};\n\nexport type RefreshScopesResult = {\n __typename?: 'RefreshScopesResult';\n success: Scalars['Boolean'];\n};\n\nexport type RegisterWebhooksResult = {\n __typename?: 'RegisterWebhooksResult';\n success: Scalars['Boolean'];\n};\n\nexport type RemoteFileSyncEvents = {\n __typename?: 'RemoteFileSyncEvents';\n changed: Array<FileSyncChangedEvent>;\n deleted: Array<FileSyncDeletedEvent>;\n remoteFilesVersion: Scalars['String'];\n};\n\nexport type Subscription = {\n __typename?: 'Subscription';\n editorActive?: Maybe<Scalars['Boolean']>;\n environmentTreePathPatches?: Maybe<EnvironmentSubscriptionResult>;\n logsSearch: LogSearchResult;\n remoteFileSyncEvents: RemoteFileSyncEvents;\n typesManifestStream: TypesManifest;\n};\n\n\nexport type SubscriptionEnvironmentTreePathPatchesArgs = {\n clientID: Scalars['String'];\n path: Scalars['String'];\n};\n\n\nexport type SubscriptionLogsSearchArgs = {\n limit?: InputMaybe<Scalars['Int']>;\n query: Scalars['String'];\n start?: InputMaybe<Scalars['DateTime']>;\n};\n\n\nexport type SubscriptionRemoteFileSyncEventsArgs = {\n encoding?: InputMaybe<FileSyncEncoding>;\n localFilesVersion: Scalars['String'];\n};\n\nexport type TypeManifestEntry = {\n __typename?: 'TypeManifestEntry';\n declaration: Scalars['String'];\n path: Scalars['String'];\n};\n\nexport type TypesManifest = {\n __typename?: 'TypesManifest';\n dependenciesHash: Scalars['String'];\n entries: Array<TypeManifestEntry>;\n environmentVersion: Scalars['Int'];\n};\n\nexport type UnregisterWebhooksResult = {\n __typename?: 'UnregisterWebhooksResult';\n success: Scalars['Boolean'];\n};\n\nexport type User = {\n __typename?: 'User';\n email: Scalars['String'];\n name?: Maybe<Scalars['String']>;\n};\n\nexport type RemoteFileSyncEventsSubscriptionVariables = Exact<{\n localFilesVersion: Scalars['String'];\n}>;\n\n\nexport type RemoteFileSyncEventsSubscription = { __typename?: 'Subscription', remoteFileSyncEvents: { __typename?: 'RemoteFileSyncEvents', remoteFilesVersion: string, changed: Array<{ __typename?: 'FileSyncChangedEvent', path: string, mode: number, content: string, encoding: FileSyncEncoding }>, deleted: Array<{ __typename?: 'FileSyncDeletedEvent', path: string }> } };\n\nexport type RemoteFilesVersionQueryVariables = Exact<{ [key: string]: never; }>;\n\n\nexport type RemoteFilesVersionQuery = { __typename?: 'Query', remoteFilesVersion: string };\n\nexport type PublishFileSyncEventsMutationVariables = Exact<{\n input: PublishFileSyncEventsInput;\n}>;\n\n\nexport type PublishFileSyncEventsMutation = { __typename?: 'Mutation', publishFileSyncEvents: { __typename?: 'PublishFileSyncEventsResult', remoteFilesVersion: string } };\n"]}
@@ -1,8 +1,6 @@
1
- /// <reference types="node" />
2
1
  import { FSWatcher } from "chokidar";
3
2
  import type { DebouncedFunc } from "lodash";
4
3
  import PQueue from "p-queue";
5
- import { TextDecoder, TextEncoder } from "util";
6
4
  import { BaseCommand } from "../lib/base-command";
7
5
  import type { Query } from "../lib/client";
8
6
  import { Client } from "../lib/client";
@@ -30,8 +28,6 @@ export default class Sync extends BaseCommand {
30
28
  status: SyncStatus;
31
29
  dir: string;
32
30
  recentWrites: Set<unknown>;
33
- encoder: TextEncoder;
34
- decoder: TextDecoder;
35
31
  filePushDelay: number;
36
32
  queue: PQueue<import("p-queue/dist/priority-queue").default, import("p-queue").DefaultAddOptions>;
37
33
  client: Client;
@@ -9,12 +9,12 @@ const execa_1 = tslib_1.__importDefault(require("execa"));
9
9
  const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
10
10
  const inquirer_1 = require("inquirer");
11
11
  const lodash_1 = require("lodash");
12
+ const lodash_2 = require("lodash");
12
13
  const normalize_path_1 = tslib_1.__importDefault(require("normalize-path"));
13
14
  const p_map_1 = tslib_1.__importDefault(require("p-map"));
14
15
  const p_queue_1 = tslib_1.__importDefault(require("p-queue"));
15
16
  const path_1 = tslib_1.__importDefault(require("path"));
16
17
  const ts_dedent_1 = tslib_1.__importDefault(require("ts-dedent"));
17
- const util_1 = require("util");
18
18
  const which_1 = tslib_1.__importDefault(require("which"));
19
19
  const base_command_1 = require("../lib/base-command");
20
20
  const client_1 = require("../lib/client");
@@ -23,6 +23,7 @@ const errors_1 = require("../lib/errors");
23
23
  const flags_1 = require("../lib/flags");
24
24
  const fs_utils_1 = require("../lib/fs-utils");
25
25
  const sleep_1 = require("../lib/sleep");
26
+ const graphql_1 = require("../__generated__/graphql");
26
27
  class Sync extends base_command_1.BaseCommand {
27
28
  constructor() {
28
29
  super(...arguments);
@@ -50,18 +51,6 @@ class Sync extends base_command_1.BaseCommand {
50
51
  writable: true,
51
52
  value: new Set()
52
53
  });
53
- Object.defineProperty(this, "encoder", {
54
- enumerable: true,
55
- configurable: true,
56
- writable: true,
57
- value: new util_1.TextEncoder()
58
- });
59
- Object.defineProperty(this, "decoder", {
60
- enumerable: true,
61
- configurable: true,
62
- writable: true,
63
- value: new util_1.TextDecoder()
64
- });
65
54
  Object.defineProperty(this, "filePushDelay", {
66
55
  enumerable: true,
67
56
  configurable: true,
@@ -138,7 +127,11 @@ class Sync extends base_command_1.BaseCommand {
138
127
  async init() {
139
128
  await super.init();
140
129
  const { args, flags } = await this.parse(Sync);
141
- this.dir = path_1.default.resolve(args["directory"]);
130
+ (0, assert_1.default)((0, lodash_1.isString)(args["directory"]));
131
+ this.dir =
132
+ this.config.windows && args["directory"].startsWith("~/")
133
+ ? path_1.default.join(this.config.home, args["directory"].slice(2))
134
+ : path_1.default.resolve(args["directory"]);
142
135
  const getApp = async () => {
143
136
  if (flags.app)
144
137
  return flags.app;
@@ -249,7 +242,8 @@ class Sync extends base_command_1.BaseCommand {
249
242
  return {
250
243
  path: this.normalize(filepath),
251
244
  mode: stats.mode,
252
- content: this.decoder.decode(await fs_extra_1.default.readFile(filepath)),
245
+ content: await fs_extra_1.default.readFile(filepath, "base64"),
246
+ encoding: graphql_1.FileSyncEncoding.Base64,
253
247
  };
254
248
  }),
255
249
  deleted: [],
@@ -328,7 +322,7 @@ class Sync extends base_command_1.BaseCommand {
328
322
  if ("content" in file) {
329
323
  await fs_extra_1.default.ensureDir(path_1.default.dirname(filepath), { mode: 0o755 });
330
324
  if (!file.path.endsWith("/")) {
331
- await fs_extra_1.default.writeFile(filepath, this.encoder.encode(file.content), { mode: file.mode });
325
+ await fs_extra_1.default.writeFile(filepath, Buffer.from(file.content, file.encoding ?? graphql_1.FileSyncEncoding.Utf8), { mode: file.mode });
332
326
  }
333
327
  if (filepath == this.absolute("yarn.lock")) {
334
328
  await (0, execa_1.default)("yarn", ["install"], { cwd: this.dir }).catch((err) => {
@@ -350,7 +344,7 @@ class Sync extends base_command_1.BaseCommand {
350
344
  },
351
345
  });
352
346
  const localFilesBuffer = new Map();
353
- this.publish = (0, lodash_1.debounce)(() => {
347
+ this.publish = (0, lodash_2.debounce)(() => {
354
348
  const localFiles = new Map(localFilesBuffer.entries());
355
349
  localFilesBuffer.clear();
356
350
  void this.queue
@@ -363,7 +357,8 @@ class Sync extends base_command_1.BaseCommand {
363
357
  changed.push({
364
358
  path: this.normalize(filepath),
365
359
  mode: file.mode,
366
- content: this.decoder.decode(await fs_extra_1.default.readFile(filepath)),
360
+ content: await fs_extra_1.default.readFile(filepath, "base64"),
361
+ encoding: graphql_1.FileSyncEncoding.Base64,
367
362
  });
368
363
  }
369
364
  catch (error) {
@@ -584,12 +579,13 @@ var Action;
584
579
  })(Action = exports.Action || (exports.Action = {}));
585
580
  exports.REMOTE_FILE_SYNC_EVENTS_SUBSCRIPTION = `
586
581
  subscription RemoteFileSyncEvents($localFilesVersion: String!) {
587
- remoteFileSyncEvents(localFilesVersion: $localFilesVersion) {
582
+ remoteFileSyncEvents(localFilesVersion: $localFilesVersion, encoding: base64) {
588
583
  remoteFilesVersion
589
584
  changed {
590
585
  path
591
586
  mode
592
587
  content
588
+ encoding
593
589
  }
594
590
  deleted {
595
591
  path
@@ -1 +1 @@
1
- {"version":3,"file":"sync.js","sourceRoot":"","sources":["../../src/commands/sync.ts"],"names":[],"mappings":";;;;AAAA,sCAAoC;AACpC,4DAA4B;AAC5B,uCAAqC;AACrC,0DAA0B;AAE1B,gEAA0B;AAC1B,uCAAkC;AAElC,mCAAkC;AAClC,4EAA2C;AAC3C,0DAAyB;AACzB,8DAA6B;AAC7B,wDAAwB;AACxB,kEAA+B;AAC/B,+BAAgD;AAChD,0DAA0B;AAC1B,sDAAkD;AAElD,0CAAuC;AACvC,4CAAyC;AACzC,0CAAmF;AACnF,wCAAmC;AACnC,8CAA6E;AAC7E,wCAA0C;AAY1C,MAAqB,IAAK,SAAQ,0BAAW;IAA7C;;QA8FE;;;;mBAAuB,IAAI;WAAC;QAE5B;;;;mBAAS,UAAU,CAAC,QAAQ;WAAC;QAE7B;;;;;WAAa;QAEb;;;;mBAAe,IAAI,GAAG,EAAE;WAAC;QAEzB;;;;mBAAU,IAAI,kBAAW,EAAE;WAAC;QAE5B;;;;mBAAU,IAAI,kBAAW,EAAE;WAAC;QAE5B;;;;;WAAuB;QAEvB;;;;mBAAQ,IAAI,iBAAM,CAAC,EAAE,WAAW,EAAE,CAAC,EAAE,CAAC;WAAC;QAEvC;;;;;WAAgB;QAEhB;;;;;WAAkB;QAElB;;;;;WAAoB;QAEpB;;;;mBAAW;gBACT,GAAG,EAAE,EAAE;gBACP,YAAY,EAAE,GAAG;gBACjB,KAAK,EAAE,CAAC;aACT;WAAC;QAEF;;;;;WAAoC;QAEp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b,CAAC;QACF,oBAAoB,EAAE,YAAK,CAAC,OAAO,CAAC;YAClC,IAAI,EAAE,oBAAoB;YAC1B,WAAW,EAAE,yDAAyD;YACtE,SAAS,EAAE,MAAM;YACjB,SAAS,EAAE,IAAI;YACf,OAAO,EAAE,GAAG;YACZ,MAAM,EAAE,IAAI;SACb,CAAC;KACH;GAAC;AAEK;;;;WAAoB;QACzB,IAAA,mBAAM,EAAA;;;;;;;;;;KAUL;QACD,IAAA,mBAAM,EAAA;;;;;;;KAOL;KACF;GAAC;AA6aJ,IAAY,UAKX;AALD,WAAY,UAAU;IACpB,mDAAQ,CAAA;IACR,iDAAO,CAAA;IACP,mDAAQ,CAAA;IACR,iDAAO,CAAA;AACT,CAAC,EALW,UAAU,GAAV,kBAAU,KAAV,kBAAU,QAKrB;AAED,IAAY,MAIX;AAJD,WAAY,MAAM;IAChB,oCAA0B,CAAA;IAC1B,sDAA4C,CAAA;IAC5C,oDAA0C,CAAA;AAC5C,CAAC,EAJW,MAAM,GAAN,cAAM,KAAN,cAAM,QAIjB;AAEY,QAAA,oCAAoC,GAG/B;;;;;;;;;;;;;;CAcjB,CAAC;AAEW,QAAA,0BAA0B,GAAmF;;;;CAIzH,CAAC;AAEW,QAAA,iCAAiC,GAG5B;;;;;;CAMjB,CAAC","sourcesContent":["import { Flags } from \"@oclif/core\";\nimport assert from \"assert\";\nimport { FSWatcher } from \"chokidar\";\nimport execa from \"execa\";\nimport type { Stats } from \"fs-extra\";\nimport fs from \"fs-extra\";\nimport { prompt } from \"inquirer\";\nimport type { DebouncedFunc } from \"lodash\";\nimport { debounce } from \"lodash\";\nimport normalizePath from \"normalize-path\";\nimport pMap from \"p-map\";\nimport PQueue from \"p-queue\";\nimport path from \"path\";\nimport dedent from \"ts-dedent\";\nimport { TextDecoder, TextEncoder } from \"util\";\nimport which from \"which\";\nimport { BaseCommand } from \"../lib/base-command\";\nimport type { Query } from \"../lib/client\";\nimport { Client } from \"../lib/client\";\nimport { context } from \"../lib/context\";\nimport { FlagError, InvalidSyncFileError, YarnNotFoundError } from \"../lib/errors\";\nimport { app } from \"../lib/flags\";\nimport { ignoreEnoent, Ignorer, isEmptyDir, walkDir } from \"../lib/fs-utils\";\nimport { sleepUntil } from \"../lib/sleep\";\nimport type {\n FileSyncChangedEventInput,\n FileSyncDeletedEventInput,\n PublishFileSyncEventsMutation,\n PublishFileSyncEventsMutationVariables,\n RemoteFilesVersionQuery,\n RemoteFilesVersionQueryVariables,\n RemoteFileSyncEventsSubscription,\n RemoteFileSyncEventsSubscriptionVariables,\n} from \"../__generated__/graphql\";\n\nexport default class Sync extends BaseCommand {\n static override priority = 1;\n\n static override summary = \"Sync your Gadget application's source code to and from your local filesystem.\";\n\n static override usage = \"sync [--app=<value>] [DIRECTORY]\";\n\n static override description = dedent`\n Sync provides the ability to sync your Gadget application's source code to and from your local\n filesystem. While \\`ggt sync\\` is running, local file changes are immediately reflected within\n Gadget, while files that are changed remotely are immediately saved to your local filesystem.\n\n Use cases for this include:\n * Developing locally with your own editor like VSCode (https://code.visualstudio.com/)\n * Storing your source code in a Git repository like GitHub (https://github.com/)\n\n Sync includes the concept of a \\`.ignore\\` file. This file can contain a list of files and\n directories that won't be sent to Gadget when syncing.\n\n The following files and directories are always ignored:\n * .gadget\n * .git\n * node_modules\n\n Note:\n * Gadget applications only support installing dependencies with Yarn 1 (https://classic.yarnpkg.com/lang/en/).\n * Since file changes are immediately reflected in Gadget, avoid the following while \\`ggt sync\\` is running:\n * Deleting all your files\n * Moving all your files to a different directory\n `;\n\n static override args = [\n {\n name: \"directory\",\n description: \"The directory to sync files to. If the directory doesn't exist, it will be created.\",\n default: \".\",\n },\n ];\n\n static override flags = {\n app: app({\n summary: \"The Gadget application to sync files to.\",\n }),\n force: Flags.boolean({\n summary: \"Whether to sync even if we can't determine the state of your local files relative to your remote ones.\",\n default: false,\n }),\n \"file-push-delay\": Flags.integer({\n summary: \"Delay in milliseconds before pushing files to your app.\",\n helpGroup: \"file\",\n helpValue: \"ms\",\n default: 100,\n hidden: true,\n }),\n \"file-stability-threshold\": Flags.integer({\n name: \"file-stability-threshold\",\n summary: \"Time in milliseconds a file's size must remain the same.\",\n helpGroup: \"file\",\n helpValue: \"ms\",\n default: 500,\n hidden: true,\n }),\n \"file-poll-interval\": Flags.integer({\n name: \"file-poll-interval\",\n description: \"Interval in milliseconds between polling a file's size.\",\n helpGroup: \"file\",\n helpValue: \"ms\",\n default: 100,\n hidden: true,\n }),\n };\n\n static override examples = [\n dedent`\n $ ggt sync --app my-app ~/gadget/my-app\n Ready\n Received\n ← routes/GET.js\n ← user/signUp/signIn.js\n Sent\n → routes/GET.js\n ^C Stopping... (press Ctrl+C again to force)\n Done\n `,\n dedent`\n # These are equivalent\n $ ggt sync -a my-app\n $ ggt sync --app my-app\n $ ggt sync --app my-app.gadget.app\n $ ggt sync --app https://my-app.gadget.app\n $ ggt sync --app https://my-app.gadget.app/edit\n `,\n ];\n\n override requireUser = true;\n\n status = SyncStatus.STARTING;\n\n dir!: string;\n\n recentWrites = new Set();\n\n encoder = new TextEncoder();\n\n decoder = new TextDecoder();\n\n filePushDelay!: number;\n\n queue = new PQueue({ concurrency: 1 });\n\n client!: Client;\n\n ignorer!: Ignorer;\n\n watcher!: FSWatcher;\n\n metadata = {\n app: \"\",\n filesVersion: \"0\",\n mtime: 0,\n };\n\n publish!: DebouncedFunc<() => void>;\n\n stop!: (error?: unknown) => Promise<void>;\n\n relative(to: string): string {\n return path.relative(this.dir, to);\n }\n\n absolute(...pathSegments: string[]): string {\n return path.resolve(this.dir, ...pathSegments);\n }\n\n normalize(filepath: string): string {\n return normalizePath(path.isAbsolute(filepath) ? this.relative(filepath) : filepath);\n }\n\n logPaths(filepaths: string[], { limit = 10, sep = \"-\" } = {}): void {\n let logged = 0;\n for (const filepath of filepaths) {\n this.log(`${sep} ${this.normalize(filepath)}`);\n if (++logged == limit && !this.debugEnabled) break;\n }\n\n if (filepaths.length > logged) {\n this.log(`… ${filepaths.length - logged} more`);\n }\n }\n\n override async init(): Promise<void> {\n await super.init();\n const { args, flags } = await this.parse(Sync);\n\n this.dir = path.resolve(args[\"directory\"] as string);\n\n const getApp = async (): Promise<string> => {\n if (flags.app) return flags.app;\n if (this.metadata.app) return this.metadata.app;\n const selected = await prompt<{ app: string }>({\n type: \"list\",\n name: \"app\",\n message: \"Please select the app to sync to.\",\n choices: await context.getAvailableApps().then((apps) => apps.map((app) => app.slug)),\n });\n return selected.app;\n };\n\n if (await isEmptyDir(this.dir)) {\n this.metadata.app = await getApp();\n } else {\n try {\n this.metadata = await fs.readJson(this.absolute(\".gadget\", \"sync.json\"));\n if (!this.metadata.app) {\n this.metadata.app = await getApp();\n }\n } catch (error) {\n if (!flags.force) {\n throw new InvalidSyncFileError(error, this, flags.app);\n }\n this.metadata.app = await getApp();\n }\n }\n\n if (flags.app && flags.app !== this.metadata.app && !flags.force) {\n throw new FlagError(\n { name: \"app\", char: \"a\" },\n dedent`\n You were about to sync the following app to the following directory:\n\n ${flags.app} → ${this.dir}\n\n However, that directory has already been synced with this app:\n\n ${this.metadata.app}\n\n If you're sure that you want to sync \"${flags.app}\" to \"${this.dir}\", run \\`ggt sync\\` again with the \\`--force\\` flag:\n\n $ ggt sync ${this.argv.join(\" \")} --force\n `\n );\n }\n\n await context.setApp(this.metadata.app);\n\n this.client = new Client();\n\n this.filePushDelay = flags[\"file-push-delay\"];\n\n // local files/folders that should never be published\n this.ignorer = new Ignorer(this.dir, [\"node_modules\", \".gadget\", \".git\"]);\n\n this.watcher = new FSWatcher({\n ignored: (filepath) => this.ignorer.ignores(filepath),\n // don't emit an event for every watched file on boot\n ignoreInitial: true,\n // make sure stats are always present on add/change events\n alwaysStat: true,\n // wait for the entire file to be written before emitting add/change events\n awaitWriteFinish: { pollInterval: flags[\"file-poll-interval\"], stabilityThreshold: flags[\"file-stability-threshold\"] },\n });\n\n this.debug(\"starting\");\n\n if (!which.sync(\"yarn\", { nothrow: true })) {\n throw new YarnNotFoundError();\n }\n\n await fs.ensureDir(this.dir);\n\n const { remoteFilesVersion } = await this.client.queryUnwrap({ query: REMOTE_FILES_VERSION_QUERY });\n const hasRemoteChanges = BigInt(remoteFilesVersion) > BigInt(this.metadata.filesVersion);\n\n const getChangedFiles = async (): Promise<Map<string, Stats>> => {\n const files = new Map();\n for await (const filepath of walkDir(this.dir, { ignorer: this.ignorer })) {\n const stats = await fs.stat(filepath);\n if (stats.mtime.getTime() > this.metadata.mtime) {\n files.set(this.absolute(filepath), stats);\n }\n }\n return files;\n };\n\n const changedFiles = await getChangedFiles();\n const hasLocalChanges = changedFiles.size > 0;\n if (hasLocalChanges) {\n this.log(\"Local files have changed since the last sync\");\n this.logPaths(Array.from(changedFiles.keys()), { limit: changedFiles.size });\n this.log();\n }\n\n this.debug(\"init %o\", { metadata: this.metadata, remoteFilesVersion, hasRemoteChanges, hasLocalChanges });\n\n let action: Action | undefined;\n if (hasLocalChanges) {\n ({ action } = await prompt({\n type: \"list\",\n name: \"action\",\n choices: [Action.CANCEL, Action.MERGE, Action.RESET],\n message: hasRemoteChanges ? \"Remote files have also changed. How would you like to proceed?\" : \"How would you like to proceed?\",\n }));\n }\n\n switch (action) {\n case Action.MERGE: {\n // get all the changed files again in case more changed\n const files = await getChangedFiles();\n\n // we purposefully don't set the returned remoteFilesVersion here because we haven't processed the in-between versions yet\n await this.client.queryUnwrap({\n query: PUBLISH_FILE_SYNC_EVENTS_MUTATION,\n variables: {\n input: {\n expectedRemoteFilesVersion: remoteFilesVersion,\n changed: await pMap(files, async ([filepath, stats]) => {\n if (stats.mtime.getTime() > this.metadata.mtime) {\n this.metadata.mtime = stats.mtime.getTime();\n }\n\n return {\n path: this.normalize(filepath),\n mode: stats.mode,\n content: this.decoder.decode(await fs.readFile(filepath)),\n };\n }),\n deleted: [],\n },\n },\n });\n break;\n }\n case Action.RESET: {\n await pMap(changedFiles, ([filepath]) => fs.remove(filepath));\n this.metadata.filesVersion = \"0\";\n break;\n }\n case Action.CANCEL: {\n process.exit(0);\n }\n }\n\n this.debug(\"started\");\n }\n\n async run(): Promise<void> {\n let error: unknown;\n\n this.stop = async (e?: unknown) => {\n if (this.status != SyncStatus.RUNNING) return;\n\n error = e;\n this.debug(\"stopping\");\n this.status = SyncStatus.STOPPING;\n\n try {\n unsubscribe();\n this.watcher.removeAllListeners();\n this.publish.flush();\n await this.queue.onIdle();\n } finally {\n await fs.outputJSON(this.absolute(\".gadget\", \"sync.json\"), this.metadata, { spaces: 2 });\n await Promise.allSettled([this.watcher.close(), this.client.dispose()]);\n\n this.debug(\"stopped\");\n this.status = SyncStatus.STOPPED;\n }\n };\n\n for (const signal of [\"SIGINT\", \"SIGTERM\"] as const) {\n process.on(signal, () => {\n if (this.status != SyncStatus.RUNNING) return;\n\n this.log(\" Stopping... (press Ctrl+C again to force)\");\n void this.stop();\n\n // When ggt is run via npx, and the user presses Ctrl+C, npx sends SIGINT twice in quick succession. In order to prevent the second\n // SIGINT from triggering the force exit listener, we wait a bit before registering it. This is a bit of a hack, but it works.\n setTimeout(() => {\n process.once(signal, () => {\n this.log(\" Exiting immediately. Note that files may not have finished syncing.\");\n process.exit(1);\n });\n }, 100).unref();\n });\n }\n\n const unsubscribe = this.client.subscribeUnwrap(\n {\n query: REMOTE_FILE_SYNC_EVENTS_SUBSCRIPTION,\n variables: () => ({ localFilesVersion: this.metadata.filesVersion }),\n },\n {\n error: (error) => void this.stop(error),\n next: ({ remoteFileSyncEvents: { remoteFilesVersion, changed, deleted } }) => {\n const remoteFiles = new Map([...deleted, ...changed].map((e) => [e.path, e]));\n\n void this.queue\n .add(async () => {\n if (!remoteFiles.size) {\n // we still need to update filesVersion, otherwise our expectedFilesVersion will be behind the next time we publish\n this.metadata.filesVersion = remoteFilesVersion;\n return;\n }\n\n this.log(\"Received\");\n this.logPaths(Array.from(remoteFiles.keys()), { sep: \"←\" });\n\n await pMap(\n remoteFiles,\n async ([relativePath, file]) => {\n const filepath = this.absolute(relativePath);\n this.recentWrites.add(filepath);\n\n if (\"content\" in file) {\n await fs.ensureDir(path.dirname(filepath), { mode: 0o755 });\n if (!file.path.endsWith(\"/\")) {\n await fs.writeFile(filepath, this.encoder.encode(file.content), { mode: file.mode });\n }\n if (filepath == this.absolute(\"yarn.lock\")) {\n await execa(\"yarn\", [\"install\"], { cwd: this.dir }).catch((err) => {\n this.debug(\"yarn install failed\");\n this.debug(err.message);\n });\n }\n } else {\n await fs.remove(filepath);\n }\n\n if (filepath == this.ignorer.filepath) {\n this.ignorer.reload();\n }\n },\n { stopOnError: false }\n );\n\n this.metadata.filesVersion = remoteFilesVersion;\n })\n .catch(this.stop);\n },\n }\n );\n\n const localFilesBuffer = new Map<string, { mode: number; mtime: number } | false>();\n\n this.publish = debounce(() => {\n const localFiles = new Map(localFilesBuffer.entries());\n localFilesBuffer.clear();\n\n void this.queue\n .add(async () => {\n const changed: FileSyncChangedEventInput[] = [];\n const deleted: FileSyncDeletedEventInput[] = [];\n\n await pMap(\n localFiles,\n async ([filepath, file]) => {\n if (file) {\n try {\n changed.push({\n path: this.normalize(filepath),\n mode: file.mode,\n content: this.decoder.decode(await fs.readFile(filepath)),\n });\n } catch (error) {\n // A file could have been changed and then deleted before we process the change event, so the readFile above will raise\n // an ENOENT. This is normal operation, so just ignore this event.\n ignoreEnoent(error);\n }\n } else {\n deleted.push({ path: this.normalize(filepath) });\n }\n },\n { stopOnError: false }\n );\n\n if (changed.length > 0 || deleted.length > 0) {\n this.log(\"Sent\");\n this.logPaths(Array.from(localFiles.keys()), { sep: \"→\" });\n\n const data = await this.client.queryUnwrap({\n query: PUBLISH_FILE_SYNC_EVENTS_MUTATION,\n variables: { input: { expectedRemoteFilesVersion: this.metadata.filesVersion, changed, deleted } },\n });\n\n const { remoteFilesVersion } = data.publishFileSyncEvents;\n this.debug(\"remote files version after publishing %s\", remoteFilesVersion);\n\n if (BigInt(remoteFilesVersion) > BigInt(this.metadata.filesVersion)) {\n this.metadata.filesVersion = remoteFilesVersion;\n }\n }\n })\n .catch(this.stop);\n }, this.filePushDelay);\n\n this.watcher\n .add(`${this.dir}/**/*`)\n .on(\"error\", (error) => void this.stop(error))\n .on(\"all\", (event, filepath, stats) => {\n const relativePath = this.relative(filepath);\n\n if (event === \"addDir\") {\n this.debug(\"skipping event caused by added directory %s\", relativePath);\n return;\n }\n\n if (stats?.isSymbolicLink?.()) {\n this.debug(\"skipping event caused by symlink %s\", relativePath);\n return;\n }\n\n if (filepath == this.ignorer.filepath) {\n this.ignorer.reload();\n } else if (this.ignorer.ignores(filepath)) {\n this.debug(\"skipping event caused by ignored file %s\", relativePath);\n return;\n }\n\n // we only update the mtime if the file is not ignored, because if we restart and the mtime is set to an ignored file, then it could\n // be greater than the mtime of all non ignored files and we'll think that local files have changed when only an ignored one has\n if (stats && stats.mtime.getTime() > this.metadata.mtime) {\n this.metadata.mtime = stats.mtime.getTime();\n }\n\n if (this.recentWrites.delete(filepath)) {\n this.debug(\"skipping event caused by recent write %s\", relativePath);\n return;\n }\n\n this.debug(\"file changed %s\", relativePath);\n\n switch (event) {\n case \"add\":\n case \"change\":\n assert(stats, \"missing stats on add/change event\");\n localFilesBuffer.set(filepath, { mode: stats.mode, mtime: stats.mtime.getTime() });\n break;\n case \"unlink\":\n case \"unlinkDir\":\n localFilesBuffer.set(filepath, false);\n break;\n }\n\n this.publish();\n });\n\n this.log(\"Ready\");\n this.status = SyncStatus.RUNNING;\n\n await sleepUntil(() => this.status == SyncStatus.STOPPED, { timeout: Infinity });\n\n if (error) {\n this.notify({ subtitle: \"Uh oh!\", message: \"An error occurred while syncing files\" });\n throw error;\n } else {\n this.log(\"Done\");\n }\n }\n}\n\nexport enum SyncStatus {\n STARTING,\n RUNNING,\n STOPPING,\n STOPPED,\n}\n\nexport enum Action {\n CANCEL = \"Cancel (Ctrl+C)\",\n MERGE = \"Merge local files with remote ones\",\n RESET = \"Reset local files to remote ones\",\n}\n\nexport const REMOTE_FILE_SYNC_EVENTS_SUBSCRIPTION: Query<\n RemoteFileSyncEventsSubscription,\n RemoteFileSyncEventsSubscriptionVariables\n> = /* GraphQL */ `\n subscription RemoteFileSyncEvents($localFilesVersion: String!) {\n remoteFileSyncEvents(localFilesVersion: $localFilesVersion) {\n remoteFilesVersion\n changed {\n path\n mode\n content\n }\n deleted {\n path\n }\n }\n }\n`;\n\nexport const REMOTE_FILES_VERSION_QUERY: Query<RemoteFilesVersionQuery, RemoteFilesVersionQueryVariables> = /* GraphQL */ `\n query RemoteFilesVersion {\n remoteFilesVersion\n }\n`;\n\nexport const PUBLISH_FILE_SYNC_EVENTS_MUTATION: Query<\n PublishFileSyncEventsMutation,\n PublishFileSyncEventsMutationVariables\n> = /* GraphQL */ `\n mutation PublishFileSyncEvents($input: PublishFileSyncEventsInput!) {\n publishFileSyncEvents(input: $input) {\n remoteFilesVersion\n }\n }\n`;\n"]}
1
+ {"version":3,"file":"sync.js","sourceRoot":"","sources":["../../src/commands/sync.ts"],"names":[],"mappings":";;;;AAAA,sCAAoC;AACpC,4DAA4B;AAC5B,uCAAqC;AACrC,0DAA0B;AAE1B,gEAA0B;AAC1B,uCAAkC;AAElC,mCAAkC;AAClC,mCAAkC;AAClC,4EAA2C;AAC3C,0DAAyB;AACzB,8DAA6B;AAC7B,wDAAwB;AACxB,kEAA+B;AAC/B,0DAA0B;AAC1B,sDAAkD;AAElD,0CAAuC;AACvC,4CAAyC;AACzC,0CAAmF;AACnF,wCAAmC;AACnC,8CAA6E;AAC7E,wCAA0C;AAW1C,sDAA4D;AAE5D,MAAqB,IAAK,SAAQ,0BAAW;IAA7C;;QA8FE;;;;mBAAuB,IAAI;WAAC;QAE5B;;;;mBAAS,UAAU,CAAC,QAAQ;WAAC;QAE7B;;;;;WAAa;QAEb;;;;mBAAe,IAAI,GAAG,EAAE;WAAC;QAEzB;;;;;WAAuB;QAEvB;;;;mBAAQ,IAAI,iBAAM,CAAC,EAAE,WAAW,EAAE,CAAC,EAAE,CAAC;WAAC;QAEvC;;;;;WAAgB;QAEhB;;;;;WAAkB;QAElB;;;;;WAAoB;QA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AC;AAEW,QAAA,0BAA0B,GAAmF;;;;CAIzH,CAAC;AAEW,QAAA,iCAAiC,GAG5B;;;;;;CAMjB,CAAC","sourcesContent":["import { Flags } from \"@oclif/core\";\nimport assert from \"assert\";\nimport { FSWatcher } from \"chokidar\";\nimport execa from \"execa\";\nimport type { Stats } from \"fs-extra\";\nimport fs from \"fs-extra\";\nimport { prompt } from \"inquirer\";\nimport type { DebouncedFunc } from \"lodash\";\nimport { isString } from \"lodash\";\nimport { debounce } from \"lodash\";\nimport normalizePath from \"normalize-path\";\nimport pMap from \"p-map\";\nimport PQueue from \"p-queue\";\nimport path from \"path\";\nimport dedent from \"ts-dedent\";\nimport which from \"which\";\nimport { BaseCommand } from \"../lib/base-command\";\nimport type { Query } from \"../lib/client\";\nimport { Client } from \"../lib/client\";\nimport { context } from \"../lib/context\";\nimport { FlagError, InvalidSyncFileError, YarnNotFoundError } from \"../lib/errors\";\nimport { app } from \"../lib/flags\";\nimport { ignoreEnoent, Ignorer, isEmptyDir, walkDir } from \"../lib/fs-utils\";\nimport { sleepUntil } from \"../lib/sleep\";\nimport type {\n FileSyncChangedEventInput,\n FileSyncDeletedEventInput,\n PublishFileSyncEventsMutation,\n PublishFileSyncEventsMutationVariables,\n RemoteFilesVersionQuery,\n RemoteFilesVersionQueryVariables,\n RemoteFileSyncEventsSubscription,\n RemoteFileSyncEventsSubscriptionVariables,\n} from \"../__generated__/graphql\";\nimport { FileSyncEncoding } from \"../__generated__/graphql\";\n\nexport default class Sync extends BaseCommand {\n static override priority = 1;\n\n static override summary = \"Sync your Gadget application's source code to and from your local filesystem.\";\n\n static override usage = \"sync [--app=<value>] [DIRECTORY]\";\n\n static override description = dedent`\n Sync provides the ability to sync your Gadget application's source code to and from your local\n filesystem. While \\`ggt sync\\` is running, local file changes are immediately reflected within\n Gadget, while files that are changed remotely are immediately saved to your local filesystem.\n\n Use cases for this include:\n * Developing locally with your own editor like VSCode (https://code.visualstudio.com/)\n * Storing your source code in a Git repository like GitHub (https://github.com/)\n\n Sync includes the concept of a \\`.ignore\\` file. This file can contain a list of files and\n directories that won't be sent to Gadget when syncing.\n\n The following files and directories are always ignored:\n * .gadget\n * .git\n * node_modules\n\n Note:\n * Gadget applications only support installing dependencies with Yarn 1 (https://classic.yarnpkg.com/lang/en/).\n * Since file changes are immediately reflected in Gadget, avoid the following while \\`ggt sync\\` is running:\n * Deleting all your files\n * Moving all your files to a different directory\n `;\n\n static override args = [\n {\n name: \"directory\",\n description: \"The directory to sync files to. If the directory doesn't exist, it will be created.\",\n default: \".\",\n },\n ];\n\n static override flags = {\n app: app({\n summary: \"The Gadget application to sync files to.\",\n }),\n force: Flags.boolean({\n summary: \"Whether to sync even if we can't determine the state of your local files relative to your remote ones.\",\n default: false,\n }),\n \"file-push-delay\": Flags.integer({\n summary: \"Delay in milliseconds before pushing files to your app.\",\n helpGroup: \"file\",\n helpValue: \"ms\",\n default: 100,\n hidden: true,\n }),\n \"file-stability-threshold\": Flags.integer({\n name: \"file-stability-threshold\",\n summary: \"Time in milliseconds a file's size must remain the same.\",\n helpGroup: \"file\",\n helpValue: \"ms\",\n default: 500,\n hidden: true,\n }),\n \"file-poll-interval\": Flags.integer({\n name: \"file-poll-interval\",\n description: \"Interval in milliseconds between polling a file's size.\",\n helpGroup: \"file\",\n helpValue: \"ms\",\n default: 100,\n hidden: true,\n }),\n };\n\n static override examples = [\n dedent`\n $ ggt sync --app my-app ~/gadget/my-app\n Ready\n Received\n ← routes/GET.js\n ← user/signUp/signIn.js\n Sent\n → routes/GET.js\n ^C Stopping... (press Ctrl+C again to force)\n Done\n `,\n dedent`\n # These are equivalent\n $ ggt sync -a my-app\n $ ggt sync --app my-app\n $ ggt sync --app my-app.gadget.app\n $ ggt sync --app https://my-app.gadget.app\n $ ggt sync --app https://my-app.gadget.app/edit\n `,\n ];\n\n override requireUser = true;\n\n status = SyncStatus.STARTING;\n\n dir!: string;\n\n recentWrites = new Set();\n\n filePushDelay!: number;\n\n queue = new PQueue({ concurrency: 1 });\n\n client!: Client;\n\n ignorer!: Ignorer;\n\n watcher!: FSWatcher;\n\n metadata = {\n app: \"\",\n filesVersion: \"0\",\n mtime: 0,\n };\n\n publish!: DebouncedFunc<() => void>;\n\n stop!: (error?: unknown) => Promise<void>;\n\n relative(to: string): string {\n return path.relative(this.dir, to);\n }\n\n absolute(...pathSegments: string[]): string {\n return path.resolve(this.dir, ...pathSegments);\n }\n\n normalize(filepath: string): string {\n return normalizePath(path.isAbsolute(filepath) ? this.relative(filepath) : filepath);\n }\n\n logPaths(filepaths: string[], { limit = 10, sep = \"-\" } = {}): void {\n let logged = 0;\n for (const filepath of filepaths) {\n this.log(`${sep} ${this.normalize(filepath)}`);\n if (++logged == limit && !this.debugEnabled) break;\n }\n\n if (filepaths.length > logged) {\n this.log(`… ${filepaths.length - logged} more`);\n }\n }\n\n override async init(): Promise<void> {\n await super.init();\n const { args, flags } = await this.parse(Sync);\n\n assert(isString(args[\"directory\"]));\n\n this.dir =\n this.config.windows && args[\"directory\"].startsWith(\"~/\")\n ? path.join(this.config.home, args[\"directory\"].slice(2))\n : path.resolve(args[\"directory\"]);\n\n const getApp = async (): Promise<string> => {\n if (flags.app) return flags.app;\n if (this.metadata.app) return this.metadata.app;\n const selected = await prompt<{ app: string }>({\n type: \"list\",\n name: \"app\",\n message: \"Please select the app to sync to.\",\n choices: await context.getAvailableApps().then((apps) => apps.map((app) => app.slug)),\n });\n return selected.app;\n };\n\n if (await isEmptyDir(this.dir)) {\n this.metadata.app = await getApp();\n } else {\n try {\n this.metadata = await fs.readJson(this.absolute(\".gadget\", \"sync.json\"));\n if (!this.metadata.app) {\n this.metadata.app = await getApp();\n }\n } catch (error) {\n if (!flags.force) {\n throw new InvalidSyncFileError(error, this, flags.app);\n }\n this.metadata.app = await getApp();\n }\n }\n\n if (flags.app && flags.app !== this.metadata.app && !flags.force) {\n throw new FlagError(\n { name: \"app\", char: \"a\" },\n dedent`\n You were about to sync the following app to the following directory:\n\n ${flags.app} → ${this.dir}\n\n However, that directory has already been synced with this app:\n\n ${this.metadata.app}\n\n If you're sure that you want to sync \"${flags.app}\" to \"${this.dir}\", run \\`ggt sync\\` again with the \\`--force\\` flag:\n\n $ ggt sync ${this.argv.join(\" \")} --force\n `\n );\n }\n\n await context.setApp(this.metadata.app);\n\n this.client = new Client();\n\n this.filePushDelay = flags[\"file-push-delay\"];\n\n // local files/folders that should never be published\n this.ignorer = new Ignorer(this.dir, [\"node_modules\", \".gadget\", \".git\"]);\n\n this.watcher = new FSWatcher({\n ignored: (filepath) => this.ignorer.ignores(filepath),\n // don't emit an event for every watched file on boot\n ignoreInitial: true,\n // make sure stats are always present on add/change events\n alwaysStat: true,\n // wait for the entire file to be written before emitting add/change events\n awaitWriteFinish: { pollInterval: flags[\"file-poll-interval\"], stabilityThreshold: flags[\"file-stability-threshold\"] },\n });\n\n this.debug(\"starting\");\n\n if (!which.sync(\"yarn\", { nothrow: true })) {\n throw new YarnNotFoundError();\n }\n\n await fs.ensureDir(this.dir);\n\n const { remoteFilesVersion } = await this.client.queryUnwrap({ query: REMOTE_FILES_VERSION_QUERY });\n const hasRemoteChanges = BigInt(remoteFilesVersion) > BigInt(this.metadata.filesVersion);\n\n const getChangedFiles = async (): Promise<Map<string, Stats>> => {\n const files = new Map();\n for await (const filepath of walkDir(this.dir, { ignorer: this.ignorer })) {\n const stats = await fs.stat(filepath);\n if (stats.mtime.getTime() > this.metadata.mtime) {\n files.set(this.absolute(filepath), stats);\n }\n }\n return files;\n };\n\n const changedFiles = await getChangedFiles();\n const hasLocalChanges = changedFiles.size > 0;\n if (hasLocalChanges) {\n this.log(\"Local files have changed since the last sync\");\n this.logPaths(Array.from(changedFiles.keys()), { limit: changedFiles.size });\n this.log();\n }\n\n this.debug(\"init %o\", { metadata: this.metadata, remoteFilesVersion, hasRemoteChanges, hasLocalChanges });\n\n let action: Action | undefined;\n if (hasLocalChanges) {\n ({ action } = await prompt({\n type: \"list\",\n name: \"action\",\n choices: [Action.CANCEL, Action.MERGE, Action.RESET],\n message: hasRemoteChanges ? \"Remote files have also changed. How would you like to proceed?\" : \"How would you like to proceed?\",\n }));\n }\n\n switch (action) {\n case Action.MERGE: {\n // get all the changed files again in case more changed\n const files = await getChangedFiles();\n\n // we purposefully don't set the returned remoteFilesVersion here because we haven't processed the in-between versions yet\n await this.client.queryUnwrap({\n query: PUBLISH_FILE_SYNC_EVENTS_MUTATION,\n variables: {\n input: {\n expectedRemoteFilesVersion: remoteFilesVersion,\n changed: await pMap(files, async ([filepath, stats]) => {\n if (stats.mtime.getTime() > this.metadata.mtime) {\n this.metadata.mtime = stats.mtime.getTime();\n }\n\n return {\n path: this.normalize(filepath),\n mode: stats.mode,\n content: await fs.readFile(filepath, \"base64\"),\n encoding: FileSyncEncoding.Base64,\n };\n }),\n deleted: [],\n },\n },\n });\n break;\n }\n case Action.RESET: {\n await pMap(changedFiles, ([filepath]) => fs.remove(filepath));\n this.metadata.filesVersion = \"0\";\n break;\n }\n case Action.CANCEL: {\n process.exit(0);\n }\n }\n\n this.debug(\"started\");\n }\n\n async run(): Promise<void> {\n let error: unknown;\n\n this.stop = async (e?: unknown) => {\n if (this.status != SyncStatus.RUNNING) return;\n\n error = e;\n this.debug(\"stopping\");\n this.status = SyncStatus.STOPPING;\n\n try {\n unsubscribe();\n this.watcher.removeAllListeners();\n this.publish.flush();\n await this.queue.onIdle();\n } finally {\n await fs.outputJSON(this.absolute(\".gadget\", \"sync.json\"), this.metadata, { spaces: 2 });\n await Promise.allSettled([this.watcher.close(), this.client.dispose()]);\n\n this.debug(\"stopped\");\n this.status = SyncStatus.STOPPED;\n }\n };\n\n for (const signal of [\"SIGINT\", \"SIGTERM\"] as const) {\n process.on(signal, () => {\n if (this.status != SyncStatus.RUNNING) return;\n\n this.log(\" Stopping... (press Ctrl+C again to force)\");\n void this.stop();\n\n // When ggt is run via npx, and the user presses Ctrl+C, npx sends SIGINT twice in quick succession. In order to prevent the second\n // SIGINT from triggering the force exit listener, we wait a bit before registering it. This is a bit of a hack, but it works.\n setTimeout(() => {\n process.once(signal, () => {\n this.log(\" Exiting immediately. Note that files may not have finished syncing.\");\n process.exit(1);\n });\n }, 100).unref();\n });\n }\n\n const unsubscribe = this.client.subscribeUnwrap(\n {\n query: REMOTE_FILE_SYNC_EVENTS_SUBSCRIPTION,\n variables: () => ({ localFilesVersion: this.metadata.filesVersion }),\n },\n {\n error: (error) => void this.stop(error),\n next: ({ remoteFileSyncEvents: { remoteFilesVersion, changed, deleted } }) => {\n const remoteFiles = new Map([...deleted, ...changed].map((e) => [e.path, e]));\n\n void this.queue\n .add(async () => {\n if (!remoteFiles.size) {\n // we still need to update filesVersion, otherwise our expectedFilesVersion will be behind the next time we publish\n this.metadata.filesVersion = remoteFilesVersion;\n return;\n }\n\n this.log(\"Received\");\n this.logPaths(Array.from(remoteFiles.keys()), { sep: \"←\" });\n\n await pMap(\n remoteFiles,\n async ([relativePath, file]) => {\n const filepath = this.absolute(relativePath);\n this.recentWrites.add(filepath);\n\n if (\"content\" in file) {\n await fs.ensureDir(path.dirname(filepath), { mode: 0o755 });\n if (!file.path.endsWith(\"/\")) {\n await fs.writeFile(filepath, Buffer.from(file.content, file.encoding ?? FileSyncEncoding.Utf8), { mode: file.mode });\n }\n if (filepath == this.absolute(\"yarn.lock\")) {\n await execa(\"yarn\", [\"install\"], { cwd: this.dir }).catch((err) => {\n this.debug(\"yarn install failed\");\n this.debug(err.message);\n });\n }\n } else {\n await fs.remove(filepath);\n }\n\n if (filepath == this.ignorer.filepath) {\n this.ignorer.reload();\n }\n },\n { stopOnError: false }\n );\n\n this.metadata.filesVersion = remoteFilesVersion;\n })\n .catch(this.stop);\n },\n }\n );\n\n const localFilesBuffer = new Map<string, { mode: number; mtime: number } | false>();\n\n this.publish = debounce(() => {\n const localFiles = new Map(localFilesBuffer.entries());\n localFilesBuffer.clear();\n\n void this.queue\n .add(async () => {\n const changed: FileSyncChangedEventInput[] = [];\n const deleted: FileSyncDeletedEventInput[] = [];\n\n await pMap(\n localFiles,\n async ([filepath, file]) => {\n if (file) {\n try {\n changed.push({\n path: this.normalize(filepath),\n mode: file.mode,\n content: await fs.readFile(filepath, \"base64\"),\n encoding: FileSyncEncoding.Base64,\n });\n } catch (error) {\n // A file could have been changed and then deleted before we process the change event, so the readFile above will raise\n // an ENOENT. This is normal operation, so just ignore this event.\n ignoreEnoent(error);\n }\n } else {\n deleted.push({ path: this.normalize(filepath) });\n }\n },\n { stopOnError: false }\n );\n\n if (changed.length > 0 || deleted.length > 0) {\n this.log(\"Sent\");\n this.logPaths(Array.from(localFiles.keys()), { sep: \"→\" });\n\n const data = await this.client.queryUnwrap({\n query: PUBLISH_FILE_SYNC_EVENTS_MUTATION,\n variables: { input: { expectedRemoteFilesVersion: this.metadata.filesVersion, changed, deleted } },\n });\n\n const { remoteFilesVersion } = data.publishFileSyncEvents;\n this.debug(\"remote files version after publishing %s\", remoteFilesVersion);\n\n if (BigInt(remoteFilesVersion) > BigInt(this.metadata.filesVersion)) {\n this.metadata.filesVersion = remoteFilesVersion;\n }\n }\n })\n .catch(this.stop);\n }, this.filePushDelay);\n\n this.watcher\n .add(`${this.dir}/**/*`)\n .on(\"error\", (error) => void this.stop(error))\n .on(\"all\", (event, filepath, stats) => {\n const relativePath = this.relative(filepath);\n\n if (event === \"addDir\") {\n this.debug(\"skipping event caused by added directory %s\", relativePath);\n return;\n }\n\n if (stats?.isSymbolicLink?.()) {\n this.debug(\"skipping event caused by symlink %s\", relativePath);\n return;\n }\n\n if (filepath == this.ignorer.filepath) {\n this.ignorer.reload();\n } else if (this.ignorer.ignores(filepath)) {\n this.debug(\"skipping event caused by ignored file %s\", relativePath);\n return;\n }\n\n // we only update the mtime if the file is not ignored, because if we restart and the mtime is set to an ignored file, then it could\n // be greater than the mtime of all non ignored files and we'll think that local files have changed when only an ignored one has\n if (stats && stats.mtime.getTime() > this.metadata.mtime) {\n this.metadata.mtime = stats.mtime.getTime();\n }\n\n if (this.recentWrites.delete(filepath)) {\n this.debug(\"skipping event caused by recent write %s\", relativePath);\n return;\n }\n\n this.debug(\"file changed %s\", relativePath);\n\n switch (event) {\n case \"add\":\n case \"change\":\n assert(stats, \"missing stats on add/change event\");\n localFilesBuffer.set(filepath, { mode: stats.mode, mtime: stats.mtime.getTime() });\n break;\n case \"unlink\":\n case \"unlinkDir\":\n localFilesBuffer.set(filepath, false);\n break;\n }\n\n this.publish();\n });\n\n this.log(\"Ready\");\n this.status = SyncStatus.RUNNING;\n\n await sleepUntil(() => this.status == SyncStatus.STOPPED, { timeout: Infinity });\n\n if (error) {\n this.notify({ subtitle: \"Uh oh!\", message: \"An error occurred while syncing files\" });\n throw error;\n } else {\n this.log(\"Done\");\n }\n }\n}\n\nexport enum SyncStatus {\n STARTING,\n RUNNING,\n STOPPING,\n STOPPED,\n}\n\nexport enum Action {\n CANCEL = \"Cancel (Ctrl+C)\",\n MERGE = \"Merge local files with remote ones\",\n RESET = \"Reset local files to remote ones\",\n}\n\nexport const REMOTE_FILE_SYNC_EVENTS_SUBSCRIPTION: Query<\n RemoteFileSyncEventsSubscription,\n RemoteFileSyncEventsSubscriptionVariables\n> = /* GraphQL */ `\n subscription RemoteFileSyncEvents($localFilesVersion: String!) {\n remoteFileSyncEvents(localFilesVersion: $localFilesVersion, encoding: base64) {\n remoteFilesVersion\n changed {\n path\n mode\n content\n encoding\n }\n deleted {\n path\n }\n }\n }\n`;\n\nexport const REMOTE_FILES_VERSION_QUERY: Query<RemoteFilesVersionQuery, RemoteFilesVersionQueryVariables> = /* GraphQL */ `\n query RemoteFilesVersion {\n remoteFilesVersion\n }\n`;\n\nexport const PUBLISH_FILE_SYNC_EVENTS_MUTATION: Query<\n PublishFileSyncEventsMutation,\n PublishFileSyncEventsMutationVariables\n> = /* GraphQL */ `\n mutation PublishFileSyncEvents($input: PublishFileSyncEventsInput!) {\n publishFileSyncEvents(input: $input) {\n remoteFilesVersion\n }\n }\n`;\n"]}
@@ -26,6 +26,10 @@ class BaseCommand extends core_1.Command {
26
26
  writable: true,
27
27
  value: false
28
28
  });
29
+ // TODO: Remove this once the `@oclif/core` warnIfFlagDeprecated function checks global flags as well.
30
+ // warnIfFlagDeprecated throws a null pointer because it assumes all parsed flags are in the flags object (which is not the case for global flags).
31
+ // https://github.com/oclif/core/blob/11c5752cec838d08bb27cd55f0f1aa2390df3c5e/src/command.ts#L259
32
+ this.ctor.flags = { ...this.ctor.flags, ...BaseCommand.globalFlags };
29
33
  }
30
34
  /**
31
35
  * Indicates whether the command is being run with the `-D/--debug` flag.