@elliots/typical-tsc-plugin 0.2.0 → 0.2.3
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/index.mjs +25 -17
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -33,7 +33,7 @@ function encodeRequest(method, payload) {
|
|
|
33
33
|
}
|
|
34
34
|
function decodeResponse(data) {
|
|
35
35
|
let offset = 0;
|
|
36
|
-
if (data[offset++] !== MessagePackTypeFixedArray3) throw new Error(`Expected 0x93, got 0x${data[0].toString(16)}`);
|
|
36
|
+
if (data[offset++] !== MessagePackTypeFixedArray3) throw new Error(`Expected 0x93, got 0x${data[0].toString(16)}: first 200 of data: ${data.subarray(0, 200).toString("utf8")}`);
|
|
37
37
|
if (data[offset++] !== MessagePackTypeU8) throw new Error(`Expected 0xCC for message type`);
|
|
38
38
|
const messageType = data[offset++];
|
|
39
39
|
const { value: methodBuf, newOffset: offset2 } = readBin(data, offset);
|
|
@@ -106,15 +106,16 @@ function debugLog(...args) {
|
|
|
106
106
|
if (debug) console.error(...args);
|
|
107
107
|
}
|
|
108
108
|
function getBinaryPath() {
|
|
109
|
-
const
|
|
109
|
+
const localBinPath = join(__dirname, "..", "bin", "typical");
|
|
110
110
|
try {
|
|
111
|
-
|
|
112
|
-
debugLog(`[CLIENT] Using
|
|
113
|
-
return
|
|
114
|
-
} catch {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}
|
|
111
|
+
require("fs").accessSync(localBinPath);
|
|
112
|
+
debugLog(`[CLIENT] Using local binary at ${localBinPath}`);
|
|
113
|
+
return localBinPath;
|
|
114
|
+
} catch {}
|
|
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;
|
|
@@ -161,11 +162,14 @@ var TypicalCompiler = class {
|
|
|
161
162
|
async loadProject(configFileName) {
|
|
162
163
|
return this.request("loadProject", { configFileName });
|
|
163
164
|
}
|
|
164
|
-
async transformFile(project, fileName) {
|
|
165
|
+
async transformFile(project, fileName, ignoreTypes, maxGeneratedFunctions, reusableValidators) {
|
|
165
166
|
const projectId = typeof project === "string" ? project : project.id;
|
|
166
167
|
return this.request("transformFile", {
|
|
167
168
|
project: projectId,
|
|
168
|
-
fileName
|
|
169
|
+
fileName,
|
|
170
|
+
ignoreTypes,
|
|
171
|
+
maxGeneratedFunctions,
|
|
172
|
+
reusableValidators
|
|
169
173
|
});
|
|
170
174
|
}
|
|
171
175
|
async release(handle) {
|
|
@@ -178,12 +182,16 @@ var TypicalCompiler = class {
|
|
|
178
182
|
*
|
|
179
183
|
* @param fileName - Virtual filename for error messages (e.g., "test.ts")
|
|
180
184
|
* @param source - TypeScript source code
|
|
185
|
+
* @param options - Optional transform options
|
|
181
186
|
* @returns Transformed code with validation
|
|
182
187
|
*/
|
|
183
|
-
async transformSource(fileName, source) {
|
|
188
|
+
async transformSource(fileName, source, options) {
|
|
184
189
|
return this.request("transformSource", {
|
|
185
190
|
fileName,
|
|
186
|
-
source
|
|
191
|
+
source,
|
|
192
|
+
ignoreTypes: options?.ignoreTypes,
|
|
193
|
+
maxGeneratedFunctions: options?.maxGeneratedFunctions,
|
|
194
|
+
reusableValidators: options?.reusableValidators
|
|
187
195
|
});
|
|
188
196
|
}
|
|
189
197
|
async request(method, payload) {
|
|
@@ -229,11 +237,11 @@ var TypicalCompiler = class {
|
|
|
229
237
|
/**
|
|
230
238
|
* Synchronous wrapper around the async compiler transformFile.
|
|
231
239
|
*/
|
|
232
|
-
function transformFileSync(compiler, project, fileName) {
|
|
240
|
+
function transformFileSync(compiler, project, fileName, config) {
|
|
233
241
|
let result;
|
|
234
242
|
let error;
|
|
235
243
|
let done = false;
|
|
236
|
-
compiler.transformFile(project, fileName).then((res) => {
|
|
244
|
+
compiler.transformFile(project, fileName, config.ignoreTypes, config.maxGeneratedFunctions, config.reusableValidators).then((res) => {
|
|
237
245
|
result = res.code;
|
|
238
246
|
done = true;
|
|
239
247
|
}, (err) => {
|
|
@@ -261,7 +269,7 @@ function transformFileSync(compiler, project, fileName) {
|
|
|
261
269
|
* }
|
|
262
270
|
*/
|
|
263
271
|
function src_default(program, host, _pluginConfig, { ts: tsInstance }) {
|
|
264
|
-
validateConfig(loadConfig());
|
|
272
|
+
const config = validateConfig(loadConfig());
|
|
265
273
|
const compiler = new TypicalCompiler({ cwd: process.cwd() });
|
|
266
274
|
let projectHandle;
|
|
267
275
|
let initError;
|
|
@@ -281,7 +289,7 @@ function src_default(program, host, _pluginConfig, { ts: tsInstance }) {
|
|
|
281
289
|
for (const sourceFile of program.getSourceFiles()) {
|
|
282
290
|
if (sourceFile.isDeclarationFile || sourceFile.fileName.includes("node_modules")) continue;
|
|
283
291
|
try {
|
|
284
|
-
const transformed = transformFileSync(compiler, projectHandle, sourceFile.fileName);
|
|
292
|
+
const transformed = transformFileSync(compiler, projectHandle, sourceFile.fileName, config);
|
|
285
293
|
transformedFiles.set(sourceFile.fileName, transformed);
|
|
286
294
|
} catch (err) {
|
|
287
295
|
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.
|
|
3
|
+
"version": "0.2.3",
|
|
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.
|
|
45
|
+
"@elliots/typical": "0.2.3",
|
|
46
46
|
"deasync": "0.1.30",
|
|
47
47
|
"strip-json-comments": "5.0.3"
|
|
48
48
|
},
|