@celljs/ta-workspace 4.8.0 → 4.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/README.zh-cn.md +2 -2
- package/package.json +13 -4
- package/web/index.js +913 -294
- package/web-src/browser-agent.ts +0 -440
- package/web-src/browser-common.tsx +0 -278
- package/web-src/browser-import.tsx +0 -126
- package/web-src/browser-webview.tsx +0 -270
- package/web-src/browser.tsx +0 -80
- package/web-src/common.tsx +0 -296
- package/web-src/editors.tsx +0 -471
- package/web-src/explorer.tsx +0 -717
- package/web-src/file-icon.tsx +0 -21
- package/web-src/host.ts +0 -121
- package/web-src/i18n.ts +0 -395
- package/web-src/index.tsx +0 -71
- package/web-src/open-files.tsx +0 -80
- package/web-src/preview.tsx +0 -132
- package/web-src/react.ts +0 -8
- package/web-src/scm.tsx +0 -388
- package/web-src/search.tsx +0 -485
- package/web-src/style.ts +0 -254
- package/web-src/terminal.tsx +0 -269
- package/web-src/util/browser-snapshot.spec.ts +0 -96
- package/web-src/util/browser-snapshot.ts +0 -225
- package/web-src/util/file-icon.spec.ts +0 -35
- package/web-src/util/file-icon.ts +0 -23
- package/web-src/util/git.ts +0 -203
- package/web-src/util/preview.spec.ts +0 -48
- package/web-src/util/preview.ts +0 -90
- package/web-src/util/search.spec.ts +0 -164
- package/web-src/util/search.ts +0 -274
- package/web-src/util/seti-font.ts +0 -6
- package/web-src/util/seti.ts +0 -761
- package/web-src/util/upload.spec.ts +0 -66
- package/web-src/util/upload.ts +0 -123
- package/web-src/util/workspace.spec.ts +0 -220
- package/web-src/util/workspace.ts +0 -396
- package/web-src/util/zip.spec.ts +0 -60
- package/web-src/util/zip.ts +0 -137
- package/web-src/workspace-client.ts +0 -221
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'bun:test';
|
|
2
|
-
import { UploadUtil } from './upload';
|
|
3
|
-
|
|
4
|
-
function fileEntry(name: string) {
|
|
5
|
-
return { name, isFile: true, isDirectory: false, file: (done: (file: File) => void) => done(new File([name], name)) };
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
function folderEntry(name: string, children: object[]) {
|
|
9
|
-
return {
|
|
10
|
-
name,
|
|
11
|
-
isFile: false,
|
|
12
|
-
isDirectory: true,
|
|
13
|
-
createReader: () => {
|
|
14
|
-
// In two batches, then an empty one, as browsers read a folder.
|
|
15
|
-
const batches = [children.slice(0, 1), children.slice(1), []];
|
|
16
|
-
return { readEntries: (done: (entries: object[]) => void) => done(batches.shift() ?? []) };
|
|
17
|
-
},
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function drop(entries: object[], files: File[] = []): Pick<DataTransfer, 'files' | 'items'> {
|
|
22
|
-
return {
|
|
23
|
-
files: files as unknown as FileList,
|
|
24
|
-
items: entries.map(entry => ({ kind: 'file', webkitGetAsEntry: () => entry })) as unknown as DataTransferItemList,
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
describe('UploadUtil', () => {
|
|
29
|
-
it('reads dropped folders through, with their empty folders', async () => {
|
|
30
|
-
const batch = await UploadUtil.fromDrop(
|
|
31
|
-
drop([folderEntry('app', [fileEntry('a.ts'), folderEntry('empty', []), folderEntry('src', [fileEntry('b.ts')])]), fileEntry('README.md')]),
|
|
32
|
-
);
|
|
33
|
-
expect(batch.files.map(file => file.path)).toEqual(['app/a.ts', 'app/src/b.ts', 'README.md']);
|
|
34
|
-
expect(batch.folders).toEqual(['app', 'app/empty', 'app/src']);
|
|
35
|
-
expect(UploadUtil.emptyFolders(batch)).toEqual(['app/empty']);
|
|
36
|
-
expect(UploadUtil.topNames(batch)).toEqual(['app', 'README.md']);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it('takes the files of a drop without entries, and those of a folder picker with their paths', async () => {
|
|
40
|
-
const file = new File(['x'], 'x.txt');
|
|
41
|
-
expect(await UploadUtil.fromDrop(drop([], [file]))).toEqual({ files: [{ path: 'x.txt', file }], folders: [] });
|
|
42
|
-
const picked = new File(['y'], 'y.txt');
|
|
43
|
-
Object.defineProperty(picked, 'webkitRelativePath', { value: 'app/src/y.txt' });
|
|
44
|
-
expect(UploadUtil.fromFiles([picked]).files[0].path).toBe('app/src/y.txt');
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('turns away paths that leave the folder', () => {
|
|
48
|
-
expect(() => UploadUtil.segments('../etc/passwd')).toThrow('Not a path');
|
|
49
|
-
expect(() => UploadUtil.segments('')).toThrow('Not a path');
|
|
50
|
-
expect(UploadUtil.segments('a\\b/./c')).toEqual(['a', 'b', 'c']);
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it('cuts a file into parts, one empty part for an empty file', () => {
|
|
54
|
-
expect(UploadUtil.parts(10, 4)).toEqual([
|
|
55
|
-
[0, 4],
|
|
56
|
-
[4, 8],
|
|
57
|
-
[8, 10],
|
|
58
|
-
]);
|
|
59
|
-
expect(UploadUtil.parts(0, 4)).toEqual([[0, 0]]);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it('writes base64 of large buffers', () => {
|
|
63
|
-
const bytes = new Uint8Array(100000).map((_, i) => i % 256);
|
|
64
|
-
expect(UploadUtil.toBase64(bytes)).toBe(Buffer.from(bytes).toString('base64'));
|
|
65
|
-
});
|
|
66
|
-
});
|
package/web-src/util/upload.ts
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
/** A file to upload, at a path relative to the folder it goes to (`docs/a.md`). */
|
|
2
|
-
export interface UploadFile {
|
|
3
|
-
path: string;
|
|
4
|
-
file: Blob & { readonly name: string };
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
/** What a drop or a picker gives: files, and folders, as the empty ones a dropped folder holds. */
|
|
8
|
-
export interface UploadBatch {
|
|
9
|
-
files: UploadFile[];
|
|
10
|
-
folders: string[];
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/** An entry of a folder dropped from the system (the File System API of browsers, `webkitGetAsEntry`). */
|
|
14
|
-
interface DroppedEntry {
|
|
15
|
-
readonly name: string;
|
|
16
|
-
readonly isFile: boolean;
|
|
17
|
-
readonly isDirectory: boolean;
|
|
18
|
-
file?(success: (file: File) => void, failure?: (error: unknown) => void): void;
|
|
19
|
-
createReader?(): { readEntries(success: (entries: DroppedEntry[]) => void, failure?: (error: unknown) => void): void };
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/** Files of the user's machine to the files of a directory: what they are, read from a drop or a picker. */
|
|
23
|
-
export namespace UploadUtil {
|
|
24
|
-
/** The parts of a relative path; throws for one that would leave its folder. */
|
|
25
|
-
export function segments(path: string): string[] {
|
|
26
|
-
const parts = path.split(/[\\/]+/).filter(part => part && part !== '.');
|
|
27
|
-
if (!parts.length || parts.some(part => part === '..' || part.includes('\0'))) {
|
|
28
|
-
throw new Error(`Not a path to upload to: ${path}`);
|
|
29
|
-
}
|
|
30
|
-
return parts;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/** Files of `<input type="file">`; a folder picker gives each its path in it (`webkitRelativePath`). */
|
|
34
|
-
export function fromFiles(files: Iterable<File>): UploadBatch {
|
|
35
|
-
return { files: Array.from(files, file => ({ path: file.webkitRelativePath || file.name, file })), folders: [] };
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Files and folders dropped from the system, folders read through. The entries are taken before the first
|
|
40
|
-
* await: the browser empties the items of a drop once its event returns.
|
|
41
|
-
*/
|
|
42
|
-
export async function fromDrop(dataTransfer: Pick<DataTransfer, 'files' | 'items'>): Promise<UploadBatch> {
|
|
43
|
-
const entries = Array.from(dataTransfer.items ?? [])
|
|
44
|
-
.filter(item => item.kind === 'file')
|
|
45
|
-
.map(item => item.webkitGetAsEntry?.() as DroppedEntry | null | undefined);
|
|
46
|
-
if (!entries.length || entries.some(entry => !entry)) {
|
|
47
|
-
return fromFiles(Array.from(dataTransfer.files ?? []));
|
|
48
|
-
}
|
|
49
|
-
const batch: UploadBatch = { files: [], folders: [] };
|
|
50
|
-
for (const entry of entries as DroppedEntry[]) {
|
|
51
|
-
await collect(entry, '', batch);
|
|
52
|
-
}
|
|
53
|
-
return batch;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
async function collect(entry: DroppedEntry, folder: string, batch: UploadBatch): Promise<void> {
|
|
57
|
-
const path = folder ? `${folder}/${entry.name}` : entry.name;
|
|
58
|
-
if (entry.isFile && entry.file) {
|
|
59
|
-
const read = entry.file.bind(entry);
|
|
60
|
-
batch.files.push({ path, file: await new Promise<File>((resolve, reject) => read(resolve, reject)) });
|
|
61
|
-
} else if (entry.isDirectory && entry.createReader) {
|
|
62
|
-
batch.folders.push(path);
|
|
63
|
-
const reader = entry.createReader();
|
|
64
|
-
// A reader gives a folder in batches (about 100 entries), then an empty one.
|
|
65
|
-
for (;;) {
|
|
66
|
-
const children = await new Promise<DroppedEntry[]>((resolve, reject) => reader.readEntries(resolve, reject));
|
|
67
|
-
if (!children.length) {
|
|
68
|
-
break;
|
|
69
|
-
}
|
|
70
|
-
for (const child of children) {
|
|
71
|
-
await collect(child, path, batch);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/** The names the batch puts in the folder it goes to: what may already be there. */
|
|
78
|
-
export function topNames(batch: UploadBatch): string[] {
|
|
79
|
-
const names = new Set<string>();
|
|
80
|
-
for (const path of [...batch.files.map(file => file.path), ...batch.folders]) {
|
|
81
|
-
names.add(segments(path)[0]);
|
|
82
|
-
}
|
|
83
|
-
return [...names];
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/** The folders no file of the batch is in: uploading the files makes the others. */
|
|
87
|
-
export function emptyFolders(batch: UploadBatch): string[] {
|
|
88
|
-
const filled = new Set<string>();
|
|
89
|
-
for (const { path } of batch.files) {
|
|
90
|
-
const parts = segments(path);
|
|
91
|
-
for (let i = 1; i < parts.length; i++) {
|
|
92
|
-
filled.add(parts.slice(0, i).join('/'));
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
const folders = batch.folders.map(folder => segments(folder).join('/'));
|
|
96
|
-
return [...new Set(folders)].filter(folder => !filled.has(folder) && !folders.some(other => other.startsWith(`${folder}/`)));
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
export function totalBytes(batch: UploadBatch): number {
|
|
100
|
-
return batch.files.reduce((sum, { file }) => sum + file.size, 0);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/** The parts a file of `size` bytes is sent in, as [start, end) offsets; one empty part for an empty file. */
|
|
104
|
-
export function parts(size: number, partBytes: number): [number, number][] {
|
|
105
|
-
if (size === 0) {
|
|
106
|
-
return [[0, 0]];
|
|
107
|
-
}
|
|
108
|
-
const out: [number, number][] = [];
|
|
109
|
-
for (let start = 0; start < size; start += partBytes) {
|
|
110
|
-
out.push([start, Math.min(size, start + partBytes)]);
|
|
111
|
-
}
|
|
112
|
-
return out;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/** Bytes in base64, in pieces so that a large buffer does not overflow the arguments of a call. */
|
|
116
|
-
export function toBase64(bytes: Uint8Array): string {
|
|
117
|
-
let binary = '';
|
|
118
|
-
for (let i = 0; i < bytes.length; i += 0x8000) {
|
|
119
|
-
binary += String.fromCharCode(...bytes.subarray(i, i + 0x8000));
|
|
120
|
-
}
|
|
121
|
-
return btoa(binary);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'bun:test';
|
|
2
|
-
import type { TaDirEntry } from '@celljs/ta-protocol';
|
|
3
|
-
import { WorkspaceUtil } from './workspace';
|
|
4
|
-
|
|
5
|
-
const dir = (path: string): TaDirEntry => ({ name: WorkspaceUtil.basename(path), path, kind: 'directory' });
|
|
6
|
-
const file = (path: string): TaDirEntry => ({ name: WorkspaceUtil.basename(path), path, kind: 'file' });
|
|
7
|
-
|
|
8
|
-
describe('WorkspaceUtil', () => {
|
|
9
|
-
it('splits paths', () => {
|
|
10
|
-
expect(WorkspaceUtil.basename('src/a/b.ts')).toBe('b.ts');
|
|
11
|
-
expect(WorkspaceUtil.basename('/Users/me/project/')).toBe('project');
|
|
12
|
-
expect(WorkspaceUtil.dirname('src/a/b.ts')).toBe('src/a');
|
|
13
|
-
expect(WorkspaceUtil.dirname('b.ts')).toBe('');
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it('shows the tree as far as it is open and read', () => {
|
|
17
|
-
const children = new Map([
|
|
18
|
-
['', [dir('src'), file('README.md')]],
|
|
19
|
-
['src', [dir('src/lib'), file('src/a.ts')]],
|
|
20
|
-
]);
|
|
21
|
-
let expanded = new Set<string>();
|
|
22
|
-
expect(WorkspaceUtil.rows(children, expanded).map(row => row.entry.path)).toEqual(['src', 'README.md']);
|
|
23
|
-
expanded = WorkspaceUtil.toggle(expanded, 'src');
|
|
24
|
-
expanded = WorkspaceUtil.toggle(expanded, 'src/lib');
|
|
25
|
-
const rows = WorkspaceUtil.rows(children, expanded);
|
|
26
|
-
expect(rows.map(row => [row.entry.path, row.depth, row.expanded, row.loading])).toEqual([
|
|
27
|
-
['src', 0, true, false],
|
|
28
|
-
['src/lib', 1, true, true],
|
|
29
|
-
['src/a.ts', 1, false, false],
|
|
30
|
-
['README.md', 0, false, false],
|
|
31
|
-
]);
|
|
32
|
-
expect([...WorkspaceUtil.toggle(expanded, 'src')]).toEqual([]);
|
|
33
|
-
expect([...WorkspaceUtil.reveal(new Set(), 'a/b/c.ts')]).toEqual(['a', 'a/b']);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it('groups git changes', () => {
|
|
37
|
-
const rows = WorkspaceUtil.gitRows({
|
|
38
|
-
repository: true,
|
|
39
|
-
files: [
|
|
40
|
-
{ path: 'z.ts', unstaged: '?' },
|
|
41
|
-
{ path: 'b.ts', staged: 'M', unstaged: 'M' },
|
|
42
|
-
{ path: 'a.ts', staged: 'A' },
|
|
43
|
-
{ path: 'c.ts', staged: 'U', unstaged: 'U' },
|
|
44
|
-
],
|
|
45
|
-
});
|
|
46
|
-
expect(rows.map(row => `${row.group}:${row.letter}:${row.file.path}`)).toEqual([
|
|
47
|
-
'merge:!:c.ts',
|
|
48
|
-
'staged:A:a.ts',
|
|
49
|
-
'staged:M:b.ts',
|
|
50
|
-
'changes:M:b.ts',
|
|
51
|
-
'changes:U:z.ts',
|
|
52
|
-
]);
|
|
53
|
-
expect(WorkspaceUtil.gitColor('U')).toBe('var(--taw-git-added)');
|
|
54
|
-
expect(WorkspaceUtil.gitColor('D')).toBe('var(--taw-git-deleted)');
|
|
55
|
-
expect(WorkspaceUtil.gitColor(undefined)).toBeUndefined();
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it('groups matches by file and marks the match', () => {
|
|
59
|
-
const groups = WorkspaceUtil.groupMatches([
|
|
60
|
-
{ path: 'a', line: 1, column: 1, length: 1, preview: 'x', previewColumn: 0 },
|
|
61
|
-
{ path: 'b', line: 2, column: 1, length: 1, preview: 'y', previewColumn: 0 },
|
|
62
|
-
{ path: 'a', line: 3, column: 1, length: 1, preview: 'z', previewColumn: 0 },
|
|
63
|
-
]);
|
|
64
|
-
expect(groups.map(group => [group.path, group.matches.length])).toEqual([
|
|
65
|
-
['a', 2],
|
|
66
|
-
['b', 1],
|
|
67
|
-
]);
|
|
68
|
-
expect(WorkspaceUtil.highlight({ preview: 'const Needle = 1', previewColumn: 6, length: 6 })).toEqual(['const ', 'Needle', ' = 1']);
|
|
69
|
-
expect(WorkspaceUtil.highlight({ preview: 'a.b', previewColumn: 0, length: 3 })).toEqual(['', 'a.b', '']);
|
|
70
|
-
// A match far in a long line keeps a few words before it, from the start of a word.
|
|
71
|
-
const long = { preview: 'const first = "aaaa bbbb cccc dddd eeee ffff gggg"; needle();', previewColumn: 52, length: 6 };
|
|
72
|
-
const [before, found] = WorkspaceUtil.highlight(long);
|
|
73
|
-
expect(found).toBe('needle');
|
|
74
|
-
expect(before).toBe('… dddd eeee ffff gggg"; ');
|
|
75
|
-
expect(WorkspaceUtil.cutBefore('x'.repeat(40), 10)).toBe(`…${'x'.repeat(10)}`);
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it('puts paths in a tree of folders, a folder holding only a folder shown with it', () => {
|
|
79
|
-
const tree = WorkspaceUtil.pathTree(
|
|
80
|
-
['b.ts', 'packages/alipay/src/node/a.ts', 'packages/alipay/src/node/test/f.ts', 'src/z.ts', 'src/a.ts', 'packages/web/x.ts'],
|
|
81
|
-
path => path,
|
|
82
|
-
);
|
|
83
|
-
const show = (folder: typeof tree, depth = 0): string[] => [
|
|
84
|
-
...folder.folders.flatMap(inner => [`${' '.repeat(depth)}${inner.name}/ ${inner.size}`, ...show(inner, depth + 1)]),
|
|
85
|
-
...folder.items.map(item => `${' '.repeat(depth)}${WorkspaceUtil.basename(item)}`),
|
|
86
|
-
];
|
|
87
|
-
expect(show(tree)).toEqual([
|
|
88
|
-
'packages/ 3',
|
|
89
|
-
' alipay/src/node/ 2',
|
|
90
|
-
' test/ 1',
|
|
91
|
-
' f.ts',
|
|
92
|
-
' a.ts',
|
|
93
|
-
' web/ 1',
|
|
94
|
-
' x.ts',
|
|
95
|
-
'src/ 2',
|
|
96
|
-
' a.ts',
|
|
97
|
-
' z.ts',
|
|
98
|
-
'b.ts',
|
|
99
|
-
]);
|
|
100
|
-
expect(tree.folders[0].folders[0].path).toBe('packages/alipay/src/node');
|
|
101
|
-
expect(
|
|
102
|
-
WorkspaceUtil.pathTree(
|
|
103
|
-
['a/b.ts', 'a/c.ts'],
|
|
104
|
-
path => path,
|
|
105
|
-
() => 5,
|
|
106
|
-
).size,
|
|
107
|
-
).toBe(10);
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
it('checks the names typed in the explorer, as VS Code does', () => {
|
|
111
|
-
const siblings = ['src', 'README.md'];
|
|
112
|
-
expect(WorkspaceUtil.validateName('', siblings)).toMatchObject({ key: 'nameEmpty', severity: 'error' });
|
|
113
|
-
expect(WorkspaceUtil.validateName(' ', siblings)).toMatchObject({ key: 'nameEmpty' });
|
|
114
|
-
expect(WorkspaceUtil.validateName('/etc', siblings)).toMatchObject({ key: 'nameSlash' });
|
|
115
|
-
expect(WorkspaceUtil.validateName('a/../b', siblings)).toMatchObject({ key: 'nameInvalid' });
|
|
116
|
-
expect(WorkspaceUtil.validateName('readme.md', siblings)).toMatchObject({ key: 'nameExists' });
|
|
117
|
-
// A path makes the folders on its way, into one that is there.
|
|
118
|
-
expect(WorkspaceUtil.validateName('src/new.ts', siblings)).toBeUndefined();
|
|
119
|
-
expect(WorkspaceUtil.validateName(' a.ts', siblings)).toMatchObject({ key: 'nameWhitespace', severity: 'warning' });
|
|
120
|
-
expect(WorkspaceUtil.validateName('a.ts', siblings)).toBeUndefined();
|
|
121
|
-
expect(WorkspaceUtil.within('src/a.ts', 'src')).toBe(true);
|
|
122
|
-
expect(WorkspaceUtil.within('srcx/a.ts', 'src')).toBe(false);
|
|
123
|
-
expect(WorkspaceUtil.join('', 'a')).toBe('a');
|
|
124
|
-
expect(WorkspaceUtil.join('src', 'a')).toBe('src/a');
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
it('reads the address bar', () => {
|
|
128
|
-
expect(WorkspaceUtil.toUrl('localhost:3000/a')).toBe('http://localhost:3000/a');
|
|
129
|
-
expect(WorkspaceUtil.toUrl('127.0.0.1:8080')).toBe('http://127.0.0.1:8080');
|
|
130
|
-
expect(WorkspaceUtil.toUrl('example.com')).toBe('https://example.com');
|
|
131
|
-
expect(WorkspaceUtil.toUrl('https://x.dev')).toBe('https://x.dev');
|
|
132
|
-
expect(WorkspaceUtil.toUrl('react hooks')).toBe('https://www.bing.com/search?q=react%20hooks');
|
|
133
|
-
expect(WorkspaceUtil.toUrl(' ')).toBeUndefined();
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
it('writes sizes', () => {
|
|
137
|
-
expect(WorkspaceUtil.size(12)).toBe('12 B');
|
|
138
|
-
expect(WorkspaceUtil.size(1536)).toBe('1.5 KB');
|
|
139
|
-
expect(WorkspaceUtil.size(5 * 1024 * 1024)).toBe('5.0 MB');
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
describe('WorkspaceUtil links', () => {
|
|
144
|
-
it('makes the path of a link absolute', () => {
|
|
145
|
-
expect(WorkspaceUtil.absolute('/repo', 'src')).toBe('/repo/src');
|
|
146
|
-
expect(WorkspaceUtil.absolute('/repo/', '')).toBe('/repo/');
|
|
147
|
-
expect(WorkspaceUtil.absolute('/', 'etc')).toBe('/etc');
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
it('gives a page of the origin of Ta an origin of its own in the browser', () => {
|
|
151
|
-
expect(WorkspaceUtil.frameSandbox('https://x.dev/', 'http://localhost:4000')).toContain('allow-same-origin');
|
|
152
|
-
expect(WorkspaceUtil.frameSandbox('http://localhost:5173/', 'http://localhost:4000')).toContain('allow-same-origin');
|
|
153
|
-
expect(WorkspaceUtil.frameSandbox('http://localhost:4000/', 'http://localhost:4000')).not.toContain('allow-same-origin');
|
|
154
|
-
expect(WorkspaceUtil.frameSandbox('/api/x', 'http://localhost:4000')).not.toContain('allow-same-origin');
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
describe('WorkspaceUtil kept state', () => {
|
|
159
|
-
it('reads back the tabs kept, and leaves out what it cannot open', () => {
|
|
160
|
-
expect(
|
|
161
|
-
WorkspaceUtil.keptFiles([
|
|
162
|
-
{ kind: 'file', cwd: '/w', path: 'a.ts', extra: 1 },
|
|
163
|
-
{ kind: 'diff', cwd: '/w', path: 'b.ts', staged: true },
|
|
164
|
-
{ kind: 'diff', cwd: '/w', path: 'c.ts' },
|
|
165
|
-
{ kind: 'folder', cwd: '/w', path: 'd' },
|
|
166
|
-
{ kind: 'file', path: 'e.ts' },
|
|
167
|
-
null,
|
|
168
|
-
]),
|
|
169
|
-
).toEqual([
|
|
170
|
-
{ kind: 'file', cwd: '/w', path: 'a.ts' },
|
|
171
|
-
{ kind: 'diff', cwd: '/w', path: 'b.ts', staged: true },
|
|
172
|
-
{ kind: 'diff', cwd: '/w', path: 'c.ts', staged: false },
|
|
173
|
-
]);
|
|
174
|
-
expect(WorkspaceUtil.keptFiles({ files: [] })).toEqual([]);
|
|
175
|
-
expect(WorkspaceUtil.paths(['src', 1, 'src/a'])).toEqual(['src', 'src/a']);
|
|
176
|
-
expect(WorkspaceUtil.paths('src')).toEqual([]);
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
it('tells the port of a page of localhost, and moves it to another', () => {
|
|
180
|
-
expect(WorkspaceUtil.localPort('http://localhost:5173/app')).toBe(5173);
|
|
181
|
-
expect(WorkspaceUtil.localPort('http://127.0.0.1/')).toBe(80);
|
|
182
|
-
expect(WorkspaceUtil.localPort('http://[::1]:3000')).toBe(3000);
|
|
183
|
-
expect(WorkspaceUtil.localPort('https://example.com:3000')).toBeUndefined();
|
|
184
|
-
expect(WorkspaceUtil.localPort('not a url')).toBeUndefined();
|
|
185
|
-
expect(WorkspaceUtil.withPort('http://localhost:5173/app?x=1#y', 61000)).toBe('http://localhost:61000/app?x=1#y');
|
|
186
|
-
expect(WorkspaceUtil.withPort('http://0.0.0.0:8080/', 61001)).toBe('http://localhost:61001/');
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
it('shows a page of a forwarded port at the address asked for', () => {
|
|
190
|
-
const asked = 'http://localhost:3000/';
|
|
191
|
-
const shown = 'http://localhost:61000/';
|
|
192
|
-
expect(WorkspaceUtil.unforward('http://localhost:61000/app?x=1', asked, shown)).toBe('http://localhost:3000/app?x=1');
|
|
193
|
-
expect(WorkspaceUtil.unforward('https://github.com/login', asked, shown)).toBe('https://github.com/login');
|
|
194
|
-
expect(WorkspaceUtil.unforward('https://x.dev/a', 'https://x.dev/', 'https://x.dev/')).toBe('https://x.dev/a');
|
|
195
|
-
expect(WorkspaceUtil.unforward('http://localhost:3000/', asked, undefined)).toBe('http://localhost:3000/');
|
|
196
|
-
expect(WorkspaceUtil.unforward('about:blank', '', undefined)).toBe('about:blank');
|
|
197
|
-
});
|
|
198
|
-
it('moves what can move into a folder, and finds where it went', () => {
|
|
199
|
-
expect(WorkspaceUtil.movable(['src', 'README.md'], 'src/lib')).toEqual(['README.md']);
|
|
200
|
-
expect(WorkspaceUtil.movable(['src/a.ts'], 'src')).toEqual([]);
|
|
201
|
-
expect(WorkspaceUtil.movable(['src', 'src/a.ts', 'docs'], 'lib')).toEqual(['src', 'docs']);
|
|
202
|
-
expect(WorkspaceUtil.movable(['src'], 'srcs')).toEqual(['src']);
|
|
203
|
-
expect(WorkspaceUtil.movable(['docs/a.md'], '')).toEqual(['docs/a.md']);
|
|
204
|
-
expect(WorkspaceUtil.movedTo('src/lib/b.ts', ['src'], 'docs')).toBe('docs/src/lib/b.ts');
|
|
205
|
-
expect(WorkspaceUtil.movedTo('docs/a.md', ['docs/a.md'], '')).toBe('a.md');
|
|
206
|
-
expect(WorkspaceUtil.movedTo('other.ts', ['src'], 'docs')).toBeUndefined();
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
it('quotes paths for a shell', () => {
|
|
210
|
-
expect(WorkspaceUtil.shellQuote('/work/app/src/a.ts')).toBe('/work/app/src/a.ts');
|
|
211
|
-
expect(WorkspaceUtil.shellQuote("/work/my app/it's.md")).toBe("'/work/my app/it'\\''s.md'");
|
|
212
|
-
expect(WorkspaceUtil.shellQuote('C:\\work\\my app', true)).toBe('"C:\\work\\my app"');
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
it('names the file manager of each system', () => {
|
|
216
|
-
expect(WorkspaceUtil.fileManagerLabel('darwin')).toBe('revealInFinder');
|
|
217
|
-
expect(WorkspaceUtil.fileManagerLabel('win32')).toBe('revealInFileExplorer');
|
|
218
|
-
expect(WorkspaceUtil.fileManagerLabel('linux')).toBe('openContainingFolder');
|
|
219
|
-
});
|
|
220
|
-
});
|