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

Adds extensionless url support #5931

Merged
merged 3 commits into from
Nov 3, 2023
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
24 changes: 24 additions & 0 deletions .yarn/versions/70b508e3.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
releases:
"@yarnpkg/cli": patch
"@yarnpkg/plugin-http": patch
Comment on lines +2 to +3
Copy link
Member

@merceyz merceyz Nov 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"@yarnpkg/cli": patch
"@yarnpkg/plugin-http": patch
"@yarnpkg/cli": minor
"@yarnpkg/plugin-http": minor

This is a new feature, no?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a reasonable case that it's a compatibility bugfix. It could be seen as a feature as well, but I don't think it's matches the typical threshold for what's worth waiting for a minor release vs a patch one.

Copy link
Member

@merceyz merceyz Nov 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

waiting for a minor release

Don't wait, we should make releases whenever we feel like it.


declined:
- "@yarnpkg/plugin-compat"
- "@yarnpkg/plugin-constraints"
- "@yarnpkg/plugin-dlx"
- "@yarnpkg/plugin-essentials"
- "@yarnpkg/plugin-init"
- "@yarnpkg/plugin-interactive-tools"
- "@yarnpkg/plugin-nm"
- "@yarnpkg/plugin-npm-cli"
- "@yarnpkg/plugin-pack"
- "@yarnpkg/plugin-patch"
- "@yarnpkg/plugin-pnp"
- "@yarnpkg/plugin-pnpm"
- "@yarnpkg/plugin-stage"
- "@yarnpkg/plugin-typescript"
- "@yarnpkg/plugin-version"
- "@yarnpkg/plugin-workspace-tools"
- "@yarnpkg/builder"
- "@yarnpkg/core"
- "@yarnpkg/doctor"
10 changes: 2 additions & 8 deletions packages/plugin-http/sources/TarballHttpFetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,11 @@ import {Fetcher, FetchOptions, MinimalFetchOptions} from '@yarnpkg/core';
import {Locator} from '@yarnpkg/core';
import {httpUtils, structUtils, tgzUtils} from '@yarnpkg/core';

import {TARBALL_REGEXP, PROTOCOL_REGEXP} from './constants';
import * as urlUtils from './urlUtils';

export class TarballHttpFetcher implements Fetcher {
supports(locator: Locator, opts: MinimalFetchOptions) {
if (!TARBALL_REGEXP.test(locator.reference))
return false;

if (PROTOCOL_REGEXP.test(locator.reference))
return true;

return false;
return urlUtils.isTgzUrl(locator.reference);
}

getLocalPath(locator: Locator, opts: FetchOptions) {
Expand Down
18 changes: 3 additions & 15 deletions packages/plugin-http/sources/TarballHttpResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,15 @@ import {Descriptor, Locator, Manifest} from '@yarnpkg
import {LinkType} from '@yarnpkg/core';
import {miscUtils, structUtils} from '@yarnpkg/core';

import {PROTOCOL_REGEXP, TARBALL_REGEXP} from './constants';
import * as urlUtils from './urlUtils';

export class TarballHttpResolver implements Resolver {
supportsDescriptor(descriptor: Descriptor, opts: MinimalResolveOptions) {
if (!TARBALL_REGEXP.test(descriptor.range))
return false;

if (PROTOCOL_REGEXP.test(descriptor.range))
return true;

return false;
return urlUtils.isTgzUrl(descriptor.range);
}

supportsLocator(locator: Locator, opts: MinimalResolveOptions) {
if (!TARBALL_REGEXP.test(locator.reference))
return false;

if (PROTOCOL_REGEXP.test(locator.reference))
return true;

return false;
return urlUtils.isTgzUrl(locator.reference);
}

shouldPersistResolution(locator: Locator, opts: MinimalResolveOptions) {
Expand Down
3 changes: 0 additions & 3 deletions packages/plugin-http/sources/constants.ts

This file was deleted.

16 changes: 16 additions & 0 deletions packages/plugin-http/sources/urlUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export function isTgzUrl(url: string) {
let parsed: URL;
try {
parsed = new URL(url);
} catch {
return false;
}

if (parsed.protocol !== `http:` && parsed.protocol !== `https:`)
return false;

if (!parsed.pathname.match(/(\.tar\.gz|\.tgz|\/[^.]+)$/))
return false;

return true;
}
17 changes: 17 additions & 0 deletions packages/plugin-http/tests/urlUtils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import * as urlUtils from '../sources/urlUtils';

const EXPECTATIONS: Array<[string, boolean]> = [
[`https://example.org/package.tar.gz`, true],
[`https://example.org/package.tgz`, true],
[`https://example.org/package`, true],
[`https://example.org/package.git`, false],
[`https://example.org/package.tgz.git`, false],
[`ftp://example.org/package.tgz`, false],
[`1.2.3`, false],
];

for (const [url, expected] of EXPECTATIONS) {
test(`isTgzUrl(${JSON.stringify(url)}) === ${JSON.stringify(expected)}`, () => {
expect(urlUtils.isTgzUrl(url)).toEqual(expected);
});
}