@imaginary-dev/typescript-transformer
Advanced tools
Comparing version 0.0.3 to 0.0.4
@@ -42,5 +42,8 @@ "use strict"; | ||
lib: ["es2015"], | ||
extendedDiagnostics: true, | ||
exclude: ["**/node_modules"], | ||
}; | ||
const makePathAbsolute = (relativePath) => (0, path_1.resolve)(process.cwd(), relativePath); | ||
function compileProject(project) { | ||
const nodeModulesASTCache = {}; | ||
// normalize the paths. | ||
@@ -51,2 +54,3 @@ const normalizedProjectFiles = Object.fromEntries(Object.entries(project.projectFiles).map(([key, value]) => [ | ||
])); | ||
const normalizedProjectFilenames = Object.keys(normalizedProjectFiles); | ||
const normalizedRootFiles = project.rootFiles.map(makePathAbsolute); | ||
@@ -58,3 +62,3 @@ // Create a Program with an in-memory emit | ||
host.fileExists = (fileName) => { | ||
if (Object.keys(normalizedProjectFiles).indexOf(fileName) !== -1) { | ||
if (normalizedProjectFilenames.indexOf(fileName) !== -1) { | ||
return true; | ||
@@ -64,10 +68,27 @@ } | ||
}; | ||
const originalGetSourceFile = host.getSourceFile; | ||
host.getSourceFile = (fileName, ...rest) => { | ||
if (fileName.includes("/node_modules/")) { | ||
// only cache files in node_modules | ||
if (fileName in nodeModulesASTCache) { | ||
return nodeModulesASTCache[fileName]; | ||
} | ||
const sourceFile = originalGetSourceFile.apply(host, [fileName, ...rest]); | ||
nodeModulesASTCache[fileName] = sourceFile; | ||
return sourceFile; | ||
} | ||
else { | ||
// never cache local files | ||
return originalGetSourceFile.apply(host, [fileName, ...rest]); | ||
} | ||
}; | ||
host.readFile = (fileName) => { | ||
// we need to make sure that ts compiler can get to the real node_modules so it | ||
// can find .d.ts files for things like Promise. | ||
if (fileName.match(/node_modules/)) { | ||
return (0, fs_1.readFileSync)(fileName, { encoding: "utf-8" }); | ||
if (fileName.includes("/node_modules/")) { | ||
const fileBody = (0, fs_1.readFileSync)(fileName, { encoding: "utf-8" }); | ||
return fileBody; | ||
} | ||
// if it's one of the files we are compiling, return the contents. | ||
if (Object.keys(normalizedProjectFiles).indexOf(fileName) !== -1) { | ||
if (normalizedProjectFilenames.indexOf(fileName) !== -1) { | ||
return normalizedProjectFiles[fileName]; | ||
@@ -82,5 +103,22 @@ } | ||
const program = ts.createProgram(normalizedRootFiles, compilerOptions, host); | ||
program.emit(undefined, undefined, undefined, undefined, { | ||
before: [(0, ts_prompt_transformer_1.default)(program)], | ||
const sourceFiles = program.getSourceFiles().filter((f) => { | ||
const absoluteSourceFile = makePathAbsolute(f.fileName); | ||
return (normalizedRootFiles.includes(absoluteSourceFile) || | ||
normalizedProjectFilenames.includes(absoluteSourceFile)); | ||
}); | ||
sourceFiles.forEach((sourceFile) => { | ||
const result = program.emit(sourceFile, undefined, undefined, undefined, { | ||
before: [(0, ts_prompt_transformer_1.default)(program)], | ||
}); | ||
const diagnostics = ts | ||
.getPreEmitDiagnostics(program) | ||
.concat(result.diagnostics); | ||
diagnostics.forEach((diagnostic) => { | ||
const { line, character } = diagnostic.file?.getLineAndCharacterOfPosition(diagnostic.start) ?? { | ||
line: -1, | ||
character: -1, | ||
}; | ||
const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n"); | ||
}); | ||
}); | ||
return { | ||
@@ -87,0 +125,0 @@ compiledFiles: createdFiles, |
@@ -41,4 +41,7 @@ "use strict"; | ||
return (sourceFile) => { | ||
if (sourceFile.fileName.includes("node_modules/")) { | ||
return sourceFile; | ||
} | ||
const promptEngineIdentifier = ts.factory.createUniqueName("promptEngine"); | ||
let addedImports = false; | ||
const promptEngineIdentifier = ts.factory.createUniqueName("promptEngine"); | ||
const visitor = (node) => { | ||
@@ -45,0 +48,0 @@ if (ts.isFunctionDeclaration(node)) { |
@@ -30,2 +30,5 @@ "use strict"; | ||
} | ||
if (jsonSchema.type === "integer") { | ||
return "number"; | ||
} | ||
// recursive types | ||
@@ -32,0 +35,0 @@ if (jsonSchema.type === "array" && typeof jsonSchema.items === "object") { |
{ | ||
"name": "@imaginary-dev/typescript-transformer", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "A TypeScript plugin for transforming imaginary functions", | ||
@@ -13,10 +13,11 @@ "files": [ | ||
"full-clean": "npm run clean && rm -rf node_modules", | ||
"test": "jest" | ||
"test": "jest", | ||
"coverage": "jest --coverage" | ||
}, | ||
"author": "Sasha Aickin", | ||
"license": "UNLICENSED", | ||
"license": "MIT", | ||
"dependencies": { | ||
"@microsoft/tsdoc": "^0.14.2", | ||
"ajv": "^8.12.0", | ||
"@imaginary-dev/util": "^0.0.3" | ||
"@imaginary-dev/util": "*" | ||
}, | ||
@@ -29,6 +30,3 @@ "devDependencies": { | ||
"extends": "../../package.json" | ||
}, | ||
"publishConfig": { | ||
"access": "restricted" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Wildcard dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
Found 1 instance in 1 package
Misc. License Issues
License(Experimental) A package's licensing information has fine-grained problems.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
155775
46
0
1893
196
+ Added@imaginary-dev/util@0.0.5(transitive)
- Removed@imaginary-dev/util@0.0.3(transitive)
Updated@imaginary-dev/util@*