Skip to content
Open
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: 2 additions & 0 deletions .yarn/versions/9438587d.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
releases:
vscode-zipfs: patch
2 changes: 1 addition & 1 deletion packages/vscode-zipfs/README.md
Original file line number Diff line number Diff line change
@@ -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:`

Expand Down
8 changes: 7 additions & 1 deletion packages/vscode-zipfs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@
"ZIP"
],
"extensions": [
".zip"
".zip",
".jar",
".war",
".apk",
".ipa",
".crx",
".3mf"
]
}
],
Expand Down
11 changes: 7 additions & 4 deletions packages/vscode-zipfs/sources/ZipFSProvider.ts
Original file line number Diff line number Diff line change
@@ -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,
}),
Expand All @@ -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;

Expand Down
15 changes: 15 additions & 0 deletions packages/vscode-zipfs/sources/zipFileExtensions.ts
Original file line number Diff line number Diff line change
@@ -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));
}
21 changes: 21 additions & 0 deletions packages/vscode-zipfs/tests/zipFileExtensions.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
Loading