Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(amplify-cli-core): use build script properly for overrides #14093

Merged
merged 4 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,8 @@ const buildResource = async (resource: ResourceMeta): Promise<void> => {
}
}

// get locally installed tsc executable

const localTscExecutablePath = path.join(targetDir, '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.',
});
}

try {
execa.sync(localTscExecutablePath, {
execa.sync(packageManager.runner, ['tsc'], {
cwd: targetDir,
stdio: 'pipe',
encoding: 'utf-8',
Expand Down
2 changes: 2 additions & 0 deletions packages/amplify-cli-core/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -1499,6 +1499,8 @@ export interface PackageManager {
// (undocumented)
readonly packageManager: PackageManagerType;
// (undocumented)
readonly runner: string;
// (undocumented)
version?: SemVer;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,7 @@ 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}`], {
execa.sync(packageManager.runner, ['tsc', '--project', tsConfigDestFilePath], {
cwd: tsConfigDir,
stdio: 'pipe',
encoding: 'utf-8',
Expand Down
6 changes: 6 additions & 0 deletions packages/amplify-cli-core/src/utils/packageManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface PackageManager {
readonly packageManager: PackageManagerType;
readonly lockFile: string;
readonly executable: string;
readonly runner: string;
readonly displayValue: string;
version?: SemVer;
getRunScriptArgs: (scriptName: string) => string[];
Expand All @@ -29,6 +30,7 @@ class NpmPackageManager implements PackageManager {
readonly packageManager = 'npm';
readonly displayValue = 'NPM';
readonly executable = 'npm';
readonly runner = 'npx';
readonly lockFile = 'package-lock.json';

getRunScriptArgs = (scriptName: string) => ['run-script', scriptName];
Expand All @@ -39,6 +41,7 @@ class YarnPackageManager implements PackageManager {
readonly packageManager: PackageManagerType = 'yarn';
readonly displayValue = 'Yarn';
readonly executable = 'yarn';
readonly runner = this.executable;
readonly lockFile = 'yarn.lock';
version?: SemVer;

Expand Down Expand Up @@ -66,6 +69,7 @@ class PnpmPackageManager implements PackageManager {
readonly packageManager: PackageManagerType = 'pnpm';
readonly displayValue = 'PNPM';
readonly executable = 'pnpm';
readonly runner = this.executable;
readonly lockFile = 'pnpm-lock.yaml';

getRunScriptArgs = (scriptName: string) => [scriptName];
Expand All @@ -77,11 +81,13 @@ class CustomPackageManager implements PackageManager {
readonly displayValue = 'Custom Build Command or Script Path';
lockFile;
executable;
runner;
version?: SemVer;

constructor() {
this.lockFile = '';
this.executable = '';
this.runner = '';
}
getRunScriptArgs = () => {
throw new AmplifyError('PackagingLambdaFunctionError', {
Expand Down
Loading