From 90e066fec12d60e91819e2e309be09f25d5b8209 Mon Sep 17 00:00:00 2001 From: Wojciech Maj Date: Wed, 17 Jul 2024 00:47:50 +0200 Subject: [PATCH] chore(deps): bump tar from 6.x to 7.x, selectively import required functions Changes from #532 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 corepack bundle size. Before update: dist\lib\corepack.cjs 927.6kb After update to tar@7: dist\lib\corepack.cjs 932.8kb After update to tar@7 + selective imports: dist\lib\corepack.cjs 924.0kb --- package.json | 3 +- sources/commands/InstallGlobal.ts | 8 +- sources/commands/Pack.ts | 4 +- sources/commands/deprecated/Hydrate.ts | 8 +- sources/commands/deprecated/Prepare.ts | 4 +- sources/corepackUtils.ts | 4 +- yarn.lock | 121 +++++++++++++++++-------- 7 files changed, 100 insertions(+), 52 deletions(-) diff --git a/package.json b/package.json index 5a44662ae..bf3f54eaa 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,6 @@ "@types/node": "^20.4.6", "@types/proxy-from-env": "^1", "@types/semver": "^7.1.0", - "@types/tar": "^6.0.0", "@types/which": "^3.0.0", "@yarnpkg/eslint-config": "^2.0.0", "@yarnpkg/fslib": "^3.0.0-rc.48", @@ -35,7 +34,7 @@ "proxy-from-env": "^1.1.0", "semver": "^7.5.2", "supports-color": "^9.0.0", - "tar": "^6.2.1", + "tar": "^7.4.0", "tsx": "^4.16.2", "typescript": "^5.3.3", "undici": "^6.19.2", diff --git a/sources/commands/InstallGlobal.ts b/sources/commands/InstallGlobal.ts index 13eefeb1b..8815bc471 100644 --- a/sources/commands/InstallGlobal.ts +++ b/sources/commands/InstallGlobal.ts @@ -77,11 +77,11 @@ export class InstallGlobalCommand extends BaseCommand { const installFolder = folderUtils.getInstallFolder(); const archiveEntries = new Map>(); - const {default: tar} = await import(`tar`); + const {list: tarT} = await import(`tar/list`); let hasShortEntries = false; - await tar.t({file: p, onentry: entry => { + await tarT({file: p, onentry: entry => { const segments = entry.path.split(/\//g); if (segments.length > 0 && segments[segments.length - 1] !== `.corepack`) return; @@ -100,6 +100,8 @@ export class InstallGlobalCommand extends BaseCommand { if (hasShortEntries || archiveEntries.size < 1) throw new UsageError(`Invalid archive format; did it get generated by 'corepack pack'?`); + const {extract: tarX} = await import(`tar/extract`); + for (const [name, references] of archiveEntries) { for (const reference of references) { if (!isSupportedPackageManager(name)) @@ -110,7 +112,7 @@ export class InstallGlobalCommand extends BaseCommand { // Recreate the folder in case it was deleted somewhere else: await fs.promises.mkdir(installFolder, {recursive: true}); - await tar.x({file: p, cwd: installFolder}, [`${name}/${reference}`]); + await tarX({file: p, cwd: installFolder}, [`${name}/${reference}`]); if (!this.cacheOnly) { await this.context.engine.activatePackageManager({name, reference}); diff --git a/sources/commands/Pack.ts b/sources/commands/Pack.ts index 6b40b90ba..d6771f196 100644 --- a/sources/commands/Pack.ts +++ b/sources/commands/Pack.ts @@ -62,11 +62,11 @@ export class PackCommand extends BaseCommand { this.context.stdout.write(`Packing the selected tools in ${path.basename(outputPath)}...\n`); } - const {default: tar} = await import(`tar`); + const {create: tarC} = await import(`tar/create`); // Recreate the folder in case it was deleted somewhere else: await mkdir(baseInstallFolder, {recursive: true}); - await tar.c({gzip: true, cwd: baseInstallFolder, file: path.resolve(outputPath)}, installLocations.map(location => { + await tarC({gzip: true, cwd: baseInstallFolder, file: path.resolve(outputPath)}, installLocations.map(location => { return path.relative(baseInstallFolder, location); })); diff --git a/sources/commands/deprecated/Hydrate.ts b/sources/commands/deprecated/Hydrate.ts index 2d7f1d23f..ed3e74a43 100644 --- a/sources/commands/deprecated/Hydrate.ts +++ b/sources/commands/deprecated/Hydrate.ts @@ -24,9 +24,9 @@ export class HydrateCommand extends Command { const archiveEntries = new Map>(); let hasShortEntries = false; - const {default: tar} = await import(`tar`); + const {list: tarT} = await import(`tar/list`); - await tar.t({file: fileName, onentry: entry => { + await tarT({file: fileName, onentry: entry => { const segments = entry.path.split(/\//g); if (segments.length < 3) { @@ -43,6 +43,8 @@ export class HydrateCommand extends Command { if (hasShortEntries || archiveEntries.size < 1) throw new UsageError(`Invalid archive format; did it get generated by 'corepack prepare'?`); + const {extract: tarX} = await import(`tar/extract`); + for (const [name, references] of archiveEntries) { for (const reference of references) { if (!isSupportedPackageManager(name)) @@ -56,7 +58,7 @@ export class HydrateCommand extends Command { // Recreate the folder in case it was deleted somewhere else: await mkdir(installFolder, {recursive: true}); - await tar.x({file: fileName, cwd: installFolder}, [`${name}/${reference}`]); + await tarX({file: fileName, cwd: installFolder}, [`${name}/${reference}`]); if (this.activate) { await this.context.engine.activatePackageManager({name, reference}); diff --git a/sources/commands/deprecated/Prepare.ts b/sources/commands/deprecated/Prepare.ts index fc1548ed7..7b1ddf240 100644 --- a/sources/commands/deprecated/Prepare.ts +++ b/sources/commands/deprecated/Prepare.ts @@ -83,10 +83,10 @@ export class PrepareCommand extends Command { if (!this.json) this.context.stdout.write(`Packing the selected tools in ${path.basename(outputPath)}...\n`); - const {default: tar} = await import(`tar`); + const {create: tarC} = await import(`tar/create`); // Recreate the folder in case it was deleted somewhere else: await mkdir(baseInstallFolder, {recursive: true}); - await tar.c({gzip: true, cwd: baseInstallFolder, file: path.resolve(outputPath)}, installLocations.map(location => { + await tarC({gzip: true, cwd: baseInstallFolder, file: path.resolve(outputPath)}, installLocations.map(location => { return path.relative(baseInstallFolder, location); })); diff --git a/sources/corepackUtils.ts b/sources/corepackUtils.ts index 49d51deaa..cf4675596 100644 --- a/sources/corepackUtils.ts +++ b/sources/corepackUtils.ts @@ -151,8 +151,8 @@ async function download(installTarget: string, url: string, algo: string, binPat let sendTo: any; if (ext === `.tgz`) { - const {default: tar} = await import(`tar`); - sendTo = tar.x({ + const {extract: tarX} = await import(`tar/extract`); + sendTo = tarX({ strip: 1, cwd: tmpFolder, filter: binPath ? path => { diff --git a/yarn.lock b/yarn.lock index 3ea340eda..5844a7a2a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -257,6 +257,15 @@ __metadata: languageName: node linkType: hard +"@isaacs/fs-minipass@npm:^4.0.0": + version: 4.0.1 + resolution: "@isaacs/fs-minipass@npm:4.0.1" + dependencies: + minipass: "npm:^7.0.4" + checksum: 10c0/c25b6dc1598790d5b55c0947a9b7d111cfa92594db5296c3b907e2f533c033666f692a3939eadac17b1c7c40d362d0b0635dc874cbfe3e70db7c2b07cc97a5d2 + languageName: node + linkType: hard + "@jridgewell/gen-mapping@npm:^0.3.5": version: 0.3.5 resolution: "@jridgewell/gen-mapping@npm:0.3.5" @@ -515,16 +524,6 @@ __metadata: languageName: node linkType: hard -"@types/tar@npm:^6.0.0": - version: 6.1.13 - resolution: "@types/tar@npm:6.1.13" - dependencies: - "@types/node": "npm:*" - minipass: "npm:^4.0.0" - checksum: 10c0/98cc72d444fa622049e86e457a64d859c6effd7c7518d36e7b40b4ab1e7aa9e2412cc868cbef396650485dae07d50d98f662e8a53bb45f4a70eb6c61f80a63c7 - languageName: node - linkType: hard - "@types/which@npm:^3.0.0": version: 3.0.4 resolution: "@types/which@npm:3.0.4" @@ -1152,6 +1151,13 @@ __metadata: languageName: node linkType: hard +"chownr@npm:^3.0.0": + version: 3.0.0 + resolution: "chownr@npm:3.0.0" + checksum: 10c0/43925b87700f7e3893296c8e9c56cc58f926411cce3a6e5898136daaf08f08b9a8eb76d37d3267e707d0dcc17aed2e2ebdf5848c0c3ce95cf910a919935c1b10 + languageName: node + linkType: hard + "clean-stack@npm:^2.0.0": version: 2.2.0 resolution: "clean-stack@npm:2.2.0" @@ -1219,7 +1225,6 @@ __metadata: "@types/node": "npm:^20.4.6" "@types/proxy-from-env": "npm:^1" "@types/semver": "npm:^7.1.0" - "@types/tar": "npm:^6.0.0" "@types/which": "npm:^3.0.0" "@yarnpkg/eslint-config": "npm:^2.0.0" "@yarnpkg/fslib": "npm:^3.0.0-rc.48" @@ -1232,7 +1237,7 @@ __metadata: proxy-from-env: "npm:^1.1.0" semver: "npm:^7.5.2" supports-color: "npm:^9.0.0" - tar: "npm:^6.2.1" + tar: "npm:^7.4.0" tsx: "npm:^4.16.2" typescript: "npm:^5.3.3" undici: "npm:^6.19.2" @@ -1286,19 +1291,7 @@ __metadata: languageName: node linkType: hard -"debug@npm:4, debug@npm:^4.1.1, debug@npm:^4.3.1, debug@npm:^4.3.2, debug@npm:^4.3.4": - version: 4.3.4 - resolution: "debug@npm:4.3.4" - dependencies: - ms: "npm:2.1.2" - peerDependenciesMeta: - supports-color: - optional: true - checksum: 10c0/cedbec45298dd5c501d01b92b119cd3faebe5438c3917ff11ae1bff86a6c722930ac9c8659792824013168ba6db7c4668225d845c633fbdafbbf902a6389f736 - languageName: node - linkType: hard - -"debug@npm:^4.3.5": +"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": version: 4.3.5 resolution: "debug@npm:4.3.5" dependencies: @@ -2115,18 +2108,19 @@ __metadata: languageName: node linkType: hard -"glob@npm:^10.2.2, glob@npm:^10.3.10": - version: 10.4.1 - resolution: "glob@npm:10.4.1" +"glob@npm:^10.2.2, glob@npm:^10.3.10, glob@npm:^10.3.7": + version: 10.4.5 + resolution: "glob@npm:10.4.5" dependencies: foreground-child: "npm:^3.1.0" jackspeak: "npm:^3.1.2" minimatch: "npm:^9.0.4" minipass: "npm:^7.1.2" + package-json-from-dist: "npm:^1.0.0" path-scurry: "npm:^1.11.1" bin: glob: dist/esm/bin.mjs - checksum: 10c0/77f2900ed98b9cc2a0e1901ee5e476d664dae3cd0f1b662b8bfd4ccf00d0edc31a11595807706a274ca10e1e251411bbf2e8e976c82bed0d879a9b89343ed379 + checksum: 10c0/19a9759ea77b8e3ca0a43c2f07ecddc2ad46216b786bb8f993c445aee80d345925a21e5280c7b7c6c59e860a0154b84e4b2b60321fea92cd3c56b4a7489f160e languageName: node linkType: hard @@ -2957,13 +2951,6 @@ __metadata: languageName: node linkType: hard -"minipass@npm:^4.0.0": - version: 4.2.8 - resolution: "minipass@npm:4.2.8" - checksum: 10c0/4ea76b030d97079f4429d6e8a8affd90baf1b6a1898977c8ccce4701c5a2ba2792e033abc6709373f25c2c4d4d95440d9d5e9464b46b7b76ca44d2ce26d939ce - languageName: node - linkType: hard - "minipass@npm:^5.0.0": version: 5.0.0 resolution: "minipass@npm:5.0.0" @@ -2971,7 +2958,7 @@ __metadata: languageName: node linkType: hard -"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": +"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": version: 7.1.2 resolution: "minipass@npm:7.1.2" checksum: 10c0/b0fd20bb9fb56e5fa9a8bfac539e8915ae07430a619e4b86ff71f5fc757ef3924b23b2c4230393af1eda647ed3d75739e4e0acb250a6b1eb277cf7f8fe449557 @@ -2988,6 +2975,16 @@ __metadata: languageName: node linkType: hard +"minizlib@npm:^3.0.1": + version: 3.0.1 + resolution: "minizlib@npm:3.0.1" + dependencies: + minipass: "npm:^7.0.4" + rimraf: "npm:^5.0.5" + checksum: 10c0/82f8bf70da8af656909a8ee299d7ed3b3372636749d29e105f97f20e88971be31f5ed7642f2e898f00283b68b701cc01307401cdc209b0efc5dd3818220e5093 + languageName: node + linkType: hard + "mkdirp-classic@npm:^0.5.2, mkdirp-classic@npm:^0.5.3": version: 0.5.3 resolution: "mkdirp-classic@npm:0.5.3" @@ -3004,6 +3001,15 @@ __metadata: languageName: node linkType: hard +"mkdirp@npm:^3.0.1": + version: 3.0.1 + resolution: "mkdirp@npm:3.0.1" + bin: + mkdirp: dist/cjs/src/bin.js + checksum: 10c0/9f2b975e9246351f5e3a40dcfac99fcd0baa31fbfab615fe059fb11e51f10e4803c63de1f384c54d656e4db31d000e4767e9ef076a22e12a641357602e31d57d + languageName: node + linkType: hard + "ms@npm:2.1.2": version: 2.1.2 resolution: "ms@npm:2.1.2" @@ -3227,6 +3233,13 @@ __metadata: languageName: node linkType: hard +"package-json-from-dist@npm:^1.0.0": + version: 1.0.0 + resolution: "package-json-from-dist@npm:1.0.0" + checksum: 10c0/e3ffaf6ac1040ab6082a658230c041ad14e72fabe99076a2081bb1d5d41210f11872403fc09082daf4387fc0baa6577f96c9c0e94c90c394fd57794b66aa4033 + languageName: node + linkType: hard + "parent-module@npm:^1.0.0": version: 1.0.1 resolution: "parent-module@npm:1.0.1" @@ -3553,6 +3566,17 @@ __metadata: languageName: node linkType: hard +"rimraf@npm:^5.0.5": + version: 5.0.9 + resolution: "rimraf@npm:5.0.9" + dependencies: + glob: "npm:^10.3.7" + bin: + rimraf: dist/esm/bin.mjs + checksum: 10c0/87374682492b9e64de9c6fcbf2c8f209c7a2cd0e9749b3732eef8a62c6f859a9ed996d46f662d9ad5dd38c2c469f8e88de56b6c509026070ee3f06369cac1bc8 + languageName: node + linkType: hard + "rollup@npm:^4.13.0": version: 4.18.1 resolution: "rollup@npm:4.18.1" @@ -4010,7 +4034,7 @@ __metadata: languageName: node linkType: hard -"tar@npm:^6.1.11, tar@npm:^6.1.2, tar@npm:^6.2.1": +"tar@npm:^6.1.11, tar@npm:^6.1.2": version: 6.2.1 resolution: "tar@npm:6.2.1" dependencies: @@ -4024,6 +4048,20 @@ __metadata: languageName: node linkType: hard +"tar@npm:^7.4.0": + version: 7.4.0 + resolution: "tar@npm:7.4.0" + dependencies: + "@isaacs/fs-minipass": "npm:^4.0.0" + chownr: "npm:^3.0.0" + minipass: "npm:^7.1.2" + minizlib: "npm:^3.0.1" + mkdirp: "npm:^3.0.1" + yallist: "npm:^5.0.0" + checksum: 10c0/f4bab85fd101585f2cececc41eb8706191052ab65cc33f1a798198e0c7905f41b06ae3d6731fb2b6084847c53bc1e2265b77e05a105c0c44afaf6cb7a08ddf14 + languageName: node + linkType: hard + "text-table@npm:^0.2.0": version: 0.2.0 resolution: "text-table@npm:0.2.0" @@ -4510,6 +4548,13 @@ __metadata: languageName: node linkType: hard +"yallist@npm:^5.0.0": + version: 5.0.0 + resolution: "yallist@npm:5.0.0" + checksum: 10c0/a499c81ce6d4a1d260d4ea0f6d49ab4da09681e32c3f0472dee16667ed69d01dae63a3b81745a24bd78476ec4fcf856114cb4896ace738e01da34b2c42235416 + languageName: node + linkType: hard + "yocto-queue@npm:^0.1.0": version: 0.1.0 resolution: "yocto-queue@npm:0.1.0"