@davidsouther/jiffies 1.0.0 → 1.1.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/build/assert.d.ts +23 -23
- package/build/assert.js +33 -33
- package/build/case.d.ts +1 -1
- package/build/case.js +5 -5
- package/build/components/button_bar.d.ts +8 -8
- package/build/components/button_bar.js +27 -27
- package/build/components/inline_edit.d.ts +12 -12
- package/build/components/inline_edit.js +48 -48
- package/build/components/logger.d.ts +6 -7
- package/build/components/logger.js +22 -22
- package/build/components/select.d.ts +13 -10
- package/build/components/select.js +3 -3
- package/build/components/test.d.ts +1 -1
- package/build/components/test.js +2 -2
- package/build/components/virtual_scroll.d.ts +40 -41
- package/build/components/virtual_scroll.js +94 -94
- package/build/components/virtual_scroll.test.d.ts +1 -1
- package/build/components/virtual_scroll.test.js +21 -21
- package/build/context.d.ts +15 -15
- package/build/context.js +43 -43
- package/build/context.test.d.ts +1 -1
- package/build/context.test.js +46 -46
- package/build/debounce.d.ts +1 -1
- package/build/debounce.js +7 -7
- package/build/display.d.ts +5 -5
- package/build/display.js +11 -11
- package/build/dom/css/border.d.ts +11 -11
- package/build/dom/css/border.js +27 -27
- package/build/dom/css/constants.d.ts +31 -31
- package/build/dom/css/constants.js +28 -28
- package/build/dom/css/core.d.ts +5 -5
- package/build/dom/css/core.js +24 -24
- package/build/dom/css/fstyle.d.ts +5 -5
- package/build/dom/css/fstyle.js +32 -32
- package/build/dom/css/sizing.d.ts +5 -5
- package/build/dom/css/sizing.js +10 -10
- package/build/dom/dom.d.ts +26 -27
- package/build/dom/dom.js +95 -95
- package/build/dom/fc.d.ts +14 -14
- package/build/dom/fc.js +36 -35
- package/build/dom/fc.test.d.ts +1 -1
- package/build/dom/fc.test.js +21 -21
- package/build/dom/form/form.app.d.ts +1 -1
- package/build/dom/form/form.app.js +23 -23
- package/build/dom/form/form.d.ts +26 -26
- package/build/dom/form/form.js +34 -34
- package/build/dom/form/form.test.js +1 -1
- package/build/dom/html.d.ts +113 -117
- package/build/dom/html.js +114 -114
- package/build/dom/html.test.d.ts +1 -1
- package/build/dom/html.test.js +58 -58
- package/build/dom/provide.d.ts +3 -3
- package/build/dom/provide.js +7 -7
- package/build/dom/router/link.d.ts +6 -6
- package/build/dom/router/link.js +3 -3
- package/build/dom/router/router.d.ts +12 -12
- package/build/dom/router/router.js +49 -49
- package/build/dom/svg.d.ts +64 -64
- package/build/dom/svg.js +65 -65
- package/build/dom/test.d.ts +1 -1
- package/build/dom/test.js +2 -2
- package/build/dom/types/css.d.ts +6612 -6612
- package/build/dom/types/css.js +23 -23
- package/build/dom/types/dom.js +1 -1
- package/build/dom/types/html.d.ts +616 -616
- package/build/dom/types/html.js +1 -1
- package/build/dom/xml.d.ts +1 -1
- package/build/dom/xml.js +4 -5
- package/build/equal.d.ts +5 -5
- package/build/equal.js +37 -37
- package/build/equal.test.d.ts +1 -1
- package/build/equal.test.js +20 -20
- package/build/flags.d.ts +7 -7
- package/build/flags.js +48 -48
- package/build/flags.test.d.ts +1 -1
- package/build/flags.test.js +35 -35
- package/build/fs.d.ts +48 -48
- package/build/fs.js +144 -144
- package/build/fs.test.d.ts +1 -1
- package/build/fs.test.js +43 -43
- package/build/generator.d.ts +1 -1
- package/build/generator.js +10 -10
- package/build/generator.test.d.ts +1 -1
- package/build/generator.test.js +24 -24
- package/build/is_browser.d.ts +1 -1
- package/build/is_browser.js +1 -1
- package/build/loader.d.mts +22 -22
- package/build/loader.mjs +35 -35
- package/build/lock.d.ts +1 -1
- package/build/lock.js +23 -23
- package/build/lock.test.d.ts +1 -1
- package/build/lock.test.js +16 -16
- package/build/log.d.ts +26 -26
- package/build/log.js +46 -46
- package/build/observable/observable.d.ts +83 -0
- package/build/observable/observable.js +148 -0
- package/build/observable/observable.test.d.ts +1 -0
- package/build/observable/observable.test.js +21 -0
- package/build/range.d.ts +1 -1
- package/build/range.js +7 -7
- package/build/result.d.ts +31 -31
- package/build/result.js +65 -65
- package/build/result.test.d.ts +1 -1
- package/build/result.test.js +71 -71
- package/build/safe.d.ts +1 -1
- package/build/safe.js +10 -10
- package/build/scope/describe.d.ts +18 -14
- package/build/scope/describe.js +61 -52
- package/build/scope/display/console.d.ts +2 -2
- package/build/scope/display/console.js +21 -21
- package/build/scope/display/dom.d.ts +3 -3
- package/build/scope/display/dom.js +26 -26
- package/build/scope/display/junit.d.ts +2 -2
- package/build/scope/display/junit.js +17 -17
- package/build/scope/execute.d.ts +12 -12
- package/build/scope/execute.js +85 -85
- package/build/scope/expect.d.ts +23 -23
- package/build/scope/expect.js +108 -108
- package/build/scope/fix.d.ts +4 -4
- package/build/scope/fix.js +22 -22
- package/build/scope/index.d.ts +3 -3
- package/build/scope/index.js +3 -3
- package/build/scope/scope.d.ts +17 -17
- package/build/scope/scope.js +1 -1
- package/build/server/http/apps.d.ts +5 -5
- package/build/server/http/apps.js +23 -23
- package/build/server/http/css.d.ts +5 -5
- package/build/server/http/css.js +50 -47
- package/build/server/http/index.d.ts +21 -21
- package/build/server/http/index.js +73 -73
- package/build/server/http/response.d.ts +4 -4
- package/build/server/http/response.js +40 -40
- package/build/server/http/sitemap.d.ts +2 -2
- package/build/server/http/sitemap.js +42 -42
- package/build/server/http/static.d.ts +2 -2
- package/build/server/http/static.js +21 -21
- package/build/server/http/typescript.d.ts +5 -5
- package/build/server/http/typescript.js +40 -40
- package/build/server/main.d.ts +2 -2
- package/build/server/main.js +9 -9
- package/build/test.d.mts +2 -2
- package/build/test.mjs +23 -23
- package/build/test_all.d.ts +7 -7
- package/build/test_all.js +18 -18
- package/build/transpile.d.mts +3 -3
- package/build/transpile.mjs +18 -18
- package/package.json +3 -3
- package/src/components/logger.ts +2 -3
- package/src/components/virtual_scroll.test.ts +4 -4
- package/src/components/virtual_scroll.ts +8 -8
- package/src/diff.test.ts +48 -0
- package/src/diff.ts +84 -0
- package/src/dom/dom.ts +73 -61
- package/src/dom/fc.ts +10 -9
- package/src/dom/html.test.ts +5 -5
- package/src/dom/html.ts +7 -10
- package/src/dom/observable.test.ts +43 -0
- package/src/dom/observable.ts +11 -0
- package/src/dom/router/router.ts +4 -4
- package/src/dom/test.ts +5 -1
- package/src/dom/xml.ts +1 -2
- package/src/index.html +6 -3
- package/src/observable/_notes +21 -8
- package/src/observable/event.ts +93 -0
- package/src/observable/observable.test.ts +73 -0
- package/src/observable/observable.ts +403 -0
- package/src/scope/describe.ts +14 -1
- package/src/scope/display/dom.ts +2 -2
- package/src/scope/execute.ts +2 -5
- package/src/server/http/css.ts +3 -1
- package/src/test_all.ts +10 -8
- package/src/observable/observable._js +0 -175
package/build/fs.js
CHANGED
|
@@ -1,144 +1,144 @@
|
|
|
1
|
-
function join(...paths) {
|
|
2
|
-
const pathParts = [];
|
|
3
|
-
for (const path of paths) {
|
|
4
|
-
for (const part of path.split("/")) {
|
|
5
|
-
switch (part) {
|
|
6
|
-
case "":
|
|
7
|
-
case ".":
|
|
8
|
-
break;
|
|
9
|
-
case "..":
|
|
10
|
-
pathParts.pop();
|
|
11
|
-
break;
|
|
12
|
-
default:
|
|
13
|
-
pathParts.push(part);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
return "/" + pathParts.join("/");
|
|
18
|
-
}
|
|
19
|
-
export class FileSystem {
|
|
20
|
-
adapter;
|
|
21
|
-
wd = "/";
|
|
22
|
-
stack = [];
|
|
23
|
-
constructor(adapter = new ObjectFileSystemAdapter()) {
|
|
24
|
-
this.adapter = adapter;
|
|
25
|
-
}
|
|
26
|
-
cwd() {
|
|
27
|
-
return this.wd;
|
|
28
|
-
}
|
|
29
|
-
cd(dir) {
|
|
30
|
-
this.wd = this.p(dir);
|
|
31
|
-
}
|
|
32
|
-
pushd(dir) {
|
|
33
|
-
this.stack.push(this.wd);
|
|
34
|
-
this.cd(dir);
|
|
35
|
-
}
|
|
36
|
-
popd() {
|
|
37
|
-
if (this.stack.length > 0) {
|
|
38
|
-
this.wd = this.stack.pop();
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
stat(path) {
|
|
42
|
-
return this.adapter.stat(join(this.cwd(), path));
|
|
43
|
-
}
|
|
44
|
-
readdir(path) {
|
|
45
|
-
return this.adapter.readdir(this.p(path) + "/");
|
|
46
|
-
}
|
|
47
|
-
copyFile(from, to) {
|
|
48
|
-
return this.adapter.copyFile(this.p(from), this.p(to));
|
|
49
|
-
}
|
|
50
|
-
readFile(path) {
|
|
51
|
-
return this.adapter.readFile(this.p(path));
|
|
52
|
-
}
|
|
53
|
-
writeFile(path, contents) {
|
|
54
|
-
return this.adapter.writeFile(this.p(path), contents);
|
|
55
|
-
}
|
|
56
|
-
rm(path) {
|
|
57
|
-
return this.adapter.rm(this.p(path));
|
|
58
|
-
}
|
|
59
|
-
p(path) {
|
|
60
|
-
return path[0] == "/" ? path : join(this.cwd(), path);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
export class ObjectFileSystemAdapter {
|
|
64
|
-
fs;
|
|
65
|
-
constructor(fs = {}) {
|
|
66
|
-
this.fs = fs;
|
|
67
|
-
}
|
|
68
|
-
stat(path) {
|
|
69
|
-
return new Promise((resolve, reject) => {
|
|
70
|
-
if (this.fs[path] != null) {
|
|
71
|
-
resolve({
|
|
72
|
-
isDirectory() {
|
|
73
|
-
return false;
|
|
74
|
-
},
|
|
75
|
-
isFile() {
|
|
76
|
-
return true;
|
|
77
|
-
},
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
reject();
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
readdir(path) {
|
|
86
|
-
return new Promise((resolve) => {
|
|
87
|
-
let dir = [];
|
|
88
|
-
for (const filename of Object.keys(this.fs)) {
|
|
89
|
-
if (filename.startsWith(path)) {
|
|
90
|
-
const end = filename.indexOf("/", path.length + 1);
|
|
91
|
-
const basename = filename.substring(path.length, end == -1 ? undefined : end);
|
|
92
|
-
dir.push(basename);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
return resolve(dir);
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
copyFile(from, to) {
|
|
99
|
-
return new Promise((resolve) => {
|
|
100
|
-
this.fs[to] = this.fs[from];
|
|
101
|
-
resolve();
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
readFile(path) {
|
|
105
|
-
return new Promise((resolve, reject) => {
|
|
106
|
-
let file = this.fs[path];
|
|
107
|
-
if (file === undefined) {
|
|
108
|
-
reject();
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
resolve(file);
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
writeFile(path, contents) {
|
|
116
|
-
return new Promise((resolve) => {
|
|
117
|
-
this.fs[path] = contents;
|
|
118
|
-
resolve();
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
rm(path) {
|
|
122
|
-
return new Promise((resolve) => {
|
|
123
|
-
delete this.fs[path];
|
|
124
|
-
resolve();
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
export class LocalStorageFileSystemAdapter extends ObjectFileSystemAdapter {
|
|
129
|
-
constructor() {
|
|
130
|
-
super(window.localStorage);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
export async function reset(fs, tree) {
|
|
134
|
-
for (const [path, file] of Object.entries(tree)) {
|
|
135
|
-
if (typeof file == "string") {
|
|
136
|
-
await fs.writeFile(path, file);
|
|
137
|
-
}
|
|
138
|
-
else {
|
|
139
|
-
fs.cd(path);
|
|
140
|
-
await reset(fs, file);
|
|
141
|
-
fs.cd("..");
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}
|
|
1
|
+
function join(...paths) {
|
|
2
|
+
const pathParts = [];
|
|
3
|
+
for (const path of paths) {
|
|
4
|
+
for (const part of path.split("/")) {
|
|
5
|
+
switch (part) {
|
|
6
|
+
case "":
|
|
7
|
+
case ".":
|
|
8
|
+
break;
|
|
9
|
+
case "..":
|
|
10
|
+
pathParts.pop();
|
|
11
|
+
break;
|
|
12
|
+
default:
|
|
13
|
+
pathParts.push(part);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return "/" + pathParts.join("/");
|
|
18
|
+
}
|
|
19
|
+
export class FileSystem {
|
|
20
|
+
adapter;
|
|
21
|
+
wd = "/";
|
|
22
|
+
stack = [];
|
|
23
|
+
constructor(adapter = new ObjectFileSystemAdapter()) {
|
|
24
|
+
this.adapter = adapter;
|
|
25
|
+
}
|
|
26
|
+
cwd() {
|
|
27
|
+
return this.wd;
|
|
28
|
+
}
|
|
29
|
+
cd(dir) {
|
|
30
|
+
this.wd = this.p(dir);
|
|
31
|
+
}
|
|
32
|
+
pushd(dir) {
|
|
33
|
+
this.stack.push(this.wd);
|
|
34
|
+
this.cd(dir);
|
|
35
|
+
}
|
|
36
|
+
popd() {
|
|
37
|
+
if (this.stack.length > 0) {
|
|
38
|
+
this.wd = this.stack.pop();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
stat(path) {
|
|
42
|
+
return this.adapter.stat(join(this.cwd(), path));
|
|
43
|
+
}
|
|
44
|
+
readdir(path) {
|
|
45
|
+
return this.adapter.readdir(this.p(path) + "/");
|
|
46
|
+
}
|
|
47
|
+
copyFile(from, to) {
|
|
48
|
+
return this.adapter.copyFile(this.p(from), this.p(to));
|
|
49
|
+
}
|
|
50
|
+
readFile(path) {
|
|
51
|
+
return this.adapter.readFile(this.p(path));
|
|
52
|
+
}
|
|
53
|
+
writeFile(path, contents) {
|
|
54
|
+
return this.adapter.writeFile(this.p(path), contents);
|
|
55
|
+
}
|
|
56
|
+
rm(path) {
|
|
57
|
+
return this.adapter.rm(this.p(path));
|
|
58
|
+
}
|
|
59
|
+
p(path) {
|
|
60
|
+
return path[0] == "/" ? path : join(this.cwd(), path);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
export class ObjectFileSystemAdapter {
|
|
64
|
+
fs;
|
|
65
|
+
constructor(fs = {}) {
|
|
66
|
+
this.fs = fs;
|
|
67
|
+
}
|
|
68
|
+
stat(path) {
|
|
69
|
+
return new Promise((resolve, reject) => {
|
|
70
|
+
if (this.fs[path] != null) {
|
|
71
|
+
resolve({
|
|
72
|
+
isDirectory() {
|
|
73
|
+
return false;
|
|
74
|
+
},
|
|
75
|
+
isFile() {
|
|
76
|
+
return true;
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
reject();
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
readdir(path) {
|
|
86
|
+
return new Promise((resolve) => {
|
|
87
|
+
let dir = [];
|
|
88
|
+
for (const filename of Object.keys(this.fs)) {
|
|
89
|
+
if (filename.startsWith(path)) {
|
|
90
|
+
const end = filename.indexOf("/", path.length + 1);
|
|
91
|
+
const basename = filename.substring(path.length, end == -1 ? undefined : end);
|
|
92
|
+
dir.push(basename);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return resolve(dir);
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
copyFile(from, to) {
|
|
99
|
+
return new Promise((resolve) => {
|
|
100
|
+
this.fs[to] = this.fs[from];
|
|
101
|
+
resolve();
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
readFile(path) {
|
|
105
|
+
return new Promise((resolve, reject) => {
|
|
106
|
+
let file = this.fs[path];
|
|
107
|
+
if (file === undefined) {
|
|
108
|
+
reject();
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
resolve(file);
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
writeFile(path, contents) {
|
|
116
|
+
return new Promise((resolve) => {
|
|
117
|
+
this.fs[path] = contents;
|
|
118
|
+
resolve();
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
rm(path) {
|
|
122
|
+
return new Promise((resolve) => {
|
|
123
|
+
delete this.fs[path];
|
|
124
|
+
resolve();
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
export class LocalStorageFileSystemAdapter extends ObjectFileSystemAdapter {
|
|
129
|
+
constructor() {
|
|
130
|
+
super(window.localStorage);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
export async function reset(fs, tree) {
|
|
134
|
+
for (const [path, file] of Object.entries(tree)) {
|
|
135
|
+
if (typeof file == "string") {
|
|
136
|
+
await fs.writeFile(path, file);
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
fs.cd(path);
|
|
140
|
+
await reset(fs, file);
|
|
141
|
+
fs.cd("..");
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
package/build/fs.test.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
package/build/fs.test.js
CHANGED
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
import { FileSystem, ObjectFileSystemAdapter } from "./fs.js";
|
|
2
|
-
import { describe, it, expect } from "./scope/index.js";
|
|
3
|
-
describe("FileSystem", () => {
|
|
4
|
-
describe("Writing", () => {
|
|
5
|
-
it("Writes files", async () => {
|
|
6
|
-
const fsObj = {};
|
|
7
|
-
const fs = new FileSystem(new ObjectFileSystemAdapter(fsObj));
|
|
8
|
-
await fs.writeFile("hello", "world");
|
|
9
|
-
expect(fsObj).toEqual({ "/hello": "world" });
|
|
10
|
-
});
|
|
11
|
-
it("Writes deep files", async () => {
|
|
12
|
-
const fsObj = {};
|
|
13
|
-
const fs = new FileSystem(new ObjectFileSystemAdapter(fsObj));
|
|
14
|
-
await fs.writeFile("deep/hello", "world");
|
|
15
|
-
expect(fsObj).toEqual({ "/deep/hello": "world" });
|
|
16
|
-
});
|
|
17
|
-
it("Writes deep files from root", async () => {
|
|
18
|
-
const fsObj = {};
|
|
19
|
-
const fs = new FileSystem(new ObjectFileSystemAdapter(fsObj));
|
|
20
|
-
await fs.writeFile("/root/deep/hello", "world");
|
|
21
|
-
expect(fsObj).toEqual({ "/root/deep/hello": "world" });
|
|
22
|
-
});
|
|
23
|
-
it("Writes files after cd", async () => {
|
|
24
|
-
const fsObj = {};
|
|
25
|
-
const fs = new FileSystem(new ObjectFileSystemAdapter(fsObj));
|
|
26
|
-
await fs.cd("deep");
|
|
27
|
-
await fs.writeFile("hello", "world");
|
|
28
|
-
expect(fsObj).toEqual({ "/deep/hello": "world" });
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
describe("directory", () => {
|
|
32
|
-
it("returns directory listing", async () => {
|
|
33
|
-
const fsObj = {
|
|
34
|
-
"/deep/hello": "world",
|
|
35
|
-
"/deep/bonjour": "monde",
|
|
36
|
-
"/other/file": "text",
|
|
37
|
-
};
|
|
38
|
-
const fs = new FileSystem(new ObjectFileSystemAdapter(fsObj));
|
|
39
|
-
const dir = await fs.readdir("deep");
|
|
40
|
-
expect(dir.sort()).toEqual(["bonjour", "hello"]);
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
});
|
|
1
|
+
import { FileSystem, ObjectFileSystemAdapter } from "./fs.js";
|
|
2
|
+
import { describe, it, expect } from "./scope/index.js";
|
|
3
|
+
describe("FileSystem", () => {
|
|
4
|
+
describe("Writing", () => {
|
|
5
|
+
it("Writes files", async () => {
|
|
6
|
+
const fsObj = {};
|
|
7
|
+
const fs = new FileSystem(new ObjectFileSystemAdapter(fsObj));
|
|
8
|
+
await fs.writeFile("hello", "world");
|
|
9
|
+
expect(fsObj).toEqual({ "/hello": "world" });
|
|
10
|
+
});
|
|
11
|
+
it("Writes deep files", async () => {
|
|
12
|
+
const fsObj = {};
|
|
13
|
+
const fs = new FileSystem(new ObjectFileSystemAdapter(fsObj));
|
|
14
|
+
await fs.writeFile("deep/hello", "world");
|
|
15
|
+
expect(fsObj).toEqual({ "/deep/hello": "world" });
|
|
16
|
+
});
|
|
17
|
+
it("Writes deep files from root", async () => {
|
|
18
|
+
const fsObj = {};
|
|
19
|
+
const fs = new FileSystem(new ObjectFileSystemAdapter(fsObj));
|
|
20
|
+
await fs.writeFile("/root/deep/hello", "world");
|
|
21
|
+
expect(fsObj).toEqual({ "/root/deep/hello": "world" });
|
|
22
|
+
});
|
|
23
|
+
it("Writes files after cd", async () => {
|
|
24
|
+
const fsObj = {};
|
|
25
|
+
const fs = new FileSystem(new ObjectFileSystemAdapter(fsObj));
|
|
26
|
+
await fs.cd("deep");
|
|
27
|
+
await fs.writeFile("hello", "world");
|
|
28
|
+
expect(fsObj).toEqual({ "/deep/hello": "world" });
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
describe("directory", () => {
|
|
32
|
+
it("returns directory listing", async () => {
|
|
33
|
+
const fsObj = {
|
|
34
|
+
"/deep/hello": "world",
|
|
35
|
+
"/deep/bonjour": "monde",
|
|
36
|
+
"/other/file": "text",
|
|
37
|
+
};
|
|
38
|
+
const fs = new FileSystem(new ObjectFileSystemAdapter(fsObj));
|
|
39
|
+
const dir = await fs.readdir("deep");
|
|
40
|
+
expect(dir.sort()).toEqual(["bonjour", "hello"]);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
});
|
package/build/generator.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function takeWhile<T>(predicate: (t: T) => boolean, iterator: Iterable<T>): Generator<T, void, unknown>;
|
|
1
|
+
export declare function takeWhile<T>(predicate: (t: T) => boolean, iterator: Iterable<T>): Generator<T, void, unknown>;
|
package/build/generator.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export function* takeWhile(predicate, iterator) {
|
|
2
|
-
for (const x of iterator) {
|
|
3
|
-
if (predicate(x)) {
|
|
4
|
-
yield x;
|
|
5
|
-
}
|
|
6
|
-
else {
|
|
7
|
-
return;
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
}
|
|
1
|
+
export function* takeWhile(predicate, iterator) {
|
|
2
|
+
for (const x of iterator) {
|
|
3
|
+
if (predicate(x)) {
|
|
4
|
+
yield x;
|
|
5
|
+
}
|
|
6
|
+
else {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
package/build/generator.test.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import { takeWhile } from "./generator.js";
|
|
2
|
-
import { describe, it, expect } from "./scope/index.js";
|
|
3
|
-
describe("Generator", () => {
|
|
4
|
-
it("takes from a generator until a predicate", () => {
|
|
5
|
-
const generator = function* () {
|
|
6
|
-
let i = 1;
|
|
7
|
-
while (true) {
|
|
8
|
-
yield (i = i * 2);
|
|
9
|
-
}
|
|
10
|
-
};
|
|
11
|
-
const filter = () => {
|
|
12
|
-
let previousValue = 0;
|
|
13
|
-
return (n) => {
|
|
14
|
-
if (previousValue < 100) {
|
|
15
|
-
previousValue = n;
|
|
16
|
-
return true;
|
|
17
|
-
}
|
|
18
|
-
return false;
|
|
19
|
-
};
|
|
20
|
-
};
|
|
21
|
-
const values = [...takeWhile(filter(), generator())];
|
|
22
|
-
expect(values).toEqual([2, 4, 8, 16, 32, 64, 128]);
|
|
23
|
-
});
|
|
24
|
-
});
|
|
1
|
+
import { takeWhile } from "./generator.js";
|
|
2
|
+
import { describe, it, expect } from "./scope/index.js";
|
|
3
|
+
describe("Generator", () => {
|
|
4
|
+
it("takes from a generator until a predicate", () => {
|
|
5
|
+
const generator = function* () {
|
|
6
|
+
let i = 1;
|
|
7
|
+
while (true) {
|
|
8
|
+
yield (i = i * 2);
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
const filter = () => {
|
|
12
|
+
let previousValue = 0;
|
|
13
|
+
return (n) => {
|
|
14
|
+
if (previousValue < 100) {
|
|
15
|
+
previousValue = n;
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
return false;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
const values = [...takeWhile(filter(), generator())];
|
|
22
|
+
expect(values).toEqual([2, 4, 8, 16, 32, 64, 128]);
|
|
23
|
+
});
|
|
24
|
+
});
|
package/build/is_browser.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const IsBrowser: boolean;
|
|
1
|
+
export const IsBrowser: boolean;
|
package/build/is_browser.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const IsBrowser = typeof window !== "undefined";
|
|
1
|
+
export const IsBrowser = typeof window !== "undefined";
|
package/build/loader.d.mts
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
/** @returns {Promise<{url: string}>} */
|
|
2
|
-
export function resolve(specifier: string, context: {
|
|
3
|
-
parentURL?: string;
|
|
4
|
-
}, defaultResolve: (specifier: string, context: {
|
|
5
|
-
parentURL?: string;
|
|
6
|
-
}, defaultResolve: Function) => Promise<{
|
|
7
|
-
url: string;
|
|
8
|
-
}>): Promise<{
|
|
9
|
-
url: string;
|
|
10
|
-
}>;
|
|
11
|
-
/** @returns {Promise<{format: string, source: string}>} */
|
|
12
|
-
export function load(url: string, context: {
|
|
13
|
-
format?: string;
|
|
14
|
-
}, defaultLoad: (url: string, context: {
|
|
15
|
-
format?: string;
|
|
16
|
-
}, defaultLoad?: Function) => Promise<{
|
|
17
|
-
format: string;
|
|
18
|
-
source: string;
|
|
19
|
-
}>): Promise<{
|
|
20
|
-
format: string;
|
|
21
|
-
source: string;
|
|
22
|
-
}>;
|
|
1
|
+
/** @returns {Promise<{url: string}>} */
|
|
2
|
+
export function resolve(specifier: string, context: {
|
|
3
|
+
parentURL?: string;
|
|
4
|
+
}, defaultResolve: (specifier: string, context: {
|
|
5
|
+
parentURL?: string;
|
|
6
|
+
}, defaultResolve: Function) => Promise<{
|
|
7
|
+
url: string;
|
|
8
|
+
}>): Promise<{
|
|
9
|
+
url: string;
|
|
10
|
+
}>;
|
|
11
|
+
/** @returns {Promise<{format: string, source: string}>} */
|
|
12
|
+
export function load(url: string, context: {
|
|
13
|
+
format?: string;
|
|
14
|
+
}, defaultLoad: (url: string, context: {
|
|
15
|
+
format?: string;
|
|
16
|
+
}, defaultLoad?: Function) => Promise<{
|
|
17
|
+
format: string;
|
|
18
|
+
source: string;
|
|
19
|
+
}>): Promise<{
|
|
20
|
+
format: string;
|
|
21
|
+
source: string;
|
|
22
|
+
}>;
|
package/build/loader.mjs
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
import { stat } from "node:fs/promises";
|
|
2
|
-
import { cwd } from "node:process";
|
|
3
|
-
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
4
|
-
import { transpile } from "./transpile.mjs";
|
|
5
|
-
const baseURL = pathToFileURL(`${cwd()}/`).href;
|
|
6
|
-
/** @returns {Promise<{url: string}>} */
|
|
7
|
-
export async function resolve(
|
|
8
|
-
/** @type string */ specifier,
|
|
9
|
-
/** @type {{parentURL?: string}} */ context,
|
|
10
|
-
/** @type {(specifier: string, context: {parentURL?: string}, defaultResolve: Function) => Promise<{url: string}>} */ defaultResolve) {
|
|
11
|
-
const tsURL = new URL(specifier.replace(/js$/, "ts"), context.parentURL ?? baseURL);
|
|
12
|
-
const tsSpecifier = tsURL.href;
|
|
13
|
-
try {
|
|
14
|
-
const stats = await stat(fileURLToPath(tsURL));
|
|
15
|
-
if (stats.isFile()) {
|
|
16
|
-
return { url: tsSpecifier };
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
catch (e) {
|
|
20
|
-
// Do nothing
|
|
21
|
-
}
|
|
22
|
-
return defaultResolve(specifier, context, defaultResolve);
|
|
23
|
-
}
|
|
24
|
-
/** @returns {Promise<{format: string, source: string}>} */
|
|
25
|
-
export async function load(
|
|
26
|
-
/** @type string */ url,
|
|
27
|
-
/** @type {{format?: string}} */ context,
|
|
28
|
-
/** @type {(url: string, context: {format?: string}, defaultLoad?: Function) => Promise<{format: string, source: string}>} */ defaultLoad) {
|
|
29
|
-
return url.endsWith("ts")
|
|
30
|
-
? {
|
|
31
|
-
format: "module",
|
|
32
|
-
source: await transpile(url, async () => (await defaultLoad(url, { format: "module" })).source),
|
|
33
|
-
}
|
|
34
|
-
: defaultLoad(url, context, defaultLoad);
|
|
35
|
-
}
|
|
1
|
+
import { stat } from "node:fs/promises";
|
|
2
|
+
import { cwd } from "node:process";
|
|
3
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
4
|
+
import { transpile } from "./transpile.mjs";
|
|
5
|
+
const baseURL = pathToFileURL(`${cwd()}/`).href;
|
|
6
|
+
/** @returns {Promise<{url: string}>} */
|
|
7
|
+
export async function resolve(
|
|
8
|
+
/** @type string */ specifier,
|
|
9
|
+
/** @type {{parentURL?: string}} */ context,
|
|
10
|
+
/** @type {(specifier: string, context: {parentURL?: string}, defaultResolve: Function) => Promise<{url: string}>} */ defaultResolve) {
|
|
11
|
+
const tsURL = new URL(specifier.replace(/js$/, "ts"), context.parentURL ?? baseURL);
|
|
12
|
+
const tsSpecifier = tsURL.href;
|
|
13
|
+
try {
|
|
14
|
+
const stats = await stat(fileURLToPath(tsURL));
|
|
15
|
+
if (stats.isFile()) {
|
|
16
|
+
return { url: tsSpecifier };
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
catch (e) {
|
|
20
|
+
// Do nothing
|
|
21
|
+
}
|
|
22
|
+
return defaultResolve(specifier, context, defaultResolve);
|
|
23
|
+
}
|
|
24
|
+
/** @returns {Promise<{format: string, source: string}>} */
|
|
25
|
+
export async function load(
|
|
26
|
+
/** @type string */ url,
|
|
27
|
+
/** @type {{format?: string}} */ context,
|
|
28
|
+
/** @type {(url: string, context: {format?: string}, defaultLoad?: Function) => Promise<{format: string, source: string}>} */ defaultLoad) {
|
|
29
|
+
return url.endsWith("ts")
|
|
30
|
+
? {
|
|
31
|
+
format: "module",
|
|
32
|
+
source: await transpile(url, async () => (await defaultLoad(url, { format: "module" })).source),
|
|
33
|
+
}
|
|
34
|
+
: defaultLoad(url, context, defaultLoad);
|
|
35
|
+
}
|
package/build/lock.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function lock(fn: Function): Function;
|
|
1
|
+
export declare function lock(fn: Function): Function;
|
package/build/lock.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
const locks = new WeakSet();
|
|
2
|
-
export function lock(fn) {
|
|
3
|
-
return function (...args) {
|
|
4
|
-
let ret = null;
|
|
5
|
-
let ex = null;
|
|
6
|
-
if (!locks.has(fn)) {
|
|
7
|
-
locks.add(fn);
|
|
8
|
-
try {
|
|
9
|
-
ret = fn(...args);
|
|
10
|
-
}
|
|
11
|
-
catch (e) {
|
|
12
|
-
ex = e;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
locks.delete(fn);
|
|
16
|
-
if (ex !== null) {
|
|
17
|
-
throw ex;
|
|
18
|
-
}
|
|
19
|
-
else {
|
|
20
|
-
return ret;
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
}
|
|
1
|
+
const locks = new WeakSet();
|
|
2
|
+
export function lock(fn) {
|
|
3
|
+
return function (...args) {
|
|
4
|
+
let ret = null;
|
|
5
|
+
let ex = null;
|
|
6
|
+
if (!locks.has(fn)) {
|
|
7
|
+
locks.add(fn);
|
|
8
|
+
try {
|
|
9
|
+
ret = fn(...args);
|
|
10
|
+
}
|
|
11
|
+
catch (e) {
|
|
12
|
+
ex = e;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
locks.delete(fn);
|
|
16
|
+
if (ex !== null) {
|
|
17
|
+
throw ex;
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
return ret;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
}
|
package/build/lock.test.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|