Skip to content

Commit 67463b2

Browse files
authored
chore(deps): bump tar from 6.x to 7.x, selectively import required functions (#533)
Changes from 06e5872 made it possible to update tar from 6.x to 7.x and use new `package.json` exports that are included in 7.x, allowing us to further reduce our bundle size.
1 parent 6019d7b commit 67463b2

File tree

7 files changed

+100
-52
lines changed

7 files changed

+100
-52
lines changed

Diff for: package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
"@types/node": "^20.4.6",
2323
"@types/proxy-from-env": "^1",
2424
"@types/semver": "^7.1.0",
25-
"@types/tar": "^6.0.0",
2625
"@types/which": "^3.0.0",
2726
"@yarnpkg/eslint-config": "^2.0.0",
2827
"@yarnpkg/fslib": "^3.0.0-rc.48",
@@ -35,7 +34,7 @@
3534
"proxy-from-env": "^1.1.0",
3635
"semver": "^7.5.2",
3736
"supports-color": "^9.0.0",
38-
"tar": "^6.2.1",
37+
"tar": "^7.4.0",
3938
"tsx": "^4.16.2",
4039
"typescript": "^5.3.3",
4140
"undici": "^6.19.2",

Diff for: sources/commands/InstallGlobal.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,11 @@ export class InstallGlobalCommand extends BaseCommand {
7777
const installFolder = folderUtils.getInstallFolder();
7878

7979
const archiveEntries = new Map<string, Set<string>>();
80-
const {default: tar} = await import(`tar`);
80+
const {list: tarT} = await import(`tar/list`);
8181

8282
let hasShortEntries = false;
8383

84-
await tar.t({file: p, onentry: entry => {
84+
await tarT({file: p, onentry: entry => {
8585
const segments = entry.path.split(/\//g);
8686
if (segments.length > 0 && segments[segments.length - 1] !== `.corepack`)
8787
return;
@@ -100,6 +100,8 @@ export class InstallGlobalCommand extends BaseCommand {
100100
if (hasShortEntries || archiveEntries.size < 1)
101101
throw new UsageError(`Invalid archive format; did it get generated by 'corepack pack'?`);
102102

103+
const {extract: tarX} = await import(`tar/extract`);
104+
103105
for (const [name, references] of archiveEntries) {
104106
for (const reference of references) {
105107
if (!isSupportedPackageManager(name))
@@ -110,7 +112,7 @@ export class InstallGlobalCommand extends BaseCommand {
110112
// Recreate the folder in case it was deleted somewhere else:
111113
await fs.promises.mkdir(installFolder, {recursive: true});
112114

113-
await tar.x({file: p, cwd: installFolder}, [`${name}/${reference}`]);
115+
await tarX({file: p, cwd: installFolder}, [`${name}/${reference}`]);
114116

115117
if (!this.cacheOnly) {
116118
await this.context.engine.activatePackageManager({name, reference});

Diff for: sources/commands/Pack.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ export class PackCommand extends BaseCommand {
6262
this.context.stdout.write(`Packing the selected tools in ${path.basename(outputPath)}...\n`);
6363
}
6464

65-
const {default: tar} = await import(`tar`);
65+
const {create: tarC} = await import(`tar/create`);
6666

6767
// Recreate the folder in case it was deleted somewhere else:
6868
await mkdir(baseInstallFolder, {recursive: true});
69-
await tar.c({gzip: true, cwd: baseInstallFolder, file: path.resolve(outputPath)}, installLocations.map(location => {
69+
await tarC({gzip: true, cwd: baseInstallFolder, file: path.resolve(outputPath)}, installLocations.map(location => {
7070
return path.relative(baseInstallFolder, location);
7171
}));
7272

Diff for: sources/commands/deprecated/Hydrate.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ export class HydrateCommand extends Command<Context> {
2424
const archiveEntries = new Map<string, Set<string>>();
2525
let hasShortEntries = false;
2626

27-
const {default: tar} = await import(`tar`);
27+
const {list: tarT} = await import(`tar/list`);
2828

29-
await tar.t({file: fileName, onentry: entry => {
29+
await tarT({file: fileName, onentry: entry => {
3030
const segments = entry.path.split(/\//g);
3131

3232
if (segments.length < 3) {
@@ -43,6 +43,8 @@ export class HydrateCommand extends Command<Context> {
4343
if (hasShortEntries || archiveEntries.size < 1)
4444
throw new UsageError(`Invalid archive format; did it get generated by 'corepack prepare'?`);
4545

46+
const {extract: tarX} = await import(`tar/extract`);
47+
4648
for (const [name, references] of archiveEntries) {
4749
for (const reference of references) {
4850
if (!isSupportedPackageManager(name))
@@ -56,7 +58,7 @@ export class HydrateCommand extends Command<Context> {
5658
// Recreate the folder in case it was deleted somewhere else:
5759
await mkdir(installFolder, {recursive: true});
5860

59-
await tar.x({file: fileName, cwd: installFolder}, [`${name}/${reference}`]);
61+
await tarX({file: fileName, cwd: installFolder}, [`${name}/${reference}`]);
6062

6163
if (this.activate) {
6264
await this.context.engine.activatePackageManager({name, reference});

Diff for: sources/commands/deprecated/Prepare.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ export class PrepareCommand extends Command<Context> {
8383
if (!this.json)
8484
this.context.stdout.write(`Packing the selected tools in ${path.basename(outputPath)}...\n`);
8585

86-
const {default: tar} = await import(`tar`);
86+
const {create: tarC} = await import(`tar/create`);
8787
// Recreate the folder in case it was deleted somewhere else:
8888
await mkdir(baseInstallFolder, {recursive: true});
89-
await tar.c({gzip: true, cwd: baseInstallFolder, file: path.resolve(outputPath)}, installLocations.map(location => {
89+
await tarC({gzip: true, cwd: baseInstallFolder, file: path.resolve(outputPath)}, installLocations.map(location => {
9090
return path.relative(baseInstallFolder, location);
9191
}));
9292

Diff for: sources/corepackUtils.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ async function download(installTarget: string, url: string, algo: string, binPat
151151
let sendTo: any;
152152

153153
if (ext === `.tgz`) {
154-
const {default: tar} = await import(`tar`);
155-
sendTo = tar.x({
154+
const {extract: tarX} = await import(`tar/extract`);
155+
sendTo = tarX({
156156
strip: 1,
157157
cwd: tmpFolder,
158158
filter: binPath ? path => {

Diff for: yarn.lock

+83-38
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,15 @@ __metadata:
257257
languageName: node
258258
linkType: hard
259259

260+
"@isaacs/fs-minipass@npm:^4.0.0":
261+
version: 4.0.1
262+
resolution: "@isaacs/fs-minipass@npm:4.0.1"
263+
dependencies:
264+
minipass: "npm:^7.0.4"
265+
checksum: 10c0/c25b6dc1598790d5b55c0947a9b7d111cfa92594db5296c3b907e2f533c033666f692a3939eadac17b1c7c40d362d0b0635dc874cbfe3e70db7c2b07cc97a5d2
266+
languageName: node
267+
linkType: hard
268+
260269
"@jridgewell/gen-mapping@npm:^0.3.5":
261270
version: 0.3.5
262271
resolution: "@jridgewell/gen-mapping@npm:0.3.5"
@@ -515,16 +524,6 @@ __metadata:
515524
languageName: node
516525
linkType: hard
517526

518-
"@types/tar@npm:^6.0.0":
519-
version: 6.1.13
520-
resolution: "@types/tar@npm:6.1.13"
521-
dependencies:
522-
"@types/node": "npm:*"
523-
minipass: "npm:^4.0.0"
524-
checksum: 10c0/98cc72d444fa622049e86e457a64d859c6effd7c7518d36e7b40b4ab1e7aa9e2412cc868cbef396650485dae07d50d98f662e8a53bb45f4a70eb6c61f80a63c7
525-
languageName: node
526-
linkType: hard
527-
528527
"@types/which@npm:^3.0.0":
529528
version: 3.0.4
530529
resolution: "@types/which@npm:3.0.4"
@@ -1152,6 +1151,13 @@ __metadata:
11521151
languageName: node
11531152
linkType: hard
11541153

1154+
"chownr@npm:^3.0.0":
1155+
version: 3.0.0
1156+
resolution: "chownr@npm:3.0.0"
1157+
checksum: 10c0/43925b87700f7e3893296c8e9c56cc58f926411cce3a6e5898136daaf08f08b9a8eb76d37d3267e707d0dcc17aed2e2ebdf5848c0c3ce95cf910a919935c1b10
1158+
languageName: node
1159+
linkType: hard
1160+
11551161
"clean-stack@npm:^2.0.0":
11561162
version: 2.2.0
11571163
resolution: "clean-stack@npm:2.2.0"
@@ -1219,7 +1225,6 @@ __metadata:
12191225
"@types/node": "npm:^20.4.6"
12201226
"@types/proxy-from-env": "npm:^1"
12211227
"@types/semver": "npm:^7.1.0"
1222-
"@types/tar": "npm:^6.0.0"
12231228
"@types/which": "npm:^3.0.0"
12241229
"@yarnpkg/eslint-config": "npm:^2.0.0"
12251230
"@yarnpkg/fslib": "npm:^3.0.0-rc.48"
@@ -1232,7 +1237,7 @@ __metadata:
12321237
proxy-from-env: "npm:^1.1.0"
12331238
semver: "npm:^7.5.2"
12341239
supports-color: "npm:^9.0.0"
1235-
tar: "npm:^6.2.1"
1240+
tar: "npm:^7.4.0"
12361241
tsx: "npm:^4.16.2"
12371242
typescript: "npm:^5.3.3"
12381243
undici: "npm:^6.19.2"
@@ -1286,19 +1291,7 @@ __metadata:
12861291
languageName: node
12871292
linkType: hard
12881293

1289-
"debug@npm:4, debug@npm:^4.1.1, debug@npm:^4.3.1, debug@npm:^4.3.2, debug@npm:^4.3.4":
1290-
version: 4.3.4
1291-
resolution: "debug@npm:4.3.4"
1292-
dependencies:
1293-
ms: "npm:2.1.2"
1294-
peerDependenciesMeta:
1295-
supports-color:
1296-
optional: true
1297-
checksum: 10c0/cedbec45298dd5c501d01b92b119cd3faebe5438c3917ff11ae1bff86a6c722930ac9c8659792824013168ba6db7c4668225d845c633fbdafbbf902a6389f736
1298-
languageName: node
1299-
linkType: hard
1300-
1301-
"debug@npm:^4.3.5":
1294+
"debug@npm:4, debug@npm:^4.1.1, debug@npm:^4.3.1, debug@npm:^4.3.2, debug@npm:^4.3.4, debug@npm:^4.3.5":
13021295
version: 4.3.5
13031296
resolution: "debug@npm:4.3.5"
13041297
dependencies:
@@ -2115,18 +2108,19 @@ __metadata:
21152108
languageName: node
21162109
linkType: hard
21172110

2118-
"glob@npm:^10.2.2, glob@npm:^10.3.10":
2119-
version: 10.4.1
2120-
resolution: "glob@npm:10.4.1"
2111+
"glob@npm:^10.2.2, glob@npm:^10.3.10, glob@npm:^10.3.7":
2112+
version: 10.4.5
2113+
resolution: "glob@npm:10.4.5"
21212114
dependencies:
21222115
foreground-child: "npm:^3.1.0"
21232116
jackspeak: "npm:^3.1.2"
21242117
minimatch: "npm:^9.0.4"
21252118
minipass: "npm:^7.1.2"
2119+
package-json-from-dist: "npm:^1.0.0"
21262120
path-scurry: "npm:^1.11.1"
21272121
bin:
21282122
glob: dist/esm/bin.mjs
2129-
checksum: 10c0/77f2900ed98b9cc2a0e1901ee5e476d664dae3cd0f1b662b8bfd4ccf00d0edc31a11595807706a274ca10e1e251411bbf2e8e976c82bed0d879a9b89343ed379
2123+
checksum: 10c0/19a9759ea77b8e3ca0a43c2f07ecddc2ad46216b786bb8f993c445aee80d345925a21e5280c7b7c6c59e860a0154b84e4b2b60321fea92cd3c56b4a7489f160e
21302124
languageName: node
21312125
linkType: hard
21322126

@@ -2957,21 +2951,14 @@ __metadata:
29572951
languageName: node
29582952
linkType: hard
29592953

2960-
"minipass@npm:^4.0.0":
2961-
version: 4.2.8
2962-
resolution: "minipass@npm:4.2.8"
2963-
checksum: 10c0/4ea76b030d97079f4429d6e8a8affd90baf1b6a1898977c8ccce4701c5a2ba2792e033abc6709373f25c2c4d4d95440d9d5e9464b46b7b76ca44d2ce26d939ce
2964-
languageName: node
2965-
linkType: hard
2966-
29672954
"minipass@npm:^5.0.0":
29682955
version: 5.0.0
29692956
resolution: "minipass@npm:5.0.0"
29702957
checksum: 10c0/a91d8043f691796a8ac88df039da19933ef0f633e3d7f0d35dcd5373af49131cf2399bfc355f41515dc495e3990369c3858cd319e5c2722b4753c90bf3152462
29712958
languageName: node
29722959
linkType: hard
29732960

2974-
"minipass@npm:^5.0.0 || ^6.0.2 || ^7.0.0, minipass@npm:^7.0.2, minipass@npm:^7.0.3, minipass@npm:^7.1.2":
2961+
"minipass@npm:^5.0.0 || ^6.0.2 || ^7.0.0, minipass@npm:^7.0.2, minipass@npm:^7.0.3, minipass@npm:^7.0.4, minipass@npm:^7.1.2":
29752962
version: 7.1.2
29762963
resolution: "minipass@npm:7.1.2"
29772964
checksum: 10c0/b0fd20bb9fb56e5fa9a8bfac539e8915ae07430a619e4b86ff71f5fc757ef3924b23b2c4230393af1eda647ed3d75739e4e0acb250a6b1eb277cf7f8fe449557
@@ -2988,6 +2975,16 @@ __metadata:
29882975
languageName: node
29892976
linkType: hard
29902977

2978+
"minizlib@npm:^3.0.1":
2979+
version: 3.0.1
2980+
resolution: "minizlib@npm:3.0.1"
2981+
dependencies:
2982+
minipass: "npm:^7.0.4"
2983+
rimraf: "npm:^5.0.5"
2984+
checksum: 10c0/82f8bf70da8af656909a8ee299d7ed3b3372636749d29e105f97f20e88971be31f5ed7642f2e898f00283b68b701cc01307401cdc209b0efc5dd3818220e5093
2985+
languageName: node
2986+
linkType: hard
2987+
29912988
"mkdirp-classic@npm:^0.5.2, mkdirp-classic@npm:^0.5.3":
29922989
version: 0.5.3
29932990
resolution: "mkdirp-classic@npm:0.5.3"
@@ -3004,6 +3001,15 @@ __metadata:
30043001
languageName: node
30053002
linkType: hard
30063003

3004+
"mkdirp@npm:^3.0.1":
3005+
version: 3.0.1
3006+
resolution: "mkdirp@npm:3.0.1"
3007+
bin:
3008+
mkdirp: dist/cjs/src/bin.js
3009+
checksum: 10c0/9f2b975e9246351f5e3a40dcfac99fcd0baa31fbfab615fe059fb11e51f10e4803c63de1f384c54d656e4db31d000e4767e9ef076a22e12a641357602e31d57d
3010+
languageName: node
3011+
linkType: hard
3012+
30073013
"ms@npm:2.1.2":
30083014
version: 2.1.2
30093015
resolution: "ms@npm:2.1.2"
@@ -3227,6 +3233,13 @@ __metadata:
32273233
languageName: node
32283234
linkType: hard
32293235

3236+
"package-json-from-dist@npm:^1.0.0":
3237+
version: 1.0.0
3238+
resolution: "package-json-from-dist@npm:1.0.0"
3239+
checksum: 10c0/e3ffaf6ac1040ab6082a658230c041ad14e72fabe99076a2081bb1d5d41210f11872403fc09082daf4387fc0baa6577f96c9c0e94c90c394fd57794b66aa4033
3240+
languageName: node
3241+
linkType: hard
3242+
32303243
"parent-module@npm:^1.0.0":
32313244
version: 1.0.1
32323245
resolution: "parent-module@npm:1.0.1"
@@ -3553,6 +3566,17 @@ __metadata:
35533566
languageName: node
35543567
linkType: hard
35553568

3569+
"rimraf@npm:^5.0.5":
3570+
version: 5.0.9
3571+
resolution: "rimraf@npm:5.0.9"
3572+
dependencies:
3573+
glob: "npm:^10.3.7"
3574+
bin:
3575+
rimraf: dist/esm/bin.mjs
3576+
checksum: 10c0/87374682492b9e64de9c6fcbf2c8f209c7a2cd0e9749b3732eef8a62c6f859a9ed996d46f662d9ad5dd38c2c469f8e88de56b6c509026070ee3f06369cac1bc8
3577+
languageName: node
3578+
linkType: hard
3579+
35563580
"rollup@npm:^4.13.0":
35573581
version: 4.18.1
35583582
resolution: "rollup@npm:4.18.1"
@@ -4010,7 +4034,7 @@ __metadata:
40104034
languageName: node
40114035
linkType: hard
40124036

4013-
"tar@npm:^6.1.11, tar@npm:^6.1.2, tar@npm:^6.2.1":
4037+
"tar@npm:^6.1.11, tar@npm:^6.1.2":
40144038
version: 6.2.1
40154039
resolution: "tar@npm:6.2.1"
40164040
dependencies:
@@ -4024,6 +4048,20 @@ __metadata:
40244048
languageName: node
40254049
linkType: hard
40264050

4051+
"tar@npm:^7.4.0":
4052+
version: 7.4.0
4053+
resolution: "tar@npm:7.4.0"
4054+
dependencies:
4055+
"@isaacs/fs-minipass": "npm:^4.0.0"
4056+
chownr: "npm:^3.0.0"
4057+
minipass: "npm:^7.1.2"
4058+
minizlib: "npm:^3.0.1"
4059+
mkdirp: "npm:^3.0.1"
4060+
yallist: "npm:^5.0.0"
4061+
checksum: 10c0/f4bab85fd101585f2cececc41eb8706191052ab65cc33f1a798198e0c7905f41b06ae3d6731fb2b6084847c53bc1e2265b77e05a105c0c44afaf6cb7a08ddf14
4062+
languageName: node
4063+
linkType: hard
4064+
40274065
"text-table@npm:^0.2.0":
40284066
version: 0.2.0
40294067
resolution: "text-table@npm:0.2.0"
@@ -4510,6 +4548,13 @@ __metadata:
45104548
languageName: node
45114549
linkType: hard
45124550

4551+
"yallist@npm:^5.0.0":
4552+
version: 5.0.0
4553+
resolution: "yallist@npm:5.0.0"
4554+
checksum: 10c0/a499c81ce6d4a1d260d4ea0f6d49ab4da09681e32c3f0472dee16667ed69d01dae63a3b81745a24bd78476ec4fcf856114cb4896ace738e01da34b2c42235416
4555+
languageName: node
4556+
linkType: hard
4557+
45134558
"yocto-queue@npm:^0.1.0":
45144559
version: 0.1.0
45154560
resolution: "yocto-queue@npm:0.1.0"

0 commit comments

Comments
 (0)