Skip to content

Commit

Permalink
fix(integ-runner): ENOENT no such file or directory 'recommended-fe…
Browse files Browse the repository at this point in the history
…ature-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*
  • Loading branch information
rix0rrr authored Jan 6, 2025
1 parent 8f97112 commit f809b94
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
3 changes: 2 additions & 1 deletion packages/@aws-cdk/integ-runner/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ test/test-archive-follow/data/linked

!**/*.snapshot/**/asset.*/*.js
!**/*.snapshot/**/asset.*/*.d.ts

!**/*.snapshot/**/asset.*/**

lib/recommended-feature-flags.json

8 changes: 5 additions & 3 deletions packages/@aws-cdk/integ-runner/lib/runner/runner-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { AVAILABILITY_ZONE_FALLBACK_CONTEXT_KEY, TARGET_PARTITIONS } from '@aws-
import * as fs from 'fs-extra';
import { IntegTestSuite, LegacyIntegTestSuite } from './integ-test-suite';
import { IntegTest } from './integration-tests';
import * as recommendedFlagsFile from '../recommended-feature-flags.json';
import { flatten } from '../utils';
import { AssemblyManifestReader, ManifestTrace } from './private/cloud-assembly';
import { DestructiveChange } from '../workers/common';
Expand Down Expand Up @@ -436,9 +437,10 @@ export const DEFAULT_SYNTH_OPTIONS = {
/**
* Return the currently recommended flags for `aws-cdk-lib`.
*
* These have been built into the CLI at build time.
* These have been built into the CLI at build time. If this ever gets changed
* back to a dynamic load, remember that this source file may be bundled into
* a JavaScript bundle, and `__dirname` might not point where you think it does.
*/
export function currentlyRecommendedAwsCdkLibFlags() {
const recommendedFlagsFile = path.join(__dirname, '..', 'recommended-feature-flags.json');
return JSON.parse(fs.readFileSync(recommendedFlagsFile, { encoding: 'utf-8' }));
return recommendedFlagsFile;
}

0 comments on commit f809b94

Please sign in to comment.