Skip to content

Commit e4b5094

Browse files
authored
Replace archiver with tar-fs for MRT bundle creation (#274)
* Replace archiver with tar-fs for MRT bundle creation archiver depends on archiver-utils which pulls in the deprecated glob@10.5.0. Since we only use archiver for tar (not zip), replace it with tar-fs which has minimal dependencies (pump + tar-stream) and no glob dependency. Net removal of 171 packages. * Upgrade c8 from 10.x to 11.x to remove glob@10.5.0 from dev deps c8@11 uses test-exclude@8 which depends on glob@13 instead of the deprecated glob@10.5.0.
1 parent e763a35 commit e4b5094

5 files changed

Lines changed: 229 additions & 185 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@salesforce/b2c-tooling-sdk': patch
3+
---
4+
5+
Replace `archiver` with `tar-fs` for MRT bundle creation, removing deprecated `glob@10.5.0` from the production dependency tree

packages/b2c-tooling-sdk/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@
348348
"@oclif/prettier-config": "catalog:",
349349
"@oclif/test": "catalog:",
350350
"@salesforce/dev-config": "catalog:",
351-
"@types/archiver": "^7.0.0",
351+
"@types/tar-fs": "^2.0.4",
352352
"@types/chai": "catalog:",
353353
"@types/ejs": "^3.1.5",
354354
"@types/mocha": "catalog:",
@@ -384,7 +384,7 @@
384384
},
385385
"dependencies": {
386386
"applicationinsights": "2.9.8",
387-
"archiver": "7.0.1",
387+
"tar-fs": "3.1.2",
388388
"chokidar": "5.0.0",
389389
"cliui": "catalog:",
390390
"ejs": "3.1.10",

packages/b2c-tooling-sdk/src/operations/mrt/bundle.ts

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@ import {createWriteStream} from 'node:fs';
1515
import {readFile, stat, mkdtemp, rm} from 'node:fs/promises';
1616
import path from 'node:path';
1717
import os from 'node:os';
18-
import archiver from 'archiver';
18+
import tar from 'tar-fs';
1919
import {Minimatch} from 'minimatch';
2020
import {getLogger} from '../../logging/logger.js';
21-
import type {Stats} from 'node:fs';
2221

2322
/**
2423
* Default SSR parameters applied to all bundles.
@@ -210,26 +209,25 @@ export async function createBundle(options: CreateBundleOptions): Promise<Bundle
210209
// Create tar archive
211210
await new Promise<void>((resolve, reject) => {
212211
const output = createWriteStream(tarPath);
213-
const archive = archiver('tar');
214-
215-
archive.pipe(output);
216212

217213
// Prefix all files with {projectSlug}/bld/
218-
const newRoot = path.join(projectSlug, 'bld', '');
219-
220-
archive.directory(buildPath, false, (entry) => {
221-
const stats = entry.stats as Stats | undefined;
222-
if (stats?.isFile() && entry.name) {
223-
filesInArchive.push(entry.name);
224-
}
225-
entry.prefix = newRoot;
226-
return entry;
214+
const newRoot = path.join(projectSlug, 'bld');
215+
216+
const pack = tar.pack(buildPath, {
217+
map(header) {
218+
if (header.type === 'file') {
219+
filesInArchive.push(header.name);
220+
}
221+
header.name = path.join(newRoot, header.name);
222+
return header;
223+
},
227224
});
228225

229-
archive.on('error', reject);
226+
pack.on('error', reject);
227+
output.on('error', reject);
230228
output.on('finish', resolve);
231229

232-
archive.finalize();
230+
pack.pipe(output);
233231
});
234232

235233
logger.debug({fileCount: filesInArchive.length}, '[MRT] Archive created');

0 commit comments

Comments
 (0)