Skip to content

Commit

Permalink
update lock file reader factory
Browse files Browse the repository at this point in the history
  • Loading branch information
rtpascual committed Jan 8, 2025
1 parent 59bb35a commit f8c8243
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +49,11 @@ void describe('LockFileReaderFactory', () => {
});
}

void it('should throw an error for unsupported package managers', () => {
void it('defaults to npm lock file reader', () => {
process.env.npm_config_user_agent =
'unsupported/1.0.0 node/v15.0.0 darwin x64';
assert.throws(() => new LockFileReaderFactory().getLockFileReader(), {
message: 'Package Manager unsupported is not supported.',
});
});

void it('should throw an error for pnpm on Windows', () => {
process.env.npm_config_user_agent = 'pnpm/1.0.0 node/v15.0.0 darwin x64';
assert.throws(
() => new LockFileReaderFactory('win32').getLockFileReader(),
{
message: 'Amplify does not support PNPM on Windows.',
details:
'Details: https://github.com/aws-amplify/amplify-backend/blob/main/packages/create-amplify/README.md',
}
);
const lockFileReader = new LockFileReaderFactory().getLockFileReader();
assert.ok(lockFileReader instanceof NpmLockFileReader);
});
});
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { AmplifyUserError } from '../errors';
import { NpmLockFileReader } from './npm_lock_file_reader';
import { PnpmLockFileReader } from './pnpm_lock_file_reader';
import { YarnClassicLockFileReader } from './yarn_classic_lock_file_reader';
Expand All @@ -22,26 +21,14 @@ export class LockFileReaderFactory {
case 'npm':
return new NpmLockFileReader();
case 'pnpm':
if (this.platform === 'win32') {
const message = 'Amplify does not support PNPM on Windows.';
const details =
'Details: https://github.com/aws-amplify/amplify-backend/blob/main/packages/create-amplify/README.md';
throw new AmplifyUserError('UnsupportedPackageManagerError', {
message,
details,
resolution: 'Use a supported package manager for your OS',
});
}
return new PnpmLockFileReader();
case 'yarn-classic':
return new YarnClassicLockFileReader();
case 'yarn-modern':
return new YarnModernLockFileReader();
default:
throw new AmplifyUserError('UnsupportedPackageManagerError', {
message: `Package Manager ${packageManagerName} is not supported.`,
resolution: 'Use npm, yarn or pnpm.',
});
// defaults to npm lock file reader as it is the most used package manager by customers
return new NpmLockFileReader();
}
}

Expand Down

0 comments on commit f8c8243

Please sign in to comment.