Skip to content

Commit a01f6b9

Browse files
0618edwardfoyle
andauthored
fix(package-manager): pnpm tsc not found (#1016)
* fix(package-manager): pnpm and e2e test * update changeset * fix e2e test to detect binary * use beta version * delete .bin folder * fix yarn test * remove yarn modern redundant packages * remove yarn more redundant packages * fix unit tests * try fixing npx which amplify * remove npx which amplify * Update packages/integration-tests/src/package_manager_sanity_checks.test.ts Co-authored-by: Edward Foyle <[email protected]> * treat yarn amplify@beta * Revert "treat yarn amplify@beta" This reverts commit 52dc1f7. * treat yarn amplify@beta again * fix yarn modern * fix yarn modern unit test * fix lint error * fix unit test * change after test install * remove corepack install * fix yarn modern unit test * fix yarn classic global create-amplify * change comments * use npm run install --------- Co-authored-by: Edward Foyle <[email protected]>
1 parent 85e953f commit a01f6b9

11 files changed

+49
-56
lines changed

.changeset/brave-pets-clean.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@aws-amplify/cli-core': patch
3+
---
4+
5+
fix pnpm Command "tsc" not found

.eslint_dictionary.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"codegen",
2121
"cognito",
2222
"commonjs",
23+
"corepack",
2324
"ctor",
2425
"darwin",
2526
"datastore",

package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/cli-core/src/package-manager-controller/package_manager_controller_base.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ Get started by running \`${this.binaryRunner} amplify sandbox\`.`;
112112
targetDir,
113113
this.binaryRunner,
114114
tscArgs,
115-
this.execa
115+
this.execa,
116+
{ preferLocal: true, localDir: targetDir }
116117
);
117118
}
118119

packages/cli-core/src/package-manager-controller/yarn_classic_package_manager_controller.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ void describe('YarnClassicPackageManagerController', () => {
138138
existsSyncMock
139139
);
140140
await yarnClassicPackageManagerController.initializeTsConfig('./amplify');
141-
assert.equal(executeWithDebugLoggerMock.mock.callCount(), 2);
141+
assert.equal(executeWithDebugLoggerMock.mock.callCount(), 1);
142142
});
143143
});
144144
});

packages/cli-core/src/package-manager-controller/yarn_classic_package_manager_controller.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,4 @@ export class YarnClassicPackageManagerController extends PackageManagerControlle
3333
existsSync
3434
);
3535
}
36-
37-
initializeTsConfig = async (targetDir: string) => {
38-
await this.addTypescript(targetDir);
39-
await super.initializeTsConfig(targetDir);
40-
};
41-
42-
/**
43-
* addTypescript - initializes a tsconfig.json file in the project root
44-
*/
45-
private addTypescript = async (targetDir: string) => {
46-
await this.executeWithDebugLogger(
47-
targetDir,
48-
'yarn',
49-
['add', 'typescript@^5'],
50-
this.execa
51-
);
52-
};
5336
}

packages/cli-core/src/package-manager-controller/yarn_modern_package_manager_controller.test.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,27 +40,15 @@ void describe('YarnModernPackageManagerController', () => {
4040
['testPackage1', 'testPackage2'],
4141
'dev'
4242
);
43-
assert.equal(executeWithDebugLoggerMock.mock.callCount(), 2);
44-
assert.deepEqual(executeWithDebugLoggerMock.mock.calls[0].arguments, [
45-
'/testProjectRoot',
46-
'yarn',
47-
['add', '-D', 'tsx', 'esbuild'],
48-
execaMock,
49-
]);
43+
assert.equal(executeWithDebugLoggerMock.mock.callCount(), 1);
5044
});
5145

5246
void it('runs yarn add with the correct arguments for prod dependencies', async () => {
5347
await yarnModernPackageManagerController.installDependencies(
5448
['testPackage1', 'testPackage2'],
5549
'prod'
5650
);
57-
assert.equal(executeWithDebugLoggerMock.mock.callCount(), 2);
58-
assert.deepEqual(executeWithDebugLoggerMock.mock.calls[0].arguments, [
59-
'/testProjectRoot',
60-
'yarn',
61-
['add', '-D', 'tsx', 'esbuild'],
62-
execaMock,
63-
]);
51+
assert.equal(executeWithDebugLoggerMock.mock.callCount(), 1);
6452
});
6553
});
6654

packages/cli-core/src/package-manager-controller/yarn_modern_package_manager_controller.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,6 @@ export class YarnModernPackageManagerController extends PackageManagerController
3636
);
3737
}
3838

39-
installDependencies: (
40-
packageNames: string[],
41-
type: 'dev' | 'prod'
42-
) => Promise<void> = async (packageNames, type) => {
43-
await this.addDependencies(this.cwd);
44-
await super.installDependencies(packageNames, type);
45-
};
46-
4739
initializeTsConfig = async (targetDir: string) => {
4840
await this.addLockFile(targetDir);
4941
await this.addTypescript(targetDir);
@@ -79,13 +71,4 @@ export class YarnModernPackageManagerController extends PackageManagerController
7971
this.execa
8072
);
8173
};
82-
83-
private addDependencies = async (targetDir: string) => {
84-
await this.executeWithDebugLogger(
85-
targetDir,
86-
'yarn',
87-
['add', '-D', 'tsx', 'esbuild'],
88-
this.execa
89-
);
90-
};
9174
}

packages/create-amplify/src/amplify_project_creator.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ export class AmplifyProjectCreator {
2222
'aws-cdk-lib@^2',
2323
'constructs@^10.0.0',
2424
'typescript@^5.0.0',
25+
'tsx',
26+
'esbuild',
2527
];
2628

2729
private readonly defaultProdPackages = ['aws-amplify'];

packages/integration-tests/src/package_manager_sanity_checks.test.ts

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { execa } from 'execa';
1+
import { execa, execaCommand } from 'execa';
22
import * as fsp from 'fs/promises';
33
import * as path from 'path';
44
import * as os from 'os';
@@ -34,10 +34,22 @@ void describe('getting started happy path', async () => {
3434
// start a local npm proxy and publish the current codebase to the proxy
3535
await execa('npm', ['run', 'clean:npm-proxy'], { stdio: 'inherit' });
3636
await execa('npm', ['run', 'vend'], { stdio: 'inherit' });
37+
/**
38+
* delete .bin folder in the repo because
39+
* 1) e2e tests should not depend on them
40+
* 2) execa would have package managers to use them if it can not find the binary in the test project
41+
*/
42+
await execaCommand(`rm -rf ${process.cwd()}/node_modules/.bin`);
3743
});
3844

3945
after(async () => {
46+
// TODO: remove the condition once GA https://github.com/aws-amplify/amplify-backend/issues/1013
47+
// create-amplify has been installed globally, we need to remove it before running `setup:local`
48+
if (packageManager === 'yarn-classic') {
49+
await execa('yarn', ['global', 'remove', 'create-amplify']);
50+
}
4051
// stop the npm proxy
52+
await execa('npm', ['install'], { stdio: 'inherit' }); // add tsx back since we removed all the binaries
4153
await execa('npm', ['run', 'stop:npm-proxy'], { stdio: 'inherit' });
4254
});
4355

@@ -67,11 +79,22 @@ void describe('getting started happy path', async () => {
6779
});
6880

6981
void it('creates new project and deploy them without an error', async () => {
70-
await runPackageManager(
71-
packageManager,
72-
['create', 'amplify', '--yes'],
73-
tempDir
74-
).run();
82+
// TODO: remove the condition once GA https://github.com/aws-amplify/amplify-backend/issues/1013
83+
if (packageManager === 'yarn-classic') {
84+
await execa('yarn', ['global', 'add', 'create-amplify@beta']);
85+
process.env.npm_config_user_agent = 'yarn/1.22.21';
86+
await runPackageManager(
87+
packageManager,
88+
['create', 'amplify', '--yes'],
89+
tempDir
90+
).run();
91+
} else {
92+
await runPackageManager(
93+
packageManager,
94+
['create', 'amplify@beta', '--yes'], // TODO: remove "@beta" once GA https://github.com/aws-amplify/amplify-backend/issues/1013
95+
tempDir
96+
).run();
97+
}
7598

7699
const pathPrefix = path.join(tempDir, 'amplify');
77100

0 commit comments

Comments
 (0)