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/workspaces/scanner/package.json b/workspaces/scanner/package.json index 2c3a2ae6..c5b81dd5 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", 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);