Skip to content

Commit f809b94

Browse files
authoredJan 6, 2025
fix(integ-runner): ENOENT no such file or directory 'recommended-feature-flags.json' (#32750)
In the `integ-runner`, we used to load the recommended feature flags file for `aws-cdk-lib` using a run-time `readFile` based on a `__dirname`. However, the source files are bundled which makes `__dirname` point to the wrong directory. Instead, load the JSON file directly using a JavaScript `import`, so that the bundler will bundle the JSON file into the source code directly, and we can't fail to load it. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 8f97112 commit f809b94

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed
 

‎packages/@aws-cdk/integ-runner/.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ test/test-archive-follow/data/linked
3232

3333
!**/*.snapshot/**/asset.*/*.js
3434
!**/*.snapshot/**/asset.*/*.d.ts
35-
3635
!**/*.snapshot/**/asset.*/**
3736

37+
lib/recommended-feature-flags.json
38+

‎packages/@aws-cdk/integ-runner/lib/runner/runner-base.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { AVAILABILITY_ZONE_FALLBACK_CONTEXT_KEY, TARGET_PARTITIONS } from '@aws-
66
import * as fs from 'fs-extra';
77
import { IntegTestSuite, LegacyIntegTestSuite } from './integ-test-suite';
88
import { IntegTest } from './integration-tests';
9+
import * as recommendedFlagsFile from '../recommended-feature-flags.json';
910
import { flatten } from '../utils';
1011
import { AssemblyManifestReader, ManifestTrace } from './private/cloud-assembly';
1112
import { DestructiveChange } from '../workers/common';
@@ -436,9 +437,10 @@ export const DEFAULT_SYNTH_OPTIONS = {
436437
/**
437438
* Return the currently recommended flags for `aws-cdk-lib`.
438439
*
439-
* These have been built into the CLI at build time.
440+
* These have been built into the CLI at build time. If this ever gets changed
441+
* back to a dynamic load, remember that this source file may be bundled into
442+
* a JavaScript bundle, and `__dirname` might not point where you think it does.
440443
*/
441444
export function currentlyRecommendedAwsCdkLibFlags() {
442-
const recommendedFlagsFile = path.join(__dirname, '..', 'recommended-feature-flags.json');
443-
return JSON.parse(fs.readFileSync(recommendedFlagsFile, { encoding: 'utf-8' }));
445+
return recommendedFlagsFile;
444446
}

0 commit comments

Comments
 (0)