@contember/cli 2.2.0-alpha.18 → 2.2.0-alpha.19

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 (114) hide show
  1. package/dist/development/src/commands/tenant/policy/TenantAuthLogCommand.cjs +1 -2
  2. package/dist/development/src/commands/tenant/policy/TenantAuthLogCommand.cjs.map +1 -1
  3. package/dist/development/src/commands/tenant/policy/TenantAuthLogCommand.js +2 -3
  4. package/dist/development/src/commands/tenant/policy/TenantAuthLogCommand.js.map +1 -1
  5. package/dist/development/src/commands/transfer/ExportCommand.cjs +2 -2
  6. package/dist/development/src/commands/transfer/ExportCommand.cjs.map +1 -1
  7. package/dist/development/src/commands/transfer/ImportCommand.cjs +2 -2
  8. package/dist/development/src/commands/transfer/ImportCommand.cjs.map +1 -1
  9. package/dist/development/src/lib/VersionChecker.cjs +2 -19
  10. package/dist/development/src/lib/VersionChecker.cjs.map +1 -1
  11. package/dist/development/src/lib/VersionChecker.js +2 -2
  12. package/dist/development/src/lib/VersionChecker.js.map +1 -1
  13. package/dist/development/src/lib/fs/FileSystem.cjs +36 -4
  14. package/dist/development/src/lib/fs/FileSystem.cjs.map +1 -1
  15. package/dist/development/src/lib/fs/FileSystem.js +35 -3
  16. package/dist/development/src/lib/fs/FileSystem.js.map +1 -1
  17. package/dist/development/src/lib/migrations/MigrationPrinter.cjs +9 -12
  18. package/dist/development/src/lib/migrations/MigrationPrinter.cjs.map +1 -1
  19. package/dist/development/src/lib/migrations/MigrationPrinter.js +10 -13
  20. package/dist/development/src/lib/migrations/MigrationPrinter.js.map +1 -1
  21. package/dist/development/src/lib/migrations/MigrationSnapshotFacade.cjs +1 -1
  22. package/dist/development/src/lib/migrations/MigrationSnapshotFacade.cjs.map +1 -1
  23. package/dist/development/src/lib/migrations/MigrationSnapshotFacade.js +1 -1
  24. package/dist/development/src/lib/migrations/MigrationSnapshotFacade.js.map +1 -1
  25. package/dist/development/src/lib/prompt/prompt.cjs +41 -7
  26. package/dist/development/src/lib/prompt/prompt.cjs.map +1 -1
  27. package/dist/development/src/lib/prompt/prompt.js +41 -7
  28. package/dist/development/src/lib/prompt/prompt.js.map +1 -1
  29. package/dist/development/src/lib/transfer/DataTransferClient.cjs +2 -2
  30. package/dist/development/src/lib/transfer/DataTransferClient.cjs.map +1 -1
  31. package/dist/development/src/lib/versionRange.cjs +276 -0
  32. package/dist/development/src/lib/versionRange.cjs.map +1 -0
  33. package/dist/development/src/lib/versionRange.js +276 -0
  34. package/dist/development/src/lib/versionRange.js.map +1 -0
  35. package/dist/production/src/commands/tenant/policy/TenantAuthLogCommand.cjs +1 -2
  36. package/dist/production/src/commands/tenant/policy/TenantAuthLogCommand.cjs.map +1 -1
  37. package/dist/production/src/commands/tenant/policy/TenantAuthLogCommand.js +2 -3
  38. package/dist/production/src/commands/tenant/policy/TenantAuthLogCommand.js.map +1 -1
  39. package/dist/production/src/commands/transfer/ExportCommand.cjs +2 -2
  40. package/dist/production/src/commands/transfer/ExportCommand.cjs.map +1 -1
  41. package/dist/production/src/commands/transfer/ImportCommand.cjs +2 -2
  42. package/dist/production/src/commands/transfer/ImportCommand.cjs.map +1 -1
  43. package/dist/production/src/lib/VersionChecker.cjs +2 -19
  44. package/dist/production/src/lib/VersionChecker.cjs.map +1 -1
  45. package/dist/production/src/lib/VersionChecker.js +2 -2
  46. package/dist/production/src/lib/VersionChecker.js.map +1 -1
  47. package/dist/production/src/lib/fs/FileSystem.cjs +36 -4
  48. package/dist/production/src/lib/fs/FileSystem.cjs.map +1 -1
  49. package/dist/production/src/lib/fs/FileSystem.js +35 -3
  50. package/dist/production/src/lib/fs/FileSystem.js.map +1 -1
  51. package/dist/production/src/lib/migrations/MigrationPrinter.cjs +9 -12
  52. package/dist/production/src/lib/migrations/MigrationPrinter.cjs.map +1 -1
  53. package/dist/production/src/lib/migrations/MigrationPrinter.js +10 -13
  54. package/dist/production/src/lib/migrations/MigrationPrinter.js.map +1 -1
  55. package/dist/production/src/lib/migrations/MigrationSnapshotFacade.cjs +1 -1
  56. package/dist/production/src/lib/migrations/MigrationSnapshotFacade.cjs.map +1 -1
  57. package/dist/production/src/lib/migrations/MigrationSnapshotFacade.js +1 -1
  58. package/dist/production/src/lib/migrations/MigrationSnapshotFacade.js.map +1 -1
  59. package/dist/production/src/lib/prompt/prompt.cjs +41 -7
  60. package/dist/production/src/lib/prompt/prompt.cjs.map +1 -1
  61. package/dist/production/src/lib/prompt/prompt.js +41 -7
  62. package/dist/production/src/lib/prompt/prompt.js.map +1 -1
  63. package/dist/production/src/lib/transfer/DataTransferClient.cjs +2 -2
  64. package/dist/production/src/lib/transfer/DataTransferClient.cjs.map +1 -1
  65. package/dist/production/src/lib/versionRange.cjs +276 -0
  66. package/dist/production/src/lib/versionRange.cjs.map +1 -0
  67. package/dist/production/src/lib/versionRange.js +276 -0
  68. package/dist/production/src/lib/versionRange.js.map +1 -0
  69. package/dist/types/commands/tenant/policy/TenantAuthLogCommand.d.ts.map +1 -1
  70. package/dist/types/lib/VersionChecker.d.ts.map +1 -1
  71. package/dist/types/lib/fs/FileSystem.d.ts +5 -0
  72. package/dist/types/lib/fs/FileSystem.d.ts.map +1 -1
  73. package/dist/types/lib/migrations/MigrationPrinter.d.ts.map +1 -1
  74. package/dist/types/lib/prompt/prompt.d.ts +17 -4
  75. package/dist/types/lib/prompt/prompt.d.ts.map +1 -1
  76. package/dist/types/lib/versionRange.d.ts +9 -0
  77. package/dist/types/lib/versionRange.d.ts.map +1 -0
  78. package/dist/types/tsconfig.tsbuildinfo +1 -1
  79. package/package.json +17 -21
  80. package/src/commands/tenant/policy/TenantAuthLogCommand.ts +2 -5
  81. package/src/lib/VersionChecker.ts +3 -2
  82. package/src/lib/fs/FileSystem.ts +46 -3
  83. package/src/lib/migrations/MigrationPrinter.ts +10 -15
  84. package/src/lib/migrations/MigrationSnapshotFacade.ts +1 -1
  85. package/src/lib/prompt/prompt.ts +55 -18
  86. package/src/lib/versionRange.ts +347 -0
  87. package/tests/cases/unit/MigrationDiffCommand.test.ts +3 -7
  88. package/tests/cases/unit/MigrationExecutionFacade.test.ts +20 -25
  89. package/tests/cases/unit/MigrationRebaseCommand.test.ts +1 -3
  90. package/tests/cases/unit/MigrationSnapshotFacade.test.ts +1 -3
  91. package/tests/cases/unit/MigrationsValidator.test.ts +2 -2
  92. package/tests/cases/unit/actions.test.ts +2 -2
  93. package/tests/cases/unit/deploy.test.ts +4 -28
  94. package/tests/cases/unit/fileSystem.test.ts +63 -0
  95. package/tests/cases/unit/fixtures/semverCorpus.json +1157 -0
  96. package/tests/cases/unit/project.test.ts +2 -2
  97. package/tests/cases/unit/prompt.test.ts +64 -0
  98. package/tests/cases/unit/transfer.test.ts +1 -3
  99. package/tests/cases/unit/versionRange.test.ts +57 -0
  100. package/dist/development/src/lib/prompt/prompt.internal.cjs +0 -21
  101. package/dist/development/src/lib/prompt/prompt.internal.cjs.map +0 -1
  102. package/dist/development/src/lib/prompt/prompt.internal.js +0 -21
  103. package/dist/development/src/lib/prompt/prompt.internal.js.map +0 -1
  104. package/dist/production/src/lib/prompt/prompt.internal.cjs +0 -21
  105. package/dist/production/src/lib/prompt/prompt.internal.cjs.map +0 -1
  106. package/dist/production/src/lib/prompt/prompt.internal.js +0 -21
  107. package/dist/production/src/lib/prompt/prompt.internal.js.map +0 -1
  108. package/dist/types/lib/prompt/prompt.internal.d.ts +0 -37
  109. package/dist/types/lib/prompt/prompt.internal.d.ts.map +0 -1
  110. package/dist/types/lib/prompt/prompt.test.d.ts +0 -2
  111. package/dist/types/lib/prompt/prompt.test.d.ts.map +0 -1
  112. package/src/lib/prompt/prompt.internal.ts +0 -69
  113. package/src/lib/prompt/prompt.test.ts +0 -100
  114. package/types/chalk-table/index.d.ts +0 -9
@@ -2,7 +2,6 @@ import { afterEach, beforeEach, expect, test } from 'bun:test'
2
2
  import * as fs from 'node:fs/promises'
3
3
  import * as os from 'node:os'
4
4
  import * as path from 'node:path'
5
- import prompts from 'prompts'
6
5
  import { Schema } from '@contember/schema'
7
6
  import { c, createSchema } from '@contember/schema-definition'
8
7
  import { emptySchema } from '@contember/schema-utils'
@@ -128,8 +127,7 @@ const buildCommand = async (schema: Schema, existingMigration = false) => {
128
127
  test('declining a diff leaves a new project filesystem untouched', async () => {
129
128
  const { command } = await buildCommand(createSchema(BlogModel))
130
129
  const before = await listTree()
131
- const { output } = createTestOutput({ stdinTty: true, stderrTty: true })
132
- prompts.inject(['no'])
130
+ const { output } = createTestOutput({ stdinTty: true, stderrTty: true, answers: ['3'] })
133
131
 
134
132
  const error = await command.run(['change'], output).then(() => null, (reason: unknown) => reason)
135
133
 
@@ -139,8 +137,7 @@ test('declining a diff leaves a new project filesystem untouched', async () => {
139
137
 
140
138
  test('executing a new diff requires a second confirmation when older migrations are pending', async () => {
141
139
  const { command, executionConfirmations } = await buildCommand(createSchema(BlogModel), true)
142
- const { output } = createTestOutput({ stdinTty: true, stderrTty: true })
143
- prompts.inject(['yes'])
140
+ const { output } = createTestOutput({ stdinTty: true, stderrTty: true, answers: ['1'] })
144
141
 
145
142
  await command.run(['change', '--execute'], output)
146
143
 
@@ -149,8 +146,7 @@ test('executing a new diff requires a second confirmation when older migrations
149
146
 
150
147
  test('executing a new diff does not require a redundant second confirmation when it is the only pending migration', async () => {
151
148
  const { command, executionConfirmations } = await buildCommand(createSchema(BlogModel))
152
- const { output } = createTestOutput({ stdinTty: true, stderrTty: true })
153
- prompts.inject(['yes'])
149
+ const { output } = createTestOutput({ stdinTty: true, stderrTty: true, answers: ['1'] })
154
150
 
155
151
  await command.run(['change', '--execute'], output)
156
152
 
@@ -2,7 +2,7 @@ import { afterEach, beforeAll, beforeEach, expect, test } from 'bun:test'
2
2
  import * as fs from 'node:fs/promises'
3
3
  import * as os from 'node:os'
4
4
  import * as path from 'node:path'
5
- import chalk from 'chalk'
5
+ import { setColorsEnabled } from '@contember/cli-common'
6
6
  import { GraphQlClient, GraphQlClientError } from '@contember/graphql-client'
7
7
  import {
8
8
  ExecutedMigrationInfo,
@@ -40,7 +40,6 @@ import { TenantClientProvider } from '../../../src/lib/TenantClientProvider.js'
40
40
  import { TenantApiTransport } from '../../../src/lib/tenant/TenantApiTransport.js'
41
41
  import { TenantCreateProjectDetails, TenantCreateProjectResult, TenantProjectClient } from '../../../src/lib/tenant/clients/TenantProjectClient.js'
42
42
  import { createTestOutput } from '../../../../cli-common/tests/lib/testOutput.js'
43
- import prompts from 'prompts'
44
43
  import { Actions, Schema } from '@contember/schema'
45
44
  import { UndefinedActionsVariablesChecker } from '../../../src/lib/actions/UndefinedActionsVariablesChecker.js'
46
45
 
@@ -156,7 +155,7 @@ namespace ExecutionModel {
156
155
  }
157
156
 
158
157
  beforeAll(() => {
159
- chalk.level = 0
158
+ setColorsEnabled(false)
160
159
  })
161
160
 
162
161
  beforeEach(async () => {
@@ -173,15 +172,17 @@ const withTargets = (schema: Schema, targets: Actions.Schema['targets']): Schema
173
172
  })
174
173
 
175
174
  const createHarness = async (
176
- { state = false, migration = false, snapshot = false, remoteExecuted = false, remoteMissing = false, stdinTty = false, targets = {} }: {
177
- state?: boolean
178
- migration?: boolean
179
- snapshot?: boolean
180
- remoteExecuted?: boolean
181
- remoteMissing?: boolean
182
- stdinTty?: boolean
183
- targets?: Actions.Schema['targets']
184
- } = {},
175
+ { state = false, migration = false, snapshot = false, remoteExecuted = false, remoteMissing = false, stdinTty = false, answers = [], targets = {} }:
176
+ {
177
+ state?: boolean
178
+ migration?: boolean
179
+ snapshot?: boolean
180
+ remoteExecuted?: boolean
181
+ remoteMissing?: boolean
182
+ stdinTty?: boolean
183
+ answers?: readonly string[]
184
+ targets?: Actions.Schema['targets']
185
+ } = {},
185
186
  ) => {
186
187
  const events: Event[] = []
187
188
  const migrationsDir = path.join(workDir, 'migrations')
@@ -206,7 +207,7 @@ const createHarness = async (
206
207
  }
207
208
  const schemaVersionBuilder = new SchemaVersionBuilder(migrationsResolver, schemaMigrator, stateManager)
208
209
  const snapshotManager = new SnapshotManager(path.join(migrationsDir, 'snapshot.json'))
209
- const io = createTestOutput({ stdinTty, stderrTty: stdinTty })
210
+ const io = createTestOutput({ stdinTty, stderrTty: stdinTty, answers })
210
211
  const snapshotFacade = new RecordingSnapshotFacade(
211
212
  events,
212
213
  migrationsResolver,
@@ -283,8 +284,7 @@ test('non-interactive state-only execution refuses before any mutation or reques
283
284
  })
284
285
 
285
286
  test('declining state-only execution does not create a project or call the executor', async () => {
286
- const { facade, events } = await createHarness({ state: true, stdinTty: true })
287
- prompts.inject(['no'])
287
+ const { facade, events } = await createHarness({ state: true, stdinTty: true, answers: ['2'] })
288
288
 
289
289
  const error = await facade.execute({ requireConfirmation: true }).then(() => null, (reason: unknown) => reason)
290
290
 
@@ -293,9 +293,8 @@ test('declining state-only execution does not create a project or call the execu
293
293
  })
294
294
 
295
295
  test('does not notify confirmation when interactive execution is declined', async () => {
296
- const { facade } = await createHarness({ state: true, stdinTty: true })
296
+ const { facade } = await createHarness({ state: true, stdinTty: true, answers: ['2'] })
297
297
  let confirmations = 0
298
- prompts.inject(['no'])
299
298
 
300
299
  await facade.execute({
301
300
  requireConfirmation: true,
@@ -340,8 +339,7 @@ test('an already-current project with local migrations returns without prompting
340
339
  })
341
340
 
342
341
  test('declining with a usable snapshot neither builds nor applies it', async () => {
343
- const { facade, events } = await createHarness({ migration: true, snapshot: true, stdinTty: true })
344
- prompts.inject(['no'])
342
+ const { facade, events } = await createHarness({ migration: true, snapshot: true, stdinTty: true, answers: ['3'] })
345
343
 
346
344
  const error = await facade.execute({ requireConfirmation: true }).then(() => null, (reason: unknown) => reason)
347
345
 
@@ -350,8 +348,7 @@ test('declining with a usable snapshot neither builds nor applies it', async ()
350
348
  })
351
349
 
352
350
  test('confirmed snapshot execution creates a tokenless project before building and applying the snapshot', async () => {
353
- const { facade, events } = await createHarness({ migration: true, snapshot: true, remoteMissing: true, stdinTty: true })
354
- prompts.inject(['yes'])
351
+ const { facade, events } = await createHarness({ migration: true, snapshot: true, remoteMissing: true, stdinTty: true, answers: ['1'] })
355
352
 
356
353
  await facade.execute({ requireConfirmation: true })
357
354
 
@@ -367,8 +364,7 @@ test('confirmed snapshot execution creates a tokenless project before building a
367
364
  })
368
365
 
369
366
  test('confirmed state-only execution reaches the executor with schema state', async () => {
370
- const { facade, events } = await createHarness({ state: true, stdinTty: true })
371
- prompts.inject(['yes'])
367
+ const { facade, events } = await createHarness({ state: true, stdinTty: true, answers: ['1'] })
372
368
 
373
369
  await facade.execute({ requireConfirmation: true })
374
370
 
@@ -378,9 +374,8 @@ test('confirmed state-only execution reaches the executor with schema state', as
378
374
  })
379
375
 
380
376
  test('notifies confirmation once after interactive execution is accepted', async () => {
381
- const { facade } = await createHarness({ state: true, stdinTty: true })
377
+ const { facade } = await createHarness({ state: true, stdinTty: true, answers: ['1'] })
382
378
  let confirmations = 0
383
- prompts.inject(['yes'])
384
379
 
385
380
  await facade.execute({
386
381
  requireConfirmation: true,
@@ -2,7 +2,6 @@ import { afterEach, beforeEach, expect, test } from 'bun:test'
2
2
  import * as fs from 'node:fs/promises'
3
3
  import * as os from 'node:os'
4
4
  import * as path from 'node:path'
5
- import prompts from 'prompts'
6
5
  import { JsonLoader, MigrationFilesManager, MigrationParser, MigrationsResolver, VERSION_LATEST } from '@contember/migrations-client'
7
6
  import { CliError, ExitCode } from '@contember/cli-common'
8
7
  import { MigrationRebaseCommand } from '../../../src/commands/migrations/MigrationRebaseCommand.js'
@@ -49,8 +48,7 @@ test('non-interactive rebase refusal returns an input error without rewriting mi
49
48
 
50
49
  test('declining rebase returns OPERATION_ABORTED without invoking the facade', async () => {
51
50
  const { command, getCalls } = await buildCommand()
52
- const { output } = createTestOutput({ stdinTty: true, stderrTty: true })
53
- prompts.inject([false])
51
+ const { output } = createTestOutput({ stdinTty: true, stderrTty: true, answers: ['n'] })
54
52
 
55
53
  const error = await command.run(['2024-01-01-120000'], output).then(() => null, (reason: unknown) => reason)
56
54
 
@@ -21,7 +21,6 @@ import { MigrationSnapshotFacade } from '../../../src/lib/migrations/MigrationSn
21
21
  import { MigrationSnapshotCommand } from '../../../src/commands/migrations/MigrationSnapshotCommand.js'
22
22
  import { CliError, ExitCode } from '@contember/cli-common'
23
23
  import { createTestOutput } from '../../../../cli-common/tests/lib/testOutput.js'
24
- import prompts from 'prompts'
25
24
 
26
25
  namespace ModelA {
27
26
  export class Author {
@@ -149,8 +148,7 @@ describe('MigrationSnapshotFacade', () => {
149
148
 
150
149
  test('declining snapshot creation does not write', async () => {
151
150
  const { command, snapshotManager } = await setup(migrationsDir)
152
- const { output } = createTestOutput({ stdinTty: true, stderrTty: true })
153
- prompts.inject([false])
151
+ const { output } = createTestOutput({ stdinTty: true, stderrTty: true, answers: ['n'] })
154
152
 
155
153
  const error = await command.run([], output).then(() => null, (reason: unknown) => reason)
156
154
 
@@ -1,5 +1,5 @@
1
1
  import { beforeAll, expect, test } from 'bun:test'
2
- import chalk from 'chalk'
2
+ import { setColorsEnabled } from '@contember/cli-common'
3
3
  import { emptySchema } from '@contember/schema-utils'
4
4
  import { MigrationDescriber, ModificationHandlerFactory, SchemaMigrator, VERSION_LATEST } from '@contember/schema-migrations'
5
5
  import { Migration } from '@contember/migrations-client'
@@ -8,7 +8,7 @@ import { createTestOutput } from '../../../../cli-common/tests/lib/testOutput.js
8
8
 
9
9
  beforeAll(() => {
10
10
  // deterministic assertions regardless of the terminal the suite runs in
11
- chalk.level = 0
11
+ setColorsEnabled(false)
12
12
  })
13
13
 
14
14
  // A migration that grants a role on an entity the model does not have — applying it succeeds, but the
@@ -1,5 +1,5 @@
1
1
  import { beforeAll, describe, expect, test } from 'bun:test'
2
- import chalk from 'chalk'
2
+ import { setColorsEnabled } from '@contember/cli-common'
3
3
  import { CliError, ExitCode, Output, OutputStream, renderCliError } from '@contember/cli-common'
4
4
  import { GraphQlClient } from '@contember/graphql-client'
5
5
  import { RemoteProjectResolver } from '../../../src/lib/project/RemoteProjectResolver.js'
@@ -15,7 +15,7 @@ import { ActionsStopEventCommand } from '../../../src/commands/actions/ActionsSt
15
15
 
16
16
  beforeAll(() => {
17
17
  // deterministic assertions regardless of the terminal the suite runs in
18
- chalk.level = 0
18
+ setColorsEnabled(false)
19
19
  })
20
20
 
21
21
  // Mirrors packages/cli-common/tests/lib/testOutput.ts — that helper isn't part of the package's
@@ -1,6 +1,5 @@
1
1
  import { afterEach, describe, expect, test } from 'bun:test'
2
- import { CliError, ExitCode, Input, Output, OutputStream } from '@contember/cli-common'
3
- import prompts from 'prompts'
2
+ import { CliError, ExitCode, Input } from '@contember/cli-common'
4
3
  import { AdminClient } from '../../../src/lib/admin/AdminClient.js'
5
4
  import { AdminDeployer } from '../../../src/lib/admin/AdminDeployer.js'
6
5
  import { DeployCommand, DeployResult } from '../../../src/commands/deploy/DeployCommand.js'
@@ -16,28 +15,7 @@ import { tmpdir } from 'node:os'
16
15
  import { join } from 'node:path'
17
16
  import { emptySchema } from '@contember/schema-utils'
18
17
  import { SchemaStateManager } from '@contember/migrations-client'
19
-
20
- // Mirrors packages/cli-common/tests/lib/testOutput.ts — that helper isn't part of the package's
21
- // public exports, so it can't be imported across the package boundary.
22
- class CapturingStream implements OutputStream {
23
- public chunks: string[] = []
24
-
25
- constructor(public readonly isTty: boolean = false, public readonly columns: number = 80) {}
26
-
27
- public write(text: string): void {
28
- this.chunks.push(text)
29
- }
30
-
31
- public get text(): string {
32
- return this.chunks.join('')
33
- }
34
- }
35
-
36
- const createTestOutput = ({ stdinTty = false, stderrTty = false }: { stdinTty?: boolean; stderrTty?: boolean } = {}) => {
37
- const stdout = new CapturingStream()
38
- const stderr = new CapturingStream(stderrTty)
39
- return { stdout, stderr, output: new Output({ stdout, stderr, isStdinTty: () => stdinTty }) }
40
- }
18
+ import { createTestOutput } from '../../../../cli-common/tests/lib/testOutput.js'
41
19
 
42
20
  // pathExists is the only FileSystem method DeployCommand touches directly.
43
21
  class StubFileSystem extends FileSystem {
@@ -334,8 +312,7 @@ describe('DeployCommand', () => {
334
312
  adminDistDir: '/project/admin/dist',
335
313
  facadeResult: false,
336
314
  })
337
- const { output } = createTestOutput({ stdinTty: true, stderrTty: true })
338
- prompts.inject([true])
315
+ const { output } = createTestOutput({ stdinTty: true, stderrTty: true, answers: ['y'] })
339
316
 
340
317
  const code = await command.execute(new Input({}, { admin: 'https://admin.example.com' }), output)
341
318
 
@@ -348,8 +325,7 @@ describe('DeployCommand', () => {
348
325
  adminDistDir: '/project/admin/dist',
349
326
  facadeResult: false,
350
327
  })
351
- const { output } = createTestOutput({ stdinTty: true, stderrTty: true })
352
- prompts.inject([false])
328
+ const { output } = createTestOutput({ stdinTty: true, stderrTty: true, answers: ['n'] })
353
329
 
354
330
  const code = await command.execute(new Input({}, { admin: 'https://admin.example.com' }), output)
355
331
 
@@ -0,0 +1,63 @@
1
+ import { afterAll, beforeAll, describe, expect, test } from 'bun:test'
2
+ import { mkdir, mkdtemp, rm, symlink, writeFile } from 'node:fs/promises'
3
+ import { tmpdir } from 'node:os'
4
+ import { join } from 'node:path'
5
+ import { FileSystem } from '../../../src/lib/fs/FileSystem.js'
6
+
7
+ describe('FileSystem.listDirectories', () => {
8
+ let dir: string
9
+ const fs = new FileSystem()
10
+
11
+ beforeAll(async () => {
12
+ dir = await mkdtemp(join(tmpdir(), 'contember-cli-fs-'))
13
+ for (const it of ['packages/a', 'packages/b', 'packages/.hidden', 'packages/c/nested', 'apps/x']) {
14
+ await mkdir(join(dir, it), { recursive: true })
15
+ }
16
+ await writeFile(join(dir, 'packages/file.txt'), '')
17
+ await symlink(join(dir, 'apps/x'), join(dir, 'packages/link'))
18
+ })
19
+
20
+ afterAll(async () => {
21
+ await rm(dir, { recursive: true, force: true })
22
+ })
23
+
24
+ const list = async (patterns: string[]) => (await fs.listDirectories(dir, patterns)).sort()
25
+
26
+ test('matches directories only, skips dot directories, follows symlinks', async () => {
27
+ expect(await list(['packages/*'])).toEqual(['packages/a', 'packages/b', 'packages/c', 'packages/link'])
28
+ })
29
+
30
+ test('globstar does not return its base directory', async () => {
31
+ expect(await list(['packages/**'])).toEqual(['packages/a', 'packages/b', 'packages/c', 'packages/c/nested', 'packages/link'])
32
+ })
33
+
34
+ test('negated patterns exclude, literal and overlapping patterns are deduplicated', async () => {
35
+ expect(await list(['packages/*', 'apps/*', 'packages/a', '!packages/b'])).toEqual(['apps/x', 'packages/a', 'packages/c', 'packages/link'])
36
+ })
37
+
38
+ test('a negation removes only what it matches, not the subtree', async () => {
39
+ expect(await list(['packages/**', '!packages/c'])).toEqual(['packages/a', 'packages/b', 'packages/c/nested', 'packages/link'])
40
+ expect(await list(['packages/**', '!packages/c/**'])).toEqual(['packages/a', 'packages/b', 'packages/link'])
41
+ expect(await list(['packages/**', '!**/c/**'])).toEqual(['packages/a', 'packages/b', 'packages/link'])
42
+ })
43
+
44
+ test('a literal pattern returns the base of another globstar pattern', async () => {
45
+ expect(await list(['packages/**', 'packages'])).toEqual([
46
+ 'packages',
47
+ 'packages/a',
48
+ 'packages/b',
49
+ 'packages/c',
50
+ 'packages/c/nested',
51
+ 'packages/link',
52
+ ])
53
+ })
54
+
55
+ test('leading ./ is normalised', async () => {
56
+ expect(await list(['./apps/*'])).toEqual(['apps/x'])
57
+ })
58
+
59
+ test('no positive pattern matches nothing', async () => {
60
+ expect(await list([])).toEqual([])
61
+ expect(await list(['!packages/a'])).toEqual([])
62
+ })
63
+ })