Skip to content

Commit 73e5ad4

Browse files
authored
fix(toolkit-lib): remove deprecated outdir option from watch (#313)
The watch functionality has been updated to: 1. Remove the deprecated outdir parameter from WatchOptions 2. Use assembly.directory instead of the hardcoded 'cdk.out' default 3. Only exclude the outdir from watching if it's under the root directory 4. Update tests to reflect these changes BREAKING CHANGE: The `outdir` option in `WatchOptions` was deprecated and has been removed. Instead, the code now determines the assembly directory directly. To explicitly restore the previous behavior, you add the value to `WatchOptions.exclude`. --- By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license
1 parent 1fc05e5 commit 73e5ad4

File tree

3 files changed

+36
-13
lines changed

3 files changed

+36
-13
lines changed

packages/@aws-cdk/toolkit-lib/lib/actions/watch/index.ts

-9
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,4 @@ export interface WatchOptions extends BaseDeployOptions {
2121
* @default process.cwd()
2222
*/
2323
readonly watchDir?: string;
24-
25-
/**
26-
* The output directory to write CloudFormation template to
27-
*
28-
* @deprecated this should be grabbed from the cloud assembly itself
29-
*
30-
* @default 'cdk.out'
31-
*/
32-
readonly outdir?: string;
3324
}

packages/@aws-cdk/toolkit-lib/lib/toolkit/toolkit.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -760,11 +760,19 @@ export class Toolkit extends CloudAssemblySourceBuilder {
760760
// 2. Any file whose name starts with a dot.
761761
// 3. Any directory's content whose name starts with a dot.
762762
// 4. Any node_modules and its content (even if it's not a JS/TS project, you might be using a local aws-cli package)
763-
const outdir = options.outdir ?? 'cdk.out';
763+
const outdir = assembly.directory;
764764
const watchExcludes = patternsArrayForWatch(options.exclude, {
765765
rootDir,
766766
returnRootDirIfEmpty: false,
767-
}).concat(`${outdir}/**`, '**/.*', '**/.*/**', '**/node_modules/**');
767+
});
768+
769+
// only exclude the outdir if it is under the rootDir
770+
const relativeOutDir = path.relative(rootDir, outdir);
771+
if (Boolean(relativeOutDir && !relativeOutDir.startsWith('..' + path.sep) && !path.isAbsolute(relativeOutDir))) {
772+
watchExcludes.push(`${relativeOutDir}/**`);
773+
}
774+
775+
watchExcludes.push('**/.*', '**/.*/**', '**/node_modules/**');
768776

769777
// Print some debug information on computed settings
770778
await ioHelper.notify(IO.CDK_TOOLKIT_I5310.msg([

packages/@aws-cdk/toolkit-lib/test/actions/watch.test.ts

+26-2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ jest.mock('chokidar', () => ({
3939
watch: mockChokidarWatch,
4040
}));
4141

42+
import * as path from 'node:path';
4243
import { HotswapMode } from '../../lib';
4344
import { Toolkit } from '../../lib/toolkit';
4445
import { builderFixture, TestIoHost } from '../_helpers';
@@ -80,7 +81,7 @@ describe('watch', () => {
8081
}));
8182
});
8283

83-
test('ignores output dir, dot files, dot directories, node_modules by default', async () => {
84+
test('dot files, dot directories, node_modules by default', async () => {
8485
// WHEN
8586
const cx = await builderFixture(toolkit, 'stack-with-role');
8687
ioHost.level = 'debug';
@@ -92,7 +93,30 @@ describe('watch', () => {
9293
expect(ioHost.notifySpy).toHaveBeenCalledWith(expect.objectContaining({
9394
action: 'watch',
9495
level: 'debug',
95-
message: expect.stringContaining('\'exclude\' patterns for \'watch\': ["cdk.out/**","**/.*","**/.*/**","**/node_modules/**"]'),
96+
code: 'CDK_TOOLKIT_I5310',
97+
message: expect.stringContaining('\'exclude\' patterns for \'watch\': ["**/.*","**/.*/**","**/node_modules/**"]'),
98+
}));
99+
});
100+
101+
test('ignores outdir when under the watch dir', async () => {
102+
// WHEN
103+
const cx = await builderFixture(toolkit, 'stack-with-role');
104+
const assembly = await toolkit.synth(cx);
105+
const outdir = (await assembly.produce()).directory;
106+
const watchDir = path.normalize(outdir + path.sep + '..');
107+
108+
ioHost.level = 'debug';
109+
await toolkit.watch(assembly, {
110+
watchDir,
111+
exclude: [],
112+
});
113+
114+
// THEN
115+
expect(ioHost.notifySpy).toHaveBeenCalledWith(expect.objectContaining({
116+
action: 'watch',
117+
level: 'debug',
118+
code: 'CDK_TOOLKIT_I5310',
119+
message: expect.stringContaining(`'exclude' patterns for 'watch': ["${path.basename(outdir)}/**","**/.*","**/.*/**","**/node_modules/**"]`),
96120
}));
97121
});
98122

0 commit comments

Comments
 (0)