@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,1982 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var node_path = require('node:path');
|
|
4
|
+
var node_fs = require('node:fs');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Known configuration file patterns organized by type.
|
|
8
|
+
*/
|
|
9
|
+
const CONFIG_PATTERNS = {
|
|
10
|
+
// Package Management
|
|
11
|
+
'package.json': {
|
|
12
|
+
patterns: ['package.json'],
|
|
13
|
+
format: 'json',
|
|
14
|
+
description: 'NPM package manifest',
|
|
15
|
+
},
|
|
16
|
+
'package-lock.json': {
|
|
17
|
+
patterns: ['package-lock.json'],
|
|
18
|
+
format: 'json',
|
|
19
|
+
description: 'NPM lockfile',
|
|
20
|
+
},
|
|
21
|
+
'pnpm-lock.yaml': {
|
|
22
|
+
patterns: ['pnpm-lock.yaml'],
|
|
23
|
+
format: 'yaml',
|
|
24
|
+
description: 'PNPM lockfile',
|
|
25
|
+
},
|
|
26
|
+
'yarn.lock': {
|
|
27
|
+
patterns: ['yarn.lock'],
|
|
28
|
+
format: 'text',
|
|
29
|
+
description: 'Yarn lockfile',
|
|
30
|
+
},
|
|
31
|
+
'.npmrc': {
|
|
32
|
+
patterns: ['.npmrc'],
|
|
33
|
+
format: 'ini',
|
|
34
|
+
description: 'NPM configuration',
|
|
35
|
+
sensitive: true,
|
|
36
|
+
},
|
|
37
|
+
// TypeScript
|
|
38
|
+
tsconfig: {
|
|
39
|
+
patterns: ['tsconfig.json', 'tsconfig.*.json'],
|
|
40
|
+
format: 'jsonc',
|
|
41
|
+
description: 'TypeScript configuration',
|
|
42
|
+
canExtend: true,
|
|
43
|
+
},
|
|
44
|
+
// Monorepo
|
|
45
|
+
nx: {
|
|
46
|
+
patterns: ['nx.json'],
|
|
47
|
+
format: 'json',
|
|
48
|
+
description: 'NX workspace configuration',
|
|
49
|
+
},
|
|
50
|
+
'project.json': {
|
|
51
|
+
patterns: ['project.json', '**/project.json'],
|
|
52
|
+
format: 'json',
|
|
53
|
+
description: 'NX project configuration',
|
|
54
|
+
},
|
|
55
|
+
'workspace.json': {
|
|
56
|
+
patterns: ['workspace.json'],
|
|
57
|
+
format: 'json',
|
|
58
|
+
description: 'NX workspace projects (deprecated)',
|
|
59
|
+
},
|
|
60
|
+
turbo: {
|
|
61
|
+
patterns: ['turbo.json'],
|
|
62
|
+
format: 'jsonc',
|
|
63
|
+
description: 'TurboRepo configuration',
|
|
64
|
+
},
|
|
65
|
+
lerna: {
|
|
66
|
+
patterns: ['lerna.json'],
|
|
67
|
+
format: 'json',
|
|
68
|
+
description: 'Lerna configuration',
|
|
69
|
+
},
|
|
70
|
+
// Build Tools
|
|
71
|
+
webpack: {
|
|
72
|
+
patterns: ['webpack.config.js', 'webpack.config.ts', 'webpack.config.cjs', 'webpack.config.mjs'],
|
|
73
|
+
format: 'js',
|
|
74
|
+
description: 'Webpack configuration',
|
|
75
|
+
},
|
|
76
|
+
rollup: {
|
|
77
|
+
patterns: ['rollup.config.js', 'rollup.config.ts', 'rollup.config.mjs'],
|
|
78
|
+
format: 'js',
|
|
79
|
+
description: 'Rollup configuration',
|
|
80
|
+
},
|
|
81
|
+
vite: {
|
|
82
|
+
patterns: ['vite.config.js', 'vite.config.ts', 'vite.config.mjs'],
|
|
83
|
+
format: 'js',
|
|
84
|
+
description: 'Vite configuration',
|
|
85
|
+
},
|
|
86
|
+
esbuild: {
|
|
87
|
+
patterns: ['esbuild.config.js', 'esbuild.config.ts', 'esbuild.config.mjs'],
|
|
88
|
+
format: 'js',
|
|
89
|
+
description: 'esbuild configuration',
|
|
90
|
+
},
|
|
91
|
+
babel: {
|
|
92
|
+
patterns: ['babel.config.js', 'babel.config.json', '.babelrc', '.babelrc.js', '.babelrc.json'],
|
|
93
|
+
format: 'json',
|
|
94
|
+
description: 'Babel configuration',
|
|
95
|
+
},
|
|
96
|
+
swc: {
|
|
97
|
+
patterns: ['.swcrc'],
|
|
98
|
+
format: 'json',
|
|
99
|
+
description: 'SWC configuration',
|
|
100
|
+
},
|
|
101
|
+
// Testing
|
|
102
|
+
jest: {
|
|
103
|
+
patterns: ['jest.config.js', 'jest.config.ts', 'jest.config.mjs'],
|
|
104
|
+
description: 'Jest configuration',
|
|
105
|
+
},
|
|
106
|
+
vitest: {
|
|
107
|
+
patterns: ['vitest.config.js', 'vitest.config.ts'],
|
|
108
|
+
description: 'Vitest configuration',
|
|
109
|
+
},
|
|
110
|
+
cypress: {
|
|
111
|
+
patterns: ['cypress.config.js', 'cypress.config.ts'],
|
|
112
|
+
description: 'Cypress configuration',
|
|
113
|
+
},
|
|
114
|
+
playwright: {
|
|
115
|
+
patterns: ['playwright.config.js', 'playwright.config.ts'],
|
|
116
|
+
description: 'Playwright configuration',
|
|
117
|
+
},
|
|
118
|
+
// Framework configs
|
|
119
|
+
next: {
|
|
120
|
+
patterns: ['next.config.js', 'next.config.mjs', 'next.config.ts'],
|
|
121
|
+
format: 'js',
|
|
122
|
+
description: 'Next.js configuration',
|
|
123
|
+
},
|
|
124
|
+
angular: {
|
|
125
|
+
patterns: ['angular.json'],
|
|
126
|
+
format: 'json',
|
|
127
|
+
description: 'Angular CLI configuration',
|
|
128
|
+
},
|
|
129
|
+
nuxt: {
|
|
130
|
+
patterns: ['nuxt.config.js', 'nuxt.config.ts'],
|
|
131
|
+
format: 'js',
|
|
132
|
+
description: 'Nuxt.js configuration',
|
|
133
|
+
},
|
|
134
|
+
svelte: {
|
|
135
|
+
patterns: ['svelte.config.js', 'svelte.config.ts'],
|
|
136
|
+
format: 'js',
|
|
137
|
+
description: 'SvelteKit configuration',
|
|
138
|
+
},
|
|
139
|
+
astro: {
|
|
140
|
+
patterns: ['astro.config.js', 'astro.config.ts', 'astro.config.mjs'],
|
|
141
|
+
format: 'js',
|
|
142
|
+
description: 'Astro configuration',
|
|
143
|
+
},
|
|
144
|
+
// Linting & Formatting
|
|
145
|
+
eslint: {
|
|
146
|
+
patterns: [
|
|
147
|
+
'eslint.config.js',
|
|
148
|
+
'eslint.config.cjs',
|
|
149
|
+
'eslint.config.mjs',
|
|
150
|
+
'.eslintrc',
|
|
151
|
+
'.eslintrc.js',
|
|
152
|
+
'.eslintrc.json',
|
|
153
|
+
'.eslintrc.yml',
|
|
154
|
+
],
|
|
155
|
+
format: 'js',
|
|
156
|
+
description: 'ESLint configuration',
|
|
157
|
+
},
|
|
158
|
+
prettier: {
|
|
159
|
+
patterns: ['prettier.config.js', 'prettier.config.cjs', '.prettierrc', '.prettierrc.js', '.prettierrc.json', '.prettierrc.yml'],
|
|
160
|
+
format: 'json',
|
|
161
|
+
description: 'Prettier configuration',
|
|
162
|
+
},
|
|
163
|
+
// Environment (sensitive)
|
|
164
|
+
env: {
|
|
165
|
+
patterns: ['.env', '.env.*', '*.env'],
|
|
166
|
+
format: 'dotenv',
|
|
167
|
+
description: 'Environment variables',
|
|
168
|
+
sensitive: true,
|
|
169
|
+
},
|
|
170
|
+
// Git
|
|
171
|
+
'.gitignore': {
|
|
172
|
+
patterns: ['.gitignore'],
|
|
173
|
+
format: 'text',
|
|
174
|
+
description: 'Git ignore patterns',
|
|
175
|
+
},
|
|
176
|
+
'.gitattributes': {
|
|
177
|
+
patterns: ['.gitattributes'],
|
|
178
|
+
format: 'text',
|
|
179
|
+
description: 'Git attributes',
|
|
180
|
+
},
|
|
181
|
+
};
|
|
182
|
+
/**
|
|
183
|
+
* Get patterns for specific config types.
|
|
184
|
+
*
|
|
185
|
+
* @param types - Array of config types to get patterns for
|
|
186
|
+
* @returns Array of file patterns
|
|
187
|
+
*/
|
|
188
|
+
function getConfigPatternsByType(types) {
|
|
189
|
+
return types.flatMap((type) => CONFIG_PATTERNS[type]?.patterns ?? []);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Safe copies of Object built-in methods.
|
|
194
|
+
*
|
|
195
|
+
* These references are captured at module initialization time to protect against
|
|
196
|
+
* prototype pollution attacks. Import only what you need for tree-shaking.
|
|
197
|
+
*
|
|
198
|
+
* @module @hyperfrontend/immutable-api-utils/built-in-copy/object
|
|
199
|
+
*/
|
|
200
|
+
// Capture references at module initialization time
|
|
201
|
+
const _Object = globalThis.Object;
|
|
202
|
+
/**
|
|
203
|
+
* (Safe copy) Prevents modification of existing property attributes and values,
|
|
204
|
+
* and prevents the addition of new properties.
|
|
205
|
+
*/
|
|
206
|
+
const freeze = _Object.freeze;
|
|
207
|
+
/**
|
|
208
|
+
* (Safe copy) Returns the names of the enumerable string properties and methods of an object.
|
|
209
|
+
*/
|
|
210
|
+
const keys = _Object.keys;
|
|
211
|
+
/**
|
|
212
|
+
* (Safe copy) Returns an array of key/values of the enumerable own properties of an object.
|
|
213
|
+
*/
|
|
214
|
+
const entries = _Object.entries;
|
|
215
|
+
/**
|
|
216
|
+
* (Safe copy) Adds one or more properties to an object, and/or modifies attributes of existing properties.
|
|
217
|
+
*/
|
|
218
|
+
const defineProperties = _Object.defineProperties;
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Safe copies of Map built-in via factory function.
|
|
222
|
+
*
|
|
223
|
+
* Since constructors cannot be safely captured via Object.assign, this module
|
|
224
|
+
* provides a factory function that uses Reflect.construct internally.
|
|
225
|
+
*
|
|
226
|
+
* These references are captured at module initialization time to protect against
|
|
227
|
+
* prototype pollution attacks. Import only what you need for tree-shaking.
|
|
228
|
+
*
|
|
229
|
+
* @module @hyperfrontend/immutable-api-utils/built-in-copy/map
|
|
230
|
+
*/
|
|
231
|
+
// Capture references at module initialization time
|
|
232
|
+
const _Map = globalThis.Map;
|
|
233
|
+
const _Reflect$2 = globalThis.Reflect;
|
|
234
|
+
/**
|
|
235
|
+
* (Safe copy) Creates a new Map using the captured Map constructor.
|
|
236
|
+
* Use this instead of `new Map()`.
|
|
237
|
+
*
|
|
238
|
+
* @param iterable - Optional iterable of key-value pairs.
|
|
239
|
+
* @returns A new Map instance.
|
|
240
|
+
*/
|
|
241
|
+
const createMap = (iterable) => _Reflect$2.construct(_Map, iterable ? [iterable] : []);
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Safe copies of Set built-in via factory function.
|
|
245
|
+
*
|
|
246
|
+
* Since constructors cannot be safely captured via Object.assign, this module
|
|
247
|
+
* provides a factory function that uses Reflect.construct internally.
|
|
248
|
+
*
|
|
249
|
+
* These references are captured at module initialization time to protect against
|
|
250
|
+
* prototype pollution attacks. Import only what you need for tree-shaking.
|
|
251
|
+
*
|
|
252
|
+
* @module @hyperfrontend/immutable-api-utils/built-in-copy/set
|
|
253
|
+
*/
|
|
254
|
+
// Capture references at module initialization time
|
|
255
|
+
const _Set = globalThis.Set;
|
|
256
|
+
const _Reflect$1 = globalThis.Reflect;
|
|
257
|
+
/**
|
|
258
|
+
* (Safe copy) Creates a new Set using the captured Set constructor.
|
|
259
|
+
* Use this instead of `new Set()`.
|
|
260
|
+
*
|
|
261
|
+
* @param iterable - Optional iterable of values.
|
|
262
|
+
* @returns A new Set instance.
|
|
263
|
+
*/
|
|
264
|
+
const createSet = (iterable) => _Reflect$1.construct(_Set, iterable ? [iterable] : []);
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Global registry of all caches for bulk operations.
|
|
268
|
+
*/
|
|
269
|
+
const cacheRegistry = createSet();
|
|
270
|
+
/**
|
|
271
|
+
* Create a cache with optional TTL and size limits.
|
|
272
|
+
*
|
|
273
|
+
* The cache provides a simple key-value store with:
|
|
274
|
+
* - Optional TTL (time-to-live) for automatic expiration
|
|
275
|
+
* - Optional maxSize for limiting cache size with FIFO eviction
|
|
276
|
+
* - Lazy expiration (entries are checked on access)
|
|
277
|
+
*
|
|
278
|
+
* @param options - Cache configuration options
|
|
279
|
+
* @returns Cache instance
|
|
280
|
+
*
|
|
281
|
+
* @example
|
|
282
|
+
* ```typescript
|
|
283
|
+
* // Basic cache
|
|
284
|
+
* const cache = createCache<string, number>()
|
|
285
|
+
* cache.set('answer', 42)
|
|
286
|
+
* cache.get('answer') // 42
|
|
287
|
+
*
|
|
288
|
+
* // Cache with TTL (expires after 60 seconds)
|
|
289
|
+
* const ttlCache = createCache<string, object>({ ttl: 60000 })
|
|
290
|
+
*
|
|
291
|
+
* // Cache with max size (evicts oldest when full)
|
|
292
|
+
* const lruCache = createCache<string, object>({ maxSize: 100 })
|
|
293
|
+
*
|
|
294
|
+
* // Combined options
|
|
295
|
+
* const configCache = createCache<string, object>({
|
|
296
|
+
* ttl: 30000,
|
|
297
|
+
* maxSize: 50
|
|
298
|
+
* })
|
|
299
|
+
* ```
|
|
300
|
+
*/
|
|
301
|
+
function createCache(options) {
|
|
302
|
+
const { ttl, maxSize } = options ?? {};
|
|
303
|
+
const store = createMap();
|
|
304
|
+
// Track insertion order for FIFO eviction
|
|
305
|
+
const insertionOrder = [];
|
|
306
|
+
/**
|
|
307
|
+
* Check if an entry is expired.
|
|
308
|
+
*
|
|
309
|
+
* @param entry - Cache entry to check
|
|
310
|
+
* @returns True if entry is expired
|
|
311
|
+
*/
|
|
312
|
+
function isExpired(entry) {
|
|
313
|
+
if (ttl === undefined)
|
|
314
|
+
return false;
|
|
315
|
+
// eslint-disable-next-line workspace/no-unsafe-builtin-methods -- Date.now() is needed for Jest fake timers compatibility
|
|
316
|
+
return Date.now() - entry.timestamp > ttl;
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Evict oldest entries to make room for new ones.
|
|
320
|
+
*/
|
|
321
|
+
function evictIfNeeded() {
|
|
322
|
+
if (maxSize === undefined)
|
|
323
|
+
return;
|
|
324
|
+
while (store.size >= maxSize && insertionOrder.length > 0) {
|
|
325
|
+
const oldestKey = insertionOrder.shift();
|
|
326
|
+
if (oldestKey !== undefined) {
|
|
327
|
+
store.delete(oldestKey);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Remove key from insertion order tracking.
|
|
333
|
+
*
|
|
334
|
+
* @param key - Key to remove from order tracking
|
|
335
|
+
*/
|
|
336
|
+
function removeFromOrder(key) {
|
|
337
|
+
const index = insertionOrder.indexOf(key);
|
|
338
|
+
if (index !== -1) {
|
|
339
|
+
insertionOrder.splice(index, 1);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
const cache = {
|
|
343
|
+
get(key) {
|
|
344
|
+
const entry = store.get(key);
|
|
345
|
+
if (!entry)
|
|
346
|
+
return undefined;
|
|
347
|
+
if (isExpired(entry)) {
|
|
348
|
+
store.delete(key);
|
|
349
|
+
removeFromOrder(key);
|
|
350
|
+
return undefined;
|
|
351
|
+
}
|
|
352
|
+
return entry.value;
|
|
353
|
+
},
|
|
354
|
+
set(key, value) {
|
|
355
|
+
// If key exists, remove from order first
|
|
356
|
+
if (store.has(key)) {
|
|
357
|
+
removeFromOrder(key);
|
|
358
|
+
}
|
|
359
|
+
else {
|
|
360
|
+
// Evict if needed before adding new entry
|
|
361
|
+
evictIfNeeded();
|
|
362
|
+
}
|
|
363
|
+
// eslint-disable-next-line workspace/no-unsafe-builtin-methods -- Date.now() is needed for Jest fake timers compatibility
|
|
364
|
+
store.set(key, { value, timestamp: Date.now() });
|
|
365
|
+
insertionOrder.push(key);
|
|
366
|
+
},
|
|
367
|
+
has(key) {
|
|
368
|
+
const entry = store.get(key);
|
|
369
|
+
if (!entry)
|
|
370
|
+
return false;
|
|
371
|
+
if (isExpired(entry)) {
|
|
372
|
+
store.delete(key);
|
|
373
|
+
removeFromOrder(key);
|
|
374
|
+
return false;
|
|
375
|
+
}
|
|
376
|
+
return true;
|
|
377
|
+
},
|
|
378
|
+
delete(key) {
|
|
379
|
+
removeFromOrder(key);
|
|
380
|
+
return store.delete(key);
|
|
381
|
+
},
|
|
382
|
+
clear() {
|
|
383
|
+
store.clear();
|
|
384
|
+
insertionOrder.length = 0;
|
|
385
|
+
},
|
|
386
|
+
size() {
|
|
387
|
+
return store.size;
|
|
388
|
+
},
|
|
389
|
+
keys() {
|
|
390
|
+
return [...insertionOrder];
|
|
391
|
+
},
|
|
392
|
+
};
|
|
393
|
+
// Register cache for global operations
|
|
394
|
+
cacheRegistry.add(cache);
|
|
395
|
+
return freeze(cache);
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* Safe copies of Error built-ins via factory functions.
|
|
400
|
+
*
|
|
401
|
+
* Since constructors cannot be safely captured via Object.assign, this module
|
|
402
|
+
* provides factory functions that use Reflect.construct internally.
|
|
403
|
+
*
|
|
404
|
+
* These references are captured at module initialization time to protect against
|
|
405
|
+
* prototype pollution attacks. Import only what you need for tree-shaking.
|
|
406
|
+
*
|
|
407
|
+
* @module @hyperfrontend/immutable-api-utils/built-in-copy/error
|
|
408
|
+
*/
|
|
409
|
+
// Capture references at module initialization time
|
|
410
|
+
const _Error = globalThis.Error;
|
|
411
|
+
const _Reflect = globalThis.Reflect;
|
|
412
|
+
/**
|
|
413
|
+
* (Safe copy) Creates a new Error using the captured Error constructor.
|
|
414
|
+
* Use this instead of `new Error()`.
|
|
415
|
+
*
|
|
416
|
+
* @param message - Optional error message.
|
|
417
|
+
* @param options - Optional error options.
|
|
418
|
+
* @returns A new Error instance.
|
|
419
|
+
*/
|
|
420
|
+
const createError = (message, options) => _Reflect.construct(_Error, [message, options]);
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
* Safe copies of JSON built-in methods.
|
|
424
|
+
*
|
|
425
|
+
* These references are captured at module initialization time to protect against
|
|
426
|
+
* prototype pollution attacks. Import only what you need for tree-shaking.
|
|
427
|
+
*
|
|
428
|
+
* @module @hyperfrontend/immutable-api-utils/built-in-copy/json
|
|
429
|
+
*/
|
|
430
|
+
// Capture references at module initialization time
|
|
431
|
+
const _JSON = globalThis.JSON;
|
|
432
|
+
/**
|
|
433
|
+
* (Safe copy) Converts a JavaScript Object Notation (JSON) string into an object.
|
|
434
|
+
*/
|
|
435
|
+
const parse = _JSON.parse;
|
|
436
|
+
/**
|
|
437
|
+
* (Safe copy) Converts a JavaScript value to a JavaScript Object Notation (JSON) string.
|
|
438
|
+
*/
|
|
439
|
+
const stringify = _JSON.stringify;
|
|
440
|
+
|
|
441
|
+
/**
|
|
442
|
+
* Safe copies of Array built-in static methods.
|
|
443
|
+
*
|
|
444
|
+
* These references are captured at module initialization time to protect against
|
|
445
|
+
* prototype pollution attacks. Import only what you need for tree-shaking.
|
|
446
|
+
*
|
|
447
|
+
* @module @hyperfrontend/immutable-api-utils/built-in-copy/array
|
|
448
|
+
*/
|
|
449
|
+
// Capture references at module initialization time
|
|
450
|
+
const _Array = globalThis.Array;
|
|
451
|
+
/**
|
|
452
|
+
* (Safe copy) Determines whether the passed value is an Array.
|
|
453
|
+
*/
|
|
454
|
+
const isArray = _Array.isArray;
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* Safe copies of Console built-in methods.
|
|
458
|
+
*
|
|
459
|
+
* These references are captured at module initialization time to protect against
|
|
460
|
+
* prototype pollution attacks. Import only what you need for tree-shaking.
|
|
461
|
+
*
|
|
462
|
+
* @module @hyperfrontend/immutable-api-utils/built-in-copy/console
|
|
463
|
+
*/
|
|
464
|
+
// Capture references at module initialization time
|
|
465
|
+
const _console = globalThis.console;
|
|
466
|
+
/**
|
|
467
|
+
* (Safe copy) Outputs a message to the console.
|
|
468
|
+
*/
|
|
469
|
+
const log = _console.log.bind(_console);
|
|
470
|
+
/**
|
|
471
|
+
* (Safe copy) Outputs a warning message to the console.
|
|
472
|
+
*/
|
|
473
|
+
const warn = _console.warn.bind(_console);
|
|
474
|
+
/**
|
|
475
|
+
* (Safe copy) Outputs an error message to the console.
|
|
476
|
+
*/
|
|
477
|
+
const error = _console.error.bind(_console);
|
|
478
|
+
/**
|
|
479
|
+
* (Safe copy) Outputs an informational message to the console.
|
|
480
|
+
*/
|
|
481
|
+
const info = _console.info.bind(_console);
|
|
482
|
+
/**
|
|
483
|
+
* (Safe copy) Outputs a debug message to the console.
|
|
484
|
+
*/
|
|
485
|
+
const debug = _console.debug.bind(_console);
|
|
486
|
+
/**
|
|
487
|
+
* (Safe copy) Outputs a stack trace to the console.
|
|
488
|
+
*/
|
|
489
|
+
_console.trace.bind(_console);
|
|
490
|
+
/**
|
|
491
|
+
* (Safe copy) Displays an interactive listing of the properties of a specified object.
|
|
492
|
+
*/
|
|
493
|
+
_console.dir.bind(_console);
|
|
494
|
+
/**
|
|
495
|
+
* (Safe copy) Displays tabular data as a table.
|
|
496
|
+
*/
|
|
497
|
+
_console.table.bind(_console);
|
|
498
|
+
/**
|
|
499
|
+
* (Safe copy) Writes an error message to the console if the assertion is false.
|
|
500
|
+
*/
|
|
501
|
+
_console.assert.bind(_console);
|
|
502
|
+
/**
|
|
503
|
+
* (Safe copy) Clears the console.
|
|
504
|
+
*/
|
|
505
|
+
_console.clear.bind(_console);
|
|
506
|
+
/**
|
|
507
|
+
* (Safe copy) Logs the number of times that this particular call to count() has been called.
|
|
508
|
+
*/
|
|
509
|
+
_console.count.bind(_console);
|
|
510
|
+
/**
|
|
511
|
+
* (Safe copy) Resets the counter used with console.count().
|
|
512
|
+
*/
|
|
513
|
+
_console.countReset.bind(_console);
|
|
514
|
+
/**
|
|
515
|
+
* (Safe copy) Creates a new inline group in the console.
|
|
516
|
+
*/
|
|
517
|
+
_console.group.bind(_console);
|
|
518
|
+
/**
|
|
519
|
+
* (Safe copy) Creates a new inline group in the console that is initially collapsed.
|
|
520
|
+
*/
|
|
521
|
+
_console.groupCollapsed.bind(_console);
|
|
522
|
+
/**
|
|
523
|
+
* (Safe copy) Exits the current inline group.
|
|
524
|
+
*/
|
|
525
|
+
_console.groupEnd.bind(_console);
|
|
526
|
+
/**
|
|
527
|
+
* (Safe copy) Starts a timer with a name specified as an input parameter.
|
|
528
|
+
*/
|
|
529
|
+
_console.time.bind(_console);
|
|
530
|
+
/**
|
|
531
|
+
* (Safe copy) Stops a timer that was previously started.
|
|
532
|
+
*/
|
|
533
|
+
_console.timeEnd.bind(_console);
|
|
534
|
+
/**
|
|
535
|
+
* (Safe copy) Logs the current value of a timer that was previously started.
|
|
536
|
+
*/
|
|
537
|
+
_console.timeLog.bind(_console);
|
|
538
|
+
|
|
539
|
+
const registeredClasses = [];
|
|
540
|
+
|
|
541
|
+
/**
|
|
542
|
+
* Returns the data type of the target.
|
|
543
|
+
* Uses native `typeof` operator, however, makes distinction between `null`, `array`, and `object`.
|
|
544
|
+
* Also, when classes are registered via `registerClass`, it checks if objects are instance of any known registered class.
|
|
545
|
+
*
|
|
546
|
+
* @param target - The target to get the data type of.
|
|
547
|
+
* @returns The data type of the target.
|
|
548
|
+
*/
|
|
549
|
+
const getType = (target) => {
|
|
550
|
+
if (target === null)
|
|
551
|
+
return 'null';
|
|
552
|
+
const nativeDataType = typeof target;
|
|
553
|
+
if (nativeDataType === 'object') {
|
|
554
|
+
if (isArray(target))
|
|
555
|
+
return 'array';
|
|
556
|
+
for (const registeredClass of registeredClasses) {
|
|
557
|
+
if (target instanceof registeredClass)
|
|
558
|
+
return registeredClass.name;
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
return nativeDataType;
|
|
562
|
+
};
|
|
563
|
+
|
|
564
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
565
|
+
/**
|
|
566
|
+
* Creates a wrapper function that only executes the wrapped function if the condition function returns true.
|
|
567
|
+
*
|
|
568
|
+
* @param func - The function to be conditionally executed.
|
|
569
|
+
* @param conditionFunc - A function that returns a boolean, determining if `func` should be executed.
|
|
570
|
+
* @returns A wrapped version of `func` that executes conditionally.
|
|
571
|
+
*/
|
|
572
|
+
function createConditionalExecutionFunction(func, conditionFunc) {
|
|
573
|
+
return function (...args) {
|
|
574
|
+
if (conditionFunc()) {
|
|
575
|
+
return func(...args);
|
|
576
|
+
}
|
|
577
|
+
};
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
581
|
+
/**
|
|
582
|
+
* Creates a wrapper function that silently ignores any errors thrown by the wrapped void function.
|
|
583
|
+
* This function is specifically for wrapping functions that do not return a value (void functions).
|
|
584
|
+
* Exceptions are swallowed without any logging or handling.
|
|
585
|
+
*
|
|
586
|
+
* @param func - The void function to be wrapped.
|
|
587
|
+
* @returns A wrapped version of the input function that ignores errors.
|
|
588
|
+
*/
|
|
589
|
+
function createErrorIgnoringFunction(func) {
|
|
590
|
+
return function (...args) {
|
|
591
|
+
try {
|
|
592
|
+
func(...args);
|
|
593
|
+
}
|
|
594
|
+
catch {
|
|
595
|
+
// Deliberately swallowing/ignoring the exception
|
|
596
|
+
}
|
|
597
|
+
};
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
601
|
+
/**
|
|
602
|
+
* A no-operation function (noop) that does nothing regardless of the arguments passed.
|
|
603
|
+
* It is designed to be as permissive as possible in its typing without using the `Function` keyword.
|
|
604
|
+
*
|
|
605
|
+
* @param args - Any arguments passed to the function (ignored)
|
|
606
|
+
*/
|
|
607
|
+
const noop = (...args) => {
|
|
608
|
+
// Intentionally does nothing
|
|
609
|
+
};
|
|
610
|
+
|
|
611
|
+
const logLevels = ['none', 'error', 'warn', 'log', 'info', 'debug'];
|
|
612
|
+
const priority = {
|
|
613
|
+
error: 4,
|
|
614
|
+
warn: 3,
|
|
615
|
+
log: 2,
|
|
616
|
+
info: 1,
|
|
617
|
+
debug: 0,
|
|
618
|
+
};
|
|
619
|
+
/**
|
|
620
|
+
* Validates whether a given string is a valid log level.
|
|
621
|
+
*
|
|
622
|
+
* @param level - The log level to validate
|
|
623
|
+
* @returns True if the level is valid, false otherwise
|
|
624
|
+
*/
|
|
625
|
+
function isValidLogLevel(level) {
|
|
626
|
+
return logLevels.includes(level);
|
|
627
|
+
}
|
|
628
|
+
/**
|
|
629
|
+
* Creates a log level configuration manager for controlling logging behavior.
|
|
630
|
+
* Provides methods to get, set, and evaluate log levels based on priority.
|
|
631
|
+
*
|
|
632
|
+
* @param level - The initial log level (defaults to 'error')
|
|
633
|
+
* @returns A configuration object with log level management methods
|
|
634
|
+
* @throws {Error} When the provided level is not a valid log level
|
|
635
|
+
*/
|
|
636
|
+
function createLogLevelConfig(level = 'error') {
|
|
637
|
+
if (!isValidLogLevel(level)) {
|
|
638
|
+
throw createError('Cannot create log level configuration with a valid default log level');
|
|
639
|
+
}
|
|
640
|
+
const state = { level };
|
|
641
|
+
const getLogLevel = () => state.level;
|
|
642
|
+
const setLogLevel = (level) => {
|
|
643
|
+
if (!isValidLogLevel(level)) {
|
|
644
|
+
throw createError(`Cannot set value '${level}' level. Expected levels are ${logLevels}.`);
|
|
645
|
+
}
|
|
646
|
+
state.level = level;
|
|
647
|
+
};
|
|
648
|
+
const shouldLog = (level) => {
|
|
649
|
+
if (state.level === 'none' || level === 'none' || !isValidLogLevel(level)) {
|
|
650
|
+
return false;
|
|
651
|
+
}
|
|
652
|
+
return priority[level] >= priority[state.level];
|
|
653
|
+
};
|
|
654
|
+
return freeze({
|
|
655
|
+
getLogLevel,
|
|
656
|
+
setLogLevel,
|
|
657
|
+
shouldLog,
|
|
658
|
+
});
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
/**
|
|
662
|
+
* Creates a logger instance with configurable log level filtering.
|
|
663
|
+
* Each log function is wrapped to respect the current log level setting.
|
|
664
|
+
*
|
|
665
|
+
* @param error - Function to handle error-level logs (required)
|
|
666
|
+
* @param warn - Function to handle warning-level logs (optional, defaults to noop)
|
|
667
|
+
* @param log - Function to handle standard logs (optional, defaults to noop)
|
|
668
|
+
* @param info - Function to handle info-level logs (optional, defaults to noop)
|
|
669
|
+
* @param debug - Function to handle debug-level logs (optional, defaults to noop)
|
|
670
|
+
* @returns A frozen logger object with log methods and level control
|
|
671
|
+
* @throws {ErrorLevelFn} When any provided log function is invalid
|
|
672
|
+
*/
|
|
673
|
+
function createLogger(error, warn = noop, log = noop, info = noop, debug = noop) {
|
|
674
|
+
if (notValidLogFn(error)) {
|
|
675
|
+
throw createError(notFnMsg('error'));
|
|
676
|
+
}
|
|
677
|
+
if (notValidLogFn(warn)) {
|
|
678
|
+
throw createError(notFnMsg('warn'));
|
|
679
|
+
}
|
|
680
|
+
if (notValidLogFn(log)) {
|
|
681
|
+
throw createError(notFnMsg('log'));
|
|
682
|
+
}
|
|
683
|
+
if (notValidLogFn(info)) {
|
|
684
|
+
throw createError(notFnMsg('info'));
|
|
685
|
+
}
|
|
686
|
+
if (notValidLogFn(debug)) {
|
|
687
|
+
throw createError(notFnMsg('debug'));
|
|
688
|
+
}
|
|
689
|
+
const { setLogLevel, getLogLevel, shouldLog } = createLogLevelConfig();
|
|
690
|
+
const wrapLogFn = (fn, level) => {
|
|
691
|
+
if (fn === noop)
|
|
692
|
+
return fn;
|
|
693
|
+
const condition = () => shouldLog(level);
|
|
694
|
+
return createConditionalExecutionFunction(createErrorIgnoringFunction(fn), condition);
|
|
695
|
+
};
|
|
696
|
+
return freeze({
|
|
697
|
+
error: wrapLogFn(error, 'error'),
|
|
698
|
+
warn: wrapLogFn(warn, 'warn'),
|
|
699
|
+
log: wrapLogFn(log, 'log'),
|
|
700
|
+
info: wrapLogFn(info, 'info'),
|
|
701
|
+
debug: wrapLogFn(debug, 'debug'),
|
|
702
|
+
setLogLevel,
|
|
703
|
+
getLogLevel,
|
|
704
|
+
});
|
|
705
|
+
}
|
|
706
|
+
/**
|
|
707
|
+
* Validates whether a given value is a valid log function.
|
|
708
|
+
*
|
|
709
|
+
* @param fn - The value to validate
|
|
710
|
+
* @returns True if the value is not a function (invalid), false if it is valid
|
|
711
|
+
*/
|
|
712
|
+
function notValidLogFn(fn) {
|
|
713
|
+
return getType(fn) !== 'function' && fn !== noop;
|
|
714
|
+
}
|
|
715
|
+
/**
|
|
716
|
+
* Generates an error message for invalid log function parameters.
|
|
717
|
+
*
|
|
718
|
+
* @param label - The name of the log function that failed validation
|
|
719
|
+
* @returns A formatted error message string
|
|
720
|
+
*/
|
|
721
|
+
function notFnMsg(label) {
|
|
722
|
+
return `Cannot create a logger when ${label} is not a function`;
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
createLogger(error, warn, log, info, debug);
|
|
726
|
+
|
|
727
|
+
/**
|
|
728
|
+
* Global log level registry.
|
|
729
|
+
* Tracks all created scoped loggers to allow global log level changes.
|
|
730
|
+
*/
|
|
731
|
+
const loggerRegistry = createSet();
|
|
732
|
+
/** Redacted placeholder for sensitive values */
|
|
733
|
+
const REDACTED = '[REDACTED]';
|
|
734
|
+
/**
|
|
735
|
+
* Patterns that indicate a sensitive key name.
|
|
736
|
+
* Keys containing these patterns will have their values sanitized.
|
|
737
|
+
*/
|
|
738
|
+
const SENSITIVE_KEY_PATTERNS = [
|
|
739
|
+
/token/i,
|
|
740
|
+
/key/i,
|
|
741
|
+
/password/i,
|
|
742
|
+
/secret/i,
|
|
743
|
+
/credential/i,
|
|
744
|
+
/auth/i,
|
|
745
|
+
/bearer/i,
|
|
746
|
+
/api[_-]?key/i,
|
|
747
|
+
/private/i,
|
|
748
|
+
/passphrase/i,
|
|
749
|
+
];
|
|
750
|
+
/**
|
|
751
|
+
* Checks if a key name indicates sensitive data.
|
|
752
|
+
*
|
|
753
|
+
* @param key - Key name to check
|
|
754
|
+
* @returns True if the key indicates sensitive data
|
|
755
|
+
*/
|
|
756
|
+
function isSensitiveKey(key) {
|
|
757
|
+
return SENSITIVE_KEY_PATTERNS.some((pattern) => pattern.test(key));
|
|
758
|
+
}
|
|
759
|
+
/**
|
|
760
|
+
* Sanitizes an object by replacing sensitive values with REDACTED.
|
|
761
|
+
* This function recursively processes nested objects and arrays.
|
|
762
|
+
*
|
|
763
|
+
* @param obj - Object to sanitize
|
|
764
|
+
* @returns New object with sensitive values redacted
|
|
765
|
+
*/
|
|
766
|
+
function sanitize(obj) {
|
|
767
|
+
if (obj === null || obj === undefined) {
|
|
768
|
+
return obj;
|
|
769
|
+
}
|
|
770
|
+
if (isArray(obj)) {
|
|
771
|
+
return obj.map((item) => sanitize(item));
|
|
772
|
+
}
|
|
773
|
+
if (typeof obj === 'object') {
|
|
774
|
+
const result = {};
|
|
775
|
+
for (const [key, value] of entries(obj)) {
|
|
776
|
+
if (isSensitiveKey(key)) {
|
|
777
|
+
result[key] = REDACTED;
|
|
778
|
+
}
|
|
779
|
+
else if (typeof value === 'object' && value !== null) {
|
|
780
|
+
result[key] = sanitize(value);
|
|
781
|
+
}
|
|
782
|
+
else {
|
|
783
|
+
result[key] = value;
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
return result;
|
|
787
|
+
}
|
|
788
|
+
return obj;
|
|
789
|
+
}
|
|
790
|
+
/**
|
|
791
|
+
* Formats a log message with optional metadata.
|
|
792
|
+
*
|
|
793
|
+
* @param namespace - Logger namespace prefix
|
|
794
|
+
* @param message - Log message
|
|
795
|
+
* @param meta - Optional metadata object
|
|
796
|
+
* @returns Formatted log string
|
|
797
|
+
*/
|
|
798
|
+
function formatMessage(namespace, message, meta) {
|
|
799
|
+
const prefix = `[${namespace}]`;
|
|
800
|
+
if (meta && keys(meta).length > 0) {
|
|
801
|
+
const sanitizedMeta = sanitize(meta);
|
|
802
|
+
return `${prefix} ${message} ${stringify(sanitizedMeta)}`;
|
|
803
|
+
}
|
|
804
|
+
return `${prefix} ${message}`;
|
|
805
|
+
}
|
|
806
|
+
/**
|
|
807
|
+
* Creates a scoped logger with namespace prefix and optional secret sanitization.
|
|
808
|
+
* All log messages will be prefixed with [namespace] and sensitive metadata
|
|
809
|
+
* values will be automatically redacted.
|
|
810
|
+
*
|
|
811
|
+
* @param namespace - Logger namespace (e.g., 'project-scope', 'analyze')
|
|
812
|
+
* @param options - Logger configuration options
|
|
813
|
+
* @returns A configured scoped logger instance
|
|
814
|
+
*
|
|
815
|
+
* @example
|
|
816
|
+
* ```typescript
|
|
817
|
+
* const logger = createScopedLogger('project-scope')
|
|
818
|
+
* logger.setLogLevel('debug')
|
|
819
|
+
*
|
|
820
|
+
* // Basic logging
|
|
821
|
+
* logger.info('Starting analysis', { path: './project' })
|
|
822
|
+
*
|
|
823
|
+
* // Sensitive data is automatically redacted
|
|
824
|
+
* logger.debug('Config loaded', { apiKey: 'secret123' })
|
|
825
|
+
* // Output: [project-scope] Config loaded {"apiKey":"[REDACTED]"}
|
|
826
|
+
* ```
|
|
827
|
+
*/
|
|
828
|
+
function createScopedLogger(namespace, options = {}) {
|
|
829
|
+
const { level = 'error', sanitizeSecrets = true } = options;
|
|
830
|
+
// Create wrapper functions that add namespace prefix and sanitization
|
|
831
|
+
const createLogFn = (baseFn) => (message, meta) => {
|
|
832
|
+
const processedMeta = sanitizeSecrets && meta ? sanitize(meta) : meta;
|
|
833
|
+
baseFn(formatMessage(namespace, message, processedMeta));
|
|
834
|
+
};
|
|
835
|
+
// Create base logger with wrapped functions
|
|
836
|
+
const baseLogger = createLogger(createLogFn(error), createLogFn(warn), createLogFn(log), createLogFn(info), createLogFn(debug));
|
|
837
|
+
// Set initial log level (use global override if set)
|
|
838
|
+
baseLogger.setLogLevel(level);
|
|
839
|
+
const scopedLogger = freeze({
|
|
840
|
+
error: (message, meta) => baseLogger.error(message, meta),
|
|
841
|
+
warn: (message, meta) => baseLogger.warn(message, meta),
|
|
842
|
+
log: (message, meta) => baseLogger.log(message, meta),
|
|
843
|
+
info: (message, meta) => baseLogger.info(message, meta),
|
|
844
|
+
debug: (message, meta) => baseLogger.debug(message, meta),
|
|
845
|
+
setLogLevel: baseLogger.setLogLevel,
|
|
846
|
+
getLogLevel: baseLogger.getLogLevel,
|
|
847
|
+
});
|
|
848
|
+
// Register logger for global level management
|
|
849
|
+
loggerRegistry.add(scopedLogger);
|
|
850
|
+
return scopedLogger;
|
|
851
|
+
}
|
|
852
|
+
/**
|
|
853
|
+
* Default logger instance for the project-scope library.
|
|
854
|
+
* Use this for general logging within the library.
|
|
855
|
+
*
|
|
856
|
+
* @example
|
|
857
|
+
* ```typescript
|
|
858
|
+
* import { logger } from '@hyperfrontend/project-scope/core'
|
|
859
|
+
*
|
|
860
|
+
* logger.setLogLevel('debug')
|
|
861
|
+
* logger.debug('Analyzing project', { path: './src' })
|
|
862
|
+
* ```
|
|
863
|
+
*/
|
|
864
|
+
createScopedLogger('project-scope');
|
|
865
|
+
|
|
866
|
+
const fsLogger = createScopedLogger('project-scope:fs');
|
|
867
|
+
/**
|
|
868
|
+
* Create a file system error with code and context.
|
|
869
|
+
*
|
|
870
|
+
* @param message - The error message describing what went wrong
|
|
871
|
+
* @param code - The category code for this type of filesystem failure
|
|
872
|
+
* @param context - Additional context including path, operation, and cause
|
|
873
|
+
* @returns A configured Error object with code and context properties
|
|
874
|
+
*/
|
|
875
|
+
function createFileSystemError(message, code, context) {
|
|
876
|
+
const error = createError(message);
|
|
877
|
+
defineProperties(error, {
|
|
878
|
+
code: { value: code, enumerable: true },
|
|
879
|
+
context: { value: context, enumerable: true },
|
|
880
|
+
});
|
|
881
|
+
return error;
|
|
882
|
+
}
|
|
883
|
+
/**
|
|
884
|
+
* Read file contents as string.
|
|
885
|
+
*
|
|
886
|
+
* @param filePath - Path to file
|
|
887
|
+
* @param encoding - File encoding (default: utf-8)
|
|
888
|
+
* @returns File contents as string
|
|
889
|
+
* @throws {Error} If file doesn't exist or can't be read
|
|
890
|
+
*
|
|
891
|
+
* @example
|
|
892
|
+
* ```typescript
|
|
893
|
+
* import { readFileContent } from '@hyperfrontend/project-scope'
|
|
894
|
+
*
|
|
895
|
+
* const content = readFileContent('./package.json')
|
|
896
|
+
* console.log(content) // JSON string
|
|
897
|
+
* ```
|
|
898
|
+
*/
|
|
899
|
+
function readFileContent(filePath, encoding = 'utf-8') {
|
|
900
|
+
if (!node_fs.existsSync(filePath)) {
|
|
901
|
+
fsLogger.debug('File not found', { path: filePath });
|
|
902
|
+
throw createFileSystemError(`File not found: ${filePath}`, 'FS_NOT_FOUND', { path: filePath, operation: 'read' });
|
|
903
|
+
}
|
|
904
|
+
try {
|
|
905
|
+
return node_fs.readFileSync(filePath, { encoding });
|
|
906
|
+
}
|
|
907
|
+
catch (error) {
|
|
908
|
+
fsLogger.warn('Failed to read file', { path: filePath });
|
|
909
|
+
throw createFileSystemError(`Failed to read file: ${filePath}`, 'FS_READ_ERROR', { path: filePath, operation: 'read', cause: error });
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
/**
|
|
913
|
+
* Read file if exists, return null otherwise.
|
|
914
|
+
*
|
|
915
|
+
* @param filePath - Path to file
|
|
916
|
+
* @param encoding - File encoding (default: utf-8)
|
|
917
|
+
* @returns File contents or null if file doesn't exist
|
|
918
|
+
*/
|
|
919
|
+
function readFileIfExists(filePath, encoding = 'utf-8') {
|
|
920
|
+
if (!node_fs.existsSync(filePath)) {
|
|
921
|
+
return null;
|
|
922
|
+
}
|
|
923
|
+
try {
|
|
924
|
+
return node_fs.readFileSync(filePath, { encoding });
|
|
925
|
+
}
|
|
926
|
+
catch {
|
|
927
|
+
return null;
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
createScopedLogger('project-scope:fs:write');
|
|
932
|
+
|
|
933
|
+
/**
|
|
934
|
+
* Get file stats with error handling.
|
|
935
|
+
*
|
|
936
|
+
* @param filePath - Path to file
|
|
937
|
+
* @param followSymlinks - Whether to follow symlinks (default: true)
|
|
938
|
+
* @returns File stats or null if path doesn't exist
|
|
939
|
+
*/
|
|
940
|
+
function getFileStat(filePath, followSymlinks = true) {
|
|
941
|
+
if (!node_fs.existsSync(filePath)) {
|
|
942
|
+
return null;
|
|
943
|
+
}
|
|
944
|
+
try {
|
|
945
|
+
const stat = followSymlinks ? node_fs.statSync(filePath) : node_fs.lstatSync(filePath);
|
|
946
|
+
return {
|
|
947
|
+
isFile: stat.isFile(),
|
|
948
|
+
isDirectory: stat.isDirectory(),
|
|
949
|
+
isSymlink: stat.isSymbolicLink(),
|
|
950
|
+
size: stat.size,
|
|
951
|
+
created: stat.birthtime,
|
|
952
|
+
modified: stat.mtime,
|
|
953
|
+
accessed: stat.atime,
|
|
954
|
+
mode: stat.mode,
|
|
955
|
+
};
|
|
956
|
+
}
|
|
957
|
+
catch {
|
|
958
|
+
return null;
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
/**
|
|
962
|
+
* Check if path is a directory.
|
|
963
|
+
*
|
|
964
|
+
* @param dirPath - Path to check
|
|
965
|
+
* @returns True if path is a directory
|
|
966
|
+
*/
|
|
967
|
+
function isDirectory(dirPath) {
|
|
968
|
+
const stats = getFileStat(dirPath);
|
|
969
|
+
return stats?.isDirectory ?? false;
|
|
970
|
+
}
|
|
971
|
+
/**
|
|
972
|
+
* Check if path exists.
|
|
973
|
+
*
|
|
974
|
+
* @param filePath - Path to check
|
|
975
|
+
* @returns True if path exists
|
|
976
|
+
*/
|
|
977
|
+
function exists(filePath) {
|
|
978
|
+
return node_fs.existsSync(filePath);
|
|
979
|
+
}
|
|
980
|
+
|
|
981
|
+
const fsDirLogger = createScopedLogger('project-scope:fs:dir');
|
|
982
|
+
/**
|
|
983
|
+
* List immediate contents of a directory.
|
|
984
|
+
*
|
|
985
|
+
* @param dirPath - Absolute or relative path to the directory
|
|
986
|
+
* @returns Array of entries with metadata for each file/directory
|
|
987
|
+
* @throws {Error} If directory doesn't exist or isn't a directory
|
|
988
|
+
*
|
|
989
|
+
* @example
|
|
990
|
+
* ```typescript
|
|
991
|
+
* import { readDirectory } from '@hyperfrontend/project-scope'
|
|
992
|
+
*
|
|
993
|
+
* const entries = readDirectory('./src')
|
|
994
|
+
* for (const entry of entries) {
|
|
995
|
+
* console.log(entry.name, entry.isFile ? 'file' : 'directory')
|
|
996
|
+
* }
|
|
997
|
+
* ```
|
|
998
|
+
*/
|
|
999
|
+
function readDirectory(dirPath) {
|
|
1000
|
+
fsDirLogger.debug('Reading directory', { path: dirPath });
|
|
1001
|
+
if (!node_fs.existsSync(dirPath)) {
|
|
1002
|
+
fsDirLogger.debug('Directory not found', { path: dirPath });
|
|
1003
|
+
throw createFileSystemError(`Directory not found: ${dirPath}`, 'FS_NOT_FOUND', { path: dirPath, operation: 'readdir' });
|
|
1004
|
+
}
|
|
1005
|
+
if (!isDirectory(dirPath)) {
|
|
1006
|
+
fsDirLogger.debug('Path is not a directory', { path: dirPath });
|
|
1007
|
+
throw createFileSystemError(`Not a directory: ${dirPath}`, 'FS_NOT_A_DIRECTORY', { path: dirPath, operation: 'readdir' });
|
|
1008
|
+
}
|
|
1009
|
+
try {
|
|
1010
|
+
const entries = node_fs.readdirSync(dirPath, { withFileTypes: true });
|
|
1011
|
+
fsDirLogger.debug('Directory read complete', { path: dirPath, entryCount: entries.length });
|
|
1012
|
+
return entries.map((entry) => ({
|
|
1013
|
+
name: entry.name,
|
|
1014
|
+
path: node_path.join(dirPath, entry.name),
|
|
1015
|
+
isFile: entry.isFile(),
|
|
1016
|
+
isDirectory: entry.isDirectory(),
|
|
1017
|
+
isSymlink: entry.isSymbolicLink(),
|
|
1018
|
+
}));
|
|
1019
|
+
}
|
|
1020
|
+
catch (error) {
|
|
1021
|
+
fsDirLogger.warn('Failed to read directory', { path: dirPath, error: error instanceof Error ? error.message : String(error) });
|
|
1022
|
+
throw createFileSystemError(`Failed to read directory: ${dirPath}`, 'FS_READ_ERROR', {
|
|
1023
|
+
path: dirPath,
|
|
1024
|
+
operation: 'readdir',
|
|
1025
|
+
cause: error,
|
|
1026
|
+
});
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
|
|
1030
|
+
createScopedLogger('project-scope:fs:traversal');
|
|
1031
|
+
|
|
1032
|
+
/**
|
|
1033
|
+
* Pattern matching utilities with ReDoS protection.
|
|
1034
|
+
* Uses character-by-character matching instead of regex where possible.
|
|
1035
|
+
*/
|
|
1036
|
+
/**
|
|
1037
|
+
* Match path against glob pattern using safe character iteration.
|
|
1038
|
+
* Avoids regex to prevent ReDoS attacks.
|
|
1039
|
+
*
|
|
1040
|
+
* Supported patterns:
|
|
1041
|
+
* - * matches any characters except /
|
|
1042
|
+
* - ** matches any characters including /
|
|
1043
|
+
* - ? matches exactly one character except /
|
|
1044
|
+
* - {a,b,c} matches any of the alternatives
|
|
1045
|
+
*
|
|
1046
|
+
* @param path - The filesystem path to test against the pattern
|
|
1047
|
+
* @param pattern - The glob pattern to match against
|
|
1048
|
+
* @returns True if path matches pattern
|
|
1049
|
+
*
|
|
1050
|
+
* @example
|
|
1051
|
+
* ```typescript
|
|
1052
|
+
* import { matchGlobPattern } from '@hyperfrontend/project-scope'
|
|
1053
|
+
*
|
|
1054
|
+
* matchGlobPattern('src/utils/helper.ts', '\*\*\/*.ts') // true
|
|
1055
|
+
* matchGlobPattern('test.spec.ts', '\*.spec.ts') // true
|
|
1056
|
+
* matchGlobPattern('config.json', '\*.{json,yaml}') // true
|
|
1057
|
+
* matchGlobPattern('src/index.ts', 'src/\*.ts') // true
|
|
1058
|
+
* ```
|
|
1059
|
+
*/
|
|
1060
|
+
function matchGlobPattern(path, pattern) {
|
|
1061
|
+
return matchSegments(path.split('/'), pattern.split('/'), 0, 0);
|
|
1062
|
+
}
|
|
1063
|
+
/**
|
|
1064
|
+
* Internal recursive function to match path segments against pattern segments.
|
|
1065
|
+
*
|
|
1066
|
+
* @param pathParts - Array of path segments split by '/'
|
|
1067
|
+
* @param patternParts - Array of pattern segments split by '/'
|
|
1068
|
+
* @param pathIdx - Current index in pathParts being examined
|
|
1069
|
+
* @param patternIdx - Current index in patternParts being examined
|
|
1070
|
+
* @returns True if remaining segments match
|
|
1071
|
+
*/
|
|
1072
|
+
function matchSegments(pathParts, patternParts, pathIdx, patternIdx) {
|
|
1073
|
+
// Base cases
|
|
1074
|
+
if (pathIdx === pathParts.length && patternIdx === patternParts.length) {
|
|
1075
|
+
return true; // Both exhausted = match
|
|
1076
|
+
}
|
|
1077
|
+
if (patternIdx >= patternParts.length) {
|
|
1078
|
+
return false; // Pattern exhausted but path remains
|
|
1079
|
+
}
|
|
1080
|
+
const patternPart = patternParts[patternIdx];
|
|
1081
|
+
// Handle ** (globstar) - matches zero or more directories
|
|
1082
|
+
if (patternPart === '**') {
|
|
1083
|
+
// Try matching rest of pattern against current position and all future positions
|
|
1084
|
+
for (let i = pathIdx; i <= pathParts.length; i++) {
|
|
1085
|
+
if (matchSegments(pathParts, patternParts, i, patternIdx + 1)) {
|
|
1086
|
+
return true;
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
return false;
|
|
1090
|
+
}
|
|
1091
|
+
if (pathIdx >= pathParts.length) {
|
|
1092
|
+
return false; // Path exhausted but pattern remains (and it's not **)
|
|
1093
|
+
}
|
|
1094
|
+
const pathPart = pathParts[pathIdx];
|
|
1095
|
+
// Match current segment
|
|
1096
|
+
if (matchSegment(pathPart, patternPart)) {
|
|
1097
|
+
return matchSegments(pathParts, patternParts, pathIdx + 1, patternIdx + 1);
|
|
1098
|
+
}
|
|
1099
|
+
return false;
|
|
1100
|
+
}
|
|
1101
|
+
/**
|
|
1102
|
+
* Match a single path segment against a pattern segment.
|
|
1103
|
+
* Handles *, ?, and {a,b,c} patterns.
|
|
1104
|
+
*
|
|
1105
|
+
* @param text - The path segment text to match
|
|
1106
|
+
* @param pattern - The pattern segment to match against
|
|
1107
|
+
* @returns True if the text matches the pattern
|
|
1108
|
+
*/
|
|
1109
|
+
function matchSegment(text, pattern) {
|
|
1110
|
+
let textIdx = 0;
|
|
1111
|
+
let patternIdx = 0;
|
|
1112
|
+
while (patternIdx < pattern.length) {
|
|
1113
|
+
const char = pattern[patternIdx];
|
|
1114
|
+
if (char === '*') {
|
|
1115
|
+
// * matches zero or more characters
|
|
1116
|
+
patternIdx++;
|
|
1117
|
+
if (patternIdx === pattern.length) {
|
|
1118
|
+
return true; // * at end matches rest of string
|
|
1119
|
+
}
|
|
1120
|
+
// Try matching rest of pattern at each position in text
|
|
1121
|
+
for (let i = textIdx; i <= text.length; i++) {
|
|
1122
|
+
if (matchSegmentFrom(text, i, pattern, patternIdx)) {
|
|
1123
|
+
return true;
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
return false;
|
|
1127
|
+
}
|
|
1128
|
+
else if (char === '?') {
|
|
1129
|
+
// ? matches exactly one character
|
|
1130
|
+
if (textIdx >= text.length) {
|
|
1131
|
+
return false;
|
|
1132
|
+
}
|
|
1133
|
+
textIdx++;
|
|
1134
|
+
patternIdx++;
|
|
1135
|
+
}
|
|
1136
|
+
else if (char === '{') {
|
|
1137
|
+
// {a,b,c} matches any alternative
|
|
1138
|
+
const closeIdx = findClosingBrace(pattern, patternIdx);
|
|
1139
|
+
if (closeIdx === -1) {
|
|
1140
|
+
// Unmatched brace, treat as literal
|
|
1141
|
+
if (textIdx >= text.length || text[textIdx] !== char) {
|
|
1142
|
+
return false;
|
|
1143
|
+
}
|
|
1144
|
+
textIdx++;
|
|
1145
|
+
patternIdx++;
|
|
1146
|
+
}
|
|
1147
|
+
else {
|
|
1148
|
+
const alternatives = extractAlternatives(pattern.slice(patternIdx + 1, closeIdx));
|
|
1149
|
+
for (const alt of alternatives) {
|
|
1150
|
+
if (matchSegmentFrom(text, textIdx, text.slice(0, textIdx) + alt + pattern.slice(closeIdx + 1), textIdx)) {
|
|
1151
|
+
return true;
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
return false;
|
|
1155
|
+
}
|
|
1156
|
+
}
|
|
1157
|
+
else {
|
|
1158
|
+
// Literal character
|
|
1159
|
+
if (textIdx >= text.length || text[textIdx] !== char) {
|
|
1160
|
+
return false;
|
|
1161
|
+
}
|
|
1162
|
+
textIdx++;
|
|
1163
|
+
patternIdx++;
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
return textIdx === text.length;
|
|
1167
|
+
}
|
|
1168
|
+
/**
|
|
1169
|
+
* Helper to match from a specific position.
|
|
1170
|
+
*
|
|
1171
|
+
* @param text - The full text being matched
|
|
1172
|
+
* @param textIdx - The starting index in text to match from
|
|
1173
|
+
* @param pattern - The full pattern being matched
|
|
1174
|
+
* @param patternIdx - The starting index in pattern to match from
|
|
1175
|
+
* @returns True if the text matches the pattern from the given positions
|
|
1176
|
+
*/
|
|
1177
|
+
function matchSegmentFrom(text, textIdx, pattern, patternIdx) {
|
|
1178
|
+
const remainingText = text.slice(textIdx);
|
|
1179
|
+
const remainingPattern = pattern.slice(patternIdx);
|
|
1180
|
+
return matchSegment(remainingText, remainingPattern);
|
|
1181
|
+
}
|
|
1182
|
+
/**
|
|
1183
|
+
* Find closing brace for {a,b,c} pattern.
|
|
1184
|
+
*
|
|
1185
|
+
* @param pattern - The pattern string to search within
|
|
1186
|
+
* @param startIdx - The index of the opening brace
|
|
1187
|
+
* @returns The index of the matching closing brace, or -1 if not found
|
|
1188
|
+
*/
|
|
1189
|
+
function findClosingBrace(pattern, startIdx) {
|
|
1190
|
+
let depth = 0;
|
|
1191
|
+
for (let i = startIdx; i < pattern.length; i++) {
|
|
1192
|
+
if (pattern[i] === '{') {
|
|
1193
|
+
depth++;
|
|
1194
|
+
}
|
|
1195
|
+
else if (pattern[i] === '}') {
|
|
1196
|
+
depth--;
|
|
1197
|
+
if (depth === 0) {
|
|
1198
|
+
return i;
|
|
1199
|
+
}
|
|
1200
|
+
}
|
|
1201
|
+
}
|
|
1202
|
+
return -1;
|
|
1203
|
+
}
|
|
1204
|
+
/**
|
|
1205
|
+
* Extract alternatives from {a,b,c} pattern content.
|
|
1206
|
+
*
|
|
1207
|
+
* @param content - The content between braces (without the braces themselves)
|
|
1208
|
+
* @returns Array of alternative strings split by commas at depth 0
|
|
1209
|
+
*/
|
|
1210
|
+
function extractAlternatives(content) {
|
|
1211
|
+
const alternatives = [];
|
|
1212
|
+
let current = '';
|
|
1213
|
+
let depth = 0;
|
|
1214
|
+
for (let i = 0; i < content.length; i++) {
|
|
1215
|
+
const char = content[i];
|
|
1216
|
+
if (char === '{') {
|
|
1217
|
+
depth++;
|
|
1218
|
+
current += char;
|
|
1219
|
+
}
|
|
1220
|
+
else if (char === '}') {
|
|
1221
|
+
depth--;
|
|
1222
|
+
current += char;
|
|
1223
|
+
}
|
|
1224
|
+
else if (char === ',' && depth === 0) {
|
|
1225
|
+
alternatives.push(current);
|
|
1226
|
+
current = '';
|
|
1227
|
+
}
|
|
1228
|
+
else {
|
|
1229
|
+
current += char;
|
|
1230
|
+
}
|
|
1231
|
+
}
|
|
1232
|
+
if (current) {
|
|
1233
|
+
alternatives.push(current);
|
|
1234
|
+
}
|
|
1235
|
+
return alternatives;
|
|
1236
|
+
}
|
|
1237
|
+
|
|
1238
|
+
const walkLogger = createScopedLogger('project-scope:project:walk');
|
|
1239
|
+
/**
|
|
1240
|
+
* Reads .gitignore file from the given directory and extracts
|
|
1241
|
+
* non-comment patterns for use in file traversal filtering.
|
|
1242
|
+
*
|
|
1243
|
+
* @param startPath - Directory containing the .gitignore file
|
|
1244
|
+
* @returns Array of gitignore patterns
|
|
1245
|
+
*/
|
|
1246
|
+
function loadGitignorePatterns(startPath) {
|
|
1247
|
+
const patterns = [];
|
|
1248
|
+
const gitignorePath = node_path.join(startPath, '.gitignore');
|
|
1249
|
+
const content = readFileIfExists(gitignorePath);
|
|
1250
|
+
if (content) {
|
|
1251
|
+
const lines = content.split('\n');
|
|
1252
|
+
for (const line of lines) {
|
|
1253
|
+
const trimmed = line.trim();
|
|
1254
|
+
if (trimmed && !trimmed.startsWith('#')) {
|
|
1255
|
+
patterns.push(trimmed);
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1259
|
+
return patterns;
|
|
1260
|
+
}
|
|
1261
|
+
/**
|
|
1262
|
+
* Evaluates whether a relative path should be ignored based on
|
|
1263
|
+
* a list of gitignore-style patterns.
|
|
1264
|
+
*
|
|
1265
|
+
* @param relativePath - Path relative to the root directory
|
|
1266
|
+
* @param patterns - Array of gitignore-style patterns to test
|
|
1267
|
+
* @returns True if the path matches any ignore pattern
|
|
1268
|
+
*/
|
|
1269
|
+
function matchesIgnorePattern(relativePath, patterns) {
|
|
1270
|
+
for (const pattern of patterns) {
|
|
1271
|
+
if (matchPattern(relativePath, pattern)) {
|
|
1272
|
+
return true;
|
|
1273
|
+
}
|
|
1274
|
+
}
|
|
1275
|
+
return false;
|
|
1276
|
+
}
|
|
1277
|
+
/**
|
|
1278
|
+
* Tests if the given path matches a gitignore-style pattern,
|
|
1279
|
+
* supporting negation patterns with '!' prefix.
|
|
1280
|
+
* Uses safe character-by-character matching to prevent ReDoS attacks.
|
|
1281
|
+
*
|
|
1282
|
+
* @param path - File or directory path to test
|
|
1283
|
+
* @param pattern - Gitignore-style pattern (may include wildcards)
|
|
1284
|
+
* @returns True if the path matches the pattern (or doesn't match if negated)
|
|
1285
|
+
*/
|
|
1286
|
+
function matchPattern(path, pattern) {
|
|
1287
|
+
const normalizedPattern = pattern.startsWith('/') ? pattern.slice(1) : pattern;
|
|
1288
|
+
const isNegation = normalizedPattern.startsWith('!');
|
|
1289
|
+
const actualPattern = isNegation ? normalizedPattern.slice(1) : normalizedPattern;
|
|
1290
|
+
const matchesFullPath = matchGlobPattern(path, actualPattern) || matchGlobPattern(path, `**/${actualPattern}`);
|
|
1291
|
+
const matchesSegment = path.split('/').some((segment) => matchGlobPattern(segment, actualPattern));
|
|
1292
|
+
const matches = matchesFullPath || matchesSegment;
|
|
1293
|
+
return isNegation ? !matches : matches;
|
|
1294
|
+
}
|
|
1295
|
+
/**
|
|
1296
|
+
* Traverses a directory tree synchronously, calling a visitor function
|
|
1297
|
+
* for each file and directory encountered. Supports depth limiting,
|
|
1298
|
+
* hidden file filtering, and gitignore pattern matching.
|
|
1299
|
+
*
|
|
1300
|
+
* @param startPath - Root directory to begin traversal
|
|
1301
|
+
* @param visitor - Callback function invoked for each file system entry
|
|
1302
|
+
* @param options - Configuration for traversal behavior
|
|
1303
|
+
*/
|
|
1304
|
+
function walkDirectory(startPath, visitor, options) {
|
|
1305
|
+
walkLogger.debug('Starting directory walk', {
|
|
1306
|
+
startPath,
|
|
1307
|
+
maxDepth: options?.maxDepth ?? -1,
|
|
1308
|
+
includeHidden: options?.includeHidden ?? false,
|
|
1309
|
+
respectGitignore: options?.respectGitignore ?? true,
|
|
1310
|
+
ignorePatterns: options?.ignorePatterns?.length ?? 0,
|
|
1311
|
+
});
|
|
1312
|
+
const maxDepth = options?.maxDepth ?? -1;
|
|
1313
|
+
const includeHidden = options?.includeHidden ?? false;
|
|
1314
|
+
const ignorePatterns = options?.ignorePatterns ?? [];
|
|
1315
|
+
const respectGitignore = options?.respectGitignore ?? true;
|
|
1316
|
+
const gitignorePatterns = respectGitignore ? loadGitignorePatterns(startPath) : [];
|
|
1317
|
+
const allIgnorePatterns = [...ignorePatterns, ...gitignorePatterns];
|
|
1318
|
+
if (gitignorePatterns.length > 0) {
|
|
1319
|
+
walkLogger.debug('Loaded gitignore patterns', { count: gitignorePatterns.length });
|
|
1320
|
+
}
|
|
1321
|
+
/**
|
|
1322
|
+
* Recursively walks directory entries, applying visitor to each.
|
|
1323
|
+
*
|
|
1324
|
+
* @param currentPath - Absolute path to current directory
|
|
1325
|
+
* @param relativePath - Path relative to the starting directory
|
|
1326
|
+
* @param depth - Current recursion depth
|
|
1327
|
+
* @returns False to stop walking, true to continue
|
|
1328
|
+
*/
|
|
1329
|
+
function walk(currentPath, relativePath, depth) {
|
|
1330
|
+
if (maxDepth !== -1 && depth > maxDepth) {
|
|
1331
|
+
return true;
|
|
1332
|
+
}
|
|
1333
|
+
let entries;
|
|
1334
|
+
try {
|
|
1335
|
+
entries = readDirectory(currentPath);
|
|
1336
|
+
}
|
|
1337
|
+
catch {
|
|
1338
|
+
return true;
|
|
1339
|
+
}
|
|
1340
|
+
for (const entry of entries) {
|
|
1341
|
+
if (!includeHidden && entry.name.startsWith('.')) {
|
|
1342
|
+
continue;
|
|
1343
|
+
}
|
|
1344
|
+
const entryRelativePath = relativePath ? `${relativePath}/${entry.name}` : entry.name;
|
|
1345
|
+
if (matchesIgnorePattern(entryRelativePath, allIgnorePatterns)) {
|
|
1346
|
+
continue;
|
|
1347
|
+
}
|
|
1348
|
+
const walkEntry = {
|
|
1349
|
+
name: entry.name,
|
|
1350
|
+
path: entry.path,
|
|
1351
|
+
relativePath: entryRelativePath,
|
|
1352
|
+
isFile: entry.isFile,
|
|
1353
|
+
isDirectory: entry.isDirectory,
|
|
1354
|
+
isSymlink: entry.isSymlink,
|
|
1355
|
+
depth,
|
|
1356
|
+
};
|
|
1357
|
+
const result = visitor(walkEntry);
|
|
1358
|
+
if (result === 'stop') {
|
|
1359
|
+
return false;
|
|
1360
|
+
}
|
|
1361
|
+
if (result === 'skip') {
|
|
1362
|
+
continue;
|
|
1363
|
+
}
|
|
1364
|
+
if (entry.isDirectory) {
|
|
1365
|
+
const shouldContinue = walk(entry.path, entryRelativePath, depth + 1);
|
|
1366
|
+
if (!shouldContinue) {
|
|
1367
|
+
return false;
|
|
1368
|
+
}
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1371
|
+
return true;
|
|
1372
|
+
}
|
|
1373
|
+
walk(startPath, '', 0);
|
|
1374
|
+
walkLogger.debug('Directory walk complete', { startPath });
|
|
1375
|
+
}
|
|
1376
|
+
|
|
1377
|
+
const searchLogger = createScopedLogger('project-scope:project:search');
|
|
1378
|
+
/**
|
|
1379
|
+
* Tests if a path matches at least one pattern from an array of globs,
|
|
1380
|
+
* enabling flexible multi-pattern file filtering.
|
|
1381
|
+
* Uses safe character-by-character matching to prevent ReDoS attacks.
|
|
1382
|
+
*
|
|
1383
|
+
* @param path - File path to test
|
|
1384
|
+
* @param patterns - Array of glob patterns
|
|
1385
|
+
* @returns True if path matches any pattern
|
|
1386
|
+
*/
|
|
1387
|
+
function matchesPatterns(path, patterns) {
|
|
1388
|
+
return patterns.some((pattern) => matchGlobPattern(path, pattern));
|
|
1389
|
+
}
|
|
1390
|
+
/**
|
|
1391
|
+
* Searches a directory tree for files matching one or more glob patterns,
|
|
1392
|
+
* returning relative or absolute paths based on options.
|
|
1393
|
+
*
|
|
1394
|
+
* @param startPath - Root directory to begin the search
|
|
1395
|
+
* @param patterns - Glob patterns (e.g., '*.ts', '**\/*.json') to filter files
|
|
1396
|
+
* @param options - Configuration for search behavior
|
|
1397
|
+
* @returns List of relative file paths that match the patterns
|
|
1398
|
+
*
|
|
1399
|
+
* @example
|
|
1400
|
+
* ```typescript
|
|
1401
|
+
* import { findFiles } from '@hyperfrontend/project-scope'
|
|
1402
|
+
*
|
|
1403
|
+
* // Find all TypeScript files
|
|
1404
|
+
* const tsFiles = findFiles('./src', '\*\*\/*.ts')
|
|
1405
|
+
*
|
|
1406
|
+
* // Find multiple file types
|
|
1407
|
+
* const configFiles = findFiles('./', ['\*.json', '\*.yaml', '\*.yml'])
|
|
1408
|
+
*
|
|
1409
|
+
* // Limit results and get absolute paths
|
|
1410
|
+
* const first10 = findFiles('./src', '\*\*\/*.ts', {
|
|
1411
|
+
* maxResults: 10,
|
|
1412
|
+
* absolutePaths: true
|
|
1413
|
+
* })
|
|
1414
|
+
* ```
|
|
1415
|
+
*/
|
|
1416
|
+
function findFiles(startPath, patterns, options) {
|
|
1417
|
+
const normalizedPatterns = isArray(patterns) ? patterns : [patterns];
|
|
1418
|
+
searchLogger.debug('Finding files', { startPath, patterns: normalizedPatterns, maxResults: options?.maxResults });
|
|
1419
|
+
const results = [];
|
|
1420
|
+
const maxResults = options?.maxResults ?? Infinity;
|
|
1421
|
+
walkDirectory(startPath, (entry) => {
|
|
1422
|
+
if (results.length >= maxResults) {
|
|
1423
|
+
return 'stop';
|
|
1424
|
+
}
|
|
1425
|
+
if (!entry.isFile) {
|
|
1426
|
+
return undefined;
|
|
1427
|
+
}
|
|
1428
|
+
if (matchesPatterns(entry.relativePath, normalizedPatterns)) {
|
|
1429
|
+
results.push(options?.absolutePaths ? entry.path : entry.relativePath);
|
|
1430
|
+
}
|
|
1431
|
+
return undefined;
|
|
1432
|
+
}, options);
|
|
1433
|
+
searchLogger.debug('File search complete', { startPath, matchCount: results.length });
|
|
1434
|
+
return results;
|
|
1435
|
+
}
|
|
1436
|
+
|
|
1437
|
+
const configLogger = createScopedLogger('project-scope:config');
|
|
1438
|
+
/**
|
|
1439
|
+
* Cache for config detection results.
|
|
1440
|
+
* TTL: 30 seconds (configs can change frequently during setup)
|
|
1441
|
+
*/
|
|
1442
|
+
const configDetectionCache = createCache({ ttl: 30000, maxSize: 50 });
|
|
1443
|
+
/**
|
|
1444
|
+
* Detect all configuration files in a directory.
|
|
1445
|
+
*
|
|
1446
|
+
* Results are cached for 30 seconds per project path and options
|
|
1447
|
+
* to avoid redundant file system operations on repeated calls.
|
|
1448
|
+
*
|
|
1449
|
+
* @param rootPath - Project root directory
|
|
1450
|
+
* @param types - Optional array of config types to check (defaults to all)
|
|
1451
|
+
* @param options - Detection options
|
|
1452
|
+
* @returns Array of detected configuration files
|
|
1453
|
+
*
|
|
1454
|
+
* @example
|
|
1455
|
+
* ```typescript
|
|
1456
|
+
* import { detectConfigs } from '@hyperfrontend/project-scope'
|
|
1457
|
+
*
|
|
1458
|
+
* // Detect all config files
|
|
1459
|
+
* const configs = detectConfigs('./my-project')
|
|
1460
|
+
* for (const config of configs) {
|
|
1461
|
+
* console.log(`${config.type}: ${config.path}`)
|
|
1462
|
+
* }
|
|
1463
|
+
* // Output:
|
|
1464
|
+
* // typescript: tsconfig.json
|
|
1465
|
+
* // eslint: eslint.config.js
|
|
1466
|
+
* // jest: jest.config.ts
|
|
1467
|
+
*
|
|
1468
|
+
* // Detect specific config types only
|
|
1469
|
+
* const tsConfigs = detectConfigs('./my-project', ['typescript', 'eslint'])
|
|
1470
|
+
* ```
|
|
1471
|
+
*/
|
|
1472
|
+
function detectConfigs(rootPath, types, options) {
|
|
1473
|
+
const typesToCheck = types ?? keys(CONFIG_PATTERNS);
|
|
1474
|
+
const results = [];
|
|
1475
|
+
const maxDepth = options?.maxDepth ?? 10;
|
|
1476
|
+
const includeHidden = options?.includeHidden ?? true;
|
|
1477
|
+
const typeKey = types ? types.sort().join(',') : 'all';
|
|
1478
|
+
const cacheKey = `${rootPath}:${typeKey}:${maxDepth}:${includeHidden}`;
|
|
1479
|
+
if (!options?.skipCache) {
|
|
1480
|
+
const cached = configDetectionCache.get(cacheKey);
|
|
1481
|
+
if (cached) {
|
|
1482
|
+
configLogger.debug('Returning cached config detection results', { rootPath });
|
|
1483
|
+
return cached;
|
|
1484
|
+
}
|
|
1485
|
+
}
|
|
1486
|
+
configLogger.debug('Detecting config files', { rootPath, types: typesToCheck.length });
|
|
1487
|
+
for (const type of typesToCheck) {
|
|
1488
|
+
const info = CONFIG_PATTERNS[type];
|
|
1489
|
+
if (!info)
|
|
1490
|
+
continue;
|
|
1491
|
+
for (const pattern of info.patterns) {
|
|
1492
|
+
const isRecursive = pattern.includes('**');
|
|
1493
|
+
if (isRecursive) {
|
|
1494
|
+
const files = findFiles(rootPath, pattern, {
|
|
1495
|
+
maxDepth,
|
|
1496
|
+
includeHidden: options?.includeHidden ?? true,
|
|
1497
|
+
});
|
|
1498
|
+
for (const file of files) {
|
|
1499
|
+
if (!results.some((r) => r.path === file && r.type === type)) {
|
|
1500
|
+
configLogger.debug('Found config file', { type, path: file });
|
|
1501
|
+
results.push({
|
|
1502
|
+
type,
|
|
1503
|
+
path: file,
|
|
1504
|
+
matchedPattern: pattern,
|
|
1505
|
+
info,
|
|
1506
|
+
});
|
|
1507
|
+
}
|
|
1508
|
+
}
|
|
1509
|
+
}
|
|
1510
|
+
else {
|
|
1511
|
+
const fullPath = node_path.join(rootPath, pattern);
|
|
1512
|
+
if (exists(fullPath)) {
|
|
1513
|
+
if (!results.some((r) => r.path === pattern && r.type === type)) {
|
|
1514
|
+
configLogger.debug('Found config file', { type, path: pattern });
|
|
1515
|
+
results.push({
|
|
1516
|
+
type,
|
|
1517
|
+
path: pattern,
|
|
1518
|
+
matchedPattern: pattern,
|
|
1519
|
+
info,
|
|
1520
|
+
});
|
|
1521
|
+
}
|
|
1522
|
+
}
|
|
1523
|
+
}
|
|
1524
|
+
}
|
|
1525
|
+
}
|
|
1526
|
+
configLogger.debug('Config detection complete', { found: results.length });
|
|
1527
|
+
configDetectionCache.set(cacheKey, results);
|
|
1528
|
+
return results;
|
|
1529
|
+
}
|
|
1530
|
+
/**
|
|
1531
|
+
* Clear the config detection cache.
|
|
1532
|
+
*
|
|
1533
|
+
* Useful for testing or when the project files have changed.
|
|
1534
|
+
*/
|
|
1535
|
+
function clearConfigDetectionCache() {
|
|
1536
|
+
configDetectionCache.clear();
|
|
1537
|
+
}
|
|
1538
|
+
/**
|
|
1539
|
+
* Find a specific configuration file.
|
|
1540
|
+
*
|
|
1541
|
+
* @param rootPath - Project root directory
|
|
1542
|
+
* @param type - Config type to find
|
|
1543
|
+
* @returns Full path to config file or null if not found
|
|
1544
|
+
*/
|
|
1545
|
+
function findConfigFile(rootPath, type) {
|
|
1546
|
+
const info = CONFIG_PATTERNS[type];
|
|
1547
|
+
if (!info)
|
|
1548
|
+
return null;
|
|
1549
|
+
for (const pattern of info.patterns) {
|
|
1550
|
+
if (!pattern.includes('*')) {
|
|
1551
|
+
const fullPath = node_path.join(rootPath, pattern);
|
|
1552
|
+
if (exists(fullPath)) {
|
|
1553
|
+
return fullPath;
|
|
1554
|
+
}
|
|
1555
|
+
}
|
|
1556
|
+
}
|
|
1557
|
+
for (const pattern of info.patterns) {
|
|
1558
|
+
if (pattern.includes('*') && !pattern.includes('**')) {
|
|
1559
|
+
const files = findFiles(rootPath, pattern, { maxDepth: 0 });
|
|
1560
|
+
if (files.length > 0) {
|
|
1561
|
+
return node_path.join(rootPath, files[0]);
|
|
1562
|
+
}
|
|
1563
|
+
}
|
|
1564
|
+
}
|
|
1565
|
+
return null;
|
|
1566
|
+
}
|
|
1567
|
+
/**
|
|
1568
|
+
* Get all known config file patterns for a given configuration type.
|
|
1569
|
+
*
|
|
1570
|
+
* @param type - Configuration type identifier
|
|
1571
|
+
* @returns Array of glob patterns for matching config files
|
|
1572
|
+
*/
|
|
1573
|
+
function getConfigPaths(type) {
|
|
1574
|
+
const info = CONFIG_PATTERNS[type];
|
|
1575
|
+
return info?.patterns ?? [];
|
|
1576
|
+
}
|
|
1577
|
+
|
|
1578
|
+
/**
|
|
1579
|
+
* Safe copies of Number built-in methods and constants.
|
|
1580
|
+
*
|
|
1581
|
+
* These references are captured at module initialization time to protect against
|
|
1582
|
+
* prototype pollution attacks. Import only what you need for tree-shaking.
|
|
1583
|
+
*
|
|
1584
|
+
* @module @hyperfrontend/immutable-api-utils/built-in-copy/number
|
|
1585
|
+
*/
|
|
1586
|
+
// Capture references at module initialization time
|
|
1587
|
+
const _parseInt = globalThis.parseInt;
|
|
1588
|
+
const _parseFloat = globalThis.parseFloat;
|
|
1589
|
+
// ============================================================================
|
|
1590
|
+
// Parsing
|
|
1591
|
+
// ============================================================================
|
|
1592
|
+
/**
|
|
1593
|
+
* (Safe copy) Parses a string and returns an integer.
|
|
1594
|
+
*/
|
|
1595
|
+
const parseInt = _parseInt;
|
|
1596
|
+
/**
|
|
1597
|
+
* (Safe copy) Parses a string and returns a floating point number.
|
|
1598
|
+
*/
|
|
1599
|
+
const parseFloat = _parseFloat;
|
|
1600
|
+
|
|
1601
|
+
/**
|
|
1602
|
+
* Create a structured error with code and optional context.
|
|
1603
|
+
*
|
|
1604
|
+
* @param message - The human-readable error message
|
|
1605
|
+
* @param code - The machine-readable error code for programmatic handling
|
|
1606
|
+
* @param context - Additional contextual information about the error
|
|
1607
|
+
* @returns Structured error instance with code and context properties
|
|
1608
|
+
*
|
|
1609
|
+
* @example
|
|
1610
|
+
* ```typescript
|
|
1611
|
+
* import { createStructuredError } from '@hyperfrontend/project-scope'
|
|
1612
|
+
*
|
|
1613
|
+
* throw createStructuredError(
|
|
1614
|
+
* 'Configuration file not found',
|
|
1615
|
+
* 'CONFIG_NOT_FOUND',
|
|
1616
|
+
* { path: './config.json', searched: ['./config.json', './settings.json'] }
|
|
1617
|
+
* )
|
|
1618
|
+
* ```
|
|
1619
|
+
*/
|
|
1620
|
+
function createStructuredError(message, code, context) {
|
|
1621
|
+
const error = createError(message);
|
|
1622
|
+
error.code = code;
|
|
1623
|
+
error.context = context ?? {};
|
|
1624
|
+
return error;
|
|
1625
|
+
}
|
|
1626
|
+
/**
|
|
1627
|
+
* Create a configuration-related error.
|
|
1628
|
+
*
|
|
1629
|
+
* @param message - The human-readable error message
|
|
1630
|
+
* @param code - The machine-readable error code for programmatic handling
|
|
1631
|
+
* @param context - Additional contextual information (e.g., file path, config key)
|
|
1632
|
+
* @returns Structured error instance tagged with type 'config'
|
|
1633
|
+
*/
|
|
1634
|
+
function createConfigError(message, code, context) {
|
|
1635
|
+
return createStructuredError(message, code, { ...context, type: 'config' });
|
|
1636
|
+
}
|
|
1637
|
+
|
|
1638
|
+
/**
|
|
1639
|
+
* Detect config type from file name.
|
|
1640
|
+
* Uses safe character-by-character matching to prevent ReDoS attacks.
|
|
1641
|
+
*
|
|
1642
|
+
* @param filePath - Path to config file
|
|
1643
|
+
* @returns Detected config type or undefined
|
|
1644
|
+
*/
|
|
1645
|
+
function detectConfigType(filePath) {
|
|
1646
|
+
const fileName = node_path.basename(filePath);
|
|
1647
|
+
for (const [type, info] of entries(CONFIG_PATTERNS)) {
|
|
1648
|
+
for (const pattern of info.patterns) {
|
|
1649
|
+
if (matchGlobPattern(fileName, pattern)) {
|
|
1650
|
+
return type;
|
|
1651
|
+
}
|
|
1652
|
+
}
|
|
1653
|
+
}
|
|
1654
|
+
return undefined;
|
|
1655
|
+
}
|
|
1656
|
+
/**
|
|
1657
|
+
* Detect format from file path.
|
|
1658
|
+
*
|
|
1659
|
+
* @param filePath - Path to config file
|
|
1660
|
+
* @returns Detected format
|
|
1661
|
+
*/
|
|
1662
|
+
function detectFormat(filePath) {
|
|
1663
|
+
const ext = filePath.split('.').pop()?.toLowerCase();
|
|
1664
|
+
switch (ext) {
|
|
1665
|
+
case 'json':
|
|
1666
|
+
return 'json';
|
|
1667
|
+
case 'yaml':
|
|
1668
|
+
case 'yml':
|
|
1669
|
+
return 'yaml';
|
|
1670
|
+
case 'js':
|
|
1671
|
+
case 'cjs':
|
|
1672
|
+
case 'mjs':
|
|
1673
|
+
return 'js';
|
|
1674
|
+
case 'ts':
|
|
1675
|
+
return 'ts';
|
|
1676
|
+
case 'toml':
|
|
1677
|
+
return 'toml';
|
|
1678
|
+
case 'ini':
|
|
1679
|
+
return 'ini';
|
|
1680
|
+
default:
|
|
1681
|
+
return 'text';
|
|
1682
|
+
}
|
|
1683
|
+
}
|
|
1684
|
+
/**
|
|
1685
|
+
* Strip JSON comments (// and /* *\/).
|
|
1686
|
+
*
|
|
1687
|
+
* @param content - JSONC content
|
|
1688
|
+
* @returns JSON content without comments
|
|
1689
|
+
*/
|
|
1690
|
+
function stripJsonComments(content) {
|
|
1691
|
+
let result = '';
|
|
1692
|
+
let inString = false;
|
|
1693
|
+
let inLineComment = false;
|
|
1694
|
+
let inBlockComment = false;
|
|
1695
|
+
let stringChar = '';
|
|
1696
|
+
for (let i = 0; i < content.length; i++) {
|
|
1697
|
+
const char = content[i];
|
|
1698
|
+
const nextChar = content[i + 1];
|
|
1699
|
+
if (inLineComment) {
|
|
1700
|
+
if (char === '\n') {
|
|
1701
|
+
inLineComment = false;
|
|
1702
|
+
result += char;
|
|
1703
|
+
}
|
|
1704
|
+
continue;
|
|
1705
|
+
}
|
|
1706
|
+
if (inBlockComment) {
|
|
1707
|
+
if (char === '*' && nextChar === '/') {
|
|
1708
|
+
inBlockComment = false;
|
|
1709
|
+
i++;
|
|
1710
|
+
}
|
|
1711
|
+
continue;
|
|
1712
|
+
}
|
|
1713
|
+
if (inString) {
|
|
1714
|
+
result += char;
|
|
1715
|
+
if (char === stringChar && content[i - 1] !== '\\') {
|
|
1716
|
+
inString = false;
|
|
1717
|
+
}
|
|
1718
|
+
continue;
|
|
1719
|
+
}
|
|
1720
|
+
if (char === '"' || char === "'") {
|
|
1721
|
+
inString = true;
|
|
1722
|
+
stringChar = char;
|
|
1723
|
+
result += char;
|
|
1724
|
+
continue;
|
|
1725
|
+
}
|
|
1726
|
+
if (char === '/' && nextChar === '/') {
|
|
1727
|
+
inLineComment = true;
|
|
1728
|
+
i++;
|
|
1729
|
+
continue;
|
|
1730
|
+
}
|
|
1731
|
+
if (char === '/' && nextChar === '*') {
|
|
1732
|
+
inBlockComment = true;
|
|
1733
|
+
i++;
|
|
1734
|
+
continue;
|
|
1735
|
+
}
|
|
1736
|
+
result += char;
|
|
1737
|
+
}
|
|
1738
|
+
return result;
|
|
1739
|
+
}
|
|
1740
|
+
/**
|
|
1741
|
+
* Parse simple YAML key-value pairs into an object.
|
|
1742
|
+
* Note: This is a simplified parser for basic config structures.
|
|
1743
|
+
*
|
|
1744
|
+
* @param content - Raw YAML file content to parse
|
|
1745
|
+
* @returns Object representation of the YAML key-value pairs
|
|
1746
|
+
*/
|
|
1747
|
+
function parseSimpleYaml(content) {
|
|
1748
|
+
const lines = content.split('\n');
|
|
1749
|
+
const result = {};
|
|
1750
|
+
for (const line of lines) {
|
|
1751
|
+
if (line.trim().startsWith('#') || !line.includes(':')) {
|
|
1752
|
+
continue;
|
|
1753
|
+
}
|
|
1754
|
+
const colonIndex = line.indexOf(':');
|
|
1755
|
+
const key = line.substring(0, colonIndex).trim();
|
|
1756
|
+
const value = line.substring(colonIndex + 1).trim();
|
|
1757
|
+
if (key && value) {
|
|
1758
|
+
if (value === 'true') {
|
|
1759
|
+
result[key] = true;
|
|
1760
|
+
}
|
|
1761
|
+
else if (value === 'false') {
|
|
1762
|
+
result[key] = false;
|
|
1763
|
+
}
|
|
1764
|
+
else if (value === 'null') {
|
|
1765
|
+
result[key] = null;
|
|
1766
|
+
}
|
|
1767
|
+
else if (/^-?\d+$/.test(value)) {
|
|
1768
|
+
result[key] = parseInt(value, 10);
|
|
1769
|
+
}
|
|
1770
|
+
else if (/^-?\d+\.\d+$/.test(value)) {
|
|
1771
|
+
result[key] = parseFloat(value);
|
|
1772
|
+
}
|
|
1773
|
+
else {
|
|
1774
|
+
result[key] = value.replace(/^["']|["']$/g, '');
|
|
1775
|
+
}
|
|
1776
|
+
}
|
|
1777
|
+
}
|
|
1778
|
+
return result;
|
|
1779
|
+
}
|
|
1780
|
+
/**
|
|
1781
|
+
* Parse INI-style configuration format into an object.
|
|
1782
|
+
* Supports sections and key-value pairs.
|
|
1783
|
+
*
|
|
1784
|
+
* @param content - Raw INI file content to parse
|
|
1785
|
+
* @returns Object with sections as keys and their key-value pairs
|
|
1786
|
+
*/
|
|
1787
|
+
function parseIniConfig(content) {
|
|
1788
|
+
const result = {};
|
|
1789
|
+
let currentSection = '';
|
|
1790
|
+
for (const line of content.split('\n')) {
|
|
1791
|
+
const trimmed = line.trim();
|
|
1792
|
+
if (!trimmed || trimmed.startsWith('#') || trimmed.startsWith(';')) {
|
|
1793
|
+
continue;
|
|
1794
|
+
}
|
|
1795
|
+
const sectionMatch = trimmed.match(/^\[([^\]]+)\]$/);
|
|
1796
|
+
if (sectionMatch) {
|
|
1797
|
+
currentSection = sectionMatch[1];
|
|
1798
|
+
result[currentSection] = {};
|
|
1799
|
+
continue;
|
|
1800
|
+
}
|
|
1801
|
+
const keyValueMatch = trimmed.match(/^([^=]+)=(.*)$/);
|
|
1802
|
+
if (keyValueMatch) {
|
|
1803
|
+
const key = keyValueMatch[1].trim();
|
|
1804
|
+
const value = keyValueMatch[2].trim();
|
|
1805
|
+
if (currentSection) {
|
|
1806
|
+
result[currentSection][key] = value;
|
|
1807
|
+
}
|
|
1808
|
+
else {
|
|
1809
|
+
result[key] = value;
|
|
1810
|
+
}
|
|
1811
|
+
}
|
|
1812
|
+
}
|
|
1813
|
+
return result;
|
|
1814
|
+
}
|
|
1815
|
+
/**
|
|
1816
|
+
* Parse dotenv-style environment variable format.
|
|
1817
|
+
* Handles quoted values and comments.
|
|
1818
|
+
*
|
|
1819
|
+
* @param content - Raw dotenv file content to parse
|
|
1820
|
+
* @returns Object mapping variable names to their values
|
|
1821
|
+
*/
|
|
1822
|
+
function parseDotenv(content) {
|
|
1823
|
+
const result = {};
|
|
1824
|
+
for (const line of content.split('\n')) {
|
|
1825
|
+
const trimmed = line.trim();
|
|
1826
|
+
if (!trimmed || trimmed.startsWith('#')) {
|
|
1827
|
+
continue;
|
|
1828
|
+
}
|
|
1829
|
+
const match = trimmed.match(/^([^=]+)=(.*)$/);
|
|
1830
|
+
if (match) {
|
|
1831
|
+
const key = match[1].trim();
|
|
1832
|
+
let value = match[2].trim();
|
|
1833
|
+
if ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'"))) {
|
|
1834
|
+
value = value.slice(1, -1);
|
|
1835
|
+
}
|
|
1836
|
+
result[key] = value;
|
|
1837
|
+
}
|
|
1838
|
+
}
|
|
1839
|
+
return result;
|
|
1840
|
+
}
|
|
1841
|
+
/**
|
|
1842
|
+
* Parse JSON configuration file.
|
|
1843
|
+
*
|
|
1844
|
+
* @param filePath - Path to the JSON configuration file
|
|
1845
|
+
* @param content - Raw file content to parse
|
|
1846
|
+
* @param type - Category of configuration (e.g., typescript, eslint)
|
|
1847
|
+
* @param format - Whether to strip comments (jsonc) or parse strictly (json)
|
|
1848
|
+
* @returns Configuration object with parsed data and extends references
|
|
1849
|
+
*/
|
|
1850
|
+
function parseJsonConfig(filePath, content, type, format = 'json') {
|
|
1851
|
+
const cleanContent = format === 'jsonc' ? stripJsonComments(content) : content;
|
|
1852
|
+
try {
|
|
1853
|
+
const data = parse(cleanContent);
|
|
1854
|
+
let extendsPath;
|
|
1855
|
+
if (typeof data['extends'] === 'string') {
|
|
1856
|
+
extendsPath = [data['extends']];
|
|
1857
|
+
}
|
|
1858
|
+
else if (isArray(data['extends'])) {
|
|
1859
|
+
extendsPath = data['extends'];
|
|
1860
|
+
}
|
|
1861
|
+
return {
|
|
1862
|
+
type: type ?? 'unknown',
|
|
1863
|
+
path: filePath,
|
|
1864
|
+
format,
|
|
1865
|
+
data,
|
|
1866
|
+
extends: extendsPath,
|
|
1867
|
+
};
|
|
1868
|
+
}
|
|
1869
|
+
catch (error) {
|
|
1870
|
+
throw createConfigError(`Failed to parse JSON config: ${filePath}`, 'CONFIG_PARSE_ERROR', {
|
|
1871
|
+
filePath,
|
|
1872
|
+
format,
|
|
1873
|
+
cause: error,
|
|
1874
|
+
});
|
|
1875
|
+
}
|
|
1876
|
+
}
|
|
1877
|
+
/**
|
|
1878
|
+
* Parse YAML configuration file.
|
|
1879
|
+
*
|
|
1880
|
+
* @param filePath - Path to the YAML configuration file
|
|
1881
|
+
* @param content - Raw file content to parse
|
|
1882
|
+
* @param type - Category of configuration (e.g., github-actions, docker-compose)
|
|
1883
|
+
* @returns Configuration object with parsed YAML data
|
|
1884
|
+
*/
|
|
1885
|
+
function parseYamlConfig(filePath, content, type) {
|
|
1886
|
+
const data = parseSimpleYaml(content);
|
|
1887
|
+
return {
|
|
1888
|
+
type: type ?? 'unknown',
|
|
1889
|
+
path: filePath,
|
|
1890
|
+
format: 'yaml',
|
|
1891
|
+
data,
|
|
1892
|
+
};
|
|
1893
|
+
}
|
|
1894
|
+
/**
|
|
1895
|
+
* Parse configuration file.
|
|
1896
|
+
*
|
|
1897
|
+
* @param filePath - Path to config file
|
|
1898
|
+
* @param type - Optional config type (auto-detected if not provided)
|
|
1899
|
+
* @returns Parsed configuration
|
|
1900
|
+
*/
|
|
1901
|
+
function parseConfig(filePath, type) {
|
|
1902
|
+
const content = readFileContent(filePath);
|
|
1903
|
+
const detectedType = type ?? detectConfigType(filePath);
|
|
1904
|
+
const info = detectedType ? CONFIG_PATTERNS[detectedType] : null;
|
|
1905
|
+
const format = info?.format ?? detectFormat(filePath);
|
|
1906
|
+
switch (format) {
|
|
1907
|
+
case 'json':
|
|
1908
|
+
return parseJsonConfig(filePath, content, detectedType, 'json');
|
|
1909
|
+
case 'jsonc':
|
|
1910
|
+
return parseJsonConfig(filePath, content, detectedType, 'jsonc');
|
|
1911
|
+
case 'yaml':
|
|
1912
|
+
return parseYamlConfig(filePath, content, detectedType);
|
|
1913
|
+
case 'ini':
|
|
1914
|
+
return {
|
|
1915
|
+
type: detectedType ?? 'unknown',
|
|
1916
|
+
path: filePath,
|
|
1917
|
+
format: 'ini',
|
|
1918
|
+
data: parseIniConfig(content),
|
|
1919
|
+
};
|
|
1920
|
+
case 'dotenv':
|
|
1921
|
+
return {
|
|
1922
|
+
type: detectedType ?? 'unknown',
|
|
1923
|
+
path: filePath,
|
|
1924
|
+
format: 'dotenv',
|
|
1925
|
+
data: parseDotenv(content),
|
|
1926
|
+
};
|
|
1927
|
+
case 'js':
|
|
1928
|
+
case 'ts':
|
|
1929
|
+
return {
|
|
1930
|
+
type: detectedType ?? 'unknown',
|
|
1931
|
+
path: filePath,
|
|
1932
|
+
format,
|
|
1933
|
+
raw: content,
|
|
1934
|
+
};
|
|
1935
|
+
default:
|
|
1936
|
+
return {
|
|
1937
|
+
type: detectedType ?? 'unknown',
|
|
1938
|
+
path: filePath,
|
|
1939
|
+
format: 'text',
|
|
1940
|
+
raw: content,
|
|
1941
|
+
};
|
|
1942
|
+
}
|
|
1943
|
+
}
|
|
1944
|
+
/**
|
|
1945
|
+
* Read and parse config file if it exists.
|
|
1946
|
+
*
|
|
1947
|
+
* @param configPath - Path to config file
|
|
1948
|
+
* @returns Parsed config or null if file doesn't exist
|
|
1949
|
+
*/
|
|
1950
|
+
function readConfigIfExists(configPath) {
|
|
1951
|
+
const content = readFileIfExists(configPath);
|
|
1952
|
+
if (!content)
|
|
1953
|
+
return null;
|
|
1954
|
+
try {
|
|
1955
|
+
const format = detectFormat(configPath);
|
|
1956
|
+
switch (format) {
|
|
1957
|
+
case 'json':
|
|
1958
|
+
return parse(content);
|
|
1959
|
+
case 'jsonc':
|
|
1960
|
+
return parse(stripJsonComments(content));
|
|
1961
|
+
case 'yaml':
|
|
1962
|
+
return parseSimpleYaml(content);
|
|
1963
|
+
default:
|
|
1964
|
+
return null;
|
|
1965
|
+
}
|
|
1966
|
+
}
|
|
1967
|
+
catch {
|
|
1968
|
+
return null;
|
|
1969
|
+
}
|
|
1970
|
+
}
|
|
1971
|
+
|
|
1972
|
+
exports.CONFIG_PATTERNS = CONFIG_PATTERNS;
|
|
1973
|
+
exports.clearConfigDetectionCache = clearConfigDetectionCache;
|
|
1974
|
+
exports.detectConfigs = detectConfigs;
|
|
1975
|
+
exports.findConfigFile = findConfigFile;
|
|
1976
|
+
exports.getConfigPaths = getConfigPaths;
|
|
1977
|
+
exports.getConfigPatternsByType = getConfigPatternsByType;
|
|
1978
|
+
exports.parseConfig = parseConfig;
|
|
1979
|
+
exports.parseJsonConfig = parseJsonConfig;
|
|
1980
|
+
exports.parseYamlConfig = parseYamlConfig;
|
|
1981
|
+
exports.readConfigIfExists = readConfigIfExists;
|
|
1982
|
+
//# sourceMappingURL=index.cjs.js.map
|