@davidsouther/jiffies 2.2.5 → 2.3.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/LICENSE +1 -1
- package/lib/cjs/assert.d.ts +2 -2
- package/lib/cjs/awaitable.d.ts +1 -1
- package/lib/cjs/components/button_bar.d.ts +2 -2
- package/lib/cjs/components/inline_edit.d.ts +2 -2
- package/lib/cjs/components/logger.d.ts +1 -1
- package/lib/cjs/components/select.d.ts +4 -7
- package/lib/cjs/components/test.d.ts +1 -1
- package/lib/cjs/components/virtual_scroll.d.ts +6 -4
- package/lib/cjs/context.d.ts +5 -9
- package/lib/cjs/debounce.d.ts +1 -1
- package/lib/cjs/diff.d.ts +2 -2
- package/lib/cjs/display.d.ts +1 -1
- package/lib/cjs/dom/css/border.d.ts +2 -2
- package/lib/cjs/dom/css/constants.d.ts +3 -3
- package/lib/cjs/dom/css/core.d.ts +1 -1
- package/lib/cjs/dom/css/fstyle.d.ts +2 -2
- package/lib/cjs/dom/css/sizing.d.ts +2 -2
- package/lib/cjs/dom/dom.d.ts +8 -8
- package/lib/cjs/dom/fc.d.ts +8 -12
- package/lib/cjs/dom/form/form.d.ts +5 -6
- package/lib/cjs/dom/html.d.ts +112 -113
- package/lib/cjs/dom/observable.d.ts +1 -1
- package/lib/cjs/dom/provide.d.ts +1 -1
- package/lib/cjs/dom/router/router.d.ts +2 -2
- package/lib/cjs/dom/svg.d.ts +64 -64
- package/lib/cjs/dom/types/css.d.ts +10 -32
- package/lib/cjs/dom/types/html.d.ts +4 -6
- package/lib/cjs/equal.d.ts +8 -5
- package/lib/cjs/flags.d.ts +1 -1
- package/lib/cjs/fs.d.ts +3 -3
- package/lib/cjs/fs_node.d.ts +1 -1
- package/lib/cjs/lock.d.ts +1 -1
- package/lib/cjs/log.d.ts +7 -9
- package/lib/cjs/observable/event.d.ts +2 -2
- package/lib/cjs/observable/observable.d.ts +37 -35
- package/lib/cjs/result.d.ts +21 -21
- package/lib/cjs/safe.d.ts +1 -1
- package/lib/cjs/scope/describe.d.ts +4 -4
- package/lib/cjs/scope/display/console.d.ts +1 -1
- package/lib/cjs/scope/display/dom.d.ts +2 -2
- package/lib/cjs/scope/display/junit.d.ts +1 -1
- package/lib/cjs/scope/execute.d.ts +2 -2
- package/lib/cjs/scope/index.d.ts +3 -3
- package/lib/cjs/scope/scope.d.ts +3 -3
- package/lib/cjs/scope/state.d.ts +1 -1
- package/lib/cjs/server/http/apps.d.ts +1 -1
- package/lib/cjs/server/http/css.d.ts +1 -1
- package/lib/cjs/server/http/index.d.ts +4 -9
- package/lib/cjs/server/http/response.d.ts +3 -3
- package/lib/cjs/server/http/sitemap.d.ts +1 -1
- package/lib/cjs/server/http/static.d.ts +1 -1
- package/lib/cjs/server/http/typescript.d.ts +1 -1
- package/lib/cjs/test_all.d.ts +9 -9
- package/lib/cjs/tsconfig.tsbuildinfo +1 -1
- package/lib/esm/assert.d.ts +2 -2
- package/lib/esm/awaitable.d.ts +1 -1
- package/lib/esm/components/button_bar.d.ts +2 -2
- package/lib/esm/components/inline_edit.d.ts +2 -2
- package/lib/esm/components/logger.d.ts +1 -1
- package/lib/esm/components/select.d.ts +3 -3
- package/lib/esm/components/test.d.ts +1 -1
- package/lib/esm/components/virtual_scroll.d.ts +6 -4
- package/lib/esm/context.d.ts +5 -9
- package/lib/esm/debounce.d.ts +1 -2
- package/lib/esm/diff.d.ts +2 -2
- package/lib/esm/display.d.ts +1 -1
- package/lib/esm/dom/css/border.d.ts +2 -2
- package/lib/esm/dom/css/constants.d.ts +3 -3
- package/lib/esm/dom/css/core.d.ts +1 -1
- package/lib/esm/dom/css/fstyle.d.ts +2 -2
- package/lib/esm/dom/css/sizing.d.ts +2 -2
- package/lib/esm/dom/dom.d.ts +8 -8
- package/lib/esm/dom/fc.d.ts +8 -12
- package/lib/esm/dom/form/form.d.ts +5 -6
- package/lib/esm/dom/html.d.ts +112 -113
- package/lib/esm/dom/observable.d.ts +1 -1
- package/lib/esm/dom/provide.d.ts +1 -1
- package/lib/esm/dom/router/router.d.ts +2 -2
- package/lib/esm/dom/svg.d.ts +64 -64
- package/lib/esm/dom/types/css.d.ts +10 -32
- package/lib/esm/dom/types/html.d.ts +4 -6
- package/lib/esm/equal.d.ts +8 -5
- package/lib/esm/flags.d.ts +1 -1
- package/lib/esm/fs.d.ts +3 -3
- package/lib/esm/fs_node.d.ts +1 -1
- package/lib/esm/lock.d.ts +1 -1
- package/lib/esm/log.d.ts +7 -9
- package/lib/esm/observable/event.d.ts +2 -2
- package/lib/esm/observable/observable.d.ts +37 -35
- package/lib/esm/result.d.ts +21 -21
- package/lib/esm/safe.d.ts +1 -1
- package/lib/esm/scope/describe.d.ts +4 -4
- package/lib/esm/scope/display/console.d.ts +1 -1
- package/lib/esm/scope/display/dom.d.ts +2 -2
- package/lib/esm/scope/display/junit.d.ts +1 -1
- package/lib/esm/scope/execute.d.ts +2 -2
- package/lib/esm/scope/index.d.ts +3 -3
- package/lib/esm/scope/scope.d.ts +3 -3
- package/lib/esm/scope/state.d.ts +1 -1
- package/lib/esm/server/http/apps.d.ts +1 -1
- package/lib/esm/server/http/css.d.ts +1 -1
- package/lib/esm/server/http/index.d.ts +4 -9
- package/lib/esm/server/http/response.d.ts +3 -3
- package/lib/esm/server/http/sitemap.d.ts +1 -1
- package/lib/esm/server/http/static.d.ts +1 -1
- package/lib/esm/server/http/typescript.d.ts +1 -1
- package/lib/esm/test_all.d.ts +9 -9
- package/lib/esm/tsconfig.tsbuildinfo +1 -1
- package/package.json +11 -9
- package/src/assert.ts +5 -5
- package/src/components/button_bar.ts +28 -30
- package/src/components/inline_edit.ts +8 -7
- package/src/components/logger.ts +6 -6
- package/src/components/select.ts +7 -7
- package/src/components/test.ts +5 -0
- package/src/components/virtual_scroll.test.ts +9 -6
- package/src/components/virtual_scroll.ts +29 -24
- package/src/context.test.ts +4 -4
- package/src/context.ts +16 -11
- package/src/debounce.ts +9 -3
- package/src/diff.test.ts +4 -4
- package/src/diff.ts +14 -16
- package/src/dom/css/border.ts +11 -11
- package/src/dom/css/core.ts +1 -1
- package/src/dom/css/fstyle.ts +4 -4
- package/src/dom/css/sizing.ts +1 -1
- package/src/dom/dom.ts +57 -47
- package/src/dom/fc.test.ts +8 -8
- package/src/dom/fc.ts +32 -35
- package/src/dom/form/form.app.ts +9 -9
- package/src/dom/form/form.ts +25 -16
- package/src/dom/form/index.html +3 -2
- package/src/dom/html.test.ts +12 -10
- package/src/dom/html.ts +2 -3
- package/src/dom/observable.test.ts +6 -6
- package/src/dom/observable.ts +2 -2
- package/src/dom/provide.ts +1 -1
- package/src/dom/router/link.ts +3 -3
- package/src/dom/router/router.ts +5 -5
- package/src/dom/svg.ts +7 -6
- package/src/dom/test.ts +3 -0
- package/src/dom/types/css.ts +43 -61
- package/src/dom/types/html.ts +2 -4
- package/src/dom/xml.ts +2 -2
- package/src/equal.test.ts +3 -3
- package/src/equal.ts +27 -14
- package/src/flags.test.ts +2 -2
- package/src/flags.ts +2 -2
- package/src/fs.test.ts +5 -5
- package/src/fs.ts +26 -20
- package/src/fs_node.ts +4 -4
- package/src/fs_win.test.ts +1 -1
- package/src/generator.test.ts +4 -3
- package/src/generator.ts +1 -1
- package/src/hooks/_notes +4 -1
- package/src/index.html +7 -7
- package/src/lock.test.ts +4 -4
- package/src/lock.ts +8 -7
- package/src/log.ts +17 -18
- package/src/observable/event.ts +7 -7
- package/src/observable/observable.test.ts +3 -3
- package/src/observable/observable.ts +71 -52
- package/src/result.test.ts +7 -10
- package/src/result.ts +51 -47
- package/src/safe.ts +1 -1
- package/src/scope/describe.ts +12 -11
- package/src/scope/display/console.ts +4 -4
- package/src/scope/display/dom.ts +9 -9
- package/src/scope/display/junit.ts +21 -24
- package/src/scope/execute.ts +17 -12
- package/src/scope/expect.ts +22 -22
- package/src/scope/fix.ts +10 -7
- package/src/scope/index.ts +3 -3
- package/src/scope/scope.ts +2 -2
- package/src/scope/state.ts +2 -2
- package/src/server/http/apps.ts +5 -5
- package/src/server/http/css.ts +10 -26
- package/src/server/http/index.ts +30 -24
- package/src/server/http/response.ts +12 -5
- package/src/server/http/sitemap.ts +8 -8
- package/src/server/http/static.ts +9 -6
- package/src/server/http/typescript.ts +25 -25
- package/src/server/main.ts +7 -4
- package/src/test.mjs +8 -8
- package/src/test_all.ts +16 -13
- package/src/transpile.mjs +6 -18
- package/build/pico.css +0 -2466
- package/build/pico.css.map +0 -1
- package/lib/cjs/assert.js +0 -46
- package/lib/cjs/awaitable.js +0 -2
- package/lib/cjs/case.js +0 -9
- package/lib/cjs/components/button_bar.js +0 -29
- package/lib/cjs/components/inline_edit.js +0 -51
- package/lib/cjs/components/logger.js +0 -27
- package/lib/cjs/components/select.js +0 -6
- package/lib/cjs/components/test.js +0 -7
- package/lib/cjs/components/virtual_scroll.js +0 -102
- package/lib/cjs/components/virtual_scroll.test.js +0 -22
- package/lib/cjs/context.js +0 -48
- package/lib/cjs/context.test.js +0 -48
- package/lib/cjs/debounce.js +0 -12
- package/lib/cjs/diff.js +0 -58
- package/lib/cjs/diff.test.js +0 -41
- package/lib/cjs/display.js +0 -16
- package/lib/cjs/dom/css/border.js +0 -33
- package/lib/cjs/dom/css/constants.js +0 -31
- package/lib/cjs/dom/css/core.js +0 -31
- package/lib/cjs/dom/css/fstyle.js +0 -36
- package/lib/cjs/dom/css/sizing.js +0 -14
- package/lib/cjs/dom/dom.js +0 -110
- package/lib/cjs/dom/fc.js +0 -39
- package/lib/cjs/dom/fc.test.js +0 -23
- package/lib/cjs/dom/form/form.app.js +0 -27
- package/lib/cjs/dom/form/form.js +0 -49
- package/lib/cjs/dom/form/form.test.js +0 -1
- package/lib/cjs/dom/html.js +0 -119
- package/lib/cjs/dom/html.test.js +0 -60
- package/lib/cjs/dom/observable.js +0 -10
- package/lib/cjs/dom/observable.test.js +0 -35
- package/lib/cjs/dom/provide.js +0 -12
- package/lib/cjs/dom/router/link.js +0 -7
- package/lib/cjs/dom/router/router.js +0 -55
- package/lib/cjs/dom/svg.js +0 -69
- package/lib/cjs/dom/test.js +0 -13
- package/lib/cjs/dom/types/css.js +0 -24
- package/lib/cjs/dom/types/dom.js +0 -1
- package/lib/cjs/dom/types/html.js +0 -2
- package/lib/cjs/dom/xml.js +0 -8
- package/lib/cjs/equal.js +0 -48
- package/lib/cjs/equal.test.js +0 -22
- package/lib/cjs/flags.js +0 -52
- package/lib/cjs/flags.test.js +0 -37
- package/lib/cjs/fs.js +0 -235
- package/lib/cjs/fs.test.js +0 -86
- package/lib/cjs/fs_node.js +0 -50
- package/lib/cjs/fs_win.test.js +0 -10
- package/lib/cjs/generator.js +0 -14
- package/lib/cjs/generator.test.js +0 -26
- package/lib/cjs/is_browser.js +0 -4
- package/lib/cjs/loader-register.d.mts +0 -1
- package/lib/cjs/loader-register.d.ts +0 -1
- package/lib/cjs/loader-register.js +0 -4
- package/lib/cjs/loader-register.mjs +0 -4
- package/lib/cjs/loader.d.mts +0 -23
- package/lib/cjs/loader.mjs +0 -41
- package/lib/cjs/lock.js +0 -27
- package/lib/cjs/lock.test.js +0 -18
- package/lib/cjs/log.js +0 -103
- package/lib/cjs/observable/event.js +0 -61
- package/lib/cjs/observable/observable.js +0 -363
- package/lib/cjs/observable/observable.test.js +0 -65
- package/lib/cjs/package.json +0 -1
- package/lib/cjs/range.js +0 -11
- package/lib/cjs/result.js +0 -80
- package/lib/cjs/result.test.js +0 -78
- package/lib/cjs/safe.js +0 -14
- package/lib/cjs/scope/describe.js +0 -73
- package/lib/cjs/scope/display/console.js +0 -25
- package/lib/cjs/scope/display/dom.js +0 -30
- package/lib/cjs/scope/display/junit.js +0 -21
- package/lib/cjs/scope/execute.js +0 -91
- package/lib/cjs/scope/expect.js +0 -110
- package/lib/cjs/scope/fix.js +0 -26
- package/lib/cjs/scope/index.js +0 -15
- package/lib/cjs/scope/scope.js +0 -2
- package/lib/cjs/scope/state.js +0 -12
- package/lib/cjs/server/http/apps.js +0 -27
- package/lib/cjs/server/http/css.js +0 -54
- package/lib/cjs/server/http/index.js +0 -77
- package/lib/cjs/server/http/response.js +0 -45
- package/lib/cjs/server/http/sitemap.js +0 -46
- package/lib/cjs/server/http/static.js +0 -25
- package/lib/cjs/server/http/typescript.js +0 -44
- package/lib/cjs/server/main.js +0 -14
- package/lib/cjs/test.mjs +0 -28
- package/lib/cjs/test_all.js +0 -30
- package/lib/cjs/transpile.mjs +0 -22
- package/lib/esm/assert.js +0 -38
- package/lib/esm/awaitable.js +0 -1
- package/lib/esm/case.js +0 -5
- package/lib/esm/components/button_bar.js +0 -27
- package/lib/esm/components/inline_edit.js +0 -48
- package/lib/esm/components/logger.js +0 -22
- package/lib/esm/components/select.js +0 -3
- package/lib/esm/components/test.js +0 -3
- package/lib/esm/components/virtual_scroll.js +0 -94
- package/lib/esm/components/virtual_scroll.test.js +0 -20
- package/lib/esm/context.js +0 -43
- package/lib/esm/context.test.js +0 -46
- package/lib/esm/debounce.js +0 -8
- package/lib/esm/diff.js +0 -54
- package/lib/esm/diff.test.js +0 -39
- package/lib/esm/display.js +0 -11
- package/lib/esm/dom/css/border.js +0 -27
- package/lib/esm/dom/css/constants.js +0 -28
- package/lib/esm/dom/css/core.js +0 -24
- package/lib/esm/dom/css/fstyle.js +0 -32
- package/lib/esm/dom/css/sizing.js +0 -10
- package/lib/esm/dom/dom.js +0 -104
- package/lib/esm/dom/fc.js +0 -35
- package/lib/esm/dom/fc.test.js +0 -21
- package/lib/esm/dom/form/form.app.js +0 -23
- package/lib/esm/dom/form/form.js +0 -34
- package/lib/esm/dom/form/form.test.js +0 -1
- package/lib/esm/dom/html.js +0 -114
- package/lib/esm/dom/html.test.js +0 -58
- package/lib/esm/dom/observable.js +0 -6
- package/lib/esm/dom/observable.test.js +0 -33
- package/lib/esm/dom/provide.js +0 -7
- package/lib/esm/dom/router/link.js +0 -3
- package/lib/esm/dom/router/router.js +0 -52
- package/lib/esm/dom/svg.js +0 -65
- package/lib/esm/dom/test.js +0 -9
- package/lib/esm/dom/types/css.js +0 -23
- package/lib/esm/dom/types/dom.js +0 -1
- package/lib/esm/dom/types/html.js +0 -1
- package/lib/esm/dom/xml.js +0 -4
- package/lib/esm/equal.js +0 -41
- package/lib/esm/equal.test.js +0 -20
- package/lib/esm/flags.js +0 -48
- package/lib/esm/flags.test.js +0 -35
- package/lib/esm/fs.js +0 -226
- package/lib/esm/fs.test.js +0 -84
- package/lib/esm/fs_node.js +0 -45
- package/lib/esm/fs_win.test.js +0 -8
- package/lib/esm/generator.js +0 -10
- package/lib/esm/generator.test.js +0 -24
- package/lib/esm/is_browser.js +0 -1
- package/lib/esm/loader-register.d.mts +0 -1
- package/lib/esm/loader-register.mjs +0 -2
- package/lib/esm/loader.d.mts +0 -23
- package/lib/esm/loader.mjs +0 -36
- package/lib/esm/lock.js +0 -23
- package/lib/esm/lock.test.js +0 -16
- package/lib/esm/log.js +0 -93
- package/lib/esm/observable/event.js +0 -46
- package/lib/esm/observable/observable.js +0 -343
- package/lib/esm/observable/observable.test.js +0 -63
- package/lib/esm/range.js +0 -7
- package/lib/esm/result.js +0 -65
- package/lib/esm/result.test.js +0 -76
- package/lib/esm/safe.js +0 -10
- package/lib/esm/scope/describe.js +0 -60
- package/lib/esm/scope/display/console.js +0 -21
- package/lib/esm/scope/display/dom.js +0 -26
- package/lib/esm/scope/display/junit.js +0 -17
- package/lib/esm/scope/execute.js +0 -85
- package/lib/esm/scope/expect.js +0 -104
- package/lib/esm/scope/fix.js +0 -22
- package/lib/esm/scope/index.js +0 -3
- package/lib/esm/scope/scope.js +0 -1
- package/lib/esm/scope/state.js +0 -8
- package/lib/esm/server/http/apps.js +0 -23
- package/lib/esm/server/http/css.js +0 -50
- package/lib/esm/server/http/index.js +0 -73
- package/lib/esm/server/http/response.js +0 -40
- package/lib/esm/server/http/sitemap.js +0 -42
- package/lib/esm/server/http/static.js +0 -21
- package/lib/esm/server/http/typescript.js +0 -40
- package/lib/esm/server/main.js +0 -12
- package/lib/esm/test.mjs +0 -26
- package/lib/esm/test_all.js +0 -28
- package/lib/esm/transpile.mjs +0 -18
- package/src/components/test.js +0 -3
- package/src/loader-register.mjs +0 -3
- package/src/loader.mjs +0 -46
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { assert } from "../assert.js";
|
|
2
|
-
import { getLogger } from "../log.js";
|
|
3
|
-
import * as state from "./state.js";
|
|
4
|
-
export const beforeall = Symbol("beforeAll");
|
|
5
|
-
export const beforeeach = Symbol("beforeEach");
|
|
6
|
-
export const afterall = Symbol("afterAll");
|
|
7
|
-
export const aftereach = Symbol("afterEach");
|
|
8
|
-
const logger = getLogger("scope");
|
|
9
|
-
const CASES = {};
|
|
10
|
-
let cases = [CASES];
|
|
11
|
-
let totalCases = 0;
|
|
12
|
-
let skippedCases = 0;
|
|
13
|
-
function push(title) {
|
|
14
|
-
const next = (cases[0][title] = cases[0][title] ?? {});
|
|
15
|
-
cases.unshift(next);
|
|
16
|
-
}
|
|
17
|
-
function pop() {
|
|
18
|
-
cases.shift();
|
|
19
|
-
}
|
|
20
|
-
export function rootCases() {
|
|
21
|
-
return CASES;
|
|
22
|
-
}
|
|
23
|
-
export function getTotalCases() {
|
|
24
|
-
return totalCases;
|
|
25
|
-
}
|
|
26
|
-
export function getSkippedCases() {
|
|
27
|
-
return skippedCases;
|
|
28
|
-
}
|
|
29
|
-
export function describe(title, block) {
|
|
30
|
-
logger.debug(`describe(${title})`);
|
|
31
|
-
push(title);
|
|
32
|
-
block();
|
|
33
|
-
pop();
|
|
34
|
-
}
|
|
35
|
-
export function it(title, block) {
|
|
36
|
-
logger.debug(`it(${title})`);
|
|
37
|
-
assert(cases[0][title] == undefined, `Block already has test ${title}`);
|
|
38
|
-
totalCases += 1;
|
|
39
|
-
cases[0][title] = block;
|
|
40
|
-
}
|
|
41
|
-
it.skip = (title, _block) => {
|
|
42
|
-
logger.debug(`it.skip(${title})`);
|
|
43
|
-
totalCases += 1;
|
|
44
|
-
skippedCases += 1;
|
|
45
|
-
};
|
|
46
|
-
export function beforeEach(fn) {
|
|
47
|
-
cases[0][beforeeach] = fn;
|
|
48
|
-
}
|
|
49
|
-
export function beforeAll(fn) {
|
|
50
|
-
cases[0][beforeall] = fn;
|
|
51
|
-
}
|
|
52
|
-
export function afterEach(fn) {
|
|
53
|
-
cases[0][aftereach] = fn;
|
|
54
|
-
}
|
|
55
|
-
export function afterAll(fn) {
|
|
56
|
-
cases[0][afterall] = fn;
|
|
57
|
-
}
|
|
58
|
-
export function cleanState(init, runner = beforeEach) {
|
|
59
|
-
return state.cleanState(init, runner);
|
|
60
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { getLogger } from "../../log.js";
|
|
2
|
-
import { getTotalCases } from "../describe.js";
|
|
3
|
-
import { flattenResults } from "../execute.js";
|
|
4
|
-
const logger = getLogger("Scope Test Runner");
|
|
5
|
-
export function onConsole(results) {
|
|
6
|
-
const { executed, failed } = results;
|
|
7
|
-
logger.info("Executed test suite.", {
|
|
8
|
-
executed,
|
|
9
|
-
total: getTotalCases(),
|
|
10
|
-
failed,
|
|
11
|
-
});
|
|
12
|
-
const flat = flattenResults(results);
|
|
13
|
-
for (const { test } of flat) {
|
|
14
|
-
logger.debug(test);
|
|
15
|
-
}
|
|
16
|
-
for (const { test, stack } of flat) {
|
|
17
|
-
if (stack) {
|
|
18
|
-
logger.error(test, { stack });
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { isHTMLLogger, makeHTMLLogger } from "../../components/logger.js";
|
|
2
|
-
import { DEFAULT_LOGGER, LEVEL } from "../../log.js";
|
|
3
|
-
import { getTotalCases } from "../describe.js";
|
|
4
|
-
import { flattenResults } from "../execute.js";
|
|
5
|
-
export function displayStatistics(results, root = document.body) {
|
|
6
|
-
const { executed, failed } = results;
|
|
7
|
-
const logger = (() => {
|
|
8
|
-
try {
|
|
9
|
-
return makeHTMLLogger(`Executed ${executed} of ${getTotalCases()}; ${failed} failed.`);
|
|
10
|
-
}
|
|
11
|
-
catch (e) {
|
|
12
|
-
return DEFAULT_LOGGER;
|
|
13
|
-
}
|
|
14
|
-
})();
|
|
15
|
-
logger.level = LEVEL.DEBUG;
|
|
16
|
-
const flat = flattenResults(results);
|
|
17
|
-
for (const { test, stack } of flat) {
|
|
18
|
-
if (stack) {
|
|
19
|
-
logger.info(test);
|
|
20
|
-
logger.debug(`${stack}`);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
if (isHTMLLogger(logger)) {
|
|
24
|
-
root.appendChild(logger.root);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { xml } from "../../dom/xml.js";
|
|
2
|
-
import { flattenResults } from "../execute.js";
|
|
3
|
-
const cases = (results) => Object.entries(results).filter(([key]) => !["executed", "passed", "failed"].includes(key));
|
|
4
|
-
export function asXML(results) {
|
|
5
|
-
return (`<?xml version="1.0" encoding="UTF-8" ?>` +
|
|
6
|
-
xml("testsuites", { tests: results.executed, failures: results.failed }, cases(results).map(([title, children]) => testsuite(title, children.executed, children.failed, flattenResults(children)))));
|
|
7
|
-
}
|
|
8
|
-
function testsuite(name, tests, failures, cases) {
|
|
9
|
-
const id = name.replace("s+", "_");
|
|
10
|
-
return xml("testsuite", { id, name, tests, failures }, cases.map(({ test, stack }) => testcase({ name: `${name} ${test}` }, stack ? [stack] : [])));
|
|
11
|
-
}
|
|
12
|
-
function testcase({ name, id = name.replace(/\s+/g, "_"), time = "0.00", }, failures) {
|
|
13
|
-
return xml("testcase", { id, name, time }, failures.map((stack) => failure({ text: stack })));
|
|
14
|
-
}
|
|
15
|
-
function failure({ text, message = text.split("\n")[0], }) {
|
|
16
|
-
return xml("failure", { message }, [`<![CDATA[${text}]]>`]);
|
|
17
|
-
}
|
package/lib/esm/scope/execute.js
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { afterall, aftereach, beforeall, beforeeach, rootCases, } from "./describe.js";
|
|
2
|
-
export async function execute(cases = rootCases()) {
|
|
3
|
-
const beforeallfn = cases[beforeall] ?? (() => { });
|
|
4
|
-
const beforeeachfn = cases[beforeeach] ?? (() => { });
|
|
5
|
-
const afterallfn = cases[afterall] ?? (() => { });
|
|
6
|
-
const aftereachfn = cases[aftereach] ?? (() => { });
|
|
7
|
-
const result = { executed: 0, passed: 0, failed: 0, total: 0 };
|
|
8
|
-
try {
|
|
9
|
-
await beforeallfn();
|
|
10
|
-
}
|
|
11
|
-
catch (e) {
|
|
12
|
-
result["_beforeAll"] = { error: e };
|
|
13
|
-
return result;
|
|
14
|
-
}
|
|
15
|
-
for (const [title, block] of Object.entries(cases)) {
|
|
16
|
-
if (typeof title === "symbol") {
|
|
17
|
-
continue;
|
|
18
|
-
}
|
|
19
|
-
if (block instanceof Function) {
|
|
20
|
-
try {
|
|
21
|
-
result.executed += 1;
|
|
22
|
-
await beforeeachfn();
|
|
23
|
-
await block();
|
|
24
|
-
await aftereachfn();
|
|
25
|
-
result.passed += 1;
|
|
26
|
-
result[title] = { passed: true };
|
|
27
|
-
}
|
|
28
|
-
catch (e) {
|
|
29
|
-
result.failed += 1;
|
|
30
|
-
result[title] = { error: /** @type Error */ e };
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
else if (block) {
|
|
34
|
-
const run = await execute(block);
|
|
35
|
-
result.executed += run.executed;
|
|
36
|
-
result.passed += run.passed;
|
|
37
|
-
result.failed += run.failed;
|
|
38
|
-
result[title] = run;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
try {
|
|
42
|
-
await afterallfn();
|
|
43
|
-
}
|
|
44
|
-
catch (e) {
|
|
45
|
-
result["_afterAll"] = { error: e };
|
|
46
|
-
}
|
|
47
|
-
return result;
|
|
48
|
-
}
|
|
49
|
-
export function getError({ error }) {
|
|
50
|
-
if (typeof error == "string") {
|
|
51
|
-
return error;
|
|
52
|
-
}
|
|
53
|
-
else if (error.message) {
|
|
54
|
-
return error.stack;
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
return "unknown error";
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
function makeResult(test, result) {
|
|
61
|
-
if (result.error)
|
|
62
|
-
return [
|
|
63
|
-
{
|
|
64
|
-
test,
|
|
65
|
-
stack: getError(result),
|
|
66
|
-
stats: { executed: 1, failed: 1 },
|
|
67
|
-
},
|
|
68
|
-
];
|
|
69
|
-
if (result.passed === true) {
|
|
70
|
-
return [{ test, stats: { executed: 1, failed: 0 } }];
|
|
71
|
-
}
|
|
72
|
-
return flattenResults(result, test);
|
|
73
|
-
}
|
|
74
|
-
export function flattenResults(results, prefix = "") {
|
|
75
|
-
const arrow = prefix == "" ? "" : " -> ";
|
|
76
|
-
let errorList = [];
|
|
77
|
-
for (const [title, result] of Object.entries(results).filter(([key]) => !["executed", "passed", "failed"].includes(key))) {
|
|
78
|
-
const test = `${prefix}${arrow}${title}`;
|
|
79
|
-
if (typeof result == "number")
|
|
80
|
-
continue;
|
|
81
|
-
const flatResult = makeResult(test, result);
|
|
82
|
-
errorList = errorList.concat(flatResult);
|
|
83
|
-
}
|
|
84
|
-
return errorList;
|
|
85
|
-
}
|
package/lib/esm/scope/expect.js
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import { assert } from "../assert.js";
|
|
2
|
-
import { display } from "../display.js";
|
|
3
|
-
import { equals } from "../equal.js";
|
|
4
|
-
export class Matcher {
|
|
5
|
-
actual;
|
|
6
|
-
constructor(actual) {
|
|
7
|
-
this.actual = actual;
|
|
8
|
-
}
|
|
9
|
-
get not() {
|
|
10
|
-
return new NotMatcher(this.actual);
|
|
11
|
-
}
|
|
12
|
-
toBe(expected) {
|
|
13
|
-
assert(this.actual === expected, () => `${this.actual} !== ${expected}`);
|
|
14
|
-
}
|
|
15
|
-
toEqual(expected, partial = false) {
|
|
16
|
-
assert(equals(this.actual, expected, partial), () => `Objects are not equivalent: ${display(this.actual)}, ${display(expected)}`);
|
|
17
|
-
}
|
|
18
|
-
toMatch(expected) {
|
|
19
|
-
assert(typeof this.actual === "string", () => "Must have string for regexp match");
|
|
20
|
-
// @ts-expect-error
|
|
21
|
-
const actual = this.actual;
|
|
22
|
-
if (typeof expected === "string") {
|
|
23
|
-
assert(actual.includes(expected), () => `${actual} does not include ${expected}`);
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
assert(expected.test(actual), () => `${actual} does not match ${expected}`);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
toMatchObject(expected) {
|
|
30
|
-
for (const [k, v] of Object.entries(expected)) {
|
|
31
|
-
// @ts-expect-error
|
|
32
|
-
const actual = this.actual[k];
|
|
33
|
-
assert(equals(actual, v, true), () => `Comparing ${k}, properties not equal: ${display(actual)}, ${display(v)}`);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
toBeNull() {
|
|
37
|
-
assert(this.actual === null, () => `Expected null, got ${JSON.stringify(this.actual)}`);
|
|
38
|
-
}
|
|
39
|
-
toThrow(message = "") {
|
|
40
|
-
let didThrow = false;
|
|
41
|
-
let result = undefined;
|
|
42
|
-
try {
|
|
43
|
-
// @ts-expect-error
|
|
44
|
-
result = this.actual();
|
|
45
|
-
}
|
|
46
|
-
catch (e) {
|
|
47
|
-
assert((e.message ?? "").match(message) !== null, () => `Expected thrown message to match ${message}, got ${e}`);
|
|
48
|
-
didThrow = true;
|
|
49
|
-
}
|
|
50
|
-
assert(didThrow, () => `Expected throw but got ${JSON.stringify(result)}`);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
export class NotMatcher {
|
|
54
|
-
actual;
|
|
55
|
-
constructor(actual) {
|
|
56
|
-
this.actual = actual;
|
|
57
|
-
}
|
|
58
|
-
get not() {
|
|
59
|
-
return new Matcher(this.actual);
|
|
60
|
-
}
|
|
61
|
-
toBe(expected) {
|
|
62
|
-
assert(this.actual !== expected, () => `${this.actual} === ${expected}`);
|
|
63
|
-
}
|
|
64
|
-
toEqual(expected) {
|
|
65
|
-
assert(!equals(this.actual, expected), () => `Objects are equivalent: ${JSON.stringify(this.actual)}, ${JSON.stringify(expected)}`);
|
|
66
|
-
}
|
|
67
|
-
toMatch(expected) {
|
|
68
|
-
assert(typeof this.actual === "string", () => "Must have string for regexp match");
|
|
69
|
-
// @ts-expect-error
|
|
70
|
-
const actual = this.actual;
|
|
71
|
-
if (typeof expected === "string") {
|
|
72
|
-
assert(!actual.includes(expected), () => `${actual} includes ${expected}`);
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
assert(!expected.test(actual), () => `${actual} matches ${expected}`);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
toMatchObject(expected) {
|
|
79
|
-
for (const [k, v] of Object.entries(expected)) {
|
|
80
|
-
// @ts-expect-error
|
|
81
|
-
const actual = this.actual[k];
|
|
82
|
-
assert(!equals(actual, v), () => `Comparing ${k}, properties equal: ${JSON.stringify(actual)}, ${JSON.stringify(v)}`);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
toBeNull() {
|
|
86
|
-
assert(this.actual !== null, () => `Expected not null`);
|
|
87
|
-
}
|
|
88
|
-
toThrow(message = "") {
|
|
89
|
-
let didThrow = false;
|
|
90
|
-
let result = undefined;
|
|
91
|
-
try {
|
|
92
|
-
// @ts-expect-error
|
|
93
|
-
result = this.actual();
|
|
94
|
-
}
|
|
95
|
-
catch (e) {
|
|
96
|
-
assert((e.message ?? "").match(message) !== null, () => `Expected thrown message to match ${message}, got ${e}`);
|
|
97
|
-
didThrow = true;
|
|
98
|
-
}
|
|
99
|
-
assert(!didThrow, () => `Expected throw but got ${JSON.stringify(result)}`);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
export function expect(t) {
|
|
103
|
-
return new Matcher(t);
|
|
104
|
-
}
|
package/lib/esm/scope/fix.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Given a value with numbers, attempt to fix all numbers to 1 decimal point.
|
|
3
|
-
*/
|
|
4
|
-
export function fix(n) {
|
|
5
|
-
if (typeof n === "number") {
|
|
6
|
-
// @ts-ignore
|
|
7
|
-
return +n.toFixed(1);
|
|
8
|
-
}
|
|
9
|
-
if (n !== Object(n)) {
|
|
10
|
-
// A primitive
|
|
11
|
-
return n;
|
|
12
|
-
}
|
|
13
|
-
if (n instanceof Array) {
|
|
14
|
-
// @ts-ignore
|
|
15
|
-
return n.map(fix);
|
|
16
|
-
}
|
|
17
|
-
// @ts-ignore
|
|
18
|
-
return mapreduce(fix, n);
|
|
19
|
-
}
|
|
20
|
-
function mapreduce(fn, iter) {
|
|
21
|
-
return Object.entries(iter).reduce((acc, [k, v]) => ((acc[k] = fn(v)), acc), {});
|
|
22
|
-
}
|
package/lib/esm/scope/index.js
DELETED
package/lib/esm/scope/scope.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/lib/esm/scope/state.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import * as fs from "fs/promises";
|
|
2
|
-
import * as path from "path";
|
|
3
|
-
import { fileResponse } from "./response.js";
|
|
4
|
-
/**
|
|
5
|
-
* Searches up the request path until the first index is found.
|
|
6
|
-
*/
|
|
7
|
-
export const findIndex = async ({ root }) => async (req) => {
|
|
8
|
-
let filename = path.join(root, req.url ?? "");
|
|
9
|
-
if (path.basename(filename).match(/\.[a-z]{1,3}$/)) {
|
|
10
|
-
return undefined;
|
|
11
|
-
}
|
|
12
|
-
while (filename.startsWith(root)) {
|
|
13
|
-
const index = path.join(filename, "index.html");
|
|
14
|
-
try {
|
|
15
|
-
const stat = await fs.stat(index);
|
|
16
|
-
return fileResponse(index, stat);
|
|
17
|
-
}
|
|
18
|
-
catch (e) {
|
|
19
|
-
filename = path.dirname(filename);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
return undefined;
|
|
23
|
-
};
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import * as fs from "fs/promises";
|
|
2
|
-
import * as path from "path";
|
|
3
|
-
import { contentResponse } from "./response.js";
|
|
4
|
-
// @ts-ignore
|
|
5
|
-
import sass from "sass";
|
|
6
|
-
const { compileStringAsync } = sass;
|
|
7
|
-
function render(source) {
|
|
8
|
-
// Replace `from "@scope` with `from "/@scope`, for browsers
|
|
9
|
-
// source = source
|
|
10
|
-
// .replaceAll(`from "@`, 'from "/@')
|
|
11
|
-
// .replaceAll(`import("@`, 'import("/@');
|
|
12
|
-
return contentResponse(source, "text/css");
|
|
13
|
-
}
|
|
14
|
-
async function compile(filename, root, vars) {
|
|
15
|
-
vars = vars.substring(1).replaceAll("=", ":");
|
|
16
|
-
filename = filename.replaceAll("\\", "/"); // Normalize for dart-sass
|
|
17
|
-
const sassString = `// Using variables: ${vars}\n${vars};\n@import "${filename}";`;
|
|
18
|
-
return (await compileStringAsync(sassString, { loadPaths: [root] })).css;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Serves .css files statically. Finds .sass files and transpiles them to css.
|
|
22
|
-
*/
|
|
23
|
-
export const cssFileServer = async ({ root, scopes = {} }) => async (req) => {
|
|
24
|
-
const Url = new URL(req.url ?? "/", `http://${req.headers.host}`);
|
|
25
|
-
if (Url.pathname.endsWith(".css")) {
|
|
26
|
-
let scope = Object.entries(scopes).find(([s]) => Url.pathname.startsWith(`/${s}`));
|
|
27
|
-
// Expand url with found scope
|
|
28
|
-
Url.protocol = "file";
|
|
29
|
-
let url = scope ? Url.pathname.replace(scope[0], scope[1]) : Url.pathname;
|
|
30
|
-
let filename = path.join(root, url);
|
|
31
|
-
try {
|
|
32
|
-
const stat = await fs.stat(filename);
|
|
33
|
-
if (stat.isFile()) {
|
|
34
|
-
const css = (await fs.readFile(filename)).toString("utf-8");
|
|
35
|
-
return render(css);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
catch { }
|
|
39
|
-
filename = filename.replace(/\.css$/, ".scss");
|
|
40
|
-
try {
|
|
41
|
-
const stat = await fs.stat(filename);
|
|
42
|
-
if (stat.isFile()) {
|
|
43
|
-
const css = await compile(filename.replace(root, "."), root, Url.search);
|
|
44
|
-
return render(css);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
catch { }
|
|
48
|
-
}
|
|
49
|
-
return undefined;
|
|
50
|
-
};
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { createServer, } from "http";
|
|
3
|
-
import * as path from "path";
|
|
4
|
-
import { info } from "../../log.js";
|
|
5
|
-
import { findIndex } from "./apps.js";
|
|
6
|
-
import { cssFileServer } from "./css.js";
|
|
7
|
-
import { fileResponse } from "./response.js";
|
|
8
|
-
import { sitemap } from "./sitemap.js";
|
|
9
|
-
import { staticFileServer } from "./static.js";
|
|
10
|
-
import { tsFileServer } from "./typescript.js";
|
|
11
|
-
const notFound = async ({ root }) => async () => fileResponse(
|
|
12
|
-
// path.join(path.dirname(FLAGS.argv0), "404.html"),
|
|
13
|
-
path.join(root, "404.html"), undefined, 404);
|
|
14
|
-
const BASE_MIDDLEWARES = [
|
|
15
|
-
sitemap,
|
|
16
|
-
tsFileServer,
|
|
17
|
-
cssFileServer,
|
|
18
|
-
staticFileServer,
|
|
19
|
-
findIndex,
|
|
20
|
-
notFound,
|
|
21
|
-
];
|
|
22
|
-
const error = (res, message) => {
|
|
23
|
-
console.error(message);
|
|
24
|
-
res.statusCode = 500;
|
|
25
|
-
res.write(message);
|
|
26
|
-
res.end();
|
|
27
|
-
return true;
|
|
28
|
-
};
|
|
29
|
-
const sendContent = async (res, { content, contentType, contentLength }) => {
|
|
30
|
-
res.setHeader("Content-Length", `${contentLength}`);
|
|
31
|
-
res.setHeader("Content-Type", contentType);
|
|
32
|
-
await res.write(content);
|
|
33
|
-
res.end();
|
|
34
|
-
return true;
|
|
35
|
-
};
|
|
36
|
-
const log = (req) => {
|
|
37
|
-
const when = new Date().toISOString();
|
|
38
|
-
const who = req.socket.remoteAddress;
|
|
39
|
-
const what = req.url;
|
|
40
|
-
const how = `${req.method} ${what}`;
|
|
41
|
-
info("Request", { when, who, how });
|
|
42
|
-
};
|
|
43
|
-
export const makeServer = async (config, middlewares = []) => {
|
|
44
|
-
const handlers = await Promise.all([...middlewares, ...BASE_MIDDLEWARES].map(async (m) => m(config)));
|
|
45
|
-
const middlewareHandler = async (req, res) => {
|
|
46
|
-
log(req);
|
|
47
|
-
let handler;
|
|
48
|
-
try {
|
|
49
|
-
for (const middleware of handlers) {
|
|
50
|
-
handler = await middleware(req);
|
|
51
|
-
if (handler !== undefined) {
|
|
52
|
-
break;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
if (handler) {
|
|
56
|
-
sendContent(res, await handler());
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
res.end();
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
catch (e) {
|
|
63
|
-
error(res, e.message + "\n" + e.stack);
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
// TODO(https)
|
|
67
|
-
const server = createServer(middlewareHandler);
|
|
68
|
-
server.on("listening", () => {
|
|
69
|
-
const { address, port } = server.address();
|
|
70
|
-
info("Server listening", { address: `http://${address}:${port}` });
|
|
71
|
-
});
|
|
72
|
-
return server;
|
|
73
|
-
};
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import * as fs from "fs/promises";
|
|
2
|
-
const MIME_TYPES = {
|
|
3
|
-
js: "text/javascript",
|
|
4
|
-
json: "text/javascript",
|
|
5
|
-
css: "text/css",
|
|
6
|
-
html: "text/html",
|
|
7
|
-
png: "image/png",
|
|
8
|
-
jpg: "image/jpeg",
|
|
9
|
-
jpeg: "image/jpeg",
|
|
10
|
-
svg: "image/svg+xml",
|
|
11
|
-
eot: "application/vnd.ms-fontobject",
|
|
12
|
-
ttf: "application/font-ttf",
|
|
13
|
-
woff: "application/font-woff",
|
|
14
|
-
woff2: "application/font-woff2",
|
|
15
|
-
};
|
|
16
|
-
const mime = (basename) => {
|
|
17
|
-
const extension = basename
|
|
18
|
-
.substring(basename.lastIndexOf(".") + 1)
|
|
19
|
-
.toLowerCase();
|
|
20
|
-
return MIME_TYPES[extension] ?? "application/octet-stream";
|
|
21
|
-
};
|
|
22
|
-
export const fileResponse = (filename, stat, status = 200) => async () => {
|
|
23
|
-
if (!stat) {
|
|
24
|
-
stat = await fs.stat(filename);
|
|
25
|
-
}
|
|
26
|
-
const content = await fs.readFile(filename);
|
|
27
|
-
const contentType = mime(filename);
|
|
28
|
-
const contentLength = stat.size;
|
|
29
|
-
return { status, contentType, contentLength, content };
|
|
30
|
-
};
|
|
31
|
-
const CHARSET = "utf-8";
|
|
32
|
-
export const contentResponse = (content, contentType, status = 200) => async () => {
|
|
33
|
-
const contentBuffer = Buffer.from(content, CHARSET);
|
|
34
|
-
return {
|
|
35
|
-
content: contentBuffer,
|
|
36
|
-
contentType: contentType.split(";")[0] + "; charset=" + CHARSET,
|
|
37
|
-
status,
|
|
38
|
-
contentLength: contentBuffer.length,
|
|
39
|
-
};
|
|
40
|
-
};
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import * as fs from "fs/promises";
|
|
2
|
-
import * as path from "path";
|
|
3
|
-
import { info } from "../../log.js";
|
|
4
|
-
import { contentResponse } from "./response.js";
|
|
5
|
-
const findSiteMap = async (root, prefix = root) => {
|
|
6
|
-
if (root.startsWith("node_modules")) {
|
|
7
|
-
return [];
|
|
8
|
-
}
|
|
9
|
-
const children = (await fs.readdir(root, { withFileTypes: true })).map(async (entry) => {
|
|
10
|
-
const next = path
|
|
11
|
-
.join(root, entry.name)
|
|
12
|
-
// Normalize separators for web
|
|
13
|
-
.replaceAll(path.sep, "/");
|
|
14
|
-
if (entry.isFile()) {
|
|
15
|
-
if (entry.name === "index.html") {
|
|
16
|
-
let index = next.replace(prefix, "");
|
|
17
|
-
info(`Adding to sitemap`, { index });
|
|
18
|
-
return [index];
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
else if (entry.isDirectory()) {
|
|
22
|
-
if (entry.name.startsWith(".")) {
|
|
23
|
-
return [];
|
|
24
|
-
}
|
|
25
|
-
const flattened = (await Promise.all(await findSiteMap(next, prefix))).flat();
|
|
26
|
-
return flattened;
|
|
27
|
-
}
|
|
28
|
-
return [];
|
|
29
|
-
});
|
|
30
|
-
return children;
|
|
31
|
-
};
|
|
32
|
-
export const sitemap = async ({ root }) => {
|
|
33
|
-
const apps = await (await Promise.all(await findSiteMap(root)))
|
|
34
|
-
.flat()
|
|
35
|
-
.filter((a) => a !== undefined);
|
|
36
|
-
return async (req) => {
|
|
37
|
-
if ((req.url ?? "").endsWith("sitemap.json")) {
|
|
38
|
-
return contentResponse(JSON.stringify(apps), "application/json");
|
|
39
|
-
}
|
|
40
|
-
return undefined;
|
|
41
|
-
};
|
|
42
|
-
};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import * as path from "path";
|
|
2
|
-
import * as fs from "fs/promises";
|
|
3
|
-
import { fileResponse } from "./response.js";
|
|
4
|
-
export const staticFileServer = async ({ root, scopes = {} }) => async (req) => {
|
|
5
|
-
const scope = Object.entries(scopes).find(([s]) => req.url?.startsWith(`/${s}`));
|
|
6
|
-
const url = new URL(req.url ?? "", `http://localhost`);
|
|
7
|
-
const pathname = scope
|
|
8
|
-
? url.pathname.replace(scope[0], scope[1])
|
|
9
|
-
: url.pathname;
|
|
10
|
-
const filename = path.join(root, pathname);
|
|
11
|
-
// Expand url with found scope
|
|
12
|
-
console.log(scope, req.url, filename);
|
|
13
|
-
try {
|
|
14
|
-
const stat = await fs.stat(filename);
|
|
15
|
-
return stat.isDirectory() ? undefined : fileResponse(filename, stat);
|
|
16
|
-
}
|
|
17
|
-
catch (e) {
|
|
18
|
-
console.error(e);
|
|
19
|
-
return undefined;
|
|
20
|
-
}
|
|
21
|
-
};
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import * as fs from "fs/promises";
|
|
2
|
-
import * as path from "path";
|
|
3
|
-
import { contentResponse } from "./response.js";
|
|
4
|
-
import { transpile } from "../../transpile.mjs";
|
|
5
|
-
function render(source) {
|
|
6
|
-
// Replace `from "@scope` with `from "/@scope`, for browsers
|
|
7
|
-
source = source
|
|
8
|
-
.replaceAll(`from "@`, 'from "/@')
|
|
9
|
-
.replaceAll(`import("@`, 'import("/@');
|
|
10
|
-
return contentResponse(source, "application/javascript");
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Serves .js files statically. Finds .ts files and transpiles them to JS.
|
|
14
|
-
*/
|
|
15
|
-
export const tsFileServer = async ({ root, scopes = {} }) => async (req) => {
|
|
16
|
-
if (req.url?.endsWith(".js")) {
|
|
17
|
-
let scope = Object.entries(scopes).find(([s]) => req.url?.startsWith(`/${s}`));
|
|
18
|
-
// Expand url with found scope
|
|
19
|
-
let url = scope ? req.url.replace(scope[0], scope[1]) : req.url;
|
|
20
|
-
let filename = path.join(root, url);
|
|
21
|
-
try {
|
|
22
|
-
const stat = await fs.stat(filename);
|
|
23
|
-
if (stat.isFile()) {
|
|
24
|
-
const js = (await fs.readFile(filename)).toString("utf-8");
|
|
25
|
-
return render(js);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
catch { }
|
|
29
|
-
filename = filename.replace(/\.js$/, ".ts");
|
|
30
|
-
try {
|
|
31
|
-
const stat = await fs.stat(filename);
|
|
32
|
-
if (stat.isFile()) {
|
|
33
|
-
const js = await transpile(filename, () => fs.readFile(filename));
|
|
34
|
-
return render(js);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
catch { }
|
|
38
|
-
}
|
|
39
|
-
return undefined;
|
|
40
|
-
};
|
package/lib/esm/server/main.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node --experimental-loader ../loader.mjs
|
|
2
|
-
import { info } from "../log.js";
|
|
3
|
-
info("Starting server", { cwd: process.cwd() });
|
|
4
|
-
import { parse } from "../flags.js";
|
|
5
|
-
const FLAGS = parse(process.argv);
|
|
6
|
-
import { makeServer } from "./http/index.js";
|
|
7
|
-
import * as path from "node:path";
|
|
8
|
-
async function main() {
|
|
9
|
-
const server = await makeServer({ root: path.join(process.cwd(), "src") });
|
|
10
|
-
server.listen(FLAGS.asNumber("port", 8080), FLAGS.asString("host", "0.0.0.0"));
|
|
11
|
-
}
|
|
12
|
-
main();
|