@appthreat/atom 0.10.1 → 0.12.0

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.
Files changed (23) hide show
  1. package/astgen.js +29 -101
  2. package/index.js +63 -39
  3. package/package.json +6 -4
  4. package/plugins/atom-1.0.0/lib/{com.fasterxml.jackson.core.jackson-annotations-2.15.1.jar → com.fasterxml.jackson.core.jackson-annotations-2.15.2.jar} +0 -0
  5. package/plugins/atom-1.0.0/lib/{com.fasterxml.jackson.core.jackson-core-2.15.1.jar → com.fasterxml.jackson.core.jackson-core-2.15.2.jar} +0 -0
  6. package/plugins/atom-1.0.0/lib/{com.fasterxml.jackson.core.jackson-databind-2.15.1.jar → com.fasterxml.jackson.core.jackson-databind-2.15.2.jar} +0 -0
  7. package/plugins/atom-1.0.0/lib/io.appthreat.atom-1.0.0-classpath.jar +0 -0
  8. package/plugins/atom-1.0.0/lib/io.appthreat.atom-1.0.0.jar +0 -0
  9. package/plugins/atom-1.0.0/lib/{io.joern.c2cpg_3-1.2.26.jar → io.joern.c2cpg_3-2.0.8.jar} +0 -0
  10. package/plugins/atom-1.0.0/lib/io.joern.dataflowengineoss_3-2.0.8.jar +0 -0
  11. package/plugins/atom-1.0.0/lib/{io.joern.javasrc2cpg_3-1.2.26.jar → io.joern.javasrc2cpg_3-2.0.8.jar} +0 -0
  12. package/plugins/atom-1.0.0/lib/{io.joern.jimple2cpg_3-1.2.26.jar → io.joern.jimple2cpg_3-2.0.8.jar} +0 -0
  13. package/plugins/atom-1.0.0/lib/{io.joern.jssrc2cpg_3-1.2.26.jar → io.joern.jssrc2cpg_3-2.0.8.jar} +0 -0
  14. package/plugins/atom-1.0.0/lib/{io.joern.pysrc2cpg_3-1.2.26.jar → io.joern.pysrc2cpg_3-2.0.8.jar} +0 -0
  15. package/plugins/atom-1.0.0/lib/{io.joern.semanticcpg_3-1.2.26.jar → io.joern.semanticcpg_3-2.0.8.jar} +0 -0
  16. package/plugins/atom-1.0.0/lib/{io.joern.x2cpg_3-1.2.26.jar → io.joern.x2cpg_3-2.0.8.jar} +0 -0
  17. package/plugins/atom-1.0.0/lib/{io.shiftleft.codepropertygraph-domain-classes_3-1.3.612.jar → io.shiftleft.codepropertygraph-domain-classes_3-1.4.1.jar} +0 -0
  18. package/plugins/atom-1.0.0/lib/{io.shiftleft.codepropertygraph-protos_3-1.3.612.jar → io.shiftleft.codepropertygraph-protos_3-1.4.1.jar} +0 -0
  19. package/plugins/atom-1.0.0/lib/{io.shiftleft.codepropertygraph_3-1.3.612.jar → io.shiftleft.codepropertygraph_3-1.4.1.jar} +0 -0
  20. package/plugins/atom-1.0.0/lib/{org.gradle.gradle-tooling-api-7.6.1.jar → org.gradle.gradle-tooling-api-7.6.2.jar} +0 -0
  21. package/utils.mjs +84 -0
  22. package/.eslintrc.js +0 -15
  23. package/plugins/atom-1.0.0/lib/io.joern.dataflowengineoss_3-1.2.26.jar +0 -0
package/astgen.js CHANGED
@@ -1,85 +1,22 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- const path = require("path");
4
- const yargs = require("yargs");
5
- const { hideBin } = require("yargs/helpers");
6
- const babelParser = require("@babel/parser");
7
- const tsc = require("typescript");
8
- const fs = require("fs");
3
+ import { join, dirname } from "path";
4
+ import yargs from "yargs";
5
+ import { hideBin } from "yargs/helpers";
6
+ import { parse } from "@babel/parser";
7
+ import tsc from "typescript";
8
+ import {
9
+ readFileSync,
10
+ mkdirSync,
11
+ writeFileSync,
12
+ accessSync,
13
+ constants,
14
+ existsSync
15
+ } from "fs";
16
+ import { getAllFiles } from "./utils.mjs";
9
17
 
10
18
  const ASTGEN_VERSION = "3.1.0";
11
19
 
12
- const IGNORE_DIRS = [
13
- "node_modules",
14
- "venv",
15
- "docs",
16
- "test",
17
- "tests",
18
- "e2e",
19
- "e2e-beta",
20
- "examples",
21
- "cypress",
22
- "jest-cache",
23
- "eslint-rules",
24
- "codemods",
25
- "flow-typed",
26
- "i18n",
27
- "vendor",
28
- "www",
29
- "dist",
30
- "build"
31
- ];
32
-
33
- const IGNORE_FILE_PATTERN = new RegExp(
34
- "(conf|test|spec|\\.d)\\.(js|ts|jsx|tsx)$",
35
- "i"
36
- );
37
-
38
- const getAllFiles = (dir, extn, files, result, regex) => {
39
- files = files || fs.readdirSync(dir);
40
- result = result || [];
41
- regex = regex || new RegExp(`\\${extn}$`);
42
-
43
- for (let i = 0; i < files.length; i++) {
44
- const file = files[i];
45
- if (
46
- file.startsWith(".") ||
47
- file.startsWith("__") ||
48
- IGNORE_FILE_PATTERN.test(file)
49
- ) {
50
- continue;
51
- }
52
- const fileWithDir = path.join(dir, file);
53
- if (fs.statSync(fileWithDir).isDirectory()) {
54
- // Ignore directories
55
- const dirName = path.basename(fileWithDir);
56
- if (
57
- dirName.startsWith(".") ||
58
- dirName.startsWith("__") ||
59
- IGNORE_DIRS.includes(dirName.toLowerCase())
60
- ) {
61
- continue;
62
- }
63
- try {
64
- result = getAllFiles(
65
- fileWithDir,
66
- extn,
67
- fs.readdirSync(fileWithDir),
68
- result,
69
- regex
70
- );
71
- } catch (error) {
72
- // ignore
73
- }
74
- } else {
75
- if (regex.test(fileWithDir)) {
76
- result.push(fileWithDir);
77
- }
78
- }
79
- }
80
- return result;
81
- };
82
-
83
20
  const babelParserOptions = {
84
21
  sourceType: "unambiguous",
85
22
  allowImportExportEverywhere: true,
@@ -138,15 +75,9 @@ const getAllSrcJSAndTSFiles = (src) =>
138
75
  */
139
76
  const fileToJsAst = (file) => {
140
77
  try {
141
- return babelParser.parse(
142
- fs.readFileSync(file, "utf-8"),
143
- babelParserOptions
144
- );
78
+ return parse(readFileSync(file, "utf-8"), babelParserOptions);
145
79
  } catch {
146
- return babelParser.parse(
147
- fs.readFileSync(file, "utf-8"),
148
- babelSafeParserOptions
149
- );
80
+ return parse(readFileSync(file, "utf-8"), babelSafeParserOptions);
150
81
  }
151
82
  };
152
83
 
@@ -155,9 +86,9 @@ const fileToJsAst = (file) => {
155
86
  */
156
87
  const codeToJsAst = (code) => {
157
88
  try {
158
- return babelParser.parse(code, babelParserOptions);
89
+ return parse(code, babelParserOptions);
159
90
  } catch {
160
- return babelParser.parse(code, babelSafeParserOptions);
91
+ return parse(code, babelSafeParserOptions);
161
92
  }
162
93
  };
163
94
 
@@ -171,7 +102,7 @@ const vuePropRegex = /\s([.:@])([a-zA-Z]*?=)/gi;
171
102
  * Convert a single vue file to AST
172
103
  */
173
104
  const toVueAst = (file) => {
174
- const code = fs.readFileSync(file, "utf-8");
105
+ const code = readFileSync(file, "utf-8");
175
106
  const cleanedCode = code
176
107
  .replace(vueCommentRegex, function (match) {
177
108
  return match.replaceAll(/\S/g, " ");
@@ -358,25 +289,22 @@ const getCircularReplacer = () => {
358
289
  */
359
290
  const writeAstFile = (file, ast, options) => {
360
291
  const relativePath = file.replace(new RegExp("^" + options.src + "/"), "");
361
- const outAstFile = path.join(options.output, relativePath + ".json");
292
+ const outAstFile = join(options.output, relativePath + ".json");
362
293
  const data = {
363
294
  fullName: file,
364
295
  relativeName: relativePath,
365
296
  ast: ast
366
297
  };
367
- fs.mkdirSync(path.dirname(outAstFile), { recursive: true });
368
- fs.writeFileSync(
369
- outAstFile,
370
- JSON.stringify(data, getCircularReplacer(), " ")
371
- );
298
+ mkdirSync(dirname(outAstFile), { recursive: true });
299
+ writeFileSync(outAstFile, JSON.stringify(data, getCircularReplacer(), " "));
372
300
  console.log("Converted AST for", relativePath, "to", outAstFile);
373
301
  };
374
302
 
375
303
  const writeTypesFile = (file, seenTypes, options) => {
376
304
  const relativePath = file.replace(new RegExp("^" + options.src + "/"), "");
377
- const outTypeFile = path.join(options.output, relativePath + ".typemap");
378
- fs.mkdirSync(path.dirname(outTypeFile), { recursive: true });
379
- fs.writeFileSync(
305
+ const outTypeFile = join(options.output, relativePath + ".typemap");
306
+ mkdirSync(dirname(outTypeFile), { recursive: true });
307
+ writeFileSync(
380
308
  outTypeFile,
381
309
  JSON.stringify(Object.fromEntries(seenTypes), undefined, " ")
382
310
  );
@@ -386,14 +314,14 @@ const writeTypesFile = (file, seenTypes, options) => {
386
314
  const createXAst = async (options) => {
387
315
  const src_dir = options.src;
388
316
  try {
389
- fs.accessSync(src_dir, fs.constants.R_OK);
317
+ accessSync(src_dir, constants.R_OK);
390
318
  } catch (err) {
391
319
  console.error(src_dir, "is invalid");
392
320
  process.exit(1);
393
321
  }
394
322
  if (
395
- fs.existsSync(path.join(src_dir, "package.json")) ||
396
- fs.existsSync(path.join(src_dir, "rush.json"))
323
+ existsSync(join(src_dir, "package.json")) ||
324
+ existsSync(join(src_dir, "rush.json"))
397
325
  ) {
398
326
  return await createJSAst(options);
399
327
  }
@@ -463,7 +391,7 @@ async function main(argvs) {
463
391
 
464
392
  try {
465
393
  if (args.output === "ast_out") {
466
- args.output = path.join(args.src, args.output);
394
+ args.output = join(args.src, args.output);
467
395
  }
468
396
  await start(args);
469
397
  } catch (e) {
package/index.js CHANGED
@@ -1,51 +1,75 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- const os = require("os");
4
- const path = require("path");
5
- const { spawnSync } = require("child_process");
6
- const isWin = require("os").platform() === "win32";
7
- const LOG4J_CONFIG = path.join(__dirname, "plugins", "log4j2.xml");
8
- const ATOM_HOME = path.join(__dirname, "plugins", "atom-1.0.0");
9
- const APP_LIB_DIR = path.join(ATOM_HOME, "lib");
10
- const freeMemoryGB = Math.floor(os.freemem() / 1024 / 1024 / 1024);
3
+ import { freemem, platform as _platform } from "node:os";
4
+ import { dirname, join, delimiter } from "node:path";
5
+ import { spawnSync } from "node:child_process";
6
+ import { fileURLToPath } from "node:url";
7
+ import { detectJava } from "./utils.mjs";
8
+
9
+ const isWin = _platform() === "win32";
10
+ let url = import.meta.url;
11
+ if (!url.startsWith("file://")) {
12
+ url = new URL(`file://${import.meta.url}`).toString();
13
+ }
14
+ const dirName = import.meta ? dirname(fileURLToPath(url)) : __dirname;
15
+
16
+ const LOG4J_CONFIG = join(dirName, "plugins", "log4j2.xml");
17
+ const ATOM_HOME = join(dirName, "plugins", "atom-1.0.0");
18
+ const APP_LIB_DIR = join(ATOM_HOME, "lib");
19
+ const freeMemoryGB = Math.floor(freemem() / 1024 / 1024 / 1024);
20
+ const JVM_ARGS =
21
+ "-XX:+UseG1GC -XX:+ExplicitGCInvokesConcurrent -XX:+ParallelRefProcEnabled -XX:+UseStringDeduplication -XX:+UnlockExperimentalVMOptions -XX:G1NewSizePercent=20 -XX:+UnlockDiagnosticVMOptions -XX:G1SummarizeRSetStatsPeriod=1";
11
22
  const JAVA_OPTS = `${process.env.JAVA_OPTS || ""} -Xms${Math.round(
12
23
  Math.floor(freeMemoryGB / 2)
13
- )}G -Xmx${freeMemoryGB}G -XX:+UseG1GC -XX:+ExplicitGCInvokesConcurrent -XX:+ParallelRefProcEnabled -XX:+UseStringDeduplication -XX:+UnlockExperimentalVMOptions -XX:G1NewSizePercent=20 -XX:+UnlockDiagnosticVMOptions -XX:G1SummarizeRSetStatsPeriod=1`;
24
+ )}G -Xmx${freeMemoryGB}G ${JVM_ARGS}`;
14
25
  const APP_MAIN_CLASS = "io.appthreat.atom.Atom";
15
- let APP_CLASSPATH = path.join(
16
- APP_LIB_DIR,
17
- "io.appthreat.atom-1.0.0-classpath.jar"
18
- );
26
+ let APP_CLASSPATH = join(APP_LIB_DIR, "io.appthreat.atom-1.0.0-classpath.jar");
19
27
  let JAVACMD = "java";
20
28
  if (process.env.JAVA_HOME) {
21
- JAVACMD = path.join(
22
- process.env.JAVA_HOME,
23
- "bin",
24
- "java" + (isWin ? ".exe" : "")
25
- );
29
+ JAVACMD = join(process.env.JAVA_HOME, "bin", "java" + (isWin ? ".exe" : ""));
26
30
  }
27
31
 
28
32
  const atomLibs = [APP_CLASSPATH];
29
33
  const argv = process.argv.slice(2);
30
- let args = JAVA_OPTS.trim()
31
- .split(" ")
32
- .concat([
33
- "-cp",
34
- atomLibs.join(path.delimiter),
35
- `-Dlog4j.configurationFile=${LOG4J_CONFIG}`,
36
- APP_MAIN_CLASS,
37
- ...argv
38
- ]);
39
- const env = {
40
- ...process.env,
41
- ATOM_HOME
34
+
35
+ const executeAtom = (atomArgs) => {
36
+ if (!detectJava()) {
37
+ // If we couldn't detect java but there is a JAVA_HOME defined then
38
+ // try fixing the PATH manually. Usually required for windows users
39
+ if (process.env.JAVA_HOME) {
40
+ process.env.PATH =
41
+ process.env.PATH +
42
+ delimiter +
43
+ join(process.env.JAVA_HOME, "bin") +
44
+ delimiter;
45
+ } else {
46
+ console.warn(
47
+ "A Java JDK is not installed or can't be found. Please install JDK version 17 or higher before running atom."
48
+ );
49
+ return false;
50
+ }
51
+ }
52
+ let args = JAVA_OPTS.trim()
53
+ .split(" ")
54
+ .concat([
55
+ "-cp",
56
+ atomLibs.join(delimiter),
57
+ `-Dlog4j.configurationFile=${LOG4J_CONFIG}`,
58
+ APP_MAIN_CLASS,
59
+ ...atomArgs
60
+ ]);
61
+ const env = {
62
+ ...process.env,
63
+ ATOM_HOME
64
+ };
65
+ const cwd = process.env.ATOM_CWD || process.cwd();
66
+ spawnSync(JAVACMD, args, {
67
+ encoding: "utf-8",
68
+ env,
69
+ cwd,
70
+ stdio: "inherit",
71
+ stderr: "inherit",
72
+ timeout: process.env.ATOM_TIMEOUT
73
+ });
42
74
  };
43
- const cwd = process.env.ATOM_CWD || process.cwd();
44
- spawnSync(JAVACMD, args, {
45
- encoding: "utf-8",
46
- env,
47
- cwd,
48
- stdio: "inherit",
49
- stderr: "inherit",
50
- timeout: undefined
51
- });
75
+ executeAtom(argv);
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "@appthreat/atom",
3
- "version": "0.10.1",
3
+ "version": "0.12.0",
4
4
  "description": "Create atom (⚛) representation for your application, packages and libraries",
5
- "main": "index.js",
5
+ "exports": "./index.js",
6
+ "type": "module",
6
7
  "scripts": {
7
- "pretty": "prettier --write *.js --trailing-comma=none",
8
- "lint": "eslint *.js"
8
+ "pretty": "prettier --write *.mjs *.js --trailing-comma=none",
9
+ "lint": "eslint *.mjs *.js"
9
10
  },
10
11
  "dependencies": {
11
12
  "@babel/parser": "^7.22.5",
@@ -42,6 +43,7 @@
42
43
  "homepage": "https://github.com/AppThreat/atom#readme",
43
44
  "files": [
44
45
  "*.js",
46
+ "*.mjs",
45
47
  "plugins/"
46
48
  ]
47
49
  }
package/utils.mjs ADDED
@@ -0,0 +1,84 @@
1
+ import { join, basename } from "node:path";
2
+ import { readdirSync, statSync } from "node:fs";
3
+ import { spawnSync } from "node:child_process";
4
+
5
+ const IGNORE_DIRS = [
6
+ "node_modules",
7
+ "venv",
8
+ "docs",
9
+ "test",
10
+ "tests",
11
+ "e2e",
12
+ "e2e-beta",
13
+ "examples",
14
+ "cypress",
15
+ "jest-cache",
16
+ "eslint-rules",
17
+ "codemods",
18
+ "flow-typed",
19
+ "i18n",
20
+ "vendor",
21
+ "www",
22
+ "dist",
23
+ "build"
24
+ ];
25
+
26
+ const IGNORE_FILE_PATTERN = new RegExp(
27
+ "(conf|test|spec|\\.d)\\.(js|ts|jsx|tsx)$",
28
+ "i"
29
+ );
30
+
31
+ export const getAllFiles = (dir, extn, files, result, regex) => {
32
+ files = files || readdirSync(dir);
33
+ result = result || [];
34
+ regex = regex || new RegExp(`\\${extn}$`);
35
+
36
+ for (let i = 0; i < files.length; i++) {
37
+ const file = files[i];
38
+ if (
39
+ file.startsWith(".") ||
40
+ file.startsWith("__") ||
41
+ IGNORE_FILE_PATTERN.test(file)
42
+ ) {
43
+ continue;
44
+ }
45
+ const fileWithDir = join(dir, file);
46
+ if (statSync(fileWithDir).isDirectory()) {
47
+ // Ignore directories
48
+ const dirName = basename(fileWithDir);
49
+ if (
50
+ dirName.startsWith(".") ||
51
+ dirName.startsWith("__") ||
52
+ IGNORE_DIRS.includes(dirName.toLowerCase())
53
+ ) {
54
+ continue;
55
+ }
56
+ try {
57
+ result = getAllFiles(
58
+ fileWithDir,
59
+ extn,
60
+ readdirSync(fileWithDir),
61
+ result,
62
+ regex
63
+ );
64
+ } catch (error) {
65
+ // ignore
66
+ }
67
+ } else {
68
+ if (regex.test(fileWithDir)) {
69
+ result.push(fileWithDir);
70
+ }
71
+ }
72
+ }
73
+ return result;
74
+ };
75
+
76
+ export const detectJava = () => {
77
+ let result = spawnSync(process.env.JAVA_CMD || "java", ["-version"], {
78
+ encoding: "utf-8"
79
+ });
80
+ if (result.status !== 0 || result.error) {
81
+ return false;
82
+ }
83
+ return true;
84
+ };
package/.eslintrc.js DELETED
@@ -1,15 +0,0 @@
1
- module.exports = {
2
- "env": {
3
- "node": true,
4
- "commonjs": true,
5
- "es2021": true
6
- },
7
- "extends": "eslint:recommended",
8
- "overrides": [
9
- ],
10
- "parserOptions": {
11
- "ecmaVersion": "latest"
12
- },
13
- "rules": {
14
- }
15
- }