Skip to content

Commit

Permalink
fix(amplify-cli-core): use build script properly for overrides
Browse files Browse the repository at this point in the history
Updated the TypeScript compilation of overrides so that it doesn't require `node_modules/.bin/tsc`.
Instead, it simply relies on the `build` script to execute `tsc`.
This is more flexible and can support alternative setups w/ hoisting (e.g. via Yarn workspaces).

This is an override corollary fix to aws-amplify#11854, which is for custom resources.

This is an improvement over my previous PR in aws-amplify#13858 in that it works with any package manager
by ensuring the `--project` and `tsconfig.json` files are passed through to the `tsc` script.
The previous implementation didn't work with `npm` because it doesn't pass through additional
args like `yarn` does. The fix was easy: simply separate the build run with `--` so that the
remaining args are treated as positional for the `tsc` script.

I've confirmed the fix works with both `yarn` and `npm` 💪

aws-amplify#11889
  • Loading branch information
brianlenz committed Feb 1, 2025
1 parent 4d368b3 commit 1557a16
Showing 1 changed file with 2 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,8 @@ export const buildOverrideDir = async (cwd: string, destDirPath: string): Promis
const tsConfigSampleFilePath = path.join(__dirname, '..', '..', 'resources', 'overrides-resource', 'tsconfig.resource.json');
fs.writeFileSync(tsConfigDestFilePath, fs.readFileSync(tsConfigSampleFilePath));

// get locally installed tsc executable

const localTscExecutablePath = path.join(cwd, 'node_modules', '.bin', 'tsc');

if (!fs.existsSync(localTscExecutablePath)) {
throw new AmplifyError('MissingOverridesInstallationRequirementsError', {
message: 'TypeScript executable not found.',
resolution: 'Please add it as a dev-dependency in the package.json file for this resource.',
});
}
execa.sync(localTscExecutablePath, [`--project`, `${tsConfigDestFilePath}`], {
// ensure the --project and specific tsconfig.json file get passed through to tsc by using --
execa.sync(packageManager.executable, [`run`, `build`, '--', `--project`, `${tsConfigDestFilePath}`], {
cwd: tsConfigDir,
stdio: 'pipe',
encoding: 'utf-8',
Expand Down

0 comments on commit 1557a16

Please sign in to comment.