New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@imaginary-dev/typescript-transformer

Package Overview
Dependencies
Maintainers
2
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@imaginary-dev/typescript-transformer - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

README.md

50

dist/transformers/typescript/src/tests/ts-compiler.js

@@ -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,

5

dist/transformers/typescript/src/ts-prompt-transformer.js

@@ -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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc