Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
package-manager-cache: false
node-version: '24.x' # max-mapper/extract-zip#154 and sass/embedded-host-node#457
node-version: 'lts/*'
check-latest: true
registry-url: 'https://registry.npmjs.org'

Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@
"@types/tar": "^7.0.87",
"@types/varint": "^6.0.1",
"@types/yargs": "^17.0.4",
"@types/yauzl": "^3.4.0",
"@typescript/native": "npm:typescript@^7.0.2",
"extract-zip": "^2.0.1",
"gts": "^7.0.0",
"jest": "^30.0.3",
"npm-run-all": "^4.1.5",
Expand All @@ -96,6 +96,7 @@
"ts-node": "^10.2.1",
"typescript": "npm:@typescript/typescript6@^6.0.2",
"yaml": "^2.2.1",
"yargs": "^17.2.1"
"yargs": "^17.2.1",
"yauzl": "^3.4.0"
}
}
8 changes: 4 additions & 4 deletions tool/prepare-optional-release.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import extractZip = require('extract-zip');
import {promises as fs} from 'fs';
import * as p from 'path';
import {extract as extractTar} from 'tar';
Expand Down Expand Up @@ -93,9 +92,10 @@ async function downloadRelease(options: {
options.outPath + '/' + options.repo + archiveExtension;
await fs.writeFile(zippedAssetPath, releaseAsset);
if (archiveExtension === '.zip') {
await extractZip(zippedAssetPath, {
dir: p.join(process.cwd(), options.outPath),
});
await utils.extractZip(
zippedAssetPath,
p.join(process.cwd(), options.outPath),
);
} else {
extractTar({
file: zippedAssetPath,
Expand Down
21 changes: 20 additions & 1 deletion tool/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
// MIT-style license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.

import {existsSync, promises as fs, lstatSync} from 'fs';
import {createWriteStream, existsSync, promises as fs, lstatSync} from 'fs';
import stream from 'stream';
import * as p from 'path';
import * as shell from 'shelljs';
import * as yauzl from 'yauzl';

shell.config.fatal = true;

Expand Down Expand Up @@ -87,3 +89,20 @@ async function tryRealpath(path: string): Promise<string | null> {
return null;
}
}

// Extract a zip file.
//
// Use this function only on trusted zip files.
export async function extractZip(source: string, dest: string): Promise<void> {
const zipfile = await yauzl.openPromise(source);
for await (const entry of zipfile.eachEntry()) {
if (entry.fileName.endsWith('/')) {
continue;
} else {
const file = p.join(dest, entry.fileName);
await fs.mkdir(p.dirname(file), {recursive: true});
const readStream = await zipfile.openReadStreamPromise(entry);
await stream.promises.pipeline(readStream, createWriteStream(file));
}
}
}
Loading