@hyperfrontend/project-scope 0.1.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/ARCHITECTURE.md +370 -0
- package/CHANGELOG.md +10 -0
- package/FUNDING.md +141 -0
- package/LICENSE.md +21 -0
- package/README.md +242 -0
- package/SECURITY.md +82 -0
- package/analyze.d.ts +33 -0
- package/analyze.d.ts.map +1 -0
- package/cli/commands/analyze.d.ts +20 -0
- package/cli/commands/analyze.d.ts.map +1 -0
- package/cli/commands/config.d.ts +20 -0
- package/cli/commands/config.d.ts.map +1 -0
- package/cli/commands/deps.d.ts +18 -0
- package/cli/commands/deps.d.ts.map +1 -0
- package/cli/commands/tree.d.ts +24 -0
- package/cli/commands/tree.d.ts.map +1 -0
- package/cli/index.cjs.js +6639 -0
- package/cli/index.cjs.js.map +1 -0
- package/cli/index.d.ts +7 -0
- package/cli/index.d.ts.map +1 -0
- package/cli/index.esm.js +6629 -0
- package/cli/index.esm.js.map +1 -0
- package/cli/run.d.ts +25 -0
- package/cli/run.d.ts.map +1 -0
- package/cli/types.d.ts +55 -0
- package/cli/types.d.ts.map +1 -0
- package/core/cache.d.ts +157 -0
- package/core/cache.d.ts.map +1 -0
- package/core/encoding/convert.d.ts +32 -0
- package/core/encoding/convert.d.ts.map +1 -0
- package/core/encoding/detect.d.ts +86 -0
- package/core/encoding/detect.d.ts.map +1 -0
- package/core/encoding/index.cjs.js +751 -0
- package/core/encoding/index.cjs.js.map +1 -0
- package/core/encoding/index.d.ts +3 -0
- package/core/encoding/index.d.ts.map +1 -0
- package/core/encoding/index.esm.js +736 -0
- package/core/encoding/index.esm.js.map +1 -0
- package/core/errors/structured-errors.d.ts +64 -0
- package/core/errors/structured-errors.d.ts.map +1 -0
- package/core/fs/directory.d.ts +88 -0
- package/core/fs/directory.d.ts.map +1 -0
- package/core/fs/index.cjs.js +1079 -0
- package/core/fs/index.cjs.js.map +1 -0
- package/core/fs/index.d.ts +6 -0
- package/core/fs/index.d.ts.map +1 -0
- package/core/fs/index.esm.js +1056 -0
- package/core/fs/index.esm.js.map +1 -0
- package/core/fs/read.d.ts +86 -0
- package/core/fs/read.d.ts.map +1 -0
- package/core/fs/stat.d.ts +58 -0
- package/core/fs/stat.d.ts.map +1 -0
- package/core/fs/traversal.d.ts +26 -0
- package/core/fs/traversal.d.ts.map +1 -0
- package/core/fs/write.d.ts +75 -0
- package/core/fs/write.d.ts.map +1 -0
- package/core/index.cjs.js +2376 -0
- package/core/index.cjs.js.map +1 -0
- package/core/index.d.ts +9 -0
- package/core/index.d.ts.map +1 -0
- package/core/index.esm.js +2286 -0
- package/core/index.esm.js.map +1 -0
- package/core/logger.d.ts +111 -0
- package/core/logger.d.ts.map +1 -0
- package/core/path/index.cjs.js +254 -0
- package/core/path/index.cjs.js.map +1 -0
- package/core/path/index.d.ts +5 -0
- package/core/path/index.d.ts.map +1 -0
- package/core/path/index.esm.js +233 -0
- package/core/path/index.esm.js.map +1 -0
- package/core/path/join.d.ts +17 -0
- package/core/path/join.d.ts.map +1 -0
- package/core/path/normalize.d.ts +37 -0
- package/core/path/normalize.d.ts.map +1 -0
- package/core/path/resolve.d.ts +52 -0
- package/core/path/resolve.d.ts.map +1 -0
- package/core/path/segments.d.ts +59 -0
- package/core/path/segments.d.ts.map +1 -0
- package/core/patterns/glob.d.ts +46 -0
- package/core/patterns/glob.d.ts.map +1 -0
- package/core/platform/detect.d.ts +66 -0
- package/core/platform/detect.d.ts.map +1 -0
- package/core/platform/index.cjs.js +241 -0
- package/core/platform/index.cjs.js.map +1 -0
- package/core/platform/index.d.ts +3 -0
- package/core/platform/index.d.ts.map +1 -0
- package/core/platform/index.esm.js +226 -0
- package/core/platform/index.esm.js.map +1 -0
- package/core/platform/line-endings.d.ts +48 -0
- package/core/platform/line-endings.d.ts.map +1 -0
- package/heuristics/dependencies/analyze.d.ts +77 -0
- package/heuristics/dependencies/analyze.d.ts.map +1 -0
- package/heuristics/dependencies/index.cjs.js +1126 -0
- package/heuristics/dependencies/index.cjs.js.map +1 -0
- package/heuristics/dependencies/index.d.ts +2 -0
- package/heuristics/dependencies/index.d.ts.map +1 -0
- package/heuristics/dependencies/index.esm.js +1122 -0
- package/heuristics/dependencies/index.esm.js.map +1 -0
- package/heuristics/entry-points/discover.d.ts +86 -0
- package/heuristics/entry-points/discover.d.ts.map +1 -0
- package/heuristics/entry-points/index.cjs.js +1581 -0
- package/heuristics/entry-points/index.cjs.js.map +1 -0
- package/heuristics/entry-points/index.d.ts +2 -0
- package/heuristics/entry-points/index.d.ts.map +1 -0
- package/heuristics/entry-points/index.esm.js +1577 -0
- package/heuristics/entry-points/index.esm.js.map +1 -0
- package/heuristics/framework/identify.d.ts +84 -0
- package/heuristics/framework/identify.d.ts.map +1 -0
- package/heuristics/framework/index.cjs.js +3618 -0
- package/heuristics/framework/index.cjs.js.map +1 -0
- package/heuristics/framework/index.d.ts +2 -0
- package/heuristics/framework/index.d.ts.map +1 -0
- package/heuristics/framework/index.esm.js +3614 -0
- package/heuristics/framework/index.esm.js.map +1 -0
- package/heuristics/index.cjs.js +4833 -0
- package/heuristics/index.cjs.js.map +1 -0
- package/heuristics/index.d.ts +5 -0
- package/heuristics/index.d.ts.map +1 -0
- package/heuristics/index.esm.js +4822 -0
- package/heuristics/index.esm.js.map +1 -0
- package/heuristics/project-type/detect.d.ts +61 -0
- package/heuristics/project-type/detect.d.ts.map +1 -0
- package/heuristics/project-type/index.cjs.js +3633 -0
- package/heuristics/project-type/index.cjs.js.map +1 -0
- package/heuristics/project-type/index.d.ts +2 -0
- package/heuristics/project-type/index.d.ts.map +1 -0
- package/heuristics/project-type/index.esm.js +3631 -0
- package/heuristics/project-type/index.esm.js.map +1 -0
- package/index.cjs.js +10255 -0
- package/index.cjs.js.map +1 -0
- package/index.d.ts +10 -0
- package/index.d.ts.map +1 -0
- package/index.esm.js +10006 -0
- package/index.esm.js.map +1 -0
- package/models/index.cjs.js +3 -0
- package/models/index.cjs.js.map +1 -0
- package/models/index.d.ts +176 -0
- package/models/index.d.ts.map +1 -0
- package/models/index.esm.js +2 -0
- package/models/index.esm.js.map +1 -0
- package/nx/detect.d.ts +105 -0
- package/nx/detect.d.ts.map +1 -0
- package/nx/devkit-loader.d.ts +62 -0
- package/nx/devkit-loader.d.ts.map +1 -0
- package/nx/index.cjs.js +1302 -0
- package/nx/index.cjs.js.map +1 -0
- package/nx/index.d.ts +4 -0
- package/nx/index.d.ts.map +1 -0
- package/nx/index.esm.js +1286 -0
- package/nx/index.esm.js.map +1 -0
- package/nx/project-config.d.ts +109 -0
- package/nx/project-config.d.ts.map +1 -0
- package/package.json +218 -0
- package/project/config/detect.d.ts +77 -0
- package/project/config/detect.d.ts.map +1 -0
- package/project/config/index.cjs.js +1982 -0
- package/project/config/index.cjs.js.map +1 -0
- package/project/config/index.d.ts +4 -0
- package/project/config/index.d.ts.map +1 -0
- package/project/config/index.esm.js +1971 -0
- package/project/config/index.esm.js.map +1 -0
- package/project/config/parse.d.ts +53 -0
- package/project/config/parse.d.ts.map +1 -0
- package/project/config/patterns.d.ts +31 -0
- package/project/config/patterns.d.ts.map +1 -0
- package/project/index.cjs.js +2585 -0
- package/project/index.cjs.js.map +1 -0
- package/project/index.d.ts +5 -0
- package/project/index.d.ts.map +1 -0
- package/project/index.esm.js +2549 -0
- package/project/index.esm.js.map +1 -0
- package/project/package/dependencies.d.ts +101 -0
- package/project/package/dependencies.d.ts.map +1 -0
- package/project/package/index.cjs.js +972 -0
- package/project/package/index.cjs.js.map +1 -0
- package/project/package/index.d.ts +3 -0
- package/project/package/index.d.ts.map +1 -0
- package/project/package/index.esm.js +957 -0
- package/project/package/index.esm.js.map +1 -0
- package/project/package/read.d.ts +66 -0
- package/project/package/read.d.ts.map +1 -0
- package/project/root/detect.d.ts +65 -0
- package/project/root/detect.d.ts.map +1 -0
- package/project/root/index.cjs.js +860 -0
- package/project/root/index.cjs.js.map +1 -0
- package/project/root/index.d.ts +2 -0
- package/project/root/index.d.ts.map +1 -0
- package/project/root/index.esm.js +853 -0
- package/project/root/index.esm.js.map +1 -0
- package/project/traversal/index.cjs.js +1179 -0
- package/project/traversal/index.cjs.js.map +1 -0
- package/project/traversal/index.d.ts +3 -0
- package/project/traversal/index.d.ts.map +1 -0
- package/project/traversal/index.esm.js +1173 -0
- package/project/traversal/index.esm.js.map +1 -0
- package/project/traversal/search.d.ts +59 -0
- package/project/traversal/search.d.ts.map +1 -0
- package/project/traversal/walk.d.ts +63 -0
- package/project/traversal/walk.d.ts.map +1 -0
- package/tech/backend/detect-all.d.ts +13 -0
- package/tech/backend/detect-all.d.ts.map +1 -0
- package/tech/backend/express.d.ts +11 -0
- package/tech/backend/express.d.ts.map +1 -0
- package/tech/backend/fastify.d.ts +11 -0
- package/tech/backend/fastify.d.ts.map +1 -0
- package/tech/backend/hono.d.ts +11 -0
- package/tech/backend/hono.d.ts.map +1 -0
- package/tech/backend/index.cjs.js +939 -0
- package/tech/backend/index.cjs.js.map +1 -0
- package/tech/backend/index.d.ts +8 -0
- package/tech/backend/index.d.ts.map +1 -0
- package/tech/backend/index.esm.js +931 -0
- package/tech/backend/index.esm.js.map +1 -0
- package/tech/backend/koa.d.ts +11 -0
- package/tech/backend/koa.d.ts.map +1 -0
- package/tech/backend/nestjs.d.ts +11 -0
- package/tech/backend/nestjs.d.ts.map +1 -0
- package/tech/backend/types.d.ts +31 -0
- package/tech/backend/types.d.ts.map +1 -0
- package/tech/build/babel.d.ts +13 -0
- package/tech/build/babel.d.ts.map +1 -0
- package/tech/build/detect-all.d.ts +13 -0
- package/tech/build/detect-all.d.ts.map +1 -0
- package/tech/build/esbuild.d.ts +11 -0
- package/tech/build/esbuild.d.ts.map +1 -0
- package/tech/build/index.cjs.js +1118 -0
- package/tech/build/index.cjs.js.map +1 -0
- package/tech/build/index.d.ts +10 -0
- package/tech/build/index.d.ts.map +1 -0
- package/tech/build/index.esm.js +1102 -0
- package/tech/build/index.esm.js.map +1 -0
- package/tech/build/parcel.d.ts +13 -0
- package/tech/build/parcel.d.ts.map +1 -0
- package/tech/build/rollup.d.ts +13 -0
- package/tech/build/rollup.d.ts.map +1 -0
- package/tech/build/swc.d.ts +13 -0
- package/tech/build/swc.d.ts.map +1 -0
- package/tech/build/types.d.ts +31 -0
- package/tech/build/types.d.ts.map +1 -0
- package/tech/build/vite.d.ts +13 -0
- package/tech/build/vite.d.ts.map +1 -0
- package/tech/build/webpack.d.ts +13 -0
- package/tech/build/webpack.d.ts.map +1 -0
- package/tech/frontend/angular.d.ts +11 -0
- package/tech/frontend/angular.d.ts.map +1 -0
- package/tech/frontend/astro.d.ts +11 -0
- package/tech/frontend/astro.d.ts.map +1 -0
- package/tech/frontend/detect-all.d.ts +13 -0
- package/tech/frontend/detect-all.d.ts.map +1 -0
- package/tech/frontend/gatsby.d.ts +11 -0
- package/tech/frontend/gatsby.d.ts.map +1 -0
- package/tech/frontend/index.cjs.js +1310 -0
- package/tech/frontend/index.cjs.js.map +1 -0
- package/tech/frontend/index.d.ts +15 -0
- package/tech/frontend/index.d.ts.map +1 -0
- package/tech/frontend/index.esm.js +1295 -0
- package/tech/frontend/index.esm.js.map +1 -0
- package/tech/frontend/nextjs.d.ts +11 -0
- package/tech/frontend/nextjs.d.ts.map +1 -0
- package/tech/frontend/nuxt.d.ts +11 -0
- package/tech/frontend/nuxt.d.ts.map +1 -0
- package/tech/frontend/qwik.d.ts +11 -0
- package/tech/frontend/qwik.d.ts.map +1 -0
- package/tech/frontend/react.d.ts +11 -0
- package/tech/frontend/react.d.ts.map +1 -0
- package/tech/frontend/remix.d.ts +11 -0
- package/tech/frontend/remix.d.ts.map +1 -0
- package/tech/frontend/solid.d.ts +11 -0
- package/tech/frontend/solid.d.ts.map +1 -0
- package/tech/frontend/svelte.d.ts +11 -0
- package/tech/frontend/svelte.d.ts.map +1 -0
- package/tech/frontend/sveltekit.d.ts +11 -0
- package/tech/frontend/sveltekit.d.ts.map +1 -0
- package/tech/frontend/types.d.ts +35 -0
- package/tech/frontend/types.d.ts.map +1 -0
- package/tech/frontend/vue.d.ts +11 -0
- package/tech/frontend/vue.d.ts.map +1 -0
- package/tech/index.cjs.js +3684 -0
- package/tech/index.cjs.js.map +1 -0
- package/tech/index.d.ts +96 -0
- package/tech/index.d.ts.map +1 -0
- package/tech/index.esm.js +3603 -0
- package/tech/index.esm.js.map +1 -0
- package/tech/legacy/angularjs.d.ts +12 -0
- package/tech/legacy/angularjs.d.ts.map +1 -0
- package/tech/legacy/backbone.d.ts +11 -0
- package/tech/legacy/backbone.d.ts.map +1 -0
- package/tech/legacy/detect-all.d.ts +13 -0
- package/tech/legacy/detect-all.d.ts.map +1 -0
- package/tech/legacy/ember.d.ts +11 -0
- package/tech/legacy/ember.d.ts.map +1 -0
- package/tech/legacy/index.cjs.js +903 -0
- package/tech/legacy/index.cjs.js.map +1 -0
- package/tech/legacy/index.d.ts +7 -0
- package/tech/legacy/index.d.ts.map +1 -0
- package/tech/legacy/index.esm.js +896 -0
- package/tech/legacy/index.esm.js.map +1 -0
- package/tech/legacy/jquery.d.ts +11 -0
- package/tech/legacy/jquery.d.ts.map +1 -0
- package/tech/legacy/types.d.ts +33 -0
- package/tech/legacy/types.d.ts.map +1 -0
- package/tech/linting/biome.d.ts +11 -0
- package/tech/linting/biome.d.ts.map +1 -0
- package/tech/linting/detect-all.d.ts +13 -0
- package/tech/linting/detect-all.d.ts.map +1 -0
- package/tech/linting/eslint.d.ts +13 -0
- package/tech/linting/eslint.d.ts.map +1 -0
- package/tech/linting/index.cjs.js +992 -0
- package/tech/linting/index.cjs.js.map +1 -0
- package/tech/linting/index.d.ts +7 -0
- package/tech/linting/index.d.ts.map +1 -0
- package/tech/linting/index.esm.js +982 -0
- package/tech/linting/index.esm.js.map +1 -0
- package/tech/linting/prettier.d.ts +13 -0
- package/tech/linting/prettier.d.ts.map +1 -0
- package/tech/linting/stylelint.d.ts +13 -0
- package/tech/linting/stylelint.d.ts.map +1 -0
- package/tech/linting/types.d.ts +31 -0
- package/tech/linting/types.d.ts.map +1 -0
- package/tech/monorepo/detect-all.d.ts +13 -0
- package/tech/monorepo/detect-all.d.ts.map +1 -0
- package/tech/monorepo/index.cjs.js +1021 -0
- package/tech/monorepo/index.cjs.js.map +1 -0
- package/tech/monorepo/index.d.ts +10 -0
- package/tech/monorepo/index.d.ts.map +1 -0
- package/tech/monorepo/index.esm.js +1011 -0
- package/tech/monorepo/index.esm.js.map +1 -0
- package/tech/monorepo/lerna.d.ts +11 -0
- package/tech/monorepo/lerna.d.ts.map +1 -0
- package/tech/monorepo/npm-workspaces.d.ts +11 -0
- package/tech/monorepo/npm-workspaces.d.ts.map +1 -0
- package/tech/monorepo/nx.d.ts +11 -0
- package/tech/monorepo/nx.d.ts.map +1 -0
- package/tech/monorepo/pnpm-workspaces.d.ts +9 -0
- package/tech/monorepo/pnpm-workspaces.d.ts.map +1 -0
- package/tech/monorepo/rush.d.ts +11 -0
- package/tech/monorepo/rush.d.ts.map +1 -0
- package/tech/monorepo/turborepo.d.ts +11 -0
- package/tech/monorepo/turborepo.d.ts.map +1 -0
- package/tech/monorepo/types.d.ts +39 -0
- package/tech/monorepo/types.d.ts.map +1 -0
- package/tech/monorepo/yarn-workspaces.d.ts +11 -0
- package/tech/monorepo/yarn-workspaces.d.ts.map +1 -0
- package/tech/shared-utils/detector-helpers.d.ts +52 -0
- package/tech/shared-utils/detector-helpers.d.ts.map +1 -0
- package/tech/shared-utils/types.d.ts +41 -0
- package/tech/shared-utils/types.d.ts.map +1 -0
- package/tech/testing/cypress.d.ts +13 -0
- package/tech/testing/cypress.d.ts.map +1 -0
- package/tech/testing/detect-all.d.ts +13 -0
- package/tech/testing/detect-all.d.ts.map +1 -0
- package/tech/testing/index.cjs.js +1031 -0
- package/tech/testing/index.cjs.js.map +1 -0
- package/tech/testing/index.d.ts +8 -0
- package/tech/testing/index.d.ts.map +1 -0
- package/tech/testing/index.esm.js +1018 -0
- package/tech/testing/index.esm.js.map +1 -0
- package/tech/testing/jest.d.ts +13 -0
- package/tech/testing/jest.d.ts.map +1 -0
- package/tech/testing/mocha.d.ts +13 -0
- package/tech/testing/mocha.d.ts.map +1 -0
- package/tech/testing/playwright.d.ts +13 -0
- package/tech/testing/playwright.d.ts.map +1 -0
- package/tech/testing/types.d.ts +35 -0
- package/tech/testing/types.d.ts.map +1 -0
- package/tech/testing/vitest.d.ts +13 -0
- package/tech/testing/vitest.d.ts.map +1 -0
- package/tech/types/detectors.d.ts +67 -0
- package/tech/types/detectors.d.ts.map +1 -0
- package/tech/types/index.cjs.js +1045 -0
- package/tech/types/index.cjs.js.map +1 -0
- package/tech/types/index.d.ts +2 -0
- package/tech/types/index.d.ts.map +1 -0
- package/tech/types/index.esm.js +1039 -0
- package/tech/types/index.esm.js.map +1 -0
- package/vfs/commit.d.ts +32 -0
- package/vfs/commit.d.ts.map +1 -0
- package/vfs/diff.d.ts +73 -0
- package/vfs/diff.d.ts.map +1 -0
- package/vfs/factory.d.ts +37 -0
- package/vfs/factory.d.ts.map +1 -0
- package/vfs/fs-tree.d.ts +13 -0
- package/vfs/fs-tree.d.ts.map +1 -0
- package/vfs/index.cjs.js +1600 -0
- package/vfs/index.cjs.js.map +1 -0
- package/vfs/index.d.ts +6 -0
- package/vfs/index.d.ts.map +1 -0
- package/vfs/index.esm.js +1590 -0
- package/vfs/index.esm.js.map +1 -0
- package/vfs/types.d.ts +178 -0
- package/vfs/types.d.ts.map +1 -0
|
@@ -0,0 +1,4822 @@
|
|
|
1
|
+
import { join as join$1, relative, dirname, resolve } from 'node:path';
|
|
2
|
+
import { existsSync, readFileSync, statSync, lstatSync, readdirSync } from 'node:fs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Safe copies of JSON built-in methods.
|
|
6
|
+
*
|
|
7
|
+
* These references are captured at module initialization time to protect against
|
|
8
|
+
* prototype pollution attacks. Import only what you need for tree-shaking.
|
|
9
|
+
*
|
|
10
|
+
* @module @hyperfrontend/immutable-api-utils/built-in-copy/json
|
|
11
|
+
*/
|
|
12
|
+
// Capture references at module initialization time
|
|
13
|
+
const _JSON = globalThis.JSON;
|
|
14
|
+
/**
|
|
15
|
+
* (Safe copy) Converts a JavaScript Object Notation (JSON) string into an object.
|
|
16
|
+
*/
|
|
17
|
+
const parse = _JSON.parse;
|
|
18
|
+
/**
|
|
19
|
+
* (Safe copy) Converts a JavaScript value to a JavaScript Object Notation (JSON) string.
|
|
20
|
+
*/
|
|
21
|
+
const stringify = _JSON.stringify;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Safe copies of Math built-in methods.
|
|
25
|
+
*
|
|
26
|
+
* These references are captured at module initialization time to protect against
|
|
27
|
+
* prototype pollution attacks. Import only what you need for tree-shaking.
|
|
28
|
+
*
|
|
29
|
+
* @module @hyperfrontend/immutable-api-utils/built-in-copy/math
|
|
30
|
+
*/
|
|
31
|
+
// Capture references at module initialization time
|
|
32
|
+
const _Math = globalThis.Math;
|
|
33
|
+
/**
|
|
34
|
+
* (Safe copy) Returns the value of a number rounded to the nearest integer.
|
|
35
|
+
*/
|
|
36
|
+
const round = _Math.round;
|
|
37
|
+
/**
|
|
38
|
+
* (Safe copy) Returns the smaller of zero or more numbers.
|
|
39
|
+
*/
|
|
40
|
+
const min = _Math.min;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Safe copies of Object built-in methods.
|
|
44
|
+
*
|
|
45
|
+
* These references are captured at module initialization time to protect against
|
|
46
|
+
* prototype pollution attacks. Import only what you need for tree-shaking.
|
|
47
|
+
*
|
|
48
|
+
* @module @hyperfrontend/immutable-api-utils/built-in-copy/object
|
|
49
|
+
*/
|
|
50
|
+
// Capture references at module initialization time
|
|
51
|
+
const _Object = globalThis.Object;
|
|
52
|
+
/**
|
|
53
|
+
* (Safe copy) Prevents modification of existing property attributes and values,
|
|
54
|
+
* and prevents the addition of new properties.
|
|
55
|
+
*/
|
|
56
|
+
const freeze = _Object.freeze;
|
|
57
|
+
/**
|
|
58
|
+
* (Safe copy) Returns the names of the enumerable string properties and methods of an object.
|
|
59
|
+
*/
|
|
60
|
+
const keys = _Object.keys;
|
|
61
|
+
/**
|
|
62
|
+
* (Safe copy) Returns an array of key/values of the enumerable own properties of an object.
|
|
63
|
+
*/
|
|
64
|
+
const entries = _Object.entries;
|
|
65
|
+
/**
|
|
66
|
+
* (Safe copy) Returns an array of values of the enumerable own properties of an object.
|
|
67
|
+
*/
|
|
68
|
+
const values = _Object.values;
|
|
69
|
+
/**
|
|
70
|
+
* (Safe copy) Adds one or more properties to an object, and/or modifies attributes of existing properties.
|
|
71
|
+
*/
|
|
72
|
+
const defineProperties = _Object.defineProperties;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Safe copies of Error built-ins via factory functions.
|
|
76
|
+
*
|
|
77
|
+
* Since constructors cannot be safely captured via Object.assign, this module
|
|
78
|
+
* provides factory functions that use Reflect.construct internally.
|
|
79
|
+
*
|
|
80
|
+
* These references are captured at module initialization time to protect against
|
|
81
|
+
* prototype pollution attacks. Import only what you need for tree-shaking.
|
|
82
|
+
*
|
|
83
|
+
* @module @hyperfrontend/immutable-api-utils/built-in-copy/error
|
|
84
|
+
*/
|
|
85
|
+
// Capture references at module initialization time
|
|
86
|
+
const _Error = globalThis.Error;
|
|
87
|
+
const _Reflect$2 = globalThis.Reflect;
|
|
88
|
+
/**
|
|
89
|
+
* (Safe copy) Creates a new Error using the captured Error constructor.
|
|
90
|
+
* Use this instead of `new Error()`.
|
|
91
|
+
*
|
|
92
|
+
* @param message - Optional error message.
|
|
93
|
+
* @param options - Optional error options.
|
|
94
|
+
* @returns A new Error instance.
|
|
95
|
+
*/
|
|
96
|
+
const createError = (message, options) => _Reflect$2.construct(_Error, [message, options]);
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Safe copies of Array built-in static methods.
|
|
100
|
+
*
|
|
101
|
+
* These references are captured at module initialization time to protect against
|
|
102
|
+
* prototype pollution attacks. Import only what you need for tree-shaking.
|
|
103
|
+
*
|
|
104
|
+
* @module @hyperfrontend/immutable-api-utils/built-in-copy/array
|
|
105
|
+
*/
|
|
106
|
+
// Capture references at module initialization time
|
|
107
|
+
const _Array = globalThis.Array;
|
|
108
|
+
/**
|
|
109
|
+
* (Safe copy) Determines whether the passed value is an Array.
|
|
110
|
+
*/
|
|
111
|
+
const isArray = _Array.isArray;
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Safe copies of Console built-in methods.
|
|
115
|
+
*
|
|
116
|
+
* These references are captured at module initialization time to protect against
|
|
117
|
+
* prototype pollution attacks. Import only what you need for tree-shaking.
|
|
118
|
+
*
|
|
119
|
+
* @module @hyperfrontend/immutable-api-utils/built-in-copy/console
|
|
120
|
+
*/
|
|
121
|
+
// Capture references at module initialization time
|
|
122
|
+
const _console = globalThis.console;
|
|
123
|
+
/**
|
|
124
|
+
* (Safe copy) Outputs a message to the console.
|
|
125
|
+
*/
|
|
126
|
+
const log = _console.log.bind(_console);
|
|
127
|
+
/**
|
|
128
|
+
* (Safe copy) Outputs a warning message to the console.
|
|
129
|
+
*/
|
|
130
|
+
const warn = _console.warn.bind(_console);
|
|
131
|
+
/**
|
|
132
|
+
* (Safe copy) Outputs an error message to the console.
|
|
133
|
+
*/
|
|
134
|
+
const error = _console.error.bind(_console);
|
|
135
|
+
/**
|
|
136
|
+
* (Safe copy) Outputs an informational message to the console.
|
|
137
|
+
*/
|
|
138
|
+
const info = _console.info.bind(_console);
|
|
139
|
+
/**
|
|
140
|
+
* (Safe copy) Outputs a debug message to the console.
|
|
141
|
+
*/
|
|
142
|
+
const debug = _console.debug.bind(_console);
|
|
143
|
+
/**
|
|
144
|
+
* (Safe copy) Outputs a stack trace to the console.
|
|
145
|
+
*/
|
|
146
|
+
_console.trace.bind(_console);
|
|
147
|
+
/**
|
|
148
|
+
* (Safe copy) Displays an interactive listing of the properties of a specified object.
|
|
149
|
+
*/
|
|
150
|
+
_console.dir.bind(_console);
|
|
151
|
+
/**
|
|
152
|
+
* (Safe copy) Displays tabular data as a table.
|
|
153
|
+
*/
|
|
154
|
+
_console.table.bind(_console);
|
|
155
|
+
/**
|
|
156
|
+
* (Safe copy) Writes an error message to the console if the assertion is false.
|
|
157
|
+
*/
|
|
158
|
+
_console.assert.bind(_console);
|
|
159
|
+
/**
|
|
160
|
+
* (Safe copy) Clears the console.
|
|
161
|
+
*/
|
|
162
|
+
_console.clear.bind(_console);
|
|
163
|
+
/**
|
|
164
|
+
* (Safe copy) Logs the number of times that this particular call to count() has been called.
|
|
165
|
+
*/
|
|
166
|
+
_console.count.bind(_console);
|
|
167
|
+
/**
|
|
168
|
+
* (Safe copy) Resets the counter used with console.count().
|
|
169
|
+
*/
|
|
170
|
+
_console.countReset.bind(_console);
|
|
171
|
+
/**
|
|
172
|
+
* (Safe copy) Creates a new inline group in the console.
|
|
173
|
+
*/
|
|
174
|
+
_console.group.bind(_console);
|
|
175
|
+
/**
|
|
176
|
+
* (Safe copy) Creates a new inline group in the console that is initially collapsed.
|
|
177
|
+
*/
|
|
178
|
+
_console.groupCollapsed.bind(_console);
|
|
179
|
+
/**
|
|
180
|
+
* (Safe copy) Exits the current inline group.
|
|
181
|
+
*/
|
|
182
|
+
_console.groupEnd.bind(_console);
|
|
183
|
+
/**
|
|
184
|
+
* (Safe copy) Starts a timer with a name specified as an input parameter.
|
|
185
|
+
*/
|
|
186
|
+
_console.time.bind(_console);
|
|
187
|
+
/**
|
|
188
|
+
* (Safe copy) Stops a timer that was previously started.
|
|
189
|
+
*/
|
|
190
|
+
_console.timeEnd.bind(_console);
|
|
191
|
+
/**
|
|
192
|
+
* (Safe copy) Logs the current value of a timer that was previously started.
|
|
193
|
+
*/
|
|
194
|
+
_console.timeLog.bind(_console);
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Safe copies of Set built-in via factory function.
|
|
198
|
+
*
|
|
199
|
+
* Since constructors cannot be safely captured via Object.assign, this module
|
|
200
|
+
* provides a factory function that uses Reflect.construct internally.
|
|
201
|
+
*
|
|
202
|
+
* These references are captured at module initialization time to protect against
|
|
203
|
+
* prototype pollution attacks. Import only what you need for tree-shaking.
|
|
204
|
+
*
|
|
205
|
+
* @module @hyperfrontend/immutable-api-utils/built-in-copy/set
|
|
206
|
+
*/
|
|
207
|
+
// Capture references at module initialization time
|
|
208
|
+
const _Set = globalThis.Set;
|
|
209
|
+
const _Reflect$1 = globalThis.Reflect;
|
|
210
|
+
/**
|
|
211
|
+
* (Safe copy) Creates a new Set using the captured Set constructor.
|
|
212
|
+
* Use this instead of `new Set()`.
|
|
213
|
+
*
|
|
214
|
+
* @param iterable - Optional iterable of values.
|
|
215
|
+
* @returns A new Set instance.
|
|
216
|
+
*/
|
|
217
|
+
const createSet = (iterable) => _Reflect$1.construct(_Set, iterable ? [iterable] : []);
|
|
218
|
+
|
|
219
|
+
const registeredClasses = [];
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Returns the data type of the target.
|
|
223
|
+
* Uses native `typeof` operator, however, makes distinction between `null`, `array`, and `object`.
|
|
224
|
+
* Also, when classes are registered via `registerClass`, it checks if objects are instance of any known registered class.
|
|
225
|
+
*
|
|
226
|
+
* @param target - The target to get the data type of.
|
|
227
|
+
* @returns The data type of the target.
|
|
228
|
+
*/
|
|
229
|
+
const getType = (target) => {
|
|
230
|
+
if (target === null)
|
|
231
|
+
return 'null';
|
|
232
|
+
const nativeDataType = typeof target;
|
|
233
|
+
if (nativeDataType === 'object') {
|
|
234
|
+
if (isArray(target))
|
|
235
|
+
return 'array';
|
|
236
|
+
for (const registeredClass of registeredClasses) {
|
|
237
|
+
if (target instanceof registeredClass)
|
|
238
|
+
return registeredClass.name;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
return nativeDataType;
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Safe copies of Map built-in via factory function.
|
|
246
|
+
*
|
|
247
|
+
* Since constructors cannot be safely captured via Object.assign, this module
|
|
248
|
+
* provides a factory function that uses Reflect.construct internally.
|
|
249
|
+
*
|
|
250
|
+
* These references are captured at module initialization time to protect against
|
|
251
|
+
* prototype pollution attacks. Import only what you need for tree-shaking.
|
|
252
|
+
*
|
|
253
|
+
* @module @hyperfrontend/immutable-api-utils/built-in-copy/map
|
|
254
|
+
*/
|
|
255
|
+
// Capture references at module initialization time
|
|
256
|
+
const _Map = globalThis.Map;
|
|
257
|
+
const _Reflect = globalThis.Reflect;
|
|
258
|
+
/**
|
|
259
|
+
* (Safe copy) Creates a new Map using the captured Map constructor.
|
|
260
|
+
* Use this instead of `new Map()`.
|
|
261
|
+
*
|
|
262
|
+
* @param iterable - Optional iterable of key-value pairs.
|
|
263
|
+
* @returns A new Map instance.
|
|
264
|
+
*/
|
|
265
|
+
const createMap = (iterable) => _Reflect.construct(_Map, iterable ? [iterable] : []);
|
|
266
|
+
|
|
267
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
268
|
+
/**
|
|
269
|
+
* Creates a wrapper function that only executes the wrapped function if the condition function returns true.
|
|
270
|
+
*
|
|
271
|
+
* @param func - The function to be conditionally executed.
|
|
272
|
+
* @param conditionFunc - A function that returns a boolean, determining if `func` should be executed.
|
|
273
|
+
* @returns A wrapped version of `func` that executes conditionally.
|
|
274
|
+
*/
|
|
275
|
+
function createConditionalExecutionFunction(func, conditionFunc) {
|
|
276
|
+
return function (...args) {
|
|
277
|
+
if (conditionFunc()) {
|
|
278
|
+
return func(...args);
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
284
|
+
/**
|
|
285
|
+
* Creates a wrapper function that silently ignores any errors thrown by the wrapped void function.
|
|
286
|
+
* This function is specifically for wrapping functions that do not return a value (void functions).
|
|
287
|
+
* Exceptions are swallowed without any logging or handling.
|
|
288
|
+
*
|
|
289
|
+
* @param func - The void function to be wrapped.
|
|
290
|
+
* @returns A wrapped version of the input function that ignores errors.
|
|
291
|
+
*/
|
|
292
|
+
function createErrorIgnoringFunction(func) {
|
|
293
|
+
return function (...args) {
|
|
294
|
+
try {
|
|
295
|
+
func(...args);
|
|
296
|
+
}
|
|
297
|
+
catch {
|
|
298
|
+
// Deliberately swallowing/ignoring the exception
|
|
299
|
+
}
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
304
|
+
/**
|
|
305
|
+
* A no-operation function (noop) that does nothing regardless of the arguments passed.
|
|
306
|
+
* It is designed to be as permissive as possible in its typing without using the `Function` keyword.
|
|
307
|
+
*
|
|
308
|
+
* @param args - Any arguments passed to the function (ignored)
|
|
309
|
+
*/
|
|
310
|
+
const noop = (...args) => {
|
|
311
|
+
// Intentionally does nothing
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
const logLevels = ['none', 'error', 'warn', 'log', 'info', 'debug'];
|
|
315
|
+
const priority = {
|
|
316
|
+
error: 4,
|
|
317
|
+
warn: 3,
|
|
318
|
+
log: 2,
|
|
319
|
+
info: 1,
|
|
320
|
+
debug: 0,
|
|
321
|
+
};
|
|
322
|
+
/**
|
|
323
|
+
* Validates whether a given string is a valid log level.
|
|
324
|
+
*
|
|
325
|
+
* @param level - The log level to validate
|
|
326
|
+
* @returns True if the level is valid, false otherwise
|
|
327
|
+
*/
|
|
328
|
+
function isValidLogLevel(level) {
|
|
329
|
+
return logLevels.includes(level);
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Creates a log level configuration manager for controlling logging behavior.
|
|
333
|
+
* Provides methods to get, set, and evaluate log levels based on priority.
|
|
334
|
+
*
|
|
335
|
+
* @param level - The initial log level (defaults to 'error')
|
|
336
|
+
* @returns A configuration object with log level management methods
|
|
337
|
+
* @throws {Error} When the provided level is not a valid log level
|
|
338
|
+
*/
|
|
339
|
+
function createLogLevelConfig(level = 'error') {
|
|
340
|
+
if (!isValidLogLevel(level)) {
|
|
341
|
+
throw createError('Cannot create log level configuration with a valid default log level');
|
|
342
|
+
}
|
|
343
|
+
const state = { level };
|
|
344
|
+
const getLogLevel = () => state.level;
|
|
345
|
+
const setLogLevel = (level) => {
|
|
346
|
+
if (!isValidLogLevel(level)) {
|
|
347
|
+
throw createError(`Cannot set value '${level}' level. Expected levels are ${logLevels}.`);
|
|
348
|
+
}
|
|
349
|
+
state.level = level;
|
|
350
|
+
};
|
|
351
|
+
const shouldLog = (level) => {
|
|
352
|
+
if (state.level === 'none' || level === 'none' || !isValidLogLevel(level)) {
|
|
353
|
+
return false;
|
|
354
|
+
}
|
|
355
|
+
return priority[level] >= priority[state.level];
|
|
356
|
+
};
|
|
357
|
+
return freeze({
|
|
358
|
+
getLogLevel,
|
|
359
|
+
setLogLevel,
|
|
360
|
+
shouldLog,
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Creates a logger instance with configurable log level filtering.
|
|
366
|
+
* Each log function is wrapped to respect the current log level setting.
|
|
367
|
+
*
|
|
368
|
+
* @param error - Function to handle error-level logs (required)
|
|
369
|
+
* @param warn - Function to handle warning-level logs (optional, defaults to noop)
|
|
370
|
+
* @param log - Function to handle standard logs (optional, defaults to noop)
|
|
371
|
+
* @param info - Function to handle info-level logs (optional, defaults to noop)
|
|
372
|
+
* @param debug - Function to handle debug-level logs (optional, defaults to noop)
|
|
373
|
+
* @returns A frozen logger object with log methods and level control
|
|
374
|
+
* @throws {ErrorLevelFn} When any provided log function is invalid
|
|
375
|
+
*/
|
|
376
|
+
function createLogger(error, warn = noop, log = noop, info = noop, debug = noop) {
|
|
377
|
+
if (notValidLogFn(error)) {
|
|
378
|
+
throw createError(notFnMsg('error'));
|
|
379
|
+
}
|
|
380
|
+
if (notValidLogFn(warn)) {
|
|
381
|
+
throw createError(notFnMsg('warn'));
|
|
382
|
+
}
|
|
383
|
+
if (notValidLogFn(log)) {
|
|
384
|
+
throw createError(notFnMsg('log'));
|
|
385
|
+
}
|
|
386
|
+
if (notValidLogFn(info)) {
|
|
387
|
+
throw createError(notFnMsg('info'));
|
|
388
|
+
}
|
|
389
|
+
if (notValidLogFn(debug)) {
|
|
390
|
+
throw createError(notFnMsg('debug'));
|
|
391
|
+
}
|
|
392
|
+
const { setLogLevel, getLogLevel, shouldLog } = createLogLevelConfig();
|
|
393
|
+
const wrapLogFn = (fn, level) => {
|
|
394
|
+
if (fn === noop)
|
|
395
|
+
return fn;
|
|
396
|
+
const condition = () => shouldLog(level);
|
|
397
|
+
return createConditionalExecutionFunction(createErrorIgnoringFunction(fn), condition);
|
|
398
|
+
};
|
|
399
|
+
return freeze({
|
|
400
|
+
error: wrapLogFn(error, 'error'),
|
|
401
|
+
warn: wrapLogFn(warn, 'warn'),
|
|
402
|
+
log: wrapLogFn(log, 'log'),
|
|
403
|
+
info: wrapLogFn(info, 'info'),
|
|
404
|
+
debug: wrapLogFn(debug, 'debug'),
|
|
405
|
+
setLogLevel,
|
|
406
|
+
getLogLevel,
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* Validates whether a given value is a valid log function.
|
|
411
|
+
*
|
|
412
|
+
* @param fn - The value to validate
|
|
413
|
+
* @returns True if the value is not a function (invalid), false if it is valid
|
|
414
|
+
*/
|
|
415
|
+
function notValidLogFn(fn) {
|
|
416
|
+
return getType(fn) !== 'function' && fn !== noop;
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* Generates an error message for invalid log function parameters.
|
|
420
|
+
*
|
|
421
|
+
* @param label - The name of the log function that failed validation
|
|
422
|
+
* @returns A formatted error message string
|
|
423
|
+
*/
|
|
424
|
+
function notFnMsg(label) {
|
|
425
|
+
return `Cannot create a logger when ${label} is not a function`;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
createLogger(error, warn, log, info, debug);
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* Global log level registry.
|
|
432
|
+
* Tracks all created scoped loggers to allow global log level changes.
|
|
433
|
+
*/
|
|
434
|
+
const loggerRegistry = createSet();
|
|
435
|
+
/** Redacted placeholder for sensitive values */
|
|
436
|
+
const REDACTED = '[REDACTED]';
|
|
437
|
+
/**
|
|
438
|
+
* Patterns that indicate a sensitive key name.
|
|
439
|
+
* Keys containing these patterns will have their values sanitized.
|
|
440
|
+
*/
|
|
441
|
+
const SENSITIVE_KEY_PATTERNS = [
|
|
442
|
+
/token/i,
|
|
443
|
+
/key/i,
|
|
444
|
+
/password/i,
|
|
445
|
+
/secret/i,
|
|
446
|
+
/credential/i,
|
|
447
|
+
/auth/i,
|
|
448
|
+
/bearer/i,
|
|
449
|
+
/api[_-]?key/i,
|
|
450
|
+
/private/i,
|
|
451
|
+
/passphrase/i,
|
|
452
|
+
];
|
|
453
|
+
/**
|
|
454
|
+
* Checks if a key name indicates sensitive data.
|
|
455
|
+
*
|
|
456
|
+
* @param key - Key name to check
|
|
457
|
+
* @returns True if the key indicates sensitive data
|
|
458
|
+
*/
|
|
459
|
+
function isSensitiveKey(key) {
|
|
460
|
+
return SENSITIVE_KEY_PATTERNS.some((pattern) => pattern.test(key));
|
|
461
|
+
}
|
|
462
|
+
/**
|
|
463
|
+
* Sanitizes an object by replacing sensitive values with REDACTED.
|
|
464
|
+
* This function recursively processes nested objects and arrays.
|
|
465
|
+
*
|
|
466
|
+
* @param obj - Object to sanitize
|
|
467
|
+
* @returns New object with sensitive values redacted
|
|
468
|
+
*/
|
|
469
|
+
function sanitize(obj) {
|
|
470
|
+
if (obj === null || obj === undefined) {
|
|
471
|
+
return obj;
|
|
472
|
+
}
|
|
473
|
+
if (isArray(obj)) {
|
|
474
|
+
return obj.map((item) => sanitize(item));
|
|
475
|
+
}
|
|
476
|
+
if (typeof obj === 'object') {
|
|
477
|
+
const result = {};
|
|
478
|
+
for (const [key, value] of entries(obj)) {
|
|
479
|
+
if (isSensitiveKey(key)) {
|
|
480
|
+
result[key] = REDACTED;
|
|
481
|
+
}
|
|
482
|
+
else if (typeof value === 'object' && value !== null) {
|
|
483
|
+
result[key] = sanitize(value);
|
|
484
|
+
}
|
|
485
|
+
else {
|
|
486
|
+
result[key] = value;
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
return result;
|
|
490
|
+
}
|
|
491
|
+
return obj;
|
|
492
|
+
}
|
|
493
|
+
/**
|
|
494
|
+
* Formats a log message with optional metadata.
|
|
495
|
+
*
|
|
496
|
+
* @param namespace - Logger namespace prefix
|
|
497
|
+
* @param message - Log message
|
|
498
|
+
* @param meta - Optional metadata object
|
|
499
|
+
* @returns Formatted log string
|
|
500
|
+
*/
|
|
501
|
+
function formatMessage(namespace, message, meta) {
|
|
502
|
+
const prefix = `[${namespace}]`;
|
|
503
|
+
if (meta && keys(meta).length > 0) {
|
|
504
|
+
const sanitizedMeta = sanitize(meta);
|
|
505
|
+
return `${prefix} ${message} ${stringify(sanitizedMeta)}`;
|
|
506
|
+
}
|
|
507
|
+
return `${prefix} ${message}`;
|
|
508
|
+
}
|
|
509
|
+
/**
|
|
510
|
+
* Creates a scoped logger with namespace prefix and optional secret sanitization.
|
|
511
|
+
* All log messages will be prefixed with [namespace] and sensitive metadata
|
|
512
|
+
* values will be automatically redacted.
|
|
513
|
+
*
|
|
514
|
+
* @param namespace - Logger namespace (e.g., 'project-scope', 'analyze')
|
|
515
|
+
* @param options - Logger configuration options
|
|
516
|
+
* @returns A configured scoped logger instance
|
|
517
|
+
*
|
|
518
|
+
* @example
|
|
519
|
+
* ```typescript
|
|
520
|
+
* const logger = createScopedLogger('project-scope')
|
|
521
|
+
* logger.setLogLevel('debug')
|
|
522
|
+
*
|
|
523
|
+
* // Basic logging
|
|
524
|
+
* logger.info('Starting analysis', { path: './project' })
|
|
525
|
+
*
|
|
526
|
+
* // Sensitive data is automatically redacted
|
|
527
|
+
* logger.debug('Config loaded', { apiKey: 'secret123' })
|
|
528
|
+
* // Output: [project-scope] Config loaded {"apiKey":"[REDACTED]"}
|
|
529
|
+
* ```
|
|
530
|
+
*/
|
|
531
|
+
function createScopedLogger(namespace, options = {}) {
|
|
532
|
+
const { level = 'error', sanitizeSecrets = true } = options;
|
|
533
|
+
// Create wrapper functions that add namespace prefix and sanitization
|
|
534
|
+
const createLogFn = (baseFn) => (message, meta) => {
|
|
535
|
+
const processedMeta = sanitizeSecrets && meta ? sanitize(meta) : meta;
|
|
536
|
+
baseFn(formatMessage(namespace, message, processedMeta));
|
|
537
|
+
};
|
|
538
|
+
// Create base logger with wrapped functions
|
|
539
|
+
const baseLogger = createLogger(createLogFn(error), createLogFn(warn), createLogFn(log), createLogFn(info), createLogFn(debug));
|
|
540
|
+
// Set initial log level (use global override if set)
|
|
541
|
+
baseLogger.setLogLevel(level);
|
|
542
|
+
const scopedLogger = freeze({
|
|
543
|
+
error: (message, meta) => baseLogger.error(message, meta),
|
|
544
|
+
warn: (message, meta) => baseLogger.warn(message, meta),
|
|
545
|
+
log: (message, meta) => baseLogger.log(message, meta),
|
|
546
|
+
info: (message, meta) => baseLogger.info(message, meta),
|
|
547
|
+
debug: (message, meta) => baseLogger.debug(message, meta),
|
|
548
|
+
setLogLevel: baseLogger.setLogLevel,
|
|
549
|
+
getLogLevel: baseLogger.getLogLevel,
|
|
550
|
+
});
|
|
551
|
+
// Register logger for global level management
|
|
552
|
+
loggerRegistry.add(scopedLogger);
|
|
553
|
+
return scopedLogger;
|
|
554
|
+
}
|
|
555
|
+
/**
|
|
556
|
+
* Default logger instance for the project-scope library.
|
|
557
|
+
* Use this for general logging within the library.
|
|
558
|
+
*
|
|
559
|
+
* @example
|
|
560
|
+
* ```typescript
|
|
561
|
+
* import { logger } from '@hyperfrontend/project-scope/core'
|
|
562
|
+
*
|
|
563
|
+
* logger.setLogLevel('debug')
|
|
564
|
+
* logger.debug('Analyzing project', { path: './src' })
|
|
565
|
+
* ```
|
|
566
|
+
*/
|
|
567
|
+
createScopedLogger('project-scope');
|
|
568
|
+
|
|
569
|
+
const fsLogger = createScopedLogger('project-scope:fs');
|
|
570
|
+
/**
|
|
571
|
+
* Create a file system error with code and context.
|
|
572
|
+
*
|
|
573
|
+
* @param message - The error message describing what went wrong
|
|
574
|
+
* @param code - The category code for this type of filesystem failure
|
|
575
|
+
* @param context - Additional context including path, operation, and cause
|
|
576
|
+
* @returns A configured Error object with code and context properties
|
|
577
|
+
*/
|
|
578
|
+
function createFileSystemError(message, code, context) {
|
|
579
|
+
const error = createError(message);
|
|
580
|
+
defineProperties(error, {
|
|
581
|
+
code: { value: code, enumerable: true },
|
|
582
|
+
context: { value: context, enumerable: true },
|
|
583
|
+
});
|
|
584
|
+
return error;
|
|
585
|
+
}
|
|
586
|
+
/**
|
|
587
|
+
* Read file contents as string.
|
|
588
|
+
*
|
|
589
|
+
* @param filePath - Path to file
|
|
590
|
+
* @param encoding - File encoding (default: utf-8)
|
|
591
|
+
* @returns File contents as string
|
|
592
|
+
* @throws {Error} If file doesn't exist or can't be read
|
|
593
|
+
*
|
|
594
|
+
* @example
|
|
595
|
+
* ```typescript
|
|
596
|
+
* import { readFileContent } from '@hyperfrontend/project-scope'
|
|
597
|
+
*
|
|
598
|
+
* const content = readFileContent('./package.json')
|
|
599
|
+
* console.log(content) // JSON string
|
|
600
|
+
* ```
|
|
601
|
+
*/
|
|
602
|
+
function readFileContent(filePath, encoding = 'utf-8') {
|
|
603
|
+
if (!existsSync(filePath)) {
|
|
604
|
+
fsLogger.debug('File not found', { path: filePath });
|
|
605
|
+
throw createFileSystemError(`File not found: ${filePath}`, 'FS_NOT_FOUND', { path: filePath, operation: 'read' });
|
|
606
|
+
}
|
|
607
|
+
try {
|
|
608
|
+
return readFileSync(filePath, { encoding });
|
|
609
|
+
}
|
|
610
|
+
catch (error) {
|
|
611
|
+
fsLogger.warn('Failed to read file', { path: filePath });
|
|
612
|
+
throw createFileSystemError(`Failed to read file: ${filePath}`, 'FS_READ_ERROR', { path: filePath, operation: 'read', cause: error });
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
/**
|
|
616
|
+
* Read file if exists, return null otherwise.
|
|
617
|
+
*
|
|
618
|
+
* @param filePath - Path to file
|
|
619
|
+
* @param encoding - File encoding (default: utf-8)
|
|
620
|
+
* @returns File contents or null if file doesn't exist
|
|
621
|
+
*/
|
|
622
|
+
function readFileIfExists(filePath, encoding = 'utf-8') {
|
|
623
|
+
if (!existsSync(filePath)) {
|
|
624
|
+
return null;
|
|
625
|
+
}
|
|
626
|
+
try {
|
|
627
|
+
return readFileSync(filePath, { encoding });
|
|
628
|
+
}
|
|
629
|
+
catch {
|
|
630
|
+
return null;
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
createScopedLogger('project-scope:fs:write');
|
|
635
|
+
|
|
636
|
+
/**
|
|
637
|
+
* Get file stats with error handling.
|
|
638
|
+
*
|
|
639
|
+
* @param filePath - Path to file
|
|
640
|
+
* @param followSymlinks - Whether to follow symlinks (default: true)
|
|
641
|
+
* @returns File stats or null if path doesn't exist
|
|
642
|
+
*/
|
|
643
|
+
function getFileStat(filePath, followSymlinks = true) {
|
|
644
|
+
if (!existsSync(filePath)) {
|
|
645
|
+
return null;
|
|
646
|
+
}
|
|
647
|
+
try {
|
|
648
|
+
const stat = followSymlinks ? statSync(filePath) : lstatSync(filePath);
|
|
649
|
+
return {
|
|
650
|
+
isFile: stat.isFile(),
|
|
651
|
+
isDirectory: stat.isDirectory(),
|
|
652
|
+
isSymlink: stat.isSymbolicLink(),
|
|
653
|
+
size: stat.size,
|
|
654
|
+
created: stat.birthtime,
|
|
655
|
+
modified: stat.mtime,
|
|
656
|
+
accessed: stat.atime,
|
|
657
|
+
mode: stat.mode,
|
|
658
|
+
};
|
|
659
|
+
}
|
|
660
|
+
catch {
|
|
661
|
+
return null;
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
/**
|
|
665
|
+
* Check if path is a file.
|
|
666
|
+
*
|
|
667
|
+
* @param filePath - Path to check
|
|
668
|
+
* @returns True if path is a file
|
|
669
|
+
*/
|
|
670
|
+
function isFile(filePath) {
|
|
671
|
+
const stats = getFileStat(filePath);
|
|
672
|
+
return stats?.isFile ?? false;
|
|
673
|
+
}
|
|
674
|
+
/**
|
|
675
|
+
* Check if path is a directory.
|
|
676
|
+
*
|
|
677
|
+
* @param dirPath - Path to check
|
|
678
|
+
* @returns True if path is a directory
|
|
679
|
+
*/
|
|
680
|
+
function isDirectory(dirPath) {
|
|
681
|
+
const stats = getFileStat(dirPath);
|
|
682
|
+
return stats?.isDirectory ?? false;
|
|
683
|
+
}
|
|
684
|
+
/**
|
|
685
|
+
* Check if path exists.
|
|
686
|
+
*
|
|
687
|
+
* @param filePath - Path to check
|
|
688
|
+
* @returns True if path exists
|
|
689
|
+
*/
|
|
690
|
+
function exists(filePath) {
|
|
691
|
+
return existsSync(filePath);
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
const fsDirLogger = createScopedLogger('project-scope:fs:dir');
|
|
695
|
+
/**
|
|
696
|
+
* List immediate contents of a directory.
|
|
697
|
+
*
|
|
698
|
+
* @param dirPath - Absolute or relative path to the directory
|
|
699
|
+
* @returns Array of entries with metadata for each file/directory
|
|
700
|
+
* @throws {Error} If directory doesn't exist or isn't a directory
|
|
701
|
+
*
|
|
702
|
+
* @example
|
|
703
|
+
* ```typescript
|
|
704
|
+
* import { readDirectory } from '@hyperfrontend/project-scope'
|
|
705
|
+
*
|
|
706
|
+
* const entries = readDirectory('./src')
|
|
707
|
+
* for (const entry of entries) {
|
|
708
|
+
* console.log(entry.name, entry.isFile ? 'file' : 'directory')
|
|
709
|
+
* }
|
|
710
|
+
* ```
|
|
711
|
+
*/
|
|
712
|
+
function readDirectory(dirPath) {
|
|
713
|
+
fsDirLogger.debug('Reading directory', { path: dirPath });
|
|
714
|
+
if (!existsSync(dirPath)) {
|
|
715
|
+
fsDirLogger.debug('Directory not found', { path: dirPath });
|
|
716
|
+
throw createFileSystemError(`Directory not found: ${dirPath}`, 'FS_NOT_FOUND', { path: dirPath, operation: 'readdir' });
|
|
717
|
+
}
|
|
718
|
+
if (!isDirectory(dirPath)) {
|
|
719
|
+
fsDirLogger.debug('Path is not a directory', { path: dirPath });
|
|
720
|
+
throw createFileSystemError(`Not a directory: ${dirPath}`, 'FS_NOT_A_DIRECTORY', { path: dirPath, operation: 'readdir' });
|
|
721
|
+
}
|
|
722
|
+
try {
|
|
723
|
+
const entries = readdirSync(dirPath, { withFileTypes: true });
|
|
724
|
+
fsDirLogger.debug('Directory read complete', { path: dirPath, entryCount: entries.length });
|
|
725
|
+
return entries.map((entry) => ({
|
|
726
|
+
name: entry.name,
|
|
727
|
+
path: join$1(dirPath, entry.name),
|
|
728
|
+
isFile: entry.isFile(),
|
|
729
|
+
isDirectory: entry.isDirectory(),
|
|
730
|
+
isSymlink: entry.isSymbolicLink(),
|
|
731
|
+
}));
|
|
732
|
+
}
|
|
733
|
+
catch (error) {
|
|
734
|
+
fsDirLogger.warn('Failed to read directory', { path: dirPath, error: error instanceof Error ? error.message : String(error) });
|
|
735
|
+
throw createFileSystemError(`Failed to read directory: ${dirPath}`, 'FS_READ_ERROR', {
|
|
736
|
+
path: dirPath,
|
|
737
|
+
operation: 'readdir',
|
|
738
|
+
cause: error,
|
|
739
|
+
});
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
/**
|
|
744
|
+
* Join path segments.
|
|
745
|
+
* Uses platform-specific separators (e.g., / or \).
|
|
746
|
+
*
|
|
747
|
+
* @param paths - Path segments to join
|
|
748
|
+
* @returns Joined path
|
|
749
|
+
*/
|
|
750
|
+
function join(...paths) {
|
|
751
|
+
return join$1(...paths);
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
createScopedLogger('project-scope:fs:traversal');
|
|
755
|
+
|
|
756
|
+
const packageLogger = createScopedLogger('project-scope:project:package');
|
|
757
|
+
/**
|
|
758
|
+
* Verifies that a value is an object with only string values,
|
|
759
|
+
* used for validating dependency maps and script definitions.
|
|
760
|
+
*
|
|
761
|
+
* @param value - Value to check
|
|
762
|
+
* @returns True if value is a record of strings
|
|
763
|
+
*/
|
|
764
|
+
function isStringRecord(value) {
|
|
765
|
+
if (typeof value !== 'object' || value === null)
|
|
766
|
+
return false;
|
|
767
|
+
return values(value).every((v) => typeof v === 'string');
|
|
768
|
+
}
|
|
769
|
+
/**
|
|
770
|
+
* Extracts and normalizes the workspaces field from package.json,
|
|
771
|
+
* supporting both array format and object with packages array.
|
|
772
|
+
*
|
|
773
|
+
* @param value - Raw workspaces value from package.json
|
|
774
|
+
* @returns Normalized workspace patterns or undefined if invalid
|
|
775
|
+
*/
|
|
776
|
+
function parseWorkspaces(value) {
|
|
777
|
+
if (isArray(value) && value.every((v) => typeof v === 'string')) {
|
|
778
|
+
return value;
|
|
779
|
+
}
|
|
780
|
+
if (typeof value === 'object' && value !== null) {
|
|
781
|
+
const obj = value;
|
|
782
|
+
if (isArray(obj['packages'])) {
|
|
783
|
+
return { packages: obj['packages'] };
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
return undefined;
|
|
787
|
+
}
|
|
788
|
+
/**
|
|
789
|
+
* Validate and normalize package.json data.
|
|
790
|
+
*
|
|
791
|
+
* @param data - Raw parsed data
|
|
792
|
+
* @returns Validated package.json
|
|
793
|
+
*/
|
|
794
|
+
function validatePackageJson(data) {
|
|
795
|
+
if (typeof data !== 'object' || data === null) {
|
|
796
|
+
throw createError('package.json must be an object');
|
|
797
|
+
}
|
|
798
|
+
const pkg = data;
|
|
799
|
+
return {
|
|
800
|
+
name: typeof pkg['name'] === 'string' ? pkg['name'] : undefined,
|
|
801
|
+
version: typeof pkg['version'] === 'string' ? pkg['version'] : undefined,
|
|
802
|
+
description: typeof pkg['description'] === 'string' ? pkg['description'] : undefined,
|
|
803
|
+
main: typeof pkg['main'] === 'string' ? pkg['main'] : undefined,
|
|
804
|
+
module: typeof pkg['module'] === 'string' ? pkg['module'] : undefined,
|
|
805
|
+
browser: typeof pkg['browser'] === 'string' ? pkg['browser'] : undefined,
|
|
806
|
+
types: typeof pkg['types'] === 'string' ? pkg['types'] : undefined,
|
|
807
|
+
bin: typeof pkg['bin'] === 'string' || isStringRecord(pkg['bin']) ? pkg['bin'] : undefined,
|
|
808
|
+
scripts: isStringRecord(pkg['scripts']) ? pkg['scripts'] : undefined,
|
|
809
|
+
dependencies: isStringRecord(pkg['dependencies']) ? pkg['dependencies'] : undefined,
|
|
810
|
+
devDependencies: isStringRecord(pkg['devDependencies']) ? pkg['devDependencies'] : undefined,
|
|
811
|
+
peerDependencies: isStringRecord(pkg['peerDependencies']) ? pkg['peerDependencies'] : undefined,
|
|
812
|
+
optionalDependencies: isStringRecord(pkg['optionalDependencies']) ? pkg['optionalDependencies'] : undefined,
|
|
813
|
+
workspaces: parseWorkspaces(pkg['workspaces']),
|
|
814
|
+
exports: typeof pkg['exports'] === 'object' ? pkg['exports'] : undefined,
|
|
815
|
+
engines: isStringRecord(pkg['engines']) ? pkg['engines'] : undefined,
|
|
816
|
+
...pkg,
|
|
817
|
+
};
|
|
818
|
+
}
|
|
819
|
+
/**
|
|
820
|
+
* Attempts to read and parse package.json if it exists,
|
|
821
|
+
* returning null on missing file or parse failure.
|
|
822
|
+
*
|
|
823
|
+
* @param projectPath - Project directory path or path to package.json
|
|
824
|
+
* @returns Parsed package.json or null if not found
|
|
825
|
+
*/
|
|
826
|
+
function readPackageJsonIfExists(projectPath) {
|
|
827
|
+
const packageJsonPath = projectPath.endsWith('package.json') ? projectPath : join$1(projectPath, 'package.json');
|
|
828
|
+
const content = readFileIfExists(packageJsonPath);
|
|
829
|
+
if (!content) {
|
|
830
|
+
packageLogger.debug('Package.json not found', { path: packageJsonPath });
|
|
831
|
+
return null;
|
|
832
|
+
}
|
|
833
|
+
try {
|
|
834
|
+
const validated = validatePackageJson(parse(content));
|
|
835
|
+
packageLogger.debug('Package.json loaded', { path: packageJsonPath, name: validated.name });
|
|
836
|
+
return validated;
|
|
837
|
+
}
|
|
838
|
+
catch {
|
|
839
|
+
packageLogger.debug('Failed to parse package.json, returning null', { path: packageJsonPath });
|
|
840
|
+
return null;
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
/**
|
|
845
|
+
* Global registry of all caches for bulk operations.
|
|
846
|
+
*/
|
|
847
|
+
const cacheRegistry = createSet();
|
|
848
|
+
/**
|
|
849
|
+
* Create a cache with optional TTL and size limits.
|
|
850
|
+
*
|
|
851
|
+
* The cache provides a simple key-value store with:
|
|
852
|
+
* - Optional TTL (time-to-live) for automatic expiration
|
|
853
|
+
* - Optional maxSize for limiting cache size with FIFO eviction
|
|
854
|
+
* - Lazy expiration (entries are checked on access)
|
|
855
|
+
*
|
|
856
|
+
* @param options - Cache configuration options
|
|
857
|
+
* @returns Cache instance
|
|
858
|
+
*
|
|
859
|
+
* @example
|
|
860
|
+
* ```typescript
|
|
861
|
+
* // Basic cache
|
|
862
|
+
* const cache = createCache<string, number>()
|
|
863
|
+
* cache.set('answer', 42)
|
|
864
|
+
* cache.get('answer') // 42
|
|
865
|
+
*
|
|
866
|
+
* // Cache with TTL (expires after 60 seconds)
|
|
867
|
+
* const ttlCache = createCache<string, object>({ ttl: 60000 })
|
|
868
|
+
*
|
|
869
|
+
* // Cache with max size (evicts oldest when full)
|
|
870
|
+
* const lruCache = createCache<string, object>({ maxSize: 100 })
|
|
871
|
+
*
|
|
872
|
+
* // Combined options
|
|
873
|
+
* const configCache = createCache<string, object>({
|
|
874
|
+
* ttl: 30000,
|
|
875
|
+
* maxSize: 50
|
|
876
|
+
* })
|
|
877
|
+
* ```
|
|
878
|
+
*/
|
|
879
|
+
function createCache(options) {
|
|
880
|
+
const { ttl, maxSize } = options ?? {};
|
|
881
|
+
const store = createMap();
|
|
882
|
+
// Track insertion order for FIFO eviction
|
|
883
|
+
const insertionOrder = [];
|
|
884
|
+
/**
|
|
885
|
+
* Check if an entry is expired.
|
|
886
|
+
*
|
|
887
|
+
* @param entry - Cache entry to check
|
|
888
|
+
* @returns True if entry is expired
|
|
889
|
+
*/
|
|
890
|
+
function isExpired(entry) {
|
|
891
|
+
if (ttl === undefined)
|
|
892
|
+
return false;
|
|
893
|
+
// eslint-disable-next-line workspace/no-unsafe-builtin-methods -- Date.now() is needed for Jest fake timers compatibility
|
|
894
|
+
return Date.now() - entry.timestamp > ttl;
|
|
895
|
+
}
|
|
896
|
+
/**
|
|
897
|
+
* Evict oldest entries to make room for new ones.
|
|
898
|
+
*/
|
|
899
|
+
function evictIfNeeded() {
|
|
900
|
+
if (maxSize === undefined)
|
|
901
|
+
return;
|
|
902
|
+
while (store.size >= maxSize && insertionOrder.length > 0) {
|
|
903
|
+
const oldestKey = insertionOrder.shift();
|
|
904
|
+
if (oldestKey !== undefined) {
|
|
905
|
+
store.delete(oldestKey);
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
/**
|
|
910
|
+
* Remove key from insertion order tracking.
|
|
911
|
+
*
|
|
912
|
+
* @param key - Key to remove from order tracking
|
|
913
|
+
*/
|
|
914
|
+
function removeFromOrder(key) {
|
|
915
|
+
const index = insertionOrder.indexOf(key);
|
|
916
|
+
if (index !== -1) {
|
|
917
|
+
insertionOrder.splice(index, 1);
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
const cache = {
|
|
921
|
+
get(key) {
|
|
922
|
+
const entry = store.get(key);
|
|
923
|
+
if (!entry)
|
|
924
|
+
return undefined;
|
|
925
|
+
if (isExpired(entry)) {
|
|
926
|
+
store.delete(key);
|
|
927
|
+
removeFromOrder(key);
|
|
928
|
+
return undefined;
|
|
929
|
+
}
|
|
930
|
+
return entry.value;
|
|
931
|
+
},
|
|
932
|
+
set(key, value) {
|
|
933
|
+
// If key exists, remove from order first
|
|
934
|
+
if (store.has(key)) {
|
|
935
|
+
removeFromOrder(key);
|
|
936
|
+
}
|
|
937
|
+
else {
|
|
938
|
+
// Evict if needed before adding new entry
|
|
939
|
+
evictIfNeeded();
|
|
940
|
+
}
|
|
941
|
+
// eslint-disable-next-line workspace/no-unsafe-builtin-methods -- Date.now() is needed for Jest fake timers compatibility
|
|
942
|
+
store.set(key, { value, timestamp: Date.now() });
|
|
943
|
+
insertionOrder.push(key);
|
|
944
|
+
},
|
|
945
|
+
has(key) {
|
|
946
|
+
const entry = store.get(key);
|
|
947
|
+
if (!entry)
|
|
948
|
+
return false;
|
|
949
|
+
if (isExpired(entry)) {
|
|
950
|
+
store.delete(key);
|
|
951
|
+
removeFromOrder(key);
|
|
952
|
+
return false;
|
|
953
|
+
}
|
|
954
|
+
return true;
|
|
955
|
+
},
|
|
956
|
+
delete(key) {
|
|
957
|
+
removeFromOrder(key);
|
|
958
|
+
return store.delete(key);
|
|
959
|
+
},
|
|
960
|
+
clear() {
|
|
961
|
+
store.clear();
|
|
962
|
+
insertionOrder.length = 0;
|
|
963
|
+
},
|
|
964
|
+
size() {
|
|
965
|
+
return store.size;
|
|
966
|
+
},
|
|
967
|
+
keys() {
|
|
968
|
+
return [...insertionOrder];
|
|
969
|
+
},
|
|
970
|
+
};
|
|
971
|
+
// Register cache for global operations
|
|
972
|
+
cacheRegistry.add(cache);
|
|
973
|
+
return freeze(cache);
|
|
974
|
+
}
|
|
975
|
+
|
|
976
|
+
/**
|
|
977
|
+
* Get combined dependencies from package.json.
|
|
978
|
+
* Merges dependencies, devDependencies, peerDependencies, and optionalDependencies.
|
|
979
|
+
*
|
|
980
|
+
* @param packageJson - The package.json object to extract dependencies from
|
|
981
|
+
* @returns Combined dependencies as a single record
|
|
982
|
+
*/
|
|
983
|
+
function collectAllDependencies(packageJson) {
|
|
984
|
+
return {
|
|
985
|
+
...packageJson?.dependencies,
|
|
986
|
+
...packageJson?.devDependencies,
|
|
987
|
+
...packageJson?.peerDependencies,
|
|
988
|
+
...packageJson?.optionalDependencies,
|
|
989
|
+
};
|
|
990
|
+
}
|
|
991
|
+
/**
|
|
992
|
+
* Extract clean version from dependency version string.
|
|
993
|
+
* Removes semver prefixes like ^, ~, >=, etc.
|
|
994
|
+
* Uses character-by-character parsing to avoid ReDoS vulnerabilities.
|
|
995
|
+
*
|
|
996
|
+
* @param versionString - The version string with optional prefix characters
|
|
997
|
+
* @returns The cleaned version string without prefix characters
|
|
998
|
+
*/
|
|
999
|
+
function parseVersionString(versionString) {
|
|
1000
|
+
if (versionString === undefined || versionString === null)
|
|
1001
|
+
return undefined;
|
|
1002
|
+
// Manual parsing instead of regex to avoid ReDoS
|
|
1003
|
+
let start = 0;
|
|
1004
|
+
while (start < versionString.length) {
|
|
1005
|
+
const char = versionString[start];
|
|
1006
|
+
if (char !== '^' && char !== '~' && char !== '>' && char !== '=' && char !== '<') {
|
|
1007
|
+
break;
|
|
1008
|
+
}
|
|
1009
|
+
start++;
|
|
1010
|
+
}
|
|
1011
|
+
return versionString.slice(start);
|
|
1012
|
+
}
|
|
1013
|
+
/**
|
|
1014
|
+
* Find first matching config file in project.
|
|
1015
|
+
* Note: Name avoids similarity to fs.readFile/fs.readFileSync.
|
|
1016
|
+
*
|
|
1017
|
+
* @param projectPath - The project directory path
|
|
1018
|
+
* @param patterns - Array of config file patterns to search for
|
|
1019
|
+
* @returns The first matching config file path or undefined
|
|
1020
|
+
*/
|
|
1021
|
+
function locateConfigFile(projectPath, patterns) {
|
|
1022
|
+
for (const pattern of patterns) {
|
|
1023
|
+
const fullPath = join(projectPath, pattern);
|
|
1024
|
+
if (exists(fullPath)) {
|
|
1025
|
+
return pattern;
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
return undefined;
|
|
1029
|
+
}
|
|
1030
|
+
/**
|
|
1031
|
+
* Find scripts containing a specific command.
|
|
1032
|
+
*
|
|
1033
|
+
* @param scripts - The scripts object from package.json
|
|
1034
|
+
* @param command - The command string to search for
|
|
1035
|
+
* @returns Array of script names that contain the command
|
|
1036
|
+
*/
|
|
1037
|
+
function filterScriptsByCommand(scripts, command) {
|
|
1038
|
+
if (!scripts)
|
|
1039
|
+
return [];
|
|
1040
|
+
return entries(scripts)
|
|
1041
|
+
.filter(([, script]) => script.includes(command))
|
|
1042
|
+
.map(([name]) => name);
|
|
1043
|
+
}
|
|
1044
|
+
|
|
1045
|
+
/**
|
|
1046
|
+
* Detect Express in project.
|
|
1047
|
+
*
|
|
1048
|
+
* @param projectPath - Project directory path
|
|
1049
|
+
* @param packageJson - Optional pre-loaded package.json
|
|
1050
|
+
* @returns Detection result or null if not detected
|
|
1051
|
+
*/
|
|
1052
|
+
function expressDetector(projectPath, packageJson) {
|
|
1053
|
+
const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
|
|
1054
|
+
const sources = [];
|
|
1055
|
+
let confidence = 0;
|
|
1056
|
+
let version;
|
|
1057
|
+
const deps = collectAllDependencies(pkg);
|
|
1058
|
+
if (deps['express']) {
|
|
1059
|
+
confidence += 80;
|
|
1060
|
+
version = parseVersionString(deps['express']);
|
|
1061
|
+
sources.push({ type: 'package.json', field: 'dependencies.express' });
|
|
1062
|
+
}
|
|
1063
|
+
// @types/express (indicates usage)
|
|
1064
|
+
if (deps['@types/express']) {
|
|
1065
|
+
confidence += 10;
|
|
1066
|
+
sources.push({ type: 'package.json', field: 'dependencies.@types/express' });
|
|
1067
|
+
}
|
|
1068
|
+
const expressMiddleware = keys(deps).filter((d) => d.includes('express-') || d === 'body-parser' || d === 'cors' || d === 'helmet' || d === 'morgan');
|
|
1069
|
+
if (expressMiddleware.length > 0) {
|
|
1070
|
+
confidence += 10;
|
|
1071
|
+
sources.push({ type: 'package.json', field: 'dependencies (express middleware)' });
|
|
1072
|
+
}
|
|
1073
|
+
if (confidence === 0) {
|
|
1074
|
+
return null;
|
|
1075
|
+
}
|
|
1076
|
+
return {
|
|
1077
|
+
id: 'express',
|
|
1078
|
+
name: 'Express',
|
|
1079
|
+
version,
|
|
1080
|
+
confidence: min(confidence, 100),
|
|
1081
|
+
detectedFrom: sources,
|
|
1082
|
+
};
|
|
1083
|
+
}
|
|
1084
|
+
|
|
1085
|
+
/**
|
|
1086
|
+
* Detect NestJS in project.
|
|
1087
|
+
*
|
|
1088
|
+
* @param projectPath - Project directory path
|
|
1089
|
+
* @param packageJson - Optional pre-loaded package.json
|
|
1090
|
+
* @returns Detection result or null if not detected
|
|
1091
|
+
*/
|
|
1092
|
+
function nestDetector(projectPath, packageJson) {
|
|
1093
|
+
const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
|
|
1094
|
+
const sources = [];
|
|
1095
|
+
let confidence = 0;
|
|
1096
|
+
let version;
|
|
1097
|
+
let configPath;
|
|
1098
|
+
const deps = collectAllDependencies(pkg);
|
|
1099
|
+
// @nestjs/core package
|
|
1100
|
+
if (deps['@nestjs/core']) {
|
|
1101
|
+
confidence += 70;
|
|
1102
|
+
version = parseVersionString(deps['@nestjs/core']);
|
|
1103
|
+
sources.push({ type: 'package.json', field: 'dependencies.@nestjs/core' });
|
|
1104
|
+
}
|
|
1105
|
+
// @nestjs/common
|
|
1106
|
+
if (deps['@nestjs/common']) {
|
|
1107
|
+
confidence += 15;
|
|
1108
|
+
sources.push({ type: 'package.json', field: 'dependencies.@nestjs/common' });
|
|
1109
|
+
}
|
|
1110
|
+
if (exists(join$1(projectPath, 'nest-cli.json'))) {
|
|
1111
|
+
confidence += 15;
|
|
1112
|
+
configPath = 'nest-cli.json';
|
|
1113
|
+
sources.push({ type: 'config-file', path: 'nest-cli.json' });
|
|
1114
|
+
}
|
|
1115
|
+
const nestPackages = keys(deps).filter((d) => d.startsWith('@nestjs/'));
|
|
1116
|
+
if (nestPackages.length > 2) {
|
|
1117
|
+
confidence += 5;
|
|
1118
|
+
sources.push({ type: 'package.json', field: 'dependencies (@nestjs packages)' });
|
|
1119
|
+
}
|
|
1120
|
+
if (confidence === 0) {
|
|
1121
|
+
return null;
|
|
1122
|
+
}
|
|
1123
|
+
return {
|
|
1124
|
+
id: 'nestjs',
|
|
1125
|
+
name: 'NestJS',
|
|
1126
|
+
version,
|
|
1127
|
+
configPath,
|
|
1128
|
+
confidence: min(confidence, 100),
|
|
1129
|
+
detectedFrom: sources,
|
|
1130
|
+
};
|
|
1131
|
+
}
|
|
1132
|
+
|
|
1133
|
+
/**
|
|
1134
|
+
* Detect Fastify in project.
|
|
1135
|
+
*
|
|
1136
|
+
* @param projectPath - Project directory path
|
|
1137
|
+
* @param packageJson - Optional pre-loaded package.json
|
|
1138
|
+
* @returns Detection result or null if not detected
|
|
1139
|
+
*/
|
|
1140
|
+
function fastifyDetector(projectPath, packageJson) {
|
|
1141
|
+
const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
|
|
1142
|
+
const sources = [];
|
|
1143
|
+
let confidence = 0;
|
|
1144
|
+
let version;
|
|
1145
|
+
const deps = collectAllDependencies(pkg);
|
|
1146
|
+
if (deps['fastify']) {
|
|
1147
|
+
confidence += 80;
|
|
1148
|
+
version = parseVersionString(deps['fastify']);
|
|
1149
|
+
sources.push({ type: 'package.json', field: 'dependencies.fastify' });
|
|
1150
|
+
}
|
|
1151
|
+
const fastifyPlugins = keys(deps).filter((d) => d.startsWith('@fastify/') || d.startsWith('fastify-'));
|
|
1152
|
+
if (fastifyPlugins.length > 0) {
|
|
1153
|
+
confidence += 15;
|
|
1154
|
+
sources.push({ type: 'package.json', field: 'dependencies (fastify plugins)' });
|
|
1155
|
+
}
|
|
1156
|
+
// @types/fastify (older versions)
|
|
1157
|
+
if (deps['@types/fastify']) {
|
|
1158
|
+
confidence += 5;
|
|
1159
|
+
sources.push({ type: 'package.json', field: 'dependencies.@types/fastify' });
|
|
1160
|
+
}
|
|
1161
|
+
if (confidence === 0) {
|
|
1162
|
+
return null;
|
|
1163
|
+
}
|
|
1164
|
+
return {
|
|
1165
|
+
id: 'fastify',
|
|
1166
|
+
name: 'Fastify',
|
|
1167
|
+
version,
|
|
1168
|
+
confidence: min(confidence, 100),
|
|
1169
|
+
detectedFrom: sources,
|
|
1170
|
+
};
|
|
1171
|
+
}
|
|
1172
|
+
|
|
1173
|
+
/**
|
|
1174
|
+
* Detect Koa in project.
|
|
1175
|
+
*
|
|
1176
|
+
* @param projectPath - Project directory path
|
|
1177
|
+
* @param packageJson - Optional pre-loaded package.json
|
|
1178
|
+
* @returns Detection result or null if not detected
|
|
1179
|
+
*/
|
|
1180
|
+
function koaDetector(projectPath, packageJson) {
|
|
1181
|
+
const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
|
|
1182
|
+
const sources = [];
|
|
1183
|
+
let confidence = 0;
|
|
1184
|
+
let version;
|
|
1185
|
+
const deps = collectAllDependencies(pkg);
|
|
1186
|
+
if (deps['koa']) {
|
|
1187
|
+
confidence += 80;
|
|
1188
|
+
version = parseVersionString(deps['koa']);
|
|
1189
|
+
sources.push({ type: 'package.json', field: 'dependencies.koa' });
|
|
1190
|
+
}
|
|
1191
|
+
// @types/koa
|
|
1192
|
+
if (deps['@types/koa']) {
|
|
1193
|
+
confidence += 10;
|
|
1194
|
+
sources.push({ type: 'package.json', field: 'dependencies.@types/koa' });
|
|
1195
|
+
}
|
|
1196
|
+
const koaMiddleware = keys(deps).filter((d) => d.startsWith('koa-') || d.startsWith('@koa/'));
|
|
1197
|
+
if (koaMiddleware.length > 0) {
|
|
1198
|
+
confidence += 10;
|
|
1199
|
+
sources.push({ type: 'package.json', field: 'dependencies (koa middleware)' });
|
|
1200
|
+
}
|
|
1201
|
+
if (confidence === 0) {
|
|
1202
|
+
return null;
|
|
1203
|
+
}
|
|
1204
|
+
return {
|
|
1205
|
+
id: 'koa',
|
|
1206
|
+
name: 'Koa',
|
|
1207
|
+
version,
|
|
1208
|
+
confidence: min(confidence, 100),
|
|
1209
|
+
detectedFrom: sources,
|
|
1210
|
+
};
|
|
1211
|
+
}
|
|
1212
|
+
|
|
1213
|
+
/**
|
|
1214
|
+
* Detect Hono in project.
|
|
1215
|
+
*
|
|
1216
|
+
* @param projectPath - Project directory path
|
|
1217
|
+
* @param packageJson - Optional pre-loaded package.json
|
|
1218
|
+
* @returns Detection result or null if not detected
|
|
1219
|
+
*/
|
|
1220
|
+
function honoDetector(projectPath, packageJson) {
|
|
1221
|
+
const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
|
|
1222
|
+
const sources = [];
|
|
1223
|
+
let confidence = 0;
|
|
1224
|
+
let version;
|
|
1225
|
+
const deps = collectAllDependencies(pkg);
|
|
1226
|
+
if (deps['hono']) {
|
|
1227
|
+
confidence += 85;
|
|
1228
|
+
version = parseVersionString(deps['hono']);
|
|
1229
|
+
sources.push({ type: 'package.json', field: 'dependencies.hono' });
|
|
1230
|
+
}
|
|
1231
|
+
const honoAdapters = keys(deps).filter((d) => d.startsWith('@hono/'));
|
|
1232
|
+
if (honoAdapters.length > 0) {
|
|
1233
|
+
confidence += 15;
|
|
1234
|
+
sources.push({ type: 'package.json', field: 'dependencies (@hono adapters)' });
|
|
1235
|
+
}
|
|
1236
|
+
if (confidence === 0) {
|
|
1237
|
+
return null;
|
|
1238
|
+
}
|
|
1239
|
+
return {
|
|
1240
|
+
id: 'hono',
|
|
1241
|
+
name: 'Hono',
|
|
1242
|
+
version,
|
|
1243
|
+
confidence: min(confidence, 100),
|
|
1244
|
+
detectedFrom: sources,
|
|
1245
|
+
};
|
|
1246
|
+
}
|
|
1247
|
+
|
|
1248
|
+
/** All backend framework detectors */
|
|
1249
|
+
const backendDetectors = [
|
|
1250
|
+
{ id: 'express', name: 'Express', detect: expressDetector },
|
|
1251
|
+
{ id: 'nestjs', name: 'NestJS', detect: nestDetector },
|
|
1252
|
+
{ id: 'fastify', name: 'Fastify', detect: fastifyDetector },
|
|
1253
|
+
{ id: 'koa', name: 'Koa', detect: koaDetector },
|
|
1254
|
+
{ id: 'hono', name: 'Hono', detect: honoDetector },
|
|
1255
|
+
];
|
|
1256
|
+
|
|
1257
|
+
/** Config patterns for Webpack */
|
|
1258
|
+
const WEBPACK_CONFIG_PATTERNS = [
|
|
1259
|
+
'webpack.config.js',
|
|
1260
|
+
'webpack.config.ts',
|
|
1261
|
+
'webpack.config.cjs',
|
|
1262
|
+
'webpack.config.mjs',
|
|
1263
|
+
'webpack.config.babel.js',
|
|
1264
|
+
];
|
|
1265
|
+
/**
|
|
1266
|
+
* Detect Webpack in project.
|
|
1267
|
+
*
|
|
1268
|
+
* @param projectPath - Project directory path
|
|
1269
|
+
* @param packageJson - Optional pre-loaded package.json
|
|
1270
|
+
* @returns Detection result or null if not detected
|
|
1271
|
+
*/
|
|
1272
|
+
function webpackDetector(projectPath, packageJson) {
|
|
1273
|
+
const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
|
|
1274
|
+
const sources = [];
|
|
1275
|
+
let confidence = 0;
|
|
1276
|
+
let version;
|
|
1277
|
+
const deps = collectAllDependencies(pkg);
|
|
1278
|
+
if (deps['webpack']) {
|
|
1279
|
+
confidence += 50;
|
|
1280
|
+
version = parseVersionString(deps['webpack']);
|
|
1281
|
+
sources.push({ type: 'package.json', field: 'dependencies.webpack' });
|
|
1282
|
+
}
|
|
1283
|
+
const configPath = locateConfigFile(projectPath, WEBPACK_CONFIG_PATTERNS);
|
|
1284
|
+
if (configPath) {
|
|
1285
|
+
confidence += 40;
|
|
1286
|
+
sources.push({ type: 'config-file', path: configPath });
|
|
1287
|
+
}
|
|
1288
|
+
if (deps['webpack-cli']) {
|
|
1289
|
+
confidence += 10;
|
|
1290
|
+
sources.push({ type: 'package.json', field: 'dependencies.webpack-cli' });
|
|
1291
|
+
}
|
|
1292
|
+
const scriptMatches = filterScriptsByCommand(pkg?.scripts, 'webpack');
|
|
1293
|
+
for (const name of scriptMatches) {
|
|
1294
|
+
confidence = min(confidence + 5, 100);
|
|
1295
|
+
sources.push({ type: 'package.json', field: `scripts.${name}` });
|
|
1296
|
+
}
|
|
1297
|
+
if (confidence === 0) {
|
|
1298
|
+
return null;
|
|
1299
|
+
}
|
|
1300
|
+
return {
|
|
1301
|
+
id: 'webpack',
|
|
1302
|
+
name: 'Webpack',
|
|
1303
|
+
version,
|
|
1304
|
+
configPath,
|
|
1305
|
+
confidence: min(confidence, 100),
|
|
1306
|
+
detectedFrom: sources,
|
|
1307
|
+
};
|
|
1308
|
+
}
|
|
1309
|
+
|
|
1310
|
+
/** Config patterns for Vite */
|
|
1311
|
+
const VITE_CONFIG_PATTERNS = ['vite.config.js', 'vite.config.ts', 'vite.config.mjs', 'vite.config.cjs'];
|
|
1312
|
+
/**
|
|
1313
|
+
* Detect Vite in project.
|
|
1314
|
+
*
|
|
1315
|
+
* @param projectPath - Project directory path
|
|
1316
|
+
* @param packageJson - Optional pre-loaded package.json
|
|
1317
|
+
* @returns Detection result or null if not detected
|
|
1318
|
+
*/
|
|
1319
|
+
function viteDetector(projectPath, packageJson) {
|
|
1320
|
+
const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
|
|
1321
|
+
const sources = [];
|
|
1322
|
+
let confidence = 0;
|
|
1323
|
+
let version;
|
|
1324
|
+
const deps = collectAllDependencies(pkg);
|
|
1325
|
+
if (deps['vite']) {
|
|
1326
|
+
confidence += 60;
|
|
1327
|
+
version = parseVersionString(deps['vite']);
|
|
1328
|
+
sources.push({ type: 'package.json', field: 'dependencies.vite' });
|
|
1329
|
+
}
|
|
1330
|
+
const configPath = locateConfigFile(projectPath, VITE_CONFIG_PATTERNS);
|
|
1331
|
+
if (configPath) {
|
|
1332
|
+
confidence += 35;
|
|
1333
|
+
sources.push({ type: 'config-file', path: configPath });
|
|
1334
|
+
}
|
|
1335
|
+
if (deps['vitest']) {
|
|
1336
|
+
confidence += 10;
|
|
1337
|
+
sources.push({ type: 'package.json', field: 'dependencies.vitest' });
|
|
1338
|
+
}
|
|
1339
|
+
const vitePlugins = keys(deps).filter((d) => d.startsWith('vite-plugin-') || d.startsWith('@vitejs/'));
|
|
1340
|
+
if (vitePlugins.length > 0) {
|
|
1341
|
+
confidence += 10;
|
|
1342
|
+
sources.push({ type: 'package.json', field: 'dependencies (vite plugins)' });
|
|
1343
|
+
}
|
|
1344
|
+
if (confidence === 0) {
|
|
1345
|
+
return null;
|
|
1346
|
+
}
|
|
1347
|
+
return {
|
|
1348
|
+
id: 'vite',
|
|
1349
|
+
name: 'Vite',
|
|
1350
|
+
version,
|
|
1351
|
+
configPath,
|
|
1352
|
+
confidence: min(confidence, 100),
|
|
1353
|
+
detectedFrom: sources,
|
|
1354
|
+
};
|
|
1355
|
+
}
|
|
1356
|
+
|
|
1357
|
+
/** Config patterns for Rollup */
|
|
1358
|
+
const ROLLUP_CONFIG_PATTERNS = ['rollup.config.js', 'rollup.config.ts', 'rollup.config.mjs', 'rollup.config.cjs'];
|
|
1359
|
+
/**
|
|
1360
|
+
* Detect Rollup in project.
|
|
1361
|
+
*
|
|
1362
|
+
* @param projectPath - Project directory path
|
|
1363
|
+
* @param packageJson - Optional pre-loaded package.json
|
|
1364
|
+
* @returns Detection result or null if not detected
|
|
1365
|
+
*/
|
|
1366
|
+
function rollupDetector(projectPath, packageJson) {
|
|
1367
|
+
const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
|
|
1368
|
+
const sources = [];
|
|
1369
|
+
let confidence = 0;
|
|
1370
|
+
let version;
|
|
1371
|
+
const deps = collectAllDependencies(pkg);
|
|
1372
|
+
if (deps['rollup']) {
|
|
1373
|
+
confidence += 55;
|
|
1374
|
+
version = parseVersionString(deps['rollup']);
|
|
1375
|
+
sources.push({ type: 'package.json', field: 'dependencies.rollup' });
|
|
1376
|
+
}
|
|
1377
|
+
const configPath = locateConfigFile(projectPath, ROLLUP_CONFIG_PATTERNS);
|
|
1378
|
+
if (configPath) {
|
|
1379
|
+
confidence += 40;
|
|
1380
|
+
sources.push({ type: 'config-file', path: configPath });
|
|
1381
|
+
}
|
|
1382
|
+
const rollupPlugins = keys(deps).filter((d) => d.startsWith('@rollup/') || d.startsWith('rollup-plugin-'));
|
|
1383
|
+
if (rollupPlugins.length > 0) {
|
|
1384
|
+
confidence += 10;
|
|
1385
|
+
sources.push({ type: 'package.json', field: 'dependencies (rollup plugins)' });
|
|
1386
|
+
}
|
|
1387
|
+
const scriptMatches = filterScriptsByCommand(pkg?.scripts, 'rollup');
|
|
1388
|
+
for (const name of scriptMatches) {
|
|
1389
|
+
confidence = min(confidence + 5, 100);
|
|
1390
|
+
sources.push({ type: 'package.json', field: `scripts.${name}` });
|
|
1391
|
+
}
|
|
1392
|
+
if (confidence === 0) {
|
|
1393
|
+
return null;
|
|
1394
|
+
}
|
|
1395
|
+
return {
|
|
1396
|
+
id: 'rollup',
|
|
1397
|
+
name: 'Rollup',
|
|
1398
|
+
version,
|
|
1399
|
+
configPath,
|
|
1400
|
+
confidence: min(confidence, 100),
|
|
1401
|
+
detectedFrom: sources,
|
|
1402
|
+
};
|
|
1403
|
+
}
|
|
1404
|
+
|
|
1405
|
+
/**
|
|
1406
|
+
* Detect esbuild in project.
|
|
1407
|
+
*
|
|
1408
|
+
* @param projectPath - Project directory path
|
|
1409
|
+
* @param packageJson - Optional pre-loaded package.json
|
|
1410
|
+
* @returns Detection result or null if not detected
|
|
1411
|
+
*/
|
|
1412
|
+
function esbuildDetector(projectPath, packageJson) {
|
|
1413
|
+
const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
|
|
1414
|
+
const sources = [];
|
|
1415
|
+
let confidence = 0;
|
|
1416
|
+
let version;
|
|
1417
|
+
const deps = collectAllDependencies(pkg);
|
|
1418
|
+
if (deps['esbuild']) {
|
|
1419
|
+
confidence += 70;
|
|
1420
|
+
version = parseVersionString(deps['esbuild']);
|
|
1421
|
+
sources.push({ type: 'package.json', field: 'dependencies.esbuild' });
|
|
1422
|
+
}
|
|
1423
|
+
const esbuildPlugins = keys(deps).filter((d) => d.includes('esbuild-plugin') || d.includes('esbuild-'));
|
|
1424
|
+
if (esbuildPlugins.length > 0) {
|
|
1425
|
+
confidence += 15;
|
|
1426
|
+
sources.push({ type: 'package.json', field: 'dependencies (esbuild plugins)' });
|
|
1427
|
+
}
|
|
1428
|
+
const scriptMatches = filterScriptsByCommand(pkg?.scripts, 'esbuild');
|
|
1429
|
+
for (const name of scriptMatches) {
|
|
1430
|
+
confidence = min(confidence + 10, 100);
|
|
1431
|
+
sources.push({ type: 'package.json', field: `scripts.${name}` });
|
|
1432
|
+
}
|
|
1433
|
+
if (confidence === 0) {
|
|
1434
|
+
return null;
|
|
1435
|
+
}
|
|
1436
|
+
return {
|
|
1437
|
+
id: 'esbuild',
|
|
1438
|
+
name: 'esbuild',
|
|
1439
|
+
version,
|
|
1440
|
+
confidence: min(confidence, 100),
|
|
1441
|
+
detectedFrom: sources,
|
|
1442
|
+
};
|
|
1443
|
+
}
|
|
1444
|
+
|
|
1445
|
+
/** Config patterns for Babel */
|
|
1446
|
+
const BABEL_CONFIG_PATTERNS = ['babel.config.js', 'babel.config.cjs', 'babel.config.mjs', 'babel.config.json', '.babelrc', '.babelrc.json', '.babelrc.js'];
|
|
1447
|
+
/**
|
|
1448
|
+
* Detect Babel in project.
|
|
1449
|
+
*
|
|
1450
|
+
* @param projectPath - Project directory path
|
|
1451
|
+
* @param packageJson - Optional pre-loaded package.json
|
|
1452
|
+
* @returns Detection result or null if not detected
|
|
1453
|
+
*/
|
|
1454
|
+
function babelDetector(projectPath, packageJson) {
|
|
1455
|
+
const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
|
|
1456
|
+
const sources = [];
|
|
1457
|
+
let confidence = 0;
|
|
1458
|
+
let version;
|
|
1459
|
+
const deps = collectAllDependencies(pkg);
|
|
1460
|
+
if (deps['@babel/core']) {
|
|
1461
|
+
confidence += 50;
|
|
1462
|
+
version = parseVersionString(deps['@babel/core']);
|
|
1463
|
+
sources.push({ type: 'package.json', field: 'dependencies.@babel/core' });
|
|
1464
|
+
}
|
|
1465
|
+
const configPath = locateConfigFile(projectPath, BABEL_CONFIG_PATTERNS);
|
|
1466
|
+
if (configPath) {
|
|
1467
|
+
confidence += 40;
|
|
1468
|
+
sources.push({ type: 'config-file', path: configPath });
|
|
1469
|
+
}
|
|
1470
|
+
if (pkg && 'babel' in pkg) {
|
|
1471
|
+
confidence += 30;
|
|
1472
|
+
sources.push({ type: 'package.json', field: 'babel' });
|
|
1473
|
+
}
|
|
1474
|
+
const babelPackages = keys(deps).filter((d) => d.startsWith('@babel/'));
|
|
1475
|
+
if (babelPackages.length > 1) {
|
|
1476
|
+
confidence += 10;
|
|
1477
|
+
sources.push({ type: 'package.json', field: 'dependencies (@babel packages)' });
|
|
1478
|
+
}
|
|
1479
|
+
if (confidence === 0) {
|
|
1480
|
+
return null;
|
|
1481
|
+
}
|
|
1482
|
+
return {
|
|
1483
|
+
id: 'babel',
|
|
1484
|
+
name: 'Babel',
|
|
1485
|
+
version,
|
|
1486
|
+
configPath,
|
|
1487
|
+
confidence: min(confidence, 100),
|
|
1488
|
+
detectedFrom: sources,
|
|
1489
|
+
};
|
|
1490
|
+
}
|
|
1491
|
+
|
|
1492
|
+
/** Config patterns for SWC */
|
|
1493
|
+
const SWC_CONFIG_PATTERNS = ['.swcrc', 'swc.config.js'];
|
|
1494
|
+
/**
|
|
1495
|
+
* Detect SWC in project.
|
|
1496
|
+
*
|
|
1497
|
+
* @param projectPath - Project directory path
|
|
1498
|
+
* @param packageJson - Optional pre-loaded package.json
|
|
1499
|
+
* @returns Detection result or null if not detected
|
|
1500
|
+
*/
|
|
1501
|
+
function swcDetector(projectPath, packageJson) {
|
|
1502
|
+
const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
|
|
1503
|
+
const sources = [];
|
|
1504
|
+
let confidence = 0;
|
|
1505
|
+
let version;
|
|
1506
|
+
const deps = collectAllDependencies(pkg);
|
|
1507
|
+
if (deps['@swc/core']) {
|
|
1508
|
+
confidence += 60;
|
|
1509
|
+
version = parseVersionString(deps['@swc/core']);
|
|
1510
|
+
sources.push({ type: 'package.json', field: 'dependencies.@swc/core' });
|
|
1511
|
+
}
|
|
1512
|
+
const configPath = locateConfigFile(projectPath, SWC_CONFIG_PATTERNS);
|
|
1513
|
+
if (configPath) {
|
|
1514
|
+
confidence += 35;
|
|
1515
|
+
sources.push({ type: 'config-file', path: configPath });
|
|
1516
|
+
}
|
|
1517
|
+
if (deps['@swc/cli']) {
|
|
1518
|
+
confidence += 10;
|
|
1519
|
+
sources.push({ type: 'package.json', field: 'dependencies.@swc/cli' });
|
|
1520
|
+
}
|
|
1521
|
+
const swcPlugins = keys(deps).filter((d) => d.startsWith('@swc/') || d.includes('swc-plugin'));
|
|
1522
|
+
if (swcPlugins.length > 1) {
|
|
1523
|
+
confidence += 5;
|
|
1524
|
+
sources.push({ type: 'package.json', field: 'dependencies (@swc packages)' });
|
|
1525
|
+
}
|
|
1526
|
+
if (confidence === 0) {
|
|
1527
|
+
return null;
|
|
1528
|
+
}
|
|
1529
|
+
return {
|
|
1530
|
+
id: 'swc',
|
|
1531
|
+
name: 'SWC',
|
|
1532
|
+
version,
|
|
1533
|
+
configPath,
|
|
1534
|
+
confidence: min(confidence, 100),
|
|
1535
|
+
detectedFrom: sources,
|
|
1536
|
+
};
|
|
1537
|
+
}
|
|
1538
|
+
|
|
1539
|
+
/** Config patterns for Parcel */
|
|
1540
|
+
const PARCEL_CONFIG_PATTERNS = ['.parcelrc'];
|
|
1541
|
+
/**
|
|
1542
|
+
* Detect Parcel in project.
|
|
1543
|
+
*
|
|
1544
|
+
* @param projectPath - Project directory path
|
|
1545
|
+
* @param packageJson - Optional pre-loaded package.json
|
|
1546
|
+
* @returns Detection result or null if not detected
|
|
1547
|
+
*/
|
|
1548
|
+
function parcelDetector(projectPath, packageJson) {
|
|
1549
|
+
const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
|
|
1550
|
+
const sources = [];
|
|
1551
|
+
let confidence = 0;
|
|
1552
|
+
let version;
|
|
1553
|
+
const deps = collectAllDependencies(pkg);
|
|
1554
|
+
if (deps['parcel']) {
|
|
1555
|
+
confidence += 60;
|
|
1556
|
+
version = parseVersionString(deps['parcel']);
|
|
1557
|
+
sources.push({ type: 'package.json', field: 'dependencies.parcel' });
|
|
1558
|
+
}
|
|
1559
|
+
if (deps['parcel-bundler']) {
|
|
1560
|
+
confidence += 60;
|
|
1561
|
+
version = parseVersionString(deps['parcel-bundler']);
|
|
1562
|
+
sources.push({ type: 'package.json', field: 'dependencies.parcel-bundler' });
|
|
1563
|
+
}
|
|
1564
|
+
const configPath = locateConfigFile(projectPath, PARCEL_CONFIG_PATTERNS);
|
|
1565
|
+
if (configPath) {
|
|
1566
|
+
confidence += 30;
|
|
1567
|
+
sources.push({ type: 'config-file', path: configPath });
|
|
1568
|
+
}
|
|
1569
|
+
const scriptMatches = filterScriptsByCommand(pkg?.scripts, 'parcel');
|
|
1570
|
+
for (const name of scriptMatches) {
|
|
1571
|
+
confidence = min(confidence + 10, 100);
|
|
1572
|
+
sources.push({ type: 'package.json', field: `scripts.${name}` });
|
|
1573
|
+
}
|
|
1574
|
+
if (confidence === 0) {
|
|
1575
|
+
return null;
|
|
1576
|
+
}
|
|
1577
|
+
return {
|
|
1578
|
+
id: 'parcel',
|
|
1579
|
+
name: 'Parcel',
|
|
1580
|
+
version,
|
|
1581
|
+
configPath,
|
|
1582
|
+
confidence: min(confidence, 100),
|
|
1583
|
+
detectedFrom: sources,
|
|
1584
|
+
};
|
|
1585
|
+
}
|
|
1586
|
+
|
|
1587
|
+
/** All build tool detectors */
|
|
1588
|
+
const buildToolDetectors = [
|
|
1589
|
+
{ id: 'webpack', name: 'Webpack', detect: webpackDetector },
|
|
1590
|
+
{ id: 'vite', name: 'Vite', detect: viteDetector },
|
|
1591
|
+
{ id: 'rollup', name: 'Rollup', detect: rollupDetector },
|
|
1592
|
+
{ id: 'esbuild', name: 'esbuild', detect: esbuildDetector },
|
|
1593
|
+
{ id: 'babel', name: 'Babel', detect: babelDetector },
|
|
1594
|
+
{ id: 'swc', name: 'SWC', detect: swcDetector },
|
|
1595
|
+
{ id: 'parcel', name: 'Parcel', detect: parcelDetector },
|
|
1596
|
+
];
|
|
1597
|
+
|
|
1598
|
+
/**
|
|
1599
|
+
* Detect React in project.
|
|
1600
|
+
*
|
|
1601
|
+
* @param projectPath - Project directory path
|
|
1602
|
+
* @param packageJson - Optional pre-loaded package.json
|
|
1603
|
+
* @returns Detection result or null if not detected
|
|
1604
|
+
*/
|
|
1605
|
+
function reactDetector(projectPath, packageJson) {
|
|
1606
|
+
const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
|
|
1607
|
+
const sources = [];
|
|
1608
|
+
let confidence = 0;
|
|
1609
|
+
let version;
|
|
1610
|
+
const metaFrameworks = [];
|
|
1611
|
+
const deps = collectAllDependencies(pkg);
|
|
1612
|
+
if (deps['react']) {
|
|
1613
|
+
confidence += 60;
|
|
1614
|
+
version = parseVersionString(deps['react']);
|
|
1615
|
+
sources.push({ type: 'package.json', field: 'dependencies.react' });
|
|
1616
|
+
}
|
|
1617
|
+
if (deps['react-dom']) {
|
|
1618
|
+
confidence += 20;
|
|
1619
|
+
sources.push({ type: 'package.json', field: 'dependencies.react-dom' });
|
|
1620
|
+
}
|
|
1621
|
+
if (deps['react-native']) {
|
|
1622
|
+
confidence += 20;
|
|
1623
|
+
sources.push({ type: 'package.json', field: 'dependencies.react-native' });
|
|
1624
|
+
}
|
|
1625
|
+
const hasJsxFiles = exists(join$1(projectPath, 'src', 'App.tsx')) ||
|
|
1626
|
+
exists(join$1(projectPath, 'src', 'App.jsx')) ||
|
|
1627
|
+
exists(join$1(projectPath, 'src', 'index.tsx')) ||
|
|
1628
|
+
exists(join$1(projectPath, 'src', 'index.jsx'));
|
|
1629
|
+
if (hasJsxFiles) {
|
|
1630
|
+
confidence += 10;
|
|
1631
|
+
sources.push({ type: 'directory', path: 'src/*.tsx or src/*.jsx' });
|
|
1632
|
+
}
|
|
1633
|
+
if (deps['next']) {
|
|
1634
|
+
metaFrameworks.push({
|
|
1635
|
+
id: 'nextjs',
|
|
1636
|
+
name: 'Next.js',
|
|
1637
|
+
category: 'meta-framework',
|
|
1638
|
+
version: parseVersionString(deps['next']),
|
|
1639
|
+
confidence: 90,
|
|
1640
|
+
detectedFrom: [{ type: 'package.json', field: 'dependencies.next' }],
|
|
1641
|
+
});
|
|
1642
|
+
}
|
|
1643
|
+
if (deps['gatsby']) {
|
|
1644
|
+
metaFrameworks.push({
|
|
1645
|
+
id: 'gatsby',
|
|
1646
|
+
name: 'Gatsby',
|
|
1647
|
+
category: 'meta-framework',
|
|
1648
|
+
version: parseVersionString(deps['gatsby']),
|
|
1649
|
+
confidence: 90,
|
|
1650
|
+
detectedFrom: [{ type: 'package.json', field: 'dependencies.gatsby' }],
|
|
1651
|
+
});
|
|
1652
|
+
}
|
|
1653
|
+
if (deps['@remix-run/react'] || deps['remix']) {
|
|
1654
|
+
metaFrameworks.push({
|
|
1655
|
+
id: 'remix',
|
|
1656
|
+
name: 'Remix',
|
|
1657
|
+
category: 'meta-framework',
|
|
1658
|
+
version: parseVersionString(deps['@remix-run/react'] ?? deps['remix']),
|
|
1659
|
+
confidence: 90,
|
|
1660
|
+
detectedFrom: [{ type: 'package.json', field: 'dependencies.@remix-run/react' }],
|
|
1661
|
+
});
|
|
1662
|
+
}
|
|
1663
|
+
if (confidence === 0) {
|
|
1664
|
+
return null;
|
|
1665
|
+
}
|
|
1666
|
+
return {
|
|
1667
|
+
id: 'react',
|
|
1668
|
+
name: 'React',
|
|
1669
|
+
category: 'frontend',
|
|
1670
|
+
version,
|
|
1671
|
+
confidence: min(confidence, 100),
|
|
1672
|
+
detectedFrom: sources,
|
|
1673
|
+
metaFrameworks: metaFrameworks.length > 0 ? metaFrameworks : undefined,
|
|
1674
|
+
};
|
|
1675
|
+
}
|
|
1676
|
+
|
|
1677
|
+
/**
|
|
1678
|
+
* Detect Next.js in project.
|
|
1679
|
+
*
|
|
1680
|
+
* @param projectPath - Project directory path
|
|
1681
|
+
* @param packageJson - Optional pre-loaded package.json
|
|
1682
|
+
* @returns Detection result or null if not detected
|
|
1683
|
+
*/
|
|
1684
|
+
function nextjsDetector(projectPath, packageJson) {
|
|
1685
|
+
const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
|
|
1686
|
+
const sources = [];
|
|
1687
|
+
let confidence = 0;
|
|
1688
|
+
let version;
|
|
1689
|
+
const deps = collectAllDependencies(pkg);
|
|
1690
|
+
if (deps['next']) {
|
|
1691
|
+
confidence += 70;
|
|
1692
|
+
version = parseVersionString(deps['next']);
|
|
1693
|
+
sources.push({ type: 'package.json', field: 'dependencies.next' });
|
|
1694
|
+
}
|
|
1695
|
+
if (exists(join$1(projectPath, 'next.config.js')) ||
|
|
1696
|
+
exists(join$1(projectPath, 'next.config.mjs')) ||
|
|
1697
|
+
exists(join$1(projectPath, 'next.config.ts'))) {
|
|
1698
|
+
confidence += 25;
|
|
1699
|
+
sources.push({ type: 'config-file', path: 'next.config.*' });
|
|
1700
|
+
}
|
|
1701
|
+
if (exists(join$1(projectPath, 'pages')) ||
|
|
1702
|
+
exists(join$1(projectPath, 'app')) ||
|
|
1703
|
+
exists(join$1(projectPath, 'src', 'pages')) ||
|
|
1704
|
+
exists(join$1(projectPath, 'src', 'app'))) {
|
|
1705
|
+
confidence += 5;
|
|
1706
|
+
sources.push({ type: 'directory', path: 'pages/ or app/' });
|
|
1707
|
+
}
|
|
1708
|
+
if (confidence === 0) {
|
|
1709
|
+
return null;
|
|
1710
|
+
}
|
|
1711
|
+
return {
|
|
1712
|
+
id: 'nextjs',
|
|
1713
|
+
name: 'Next.js',
|
|
1714
|
+
category: 'meta-framework',
|
|
1715
|
+
version,
|
|
1716
|
+
confidence: min(confidence, 100),
|
|
1717
|
+
detectedFrom: sources,
|
|
1718
|
+
};
|
|
1719
|
+
}
|
|
1720
|
+
|
|
1721
|
+
/**
|
|
1722
|
+
* Detect Remix in project.
|
|
1723
|
+
*
|
|
1724
|
+
* @param projectPath - Project directory path
|
|
1725
|
+
* @param packageJson - Optional pre-loaded package.json
|
|
1726
|
+
* @returns Detection result or null if not detected
|
|
1727
|
+
*/
|
|
1728
|
+
function remixDetector(projectPath, packageJson) {
|
|
1729
|
+
const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
|
|
1730
|
+
const sources = [];
|
|
1731
|
+
let confidence = 0;
|
|
1732
|
+
let version;
|
|
1733
|
+
const deps = collectAllDependencies(pkg);
|
|
1734
|
+
// @remix-run packages
|
|
1735
|
+
if (deps['@remix-run/react']) {
|
|
1736
|
+
confidence += 70;
|
|
1737
|
+
version = parseVersionString(deps['@remix-run/react']);
|
|
1738
|
+
sources.push({ type: 'package.json', field: 'dependencies.@remix-run/react' });
|
|
1739
|
+
}
|
|
1740
|
+
if (deps['@remix-run/node'] || deps['@remix-run/cloudflare'] || deps['@remix-run/deno']) {
|
|
1741
|
+
confidence += 20;
|
|
1742
|
+
sources.push({ type: 'package.json', field: 'dependencies.@remix-run/*' });
|
|
1743
|
+
}
|
|
1744
|
+
if (exists(join$1(projectPath, 'remix.config.js')) || exists(join$1(projectPath, 'remix.config.ts'))) {
|
|
1745
|
+
confidence += 10;
|
|
1746
|
+
sources.push({ type: 'config-file', path: 'remix.config.*' });
|
|
1747
|
+
}
|
|
1748
|
+
if (confidence === 0) {
|
|
1749
|
+
return null;
|
|
1750
|
+
}
|
|
1751
|
+
return {
|
|
1752
|
+
id: 'remix',
|
|
1753
|
+
name: 'Remix',
|
|
1754
|
+
category: 'meta-framework',
|
|
1755
|
+
version,
|
|
1756
|
+
confidence: min(confidence, 100),
|
|
1757
|
+
detectedFrom: sources,
|
|
1758
|
+
};
|
|
1759
|
+
}
|
|
1760
|
+
|
|
1761
|
+
/**
|
|
1762
|
+
* Detect Gatsby in project.
|
|
1763
|
+
*
|
|
1764
|
+
* @param projectPath - Project directory path
|
|
1765
|
+
* @param packageJson - Optional pre-loaded package.json
|
|
1766
|
+
* @returns Detection result or null if not detected
|
|
1767
|
+
*/
|
|
1768
|
+
function gatsbyDetector(projectPath, packageJson) {
|
|
1769
|
+
const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
|
|
1770
|
+
const sources = [];
|
|
1771
|
+
let confidence = 0;
|
|
1772
|
+
let version;
|
|
1773
|
+
const deps = collectAllDependencies(pkg);
|
|
1774
|
+
if (deps['gatsby']) {
|
|
1775
|
+
confidence += 70;
|
|
1776
|
+
version = parseVersionString(deps['gatsby']);
|
|
1777
|
+
sources.push({ type: 'package.json', field: 'dependencies.gatsby' });
|
|
1778
|
+
}
|
|
1779
|
+
if (exists(join$1(projectPath, 'gatsby-config.js')) || exists(join$1(projectPath, 'gatsby-config.ts'))) {
|
|
1780
|
+
confidence += 25;
|
|
1781
|
+
sources.push({ type: 'config-file', path: 'gatsby-config.*' });
|
|
1782
|
+
}
|
|
1783
|
+
const gatsbyPlugins = keys(deps).filter((d) => d.startsWith('gatsby-plugin-') || d.startsWith('gatsby-source-'));
|
|
1784
|
+
if (gatsbyPlugins.length > 0) {
|
|
1785
|
+
confidence += 5;
|
|
1786
|
+
sources.push({ type: 'package.json', field: 'dependencies (gatsby plugins)' });
|
|
1787
|
+
}
|
|
1788
|
+
if (confidence === 0) {
|
|
1789
|
+
return null;
|
|
1790
|
+
}
|
|
1791
|
+
return {
|
|
1792
|
+
id: 'gatsby',
|
|
1793
|
+
name: 'Gatsby',
|
|
1794
|
+
category: 'meta-framework',
|
|
1795
|
+
version,
|
|
1796
|
+
confidence: min(confidence, 100),
|
|
1797
|
+
detectedFrom: sources,
|
|
1798
|
+
};
|
|
1799
|
+
}
|
|
1800
|
+
|
|
1801
|
+
/**
|
|
1802
|
+
* Detect Vue in project.
|
|
1803
|
+
*
|
|
1804
|
+
* @param projectPath - Project directory path
|
|
1805
|
+
* @param packageJson - Optional pre-loaded package.json
|
|
1806
|
+
* @returns Detection result or null if not detected
|
|
1807
|
+
*/
|
|
1808
|
+
function vueDetector(projectPath, packageJson) {
|
|
1809
|
+
const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
|
|
1810
|
+
const sources = [];
|
|
1811
|
+
let confidence = 0;
|
|
1812
|
+
let version;
|
|
1813
|
+
const metaFrameworks = [];
|
|
1814
|
+
const deps = collectAllDependencies(pkg);
|
|
1815
|
+
if (deps['vue']) {
|
|
1816
|
+
confidence += 70;
|
|
1817
|
+
version = parseVersionString(deps['vue']);
|
|
1818
|
+
sources.push({ type: 'package.json', field: 'dependencies.vue' });
|
|
1819
|
+
}
|
|
1820
|
+
if (deps['@vue/cli-service']) {
|
|
1821
|
+
confidence += 15;
|
|
1822
|
+
sources.push({ type: 'package.json', field: 'dependencies.@vue/cli-service' });
|
|
1823
|
+
}
|
|
1824
|
+
const hasVueFiles = exists(join$1(projectPath, 'src', 'App.vue')) || exists(join$1(projectPath, 'src', 'main.vue'));
|
|
1825
|
+
if (hasVueFiles) {
|
|
1826
|
+
confidence += 10;
|
|
1827
|
+
sources.push({ type: 'directory', path: 'src/*.vue' });
|
|
1828
|
+
}
|
|
1829
|
+
if (exists(join$1(projectPath, 'vue.config.js'))) {
|
|
1830
|
+
confidence += 5;
|
|
1831
|
+
sources.push({ type: 'config-file', path: 'vue.config.js' });
|
|
1832
|
+
}
|
|
1833
|
+
if (deps['nuxt'] || deps['nuxt3']) {
|
|
1834
|
+
metaFrameworks.push({
|
|
1835
|
+
id: 'nuxt',
|
|
1836
|
+
name: 'Nuxt',
|
|
1837
|
+
category: 'meta-framework',
|
|
1838
|
+
version: parseVersionString(deps['nuxt'] ?? deps['nuxt3']),
|
|
1839
|
+
confidence: 90,
|
|
1840
|
+
detectedFrom: [{ type: 'package.json', field: 'dependencies.nuxt' }],
|
|
1841
|
+
});
|
|
1842
|
+
}
|
|
1843
|
+
if (confidence === 0) {
|
|
1844
|
+
return null;
|
|
1845
|
+
}
|
|
1846
|
+
return {
|
|
1847
|
+
id: 'vue',
|
|
1848
|
+
name: 'Vue',
|
|
1849
|
+
category: 'frontend',
|
|
1850
|
+
version,
|
|
1851
|
+
confidence: min(confidence, 100),
|
|
1852
|
+
detectedFrom: sources,
|
|
1853
|
+
metaFrameworks: metaFrameworks.length > 0 ? metaFrameworks : undefined,
|
|
1854
|
+
};
|
|
1855
|
+
}
|
|
1856
|
+
|
|
1857
|
+
/**
|
|
1858
|
+
* Detect Nuxt in project.
|
|
1859
|
+
*
|
|
1860
|
+
* @param projectPath - Project directory path
|
|
1861
|
+
* @param packageJson - Optional pre-loaded package.json
|
|
1862
|
+
* @returns Detection result or null if not detected
|
|
1863
|
+
*/
|
|
1864
|
+
function nuxtDetector(projectPath, packageJson) {
|
|
1865
|
+
const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
|
|
1866
|
+
const sources = [];
|
|
1867
|
+
let confidence = 0;
|
|
1868
|
+
let version;
|
|
1869
|
+
const deps = collectAllDependencies(pkg);
|
|
1870
|
+
if (deps['nuxt'] || deps['nuxt3']) {
|
|
1871
|
+
confidence += 70;
|
|
1872
|
+
version = parseVersionString(deps['nuxt'] ?? deps['nuxt3']);
|
|
1873
|
+
sources.push({ type: 'package.json', field: 'dependencies.nuxt' });
|
|
1874
|
+
}
|
|
1875
|
+
if (exists(join$1(projectPath, 'nuxt.config.js')) || exists(join$1(projectPath, 'nuxt.config.ts'))) {
|
|
1876
|
+
confidence += 25;
|
|
1877
|
+
sources.push({ type: 'config-file', path: 'nuxt.config.*' });
|
|
1878
|
+
}
|
|
1879
|
+
if (exists(join$1(projectPath, 'pages'))) {
|
|
1880
|
+
confidence += 5;
|
|
1881
|
+
sources.push({ type: 'directory', path: 'pages/' });
|
|
1882
|
+
}
|
|
1883
|
+
if (confidence === 0) {
|
|
1884
|
+
return null;
|
|
1885
|
+
}
|
|
1886
|
+
return {
|
|
1887
|
+
id: 'nuxt',
|
|
1888
|
+
name: 'Nuxt',
|
|
1889
|
+
category: 'meta-framework',
|
|
1890
|
+
version,
|
|
1891
|
+
confidence: min(confidence, 100),
|
|
1892
|
+
detectedFrom: sources,
|
|
1893
|
+
};
|
|
1894
|
+
}
|
|
1895
|
+
|
|
1896
|
+
/**
|
|
1897
|
+
* Detect Angular in project.
|
|
1898
|
+
*
|
|
1899
|
+
* @param projectPath - Project directory path
|
|
1900
|
+
* @param packageJson - Optional pre-loaded package.json
|
|
1901
|
+
* @returns Detection result or null if not detected
|
|
1902
|
+
*/
|
|
1903
|
+
function angularDetector(projectPath, packageJson) {
|
|
1904
|
+
const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
|
|
1905
|
+
const sources = [];
|
|
1906
|
+
let confidence = 0;
|
|
1907
|
+
let version;
|
|
1908
|
+
const deps = collectAllDependencies(pkg);
|
|
1909
|
+
if (deps['@angular/core']) {
|
|
1910
|
+
confidence += 70;
|
|
1911
|
+
version = parseVersionString(deps['@angular/core']);
|
|
1912
|
+
sources.push({ type: 'package.json', field: 'dependencies.@angular/core' });
|
|
1913
|
+
}
|
|
1914
|
+
if (deps['@angular/cli']) {
|
|
1915
|
+
confidence += 15;
|
|
1916
|
+
sources.push({ type: 'package.json', field: 'dependencies.@angular/cli' });
|
|
1917
|
+
}
|
|
1918
|
+
if (exists(join$1(projectPath, 'angular.json'))) {
|
|
1919
|
+
confidence += 15;
|
|
1920
|
+
sources.push({ type: 'config-file', path: 'angular.json' });
|
|
1921
|
+
}
|
|
1922
|
+
if (deps['angular'] && !deps['@angular/core']) {
|
|
1923
|
+
return {
|
|
1924
|
+
id: 'angularjs',
|
|
1925
|
+
name: 'AngularJS (Legacy)',
|
|
1926
|
+
category: 'frontend',
|
|
1927
|
+
version: parseVersionString(deps['angular']),
|
|
1928
|
+
confidence: 80,
|
|
1929
|
+
detectedFrom: [{ type: 'package.json', field: 'dependencies.angular' }],
|
|
1930
|
+
};
|
|
1931
|
+
}
|
|
1932
|
+
if (confidence === 0) {
|
|
1933
|
+
return null;
|
|
1934
|
+
}
|
|
1935
|
+
return {
|
|
1936
|
+
id: 'angular',
|
|
1937
|
+
name: 'Angular',
|
|
1938
|
+
category: 'frontend',
|
|
1939
|
+
version,
|
|
1940
|
+
confidence: min(confidence, 100),
|
|
1941
|
+
detectedFrom: sources,
|
|
1942
|
+
};
|
|
1943
|
+
}
|
|
1944
|
+
|
|
1945
|
+
/**
|
|
1946
|
+
* Detect Svelte in project.
|
|
1947
|
+
*
|
|
1948
|
+
* @param projectPath - Project directory path
|
|
1949
|
+
* @param packageJson - Optional pre-loaded package.json
|
|
1950
|
+
* @returns Detection result or null if not detected
|
|
1951
|
+
*/
|
|
1952
|
+
function svelteDetector(projectPath, packageJson) {
|
|
1953
|
+
const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
|
|
1954
|
+
const sources = [];
|
|
1955
|
+
let confidence = 0;
|
|
1956
|
+
let version;
|
|
1957
|
+
const metaFrameworks = [];
|
|
1958
|
+
const deps = collectAllDependencies(pkg);
|
|
1959
|
+
if (deps['svelte']) {
|
|
1960
|
+
confidence += 70;
|
|
1961
|
+
version = parseVersionString(deps['svelte']);
|
|
1962
|
+
sources.push({ type: 'package.json', field: 'dependencies.svelte' });
|
|
1963
|
+
}
|
|
1964
|
+
if (exists(join$1(projectPath, 'svelte.config.js'))) {
|
|
1965
|
+
confidence += 20;
|
|
1966
|
+
sources.push({ type: 'config-file', path: 'svelte.config.js' });
|
|
1967
|
+
}
|
|
1968
|
+
const hasSvelteFiles = exists(join$1(projectPath, 'src', 'App.svelte')) || exists(join$1(projectPath, 'src', 'routes'));
|
|
1969
|
+
if (hasSvelteFiles) {
|
|
1970
|
+
confidence += 10;
|
|
1971
|
+
sources.push({ type: 'directory', path: 'src/*.svelte or src/routes/' });
|
|
1972
|
+
}
|
|
1973
|
+
if (deps['@sveltejs/kit']) {
|
|
1974
|
+
metaFrameworks.push({
|
|
1975
|
+
id: 'sveltekit',
|
|
1976
|
+
name: 'SvelteKit',
|
|
1977
|
+
category: 'meta-framework',
|
|
1978
|
+
version: parseVersionString(deps['@sveltejs/kit']),
|
|
1979
|
+
confidence: 90,
|
|
1980
|
+
detectedFrom: [{ type: 'package.json', field: 'dependencies.@sveltejs/kit' }],
|
|
1981
|
+
});
|
|
1982
|
+
}
|
|
1983
|
+
if (confidence === 0) {
|
|
1984
|
+
return null;
|
|
1985
|
+
}
|
|
1986
|
+
return {
|
|
1987
|
+
id: 'svelte',
|
|
1988
|
+
name: 'Svelte',
|
|
1989
|
+
category: 'frontend',
|
|
1990
|
+
version,
|
|
1991
|
+
confidence: min(confidence, 100),
|
|
1992
|
+
detectedFrom: sources,
|
|
1993
|
+
metaFrameworks: metaFrameworks.length > 0 ? metaFrameworks : undefined,
|
|
1994
|
+
};
|
|
1995
|
+
}
|
|
1996
|
+
|
|
1997
|
+
/**
|
|
1998
|
+
* Detect SvelteKit in project.
|
|
1999
|
+
*
|
|
2000
|
+
* @param projectPath - Project directory path
|
|
2001
|
+
* @param packageJson - Optional pre-loaded package.json
|
|
2002
|
+
* @returns Detection result or null if not detected
|
|
2003
|
+
*/
|
|
2004
|
+
function sveltekitDetector(projectPath, packageJson) {
|
|
2005
|
+
const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
|
|
2006
|
+
const sources = [];
|
|
2007
|
+
let confidence = 0;
|
|
2008
|
+
let version;
|
|
2009
|
+
const deps = collectAllDependencies(pkg);
|
|
2010
|
+
// @sveltejs/kit package
|
|
2011
|
+
if (deps['@sveltejs/kit']) {
|
|
2012
|
+
confidence += 70;
|
|
2013
|
+
version = parseVersionString(deps['@sveltejs/kit']);
|
|
2014
|
+
sources.push({ type: 'package.json', field: 'dependencies.@sveltejs/kit' });
|
|
2015
|
+
}
|
|
2016
|
+
if (exists(join$1(projectPath, 'svelte.config.js'))) {
|
|
2017
|
+
confidence += 20;
|
|
2018
|
+
sources.push({ type: 'config-file', path: 'svelte.config.js' });
|
|
2019
|
+
}
|
|
2020
|
+
if (exists(join$1(projectPath, 'src', 'routes'))) {
|
|
2021
|
+
confidence += 10;
|
|
2022
|
+
sources.push({ type: 'directory', path: 'src/routes/' });
|
|
2023
|
+
}
|
|
2024
|
+
if (confidence === 0) {
|
|
2025
|
+
return null;
|
|
2026
|
+
}
|
|
2027
|
+
return {
|
|
2028
|
+
id: 'sveltekit',
|
|
2029
|
+
name: 'SvelteKit',
|
|
2030
|
+
category: 'meta-framework',
|
|
2031
|
+
version,
|
|
2032
|
+
confidence: min(confidence, 100),
|
|
2033
|
+
detectedFrom: sources,
|
|
2034
|
+
};
|
|
2035
|
+
}
|
|
2036
|
+
|
|
2037
|
+
/**
|
|
2038
|
+
* Detect Solid in project.
|
|
2039
|
+
*
|
|
2040
|
+
* @param projectPath - Project directory path
|
|
2041
|
+
* @param packageJson - Optional pre-loaded package.json
|
|
2042
|
+
* @returns Detection result or null if not detected
|
|
2043
|
+
*/
|
|
2044
|
+
function solidDetector(projectPath, packageJson) {
|
|
2045
|
+
const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
|
|
2046
|
+
const sources = [];
|
|
2047
|
+
let confidence = 0;
|
|
2048
|
+
let version;
|
|
2049
|
+
const deps = collectAllDependencies(pkg);
|
|
2050
|
+
if (deps['solid-js']) {
|
|
2051
|
+
confidence += 70;
|
|
2052
|
+
version = parseVersionString(deps['solid-js']);
|
|
2053
|
+
sources.push({ type: 'package.json', field: 'dependencies.solid-js' });
|
|
2054
|
+
}
|
|
2055
|
+
if (deps['vite-plugin-solid']) {
|
|
2056
|
+
confidence += 20;
|
|
2057
|
+
sources.push({ type: 'package.json', field: 'dependencies.vite-plugin-solid' });
|
|
2058
|
+
}
|
|
2059
|
+
if (deps['solid-start'] || deps['@solidjs/start']) {
|
|
2060
|
+
confidence += 10;
|
|
2061
|
+
sources.push({ type: 'package.json', field: 'dependencies.solid-start' });
|
|
2062
|
+
}
|
|
2063
|
+
if (confidence === 0) {
|
|
2064
|
+
return null;
|
|
2065
|
+
}
|
|
2066
|
+
return {
|
|
2067
|
+
id: 'solid',
|
|
2068
|
+
name: 'Solid',
|
|
2069
|
+
category: 'frontend',
|
|
2070
|
+
version,
|
|
2071
|
+
confidence: min(confidence, 100),
|
|
2072
|
+
detectedFrom: sources,
|
|
2073
|
+
};
|
|
2074
|
+
}
|
|
2075
|
+
|
|
2076
|
+
/**
|
|
2077
|
+
* Detect Qwik in project.
|
|
2078
|
+
*
|
|
2079
|
+
* @param projectPath - Project directory path
|
|
2080
|
+
* @param packageJson - Optional pre-loaded package.json
|
|
2081
|
+
* @returns Detection result or null if not detected
|
|
2082
|
+
*/
|
|
2083
|
+
function qwikDetector(projectPath, packageJson) {
|
|
2084
|
+
const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
|
|
2085
|
+
const sources = [];
|
|
2086
|
+
let confidence = 0;
|
|
2087
|
+
let version;
|
|
2088
|
+
const deps = collectAllDependencies(pkg);
|
|
2089
|
+
// @builder.io/qwik package
|
|
2090
|
+
if (deps['@builder.io/qwik']) {
|
|
2091
|
+
confidence += 70;
|
|
2092
|
+
version = parseVersionString(deps['@builder.io/qwik']);
|
|
2093
|
+
sources.push({ type: 'package.json', field: 'dependencies.@builder.io/qwik' });
|
|
2094
|
+
}
|
|
2095
|
+
// @builder.io/qwik-city
|
|
2096
|
+
if (deps['@builder.io/qwik-city']) {
|
|
2097
|
+
confidence += 20;
|
|
2098
|
+
sources.push({ type: 'package.json', field: 'dependencies.@builder.io/qwik-city' });
|
|
2099
|
+
}
|
|
2100
|
+
if (exists(join$1(projectPath, 'qwik.config.ts')) || exists(join$1(projectPath, 'qwik.config.js'))) {
|
|
2101
|
+
confidence += 10;
|
|
2102
|
+
sources.push({ type: 'config-file', path: 'qwik.config.*' });
|
|
2103
|
+
}
|
|
2104
|
+
if (confidence === 0) {
|
|
2105
|
+
return null;
|
|
2106
|
+
}
|
|
2107
|
+
return {
|
|
2108
|
+
id: 'qwik',
|
|
2109
|
+
name: 'Qwik',
|
|
2110
|
+
category: 'frontend',
|
|
2111
|
+
version,
|
|
2112
|
+
confidence: min(confidence, 100),
|
|
2113
|
+
detectedFrom: sources,
|
|
2114
|
+
};
|
|
2115
|
+
}
|
|
2116
|
+
|
|
2117
|
+
/**
|
|
2118
|
+
* Detect Astro in project.
|
|
2119
|
+
*
|
|
2120
|
+
* @param projectPath - Project directory path
|
|
2121
|
+
* @param packageJson - Optional pre-loaded package.json
|
|
2122
|
+
* @returns Detection result or null if not detected
|
|
2123
|
+
*/
|
|
2124
|
+
function astroDetector(projectPath, packageJson) {
|
|
2125
|
+
const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
|
|
2126
|
+
const sources = [];
|
|
2127
|
+
let confidence = 0;
|
|
2128
|
+
let version;
|
|
2129
|
+
const deps = collectAllDependencies(pkg);
|
|
2130
|
+
if (deps['astro']) {
|
|
2131
|
+
confidence += 70;
|
|
2132
|
+
version = parseVersionString(deps['astro']);
|
|
2133
|
+
sources.push({ type: 'package.json', field: 'dependencies.astro' });
|
|
2134
|
+
}
|
|
2135
|
+
if (exists(join$1(projectPath, 'astro.config.mjs')) ||
|
|
2136
|
+
exists(join$1(projectPath, 'astro.config.ts')) ||
|
|
2137
|
+
exists(join$1(projectPath, 'astro.config.js'))) {
|
|
2138
|
+
confidence += 25;
|
|
2139
|
+
sources.push({ type: 'config-file', path: 'astro.config.*' });
|
|
2140
|
+
}
|
|
2141
|
+
if (exists(join$1(projectPath, 'src', 'pages'))) {
|
|
2142
|
+
confidence += 5;
|
|
2143
|
+
sources.push({ type: 'directory', path: 'src/pages/' });
|
|
2144
|
+
}
|
|
2145
|
+
if (confidence === 0) {
|
|
2146
|
+
return null;
|
|
2147
|
+
}
|
|
2148
|
+
return {
|
|
2149
|
+
id: 'astro',
|
|
2150
|
+
name: 'Astro',
|
|
2151
|
+
category: 'meta-framework',
|
|
2152
|
+
version,
|
|
2153
|
+
confidence: min(confidence, 100),
|
|
2154
|
+
detectedFrom: sources,
|
|
2155
|
+
};
|
|
2156
|
+
}
|
|
2157
|
+
|
|
2158
|
+
/** All frontend framework detectors */
|
|
2159
|
+
const frameworkDetectors = [
|
|
2160
|
+
{ id: 'react', name: 'React', category: 'frontend', detect: reactDetector },
|
|
2161
|
+
{ id: 'nextjs', name: 'Next.js', category: 'meta-framework', detect: nextjsDetector },
|
|
2162
|
+
{ id: 'remix', name: 'Remix', category: 'meta-framework', detect: remixDetector },
|
|
2163
|
+
{ id: 'gatsby', name: 'Gatsby', category: 'meta-framework', detect: gatsbyDetector },
|
|
2164
|
+
{ id: 'vue', name: 'Vue', category: 'frontend', detect: vueDetector },
|
|
2165
|
+
{ id: 'nuxt', name: 'Nuxt', category: 'meta-framework', detect: nuxtDetector },
|
|
2166
|
+
{ id: 'angular', name: 'Angular', category: 'frontend', detect: angularDetector },
|
|
2167
|
+
{ id: 'svelte', name: 'Svelte', category: 'frontend', detect: svelteDetector },
|
|
2168
|
+
{ id: 'sveltekit', name: 'SvelteKit', category: 'meta-framework', detect: sveltekitDetector },
|
|
2169
|
+
{ id: 'solid', name: 'Solid', category: 'frontend', detect: solidDetector },
|
|
2170
|
+
{ id: 'qwik', name: 'Qwik', category: 'frontend', detect: qwikDetector },
|
|
2171
|
+
{ id: 'astro', name: 'Astro', category: 'meta-framework', detect: astroDetector },
|
|
2172
|
+
];
|
|
2173
|
+
|
|
2174
|
+
/**
|
|
2175
|
+
* Detect AngularJS (1.x) in project.
|
|
2176
|
+
* AngularJS is the original Angular framework, distinct from Angular 2+.
|
|
2177
|
+
*
|
|
2178
|
+
* @param projectPath - Project directory path
|
|
2179
|
+
* @param packageJson - Optional pre-loaded package.json
|
|
2180
|
+
* @returns Detection result or null if not detected
|
|
2181
|
+
*/
|
|
2182
|
+
function angularJSDetector(projectPath, packageJson) {
|
|
2183
|
+
const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
|
|
2184
|
+
const sources = [];
|
|
2185
|
+
let confidence = 0;
|
|
2186
|
+
let version;
|
|
2187
|
+
const deps = collectAllDependencies(pkg);
|
|
2188
|
+
// AngularJS package (angular, not @angular/core)
|
|
2189
|
+
if (deps['angular']) {
|
|
2190
|
+
confidence += 70;
|
|
2191
|
+
version = parseVersionString(deps['angular']);
|
|
2192
|
+
sources.push({ type: 'package.json', field: 'dependencies.angular' });
|
|
2193
|
+
}
|
|
2194
|
+
// AngularJS router
|
|
2195
|
+
if (deps['angular-route']) {
|
|
2196
|
+
confidence += 15;
|
|
2197
|
+
sources.push({ type: 'package.json', field: 'dependencies.angular-route' });
|
|
2198
|
+
}
|
|
2199
|
+
// AngularJS resource
|
|
2200
|
+
if (deps['angular-resource']) {
|
|
2201
|
+
confidence += 10;
|
|
2202
|
+
sources.push({ type: 'package.json', field: 'dependencies.angular-resource' });
|
|
2203
|
+
}
|
|
2204
|
+
// AngularJS animate
|
|
2205
|
+
if (deps['angular-animate']) {
|
|
2206
|
+
confidence += 5;
|
|
2207
|
+
sources.push({ type: 'package.json', field: 'dependencies.angular-animate' });
|
|
2208
|
+
}
|
|
2209
|
+
if (confidence === 0) {
|
|
2210
|
+
return null;
|
|
2211
|
+
}
|
|
2212
|
+
return {
|
|
2213
|
+
id: 'angularjs',
|
|
2214
|
+
name: 'AngularJS',
|
|
2215
|
+
category: 'legacy-frontend',
|
|
2216
|
+
version,
|
|
2217
|
+
confidence: min(confidence, 100),
|
|
2218
|
+
detectedFrom: sources,
|
|
2219
|
+
};
|
|
2220
|
+
}
|
|
2221
|
+
|
|
2222
|
+
/**
|
|
2223
|
+
* Detect Backbone.js in project.
|
|
2224
|
+
*
|
|
2225
|
+
* @param projectPath - Project directory path
|
|
2226
|
+
* @param packageJson - Optional pre-loaded package.json
|
|
2227
|
+
* @returns Detection result or null if not detected
|
|
2228
|
+
*/
|
|
2229
|
+
function backboneDetector(projectPath, packageJson) {
|
|
2230
|
+
const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
|
|
2231
|
+
const sources = [];
|
|
2232
|
+
let confidence = 0;
|
|
2233
|
+
let version;
|
|
2234
|
+
const deps = collectAllDependencies(pkg);
|
|
2235
|
+
// Backbone package
|
|
2236
|
+
if (deps['backbone']) {
|
|
2237
|
+
confidence += 70;
|
|
2238
|
+
version = parseVersionString(deps['backbone']);
|
|
2239
|
+
sources.push({ type: 'package.json', field: 'dependencies.backbone' });
|
|
2240
|
+
// Underscore (commonly used with Backbone)
|
|
2241
|
+
if (deps['underscore']) {
|
|
2242
|
+
confidence += 15;
|
|
2243
|
+
sources.push({ type: 'package.json', field: 'dependencies.underscore' });
|
|
2244
|
+
}
|
|
2245
|
+
// Lodash can be used as underscore replacement
|
|
2246
|
+
if (deps['lodash']) {
|
|
2247
|
+
confidence += 5;
|
|
2248
|
+
sources.push({ type: 'package.json', field: 'dependencies.lodash' });
|
|
2249
|
+
}
|
|
2250
|
+
}
|
|
2251
|
+
// Marionette (Backbone framework)
|
|
2252
|
+
if (deps['backbone.marionette'] || deps['marionette']) {
|
|
2253
|
+
confidence += 10;
|
|
2254
|
+
sources.push({ type: 'package.json', field: 'dependencies.backbone.marionette' });
|
|
2255
|
+
}
|
|
2256
|
+
if (confidence === 0) {
|
|
2257
|
+
return null;
|
|
2258
|
+
}
|
|
2259
|
+
return {
|
|
2260
|
+
id: 'backbone',
|
|
2261
|
+
name: 'Backbone.js',
|
|
2262
|
+
category: 'legacy-frontend',
|
|
2263
|
+
version,
|
|
2264
|
+
confidence: min(confidence, 100),
|
|
2265
|
+
detectedFrom: sources,
|
|
2266
|
+
};
|
|
2267
|
+
}
|
|
2268
|
+
|
|
2269
|
+
/**
|
|
2270
|
+
* Detect Ember.js in project.
|
|
2271
|
+
*
|
|
2272
|
+
* @param projectPath - Project directory path
|
|
2273
|
+
* @param packageJson - Optional pre-loaded package.json
|
|
2274
|
+
* @returns Detection result or null if not detected
|
|
2275
|
+
*/
|
|
2276
|
+
function emberDetector(projectPath, packageJson) {
|
|
2277
|
+
const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
|
|
2278
|
+
const sources = [];
|
|
2279
|
+
let confidence = 0;
|
|
2280
|
+
let version;
|
|
2281
|
+
const deps = collectAllDependencies(pkg);
|
|
2282
|
+
// Ember source package
|
|
2283
|
+
if (deps['ember-source']) {
|
|
2284
|
+
confidence += 70;
|
|
2285
|
+
version = parseVersionString(deps['ember-source']);
|
|
2286
|
+
sources.push({ type: 'package.json', field: 'dependencies.ember-source' });
|
|
2287
|
+
}
|
|
2288
|
+
// Ember CLI
|
|
2289
|
+
if (deps['ember-cli']) {
|
|
2290
|
+
confidence += 20;
|
|
2291
|
+
sources.push({ type: 'package.json', field: 'devDependencies.ember-cli' });
|
|
2292
|
+
}
|
|
2293
|
+
// Ember Data
|
|
2294
|
+
if (deps['ember-data']) {
|
|
2295
|
+
confidence += 10;
|
|
2296
|
+
sources.push({ type: 'package.json', field: 'dependencies.ember-data' });
|
|
2297
|
+
}
|
|
2298
|
+
if (confidence === 0) {
|
|
2299
|
+
return null;
|
|
2300
|
+
}
|
|
2301
|
+
return {
|
|
2302
|
+
id: 'ember',
|
|
2303
|
+
name: 'Ember.js',
|
|
2304
|
+
category: 'legacy-frontend',
|
|
2305
|
+
version,
|
|
2306
|
+
confidence: min(confidence, 100),
|
|
2307
|
+
detectedFrom: sources,
|
|
2308
|
+
};
|
|
2309
|
+
}
|
|
2310
|
+
|
|
2311
|
+
/**
|
|
2312
|
+
* Detect jQuery in project.
|
|
2313
|
+
*
|
|
2314
|
+
* @param projectPath - Project directory path
|
|
2315
|
+
* @param packageJson - Optional pre-loaded package.json
|
|
2316
|
+
* @returns Detection result or null if not detected
|
|
2317
|
+
*/
|
|
2318
|
+
function jqueryDetector(projectPath, packageJson) {
|
|
2319
|
+
const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
|
|
2320
|
+
const sources = [];
|
|
2321
|
+
let confidence = 0;
|
|
2322
|
+
let version;
|
|
2323
|
+
const deps = collectAllDependencies(pkg);
|
|
2324
|
+
// jQuery package
|
|
2325
|
+
if (deps['jquery']) {
|
|
2326
|
+
confidence += 80;
|
|
2327
|
+
version = parseVersionString(deps['jquery']);
|
|
2328
|
+
sources.push({ type: 'package.json', field: 'dependencies.jquery' });
|
|
2329
|
+
}
|
|
2330
|
+
// jQuery UI
|
|
2331
|
+
if (deps['jquery-ui']) {
|
|
2332
|
+
confidence += 10;
|
|
2333
|
+
sources.push({ type: 'package.json', field: 'dependencies.jquery-ui' });
|
|
2334
|
+
}
|
|
2335
|
+
// jQuery plugins
|
|
2336
|
+
if (deps['jquery-validation']) {
|
|
2337
|
+
confidence += 5;
|
|
2338
|
+
sources.push({ type: 'package.json', field: 'dependencies.jquery-validation' });
|
|
2339
|
+
}
|
|
2340
|
+
if (confidence === 0) {
|
|
2341
|
+
return null;
|
|
2342
|
+
}
|
|
2343
|
+
return {
|
|
2344
|
+
id: 'jquery',
|
|
2345
|
+
name: 'jQuery',
|
|
2346
|
+
category: 'legacy-frontend',
|
|
2347
|
+
version,
|
|
2348
|
+
confidence: min(confidence, 100),
|
|
2349
|
+
detectedFrom: sources,
|
|
2350
|
+
};
|
|
2351
|
+
}
|
|
2352
|
+
|
|
2353
|
+
/** All legacy framework detectors */
|
|
2354
|
+
const legacyDetectors = [
|
|
2355
|
+
{ id: 'angularjs', name: 'AngularJS', category: 'legacy-frontend', detect: angularJSDetector },
|
|
2356
|
+
{ id: 'backbone', name: 'Backbone.js', category: 'legacy-frontend', detect: backboneDetector },
|
|
2357
|
+
{ id: 'ember', name: 'Ember.js', category: 'legacy-frontend', detect: emberDetector },
|
|
2358
|
+
{ id: 'jquery', name: 'jQuery', category: 'legacy-frontend', detect: jqueryDetector },
|
|
2359
|
+
];
|
|
2360
|
+
|
|
2361
|
+
/** Config patterns for ESLint */
|
|
2362
|
+
const ESLINT_CONFIG_PATTERNS = [
|
|
2363
|
+
'eslint.config.js',
|
|
2364
|
+
'eslint.config.mjs',
|
|
2365
|
+
'eslint.config.cjs',
|
|
2366
|
+
'eslint.config.ts',
|
|
2367
|
+
'.eslintrc.js',
|
|
2368
|
+
'.eslintrc.cjs',
|
|
2369
|
+
'.eslintrc.json',
|
|
2370
|
+
'.eslintrc.yaml',
|
|
2371
|
+
'.eslintrc.yml',
|
|
2372
|
+
'.eslintrc',
|
|
2373
|
+
];
|
|
2374
|
+
/**
|
|
2375
|
+
* Detect ESLint in project.
|
|
2376
|
+
*
|
|
2377
|
+
* @param projectPath - Project directory path
|
|
2378
|
+
* @param packageJson - Optional pre-loaded package.json
|
|
2379
|
+
* @returns Detection result or null if not detected
|
|
2380
|
+
*/
|
|
2381
|
+
function eslintDetector(projectPath, packageJson) {
|
|
2382
|
+
const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
|
|
2383
|
+
const sources = [];
|
|
2384
|
+
let confidence = 0;
|
|
2385
|
+
let version;
|
|
2386
|
+
const deps = collectAllDependencies(pkg);
|
|
2387
|
+
if (deps['eslint']) {
|
|
2388
|
+
confidence += 50;
|
|
2389
|
+
version = parseVersionString(deps['eslint']);
|
|
2390
|
+
sources.push({ type: 'package.json', field: 'dependencies.eslint' });
|
|
2391
|
+
}
|
|
2392
|
+
const configPath = locateConfigFile(projectPath, ESLINT_CONFIG_PATTERNS);
|
|
2393
|
+
if (configPath) {
|
|
2394
|
+
confidence += 40;
|
|
2395
|
+
sources.push({ type: 'config-file', path: configPath });
|
|
2396
|
+
}
|
|
2397
|
+
if (pkg && 'eslintConfig' in pkg) {
|
|
2398
|
+
confidence += 30;
|
|
2399
|
+
sources.push({ type: 'package.json', field: 'eslintConfig' });
|
|
2400
|
+
}
|
|
2401
|
+
const eslintPlugins = keys(deps).filter((d) => d.startsWith('eslint-plugin-') || d.startsWith('@typescript-eslint/') || d.startsWith('eslint-config-'));
|
|
2402
|
+
if (eslintPlugins.length > 0) {
|
|
2403
|
+
confidence += 10;
|
|
2404
|
+
sources.push({ type: 'package.json', field: 'dependencies (eslint plugins)' });
|
|
2405
|
+
}
|
|
2406
|
+
const lintScript = pkg?.scripts?.['lint'] ?? '';
|
|
2407
|
+
if (lintScript.includes('eslint')) {
|
|
2408
|
+
confidence += 5;
|
|
2409
|
+
sources.push({ type: 'package.json', field: 'scripts.lint' });
|
|
2410
|
+
}
|
|
2411
|
+
if (confidence === 0) {
|
|
2412
|
+
return null;
|
|
2413
|
+
}
|
|
2414
|
+
return {
|
|
2415
|
+
id: 'eslint',
|
|
2416
|
+
name: 'ESLint',
|
|
2417
|
+
version,
|
|
2418
|
+
configPath,
|
|
2419
|
+
confidence: min(confidence, 100),
|
|
2420
|
+
detectedFrom: sources,
|
|
2421
|
+
};
|
|
2422
|
+
}
|
|
2423
|
+
|
|
2424
|
+
/** Config patterns for Prettier */
|
|
2425
|
+
const PRETTIER_CONFIG_PATTERNS = [
|
|
2426
|
+
'prettier.config.js',
|
|
2427
|
+
'prettier.config.mjs',
|
|
2428
|
+
'prettier.config.cjs',
|
|
2429
|
+
'.prettierrc',
|
|
2430
|
+
'.prettierrc.json',
|
|
2431
|
+
'.prettierrc.yaml',
|
|
2432
|
+
'.prettierrc.yml',
|
|
2433
|
+
'.prettierrc.js',
|
|
2434
|
+
'.prettierrc.cjs',
|
|
2435
|
+
'.prettierrc.toml',
|
|
2436
|
+
];
|
|
2437
|
+
/**
|
|
2438
|
+
* Detect Prettier in project.
|
|
2439
|
+
*
|
|
2440
|
+
* @param projectPath - Project directory path
|
|
2441
|
+
* @param packageJson - Optional pre-loaded package.json
|
|
2442
|
+
* @returns Detection result or null if not detected
|
|
2443
|
+
*/
|
|
2444
|
+
function prettierDetector(projectPath, packageJson) {
|
|
2445
|
+
const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
|
|
2446
|
+
const sources = [];
|
|
2447
|
+
let confidence = 0;
|
|
2448
|
+
let version;
|
|
2449
|
+
const deps = collectAllDependencies(pkg);
|
|
2450
|
+
if (deps['prettier']) {
|
|
2451
|
+
confidence += 50;
|
|
2452
|
+
version = parseVersionString(deps['prettier']);
|
|
2453
|
+
sources.push({ type: 'package.json', field: 'dependencies.prettier' });
|
|
2454
|
+
}
|
|
2455
|
+
const configPath = locateConfigFile(projectPath, PRETTIER_CONFIG_PATTERNS);
|
|
2456
|
+
if (configPath) {
|
|
2457
|
+
confidence += 40;
|
|
2458
|
+
sources.push({ type: 'config-file', path: configPath });
|
|
2459
|
+
}
|
|
2460
|
+
if (pkg && 'prettier' in pkg) {
|
|
2461
|
+
confidence += 30;
|
|
2462
|
+
sources.push({ type: 'package.json', field: 'prettier' });
|
|
2463
|
+
}
|
|
2464
|
+
// .prettierignore file
|
|
2465
|
+
if (exists(join$1(projectPath, '.prettierignore'))) {
|
|
2466
|
+
confidence += 10;
|
|
2467
|
+
sources.push({ type: 'config-file', path: '.prettierignore' });
|
|
2468
|
+
}
|
|
2469
|
+
const prettierPlugins = keys(deps).filter((d) => d.startsWith('prettier-plugin-'));
|
|
2470
|
+
if (prettierPlugins.length > 0) {
|
|
2471
|
+
confidence += 5;
|
|
2472
|
+
sources.push({ type: 'package.json', field: 'dependencies (prettier plugins)' });
|
|
2473
|
+
}
|
|
2474
|
+
const formatScript = pkg?.scripts?.['format'] ?? pkg?.scripts?.['prettier'] ?? '';
|
|
2475
|
+
if (formatScript.includes('prettier')) {
|
|
2476
|
+
confidence += 5;
|
|
2477
|
+
sources.push({ type: 'package.json', field: 'scripts.format' });
|
|
2478
|
+
}
|
|
2479
|
+
if (confidence === 0) {
|
|
2480
|
+
return null;
|
|
2481
|
+
}
|
|
2482
|
+
return {
|
|
2483
|
+
id: 'prettier',
|
|
2484
|
+
name: 'Prettier',
|
|
2485
|
+
version,
|
|
2486
|
+
configPath,
|
|
2487
|
+
confidence: min(confidence, 100),
|
|
2488
|
+
detectedFrom: sources,
|
|
2489
|
+
};
|
|
2490
|
+
}
|
|
2491
|
+
|
|
2492
|
+
/** Config patterns for Stylelint */
|
|
2493
|
+
const STYLELINT_CONFIG_PATTERNS = [
|
|
2494
|
+
'.stylelintrc',
|
|
2495
|
+
'.stylelintrc.json',
|
|
2496
|
+
'.stylelintrc.js',
|
|
2497
|
+
'stylelint.config.js',
|
|
2498
|
+
'stylelint.config.cjs',
|
|
2499
|
+
];
|
|
2500
|
+
/**
|
|
2501
|
+
* Detect Stylelint in project.
|
|
2502
|
+
*
|
|
2503
|
+
* @param projectPath - Project directory path
|
|
2504
|
+
* @param packageJson - Optional pre-loaded package.json
|
|
2505
|
+
* @returns Detection result or null if not detected
|
|
2506
|
+
*/
|
|
2507
|
+
function stylelintDetector(projectPath, packageJson) {
|
|
2508
|
+
const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
|
|
2509
|
+
const sources = [];
|
|
2510
|
+
let confidence = 0;
|
|
2511
|
+
let configPath;
|
|
2512
|
+
let version;
|
|
2513
|
+
const deps = collectAllDependencies(pkg);
|
|
2514
|
+
if (deps['stylelint']) {
|
|
2515
|
+
confidence += 60;
|
|
2516
|
+
version = parseVersionString(deps['stylelint']);
|
|
2517
|
+
sources.push({ type: 'package.json', field: 'dependencies.stylelint' });
|
|
2518
|
+
}
|
|
2519
|
+
for (const config of STYLELINT_CONFIG_PATTERNS) {
|
|
2520
|
+
if (exists(join$1(projectPath, config))) {
|
|
2521
|
+
confidence += 35;
|
|
2522
|
+
configPath = config;
|
|
2523
|
+
sources.push({ type: 'config-file', path: config });
|
|
2524
|
+
break;
|
|
2525
|
+
}
|
|
2526
|
+
}
|
|
2527
|
+
const stylelintPlugins = keys(deps).filter((d) => d.startsWith('stylelint-'));
|
|
2528
|
+
if (stylelintPlugins.length > 0) {
|
|
2529
|
+
confidence += 5;
|
|
2530
|
+
sources.push({ type: 'package.json', field: 'dependencies (stylelint plugins)' });
|
|
2531
|
+
}
|
|
2532
|
+
if (confidence === 0) {
|
|
2533
|
+
return null;
|
|
2534
|
+
}
|
|
2535
|
+
return {
|
|
2536
|
+
id: 'stylelint',
|
|
2537
|
+
name: 'Stylelint',
|
|
2538
|
+
version,
|
|
2539
|
+
configPath,
|
|
2540
|
+
confidence: min(confidence, 100),
|
|
2541
|
+
detectedFrom: sources,
|
|
2542
|
+
};
|
|
2543
|
+
}
|
|
2544
|
+
|
|
2545
|
+
/**
|
|
2546
|
+
* Detect Biome in project.
|
|
2547
|
+
*
|
|
2548
|
+
* @param projectPath - Project directory path
|
|
2549
|
+
* @param packageJson - Optional pre-loaded package.json
|
|
2550
|
+
* @returns Detection result or null if not detected
|
|
2551
|
+
*/
|
|
2552
|
+
function biomeDetector(projectPath, packageJson) {
|
|
2553
|
+
const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
|
|
2554
|
+
const sources = [];
|
|
2555
|
+
let confidence = 0;
|
|
2556
|
+
let configPath;
|
|
2557
|
+
let version;
|
|
2558
|
+
const deps = collectAllDependencies(pkg);
|
|
2559
|
+
// @biomejs/biome package
|
|
2560
|
+
if (deps['@biomejs/biome']) {
|
|
2561
|
+
confidence += 70;
|
|
2562
|
+
version = parseVersionString(deps['@biomejs/biome']);
|
|
2563
|
+
sources.push({ type: 'package.json', field: 'dependencies.@biomejs/biome' });
|
|
2564
|
+
}
|
|
2565
|
+
if (exists(join$1(projectPath, 'biome.json'))) {
|
|
2566
|
+
confidence += 30;
|
|
2567
|
+
configPath = 'biome.json';
|
|
2568
|
+
sources.push({ type: 'config-file', path: 'biome.json' });
|
|
2569
|
+
}
|
|
2570
|
+
if (!configPath && exists(join$1(projectPath, 'biome.jsonc'))) {
|
|
2571
|
+
confidence += 30;
|
|
2572
|
+
configPath = 'biome.jsonc';
|
|
2573
|
+
sources.push({ type: 'config-file', path: 'biome.jsonc' });
|
|
2574
|
+
}
|
|
2575
|
+
if (confidence === 0) {
|
|
2576
|
+
return null;
|
|
2577
|
+
}
|
|
2578
|
+
return {
|
|
2579
|
+
id: 'biome',
|
|
2580
|
+
name: 'Biome',
|
|
2581
|
+
version,
|
|
2582
|
+
configPath,
|
|
2583
|
+
confidence: min(confidence, 100),
|
|
2584
|
+
detectedFrom: sources,
|
|
2585
|
+
};
|
|
2586
|
+
}
|
|
2587
|
+
|
|
2588
|
+
/** All linting tool detectors */
|
|
2589
|
+
const lintingDetectors = [
|
|
2590
|
+
{ id: 'eslint', name: 'ESLint', detect: eslintDetector },
|
|
2591
|
+
{ id: 'prettier', name: 'Prettier', detect: prettierDetector },
|
|
2592
|
+
{ id: 'stylelint', name: 'Stylelint', detect: stylelintDetector },
|
|
2593
|
+
{ id: 'biome', name: 'Biome', detect: biomeDetector },
|
|
2594
|
+
];
|
|
2595
|
+
|
|
2596
|
+
/**
|
|
2597
|
+
* Detect NX in project.
|
|
2598
|
+
*
|
|
2599
|
+
* @param workspacePath - Workspace directory path
|
|
2600
|
+
* @param packageJson - Optional pre-loaded package.json
|
|
2601
|
+
* @returns Detection result or null if not detected
|
|
2602
|
+
*/
|
|
2603
|
+
function nxDetector(workspacePath, packageJson) {
|
|
2604
|
+
const pkg = packageJson ?? readPackageJsonIfExists(workspacePath);
|
|
2605
|
+
const sources = [];
|
|
2606
|
+
let confidence = 0;
|
|
2607
|
+
let version;
|
|
2608
|
+
let workspaceLayout;
|
|
2609
|
+
const nxJsonPath = join$1(workspacePath, 'nx.json');
|
|
2610
|
+
if (exists(nxJsonPath)) {
|
|
2611
|
+
confidence += 70;
|
|
2612
|
+
sources.push({ type: 'config-file', path: 'nx.json' });
|
|
2613
|
+
}
|
|
2614
|
+
const deps = collectAllDependencies(pkg);
|
|
2615
|
+
if (deps['nx']) {
|
|
2616
|
+
confidence += 20;
|
|
2617
|
+
version = parseVersionString(deps['nx']);
|
|
2618
|
+
sources.push({ type: 'package.json', field: 'dependencies.nx' });
|
|
2619
|
+
}
|
|
2620
|
+
const hasApps = exists(join$1(workspacePath, 'apps'));
|
|
2621
|
+
const hasLibs = exists(join$1(workspacePath, 'libs'));
|
|
2622
|
+
if (hasApps || hasLibs) {
|
|
2623
|
+
confidence += 10;
|
|
2624
|
+
sources.push({ type: 'directory', path: 'apps/ or libs/' });
|
|
2625
|
+
workspaceLayout = {
|
|
2626
|
+
appsDir: hasApps ? 'apps' : '',
|
|
2627
|
+
libsDir: hasLibs ? 'libs' : '',
|
|
2628
|
+
};
|
|
2629
|
+
}
|
|
2630
|
+
const nxPackages = keys(deps).filter((d) => d.startsWith('@nx/') || d.startsWith('@nrwl/'));
|
|
2631
|
+
if (nxPackages.length > 0) {
|
|
2632
|
+
confidence += 10;
|
|
2633
|
+
sources.push({ type: 'package.json', field: '@nx/* packages' });
|
|
2634
|
+
}
|
|
2635
|
+
if (confidence === 0) {
|
|
2636
|
+
return null;
|
|
2637
|
+
}
|
|
2638
|
+
return {
|
|
2639
|
+
id: 'nx',
|
|
2640
|
+
name: 'NX',
|
|
2641
|
+
version,
|
|
2642
|
+
configPath: exists(nxJsonPath) ? 'nx.json' : undefined,
|
|
2643
|
+
confidence: min(confidence, 100),
|
|
2644
|
+
detectedFrom: sources,
|
|
2645
|
+
workspaceLayout,
|
|
2646
|
+
};
|
|
2647
|
+
}
|
|
2648
|
+
|
|
2649
|
+
/**
|
|
2650
|
+
* Detect Turborepo in project.
|
|
2651
|
+
*
|
|
2652
|
+
* @param workspacePath - Workspace directory path
|
|
2653
|
+
* @param packageJson - Optional pre-loaded package.json
|
|
2654
|
+
* @returns Detection result or null if not detected
|
|
2655
|
+
*/
|
|
2656
|
+
function turborepoDetector(workspacePath, packageJson) {
|
|
2657
|
+
const pkg = packageJson ?? readPackageJsonIfExists(workspacePath);
|
|
2658
|
+
const sources = [];
|
|
2659
|
+
let confidence = 0;
|
|
2660
|
+
let version;
|
|
2661
|
+
let configPath;
|
|
2662
|
+
const turboJsonPath = join$1(workspacePath, 'turbo.json');
|
|
2663
|
+
if (exists(turboJsonPath)) {
|
|
2664
|
+
confidence += 80;
|
|
2665
|
+
configPath = 'turbo.json';
|
|
2666
|
+
sources.push({ type: 'config-file', path: 'turbo.json' });
|
|
2667
|
+
}
|
|
2668
|
+
const deps = collectAllDependencies(pkg);
|
|
2669
|
+
if (deps['turbo']) {
|
|
2670
|
+
confidence += 15;
|
|
2671
|
+
version = parseVersionString(deps['turbo']);
|
|
2672
|
+
sources.push({ type: 'package.json', field: 'dependencies.turbo' });
|
|
2673
|
+
}
|
|
2674
|
+
const scripts = pkg?.scripts ?? {};
|
|
2675
|
+
if (values(scripts).some((s) => s?.includes('turbo'))) {
|
|
2676
|
+
confidence += 5;
|
|
2677
|
+
sources.push({ type: 'package.json', field: 'scripts (turbo commands)' });
|
|
2678
|
+
}
|
|
2679
|
+
if (confidence === 0) {
|
|
2680
|
+
return null;
|
|
2681
|
+
}
|
|
2682
|
+
return {
|
|
2683
|
+
id: 'turborepo',
|
|
2684
|
+
name: 'Turborepo',
|
|
2685
|
+
version,
|
|
2686
|
+
configPath,
|
|
2687
|
+
confidence: min(confidence, 100),
|
|
2688
|
+
detectedFrom: sources,
|
|
2689
|
+
};
|
|
2690
|
+
}
|
|
2691
|
+
|
|
2692
|
+
/**
|
|
2693
|
+
* Detect Lerna in project.
|
|
2694
|
+
*
|
|
2695
|
+
* @param workspacePath - Workspace directory path
|
|
2696
|
+
* @param packageJson - Optional pre-loaded package.json
|
|
2697
|
+
* @returns Detection result or null if not detected
|
|
2698
|
+
*/
|
|
2699
|
+
function lernaDetector(workspacePath, packageJson) {
|
|
2700
|
+
const pkg = packageJson ?? readPackageJsonIfExists(workspacePath);
|
|
2701
|
+
const sources = [];
|
|
2702
|
+
let confidence = 0;
|
|
2703
|
+
let version;
|
|
2704
|
+
let configPath;
|
|
2705
|
+
const lernaJsonPath = join$1(workspacePath, 'lerna.json');
|
|
2706
|
+
if (exists(lernaJsonPath)) {
|
|
2707
|
+
confidence += 80;
|
|
2708
|
+
configPath = 'lerna.json';
|
|
2709
|
+
sources.push({ type: 'config-file', path: 'lerna.json' });
|
|
2710
|
+
}
|
|
2711
|
+
const deps = collectAllDependencies(pkg);
|
|
2712
|
+
if (deps['lerna']) {
|
|
2713
|
+
confidence += 15;
|
|
2714
|
+
version = parseVersionString(deps['lerna']);
|
|
2715
|
+
sources.push({ type: 'package.json', field: 'dependencies.lerna' });
|
|
2716
|
+
}
|
|
2717
|
+
if (exists(join$1(workspacePath, 'packages'))) {
|
|
2718
|
+
confidence += 5;
|
|
2719
|
+
sources.push({ type: 'directory', path: 'packages/' });
|
|
2720
|
+
}
|
|
2721
|
+
if (confidence === 0) {
|
|
2722
|
+
return null;
|
|
2723
|
+
}
|
|
2724
|
+
return {
|
|
2725
|
+
id: 'lerna',
|
|
2726
|
+
name: 'Lerna',
|
|
2727
|
+
version,
|
|
2728
|
+
configPath,
|
|
2729
|
+
confidence: min(confidence, 100),
|
|
2730
|
+
detectedFrom: sources,
|
|
2731
|
+
};
|
|
2732
|
+
}
|
|
2733
|
+
|
|
2734
|
+
/**
|
|
2735
|
+
* Detect Rush in project.
|
|
2736
|
+
*
|
|
2737
|
+
* @param workspacePath - Workspace directory path
|
|
2738
|
+
* @param packageJson - Optional pre-loaded package.json
|
|
2739
|
+
* @returns Detection result or null if not detected
|
|
2740
|
+
*/
|
|
2741
|
+
function rushDetector(workspacePath, packageJson) {
|
|
2742
|
+
const pkg = packageJson ?? readPackageJsonIfExists(workspacePath);
|
|
2743
|
+
const sources = [];
|
|
2744
|
+
let confidence = 0;
|
|
2745
|
+
let version;
|
|
2746
|
+
let configPath;
|
|
2747
|
+
const rushJsonPath = join$1(workspacePath, 'rush.json');
|
|
2748
|
+
if (exists(rushJsonPath)) {
|
|
2749
|
+
confidence += 90;
|
|
2750
|
+
configPath = 'rush.json';
|
|
2751
|
+
sources.push({ type: 'config-file', path: 'rush.json' });
|
|
2752
|
+
}
|
|
2753
|
+
const deps = collectAllDependencies(pkg);
|
|
2754
|
+
if (deps['@microsoft/rush']) {
|
|
2755
|
+
confidence += 10;
|
|
2756
|
+
version = parseVersionString(deps['@microsoft/rush']);
|
|
2757
|
+
sources.push({ type: 'package.json', field: 'dependencies.@microsoft/rush' });
|
|
2758
|
+
}
|
|
2759
|
+
if (exists(join$1(workspacePath, 'common', 'config', 'rush'))) {
|
|
2760
|
+
confidence += 5;
|
|
2761
|
+
sources.push({ type: 'directory', path: 'common/config/rush/' });
|
|
2762
|
+
}
|
|
2763
|
+
if (confidence === 0) {
|
|
2764
|
+
return null;
|
|
2765
|
+
}
|
|
2766
|
+
return {
|
|
2767
|
+
id: 'rush',
|
|
2768
|
+
name: 'Rush',
|
|
2769
|
+
version,
|
|
2770
|
+
configPath,
|
|
2771
|
+
confidence: min(confidence, 100),
|
|
2772
|
+
detectedFrom: sources,
|
|
2773
|
+
};
|
|
2774
|
+
}
|
|
2775
|
+
|
|
2776
|
+
/**
|
|
2777
|
+
* Detect pnpm workspaces in project.
|
|
2778
|
+
*
|
|
2779
|
+
* @param workspacePath - Workspace directory path
|
|
2780
|
+
* @returns Detection result or null if not detected
|
|
2781
|
+
*/
|
|
2782
|
+
function pnpmWorkspacesDetector(workspacePath) {
|
|
2783
|
+
const sources = [];
|
|
2784
|
+
let confidence = 0;
|
|
2785
|
+
let configPath;
|
|
2786
|
+
const pnpmWorkspacePath = join$1(workspacePath, 'pnpm-workspace.yaml');
|
|
2787
|
+
if (exists(pnpmWorkspacePath)) {
|
|
2788
|
+
confidence += 90;
|
|
2789
|
+
configPath = 'pnpm-workspace.yaml';
|
|
2790
|
+
sources.push({ type: 'config-file', path: 'pnpm-workspace.yaml' });
|
|
2791
|
+
}
|
|
2792
|
+
if (exists(join$1(workspacePath, 'pnpm-lock.yaml'))) {
|
|
2793
|
+
confidence += 10;
|
|
2794
|
+
sources.push({ type: 'lockfile', path: 'pnpm-lock.yaml' });
|
|
2795
|
+
}
|
|
2796
|
+
if (confidence === 0) {
|
|
2797
|
+
return null;
|
|
2798
|
+
}
|
|
2799
|
+
return {
|
|
2800
|
+
id: 'pnpm-workspaces',
|
|
2801
|
+
name: 'pnpm Workspaces',
|
|
2802
|
+
configPath,
|
|
2803
|
+
confidence: min(confidence, 100),
|
|
2804
|
+
detectedFrom: sources,
|
|
2805
|
+
};
|
|
2806
|
+
}
|
|
2807
|
+
|
|
2808
|
+
/**
|
|
2809
|
+
* Detect npm workspaces in project.
|
|
2810
|
+
*
|
|
2811
|
+
* @param workspacePath - Workspace directory path
|
|
2812
|
+
* @param packageJson - Optional pre-loaded package.json
|
|
2813
|
+
* @returns Detection result or null if not detected
|
|
2814
|
+
*/
|
|
2815
|
+
function npmWorkspacesDetector(workspacePath, packageJson) {
|
|
2816
|
+
const pkg = packageJson ?? readPackageJsonIfExists(workspacePath);
|
|
2817
|
+
const sources = [];
|
|
2818
|
+
let confidence = 0;
|
|
2819
|
+
if (pkg?.workspaces) {
|
|
2820
|
+
confidence += 80;
|
|
2821
|
+
sources.push({ type: 'package.json', field: 'workspaces' });
|
|
2822
|
+
}
|
|
2823
|
+
if (exists(join$1(workspacePath, 'package-lock.json'))) {
|
|
2824
|
+
confidence += 10;
|
|
2825
|
+
sources.push({ type: 'lockfile', path: 'package-lock.json' });
|
|
2826
|
+
}
|
|
2827
|
+
if (exists(join$1(workspacePath, 'yarn.lock'))) {
|
|
2828
|
+
return null; // Let yarn workspace detector handle this
|
|
2829
|
+
}
|
|
2830
|
+
if (confidence === 0) {
|
|
2831
|
+
return null;
|
|
2832
|
+
}
|
|
2833
|
+
return {
|
|
2834
|
+
id: 'npm-workspaces',
|
|
2835
|
+
name: 'npm Workspaces',
|
|
2836
|
+
configPath: 'package.json',
|
|
2837
|
+
confidence: min(confidence, 100),
|
|
2838
|
+
detectedFrom: sources,
|
|
2839
|
+
};
|
|
2840
|
+
}
|
|
2841
|
+
|
|
2842
|
+
/**
|
|
2843
|
+
* Detect yarn workspaces in project.
|
|
2844
|
+
*
|
|
2845
|
+
* @param workspacePath - Workspace directory path
|
|
2846
|
+
* @param packageJson - Optional pre-loaded package.json
|
|
2847
|
+
* @returns Detection result or null if not detected
|
|
2848
|
+
*/
|
|
2849
|
+
function yarnWorkspacesDetector(workspacePath, packageJson) {
|
|
2850
|
+
const pkg = packageJson ?? readPackageJsonIfExists(workspacePath);
|
|
2851
|
+
const sources = [];
|
|
2852
|
+
let confidence = 0;
|
|
2853
|
+
if (pkg?.workspaces) {
|
|
2854
|
+
confidence += 70;
|
|
2855
|
+
sources.push({ type: 'package.json', field: 'workspaces' });
|
|
2856
|
+
}
|
|
2857
|
+
if (exists(join$1(workspacePath, 'yarn.lock'))) {
|
|
2858
|
+
confidence += 20;
|
|
2859
|
+
sources.push({ type: 'lockfile', path: 'yarn.lock' });
|
|
2860
|
+
}
|
|
2861
|
+
if (exists(join$1(workspacePath, '.yarnrc.yml'))) {
|
|
2862
|
+
confidence += 10;
|
|
2863
|
+
sources.push({ type: 'config-file', path: '.yarnrc.yml' });
|
|
2864
|
+
}
|
|
2865
|
+
if (confidence === 0 || !pkg?.workspaces) {
|
|
2866
|
+
return null;
|
|
2867
|
+
}
|
|
2868
|
+
return {
|
|
2869
|
+
id: 'yarn-workspaces',
|
|
2870
|
+
name: 'Yarn Workspaces',
|
|
2871
|
+
configPath: 'package.json',
|
|
2872
|
+
confidence: min(confidence, 100),
|
|
2873
|
+
detectedFrom: sources,
|
|
2874
|
+
};
|
|
2875
|
+
}
|
|
2876
|
+
|
|
2877
|
+
/** All monorepo detectors */
|
|
2878
|
+
const monorepoDetectors = [
|
|
2879
|
+
{ id: 'nx', name: 'NX', detect: nxDetector },
|
|
2880
|
+
{ id: 'turborepo', name: 'Turborepo', detect: turborepoDetector },
|
|
2881
|
+
{ id: 'lerna', name: 'Lerna', detect: lernaDetector },
|
|
2882
|
+
{ id: 'rush', name: 'Rush', detect: rushDetector },
|
|
2883
|
+
{ id: 'pnpm-workspaces', name: 'pnpm Workspaces', detect: pnpmWorkspacesDetector },
|
|
2884
|
+
{ id: 'npm-workspaces', name: 'npm Workspaces', detect: npmWorkspacesDetector },
|
|
2885
|
+
{ id: 'yarn-workspaces', name: 'Yarn Workspaces', detect: yarnWorkspacesDetector },
|
|
2886
|
+
];
|
|
2887
|
+
|
|
2888
|
+
/** Config patterns for Jest */
|
|
2889
|
+
const JEST_CONFIG_PATTERNS = ['jest.config.js', 'jest.config.ts', 'jest.config.mjs', 'jest.config.cjs', 'jest.config.json'];
|
|
2890
|
+
/**
|
|
2891
|
+
* Detect Jest in project.
|
|
2892
|
+
*
|
|
2893
|
+
* @param projectPath - Project directory path
|
|
2894
|
+
* @param packageJson - Optional pre-loaded package.json
|
|
2895
|
+
* @returns Detection result or null if not detected
|
|
2896
|
+
*/
|
|
2897
|
+
function jestDetector(projectPath, packageJson) {
|
|
2898
|
+
const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
|
|
2899
|
+
const sources = [];
|
|
2900
|
+
let confidence = 0;
|
|
2901
|
+
let version;
|
|
2902
|
+
const deps = collectAllDependencies(pkg);
|
|
2903
|
+
if (deps['jest']) {
|
|
2904
|
+
confidence += 60;
|
|
2905
|
+
version = parseVersionString(deps['jest']);
|
|
2906
|
+
sources.push({ type: 'package.json', field: 'dependencies.jest' });
|
|
2907
|
+
}
|
|
2908
|
+
const configPath = locateConfigFile(projectPath, JEST_CONFIG_PATTERNS);
|
|
2909
|
+
if (configPath) {
|
|
2910
|
+
confidence += 30;
|
|
2911
|
+
sources.push({ type: 'config-file', path: configPath });
|
|
2912
|
+
}
|
|
2913
|
+
if (pkg && 'jest' in pkg) {
|
|
2914
|
+
confidence += 20;
|
|
2915
|
+
sources.push({ type: 'package.json', field: 'jest' });
|
|
2916
|
+
}
|
|
2917
|
+
const testScript = pkg?.scripts?.['test'] ?? '';
|
|
2918
|
+
if (testScript.includes('jest')) {
|
|
2919
|
+
confidence += 10;
|
|
2920
|
+
sources.push({ type: 'package.json', field: 'scripts.test' });
|
|
2921
|
+
}
|
|
2922
|
+
if (deps['@types/jest']) {
|
|
2923
|
+
confidence += 5;
|
|
2924
|
+
sources.push({ type: 'package.json', field: 'dependencies.@types/jest' });
|
|
2925
|
+
}
|
|
2926
|
+
if (deps['ts-jest']) {
|
|
2927
|
+
confidence += 5;
|
|
2928
|
+
sources.push({ type: 'package.json', field: 'dependencies.ts-jest' });
|
|
2929
|
+
}
|
|
2930
|
+
if (confidence === 0) {
|
|
2931
|
+
return null;
|
|
2932
|
+
}
|
|
2933
|
+
return {
|
|
2934
|
+
id: 'jest',
|
|
2935
|
+
name: 'Jest',
|
|
2936
|
+
type: 'unit',
|
|
2937
|
+
version,
|
|
2938
|
+
configPath,
|
|
2939
|
+
confidence: min(confidence, 100),
|
|
2940
|
+
detectedFrom: sources,
|
|
2941
|
+
};
|
|
2942
|
+
}
|
|
2943
|
+
|
|
2944
|
+
/** Config patterns for Vitest */
|
|
2945
|
+
const VITEST_CONFIG_PATTERNS = ['vitest.config.js', 'vitest.config.ts', 'vitest.config.mjs'];
|
|
2946
|
+
/**
|
|
2947
|
+
* Detect Vitest in project.
|
|
2948
|
+
*
|
|
2949
|
+
* @param projectPath - Project directory path
|
|
2950
|
+
* @param packageJson - Optional pre-loaded package.json
|
|
2951
|
+
* @returns Detection result or null if not detected
|
|
2952
|
+
*/
|
|
2953
|
+
function vitestDetector(projectPath, packageJson) {
|
|
2954
|
+
const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
|
|
2955
|
+
const sources = [];
|
|
2956
|
+
let confidence = 0;
|
|
2957
|
+
let version;
|
|
2958
|
+
const deps = collectAllDependencies(pkg);
|
|
2959
|
+
if (deps['vitest']) {
|
|
2960
|
+
confidence += 70;
|
|
2961
|
+
version = parseVersionString(deps['vitest']);
|
|
2962
|
+
sources.push({ type: 'package.json', field: 'dependencies.vitest' });
|
|
2963
|
+
}
|
|
2964
|
+
const configPath = locateConfigFile(projectPath, VITEST_CONFIG_PATTERNS);
|
|
2965
|
+
if (configPath) {
|
|
2966
|
+
confidence += 25;
|
|
2967
|
+
sources.push({ type: 'config-file', path: configPath });
|
|
2968
|
+
}
|
|
2969
|
+
if (!configPath) {
|
|
2970
|
+
const viteConfig = exists(join$1(projectPath, 'vite.config.ts')) ||
|
|
2971
|
+
exists(join$1(projectPath, 'vite.config.js')) ||
|
|
2972
|
+
exists(join$1(projectPath, 'vite.config.mjs'));
|
|
2973
|
+
if (viteConfig && deps['vitest']) {
|
|
2974
|
+
confidence += 5;
|
|
2975
|
+
sources.push({ type: 'config-file', path: 'vite.config.*' });
|
|
2976
|
+
}
|
|
2977
|
+
}
|
|
2978
|
+
const testScript = pkg?.scripts?.['test'] ?? '';
|
|
2979
|
+
if (testScript.includes('vitest')) {
|
|
2980
|
+
confidence += 10;
|
|
2981
|
+
sources.push({ type: 'package.json', field: 'scripts.test' });
|
|
2982
|
+
}
|
|
2983
|
+
if (confidence === 0) {
|
|
2984
|
+
return null;
|
|
2985
|
+
}
|
|
2986
|
+
return {
|
|
2987
|
+
id: 'vitest',
|
|
2988
|
+
name: 'Vitest',
|
|
2989
|
+
type: 'unit',
|
|
2990
|
+
version,
|
|
2991
|
+
configPath,
|
|
2992
|
+
confidence: min(confidence, 100),
|
|
2993
|
+
detectedFrom: sources,
|
|
2994
|
+
};
|
|
2995
|
+
}
|
|
2996
|
+
|
|
2997
|
+
/** Config patterns for Mocha */
|
|
2998
|
+
const MOCHA_CONFIG_PATTERNS = ['.mocharc.js', '.mocharc.json', '.mocharc.yaml', '.mocharc.yml', 'mocha.opts'];
|
|
2999
|
+
/**
|
|
3000
|
+
* Detect Mocha in project.
|
|
3001
|
+
*
|
|
3002
|
+
* @param projectPath - Project directory path
|
|
3003
|
+
* @param packageJson - Optional pre-loaded package.json
|
|
3004
|
+
* @returns Detection result or null if not detected
|
|
3005
|
+
*/
|
|
3006
|
+
function mochaDetector(projectPath, packageJson) {
|
|
3007
|
+
const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
|
|
3008
|
+
const sources = [];
|
|
3009
|
+
let confidence = 0;
|
|
3010
|
+
let version;
|
|
3011
|
+
const deps = collectAllDependencies(pkg);
|
|
3012
|
+
if (deps['mocha']) {
|
|
3013
|
+
confidence += 65;
|
|
3014
|
+
version = parseVersionString(deps['mocha']);
|
|
3015
|
+
sources.push({ type: 'package.json', field: 'dependencies.mocha' });
|
|
3016
|
+
}
|
|
3017
|
+
const configPath = locateConfigFile(projectPath, MOCHA_CONFIG_PATTERNS);
|
|
3018
|
+
if (configPath) {
|
|
3019
|
+
confidence += 30;
|
|
3020
|
+
sources.push({ type: 'config-file', path: configPath });
|
|
3021
|
+
}
|
|
3022
|
+
if (deps['@types/mocha']) {
|
|
3023
|
+
confidence += 5;
|
|
3024
|
+
sources.push({ type: 'package.json', field: 'dependencies.@types/mocha' });
|
|
3025
|
+
}
|
|
3026
|
+
if (deps['chai']) {
|
|
3027
|
+
confidence += 5;
|
|
3028
|
+
sources.push({ type: 'package.json', field: 'dependencies.chai' });
|
|
3029
|
+
}
|
|
3030
|
+
const testScript = pkg?.scripts?.['test'] ?? '';
|
|
3031
|
+
if (testScript.includes('mocha')) {
|
|
3032
|
+
confidence += 10;
|
|
3033
|
+
sources.push({ type: 'package.json', field: 'scripts.test' });
|
|
3034
|
+
}
|
|
3035
|
+
if (confidence === 0) {
|
|
3036
|
+
return null;
|
|
3037
|
+
}
|
|
3038
|
+
return {
|
|
3039
|
+
id: 'mocha',
|
|
3040
|
+
name: 'Mocha',
|
|
3041
|
+
type: 'unit',
|
|
3042
|
+
version,
|
|
3043
|
+
configPath,
|
|
3044
|
+
confidence: min(confidence, 100),
|
|
3045
|
+
detectedFrom: sources,
|
|
3046
|
+
};
|
|
3047
|
+
}
|
|
3048
|
+
|
|
3049
|
+
/** Config patterns for Cypress */
|
|
3050
|
+
const CYPRESS_CONFIG_PATTERNS = ['cypress.config.js', 'cypress.config.ts', 'cypress.config.mjs', 'cypress.json'];
|
|
3051
|
+
/**
|
|
3052
|
+
* Detect Cypress in project.
|
|
3053
|
+
*
|
|
3054
|
+
* @param projectPath - Project directory path
|
|
3055
|
+
* @param packageJson - Optional pre-loaded package.json
|
|
3056
|
+
* @returns Detection result or null if not detected
|
|
3057
|
+
*/
|
|
3058
|
+
function cypressDetector(projectPath, packageJson) {
|
|
3059
|
+
const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
|
|
3060
|
+
const sources = [];
|
|
3061
|
+
let confidence = 0;
|
|
3062
|
+
let version;
|
|
3063
|
+
const deps = collectAllDependencies(pkg);
|
|
3064
|
+
if (deps['cypress']) {
|
|
3065
|
+
confidence += 60;
|
|
3066
|
+
version = parseVersionString(deps['cypress']);
|
|
3067
|
+
sources.push({ type: 'package.json', field: 'dependencies.cypress' });
|
|
3068
|
+
}
|
|
3069
|
+
const configPath = locateConfigFile(projectPath, CYPRESS_CONFIG_PATTERNS);
|
|
3070
|
+
if (configPath) {
|
|
3071
|
+
confidence += 30;
|
|
3072
|
+
sources.push({ type: 'config-file', path: configPath });
|
|
3073
|
+
}
|
|
3074
|
+
if (exists(join$1(projectPath, 'cypress'))) {
|
|
3075
|
+
confidence += 10;
|
|
3076
|
+
sources.push({ type: 'directory', path: 'cypress/' });
|
|
3077
|
+
}
|
|
3078
|
+
const e2eScript = pkg?.scripts?.['e2e'] ?? pkg?.scripts?.['test:e2e'] ?? '';
|
|
3079
|
+
if (e2eScript.includes('cypress')) {
|
|
3080
|
+
confidence += 5;
|
|
3081
|
+
sources.push({ type: 'package.json', field: 'scripts.e2e or scripts.test:e2e' });
|
|
3082
|
+
}
|
|
3083
|
+
if (confidence === 0) {
|
|
3084
|
+
return null;
|
|
3085
|
+
}
|
|
3086
|
+
return {
|
|
3087
|
+
id: 'cypress',
|
|
3088
|
+
name: 'Cypress',
|
|
3089
|
+
type: 'e2e',
|
|
3090
|
+
version,
|
|
3091
|
+
configPath,
|
|
3092
|
+
confidence: min(confidence, 100),
|
|
3093
|
+
detectedFrom: sources,
|
|
3094
|
+
};
|
|
3095
|
+
}
|
|
3096
|
+
|
|
3097
|
+
/** Config patterns for Playwright */
|
|
3098
|
+
const PLAYWRIGHT_CONFIG_PATTERNS = ['playwright.config.js', 'playwright.config.ts', 'playwright.config.mjs'];
|
|
3099
|
+
/**
|
|
3100
|
+
* Detect Playwright in project.
|
|
3101
|
+
*
|
|
3102
|
+
* @param projectPath - Project directory path
|
|
3103
|
+
* @param packageJson - Optional pre-loaded package.json
|
|
3104
|
+
* @returns Detection result or null if not detected
|
|
3105
|
+
*/
|
|
3106
|
+
function playwrightDetector(projectPath, packageJson) {
|
|
3107
|
+
const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
|
|
3108
|
+
const sources = [];
|
|
3109
|
+
let confidence = 0;
|
|
3110
|
+
let version;
|
|
3111
|
+
const deps = collectAllDependencies(pkg);
|
|
3112
|
+
if (deps['@playwright/test']) {
|
|
3113
|
+
confidence += 70;
|
|
3114
|
+
version = parseVersionString(deps['@playwright/test']);
|
|
3115
|
+
sources.push({ type: 'package.json', field: 'dependencies.@playwright/test' });
|
|
3116
|
+
}
|
|
3117
|
+
if (deps['playwright']) {
|
|
3118
|
+
confidence += 50;
|
|
3119
|
+
version = version ?? parseVersionString(deps['playwright']);
|
|
3120
|
+
sources.push({ type: 'package.json', field: 'dependencies.playwright' });
|
|
3121
|
+
}
|
|
3122
|
+
const configPath = locateConfigFile(projectPath, PLAYWRIGHT_CONFIG_PATTERNS);
|
|
3123
|
+
if (configPath) {
|
|
3124
|
+
confidence += 25;
|
|
3125
|
+
sources.push({ type: 'config-file', path: configPath });
|
|
3126
|
+
}
|
|
3127
|
+
if (exists(join$1(projectPath, 'e2e')) || exists(join$1(projectPath, 'tests'))) {
|
|
3128
|
+
confidence += 5;
|
|
3129
|
+
sources.push({ type: 'directory', path: 'e2e/ or tests/' });
|
|
3130
|
+
}
|
|
3131
|
+
const e2eScript = pkg?.scripts?.['e2e'] ?? pkg?.scripts?.['test:e2e'] ?? '';
|
|
3132
|
+
if (e2eScript.includes('playwright')) {
|
|
3133
|
+
confidence += 5;
|
|
3134
|
+
sources.push({ type: 'package.json', field: 'scripts.e2e or scripts.test:e2e' });
|
|
3135
|
+
}
|
|
3136
|
+
if (confidence === 0) {
|
|
3137
|
+
return null;
|
|
3138
|
+
}
|
|
3139
|
+
return {
|
|
3140
|
+
id: 'playwright',
|
|
3141
|
+
name: 'Playwright',
|
|
3142
|
+
type: 'e2e',
|
|
3143
|
+
version,
|
|
3144
|
+
configPath,
|
|
3145
|
+
confidence: min(confidence, 100),
|
|
3146
|
+
detectedFrom: sources,
|
|
3147
|
+
};
|
|
3148
|
+
}
|
|
3149
|
+
|
|
3150
|
+
/** All testing framework detectors */
|
|
3151
|
+
const testingDetectors = [
|
|
3152
|
+
{ id: 'jest', name: 'Jest', testType: 'unit', detect: jestDetector },
|
|
3153
|
+
{ id: 'vitest', name: 'Vitest', testType: 'unit', detect: vitestDetector },
|
|
3154
|
+
{ id: 'mocha', name: 'Mocha', testType: 'unit', detect: mochaDetector },
|
|
3155
|
+
{ id: 'cypress', name: 'Cypress', testType: 'e2e', detect: cypressDetector },
|
|
3156
|
+
{ id: 'playwright', name: 'Playwright', testType: 'e2e', detect: playwrightDetector },
|
|
3157
|
+
];
|
|
3158
|
+
|
|
3159
|
+
/**
|
|
3160
|
+
* Check if tsconfig has strict mode enabled.
|
|
3161
|
+
*
|
|
3162
|
+
* @param projectPath - The project directory path
|
|
3163
|
+
* @returns True if strict mode is enabled, undefined if unable to determine
|
|
3164
|
+
*/
|
|
3165
|
+
function checkTsConfigStrict(projectPath) {
|
|
3166
|
+
const tsconfigPath = join$1(projectPath, 'tsconfig.json');
|
|
3167
|
+
const content = readFileIfExists(tsconfigPath);
|
|
3168
|
+
if (!content)
|
|
3169
|
+
return undefined;
|
|
3170
|
+
try {
|
|
3171
|
+
// Simple JSON parsing - doesn't handle comments but good enough for strict check
|
|
3172
|
+
const cleanContent = content.replace(/\/\*[\s\S]*?\*\/|\/\/.*/g, '');
|
|
3173
|
+
const parsed = parse(cleanContent);
|
|
3174
|
+
return parsed?.compilerOptions?.strict === true;
|
|
3175
|
+
}
|
|
3176
|
+
catch {
|
|
3177
|
+
return undefined;
|
|
3178
|
+
}
|
|
3179
|
+
}
|
|
3180
|
+
/**
|
|
3181
|
+
* Detect TypeScript in project.
|
|
3182
|
+
*
|
|
3183
|
+
* @param projectPath - Project directory path
|
|
3184
|
+
* @param packageJson - Optional pre-loaded package.json
|
|
3185
|
+
* @returns Detection result or null if not detected
|
|
3186
|
+
*/
|
|
3187
|
+
function typescriptDetector(projectPath, packageJson) {
|
|
3188
|
+
const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
|
|
3189
|
+
const sources = [];
|
|
3190
|
+
let confidence = 0;
|
|
3191
|
+
let configPath;
|
|
3192
|
+
let version;
|
|
3193
|
+
const deps = collectAllDependencies(pkg);
|
|
3194
|
+
// TypeScript package
|
|
3195
|
+
if (deps['typescript']) {
|
|
3196
|
+
confidence += 50;
|
|
3197
|
+
version = parseVersionString(deps['typescript']);
|
|
3198
|
+
sources.push({ type: 'package.json', field: 'dependencies.typescript' });
|
|
3199
|
+
}
|
|
3200
|
+
// tsconfig.json
|
|
3201
|
+
if (exists(join$1(projectPath, 'tsconfig.json'))) {
|
|
3202
|
+
confidence += 40;
|
|
3203
|
+
configPath = 'tsconfig.json';
|
|
3204
|
+
sources.push({ type: 'config-file', path: 'tsconfig.json' });
|
|
3205
|
+
}
|
|
3206
|
+
// tsconfig.*.json variants
|
|
3207
|
+
const tsconfigVariants = ['tsconfig.build.json', 'tsconfig.lib.json', 'tsconfig.spec.json', 'tsconfig.app.json'];
|
|
3208
|
+
for (const variant of tsconfigVariants) {
|
|
3209
|
+
if (exists(join$1(projectPath, variant))) {
|
|
3210
|
+
confidence += 5;
|
|
3211
|
+
sources.push({ type: 'config-file', path: variant });
|
|
3212
|
+
break;
|
|
3213
|
+
}
|
|
3214
|
+
}
|
|
3215
|
+
// @types packages
|
|
3216
|
+
const typePackages = keys(deps).filter((d) => d.startsWith('@types/'));
|
|
3217
|
+
if (typePackages.length > 0) {
|
|
3218
|
+
confidence += 10;
|
|
3219
|
+
sources.push({ type: 'package.json', field: '@types/* packages' });
|
|
3220
|
+
}
|
|
3221
|
+
if (confidence === 0) {
|
|
3222
|
+
return null;
|
|
3223
|
+
}
|
|
3224
|
+
const strictMode = checkTsConfigStrict(projectPath);
|
|
3225
|
+
return {
|
|
3226
|
+
id: 'typescript',
|
|
3227
|
+
name: 'TypeScript',
|
|
3228
|
+
version,
|
|
3229
|
+
configPath,
|
|
3230
|
+
strictMode,
|
|
3231
|
+
confidence: min(confidence, 100),
|
|
3232
|
+
detectedFrom: sources,
|
|
3233
|
+
};
|
|
3234
|
+
}
|
|
3235
|
+
/**
|
|
3236
|
+
* Detect Flow in project.
|
|
3237
|
+
*
|
|
3238
|
+
* @param projectPath - Project directory path
|
|
3239
|
+
* @param packageJson - Optional pre-loaded package.json
|
|
3240
|
+
* @returns Detection result or null if not detected
|
|
3241
|
+
*/
|
|
3242
|
+
function flowDetector(projectPath, packageJson) {
|
|
3243
|
+
const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
|
|
3244
|
+
const sources = [];
|
|
3245
|
+
let confidence = 0;
|
|
3246
|
+
let configPath;
|
|
3247
|
+
let version;
|
|
3248
|
+
const deps = collectAllDependencies(pkg);
|
|
3249
|
+
// flow-bin package
|
|
3250
|
+
if (deps['flow-bin']) {
|
|
3251
|
+
confidence += 60;
|
|
3252
|
+
version = parseVersionString(deps['flow-bin']);
|
|
3253
|
+
sources.push({ type: 'package.json', field: 'dependencies.flow-bin' });
|
|
3254
|
+
}
|
|
3255
|
+
// .flowconfig
|
|
3256
|
+
if (exists(join$1(projectPath, '.flowconfig'))) {
|
|
3257
|
+
confidence += 40;
|
|
3258
|
+
configPath = '.flowconfig';
|
|
3259
|
+
sources.push({ type: 'config-file', path: '.flowconfig' });
|
|
3260
|
+
}
|
|
3261
|
+
// flow-typed directory
|
|
3262
|
+
if (exists(join$1(projectPath, 'flow-typed'))) {
|
|
3263
|
+
confidence += 10;
|
|
3264
|
+
sources.push({ type: 'directory', path: 'flow-typed/' });
|
|
3265
|
+
}
|
|
3266
|
+
// @babel/preset-flow
|
|
3267
|
+
if (deps['@babel/preset-flow']) {
|
|
3268
|
+
confidence += 10;
|
|
3269
|
+
sources.push({ type: 'package.json', field: 'dependencies.@babel/preset-flow' });
|
|
3270
|
+
}
|
|
3271
|
+
if (confidence === 0) {
|
|
3272
|
+
return null;
|
|
3273
|
+
}
|
|
3274
|
+
return {
|
|
3275
|
+
id: 'flow',
|
|
3276
|
+
name: 'Flow',
|
|
3277
|
+
version,
|
|
3278
|
+
configPath,
|
|
3279
|
+
confidence: min(confidence, 100),
|
|
3280
|
+
detectedFrom: sources,
|
|
3281
|
+
};
|
|
3282
|
+
}
|
|
3283
|
+
/**
|
|
3284
|
+
* Check if a file contains JSDoc type annotations.
|
|
3285
|
+
*
|
|
3286
|
+
* @param content - The file content to check.
|
|
3287
|
+
* @returns `true` if the content contains JSDoc type annotations.
|
|
3288
|
+
*/
|
|
3289
|
+
function hasJsDocTypes(content) {
|
|
3290
|
+
// Check for JSDoc type annotations
|
|
3291
|
+
return (content.includes('@type {') ||
|
|
3292
|
+
content.includes('@param {') ||
|
|
3293
|
+
content.includes('@returns {') ||
|
|
3294
|
+
content.includes('@typedef') ||
|
|
3295
|
+
content.includes('@template'));
|
|
3296
|
+
}
|
|
3297
|
+
/**
|
|
3298
|
+
* Detect JSDoc type annotations in project.
|
|
3299
|
+
*
|
|
3300
|
+
* @param projectPath - Project directory path
|
|
3301
|
+
* @param packageJson - Optional pre-loaded package.json
|
|
3302
|
+
* @returns Detection result or null if not detected
|
|
3303
|
+
*/
|
|
3304
|
+
function jsdocDetector(projectPath, packageJson) {
|
|
3305
|
+
const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
|
|
3306
|
+
const sources = [];
|
|
3307
|
+
let confidence = 0;
|
|
3308
|
+
const deps = collectAllDependencies(pkg);
|
|
3309
|
+
// jsdoc package
|
|
3310
|
+
if (deps['jsdoc']) {
|
|
3311
|
+
confidence += 30;
|
|
3312
|
+
sources.push({ type: 'package.json', field: 'dependencies.jsdoc' });
|
|
3313
|
+
}
|
|
3314
|
+
// typescript with checkJs (JSDoc type checking)
|
|
3315
|
+
if (deps['typescript']) {
|
|
3316
|
+
// Check if checkJs is enabled in tsconfig
|
|
3317
|
+
const tsconfigPath = join$1(projectPath, 'tsconfig.json');
|
|
3318
|
+
const content = readFileIfExists(tsconfigPath);
|
|
3319
|
+
if (content) {
|
|
3320
|
+
try {
|
|
3321
|
+
const cleanContent = content.replace(/\/\*[\s\S]*?\*\/|\/\/.*/g, '');
|
|
3322
|
+
const parsed = parse(cleanContent);
|
|
3323
|
+
if (parsed?.compilerOptions?.checkJs === true || parsed?.compilerOptions?.allowJs === true) {
|
|
3324
|
+
confidence += 30;
|
|
3325
|
+
sources.push({ type: 'config-file', path: 'tsconfig.json (checkJs/allowJs)' });
|
|
3326
|
+
}
|
|
3327
|
+
}
|
|
3328
|
+
catch {
|
|
3329
|
+
// Ignore parsing errors
|
|
3330
|
+
}
|
|
3331
|
+
}
|
|
3332
|
+
}
|
|
3333
|
+
// Check for jsconfig.json (VS Code JS type checking)
|
|
3334
|
+
if (exists(join$1(projectPath, 'jsconfig.json'))) {
|
|
3335
|
+
confidence += 40;
|
|
3336
|
+
sources.push({ type: 'config-file', path: 'jsconfig.json' });
|
|
3337
|
+
}
|
|
3338
|
+
// Sample check for JSDoc annotations in source files
|
|
3339
|
+
const srcDir = join$1(projectPath, 'src');
|
|
3340
|
+
if (exists(srcDir)) {
|
|
3341
|
+
try {
|
|
3342
|
+
const entries = readDirectory(srcDir);
|
|
3343
|
+
const files = entries.filter((e) => e.isFile && (e.name.endsWith('.js') || e.name.endsWith('.mjs'))).map((e) => e.name);
|
|
3344
|
+
for (const file of files.slice(0, 3)) {
|
|
3345
|
+
const content = readFileIfExists(join$1(srcDir, file));
|
|
3346
|
+
if (content && hasJsDocTypes(content)) {
|
|
3347
|
+
confidence += 20;
|
|
3348
|
+
sources.push({ type: 'directory', path: `src/${file} (JSDoc annotations)` });
|
|
3349
|
+
break;
|
|
3350
|
+
}
|
|
3351
|
+
}
|
|
3352
|
+
}
|
|
3353
|
+
catch {
|
|
3354
|
+
// Ignore directory read errors
|
|
3355
|
+
}
|
|
3356
|
+
}
|
|
3357
|
+
if (confidence === 0) {
|
|
3358
|
+
return null;
|
|
3359
|
+
}
|
|
3360
|
+
return {
|
|
3361
|
+
id: 'jsdoc',
|
|
3362
|
+
name: 'JSDoc',
|
|
3363
|
+
confidence: min(confidence, 100),
|
|
3364
|
+
detectedFrom: sources,
|
|
3365
|
+
};
|
|
3366
|
+
}
|
|
3367
|
+
/** All type system detectors */
|
|
3368
|
+
const typeSystemDetectors = [
|
|
3369
|
+
{ id: 'typescript', name: 'TypeScript', detect: typescriptDetector },
|
|
3370
|
+
{ id: 'flow', name: 'Flow', detect: flowDetector },
|
|
3371
|
+
{ id: 'jsdoc', name: 'JSDoc', detect: jsdocDetector },
|
|
3372
|
+
];
|
|
3373
|
+
|
|
3374
|
+
const techLogger = createScopedLogger('project-scope:tech');
|
|
3375
|
+
/**
|
|
3376
|
+
* Cache for tech detection results.
|
|
3377
|
+
* TTL: 60 seconds (tech stack can change during active development)
|
|
3378
|
+
*/
|
|
3379
|
+
const detectAllCache = createCache({ ttl: 60000, maxSize: 50 });
|
|
3380
|
+
/**
|
|
3381
|
+
* Check if the value is a DetectAllOptions object.
|
|
3382
|
+
*
|
|
3383
|
+
* @param value - Value to check
|
|
3384
|
+
* @returns True if value is DetectAllOptions
|
|
3385
|
+
*/
|
|
3386
|
+
function isDetectAllOptions(value) {
|
|
3387
|
+
if (typeof value !== 'object' || value === null)
|
|
3388
|
+
return false;
|
|
3389
|
+
// DetectAllOptions has skipCache or packageJson fields specifically
|
|
3390
|
+
// PackageJson never has skipCache field
|
|
3391
|
+
return 'skipCache' in value || 'packageJson' in value;
|
|
3392
|
+
}
|
|
3393
|
+
/**
|
|
3394
|
+
* Run all technology detectors on a project.
|
|
3395
|
+
*
|
|
3396
|
+
* Results are cached for 60 seconds per project path to avoid
|
|
3397
|
+
* redundant file system operations on repeated calls.
|
|
3398
|
+
*
|
|
3399
|
+
* @param projectPath - Path to project directory
|
|
3400
|
+
* @param packageJsonOrOptions - Optional pre-loaded package.json or options object
|
|
3401
|
+
* @returns All detection results organized by category
|
|
3402
|
+
*
|
|
3403
|
+
* @example
|
|
3404
|
+
* ```typescript
|
|
3405
|
+
* import { detectAll } from '@hyperfrontend/project-scope'
|
|
3406
|
+
*
|
|
3407
|
+
* const detections = detectAll('./my-project')
|
|
3408
|
+
*
|
|
3409
|
+
* // Check frontend frameworks
|
|
3410
|
+
* for (const fw of detections.frontendFrameworks) {
|
|
3411
|
+
* console.log(`${fw.name} v${fw.version} (${fw.confidence}% confidence)`)
|
|
3412
|
+
* }
|
|
3413
|
+
*
|
|
3414
|
+
* // Check build tools
|
|
3415
|
+
* console.log('Build tools:', detections.buildTools.map(t => t.name))
|
|
3416
|
+
*
|
|
3417
|
+
* // Check testing frameworks
|
|
3418
|
+
* console.log('Testing:', detections.testingFrameworks.map(t => t.name))
|
|
3419
|
+
* ```
|
|
3420
|
+
*/
|
|
3421
|
+
function detectAll(projectPath, packageJsonOrOptions) {
|
|
3422
|
+
// Handle backward-compatible arguments
|
|
3423
|
+
const options = isDetectAllOptions(packageJsonOrOptions) ? packageJsonOrOptions : { packageJson: packageJsonOrOptions };
|
|
3424
|
+
// Check cache first (unless skipCache is true)
|
|
3425
|
+
if (!options.skipCache) {
|
|
3426
|
+
const cached = detectAllCache.get(projectPath);
|
|
3427
|
+
if (cached) {
|
|
3428
|
+
techLogger.debug('Returning cached tech detection results', { projectPath });
|
|
3429
|
+
return cached;
|
|
3430
|
+
}
|
|
3431
|
+
}
|
|
3432
|
+
const pkg = options.packageJson ?? readPackageJsonIfExists(projectPath);
|
|
3433
|
+
techLogger.debug('Running all tech detectors', { projectPath });
|
|
3434
|
+
const result = {
|
|
3435
|
+
buildTools: buildToolDetectors
|
|
3436
|
+
.map((d) => d.detect(projectPath, pkg ?? undefined))
|
|
3437
|
+
.filter((r) => r !== null)
|
|
3438
|
+
.sort((a, b) => b.confidence - a.confidence),
|
|
3439
|
+
monorepo: monorepoDetectors
|
|
3440
|
+
.map((d) => d.detect(projectPath, pkg ?? undefined))
|
|
3441
|
+
.filter((r) => r !== null)
|
|
3442
|
+
.sort((a, b) => b.confidence - a.confidence),
|
|
3443
|
+
frontendFrameworks: frameworkDetectors
|
|
3444
|
+
.map((d) => d.detect(projectPath, pkg ?? undefined))
|
|
3445
|
+
.filter((r) => r !== null)
|
|
3446
|
+
.sort((a, b) => b.confidence - a.confidence),
|
|
3447
|
+
backendFrameworks: backendDetectors
|
|
3448
|
+
.map((d) => d.detect(projectPath, pkg ?? undefined))
|
|
3449
|
+
.filter((r) => r !== null)
|
|
3450
|
+
.sort((a, b) => b.confidence - a.confidence),
|
|
3451
|
+
legacyFrameworks: legacyDetectors
|
|
3452
|
+
.map((d) => d.detect(projectPath, pkg ?? undefined))
|
|
3453
|
+
.filter((r) => r !== null)
|
|
3454
|
+
.sort((a, b) => b.confidence - a.confidence),
|
|
3455
|
+
testingFrameworks: testingDetectors
|
|
3456
|
+
.map((d) => d.detect(projectPath, pkg ?? undefined))
|
|
3457
|
+
.filter((r) => r !== null)
|
|
3458
|
+
.sort((a, b) => b.confidence - a.confidence),
|
|
3459
|
+
typeSystem: typeSystemDetectors
|
|
3460
|
+
.map((d) => d.detect(projectPath, pkg ?? undefined))
|
|
3461
|
+
.filter((r) => r !== null)
|
|
3462
|
+
.sort((a, b) => b.confidence - a.confidence),
|
|
3463
|
+
linting: lintingDetectors
|
|
3464
|
+
.map((d) => d.detect(projectPath, pkg ?? undefined))
|
|
3465
|
+
.filter((r) => r !== null)
|
|
3466
|
+
.sort((a, b) => b.confidence - a.confidence),
|
|
3467
|
+
};
|
|
3468
|
+
techLogger.debug('Tech detection complete', {
|
|
3469
|
+
buildTools: result.buildTools.map((t) => t.id),
|
|
3470
|
+
frontendFrameworks: result.frontendFrameworks.map((f) => f.id),
|
|
3471
|
+
backendFrameworks: result.backendFrameworks.map((f) => f.id),
|
|
3472
|
+
legacyFrameworks: result.legacyFrameworks.map((f) => f.id),
|
|
3473
|
+
testingFrameworks: result.testingFrameworks.map((f) => f.id),
|
|
3474
|
+
});
|
|
3475
|
+
// Cache the result
|
|
3476
|
+
detectAllCache.set(projectPath, result);
|
|
3477
|
+
return result;
|
|
3478
|
+
}
|
|
3479
|
+
|
|
3480
|
+
const projectTypeLogger = createScopedLogger('project-scope:heuristics:project-type');
|
|
3481
|
+
/**
|
|
3482
|
+
* Detect the type of a project based on its structure and configuration.
|
|
3483
|
+
*
|
|
3484
|
+
* Uses multiple heuristics including:
|
|
3485
|
+
* - Package name patterns
|
|
3486
|
+
* - Exports/main/module fields
|
|
3487
|
+
* - Binary (bin) field
|
|
3488
|
+
* - Entry point patterns
|
|
3489
|
+
* - Testing framework presence
|
|
3490
|
+
* - Directory structure
|
|
3491
|
+
* - Framework detection
|
|
3492
|
+
* - NX project type field
|
|
3493
|
+
*
|
|
3494
|
+
* @param projectPath - Project directory path
|
|
3495
|
+
* @param options - Detection options
|
|
3496
|
+
* @returns Project type detection result with confidence score
|
|
3497
|
+
*
|
|
3498
|
+
* @example
|
|
3499
|
+
* ```typescript
|
|
3500
|
+
* import { detectProjectType } from '@hyperfrontend/project-scope'
|
|
3501
|
+
*
|
|
3502
|
+
* const result = detectProjectType('./my-lib')
|
|
3503
|
+
* console.log(result.type) // 'library' | 'application' | 'e2e' | 'tool' | 'plugin'
|
|
3504
|
+
* console.log(result.confidence) // 85
|
|
3505
|
+
* console.log(result.evidence) // [{ factor: 'exports', confidence: 20, ... }]
|
|
3506
|
+
* ```
|
|
3507
|
+
*/
|
|
3508
|
+
function detectProjectType(projectPath, options) {
|
|
3509
|
+
projectTypeLogger.debug('Detecting project type', { projectPath, skipTechDetection: options?.skipTechDetection });
|
|
3510
|
+
const evidence = [];
|
|
3511
|
+
const typeScores = {
|
|
3512
|
+
application: 0,
|
|
3513
|
+
library: 0,
|
|
3514
|
+
e2e: 0,
|
|
3515
|
+
tool: 0,
|
|
3516
|
+
plugin: 0,
|
|
3517
|
+
unknown: 0,
|
|
3518
|
+
};
|
|
3519
|
+
const packageJson = readPackageJsonIfExists(projectPath);
|
|
3520
|
+
if (packageJson?.name) {
|
|
3521
|
+
const name = packageJson.name;
|
|
3522
|
+
if (name.includes('-e2e') || name.endsWith('-test') || name.includes('e2e-')) {
|
|
3523
|
+
typeScores.e2e += 30;
|
|
3524
|
+
evidence.push({ factor: 'name-pattern', confidence: 30, description: `Name suggests e2e: ${name}` });
|
|
3525
|
+
}
|
|
3526
|
+
if (name.includes('-plugin') || name.includes('/plugin-')) {
|
|
3527
|
+
typeScores.plugin += 30;
|
|
3528
|
+
evidence.push({ factor: 'name-pattern', confidence: 30, description: `Name suggests plugin: ${name}` });
|
|
3529
|
+
}
|
|
3530
|
+
if (name.includes('-cli') || name.includes('/cli') || name.endsWith('-cli')) {
|
|
3531
|
+
typeScores.tool += 25;
|
|
3532
|
+
evidence.push({ factor: 'name-pattern', confidence: 25, description: `Name suggests CLI tool: ${name}` });
|
|
3533
|
+
}
|
|
3534
|
+
if (name.includes('-lib') || name.includes('/lib-') || name.includes('-utils') || name.includes('/utils')) {
|
|
3535
|
+
typeScores.library += 15;
|
|
3536
|
+
evidence.push({ factor: 'name-pattern', confidence: 15, description: `Name suggests library: ${name}` });
|
|
3537
|
+
}
|
|
3538
|
+
if (name.includes('-app') || name.includes('/app-') || name.includes('-web') || name.includes('-frontend')) {
|
|
3539
|
+
typeScores.application += 15;
|
|
3540
|
+
evidence.push({ factor: 'name-pattern', confidence: 15, description: `Name suggests application: ${name}` });
|
|
3541
|
+
}
|
|
3542
|
+
}
|
|
3543
|
+
if (packageJson?.exports || packageJson?.main || packageJson?.module) {
|
|
3544
|
+
typeScores.library += 20;
|
|
3545
|
+
evidence.push({ factor: 'exports', confidence: 20, description: 'Has exports/main/module field' });
|
|
3546
|
+
}
|
|
3547
|
+
if (packageJson && 'bin' in packageJson) {
|
|
3548
|
+
typeScores.tool += 40;
|
|
3549
|
+
evidence.push({ factor: 'bin-field', confidence: 40, description: 'Has bin field (CLI executable)' });
|
|
3550
|
+
}
|
|
3551
|
+
const serverEntryPatterns = ['src/server.ts', 'src/server.js', 'server.ts', 'server.js', 'src/main.ts', 'src/app.ts'];
|
|
3552
|
+
const indexEntryPatterns = ['src/index.ts', 'src/index.js', 'index.ts', 'index.js', 'lib/index.ts', 'lib/index.js'];
|
|
3553
|
+
const hasServerEntry = serverEntryPatterns.some((p) => exists(join$1(projectPath, p)));
|
|
3554
|
+
const hasIndexEntry = indexEntryPatterns.some((p) => exists(join$1(projectPath, p)));
|
|
3555
|
+
if (hasServerEntry) {
|
|
3556
|
+
typeScores.application += 30;
|
|
3557
|
+
evidence.push({ factor: 'entry-point', confidence: 30, description: 'Has server/app entry point' });
|
|
3558
|
+
}
|
|
3559
|
+
if (hasIndexEntry && !hasServerEntry) {
|
|
3560
|
+
typeScores.library += 20;
|
|
3561
|
+
evidence.push({ factor: 'entry-point', confidence: 20, description: 'Has library-style index entry' });
|
|
3562
|
+
}
|
|
3563
|
+
if (options?.skipTechDetection !== true) {
|
|
3564
|
+
const techDetections = detectAll(projectPath, packageJson ?? undefined);
|
|
3565
|
+
const e2eFrameworkIds = ['cypress', 'playwright', 'puppeteer', 'webdriverio'];
|
|
3566
|
+
const hasE2EFramework = techDetections.testingFrameworks.some((t) => e2eFrameworkIds.includes(t.id));
|
|
3567
|
+
if (hasE2EFramework) {
|
|
3568
|
+
typeScores.e2e += 25;
|
|
3569
|
+
evidence.push({ factor: 'e2e-framework', confidence: 25, description: 'Has E2E testing framework' });
|
|
3570
|
+
}
|
|
3571
|
+
const unitFrameworkIds = ['jest', 'vitest', 'mocha'];
|
|
3572
|
+
const hasUnitFramework = techDetections.testingFrameworks.some((t) => unitFrameworkIds.includes(t.id) && t.type === 'unit');
|
|
3573
|
+
if (hasUnitFramework && !hasE2EFramework) {
|
|
3574
|
+
typeScores.library += 10;
|
|
3575
|
+
evidence.push({ factor: 'unit-framework', confidence: 10, description: 'Has unit testing framework' });
|
|
3576
|
+
}
|
|
3577
|
+
const hasFrontendFramework = techDetections.frontendFrameworks.length > 0;
|
|
3578
|
+
const hasBackendFramework = techDetections.backendFrameworks.length > 0;
|
|
3579
|
+
if (hasFrontendFramework || hasBackendFramework) {
|
|
3580
|
+
typeScores.application += 20;
|
|
3581
|
+
const frameworks = [
|
|
3582
|
+
...techDetections.frontendFrameworks.map((f) => f.name),
|
|
3583
|
+
...techDetections.backendFrameworks.map((f) => f.name),
|
|
3584
|
+
].join(', ');
|
|
3585
|
+
evidence.push({ factor: 'framework', confidence: 20, description: `Uses application framework: ${frameworks}` });
|
|
3586
|
+
}
|
|
3587
|
+
}
|
|
3588
|
+
const hasPublicDir = exists(join$1(projectPath, 'public'));
|
|
3589
|
+
const hasStaticDir = exists(join$1(projectPath, 'static'));
|
|
3590
|
+
const hasAssetsDir = exists(join$1(projectPath, 'assets'));
|
|
3591
|
+
const hasPagesDir = exists(join$1(projectPath, 'pages')) || exists(join$1(projectPath, 'src', 'pages'));
|
|
3592
|
+
const hasAppDir = exists(join$1(projectPath, 'app')) || exists(join$1(projectPath, 'src', 'app'));
|
|
3593
|
+
const hasLibDir = exists(join$1(projectPath, 'lib')) || exists(join$1(projectPath, 'src', 'lib'));
|
|
3594
|
+
const hasCypressDir = exists(join$1(projectPath, 'cypress'));
|
|
3595
|
+
const hasE2EDir = exists(join$1(projectPath, 'e2e'));
|
|
3596
|
+
if (hasPublicDir || hasStaticDir || hasAssetsDir) {
|
|
3597
|
+
typeScores.application += 15;
|
|
3598
|
+
evidence.push({ factor: 'structure', confidence: 15, description: 'Has public/static/assets directory' });
|
|
3599
|
+
}
|
|
3600
|
+
if (hasPagesDir || hasAppDir) {
|
|
3601
|
+
typeScores.application += 15;
|
|
3602
|
+
evidence.push({ factor: 'structure', confidence: 15, description: 'Has pages/app directory' });
|
|
3603
|
+
}
|
|
3604
|
+
if (hasLibDir && !hasPagesDir && !hasAppDir) {
|
|
3605
|
+
typeScores.library += 10;
|
|
3606
|
+
evidence.push({ factor: 'structure', confidence: 10, description: 'Has lib directory' });
|
|
3607
|
+
}
|
|
3608
|
+
if (hasCypressDir || hasE2EDir) {
|
|
3609
|
+
typeScores.e2e += 20;
|
|
3610
|
+
evidence.push({ factor: 'structure', confidence: 20, description: 'Has cypress/e2e directory' });
|
|
3611
|
+
}
|
|
3612
|
+
const projectJsonPath = join$1(projectPath, 'project.json');
|
|
3613
|
+
const projectJsonContent = readFileIfExists(projectJsonPath);
|
|
3614
|
+
if (projectJsonContent) {
|
|
3615
|
+
try {
|
|
3616
|
+
const projectJson = parse(projectJsonContent);
|
|
3617
|
+
if (projectJson.projectType) {
|
|
3618
|
+
const nxType = projectJson.projectType === 'library' ? 'library' : 'application';
|
|
3619
|
+
typeScores[nxType] += 50;
|
|
3620
|
+
evidence.push({ factor: 'nx-project-type', confidence: 50, description: `NX project type: ${projectJson.projectType}` });
|
|
3621
|
+
}
|
|
3622
|
+
const tags = projectJson.tags ?? [];
|
|
3623
|
+
if (tags.some((t) => t.includes('e2e'))) {
|
|
3624
|
+
typeScores.e2e += 15;
|
|
3625
|
+
evidence.push({ factor: 'nx-tags', confidence: 15, description: 'NX tags contain e2e' });
|
|
3626
|
+
}
|
|
3627
|
+
if (tags.some((t) => t.includes('util') || t.includes('lib'))) {
|
|
3628
|
+
typeScores.library += 10;
|
|
3629
|
+
evidence.push({ factor: 'nx-tags', confidence: 10, description: 'NX tags suggest library' });
|
|
3630
|
+
}
|
|
3631
|
+
}
|
|
3632
|
+
catch {
|
|
3633
|
+
// Ignore parse errors
|
|
3634
|
+
}
|
|
3635
|
+
}
|
|
3636
|
+
const hasNextConfig = exists(join$1(projectPath, 'next.config.js')) || exists(join$1(projectPath, 'next.config.mjs'));
|
|
3637
|
+
const hasAngularJson = exists(join$1(projectPath, 'angular.json'));
|
|
3638
|
+
const hasDockerfile = exists(join$1(projectPath, 'Dockerfile'));
|
|
3639
|
+
if (hasNextConfig || hasAngularJson) {
|
|
3640
|
+
typeScores.application += 25;
|
|
3641
|
+
evidence.push({ factor: 'framework-config', confidence: 25, description: 'Has framework config (Next.js/Angular)' });
|
|
3642
|
+
}
|
|
3643
|
+
if (hasDockerfile) {
|
|
3644
|
+
typeScores.application += 10;
|
|
3645
|
+
evidence.push({ factor: 'docker', confidence: 10, description: 'Has Dockerfile' });
|
|
3646
|
+
}
|
|
3647
|
+
const sortedTypes = entries(typeScores)
|
|
3648
|
+
.sort(([, a], [, b]) => b - a)
|
|
3649
|
+
.filter(([, score]) => score > 0);
|
|
3650
|
+
const [primaryType, primaryScore] = sortedTypes[0] ?? ['unknown', 0];
|
|
3651
|
+
const secondaryTypes = sortedTypes.slice(1).map(([type]) => type);
|
|
3652
|
+
const totalScore = values(typeScores).reduce((a, b) => a + b, 0);
|
|
3653
|
+
const confidence = totalScore > 0 ? min(round((primaryScore / totalScore) * 100), 100) : 0;
|
|
3654
|
+
projectTypeLogger.debug('Project type detection complete', {
|
|
3655
|
+
projectPath,
|
|
3656
|
+
detectedType: primaryType,
|
|
3657
|
+
confidence,
|
|
3658
|
+
evidenceCount: evidence.length,
|
|
3659
|
+
secondaryTypes,
|
|
3660
|
+
});
|
|
3661
|
+
return {
|
|
3662
|
+
type: primaryType,
|
|
3663
|
+
secondaryTypes,
|
|
3664
|
+
confidence,
|
|
3665
|
+
evidence,
|
|
3666
|
+
};
|
|
3667
|
+
}
|
|
3668
|
+
|
|
3669
|
+
const frameworkLogger = createScopedLogger('project-scope:heuristics:framework');
|
|
3670
|
+
/**
|
|
3671
|
+
* Cache for framework identification results.
|
|
3672
|
+
* TTL: 60 seconds (frameworks are stable but can change during development)
|
|
3673
|
+
*/
|
|
3674
|
+
const frameworkIdCache = createCache({ ttl: 60000, maxSize: 50 });
|
|
3675
|
+
/**
|
|
3676
|
+
* Build a human-readable summary string from detected frameworks.
|
|
3677
|
+
*
|
|
3678
|
+
* @param frontend - Frontend framework names
|
|
3679
|
+
* @param backend - Backend framework names
|
|
3680
|
+
* @param testing - Testing framework names
|
|
3681
|
+
* @returns Human-readable summary
|
|
3682
|
+
*/
|
|
3683
|
+
function buildSummary(frontend, backend, testing) {
|
|
3684
|
+
const parts = [];
|
|
3685
|
+
if (frontend.length > 0) {
|
|
3686
|
+
parts.push(frontend.join(' + '));
|
|
3687
|
+
}
|
|
3688
|
+
if (backend.length > 0) {
|
|
3689
|
+
if (parts.length > 0) {
|
|
3690
|
+
parts.push('with');
|
|
3691
|
+
}
|
|
3692
|
+
parts.push(backend.join(' + '));
|
|
3693
|
+
}
|
|
3694
|
+
if (testing.length > 0) {
|
|
3695
|
+
if (parts.length > 0) {
|
|
3696
|
+
parts.push('and');
|
|
3697
|
+
}
|
|
3698
|
+
parts.push(testing.join('/'));
|
|
3699
|
+
}
|
|
3700
|
+
return parts.length > 0 ? parts.join(' ') : 'No frameworks detected';
|
|
3701
|
+
}
|
|
3702
|
+
/**
|
|
3703
|
+
* Identify all frameworks in project.
|
|
3704
|
+
*
|
|
3705
|
+
* Runs all technology detectors and aggregates results into a comprehensive
|
|
3706
|
+
* framework identification with confidence scoring.
|
|
3707
|
+
*
|
|
3708
|
+
* @param projectPath - Project directory path
|
|
3709
|
+
* @param options - Identification options
|
|
3710
|
+
* @returns Framework identification result
|
|
3711
|
+
*
|
|
3712
|
+
* @example
|
|
3713
|
+
* ```typescript
|
|
3714
|
+
* import { identifyFrameworks } from '@hyperfrontend/project-scope'
|
|
3715
|
+
*
|
|
3716
|
+
* const result = identifyFrameworks('./my-react-app')
|
|
3717
|
+
* console.log(result.summary) // 'React + Next.js with Jest'
|
|
3718
|
+
* console.log(result.primary?.name) // 'React'
|
|
3719
|
+
* console.log(result.stack.frontend) // ['react', 'nextjs']
|
|
3720
|
+
* console.log(result.stack.testing) // ['jest']
|
|
3721
|
+
* ```
|
|
3722
|
+
*/
|
|
3723
|
+
function identifyFrameworks(projectPath, options) {
|
|
3724
|
+
frameworkLogger.debug('Identifying frameworks', { projectPath, minConfidence: options?.minConfidence ?? 10 });
|
|
3725
|
+
const minConfidence = options?.minConfidence ?? 10;
|
|
3726
|
+
const cacheKey = `${projectPath}:${minConfidence}`;
|
|
3727
|
+
if (!options?.skipCache) {
|
|
3728
|
+
const cached = frameworkIdCache.get(cacheKey);
|
|
3729
|
+
if (cached) {
|
|
3730
|
+
frameworkLogger.debug('Returning cached framework identification', { projectPath });
|
|
3731
|
+
return cached;
|
|
3732
|
+
}
|
|
3733
|
+
}
|
|
3734
|
+
const packageJson = readPackageJsonIfExists(projectPath);
|
|
3735
|
+
const detections = detectAll(projectPath, packageJson ?? undefined);
|
|
3736
|
+
const frontendFrameworks = detections.frontendFrameworks
|
|
3737
|
+
.filter((d) => d.confidence >= minConfidence)
|
|
3738
|
+
.map((d) => ({
|
|
3739
|
+
id: d.id,
|
|
3740
|
+
name: d.name,
|
|
3741
|
+
version: d.version,
|
|
3742
|
+
confidence: d.confidence,
|
|
3743
|
+
category: d.category === 'meta-framework' ? 'frontend' : 'frontend',
|
|
3744
|
+
metaFrameworks: d.metaFrameworks?.map((m) => m.id),
|
|
3745
|
+
}));
|
|
3746
|
+
const metaFrameworks = [];
|
|
3747
|
+
for (const detection of detections.frontendFrameworks) {
|
|
3748
|
+
if (detection.category === 'meta-framework' && detection.confidence >= minConfidence) {
|
|
3749
|
+
metaFrameworks.push({
|
|
3750
|
+
id: detection.id,
|
|
3751
|
+
name: detection.name,
|
|
3752
|
+
version: detection.version,
|
|
3753
|
+
confidence: detection.confidence,
|
|
3754
|
+
category: 'frontend',
|
|
3755
|
+
});
|
|
3756
|
+
}
|
|
3757
|
+
if (detection.metaFrameworks) {
|
|
3758
|
+
for (const meta of detection.metaFrameworks) {
|
|
3759
|
+
if (meta.confidence >= minConfidence && !metaFrameworks.some((m) => m.id === meta.id)) {
|
|
3760
|
+
metaFrameworks.push({
|
|
3761
|
+
id: meta.id,
|
|
3762
|
+
name: meta.name,
|
|
3763
|
+
version: meta.version,
|
|
3764
|
+
confidence: meta.confidence,
|
|
3765
|
+
category: 'frontend',
|
|
3766
|
+
});
|
|
3767
|
+
}
|
|
3768
|
+
}
|
|
3769
|
+
}
|
|
3770
|
+
}
|
|
3771
|
+
const backendFrameworks = detections.backendFrameworks
|
|
3772
|
+
.filter((d) => d.confidence >= minConfidence)
|
|
3773
|
+
.map((d) => ({
|
|
3774
|
+
id: d.id,
|
|
3775
|
+
name: d.name,
|
|
3776
|
+
version: d.version,
|
|
3777
|
+
confidence: d.confidence,
|
|
3778
|
+
category: 'backend',
|
|
3779
|
+
}));
|
|
3780
|
+
const testingFrameworks = detections.testingFrameworks
|
|
3781
|
+
.filter((d) => d.confidence >= minConfidence)
|
|
3782
|
+
.map((d) => ({
|
|
3783
|
+
id: d.id,
|
|
3784
|
+
name: d.name,
|
|
3785
|
+
version: d.version,
|
|
3786
|
+
configPath: d.configPath,
|
|
3787
|
+
type: d.type,
|
|
3788
|
+
confidence: d.confidence,
|
|
3789
|
+
}));
|
|
3790
|
+
const stack = {
|
|
3791
|
+
frontend: detections.frontendFrameworks.filter((d) => d.confidence >= minConfidence).map((d) => d.id),
|
|
3792
|
+
backend: detections.backendFrameworks.filter((d) => d.confidence >= minConfidence).map((d) => d.id),
|
|
3793
|
+
testing: detections.testingFrameworks.filter((d) => d.confidence >= minConfidence).map((d) => d.id),
|
|
3794
|
+
build: detections.buildTools.filter((d) => d.confidence >= minConfidence).map((d) => d.id),
|
|
3795
|
+
typeSystem: detections.typeSystem.filter((d) => d.confidence >= minConfidence).map((d) => d.id),
|
|
3796
|
+
linting: detections.linting.filter((d) => d.confidence >= minConfidence).map((d) => d.id),
|
|
3797
|
+
};
|
|
3798
|
+
const allFrameworks = [...frontendFrameworks, ...backendFrameworks];
|
|
3799
|
+
allFrameworks.sort((a, b) => b.confidence - a.confidence);
|
|
3800
|
+
const primary = allFrameworks[0];
|
|
3801
|
+
const summary = buildSummary(frontendFrameworks.map((f) => f.name), backendFrameworks.map((f) => f.name), testingFrameworks.map((f) => f.name));
|
|
3802
|
+
frameworkLogger.debug('Framework identification complete', {
|
|
3803
|
+
projectPath,
|
|
3804
|
+
primaryFramework: primary?.name ?? 'none',
|
|
3805
|
+
frontendCount: frontendFrameworks.length,
|
|
3806
|
+
backendCount: backendFrameworks.length,
|
|
3807
|
+
testingCount: testingFrameworks.length,
|
|
3808
|
+
metaFrameworkCount: metaFrameworks.length,
|
|
3809
|
+
summary,
|
|
3810
|
+
});
|
|
3811
|
+
const result = {
|
|
3812
|
+
primary,
|
|
3813
|
+
frontend: frontendFrameworks,
|
|
3814
|
+
backend: backendFrameworks,
|
|
3815
|
+
testing: testingFrameworks,
|
|
3816
|
+
metaFrameworks,
|
|
3817
|
+
summary,
|
|
3818
|
+
stack,
|
|
3819
|
+
};
|
|
3820
|
+
frameworkIdCache.set(cacheKey, result);
|
|
3821
|
+
return result;
|
|
3822
|
+
}
|
|
3823
|
+
/**
|
|
3824
|
+
* Clear the framework identification cache.
|
|
3825
|
+
*
|
|
3826
|
+
* Useful for testing or when the project files have changed.
|
|
3827
|
+
*/
|
|
3828
|
+
function clearFrameworkIdentificationCache() {
|
|
3829
|
+
frameworkIdCache.clear();
|
|
3830
|
+
}
|
|
3831
|
+
/**
|
|
3832
|
+
* Check if a project uses a specific framework.
|
|
3833
|
+
*
|
|
3834
|
+
* @param projectPath - Project directory path
|
|
3835
|
+
* @param frameworkId - Framework identifier to check
|
|
3836
|
+
* @param minConfidence - Minimum confidence threshold (default: 50)
|
|
3837
|
+
* @returns True if the framework is detected with sufficient confidence
|
|
3838
|
+
*/
|
|
3839
|
+
function usesFramework(projectPath, frameworkId, minConfidence = 50) {
|
|
3840
|
+
const identification = identifyFrameworks(projectPath, { minConfidence });
|
|
3841
|
+
const allFrameworks = [...identification.frontend, ...identification.backend, ...identification.metaFrameworks];
|
|
3842
|
+
return allFrameworks.some((f) => f.id === frameworkId && f.confidence >= minConfidence);
|
|
3843
|
+
}
|
|
3844
|
+
|
|
3845
|
+
/**
|
|
3846
|
+
* Pattern matching utilities with ReDoS protection.
|
|
3847
|
+
* Uses character-by-character matching instead of regex where possible.
|
|
3848
|
+
*/
|
|
3849
|
+
/**
|
|
3850
|
+
* Match path against glob pattern using safe character iteration.
|
|
3851
|
+
* Avoids regex to prevent ReDoS attacks.
|
|
3852
|
+
*
|
|
3853
|
+
* Supported patterns:
|
|
3854
|
+
* - * matches any characters except /
|
|
3855
|
+
* - ** matches any characters including /
|
|
3856
|
+
* - ? matches exactly one character except /
|
|
3857
|
+
* - {a,b,c} matches any of the alternatives
|
|
3858
|
+
*
|
|
3859
|
+
* @param path - The filesystem path to test against the pattern
|
|
3860
|
+
* @param pattern - The glob pattern to match against
|
|
3861
|
+
* @returns True if path matches pattern
|
|
3862
|
+
*
|
|
3863
|
+
* @example
|
|
3864
|
+
* ```typescript
|
|
3865
|
+
* import { matchGlobPattern } from '@hyperfrontend/project-scope'
|
|
3866
|
+
*
|
|
3867
|
+
* matchGlobPattern('src/utils/helper.ts', '\*\*\/*.ts') // true
|
|
3868
|
+
* matchGlobPattern('test.spec.ts', '\*.spec.ts') // true
|
|
3869
|
+
* matchGlobPattern('config.json', '\*.{json,yaml}') // true
|
|
3870
|
+
* matchGlobPattern('src/index.ts', 'src/\*.ts') // true
|
|
3871
|
+
* ```
|
|
3872
|
+
*/
|
|
3873
|
+
function matchGlobPattern(path, pattern) {
|
|
3874
|
+
return matchSegments(path.split('/'), pattern.split('/'), 0, 0);
|
|
3875
|
+
}
|
|
3876
|
+
/**
|
|
3877
|
+
* Internal recursive function to match path segments against pattern segments.
|
|
3878
|
+
*
|
|
3879
|
+
* @param pathParts - Array of path segments split by '/'
|
|
3880
|
+
* @param patternParts - Array of pattern segments split by '/'
|
|
3881
|
+
* @param pathIdx - Current index in pathParts being examined
|
|
3882
|
+
* @param patternIdx - Current index in patternParts being examined
|
|
3883
|
+
* @returns True if remaining segments match
|
|
3884
|
+
*/
|
|
3885
|
+
function matchSegments(pathParts, patternParts, pathIdx, patternIdx) {
|
|
3886
|
+
// Base cases
|
|
3887
|
+
if (pathIdx === pathParts.length && patternIdx === patternParts.length) {
|
|
3888
|
+
return true; // Both exhausted = match
|
|
3889
|
+
}
|
|
3890
|
+
if (patternIdx >= patternParts.length) {
|
|
3891
|
+
return false; // Pattern exhausted but path remains
|
|
3892
|
+
}
|
|
3893
|
+
const patternPart = patternParts[patternIdx];
|
|
3894
|
+
// Handle ** (globstar) - matches zero or more directories
|
|
3895
|
+
if (patternPart === '**') {
|
|
3896
|
+
// Try matching rest of pattern against current position and all future positions
|
|
3897
|
+
for (let i = pathIdx; i <= pathParts.length; i++) {
|
|
3898
|
+
if (matchSegments(pathParts, patternParts, i, patternIdx + 1)) {
|
|
3899
|
+
return true;
|
|
3900
|
+
}
|
|
3901
|
+
}
|
|
3902
|
+
return false;
|
|
3903
|
+
}
|
|
3904
|
+
if (pathIdx >= pathParts.length) {
|
|
3905
|
+
return false; // Path exhausted but pattern remains (and it's not **)
|
|
3906
|
+
}
|
|
3907
|
+
const pathPart = pathParts[pathIdx];
|
|
3908
|
+
// Match current segment
|
|
3909
|
+
if (matchSegment(pathPart, patternPart)) {
|
|
3910
|
+
return matchSegments(pathParts, patternParts, pathIdx + 1, patternIdx + 1);
|
|
3911
|
+
}
|
|
3912
|
+
return false;
|
|
3913
|
+
}
|
|
3914
|
+
/**
|
|
3915
|
+
* Match a single path segment against a pattern segment.
|
|
3916
|
+
* Handles *, ?, and {a,b,c} patterns.
|
|
3917
|
+
*
|
|
3918
|
+
* @param text - The path segment text to match
|
|
3919
|
+
* @param pattern - The pattern segment to match against
|
|
3920
|
+
* @returns True if the text matches the pattern
|
|
3921
|
+
*/
|
|
3922
|
+
function matchSegment(text, pattern) {
|
|
3923
|
+
let textIdx = 0;
|
|
3924
|
+
let patternIdx = 0;
|
|
3925
|
+
while (patternIdx < pattern.length) {
|
|
3926
|
+
const char = pattern[patternIdx];
|
|
3927
|
+
if (char === '*') {
|
|
3928
|
+
// * matches zero or more characters
|
|
3929
|
+
patternIdx++;
|
|
3930
|
+
if (patternIdx === pattern.length) {
|
|
3931
|
+
return true; // * at end matches rest of string
|
|
3932
|
+
}
|
|
3933
|
+
// Try matching rest of pattern at each position in text
|
|
3934
|
+
for (let i = textIdx; i <= text.length; i++) {
|
|
3935
|
+
if (matchSegmentFrom(text, i, pattern, patternIdx)) {
|
|
3936
|
+
return true;
|
|
3937
|
+
}
|
|
3938
|
+
}
|
|
3939
|
+
return false;
|
|
3940
|
+
}
|
|
3941
|
+
else if (char === '?') {
|
|
3942
|
+
// ? matches exactly one character
|
|
3943
|
+
if (textIdx >= text.length) {
|
|
3944
|
+
return false;
|
|
3945
|
+
}
|
|
3946
|
+
textIdx++;
|
|
3947
|
+
patternIdx++;
|
|
3948
|
+
}
|
|
3949
|
+
else if (char === '{') {
|
|
3950
|
+
// {a,b,c} matches any alternative
|
|
3951
|
+
const closeIdx = findClosingBrace(pattern, patternIdx);
|
|
3952
|
+
if (closeIdx === -1) {
|
|
3953
|
+
// Unmatched brace, treat as literal
|
|
3954
|
+
if (textIdx >= text.length || text[textIdx] !== char) {
|
|
3955
|
+
return false;
|
|
3956
|
+
}
|
|
3957
|
+
textIdx++;
|
|
3958
|
+
patternIdx++;
|
|
3959
|
+
}
|
|
3960
|
+
else {
|
|
3961
|
+
const alternatives = extractAlternatives(pattern.slice(patternIdx + 1, closeIdx));
|
|
3962
|
+
for (const alt of alternatives) {
|
|
3963
|
+
if (matchSegmentFrom(text, textIdx, text.slice(0, textIdx) + alt + pattern.slice(closeIdx + 1), textIdx)) {
|
|
3964
|
+
return true;
|
|
3965
|
+
}
|
|
3966
|
+
}
|
|
3967
|
+
return false;
|
|
3968
|
+
}
|
|
3969
|
+
}
|
|
3970
|
+
else {
|
|
3971
|
+
// Literal character
|
|
3972
|
+
if (textIdx >= text.length || text[textIdx] !== char) {
|
|
3973
|
+
return false;
|
|
3974
|
+
}
|
|
3975
|
+
textIdx++;
|
|
3976
|
+
patternIdx++;
|
|
3977
|
+
}
|
|
3978
|
+
}
|
|
3979
|
+
return textIdx === text.length;
|
|
3980
|
+
}
|
|
3981
|
+
/**
|
|
3982
|
+
* Helper to match from a specific position.
|
|
3983
|
+
*
|
|
3984
|
+
* @param text - The full text being matched
|
|
3985
|
+
* @param textIdx - The starting index in text to match from
|
|
3986
|
+
* @param pattern - The full pattern being matched
|
|
3987
|
+
* @param patternIdx - The starting index in pattern to match from
|
|
3988
|
+
* @returns True if the text matches the pattern from the given positions
|
|
3989
|
+
*/
|
|
3990
|
+
function matchSegmentFrom(text, textIdx, pattern, patternIdx) {
|
|
3991
|
+
const remainingText = text.slice(textIdx);
|
|
3992
|
+
const remainingPattern = pattern.slice(patternIdx);
|
|
3993
|
+
return matchSegment(remainingText, remainingPattern);
|
|
3994
|
+
}
|
|
3995
|
+
/**
|
|
3996
|
+
* Find closing brace for {a,b,c} pattern.
|
|
3997
|
+
*
|
|
3998
|
+
* @param pattern - The pattern string to search within
|
|
3999
|
+
* @param startIdx - The index of the opening brace
|
|
4000
|
+
* @returns The index of the matching closing brace, or -1 if not found
|
|
4001
|
+
*/
|
|
4002
|
+
function findClosingBrace(pattern, startIdx) {
|
|
4003
|
+
let depth = 0;
|
|
4004
|
+
for (let i = startIdx; i < pattern.length; i++) {
|
|
4005
|
+
if (pattern[i] === '{') {
|
|
4006
|
+
depth++;
|
|
4007
|
+
}
|
|
4008
|
+
else if (pattern[i] === '}') {
|
|
4009
|
+
depth--;
|
|
4010
|
+
if (depth === 0) {
|
|
4011
|
+
return i;
|
|
4012
|
+
}
|
|
4013
|
+
}
|
|
4014
|
+
}
|
|
4015
|
+
return -1;
|
|
4016
|
+
}
|
|
4017
|
+
/**
|
|
4018
|
+
* Extract alternatives from {a,b,c} pattern content.
|
|
4019
|
+
*
|
|
4020
|
+
* @param content - The content between braces (without the braces themselves)
|
|
4021
|
+
* @returns Array of alternative strings split by commas at depth 0
|
|
4022
|
+
*/
|
|
4023
|
+
function extractAlternatives(content) {
|
|
4024
|
+
const alternatives = [];
|
|
4025
|
+
let current = '';
|
|
4026
|
+
let depth = 0;
|
|
4027
|
+
for (let i = 0; i < content.length; i++) {
|
|
4028
|
+
const char = content[i];
|
|
4029
|
+
if (char === '{') {
|
|
4030
|
+
depth++;
|
|
4031
|
+
current += char;
|
|
4032
|
+
}
|
|
4033
|
+
else if (char === '}') {
|
|
4034
|
+
depth--;
|
|
4035
|
+
current += char;
|
|
4036
|
+
}
|
|
4037
|
+
else if (char === ',' && depth === 0) {
|
|
4038
|
+
alternatives.push(current);
|
|
4039
|
+
current = '';
|
|
4040
|
+
}
|
|
4041
|
+
else {
|
|
4042
|
+
current += char;
|
|
4043
|
+
}
|
|
4044
|
+
}
|
|
4045
|
+
if (current) {
|
|
4046
|
+
alternatives.push(current);
|
|
4047
|
+
}
|
|
4048
|
+
return alternatives;
|
|
4049
|
+
}
|
|
4050
|
+
|
|
4051
|
+
const walkLogger = createScopedLogger('project-scope:project:walk');
|
|
4052
|
+
/**
|
|
4053
|
+
* Reads .gitignore file from the given directory and extracts
|
|
4054
|
+
* non-comment patterns for use in file traversal filtering.
|
|
4055
|
+
*
|
|
4056
|
+
* @param startPath - Directory containing the .gitignore file
|
|
4057
|
+
* @returns Array of gitignore patterns
|
|
4058
|
+
*/
|
|
4059
|
+
function loadGitignorePatterns(startPath) {
|
|
4060
|
+
const patterns = [];
|
|
4061
|
+
const gitignorePath = join$1(startPath, '.gitignore');
|
|
4062
|
+
const content = readFileIfExists(gitignorePath);
|
|
4063
|
+
if (content) {
|
|
4064
|
+
const lines = content.split('\n');
|
|
4065
|
+
for (const line of lines) {
|
|
4066
|
+
const trimmed = line.trim();
|
|
4067
|
+
if (trimmed && !trimmed.startsWith('#')) {
|
|
4068
|
+
patterns.push(trimmed);
|
|
4069
|
+
}
|
|
4070
|
+
}
|
|
4071
|
+
}
|
|
4072
|
+
return patterns;
|
|
4073
|
+
}
|
|
4074
|
+
/**
|
|
4075
|
+
* Evaluates whether a relative path should be ignored based on
|
|
4076
|
+
* a list of gitignore-style patterns.
|
|
4077
|
+
*
|
|
4078
|
+
* @param relativePath - Path relative to the root directory
|
|
4079
|
+
* @param patterns - Array of gitignore-style patterns to test
|
|
4080
|
+
* @returns True if the path matches any ignore pattern
|
|
4081
|
+
*/
|
|
4082
|
+
function matchesIgnorePattern(relativePath, patterns) {
|
|
4083
|
+
for (const pattern of patterns) {
|
|
4084
|
+
if (matchPattern(relativePath, pattern)) {
|
|
4085
|
+
return true;
|
|
4086
|
+
}
|
|
4087
|
+
}
|
|
4088
|
+
return false;
|
|
4089
|
+
}
|
|
4090
|
+
/**
|
|
4091
|
+
* Tests if the given path matches a gitignore-style pattern,
|
|
4092
|
+
* supporting negation patterns with '!' prefix.
|
|
4093
|
+
* Uses safe character-by-character matching to prevent ReDoS attacks.
|
|
4094
|
+
*
|
|
4095
|
+
* @param path - File or directory path to test
|
|
4096
|
+
* @param pattern - Gitignore-style pattern (may include wildcards)
|
|
4097
|
+
* @returns True if the path matches the pattern (or doesn't match if negated)
|
|
4098
|
+
*/
|
|
4099
|
+
function matchPattern(path, pattern) {
|
|
4100
|
+
const normalizedPattern = pattern.startsWith('/') ? pattern.slice(1) : pattern;
|
|
4101
|
+
const isNegation = normalizedPattern.startsWith('!');
|
|
4102
|
+
const actualPattern = isNegation ? normalizedPattern.slice(1) : normalizedPattern;
|
|
4103
|
+
const matchesFullPath = matchGlobPattern(path, actualPattern) || matchGlobPattern(path, `**/${actualPattern}`);
|
|
4104
|
+
const matchesSegment = path.split('/').some((segment) => matchGlobPattern(segment, actualPattern));
|
|
4105
|
+
const matches = matchesFullPath || matchesSegment;
|
|
4106
|
+
return isNegation ? !matches : matches;
|
|
4107
|
+
}
|
|
4108
|
+
/**
|
|
4109
|
+
* Traverses a directory tree synchronously, calling a visitor function
|
|
4110
|
+
* for each file and directory encountered. Supports depth limiting,
|
|
4111
|
+
* hidden file filtering, and gitignore pattern matching.
|
|
4112
|
+
*
|
|
4113
|
+
* @param startPath - Root directory to begin traversal
|
|
4114
|
+
* @param visitor - Callback function invoked for each file system entry
|
|
4115
|
+
* @param options - Configuration for traversal behavior
|
|
4116
|
+
*/
|
|
4117
|
+
function walkDirectory(startPath, visitor, options) {
|
|
4118
|
+
walkLogger.debug('Starting directory walk', {
|
|
4119
|
+
startPath,
|
|
4120
|
+
maxDepth: options?.maxDepth ?? -1,
|
|
4121
|
+
includeHidden: options?.includeHidden ?? false,
|
|
4122
|
+
respectGitignore: options?.respectGitignore ?? true,
|
|
4123
|
+
ignorePatterns: options?.ignorePatterns?.length ?? 0,
|
|
4124
|
+
});
|
|
4125
|
+
const maxDepth = options?.maxDepth ?? -1;
|
|
4126
|
+
const includeHidden = options?.includeHidden ?? false;
|
|
4127
|
+
const ignorePatterns = options?.ignorePatterns ?? [];
|
|
4128
|
+
const respectGitignore = options?.respectGitignore ?? true;
|
|
4129
|
+
const gitignorePatterns = respectGitignore ? loadGitignorePatterns(startPath) : [];
|
|
4130
|
+
const allIgnorePatterns = [...ignorePatterns, ...gitignorePatterns];
|
|
4131
|
+
if (gitignorePatterns.length > 0) {
|
|
4132
|
+
walkLogger.debug('Loaded gitignore patterns', { count: gitignorePatterns.length });
|
|
4133
|
+
}
|
|
4134
|
+
/**
|
|
4135
|
+
* Recursively walks directory entries, applying visitor to each.
|
|
4136
|
+
*
|
|
4137
|
+
* @param currentPath - Absolute path to current directory
|
|
4138
|
+
* @param relativePath - Path relative to the starting directory
|
|
4139
|
+
* @param depth - Current recursion depth
|
|
4140
|
+
* @returns False to stop walking, true to continue
|
|
4141
|
+
*/
|
|
4142
|
+
function walk(currentPath, relativePath, depth) {
|
|
4143
|
+
if (maxDepth !== -1 && depth > maxDepth) {
|
|
4144
|
+
return true;
|
|
4145
|
+
}
|
|
4146
|
+
let entries;
|
|
4147
|
+
try {
|
|
4148
|
+
entries = readDirectory(currentPath);
|
|
4149
|
+
}
|
|
4150
|
+
catch {
|
|
4151
|
+
return true;
|
|
4152
|
+
}
|
|
4153
|
+
for (const entry of entries) {
|
|
4154
|
+
if (!includeHidden && entry.name.startsWith('.')) {
|
|
4155
|
+
continue;
|
|
4156
|
+
}
|
|
4157
|
+
const entryRelativePath = relativePath ? `${relativePath}/${entry.name}` : entry.name;
|
|
4158
|
+
if (matchesIgnorePattern(entryRelativePath, allIgnorePatterns)) {
|
|
4159
|
+
continue;
|
|
4160
|
+
}
|
|
4161
|
+
const walkEntry = {
|
|
4162
|
+
name: entry.name,
|
|
4163
|
+
path: entry.path,
|
|
4164
|
+
relativePath: entryRelativePath,
|
|
4165
|
+
isFile: entry.isFile,
|
|
4166
|
+
isDirectory: entry.isDirectory,
|
|
4167
|
+
isSymlink: entry.isSymlink,
|
|
4168
|
+
depth,
|
|
4169
|
+
};
|
|
4170
|
+
const result = visitor(walkEntry);
|
|
4171
|
+
if (result === 'stop') {
|
|
4172
|
+
return false;
|
|
4173
|
+
}
|
|
4174
|
+
if (result === 'skip') {
|
|
4175
|
+
continue;
|
|
4176
|
+
}
|
|
4177
|
+
if (entry.isDirectory) {
|
|
4178
|
+
const shouldContinue = walk(entry.path, entryRelativePath, depth + 1);
|
|
4179
|
+
if (!shouldContinue) {
|
|
4180
|
+
return false;
|
|
4181
|
+
}
|
|
4182
|
+
}
|
|
4183
|
+
}
|
|
4184
|
+
return true;
|
|
4185
|
+
}
|
|
4186
|
+
walk(startPath, '', 0);
|
|
4187
|
+
walkLogger.debug('Directory walk complete', { startPath });
|
|
4188
|
+
}
|
|
4189
|
+
|
|
4190
|
+
const searchLogger = createScopedLogger('project-scope:project:search');
|
|
4191
|
+
/**
|
|
4192
|
+
* Tests if a path matches at least one pattern from an array of globs,
|
|
4193
|
+
* enabling flexible multi-pattern file filtering.
|
|
4194
|
+
* Uses safe character-by-character matching to prevent ReDoS attacks.
|
|
4195
|
+
*
|
|
4196
|
+
* @param path - File path to test
|
|
4197
|
+
* @param patterns - Array of glob patterns
|
|
4198
|
+
* @returns True if path matches any pattern
|
|
4199
|
+
*/
|
|
4200
|
+
function matchesPatterns(path, patterns) {
|
|
4201
|
+
return patterns.some((pattern) => matchGlobPattern(path, pattern));
|
|
4202
|
+
}
|
|
4203
|
+
/**
|
|
4204
|
+
* Searches a directory tree for files matching one or more glob patterns,
|
|
4205
|
+
* returning relative or absolute paths based on options.
|
|
4206
|
+
*
|
|
4207
|
+
* @param startPath - Root directory to begin the search
|
|
4208
|
+
* @param patterns - Glob patterns (e.g., '*.ts', '**\/*.json') to filter files
|
|
4209
|
+
* @param options - Configuration for search behavior
|
|
4210
|
+
* @returns List of relative file paths that match the patterns
|
|
4211
|
+
*
|
|
4212
|
+
* @example
|
|
4213
|
+
* ```typescript
|
|
4214
|
+
* import { findFiles } from '@hyperfrontend/project-scope'
|
|
4215
|
+
*
|
|
4216
|
+
* // Find all TypeScript files
|
|
4217
|
+
* const tsFiles = findFiles('./src', '\*\*\/*.ts')
|
|
4218
|
+
*
|
|
4219
|
+
* // Find multiple file types
|
|
4220
|
+
* const configFiles = findFiles('./', ['\*.json', '\*.yaml', '\*.yml'])
|
|
4221
|
+
*
|
|
4222
|
+
* // Limit results and get absolute paths
|
|
4223
|
+
* const first10 = findFiles('./src', '\*\*\/*.ts', {
|
|
4224
|
+
* maxResults: 10,
|
|
4225
|
+
* absolutePaths: true
|
|
4226
|
+
* })
|
|
4227
|
+
* ```
|
|
4228
|
+
*/
|
|
4229
|
+
function findFiles(startPath, patterns, options) {
|
|
4230
|
+
const normalizedPatterns = isArray(patterns) ? patterns : [patterns];
|
|
4231
|
+
searchLogger.debug('Finding files', { startPath, patterns: normalizedPatterns, maxResults: options?.maxResults });
|
|
4232
|
+
const results = [];
|
|
4233
|
+
const maxResults = options?.maxResults ?? Infinity;
|
|
4234
|
+
walkDirectory(startPath, (entry) => {
|
|
4235
|
+
if (results.length >= maxResults) {
|
|
4236
|
+
return 'stop';
|
|
4237
|
+
}
|
|
4238
|
+
if (!entry.isFile) {
|
|
4239
|
+
return undefined;
|
|
4240
|
+
}
|
|
4241
|
+
if (matchesPatterns(entry.relativePath, normalizedPatterns)) {
|
|
4242
|
+
results.push(options?.absolutePaths ? entry.path : entry.relativePath);
|
|
4243
|
+
}
|
|
4244
|
+
return undefined;
|
|
4245
|
+
}, options);
|
|
4246
|
+
searchLogger.debug('File search complete', { startPath, matchCount: results.length });
|
|
4247
|
+
return results;
|
|
4248
|
+
}
|
|
4249
|
+
|
|
4250
|
+
const entryPointLogger = createScopedLogger('project-scope:heuristics:entry-points');
|
|
4251
|
+
/**
|
|
4252
|
+
* Cache for entry point discovery results.
|
|
4253
|
+
* TTL: 60 seconds (entry points are relatively stable)
|
|
4254
|
+
*/
|
|
4255
|
+
const entryPointCache = createCache({ ttl: 60000, maxSize: 50 });
|
|
4256
|
+
/**
|
|
4257
|
+
* Common entry point patterns.
|
|
4258
|
+
*/
|
|
4259
|
+
const ENTRY_POINT_PATTERNS = {
|
|
4260
|
+
/** Library entry patterns */
|
|
4261
|
+
library: ['src/index.ts', 'src/index.js', 'index.ts', 'index.js', 'lib/index.ts'],
|
|
4262
|
+
/** Application entry patterns */
|
|
4263
|
+
application: ['src/main.ts', 'src/main.tsx', 'main.ts', 'src/app.ts', 'app.ts'],
|
|
4264
|
+
/** Server entry patterns */
|
|
4265
|
+
server: ['src/server.ts', 'server.ts', 'src/main.ts'],
|
|
4266
|
+
/** CLI entry patterns */
|
|
4267
|
+
cli: ['src/cli.ts', 'bin/cli.ts', 'cli.ts'],
|
|
4268
|
+
};
|
|
4269
|
+
/**
|
|
4270
|
+
* Convention-based entry patterns with types and confidence.
|
|
4271
|
+
*/
|
|
4272
|
+
const CONVENTION_ENTRIES = [
|
|
4273
|
+
{ pattern: 'src/index.ts', type: 'main', confidence: 90 },
|
|
4274
|
+
{ pattern: 'src/index.js', type: 'main', confidence: 90 },
|
|
4275
|
+
{ pattern: 'src/main.ts', type: 'app', confidence: 85 },
|
|
4276
|
+
{ pattern: 'src/main.tsx', type: 'app', confidence: 85 },
|
|
4277
|
+
{ pattern: 'src/app.ts', type: 'app', confidence: 80 },
|
|
4278
|
+
{ pattern: 'src/app.tsx', type: 'app', confidence: 80 },
|
|
4279
|
+
{ pattern: 'src/server.ts', type: 'server', confidence: 85 },
|
|
4280
|
+
{ pattern: 'src/server.js', type: 'server', confidence: 85 },
|
|
4281
|
+
{ pattern: 'server.ts', type: 'server', confidence: 80 },
|
|
4282
|
+
{ pattern: 'server.js', type: 'server', confidence: 80 },
|
|
4283
|
+
{ pattern: 'index.ts', type: 'main', confidence: 85 },
|
|
4284
|
+
{ pattern: 'index.js', type: 'main', confidence: 85 },
|
|
4285
|
+
{ pattern: 'lib/index.ts', type: 'main', confidence: 80 },
|
|
4286
|
+
{ pattern: 'lib/index.js', type: 'main', confidence: 80 },
|
|
4287
|
+
{ pattern: 'src/cli.ts', type: 'cli', confidence: 85 },
|
|
4288
|
+
{ pattern: 'bin/cli.ts', type: 'cli', confidence: 85 },
|
|
4289
|
+
{ pattern: 'cli.ts', type: 'cli', confidence: 80 },
|
|
4290
|
+
];
|
|
4291
|
+
/**
|
|
4292
|
+
* Extract entry points from exports field.
|
|
4293
|
+
*
|
|
4294
|
+
* @param exports - The exports field from package.json
|
|
4295
|
+
* @param entryPoints - Array to add entry points to
|
|
4296
|
+
*/
|
|
4297
|
+
function discoverFromExports(exports$1, entryPoints) {
|
|
4298
|
+
for (const [key, value] of entries(exports$1)) {
|
|
4299
|
+
if (typeof value === 'string') {
|
|
4300
|
+
if (!entryPoints.some((e) => e.path === value)) {
|
|
4301
|
+
entryPoints.push({
|
|
4302
|
+
path: value,
|
|
4303
|
+
type: 'main',
|
|
4304
|
+
confidence: 100,
|
|
4305
|
+
source: { type: 'package.json', field: `exports["${key}"]` },
|
|
4306
|
+
});
|
|
4307
|
+
}
|
|
4308
|
+
}
|
|
4309
|
+
else if (typeof value === 'object' && value !== null) {
|
|
4310
|
+
const conditions = value;
|
|
4311
|
+
const paths = [conditions['import'], conditions['require'], conditions['default'], conditions['types']].filter((p) => typeof p === 'string');
|
|
4312
|
+
if (paths.length > 0) {
|
|
4313
|
+
const mainPath = paths[0];
|
|
4314
|
+
if (!entryPoints.some((e) => e.path === mainPath)) {
|
|
4315
|
+
entryPoints.push({
|
|
4316
|
+
path: mainPath,
|
|
4317
|
+
type: 'main',
|
|
4318
|
+
confidence: 100,
|
|
4319
|
+
source: { type: 'package.json', field: `exports["${key}"]` },
|
|
4320
|
+
});
|
|
4321
|
+
}
|
|
4322
|
+
}
|
|
4323
|
+
}
|
|
4324
|
+
}
|
|
4325
|
+
}
|
|
4326
|
+
/**
|
|
4327
|
+
* Discover entry points in project.
|
|
4328
|
+
*
|
|
4329
|
+
* Analyzes package.json fields (main, module, bin, exports),
|
|
4330
|
+
* convention-based patterns, and framework-specific entries.
|
|
4331
|
+
*
|
|
4332
|
+
* Results are cached for 60 seconds per project path and options
|
|
4333
|
+
* to avoid redundant file system operations on repeated calls.
|
|
4334
|
+
*
|
|
4335
|
+
* @param projectPath - Project directory path
|
|
4336
|
+
* @param options - Discovery options
|
|
4337
|
+
* @returns Array of discovered entry points sorted by confidence
|
|
4338
|
+
*
|
|
4339
|
+
* @example
|
|
4340
|
+
* ```typescript
|
|
4341
|
+
* import { discoverEntryPoints } from '@hyperfrontend/project-scope'
|
|
4342
|
+
*
|
|
4343
|
+
* const entryPoints = discoverEntryPoints('./my-app')
|
|
4344
|
+
* for (const entry of entryPoints) {
|
|
4345
|
+
* console.log(`${entry.path} (${entry.type}) - ${entry.confidence}% confidence`)
|
|
4346
|
+
* }
|
|
4347
|
+
* // Output:
|
|
4348
|
+
* // src/index.ts (main) - 100% confidence
|
|
4349
|
+
* // src/cli.ts (cli) - 85% confidence
|
|
4350
|
+
* ```
|
|
4351
|
+
*/
|
|
4352
|
+
function discoverEntryPoints(projectPath, options) {
|
|
4353
|
+
entryPointLogger.debug('Discovering entry points', { projectPath, options });
|
|
4354
|
+
const includeFramework = options?.includeFrameworkEntries !== false;
|
|
4355
|
+
const maxDepth = options?.maxDepth ?? 5;
|
|
4356
|
+
const cacheKey = `${projectPath}:${includeFramework}:${maxDepth}`;
|
|
4357
|
+
if (!options?.skipCache) {
|
|
4358
|
+
const cached = entryPointCache.get(cacheKey);
|
|
4359
|
+
if (cached) {
|
|
4360
|
+
entryPointLogger.debug('Returning cached entry points', { projectPath });
|
|
4361
|
+
return cached;
|
|
4362
|
+
}
|
|
4363
|
+
}
|
|
4364
|
+
const extendedEntryPoints = [];
|
|
4365
|
+
const packageJson = readPackageJsonIfExists(projectPath);
|
|
4366
|
+
if (packageJson) {
|
|
4367
|
+
entryPointLogger.debug('Reading entry points from package.json');
|
|
4368
|
+
if (packageJson.main && typeof packageJson.main === 'string') {
|
|
4369
|
+
extendedEntryPoints.push({
|
|
4370
|
+
path: packageJson.main,
|
|
4371
|
+
type: 'main',
|
|
4372
|
+
confidence: 100,
|
|
4373
|
+
source: { type: 'package.json', field: 'main' },
|
|
4374
|
+
});
|
|
4375
|
+
}
|
|
4376
|
+
if (packageJson.module && typeof packageJson.module === 'string') {
|
|
4377
|
+
if (!extendedEntryPoints.some((e) => e.path === packageJson.module)) {
|
|
4378
|
+
extendedEntryPoints.push({
|
|
4379
|
+
path: packageJson.module,
|
|
4380
|
+
type: 'main',
|
|
4381
|
+
confidence: 100,
|
|
4382
|
+
source: { type: 'package.json', field: 'module' },
|
|
4383
|
+
});
|
|
4384
|
+
}
|
|
4385
|
+
}
|
|
4386
|
+
if (packageJson.browser && typeof packageJson.browser === 'string') {
|
|
4387
|
+
if (!extendedEntryPoints.some((e) => e.path === packageJson.browser)) {
|
|
4388
|
+
extendedEntryPoints.push({
|
|
4389
|
+
path: packageJson.browser,
|
|
4390
|
+
type: 'main',
|
|
4391
|
+
confidence: 95,
|
|
4392
|
+
source: { type: 'package.json', field: 'browser' },
|
|
4393
|
+
});
|
|
4394
|
+
}
|
|
4395
|
+
}
|
|
4396
|
+
if (packageJson.bin) {
|
|
4397
|
+
const bins = typeof packageJson.bin === 'string' ? { [packageJson.name ?? 'cli']: packageJson.bin } : packageJson.bin;
|
|
4398
|
+
for (const [name, path] of entries(bins)) {
|
|
4399
|
+
if (typeof path === 'string' && !extendedEntryPoints.some((e) => e.path === path)) {
|
|
4400
|
+
extendedEntryPoints.push({
|
|
4401
|
+
path,
|
|
4402
|
+
type: 'cli',
|
|
4403
|
+
confidence: 100,
|
|
4404
|
+
source: { type: 'package.json', field: `bin.${name}` },
|
|
4405
|
+
});
|
|
4406
|
+
}
|
|
4407
|
+
}
|
|
4408
|
+
}
|
|
4409
|
+
if (packageJson.exports && typeof packageJson.exports === 'object') {
|
|
4410
|
+
discoverFromExports(packageJson.exports, extendedEntryPoints);
|
|
4411
|
+
}
|
|
4412
|
+
}
|
|
4413
|
+
for (const entry of CONVENTION_ENTRIES) {
|
|
4414
|
+
const fullPath = join$1(projectPath, entry.pattern);
|
|
4415
|
+
if (exists(fullPath)) {
|
|
4416
|
+
if (!extendedEntryPoints.some((e) => e.path === entry.pattern)) {
|
|
4417
|
+
extendedEntryPoints.push({
|
|
4418
|
+
path: entry.pattern,
|
|
4419
|
+
type: entry.type,
|
|
4420
|
+
confidence: entry.confidence,
|
|
4421
|
+
source: { type: 'convention', pattern: entry.pattern },
|
|
4422
|
+
});
|
|
4423
|
+
}
|
|
4424
|
+
}
|
|
4425
|
+
}
|
|
4426
|
+
if (options?.includeFrameworkEntries !== false) {
|
|
4427
|
+
const hasNextPages = exists(join$1(projectPath, 'pages')) || exists(join$1(projectPath, 'src', 'pages'));
|
|
4428
|
+
const hasNextApp = exists(join$1(projectPath, 'app')) || exists(join$1(projectPath, 'src', 'app'));
|
|
4429
|
+
if (hasNextPages || hasNextApp) {
|
|
4430
|
+
const pagesDir = exists(join$1(projectPath, 'pages')) ? 'pages' : 'src/pages';
|
|
4431
|
+
const appDir = exists(join$1(projectPath, 'app')) ? 'app' : 'src/app';
|
|
4432
|
+
if (hasNextPages) {
|
|
4433
|
+
const pageFiles = findFiles(projectPath, `${pagesDir}/**/*.{ts,tsx,js,jsx}`, {
|
|
4434
|
+
maxDepth: options?.maxDepth ?? 5,
|
|
4435
|
+
});
|
|
4436
|
+
for (const file of pageFiles.slice(0, 10)) {
|
|
4437
|
+
if (!file.includes('_app') && !file.includes('_document') && !file.includes('api/')) {
|
|
4438
|
+
extendedEntryPoints.push({
|
|
4439
|
+
path: file,
|
|
4440
|
+
type: 'app',
|
|
4441
|
+
confidence: 80,
|
|
4442
|
+
source: { type: 'framework', framework: 'nextjs' },
|
|
4443
|
+
});
|
|
4444
|
+
}
|
|
4445
|
+
}
|
|
4446
|
+
}
|
|
4447
|
+
if (hasNextApp) {
|
|
4448
|
+
const appFiles = findFiles(projectPath, `${appDir}/**/page.{ts,tsx,js,jsx}`, {
|
|
4449
|
+
maxDepth: options?.maxDepth ?? 5,
|
|
4450
|
+
});
|
|
4451
|
+
for (const file of appFiles.slice(0, 10)) {
|
|
4452
|
+
extendedEntryPoints.push({
|
|
4453
|
+
path: file,
|
|
4454
|
+
type: 'app',
|
|
4455
|
+
confidence: 80,
|
|
4456
|
+
source: { type: 'framework', framework: 'nextjs' },
|
|
4457
|
+
});
|
|
4458
|
+
}
|
|
4459
|
+
}
|
|
4460
|
+
}
|
|
4461
|
+
const angularMain = join$1(projectPath, 'src', 'main.ts');
|
|
4462
|
+
if (exists(angularMain) && exists(join$1(projectPath, 'angular.json'))) {
|
|
4463
|
+
if (!extendedEntryPoints.some((e) => e.path === 'src/main.ts' && e.source.type === 'framework')) {
|
|
4464
|
+
extendedEntryPoints.push({
|
|
4465
|
+
path: 'src/main.ts',
|
|
4466
|
+
type: 'app',
|
|
4467
|
+
confidence: 95,
|
|
4468
|
+
source: { type: 'framework', framework: 'angular' },
|
|
4469
|
+
});
|
|
4470
|
+
}
|
|
4471
|
+
}
|
|
4472
|
+
const hasSvelteRoutes = exists(join$1(projectPath, 'src', 'routes'));
|
|
4473
|
+
if (hasSvelteRoutes && exists(join$1(projectPath, 'svelte.config.js'))) {
|
|
4474
|
+
const routeFiles = findFiles(projectPath, 'src/routes/**/+page.svelte', {
|
|
4475
|
+
maxDepth: options?.maxDepth ?? 5,
|
|
4476
|
+
});
|
|
4477
|
+
for (const file of routeFiles.slice(0, 10)) {
|
|
4478
|
+
extendedEntryPoints.push({
|
|
4479
|
+
path: file,
|
|
4480
|
+
type: 'app',
|
|
4481
|
+
confidence: 80,
|
|
4482
|
+
source: { type: 'framework', framework: 'sveltekit' },
|
|
4483
|
+
});
|
|
4484
|
+
}
|
|
4485
|
+
}
|
|
4486
|
+
}
|
|
4487
|
+
extendedEntryPoints.sort((a, b) => b.confidence - a.confidence);
|
|
4488
|
+
entryPointLogger.debug('Entry point discovery complete', {
|
|
4489
|
+
projectPath,
|
|
4490
|
+
totalFound: extendedEntryPoints.length,
|
|
4491
|
+
bySource: {
|
|
4492
|
+
packageJson: extendedEntryPoints.filter((e) => e.source.type === 'package.json').length,
|
|
4493
|
+
convention: extendedEntryPoints.filter((e) => e.source.type === 'convention').length,
|
|
4494
|
+
framework: extendedEntryPoints.filter((e) => e.source.type === 'framework').length,
|
|
4495
|
+
},
|
|
4496
|
+
});
|
|
4497
|
+
const result = extendedEntryPoints.map((e) => ({
|
|
4498
|
+
path: e.path,
|
|
4499
|
+
type: e.type,
|
|
4500
|
+
confidence: e.confidence,
|
|
4501
|
+
}));
|
|
4502
|
+
entryPointCache.set(cacheKey, result);
|
|
4503
|
+
return result;
|
|
4504
|
+
}
|
|
4505
|
+
/**
|
|
4506
|
+
* Clear the entry point discovery cache.
|
|
4507
|
+
*
|
|
4508
|
+
* Useful for testing or when the project files have changed.
|
|
4509
|
+
*/
|
|
4510
|
+
function clearEntryPointCache() {
|
|
4511
|
+
entryPointCache.clear();
|
|
4512
|
+
}
|
|
4513
|
+
|
|
4514
|
+
const depsLogger = createScopedLogger('project-scope:heuristics:deps');
|
|
4515
|
+
/**
|
|
4516
|
+
* Extract import/require statements from source code.
|
|
4517
|
+
*
|
|
4518
|
+
* @param content - File content
|
|
4519
|
+
* @returns Array of imported module paths
|
|
4520
|
+
*/
|
|
4521
|
+
function extractImports(content) {
|
|
4522
|
+
const imports = [];
|
|
4523
|
+
// ES import with 'from': import X from 'path' or import { X } from 'path'
|
|
4524
|
+
// Use non-greedy match and avoid nested quantifiers by matching "from" keyword directly
|
|
4525
|
+
const esImportFromRegex = /import\s+.+?\s+from\s+['"]([^'"]+)['"]/g;
|
|
4526
|
+
let match;
|
|
4527
|
+
while ((match = esImportFromRegex.exec(content)) !== null) {
|
|
4528
|
+
imports.push(match[1]);
|
|
4529
|
+
}
|
|
4530
|
+
// Side-effect import: import 'path'
|
|
4531
|
+
const sideEffectImportRegex = /import\s+['"]([^'"]+)['"]/g;
|
|
4532
|
+
while ((match = sideEffectImportRegex.exec(content)) !== null) {
|
|
4533
|
+
imports.push(match[1]);
|
|
4534
|
+
}
|
|
4535
|
+
// Dynamic import: import('path')
|
|
4536
|
+
const dynamicImportRegex = /import\s*\(\s*['"]([^'"]+)['"]\s*\)/g;
|
|
4537
|
+
while ((match = dynamicImportRegex.exec(content)) !== null) {
|
|
4538
|
+
imports.push(match[1]);
|
|
4539
|
+
}
|
|
4540
|
+
// require: require('path')
|
|
4541
|
+
const requireRegex = /require\s*\(\s*['"]([^'"]+)['"]\s*\)/g;
|
|
4542
|
+
while ((match = requireRegex.exec(content)) !== null) {
|
|
4543
|
+
imports.push(match[1]);
|
|
4544
|
+
}
|
|
4545
|
+
// Re-export: export * from 'path' or export { X } from 'path'
|
|
4546
|
+
const exportFromRegex = /export\s+.+?\s+from\s+['"]([^'"]+)['"]/g;
|
|
4547
|
+
while ((match = exportFromRegex.exec(content)) !== null) {
|
|
4548
|
+
imports.push(match[1]);
|
|
4549
|
+
}
|
|
4550
|
+
return imports;
|
|
4551
|
+
}
|
|
4552
|
+
/**
|
|
4553
|
+
* Resolve import path to actual file path.
|
|
4554
|
+
*
|
|
4555
|
+
* @param importPath - Import specifier from source code
|
|
4556
|
+
* @param fromFile - Absolute path of file containing the import
|
|
4557
|
+
* @param projectPath - Project root directory
|
|
4558
|
+
* @param extensions - File extensions to check when resolving
|
|
4559
|
+
* @returns Resolved relative path or null if external/not found
|
|
4560
|
+
*/
|
|
4561
|
+
function resolveImportPath(importPath, fromFile, projectPath, extensions) {
|
|
4562
|
+
if (!importPath.startsWith('.') && !importPath.startsWith('/')) {
|
|
4563
|
+
return null;
|
|
4564
|
+
}
|
|
4565
|
+
const fromDir = dirname(fromFile);
|
|
4566
|
+
const absolutePath = resolve(fromDir, importPath);
|
|
4567
|
+
if (exists(absolutePath)) {
|
|
4568
|
+
if (isFile(absolutePath)) {
|
|
4569
|
+
return relative(projectPath, absolutePath);
|
|
4570
|
+
}
|
|
4571
|
+
if (isDirectory(absolutePath)) {
|
|
4572
|
+
for (const ext of extensions) {
|
|
4573
|
+
const indexPath = join$1(absolutePath, `index${ext}`);
|
|
4574
|
+
if (exists(indexPath) && isFile(indexPath)) {
|
|
4575
|
+
return relative(projectPath, indexPath);
|
|
4576
|
+
}
|
|
4577
|
+
}
|
|
4578
|
+
}
|
|
4579
|
+
}
|
|
4580
|
+
for (const ext of extensions) {
|
|
4581
|
+
const pathWithExt = absolutePath + ext;
|
|
4582
|
+
if (exists(pathWithExt) && isFile(pathWithExt)) {
|
|
4583
|
+
return relative(projectPath, pathWithExt);
|
|
4584
|
+
}
|
|
4585
|
+
}
|
|
4586
|
+
return null;
|
|
4587
|
+
}
|
|
4588
|
+
/**
|
|
4589
|
+
* Collect source files from directory.
|
|
4590
|
+
*
|
|
4591
|
+
* @param dir - Absolute path of directory to scan
|
|
4592
|
+
* @param extensions - File extensions to include (e.g., '.ts')
|
|
4593
|
+
* @param maxDepth - Maximum recursion depth for subdirectories
|
|
4594
|
+
* @param currentDepth - Current recursion depth (internal use)
|
|
4595
|
+
* @returns Array of absolute file paths
|
|
4596
|
+
*/
|
|
4597
|
+
function collectSourceFiles(dir, extensions, maxDepth, currentDepth = 0) {
|
|
4598
|
+
if (currentDepth > maxDepth)
|
|
4599
|
+
return [];
|
|
4600
|
+
const files = [];
|
|
4601
|
+
try {
|
|
4602
|
+
const entries = readDirectory(dir);
|
|
4603
|
+
for (const entry of entries) {
|
|
4604
|
+
const fullPath = join$1(dir, entry.name);
|
|
4605
|
+
if (entry.name.startsWith('.') || entry.name === 'node_modules' || entry.name === 'dist') {
|
|
4606
|
+
continue;
|
|
4607
|
+
}
|
|
4608
|
+
if (entry.isDirectory) {
|
|
4609
|
+
files.push(...collectSourceFiles(fullPath, extensions, maxDepth, currentDepth + 1));
|
|
4610
|
+
}
|
|
4611
|
+
else if (entry.isFile) {
|
|
4612
|
+
const hasValidExt = extensions.some((ext) => entry.name.endsWith(ext));
|
|
4613
|
+
if (hasValidExt) {
|
|
4614
|
+
files.push(fullPath);
|
|
4615
|
+
}
|
|
4616
|
+
}
|
|
4617
|
+
}
|
|
4618
|
+
}
|
|
4619
|
+
catch {
|
|
4620
|
+
// Directory not readable
|
|
4621
|
+
}
|
|
4622
|
+
return files;
|
|
4623
|
+
}
|
|
4624
|
+
/**
|
|
4625
|
+
* Build dependency graph from source files.
|
|
4626
|
+
*
|
|
4627
|
+
* Analyzes imports/exports in source files to build a graph of
|
|
4628
|
+
* internal dependencies.
|
|
4629
|
+
*
|
|
4630
|
+
* @param projectPath - Absolute path to project root
|
|
4631
|
+
* @param options - Configuration for graph building
|
|
4632
|
+
* @returns Dependency graph with nodes, roots, and leaves
|
|
4633
|
+
*
|
|
4634
|
+
* @example
|
|
4635
|
+
* ```typescript
|
|
4636
|
+
* import { buildDependencyGraph } from '@hyperfrontend/project-scope'
|
|
4637
|
+
*
|
|
4638
|
+
* const graph = buildDependencyGraph('./my-lib')
|
|
4639
|
+
* console.log('Root files:', graph.roots) // Files not imported by anything
|
|
4640
|
+
* console.log('Leaf files:', graph.leaves) // Files that don't import anything
|
|
4641
|
+
* console.log('Total nodes:', graph.nodes.size)
|
|
4642
|
+
*
|
|
4643
|
+
* // Examine a specific node's dependencies
|
|
4644
|
+
* const node = graph.nodes.get('src/utils/helper.ts')
|
|
4645
|
+
* console.log('Depends on:', node?.dependencies)
|
|
4646
|
+
* console.log('Used by:', node?.dependents)
|
|
4647
|
+
* ```
|
|
4648
|
+
*/
|
|
4649
|
+
function buildDependencyGraph(projectPath, options) {
|
|
4650
|
+
const extensions = options?.extensions ?? ['.ts', '.tsx', '.js', '.jsx'];
|
|
4651
|
+
const maxDepth = options?.maxDepth ?? 10;
|
|
4652
|
+
const includeExternal = options?.includeExternal ?? false;
|
|
4653
|
+
depsLogger.debug('Building dependency graph', { projectPath, extensions, maxDepth, includeExternal });
|
|
4654
|
+
const nodes = createMap();
|
|
4655
|
+
const incomingEdges = createMap();
|
|
4656
|
+
const srcDir = join$1(projectPath, 'src');
|
|
4657
|
+
let sourceFiles;
|
|
4658
|
+
if (exists(srcDir) && isDirectory(srcDir)) {
|
|
4659
|
+
sourceFiles = collectSourceFiles(srcDir, extensions, maxDepth);
|
|
4660
|
+
depsLogger.debug('Collected source files from src directory', { count: sourceFiles.length });
|
|
4661
|
+
}
|
|
4662
|
+
else {
|
|
4663
|
+
sourceFiles = collectSourceFiles(projectPath, extensions, maxDepth);
|
|
4664
|
+
depsLogger.debug('Collected source files from project root', { count: sourceFiles.length });
|
|
4665
|
+
}
|
|
4666
|
+
for (const file of sourceFiles) {
|
|
4667
|
+
const relativePath = relative(projectPath, file);
|
|
4668
|
+
nodes.set(relativePath, {
|
|
4669
|
+
id: relativePath,
|
|
4670
|
+
path: relativePath,
|
|
4671
|
+
dependencies: [],
|
|
4672
|
+
dependents: [],
|
|
4673
|
+
});
|
|
4674
|
+
incomingEdges.set(relativePath, createSet());
|
|
4675
|
+
}
|
|
4676
|
+
for (const file of sourceFiles) {
|
|
4677
|
+
const relativePath = relative(projectPath, file);
|
|
4678
|
+
const node = nodes.get(relativePath);
|
|
4679
|
+
if (!node)
|
|
4680
|
+
continue;
|
|
4681
|
+
try {
|
|
4682
|
+
const content = readFileContent(file);
|
|
4683
|
+
const imports = extractImports(content);
|
|
4684
|
+
for (const importPath of imports) {
|
|
4685
|
+
const resolved = resolveImportPath(importPath, file, projectPath, extensions);
|
|
4686
|
+
if (resolved && nodes.has(resolved)) {
|
|
4687
|
+
if (!node.dependencies.includes(resolved)) {
|
|
4688
|
+
node.dependencies.push(resolved);
|
|
4689
|
+
}
|
|
4690
|
+
const incoming = incomingEdges.get(resolved);
|
|
4691
|
+
if (incoming) {
|
|
4692
|
+
incoming.add(relativePath);
|
|
4693
|
+
}
|
|
4694
|
+
const dependentNode = nodes.get(resolved);
|
|
4695
|
+
if (dependentNode && !dependentNode.dependents.includes(relativePath)) {
|
|
4696
|
+
dependentNode.dependents.push(relativePath);
|
|
4697
|
+
}
|
|
4698
|
+
}
|
|
4699
|
+
else if (includeExternal && !importPath.startsWith('.')) {
|
|
4700
|
+
if (!node.dependencies.includes(importPath)) {
|
|
4701
|
+
node.dependencies.push(importPath);
|
|
4702
|
+
}
|
|
4703
|
+
}
|
|
4704
|
+
}
|
|
4705
|
+
}
|
|
4706
|
+
catch {
|
|
4707
|
+
// File not readable
|
|
4708
|
+
}
|
|
4709
|
+
}
|
|
4710
|
+
const roots = [];
|
|
4711
|
+
for (const [path, incoming] of incomingEdges) {
|
|
4712
|
+
if (incoming.size === 0) {
|
|
4713
|
+
roots.push(path);
|
|
4714
|
+
}
|
|
4715
|
+
}
|
|
4716
|
+
const leaves = [];
|
|
4717
|
+
for (const [path, node] of nodes) {
|
|
4718
|
+
const hasInternalDeps = node.dependencies.some((dep) => nodes.has(dep));
|
|
4719
|
+
if (!hasInternalDeps) {
|
|
4720
|
+
leaves.push(path);
|
|
4721
|
+
}
|
|
4722
|
+
}
|
|
4723
|
+
depsLogger.debug('Dependency graph built', {
|
|
4724
|
+
nodeCount: nodes.size,
|
|
4725
|
+
rootCount: roots.length,
|
|
4726
|
+
leafCount: leaves.length,
|
|
4727
|
+
});
|
|
4728
|
+
return { nodes, roots, leaves };
|
|
4729
|
+
}
|
|
4730
|
+
/**
|
|
4731
|
+
* Find circular dependencies in graph using DFS.
|
|
4732
|
+
*
|
|
4733
|
+
* @param graph - Dependency graph
|
|
4734
|
+
* @returns Array of circular dependencies found
|
|
4735
|
+
*/
|
|
4736
|
+
function findCircularDependencies(graph) {
|
|
4737
|
+
depsLogger.debug('Searching for circular dependencies', { nodeCount: graph.nodes.size });
|
|
4738
|
+
const cycles = [];
|
|
4739
|
+
const visited = createSet();
|
|
4740
|
+
const recursionStack = createSet();
|
|
4741
|
+
const path = [];
|
|
4742
|
+
/**
|
|
4743
|
+
* Depth-first search to detect cycles.
|
|
4744
|
+
*
|
|
4745
|
+
* @param nodeId - Current node being visited
|
|
4746
|
+
*/
|
|
4747
|
+
function dfs(nodeId) {
|
|
4748
|
+
if (recursionStack.has(nodeId)) {
|
|
4749
|
+
const cycleStart = path.indexOf(nodeId);
|
|
4750
|
+
if (cycleStart !== -1) {
|
|
4751
|
+
const cycle = path.slice(cycleStart);
|
|
4752
|
+
cycle.push(nodeId);
|
|
4753
|
+
const normalized = [...cycle].sort().join('|');
|
|
4754
|
+
const isDuplicate = cycles.some((c) => [...c.cycle].sort().join('|') === normalized);
|
|
4755
|
+
if (!isDuplicate) {
|
|
4756
|
+
depsLogger.debug('Found circular dependency', { cycleLength: cycle.length - 1, cycle });
|
|
4757
|
+
cycles.push({
|
|
4758
|
+
cycle,
|
|
4759
|
+
length: cycle.length - 1,
|
|
4760
|
+
});
|
|
4761
|
+
}
|
|
4762
|
+
}
|
|
4763
|
+
return;
|
|
4764
|
+
}
|
|
4765
|
+
if (visited.has(nodeId)) {
|
|
4766
|
+
return;
|
|
4767
|
+
}
|
|
4768
|
+
const node = graph.nodes.get(nodeId);
|
|
4769
|
+
if (!node)
|
|
4770
|
+
return;
|
|
4771
|
+
visited.add(nodeId);
|
|
4772
|
+
recursionStack.add(nodeId);
|
|
4773
|
+
path.push(nodeId);
|
|
4774
|
+
for (const dep of node.dependencies) {
|
|
4775
|
+
if (graph.nodes.has(dep)) {
|
|
4776
|
+
dfs(dep);
|
|
4777
|
+
}
|
|
4778
|
+
}
|
|
4779
|
+
path.pop();
|
|
4780
|
+
recursionStack.delete(nodeId);
|
|
4781
|
+
}
|
|
4782
|
+
for (const nodeId of graph.nodes.keys()) {
|
|
4783
|
+
if (!visited.has(nodeId)) {
|
|
4784
|
+
dfs(nodeId);
|
|
4785
|
+
}
|
|
4786
|
+
}
|
|
4787
|
+
depsLogger.debug('Circular dependency search complete', { cyclesFound: cycles.length });
|
|
4788
|
+
return cycles;
|
|
4789
|
+
}
|
|
4790
|
+
/**
|
|
4791
|
+
* Collect all dependencies from package.json grouped by category.
|
|
4792
|
+
*
|
|
4793
|
+
* @param projectPath - Project directory
|
|
4794
|
+
* @returns Dependencies grouped by runtime, dev, peer, and optional
|
|
4795
|
+
*/
|
|
4796
|
+
function getProjectDependencies(projectPath) {
|
|
4797
|
+
const packageJson = readPackageJsonIfExists(projectPath);
|
|
4798
|
+
if (!packageJson) {
|
|
4799
|
+
return {
|
|
4800
|
+
runtime: [],
|
|
4801
|
+
development: [],
|
|
4802
|
+
peer: [],
|
|
4803
|
+
optional: [],
|
|
4804
|
+
total: 0,
|
|
4805
|
+
};
|
|
4806
|
+
}
|
|
4807
|
+
const runtime = packageJson.dependencies ? keys(packageJson.dependencies) : [];
|
|
4808
|
+
const development = packageJson.devDependencies ? keys(packageJson.devDependencies) : [];
|
|
4809
|
+
const peer = packageJson.peerDependencies ? keys(packageJson.peerDependencies) : [];
|
|
4810
|
+
const optional = packageJson.optionalDependencies ? keys(packageJson.optionalDependencies) : [];
|
|
4811
|
+
const allDeps = createSet([...runtime, ...development, ...peer, ...optional]);
|
|
4812
|
+
return {
|
|
4813
|
+
runtime,
|
|
4814
|
+
development,
|
|
4815
|
+
peer,
|
|
4816
|
+
optional,
|
|
4817
|
+
total: allDeps.size,
|
|
4818
|
+
};
|
|
4819
|
+
}
|
|
4820
|
+
|
|
4821
|
+
export { ENTRY_POINT_PATTERNS, buildDependencyGraph, clearEntryPointCache, clearFrameworkIdentificationCache, detectProjectType, discoverEntryPoints, findCircularDependencies, getProjectDependencies, identifyFrameworks, usesFramework };
|
|
4822
|
+
//# sourceMappingURL=index.esm.js.map
|