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.test.ts b/packages/sandbox/src/file_watching_sandbox.test.ts index 68e410a56f..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 from '@parcel/watcher'; +import watcher, { subscribe as _subscribe } from '@parcel/watcher'; import { CDK_DEFAULT_BOOTSTRAP_VERSION_PARAMETER_NAME, FileWatchingSandbox, @@ -39,7 +39,12 @@ 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< + ( + ...args: Parameters + ) => Promise<{ unsubscribe: typeof unsubscribeMockFn }> +>(async () => { return { unsubscribe: unsubscribeMockFn }; }); const packageManagerControllerFactory = new PackageManagerControllerFactory( @@ -147,7 +152,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 +1169,8 @@ const setupAndStartSandbox = async ( testData.ssmClient, testData.functionsLogStreamer, printer as unknown as Printer, - testData.open ?? _open + testData.open ?? _open, + subscribeMock as never ); await sandboxInstance.start(sandboxOptions); diff --git a/packages/sandbox/src/file_watching_sandbox.ts b/packages/sandbox/src/file_watching_sandbox.ts index aa1bb1c6a1..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 parcelWatcher, { 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 parcelWatcher.subscribe( + this.watcherSubscription = await this.subscribe( watchDir, async (_, events) => { // Log and track file changes.