A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/yarnpkg/berry/commit/09ce636cef8bd6b3aa0a949ce219435f1047838b below:

Adds support for the `jsr:` protocol (#6752) · yarnpkg/berry@09ce636 · GitHub

File tree Expand file treeCollapse file tree 14 files changed

+359

-3

lines changed

Filter options

Expand file treeCollapse file tree 14 files changed

+359

-3

lines changed Original file line number Diff line number Diff line change

@@ -0,0 +1,35 @@

1 +

releases:

2 +

"@yarnpkg/cli": minor

3 +

"@yarnpkg/core": minor

4 +

"@yarnpkg/plugin-jsr": minor

5 +

"@yarnpkg/plugin-npm": minor

6 + 7 +

declined:

8 +

- "@yarnpkg/plugin-compat"

9 +

- "@yarnpkg/plugin-constraints"

10 +

- "@yarnpkg/plugin-dlx"

11 +

- "@yarnpkg/plugin-essentials"

12 +

- "@yarnpkg/plugin-exec"

13 +

- "@yarnpkg/plugin-file"

14 +

- "@yarnpkg/plugin-git"

15 +

- "@yarnpkg/plugin-github"

16 +

- "@yarnpkg/plugin-http"

17 +

- "@yarnpkg/plugin-init"

18 +

- "@yarnpkg/plugin-interactive-tools"

19 +

- "@yarnpkg/plugin-link"

20 +

- "@yarnpkg/plugin-nm"

21 +

- "@yarnpkg/plugin-npm-cli"

22 +

- "@yarnpkg/plugin-pack"

23 +

- "@yarnpkg/plugin-patch"

24 +

- "@yarnpkg/plugin-pnp"

25 +

- "@yarnpkg/plugin-pnpm"

26 +

- "@yarnpkg/plugin-stage"

27 +

- "@yarnpkg/plugin-typescript"

28 +

- "@yarnpkg/plugin-version"

29 +

- "@yarnpkg/plugin-workspace-tools"

30 +

- "@yarnpkg/builder"

31 +

- "@yarnpkg/doctor"

32 +

- "@yarnpkg/extensions"

33 +

- "@yarnpkg/nm"

34 +

- "@yarnpkg/pnpify"

35 +

- "@yarnpkg/sdks"

Original file line number Diff line number Diff line change

@@ -423,6 +423,16 @@ export const startPackageServer = ({type}: {type: keyof typeof packageServerUrls

423 423

const {scope, localName, version} = parsedRequest;

424 424

const name = scope ? `${scope}/${localName}` : localName;

425 425 426 +

if (parsedRequest.registry === `jsr` && scope !== `jsr`) {

427 +

processError(response, 404, `Package not found: ${name}`);

428 +

return;

429 +

}

430 + 431 +

if (parsedRequest.registry !== `jsr` && scope === `jsr`) {

432 +

processError(response, 404, `Package not found: ${name}`);

433 +

return;

434 +

}

435 + 426 436

const packageEntry = await getPackageEntry(name);

427 437

if (!packageEntry) {

428 438

processError(response, 404, `Package not found: ${name}`);

Original file line number Diff line number Diff line change

@@ -0,0 +1,7 @@

1 +

module.exports = require(`./package.json`);

2 + 3 +

for (const key of [`dependencies`, `devDependencies`, `peerDependencies`]) {

4 +

for (const dep of Object.keys(module.exports[key] || {})) {

5 +

module.exports[key][dep] = require(dep);

6 +

}

7 +

}

Original file line number Diff line number Diff line change

@@ -0,0 +1,4 @@

1 +

{

2 +

"name": "@jsr/no-deps-jsr",

3 +

"version": "1.0.0"

4 +

}

Original file line number Diff line number Diff line change

@@ -0,0 +1,93 @@

1 +

import {ppath, xfs} from '@yarnpkg/fslib';

2 +

import {fs as fsUtils} from 'pkg-tests-core';

3 +

import {tests} from 'pkg-tests-core';

4 + 5 +

describe(`Protocols`, () => {

6 +

describe(`jsr:`, () => {

7 +

test(

8 +

`it should allow installing a package from a jsr registry`,

9 +

makeTemporaryEnv(

10 +

{

11 +

dependencies: {[`no-deps-jsr`]: `jsr:1.0.0`},

12 +

},

13 +

async ({path, run, source}) => {

14 +

await xfs.writeFilePromise(ppath.join(path, `.yarnrc.yml`), JSON.stringify({

15 +

[`npmScopes`]: {

16 +

[`jsr`]: {

17 +

[`npmRegistryServer`]: `${await tests.startPackageServer()}/registry/jsr`,

18 +

},

19 +

},

20 +

}));

21 + 22 +

await run(`install`);

23 + 24 +

await expect(source(`require('no-deps-jsr')`)).resolves.toMatchObject({

25 +

// The package name is prefixed with @jsr/ because that's what the registry returns

26 +

name: `@jsr/no-deps-jsr`,

27 +

version: `1.0.0`,

28 +

});

29 +

},

30 +

),

31 +

);

32 + 33 +

test(

34 +

`it should allow renaming packages`,

35 +

makeTemporaryEnv(

36 +

{

37 +

dependencies: {[`foo`]: `jsr:no-deps-jsr@1.0.0`},

38 +

},

39 +

async ({path, run, source}) => {

40 +

await xfs.writeFilePromise(ppath.join(path, `.yarnrc.yml`), JSON.stringify({

41 +

[`npmScopes`]: {

42 +

[`jsr`]: {

43 +

[`npmRegistryServer`]: `${await tests.startPackageServer()}/registry/jsr`,

44 +

},

45 +

},

46 +

}));

47 + 48 +

await run(`install`);

49 + 50 +

await expect(source(`require('foo')`)).resolves.toMatchObject({

51 +

name: `@jsr/no-deps-jsr`,

52 +

version: `1.0.0`,

53 +

});

54 +

},

55 +

),

56 +

);

57 + 58 +

test(

59 +

`it should replace the jsr registry with a npm registry during packing`,

60 +

makeTemporaryEnv(

61 +

{

62 +

dependencies: {[`no-deps-jsr`]: `jsr:1.0.0`},

63 +

},

64 +

async ({path, run, source}) => {

65 +

await xfs.writeFilePromise(ppath.join(path, `.yarnrc.yml`), JSON.stringify({

66 +

[`npmScopes`]: {

67 +

[`jsr`]: {

68 +

[`npmRegistryServer`]: `${await tests.startPackageServer()}/registry/jsr`,

69 +

},

70 +

},

71 +

}));

72 + 73 +

await run(`install`);

74 +

await run(`pack`);

75 + 76 +

const tarballPath = ppath.join(path, `package.tgz`);

77 +

const unpackedPath = ppath.join(path, `unpacked`);

78 + 79 +

await xfs.mkdirPromise(unpackedPath);

80 +

await fsUtils.unpackToDirectory(unpackedPath, tarballPath);

81 + 82 +

const manifest = await xfs.readJsonPromise(ppath.join(unpackedPath, `package`, `package.json`));

83 + 84 +

expect(manifest).toMatchObject({

85 +

dependencies: {

86 +

[`no-deps-jsr`]: `npm:@jsr/no-deps-jsr@1.0.0`,

87 +

},

88 +

});

89 +

},

90 +

),

91 +

);

92 +

});

93 +

});

Original file line number Diff line number Diff line change

@@ -0,0 +1,22 @@

1 +

---

2 +

category: protocols

3 +

slug: /protocol/jsr

4 +

title: "JSR Protocol"

5 +

description: How JSR dependencies work in Yarn.

6 +

---

7 + 8 +

The `jsr:` protocol fetches packages from the [JSR registry](https://jsr.io/).

9 + 10 +

```

11 +

yarn add @luca/flag@jsr:2.0.0

12 +

```

13 + 14 +

Note that because the JSR registry is responsible for compiling packages from TypeScript to JavaScript they sometimes re-pack packages. As a result, the Yarn lockfile contains the full tarball URLs.

15 + 16 +

Quoting the [JSR documentation](https://jsr.io/docs/npm-compatibility):

17 + 18 +

> The specific tarballs advertised for a given version of a package may change over time, even if the version itself is not changed. This is because the JSR registry may re-generate npm compatible tarballs for a package version to fix compatibility issues with npm or improve the transpile output in the generated tarball. We refer to this as the “revision” of a tarball. The revision of a tarball is not advertised in the npm registry endpoint, but it is included in the URL of the tarball itself and is included in the `package.json` file in the tarball at the `_jsr_revision` field. The revision of a tarball is not considered part of the package version, and does not affect semver resolution.

19 +

>

20 +

> However, tarball URLs are immutable. Tools that have a reference to a specific tarball URL will always be able to download that exact tarball. When a new revision of a tarball is generated, the old tarball is not deleted and will continue to be available at the same URL. The new tarball will be available at a new URL that includes the new revision.

21 +

>

22 +

> Because the tarball URL is included in package manager lock files, running `npm i` / `yarn` / `pnpm i` will never accidentally download a new revision of the tarball.

Original file line number Diff line number Diff line change

@@ -0,0 +1,7 @@

1 +

# `@yarnpkg/plugin-jsr`

2 + 3 +

This plugin adds support for the `jsr:` protocol.

4 + 5 +

## Install

6 + 7 +

This plugin is included by default in Yarn.

Original file line number Diff line number Diff line change

@@ -0,0 +1,43 @@

1 +

{

2 +

"name": "@yarnpkg/plugin-jsr",

3 +

"version": "1.0.0",

4 +

"license": "BSD-2-Clause",

5 +

"main": "./sources/index.ts",

6 +

"exports": {

7 +

".": "./sources/index.ts",

8 +

"./package.json": "./package.json"

9 +

},

10 +

"dependencies": {

11 +

"@yarnpkg/fslib": "workspace:^",

12 +

"tslib": "^2.4.0"

13 +

},

14 +

"peerDependencies": {

15 +

"@yarnpkg/core": "workspace:^"

16 +

},

17 +

"devDependencies": {

18 +

"@yarnpkg/core": "workspace:^"

19 +

},

20 +

"repository": {

21 +

"type": "git",

22 +

"url": "git+https://github.com/yarnpkg/berry.git",

23 +

"directory": "packages/plugin-jsr"

24 +

},

25 +

"scripts": {

26 +

"postpack": "rm -rf lib",

27 +

"prepack": "run build:compile \"$(pwd)\""

28 +

},

29 +

"publishConfig": {

30 +

"main": "./lib/index.js",

31 +

"exports": {

32 +

".": "./lib/index.js",

33 +

"./package.json": "./package.json"

34 +

}

35 +

},

36 +

"files": [

37 +

"/lib/**/*"

38 +

],

39 +

"engines": {

40 +

"node": ">=18.12.0"

41 +

},

42 +

"stableVersion": "1.0.0"

43 +

}

Original file line number Diff line number Diff line change

@@ -0,0 +1,54 @@

1 +

import {Descriptor, Locator, Plugin, Project, ResolveOptions, Resolver, Workspace} from '@yarnpkg/core';

2 +

import {structUtils, semverUtils} from '@yarnpkg/core';

3 + 4 +

function normalizeJsrDependency(dependency: Descriptor) {

5 +

if (semverUtils.validRange(dependency.range.slice(4)))

6 +

return structUtils.makeDescriptor(dependency, `npm:${structUtils.wrapIdentIntoScope(dependency, `jsr`)}@${dependency.range.slice(4)}`);

7 + 8 +

const parsedRange = structUtils.tryParseDescriptor(dependency.range.slice(4), true);

9 +

if (parsedRange !== null)

10 +

return structUtils.makeDescriptor(dependency, `npm:${structUtils.wrapIdentIntoScope(parsedRange, `jsr`)}@${parsedRange.range}`);

11 + 12 + 13 +

return dependency;

14 +

}

15 + 16 +

function reduceDependency(dependency: Descriptor, project: Project, locator: Locator, initialDependency: Descriptor, {resolver, resolveOptions}: {resolver: Resolver, resolveOptions: ResolveOptions}) {

17 +

return dependency.range.startsWith(`jsr:`)

18 +

? normalizeJsrDependency(dependency)

19 +

: dependency;

20 +

}

21 + 22 +

const DEPENDENCY_TYPES = [`dependencies`, `devDependencies`, `peerDependencies`];

23 + 24 +

function beforeWorkspacePacking(workspace: Workspace, rawManifest: any) {

25 +

for (const dependencyType of DEPENDENCY_TYPES) {

26 +

for (const descriptor of workspace.manifest.getForScope(dependencyType).values()) {

27 +

if (!descriptor.range.startsWith(`jsr:`))

28 +

continue;

29 + 30 +

const normalizedDescriptor = normalizeJsrDependency(descriptor);

31 + 32 +

// Ensure optional dependencies are handled as well

33 +

const identDescriptor = dependencyType === `dependencies`

34 +

? structUtils.makeDescriptor(descriptor, `unknown`)

35 +

: null;

36 + 37 +

const finalDependencyType = identDescriptor !== null && workspace.manifest.ensureDependencyMeta(identDescriptor).optional

38 +

? `optionalDependencies`

39 +

: dependencyType;

40 + 41 +

rawManifest[finalDependencyType][structUtils.stringifyIdent(descriptor)] = normalizedDescriptor.range;

42 +

}

43 +

}

44 +

}

45 + 46 +

const plugin: Plugin = {

47 +

hooks: {

48 +

reduceDependency,

49 +

beforeWorkspacePacking,

50 +

},

51 +

};

52 + 53 +

// eslint-disable-next-line arca/no-default-export

54 +

export default plugin;

You can’t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4