Skip to content

Commit c111ea7

Browse files
authored
fix(pnp): ensure URL is imported on Node.js < 20 (#6060)
**What's the problem this PR addresses?** Before nodejs/node#46904 using a custom global URL class wasn't supported by `fileURLToPath`. Closes #6030 Fixes #5915 **How did you fix it?** - Created a rollup plugin to ensure that the builtin URL class is always used on Node.js < v20. - Removed all imports of `URL` since it's a global and to avoid mixing custom and builtin URL class instances. **Checklist** - [x] I have read the [Contributing Guide](https://yarnpkg.com/advanced/contributing). - [x] I have set the packages that need to be released for my changes to be effective. - [x] I will check that all automated PR checks pass before the PR gets reviewed.
1 parent eae38cb commit c111ea7

File tree

17 files changed

+105
-64
lines changed

17 files changed

+105
-64
lines changed

.eslintrc.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,17 @@ module.exports = {
4444
message: `Use 'httpUtils' instead`,
4545
},
4646
],
47+
'no-restricted-imports': [
48+
`error`,
49+
{
50+
patterns: [
51+
{
52+
group: [`url`, `node:url`],
53+
importNames: [`URL`],
54+
message: `URL is a global, no need to import it`,
55+
},
56+
],
57+
},
58+
],
4759
},
4860
};

.pnp.cjs

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

.pnp.loader.mjs

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

.yarn/versions/ae9dd917.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
releases:
2+
"@yarnpkg/cli": patch
3+
"@yarnpkg/core": patch
4+
"@yarnpkg/fslib": patch
5+
"@yarnpkg/plugin-essentials": patch
6+
"@yarnpkg/plugin-npm": patch
7+
"@yarnpkg/pnp": patch
8+
9+
declined:
10+
- "@yarnpkg/plugin-compat"
11+
- "@yarnpkg/plugin-constraints"
12+
- "@yarnpkg/plugin-dlx"
13+
- "@yarnpkg/plugin-exec"
14+
- "@yarnpkg/plugin-file"
15+
- "@yarnpkg/plugin-git"
16+
- "@yarnpkg/plugin-github"
17+
- "@yarnpkg/plugin-http"
18+
- "@yarnpkg/plugin-init"
19+
- "@yarnpkg/plugin-interactive-tools"
20+
- "@yarnpkg/plugin-link"
21+
- "@yarnpkg/plugin-nm"
22+
- "@yarnpkg/plugin-npm-cli"
23+
- "@yarnpkg/plugin-pack"
24+
- "@yarnpkg/plugin-patch"
25+
- "@yarnpkg/plugin-pnp"
26+
- "@yarnpkg/plugin-pnpm"
27+
- "@yarnpkg/plugin-stage"
28+
- "@yarnpkg/plugin-typescript"
29+
- "@yarnpkg/plugin-version"
30+
- "@yarnpkg/plugin-workspace-tools"
31+
- vscode-zipfs
32+
- "@yarnpkg/builder"
33+
- "@yarnpkg/doctor"
34+
- "@yarnpkg/extensions"
35+
- "@yarnpkg/libzip"
36+
- "@yarnpkg/nm"
37+
- "@yarnpkg/pnpify"
38+
- "@yarnpkg/sdks"
39+
- "@yarnpkg/shell"

packages/acceptance-tests/pkg-tests-core/sources/utils/makeTemporaryEnv.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import {npath} from '@yarnpkg/fslib';
22
import {delimiter} from 'path';
3-
import {URL} from 'url';
43

54
import * as exec from './exec';
65
import * as tests from './tests';

packages/plugin-essentials/sources/commands/plugin/import.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {YarnVersion, formatUtils, httpUtils, structUtils, hashUtils}
55
import {PortablePath, npath, ppath, xfs} from '@yarnpkg/fslib';
66
import {Command, Option, Usage} from 'clipanion';
77
import semver from 'semver';
8-
import {URL} from 'url';
98
import {runInNewContext} from 'vm';
109

1110
import {getAvailablePlugins} from './list';

packages/plugin-npm/sources/NpmSemverFetcher.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import {Configuration, Fetcher, FetchOptions, MinimalFetchOptions} from '@yarnpk
22
import {structUtils, tgzUtils, semverUtils} from '@yarnpkg/core';
33
import {Locator, MessageName, ReportError} from '@yarnpkg/core';
44
import semver from 'semver';
5-
import {URL} from 'url';
65

76
import {PROTOCOL} from './constants';
87
import * as npmConfigUtils from './npmConfigUtils';

packages/plugin-npm/sources/npmHttpUtils.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {Filename, PortablePath, ppath, xfs}
44
import {prompt} from 'enquirer';
55
import pick from 'lodash/pick';
66
import semver from 'semver';
7-
import {URL} from 'url';
87

98
import {Hooks} from './index';
109
import * as npmConfigUtils from './npmConfigUtils';

packages/plugin-npm/sources/npmPublishUtils.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {PortablePath, xfs, npath} from '@yarnpkg/fslib';
44
import {packUtils} from '@yarnpkg/plugin-pack';
55
import {createHash} from 'crypto';
66
import ssri from 'ssri';
7-
import {URL} from 'url';
87

98
import {normalizeRegistry} from './npmConfigUtils';
109

packages/yarnpkg-core/sources/Plugin.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import {PortablePath} from '@yarnpkg/fslib';
22
import {CommandClass} from 'clipanion';
33
import {Writable, Readable} from 'stream';
4-
import {URL} from 'url';
54

65
import {PluginConfiguration, Configuration, ConfigurationDefinitionMap, PackageExtensionData} from './Configuration';
76
import {Fetcher} from './Fetcher';

0 commit comments

Comments
 (0)