From 5fb2088874f6792029225b903ff21b5d50313944 Mon Sep 17 00:00:00 2001 From: fraxken Date: Wed, 24 Dec 2025 15:52:58 +0100 Subject: [PATCH] feat(tarball): implement support of typescript source files --- .changeset/open-pears-exist.md | 5 +++ package.json | 2 +- workspaces/scanner/package.json | 5 +-- workspaces/tarball/package.json | 2 +- .../tarball/src/class/NpmTarball.class.ts | 4 +- .../tarball/test/SourceCodeScanner.spec.ts | 40 +++++++++++++++++++ .../fixtures/scanPackage/tsOnly/package.json | 4 ++ .../fixtures/scanPackage/tsOnly/src/bar.ts | 1 + .../fixtures/scanPackage/tsOnly/src/index.ts | 3 ++ workspaces/tree-walker/package.json | 2 +- .../tree-walker/test/npm/TreeWalker.spec.ts | 7 ++-- 11 files changed, 64 insertions(+), 11 deletions(-) create mode 100644 .changeset/open-pears-exist.md create mode 100644 workspaces/tarball/test/fixtures/scanPackage/tsOnly/package.json create mode 100644 workspaces/tarball/test/fixtures/scanPackage/tsOnly/src/bar.ts create mode 100644 workspaces/tarball/test/fixtures/scanPackage/tsOnly/src/index.ts diff --git a/.changeset/open-pears-exist.md b/.changeset/open-pears-exist.md new file mode 100644 index 00000000..f57436ea --- /dev/null +++ b/.changeset/open-pears-exist.md @@ -0,0 +1,5 @@ +--- +"@nodesecure/tarball": minor +--- + +Integrate support of TypeScript source files diff --git a/package.json b/package.json index b16973a5..674cfccb 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "c8": "^10.1.2", "pkg-ok": "^3.0.0", "tsd": "^0.33.0", - "typescript": "^5.5.3" + "typescript": "5.9.3" }, "engines": { "node": ">=20" diff --git a/workspaces/scanner/package.json b/workspaces/scanner/package.json index 2c3a2ae6..7f8d3d91 100644 --- a/workspaces/scanner/package.json +++ b/workspaces/scanner/package.json @@ -68,7 +68,7 @@ "@nodesecure/contact": "^3.0.0", "@nodesecure/flags": "^3.0.3", "@nodesecure/i18n": "^4.0.2", - "@nodesecure/js-x-ray": "11.0.1", + "@nodesecure/js-x-ray": "11.1.0", "@nodesecure/mama": "^2.0.2", "@nodesecure/npm-registry-sdk": "^4.4.0", "@nodesecure/npm-types": "^1.3.0", @@ -89,7 +89,6 @@ "@npmcli/config": "^10.4.2", "@types/node": "^24.0.2", "@types/npmcli__config": "^6.0.3", - "c8": "^10.1.3", - "typescript": "^5.8.3" + "c8": "^10.1.3" } } diff --git a/workspaces/tarball/package.json b/workspaces/tarball/package.json index ec603b03..308cd63b 100644 --- a/workspaces/tarball/package.json +++ b/workspaces/tarball/package.json @@ -47,7 +47,7 @@ "dependencies": { "@nodesecure/conformance": "^1.2.0", "@nodesecure/fs-walk": "^2.0.0", - "@nodesecure/js-x-ray": "11.0.1", + "@nodesecure/js-x-ray": "11.1.0", "@nodesecure/mama": "^2.0.0", "@nodesecure/npm-types": "^1.2.0", "@nodesecure/utils": "^2.3.0", diff --git a/workspaces/tarball/src/class/NpmTarball.class.ts b/workspaces/tarball/src/class/NpmTarball.class.ts index 22e6e2df..40d70de9 100644 --- a/workspaces/tarball/src/class/NpmTarball.class.ts +++ b/workspaces/tarball/src/class/NpmTarball.class.ts @@ -30,7 +30,9 @@ export interface ScannedFilesResult { export class NpmTarball { static JS_EXTENSIONS = new Set([ - ".js", ".mjs", ".cjs" + ".js", ".mjs", ".cjs", + ".ts", ".mts", ".cts", + ".jsx", ".tsx" ]); manifest: LocatedManifestManager; diff --git a/workspaces/tarball/test/SourceCodeScanner.spec.ts b/workspaces/tarball/test/SourceCodeScanner.spec.ts index 65a6bb9e..ec27b3a1 100644 --- a/workspaces/tarball/test/SourceCodeScanner.spec.ts +++ b/workspaces/tarball/test/SourceCodeScanner.spec.ts @@ -136,6 +136,46 @@ describe("SourceCodeScanner", () => { ] ); }); + + test("iterate() should report typescript files", async() => { + const mama = loadFixtureManifest("tsOnly"); + const astAnalyser = new AstAnalyser(); + const aggregator = createAggregator(); + + const scanner = new SourceCodeScanner(mama, { + reportInitiator: () => aggregator, + astAnalyser + }); + await scanner.iterate({ + manifest: [ + "src/index.ts" + ], + javascript: [] + }); + + const { reports } = aggregator; + + const firstReport = reports[0]; + if (firstReport.ok) { + assert.ok(firstReport.dependencies.has("node:http")); + assert.ok(firstReport.dependencies.has("./bar.ts")); + } + else { + assert.fail("First report should be ok"); + } + + const files = reports + .map((report) => path.normalize(report.file)) + .sort(); + + assert.deepEqual( + files, + [ + "src\\index.ts", + "src\\bar.ts" + ].sort() + ); + }); }); function loadFixtureManifest( diff --git a/workspaces/tarball/test/fixtures/scanPackage/tsOnly/package.json b/workspaces/tarball/test/fixtures/scanPackage/tsOnly/package.json new file mode 100644 index 00000000..45aeb848 --- /dev/null +++ b/workspaces/tarball/test/fixtures/scanPackage/tsOnly/package.json @@ -0,0 +1,4 @@ +{ + "name": "foobar", + "main": "./src/index.ts" +} diff --git a/workspaces/tarball/test/fixtures/scanPackage/tsOnly/src/bar.ts b/workspaces/tarball/test/fixtures/scanPackage/tsOnly/src/bar.ts new file mode 100644 index 00000000..affdaa64 --- /dev/null +++ b/workspaces/tarball/test/fixtures/scanPackage/tsOnly/src/bar.ts @@ -0,0 +1 @@ +export const foo = "hello world"; diff --git a/workspaces/tarball/test/fixtures/scanPackage/tsOnly/src/index.ts b/workspaces/tarball/test/fixtures/scanPackage/tsOnly/src/index.ts new file mode 100644 index 00000000..46b8980b --- /dev/null +++ b/workspaces/tarball/test/fixtures/scanPackage/tsOnly/src/index.ts @@ -0,0 +1,3 @@ +import http from "node:http"; +import { foo } from "./bar.ts"; +console.log(foo); diff --git a/workspaces/tree-walker/package.json b/workspaces/tree-walker/package.json index c50786cf..0f4c7434 100644 --- a/workspaces/tree-walker/package.json +++ b/workspaces/tree-walker/package.json @@ -40,7 +40,7 @@ "@nodesecure/js-x-ray": "11.0.1", "@nodesecure/npm-registry-sdk": "^4.0.0", "@nodesecure/npm-types": "^1.1.0", - "@npmcli/arborist": "^9.0.2", + "@npmcli/arborist": "9.1.9", "combine-async-iterators": "^3.0.0", "itertools": "^2.3.1", "npm-pick-manifest": "^11.0.1", diff --git a/workspaces/tree-walker/test/npm/TreeWalker.spec.ts b/workspaces/tree-walker/test/npm/TreeWalker.spec.ts index 6891e878..cdf29c0f 100644 --- a/workspaces/tree-walker/test/npm/TreeWalker.spec.ts +++ b/workspaces/tree-walker/test/npm/TreeWalker.spec.ts @@ -175,14 +175,13 @@ describe("npm.TreeWalker", () => { const names = dependencies .map((dependency) => dependency.name) .sort(sortByName); - assert.strictEqual( - names.length, - rootDependency.dependencyCount + 1 - ); assert.deepEqual( names, [ ...manifestWorkspaces, + // Note: there is a BUG with arborist including 'typescript' as a workspace dependency + // Test will break when the BUG will be fixed + "typescript", "workspace" ].sort(sortByName) );