Skip to content

Commit

Permalink
chore(deps): bump tar from 6.x to 7.x, selectively import required fu…
Browse files Browse the repository at this point in the history
…nctions (#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.
  • Loading branch information
wojtekmaj committed Jul 18, 2024
1 parent 6019d7b commit 67463b2
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 52 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
8 changes: 5 additions & 3 deletions sources/commands/InstallGlobal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ export class InstallGlobalCommand extends BaseCommand {
const installFolder = folderUtils.getInstallFolder();

const archiveEntries = new Map<string, Set<string>>();
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;
Expand All @@ -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))
Expand All @@ -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});
Expand Down
4 changes: 2 additions & 2 deletions sources/commands/Pack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}));

Expand Down
8 changes: 5 additions & 3 deletions sources/commands/deprecated/Hydrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ export class HydrateCommand extends Command<Context> {
const archiveEntries = new Map<string, Set<string>>();
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) {
Expand All @@ -43,6 +43,8 @@ export class HydrateCommand extends Command<Context> {
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))
Expand All @@ -56,7 +58,7 @@ export class HydrateCommand extends Command<Context> {
// 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});
Expand Down
4 changes: 2 additions & 2 deletions sources/commands/deprecated/Prepare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ export class PrepareCommand extends Command<Context> {
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);
}));

Expand Down
4 changes: 2 additions & 2 deletions sources/corepackUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
121 changes: 83 additions & 38 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -2957,21 +2951,14 @@ __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"
checksum: 10c0/a91d8043f691796a8ac88df039da19933ef0f633e3d7f0d35dcd5373af49131cf2399bfc355f41515dc495e3990369c3858cd319e5c2722b4753c90bf3152462
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
Expand All @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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:
Expand All @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 67463b2

Please sign in to comment.