diff --git a/.yarn/versions/9438587d.yml b/.yarn/versions/9438587d.yml new file mode 100644 index 000000000000..1a6a0ec1b6de --- /dev/null +++ b/.yarn/versions/9438587d.yml @@ -0,0 +1,2 @@ +releases: + vscode-zipfs: patch diff --git a/packages/vscode-zipfs/README.md b/packages/vscode-zipfs/README.md index a0dcfefbb543..8256ad1f0952 100644 --- a/packages/vscode-zipfs/README.md +++ b/packages/vscode-zipfs/README.md @@ -1,6 +1,6 @@ # ZipFS -This extension adds support into VSCode to read files directly from zip archives. It's maintained as part of the Yarn toolchain. Using this extension together with the [Yarn SDK](https://yarnpkg.com/getting-started/editor-sdks) will allow you to seamlessly open & edit files from your cache. +This extension adds support into VSCode to read files directly from zip archives and common ZIP-based package formats, including JAR, WAR, APK, IPA, and CRX files. It's maintained as part of the Yarn toolchain. Using this extension together with the [Yarn SDK](https://yarnpkg.com/getting-started/editor-sdks) will allow you to seamlessly open & edit files from your cache. ## New protocol: `zip:` diff --git a/packages/vscode-zipfs/package.json b/packages/vscode-zipfs/package.json index 98ca6db536e3..f51c55a1ddb1 100644 --- a/packages/vscode-zipfs/package.json +++ b/packages/vscode-zipfs/package.json @@ -37,7 +37,13 @@ "ZIP" ], "extensions": [ - ".zip" + ".zip", + ".jar", + ".war", + ".apk", + ".ipa", + ".crx", + ".3mf" ] } ], diff --git a/packages/vscode-zipfs/sources/ZipFSProvider.ts b/packages/vscode-zipfs/sources/ZipFSProvider.ts index 001bd97c24ff..66ec07ccc202 100644 --- a/packages/vscode-zipfs/sources/ZipFSProvider.ts +++ b/packages/vscode-zipfs/sources/ZipFSProvider.ts @@ -1,11 +1,14 @@ -import {VirtualFS, PosixFS, npath} from '@yarnpkg/fslib'; -import {ZipOpenFS} from '@yarnpkg/libzip'; -import * as vscode from 'vscode'; +import {VirtualFS, PosixFS} from '@yarnpkg/fslib'; +import {ZipOpenFS} from '@yarnpkg/libzip'; +import * as vscode from 'vscode'; + +import {isZipFile, ZIP_FILE_EXTENSIONS} from './zipFileExtensions'; export class ZipFSProvider implements vscode.FileSystemProvider { private readonly fs = new PosixFS( new VirtualFS({ baseFs: new ZipOpenFS({ + fileExtensions: ZIP_FILE_EXTENSIONS, useCache: true, maxOpenFiles: 80, }), @@ -17,7 +20,7 @@ export class ZipFSProvider implements vscode.FileSystemProvider { switch (true) { case stat.isDirectory(): - case npath.extname(uri.fsPath) === `.zip`: { + case isZipFile(uri.fsPath): { stat.type = vscode.FileType.Directory; } break; diff --git a/packages/vscode-zipfs/sources/zipFileExtensions.ts b/packages/vscode-zipfs/sources/zipFileExtensions.ts new file mode 100644 index 000000000000..e270fc0623d8 --- /dev/null +++ b/packages/vscode-zipfs/sources/zipFileExtensions.ts @@ -0,0 +1,15 @@ +import {npath} from '@yarnpkg/fslib'; + +export const ZIP_FILE_EXTENSIONS = [ + `.zip`, + `.jar`, + `.war`, + `.apk`, + `.ipa`, + `.crx`, + `.3mf`, +]; + +export function isZipFile(path: string): boolean { + return ZIP_FILE_EXTENSIONS.includes(npath.extname(path)); +} diff --git a/packages/vscode-zipfs/tests/zipFileExtensions.test.ts b/packages/vscode-zipfs/tests/zipFileExtensions.test.ts new file mode 100644 index 000000000000..624cd9f5d9a6 --- /dev/null +++ b/packages/vscode-zipfs/tests/zipFileExtensions.test.ts @@ -0,0 +1,21 @@ +import extensionManifest from '../package.json'; +import {isZipFile, ZIP_FILE_EXTENSIONS} from '../sources/zipFileExtensions'; + +describe(`ZipFS archive extensions`, () => { + it(`keeps the VS Code language registration in sync with the filesystem`, () => { + expect(extensionManifest.contributes.languages[0].extensions).toEqual(ZIP_FILE_EXTENSIONS); + }); + + it.each([ + [`archive.zip`, true], + [`application.jar`, true], + [`service.war`, true], + [`app.apk`, true], + [`application.ipa`, true], + [`extension.crx`, true], + [`model.3mf`, true], + [`archive.tar.gz`, false], + ])(`recognizes %s as %s`, (path, expected) => { + expect(isZipFile(path)).toBe(expected); + }); +});