refactor: replace gulp-untar with custom untar implementation and update dependencies (#288081)

This commit is contained in:
João Moreno
2026-01-15 16:13:11 +01:00
committed by GitHub
parent 82352d9ab5
commit 1deca733b3
6 changed files with 177 additions and 184 deletions

View File

@@ -13,9 +13,8 @@ import { tmpdir } from 'os';
import { existsSync, mkdirSync, rmSync } from 'fs';
import * as task from './lib/task.ts';
import watcher from './lib/watch/index.ts';
import { debounce } from './lib/util.ts';
import { debounce, untar } from './lib/util.ts';
import { createReporter } from './lib/reporter.ts';
import untar from 'gulp-untar';
import gunzip from 'gulp-gunzip';
const root = 'cli';

View File

@@ -21,7 +21,7 @@ import vfs from 'vinyl-fs';
import packageJson from '../package.json' with { type: 'json' };
import flatmap from 'gulp-flatmap';
import gunzip from 'gulp-gunzip';
import untar from 'gulp-untar';
import { untar } from './lib/util.ts';
import File from 'vinyl';
import * as fs from 'fs';
import glob from 'glob';

View File

@@ -1,12 +0,0 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
declare module 'gulp-untar' {
import type { Transform } from 'stream';
function untar(): Transform;
export = untar;
}

View File

@@ -15,6 +15,8 @@ import through from 'through';
import sm from 'source-map';
import { pathToFileURL } from 'url';
import ternaryStream from 'ternary-stream';
import type { Transform } from 'stream';
import * as tar from 'tar';
const root = path.dirname(path.dirname(import.meta.dirname));
@@ -429,3 +431,39 @@ export class VinylStat implements fs.Stats {
isFIFO(): boolean { return false; }
isSocket(): boolean { return false; }
}
export function untar(): Transform {
return es.through(function (this: through.ThroughStream, f: VinylFile) {
if (!f.contents || !Buffer.isBuffer(f.contents)) {
this.emit('error', new Error('Expected file with Buffer contents'));
return;
}
const self = this;
const parser = new tar.Parser();
parser.on('entry', (entry: tar.ReadEntry) => {
if (entry.type === 'File') {
const chunks: Buffer[] = [];
entry.on('data', (chunk: Buffer) => chunks.push(chunk));
entry.on('end', () => {
const file = new VinylFile({
path: entry.path,
contents: Buffer.concat(chunks),
stat: new VinylStat({
mode: entry.mode,
mtime: entry.mtime,
size: entry.size
})
});
self.emit('data', file);
});
} else {
entry.resume();
}
});
parser.on('error', (err: Error) => self.emit('error', err));
parser.end(f.contents);
}) as Transform;
}