@danielx/civet 0.4.0 → 0.4.1-8.2
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 +105 -55
- package/dist/browser.js +3499 -960
- package/dist/civet +28 -12
- package/dist/esbuild-plugin.js +20 -14
- package/dist/esm.mjs +49 -49
- package/dist/main.js +3499 -960
- package/package.json +1 -1
package/dist/civet
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
|
-
var
|
|
3
|
+
var compile, encoding, fs, generate, parse, prune, read;
|
|
4
4
|
if (process.argv.includes("--version")) {
|
|
5
5
|
process.stdout.write(require("../package.json").version + "\n");
|
|
6
6
|
process.exit(0);
|
|
@@ -9,14 +9,30 @@ if (process.argv.includes("--version")) {
|
|
|
9
9
|
({ prune } = generate);
|
|
10
10
|
encoding = "utf8";
|
|
11
11
|
fs = require("fs");
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
12
|
+
read = function(stream, encoding2) {
|
|
13
|
+
return new Promise(function(resolve, reject) {
|
|
14
|
+
var parts;
|
|
15
|
+
parts = [];
|
|
16
|
+
stream.resume();
|
|
17
|
+
stream.on("data", function(buffer) {
|
|
18
|
+
return parts.push(buffer);
|
|
19
|
+
});
|
|
20
|
+
stream.on("error", reject);
|
|
21
|
+
return stream.on("end", function() {
|
|
22
|
+
return resolve(Buffer.concat(parts).toString(encoding2));
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
read(process.stdin, encoding).then(function(input) {
|
|
27
|
+
var ast, inlineMap, js, output;
|
|
28
|
+
process.argv.includes("--ast");
|
|
29
|
+
js = process.argv.includes("--js");
|
|
30
|
+
inlineMap = process.argv.includes("--inline-map");
|
|
31
|
+
if (ast) {
|
|
32
|
+
ast = prune(parse(input));
|
|
33
|
+
process.stdout.write(JSON.stringify(ast, null, 2));
|
|
34
|
+
process.exit(0);
|
|
35
|
+
}
|
|
36
|
+
output = compile(input, { js, inlineMap });
|
|
37
|
+
return process.stdout.write(output);
|
|
38
|
+
});
|
package/dist/esbuild-plugin.js
CHANGED
|
@@ -1,29 +1,35 @@
|
|
|
1
|
-
const { readFile } = require('fs/promises')
|
|
2
|
-
const path = require('path')
|
|
1
|
+
const { readFile } = require('fs/promises')
|
|
2
|
+
const path = require('path')
|
|
3
3
|
|
|
4
4
|
// NOTE: this references the built version of the module, not the source
|
|
5
|
-
const { compile } = require("../dist/main.js")
|
|
5
|
+
const { compile } = require("../dist/main.js")
|
|
6
6
|
|
|
7
7
|
module.exports = {
|
|
8
8
|
name: 'civet',
|
|
9
9
|
setup(build) {
|
|
10
|
-
build.onLoad({
|
|
11
|
-
filter: /\.civet
|
|
10
|
+
return build.onLoad({
|
|
11
|
+
filter: /\.civet$/
|
|
12
12
|
}, async function(args) {
|
|
13
13
|
try {
|
|
14
|
-
const source = await readFile(args.path, 'utf8')
|
|
15
|
-
const filename = path.relative(process.cwd(), args.path)
|
|
14
|
+
const source = await readFile(args.path, 'utf8')
|
|
15
|
+
const filename = path.relative(process.cwd(), args.path)
|
|
16
|
+
const compiled = compile(source, {
|
|
17
|
+
filename,
|
|
18
|
+
inlineMap: true,
|
|
19
|
+
js: true
|
|
20
|
+
})
|
|
21
|
+
|
|
16
22
|
return {
|
|
17
|
-
contents:
|
|
18
|
-
}
|
|
23
|
+
contents: compiled,
|
|
24
|
+
}
|
|
19
25
|
}
|
|
20
26
|
catch (e) {
|
|
21
27
|
return {
|
|
22
28
|
errors: [{
|
|
23
|
-
text: e.message
|
|
29
|
+
text: e.message
|
|
24
30
|
}],
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
})
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
})
|
|
28
34
|
},
|
|
29
|
-
}
|
|
35
|
+
}
|
package/dist/esm.mjs
CHANGED
|
@@ -9,82 +9,82 @@ node --loader ts-node/esm --loader @danielx/civet/esm
|
|
|
9
9
|
```
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
import { readFileSync } from "fs"
|
|
13
|
-
import { createRequire } from "module"
|
|
14
|
-
import { pathToFileURL, fileURLToPath } from "url"
|
|
12
|
+
import { readFileSync } from "fs"
|
|
13
|
+
import { createRequire } from "module"
|
|
14
|
+
import { pathToFileURL, fileURLToPath } from "url"
|
|
15
15
|
|
|
16
|
-
import sourceMapSupport from "@cspotcode/source-map-support"
|
|
16
|
+
import sourceMapSupport from "@cspotcode/source-map-support"
|
|
17
17
|
|
|
18
18
|
// NOTE: this references the built version of the module, not the source
|
|
19
|
-
import Civet from "../dist/main.js"
|
|
20
|
-
const { compile, util } = Civet
|
|
21
|
-
const { SourceMap } = util
|
|
19
|
+
import Civet from "../dist/main.js"
|
|
20
|
+
const { compile, util } = Civet
|
|
21
|
+
const { SourceMap } = util
|
|
22
22
|
|
|
23
|
-
const baseURL = pathToFileURL(process.cwd() + '/').href
|
|
24
|
-
const extensionsRegex = /\.civet
|
|
23
|
+
const baseURL = pathToFileURL(process.cwd() + '/').href
|
|
24
|
+
const extensionsRegex = /\.civet$/
|
|
25
25
|
|
|
26
|
-
let registered = false
|
|
27
|
-
const outputCache = new Map
|
|
26
|
+
let registered = false
|
|
27
|
+
const outputCache = new Map
|
|
28
28
|
|
|
29
|
-
const directorySeparator = '/'
|
|
30
|
-
const backslashRegExp = /\\/g
|
|
29
|
+
const directorySeparator = '/'
|
|
30
|
+
const backslashRegExp = /\\/g
|
|
31
31
|
/**
|
|
32
32
|
* Replace backslashes with forward slashes.
|
|
33
33
|
*/
|
|
34
34
|
function normalizeSlashes(value) {
|
|
35
35
|
return value.replace(backslashRegExp, directorySeparator);
|
|
36
|
-
}
|
|
36
|
+
}
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
function ensureRegister () {
|
|
39
|
+
if (registered)return
|
|
40
40
|
|
|
41
41
|
const installation = {
|
|
42
42
|
environment: 'node',
|
|
43
43
|
retrieveFile(pathOrUrl) {
|
|
44
|
-
let path = pathOrUrl
|
|
44
|
+
let path = pathOrUrl
|
|
45
45
|
// If it's a file URL, convert to local path
|
|
46
46
|
// I could not find a way to handle non-URLs except to swallow an error
|
|
47
47
|
if (path.startsWith('file://')) {
|
|
48
48
|
try {
|
|
49
|
-
path = fileURLToPath(path)
|
|
50
|
-
} catch {}
|
|
51
|
-
}
|
|
52
|
-
path = normalizeSlashes(path)
|
|
49
|
+
path = fileURLToPath(path)
|
|
50
|
+
} catch(e) {}
|
|
51
|
+
}
|
|
52
|
+
path = normalizeSlashes(path)
|
|
53
53
|
|
|
54
|
-
return outputCache.get(path)
|
|
54
|
+
return outputCache.get(path)
|
|
55
55
|
},
|
|
56
|
-
}
|
|
56
|
+
}
|
|
57
57
|
|
|
58
|
-
sourceMapSupport.install(installation)
|
|
58
|
+
sourceMapSupport.install(installation)
|
|
59
59
|
|
|
60
|
-
registered = true
|
|
61
|
-
}
|
|
60
|
+
return registered = true
|
|
61
|
+
}
|
|
62
62
|
|
|
63
63
|
export function resolve(specifier, context, next) {
|
|
64
|
-
const { parentURL = baseURL } = context
|
|
64
|
+
const { parentURL = baseURL } = context
|
|
65
65
|
|
|
66
66
|
if (extensionsRegex.test(specifier)) {
|
|
67
67
|
return {
|
|
68
68
|
shortCircuit: true,
|
|
69
69
|
format: "civet",
|
|
70
70
|
url: new URL(specifier, parentURL).href,
|
|
71
|
-
}
|
|
72
|
-
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
73
|
|
|
74
74
|
// Let Node.js handle all other specifiers.
|
|
75
|
-
return next(specifier, context)
|
|
76
|
-
}
|
|
75
|
+
return next(specifier, context)
|
|
76
|
+
}
|
|
77
77
|
|
|
78
78
|
export async function load(url, context, next) {
|
|
79
79
|
if (context.format === "civet") {
|
|
80
|
-
const path = fileURLToPath(url)
|
|
81
|
-
const source = readFileSync(path, "utf8")
|
|
80
|
+
const path = fileURLToPath(url)
|
|
81
|
+
const source = readFileSync(path, "utf8")
|
|
82
82
|
const {code: tsSource, sourceMap} = compile(source, {
|
|
83
83
|
filename: path,
|
|
84
84
|
sourceMap: true,
|
|
85
|
-
})
|
|
85
|
+
})
|
|
86
86
|
|
|
87
|
-
const transpiledPath = url + ".ts"
|
|
87
|
+
const transpiledPath = url + ".ts"
|
|
88
88
|
|
|
89
89
|
// NOTE: Assuming ts-node hook follows load hook
|
|
90
90
|
const result = await next(transpiledPath, {
|
|
@@ -93,34 +93,34 @@ export async function load(url, context, next) {
|
|
|
93
93
|
format: "module",
|
|
94
94
|
// NOTE: Setting the source in the context makes it available when ts-node uses defaultLoad
|
|
95
95
|
source: tsSource,
|
|
96
|
-
})
|
|
96
|
+
})
|
|
97
97
|
|
|
98
98
|
// NOTE: we must install our source map support after ts-node does to take priority
|
|
99
|
-
ensureRegister()
|
|
99
|
+
ensureRegister()
|
|
100
100
|
|
|
101
101
|
// parse source map from downstream (ts-node) result
|
|
102
102
|
// compose with civet source map
|
|
103
|
-
result.source = SourceMap.remap(result.source, sourceMap, url, "")
|
|
103
|
+
result.source = SourceMap.remap(result.source, sourceMap, url, "")
|
|
104
104
|
// NOTE: This path needs to match what ts-node uses so we can override the source map
|
|
105
|
-
outputCache.set(normalizeSlashes(path), result.source)
|
|
105
|
+
outputCache.set(normalizeSlashes(path), result.source)
|
|
106
106
|
|
|
107
|
-
return result
|
|
108
|
-
}
|
|
107
|
+
return result
|
|
108
|
+
}
|
|
109
109
|
|
|
110
110
|
// Other URLs continue unchanged.
|
|
111
|
-
return next(url, context)
|
|
112
|
-
}
|
|
111
|
+
return next(url, context)
|
|
112
|
+
}
|
|
113
113
|
|
|
114
114
|
// commonjs hook
|
|
115
|
-
const require = createRequire(import.meta.url)
|
|
115
|
+
const require = createRequire(import.meta.url)
|
|
116
116
|
require.extensions[".civet"] = function(m, filename) {
|
|
117
|
-
const source = readFileSync(filename, "utf8")
|
|
117
|
+
const source = readFileSync(filename, "utf8")
|
|
118
118
|
const code = compile(source, {
|
|
119
119
|
filename,
|
|
120
120
|
inlineMap: true,
|
|
121
|
-
js: true
|
|
122
|
-
})
|
|
121
|
+
js: true
|
|
122
|
+
})
|
|
123
123
|
|
|
124
124
|
//@ts-ignore TODO: Figure out how to load types from inculde folders in Civet LSP
|
|
125
|
-
m._compile(code, filename)
|
|
126
|
-
}
|
|
125
|
+
return m._compile(code, filename)
|
|
126
|
+
}
|