@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/rollup.d.mts CHANGED
@@ -1,6 +1,8 @@
1
- import * as unplugin from 'unplugin';
1
+ import * as rollup from 'rollup';
2
2
  import { PluginOptions } from './unplugin.mjs';
3
+ import 'unplugin';
4
+ import '@danielx/civet';
3
5
 
4
- declare const _default: (options: PluginOptions) => unplugin.RollupPlugin<any> | unplugin.RollupPlugin<any>[];
6
+ declare const _default: (options: PluginOptions) => rollup.Plugin | rollup.Plugin[];
5
7
 
6
8
  export { _default as default };
package/dist/rollup.d.ts CHANGED
@@ -1,6 +1,8 @@
1
- import * as unplugin from 'unplugin';
1
+ import * as rollup from 'rollup';
2
2
  import { PluginOptions } from './unplugin.js';
3
+ import 'unplugin';
4
+ import '@danielx/civet';
3
5
 
4
- declare const _default: (options: PluginOptions) => unplugin.RollupPlugin<any> | unplugin.RollupPlugin<any>[];
6
+ declare const _default: (options: PluginOptions) => rollup.Plugin | rollup.Plugin[];
5
7
 
6
8
  export { _default as default };
package/dist/rollup.js CHANGED
@@ -37,6 +37,7 @@ module.exports = __toCommonJS(rollup_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/types.d.ts CHANGED
@@ -57,14 +57,21 @@ declare module "@danielx/civet" {
57
57
 
58
58
  // TODO: Import ParseError class from Hera
59
59
  export type ParseError = {
60
- message: string
61
- name: string
60
+ name: "ParseError"
61
+ message: string // filename:line:column header\nbody
62
+ header: string
63
+ body: string
62
64
  filename: string
63
65
  line: number
64
66
  column: number
65
67
  offset: number
66
68
  }
67
- export function isCompileError(err: any): err is ParseError
69
+ export type ParseErrors = {
70
+ name: "ParseErrors"
71
+ message: string
72
+ errors: ParseError[]
73
+ }
74
+ export function isCompileError(err: any): err is ParseError | ParseErrors
68
75
 
69
76
  type CompileOutput<T extends CompileOptions> =
70
77
  T extends { ast: true } ? CivetAST :
@@ -87,7 +94,7 @@ declare module "@danielx/civet" {
87
94
  isCompileError: typeof isCompileError
88
95
  parse: typeof parse
89
96
  generate: typeof generate
90
- util: {
97
+ sourcemap: {
91
98
  locationTable(input: string): number[]
92
99
  lookupLineColumn(table: number[], pos: number): [number, number]
93
100
  SourceMap(input: string): SourceMap
@@ -112,11 +119,14 @@ declare module "@danielx/civet/esbuild-plugin" {
112
119
  }
113
120
 
114
121
  declare module "@danielx/civet/config" {
115
- const Config: {
116
- findConfig: (path: string) => Promise<string | null>
117
- loadConfig: (
118
- path: string
119
- ) => Promise<import("@danielx/civet").CompileOptions>
122
+ export function findInDir(dirPath: string): Promise<string | undefined>
123
+ export function findConfig(path: string): Promise<string | null>
124
+ export function loadConfig(
125
+ path: string
126
+ ): Promise<import("@danielx/civet").CompileOptions>
127
+ export default {
128
+ findInDir: typeof findInDir,
129
+ findConfig: typeof findConfig,
130
+ loadConfig: typeof loadConfig,
120
131
  }
121
- export default Config
122
132
  }
@@ -1,6 +1,7 @@
1
1
  // src/index.ts
2
2
  import { createUnplugin } from "unplugin";
3
3
  import civet from "@danielx/civet";
4
+ import { findInDir, loadConfig } from "@danielx/civet/config";
4
5
  import {
5
6
  remapRange,
6
7
  flattenDiagnosticMessageText
@@ -57,6 +58,7 @@ var rawPlugin = (options = {}, meta) => {
57
58
  options.emitDeclaration = options.dts;
58
59
  if (options.js)
59
60
  options.ts = "civet";
61
+ let compileOptions = {};
60
62
  const transformTS = options.emitDeclaration || options.typecheck;
61
63
  const outExt = options.outputExtension ?? (options.ts === "preserve" ? ".tsx" : ".jsx");
62
64
  const implicitExtension = options.implicitExtension ?? true;
@@ -79,12 +81,20 @@ var rawPlugin = (options = {}, meta) => {
79
81
  async buildStart() {
80
82
  if (transformTS || options.ts === "tsc") {
81
83
  const ts = await tsPromise;
82
- const configPath = ts.findConfigFile(process.cwd(), ts.sys.fileExists);
83
- if (!configPath) {
84
+ const civetConfigPath = "config" in options ? options.config : await findInDir(process.cwd());
85
+ if (civetConfigPath) {
86
+ compileOptions = await loadConfig(civetConfigPath);
87
+ }
88
+ compileOptions.parseOptions = {
89
+ ...compileOptions.parseOptions,
90
+ ...options.parseOptions
91
+ };
92
+ const tsConfigPath = ts.findConfigFile(process.cwd(), ts.sys.fileExists);
93
+ if (!tsConfigPath) {
84
94
  throw new Error("Could not find 'tsconfig.json'");
85
95
  }
86
96
  const { config, error } = ts.readConfigFile(
87
- configPath,
97
+ tsConfigPath,
88
98
  ts.sys.readFile
89
99
  );
90
100
  if (error) {
@@ -131,9 +141,9 @@ var rawPlugin = (options = {}, meta) => {
131
141
  encoding
132
142
  });
133
143
  const compiledTS = civet.compile(rawCivetSource, {
144
+ ...compileOptions,
134
145
  filename,
135
146
  js: false,
136
- comptime: Boolean(options.comptime),
137
147
  sync: true
138
148
  // TS readFile API seems to need to be synchronous
139
149
  });
@@ -281,11 +291,9 @@ var rawPlugin = (options = {}, meta) => {
281
291
  this.addWatchFile(filename);
282
292
  let compiled;
283
293
  const civetOptions = {
294
+ ...compileOptions,
284
295
  filename: id,
285
- sourceMap: true,
286
- parseOptions: {
287
- comptime: Boolean(options.comptime)
288
- }
296
+ sourceMap: true
289
297
  };
290
298
  if (options.ts === "civet" && !transformTS) {
291
299
  compiled = await civet.compile(rawCivetSource, {
@@ -1,5 +1,6 @@
1
- import * as unplugin$1 from 'unplugin';
1
+ import * as _unplugin from 'unplugin';
2
2
  import { TransformResult, createUnplugin } from 'unplugin';
3
+ import { ParseOptions } from '@danielx/civet';
3
4
 
4
5
  type PluginOptions = {
5
6
  implicitExtension?: boolean;
@@ -12,10 +13,12 @@ type PluginOptions = {
12
13
  js?: boolean;
13
14
  /** @deprecated Use "emitDeclaration" instead */
14
15
  dts?: boolean;
15
- comptime?: boolean;
16
+ /** config filename, or null to not look for default config file */
17
+ config?: string | null | undefined;
18
+ parseOptions?: ParseOptions;
16
19
  };
17
20
  declare function slash(p: string): string;
18
21
  declare const rawPlugin: Parameters<typeof createUnplugin<PluginOptions>>[0];
19
- declare var unplugin: unplugin$1.UnpluginInstance<PluginOptions, boolean>;
22
+ declare var unplugin: _unplugin.UnpluginInstance<PluginOptions, boolean>;
20
23
 
21
- export { type PluginOptions, unplugin as default, rawPlugin, slash };
24
+ export { PluginOptions, unplugin as default, rawPlugin, slash };
@@ -1,5 +1,6 @@
1
- import * as unplugin$1 from 'unplugin';
1
+ import * as _unplugin from 'unplugin';
2
2
  import { TransformResult, createUnplugin } from 'unplugin';
3
+ import { ParseOptions } from '@danielx/civet';
3
4
 
4
5
  type PluginOptions = {
5
6
  implicitExtension?: boolean;
@@ -12,10 +13,12 @@ type PluginOptions = {
12
13
  js?: boolean;
13
14
  /** @deprecated Use "emitDeclaration" instead */
14
15
  dts?: boolean;
15
- comptime?: boolean;
16
+ /** config filename, or null to not look for default config file */
17
+ config?: string | null | undefined;
18
+ parseOptions?: ParseOptions;
16
19
  };
17
20
  declare function slash(p: string): string;
18
21
  declare const rawPlugin: Parameters<typeof createUnplugin<PluginOptions>>[0];
19
- declare var unplugin: unplugin$1.UnpluginInstance<PluginOptions, boolean>;
22
+ declare var unplugin: _unplugin.UnpluginInstance<PluginOptions, boolean>;
20
23
 
21
- export { type PluginOptions, unplugin as default, rawPlugin, slash };
24
+ export { PluginOptions, unplugin as default, rawPlugin, slash };
package/dist/unplugin.js CHANGED
@@ -37,6 +37,7 @@ __export(src_exports, {
37
37
  module.exports = __toCommonJS(src_exports);
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/vite.d.mts CHANGED
@@ -1,6 +1,7 @@
1
1
  import * as vite from 'vite';
2
2
  import { PluginOptions } from './unplugin.mjs';
3
3
  import 'unplugin';
4
+ import '@danielx/civet';
4
5
 
5
6
  declare const _default: (options: PluginOptions) => vite.Plugin | vite.Plugin[];
6
7
 
package/dist/vite.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import * as vite from 'vite';
2
2
  import { PluginOptions } from './unplugin.js';
3
3
  import 'unplugin';
4
+ import '@danielx/civet';
4
5
 
5
6
  declare const _default: (options: PluginOptions) => vite.Plugin | vite.Plugin[];
6
7
 
package/dist/vite.js CHANGED
@@ -37,6 +37,7 @@ module.exports = __toCommonJS(vite_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, {
@@ -1,5 +1,6 @@
1
1
  import { PluginOptions } from './unplugin.mjs';
2
2
  import 'unplugin';
3
+ import '@danielx/civet';
3
4
 
4
5
  declare const _default: (options: PluginOptions) => WebpackPluginInstance;
5
6
 
package/dist/webpack.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { PluginOptions } from './unplugin.js';
2
2
  import 'unplugin';
3
+ import '@danielx/civet';
3
4
 
4
5
  declare const _default: (options: PluginOptions) => WebpackPluginInstance;
5
6
 
package/dist/webpack.js CHANGED
@@ -37,6 +37,7 @@ module.exports = __toCommonJS(webpack_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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@danielx/civet",
3
3
  "type": "commonjs",
4
- "version": "0.7.8",
4
+ "version": "0.7.10",
5
5
  "description": "CoffeeScript style syntax for TypeScript",
6
6
  "main": "dist/main.js",
7
7
  "module": "dist/main.mjs",
@@ -75,8 +75,8 @@
75
75
  },
76
76
  "devDependencies": {
77
77
  "@danielx/civet": "0.7.4",
78
- "@danielx/hera": "^0.8.13",
79
- "@prettier/sync": "^0.3.0",
78
+ "@danielx/hera": "^0.8.14",
79
+ "@prettier/sync": "^0.5.2",
80
80
  "@types/assert": "^1.5.6",
81
81
  "@types/mocha": "^9.1.1",
82
82
  "@types/node": "^20.12.2",
@@ -84,7 +84,7 @@
84
84
  "esbuild": "0.20.0",
85
85
  "marked": "^4.2.4",
86
86
  "mocha": "^10.0.0",
87
- "prettier": "^3.1.1",
87
+ "prettier": "^3.2.5",
88
88
  "terser": "^5.16.1",
89
89
  "ts-node": "^10.9.1",
90
90
  "tslib": "^2.4.0",