Skip to content

Commit e64af83

Browse files
authored
Adds support for the libc field in package.json (#3981)
* Adds support for the libc field in package.json * Updates tests * Fixes tests and adds more patterns * Adds comment * Update pnp.test.js * Update pnp.test.js * Fixes race condition when spawning server twice * Avoids calling getReport on Windows * Missing comment part
1 parent ecfeca0 commit e64af83

File tree

18 files changed

+256
-23
lines changed

18 files changed

+256
-23
lines changed

.yarn/versions/7f7b169a.yml

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

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -256,15 +256,14 @@ export const getPackageDirectoryPath = async (
256256
};
257257

258258
const packageServerUrls: {
259-
http: string | null;
260-
https: string | null;
259+
http: Promise<string> | null;
260+
https: Promise<string> | null;
261261
} = {http: null, https: null};
262262

263263
export const startPackageServer = ({type}: { type: keyof typeof packageServerUrls } = {type: `http`}): Promise<string> => {
264264
const serverUrl = packageServerUrls[type];
265-
266265
if (serverUrl !== null)
267-
return Promise.resolve(serverUrl);
266+
return serverUrl;
268267

269268
const applyOtpValidation = (req: IncomingMessage, res: ServerResponse, user: Login) => {
270269
const otp = req.headers[`npm-otp`];
@@ -536,7 +535,7 @@ export const startPackageServer = ({type}: { type: keyof typeof packageServerUrl
536535
validAuthorizations.set(`Basic ${user.npmAuthIdent.encoded}`, user);
537536
}
538537

539-
return new Promise((resolve, reject) => {
538+
return packageServerUrls[type] = new Promise((resolve, reject) => {
540539
const listener: http.RequestListener = (req, res) =>
541540
void (async () => {
542541
try {
@@ -595,7 +594,7 @@ export const startPackageServer = ({type}: { type: keyof typeof packageServerUrl
595594
server.unref();
596595
server.listen(() => {
597596
const {port} = server.address() as AddressInfo;
598-
resolve((packageServerUrls[type] = `${type}://localhost:${port}`));
597+
resolve(`${type}://localhost:${port}`);
599598
});
600599
})();
601600
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/* @flow */
2+
3+
module.exports = require(`./package.json`);
4+
5+
for (const key of [`dependencies`, `devDependencies`, `peerDependencies`]) {
6+
for (const dep of Object.keys(module.exports[key] || {})) {
7+
// $FlowFixMe The whole point of this file is to be dynamic
8+
module.exports[key][dep] = require(dep);
9+
}
10+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "native-libc-glibc",
3+
"version": "1.0.0",
4+
"libc": ["glibc"]
5+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/* @flow */
2+
3+
module.exports = require(`./package.json`);
4+
5+
for (const key of [`dependencies`, `devDependencies`, `peerDependencies`]) {
6+
for (const dep of Object.keys(module.exports[key] || {})) {
7+
// $FlowFixMe The whole point of this file is to be dynamic
8+
module.exports[key][dep] = require(dep);
9+
}
10+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "native-libc-musl",
3+
"version": "1.0.0",
4+
"libc": ["musl"]
5+
}

packages/acceptance-tests/pkg-tests-fixtures/packages/optional-native-1.0.0/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
"optionalDependencies": {
55
"native-bar-x64": "1.0.0",
66
"native-foo-x64": "1.0.0",
7-
"native-foo-x86": "1.0.0"
7+
"native-foo-x86": "1.0.0",
8+
"native-libc-glibc": "1.0.0",
9+
"native-libc-musl": "1.0.0"
810
}
911
}

packages/acceptance-tests/pkg-tests-specs/sources/features/__snapshots__/prunedNativeDeps.test.ts.snap

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,41 @@ __metadata:
2929
languageName: node
3030
linkType: hard
3131
32+
\\"native-libc-glibc@npm:1.0.0\\":
33+
version: 1.0.0
34+
resolution: \\"native-libc-glibc@npm:1.0.0\\"
35+
conditions: libc=glibc
36+
languageName: node
37+
linkType: hard
38+
39+
\\"native-libc-musl@npm:1.0.0\\":
40+
version: 1.0.0
41+
resolution: \\"native-libc-musl@npm:1.0.0\\"
42+
conditions: libc=musl
43+
languageName: node
44+
linkType: hard
45+
3246
\\"optional-native@npm:1.0.0\\":
3347
version: 1.0.0
3448
resolution: \\"optional-native@npm:1.0.0\\"
3549
dependencies:
3650
native-bar-x64: 1.0.0
3751
native-foo-x64: 1.0.0
3852
native-foo-x86: 1.0.0
53+
native-libc-glibc: 1.0.0
54+
native-libc-musl: 1.0.0
3955
dependenciesMeta:
4056
native-bar-x64:
4157
optional: true
4258
native-foo-x64:
4359
optional: true
4460
native-foo-x86:
4561
optional: true
46-
checksum: 0e662ccf2f901c37aa95cc3e8bee87315782ca27582521644c86e1ee44367a31a0201049bad23109ca9783efc9ac70bc7dae8619c31f2b6472830b7cf1670f0d
62+
native-libc-glibc:
63+
optional: true
64+
native-libc-musl:
65+
optional: true
66+
checksum: b62ce5449e2631a9bc4d264ca9cd32cdb96465d6d739cca3378a4e48cf2db199e01c83e97cccee2f657709e5b79403b0cd4dcbc3aa6a96608c11b17b72df3e2c
4767
languageName: node
4868
linkType: hard
4969

packages/acceptance-tests/pkg-tests-specs/sources/features/prunedNativeDeps.test.ts

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ describe(`Features`, () => {
1414
supportedArchitectures: {
1515
cpu: [`foo`],
1616
os: [`x64`],
17+
libc: [`glibc`],
1718
},
1819
});
1920

@@ -31,6 +32,7 @@ describe(`Features`, () => {
3132
supportedArchitectures: {
3233
os: [`foo`],
3334
cpu: [`x64`],
35+
libc: [`glibc`],
3436
},
3537
});
3638

@@ -50,6 +52,10 @@ describe(`Features`, () => {
5052
type: RequestType.PackageTarball,
5153
localName: `native-foo-x64`,
5254
version: `1.0.0`,
55+
}, {
56+
type: RequestType.PackageTarball,
57+
localName: `native-libc-glibc`,
58+
version: `1.0.0`,
5359
}, {
5460
type: RequestType.PackageTarball,
5561
localName: `optional-native`,
@@ -66,6 +72,7 @@ describe(`Features`, () => {
6672
supportedArchitectures: {
6773
os: [`foo`],
6874
cpu: [`x64`, `x86`],
75+
libc: [`glibc`, `musl`],
6976
},
7077
});
7178

@@ -89,6 +96,14 @@ describe(`Features`, () => {
8996
type: RequestType.PackageTarball,
9097
localName: `native-foo-x86`,
9198
version: `1.0.0`,
99+
}, {
100+
type: RequestType.PackageTarball,
101+
localName: `native-libc-glibc`,
102+
version: `1.0.0`,
103+
}, {
104+
type: RequestType.PackageTarball,
105+
localName: `native-libc-musl`,
106+
version: `1.0.0`,
92107
}, {
93108
type: RequestType.PackageTarball,
94109
localName: `optional-native`,
@@ -105,6 +120,7 @@ describe(`Features`, () => {
105120
supportedArchitectures: {
106121
os: [`foo`],
107122
cpu: [`x64`],
123+
libc: [`glibc`],
108124
},
109125
});
110126

@@ -113,8 +129,9 @@ describe(`Features`, () => {
113129

114130
await xfs.writeJsonPromise(ppath.join(path, Filename.rc), {
115131
supportedArchitectures: {
116-
os: [`foo`],
132+
os: [`bar`],
117133
cpu: [`x86`],
134+
libc: [`musl`],
118135
},
119136
});
120137

@@ -133,6 +150,7 @@ describe(`Features`, () => {
133150
supportedArchitectures: {
134151
os: [`foo`],
135152
cpu: [`x64`],
153+
libc: [`glibc`],
136154
},
137155
});
138156

@@ -141,8 +159,9 @@ describe(`Features`, () => {
141159

142160
await xfs.writeJsonPromise(ppath.join(path, Filename.rc), {
143161
supportedArchitectures: {
144-
os: [`foo`],
162+
os: [`bar`],
145163
cpu: [`x86`],
164+
libc: [`musl`],
146165
},
147166
});
148167

@@ -161,6 +180,7 @@ describe(`Features`, () => {
161180
supportedArchitectures: {
162181
os: [`foo`],
163182
cpu: [`x64`],
183+
libc: [`glibc`],
164184
},
165185
});
166186

@@ -185,6 +205,7 @@ describe(`Features`, () => {
185205
supportedArchitectures: {
186206
os: [`foo`],
187207
cpu: [`x64`],
208+
libc: [`glibc`],
188209
},
189210
});
190211

@@ -213,6 +234,7 @@ describe(`Features`, () => {
213234
supportedArchitectures: {
214235
os: [`foo`],
215236
cpu: [`x64`, `x86`],
237+
libc: [`glibc`],
216238
},
217239
});
218240

@@ -231,6 +253,7 @@ describe(`Features`, () => {
231253
supportedArchitectures: {
232254
os: [`foo`],
233255
cpu: [`x86`],
256+
libc: [`glibc`],
234257
},
235258
});
236259

@@ -248,6 +271,7 @@ describe(`Features`, () => {
248271
supportedArchitectures: {
249272
os: [`foo`],
250273
cpu: [`x64`, `x86`],
274+
libc: [`glibc`],
251275
},
252276
});
253277

@@ -257,6 +281,7 @@ describe(`Features`, () => {
257281
supportedArchitectures: {
258282
os: [`foo`],
259283
cpu: [`x64`],
284+
libc: [`glibc`],
260285
},
261286
});
262287

@@ -280,6 +305,10 @@ describe(`Features`, () => {
280305
type: RequestType.PackageTarball,
281306
localName: `native-foo-x86`,
282307
version: `1.0.0`,
308+
}, {
309+
type: RequestType.PackageTarball,
310+
localName: `native-libc-glibc`,
311+
version: `1.0.0`,
283312
}, {
284313
type: RequestType.PackageTarball,
285314
localName: `optional-native`,

packages/acceptance-tests/pkg-tests-specs/sources/pnp.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1636,7 +1636,7 @@ describe(`Plug'n'Play`, () => {
16361636
const stdout = (await run(`install`)).stdout;
16371637

16381638
expect(stdout).not.toContain(`Shall not be run`);
1639-
expect(stdout).toMatch(new RegExp(`dep@file:./dep.*The ${process.platform}-${process.arch} architecture is incompatible with this module, build skipped.`));
1639+
expect(stdout).toMatch(new RegExp(`dep@file:./dep.*The ${process.platform}-${process.arch}(-[a-z]+)? architecture is incompatible with this package, build skipped.`));
16401640

16411641
await expect(source(`require('dep')`)).resolves.toMatchObject({
16421642
name: `dep`,

packages/gatsby/static/configuration/yarnrc.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,15 @@
691691
},
692692
"default": [],
693693
"_exampleItems": ["current", "x86", "ia32"]
694+
},
695+
"libc": {
696+
"description": "The list of standard libraries to cover.",
697+
"type": "array",
698+
"items": {
699+
"type": "string"
700+
},
701+
"default": [],
702+
"_exampleItems": ["current", "glibc", "musl"]
694703
}
695704
},
696705
"_exampleKeys": ["os", "cpu"]

packages/plugin-pnp/sources/jsInstallUtils.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import {BuildDirective, BuildType, Configuration, DependencyMeta, FetchResult, LinkType, Manifest, MessageName, Package, Report, structUtils} from '@yarnpkg/core';
2-
import {Filename, ppath} from '@yarnpkg/fslib';
1+
import {BuildDirective, BuildType, Configuration, DependencyMeta, FetchResult, LinkType, Manifest, MessageName, Package, Report, nodeUtils, structUtils} from '@yarnpkg/core';
2+
import {Filename, ppath} from '@yarnpkg/fslib';
33

44
export function checkManifestCompatibility(pkg: Package) {
5-
return structUtils.isPackageCompatible(pkg, {os: [process.platform], cpu: [process.arch]});
5+
return structUtils.isPackageCompatible(pkg, nodeUtils.getArchitectureSet());
66
}
77

88
export function checkAndReportManifestCompatibility(pkg: Package, label: string, {configuration, report}: {configuration: Configuration, report?: Report | null}) {
99
if (!checkManifestCompatibility(pkg)) {
10-
report?.reportWarningOnce(MessageName.INCOMPATIBLE_ARCHITECTURE, `${structUtils.prettyLocator(configuration, pkg)} The ${process.platform}-${process.arch} architecture is incompatible with this module, ${label} skipped.`);
10+
report?.reportWarningOnce(MessageName.INCOMPATIBLE_ARCHITECTURE, `${structUtils.prettyLocator(configuration, pkg)} The ${nodeUtils.getArchitectureName()} architecture is incompatible with this package, ${label} skipped.`);
1111
return false;
1212
}
1313

packages/yarnpkg-core/sources/Configuration.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export enum SettingsType {
7979
export type SupportedArchitectures = {
8080
os: Array<string> | null;
8181
cpu: Array<string> | null;
82+
libc: Array<string> | null;
8283
};
8384

8485
export type FormatType = formatUtils.Type;
@@ -307,6 +308,13 @@ export const coreDefinitions: {[coreSettingName: string]: SettingsDefinition} =
307308
isNullable: true,
308309
default: [`current`],
309310
},
311+
libc: {
312+
description: `Array of supported libc libraries, or null to target them all`,
313+
type: SettingsType.STRING,
314+
isArray: true,
315+
isNullable: true,
316+
default: [`current`],
317+
},
310318
},
311319
},
312320

@@ -1469,18 +1477,23 @@ export class Configuration {
14691477
return linkers;
14701478
}
14711479

1472-
getSupportedArchitectures() {
1480+
getSupportedArchitectures(): nodeUtils.ArchitectureSet {
1481+
const architecture = nodeUtils.getArchitecture();
14731482
const supportedArchitectures = this.get(`supportedArchitectures`);
14741483

14751484
let os = supportedArchitectures.get(`os`);
14761485
if (os !== null)
1477-
os = os.map(value => value === `current` ? process.platform : value);
1486+
os = os.map(value => value === `current` ? architecture.os : value);
14781487

14791488
let cpu = supportedArchitectures.get(`cpu`);
14801489
if (cpu !== null)
1481-
cpu = cpu.map(value => value === `current` ? process.arch : value);
1490+
cpu = cpu.map(value => value === `current` ? architecture.cpu : value);
1491+
1492+
let libc = supportedArchitectures.get(`libc`);
1493+
if (libc !== null)
1494+
libc = miscUtils.mapAndFilter(libc, value => value === `current` ? architecture.libc ?? miscUtils.mapAndFilter.skip : value);
14821495

1483-
return {os, cpu};
1496+
return {os, cpu, libc};
14841497
}
14851498

14861499
async refreshPackageExtensions() {

0 commit comments

Comments
 (0)