@elliots/typical-tsc-plugin 0.2.1 → 0.2.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.
Files changed (3) hide show
  1. package/LICENSE +21 -0
  2. package/dist/index.mjs +37 -17
  3. package/package.json +2 -2
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Elliot Shepherd
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.mjs CHANGED
@@ -2,6 +2,7 @@ import { createRequire } from "node:module";
2
2
  import { spawn } from "node:child_process";
3
3
  import { dirname, join } from "node:path";
4
4
  import { fileURLToPath } from "node:url";
5
+ import { existsSync } from "node:fs";
5
6
  import { loadConfig, validateConfig } from "@elliots/typical";
6
7
  import deasync from "deasync";
7
8
 
@@ -106,15 +107,15 @@ function debugLog(...args) {
106
107
  if (debug) console.error(...args);
107
108
  }
108
109
  function getBinaryPath() {
109
- const pkgName = `@elliots/typical-compiler-${process.platform}-${process.arch}`;
110
- try {
111
- const pkg = require(pkgName);
112
- debugLog(`[CLIENT] Using platform binary from ${pkgName}`);
113
- return pkg.binaryPath;
114
- } catch {
115
- debugLog(`[CLIENT] Platform package ${pkgName} not found, falling back to local bin`);
116
- return join(__dirname, "..", "bin", "typical");
110
+ const devPath = join(__dirname, "../bin/typical");
111
+ if (existsSync(devPath)) {
112
+ debugLog(`[CLIENT] Using development binary at ${devPath}`);
113
+ return devPath;
117
114
  }
115
+ const pkgName = `@elliots/typical-compiler-${process.platform}-${process.arch}`;
116
+ const pkg = require(pkgName);
117
+ debugLog(`[CLIENT] Using platform binary from ${pkgName}`);
118
+ return pkg.binaryPath;
118
119
  }
119
120
  var TypicalCompiler = class {
120
121
  process = null;
@@ -175,21 +176,40 @@ var TypicalCompiler = class {
175
176
  await this.request("release", id);
176
177
  }
177
178
  /**
179
+ * Analyse a file for validation points without transforming it.
180
+ * Returns information about which parameters, returns, and casts will be validated.
181
+ * Used by the VSCode extension to show validation indicators.
182
+ *
183
+ * @param project - Project handle or ID
184
+ * @param fileName - Path to the file to analyse
185
+ * @param content - Optional file content for live updates (uses disk version if not provided)
186
+ * @param ignoreTypes - Optional glob patterns for types to skip
187
+ * @returns Analysis result with validation items
188
+ */
189
+ async analyseFile(project, fileName, content, ignoreTypes) {
190
+ const projectId = typeof project === "string" ? project : project.id;
191
+ return this.request("analyseFile", {
192
+ project: projectId,
193
+ fileName,
194
+ content,
195
+ ignoreTypes
196
+ });
197
+ }
198
+ /**
178
199
  * Transform a standalone TypeScript source string.
179
200
  * Creates a temporary project to enable type checking.
180
201
  *
181
202
  * @param fileName - Virtual filename for error messages (e.g., "test.ts")
182
203
  * @param source - TypeScript source code
183
- * @param ignoreTypes - Glob patterns for types to skip validation (e.g., ["FieldConfig", "React.*"])
184
- * @param maxGeneratedFunctions - Max helper functions before error (0 = default 50)
204
+ * @param options - Optional transform options
185
205
  * @returns Transformed code with validation
186
206
  */
187
- async transformSource(fileName, source, ignoreTypes, maxGeneratedFunctions) {
207
+ async transformSource(fileName, source, options) {
188
208
  return this.request("transformSource", {
189
209
  fileName,
190
210
  source,
191
- ignoreTypes,
192
- maxGeneratedFunctions
211
+ ignoreTypes: options?.ignoreTypes,
212
+ maxGeneratedFunctions: options?.maxGeneratedFunctions
193
213
  });
194
214
  }
195
215
  async request(method, payload) {
@@ -235,11 +255,11 @@ var TypicalCompiler = class {
235
255
  /**
236
256
  * Synchronous wrapper around the async compiler transformFile.
237
257
  */
238
- function transformFileSync(compiler, project, fileName) {
258
+ function transformFileSync(compiler, project, fileName, config) {
239
259
  let result;
240
260
  let error;
241
261
  let done = false;
242
- compiler.transformFile(project, fileName).then((res) => {
262
+ compiler.transformFile(project, fileName, config.ignoreTypes, config.maxGeneratedFunctions).then((res) => {
243
263
  result = res.code;
244
264
  done = true;
245
265
  }, (err) => {
@@ -267,7 +287,7 @@ function transformFileSync(compiler, project, fileName) {
267
287
  * }
268
288
  */
269
289
  function src_default(program, host, _pluginConfig, { ts: tsInstance }) {
270
- validateConfig(loadConfig());
290
+ const config = validateConfig(loadConfig());
271
291
  const compiler = new TypicalCompiler({ cwd: process.cwd() });
272
292
  let projectHandle;
273
293
  let initError;
@@ -287,7 +307,7 @@ function src_default(program, host, _pluginConfig, { ts: tsInstance }) {
287
307
  for (const sourceFile of program.getSourceFiles()) {
288
308
  if (sourceFile.isDeclarationFile || sourceFile.fileName.includes("node_modules")) continue;
289
309
  try {
290
- const transformed = transformFileSync(compiler, projectHandle, sourceFile.fileName);
310
+ const transformed = transformFileSync(compiler, projectHandle, sourceFile.fileName, config);
291
311
  transformedFiles.set(sourceFile.fileName, transformed);
292
312
  } catch (err) {
293
313
  console.error(`[typical] Failed to transform ${sourceFile.fileName}:`, err);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elliots/typical-tsc-plugin",
3
- "version": "0.2.1",
3
+ "version": "0.2.4",
4
4
  "description": "TSC plugin for typical - runtime safe TypeScript transformer",
5
5
  "keywords": [
6
6
  "runtime",
@@ -42,7 +42,7 @@
42
42
  "access": "public"
43
43
  },
44
44
  "dependencies": {
45
- "@elliots/typical": "0.2.1",
45
+ "@elliots/typical": "0.2.4",
46
46
  "deasync": "0.1.30",
47
47
  "strip-json-comments": "5.0.3"
48
48
  },