@elliots/typical-tsc-plugin 0.2.1 → 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 +21 -19
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -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,13 +162,14 @@ var TypicalCompiler = class {
|
|
|
161
162
|
async loadProject(configFileName) {
|
|
162
163
|
return this.request("loadProject", { configFileName });
|
|
163
164
|
}
|
|
164
|
-
async transformFile(project, fileName, ignoreTypes, maxGeneratedFunctions) {
|
|
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
169
|
fileName,
|
|
169
170
|
ignoreTypes,
|
|
170
|
-
maxGeneratedFunctions
|
|
171
|
+
maxGeneratedFunctions,
|
|
172
|
+
reusableValidators
|
|
171
173
|
});
|
|
172
174
|
}
|
|
173
175
|
async release(handle) {
|
|
@@ -180,16 +182,16 @@ var TypicalCompiler = class {
|
|
|
180
182
|
*
|
|
181
183
|
* @param fileName - Virtual filename for error messages (e.g., "test.ts")
|
|
182
184
|
* @param source - TypeScript source code
|
|
183
|
-
* @param
|
|
184
|
-
* @param maxGeneratedFunctions - Max helper functions before error (0 = default 50)
|
|
185
|
+
* @param options - Optional transform options
|
|
185
186
|
* @returns Transformed code with validation
|
|
186
187
|
*/
|
|
187
|
-
async transformSource(fileName, source,
|
|
188
|
+
async transformSource(fileName, source, options) {
|
|
188
189
|
return this.request("transformSource", {
|
|
189
190
|
fileName,
|
|
190
191
|
source,
|
|
191
|
-
ignoreTypes,
|
|
192
|
-
maxGeneratedFunctions
|
|
192
|
+
ignoreTypes: options?.ignoreTypes,
|
|
193
|
+
maxGeneratedFunctions: options?.maxGeneratedFunctions,
|
|
194
|
+
reusableValidators: options?.reusableValidators
|
|
193
195
|
});
|
|
194
196
|
}
|
|
195
197
|
async request(method, payload) {
|
|
@@ -235,11 +237,11 @@ var TypicalCompiler = class {
|
|
|
235
237
|
/**
|
|
236
238
|
* Synchronous wrapper around the async compiler transformFile.
|
|
237
239
|
*/
|
|
238
|
-
function transformFileSync(compiler, project, fileName) {
|
|
240
|
+
function transformFileSync(compiler, project, fileName, config) {
|
|
239
241
|
let result;
|
|
240
242
|
let error;
|
|
241
243
|
let done = false;
|
|
242
|
-
compiler.transformFile(project, fileName).then((res) => {
|
|
244
|
+
compiler.transformFile(project, fileName, config.ignoreTypes, config.maxGeneratedFunctions, config.reusableValidators).then((res) => {
|
|
243
245
|
result = res.code;
|
|
244
246
|
done = true;
|
|
245
247
|
}, (err) => {
|
|
@@ -267,7 +269,7 @@ function transformFileSync(compiler, project, fileName) {
|
|
|
267
269
|
* }
|
|
268
270
|
*/
|
|
269
271
|
function src_default(program, host, _pluginConfig, { ts: tsInstance }) {
|
|
270
|
-
validateConfig(loadConfig());
|
|
272
|
+
const config = validateConfig(loadConfig());
|
|
271
273
|
const compiler = new TypicalCompiler({ cwd: process.cwd() });
|
|
272
274
|
let projectHandle;
|
|
273
275
|
let initError;
|
|
@@ -287,7 +289,7 @@ function src_default(program, host, _pluginConfig, { ts: tsInstance }) {
|
|
|
287
289
|
for (const sourceFile of program.getSourceFiles()) {
|
|
288
290
|
if (sourceFile.isDeclarationFile || sourceFile.fileName.includes("node_modules")) continue;
|
|
289
291
|
try {
|
|
290
|
-
const transformed = transformFileSync(compiler, projectHandle, sourceFile.fileName);
|
|
292
|
+
const transformed = transformFileSync(compiler, projectHandle, sourceFile.fileName, config);
|
|
291
293
|
transformedFiles.set(sourceFile.fileName, transformed);
|
|
292
294
|
} catch (err) {
|
|
293
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
|
},
|