Skip to content

Commit 008288a

Browse files
authored
Merge branch 'master' into migrate-ts-source-parser
2 parents 6257a89 + 1f763eb commit 008288a

35 files changed

Lines changed: 336 additions & 125 deletions

.changeset/empty-dingos-yell.md

Lines changed: 0 additions & 5 deletions
This file was deleted.

.changeset/loose-mails-float.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@nodesecure/estree-ast-utils": major
3+
---
4+
5+
Remove VariableTracer

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ Click on one of the links to access the documentation of the workspace:
148148
| name | package and link |
149149
| --- | --- |
150150
| estree-ast-utils | [@nodesecure/estree-ast-utils](./workspaces/estree-ast-utils) |
151+
| tracer | [@nodesecure/tracer](./workspaces/tracer) |
151152
| sec-literal | [@nodesecure/sec-literal ](./workspaces/sec-literal) |
152153
| ts-source-parser | [@nodesecure/ts-source-parser ](./workspaces/ts-source-parser) |
153154

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
"workspaces": [
3333
"workspaces/estree-ast-utils",
3434
"workspaces/sec-literal",
35-
"workspaces/ts-source-parser"
35+
"workspaces/ts-source-parser",
36+
"workspaces/tracer"
3637
],
3738
"keywords": [
3839
"ast",
@@ -57,6 +58,7 @@
5758
"dependencies": {
5859
"@nodesecure/estree-ast-utils": "^1.5.0",
5960
"@nodesecure/sec-literal": "^1.2.0",
61+
"@nodesecure/tracer": "^1.0.0",
6062
"digraph-js": "^2.2.3",
6163
"estree-walker": "^3.0.1",
6264
"frequency-set": "^1.0.2",
@@ -70,7 +72,7 @@
7072
"@changesets/cli": "^2.29.4",
7173
"@openally/config.eslint": "^2.0.0",
7274
"@openally/config.typescript": "^1.0.3",
73-
"@types/node": "^22.0.0",
75+
"@types/node": "^24.0.2",
7476
"c8": "^10.1.2",
7577
"glob": "^11.0.0",
7678
"iterator-matcher": "^2.1.0",

src/EntryFilesAnalyser.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,12 @@ export class EntryFilesAnalyser {
4141
this.dependencies = new DiGraph();
4242

4343
for (const entryFile of new Set(entryFiles)) {
44-
const normalizedEntryFile = path.normalize(
45-
fileURLToPathExtended(entryFile)
46-
);
44+
const normalizedEntryFile = this.#normalizeAndCleanEntryFile(entryFile);
4745

48-
if (this.ignoreENOENT && !await this.#fileExists(normalizedEntryFile)) {
46+
if (
47+
this.ignoreENOENT &&
48+
!await this.#fileExists(normalizedEntryFile)
49+
) {
4950
return;
5051
}
5152

@@ -57,8 +58,21 @@ export class EntryFilesAnalyser {
5758
}
5859
}
5960

61+
#normalizeAndCleanEntryFile(file) {
62+
let normalizedEntryFile = path.normalize(
63+
fileURLToPathExtended(file)
64+
);
65+
if (this.#rootPath !== null && !path.isAbsolute(normalizedEntryFile)) {
66+
normalizedEntryFile = path.join(this.#rootPath, normalizedEntryFile);
67+
}
68+
69+
return normalizedEntryFile;
70+
}
71+
6072
#getRelativeFilePath(file) {
61-
return this.#rootPath ? path.relative(this.#rootPath, file) : file;
73+
return this.#rootPath ?
74+
path.relative(this.#rootPath, file) :
75+
file;
6276
}
6377

6478
async* #analyseFile(

src/SourceFile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Import Third-party Dependencies
22
import { Utils, Literal } from "@nodesecure/sec-literal";
3-
import { VariableTracer } from "@nodesecure/estree-ast-utils";
3+
import { VariableTracer } from "@nodesecure/tracer";
44

55
// Import Internal Dependencies
66
import { rootLocation, toArrayLocation } from "./utils/index.js";

test/EntryFilesAnalyser.spec.js

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -181,23 +181,43 @@ describe("EntryFilesAnalyser", () => {
181181
assert.ok(to.startsWith(kFixtureURLPath));
182182
}
183183
});
184-
});
185184

186-
it("should ignore file that does not exist when option ignoreENOENT is provided", async() => {
187-
const entryFilesAnalyser = new EntryFilesAnalyser({
188-
ignoreENOENT: true,
189-
rootPath: kFixtureURL
185+
it("should automatically build absolute path for entryFiles when rootPath is provided", async() => {
186+
const entryFilesAnalyser = new EntryFilesAnalyser({
187+
rootPath: kFixtureURL
188+
});
189+
190+
const generator = entryFilesAnalyser.analyse(
191+
["recursive/A.js"]
192+
);
193+
const reports = await fromAsync(generator);
194+
195+
const files = reports.map((report) => path.normalize(report.file));
196+
assert.deepEqual(
197+
files,
198+
[
199+
"recursive/A.js",
200+
"recursive/B.js"
201+
].map((file) => path.normalize(file))
202+
);
190203
});
191204

192-
const entryUrl = new URL("does-not-exists.js", kFixtureURL);
205+
it("should ignore file that does not exist when option ignoreENOENT is provided", async() => {
206+
const entryFilesAnalyser = new EntryFilesAnalyser({
207+
ignoreENOENT: true,
208+
rootPath: kFixtureURL
209+
});
210+
211+
const entryUrl = new URL("does-not-exists.js", kFixtureURL);
193212

194-
const generator = entryFilesAnalyser.analyse(
195-
[entryUrl]
196-
);
213+
const generator = entryFilesAnalyser.analyse(
214+
[entryUrl]
215+
);
197216

198-
const reports = await fromAsync(generator);
199-
assert.strictEqual(reports.length, 0);
200-
assert.strictEqual(entryFilesAnalyser.dependencies.hasVertex("does-not-exists.js"), false);
217+
const reports = await fromAsync(generator);
218+
assert.strictEqual(reports.length, 0);
219+
assert.strictEqual(entryFilesAnalyser.dependencies.hasVertex("does-not-exists.js"), false);
220+
});
201221
});
202222

203223
// TODO: replace with Array.fromAsync when droping Node.js 20

workspaces/estree-ast-utils/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# @nodesecure/estree-ast-utils
22

3+
## 2.0.0
4+
5+
### Major Changes
6+
7+
- [#342](https://github.com/NodeSecure/js-x-ray/pull/342) [`633f334`](https://github.com/NodeSecure/js-x-ray/commit/633f334e1fbceb3d7eb20a08907c56502b51d6ca) Thanks [@fraxken](https://github.com/fraxken)! - Resolve CallExpression in MemberExpression with getCallExpressionIdentifier helper
8+
39
## 1.6.0
410

511
### Minor Changes

workspaces/estree-ast-utils/README.md

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,6 @@ $ npm i @nodesecure/estree-ast-utils
1919
$ yarn add @nodesecure/estree-ast-utils
2020
```
2121

22-
## Usage example
23-
24-
```js
25-
import { VariableTracer } from "@nodesecure/estree-ast-utils";
26-
27-
const tracer = new VariableTracer().enableDefaultTracing();
28-
29-
const data = tracer.getDataFromIdentifier("identifier...here");
30-
console.log(data);
31-
```
32-
3322
## API
3423

3524
<details><summary>arrayExpressionToString(node): IterableIterator< string ></summary>

workspaces/estree-ast-utils/package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nodesecure/estree-ast-utils",
3-
"version": "1.6.0",
3+
"version": "2.0.0",
44
"description": "Utilities for AST (ESTree compliant)",
55
"type": "module",
66
"exports": "./src/index.js",
@@ -29,9 +29,6 @@
2929
"url": "https://github.com/NodeSecure/js-x-ray/issues"
3030
},
3131
"homepage": "https://github.com/NodeSecure/js-x-ray/tree/master/workspaces/estree-ast-utils#readme",
32-
"devDependencies": {
33-
"estree-walker": "^3.0.2"
34-
},
3532
"dependencies": {
3633
"@nodesecure/sec-literal": "^1.1.0"
3734
}

0 commit comments

Comments
 (0)