@gadgetinc/ggt 0.4.10 → 1.0.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.
Files changed (142) hide show
  1. package/README.md +165 -93
  2. package/lib/__generated__/graphql.js +66 -1
  3. package/lib/__generated__/graphql.js.map +1 -1
  4. package/lib/commands/deploy.js +328 -230
  5. package/lib/commands/deploy.js.map +1 -1
  6. package/lib/commands/dev.js +445 -0
  7. package/lib/commands/dev.js.map +1 -0
  8. package/lib/commands/list.js +27 -19
  9. package/lib/commands/list.js.map +1 -1
  10. package/lib/commands/login.js +15 -11
  11. package/lib/commands/login.js.map +1 -1
  12. package/lib/commands/logout.js +5 -5
  13. package/lib/commands/logout.js.map +1 -1
  14. package/lib/commands/open.js +200 -0
  15. package/lib/commands/open.js.map +1 -0
  16. package/lib/commands/pull.js +128 -0
  17. package/lib/commands/pull.js.map +1 -0
  18. package/lib/commands/push.js +126 -0
  19. package/lib/commands/push.js.map +1 -0
  20. package/lib/commands/root.js +46 -28
  21. package/lib/commands/root.js.map +1 -1
  22. package/lib/commands/status.js +61 -0
  23. package/lib/commands/status.js.map +1 -0
  24. package/lib/commands/version.js +6 -6
  25. package/lib/commands/version.js.map +1 -1
  26. package/lib/commands/whoami.js +6 -6
  27. package/lib/commands/whoami.js.map +1 -1
  28. package/lib/ggt.js +33 -8
  29. package/lib/ggt.js.map +1 -1
  30. package/lib/main.js +5 -0
  31. package/lib/main.js.map +1 -0
  32. package/lib/services/app/api/api.js +191 -0
  33. package/lib/services/app/api/api.js.map +1 -0
  34. package/lib/services/app/api/operation.js +12 -0
  35. package/lib/services/app/api/operation.js.map +1 -0
  36. package/lib/services/app/app.js +44 -10
  37. package/lib/services/app/app.js.map +1 -1
  38. package/lib/services/app/{edit/client.js → client.js} +29 -19
  39. package/lib/services/app/client.js.map +1 -0
  40. package/lib/services/app/edit/edit.js +67 -31
  41. package/lib/services/app/edit/edit.js.map +1 -1
  42. package/lib/services/app/edit/operation.js +4 -3
  43. package/lib/services/app/edit/operation.js.map +1 -1
  44. package/lib/services/app/{edit/error.js → error.js} +6 -6
  45. package/lib/services/app/error.js.map +1 -0
  46. package/lib/services/command/arg.js +4 -4
  47. package/lib/services/command/arg.js.map +1 -1
  48. package/lib/services/command/command.js +9 -7
  49. package/lib/services/command/command.js.map +1 -1
  50. package/lib/services/command/context.js +82 -20
  51. package/lib/services/command/context.js.map +1 -1
  52. package/lib/services/config/config.js +4 -7
  53. package/lib/services/config/config.js.map +1 -1
  54. package/lib/services/config/env.js +1 -1
  55. package/lib/services/config/env.js.map +1 -1
  56. package/lib/services/filesync/changes.js +76 -37
  57. package/lib/services/filesync/changes.js.map +1 -1
  58. package/lib/services/filesync/conflicts.js +10 -9
  59. package/lib/services/filesync/conflicts.js.map +1 -1
  60. package/lib/services/filesync/directory.js +16 -1
  61. package/lib/services/filesync/directory.js.map +1 -1
  62. package/lib/services/filesync/error.js +96 -27
  63. package/lib/services/filesync/error.js.map +1 -1
  64. package/lib/services/filesync/filesync.js +448 -490
  65. package/lib/services/filesync/filesync.js.map +1 -1
  66. package/lib/services/filesync/hashes.js +8 -5
  67. package/lib/services/filesync/hashes.js.map +1 -1
  68. package/lib/services/filesync/strategy.js +59 -0
  69. package/lib/services/filesync/strategy.js.map +1 -0
  70. package/lib/services/filesync/sync-json.js +475 -0
  71. package/lib/services/filesync/sync-json.js.map +1 -0
  72. package/lib/services/http/auth.js +30 -1
  73. package/lib/services/http/auth.js.map +1 -1
  74. package/lib/services/http/http.js +5 -0
  75. package/lib/services/http/http.js.map +1 -1
  76. package/lib/services/output/confirm.js +149 -0
  77. package/lib/services/output/confirm.js.map +1 -0
  78. package/lib/services/output/footer.js +22 -0
  79. package/lib/services/output/footer.js.map +1 -0
  80. package/lib/services/output/log/format/pretty.js +2 -1
  81. package/lib/services/output/log/format/pretty.js.map +1 -1
  82. package/lib/services/output/log/logger.js +13 -5
  83. package/lib/services/output/log/logger.js.map +1 -1
  84. package/lib/services/output/log/structured.js +2 -2
  85. package/lib/services/output/log/structured.js.map +1 -1
  86. package/lib/services/output/output.js +197 -0
  87. package/lib/services/output/output.js.map +1 -0
  88. package/lib/services/output/print.js +31 -0
  89. package/lib/services/output/print.js.map +1 -0
  90. package/lib/services/output/problems.js +84 -0
  91. package/lib/services/output/problems.js.map +1 -0
  92. package/lib/services/output/prompt.js +173 -40
  93. package/lib/services/output/prompt.js.map +1 -1
  94. package/lib/services/output/report.js +63 -19
  95. package/lib/services/output/report.js.map +1 -1
  96. package/lib/services/output/select.js +198 -0
  97. package/lib/services/output/select.js.map +1 -0
  98. package/lib/services/output/spinner.js +141 -0
  99. package/lib/services/output/spinner.js.map +1 -0
  100. package/lib/services/output/sprint.js +38 -15
  101. package/lib/services/output/sprint.js.map +1 -1
  102. package/lib/services/output/symbols.js +23 -0
  103. package/lib/services/output/symbols.js.map +1 -0
  104. package/lib/services/output/table.js +98 -0
  105. package/lib/services/output/table.js.map +1 -0
  106. package/lib/services/output/timestamp.js +12 -0
  107. package/lib/services/output/timestamp.js.map +1 -0
  108. package/lib/services/output/update.js +29 -9
  109. package/lib/services/output/update.js.map +1 -1
  110. package/lib/services/user/session.js +4 -0
  111. package/lib/services/user/session.js.map +1 -1
  112. package/lib/services/user/user.js +15 -10
  113. package/lib/services/user/user.js.map +1 -1
  114. package/lib/services/util/assert.js +11 -0
  115. package/lib/services/util/assert.js.map +1 -0
  116. package/lib/services/util/boolean.js +2 -2
  117. package/lib/services/util/boolean.js.map +1 -1
  118. package/lib/services/util/function.js +45 -7
  119. package/lib/services/util/function.js.map +1 -1
  120. package/lib/services/util/is.js +23 -2
  121. package/lib/services/util/is.js.map +1 -1
  122. package/lib/services/util/json.js +16 -13
  123. package/lib/services/util/json.js.map +1 -1
  124. package/lib/services/util/object.js +2 -2
  125. package/lib/services/util/object.js.map +1 -1
  126. package/lib/services/util/promise.js +5 -2
  127. package/lib/services/util/promise.js.map +1 -1
  128. package/lib/services/util/types.js.map +1 -1
  129. package/npm-shrinkwrap.json +3415 -2973
  130. package/package.json +47 -40
  131. package/bin/dev.cmd +0 -3
  132. package/bin/dev.js +0 -14
  133. package/bin/run.cmd +0 -3
  134. package/bin/run.js +0 -5
  135. package/lib/commands/sync.js +0 -284
  136. package/lib/commands/sync.js.map +0 -1
  137. package/lib/services/app/edit/client.js.map +0 -1
  138. package/lib/services/app/edit/error.js.map +0 -1
  139. package/lib/services/output/log/printer.js +0 -120
  140. package/lib/services/output/log/printer.js.map +0 -1
  141. package/lib/services/output/stream.js +0 -54
  142. package/lib/services/output/stream.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/services/command/context.ts"],"sourcesContent":["import assert from \"node:assert\";\nimport type { EmptyObject } from \"type-fest\";\nimport type { RootArgs } from \"../../commands/root.js\";\nimport type { App } from \"../app/app.js\";\nimport { createLogger, type Logger } from \"../output/log/logger.js\";\nimport type { StructuredLoggerOptions } from \"../output/log/structured.js\";\nimport type { User } from \"../user/user.js\";\nimport { defaults, pick } from \"../util/object.js\";\nimport type { AnyVoid } from \"../util/types.js\";\nimport { parseArgs, type ArgsDefinition, type ArgsDefinitionResult, type ParseArgsOptions } from \"./arg.js\";\n\n/**\n * Represents the options that can be passed to {@linkcode Context.init}.\n */\nexport type ContextInit<Args extends ArgsDefinition> = ParseArgsOptions &\n StructuredLoggerOptions & {\n /**\n * The {@linkcode ArgsDefinition} to use to parse the arguments (`argv`).\n */\n parse?: Args;\n };\n\n/**\n * Represents the options that can be passed to {@linkcode Context.child}.\n *\n * @see {@linkcode Context.child}\n * @see {@linkcode ContextInit}\n */\nexport type ChildContextInit<Args extends ArgsDefinition, Parsed extends ArgsDefinitionResult<ArgsDefinition>> = Partial<\n ContextInit<Args>\n> & {\n /**\n * Replaces the parsed arguments of the parent context.\n */\n overwrite?: Partial<Omit<Parsed, \"_\">>;\n};\n\n/**\n * Represents the context of a command-line operation.\n */\nexport class Context<\n Args extends ArgsDefinition = EmptyObject,\n ParentArgs extends ArgsDefinition = RootArgs,\n ThisArgs extends ArgsDefinition = ParentArgs & Args,\n> extends AbortController {\n /**\n * The parsed command-line arguments for the current context and any\n * parent contexts.\n */\n readonly args: ArgsDefinitionResult<ThisArgs>;\n\n #log: Logger;\n #parent?: Context<ArgsDefinition, ParentArgs>;\n #user?: User;\n #app?: App;\n\n private constructor({\n args,\n log,\n parent,\n }: {\n parent?: Context<ArgsDefinition, ParentArgs>;\n args: ArgsDefinitionResult<ThisArgs>;\n log: Logger;\n }) {\n super();\n this.args = args;\n this.#log = log;\n this.#parent = parent;\n\n // in case this context is ...spread into another object\n this.abort = this.abort.bind(this);\n this.child = this.child.bind(this);\n this.onAbort = this.onAbort.bind(this);\n }\n\n /**\n * A {@linkcode Logger} that can print to stdout and log structured\n * messages to stderr.\n */\n get log(): Logger {\n return this.#log;\n }\n\n get user(): User | undefined {\n return this.#user ?? this.#parent?.user;\n }\n\n set user(user: User) {\n this.#user = user;\n if (this.#parent) {\n this.#parent.user = user;\n }\n\n this.#log = this.#log.child({ fields: { user: pick(user, [\"id\", \"name\", \"email\"]) } });\n }\n\n // eslint-disable-next-line @typescript-eslint/member-ordering\n get app(): App | undefined {\n return this.#app ?? this.#parent?.app;\n }\n\n set app(app: App) {\n this.#app = app;\n if (this.#parent) {\n this.#parent.app = app;\n }\n\n this.#log = this.#log.child({ fields: { app } });\n }\n\n /**\n * Initializes a new context.\n *\n * @see {@linkcode ContextInit}\n */\n static init<Args extends ArgsDefinition = EmptyObject>({ parse: spec, ...options }: ContextInit<Args>): Context<Args> {\n return new Context({\n args: spec ? parseArgs(spec, pick(options, [\"argv\", \"permissive\", \"stopAtPositional\"])) : ({} as ArgsDefinitionResult<Args>),\n log: createLogger(pick(options, [\"name\", \"fields\", \"devFields\"])),\n });\n }\n\n /**\n * Returns a new context that is a child of the current context.\n *\n * @see {@linkcode ChildContextInit}\n */\n child<ChildArgs extends ArgsDefinition = EmptyObject>({\n parse: spec,\n ...options\n }: ChildContextInit<ChildArgs, ArgsDefinitionResult<ThisArgs>>): Context<ChildArgs, ThisArgs> {\n const ctx = new Context<ChildArgs, ThisArgs>({\n parent: this,\n args: {\n ...this.args,\n ...options.overwrite,\n ...(spec\n ? parseArgs(spec, defaults(pick(options, [\"argv\", \"permissive\", \"stopAtPositional\"]), { argv: this.args._ }))\n : ({} as ArgsDefinitionResult<ChildArgs>)),\n },\n log: this.log.child(pick(options, [\"name\", \"fields\", \"devFields\"])),\n });\n\n this.onAbort(() => ctx.abort());\n\n return ctx;\n }\n\n /**\n * Registers a callback that will be called when the context is\n * aborted (e.g. when the user presses Ctrl+C).\n *\n * @param callback - The callback to call when the context is aborted.\n */\n onAbort(callback: OnAbort): void {\n this.signal.addEventListener(\n \"abort\",\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n async () => {\n try {\n assert(callback, \"callback must have been provided\");\n await callback(this.signal.reason);\n } catch (error: unknown) {\n this.log.error(\"error during abort\", { error });\n }\n },\n );\n }\n}\n\n/**\n * A callback that will be called when the context is aborted.\n */\nexport type OnAbort = (reason: unknown) => AnyVoid;\n"],"names":["assert","createLogger","defaults","pick","parseArgs","Context","AbortController","log","user","parent","child","fields","app","init","parse","spec","options","args","ctx","overwrite","argv","_","onAbort","abort","callback","signal","addEventListener","reason","error","bind"],"mappings":";;;;AAAA,OAAOA,YAAY,cAAc;AAIjC,SAASC,YAAY,QAAqB,0BAA0B;AAGpE,SAASC,QAAQ,EAAEC,IAAI,QAAQ,oBAAoB;AAEnD,SAASC,SAAS,QAA+E,WAAW;IA0C1G,oCACA,uCACA,qCACA;AAjBF;;CAEC,GACD,OAAO,MAAMC,gBAIHC;IAgCR;;;GAGC,GACD,IAAIC,MAAc;QAChB,gCAAO,IAAI,EAAEA;IACf;IAEA,IAAIC,OAAyB;QAC3B,OAAO,yBAAA,IAAI,EAAEA,mCAAQ,IAAI,EAAEC,UAAQD;IACrC;IAEA,IAAIA,KAAKA,IAAU,EAAE;uCACbA,OAAOA;QACb,6BAAI,IAAI,EAAEC,U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,KAAKa,SAAS;gBAAC;gBAAQ;gBAAU;aAAY;QACnE;QAEA,IAAI,CAACM,OAAO,CAAC,IAAMJ,IAAIK,KAAK;QAE5B,OAAOL;IACT;IAEA;;;;;GAKC,GACDI,QAAQE,QAAiB,EAAQ;QAC/B,IAAI,CAACC,MAAM,CAACC,gBAAgB,CAC1B,SACA,kEAAkE;QAClE;YACE,IAAI;gBACF1B,OAAOwB,UAAU;gBACjB,MAAMA,SAAS,IAAI,CAACC,MAAM,CAACE,MAAM;YACnC,EAAE,OAAOC,OAAgB;gBACvB,IAAI,CAACrB,GAAG,CAACqB,KAAK,CAAC,sBAAsB;oBAAEA;gBAAM;YAC/C;QACF;IAEJ;IAhHA,YAAoB,EAClBX,IAAI,EACJV,GAAG,EACHE,MAAM,EAKP,CAAE;QACD,KAAK;QApBP;;;GAGC,GACD,uBAASQ,QAAT,KAAA;QAEA,gCAAA;;mBAAA,KAAA;;QACA,gCAAA;;mBAAA,KAAA;;QACA,gCAAA;;mBAAA,KAAA;;QACA,gCAAA;;mBAAA,KAAA;;QAYE,IAAI,CAACA,IAAI,GAAGA;uCACNV,MAAMA;uCACNE,SAASA;QAEf,wDAAwD;QACxD,IAAI,CAACc,KAAK,GAAG,IAAI,CAACA,KAAK,CAACM,IAAI,CAAC,IAAI;QACjC,IAAI,CAACnB,KAAK,GAAG,IAAI,CAACA,KAAK,CAACmB,IAAI,CAAC,IAAI;QACjC,IAAI,CAACP,OAAO,GAAG,IAAI,CAACA,OAAO,CAACO,IAAI,CAAC,IAAI;IACvC;AA+FF"}
1
+ {"version":3,"sources":["../../../src/services/command/context.ts"],"sourcesContent":["import type { EmptyObject } from \"type-fest\";\nimport type { RootArgs } from \"../../commands/root.js\";\nimport type { Application, Environment } from \"../app/app.js\";\nimport { createLogger, type Logger } from \"../output/log/logger.js\";\nimport type { StructuredLoggerOptions } from \"../output/log/structured.js\";\nimport type { User } from \"../user/user.js\";\nimport { defaults, pick } from \"../util/object.js\";\nimport { PromiseSignal } from \"../util/promise.js\";\nimport type { AnyVoid } from \"../util/types.js\";\nimport { parseArgs, type ArgsDefinition, type ArgsDefinitionResult, type ParseArgsOptions } from \"./arg.js\";\nimport type { AvailableCommand } from \"./command.js\";\n\n/**\n * Represents the options that can be passed to {@linkcode Context.init}.\n */\nexport type ContextInit<Args extends ArgsDefinition> = ParseArgsOptions &\n StructuredLoggerOptions & {\n /**\n * The command that this context is running.\n */\n command?: AvailableCommand;\n\n /**\n * The {@linkcode ArgsDefinition} to use to parse the arguments (`argv`).\n */\n parse?: Args;\n };\n\n/**\n * Represents the options that can be passed to {@linkcode Context.child}.\n *\n * @see {@linkcode Context.child}\n * @see {@linkcode ContextInit}\n */\nexport type ChildContextInit<Args extends ArgsDefinition, Parsed extends ArgsDefinitionResult<ArgsDefinition>> = Partial<\n ContextInit<Args>\n> & {\n /**\n * Replaces the parsed arguments of the parent context.\n */\n overwrite?: Partial<Omit<Parsed, \"_\">>;\n};\n\n/**\n * Represents the context of a command-line operation.\n */\nexport class Context<\n Args extends ArgsDefinition = EmptyObject,\n ParentArgs extends ArgsDefinition = RootArgs,\n ThisArgs extends ArgsDefinition = ParentArgs & Args,\n> extends AbortController {\n /**\n * The parsed command-line arguments for the current context and any\n * parent contexts.\n */\n readonly args: ArgsDefinitionResult<ThisArgs>;\n\n /**\n * A promise that resolves when the context is aborted and all the\n * registered onAbort callbacks have finished.\n */\n readonly done = new PromiseSignal<void>();\n\n /**\n * The logger for the current context.\n */\n #log: Logger;\n\n /**\n * The callbacks that will be called when this context is aborted.\n */\n #onAborts: OnAbort[] = [];\n\n /**\n * The parent context, if any.\n */\n #parent?: Context<ArgsDefinition, ParentArgs>;\n\n /**\n * The command that this context is running.\n */\n #command?: AvailableCommand;\n\n /**\n * The user who is running this command, if any.\n */\n #user?: User;\n\n /**\n * The app this command is running against, if any.\n */\n #app?: Application;\n\n /**\n * The environment this command is running against, if any.\n */\n #env?: Environment;\n\n private constructor({\n parent,\n command,\n args,\n log,\n }: {\n parent?: Context<ArgsDefinition, ParentArgs>;\n command?: AvailableCommand;\n args: ArgsDefinitionResult<ThisArgs>;\n log: Logger;\n }) {\n super();\n this.args = args;\n this.#log = log;\n this.#parent = parent;\n this.#command = command;\n\n // in case this context is ...spread into another object\n this.abort = this.abort.bind(this);\n this.child = this.child.bind(this);\n this.onAbort = this.onAbort.bind(this);\n\n // when the context is aborted, call all the registered callbacks\n this.signal.addEventListener(\n \"abort\",\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n async () => {\n let error: unknown;\n\n // call the callbacks in reverse order, like go's defer\n for (const callback of this.#onAborts.reverse()) {\n try {\n await callback(this.signal.reason);\n } catch (e: unknown) {\n error = e;\n this.log.error(\"error during abort\", { error });\n }\n }\n\n if (error) {\n this.done.reject(error);\n } else {\n this.done.resolve();\n }\n },\n );\n }\n\n /**\n * A {@linkcode Logger} that can print to stdout and log structured\n * messages to stderr.\n */\n get log(): Logger {\n return this.#log;\n }\n\n get command(): AvailableCommand | \"root\" {\n return this.#command ?? this.#parent?.command ?? \"root\";\n }\n\n get user(): User | undefined {\n return this.#user ?? this.#parent?.user;\n }\n\n set user(user: User) {\n this.#user = user;\n if (this.#parent) {\n this.#parent.user = user;\n }\n\n this.#log = this.#log.child({\n fields: { user: { id: user.id } },\n devFields: { user },\n });\n }\n\n // eslint-disable-next-line @typescript-eslint/member-ordering\n get app(): Application | undefined {\n return this.#app ?? this.#parent?.app;\n }\n\n set app(app: Application) {\n this.#app = app;\n if (this.#parent) {\n this.#parent.app = app;\n }\n\n this.#log = this.#log.child({ fields: { app } });\n }\n\n // eslint-disable-next-line @typescript-eslint/member-ordering\n get env(): Environment | undefined {\n return this.#env ?? this.#parent?.env;\n }\n\n set env(env: Environment) {\n this.#env = env;\n if (this.#parent) {\n this.#parent.env = env;\n }\n\n this.#log = this.#log.child({ fields: { env } });\n }\n\n /**\n * Initializes a new context.\n *\n * @see {@linkcode ContextInit}\n */\n static init<Args extends ArgsDefinition = EmptyObject>({ parse: spec, ...options }: ContextInit<Args>): Context<Args> {\n return new Context({\n args: spec ? parseArgs(spec, pick(options, [\"argv\", \"permissive\", \"stopAtPositional\"])) : ({} as ArgsDefinitionResult<Args>),\n log: createLogger(pick(options, [\"name\", \"fields\", \"devFields\"])),\n });\n }\n\n /**\n * Returns a new context that is a child of the current context.\n *\n * @see {@linkcode ChildContextInit}\n */\n child<ChildArgs extends ArgsDefinition = EmptyObject>({\n parse: spec,\n command = this.#command,\n ...options\n }: ChildContextInit<ChildArgs, ArgsDefinitionResult<ThisArgs>>): Context<ChildArgs, ThisArgs> {\n const ctx = new Context<ChildArgs, ThisArgs>({\n parent: this,\n command,\n args: {\n ...this.args,\n ...options.overwrite,\n ...(spec\n ? parseArgs(spec, defaults(pick(options, [\"argv\", \"permissive\", \"stopAtPositional\"]), { argv: this.args._ }))\n : ({} as ArgsDefinitionResult<ChildArgs>)),\n },\n log: this.log.child(pick(options, [\"name\", \"fields\", \"devFields\"])),\n });\n\n this.onAbort(() => ctx.abort());\n\n return ctx;\n }\n\n /**\n * Registers a callback that will be called when the context is\n * aborted (e.g. when the user presses Ctrl+C).\n *\n * @param callback - The callback to call when the context is aborted.\n */\n onAbort(callback: OnAbort): void {\n this.#onAborts.push(callback);\n }\n}\n\n/**\n * A callback that will be called when the context is aborted.\n */\nexport type OnAbort = (reason: unknown) => AnyVoid;\n"],"names":["createLogger","defaults","pick","PromiseSignal","parseArgs","Context","AbortController","log","command","parent","user","child","fields","id","devFields","app","env","init","parse","spec","options","args","ctx","overwrite","argv","_","onAbort","abort","callback","onAborts","push","done","bind","signal","addEventListener","error","reverse","reason","e","reject","resolve"],"mappings":";;;;AAGA,SAASA,YAAY,QAAqB,0BAA0B;AAGpE,SAASC,QAAQ,EAAEC,IAAI,QAAQ,oBAAoB;AACnD,SAASC,aAAa,QAAQ,qBAAqB;AAEnD,SAASC,SAAS,QAA+E,WAAW;IAsD1G;;GAEC,GACD,oCAEA;;GAEC,GACD,yCAEA;;GAEC,GACD,uCAEA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mBAAA,KAAA;;QAKA,gCAAA;;mBAAuB,EAAE;;QAKzB,gCAAA;;mBAAA,KAAA;;QAKA,gCAAA;;mBAAA,KAAA;;QAKA,gCAAA;;mBAAA,KAAA;;QAKA,gCAAA;;mBAAA,KAAA;;QAKA,gCAAA;;mBAAA,KAAA;;QAcE,IAAI,CAACkB,IAAI,GAAGA;uCACNd,MAAMA;uCACNE,SAASA;uCACTD,UAAUA;QAEhB,wDAAwD;QACxD,IAAI,CAACmB,KAAK,GAAG,IAAI,CAACA,KAAK,CAACK,IAAI,CAAC,IAAI;QACjC,IAAI,CAACrB,KAAK,GAAG,IAAI,CAACA,KAAK,CAACqB,IAAI,CAAC,IAAI;QACjC,IAAI,CAACN,OAAO,GAAG,IAAI,CAACA,OAAO,CAACM,IAAI,CAAC,IAAI;QAErC,iEAAiE;QACjE,IAAI,CAACC,MAAM,CAACC,gBAAgB,CAC1B,SACA,kEAAkE;QAClE;YACE,IAAIC;YAEJ,uDAAuD;YACvD,KAAK,MAAMP,YAAY,yBAAA,IAAI,EAAEC,WAASO,OAAO,GAAI;gBAC/C,IAAI;oBACF,MAAMR,SAAS,IAAI,CAACK,MAAM,CAACI,MAAM;gBACnC,EAAE,OAAOC,GAAY;oBACnBH,QAAQG;oBACR,IAAI,CAAC/B,GAAG,CAAC4B,KAAK,CAAC,sBAAsB;wBAAEA;oBAAM;gBAC/C;YACF;YAEA,IAAIA,OAAO;gBACT,IAAI,CAACJ,IAAI,CAACQ,MAAM,CAACJ;YACnB,OAAO;gBACL,IAAI,CAACJ,IAAI,CAACS,OAAO;YACnB;QACF;IAEJ;AA2GF"}
@@ -6,12 +6,6 @@ import { Level, parseLevel } from "../output/log/level.js";
6
6
  import { env } from "./env.js";
7
7
  import { packageJson } from "./package-json.js";
8
8
  export const config = {
9
- get name () {
10
- return packageJson.name;
11
- },
12
- get version () {
13
- return packageJson.version;
14
- },
15
9
  get logLevel () {
16
10
  return parseLevel(process.env["GGT_LOG_LEVEL"], Level.PRINT);
17
11
  },
@@ -25,7 +19,7 @@ export const config = {
25
19
  *
26
20
  * @example "ggt/1.2.3 darwin-arm64 node-v16.0.0"
27
21
  */ get versionFull () {
28
- return `${this.name}/${this.version} ${this.platform}-${this.arch} node-${process.version}`;
22
+ return `${packageJson.name}/${packageJson.version} ${this.platform}-${this.arch} node-${process.version}`;
29
23
  },
30
24
  get arch () {
31
25
  return os.arch() === "ia32" ? "x86" : os.arch();
@@ -36,6 +30,9 @@ export const config = {
36
30
  get windows () {
37
31
  return process.platform === "win32";
38
32
  },
33
+ get windowsOrWsl () {
34
+ return this.windows || isWsl;
35
+ },
39
36
  get macos () {
40
37
  return process.platform === "darwin";
41
38
  },
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/services/config/config.ts"],"sourcesContent":["import isWsl from \"is-wsl\";\nimport os from \"node:os\";\nimport path from \"node:path\";\nimport process from \"node:process\";\nimport { Level, parseLevel } from \"../output/log/level.js\";\nimport { env } from \"./env.js\";\nimport { packageJson } from \"./package-json.js\";\n\nexport const config = {\n get name(): string {\n return packageJson.name;\n },\n\n get version(): string {\n return packageJson.version;\n },\n\n get logLevel() {\n return parseLevel(process.env[\"GGT_LOG_LEVEL\"], Level.PRINT);\n },\n\n get logFormat() {\n return process.env[\"GGT_LOG_FORMAT\"] === \"json\" ? \"json\" : \"pretty\";\n },\n\n /**\n * Returns the full version string including name, version, platform,\n * arch, and Node.js version. This is passed as the user agent for all\n * outgoing http requests.\n *\n * @example \"ggt/1.2.3 darwin-arm64 node-v16.0.0\"\n */\n get versionFull(): string {\n return `${this.name}/${this.version} ${this.platform}-${this.arch} node-${process.version}`;\n },\n\n get arch(): string {\n return os.arch() === \"ia32\" ? \"x86\" : os.arch();\n },\n\n get platform(): string {\n return isWsl ? \"wsl\" : os.platform();\n },\n\n get windows(): boolean {\n return process.platform === \"win32\";\n },\n\n get macos(): boolean {\n return process.platform === \"darwin\";\n },\n\n get shell(): string | undefined {\n const SHELL = process.env[\"SHELL\"] ?? os.userInfo().shell?.split(path.sep).pop();\n if (SHELL) {\n return SHELL.split(\"/\").at(-1);\n }\n if (this.windows && process.env[\"COMSPEC\"]) {\n return process.env[\"COMSPEC\"].split(/\\\\|\\//).at(-1);\n }\n return \"unknown\";\n },\n\n get homeDir(): string {\n if (process.env[\"HOME\"]) {\n return process.env[\"HOME\"];\n }\n\n if (this.windows) {\n if (process.env[\"HOMEDRIVE\"] && process.env[\"HOMEPATH\"]) {\n return path.join(process.env[\"HOMEDRIVE\"], process.env[\"HOMEPATH\"]);\n }\n if (process.env[\"USERPROFILE\"]) {\n return process.env[\"USERPROFILE\"];\n }\n }\n\n return os.homedir() || os.tmpdir();\n },\n\n /**\n * - Unix: `~/.config/ggt`\n * - Windows: `%LOCALAPPDATA%\\ggt`\n *\n * Can be overridden by `GGT_CONFIG_DIR`\n */\n get configDir(): string {\n if (process.env[\"GGT_CONFIG_DIR\"]) {\n return process.env[\"GGT_CONFIG_DIR\"];\n }\n\n const base = process.env[\"XDG_CONFIG_HOME\"] || (this.windows && process.env[\"LOCALAPPDATA\"]) || path.join(this.homeDir, \".config\");\n return path.join(base, \"ggt\");\n },\n\n /**\n * - Linux: `~/.cache/ggt`\n * - macOS: `~/Library/Caches/ggt`\n * - Windows: `%LOCALAPPDATA%\\ggt`\n *\n * Can be overridden with `GGT_CACHE_DIR`\n */\n get cacheDir(): string {\n if (process.env[\"GGT_CACHE_DIR\"]) {\n return process.env[\"GGT_CACHE_DIR\"];\n }\n\n if (this.macos) {\n return path.join(this.homeDir, \"Library/Caches/ggt\");\n }\n\n const base = process.env[\"XDG_CACHE_HOME\"] || (this.windows && process.env[\"LOCALAPPDATA\"]) || path.join(this.homeDir, \".cache\");\n return path.join(base, \"ggt\");\n },\n\n /**\n * - Unix: `~/.local/share/ggt`\n * - Windows: `%LOCALAPPDATA%\\ggt`\n *\n * Can be overridden with `GGT_DATA_DIR`\n */\n get dataDir(): string {\n if (process.env[\"GGT_DATA_DIR\"]) {\n return process.env[\"GGT_DATA_DIR\"];\n }\n\n const base = process.env[\"XDG_DATA_HOME\"] || (this.windows && process.env[\"LOCALAPPDATA\"]) || path.join(this.homeDir, \".local/share\");\n return path.join(base, \"ggt\");\n },\n\n /**\n * Domains for various Gadget services.\n */\n domains: {\n /**\n * The domain for the Gadget applications. This is where the user's application is hosted.\n */\n get app() {\n return process.env[\"GGT_GADGET_APP_DOMAIN\"] || (env.productionLike ? \"gadget.app\" : \"ggt.pub\");\n },\n\n /**\n * The domain for the Gadget services. This is where Gadget's API is hosted.\n */\n get services() {\n return process.env[\"GGT_GADGET_SERVICES_DOMAIN\"] || (env.productionLike ? \"app.gadget.dev\" : \"app.ggt.dev\");\n },\n },\n};\n\n/**\n * Returns an absolute path within the {@linkcode config.configDir}\n * directory.\n *\n * @param segments - The segments of the path to join.\n * @returns The absolute path to the file or directory.\n */\nexport const configPath = (...segments: string[]): string => path.join(config.configDir, ...segments);\n\n/**\n * Returns an absolute path within the {@linkcode config.homeDir}\n * directory.\n *\n * @param segments - The segments of the path to join.\n * @returns The absolute path to the file or directory.\n */\nexport const homePath = (...segments: string[]): string => path.join(config.homeDir, ...segments);\n"],"names":["isWsl","os","path","process","Level","parseLevel","env","packageJson","config","name","version","logLevel","PRINT","logFormat","versionFull","platform","arch","windows","macos","shell","SHELL","userInfo","split","sep","pop","at","homeDir","join","homedir","tmpdir","configDir","base","cacheDir","dataDir","domains","app","productionLike","services","configPath","segments","homePath"],"mappings":"AAAA,OAAOA,WAAW,SAAS;AAC3B,OAAOC,QAAQ,UAAU;AACzB,OAAOC,UAAU,YAAY;AAC7B,OAAOC,aAAa,eAAe;AACnC,SAASC,KAAK,EAAEC,UAAU,QAAQ,yBAAyB;AAC3D,SAASC,GAAG,QAAQ,WAAW;AAC/B,SAASC,WAAW,QAAQ,oBAAoB;AAEhD,OAAO,MAAMC,SAAS;IACpB,IAAIC,QAAe;QACjB,OAAOF,YAAYE,IAAI;IACzB;IAEA,IAAIC,WAAkB;QACpB,OAAOH,YAAYG,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,CAAC,eAAe;QACpC;QAEA,MAAMyB,OAAO5B,QAAQG,GAAG,CAAC,gBAAgB,IAAK,IAAI,CAACW,OAAO,IAAId,QAAQG,GAAG,CAAC,eAAe,IAAKJ,KAAKyB,IAAI,CAAC,IAAI,CAACD,OAAO,EAAE;QACtH,OAAOxB,KAAKyB,IAAI,CAACI,MAAM;IACzB;IAEA;;GAEC,GACDG,SAAS;QACP;;KAEC,GACD,IAAIC,OAAM;YACR,OAAOhC,QAAQG,GAAG,CAAC,wBAAwB,IAAKA,CAAAA,IAAI8B,cAAc,GAAG,eAAe,SAAQ;QAC9F;QAEA;;KAEC,GACD,IAAIC,YAAW;YACb,OAAOlC,QAAQG,GAAG,CAAC,6BAA6B,IAAKA,CAAAA,IAAI8B,cAAc,GAAG,mBAAmB,aAAY;QAC3G;IACF;AACF,EAAE;AAEF;;;;;;CAMC,GACD,OAAO,MAAME,aAAa,CAAC,GAAGC,WAA+BrC,KAAKyB,IAAI,CAACnB,OAAOsB,SAAS,KAAKS,UAAU;AAEtG;;;;;;CAMC,GACD,OAAO,MAAMC,WAAW,CAAC,GAAGD,WAA+BrC,KAAKyB,IAAI,CAACnB,OAAOkB,OAAO,KAAKa,UAAU"}
1
+ {"version":3,"sources":["../../../src/services/config/config.ts"],"sourcesContent":["import isWsl from \"is-wsl\";\nimport os from \"node:os\";\nimport path from \"node:path\";\nimport process from \"node:process\";\nimport { Level, parseLevel } from \"../output/log/level.js\";\nimport { env } from \"./env.js\";\nimport { packageJson } from \"./package-json.js\";\n\nexport const config = {\n get logLevel() {\n return parseLevel(process.env[\"GGT_LOG_LEVEL\"], Level.PRINT);\n },\n\n get logFormat() {\n return process.env[\"GGT_LOG_FORMAT\"] === \"json\" ? \"json\" : \"pretty\";\n },\n\n /**\n * Returns the full version string including name, version, platform,\n * arch, and Node.js version. This is passed as the user agent for all\n * outgoing http requests.\n *\n * @example \"ggt/1.2.3 darwin-arm64 node-v16.0.0\"\n */\n get versionFull(): string {\n return `${packageJson.name}/${packageJson.version} ${this.platform}-${this.arch} node-${process.version}`;\n },\n\n get arch(): string {\n return os.arch() === \"ia32\" ? \"x86\" : os.arch();\n },\n\n get platform(): NodeJS.Platform | \"wsl\" {\n return isWsl ? \"wsl\" : os.platform();\n },\n\n get windows(): boolean {\n return process.platform === \"win32\";\n },\n\n get windowsOrWsl(): boolean {\n return this.windows || isWsl;\n },\n\n get macos(): boolean {\n return process.platform === \"darwin\";\n },\n\n get shell(): string | undefined {\n const SHELL = process.env[\"SHELL\"] ?? os.userInfo().shell?.split(path.sep).pop();\n if (SHELL) {\n return SHELL.split(\"/\").at(-1);\n }\n if (this.windows && process.env[\"COMSPEC\"]) {\n return process.env[\"COMSPEC\"].split(/\\\\|\\//).at(-1);\n }\n return \"unknown\";\n },\n\n get homeDir(): string {\n if (process.env[\"HOME\"]) {\n return process.env[\"HOME\"];\n }\n\n if (this.windows) {\n if (process.env[\"HOMEDRIVE\"] && process.env[\"HOMEPATH\"]) {\n return path.join(process.env[\"HOMEDRIVE\"], process.env[\"HOMEPATH\"]);\n }\n if (process.env[\"USERPROFILE\"]) {\n return process.env[\"USERPROFILE\"];\n }\n }\n\n return os.homedir() || os.tmpdir();\n },\n\n /**\n * - Unix: `~/.config/ggt`\n * - Windows: `%LOCALAPPDATA%\\ggt`\n *\n * Can be overridden by `GGT_CONFIG_DIR`\n */\n get configDir(): string {\n if (process.env[\"GGT_CONFIG_DIR\"]) {\n return process.env[\"GGT_CONFIG_DIR\"];\n }\n\n const base = process.env[\"XDG_CONFIG_HOME\"] || (this.windows && process.env[\"LOCALAPPDATA\"]) || path.join(this.homeDir, \".config\");\n return path.join(base, \"ggt\");\n },\n\n /**\n * - Linux: `~/.cache/ggt`\n * - macOS: `~/Library/Caches/ggt`\n * - Windows: `%LOCALAPPDATA%\\ggt`\n *\n * Can be overridden with `GGT_CACHE_DIR`\n */\n get cacheDir(): string {\n if (process.env[\"GGT_CACHE_DIR\"]) {\n return process.env[\"GGT_CACHE_DIR\"];\n }\n\n if (this.macos) {\n return path.join(this.homeDir, \"Library/Caches/ggt\");\n }\n\n const base = process.env[\"XDG_CACHE_HOME\"] || (this.windows && process.env[\"LOCALAPPDATA\"]) || path.join(this.homeDir, \".cache\");\n return path.join(base, \"ggt\");\n },\n\n /**\n * - Unix: `~/.local/share/ggt`\n * - Windows: `%LOCALAPPDATA%\\ggt`\n *\n * Can be overridden with `GGT_DATA_DIR`\n */\n get dataDir(): string {\n if (process.env[\"GGT_DATA_DIR\"]) {\n return process.env[\"GGT_DATA_DIR\"];\n }\n\n const base = process.env[\"XDG_DATA_HOME\"] || (this.windows && process.env[\"LOCALAPPDATA\"]) || path.join(this.homeDir, \".local/share\");\n return path.join(base, \"ggt\");\n },\n\n /**\n * Domains for various Gadget services.\n */\n domains: {\n /**\n * The domain for the Gadget applications. This is where the user's application is hosted.\n */\n get app() {\n return process.env[\"GGT_GADGET_APP_DOMAIN\"] || (env.productionLike ? \"gadget.app\" : \"ggt.pub\");\n },\n\n /**\n * The domain for the Gadget services. This is where Gadget's API is hosted.\n */\n get services() {\n return process.env[\"GGT_GADGET_SERVICES_DOMAIN\"] || (env.productionLike ? \"app.gadget.dev\" : \"app.ggt.dev\");\n },\n },\n};\n\n/**\n * Returns an absolute path within the {@linkcode config.configDir}\n * directory.\n *\n * @param segments - The segments of the path to join.\n * @returns The absolute path to the file or directory.\n */\nexport const configPath = (...segments: string[]): string => path.join(config.configDir, ...segments);\n\n/**\n * Returns an absolute path within the {@linkcode config.homeDir}\n * directory.\n *\n * @param segments - The segments of the path to join.\n * @returns The absolute path to the file or directory.\n */\nexport const homePath = (...segments: string[]): string => path.join(config.homeDir, ...segments);\n"],"names":["isWsl","os","path","process","Level","parseLevel","env","packageJson","config","logLevel","PRINT","logFormat","versionFull","name","version","platform","arch","windows","windowsOrWsl","macos","shell","SHELL","userInfo","split","sep","pop","at","homeDir","join","homedir","tmpdir","configDir","base","cacheDir","dataDir","domains","app","productionLike","services","configPath","segments","homePath"],"mappings":"A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B,QAAQG,GAAG,CAAC,iBAAiB,IAAK,IAAI,CAACW,OAAO,IAAId,QAAQG,GAAG,CAAC,eAAe,IAAKJ,KAAK0B,IAAI,CAAC,IAAI,CAACD,OAAO,EAAE;QACvH,OAAOzB,KAAK0B,IAAI,CAACI,MAAM;IACzB;IAEA;;;;;GAKC,GACD,IAAIE,WAAkB;QACpB,IAAI/B,QAAQG,GAAG,CAAC,eAAe,EAAE;YAC/B,OAAOH,QAAQG,GAAG,CAAC,eAAe;QACpC;QAEA,MAAM0B,OAAO7B,QAAQG,GAAG,CAAC,gBAAgB,IAAK,IAAI,CAACW,OAAO,IAAId,QAAQG,GAAG,CAAC,eAAe,IAAKJ,KAAK0B,IAAI,CAAC,IAAI,CAACD,OAAO,EAAE;QACtH,OAAOzB,KAAK0B,IAAI,CAACI,MAAM;IACzB;IAEA;;GAEC,GACDG,SAAS;QACP;;KAEC,GACD,IAAIC,OAAM;YACR,OAAOjC,QAAQG,GAAG,CAAC,wBAAwB,IAAKA,CAAAA,IAAI+B,cAAc,GAAG,eAAe,SAAQ;QAC9F;QAEA;;KAEC,GACD,IAAIC,YAAW;YACb,OAAOnC,QAAQG,GAAG,CAAC,6BAA6B,IAAKA,CAAAA,IAAI+B,cAAc,GAAG,mBAAmB,aAAY;QAC3G;IACF;AACF,EAAE;AAEF;;;;;;CAMC,GACD,OAAO,MAAME,aAAa,CAAC,GAAGC,WAA+BtC,KAAK0B,IAAI,CAACpB,OAAOuB,SAAS,KAAKS,UAAU;AAEtG;;;;;;CAMC,GACD,OAAO,MAAMC,WAAW,CAAC,GAAGD,WAA+BtC,KAAK0B,IAAI,CAACpB,OAAOmB,OAAO,KAAKa,UAAU"}
@@ -1,6 +1,6 @@
1
1
  import process from "node:process";
2
2
  /**
3
- * Captures the name and nature of the environment
3
+ * Captures the current environment ggt is running in.
4
4
  */ export const env = {
5
5
  get value () {
6
6
  return process.env["GGT_ENV"] || "production";
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/services/config/env.ts"],"sourcesContent":["import process from \"node:process\";\n\n/**\n * Captures the name and nature of the environment\n */\nexport const env = {\n get value(): string {\n return process.env[\"GGT_ENV\"] || \"production\";\n },\n\n get productionLike(): boolean {\n return !this.developmentOrTestLike;\n },\n\n get developmentLike(): boolean {\n return this.value.startsWith(\"development\");\n },\n\n get testLike(): boolean {\n return this.value.startsWith(\"test\");\n },\n\n get developmentOrTestLike(): boolean {\n return this.developmentLike || this.testLike;\n },\n};\n"],"names":["process","env","value","productionLike","developmentOrTestLike","developmentLike","startsWith","testLike"],"mappings":"AAAA,OAAOA,aAAa,eAAe;AAEnC;;CAEC,GACD,OAAO,MAAMC,MAAM;IACjB,IAAIC,SAAgB;QAClB,OAAOF,QAAQC,GAAG,CAAC,UAAU,IAAI;IACnC;IAEA,IAAIE,kBAA0B;QAC5B,OAAO,CAAC,IAAI,CAACC,qBAAqB;IACpC;IAEA,IAAIC,mBAA2B;QAC7B,OAAO,IAAI,CAACH,KAAK,CAACI,UAAU,CAAC;IAC/B;IAEA,IAAIC,YAAoB;QACtB,OAAO,IAAI,CAACL,KAAK,CAACI,UAAU,CAAC;IAC/B;IAEA,IAAIF,yBAAiC;QACnC,OAAO,IAAI,CAACC,eAAe,IAAI,IAAI,CAACE,QAAQ;IAC9C;AACF,EAAE"}
1
+ {"version":3,"sources":["../../../src/services/config/env.ts"],"sourcesContent":["import process from \"node:process\";\n\n/**\n * Captures the current environment ggt is running in.\n */\nexport const env = {\n get value(): string {\n return process.env[\"GGT_ENV\"] || \"production\";\n },\n\n get productionLike(): boolean {\n return !this.developmentOrTestLike;\n },\n\n get developmentLike(): boolean {\n return this.value.startsWith(\"development\");\n },\n\n get testLike(): boolean {\n return this.value.startsWith(\"test\");\n },\n\n get developmentOrTestLike(): boolean {\n return this.developmentLike || this.testLike;\n },\n};\n"],"names":["process","env","value","productionLike","developmentOrTestLike","developmentLike","startsWith","testLike"],"mappings":"AAAA,OAAOA,aAAa,eAAe;AAEnC;;CAEC,GACD,OAAO,MAAMC,MAAM;IACjB,IAAIC,SAAgB;QAClB,OAAOF,QAAQC,GAAG,CAAC,UAAU,IAAI;IACnC;IAEA,IAAIE,kBAA0B;QAC5B,OAAO,CAAC,IAAI,CAACC,qBAAqB;IACpC;IAEA,IAAIC,mBAA2B;QAC7B,OAAO,IAAI,CAACH,KAAK,CAACI,UAAU,CAAC;IAC/B;IAEA,IAAIC,YAAoB;QACtB,OAAO,IAAI,CAACL,KAAK,CAACI,UAAU,CAAC;IAC/B;IAEA,IAAIF,yBAAiC;QACnC,OAAO,IAAI,CAACC,eAAe,IAAI,IAAI,CAACE,QAAQ;IAC9C;AACF,EAAE"}
@@ -1,57 +1,81 @@
1
+ import { _ as _define_property } from "@swc/helpers/_/_define_property";
1
2
  import chalk from "chalk";
2
3
  import pluralize from "pluralize";
3
4
  import { config } from "../config/config.js";
4
5
  import { Level } from "../output/log/level.js";
5
- import { sprint } from "../output/sprint.js";
6
+ import { println } from "../output/print.js";
7
+ import { sprint, sprintln } from "../output/sprint.js";
8
+ import { symbol } from "../output/symbols.js";
9
+ import { sprintTable } from "../output/table.js";
10
+ import { memo } from "../util/function.js";
6
11
  import { isNever, isString } from "../util/is.js";
7
12
  export class Changes extends Map {
8
- created() {
9
- return Array.from(this.entries()).filter(([, change])=>change.type === "create").map(([path])=>path);
10
- }
11
- updated() {
12
- return Array.from(this.entries()).filter(([, change])=>change.type === "update").map(([path])=>path);
13
- }
14
- deleted() {
15
- return Array.from(this.entries()).filter(([, change])=>change.type === "delete").map(([path])=>path);
13
+ constructor(...args){
14
+ super(...args);
15
+ _define_property(this, "created", memo(()=>{
16
+ return Array.from(this.entries()).filter(([, change])=>change.type === "create").map(([path])=>path);
17
+ }));
18
+ _define_property(this, "updated", memo(()=>{
19
+ return Array.from(this.entries()).filter(([, change])=>change.type === "update").map(([path])=>path);
20
+ }));
21
+ _define_property(this, "deleted", memo(()=>{
22
+ return Array.from(this.entries()).filter(([, change])=>change.type === "delete").map(([path])=>path);
23
+ }));
16
24
  }
17
25
  }
26
+ const createdSymbol = chalk.greenBright("+");
27
+ const updatedSymbol = chalk.blueBright("±");
28
+ const deletedSymbol = chalk.redBright("-");
29
+ const renameSymbol = chalk.yellowBright("→");
18
30
  /**
19
31
  * Prints the changes to the console.
20
32
  *
21
- * @param ctx - The current context.
22
- * @param options - The options to use.
23
- * @param options.changes - The changes to print.
24
- * @param options.tense - The tense to use for the change type.
25
- * @param options.limit - The maximum number of changes to print.
26
- */ export const printChanges = (ctx, { changes, tense, limit = Infinity, ...tableOptions })=>{
33
+ * @param _ctx - The current context.
34
+ * @see {@linkcode SprintChangesOptions}
35
+ */ export const sprintChanges = (_ctx, { changes, tense, includeDotGadget, limit = Infinity, ...tableOptions })=>{
27
36
  if (config.logLevel <= Level.TRACE) {
28
37
  // print all changes when tracing
29
38
  limit = Infinity;
30
39
  }
31
- const renamed = chalk.yellowBright((tense === "past" ? "renamed" : "rename") + " →");
32
- const created = chalk.greenBright((tense === "past" ? "created" : "create") + " +");
33
- const updated = chalk.blueBright((tense === "past" ? "updated" : "update") + " ±");
34
- const deleted = chalk.redBright((tense === "past" ? "deleted" : "delete") + " -");
35
- const rows = Array.from(changes.entries()).sort((a, b)=>a[0].localeCompare(b[0])).slice(0, limit).map(([path, change])=>{
40
+ let changesToPrint = Array.from(changes.entries());
41
+ if (includeDotGadget === undefined && changesToPrint.every(([filepath])=>filepath.startsWith(".gadget/"))) {
42
+ // we weren't explicitly told to exclude `.gadget/` files, and all
43
+ // the changes are to files within `.gadget/`, so include them since
44
+ // there's nothing else to show
45
+ includeDotGadget = true;
46
+ }
47
+ if (!includeDotGadget) {
48
+ changesToPrint = changesToPrint.filter(([filepath])=>!filepath.startsWith(".gadget/"));
49
+ }
50
+ const renamed = chalk.yellowBright(tense === "past" ? "renamed" : "rename");
51
+ const created = chalk.greenBright(tense === "past" ? "created" : "create");
52
+ const updated = chalk.blueBright(tense === "past" ? "updated" : "update");
53
+ const deleted = chalk.redBright(tense === "past" ? "deleted" : "delete");
54
+ const rows = changesToPrint.sort((a, b)=>a[0].localeCompare(b[0])).slice(0, limit).map(([path, change])=>{
36
55
  switch(true){
37
56
  case change.type === "create" && isString(change.oldPath):
38
57
  return [
58
+ renameSymbol,
39
59
  chalk.yellowBright(change.oldPath),
40
60
  renamed,
61
+ renameSymbol,
41
62
  chalk.yellowBright(path)
42
63
  ];
43
64
  case change.type === "create":
44
65
  return [
66
+ createdSymbol,
45
67
  chalk.greenBright(path),
46
68
  created
47
69
  ];
48
70
  case change.type === "update":
49
71
  return [
72
+ updatedSymbol,
50
73
  chalk.blueBright(path),
51
74
  updated
52
75
  ];
53
76
  case change.type === "delete":
54
77
  return [
78
+ deletedSymbol,
55
79
  chalk.redBright(path),
56
80
  deleted
57
81
  ];
@@ -59,37 +83,52 @@ export class Changes extends Map {
59
83
  return isNever(change);
60
84
  }
61
85
  });
62
- if (changes.size > limit) {
86
+ if (changesToPrint.length > limit) {
63
87
  rows.push([
64
- sprint`{gray … ${changes.size - limit} more}`,
88
+ chalk.gray(symbol.ellipsis),
89
+ sprint`{gray ${changesToPrint.length - limit} more}`,
65
90
  ""
66
91
  ]);
67
92
  }
68
93
  let footer;
69
- if (changes.size >= 10) {
70
- tableOptions.spaceY = 1;
71
- footer = sprint`${pluralize("change", changes.size, true)} in total. `;
94
+ if (changesToPrint.length >= 5) {
72
95
  const breakdown = [];
73
- const created = changes.created();
74
- if (created.length > 0) {
75
- breakdown.push(sprint`{greenBright ${pluralize("create", created.length, true)}}`);
96
+ const createdCount = changesToPrint.filter(([, change])=>change.type === "create").length;
97
+ if (createdCount > 0) {
98
+ const created = tense === "past" ? `${createdCount} created` : pluralize("create", createdCount, true);
99
+ breakdown.push(sprint`{greenBright ${created}}`);
76
100
  }
77
- const updated = changes.updated();
78
- if (updated.length > 0) {
79
- breakdown.push(sprint`{blueBright ${pluralize("update", updated.length, true)}}`);
101
+ const updatedCount = changesToPrint.filter(([, change])=>change.type === "update").length;
102
+ if (updatedCount > 0) {
103
+ const updated = tense === "past" ? `${updatedCount} updated` : pluralize("update", updatedCount, true);
104
+ breakdown.push(sprint`{blueBright ${updated}}`);
80
105
  }
81
- const deleted = changes.deleted();
82
- if (deleted.length > 0) {
83
- breakdown.push(sprint`{redBright ${pluralize("delete", deleted.length, true)}}`);
106
+ const deletedCount = changesToPrint.filter(([, change])=>change.type === "delete").length;
107
+ if (deletedCount > 0) {
108
+ const deleted = tense === "past" ? `${deletedCount} deleted` : pluralize("delete", deletedCount, true);
109
+ breakdown.push(sprint`{redBright ${deleted}}`);
84
110
  }
85
- footer += breakdown.join(", ");
86
- footer += ".";
111
+ footer = sprintln`
112
+ ${pluralize("change", changesToPrint.length, true)} in total. ${breakdown.join(", ")}.
113
+ `;
87
114
  }
88
- ctx.log.printTable({
115
+ return sprintTable({
89
116
  rows,
90
117
  footer,
118
+ ensureEmptyLineAbove: true,
119
+ ensureEmptyLineAboveBody: false,
120
+ ensureEmptyLineAboveFooter: true,
121
+ indent: 0,
91
122
  ...tableOptions
92
123
  });
93
124
  };
125
+ /**
126
+ * Prints the changes to the console.
127
+ *
128
+ * @param _ctx - The current context.
129
+ * @see {@linkcode SprintChangesOptions}
130
+ */ export const printChanges = (_ctx, options)=>{
131
+ println(sprintChanges(_ctx, options));
132
+ };
94
133
 
95
134
  //# sourceMappingURL=changes.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/services/filesync/changes.ts"],"sourcesContent":["import chalk from \"chalk\";\nimport pluralize from \"pluralize\";\nimport type { Context } from \"../command/context.js\";\nimport { config } from \"../config/config.js\";\nimport { Level } from \"../output/log/level.js\";\nimport type { PrintTableOptions } from \"../output/log/printer.js\";\nimport { sprint } from \"../output/sprint.js\";\nimport { isNever, isString } from \"../util/is.js\";\n\nexport type Create = { type: \"create\"; oldPath?: string };\nexport type Update = { type: \"update\" };\nexport type Delete = { type: \"delete\" };\nexport type Change = Create | Update | Delete;\n\nexport class Changes extends Map<string, Change> {\n created(): string[] {\n return Array.from(this.entries())\n .filter(([, change]) => change.type === \"create\")\n .map(([path]) => path);\n }\n\n updated(): string[] {\n return Array.from(this.entries())\n .filter(([, change]) => change.type === \"update\")\n .map(([path]) => path);\n }\n\n deleted(): string[] {\n return Array.from(this.entries())\n .filter(([, change]) => change.type === \"delete\")\n .map(([path]) => path);\n }\n}\n\n/**\n * Prints the changes to the console.\n *\n * @param ctx - The current context.\n * @param options - The options to use.\n * @param options.changes - The changes to print.\n * @param options.tense - The tense to use for the change type.\n * @param options.limit - The maximum number of changes to print.\n */\nexport const printChanges = (\n ctx: Context,\n {\n changes,\n tense,\n limit = Infinity,\n ...tableOptions\n }: {\n changes: Changes;\n tense: \"past\" | \"present\";\n limit?: number;\n } & Partial<PrintTableOptions>,\n): void => {\n if (config.logLevel <= Level.TRACE) {\n // print all changes when tracing\n limit = Infinity;\n }\n\n const renamed = chalk.yellowBright((tense === \"past\" ? \"renamed\" : \"rename\") + \" →\");\n const created = chalk.greenBright((tense === \"past\" ? \"created\" : \"create\") + \" +\");\n const updated = chalk.blueBright((tense === \"past\" ? \"updated\" : \"update\") + \" ±\");\n const deleted = chalk.redBright((tense === \"past\" ? \"deleted\" : \"delete\") + \" -\");\n\n const rows = Array.from(changes.entries())\n .sort((a, b) => a[0].localeCompare(b[0]))\n .slice(0, limit)\n .map(([path, change]) => {\n switch (true) {\n case change.type === \"create\" && isString(change.oldPath):\n return [chalk.yellowBright(change.oldPath), renamed, chalk.yellowBright(path)];\n case change.type === \"create\":\n return [chalk.greenBright(path), created];\n case change.type === \"update\":\n return [chalk.blueBright(path), updated];\n case change.type === \"delete\":\n return [chalk.redBright(path), deleted];\n default:\n return isNever(change);\n }\n });\n\n if (changes.size > limit) {\n rows.push([sprint`{gray … ${changes.size - limit} more}`, \"\"]);\n }\n\n let footer: string | undefined;\n if (changes.size >= 10) {\n tableOptions.spaceY = 1;\n\n footer = sprint`${pluralize(\"change\", changes.size, true)} in total. `;\n\n const breakdown = [];\n\n const created = changes.created();\n if (created.length > 0) {\n breakdown.push(sprint`{greenBright ${pluralize(\"create\", created.length, true)}}`);\n }\n\n const updated = changes.updated();\n if (updated.length > 0) {\n breakdown.push(sprint`{blueBright ${pluralize(\"update\", updated.length, true)}}`);\n }\n\n const deleted = changes.deleted();\n if (deleted.length > 0) {\n breakdown.push(sprint`{redBright ${pluralize(\"delete\", deleted.length, true)}}`);\n }\n\n footer += breakdown.join(\", \");\n footer += \".\";\n }\n\n ctx.log.printTable({ rows, footer, ...tableOptions });\n};\n"],"names":["chalk","pluralize","config","Level","sprint","isNever","isString","Changes","Map","created","Array","from","entries","filter","change","type","map","path","updated","deleted","printChanges","ctx","changes","tense","limit","Infinity","tableOptions","logLevel","TRACE","renamed","yellowBright","greenBright","blueBright","redBright","rows","sort","a","b","localeCompare","slice","oldPath","size","push","footer","spaceY","breakdown","length","join","log","printTable"],"mappings":"AAAA,OAAOA,WAAW,QAAQ;AAC1B,OAAOC,eAAe,YAAY;AAElC,SAASC,MAAM,QAAQ,sBAAsB;AAC7C,SAASC,KAAK,QAAQ,yBAAyB;AAE/C,SAASC,MAAM,QAAQ,sBAAsB;AAC7C,SAASC,OAAO,EAAEC,QAAQ,QAAQ,gBAAgB;AAOlD,OAAO,MAAMC,gBAAgBC;IAC3BC,UAAoB;QAClB,OAAOC,MAAMC,IAAI,CAAC,IAAI,CAACC,OAAO,IAC3BC,MAAM,CAAC,CAAC,GAAGC,OAAO,GAAKA,OAAOC,IAAI,KAAK,UACvCC,GAAG,CAAC,CAAC,CAACC,KAAK,GAAKA;IACrB;IAEAC,UAAoB;QAClB,OAAOR,MAAMC,IAAI,CAAC,IAAI,CAACC,OAAO,IAC3BC,MAAM,CAAC,CAAC,GAAGC,OAAO,GAAKA,OAAOC,IAAI,KAAK,UACvCC,GAAG,CAAC,CAAC,CAACC,KAAK,GAAKA;IACrB;IAEAE,UAAoB;QAClB,OAAOT,MAAMC,IAAI,CAAC,IAAI,CAACC,OAAO,IAC3BC,MAAM,CAAC,CAAC,GAAGC,O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/services/filesync/changes.ts"],"sourcesContent":["import chalk from \"chalk\";\nimport pluralize from \"pluralize\";\nimport type { Context } from \"../command/context.js\";\nimport { config } from \"../config/config.js\";\nimport { Level } from \"../output/log/level.js\";\nimport { println } from \"../output/print.js\";\nimport { sprint, sprintln } from \"../output/sprint.js\";\nimport { symbol } from \"../output/symbols.js\";\nimport { sprintTable, type SprintTableOptions } from \"../output/table.js\";\nimport { memo } from \"../util/function.js\";\nimport { isNever, isString } from \"../util/is.js\";\nimport type { ChangesWithHash } from \"./hashes.js\";\n\nexport type Create = { type: \"create\"; oldPath?: string };\nexport type Update = { type: \"update\" };\nexport type Delete = { type: \"delete\" };\nexport type Change = Create | Update | Delete;\n\nexport class Changes extends Map<string, Change> {\n created = memo((): string[] => {\n return Array.from(this.entries())\n .filter(([, change]) => change.type === \"create\")\n .map(([path]) => path);\n });\n\n updated = memo((): string[] => {\n return Array.from(this.entries())\n .filter(([, change]) => change.type === \"update\")\n .map(([path]) => path);\n });\n\n deleted = memo((): string[] => {\n return Array.from(this.entries())\n .filter(([, change]) => change.type === \"delete\")\n .map(([path]) => path);\n });\n}\n\nexport type PrintChangesOptions = Partial<SprintTableOptions> & {\n /**\n * The tense to use for the change type.\n */\n tense: \"past\" | \"present\";\n\n /**\n * Whether to include `.gadget/` files in the output.\n *\n * @default undefined (true if there are no other changes, false otherwise)\n */\n includeDotGadget?: boolean;\n\n /**\n * The maximum number of changes to print.\n *\n * @default Infinity\n */\n limit?: number;\n};\n\nconst createdSymbol = chalk.greenBright(\"+\");\nconst updatedSymbol = chalk.blueBright(\"±\");\nconst deletedSymbol = chalk.redBright(\"-\");\nconst renameSymbol = chalk.yellowBright(\"→\");\n\n/**\n * Prints the changes to the console.\n *\n * @param _ctx - The current context.\n * @see {@linkcode SprintChangesOptions}\n */\nexport const sprintChanges = (\n _ctx: Context,\n { changes, tense, includeDotGadget, limit = Infinity, ...tableOptions }: { changes: Changes | ChangesWithHash } & PrintChangesOptions,\n): string => {\n if (config.logLevel <= Level.TRACE) {\n // print all changes when tracing\n limit = Infinity;\n }\n\n let changesToPrint = Array.from(changes.entries());\n\n if (includeDotGadget === undefined && changesToPrint.every(([filepath]) => filepath.startsWith(\".gadget/\"))) {\n // we weren't explicitly told to exclude `.gadget/` files, and all\n // the changes are to files within `.gadget/`, so include them since\n // there's nothing else to show\n includeDotGadget = true;\n }\n\n if (!includeDotGadget) {\n changesToPrint = changesToPrint.filter(([filepath]) => !filepath.startsWith(\".gadget/\"));\n }\n\n const renamed = chalk.yellowBright(tense === \"past\" ? \"renamed\" : \"rename\");\n const created = chalk.greenBright(tense === \"past\" ? \"created\" : \"create\");\n const updated = chalk.blueBright(tense === \"past\" ? \"updated\" : \"update\");\n const deleted = chalk.redBright(tense === \"past\" ? \"deleted\" : \"delete\");\n\n const rows = changesToPrint\n .sort((a, b) => a[0].localeCompare(b[0]))\n .slice(0, limit)\n .map(([path, change]) => {\n switch (true) {\n case change.type === \"create\" && isString(change.oldPath):\n return [renameSymbol, chalk.yellowBright(change.oldPath), renamed, renameSymbol, chalk.yellowBright(path)];\n case change.type === \"create\":\n return [createdSymbol, chalk.greenBright(path), created];\n case change.type === \"update\":\n return [updatedSymbol, chalk.blueBright(path), updated];\n case change.type === \"delete\":\n return [deletedSymbol, chalk.redBright(path), deleted];\n default:\n return isNever(change);\n }\n });\n\n if (changesToPrint.length > limit) {\n rows.push([chalk.gray(symbol.ellipsis), sprint`{gray ${changesToPrint.length - limit} more}`, \"\"]);\n }\n\n let footer: string | undefined;\n if (changesToPrint.length >= 5) {\n const breakdown = [];\n\n const createdCount = changesToPrint.filter(([, change]) => change.type === \"create\").length;\n if (createdCount > 0) {\n const created = tense === \"past\" ? `${createdCount} created` : pluralize(\"create\", createdCount, true);\n breakdown.push(sprint`{greenBright ${created}}`);\n }\n\n const updatedCount = changesToPrint.filter(([, change]) => change.type === \"update\").length;\n if (updatedCount > 0) {\n const updated = tense === \"past\" ? `${updatedCount} updated` : pluralize(\"update\", updatedCount, true);\n breakdown.push(sprint`{blueBright ${updated}}`);\n }\n\n const deletedCount = changesToPrint.filter(([, change]) => change.type === \"delete\").length;\n if (deletedCount > 0) {\n const deleted = tense === \"past\" ? `${deletedCount} deleted` : pluralize(\"delete\", deletedCount, true);\n breakdown.push(sprint`{redBright ${deleted}}`);\n }\n\n footer = sprintln`\n ${pluralize(\"change\", changesToPrint.length, true)} in total. ${breakdown.join(\", \")}.\n `;\n }\n\n return sprintTable({\n rows,\n footer,\n ensureEmptyLineAbove: true,\n ensureEmptyLineAboveBody: false,\n ensureEmptyLineAboveFooter: true,\n indent: 0,\n ...tableOptions,\n });\n};\n\n/**\n * Prints the changes to the console.\n *\n * @param _ctx - The current context.\n * @see {@linkcode SprintChangesOptions}\n */\nexport const printChanges = (_ctx: Context, options: { changes: Changes | ChangesWithHash } & PrintChangesOptions): void => {\n println(sprintChanges(_ctx, options));\n};\n"],"names":["chalk","pluralize","config","Level","println","sprint","sprintln","symbol","sprintTable","memo","isNever","isString","Changes","Map","created","Array","from","entries","filter","change","type","map","path","updated","deleted","createdSymbol","greenBright","updatedSymbol","blueBright","deletedSymbol","redBright","renameSymbol","yellowBright","sprintChanges","_ctx","changes","tense","includeDotGadget","limit","Infinity","tableOptions","logLevel","TRACE","changesToPrint","undefined","every","filepath","startsWith","renamed","rows","sort","a","b","localeCompare","slice","oldPath","length","push","gray","ellipsis","footer","breakdown","createdCount","updatedCount","deletedCount","join","ensureEmptyLineAbove","ensureEmptyLineAboveBody","ensureEmptyLineAboveFooter","indent","printChanges","options"],"mappings":";AAAA,OAAOA,WAAW,QAAQ;AAC1B,OAAOC,eAAe,YAAY;AAElC,SAASC,MAAM,QAAQ,sBAAsB;AAC7C,SAASC,KAAK,QAAQ,yBAAyB;AAC/C,SAASC,OAAO,QAAQ,qBAAqB;AAC7C,SAASC,MAAM,EAAEC,QAAQ,QAAQ,sBAAsB;AACvD,SAASC,MAAM,QAAQ,uBAAuB;AAC9C,SAASC,WAAW,QAAiC,qBAAqB;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AE,MAAM,WAAW,EAAEK,UAAUI,IAAI,CAAC,MAAM;IACvF,CAAC;IACH;IAEA,OAAOzD,YAAY;QACjByC;QACAW;QACAM,sBAAsB;QACtBC,0BAA0B;QAC1BC,4BAA4B;QAC5BC,QAAQ;QACR,GAAG7B,YAAY;IACjB;AACF,EAAE;AAEF;;;;;CAKC,GACD,OAAO,MAAM8B,eAAe,CAACpC,MAAeqC;IAC1CnE,QAAQ6B,cAAcC,MAAMqC;AAC9B,EAAE"}
@@ -1,4 +1,5 @@
1
1
  import chalk from "chalk";
2
+ import { printTable } from "../output/table.js";
2
3
  import { ChangesWithHash, isEqualHash } from "./hashes.js";
3
4
  /**
4
5
  * A map of conflicting changes made between the user's local filesystem
@@ -9,10 +10,10 @@ import { ChangesWithHash, isEqualHash } from "./hashes.js";
9
10
  /**
10
11
  * Returns the conflicting changes between the user's local filesystem
11
12
  * and Gadget's filesystem.
12
- */ export const getConflicts = ({ localChanges, gadgetChanges })=>{
13
+ */ export const getConflicts = ({ localChanges, environmentChanges })=>{
13
14
  const conflicts = new Conflicts();
14
15
  for (const [filepath, localChange] of localChanges){
15
- const gadgetChange = gadgetChanges.get(filepath);
16
+ const gadgetChange = environmentChanges.get(filepath);
16
17
  if (!gadgetChange) {
17
18
  continue;
18
19
  }
@@ -58,16 +59,17 @@ import { ChangesWithHash, isEqualHash } from "./hashes.js";
58
59
  /**
59
60
  * Prints a table of conflicts between local changes and gadget changes.
60
61
  *
61
- * @param ctx - The current context.
62
62
  * @param options - The options to use.
63
- * @param options.message - The message to print above the table.
64
63
  * @param options.conflicts - The conflicts to print.
65
- */ export const printConflicts = (ctx, { message, conflicts })=>{
64
+ */ // TODO: write a snapshot test for this!
65
+ export const printConflicts = ({ conflicts })=>{
66
66
  const created = chalk.greenBright("+ created");
67
67
  const updated = chalk.blueBright("± updated");
68
68
  const deleted = chalk.redBright("- deleted");
69
- ctx.log.printTable({
70
- message,
69
+ printTable({
70
+ title: "These files have conflicting changes.",
71
+ ensureEmptyLineAbove: true,
72
+ ensureEmptyLineAboveBody: true,
71
73
  colAligns: [
72
74
  "left",
73
75
  "center",
@@ -76,9 +78,8 @@ import { ChangesWithHash, isEqualHash } from "./hashes.js";
76
78
  headers: [
77
79
  "",
78
80
  "You",
79
- "Gadget"
81
+ "Environment"
80
82
  ],
81
- spaceY: 1,
82
83
  rows: Array.from(conflicts.entries()).sort((a, b)=>a[0].localeCompare(b[0])).map(([path, { localChange, gadgetChange }])=>{
83
84
  switch(true){
84
85
  case localChange.type === "create" && gadgetChange.type === "create":
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/services/filesync/conflicts.ts"],"sourcesContent":["import chalk from \"chalk\";\nimport type { Context } from \"../command/context.js\";\nimport { ChangesWithHash, isEqualHash, type ChangeWithHash } from \"./hashes.js\";\n\n/**\n * A map of conflicting changes made between the user's local filesystem\n * and Gadget's filesystem where the key is the path of the conflicting\n * file and the value is an object containing the conflicting changes.\n */\nexport class Conflicts extends Map<string, { localChange: ChangeWithHash; gadgetChange: ChangeWithHash }> {}\n\n/**\n * Returns the conflicting changes between the user's local filesystem\n * and Gadget's filesystem.\n */\nexport const getConflicts = ({\n localChanges,\n gadgetChanges,\n}: {\n localChanges: ChangesWithHash;\n gadgetChanges: ChangesWithHash;\n}): Conflicts => {\n const conflicts = new Conflicts();\n\n for (const [filepath, localChange] of localChanges) {\n const gadgetChange = gadgetChanges.get(filepath);\n if (!gadgetChange) {\n // gadget doesn't have this change, so there's no conflict\n continue;\n }\n\n if (localChange.type === \"delete\" && gadgetChange.type === \"delete\") {\n // local and gadget both deleted the same file\n continue;\n }\n\n if (\n \"targetHash\" in localChange &&\n \"targetHash\" in gadgetChange &&\n isEqualHash(filepath, localChange.targetHash, gadgetChange.targetHash)\n ) {\n // local and gadget both created/updated the same file with the same content\n continue;\n }\n\n // local and gadget both updated the same file with different\n // content or one updated and the other deleted\n conflicts.set(filepath, { localChange, gadgetChange });\n }\n\n // ignore .gadget/ file conflicts and always use gadget's version\n // since gadget is the source of truth for .gadget/ files\n for (const filepath of conflicts.keys()) {\n if (filepath.startsWith(\".gadget/\")) {\n conflicts.delete(filepath);\n }\n }\n\n return conflicts;\n};\n\n/**\n * Returns a new `Changes` object that contains only the changes that do\n * not have conflicts.\n *\n * @param options - The options to use.\n * @param options.conflicts - The conflicts to check against.\n * @param options.changes - The changes to filter.\n * @returns A new {@linkcode Changes} object without conflicts.\n */\nexport const withoutConflictingChanges = ({ conflicts, changes }: { conflicts: Conflicts; changes: ChangesWithHash }): ChangesWithHash => {\n const changesWithoutConflicts = new ChangesWithHash(changes);\n\n for (const [filepath] of changesWithoutConflicts) {\n if (conflicts.has(filepath)) {\n changesWithoutConflicts.delete(filepath);\n }\n }\n\n return changesWithoutConflicts;\n};\n\n/**\n * Prints a table of conflicts between local changes and gadget changes.\n *\n * @param ctx - The current context.\n * @param options - The options to use.\n * @param options.message - The message to print above the table.\n * @param options.conflicts - The conflicts to print.\n */\nexport const printConflicts = (ctx: Context, { message, conflicts }: { message: string; conflicts: Conflicts }): void => {\n const created = chalk.greenBright(\"+ created\");\n const updated = chalk.blueBright(\"± updated\");\n const deleted = chalk.redBright(\"- deleted\");\n\n ctx.log.printTable({\n message,\n colAligns: [\"left\", \"center\", \"center\"],\n headers: [\"\", \"You\", \"Gadget\"],\n spaceY: 1,\n rows: Array.from(conflicts.entries())\n .sort((a, b) => a[0].localeCompare(b[0]))\n .map(([path, { localChange, gadgetChange }]) => {\n switch (true) {\n case localChange.type === \"create\" && gadgetChange.type === \"create\":\n return [path, created, created];\n case localChange.type === \"create\" && gadgetChange.type === \"update\":\n return [path, created, updated];\n case localChange.type === \"create\" && gadgetChange.type === \"delete\":\n return [path, created, deleted];\n case localChange.type === \"update\" && gadgetChange.type === \"create\":\n return [path, updated, created];\n case localChange.type === \"update\" && gadgetChange.type === \"update\":\n return [path, updated, updated];\n case localChange.type === \"update\" && gadgetChange.type === \"delete\":\n return [path, updated, deleted];\n case localChange.type === \"delete\" && gadgetChange.type === \"create\":\n return [path, deleted, created];\n case localChange.type === \"delete\" && gadgetChange.type === \"update\":\n return [path, deleted, updated];\n default:\n throw new Error(`Unexpected conflict: ${localChange.type} vs ${gadgetChange.type}`);\n }\n }),\n });\n};\n"],"names":["chalk","ChangesWithHash","isEqualHash","Conflicts","Map","getConflicts","localChanges","gadgetChanges","conflicts","filepath","localChange","gadgetChange","get","type","targetHash","set","keys","startsWith","delete","withoutConflictingChanges","changes","changesWithoutConflicts","has","printConflicts","ctx","message","created","greenBright","updated","blueBright","deleted","redBright","log","printTable","colAligns","headers","spaceY","rows","Array","from","entries","sort","a","b","localeCompare","map","path","Error"],"mappings":"AAAA,OAAOA,WAAW,QAAQ;AAE1B,SAASC,eAAe,EAAEC,WAAW,QAA6B,cAAc;AAEhF;;;;CAIC,GACD,OAAO,MAAMC,kBAAkBC;AAA4E;AAE3G;;;CAGC,GACD,OAAO,MAAMC,eAAe,CAAC,EAC3BC,YAAY,EACZC,aAAa,EAId;IACC,MAAMC,YAAY,IAAIL;IAEtB,KAAK,MAAM,CAACM,UAAUC,YAAY,IAAIJ,aAAc;QAClD,MAAMK,eAAeJ,cAAcK,GAAG,CAACH;QACvC,IAAI,CAACE,cAAc;YAEjB;QACF;QAEA,IAAID,YAAYG,IAAI,KAAK,YAAYF,aAAaE,IAAI,KAAK,UAAU;YAEnE;QACF;QAEA,IACE,gBAAgBH,eAChB,gBAAgBC,gBAChBT,YAAYO,UAAUC,YAAYI,UAAU,EAAEH,aAAaG,UAAU,GACrE;YAEA;QACF;QAEA,6DAA6D;QAC7D,+CAA+C;QAC/CN,UAAUO,GAAG,CAACN,UAAU;YAAEC;YAAaC;QAAa;IACtD;IAEA,iEAAiE;IACjE,yDAAyD;IACzD,KAAK,MAAMF,YAAYD,UAAUQ,IAAI,GAAI;QACvC,IAAIP,SAASQ,UAAU,CAAC,aAAa;YACnCT,UAAUU,MAAM,CAACT;QACnB;IACF;IAEA,OAAOD;AACT,EAAE;AAEF;;;;;;;;CAQC,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KAAK;oBAC1D,OAAO;wBAACiC;wBAAMlB;wBAASF;qBAAQ;gBACjC,KAAKhB,YAAYG,IAAI,KAAK,YAAYF,aAAaE,IAAI,KAAK;oBAC1D,OAAO;wBAACiC;wBAAMlB;wBAASA;qBAAQ;gBACjC,KAAKlB,YAAYG,IAAI,KAAK,YAAYF,aAAaE,IAAI,KAAK;oBAC1D,OAAO;wBAACiC;wBAAMlB;wBAASE;qBAAQ;gBACjC,KAAKpB,YAAYG,IAAI,KAAK,YAAYF,aAAaE,IAAI,KAAK;oBAC1D,OAAO;wBAACiC;wBAAMhB;wBAASJ;qBAAQ;gBACjC,KAAKhB,YAAYG,IAAI,KAAK,YAAYF,aAAaE,IAAI,KAAK;oBAC1D,OAAO;wBAACiC;wBAAMhB;wBAASF;qBAAQ;gBACjC;oBACE,MAAM,IAAImB,MAAM,CAAC,qBAAqB,EAAErC,YAAYG,IAAI,CAAC,IAAI,EAAEF,aAAaE,IAAI,CAAC,CAAC;YACtF;QACF;IACJ;AACF,EAAE"}
1
+ {"version":3,"sources":["../../../src/services/filesync/conflicts.ts"],"sourcesContent":["import chalk from \"chalk\";\nimport { printTable } from \"../output/table.js\";\nimport { ChangesWithHash, isEqualHash, type ChangeWithHash } from \"./hashes.js\";\n\n/**\n * A map of conflicting changes made between the user's local filesystem\n * and Gadget's filesystem where the key is the path of the conflicting\n * file and the value is an object containing the conflicting changes.\n */\nexport class Conflicts extends Map<string, { localChange: ChangeWithHash; gadgetChange: ChangeWithHash }> {}\n\n/**\n * Returns the conflicting changes between the user's local filesystem\n * and Gadget's filesystem.\n */\nexport const getConflicts = ({\n localChanges,\n environmentChanges,\n}: {\n localChanges: ChangesWithHash;\n environmentChanges: ChangesWithHash;\n}): Conflicts => {\n const conflicts = new Conflicts();\n\n for (const [filepath, localChange] of localChanges) {\n const gadgetChange = environmentChanges.get(filepath);\n if (!gadgetChange) {\n // gadget doesn't have this change, so there's no conflict\n continue;\n }\n\n if (localChange.type === \"delete\" && gadgetChange.type === \"delete\") {\n // local and gadget both deleted the same file\n continue;\n }\n\n if (\n \"targetHash\" in localChange &&\n \"targetHash\" in gadgetChange &&\n isEqualHash(filepath, localChange.targetHash, gadgetChange.targetHash)\n ) {\n // local and gadget both created/updated the same file with the same content\n continue;\n }\n\n // local and gadget both updated the same file with different\n // content or one updated and the other deleted\n conflicts.set(filepath, { localChange, gadgetChange });\n }\n\n // ignore .gadget/ file conflicts and always use gadget's version\n // since gadget is the source of truth for .gadget/ files\n for (const filepath of conflicts.keys()) {\n if (filepath.startsWith(\".gadget/\")) {\n conflicts.delete(filepath);\n }\n }\n\n return conflicts;\n};\n\n/**\n * Returns a new `Changes` object that contains only the changes that do\n * not have conflicts.\n *\n * @param options - The options to use.\n * @param options.conflicts - The conflicts to check against.\n * @param options.changes - The changes to filter.\n * @returns A new {@linkcode Changes} object without conflicts.\n */\nexport const withoutConflictingChanges = ({ conflicts, changes }: { conflicts: Conflicts; changes: ChangesWithHash }): ChangesWithHash => {\n const changesWithoutConflicts = new ChangesWithHash(changes);\n\n for (const [filepath] of changesWithoutConflicts) {\n if (conflicts.has(filepath)) {\n changesWithoutConflicts.delete(filepath);\n }\n }\n\n return changesWithoutConflicts;\n};\n\n/**\n * Prints a table of conflicts between local changes and gadget changes.\n *\n * @param options - The options to use.\n * @param options.conflicts - The conflicts to print.\n */\n// TODO: write a snapshot test for this!\nexport const printConflicts = ({ conflicts }: { conflicts: Conflicts }): void => {\n const created = chalk.greenBright(\"+ created\");\n const updated = chalk.blueBright(\"± updated\");\n const deleted = chalk.redBright(\"- deleted\");\n\n printTable({\n title: \"These files have conflicting changes.\",\n ensureEmptyLineAbove: true,\n ensureEmptyLineAboveBody: true,\n colAligns: [\"left\", \"center\", \"center\"],\n headers: [\"\", \"You\", \"Environment\"],\n rows: Array.from(conflicts.entries())\n .sort((a, b) => a[0].localeCompare(b[0]))\n .map(([path, { localChange, gadgetChange }]) => {\n switch (true) {\n case localChange.type === \"create\" && gadgetChange.type === \"create\":\n return [path, created, created];\n case localChange.type === \"create\" && gadgetChange.type === \"update\":\n return [path, created, updated];\n case localChange.type === \"create\" && gadgetChange.type === \"delete\":\n return [path, created, deleted];\n case localChange.type === \"update\" && gadgetChange.type === \"create\":\n return [path, updated, created];\n case localChange.type === \"update\" && gadgetChange.type === \"update\":\n return [path, updated, updated];\n case localChange.type === \"update\" && gadgetChange.type === \"delete\":\n return [path, updated, deleted];\n case localChange.type === \"delete\" && gadgetChange.type === \"create\":\n return [path, deleted, created];\n case localChange.type === \"delete\" && gadgetChange.type === \"update\":\n return [path, deleted, updated];\n default:\n throw new Error(`Unexpected conflict: ${localChange.type} vs ${gadgetChange.type}`);\n }\n }),\n });\n};\n"],"names":["chalk","printTable","ChangesWithHash","isEqualHash","Conflicts","Map","getConflicts","localChanges","environmentChanges","conflicts","filepath","localChange","gadgetChange","get","type","targetHash","set","keys","startsWith","delete","withoutConflictingChanges","changes","changesWithoutConflicts","has","printConflicts","created","greenBright","updated","blueBright","deleted","redBright","title","ensureEmptyLineAbove","ensureEmptyLineAboveBody","colAligns","headers","rows","Array","from","entries","sort","a","b","localeCompare","map","path","Error"],"mappings":"AAAA,OAAOA,WAAW,QAAQ;AAC1B,SAASC,UAAU,QAAQ,qBAAqB;AAChD,SAASC,eAAe,EAAEC,WAAW,QAA6B,cAAc;AAEhF;;;;CAIC,GACD,OAAO,MAAMC,kBAAkBC;AAA4E;AAE3G;;;CAGC,GACD,OAAO,MAAMC,eAAe,CAAC,EAC3BC,YAAY,EACZC,kBAAkB,EAInB;IACC,MAAMC,YAAY,IAAIL;IAEtB,KAAK,MAAM,CAACM,UAAUC,YAAY,IAAIJ,aAAc;QAClD,MAAMK,eAAeJ,mBAAmBK,GAAG,CAACH;QAC5C,IAAI,CAACE,cAAc;YAEjB;QACF;QAEA,IAAID,YAAYG,IAAI,KAAK,YAAYF,aAAaE,IAAI,KAAK,UAAU;YAEnE;QACF;QAEA,IACE,gBAAgBH,eAChB,gBAAgBC,gBAChBT,YAAY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IAAI,KAAK;oBAC1D,OAAO;wBAAC+B;wBAAMpB;wBAASA;qBAAQ;gBACjC,KAAKd,YAAYG,IAAI,KAAK,YAAYF,aAAaE,IAAI,KAAK;oBAC1D,OAAO;wBAAC+B;wBAAMpB;wBAASE;qBAAQ;gBACjC,KAAKhB,YAAYG,IAAI,KAAK,YAAYF,aAAaE,IAAI,KAAK;oBAC1D,OAAO;wBAAC+B;wBAAMpB;wBAASI;qBAAQ;gBACjC,KAAKlB,YAAYG,IAAI,KAAK,YAAYF,aAAaE,IAAI,KAAK;oBAC1D,OAAO;wBAAC+B;wBAAMlB;wBAASF;qBAAQ;gBACjC,KAAKd,YAAYG,IAAI,KAAK,YAAYF,aAAaE,IAAI,KAAK;oBAC1D,OAAO;wBAAC+B;wBAAMlB;wBAASA;qBAAQ;gBACjC,KAAKhB,YAAYG,IAAI,KAAK,YAAYF,aAAaE,IAAI,KAAK;oBAC1D,OAAO;wBAAC+B;wBAAMlB;wBAASE;qBAAQ;gBACjC,KAAKlB,YAAYG,IAAI,KAAK,YAAYF,aAAaE,IAAI,KAAK;oBAC1D,OAAO;wBAAC+B;wBAAMhB;wBAASJ;qBAAQ;gBACjC,KAAKd,YAAYG,IAAI,KAAK,YAAYF,aAAaE,IAAI,KAAK;oBAC1D,OAAO;wBAAC+B;wBAAMhB;wBAASF;qBAAQ;gBACjC;oBACE,MAAM,IAAImB,MAAM,CAAC,qBAAqB,EAAEnC,YAAYG,IAAI,CAAC,IAAI,EAAEF,aAAaE,IAAI,CAAC,CAAC;YACtF;QACF;IACJ;AACF,EAAE"}
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * DO NOT MODIFY
3
3
  *
4
- * Everything in this file also exists in ggt to ensure that this logic
4
+ * Everything in this file also exists in gadget to ensure that this logic
5
5
  * is the same between the two projects.
6
6
  */ import { _ as _define_property } from "@swc/helpers/_/_define_property";
7
7
  import fs from "fs-extra";
@@ -167,6 +167,21 @@ import normalizePath from "normalize-path";
167
167
  this._isHashing = false;
168
168
  }
169
169
  }
170
+ async hasFiles() {
171
+ return !await this.isEmptyOrNonExistent();
172
+ }
173
+ async isEmptyOrNonExistent() {
174
+ let isEmptyOrNonExistent = true;
175
+ try {
176
+ for await (const _ of this.walk()){
177
+ isEmptyOrNonExistent = false;
178
+ break;
179
+ }
180
+ } catch (error) {
181
+ swallowEnoent(error);
182
+ }
183
+ return isEmptyOrNonExistent;
184
+ }
170
185
  constructor(/**
171
186
  * An absolute path to the directory that is being synced.
172
187
  */ path){
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/services/filesync/directory.ts"],"sourcesContent":["/**\n * DO NOT MODIFY\n *\n * Everything in this file also exists in ggt to ensure that this logic\n * is the same between the two projects.\n */\nimport fs from \"fs-extra\";\nimport type { Ignore } from \"ignore\";\nimport ignore from \"ignore\";\nimport assert from \"node:assert\";\nimport { createHash } from \"node:crypto\";\nimport path from \"node:path\";\nimport { Transform } from \"node:stream\";\nimport { pipeline } from \"node:stream/promises\";\nimport normalizePath from \"normalize-path\";\n\n/**\n * Paths that are always ignored, regardless of the contents of the `.ignore` file.\n */\nexport const ALWAYS_IGNORE_PATHS = [\".DS_Store\", \"node_modules\", \".git\"] as const;\n\n/**\n * Paths that are ignored when hashing the directory.\n *\n * NOTE: This is the _only_ thing that is allowed to be different between gadget and ggt.\n */\nexport const HASHING_IGNORE_PATHS = [\".gadget/sync.json\", \".gadget/backup\", \"yarn-error.log\"] as const;\n\n/**\n * Represents a directory that is being synced.\n */\nexport class Directory {\n /**\n * A gitignore-style file parser used to determine which files to\n * ignore while syncing.\n *\n * @see https://www.npmjs.com/package/ignore\n */\n private _ignorer!: Ignore;\n\n /**\n * Whether the directory is currently being hashed.\n */\n private _isHashing = false;\n\n private constructor(\n /**\n * An absolute path to the directory that is being synced.\n */\n readonly path: string,\n ) {}\n\n /**\n * Initializes a directory to be synced.\n *\n * If the directory does not exist, it is created.\n *\n * @param dir - The directory to initialize.\n * @returns A Promise that resolves to a Directory instance.\n */\n static async init(dir: string): Promise<Directory> {\n const directory = new Directory(dir);\n await directory.loadIgnoreFile();\n return directory;\n }\n\n /**\n * Returns the relative path from this directory to the specified path.\n *\n * @param to - The path to which the relative path is calculated.\n * @returns The relative path from this directory to the specified path.\n */\n relative(to: string): string {\n if (!path.isAbsolute(to)) {\n // the filepath is already relative\n return to;\n }\n\n return path.relative(this.path, to);\n }\n\n /**\n * Returns the absolute path by resolving the given path segments\n * relative to the directory path.\n *\n * @param pathSegments - The path segments to resolve.\n * @returns The absolute path.\n */\n absolute(...pathSegments: string[]): string {\n const result = path.resolve(this.path, ...pathSegments);\n assert(result.startsWith(this.path), `expected ${result} to be within ${this.path}`);\n return result;\n }\n\n /**\n * Similar to {@linkcode relative} in that it converts an absolute\n * path into a relative one from {@linkcode path}. However, it also\n * changes any slashes to be posix/unix-like forward slashes,\n * condenses repeated slashes into a single slash, and adds a trailing\n * slash if the path is a directory.\n *\n * This is used when sending files to Gadget to ensure that the paths\n * are consistent across platforms.\n *\n * @see https://www.npmjs.com/package/normalize-path\n */\n normalize(filepath: string, isDirectory: boolean): string {\n if (path.isAbsolute(filepath)) {\n filepath = this.relative(filepath);\n }\n\n // true = trim trailing slashes\n filepath = normalizePath(filepath, true);\n\n if (isDirectory) {\n filepath += \"/\";\n }\n\n return filepath;\n }\n\n /**\n * Loads the `.ignore` file in the directory. If the file does not\n * exist, it is silently ignored.\n */\n async loadIgnoreFile(): Promise<void> {\n this._ignorer = ignore.default();\n this._ignorer.add(ALWAYS_IGNORE_PATHS);\n\n try {\n const content = await fs.readFile(this.absolute(\".ignore\"), \"utf8\");\n this._ignorer.add(content);\n } catch (error) {\n swallowEnoent(error);\n }\n }\n\n /**\n * Determines if a file should be ignored based on its filepath.\n *\n * @param filepath - The filepath of the file to check.\n * @returns True if the file should be ignored, false otherwise.\n */\n ignores(filepath: string): boolean {\n filepath = this.relative(filepath);\n if (filepath === \"\") {\n // don't ignore the root dir\n return false;\n }\n\n if (filepath.startsWith(\"..\")) {\n // anything above the root dir is ignored\n return true;\n }\n\n // false = don't trim trailing slashes\n filepath = normalizePath(filepath, false);\n if (this._isHashing && HASHING_IGNORE_PATHS.some((ignored) => filepath.startsWith(ignored))) {\n // special case for hashing\n return true;\n }\n\n return this._ignorer.ignores(filepath);\n }\n\n /**\n * Recursively walks through the directory and yields all non-ignored\n * files and directories within it.\n *\n * @yields - The normalized path of each file and directory.\n */\n async *walk({ dir = this.path } = {}): AsyncGenerator<string> {\n // don't yield the root directory\n if (dir !== this.path) {\n yield this.normalize(dir, true);\n }\n\n for await (const entry of await fs.opendir(dir)) {\n const filepath = path.join(dir, entry.name);\n if (this.ignores(filepath)) {\n continue;\n }\n\n if (entry.isDirectory()) {\n yield* this.walk({ dir: filepath });\n } else if (entry.isFile()) {\n yield this.normalize(filepath, false);\n }\n }\n }\n\n /**\n * Calculates the hash of each file and directory and returns an\n * object containing the hashes keyed by the normalized file path.\n *\n * @returns A Promise that resolves to an object containing the hashes\n * of each file.\n */\n async hashes(): Promise<Hashes> {\n try {\n this._isHashing = true;\n const files = {} as Hashes;\n\n for await (const normalizedPath of this.walk()) {\n const absolutePath = this.absolute(normalizedPath);\n files[normalizedPath] = await hash(absolutePath);\n }\n\n return files;\n } finally {\n this._isHashing = false;\n }\n }\n}\n\n/**\n * Key/value pairs where the key is the normalized path and the value is\n * the result of {@linkcode hash} for that path.\n */\nexport type Hashes = Record<string, Hash>;\n\nexport type Hash = {\n /**\n * The SHA-1 hash of the file or directory.\n *\n * If the path points to a directory, the hash is calculated based on\n * the directory's basename. If the path points to a file, the hash is\n * calculated based on the file's basename and contents.\n */\n sha1: string;\n\n /**\n * The Unix-style file permissions of the file or directory, or\n * undefined if the platform that generated this hash doesn't support\n * them.\n *\n * @example 0o644\n * @see supportsPermissions\n */\n permissions?: number;\n};\n\n/**\n * Whether the current platform supports Unix-style file permissions.\n *\n * Windows doesn't support Unix-style file permissions and all file\n * permissions retrieved via `node:fs` on Windows are translated to 666\n * or 444.\n */\nexport const supportsPermissions = process.platform === \"linux\" || process.platform === \"darwin\";\n\n/**\n * Calculates the {@linkcode Hash} of the file or directory at the\n * specified absolute path.\n *\n * @param absolutePath - The absolute path to the file or directory.\n * @returns A Promise that resolves to the {@linkcode Hash} of the file\n * or directory.\n */\nconst hash = async (absolutePath: string): Promise<Hash> => {\n const sha1 = createHash(\"sha1\");\n sha1.update(path.basename(absolutePath));\n\n const stats = await fs.stat(absolutePath);\n\n let permissions;\n if (supportsPermissions) {\n // strip everything but the permissions\n permissions = stats.mode & 0o777;\n }\n\n if (stats.isDirectory()) {\n return { sha1: sha1.digest(\"hex\"), permissions };\n }\n\n // windows uses CRLF line endings whereas unix uses LF line endings so\n // we always strip out CR bytes (0x0d) when hashing files. this does\n // make us blind to files that only differ by CR bytes, but that's a\n // tradeoff we're willing to make.\n const removeCR = new Transform({\n transform(chunk: Buffer, _encoding, callback) {\n if (!chunk.includes(0x0d)) {\n callback(undefined, chunk);\n return;\n }\n\n const filteredChunk = Buffer.alloc(chunk.length);\n let i = 0;\n for (const byte of chunk) {\n if (byte !== 0x0d) {\n filteredChunk[i++] = byte;\n }\n }\n\n callback(undefined, filteredChunk.slice(0, i));\n },\n });\n\n await pipeline(fs.createReadStream(absolutePath), removeCR, sha1);\n\n return { sha1: sha1.digest(\"hex\"), permissions };\n};\n\n/**\n * Swallows ENOENT errors and throws any other errors.\n *\n * @param error - The error to handle.\n * @throws The original error if it is not an ENOENT error.\n */\nexport const swallowEnoent = (error: unknown): void => {\n if (error && typeof error === \"object\" && \"code\" in error && error.code === \"ENOENT\") {\n return;\n }\n throw error;\n};\n"],"names":["fs","ignore","assert","createHash","path","Transform","pipeline","normalizePath","ALWAYS_IGNORE_PATHS","HASHING_IGNORE_PATHS","Directory","init","dir","directory","loadIgnoreFile","relative","to","isAbsolute","absolute","pathSegments","result","resolve","startsWith","normalize","filepath","isDirectory","_ignorer","default","add","content","readFile","error","swallowEnoent","ignores","_isHashing","some","ignored","walk","entry","opendir","join","name","isFile","hashes","files","normalizedPath","absolutePath","hash","supportsPermissions","process","platform","sha1","update","basename","stats","stat","permissions","mode","digest","removeCR","transform","chunk","_encoding","callback","includes","undefined","filteredChunk","Buffer","alloc","length","i","byte","slice","createReadStream","code"],"mappings":"AAAA;;;;;CAKC;AACD,OAAOA,QAAQ,WAAW;AAE1B,OAAOC,YAAY,SAAS;AAC5B,OAAOC,YAAY,cAAc;AACjC,SAASC,UAAU,QAAQ,cAAc;AACzC,OAAOC,UAAU,YAAY;AAC7B,SAASC,SAAS,QAAQ,cAAc;AACxC,SAASC,QAAQ,QAAQ,uBAAuB;AAChD,OAAOC,mBAAmB,iBAAiB;AAE3C;;CAEC,GACD,OAAO,MAAMC,sBAAsB;IAAC;IAAa;IAAgB;CAAO,CAAU;AAElF;;;;CAIC,GACD,OAAO,MAAMC,uBAAuB;IAAC;IAAqB;IAAkB;CAAiB,CAAU;AAEvG;;CAEC,GACD,OAAO,MAAMC;IAqBX;;;;;;;GAOC,GACD,aAAaC,KAAKC,GAAW,EAAsB;QACjD,MAAMC,YAAY,IAAIH,UAAUE;QAChC,MAAMC,UAAUC,cAAc;QAC9B,OAAOD;IACT;IAEA;;;;;GAKC,GACDE,SAASC,EAAU,EAAU;QAC3B,IAAI,CAACZ,KAAKa,UAAU,CAACD,KAAK;YACxB,mCAAmC;YACnC,OAAOA;QACT;QAEA,OAAOZ,KAAKW,QAAQ,CAAC,IAAI,CAACX,IAAI,EAAEY;IAClC;IAEA;;;;;;GAMC,GACDE,SAAS,GAAGC,YAAsB,EAAU;QAC1C,MAAMC,SAAShB,KAAKiB,OAAO,CAAC,IAAI,CAACjB,IAAI,KAAKe;QAC1CjB,OAAOkB,OAAOE,UAAU,CAAC,IAAI,CAAClB,IAAI,GAAG,CAAC,SAAS,EAAEgB,OAAO,cAAc,EAAE,IAAI,CAAChB,IAAI,CAAC,CAAC;QACnF,OAAOgB;IACT;IAEA;;;;;;;;;;;GAWC,GACDG,UAAUC,QAAgB,EAAEC,WAAoB,EAAU;Q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AAE0B,MAAMA,KAAKO,MAAM,CAAC;YAAQF;QAAY;IACjD;IAEA,sEAAsE;IACtE,oEAAoE;IACpE,oEAAoE;IACpE,kCAAkC;IAClC,MAAMG,WAAW,IAAItD,UAAU;QAC7BuD,WAAUC,KAAa,EAAEC,SAAS,EAAEC,QAAQ;YAC1C,IAAI,CAACF,MAAMG,QAAQ,CAAC,OAAO;gBACzBD,SAASE,WAAWJ;gBACpB;YACF;YAEA,MAAMK,gBAAgBC,OAAOC,KAAK,CAACP,MAAMQ,MAAM;YAC/C,IAAIC,IAAI;YACR,KAAK,MAAMC,QAAQV,MAAO;gBACxB,IAAIU,SAAS,MAAM;oBACjBL,aAAa,CAACI,IAAI,GAAGC;gBACvB;YACF;YAEAR,SAASE,WAAWC,cAAcM,KAAK,CAAC,GAAGF;QAC7C;IACF;IAEA,MAAMhE,SAASN,GAAGyE,gBAAgB,CAAC3B,eAAea,UAAUR;IAE5D,OAAO;QAAEA,MAAMA,KAAKO,MAAM,CAAC;QAAQF;IAAY;AACjD;AAEA;;;;;CAKC,GACD,OAAO,MAAMxB,gBAAgB,CAACD;IAC5B,IAAIA,SAAS,OAAOA,UAAU,YAAY,UAAUA,SAASA,MAAM2C,IAAI,KAAK,UAAU;QACpF;IACF;IACA,MAAM3C;AACR,EAAE"}
1
+ {"version":3,"sources":["../../../src/services/filesync/directory.ts"],"sourcesContent":["/**\n * DO NOT MODIFY\n *\n * Everything in this file also exists in gadget to ensure that this logic\n * is the same between the two projects.\n */\nimport fs from \"fs-extra\";\nimport type { Ignore } from \"ignore\";\nimport ignore from \"ignore\";\nimport assert from \"node:assert\";\nimport { createHash } from \"node:crypto\";\nimport path from \"node:path\";\nimport { Transform } from \"node:stream\";\nimport { pipeline } from \"node:stream/promises\";\nimport normalizePath from \"normalize-path\";\n\n/**\n * Paths that are always ignored, regardless of the contents of the `.ignore` file.\n */\nexport const ALWAYS_IGNORE_PATHS = [\".DS_Store\", \"node_modules\", \".git\"] as const;\n\n/**\n * Paths that are ignored when hashing the directory.\n *\n * NOTE: This is the _only_ thing that is allowed to be different between gadget and ggt.\n */\nexport const HASHING_IGNORE_PATHS = [\".gadget/sync.json\", \".gadget/backup\", \"yarn-error.log\"] as const;\n\n/**\n * Represents a directory that is being synced.\n */\nexport class Directory {\n /**\n * A gitignore-style file parser used to determine which files to\n * ignore while syncing.\n *\n * @see https://www.npmjs.com/package/ignore\n */\n private _ignorer!: Ignore;\n\n /**\n * Whether the directory is currently being hashed.\n */\n private _isHashing = false;\n\n private constructor(\n /**\n * An absolute path to the directory that is being synced.\n */\n readonly path: string,\n ) {}\n\n /**\n * Initializes a directory to be synced.\n *\n * If the directory does not exist, it is created.\n *\n * @param dir - The directory to initialize.\n * @returns A Promise that resolves to a Directory instance.\n */\n static async init(dir: string): Promise<Directory> {\n const directory = new Directory(dir);\n await directory.loadIgnoreFile();\n return directory;\n }\n\n /**\n * Returns the relative path from this directory to the specified path.\n *\n * @param to - The path to which the relative path is calculated.\n * @returns The relative path from this directory to the specified path.\n */\n relative(to: string): string {\n if (!path.isAbsolute(to)) {\n // the filepath is already relative\n return to;\n }\n\n return path.relative(this.path, to);\n }\n\n /**\n * Returns the absolute path by resolving the given path segments\n * relative to the directory path.\n *\n * @param pathSegments - The path segments to resolve.\n * @returns The absolute path.\n */\n absolute(...pathSegments: string[]): string {\n const result = path.resolve(this.path, ...pathSegments);\n assert(result.startsWith(this.path), `expected ${result} to be within ${this.path}`);\n return result;\n }\n\n /**\n * Similar to {@linkcode relative} in that it converts an absolute\n * path into a relative one from {@linkcode path}. However, it also\n * changes any slashes to be posix/unix-like forward slashes,\n * condenses repeated slashes into a single slash, and adds a trailing\n * slash if the path is a directory.\n *\n * This is used when sending files to Gadget to ensure that the paths\n * are consistent across platforms.\n *\n * @see https://www.npmjs.com/package/normalize-path\n */\n normalize(filepath: string, isDirectory: boolean): string {\n if (path.isAbsolute(filepath)) {\n filepath = this.relative(filepath);\n }\n\n // true = trim trailing slashes\n filepath = normalizePath(filepath, true);\n\n if (isDirectory) {\n filepath += \"/\";\n }\n\n return filepath;\n }\n\n /**\n * Loads the `.ignore` file in the directory. If the file does not\n * exist, it is silently ignored.\n */\n async loadIgnoreFile(): Promise<void> {\n this._ignorer = ignore.default();\n this._ignorer.add(ALWAYS_IGNORE_PATHS);\n\n try {\n const content = await fs.readFile(this.absolute(\".ignore\"), \"utf8\");\n this._ignorer.add(content);\n } catch (error) {\n swallowEnoent(error);\n }\n }\n\n /**\n * Determines if a file should be ignored based on its filepath.\n *\n * @param filepath - The filepath of the file to check.\n * @returns True if the file should be ignored, false otherwise.\n */\n ignores(filepath: string): boolean {\n filepath = this.relative(filepath);\n if (filepath === \"\") {\n // don't ignore the root dir\n return false;\n }\n\n if (filepath.startsWith(\"..\")) {\n // anything above the root dir is ignored\n return true;\n }\n\n // false = don't trim trailing slashes\n filepath = normalizePath(filepath, false);\n if (this._isHashing && HASHING_IGNORE_PATHS.some((ignored) => filepath.startsWith(ignored))) {\n // special case for hashing\n return true;\n }\n\n return this._ignorer.ignores(filepath);\n }\n\n /**\n * Recursively walks through the directory and yields all non-ignored\n * files and directories within it.\n *\n * @yields - The normalized path of each file and directory.\n */\n async *walk({ dir = this.path } = {}): AsyncGenerator<string> {\n // don't yield the root directory\n if (dir !== this.path) {\n yield this.normalize(dir, true);\n }\n\n for await (const entry of await fs.opendir(dir)) {\n const filepath = path.join(dir, entry.name);\n if (this.ignores(filepath)) {\n continue;\n }\n\n if (entry.isDirectory()) {\n yield* this.walk({ dir: filepath });\n } else if (entry.isFile()) {\n yield this.normalize(filepath, false);\n }\n }\n }\n\n /**\n * Calculates the hash of each file and directory and returns an\n * object containing the hashes keyed by the normalized file path.\n *\n * @returns A Promise that resolves to an object containing the hashes\n * of each file.\n */\n async hashes(): Promise<Hashes> {\n try {\n this._isHashing = true;\n const files = {} as Hashes;\n\n for await (const normalizedPath of this.walk()) {\n const absolutePath = this.absolute(normalizedPath);\n files[normalizedPath] = await hash(absolutePath);\n }\n\n return files;\n } finally {\n this._isHashing = false;\n }\n }\n\n async hasFiles(): Promise<boolean> {\n return !(await this.isEmptyOrNonExistent());\n }\n\n async isEmptyOrNonExistent(): Promise<boolean> {\n let isEmptyOrNonExistent = true;\n try {\n for await (const _ of this.walk()) {\n isEmptyOrNonExistent = false;\n break;\n }\n } catch (error) {\n swallowEnoent(error);\n }\n return isEmptyOrNonExistent;\n }\n}\n\n/**\n * Key/value pairs where the key is the normalized path and the value is\n * the result of {@linkcode hash} for that path.\n */\nexport type Hashes = Record<string, Hash>;\n\nexport type Hash = {\n /**\n * The SHA-1 hash of the file or directory.\n *\n * If the path points to a directory, the hash is calculated based on\n * the directory's basename. If the path points to a file, the hash is\n * calculated based on the file's basename and contents.\n */\n sha1: string;\n\n /**\n * The Unix-style file permissions of the file or directory, or\n * undefined if the platform that generated this hash doesn't support\n * them.\n *\n * @example 0o644\n * @see supportsPermissions\n */\n permissions?: number;\n};\n\n/**\n * Whether the current platform supports Unix-style file permissions.\n *\n * Windows doesn't support Unix-style file permissions and all file\n * permissions retrieved via `node:fs` on Windows are translated to 666\n * or 444.\n */\nexport const supportsPermissions = process.platform === \"linux\" || process.platform === \"darwin\";\n\n/**\n * Calculates the {@linkcode Hash} of the file or directory at the\n * specified absolute path.\n *\n * @param absolutePath - The absolute path to the file or directory.\n * @returns A Promise that resolves to the {@linkcode Hash} of the file\n * or directory.\n */\nconst hash = async (absolutePath: string): Promise<Hash> => {\n const sha1 = createHash(\"sha1\");\n sha1.update(path.basename(absolutePath));\n\n const stats = await fs.stat(absolutePath);\n\n let permissions;\n if (supportsPermissions) {\n // strip everything but the permissions\n permissions = stats.mode & 0o777;\n }\n\n if (stats.isDirectory()) {\n return { sha1: sha1.digest(\"hex\"), permissions };\n }\n\n // windows uses CRLF line endings whereas unix uses LF line endings so\n // we always strip out CR bytes (0x0d) when hashing files. this does\n // make us blind to files that only differ by CR bytes, but that's a\n // tradeoff we're willing to make.\n const removeCR = new Transform({\n transform(chunk: Buffer, _encoding, callback) {\n if (!chunk.includes(0x0d)) {\n callback(undefined, chunk);\n return;\n }\n\n const filteredChunk = Buffer.alloc(chunk.length);\n let i = 0;\n for (const byte of chunk) {\n if (byte !== 0x0d) {\n filteredChunk[i++] = byte;\n }\n }\n\n callback(undefined, filteredChunk.slice(0, i));\n },\n });\n\n await pipeline(fs.createReadStream(absolutePath), removeCR, sha1);\n\n return { sha1: sha1.digest(\"hex\"), permissions };\n};\n\n/**\n * Swallows ENOENT errors and throws any other errors.\n *\n * @param error - The error to handle.\n * @throws The original error if it is not an ENOENT error.\n */\nexport const swallowEnoent = (error: unknown): void => {\n if (error && typeof error === \"object\" && \"code\" in error && error.code === \"ENOENT\") {\n return;\n }\n throw error;\n};\n"],"names":["fs","ignore","assert","createHash","path","Transform","pipeline","normalizePath","ALWAYS_IGNORE_PATHS","HASHING_IGNORE_PATHS","Directory","init","dir","directory","loadIgnoreFile","relative","to","isAbsolute","absolute","pathSegments","result","resolve","startsWith","normalize","filepath","isDirectory","_ignorer","default","add","content","readFile","error","swallowEnoent","ignores","_isHashing","some","ignored","walk","entry","opendir","join","name","isFile","hashes","files","normalizedPath","absolutePath","hash","hasFiles","isEmptyOrNonExistent","_","supportsPermissions","process","platform","sha1","update","basename","stats","stat","permissions","mode","digest","removeCR","transform","chunk","_encoding","callback","includes","undefined","filteredChunk","Buffer","alloc","length","i","byte","slice","createReadStream","code"],"mappings":"AAAA;;;;;CAKC;AACD,OAAOA,QAAQ,WAAW;AAE1B,OAAOC,YAAY,SAAS;AAC5B,OAAOC,YAAY,cAAc;AACjC,SAASC,UAAU,QAAQ,cAAc;AACzC,OAAOC,UAAU,YAAY;AAC7B,SAASC,SAAS,QAAQ,cAAc;AACxC,SAASC,QAAQ,QAAQ,uBAAuB;AAChD,OAAOC,mBAAmB,iBAAiB;AAE3C;;CAEC,GACD,OAAO,MAAMC,sBAAsB;IAAC;IAAa;IAAgB;CAAO,CAAU;AAElF;;;;CAIC,GACD,OAAO,MAAMC,uBAAuB;I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