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