-
Notifications
You must be signed in to change notification settings - Fork 0
/
replete.js
51 lines (47 loc) · 1.41 KB
/
replete.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// @ts-nocheck x
import run from 'https://deno.land/x/replete/run.js';
import initSwc, { transformSync } from 'https://esm.sh/@swc/wasm-web';
import ecomcon from 'https://raw.githubusercontent.com/douglascrockford/ecomcon/master/ecomcon.js';
await initSwc();
function compile_jsx(command) {
return transformSync(ecomcon(command.source, ['demo']), {
jsc: {
parser: { syntax: 'ecmascript', jsx: true },
transform: { react: { runtime: 'classic' } },
},
}).code;
}
run({
deno_args: ['--allow-all', '--config', './deno.json'],
locate(specifier, parent_locator) {
return Promise.resolve(
specifier.startsWith('.')
? new URL(specifier, parent_locator).href
: import.meta.resolve(specifier)
);
},
command(message) {
if (message.locator !== undefined && message.locator.endsWith('.jsx')) {
message.source = compile_jsx(message);
}
return Promise.resolve(message);
},
read(locator) {
return Deno.readFile(new URL(locator)).then(function (buffer) {
return locator.endsWith('.jsx')
? compile_jsx({ source: new TextDecoder().decode(buffer), locator })
: buffer;
});
},
mime(locator) {
if (locator.endsWith('.css')) {
return 'text/css';
}
if (locator.endsWith('.js') || locator.endsWith('.jsx')) {
return 'text/javascript';
}
if (locator.endsWith('.wasm')) {
return 'application/wasm';
}
},
});