@danielx/civet 0.3.0 → 0.3.4

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/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "@danielx/civet",
3
- "version": "0.3.0",
3
+ "version": "0.3.4",
4
4
  "description": "CoffeeScript style syntax for TypeScript",
5
5
  "main": "dist/main.js",
6
6
  "exports": {
7
7
  ".": "./dist/main.js",
8
- "./esm": "./register.mjs"
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
- "require": [
46
- "coffeescript/register",
47
- "@danielx/hera/register"
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
- const code = cache.get(filename)
63
- if (!code) throw new Error(`Code for ${filename} wasn't in transpiled cache.`)
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
  }