Skip to content

Commit

Permalink
Make version parsing more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
connor-baer committed Jan 29, 2024
1 parent aa6f69e commit c6dc5bb
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 5 deletions.
33 changes: 33 additions & 0 deletions src/lib/options.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,39 @@ describe('options', () => {
'"eslint-plugin-playwright" is installed at version "^1.0.0". Foundry has only been tested with versions ">=0.17.0 <1.0.0". You may find that it works just fine, or you may not.',
);
});

it('should extract the version if a plugin is installed from a tarball URL', () => {
const packageJson = {
...basePackageJson,
license: 'MIT',
dependencies: {
'@sumup/eslint-plugin-circuit-ui':
'https://registry.npmjs.org/@sumup/eslint-plugin-circuit-ui/-/eslint-plugin-circuit-ui-1.0.0.tgz',
},
};

warnAboutUnsupportedPlugins(packageJson);

expect(logger.warn).toHaveBeenCalledOnce();
expect(logger.warn).toHaveBeenCalledWith(
'"@sumup/eslint-plugin-circuit-ui" is installed at version "1.0.0". Foundry has only been tested with versions ">=3.0.0 <5.0.0". You may find that it works just fine, or you may not.',
);
});

it('should log a warning if the installed plugin version cannot be verified', () => {
const packageJson = {
...basePackageJson,
license: 'MIT',
dependencies: { 'eslint-plugin-playwright': 'latest' },
};

warnAboutUnsupportedPlugins(packageJson);

expect(logger.warn).toHaveBeenCalledOnce();
expect(logger.warn).toHaveBeenCalledWith(
'Failed to verify whether "eslint-plugin-playwright" installed at version "latest" is supported. You may find that it works just fine, or you may not.',
);
});
});

describe('warnAboutMissingPlugins', () => {
Expand Down
27 changes: 22 additions & 5 deletions src/lib/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,18 +180,35 @@ export function detectFrameworks(packageJson: PackageJson): Framework[] {

export function warnAboutUnsupportedPlugins(packageJson: PackageJson): void {
PLUGINS.forEach(({ pluginPackage, supportedRange }) => {
const version = getDependencyVersion(packageJson, pluginPackage);
let version = getDependencyVersion(packageJson, pluginPackage);

if (!version) {
return;
}

const isSupported = intersects(version, supportedRange);

if (!isSupported) {
try {
// Extract the version from tarball URLs
if (version.startsWith('https://')) {
const matches = version.match(/(\d\.\d\.\d.*)\.tgz/);

if (matches) {
// eslint-disable-next-line prefer-destructuring
version = matches[1];
}
}

const isSupported = intersects(version, supportedRange);

if (!isSupported) {
logger.warn(
`"${pluginPackage}" is installed at version "${version}". Foundry has only been tested with versions "${supportedRange}". You may find that it works just fine, or you may not.`,
);
}
} catch (error) {
logger.warn(
`"${pluginPackage}" is installed at version "${version}". Foundry has only been tested with versions "${supportedRange}". You may find that it works just fine, or you may not.`,
`Failed to verify whether "${pluginPackage}" installed at version "${version}" is supported. You may find that it works just fine, or you may not.`,
);
logger.debug((error as Error).message);
}
});
}
Expand Down

0 comments on commit c6dc5bb

Please sign in to comment.