From b91883beaf931d72dacf992a44cc1adbf80281aa Mon Sep 17 00:00:00 2001 From: josefaidt Date: Fri, 13 Dec 2024 16:23:52 -0800 Subject: [PATCH 1/3] import named export from parcel/watcher --- .changeset/chilled-pants-kiss.md | 5 +++++ packages/sandbox/src/file_watching_sandbox.ts | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 .changeset/chilled-pants-kiss.md diff --git a/.changeset/chilled-pants-kiss.md b/.changeset/chilled-pants-kiss.md new file mode 100644 index 0000000000..7859728db7 --- /dev/null +++ b/.changeset/chilled-pants-kiss.md @@ -0,0 +1,5 @@ +--- +'@aws-amplify/sandbox': patch +--- + +move from importing the default export from the commonjs distribution of parcle/watcher to named export diff --git a/packages/sandbox/src/file_watching_sandbox.ts b/packages/sandbox/src/file_watching_sandbox.ts index aa1bb1c6a1..a6a9794074 100644 --- a/packages/sandbox/src/file_watching_sandbox.ts +++ b/packages/sandbox/src/file_watching_sandbox.ts @@ -1,5 +1,5 @@ import debounce from 'debounce-promise'; -import parcelWatcher, { subscribe } from '@parcel/watcher'; +import { subscribe } from '@parcel/watcher'; import { AmplifySandboxExecutor } from './sandbox_executor.js'; import { BackendIdSandboxResolver, @@ -197,7 +197,7 @@ export class FileWatchingSandbox extends EventEmitter implements Sandbox { }); if (watchForChanges) { - this.watcherSubscription = await parcelWatcher.subscribe( + this.watcherSubscription = await subscribe( watchDir, async (_, events) => { // Log and track file changes. From 4e1050475fcecb4b904d861fb1dd4645fec87c7e Mon Sep 17 00:00:00 2001 From: josefaidt Date: Mon, 16 Dec 2024 16:54:00 -0800 Subject: [PATCH 2/3] try injecting subscribe --- packages/sandbox/src/file_watching_sandbox.test.ts | 12 ++++++++---- packages/sandbox/src/file_watching_sandbox.ts | 9 +++++---- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/packages/sandbox/src/file_watching_sandbox.test.ts b/packages/sandbox/src/file_watching_sandbox.test.ts index 68e410a56f..a159bb8425 100644 --- a/packages/sandbox/src/file_watching_sandbox.test.ts +++ b/packages/sandbox/src/file_watching_sandbox.test.ts @@ -1,6 +1,6 @@ import { afterEach, beforeEach, describe, it, mock } from 'node:test'; import path from 'path'; -import watcher from '@parcel/watcher'; +import watcher, { subscribe } from '@parcel/watcher'; import { CDK_DEFAULT_BOOTSTRAP_VERSION_PARAMETER_NAME, FileWatchingSandbox, @@ -39,7 +39,8 @@ import { // Watcher mocks const unsubscribeMockFn = mock.fn(); -const subscribeMock = mock.method(watcher, 'subscribe', async () => { +// eslint-disable-next-line @typescript-eslint/no-unused-vars +const subscribeMock = mock.fn(async (_dir, _effect, _options) => { return { unsubscribe: unsubscribeMockFn }; }); const packageManagerControllerFactory = new PackageManagerControllerFactory( @@ -147,7 +148,8 @@ void describe('Sandbox to check if region is bootstrapped', () => { ssmClientMock, functionsLogStreamerMock as unknown as LambdaFunctionLogStreamer, printer as unknown as Printer, - openMock as never + openMock as never, + subscribeMock as never ); ssmClientSendMock.mock.resetCalls(); @@ -1163,7 +1165,8 @@ const setupAndStartSandbox = async ( testData.ssmClient, testData.functionsLogStreamer, printer as unknown as Printer, - testData.open ?? _open + testData.open ?? _open, + testData.subscribe ?? subscribe ); await sandboxInstance.start(sandboxOptions); @@ -1216,4 +1219,5 @@ type SandboxTestData = { ssmClient: SSMClient; functionsLogStreamer: LambdaFunctionLogStreamer; open?: typeof _open; + subscribe?: typeof subscribe; }; diff --git a/packages/sandbox/src/file_watching_sandbox.ts b/packages/sandbox/src/file_watching_sandbox.ts index a6a9794074..b056b85b8f 100644 --- a/packages/sandbox/src/file_watching_sandbox.ts +++ b/packages/sandbox/src/file_watching_sandbox.ts @@ -1,5 +1,5 @@ import debounce from 'debounce-promise'; -import { subscribe } from '@parcel/watcher'; +import { subscribe as _subscribe } from '@parcel/watcher'; import { AmplifySandboxExecutor } from './sandbox_executor.js'; import { BackendIdSandboxResolver, @@ -66,7 +66,7 @@ export const getBootstrapUrl = (region: string) => * Runs a file watcher and deploys */ export class FileWatchingSandbox extends EventEmitter implements Sandbox { - private watcherSubscription: Awaited>; + private watcherSubscription: Awaited>; private outputFilesExcludedFromWatch = ['.amplify']; private filesChangesTracker: FilesChangesTracker; @@ -79,7 +79,8 @@ export class FileWatchingSandbox extends EventEmitter implements Sandbox { private readonly ssmClient: SSMClient, private readonly functionsLogStreamer: LambdaFunctionLogStreamer, private readonly printer: Printer, - private readonly open = _open + private readonly open = _open, + private readonly subscribe = _subscribe ) { process.once('SIGINT', () => void this.stop()); process.once('SIGTERM', () => void this.stop()); @@ -197,7 +198,7 @@ export class FileWatchingSandbox extends EventEmitter implements Sandbox { }); if (watchForChanges) { - this.watcherSubscription = await subscribe( + this.watcherSubscription = await this.subscribe( watchDir, async (_, events) => { // Log and track file changes. From e39699185a5c3c6483ed11f04b9dbd21fb665e96 Mon Sep 17 00:00:00 2001 From: josefaidt Date: Tue, 17 Dec 2024 09:20:18 -0800 Subject: [PATCH 3/3] revise subscription mock --- packages/sandbox/src/file_watching_sandbox.test.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/sandbox/src/file_watching_sandbox.test.ts b/packages/sandbox/src/file_watching_sandbox.test.ts index a159bb8425..27ce143ab7 100644 --- a/packages/sandbox/src/file_watching_sandbox.test.ts +++ b/packages/sandbox/src/file_watching_sandbox.test.ts @@ -1,6 +1,6 @@ import { afterEach, beforeEach, describe, it, mock } from 'node:test'; import path from 'path'; -import watcher, { subscribe } from '@parcel/watcher'; +import watcher, { subscribe as _subscribe } from '@parcel/watcher'; import { CDK_DEFAULT_BOOTSTRAP_VERSION_PARAMETER_NAME, FileWatchingSandbox, @@ -40,7 +40,11 @@ import { // Watcher mocks const unsubscribeMockFn = mock.fn(); // eslint-disable-next-line @typescript-eslint/no-unused-vars -const subscribeMock = mock.fn(async (_dir, _effect, _options) => { +const subscribeMock = mock.fn< + ( + ...args: Parameters + ) => Promise<{ unsubscribe: typeof unsubscribeMockFn }> +>(async () => { return { unsubscribe: unsubscribeMockFn }; }); const packageManagerControllerFactory = new PackageManagerControllerFactory( @@ -1166,7 +1170,7 @@ const setupAndStartSandbox = async ( testData.functionsLogStreamer, printer as unknown as Printer, testData.open ?? _open, - testData.subscribe ?? subscribe + subscribeMock as never ); await sandboxInstance.start(sandboxOptions); @@ -1219,5 +1223,4 @@ type SandboxTestData = { ssmClient: SSMClient; functionsLogStreamer: LambdaFunctionLogStreamer; open?: typeof _open; - subscribe?: typeof subscribe; };