@danielx/civet 0.5.21 → 0.5.22

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 CHANGED
@@ -23,6 +23,8 @@ Quickstart Guide
23
23
  ```bash
24
24
  # Install
25
25
  npm install -g @danielx/civet
26
+ # Run civet code directly in a REPL
27
+ civet
26
28
  # Compile civet source file to typescript
27
29
  civet < source.civet > output.ts
28
30
  # Execute a civet source file in node using ts-node
package/dist/civet CHANGED
@@ -186,6 +186,7 @@ cli = async function() {
186
186
  if (options.run) {
187
187
  options.js = true;
188
188
  options.inlineMap = true;
189
+ require("../register.js");
189
190
  }
190
191
  if (options.repl) {
191
192
  return repl(options);
@@ -247,8 +248,10 @@ cli = async function() {
247
248
  }
248
249
  }
249
250
  } else {
251
+ module.filename = await fs.realpath(filename);
252
+ module.paths = require("module")._nodeModulePaths(path.dirname(module.filename));
250
253
  try {
251
- results.push(require.main._compile(output, filename));
254
+ results.push(module._compile(output, module.filename));
252
255
  } catch (error1) {
253
256
  error = error1;
254
257
  console.error(`${filename} crashed while running:`);
package/dist/esm.mjs CHANGED
@@ -5,7 +5,7 @@ Currently depends on ts-node esm loader being downstream
5
5
 
6
6
  @example
7
7
  ```bash
8
- node --loader ts-node/esm --loader @danielx/civet/esm
8
+ node --loader ts-node/esm --loader @danielx/civet/esm source.civet
9
9
  ```
10
10
  */
11
11
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@danielx/civet",
3
- "version": "0.5.21",
3
+ "version": "0.5.22",
4
4
  "description": "CoffeeScript style syntax for TypeScript",
5
5
  "main": "dist/main.js",
6
6
  "exports": {
@@ -36,6 +36,7 @@
36
36
  "@types/coffeescript": "^2.5.2",
37
37
  "@types/mocha": "^9.1.1",
38
38
  "@types/node": "^18.7.8",
39
+ "axios": "^1.2.2",
39
40
  "c8": "^7.12.0",
40
41
  "esbuild": "^0.14.49",
41
42
  "esbuild-coffeescript": "^2.1.0",
package/register.js CHANGED
@@ -1,10 +1,23 @@
1
+ /**
2
+ @file Civet CJS registration
3
+
4
+ `require`ing this file will register the `.civet` extension with
5
+ Node.js's `require`.
6
+
7
+ @example
8
+ ```bash
9
+ node -r @danielx/civet/register.js source.civet
10
+ ```
11
+ */
12
+
1
13
  if (require.extensions) {
2
14
  const fs = require("fs");
3
15
  const { compile } = require("./");
4
16
 
5
17
  require.extensions[".civet"] = function (module, filename) {
6
18
  const js = compile(fs.readFileSync(filename, 'utf8'), {
7
- js: true
19
+ js: true,
20
+ inlineMap: true,
8
21
  });
9
22
  module._compile(js, filename);
10
23
  return;
package/register.mjs DELETED
@@ -1,56 +0,0 @@
1
- import { readFileSync } from 'fs';
2
- import { readFile } from 'fs/promises';
3
- import { createRequire } from 'module';
4
- import { pathToFileURL, fileURLToPath } from 'url';
5
-
6
- import { compile } from "./dist/main.js";
7
-
8
- const baseURL = pathToFileURL(process.cwd() + '/').href;
9
- const extensionsRegex = /\.civet$/;
10
-
11
- export async 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 async function load(url, context, next) {
27
- if (context.format === "civet") {
28
- const path = fileURLToPath(url)
29
- const source = await readFile(path, "utf8")
30
- const tsSource = compile(source, { filename: path })
31
-
32
- // NOTE: Assuming ts-node hook follows load hook
33
- // NOTE: This causes .civet files to show up as .ts in ts-node error reporting (TODO: May be able to add a sourcemapping)
34
- const result = await next(url.replace(extensionsRegex, ".tsx"), {
35
- // ts-node won't transpile unless this is module
36
- // can't use commonjs since we don't rewrite imports
37
- format: "module",
38
- // NOTE: Setting the source in the context makes it available when ts-node uses defaultLoad
39
- source: tsSource
40
- });
41
-
42
- return result
43
- }
44
-
45
- // Let Node.js handle all other URLs.
46
- return next(url, context);
47
- }
48
-
49
- const require = createRequire(import.meta.url);
50
- require.extensions[".civet"] = function (m, filename) {
51
- // We end up here when being required from cjs
52
- const source = readFileSync(filename, "utf8")
53
- const code = compile(source, { filename, js: true })
54
-
55
- m._compile(code, filename)
56
- }