@danielx/civet 0.3.1 → 0.3.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 +1 -0
- package/dist/browser.js +19 -6
- package/dist/browser.js.map +2 -2
- package/dist/civet +10 -10
- package/dist/cli.js.map +3 -3
- package/{esbuild-plugin.js → dist/esbuild-plugin.js} +0 -0
- package/dist/esm.mjs +61 -0
- package/dist/main.js +19 -6
- package/package.json +9 -6
- package/register.mjs +5 -17
|
File without changes
|
package/dist/esm.mjs
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { readFileSync } from 'fs';
|
|
2
|
+
import { createRequire } from 'module';
|
|
3
|
+
import { pathToFileURL, fileURLToPath } from 'url';
|
|
4
|
+
|
|
5
|
+
//@ts-ignore Note: this is the compiled name
|
|
6
|
+
import { compile } from "./main.js";
|
|
7
|
+
|
|
8
|
+
const baseURL = pathToFileURL(process.cwd() + '/').href;
|
|
9
|
+
const extensionsRegex = /\.civet$/;
|
|
10
|
+
|
|
11
|
+
export function resolve(specifier, context, next) {
|
|
12
|
+
const { parentURL = baseURL } = context;
|
|
13
|
+
|
|
14
|
+
if (extensionsRegex.test(specifier)) {
|
|
15
|
+
return {
|
|
16
|
+
shortCircuit: true,
|
|
17
|
+
format: "civet",
|
|
18
|
+
url: new URL(specifier, parentURL).href,
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// Let Node.js handle all other specifiers.
|
|
23
|
+
return next(specifier, context);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export function load(url, context, next) {
|
|
27
|
+
if (context.format === "civet") {
|
|
28
|
+
const path = fileURLToPath(url);
|
|
29
|
+
const source = readFileSync(path, "utf8");
|
|
30
|
+
const tsSource = compile(source, {
|
|
31
|
+
filename: path,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
// NOTE: Assuming ts-node hook follows load hook
|
|
35
|
+
// NOTE: This causes .civet files to show up as .ts in ts-node error reporting (TODO: May be able to add a sourcemapping)
|
|
36
|
+
return next(url.replace(extensionsRegex, ".ts"), {
|
|
37
|
+
// ts-node won't transpile unless this is module
|
|
38
|
+
// can't use commonjs since we don't rewrite imports
|
|
39
|
+
format: "module",
|
|
40
|
+
// NOTE: Setting the source in the context makes it available when ts-node uses defaultLoad
|
|
41
|
+
source: tsSource,
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// Let Node.js handle all other URLs.
|
|
46
|
+
return next(url, context);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
// commonjs hook
|
|
51
|
+
const require = createRequire(import.meta.url);
|
|
52
|
+
require.extensions[".civet"] = function(m, filename) {
|
|
53
|
+
const source = readFileSync(filename, "utf8");
|
|
54
|
+
const code = compile(source, {
|
|
55
|
+
filename,
|
|
56
|
+
js: true,
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
//@ts-ignore TODO: Figure out how to load types from inculde folders in Civet LSP
|
|
60
|
+
m._compile(code, filename);
|
|
61
|
+
};
|
package/dist/main.js
CHANGED
|
@@ -547,6 +547,7 @@ var require_parser = __commonJS({
|
|
|
547
547
|
MaybeNestedExpression,
|
|
548
548
|
Return,
|
|
549
549
|
ImportDeclaration,
|
|
550
|
+
ImpliedImport,
|
|
550
551
|
Import,
|
|
551
552
|
ImportClause,
|
|
552
553
|
NameSpaceImport,
|
|
@@ -1305,9 +1306,9 @@ var require_parser = __commonJS({
|
|
|
1305
1306
|
return SpacedApplication$0(state);
|
|
1306
1307
|
}
|
|
1307
1308
|
}
|
|
1308
|
-
var ApplicationStart$0 = $TS($S($E(OptionalShorthand), $TEXT($P(_)), $N(AdditionalReservedWords)), function($skip, $loc, $0, $1, $2, $3) {
|
|
1309
|
+
var ApplicationStart$0 = $TS($S($E(OptionalShorthand), $N(EOS), $TEXT($P(_)), $N(AdditionalReservedWords)), function($skip, $loc, $0, $1, $2, $3, $4) {
|
|
1309
1310
|
var opt = $1;
|
|
1310
|
-
var spacing = $
|
|
1311
|
+
var spacing = $3;
|
|
1311
1312
|
return [opt, "(", spacing.replace(/^ /, "")];
|
|
1312
1313
|
});
|
|
1313
1314
|
function ApplicationStart(state) {
|
|
@@ -2498,11 +2499,24 @@ var require_parser = __commonJS({
|
|
|
2498
2499
|
});
|
|
2499
2500
|
var ImportDeclaration$1 = $S(Import, __, ImportClause, __, FromClause);
|
|
2500
2501
|
var ImportDeclaration$2 = $S(Import, __, ModuleSpecifier);
|
|
2502
|
+
var ImportDeclaration$3 = $S(ImpliedImport, ImportClause, __, FromClause);
|
|
2501
2503
|
function ImportDeclaration(state) {
|
|
2502
2504
|
if (state.tokenize) {
|
|
2503
|
-
return $TOKEN("ImportDeclaration", state, ImportDeclaration$0(state) || ImportDeclaration$1(state) || ImportDeclaration$2(state));
|
|
2505
|
+
return $TOKEN("ImportDeclaration", state, ImportDeclaration$0(state) || ImportDeclaration$1(state) || ImportDeclaration$2(state) || ImportDeclaration$3(state));
|
|
2504
2506
|
} else {
|
|
2505
|
-
return ImportDeclaration$0(state) || ImportDeclaration$1(state) || ImportDeclaration$2(state);
|
|
2507
|
+
return ImportDeclaration$0(state) || ImportDeclaration$1(state) || ImportDeclaration$2(state) || ImportDeclaration$3(state);
|
|
2508
|
+
}
|
|
2509
|
+
}
|
|
2510
|
+
var ImpliedImport$0 = $T($EXPECT($L32, fail, 'ImpliedImport ""'), function(value) {
|
|
2511
|
+
return "import ";
|
|
2512
|
+
});
|
|
2513
|
+
function ImpliedImport(state) {
|
|
2514
|
+
if (state.verbose)
|
|
2515
|
+
console.log("ENTER:", "ImpliedImport");
|
|
2516
|
+
if (state.tokenize) {
|
|
2517
|
+
return $TOKEN("ImpliedImport", state, ImpliedImport$0(state));
|
|
2518
|
+
} else {
|
|
2519
|
+
return ImpliedImport$0(state);
|
|
2506
2520
|
}
|
|
2507
2521
|
}
|
|
2508
2522
|
var Import$0 = $TS($S($EXPECT($L24, fail, 'Import "import"'), NonIdContinue), function($skip, $loc, $0, $1, $2) {
|
|
@@ -3766,8 +3780,7 @@ var require_parser = __commonJS({
|
|
|
3766
3780
|
if (spacing) {
|
|
3767
3781
|
str = str.replaceAll(spacing[0], "\n");
|
|
3768
3782
|
}
|
|
3769
|
-
str = str.replace(/^(\r?\n|\n)/, "");
|
|
3770
|
-
str = str.replace(/(\r?\n|\n)$/, "");
|
|
3783
|
+
str = str.replace(/^(\r?\n|\n)/, "").replace(/(\r?\n|\n)[ \t]*$/, "").replace(/(`|\$)/g, "\\$1");
|
|
3771
3784
|
return str;
|
|
3772
3785
|
};
|
|
3773
3786
|
return $0;
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@danielx/civet",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "CoffeeScript style syntax for TypeScript",
|
|
5
5
|
"main": "dist/main.js",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": "./dist/main.js",
|
|
8
|
-
"./esm": "./
|
|
8
|
+
"./esm": "./dist/esm.mjs",
|
|
9
|
+
"./esbuild-plugin": "./dist/esbuild-plugin.js"
|
|
9
10
|
},
|
|
10
11
|
"types": "dist/types.d.ts",
|
|
11
12
|
"bin": {
|
|
@@ -13,7 +14,6 @@
|
|
|
13
14
|
},
|
|
14
15
|
"files": [
|
|
15
16
|
"dist/",
|
|
16
|
-
"esbuild-plugin.js",
|
|
17
17
|
"register.js",
|
|
18
18
|
"register.mjs"
|
|
19
19
|
],
|
|
@@ -40,11 +40,14 @@
|
|
|
40
40
|
},
|
|
41
41
|
"mocha": {
|
|
42
42
|
"extension": [
|
|
43
|
+
"civet",
|
|
43
44
|
"coffee"
|
|
44
45
|
],
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
46
|
+
"loader": [
|
|
47
|
+
"ts-node/esm",
|
|
48
|
+
"./build/coffee-esm.mjs",
|
|
49
|
+
"./build/hera-esm.mjs",
|
|
50
|
+
"./dist/esm.mjs"
|
|
48
51
|
],
|
|
49
52
|
"reporter": "dot",
|
|
50
53
|
"recursive": true,
|
package/register.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { readFileSync } from 'fs';
|
|
1
2
|
import { readFile } from 'fs/promises';
|
|
2
3
|
import { createRequire } from 'module';
|
|
3
4
|
import { pathToFileURL, fileURLToPath } from 'url';
|
|
@@ -7,8 +8,6 @@ import { compile } from "./dist/main.js";
|
|
|
7
8
|
const baseURL = pathToFileURL(process.cwd() + '/').href;
|
|
8
9
|
const extensionsRegex = /\.civet$/;
|
|
9
10
|
|
|
10
|
-
const cache = new Map
|
|
11
|
-
|
|
12
11
|
export async function resolve(specifier, context, next) {
|
|
13
12
|
const { parentURL = baseURL } = context;
|
|
14
13
|
|
|
@@ -28,7 +27,7 @@ export async function load(url, context, next) {
|
|
|
28
27
|
if (context.format === "civet") {
|
|
29
28
|
const path = fileURLToPath(url)
|
|
30
29
|
const source = await readFile(path, "utf8")
|
|
31
|
-
const tsSource = compile(source)
|
|
30
|
+
const tsSource = compile(source, { filename: path })
|
|
32
31
|
|
|
33
32
|
// NOTE: Assuming ts-node hook follows load hook
|
|
34
33
|
// NOTE: This causes .civet files to show up as .ts in ts-node error reporting (TODO: May be able to add a sourcemapping)
|
|
@@ -40,15 +39,6 @@ export async function load(url, context, next) {
|
|
|
40
39
|
source: tsSource
|
|
41
40
|
});
|
|
42
41
|
|
|
43
|
-
// NOTE: If I don't set the format to 'commonjs' then I get
|
|
44
|
-
// "ReferenceError: exports is not defined in ES module scope"
|
|
45
|
-
// setting the format to commonjs causes the require.extensions
|
|
46
|
-
// handler to be invoked. So we cache the ts-node transpilation
|
|
47
|
-
// result, hook into require.extensions, and return the result there.
|
|
48
|
-
// Hopefully node loaders simplify this in the future.
|
|
49
|
-
result.format = "commonjs"
|
|
50
|
-
cache.set(path, result.source)
|
|
51
|
-
|
|
52
42
|
return result
|
|
53
43
|
}
|
|
54
44
|
|
|
@@ -56,13 +46,11 @@ export async function load(url, context, next) {
|
|
|
56
46
|
return next(url, context);
|
|
57
47
|
}
|
|
58
48
|
|
|
59
|
-
// Cache our double transpiled sources (.civet -> .ts -> .js)
|
|
60
49
|
const require = createRequire(import.meta.url);
|
|
61
50
|
require.extensions[".civet"] = function (m, filename) {
|
|
62
|
-
|
|
63
|
-
|
|
51
|
+
// We end up here when being required from cjs
|
|
52
|
+
const source = readFileSync(filename, "utf8")
|
|
53
|
+
const code = compile(source, { filename, js: true })
|
|
64
54
|
|
|
65
55
|
m._compile(code, filename)
|
|
66
|
-
// Module should be cached after the first load so we can release the memory
|
|
67
|
-
cache.delete(filename)
|
|
68
56
|
}
|