@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,1310 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var node_path = require('node:path');
|
|
4
|
+
var node_fs = require('node:fs');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Safe copies of Math built-in methods.
|
|
8
|
+
*
|
|
9
|
+
* These references are captured at module initialization time to protect against
|
|
10
|
+
* prototype pollution attacks. Import only what you need for tree-shaking.
|
|
11
|
+
*
|
|
12
|
+
* @module @hyperfrontend/immutable-api-utils/built-in-copy/math
|
|
13
|
+
*/
|
|
14
|
+
// Capture references at module initialization time
|
|
15
|
+
const _Math = globalThis.Math;
|
|
16
|
+
/**
|
|
17
|
+
* (Safe copy) Returns the smaller of zero or more numbers.
|
|
18
|
+
*/
|
|
19
|
+
const min = _Math.min;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Safe copies of Error built-ins via factory functions.
|
|
23
|
+
*
|
|
24
|
+
* Since constructors cannot be safely captured via Object.assign, this module
|
|
25
|
+
* provides factory functions that use Reflect.construct internally.
|
|
26
|
+
*
|
|
27
|
+
* These references are captured at module initialization time to protect against
|
|
28
|
+
* prototype pollution attacks. Import only what you need for tree-shaking.
|
|
29
|
+
*
|
|
30
|
+
* @module @hyperfrontend/immutable-api-utils/built-in-copy/error
|
|
31
|
+
*/
|
|
32
|
+
// Capture references at module initialization time
|
|
33
|
+
const _Error = globalThis.Error;
|
|
34
|
+
const _Reflect$1 = globalThis.Reflect;
|
|
35
|
+
/**
|
|
36
|
+
* (Safe copy) Creates a new Error using the captured Error constructor.
|
|
37
|
+
* Use this instead of `new Error()`.
|
|
38
|
+
*
|
|
39
|
+
* @param message - Optional error message.
|
|
40
|
+
* @param options - Optional error options.
|
|
41
|
+
* @returns A new Error instance.
|
|
42
|
+
*/
|
|
43
|
+
const createError = (message, options) => _Reflect$1.construct(_Error, [message, options]);
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Safe copies of JSON built-in methods.
|
|
47
|
+
*
|
|
48
|
+
* These references are captured at module initialization time to protect against
|
|
49
|
+
* prototype pollution attacks. Import only what you need for tree-shaking.
|
|
50
|
+
*
|
|
51
|
+
* @module @hyperfrontend/immutable-api-utils/built-in-copy/json
|
|
52
|
+
*/
|
|
53
|
+
// Capture references at module initialization time
|
|
54
|
+
const _JSON = globalThis.JSON;
|
|
55
|
+
/**
|
|
56
|
+
* (Safe copy) Converts a JavaScript Object Notation (JSON) string into an object.
|
|
57
|
+
*/
|
|
58
|
+
const parse = _JSON.parse;
|
|
59
|
+
/**
|
|
60
|
+
* (Safe copy) Converts a JavaScript value to a JavaScript Object Notation (JSON) string.
|
|
61
|
+
*/
|
|
62
|
+
const stringify = _JSON.stringify;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Safe copies of Object built-in methods.
|
|
66
|
+
*
|
|
67
|
+
* These references are captured at module initialization time to protect against
|
|
68
|
+
* prototype pollution attacks. Import only what you need for tree-shaking.
|
|
69
|
+
*
|
|
70
|
+
* @module @hyperfrontend/immutable-api-utils/built-in-copy/object
|
|
71
|
+
*/
|
|
72
|
+
// Capture references at module initialization time
|
|
73
|
+
const _Object = globalThis.Object;
|
|
74
|
+
/**
|
|
75
|
+
* (Safe copy) Prevents modification of existing property attributes and values,
|
|
76
|
+
* and prevents the addition of new properties.
|
|
77
|
+
*/
|
|
78
|
+
const freeze = _Object.freeze;
|
|
79
|
+
/**
|
|
80
|
+
* (Safe copy) Returns the names of the enumerable string properties and methods of an object.
|
|
81
|
+
*/
|
|
82
|
+
const keys = _Object.keys;
|
|
83
|
+
/**
|
|
84
|
+
* (Safe copy) Returns an array of key/values of the enumerable own properties of an object.
|
|
85
|
+
*/
|
|
86
|
+
const entries = _Object.entries;
|
|
87
|
+
/**
|
|
88
|
+
* (Safe copy) Returns an array of values of the enumerable own properties of an object.
|
|
89
|
+
*/
|
|
90
|
+
const values = _Object.values;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Safe copies of Array built-in static methods.
|
|
94
|
+
*
|
|
95
|
+
* These references are captured at module initialization time to protect against
|
|
96
|
+
* prototype pollution attacks. Import only what you need for tree-shaking.
|
|
97
|
+
*
|
|
98
|
+
* @module @hyperfrontend/immutable-api-utils/built-in-copy/array
|
|
99
|
+
*/
|
|
100
|
+
// Capture references at module initialization time
|
|
101
|
+
const _Array = globalThis.Array;
|
|
102
|
+
/**
|
|
103
|
+
* (Safe copy) Determines whether the passed value is an Array.
|
|
104
|
+
*/
|
|
105
|
+
const isArray = _Array.isArray;
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Safe copies of Console built-in methods.
|
|
109
|
+
*
|
|
110
|
+
* These references are captured at module initialization time to protect against
|
|
111
|
+
* prototype pollution attacks. Import only what you need for tree-shaking.
|
|
112
|
+
*
|
|
113
|
+
* @module @hyperfrontend/immutable-api-utils/built-in-copy/console
|
|
114
|
+
*/
|
|
115
|
+
// Capture references at module initialization time
|
|
116
|
+
const _console = globalThis.console;
|
|
117
|
+
/**
|
|
118
|
+
* (Safe copy) Outputs a message to the console.
|
|
119
|
+
*/
|
|
120
|
+
const log = _console.log.bind(_console);
|
|
121
|
+
/**
|
|
122
|
+
* (Safe copy) Outputs a warning message to the console.
|
|
123
|
+
*/
|
|
124
|
+
const warn = _console.warn.bind(_console);
|
|
125
|
+
/**
|
|
126
|
+
* (Safe copy) Outputs an error message to the console.
|
|
127
|
+
*/
|
|
128
|
+
const error = _console.error.bind(_console);
|
|
129
|
+
/**
|
|
130
|
+
* (Safe copy) Outputs an informational message to the console.
|
|
131
|
+
*/
|
|
132
|
+
const info = _console.info.bind(_console);
|
|
133
|
+
/**
|
|
134
|
+
* (Safe copy) Outputs a debug message to the console.
|
|
135
|
+
*/
|
|
136
|
+
const debug = _console.debug.bind(_console);
|
|
137
|
+
/**
|
|
138
|
+
* (Safe copy) Outputs a stack trace to the console.
|
|
139
|
+
*/
|
|
140
|
+
_console.trace.bind(_console);
|
|
141
|
+
/**
|
|
142
|
+
* (Safe copy) Displays an interactive listing of the properties of a specified object.
|
|
143
|
+
*/
|
|
144
|
+
_console.dir.bind(_console);
|
|
145
|
+
/**
|
|
146
|
+
* (Safe copy) Displays tabular data as a table.
|
|
147
|
+
*/
|
|
148
|
+
_console.table.bind(_console);
|
|
149
|
+
/**
|
|
150
|
+
* (Safe copy) Writes an error message to the console if the assertion is false.
|
|
151
|
+
*/
|
|
152
|
+
_console.assert.bind(_console);
|
|
153
|
+
/**
|
|
154
|
+
* (Safe copy) Clears the console.
|
|
155
|
+
*/
|
|
156
|
+
_console.clear.bind(_console);
|
|
157
|
+
/**
|
|
158
|
+
* (Safe copy) Logs the number of times that this particular call to count() has been called.
|
|
159
|
+
*/
|
|
160
|
+
_console.count.bind(_console);
|
|
161
|
+
/**
|
|
162
|
+
* (Safe copy) Resets the counter used with console.count().
|
|
163
|
+
*/
|
|
164
|
+
_console.countReset.bind(_console);
|
|
165
|
+
/**
|
|
166
|
+
* (Safe copy) Creates a new inline group in the console.
|
|
167
|
+
*/
|
|
168
|
+
_console.group.bind(_console);
|
|
169
|
+
/**
|
|
170
|
+
* (Safe copy) Creates a new inline group in the console that is initially collapsed.
|
|
171
|
+
*/
|
|
172
|
+
_console.groupCollapsed.bind(_console);
|
|
173
|
+
/**
|
|
174
|
+
* (Safe copy) Exits the current inline group.
|
|
175
|
+
*/
|
|
176
|
+
_console.groupEnd.bind(_console);
|
|
177
|
+
/**
|
|
178
|
+
* (Safe copy) Starts a timer with a name specified as an input parameter.
|
|
179
|
+
*/
|
|
180
|
+
_console.time.bind(_console);
|
|
181
|
+
/**
|
|
182
|
+
* (Safe copy) Stops a timer that was previously started.
|
|
183
|
+
*/
|
|
184
|
+
_console.timeEnd.bind(_console);
|
|
185
|
+
/**
|
|
186
|
+
* (Safe copy) Logs the current value of a timer that was previously started.
|
|
187
|
+
*/
|
|
188
|
+
_console.timeLog.bind(_console);
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Safe copies of Set built-in via factory function.
|
|
192
|
+
*
|
|
193
|
+
* Since constructors cannot be safely captured via Object.assign, this module
|
|
194
|
+
* provides a factory function that uses Reflect.construct internally.
|
|
195
|
+
*
|
|
196
|
+
* These references are captured at module initialization time to protect against
|
|
197
|
+
* prototype pollution attacks. Import only what you need for tree-shaking.
|
|
198
|
+
*
|
|
199
|
+
* @module @hyperfrontend/immutable-api-utils/built-in-copy/set
|
|
200
|
+
*/
|
|
201
|
+
// Capture references at module initialization time
|
|
202
|
+
const _Set = globalThis.Set;
|
|
203
|
+
const _Reflect = globalThis.Reflect;
|
|
204
|
+
/**
|
|
205
|
+
* (Safe copy) Creates a new Set using the captured Set constructor.
|
|
206
|
+
* Use this instead of `new Set()`.
|
|
207
|
+
*
|
|
208
|
+
* @param iterable - Optional iterable of values.
|
|
209
|
+
* @returns A new Set instance.
|
|
210
|
+
*/
|
|
211
|
+
const createSet = (iterable) => _Reflect.construct(_Set, iterable ? [iterable] : []);
|
|
212
|
+
|
|
213
|
+
const registeredClasses = [];
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Returns the data type of the target.
|
|
217
|
+
* Uses native `typeof` operator, however, makes distinction between `null`, `array`, and `object`.
|
|
218
|
+
* Also, when classes are registered via `registerClass`, it checks if objects are instance of any known registered class.
|
|
219
|
+
*
|
|
220
|
+
* @param target - The target to get the data type of.
|
|
221
|
+
* @returns The data type of the target.
|
|
222
|
+
*/
|
|
223
|
+
const getType = (target) => {
|
|
224
|
+
if (target === null)
|
|
225
|
+
return 'null';
|
|
226
|
+
const nativeDataType = typeof target;
|
|
227
|
+
if (nativeDataType === 'object') {
|
|
228
|
+
if (isArray(target))
|
|
229
|
+
return 'array';
|
|
230
|
+
for (const registeredClass of registeredClasses) {
|
|
231
|
+
if (target instanceof registeredClass)
|
|
232
|
+
return registeredClass.name;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
return nativeDataType;
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
239
|
+
/**
|
|
240
|
+
* Creates a wrapper function that only executes the wrapped function if the condition function returns true.
|
|
241
|
+
*
|
|
242
|
+
* @param func - The function to be conditionally executed.
|
|
243
|
+
* @param conditionFunc - A function that returns a boolean, determining if `func` should be executed.
|
|
244
|
+
* @returns A wrapped version of `func` that executes conditionally.
|
|
245
|
+
*/
|
|
246
|
+
function createConditionalExecutionFunction(func, conditionFunc) {
|
|
247
|
+
return function (...args) {
|
|
248
|
+
if (conditionFunc()) {
|
|
249
|
+
return func(...args);
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
255
|
+
/**
|
|
256
|
+
* Creates a wrapper function that silently ignores any errors thrown by the wrapped void function.
|
|
257
|
+
* This function is specifically for wrapping functions that do not return a value (void functions).
|
|
258
|
+
* Exceptions are swallowed without any logging or handling.
|
|
259
|
+
*
|
|
260
|
+
* @param func - The void function to be wrapped.
|
|
261
|
+
* @returns A wrapped version of the input function that ignores errors.
|
|
262
|
+
*/
|
|
263
|
+
function createErrorIgnoringFunction(func) {
|
|
264
|
+
return function (...args) {
|
|
265
|
+
try {
|
|
266
|
+
func(...args);
|
|
267
|
+
}
|
|
268
|
+
catch {
|
|
269
|
+
// Deliberately swallowing/ignoring the exception
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
275
|
+
/**
|
|
276
|
+
* A no-operation function (noop) that does nothing regardless of the arguments passed.
|
|
277
|
+
* It is designed to be as permissive as possible in its typing without using the `Function` keyword.
|
|
278
|
+
*
|
|
279
|
+
* @param args - Any arguments passed to the function (ignored)
|
|
280
|
+
*/
|
|
281
|
+
const noop = (...args) => {
|
|
282
|
+
// Intentionally does nothing
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
const logLevels = ['none', 'error', 'warn', 'log', 'info', 'debug'];
|
|
286
|
+
const priority = {
|
|
287
|
+
error: 4,
|
|
288
|
+
warn: 3,
|
|
289
|
+
log: 2,
|
|
290
|
+
info: 1,
|
|
291
|
+
debug: 0,
|
|
292
|
+
};
|
|
293
|
+
/**
|
|
294
|
+
* Validates whether a given string is a valid log level.
|
|
295
|
+
*
|
|
296
|
+
* @param level - The log level to validate
|
|
297
|
+
* @returns True if the level is valid, false otherwise
|
|
298
|
+
*/
|
|
299
|
+
function isValidLogLevel(level) {
|
|
300
|
+
return logLevels.includes(level);
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Creates a log level configuration manager for controlling logging behavior.
|
|
304
|
+
* Provides methods to get, set, and evaluate log levels based on priority.
|
|
305
|
+
*
|
|
306
|
+
* @param level - The initial log level (defaults to 'error')
|
|
307
|
+
* @returns A configuration object with log level management methods
|
|
308
|
+
* @throws {Error} When the provided level is not a valid log level
|
|
309
|
+
*/
|
|
310
|
+
function createLogLevelConfig(level = 'error') {
|
|
311
|
+
if (!isValidLogLevel(level)) {
|
|
312
|
+
throw createError('Cannot create log level configuration with a valid default log level');
|
|
313
|
+
}
|
|
314
|
+
const state = { level };
|
|
315
|
+
const getLogLevel = () => state.level;
|
|
316
|
+
const setLogLevel = (level) => {
|
|
317
|
+
if (!isValidLogLevel(level)) {
|
|
318
|
+
throw createError(`Cannot set value '${level}' level. Expected levels are ${logLevels}.`);
|
|
319
|
+
}
|
|
320
|
+
state.level = level;
|
|
321
|
+
};
|
|
322
|
+
const shouldLog = (level) => {
|
|
323
|
+
if (state.level === 'none' || level === 'none' || !isValidLogLevel(level)) {
|
|
324
|
+
return false;
|
|
325
|
+
}
|
|
326
|
+
return priority[level] >= priority[state.level];
|
|
327
|
+
};
|
|
328
|
+
return freeze({
|
|
329
|
+
getLogLevel,
|
|
330
|
+
setLogLevel,
|
|
331
|
+
shouldLog,
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* Creates a logger instance with configurable log level filtering.
|
|
337
|
+
* Each log function is wrapped to respect the current log level setting.
|
|
338
|
+
*
|
|
339
|
+
* @param error - Function to handle error-level logs (required)
|
|
340
|
+
* @param warn - Function to handle warning-level logs (optional, defaults to noop)
|
|
341
|
+
* @param log - Function to handle standard logs (optional, defaults to noop)
|
|
342
|
+
* @param info - Function to handle info-level logs (optional, defaults to noop)
|
|
343
|
+
* @param debug - Function to handle debug-level logs (optional, defaults to noop)
|
|
344
|
+
* @returns A frozen logger object with log methods and level control
|
|
345
|
+
* @throws {ErrorLevelFn} When any provided log function is invalid
|
|
346
|
+
*/
|
|
347
|
+
function createLogger(error, warn = noop, log = noop, info = noop, debug = noop) {
|
|
348
|
+
if (notValidLogFn(error)) {
|
|
349
|
+
throw createError(notFnMsg('error'));
|
|
350
|
+
}
|
|
351
|
+
if (notValidLogFn(warn)) {
|
|
352
|
+
throw createError(notFnMsg('warn'));
|
|
353
|
+
}
|
|
354
|
+
if (notValidLogFn(log)) {
|
|
355
|
+
throw createError(notFnMsg('log'));
|
|
356
|
+
}
|
|
357
|
+
if (notValidLogFn(info)) {
|
|
358
|
+
throw createError(notFnMsg('info'));
|
|
359
|
+
}
|
|
360
|
+
if (notValidLogFn(debug)) {
|
|
361
|
+
throw createError(notFnMsg('debug'));
|
|
362
|
+
}
|
|
363
|
+
const { setLogLevel, getLogLevel, shouldLog } = createLogLevelConfig();
|
|
364
|
+
const wrapLogFn = (fn, level) => {
|
|
365
|
+
if (fn === noop)
|
|
366
|
+
return fn;
|
|
367
|
+
const condition = () => shouldLog(level);
|
|
368
|
+
return createConditionalExecutionFunction(createErrorIgnoringFunction(fn), condition);
|
|
369
|
+
};
|
|
370
|
+
return freeze({
|
|
371
|
+
error: wrapLogFn(error, 'error'),
|
|
372
|
+
warn: wrapLogFn(warn, 'warn'),
|
|
373
|
+
log: wrapLogFn(log, 'log'),
|
|
374
|
+
info: wrapLogFn(info, 'info'),
|
|
375
|
+
debug: wrapLogFn(debug, 'debug'),
|
|
376
|
+
setLogLevel,
|
|
377
|
+
getLogLevel,
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Validates whether a given value is a valid log function.
|
|
382
|
+
*
|
|
383
|
+
* @param fn - The value to validate
|
|
384
|
+
* @returns True if the value is not a function (invalid), false if it is valid
|
|
385
|
+
*/
|
|
386
|
+
function notValidLogFn(fn) {
|
|
387
|
+
return getType(fn) !== 'function' && fn !== noop;
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* Generates an error message for invalid log function parameters.
|
|
391
|
+
*
|
|
392
|
+
* @param label - The name of the log function that failed validation
|
|
393
|
+
* @returns A formatted error message string
|
|
394
|
+
*/
|
|
395
|
+
function notFnMsg(label) {
|
|
396
|
+
return `Cannot create a logger when ${label} is not a function`;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
createLogger(error, warn, log, info, debug);
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* Global log level registry.
|
|
403
|
+
* Tracks all created scoped loggers to allow global log level changes.
|
|
404
|
+
*/
|
|
405
|
+
const loggerRegistry = createSet();
|
|
406
|
+
/** Redacted placeholder for sensitive values */
|
|
407
|
+
const REDACTED = '[REDACTED]';
|
|
408
|
+
/**
|
|
409
|
+
* Patterns that indicate a sensitive key name.
|
|
410
|
+
* Keys containing these patterns will have their values sanitized.
|
|
411
|
+
*/
|
|
412
|
+
const SENSITIVE_KEY_PATTERNS = [
|
|
413
|
+
/token/i,
|
|
414
|
+
/key/i,
|
|
415
|
+
/password/i,
|
|
416
|
+
/secret/i,
|
|
417
|
+
/credential/i,
|
|
418
|
+
/auth/i,
|
|
419
|
+
/bearer/i,
|
|
420
|
+
/api[_-]?key/i,
|
|
421
|
+
/private/i,
|
|
422
|
+
/passphrase/i,
|
|
423
|
+
];
|
|
424
|
+
/**
|
|
425
|
+
* Checks if a key name indicates sensitive data.
|
|
426
|
+
*
|
|
427
|
+
* @param key - Key name to check
|
|
428
|
+
* @returns True if the key indicates sensitive data
|
|
429
|
+
*/
|
|
430
|
+
function isSensitiveKey(key) {
|
|
431
|
+
return SENSITIVE_KEY_PATTERNS.some((pattern) => pattern.test(key));
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* Sanitizes an object by replacing sensitive values with REDACTED.
|
|
435
|
+
* This function recursively processes nested objects and arrays.
|
|
436
|
+
*
|
|
437
|
+
* @param obj - Object to sanitize
|
|
438
|
+
* @returns New object with sensitive values redacted
|
|
439
|
+
*/
|
|
440
|
+
function sanitize(obj) {
|
|
441
|
+
if (obj === null || obj === undefined) {
|
|
442
|
+
return obj;
|
|
443
|
+
}
|
|
444
|
+
if (isArray(obj)) {
|
|
445
|
+
return obj.map((item) => sanitize(item));
|
|
446
|
+
}
|
|
447
|
+
if (typeof obj === 'object') {
|
|
448
|
+
const result = {};
|
|
449
|
+
for (const [key, value] of entries(obj)) {
|
|
450
|
+
if (isSensitiveKey(key)) {
|
|
451
|
+
result[key] = REDACTED;
|
|
452
|
+
}
|
|
453
|
+
else if (typeof value === 'object' && value !== null) {
|
|
454
|
+
result[key] = sanitize(value);
|
|
455
|
+
}
|
|
456
|
+
else {
|
|
457
|
+
result[key] = value;
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
return result;
|
|
461
|
+
}
|
|
462
|
+
return obj;
|
|
463
|
+
}
|
|
464
|
+
/**
|
|
465
|
+
* Formats a log message with optional metadata.
|
|
466
|
+
*
|
|
467
|
+
* @param namespace - Logger namespace prefix
|
|
468
|
+
* @param message - Log message
|
|
469
|
+
* @param meta - Optional metadata object
|
|
470
|
+
* @returns Formatted log string
|
|
471
|
+
*/
|
|
472
|
+
function formatMessage(namespace, message, meta) {
|
|
473
|
+
const prefix = `[${namespace}]`;
|
|
474
|
+
if (meta && keys(meta).length > 0) {
|
|
475
|
+
const sanitizedMeta = sanitize(meta);
|
|
476
|
+
return `${prefix} ${message} ${stringify(sanitizedMeta)}`;
|
|
477
|
+
}
|
|
478
|
+
return `${prefix} ${message}`;
|
|
479
|
+
}
|
|
480
|
+
/**
|
|
481
|
+
* Creates a scoped logger with namespace prefix and optional secret sanitization.
|
|
482
|
+
* All log messages will be prefixed with [namespace] and sensitive metadata
|
|
483
|
+
* values will be automatically redacted.
|
|
484
|
+
*
|
|
485
|
+
* @param namespace - Logger namespace (e.g., 'project-scope', 'analyze')
|
|
486
|
+
* @param options - Logger configuration options
|
|
487
|
+
* @returns A configured scoped logger instance
|
|
488
|
+
*
|
|
489
|
+
* @example
|
|
490
|
+
* ```typescript
|
|
491
|
+
* const logger = createScopedLogger('project-scope')
|
|
492
|
+
* logger.setLogLevel('debug')
|
|
493
|
+
*
|
|
494
|
+
* // Basic logging
|
|
495
|
+
* logger.info('Starting analysis', { path: './project' })
|
|
496
|
+
*
|
|
497
|
+
* // Sensitive data is automatically redacted
|
|
498
|
+
* logger.debug('Config loaded', { apiKey: 'secret123' })
|
|
499
|
+
* // Output: [project-scope] Config loaded {"apiKey":"[REDACTED]"}
|
|
500
|
+
* ```
|
|
501
|
+
*/
|
|
502
|
+
function createScopedLogger(namespace, options = {}) {
|
|
503
|
+
const { level = 'error', sanitizeSecrets = true } = options;
|
|
504
|
+
// Create wrapper functions that add namespace prefix and sanitization
|
|
505
|
+
const createLogFn = (baseFn) => (message, meta) => {
|
|
506
|
+
const processedMeta = sanitizeSecrets && meta ? sanitize(meta) : meta;
|
|
507
|
+
baseFn(formatMessage(namespace, message, processedMeta));
|
|
508
|
+
};
|
|
509
|
+
// Create base logger with wrapped functions
|
|
510
|
+
const baseLogger = createLogger(createLogFn(error), createLogFn(warn), createLogFn(log), createLogFn(info), createLogFn(debug));
|
|
511
|
+
// Set initial log level (use global override if set)
|
|
512
|
+
baseLogger.setLogLevel(level);
|
|
513
|
+
const scopedLogger = freeze({
|
|
514
|
+
error: (message, meta) => baseLogger.error(message, meta),
|
|
515
|
+
warn: (message, meta) => baseLogger.warn(message, meta),
|
|
516
|
+
log: (message, meta) => baseLogger.log(message, meta),
|
|
517
|
+
info: (message, meta) => baseLogger.info(message, meta),
|
|
518
|
+
debug: (message, meta) => baseLogger.debug(message, meta),
|
|
519
|
+
setLogLevel: baseLogger.setLogLevel,
|
|
520
|
+
getLogLevel: baseLogger.getLogLevel,
|
|
521
|
+
});
|
|
522
|
+
// Register logger for global level management
|
|
523
|
+
loggerRegistry.add(scopedLogger);
|
|
524
|
+
return scopedLogger;
|
|
525
|
+
}
|
|
526
|
+
/**
|
|
527
|
+
* Default logger instance for the project-scope library.
|
|
528
|
+
* Use this for general logging within the library.
|
|
529
|
+
*
|
|
530
|
+
* @example
|
|
531
|
+
* ```typescript
|
|
532
|
+
* import { logger } from '@hyperfrontend/project-scope/core'
|
|
533
|
+
*
|
|
534
|
+
* logger.setLogLevel('debug')
|
|
535
|
+
* logger.debug('Analyzing project', { path: './src' })
|
|
536
|
+
* ```
|
|
537
|
+
*/
|
|
538
|
+
createScopedLogger('project-scope');
|
|
539
|
+
|
|
540
|
+
createScopedLogger('project-scope:fs');
|
|
541
|
+
/**
|
|
542
|
+
* Read file if exists, return null otherwise.
|
|
543
|
+
*
|
|
544
|
+
* @param filePath - Path to file
|
|
545
|
+
* @param encoding - File encoding (default: utf-8)
|
|
546
|
+
* @returns File contents or null if file doesn't exist
|
|
547
|
+
*/
|
|
548
|
+
function readFileIfExists(filePath, encoding = 'utf-8') {
|
|
549
|
+
if (!node_fs.existsSync(filePath)) {
|
|
550
|
+
return null;
|
|
551
|
+
}
|
|
552
|
+
try {
|
|
553
|
+
return node_fs.readFileSync(filePath, { encoding });
|
|
554
|
+
}
|
|
555
|
+
catch {
|
|
556
|
+
return null;
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
createScopedLogger('project-scope:fs:write');
|
|
561
|
+
|
|
562
|
+
/**
|
|
563
|
+
* Check if path exists.
|
|
564
|
+
*
|
|
565
|
+
* @param filePath - Path to check
|
|
566
|
+
* @returns True if path exists
|
|
567
|
+
*/
|
|
568
|
+
function exists(filePath) {
|
|
569
|
+
return node_fs.existsSync(filePath);
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
createScopedLogger('project-scope:fs:dir');
|
|
573
|
+
|
|
574
|
+
createScopedLogger('project-scope:fs:traversal');
|
|
575
|
+
|
|
576
|
+
const packageLogger = createScopedLogger('project-scope:project:package');
|
|
577
|
+
/**
|
|
578
|
+
* Verifies that a value is an object with only string values,
|
|
579
|
+
* used for validating dependency maps and script definitions.
|
|
580
|
+
*
|
|
581
|
+
* @param value - Value to check
|
|
582
|
+
* @returns True if value is a record of strings
|
|
583
|
+
*/
|
|
584
|
+
function isStringRecord(value) {
|
|
585
|
+
if (typeof value !== 'object' || value === null)
|
|
586
|
+
return false;
|
|
587
|
+
return values(value).every((v) => typeof v === 'string');
|
|
588
|
+
}
|
|
589
|
+
/**
|
|
590
|
+
* Extracts and normalizes the workspaces field from package.json,
|
|
591
|
+
* supporting both array format and object with packages array.
|
|
592
|
+
*
|
|
593
|
+
* @param value - Raw workspaces value from package.json
|
|
594
|
+
* @returns Normalized workspace patterns or undefined if invalid
|
|
595
|
+
*/
|
|
596
|
+
function parseWorkspaces(value) {
|
|
597
|
+
if (isArray(value) && value.every((v) => typeof v === 'string')) {
|
|
598
|
+
return value;
|
|
599
|
+
}
|
|
600
|
+
if (typeof value === 'object' && value !== null) {
|
|
601
|
+
const obj = value;
|
|
602
|
+
if (isArray(obj['packages'])) {
|
|
603
|
+
return { packages: obj['packages'] };
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
return undefined;
|
|
607
|
+
}
|
|
608
|
+
/**
|
|
609
|
+
* Validate and normalize package.json data.
|
|
610
|
+
*
|
|
611
|
+
* @param data - Raw parsed data
|
|
612
|
+
* @returns Validated package.json
|
|
613
|
+
*/
|
|
614
|
+
function validatePackageJson(data) {
|
|
615
|
+
if (typeof data !== 'object' || data === null) {
|
|
616
|
+
throw createError('package.json must be an object');
|
|
617
|
+
}
|
|
618
|
+
const pkg = data;
|
|
619
|
+
return {
|
|
620
|
+
name: typeof pkg['name'] === 'string' ? pkg['name'] : undefined,
|
|
621
|
+
version: typeof pkg['version'] === 'string' ? pkg['version'] : undefined,
|
|
622
|
+
description: typeof pkg['description'] === 'string' ? pkg['description'] : undefined,
|
|
623
|
+
main: typeof pkg['main'] === 'string' ? pkg['main'] : undefined,
|
|
624
|
+
module: typeof pkg['module'] === 'string' ? pkg['module'] : undefined,
|
|
625
|
+
browser: typeof pkg['browser'] === 'string' ? pkg['browser'] : undefined,
|
|
626
|
+
types: typeof pkg['types'] === 'string' ? pkg['types'] : undefined,
|
|
627
|
+
bin: typeof pkg['bin'] === 'string' || isStringRecord(pkg['bin']) ? pkg['bin'] : undefined,
|
|
628
|
+
scripts: isStringRecord(pkg['scripts']) ? pkg['scripts'] : undefined,
|
|
629
|
+
dependencies: isStringRecord(pkg['dependencies']) ? pkg['dependencies'] : undefined,
|
|
630
|
+
devDependencies: isStringRecord(pkg['devDependencies']) ? pkg['devDependencies'] : undefined,
|
|
631
|
+
peerDependencies: isStringRecord(pkg['peerDependencies']) ? pkg['peerDependencies'] : undefined,
|
|
632
|
+
optionalDependencies: isStringRecord(pkg['optionalDependencies']) ? pkg['optionalDependencies'] : undefined,
|
|
633
|
+
workspaces: parseWorkspaces(pkg['workspaces']),
|
|
634
|
+
exports: typeof pkg['exports'] === 'object' ? pkg['exports'] : undefined,
|
|
635
|
+
engines: isStringRecord(pkg['engines']) ? pkg['engines'] : undefined,
|
|
636
|
+
...pkg,
|
|
637
|
+
};
|
|
638
|
+
}
|
|
639
|
+
/**
|
|
640
|
+
* Attempts to read and parse package.json if it exists,
|
|
641
|
+
* returning null on missing file or parse failure.
|
|
642
|
+
*
|
|
643
|
+
* @param projectPath - Project directory path or path to package.json
|
|
644
|
+
* @returns Parsed package.json or null if not found
|
|
645
|
+
*/
|
|
646
|
+
function readPackageJsonIfExists(projectPath) {
|
|
647
|
+
const packageJsonPath = projectPath.endsWith('package.json') ? projectPath : node_path.join(projectPath, 'package.json');
|
|
648
|
+
const content = readFileIfExists(packageJsonPath);
|
|
649
|
+
if (!content) {
|
|
650
|
+
packageLogger.debug('Package.json not found', { path: packageJsonPath });
|
|
651
|
+
return null;
|
|
652
|
+
}
|
|
653
|
+
try {
|
|
654
|
+
const validated = validatePackageJson(parse(content));
|
|
655
|
+
packageLogger.debug('Package.json loaded', { path: packageJsonPath, name: validated.name });
|
|
656
|
+
return validated;
|
|
657
|
+
}
|
|
658
|
+
catch {
|
|
659
|
+
packageLogger.debug('Failed to parse package.json, returning null', { path: packageJsonPath });
|
|
660
|
+
return null;
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
/**
|
|
665
|
+
* Get combined dependencies from package.json.
|
|
666
|
+
* Merges dependencies, devDependencies, peerDependencies, and optionalDependencies.
|
|
667
|
+
*
|
|
668
|
+
* @param packageJson - The package.json object to extract dependencies from
|
|
669
|
+
* @returns Combined dependencies as a single record
|
|
670
|
+
*/
|
|
671
|
+
function collectAllDependencies(packageJson) {
|
|
672
|
+
return {
|
|
673
|
+
...packageJson?.dependencies,
|
|
674
|
+
...packageJson?.devDependencies,
|
|
675
|
+
...packageJson?.peerDependencies,
|
|
676
|
+
...packageJson?.optionalDependencies,
|
|
677
|
+
};
|
|
678
|
+
}
|
|
679
|
+
/**
|
|
680
|
+
* Extract clean version from dependency version string.
|
|
681
|
+
* Removes semver prefixes like ^, ~, >=, etc.
|
|
682
|
+
* Uses character-by-character parsing to avoid ReDoS vulnerabilities.
|
|
683
|
+
*
|
|
684
|
+
* @param versionString - The version string with optional prefix characters
|
|
685
|
+
* @returns The cleaned version string without prefix characters
|
|
686
|
+
*/
|
|
687
|
+
function parseVersionString(versionString) {
|
|
688
|
+
if (versionString === undefined || versionString === null)
|
|
689
|
+
return undefined;
|
|
690
|
+
// Manual parsing instead of regex to avoid ReDoS
|
|
691
|
+
let start = 0;
|
|
692
|
+
while (start < versionString.length) {
|
|
693
|
+
const char = versionString[start];
|
|
694
|
+
if (char !== '^' && char !== '~' && char !== '>' && char !== '=' && char !== '<') {
|
|
695
|
+
break;
|
|
696
|
+
}
|
|
697
|
+
start++;
|
|
698
|
+
}
|
|
699
|
+
return versionString.slice(start);
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
/**
|
|
703
|
+
* Detect React in project.
|
|
704
|
+
*
|
|
705
|
+
* @param projectPath - Project directory path
|
|
706
|
+
* @param packageJson - Optional pre-loaded package.json
|
|
707
|
+
* @returns Detection result or null if not detected
|
|
708
|
+
*/
|
|
709
|
+
function reactDetector(projectPath, packageJson) {
|
|
710
|
+
const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
|
|
711
|
+
const sources = [];
|
|
712
|
+
let confidence = 0;
|
|
713
|
+
let version;
|
|
714
|
+
const metaFrameworks = [];
|
|
715
|
+
const deps = collectAllDependencies(pkg);
|
|
716
|
+
if (deps['react']) {
|
|
717
|
+
confidence += 60;
|
|
718
|
+
version = parseVersionString(deps['react']);
|
|
719
|
+
sources.push({ type: 'package.json', field: 'dependencies.react' });
|
|
720
|
+
}
|
|
721
|
+
if (deps['react-dom']) {
|
|
722
|
+
confidence += 20;
|
|
723
|
+
sources.push({ type: 'package.json', field: 'dependencies.react-dom' });
|
|
724
|
+
}
|
|
725
|
+
if (deps['react-native']) {
|
|
726
|
+
confidence += 20;
|
|
727
|
+
sources.push({ type: 'package.json', field: 'dependencies.react-native' });
|
|
728
|
+
}
|
|
729
|
+
const hasJsxFiles = exists(node_path.join(projectPath, 'src', 'App.tsx')) ||
|
|
730
|
+
exists(node_path.join(projectPath, 'src', 'App.jsx')) ||
|
|
731
|
+
exists(node_path.join(projectPath, 'src', 'index.tsx')) ||
|
|
732
|
+
exists(node_path.join(projectPath, 'src', 'index.jsx'));
|
|
733
|
+
if (hasJsxFiles) {
|
|
734
|
+
confidence += 10;
|
|
735
|
+
sources.push({ type: 'directory', path: 'src/*.tsx or src/*.jsx' });
|
|
736
|
+
}
|
|
737
|
+
if (deps['next']) {
|
|
738
|
+
metaFrameworks.push({
|
|
739
|
+
id: 'nextjs',
|
|
740
|
+
name: 'Next.js',
|
|
741
|
+
category: 'meta-framework',
|
|
742
|
+
version: parseVersionString(deps['next']),
|
|
743
|
+
confidence: 90,
|
|
744
|
+
detectedFrom: [{ type: 'package.json', field: 'dependencies.next' }],
|
|
745
|
+
});
|
|
746
|
+
}
|
|
747
|
+
if (deps['gatsby']) {
|
|
748
|
+
metaFrameworks.push({
|
|
749
|
+
id: 'gatsby',
|
|
750
|
+
name: 'Gatsby',
|
|
751
|
+
category: 'meta-framework',
|
|
752
|
+
version: parseVersionString(deps['gatsby']),
|
|
753
|
+
confidence: 90,
|
|
754
|
+
detectedFrom: [{ type: 'package.json', field: 'dependencies.gatsby' }],
|
|
755
|
+
});
|
|
756
|
+
}
|
|
757
|
+
if (deps['@remix-run/react'] || deps['remix']) {
|
|
758
|
+
metaFrameworks.push({
|
|
759
|
+
id: 'remix',
|
|
760
|
+
name: 'Remix',
|
|
761
|
+
category: 'meta-framework',
|
|
762
|
+
version: parseVersionString(deps['@remix-run/react'] ?? deps['remix']),
|
|
763
|
+
confidence: 90,
|
|
764
|
+
detectedFrom: [{ type: 'package.json', field: 'dependencies.@remix-run/react' }],
|
|
765
|
+
});
|
|
766
|
+
}
|
|
767
|
+
if (confidence === 0) {
|
|
768
|
+
return null;
|
|
769
|
+
}
|
|
770
|
+
return {
|
|
771
|
+
id: 'react',
|
|
772
|
+
name: 'React',
|
|
773
|
+
category: 'frontend',
|
|
774
|
+
version,
|
|
775
|
+
confidence: min(confidence, 100),
|
|
776
|
+
detectedFrom: sources,
|
|
777
|
+
metaFrameworks: metaFrameworks.length > 0 ? metaFrameworks : undefined,
|
|
778
|
+
};
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
/**
|
|
782
|
+
* Detect Next.js in project.
|
|
783
|
+
*
|
|
784
|
+
* @param projectPath - Project directory path
|
|
785
|
+
* @param packageJson - Optional pre-loaded package.json
|
|
786
|
+
* @returns Detection result or null if not detected
|
|
787
|
+
*/
|
|
788
|
+
function nextjsDetector(projectPath, packageJson) {
|
|
789
|
+
const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
|
|
790
|
+
const sources = [];
|
|
791
|
+
let confidence = 0;
|
|
792
|
+
let version;
|
|
793
|
+
const deps = collectAllDependencies(pkg);
|
|
794
|
+
if (deps['next']) {
|
|
795
|
+
confidence += 70;
|
|
796
|
+
version = parseVersionString(deps['next']);
|
|
797
|
+
sources.push({ type: 'package.json', field: 'dependencies.next' });
|
|
798
|
+
}
|
|
799
|
+
if (exists(node_path.join(projectPath, 'next.config.js')) ||
|
|
800
|
+
exists(node_path.join(projectPath, 'next.config.mjs')) ||
|
|
801
|
+
exists(node_path.join(projectPath, 'next.config.ts'))) {
|
|
802
|
+
confidence += 25;
|
|
803
|
+
sources.push({ type: 'config-file', path: 'next.config.*' });
|
|
804
|
+
}
|
|
805
|
+
if (exists(node_path.join(projectPath, 'pages')) ||
|
|
806
|
+
exists(node_path.join(projectPath, 'app')) ||
|
|
807
|
+
exists(node_path.join(projectPath, 'src', 'pages')) ||
|
|
808
|
+
exists(node_path.join(projectPath, 'src', 'app'))) {
|
|
809
|
+
confidence += 5;
|
|
810
|
+
sources.push({ type: 'directory', path: 'pages/ or app/' });
|
|
811
|
+
}
|
|
812
|
+
if (confidence === 0) {
|
|
813
|
+
return null;
|
|
814
|
+
}
|
|
815
|
+
return {
|
|
816
|
+
id: 'nextjs',
|
|
817
|
+
name: 'Next.js',
|
|
818
|
+
category: 'meta-framework',
|
|
819
|
+
version,
|
|
820
|
+
confidence: min(confidence, 100),
|
|
821
|
+
detectedFrom: sources,
|
|
822
|
+
};
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
/**
|
|
826
|
+
* Detect Remix in project.
|
|
827
|
+
*
|
|
828
|
+
* @param projectPath - Project directory path
|
|
829
|
+
* @param packageJson - Optional pre-loaded package.json
|
|
830
|
+
* @returns Detection result or null if not detected
|
|
831
|
+
*/
|
|
832
|
+
function remixDetector(projectPath, packageJson) {
|
|
833
|
+
const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
|
|
834
|
+
const sources = [];
|
|
835
|
+
let confidence = 0;
|
|
836
|
+
let version;
|
|
837
|
+
const deps = collectAllDependencies(pkg);
|
|
838
|
+
// @remix-run packages
|
|
839
|
+
if (deps['@remix-run/react']) {
|
|
840
|
+
confidence += 70;
|
|
841
|
+
version = parseVersionString(deps['@remix-run/react']);
|
|
842
|
+
sources.push({ type: 'package.json', field: 'dependencies.@remix-run/react' });
|
|
843
|
+
}
|
|
844
|
+
if (deps['@remix-run/node'] || deps['@remix-run/cloudflare'] || deps['@remix-run/deno']) {
|
|
845
|
+
confidence += 20;
|
|
846
|
+
sources.push({ type: 'package.json', field: 'dependencies.@remix-run/*' });
|
|
847
|
+
}
|
|
848
|
+
if (exists(node_path.join(projectPath, 'remix.config.js')) || exists(node_path.join(projectPath, 'remix.config.ts'))) {
|
|
849
|
+
confidence += 10;
|
|
850
|
+
sources.push({ type: 'config-file', path: 'remix.config.*' });
|
|
851
|
+
}
|
|
852
|
+
if (confidence === 0) {
|
|
853
|
+
return null;
|
|
854
|
+
}
|
|
855
|
+
return {
|
|
856
|
+
id: 'remix',
|
|
857
|
+
name: 'Remix',
|
|
858
|
+
category: 'meta-framework',
|
|
859
|
+
version,
|
|
860
|
+
confidence: min(confidence, 100),
|
|
861
|
+
detectedFrom: sources,
|
|
862
|
+
};
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
/**
|
|
866
|
+
* Detect Gatsby in project.
|
|
867
|
+
*
|
|
868
|
+
* @param projectPath - Project directory path
|
|
869
|
+
* @param packageJson - Optional pre-loaded package.json
|
|
870
|
+
* @returns Detection result or null if not detected
|
|
871
|
+
*/
|
|
872
|
+
function gatsbyDetector(projectPath, packageJson) {
|
|
873
|
+
const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
|
|
874
|
+
const sources = [];
|
|
875
|
+
let confidence = 0;
|
|
876
|
+
let version;
|
|
877
|
+
const deps = collectAllDependencies(pkg);
|
|
878
|
+
if (deps['gatsby']) {
|
|
879
|
+
confidence += 70;
|
|
880
|
+
version = parseVersionString(deps['gatsby']);
|
|
881
|
+
sources.push({ type: 'package.json', field: 'dependencies.gatsby' });
|
|
882
|
+
}
|
|
883
|
+
if (exists(node_path.join(projectPath, 'gatsby-config.js')) || exists(node_path.join(projectPath, 'gatsby-config.ts'))) {
|
|
884
|
+
confidence += 25;
|
|
885
|
+
sources.push({ type: 'config-file', path: 'gatsby-config.*' });
|
|
886
|
+
}
|
|
887
|
+
const gatsbyPlugins = keys(deps).filter((d) => d.startsWith('gatsby-plugin-') || d.startsWith('gatsby-source-'));
|
|
888
|
+
if (gatsbyPlugins.length > 0) {
|
|
889
|
+
confidence += 5;
|
|
890
|
+
sources.push({ type: 'package.json', field: 'dependencies (gatsby plugins)' });
|
|
891
|
+
}
|
|
892
|
+
if (confidence === 0) {
|
|
893
|
+
return null;
|
|
894
|
+
}
|
|
895
|
+
return {
|
|
896
|
+
id: 'gatsby',
|
|
897
|
+
name: 'Gatsby',
|
|
898
|
+
category: 'meta-framework',
|
|
899
|
+
version,
|
|
900
|
+
confidence: min(confidence, 100),
|
|
901
|
+
detectedFrom: sources,
|
|
902
|
+
};
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
/**
|
|
906
|
+
* Detect Vue in project.
|
|
907
|
+
*
|
|
908
|
+
* @param projectPath - Project directory path
|
|
909
|
+
* @param packageJson - Optional pre-loaded package.json
|
|
910
|
+
* @returns Detection result or null if not detected
|
|
911
|
+
*/
|
|
912
|
+
function vueDetector(projectPath, packageJson) {
|
|
913
|
+
const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
|
|
914
|
+
const sources = [];
|
|
915
|
+
let confidence = 0;
|
|
916
|
+
let version;
|
|
917
|
+
const metaFrameworks = [];
|
|
918
|
+
const deps = collectAllDependencies(pkg);
|
|
919
|
+
if (deps['vue']) {
|
|
920
|
+
confidence += 70;
|
|
921
|
+
version = parseVersionString(deps['vue']);
|
|
922
|
+
sources.push({ type: 'package.json', field: 'dependencies.vue' });
|
|
923
|
+
}
|
|
924
|
+
if (deps['@vue/cli-service']) {
|
|
925
|
+
confidence += 15;
|
|
926
|
+
sources.push({ type: 'package.json', field: 'dependencies.@vue/cli-service' });
|
|
927
|
+
}
|
|
928
|
+
const hasVueFiles = exists(node_path.join(projectPath, 'src', 'App.vue')) || exists(node_path.join(projectPath, 'src', 'main.vue'));
|
|
929
|
+
if (hasVueFiles) {
|
|
930
|
+
confidence += 10;
|
|
931
|
+
sources.push({ type: 'directory', path: 'src/*.vue' });
|
|
932
|
+
}
|
|
933
|
+
if (exists(node_path.join(projectPath, 'vue.config.js'))) {
|
|
934
|
+
confidence += 5;
|
|
935
|
+
sources.push({ type: 'config-file', path: 'vue.config.js' });
|
|
936
|
+
}
|
|
937
|
+
if (deps['nuxt'] || deps['nuxt3']) {
|
|
938
|
+
metaFrameworks.push({
|
|
939
|
+
id: 'nuxt',
|
|
940
|
+
name: 'Nuxt',
|
|
941
|
+
category: 'meta-framework',
|
|
942
|
+
version: parseVersionString(deps['nuxt'] ?? deps['nuxt3']),
|
|
943
|
+
confidence: 90,
|
|
944
|
+
detectedFrom: [{ type: 'package.json', field: 'dependencies.nuxt' }],
|
|
945
|
+
});
|
|
946
|
+
}
|
|
947
|
+
if (confidence === 0) {
|
|
948
|
+
return null;
|
|
949
|
+
}
|
|
950
|
+
return {
|
|
951
|
+
id: 'vue',
|
|
952
|
+
name: 'Vue',
|
|
953
|
+
category: 'frontend',
|
|
954
|
+
version,
|
|
955
|
+
confidence: min(confidence, 100),
|
|
956
|
+
detectedFrom: sources,
|
|
957
|
+
metaFrameworks: metaFrameworks.length > 0 ? metaFrameworks : undefined,
|
|
958
|
+
};
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
/**
|
|
962
|
+
* Detect Nuxt in project.
|
|
963
|
+
*
|
|
964
|
+
* @param projectPath - Project directory path
|
|
965
|
+
* @param packageJson - Optional pre-loaded package.json
|
|
966
|
+
* @returns Detection result or null if not detected
|
|
967
|
+
*/
|
|
968
|
+
function nuxtDetector(projectPath, packageJson) {
|
|
969
|
+
const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
|
|
970
|
+
const sources = [];
|
|
971
|
+
let confidence = 0;
|
|
972
|
+
let version;
|
|
973
|
+
const deps = collectAllDependencies(pkg);
|
|
974
|
+
if (deps['nuxt'] || deps['nuxt3']) {
|
|
975
|
+
confidence += 70;
|
|
976
|
+
version = parseVersionString(deps['nuxt'] ?? deps['nuxt3']);
|
|
977
|
+
sources.push({ type: 'package.json', field: 'dependencies.nuxt' });
|
|
978
|
+
}
|
|
979
|
+
if (exists(node_path.join(projectPath, 'nuxt.config.js')) || exists(node_path.join(projectPath, 'nuxt.config.ts'))) {
|
|
980
|
+
confidence += 25;
|
|
981
|
+
sources.push({ type: 'config-file', path: 'nuxt.config.*' });
|
|
982
|
+
}
|
|
983
|
+
if (exists(node_path.join(projectPath, 'pages'))) {
|
|
984
|
+
confidence += 5;
|
|
985
|
+
sources.push({ type: 'directory', path: 'pages/' });
|
|
986
|
+
}
|
|
987
|
+
if (confidence === 0) {
|
|
988
|
+
return null;
|
|
989
|
+
}
|
|
990
|
+
return {
|
|
991
|
+
id: 'nuxt',
|
|
992
|
+
name: 'Nuxt',
|
|
993
|
+
category: 'meta-framework',
|
|
994
|
+
version,
|
|
995
|
+
confidence: min(confidence, 100),
|
|
996
|
+
detectedFrom: sources,
|
|
997
|
+
};
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
/**
|
|
1001
|
+
* Detect Angular in project.
|
|
1002
|
+
*
|
|
1003
|
+
* @param projectPath - Project directory path
|
|
1004
|
+
* @param packageJson - Optional pre-loaded package.json
|
|
1005
|
+
* @returns Detection result or null if not detected
|
|
1006
|
+
*/
|
|
1007
|
+
function angularDetector(projectPath, packageJson) {
|
|
1008
|
+
const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
|
|
1009
|
+
const sources = [];
|
|
1010
|
+
let confidence = 0;
|
|
1011
|
+
let version;
|
|
1012
|
+
const deps = collectAllDependencies(pkg);
|
|
1013
|
+
if (deps['@angular/core']) {
|
|
1014
|
+
confidence += 70;
|
|
1015
|
+
version = parseVersionString(deps['@angular/core']);
|
|
1016
|
+
sources.push({ type: 'package.json', field: 'dependencies.@angular/core' });
|
|
1017
|
+
}
|
|
1018
|
+
if (deps['@angular/cli']) {
|
|
1019
|
+
confidence += 15;
|
|
1020
|
+
sources.push({ type: 'package.json', field: 'dependencies.@angular/cli' });
|
|
1021
|
+
}
|
|
1022
|
+
if (exists(node_path.join(projectPath, 'angular.json'))) {
|
|
1023
|
+
confidence += 15;
|
|
1024
|
+
sources.push({ type: 'config-file', path: 'angular.json' });
|
|
1025
|
+
}
|
|
1026
|
+
if (deps['angular'] && !deps['@angular/core']) {
|
|
1027
|
+
return {
|
|
1028
|
+
id: 'angularjs',
|
|
1029
|
+
name: 'AngularJS (Legacy)',
|
|
1030
|
+
category: 'frontend',
|
|
1031
|
+
version: parseVersionString(deps['angular']),
|
|
1032
|
+
confidence: 80,
|
|
1033
|
+
detectedFrom: [{ type: 'package.json', field: 'dependencies.angular' }],
|
|
1034
|
+
};
|
|
1035
|
+
}
|
|
1036
|
+
if (confidence === 0) {
|
|
1037
|
+
return null;
|
|
1038
|
+
}
|
|
1039
|
+
return {
|
|
1040
|
+
id: 'angular',
|
|
1041
|
+
name: 'Angular',
|
|
1042
|
+
category: 'frontend',
|
|
1043
|
+
version,
|
|
1044
|
+
confidence: min(confidence, 100),
|
|
1045
|
+
detectedFrom: sources,
|
|
1046
|
+
};
|
|
1047
|
+
}
|
|
1048
|
+
|
|
1049
|
+
/**
|
|
1050
|
+
* Detect Svelte in project.
|
|
1051
|
+
*
|
|
1052
|
+
* @param projectPath - Project directory path
|
|
1053
|
+
* @param packageJson - Optional pre-loaded package.json
|
|
1054
|
+
* @returns Detection result or null if not detected
|
|
1055
|
+
*/
|
|
1056
|
+
function svelteDetector(projectPath, packageJson) {
|
|
1057
|
+
const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
|
|
1058
|
+
const sources = [];
|
|
1059
|
+
let confidence = 0;
|
|
1060
|
+
let version;
|
|
1061
|
+
const metaFrameworks = [];
|
|
1062
|
+
const deps = collectAllDependencies(pkg);
|
|
1063
|
+
if (deps['svelte']) {
|
|
1064
|
+
confidence += 70;
|
|
1065
|
+
version = parseVersionString(deps['svelte']);
|
|
1066
|
+
sources.push({ type: 'package.json', field: 'dependencies.svelte' });
|
|
1067
|
+
}
|
|
1068
|
+
if (exists(node_path.join(projectPath, 'svelte.config.js'))) {
|
|
1069
|
+
confidence += 20;
|
|
1070
|
+
sources.push({ type: 'config-file', path: 'svelte.config.js' });
|
|
1071
|
+
}
|
|
1072
|
+
const hasSvelteFiles = exists(node_path.join(projectPath, 'src', 'App.svelte')) || exists(node_path.join(projectPath, 'src', 'routes'));
|
|
1073
|
+
if (hasSvelteFiles) {
|
|
1074
|
+
confidence += 10;
|
|
1075
|
+
sources.push({ type: 'directory', path: 'src/*.svelte or src/routes/' });
|
|
1076
|
+
}
|
|
1077
|
+
if (deps['@sveltejs/kit']) {
|
|
1078
|
+
metaFrameworks.push({
|
|
1079
|
+
id: 'sveltekit',
|
|
1080
|
+
name: 'SvelteKit',
|
|
1081
|
+
category: 'meta-framework',
|
|
1082
|
+
version: parseVersionString(deps['@sveltejs/kit']),
|
|
1083
|
+
confidence: 90,
|
|
1084
|
+
detectedFrom: [{ type: 'package.json', field: 'dependencies.@sveltejs/kit' }],
|
|
1085
|
+
});
|
|
1086
|
+
}
|
|
1087
|
+
if (confidence === 0) {
|
|
1088
|
+
return null;
|
|
1089
|
+
}
|
|
1090
|
+
return {
|
|
1091
|
+
id: 'svelte',
|
|
1092
|
+
name: 'Svelte',
|
|
1093
|
+
category: 'frontend',
|
|
1094
|
+
version,
|
|
1095
|
+
confidence: min(confidence, 100),
|
|
1096
|
+
detectedFrom: sources,
|
|
1097
|
+
metaFrameworks: metaFrameworks.length > 0 ? metaFrameworks : undefined,
|
|
1098
|
+
};
|
|
1099
|
+
}
|
|
1100
|
+
|
|
1101
|
+
/**
|
|
1102
|
+
* Detect SvelteKit in project.
|
|
1103
|
+
*
|
|
1104
|
+
* @param projectPath - Project directory path
|
|
1105
|
+
* @param packageJson - Optional pre-loaded package.json
|
|
1106
|
+
* @returns Detection result or null if not detected
|
|
1107
|
+
*/
|
|
1108
|
+
function sveltekitDetector(projectPath, packageJson) {
|
|
1109
|
+
const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
|
|
1110
|
+
const sources = [];
|
|
1111
|
+
let confidence = 0;
|
|
1112
|
+
let version;
|
|
1113
|
+
const deps = collectAllDependencies(pkg);
|
|
1114
|
+
// @sveltejs/kit package
|
|
1115
|
+
if (deps['@sveltejs/kit']) {
|
|
1116
|
+
confidence += 70;
|
|
1117
|
+
version = parseVersionString(deps['@sveltejs/kit']);
|
|
1118
|
+
sources.push({ type: 'package.json', field: 'dependencies.@sveltejs/kit' });
|
|
1119
|
+
}
|
|
1120
|
+
if (exists(node_path.join(projectPath, 'svelte.config.js'))) {
|
|
1121
|
+
confidence += 20;
|
|
1122
|
+
sources.push({ type: 'config-file', path: 'svelte.config.js' });
|
|
1123
|
+
}
|
|
1124
|
+
if (exists(node_path.join(projectPath, 'src', 'routes'))) {
|
|
1125
|
+
confidence += 10;
|
|
1126
|
+
sources.push({ type: 'directory', path: 'src/routes/' });
|
|
1127
|
+
}
|
|
1128
|
+
if (confidence === 0) {
|
|
1129
|
+
return null;
|
|
1130
|
+
}
|
|
1131
|
+
return {
|
|
1132
|
+
id: 'sveltekit',
|
|
1133
|
+
name: 'SvelteKit',
|
|
1134
|
+
category: 'meta-framework',
|
|
1135
|
+
version,
|
|
1136
|
+
confidence: min(confidence, 100),
|
|
1137
|
+
detectedFrom: sources,
|
|
1138
|
+
};
|
|
1139
|
+
}
|
|
1140
|
+
|
|
1141
|
+
/**
|
|
1142
|
+
* Detect Solid in project.
|
|
1143
|
+
*
|
|
1144
|
+
* @param projectPath - Project directory path
|
|
1145
|
+
* @param packageJson - Optional pre-loaded package.json
|
|
1146
|
+
* @returns Detection result or null if not detected
|
|
1147
|
+
*/
|
|
1148
|
+
function solidDetector(projectPath, packageJson) {
|
|
1149
|
+
const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
|
|
1150
|
+
const sources = [];
|
|
1151
|
+
let confidence = 0;
|
|
1152
|
+
let version;
|
|
1153
|
+
const deps = collectAllDependencies(pkg);
|
|
1154
|
+
if (deps['solid-js']) {
|
|
1155
|
+
confidence += 70;
|
|
1156
|
+
version = parseVersionString(deps['solid-js']);
|
|
1157
|
+
sources.push({ type: 'package.json', field: 'dependencies.solid-js' });
|
|
1158
|
+
}
|
|
1159
|
+
if (deps['vite-plugin-solid']) {
|
|
1160
|
+
confidence += 20;
|
|
1161
|
+
sources.push({ type: 'package.json', field: 'dependencies.vite-plugin-solid' });
|
|
1162
|
+
}
|
|
1163
|
+
if (deps['solid-start'] || deps['@solidjs/start']) {
|
|
1164
|
+
confidence += 10;
|
|
1165
|
+
sources.push({ type: 'package.json', field: 'dependencies.solid-start' });
|
|
1166
|
+
}
|
|
1167
|
+
if (confidence === 0) {
|
|
1168
|
+
return null;
|
|
1169
|
+
}
|
|
1170
|
+
return {
|
|
1171
|
+
id: 'solid',
|
|
1172
|
+
name: 'Solid',
|
|
1173
|
+
category: 'frontend',
|
|
1174
|
+
version,
|
|
1175
|
+
confidence: min(confidence, 100),
|
|
1176
|
+
detectedFrom: sources,
|
|
1177
|
+
};
|
|
1178
|
+
}
|
|
1179
|
+
|
|
1180
|
+
/**
|
|
1181
|
+
* Detect Qwik in project.
|
|
1182
|
+
*
|
|
1183
|
+
* @param projectPath - Project directory path
|
|
1184
|
+
* @param packageJson - Optional pre-loaded package.json
|
|
1185
|
+
* @returns Detection result or null if not detected
|
|
1186
|
+
*/
|
|
1187
|
+
function qwikDetector(projectPath, packageJson) {
|
|
1188
|
+
const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
|
|
1189
|
+
const sources = [];
|
|
1190
|
+
let confidence = 0;
|
|
1191
|
+
let version;
|
|
1192
|
+
const deps = collectAllDependencies(pkg);
|
|
1193
|
+
// @builder.io/qwik package
|
|
1194
|
+
if (deps['@builder.io/qwik']) {
|
|
1195
|
+
confidence += 70;
|
|
1196
|
+
version = parseVersionString(deps['@builder.io/qwik']);
|
|
1197
|
+
sources.push({ type: 'package.json', field: 'dependencies.@builder.io/qwik' });
|
|
1198
|
+
}
|
|
1199
|
+
// @builder.io/qwik-city
|
|
1200
|
+
if (deps['@builder.io/qwik-city']) {
|
|
1201
|
+
confidence += 20;
|
|
1202
|
+
sources.push({ type: 'package.json', field: 'dependencies.@builder.io/qwik-city' });
|
|
1203
|
+
}
|
|
1204
|
+
if (exists(node_path.join(projectPath, 'qwik.config.ts')) || exists(node_path.join(projectPath, 'qwik.config.js'))) {
|
|
1205
|
+
confidence += 10;
|
|
1206
|
+
sources.push({ type: 'config-file', path: 'qwik.config.*' });
|
|
1207
|
+
}
|
|
1208
|
+
if (confidence === 0) {
|
|
1209
|
+
return null;
|
|
1210
|
+
}
|
|
1211
|
+
return {
|
|
1212
|
+
id: 'qwik',
|
|
1213
|
+
name: 'Qwik',
|
|
1214
|
+
category: 'frontend',
|
|
1215
|
+
version,
|
|
1216
|
+
confidence: min(confidence, 100),
|
|
1217
|
+
detectedFrom: sources,
|
|
1218
|
+
};
|
|
1219
|
+
}
|
|
1220
|
+
|
|
1221
|
+
/**
|
|
1222
|
+
* Detect Astro in project.
|
|
1223
|
+
*
|
|
1224
|
+
* @param projectPath - Project directory path
|
|
1225
|
+
* @param packageJson - Optional pre-loaded package.json
|
|
1226
|
+
* @returns Detection result or null if not detected
|
|
1227
|
+
*/
|
|
1228
|
+
function astroDetector(projectPath, packageJson) {
|
|
1229
|
+
const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
|
|
1230
|
+
const sources = [];
|
|
1231
|
+
let confidence = 0;
|
|
1232
|
+
let version;
|
|
1233
|
+
const deps = collectAllDependencies(pkg);
|
|
1234
|
+
if (deps['astro']) {
|
|
1235
|
+
confidence += 70;
|
|
1236
|
+
version = parseVersionString(deps['astro']);
|
|
1237
|
+
sources.push({ type: 'package.json', field: 'dependencies.astro' });
|
|
1238
|
+
}
|
|
1239
|
+
if (exists(node_path.join(projectPath, 'astro.config.mjs')) ||
|
|
1240
|
+
exists(node_path.join(projectPath, 'astro.config.ts')) ||
|
|
1241
|
+
exists(node_path.join(projectPath, 'astro.config.js'))) {
|
|
1242
|
+
confidence += 25;
|
|
1243
|
+
sources.push({ type: 'config-file', path: 'astro.config.*' });
|
|
1244
|
+
}
|
|
1245
|
+
if (exists(node_path.join(projectPath, 'src', 'pages'))) {
|
|
1246
|
+
confidence += 5;
|
|
1247
|
+
sources.push({ type: 'directory', path: 'src/pages/' });
|
|
1248
|
+
}
|
|
1249
|
+
if (confidence === 0) {
|
|
1250
|
+
return null;
|
|
1251
|
+
}
|
|
1252
|
+
return {
|
|
1253
|
+
id: 'astro',
|
|
1254
|
+
name: 'Astro',
|
|
1255
|
+
category: 'meta-framework',
|
|
1256
|
+
version,
|
|
1257
|
+
confidence: min(confidence, 100),
|
|
1258
|
+
detectedFrom: sources,
|
|
1259
|
+
};
|
|
1260
|
+
}
|
|
1261
|
+
|
|
1262
|
+
/** All frontend framework detectors */
|
|
1263
|
+
const frameworkDetectors = [
|
|
1264
|
+
{ id: 'react', name: 'React', category: 'frontend', detect: reactDetector },
|
|
1265
|
+
{ id: 'nextjs', name: 'Next.js', category: 'meta-framework', detect: nextjsDetector },
|
|
1266
|
+
{ id: 'remix', name: 'Remix', category: 'meta-framework', detect: remixDetector },
|
|
1267
|
+
{ id: 'gatsby', name: 'Gatsby', category: 'meta-framework', detect: gatsbyDetector },
|
|
1268
|
+
{ id: 'vue', name: 'Vue', category: 'frontend', detect: vueDetector },
|
|
1269
|
+
{ id: 'nuxt', name: 'Nuxt', category: 'meta-framework', detect: nuxtDetector },
|
|
1270
|
+
{ id: 'angular', name: 'Angular', category: 'frontend', detect: angularDetector },
|
|
1271
|
+
{ id: 'svelte', name: 'Svelte', category: 'frontend', detect: svelteDetector },
|
|
1272
|
+
{ id: 'sveltekit', name: 'SvelteKit', category: 'meta-framework', detect: sveltekitDetector },
|
|
1273
|
+
{ id: 'solid', name: 'Solid', category: 'frontend', detect: solidDetector },
|
|
1274
|
+
{ id: 'qwik', name: 'Qwik', category: 'frontend', detect: qwikDetector },
|
|
1275
|
+
{ id: 'astro', name: 'Astro', category: 'meta-framework', detect: astroDetector },
|
|
1276
|
+
];
|
|
1277
|
+
/**
|
|
1278
|
+
* Detect all frontend frameworks in project.
|
|
1279
|
+
*
|
|
1280
|
+
* @param projectPath - Project directory path
|
|
1281
|
+
* @param packageJson - Optional pre-loaded package.json
|
|
1282
|
+
* @returns Array of detected frameworks, sorted by confidence
|
|
1283
|
+
*/
|
|
1284
|
+
function detectFrontendFrameworks(projectPath, packageJson) {
|
|
1285
|
+
const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
|
|
1286
|
+
const results = [];
|
|
1287
|
+
for (const detector of frameworkDetectors) {
|
|
1288
|
+
const detection = detector.detect(projectPath, pkg ?? undefined);
|
|
1289
|
+
if (detection) {
|
|
1290
|
+
results.push(detection);
|
|
1291
|
+
}
|
|
1292
|
+
}
|
|
1293
|
+
return results.sort((a, b) => b.confidence - a.confidence);
|
|
1294
|
+
}
|
|
1295
|
+
|
|
1296
|
+
exports.angularDetector = angularDetector;
|
|
1297
|
+
exports.astroDetector = astroDetector;
|
|
1298
|
+
exports.detectFrontendFrameworks = detectFrontendFrameworks;
|
|
1299
|
+
exports.frameworkDetectors = frameworkDetectors;
|
|
1300
|
+
exports.gatsbyDetector = gatsbyDetector;
|
|
1301
|
+
exports.nextjsDetector = nextjsDetector;
|
|
1302
|
+
exports.nuxtDetector = nuxtDetector;
|
|
1303
|
+
exports.qwikDetector = qwikDetector;
|
|
1304
|
+
exports.reactDetector = reactDetector;
|
|
1305
|
+
exports.remixDetector = remixDetector;
|
|
1306
|
+
exports.solidDetector = solidDetector;
|
|
1307
|
+
exports.svelteDetector = svelteDetector;
|
|
1308
|
+
exports.sveltekitDetector = sveltekitDetector;
|
|
1309
|
+
exports.vueDetector = vueDetector;
|
|
1310
|
+
//# sourceMappingURL=index.cjs.js.map
|