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

akitainu-checker-typescript

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

akitainu-checker-typescript - npm Package Compare versions

Comparing version 0.1.0-alpha.3 to 0.1.0-alpha.5

23

dist/index.js

@@ -6,5 +6,6 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
const minimatch_1 = require("minimatch");
const glob_1 = require("glob");
const path_1 = __importDefault(require("path"));
const typescript_1 = __importDefault(require("typescript"));
const util_1 = require("util");
function typescriptChecker({ tsconfig, compilerOptions, }) {

@@ -34,2 +35,12 @@ const checker = {

}
// innvoke search of targetFiles
// TODO: delaying await may not be really meaning here, without spilling out type checkign to another thread
const targetFilesResultP = targetFiles &&
targetFiles.length > 0 &&
(0, util_1.promisify)(glob_1.glob)(targetFiles.length > 1
? `{${targetFiles.join(",")}}`
: targetFiles[0], {
cwd: baseDirectory,
absolute: true,
});
const program = typescript_1.default.createProgram({

@@ -45,7 +56,4 @@ rootNames: (_b = (_a = parsedCommandLine === null || parsedCommandLine === void 0 ? void 0 : parsedCommandLine.fileNames) !== null && _a !== void 0 ? _a : targetFiles) !== null && _b !== void 0 ? _b : [],

.concat(emitResult.diagnostics);
const fileFilter = targetFiles &&
targetFiles.length > 0 &&
new minimatch_1.Minimatch(targetFiles.length > 1
? `{${targetFiles.join(",")}}`
: targetFiles[0]);
const targetFilesResult = await targetFilesResultP;
const fileFilter = targetFilesResult && new Set(targetFilesResult);
const errors = allDiagnostics.flatMap((d) => {

@@ -63,4 +71,3 @@ const { file, start = 0 } = d;

}
const fileName = path_1.default.relative(baseDirectory, file.fileName);
if (fileFilter && !fileFilter.match(fileName)) {
if (fileFilter && !fileFilter.has(file.fileName)) {
return [];

@@ -67,0 +74,0 @@ }

@@ -89,2 +89,23 @@ "use strict";

});
it("filtering by absolute path", async () => {
const projectDir = path_1.default.resolve(__dirname, "..", "test-fixtures/project1");
const checker = (0, _1.default)({
tsconfig: path_1.default.join(projectDir, "tsconfig.json"),
});
const { errors } = await checker.run({
targetFiles: [path_1.default.join(projectDir, "src/foo.ts")],
baseDirectory: projectDir,
});
expect(errors).toEqual([
{
code: "TS2322",
location: {
file: "src/foo.ts",
line: 1,
column: 14,
},
message: "Type 'number' is not assignable to type 'string'.",
},
]);
});
});
{
"name": "akitainu-checker-typescript",
"version": "0.1.0-alpha.3",
"version": "0.1.0-alpha.5",
"description": "TypeScript checker for Akitainu",

@@ -26,4 +26,4 @@ "main": "dist/index.js",

"@babel/preset-typescript": "^7.13.0",
"@types/glob": "^7.1.3",
"@types/jest": "^26.0.22",
"@types/minimatch": "^3.0.4",
"babel-jest": "^26.6.3",

@@ -38,4 +38,4 @@ "jest": "^26.6.3",

"dependencies": {
"minimatch": "^3.0.4"
"glob": "^7.1.6"
}
}

@@ -85,2 +85,23 @@ import path from "path";

});
it("filtering by absolute path", async () => {
const projectDir = path.resolve(__dirname, "..", "test-fixtures/project1");
const checker = typescriptChecker({
tsconfig: path.join(projectDir, "tsconfig.json"),
});
const { errors } = await checker.run({
targetFiles: [path.join(projectDir, "src/foo.ts")],
baseDirectory: projectDir,
});
expect(errors).toEqual([
{
code: "TS2322",
location: {
file: "src/foo.ts",
line: 1,
column: 14,
},
message: "Type 'number' is not assignable to type 'string'.",
},
]);
});
});
import { Checker, CheckError } from "akitainu";
import { Minimatch } from "minimatch";
import { glob } from "glob";
import path from "path";
import ts from "typescript";
import { promisify } from "util";

@@ -46,2 +47,18 @@ type TypeScriptCheckerOptions = {

}
// innvoke search of targetFiles
// TODO: delaying await may not be really meaning here, without spilling out type checkign to another thread
const targetFilesResultP =
targetFiles &&
targetFiles.length > 0 &&
promisify(glob)(
targetFiles.length > 1
? `{${targetFiles.join(",")}}`
: (targetFiles[0] as string),
{
cwd: baseDirectory,
absolute: true,
}
);
const program = ts.createProgram({

@@ -58,10 +75,5 @@ rootNames: parsedCommandLine?.fileNames ?? targetFiles ?? [],

const fileFilter =
targetFiles &&
targetFiles.length > 0 &&
new Minimatch(
targetFiles.length > 1
? `{${targetFiles.join(",")}}`
: (targetFiles[0] as string)
);
const targetFilesResult = await targetFilesResultP;
const fileFilter = targetFilesResult && new Set(targetFilesResult);
const errors: CheckError[] = allDiagnostics.flatMap((d) => {

@@ -79,4 +91,3 @@ const { file, start = 0 } = d;

}
const fileName = path.relative(baseDirectory, file.fileName);
if (fileFilter && !fileFilter.match(fileName)) {
if (fileFilter && !fileFilter.has(file.fileName)) {
return [];

@@ -83,0 +94,0 @@ }

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