Skip to content

Commit 43f7161

Browse files
committed
fix: Pnpm and apt tests
1 parent abecef2 commit 43f7161

5 files changed

Lines changed: 54 additions & 33 deletions

File tree

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"devDependencies": {
5858
"@anthropic-ai/claude-agent-sdk": "^0.2.97",
5959
"@apidevtools/json-schema-ref-parser": "^11.7.2",
60-
"@codifycli/plugin-test": "1.1.0-beta6",
60+
"@codifycli/plugin-test": "1.1.0-beta7",
6161
"@fastify/merge-json-schemas": "^0.2.0",
6262
"@oclif/prettier-config": "^0.2.1",
6363
"@oclif/test": "^3",

src/resources/javascript/pnpm/pnpm-global-env-stateful-parameter.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,18 @@ export class PnpmGlobalEnvStatefulParameter extends StatefulParameter<PnpmConfig
1515
async refresh(): Promise<null | string> {
1616
const pty = getPty()
1717

18-
const { data: path } = await pty.spawnSafe('echo $PNPM_HOME/node')
19-
if (!path || !(await FileUtils.fileExists(path))) {
18+
const { data: nodejsDir } = await pty.spawnSafe('echo $PNPM_HOME/bin', { interactive: true })
19+
if (!nodejsDir?.trim() || !(await FileUtils.dirExists(nodejsDir.trim()))) {
2020
return null;
2121
}
2222

23-
const { data: version } = await pty.spawn(`${path} -v`)
24-
return version.trim().slice(1);
23+
const nodeBin = `${nodejsDir.trim()}/node`
24+
if (!(await FileUtils.fileExists(nodeBin))) {
25+
return null;
26+
}
27+
28+
const { data: version } = await pty.spawn(`${nodeBin} -v`)
29+
return version.trim().replace(/^v/, '');
2530
}
2631

2732
async add(valueToAdd: string): Promise<void> {
@@ -31,12 +36,12 @@ export class PnpmGlobalEnvStatefulParameter extends StatefulParameter<PnpmConfig
3136

3237
async modify(newValue: string): Promise<void> {
3338
const $ = getPty();
34-
await $.spawn(`pnpm runtime set node -g ${newValue}`, { interactive: true })
39+
await $.spawn(`pnpm runtime set node -g ${newValue}`, { interactive: true })
3540
}
3641

3742
async remove(): Promise<void> {
3843
const $ = getPty();
39-
const { data: path } = await $.spawn('echo $PNPM_HOME/nodejs', { interactive: true })
40-
await fs.rm(path!, { recursive: true, force: true });
44+
const { data: nodejsDir } = await $.spawn('echo $PNPM_HOME/nodejs', { interactive: true })
45+
await fs.rm(nodejsDir.trim(), { recursive: true, force: true });
4146
}
4247
}

src/resources/javascript/pnpm/pnpm.ts

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,26 +73,40 @@ export class Pnpm extends Resource<PnpmConfig> {
7373
: path.join(os.homedir(), '.local', 'share', 'pnpm');
7474

7575
const { data: pnpmLocation } = await $.spawn('which pnpm', { interactive: true });
76-
if (pnpmLocation.trim().toLowerCase() !== path.join(expectedPnpmHome, 'pnpm').trim().toLowerCase()) {
77-
throw new Error('pnpm was installed outside of Codify. Please uninstall manually and re-run Codify');
78-
}
76+
const actual = pnpmLocation.trim().toLowerCase();
7977

80-
const { data: pnpmHome } = await $.spawnSafe('echo $PNPM_HOME', { interactive: true });
81-
if (!pnpmHome) {
82-
throw new Error('$PNPM_HOME variable is not set. Unable to determine how to uninstall pnpm. Please uninstall manually and re-run Codify.')
83-
}
78+
const expectedPnpmBin = path.join(expectedPnpmHome, 'bin', 'pnpm').toLowerCase();
79+
const expectedPnpmBinFallback = path.join(expectedPnpmHome, 'pnpm').toLowerCase();
80+
const isInstalledByScript = actual === expectedPnpmBin || actual === expectedPnpmBinFallback;
81+
const isInstalledByNpm = actual.includes('node_modules/.bin/pnpm') || actual.includes('node_modules/pnpm');
82+
const isInstalledByHomebrew = actual.includes('/homebrew/') || actual.includes('/linuxbrew/') || actual.includes('/opt/homebrew/');
8483

85-
await fs.rm(pnpmHome, { recursive: true, force: true });
86-
console.log('Successfully uninstalled pnpm');
84+
if (isInstalledByScript) {
85+
const { data: pnpmHome } = await $.spawnSafe('echo $PNPM_HOME', { interactive: true });
86+
await fs.rm(pnpmHome?.trim() || expectedPnpmHome, { recursive: true, force: true });
8787

88-
const shellRc = Utils.getPrimaryShellRc();
89-
await FileUtils.removeLineFromStartupFile('# pnpm')
90-
await FileUtils.removeLineFromStartupFile(`export PNPM_HOME="${expectedPnpmHome}"`)
91-
await FileUtils.removeFromFile(shellRc,
88+
const shellRc = Utils.getPrimaryShellRc();
89+
await FileUtils.removeLineFromStartupFile('# pnpm')
90+
await FileUtils.removeLineFromStartupFile(`export PNPM_HOME="${expectedPnpmHome}"`)
91+
await FileUtils.removeFromFile(shellRc,
92+
`case ":$PATH:" in
93+
*":$PNPM_HOME/bin:"*) ;;
94+
*) export PATH="$PNPM_HOME/bin:$PATH" ;;
95+
esac`)
96+
await FileUtils.removeFromFile(shellRc,
9297
`case ":$PATH:" in
9398
*":$PNPM_HOME:"*) ;;
9499
*) export PATH="$PNPM_HOME:$PATH" ;;
95100
esac`)
96-
await FileUtils.removeLineFromStartupFile('# pnpm end')
101+
await FileUtils.removeLineFromStartupFile('# pnpm end')
102+
} else if (isInstalledByNpm) {
103+
await $.spawn('npm uninstall -g pnpm', { interactive: true });
104+
} else if (isInstalledByHomebrew) {
105+
await Utils.uninstallViaPkgMgr('pnpm');
106+
} else {
107+
throw new Error(`pnpm is installed at an unrecognized location: ${actual}. Please uninstall manually and re-run Codify`);
108+
}
109+
110+
console.log('Successfully uninstalled pnpm');
97111
}
98112
}

test/apt/apt.test.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,22 @@ describe('Apt resource integration tests', { skip: !Utils.isLinux() }, () => {
5050
});
5151

5252
it('Can install packages with specific versions', { timeout: 300000 }, async () => {
53-
// Get available version of a package
54-
const { data: availableVersions } = await testSpawn('apt-cache madison curl | head -1 | awk \'{print $3}\'');
53+
// Use the currently installed version (or latest available if not installed) to test version-pinned syntax
54+
const { data: installedVer } = await testSpawn('dpkg-query -W -f=\'${Version}\' curl 2>/dev/null || true');
55+
const { data: availableVer } = await testSpawn('apt-cache madison curl | head -1 | awk \'{print $3}\'');
56+
const pinnedVersion = installedVer.trim() || availableVer.trim();
5557

5658
await PluginTester.fullTest(pluginPath, [{
5759
type: 'apt',
5860
install: [
59-
`curl=${availableVersions}`
61+
`curl=${pinnedVersion}`
6062
]
6163
}], {
6264
skipUninstall: true,
6365
validateApply: async () => {
6466
expect(await testSpawn('which curl')).toMatchObject({ status: SpawnStatus.SUCCESS });
65-
const { data: installedVersion } = await testSpawn('dpkg-query -W -f=\'${Version}\' curl');
66-
expect(installedVersion).toBe(availableVersions);
67+
const { data: actualVersion } = await testSpawn('dpkg-query -W -f=\'${Version}\' curl');
68+
expect(actualVersion).toBe(pinnedVersion);
6769
},
6870
});
6971
});

0 commit comments

Comments
 (0)