@nodesecure/js-x-ray 8.1.1 → 8.2.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.
package/README.md CHANGED
@@ -161,7 +161,7 @@ $ yarn add @nodesecure/estree-ast-util
161
161
  ## Contributors ✨
162
162
 
163
163
  <!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
164
- [![All Contributors](https://img.shields.io/badge/all_contributors-18-orange.svg?style=flat-square)](#contributors-)
164
+ [![All Contributors](https://img.shields.io/badge/all_contributors-19-orange.svg?style=flat-square)](#contributors-)
165
165
  <!-- ALL-CONTRIBUTORS-BADGE:END -->
166
166
 
167
167
  Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
@@ -194,6 +194,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
194
194
  <td align="center" valign="top" width="14.28%"><a href="https://github.com/madina0801"><img src="https://avatars.githubusercontent.com/u/101329759?v=4?s=100" width="100px;" alt="Madina"/><br /><sub><b>Madina</b></sub></a><br /><a href="https://github.com/NodeSecure/js-x-ray/commits?author=madina0801" title="Code">💻</a></td>
195
195
  <td align="center" valign="top" width="14.28%"><a href="https://github.com/sairuss7"><img src="https://avatars.githubusercontent.com/u/87803528?v=4?s=100" width="100px;" alt="SairussDev"/><br /><sub><b>SairussDev</b></sub></a><br /><a href="https://github.com/NodeSecure/js-x-ray/commits?author=sairuss7" title="Code">💻</a></td>
196
196
  <td align="center" valign="top" width="14.28%"><a href="https://github.com/fless-lab"><img src="https://avatars.githubusercontent.com/u/71844440?v=4?s=100" width="100px;" alt="Abdou-Raouf ATARMLA"/><br /><sub><b>Abdou-Raouf ATARMLA</b></sub></a><br /><a href="https://github.com/NodeSecure/js-x-ray/commits?author=fless-lab" title="Code">💻</a></td>
197
+ <td align="center" valign="top" width="14.28%"><a href="https://clementgombauld.netlify.app/"><img src="https://avatars.githubusercontent.com/u/91478082?v=4?s=100" width="100px;" alt="Clement Gombauld"/><br /><sub><b>Clement Gombauld</b></sub></a><br /><a href="https://github.com/NodeSecure/js-x-ray/commits?author=clemgbld" title="Code">💻</a> <a href="https://github.com/NodeSecure/js-x-ray/commits?author=clemgbld" title="Tests">⚠️</a></td>
197
198
  </tr>
198
199
  </tbody>
199
200
  </table>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nodesecure/js-x-ray",
3
- "version": "8.1.1",
3
+ "version": "8.2.0",
4
4
  "description": "JavaScript AST XRay analysis",
5
5
  "type": "module",
6
6
  "exports": "./index.js",
@@ -78,6 +78,7 @@ export class AstAnalyser {
78
78
  return {
79
79
  ...source.getResult(isMinified),
80
80
  dependencies: source.dependencies,
81
+ flags: source.flags,
81
82
  isOneLineRequire: isOneLineExpressionExport(body)
82
83
  };
83
84
  }
@@ -115,6 +116,7 @@ export class AstAnalyser {
115
116
  ok: true,
116
117
  dependencies: data.dependencies,
117
118
  warnings: data.warnings,
119
+ flags: data.flags,
118
120
  isMinified: !data.isOneLineRequire && isMin
119
121
  };
120
122
  }
@@ -19,7 +19,8 @@ export class EntryFilesAnalyser {
19
19
  const {
20
20
  astAnalyzer = new AstAnalyser(),
21
21
  loadExtensions,
22
- rootPath = null
22
+ rootPath = null,
23
+ ignoreENOENT = false
23
24
  } = options;
24
25
 
25
26
  this.astAnalyzer = astAnalyzer;
@@ -30,6 +31,7 @@ export class EntryFilesAnalyser {
30
31
  this.allowedExtensions = new Set(rawAllowedExtensions);
31
32
  this.#rootPath = options.rootPath === null ?
32
33
  null : fileURLToPathExtended(rootPath);
34
+ this.ignoreENOENT = ignoreENOENT;
33
35
  }
34
36
 
35
37
  async* analyse(
@@ -43,6 +45,10 @@ export class EntryFilesAnalyser {
43
45
  fileURLToPathExtended(entryFile)
44
46
  );
45
47
 
48
+ if (this.ignoreENOENT && !await this.#fileExists(normalizedEntryFile)) {
49
+ return;
50
+ }
51
+
46
52
  yield* this.#analyseFile(
47
53
  normalizedEntryFile,
48
54
  this.#getRelativeFilePath(normalizedEntryFile),
@@ -12,6 +12,7 @@ import isWeakCrypto from "./probes/isWeakCrypto.js";
12
12
  import isBinaryExpression from "./probes/isBinaryExpression.js";
13
13
  import isArrayExpression from "./probes/isArrayExpression.js";
14
14
  import isESMExport from "./probes/isESMExport.js";
15
+ import isFetch from "./probes/isFetch.js";
15
16
 
16
17
  // Import Internal Dependencies
17
18
  import { SourceFile } from "./SourceFile.js";
@@ -39,6 +40,7 @@ export class ProbeRunner {
39
40
  * @type {Probe[]}
40
41
  */
41
42
  static Defaults = [
43
+ isFetch,
42
44
  isRequire,
43
45
  isESMExport,
44
46
  isUnsafeCallee,
package/src/SourceFile.js CHANGED
@@ -19,6 +19,8 @@ export class SourceFile {
19
19
  dependencies = new Map();
20
20
  encodedLiterals = new Map();
21
21
  warnings = [];
22
+ /** @type {Set<string>} */
23
+ flags = new Set();
22
24
 
23
25
  constructor(sourceCodeString, probesOptions = {}) {
24
26
  this.tracer = new VariableTracer()
@@ -0,0 +1,19 @@
1
+ // Import Third-party Dependencies
2
+ import { getCallExpressionIdentifier } from "@nodesecure/estree-ast-utils";
3
+
4
+ function validateNode(node) {
5
+ const id = getCallExpressionIdentifier(node);
6
+
7
+ return [id === "fetch"];
8
+ }
9
+
10
+ function main(_node, { sourceFile }) {
11
+ sourceFile.flags.add("fetch");
12
+ }
13
+
14
+ export default {
15
+ name: "isFetch",
16
+ validateNode,
17
+ main,
18
+ breakOnMatch: false
19
+ };
package/types/api.d.ts CHANGED
@@ -24,10 +24,14 @@ export {
24
24
  Report,
25
25
  ReportOnFile,
26
26
 
27
+ SourceFlags,
27
28
  SourceLocation,
28
29
  Dependency
29
30
  }
30
31
 
32
+ type SourceFlags =
33
+ | "fetch";
34
+
31
35
  interface SourceLocation {
32
36
  start: {
33
37
  line: number;
@@ -89,6 +93,7 @@ interface Probe {
89
93
  interface Report {
90
94
  dependencies: Map<string, Dependency>;
91
95
  warnings: Warning[];
96
+ flags: Set<SourceFlags>;
92
97
  idsLengthAvg: number;
93
98
  stringScore: number;
94
99
  isOneLineRequire: boolean;
@@ -98,6 +103,7 @@ type ReportOnFile = {
98
103
  ok: true,
99
104
  warnings: Warning[];
100
105
  dependencies: Map<string, Dependency>;
106
+ flags: Set<SourceFlags>;
101
107
  isMinified: boolean;
102
108
  } | {
103
109
  ok: false,
@@ -125,6 +131,8 @@ declare class AstAnalyser {
125
131
  }
126
132
 
127
133
  declare class SourceFile {
134
+ flags: Set<SourceFlags>;
135
+
128
136
  constructor(source: string, options: any);
129
137
  addDependency(
130
138
  name: string,
@@ -145,6 +153,7 @@ interface EntryFilesAnalyserOptions {
145
153
  astAnalyzer?: AstAnalyser;
146
154
  loadExtensions?: (defaults: string[]) => string[];
147
155
  rootPath?: string | URL;
156
+ ignoreENOENT?: boolean;
148
157
  }
149
158
 
150
159
  declare class EntryFilesAnalyser {