Skip to content

Commit b359bc6

Browse files
josefaidtsobolk
andauthored
import named export from parcel/watcher (#2341)
* import named export from parcel/watcher * try injecting subscribe * revise subscription mock * not needed --------- Co-authored-by: Kamil Sobol <[email protected]>
1 parent cbff026 commit b359bc6

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

.changeset/chilled-pants-kiss.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@aws-amplify/sandbox': patch
3+
---
4+
5+
move from importing the default export from the commonjs distribution of parcle/watcher to named export

packages/sandbox/src/file_watching_sandbox.test.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { afterEach, beforeEach, describe, it, mock } from 'node:test';
22
import path from 'path';
3-
import watcher from '@parcel/watcher';
3+
import watcher, { subscribe as _subscribe } from '@parcel/watcher';
44
import {
55
CDK_DEFAULT_BOOTSTRAP_VERSION_PARAMETER_NAME,
66
FileWatchingSandbox,
@@ -40,7 +40,11 @@ import { EOL } from 'os';
4040

4141
// Watcher mocks
4242
const unsubscribeMockFn = mock.fn();
43-
const subscribeMock = mock.method(watcher, 'subscribe', async () => {
43+
const subscribeMock = mock.fn<
44+
(
45+
...args: Parameters<typeof _subscribe>
46+
) => Promise<{ unsubscribe: typeof unsubscribeMockFn }>
47+
>(async () => {
4448
return { unsubscribe: unsubscribeMockFn };
4549
});
4650
const packageManagerControllerFactory = new PackageManagerControllerFactory(
@@ -148,7 +152,8 @@ void describe('Sandbox to check if region is bootstrapped', () => {
148152
ssmClientMock,
149153
functionsLogStreamerMock as unknown as LambdaFunctionLogStreamer,
150154
printer as unknown as Printer,
151-
openMock as never
155+
openMock as never,
156+
subscribeMock as never
152157
);
153158

154159
ssmClientSendMock.mock.resetCalls();
@@ -1172,7 +1177,8 @@ const setupAndStartSandbox = async (
11721177
testData.ssmClient,
11731178
testData.functionsLogStreamer,
11741179
printer as unknown as Printer,
1175-
testData.open ?? _open
1180+
testData.open ?? _open,
1181+
subscribeMock as never
11761182
);
11771183

11781184
await sandboxInstance.start(sandboxOptions);

packages/sandbox/src/file_watching_sandbox.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import debounce from 'debounce-promise';
2-
import parcelWatcher, { subscribe } from '@parcel/watcher';
2+
import { subscribe as _subscribe } from '@parcel/watcher';
33
import { AmplifySandboxExecutor } from './sandbox_executor.js';
44
import {
55
BackendIdSandboxResolver,
@@ -67,7 +67,7 @@ export const getBootstrapUrl = (region: string) =>
6767
* Runs a file watcher and deploys
6868
*/
6969
export class FileWatchingSandbox extends EventEmitter implements Sandbox {
70-
private watcherSubscription: Awaited<ReturnType<typeof subscribe>>;
70+
private watcherSubscription: Awaited<ReturnType<typeof _subscribe>>;
7171
private outputFilesExcludedFromWatch = ['.amplify'];
7272
private filesChangesTracker: FilesChangesTracker;
7373

@@ -80,7 +80,8 @@ export class FileWatchingSandbox extends EventEmitter implements Sandbox {
8080
private readonly ssmClient: SSMClient,
8181
private readonly functionsLogStreamer: LambdaFunctionLogStreamer,
8282
private readonly printer: Printer,
83-
private readonly open = _open
83+
private readonly open = _open,
84+
private readonly subscribe = _subscribe
8485
) {
8586
process.once('SIGINT', () => void this.stop());
8687
process.once('SIGTERM', () => void this.stop());
@@ -202,7 +203,7 @@ export class FileWatchingSandbox extends EventEmitter implements Sandbox {
202203
});
203204

204205
if (watchForChanges) {
205-
this.watcherSubscription = await parcelWatcher.subscribe(
206+
this.watcherSubscription = await this.subscribe(
206207
watchDir,
207208
async (_, events) => {
208209
// Log and track file changes.

0 commit comments

Comments
 (0)