@danielx/civet 0.7.8 → 0.7.10

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/dist/civet CHANGED
@@ -46,11 +46,11 @@ var unplugin;
46
46
  function version() {
47
47
  return require("../package.json").version;
48
48
  }
49
- if (process.argv.includes("--version")) {
49
+ if (process.argv.some((a) => a === "--version" || a === "-version" || a === "-v")) {
50
50
  console.log(version());
51
51
  process.exit(0);
52
52
  }
53
- if (process.argv.includes("--help")) {
53
+ if (process.argv.some((a1) => a1 === "--help" || a1 === "-help" || a1 === "-h")) {
54
54
  process.stderr.write(` \u2584\u2584\xB7 \u25AA \u258C \u2590\xB7\u2584\u2584\u2584 .\u2584\u2584\u2584\u2584\u2584
55
55
  \u2590\u2588 \u258C\u25AA\u2588\u2588 \u25AA\u2588\xB7\u2588\u258C\u2580\u2584.\u2580\xB7\u2022\u2588\u2588 _._ _,-'""\`-._
56
56
  \u2588\u2588 \u2584\u2584\u2590\u2588\xB7\u2590\u2588\u2590\u2588\u2022\u2590\u2580\u2580\u25AA\u2584 \u2590\u2588.\u25AA (,-.\`._,'( |\\\`-/|
@@ -106,6 +106,7 @@ function parseArgs(args) {
106
106
  const filenames = [];
107
107
  let scriptArgs = [];
108
108
  let i = 0;
109
+ let errors = 0;
109
110
  function endOfArgs(j) {
110
111
  i = args.length;
111
112
  if (j >= args.length) {
@@ -199,9 +200,9 @@ function parseArgs(args) {
199
200
  }
200
201
  default: {
201
202
  if (arg.startsWith("-") && arg !== "-") {
202
- throw new Error(`Invalid command-line argument ${arg}`);
203
- }
204
- if (options.run) {
203
+ console.error(`Invalid command-line argument: ${arg}`);
204
+ errors++;
205
+ } else if (options.run) {
205
206
  endOfArgs(i);
206
207
  } else {
207
208
  filenames.push(arg);
@@ -210,6 +211,9 @@ function parseArgs(args) {
210
211
  }
211
212
  i++;
212
213
  }
214
+ if (errors) {
215
+ process.exit(Math.min(255, errors));
216
+ }
213
217
  return { filenames, scriptArgs, options };
214
218
  }
215
219
  async function* readFiles(filenames) {
@@ -273,7 +277,6 @@ async function repl(options) {
273
277
  };
274
278
  } else {
275
279
  const execArgv = ["--experimental-vm-modules"];
276
- const { register } = await import("node:module");
277
280
  if (process.env.NODE_OPTIONS) {
278
281
  execArgv.push(process.env.NODE_OPTIONS);
279
282
  }
@@ -343,17 +346,36 @@ async function repl(options) {
343
346
  } else if (input in ["quit\n", "exit\n", "quit()\n", "exit()\n"]) {
344
347
  return process.exit(0);
345
348
  } else if (input.endsWith("\n\n")) {
349
+ let showError2 = function(error) {
350
+ console.error("Error while parsing Civet code:");
351
+ if ((0, import_main.isCompileError)(error)) {
352
+ if (error.errors != null) {
353
+ error = error.errors[0];
354
+ }
355
+ return console.log(`${input.split("\n").slice(0, error.line).join("\n")}
356
+ ${" ".repeat(error.column - 1)}^ ${error.header}`);
357
+ } else {
358
+ return console.error(error);
359
+ }
360
+ };
361
+ var showError = showError2;
346
362
  let output;
347
363
  if (options.compile || options.ast) {
348
364
  try {
349
365
  output = await (0, import_main.compile)(input, { ...options, filename });
350
366
  } catch (error) {
351
- console.error(error);
367
+ showError2(error);
352
368
  return callback(null, void 0);
353
369
  }
354
370
  return callback(null, output);
355
371
  }
356
- let ast = await (0, import_main.compile)(input, { ...options, filename, ast: true });
372
+ let ast;
373
+ try {
374
+ ast = await (0, import_main.compile)(input, { ...options, filename, ast: true });
375
+ } catch (error) {
376
+ showError2(error);
377
+ return callback(null, void 0);
378
+ }
357
379
  const topLevelAwait = import_main.lib.hasAwait(ast) || import_main.lib.hasImportDeclaration(ast);
358
380
  if (topLevelAwait) {
359
381
  const [prologue, rest] = (0, import_main.parse)(input, { startRule: "ProloguePrefix" });
@@ -373,7 +395,7 @@ async function repl(options) {
373
395
  });
374
396
  });
375
397
  }
376
- const errors = [];
398
+ let errors = [];
377
399
  try {
378
400
  output = (0, import_main.generate)(ast, { errors });
379
401
  } catch (error) {
@@ -381,7 +403,9 @@ async function repl(options) {
381
403
  return callback(null, void 0);
382
404
  }
383
405
  if (errors.length) {
384
- console.error(`Parse errors: ${errors.map(($2) => $2.message).join("\n")}`);
406
+ errors = [];
407
+ (0, import_main.generate)(ast, { errors, sourceMap: (0, import_main.SourceMap)(input) });
408
+ showError2(errors[0]);
385
409
  return callback(null, void 0);
386
410
  }
387
411
  let result;
@@ -531,7 +555,7 @@ async function cli() {
531
555
  targetPath = outputPath;
532
556
  }
533
557
  if (targetPath.dir) {
534
- import_promises.default.mkdir(targetPath.dir, { recursive: true });
558
+ await import_promises.default.mkdir(targetPath.dir, { recursive: true });
535
559
  }
536
560
  const targetFilename = import_path.default.format(targetPath);
537
561
  try {
package/dist/config.js CHANGED
@@ -31,6 +31,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
31
31
  var config_exports = {};
32
32
  __export(config_exports, {
33
33
  findConfig: () => findConfig,
34
+ findInDir: () => findInDir,
34
35
  loadConfig: () => loadConfig
35
36
  });
36
37
  module.exports = __toCommonJS(config_exports);
@@ -41,14 +42,16 @@ var configFileNames = /* @__PURE__ */ new Set([
41
42
  "\u{1F408}.json",
42
43
  "\u{1F408}.civet",
43
44
  "civetconfig.json",
44
- "civetconfig.civet"
45
+ "civetconfig.civet",
46
+ "civet.config.json",
47
+ "civet.config.civet"
45
48
  ]);
46
49
  async function findInDir(dirPath) {
47
50
  for (const entryName of await import_promises.default.readdir(dirPath)) {
48
51
  const entryPath = import_path.default.join(dirPath, entryName);
49
52
  if (entryName === ".config" && await (async () => {
50
53
  try {
51
- return (await import_promises.default.stat(entryPath)).isDir();
54
+ return (await import_promises.default.stat(entryPath)).isDirectory();
52
55
  } catch (e) {
53
56
  return;
54
57
  }
@@ -119,5 +122,6 @@ async function loadConfig(path2) {
119
122
  // Annotate the CommonJS export names for ESM import in node:
120
123
  0 && (module.exports = {
121
124
  findConfig,
125
+ findInDir,
122
126
  loadConfig
123
127
  });
@@ -1,6 +1,7 @@
1
1
  import * as esbuild from 'esbuild';
2
2
  import { PluginOptions } from './unplugin.mjs';
3
3
  import 'unplugin';
4
+ import '@danielx/civet';
4
5
 
5
6
  declare const _default: (options: PluginOptions) => esbuild.Plugin;
6
7
 
package/dist/esbuild.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import * as esbuild from 'esbuild';
2
2
  import { PluginOptions } from './unplugin.js';
3
3
  import 'unplugin';
4
+ import '@danielx/civet';
4
5
 
5
6
  declare const _default: (options: PluginOptions) => esbuild.Plugin;
6
7
 
package/dist/esbuild.js CHANGED
@@ -37,6 +37,7 @@ module.exports = __toCommonJS(esbuild_exports);
37
37
  // src/index.ts
38
38
  var import_unplugin = require("unplugin");
39
39
  var import_civet = __toESM(require("@danielx/civet"));
40
+ var import_config = require("@danielx/civet/config");
40
41
  var import_ts_diagnostic = require("@danielx/civet/ts-diagnostic");
41
42
  var fs = __toESM(require("fs"));
42
43
  var import_path = __toESM(require("path"));
@@ -90,6 +91,7 @@ var rawPlugin = (options = {}, meta) => {
90
91
  options.emitDeclaration = options.dts;
91
92
  if (options.js)
92
93
  options.ts = "civet";
94
+ let compileOptions = {};
93
95
  const transformTS = options.emitDeclaration || options.typecheck;
94
96
  const outExt = options.outputExtension ?? (options.ts === "preserve" ? ".tsx" : ".jsx");
95
97
  const implicitExtension = options.implicitExtension ?? true;
@@ -112,12 +114,20 @@ var rawPlugin = (options = {}, meta) => {
112
114
  async buildStart() {
113
115
  if (transformTS || options.ts === "tsc") {
114
116
  const ts = await tsPromise;
115
- const configPath = ts.findConfigFile(process.cwd(), ts.sys.fileExists);
116
- if (!configPath) {
117
+ const civetConfigPath = "config" in options ? options.config : await (0, import_config.findInDir)(process.cwd());
118
+ if (civetConfigPath) {
119
+ compileOptions = await (0, import_config.loadConfig)(civetConfigPath);
120
+ }
121
+ compileOptions.parseOptions = {
122
+ ...compileOptions.parseOptions,
123
+ ...options.parseOptions
124
+ };
125
+ const tsConfigPath = ts.findConfigFile(process.cwd(), ts.sys.fileExists);
126
+ if (!tsConfigPath) {
117
127
  throw new Error("Could not find 'tsconfig.json'");
118
128
  }
119
129
  const { config, error } = ts.readConfigFile(
120
- configPath,
130
+ tsConfigPath,
121
131
  ts.sys.readFile
122
132
  );
123
133
  if (error) {
@@ -164,9 +174,9 @@ var rawPlugin = (options = {}, meta) => {
164
174
  encoding
165
175
  });
166
176
  const compiledTS = import_civet.default.compile(rawCivetSource, {
177
+ ...compileOptions,
167
178
  filename,
168
179
  js: false,
169
- comptime: Boolean(options.comptime),
170
180
  sync: true
171
181
  // TS readFile API seems to need to be synchronous
172
182
  });
@@ -314,11 +324,9 @@ var rawPlugin = (options = {}, meta) => {
314
324
  this.addWatchFile(filename);
315
325
  let compiled;
316
326
  const civetOptions = {
327
+ ...compileOptions,
317
328
  filename: id,
318
- sourceMap: true,
319
- parseOptions: {
320
- comptime: Boolean(options.comptime)
321
- }
329
+ sourceMap: true
322
330
  };
323
331
  if (options.ts === "civet" && !transformTS) {
324
332
  compiled = await import_civet.default.compile(rawCivetSource, {
package/dist/esm.mjs CHANGED
@@ -3,8 +3,7 @@ import { readFileSync } from "fs";
3
3
  import { pathToFileURL, fileURLToPath } from "url";
4
4
  import sourceMapSupport from "@cspotcode/source-map-support";
5
5
  import Civet from "./main.js";
6
- var { compile, util } = Civet;
7
- var { SourceMap } = util;
6
+ var { compile, SourceMap } = Civet;
8
7
  var baseURL = pathToFileURL(process.cwd() + "/").href;
9
8
  var extensionsRegex = /\.civet$/;
10
9
  var registered = false;