@hyperfrontend/project-scope 0.2.1 → 0.2.3
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/CHANGELOG.md +14 -1
- package/README.md +3 -4
- package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/array/index.cjs.js +7 -0
- package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/array/index.esm.js +5 -0
- package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/console/index.cjs.js +13 -0
- package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/console/index.esm.js +8 -0
- package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/date/index.cjs.js +10 -0
- package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/date/index.esm.js +8 -0
- package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/error/index.cjs.js +6 -0
- package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/error/index.esm.js +5 -0
- package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/json/index.cjs.js +7 -0
- package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/json/index.esm.js +5 -0
- package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/map/index.cjs.js +6 -0
- package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/map/index.esm.js +5 -0
- package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/math/index.cjs.js +9 -0
- package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/math/index.esm.js +6 -0
- package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/number/index.cjs.js +7 -0
- package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/number/index.esm.js +7 -0
- package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/object/index.cjs.js +15 -0
- package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/object/index.esm.js +9 -0
- package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/set/index.cjs.js +6 -0
- package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/set/index.esm.js +5 -0
- package/_dependencies/@hyperfrontend/logging/index.cjs.js +191 -0
- package/_dependencies/@hyperfrontend/logging/index.d.ts +151 -0
- package/_dependencies/@hyperfrontend/logging/index.esm.js +186 -0
- package/_shared/core/cache/index.cjs.js +135 -0
- package/_shared/core/cache/index.esm.js +128 -0
- package/_shared/core/errors/structured-errors/index.cjs.js +28 -0
- package/_shared/core/errors/structured-errors/index.esm.js +23 -0
- package/_shared/core/fs/guard/index.cjs.js +7 -0
- package/_shared/core/fs/guard/index.esm.js +5 -0
- package/_shared/core/fs/stat/index.cjs.js +47 -0
- package/_shared/core/fs/stat/index.esm.js +41 -0
- package/_shared/core/path/confine/index.cjs.js +22 -0
- package/_shared/core/path/confine/index.esm.js +19 -0
- package/_shared/core/path/join/index.cjs.js +13 -0
- package/_shared/core/path/join/index.esm.js +10 -0
- package/_shared/core/path/normalize/index.cjs.js +37 -0
- package/_shared/core/path/normalize/index.esm.js +31 -0
- package/_shared/core/path/resolve/index.cjs.js +47 -0
- package/_shared/core/path/resolve/index.esm.js +41 -0
- package/_shared/core/path/segments/index.cjs.js +38 -0
- package/_shared/core/path/segments/index.esm.js +31 -0
- package/_shared/core/patterns/glob/index.cjs.js +145 -0
- package/_shared/core/patterns/glob/index.esm.js +136 -0
- package/_shared/core/platform/detect/index.cjs.js +103 -0
- package/_shared/core/platform/detect/index.esm.js +95 -0
- package/_shared/core/platform/line-endings/index.cjs.js +52 -0
- package/_shared/core/platform/line-endings/index.esm.js +44 -0
- package/_shared/project/config/patterns/index.cjs.js +172 -0
- package/_shared/project/config/patterns/index.esm.js +169 -0
- package/_shared/tech/monorepo/pnpm-workspaces/index.cjs.js +33 -0
- package/_shared/tech/monorepo/pnpm-workspaces/index.esm.js +31 -0
- package/_shared/tech/shared-utils/detector-helpers/index.cjs.js +48 -0
- package/_shared/tech/shared-utils/detector-helpers/index.esm.js +43 -0
- package/_shared/vfs/types/index.cjs.js +14 -0
- package/_shared/vfs/types/index.esm.js +12 -0
- package/cli/index.cjs.js +1706 -1910
- package/cli/index.d.ts +273 -7
- package/cli/index.d.ts.map +1 -1
- package/cli/index.esm.js +1593 -1797
- package/core/encoding/index.cjs.js +86 -401
- package/core/encoding/index.d.ts +186 -3
- package/core/encoding/index.d.ts.map +1 -1
- package/core/encoding/index.esm.js +78 -392
- package/core/fs/index.cjs.js +243 -583
- package/core/fs/index.d.ts +479 -6
- package/core/fs/index.d.ts.map +1 -1
- package/core/fs/index.esm.js +233 -573
- package/core/index.cjs.js +526 -1746
- package/core/index.d.ts +486 -9
- package/core/index.d.ts.map +1 -1
- package/core/index.esm.js +515 -1732
- package/core/path/index.cjs.js +8 -234
- package/core/path/index.d.ts +327 -5
- package/core/path/index.d.ts.map +1 -1
- package/core/path/index.esm.js +8 -235
- package/core/platform/index.cjs.js +5 -216
- package/core/platform/index.d.ts +185 -3
- package/core/platform/index.d.ts.map +1 -1
- package/core/platform/index.esm.js +3 -212
- package/heuristics/dependencies/index.cjs.js +105 -493
- package/heuristics/dependencies/index.d.ts +99 -2
- package/heuristics/dependencies/index.d.ts.map +1 -1
- package/heuristics/dependencies/index.esm.js +81 -469
- package/heuristics/entry-points/index.cjs.js +93 -796
- package/heuristics/entry-points/index.d.ts +123 -2
- package/heuristics/entry-points/index.d.ts.map +1 -1
- package/heuristics/entry-points/index.esm.js +74 -777
- package/heuristics/framework/index.cjs.js +1483 -1411
- package/heuristics/framework/index.d.ts +104 -2
- package/heuristics/framework/index.d.ts.map +1 -1
- package/heuristics/framework/index.esm.js +1419 -1347
- package/heuristics/index.cjs.js +3220 -3306
- package/heuristics/index.d.ts +4 -5
- package/heuristics/index.d.ts.map +1 -1
- package/heuristics/index.esm.js +3244 -3330
- package/heuristics/project-type/index.cjs.js +1489 -1438
- package/heuristics/project-type/index.d.ts +64 -2
- package/heuristics/project-type/index.d.ts.map +1 -1
- package/heuristics/project-type/index.esm.js +1419 -1368
- package/index.cjs.js +3058 -3532
- package/index.d.ts +44 -10
- package/index.d.ts.map +1 -1
- package/index.esm.js +2914 -3376
- package/models/index.cjs.js +0 -1
- package/models/index.d.ts +20 -14
- package/models/index.d.ts.map +1 -1
- package/models/index.esm.js +0 -1
- package/nx/index.cjs.js +166 -579
- package/nx/index.d.ts +279 -4
- package/nx/index.d.ts.map +1 -1
- package/nx/index.esm.js +148 -556
- package/package.json +13 -12
- package/project/config/index.cjs.js +127 -1063
- package/project/config/index.d.ts +202 -4
- package/project/config/index.d.ts.map +1 -1
- package/project/config/index.esm.js +110 -1044
- package/project/index.cjs.js +328 -1101
- package/project/index.d.ts +4 -5
- package/project/index.d.ts.map +1 -1
- package/project/index.esm.js +307 -1077
- package/project/package/index.cjs.js +196 -473
- package/project/package/index.d.ts +280 -3
- package/project/package/index.d.ts.map +1 -1
- package/project/package/index.esm.js +183 -459
- package/project/root/index.cjs.js +109 -417
- package/project/root/index.d.ts +83 -2
- package/project/root/index.d.ts.map +1 -1
- package/project/root/index.esm.js +98 -406
- package/project/traversal/index.cjs.js +96 -622
- package/project/traversal/index.d.ts +165 -3
- package/project/traversal/index.d.ts.map +1 -1
- package/project/traversal/index.esm.js +82 -608
- package/tech/backend/index.cjs.js +223 -508
- package/tech/backend/index.d.ts +205 -8
- package/tech/backend/index.d.ts.map +1 -1
- package/tech/backend/index.esm.js +202 -487
- package/tech/build/index.cjs.js +350 -636
- package/tech/build/index.d.ts +276 -10
- package/tech/build/index.d.ts.map +1 -1
- package/tech/build/index.esm.js +328 -614
- package/tech/frontend/index.cjs.js +507 -685
- package/tech/frontend/index.d.ts +379 -15
- package/tech/frontend/index.d.ts.map +1 -1
- package/tech/frontend/index.esm.js +483 -661
- package/tech/index.cjs.js +1581 -1420
- package/tech/index.d.ts +55 -32
- package/tech/index.d.ts.map +1 -1
- package/tech/index.esm.js +1515 -1354
- package/tech/legacy/index.cjs.js +99 -449
- package/tech/legacy/index.d.ts +125 -7
- package/tech/legacy/index.d.ts.map +1 -1
- package/tech/legacy/index.esm.js +81 -431
- package/tech/linting/index.cjs.js +138 -523
- package/tech/linting/index.d.ts +129 -7
- package/tech/linting/index.d.ts.map +1 -1
- package/tech/linting/index.esm.js +118 -503
- package/tech/monorepo/index.cjs.js +246 -573
- package/tech/monorepo/index.d.ts +241 -10
- package/tech/monorepo/index.d.ts.map +1 -1
- package/tech/monorepo/index.esm.js +226 -553
- package/tech/testing/index.cjs.js +216 -571
- package/tech/testing/index.d.ts +176 -8
- package/tech/testing/index.d.ts.map +1 -1
- package/tech/testing/index.esm.js +198 -553
- package/tech/types/index.cjs.js +123 -506
- package/tech/types/index.d.ts +120 -2
- package/tech/types/index.d.ts.map +1 -1
- package/tech/types/index.esm.js +101 -484
- package/vfs/index.cjs.js +647 -1142
- package/vfs/index.d.ts +360 -6
- package/vfs/index.d.ts.map +1 -1
- package/vfs/index.esm.js +672 -1167
- package/ARCHITECTURE.md +0 -370
- package/analyze.d.ts +0 -33
- package/analyze.d.ts.map +0 -1
- package/cli/commands/analyze.d.ts +0 -28
- package/cli/commands/analyze.d.ts.map +0 -1
- package/cli/commands/config.d.ts +0 -27
- package/cli/commands/config.d.ts.map +0 -1
- package/cli/commands/deps.d.ts +0 -24
- package/cli/commands/deps.d.ts.map +0 -1
- package/cli/commands/tree.d.ts +0 -36
- package/cli/commands/tree.d.ts.map +0 -1
- package/cli/index.cjs.js.map +0 -1
- package/cli/index.esm.js.map +0 -1
- package/cli/run.d.ts +0 -25
- package/cli/run.d.ts.map +0 -1
- package/cli/types.d.ts +0 -55
- package/cli/types.d.ts.map +0 -1
- package/core/cache.d.ts +0 -158
- package/core/cache.d.ts.map +0 -1
- package/core/encoding/convert.d.ts +0 -32
- package/core/encoding/convert.d.ts.map +0 -1
- package/core/encoding/detect.d.ts +0 -91
- package/core/encoding/detect.d.ts.map +0 -1
- package/core/encoding/index.cjs.js.map +0 -1
- package/core/encoding/index.esm.js.map +0 -1
- package/core/errors/structured-errors.d.ts +0 -66
- package/core/errors/structured-errors.d.ts.map +0 -1
- package/core/fs/directory.d.ts +0 -91
- package/core/fs/directory.d.ts.map +0 -1
- package/core/fs/index.cjs.js.map +0 -1
- package/core/fs/index.esm.js.map +0 -1
- package/core/fs/read.d.ts +0 -94
- package/core/fs/read.d.ts.map +0 -1
- package/core/fs/stat.d.ts +0 -58
- package/core/fs/stat.d.ts.map +0 -1
- package/core/fs/traversal.d.ts +0 -26
- package/core/fs/traversal.d.ts.map +0 -1
- package/core/fs/write.d.ts +0 -75
- package/core/fs/write.d.ts.map +0 -1
- package/core/index.cjs.js.map +0 -1
- package/core/index.esm.js.map +0 -1
- package/core/logger.d.ts +0 -111
- package/core/logger.d.ts.map +0 -1
- package/core/path/index.cjs.js.map +0 -1
- package/core/path/index.esm.js.map +0 -1
- package/core/path/join.d.ts +0 -17
- package/core/path/join.d.ts.map +0 -1
- package/core/path/normalize.d.ts +0 -37
- package/core/path/normalize.d.ts.map +0 -1
- package/core/path/resolve.d.ts +0 -52
- package/core/path/resolve.d.ts.map +0 -1
- package/core/path/segments.d.ts +0 -59
- package/core/path/segments.d.ts.map +0 -1
- package/core/patterns/glob.d.ts +0 -42
- package/core/patterns/glob.d.ts.map +0 -1
- package/core/platform/detect.d.ts +0 -66
- package/core/platform/detect.d.ts.map +0 -1
- package/core/platform/index.cjs.js.map +0 -1
- package/core/platform/index.esm.js.map +0 -1
- package/core/platform/line-endings.d.ts +0 -48
- package/core/platform/line-endings.d.ts.map +0 -1
- package/heuristics/dependencies/analyze.d.ts +0 -77
- package/heuristics/dependencies/analyze.d.ts.map +0 -1
- package/heuristics/dependencies/index.cjs.js.map +0 -1
- package/heuristics/dependencies/index.esm.js.map +0 -1
- package/heuristics/entry-points/discover.d.ts +0 -113
- package/heuristics/entry-points/discover.d.ts.map +0 -1
- package/heuristics/entry-points/index.cjs.js.map +0 -1
- package/heuristics/entry-points/index.esm.js.map +0 -1
- package/heuristics/framework/identify.d.ts +0 -84
- package/heuristics/framework/identify.d.ts.map +0 -1
- package/heuristics/framework/index.cjs.js.map +0 -1
- package/heuristics/framework/index.esm.js.map +0 -1
- package/heuristics/index.cjs.js.map +0 -1
- package/heuristics/index.esm.js.map +0 -1
- package/heuristics/project-type/detect.d.ts +0 -61
- package/heuristics/project-type/detect.d.ts.map +0 -1
- package/heuristics/project-type/index.cjs.js.map +0 -1
- package/heuristics/project-type/index.esm.js.map +0 -1
- package/index.cjs.js.map +0 -1
- package/index.esm.js.map +0 -1
- package/models/index.cjs.js.map +0 -1
- package/models/index.esm.js.map +0 -1
- package/nx/detect.d.ts +0 -105
- package/nx/detect.d.ts.map +0 -1
- package/nx/devkit-loader.d.ts +0 -62
- package/nx/devkit-loader.d.ts.map +0 -1
- package/nx/index.cjs.js.map +0 -1
- package/nx/index.esm.js.map +0 -1
- package/nx/project-config.d.ts +0 -111
- package/nx/project-config.d.ts.map +0 -1
- package/project/config/detect.d.ts +0 -77
- package/project/config/detect.d.ts.map +0 -1
- package/project/config/index.cjs.js.map +0 -1
- package/project/config/index.esm.js.map +0 -1
- package/project/config/parse.d.ts +0 -53
- package/project/config/parse.d.ts.map +0 -1
- package/project/config/patterns.d.ts +0 -31
- package/project/config/patterns.d.ts.map +0 -1
- package/project/index.cjs.js.map +0 -1
- package/project/index.esm.js.map +0 -1
- package/project/package/dependencies.d.ts +0 -101
- package/project/package/dependencies.d.ts.map +0 -1
- package/project/package/index.cjs.js.map +0 -1
- package/project/package/index.esm.js.map +0 -1
- package/project/package/read.d.ts +0 -67
- package/project/package/read.d.ts.map +0 -1
- package/project/root/detect.d.ts +0 -65
- package/project/root/detect.d.ts.map +0 -1
- package/project/root/index.cjs.js.map +0 -1
- package/project/root/index.esm.js.map +0 -1
- package/project/traversal/index.cjs.js.map +0 -1
- package/project/traversal/index.esm.js.map +0 -1
- package/project/traversal/search.d.ts +0 -59
- package/project/traversal/search.d.ts.map +0 -1
- package/project/traversal/walk.d.ts +0 -63
- package/project/traversal/walk.d.ts.map +0 -1
- package/tech/backend/detect-all.d.ts +0 -13
- package/tech/backend/detect-all.d.ts.map +0 -1
- package/tech/backend/express.d.ts +0 -11
- package/tech/backend/express.d.ts.map +0 -1
- package/tech/backend/fastify.d.ts +0 -11
- package/tech/backend/fastify.d.ts.map +0 -1
- package/tech/backend/hono.d.ts +0 -11
- package/tech/backend/hono.d.ts.map +0 -1
- package/tech/backend/index.cjs.js.map +0 -1
- package/tech/backend/index.esm.js.map +0 -1
- package/tech/backend/koa.d.ts +0 -11
- package/tech/backend/koa.d.ts.map +0 -1
- package/tech/backend/nestjs.d.ts +0 -11
- package/tech/backend/nestjs.d.ts.map +0 -1
- package/tech/backend/types.d.ts +0 -31
- package/tech/backend/types.d.ts.map +0 -1
- package/tech/build/babel.d.ts +0 -13
- package/tech/build/babel.d.ts.map +0 -1
- package/tech/build/detect-all.d.ts +0 -13
- package/tech/build/detect-all.d.ts.map +0 -1
- package/tech/build/esbuild.d.ts +0 -11
- package/tech/build/esbuild.d.ts.map +0 -1
- package/tech/build/index.cjs.js.map +0 -1
- package/tech/build/index.esm.js.map +0 -1
- package/tech/build/parcel.d.ts +0 -13
- package/tech/build/parcel.d.ts.map +0 -1
- package/tech/build/rollup.d.ts +0 -13
- package/tech/build/rollup.d.ts.map +0 -1
- package/tech/build/swc.d.ts +0 -13
- package/tech/build/swc.d.ts.map +0 -1
- package/tech/build/types.d.ts +0 -31
- package/tech/build/types.d.ts.map +0 -1
- package/tech/build/vite.d.ts +0 -13
- package/tech/build/vite.d.ts.map +0 -1
- package/tech/build/webpack.d.ts +0 -13
- package/tech/build/webpack.d.ts.map +0 -1
- package/tech/frontend/angular.d.ts +0 -11
- package/tech/frontend/angular.d.ts.map +0 -1
- package/tech/frontend/astro.d.ts +0 -11
- package/tech/frontend/astro.d.ts.map +0 -1
- package/tech/frontend/detect-all.d.ts +0 -13
- package/tech/frontend/detect-all.d.ts.map +0 -1
- package/tech/frontend/gatsby.d.ts +0 -11
- package/tech/frontend/gatsby.d.ts.map +0 -1
- package/tech/frontend/index.cjs.js.map +0 -1
- package/tech/frontend/index.esm.js.map +0 -1
- package/tech/frontend/nextjs.d.ts +0 -11
- package/tech/frontend/nextjs.d.ts.map +0 -1
- package/tech/frontend/nuxt.d.ts +0 -11
- package/tech/frontend/nuxt.d.ts.map +0 -1
- package/tech/frontend/qwik.d.ts +0 -11
- package/tech/frontend/qwik.d.ts.map +0 -1
- package/tech/frontend/react.d.ts +0 -11
- package/tech/frontend/react.d.ts.map +0 -1
- package/tech/frontend/remix.d.ts +0 -11
- package/tech/frontend/remix.d.ts.map +0 -1
- package/tech/frontend/solid.d.ts +0 -11
- package/tech/frontend/solid.d.ts.map +0 -1
- package/tech/frontend/svelte.d.ts +0 -11
- package/tech/frontend/svelte.d.ts.map +0 -1
- package/tech/frontend/sveltekit.d.ts +0 -11
- package/tech/frontend/sveltekit.d.ts.map +0 -1
- package/tech/frontend/types.d.ts +0 -35
- package/tech/frontend/types.d.ts.map +0 -1
- package/tech/frontend/vue.d.ts +0 -11
- package/tech/frontend/vue.d.ts.map +0 -1
- package/tech/index.cjs.js.map +0 -1
- package/tech/index.esm.js.map +0 -1
- package/tech/legacy/angularjs.d.ts +0 -12
- package/tech/legacy/angularjs.d.ts.map +0 -1
- package/tech/legacy/backbone.d.ts +0 -11
- package/tech/legacy/backbone.d.ts.map +0 -1
- package/tech/legacy/detect-all.d.ts +0 -13
- package/tech/legacy/detect-all.d.ts.map +0 -1
- package/tech/legacy/ember.d.ts +0 -11
- package/tech/legacy/ember.d.ts.map +0 -1
- package/tech/legacy/index.cjs.js.map +0 -1
- package/tech/legacy/index.esm.js.map +0 -1
- package/tech/legacy/jquery.d.ts +0 -11
- package/tech/legacy/jquery.d.ts.map +0 -1
- package/tech/legacy/types.d.ts +0 -33
- package/tech/legacy/types.d.ts.map +0 -1
- package/tech/linting/biome.d.ts +0 -11
- package/tech/linting/biome.d.ts.map +0 -1
- package/tech/linting/detect-all.d.ts +0 -13
- package/tech/linting/detect-all.d.ts.map +0 -1
- package/tech/linting/eslint.d.ts +0 -13
- package/tech/linting/eslint.d.ts.map +0 -1
- package/tech/linting/index.cjs.js.map +0 -1
- package/tech/linting/index.esm.js.map +0 -1
- package/tech/linting/prettier.d.ts +0 -13
- package/tech/linting/prettier.d.ts.map +0 -1
- package/tech/linting/stylelint.d.ts +0 -13
- package/tech/linting/stylelint.d.ts.map +0 -1
- package/tech/linting/types.d.ts +0 -31
- package/tech/linting/types.d.ts.map +0 -1
- package/tech/monorepo/detect-all.d.ts +0 -13
- package/tech/monorepo/detect-all.d.ts.map +0 -1
- package/tech/monorepo/index.cjs.js.map +0 -1
- package/tech/monorepo/index.esm.js.map +0 -1
- package/tech/monorepo/lerna.d.ts +0 -11
- package/tech/monorepo/lerna.d.ts.map +0 -1
- package/tech/monorepo/npm-workspaces.d.ts +0 -11
- package/tech/monorepo/npm-workspaces.d.ts.map +0 -1
- package/tech/monorepo/nx.d.ts +0 -11
- package/tech/monorepo/nx.d.ts.map +0 -1
- package/tech/monorepo/pnpm-workspaces.d.ts +0 -9
- package/tech/monorepo/pnpm-workspaces.d.ts.map +0 -1
- package/tech/monorepo/rush.d.ts +0 -11
- package/tech/monorepo/rush.d.ts.map +0 -1
- package/tech/monorepo/turborepo.d.ts +0 -11
- package/tech/monorepo/turborepo.d.ts.map +0 -1
- package/tech/monorepo/types.d.ts +0 -39
- package/tech/monorepo/types.d.ts.map +0 -1
- package/tech/monorepo/yarn-workspaces.d.ts +0 -11
- package/tech/monorepo/yarn-workspaces.d.ts.map +0 -1
- package/tech/shared-utils/detector-helpers.d.ts +0 -52
- package/tech/shared-utils/detector-helpers.d.ts.map +0 -1
- package/tech/shared-utils/types.d.ts +0 -41
- package/tech/shared-utils/types.d.ts.map +0 -1
- package/tech/testing/cypress.d.ts +0 -13
- package/tech/testing/cypress.d.ts.map +0 -1
- package/tech/testing/detect-all.d.ts +0 -13
- package/tech/testing/detect-all.d.ts.map +0 -1
- package/tech/testing/index.cjs.js.map +0 -1
- package/tech/testing/index.esm.js.map +0 -1
- package/tech/testing/jest.d.ts +0 -13
- package/tech/testing/jest.d.ts.map +0 -1
- package/tech/testing/mocha.d.ts +0 -13
- package/tech/testing/mocha.d.ts.map +0 -1
- package/tech/testing/playwright.d.ts +0 -13
- package/tech/testing/playwright.d.ts.map +0 -1
- package/tech/testing/types.d.ts +0 -35
- package/tech/testing/types.d.ts.map +0 -1
- package/tech/testing/vitest.d.ts +0 -13
- package/tech/testing/vitest.d.ts.map +0 -1
- package/tech/types/detectors.d.ts +0 -67
- package/tech/types/detectors.d.ts.map +0 -1
- package/tech/types/index.cjs.js.map +0 -1
- package/tech/types/index.esm.js.map +0 -1
- package/vfs/commit.d.ts +0 -32
- package/vfs/commit.d.ts.map +0 -1
- package/vfs/diff.d.ts +0 -73
- package/vfs/diff.d.ts.map +0 -1
- package/vfs/factory.d.ts +0 -37
- package/vfs/factory.d.ts.map +0 -1
- package/vfs/fs-tree.d.ts +0 -13
- package/vfs/fs-tree.d.ts.map +0 -1
- package/vfs/index.cjs.js.map +0 -1
- package/vfs/index.esm.js.map +0 -1
- package/vfs/types.d.ts +0 -179
- package/vfs/types.d.ts.map +0 -1
package/core/index.esm.js
CHANGED
|
@@ -1,420 +1,26 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { createMap } from '../_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/map/index.esm.js';
|
|
2
|
+
import { freeze, defineProperty, entries, keys, defineProperties } from '../_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/object/index.esm.js';
|
|
3
|
+
import { createSet } from '../_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/set/index.esm.js';
|
|
4
|
+
import { createError } from '../_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/error/index.esm.js';
|
|
5
|
+
import { isArray } from '../_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/array/index.esm.js';
|
|
6
|
+
import { error, warn, log, info, debug } from '../_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/console/index.esm.js';
|
|
7
|
+
import { stringify, parse } from '../_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/json/index.esm.js';
|
|
8
|
+
import { createLogger } from '../_dependencies/@hyperfrontend/logging/index.esm.js';
|
|
9
|
+
import { min } from '../_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/math/index.esm.js';
|
|
10
|
+
import { existsSync, readFileSync, statSync, lstatSync, mkdirSync, readdirSync, rmSync, realpathSync, writeFileSync, mkdtempSync, unlinkSync, rmdirSync } from 'node:fs';
|
|
11
|
+
import { join as join$1, normalize, sep, posix, isAbsolute as isAbsolute$1, relative, resolve, basename, dirname, extname, parse as parse$1 } from 'node:path';
|
|
3
12
|
import { tmpdir, platform, arch } from 'node:os';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
*/
|
|
16
|
-
const _Error = globalThis.Error;
|
|
17
|
-
const _Reflect$2 = globalThis.Reflect;
|
|
18
|
-
/**
|
|
19
|
-
* (Safe copy) Creates a new Error using the captured Error constructor.
|
|
20
|
-
* Use this instead of `new Error()`.
|
|
21
|
-
*
|
|
22
|
-
* @param message - Optional error message.
|
|
23
|
-
* @param options - Optional error options.
|
|
24
|
-
* @returns A new Error instance.
|
|
25
|
-
*/
|
|
26
|
-
const createError = (message, options) => _Reflect$2.construct(_Error, [message, options]);
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Safe copies of JSON built-in methods.
|
|
30
|
-
*
|
|
31
|
-
* These references are captured at module initialization time to protect against
|
|
32
|
-
* prototype pollution attacks. Import only what you need for tree-shaking.
|
|
33
|
-
*
|
|
34
|
-
* @module @hyperfrontend/immutable-api-utils/built-in-copy/json
|
|
35
|
-
*/
|
|
36
|
-
const _JSON = globalThis.JSON;
|
|
37
|
-
/**
|
|
38
|
-
* (Safe copy) Converts a JavaScript Object Notation (JSON) string into an object.
|
|
39
|
-
*/
|
|
40
|
-
const parse = _JSON.parse;
|
|
41
|
-
/**
|
|
42
|
-
* (Safe copy) Converts a JavaScript value to a JavaScript Object Notation (JSON) string.
|
|
43
|
-
*/
|
|
44
|
-
const stringify = _JSON.stringify;
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Safe copies of Object built-in methods.
|
|
48
|
-
*
|
|
49
|
-
* These references are captured at module initialization time to protect against
|
|
50
|
-
* prototype pollution attacks. Import only what you need for tree-shaking.
|
|
51
|
-
*
|
|
52
|
-
* @module @hyperfrontend/immutable-api-utils/built-in-copy/object
|
|
53
|
-
*/
|
|
54
|
-
const _Object = globalThis.Object;
|
|
55
|
-
/**
|
|
56
|
-
* (Safe copy) Prevents modification of existing property attributes and values,
|
|
57
|
-
* and prevents the addition of new properties.
|
|
58
|
-
*/
|
|
59
|
-
const freeze = _Object.freeze;
|
|
60
|
-
/**
|
|
61
|
-
* (Safe copy) Returns the names of the enumerable string properties and methods of an object.
|
|
62
|
-
*/
|
|
63
|
-
const keys = _Object.keys;
|
|
64
|
-
/**
|
|
65
|
-
* (Safe copy) Returns an array of key/values of the enumerable own properties of an object.
|
|
66
|
-
*/
|
|
67
|
-
const entries = _Object.entries;
|
|
68
|
-
/**
|
|
69
|
-
* (Safe copy) Adds a property to an object, or modifies attributes of an existing property.
|
|
70
|
-
*/
|
|
71
|
-
const defineProperty = _Object.defineProperty;
|
|
72
|
-
/**
|
|
73
|
-
* (Safe copy) Adds one or more properties to an object, and/or modifies attributes of existing properties.
|
|
74
|
-
*/
|
|
75
|
-
const defineProperties = _Object.defineProperties;
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Safe copies of Array built-in static methods.
|
|
79
|
-
*
|
|
80
|
-
* These references are captured at module initialization time to protect against
|
|
81
|
-
* prototype pollution attacks. Import only what you need for tree-shaking.
|
|
82
|
-
*
|
|
83
|
-
* @module @hyperfrontend/immutable-api-utils/built-in-copy/array
|
|
84
|
-
*/
|
|
85
|
-
const _Array = globalThis.Array;
|
|
86
|
-
/**
|
|
87
|
-
* (Safe copy) Determines whether the passed value is an Array.
|
|
88
|
-
*/
|
|
89
|
-
const isArray = _Array.isArray;
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Safe copies of Console built-in methods.
|
|
93
|
-
*
|
|
94
|
-
* These references are captured at module initialization time to protect against
|
|
95
|
-
* prototype pollution attacks. Import only what you need for tree-shaking.
|
|
96
|
-
*
|
|
97
|
-
* @module @hyperfrontend/immutable-api-utils/built-in-copy/console
|
|
98
|
-
*/
|
|
99
|
-
const _console = globalThis.console;
|
|
100
|
-
/**
|
|
101
|
-
* (Safe copy) Outputs a message to the console.
|
|
102
|
-
*/
|
|
103
|
-
const log = _console.log.bind(_console);
|
|
104
|
-
/**
|
|
105
|
-
* (Safe copy) Outputs a warning message to the console.
|
|
106
|
-
*/
|
|
107
|
-
const warn = _console.warn.bind(_console);
|
|
108
|
-
/**
|
|
109
|
-
* (Safe copy) Outputs an error message to the console.
|
|
110
|
-
*/
|
|
111
|
-
const error = _console.error.bind(_console);
|
|
112
|
-
/**
|
|
113
|
-
* (Safe copy) Outputs an informational message to the console.
|
|
114
|
-
*/
|
|
115
|
-
const info = _console.info.bind(_console);
|
|
116
|
-
/**
|
|
117
|
-
* (Safe copy) Outputs a debug message to the console.
|
|
118
|
-
*/
|
|
119
|
-
const debug = _console.debug.bind(_console);
|
|
120
|
-
/**
|
|
121
|
-
* (Safe copy) Outputs a stack trace to the console.
|
|
122
|
-
*/
|
|
123
|
-
_console.trace.bind(_console);
|
|
124
|
-
/**
|
|
125
|
-
* (Safe copy) Displays an interactive listing of the properties of a specified object.
|
|
126
|
-
*/
|
|
127
|
-
_console.dir.bind(_console);
|
|
128
|
-
/**
|
|
129
|
-
* (Safe copy) Displays tabular data as a table.
|
|
130
|
-
*/
|
|
131
|
-
_console.table.bind(_console);
|
|
132
|
-
/**
|
|
133
|
-
* (Safe copy) Writes an error message to the console if the assertion is false.
|
|
134
|
-
*/
|
|
135
|
-
_console.assert.bind(_console);
|
|
136
|
-
/**
|
|
137
|
-
* (Safe copy) Clears the console.
|
|
138
|
-
*/
|
|
139
|
-
_console.clear.bind(_console);
|
|
140
|
-
/**
|
|
141
|
-
* (Safe copy) Logs the number of times that this particular call to count() has been called.
|
|
142
|
-
*/
|
|
143
|
-
_console.count.bind(_console);
|
|
144
|
-
/**
|
|
145
|
-
* (Safe copy) Resets the counter used with console.count().
|
|
146
|
-
*/
|
|
147
|
-
_console.countReset.bind(_console);
|
|
148
|
-
/**
|
|
149
|
-
* (Safe copy) Creates a new inline group in the console.
|
|
150
|
-
*/
|
|
151
|
-
_console.group.bind(_console);
|
|
152
|
-
/**
|
|
153
|
-
* (Safe copy) Creates a new inline group in the console that is initially collapsed.
|
|
154
|
-
*/
|
|
155
|
-
_console.groupCollapsed.bind(_console);
|
|
156
|
-
/**
|
|
157
|
-
* (Safe copy) Exits the current inline group.
|
|
158
|
-
*/
|
|
159
|
-
_console.groupEnd.bind(_console);
|
|
160
|
-
/**
|
|
161
|
-
* (Safe copy) Starts a timer with a name specified as an input parameter.
|
|
162
|
-
*/
|
|
163
|
-
_console.time.bind(_console);
|
|
164
|
-
/**
|
|
165
|
-
* (Safe copy) Stops a timer that was previously started.
|
|
166
|
-
*/
|
|
167
|
-
_console.timeEnd.bind(_console);
|
|
168
|
-
/**
|
|
169
|
-
* (Safe copy) Logs the current value of a timer that was previously started.
|
|
170
|
-
*/
|
|
171
|
-
_console.timeLog.bind(_console);
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* Safe copies of Set built-in via factory function.
|
|
175
|
-
*
|
|
176
|
-
* Since constructors cannot be safely captured via Object.assign, this module
|
|
177
|
-
* provides a factory function that uses Reflect.construct internally.
|
|
178
|
-
*
|
|
179
|
-
* These references are captured at module initialization time to protect against
|
|
180
|
-
* prototype pollution attacks. Import only what you need for tree-shaking.
|
|
181
|
-
*
|
|
182
|
-
* @module @hyperfrontend/immutable-api-utils/built-in-copy/set
|
|
183
|
-
*/
|
|
184
|
-
const _Set = globalThis.Set;
|
|
185
|
-
const _Reflect$1 = globalThis.Reflect;
|
|
186
|
-
/**
|
|
187
|
-
* (Safe copy) Creates a new Set using the captured Set constructor.
|
|
188
|
-
* Use this instead of `new Set()`.
|
|
189
|
-
*
|
|
190
|
-
* @param iterable - Optional iterable of values.
|
|
191
|
-
* @returns A new Set instance.
|
|
192
|
-
*/
|
|
193
|
-
const createSet = (iterable) => _Reflect$1.construct(_Set, iterable ? [iterable] : []);
|
|
194
|
-
|
|
195
|
-
const registeredClasses = [];
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* Returns the data type of the target.
|
|
199
|
-
* Uses native `typeof` operator, however, makes distinction between `null`, `array`, and `object`.
|
|
200
|
-
* Also, when classes are registered via `registerClass`, it checks if objects are instance of any known registered class.
|
|
201
|
-
*
|
|
202
|
-
* @param target - The target to get the data type of.
|
|
203
|
-
* @returns The data type of the target.
|
|
204
|
-
*/
|
|
205
|
-
const getType = (target) => {
|
|
206
|
-
if (target === null)
|
|
207
|
-
return 'null';
|
|
208
|
-
const nativeDataType = typeof target;
|
|
209
|
-
if (nativeDataType === 'object') {
|
|
210
|
-
if (isArray(target))
|
|
211
|
-
return 'array';
|
|
212
|
-
for (const registeredClass of registeredClasses) {
|
|
213
|
-
if (target instanceof registeredClass)
|
|
214
|
-
return registeredClass.name;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
return nativeDataType;
|
|
218
|
-
};
|
|
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
|
-
const _Map = globalThis.Map;
|
|
232
|
-
const _Reflect = globalThis.Reflect;
|
|
233
|
-
/**
|
|
234
|
-
* (Safe copy) Creates a new Map using the captured Map constructor.
|
|
235
|
-
* Use this instead of `new Map()`.
|
|
236
|
-
*
|
|
237
|
-
* @param iterable - Optional iterable of key-value pairs.
|
|
238
|
-
* @returns A new Map instance.
|
|
239
|
-
*/
|
|
240
|
-
const createMap = (iterable) => _Reflect.construct(_Map, iterable ? [iterable] : []);
|
|
241
|
-
|
|
242
|
-
/**
|
|
243
|
-
* Safe copies of Math built-in methods.
|
|
244
|
-
*
|
|
245
|
-
* These references are captured at module initialization time to protect against
|
|
246
|
-
* prototype pollution attacks. Import only what you need for tree-shaking.
|
|
247
|
-
*
|
|
248
|
-
* @module @hyperfrontend/immutable-api-utils/built-in-copy/math
|
|
249
|
-
*/
|
|
250
|
-
const _Math = globalThis.Math;
|
|
251
|
-
/**
|
|
252
|
-
* (Safe copy) Returns the smaller of zero or more numbers.
|
|
253
|
-
*/
|
|
254
|
-
const min = _Math.min;
|
|
255
|
-
|
|
256
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
257
|
-
/**
|
|
258
|
-
* Creates a wrapper function that only executes the wrapped function if the condition function returns true.
|
|
259
|
-
*
|
|
260
|
-
* @param func - The function to be conditionally executed.
|
|
261
|
-
* @param conditionFunc - A function that returns a boolean, determining if `func` should be executed.
|
|
262
|
-
* @returns A wrapped version of `func` that executes conditionally.
|
|
263
|
-
*/
|
|
264
|
-
function createConditionalExecutionFunction(func, conditionFunc) {
|
|
265
|
-
return function (...args) {
|
|
266
|
-
if (conditionFunc()) {
|
|
267
|
-
return func(...args);
|
|
268
|
-
}
|
|
269
|
-
};
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
273
|
-
/**
|
|
274
|
-
* Creates a wrapper function that silently ignores any errors thrown by the wrapped void function.
|
|
275
|
-
* This function is specifically for wrapping functions that do not return a value (void functions).
|
|
276
|
-
* Exceptions are swallowed without any logging or handling.
|
|
277
|
-
*
|
|
278
|
-
* @param func - The void function to be wrapped.
|
|
279
|
-
* @returns A wrapped version of the input function that ignores errors.
|
|
280
|
-
*/
|
|
281
|
-
function createErrorIgnoringFunction(func) {
|
|
282
|
-
return function (...args) {
|
|
283
|
-
try {
|
|
284
|
-
func(...args);
|
|
285
|
-
}
|
|
286
|
-
catch {
|
|
287
|
-
// Deliberately swallowing/ignoring the exception
|
|
288
|
-
}
|
|
289
|
-
};
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
293
|
-
/**
|
|
294
|
-
* A no-operation function (noop) that does nothing regardless of the arguments passed.
|
|
295
|
-
* It is designed to be as permissive as possible in its typing without using the `Function` keyword.
|
|
296
|
-
*
|
|
297
|
-
* @param args - Any arguments passed to the function (ignored)
|
|
298
|
-
*/
|
|
299
|
-
const noop = (...args) => {
|
|
300
|
-
// Intentionally does nothing
|
|
301
|
-
};
|
|
302
|
-
|
|
303
|
-
const logLevels = ['none', 'error', 'warn', 'log', 'info', 'debug'];
|
|
304
|
-
const priority = {
|
|
305
|
-
error: 4,
|
|
306
|
-
warn: 3,
|
|
307
|
-
log: 2,
|
|
308
|
-
info: 1,
|
|
309
|
-
debug: 0,
|
|
310
|
-
};
|
|
311
|
-
/**
|
|
312
|
-
* Validates whether a given string is a valid log level.
|
|
313
|
-
*
|
|
314
|
-
* @param level - The log level to validate
|
|
315
|
-
* @returns True if the level is valid, false otherwise
|
|
316
|
-
*/
|
|
317
|
-
function isValidLogLevel(level) {
|
|
318
|
-
return logLevels.includes(level);
|
|
319
|
-
}
|
|
320
|
-
/**
|
|
321
|
-
* Creates a log level configuration manager for controlling logging behavior.
|
|
322
|
-
* Provides methods to get, set, and evaluate log levels based on priority.
|
|
323
|
-
*
|
|
324
|
-
* @param level - The initial log level (defaults to 'error')
|
|
325
|
-
* @returns A configuration object with log level management methods
|
|
326
|
-
* @throws {Error} When the provided level is not a valid log level
|
|
327
|
-
*/
|
|
328
|
-
function createLogLevelConfig(level = 'error') {
|
|
329
|
-
if (!isValidLogLevel(level)) {
|
|
330
|
-
throw createError('Cannot create log level configuration with a valid default log level');
|
|
331
|
-
}
|
|
332
|
-
const state = { level };
|
|
333
|
-
const getLogLevel = () => state.level;
|
|
334
|
-
const setLogLevel = (level) => {
|
|
335
|
-
if (!isValidLogLevel(level)) {
|
|
336
|
-
throw createError(`Cannot set value '${level}' level. Expected levels are ${logLevels}.`);
|
|
337
|
-
}
|
|
338
|
-
state.level = level;
|
|
339
|
-
};
|
|
340
|
-
const shouldLog = (level) => {
|
|
341
|
-
if (state.level === 'none' || level === 'none' || !isValidLogLevel(level)) {
|
|
342
|
-
return false;
|
|
343
|
-
}
|
|
344
|
-
return priority[level] >= priority[state.level];
|
|
345
|
-
};
|
|
346
|
-
return freeze({
|
|
347
|
-
getLogLevel,
|
|
348
|
-
setLogLevel,
|
|
349
|
-
shouldLog,
|
|
350
|
-
});
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
/**
|
|
354
|
-
* Creates a logger instance with configurable log level filtering.
|
|
355
|
-
* Each log function is wrapped to respect the current log level setting.
|
|
356
|
-
*
|
|
357
|
-
* @param error - Function to handle error-level logs (required)
|
|
358
|
-
* @param warn - Function to handle warning-level logs (optional, defaults to noop)
|
|
359
|
-
* @param log - Function to handle standard logs (optional, defaults to noop)
|
|
360
|
-
* @param info - Function to handle info-level logs (optional, defaults to noop)
|
|
361
|
-
* @param debug - Function to handle debug-level logs (optional, defaults to noop)
|
|
362
|
-
* @returns A frozen logger object with log methods and level control
|
|
363
|
-
* @throws {ErrorLevelFn} When any provided log function is invalid
|
|
364
|
-
*/
|
|
365
|
-
function createLogger(error, warn = noop, log = noop, info = noop, debug = noop) {
|
|
366
|
-
if (notValidLogFn(error)) {
|
|
367
|
-
throw createError(notFnMsg('error'));
|
|
368
|
-
}
|
|
369
|
-
if (notValidLogFn(warn)) {
|
|
370
|
-
throw createError(notFnMsg('warn'));
|
|
371
|
-
}
|
|
372
|
-
if (notValidLogFn(log)) {
|
|
373
|
-
throw createError(notFnMsg('log'));
|
|
374
|
-
}
|
|
375
|
-
if (notValidLogFn(info)) {
|
|
376
|
-
throw createError(notFnMsg('info'));
|
|
377
|
-
}
|
|
378
|
-
if (notValidLogFn(debug)) {
|
|
379
|
-
throw createError(notFnMsg('debug'));
|
|
380
|
-
}
|
|
381
|
-
const { setLogLevel, getLogLevel, shouldLog } = createLogLevelConfig();
|
|
382
|
-
const wrapLogFn = (fn, level) => {
|
|
383
|
-
if (fn === noop)
|
|
384
|
-
return fn;
|
|
385
|
-
const condition = () => shouldLog(level);
|
|
386
|
-
return createConditionalExecutionFunction(createErrorIgnoringFunction(fn), condition);
|
|
387
|
-
};
|
|
388
|
-
return freeze({
|
|
389
|
-
error: wrapLogFn(error, 'error'),
|
|
390
|
-
warn: wrapLogFn(warn, 'warn'),
|
|
391
|
-
log: wrapLogFn(log, 'log'),
|
|
392
|
-
info: wrapLogFn(info, 'info'),
|
|
393
|
-
debug: wrapLogFn(debug, 'debug'),
|
|
394
|
-
setLogLevel,
|
|
395
|
-
getLogLevel,
|
|
396
|
-
});
|
|
397
|
-
}
|
|
398
|
-
/**
|
|
399
|
-
* Validates whether a given value is a valid log function.
|
|
400
|
-
*
|
|
401
|
-
* @param fn - The value to validate
|
|
402
|
-
* @returns True if the value is not a function (invalid), false if it is valid
|
|
403
|
-
*/
|
|
404
|
-
function notValidLogFn(fn) {
|
|
405
|
-
return getType(fn) !== 'function' && fn !== noop;
|
|
406
|
-
}
|
|
407
|
-
/**
|
|
408
|
-
* Generates an error message for invalid log function parameters.
|
|
409
|
-
*
|
|
410
|
-
* @param label - The name of the log function that failed validation
|
|
411
|
-
* @returns A formatted error message string
|
|
412
|
-
*/
|
|
413
|
-
function notFnMsg(label) {
|
|
414
|
-
return `Cannot create a logger when ${label} is not a function`;
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
createLogger(error, warn, log, info, debug);
|
|
13
|
+
import { isSafePath } from '../_shared/core/fs/guard/index.esm.js';
|
|
14
|
+
import { getFileStat, isFile, isDirectory, isSymlink, exists } from '../_shared/core/fs/stat/index.esm.js';
|
|
15
|
+
import { normalizePath, normalizeToForwardSlashes, normalizeToNative, removeTrailingSlash, ensureTrailingSlash } from '../_shared/core/path/normalize/index.esm.js';
|
|
16
|
+
import { join, joinPosix } from '../_shared/core/path/join/index.esm.js';
|
|
17
|
+
import { resolvePath, resolveFromWorkspace, resolveRealPath, relativePath, joinPath, isAbsolute, offsetFromRoot } from '../_shared/core/path/resolve/index.esm.js';
|
|
18
|
+
import { pathSegments, getBasename, getDirname, getExtension, getFileNameWithoutExtension, parsePath } from '../_shared/core/path/segments/index.esm.js';
|
|
19
|
+
import { createStructuredError, createConfigError, createFsError, createParseError, createValidationError } from '../_shared/core/errors/structured-errors/index.esm.js';
|
|
20
|
+
import { createCache, clearAllCaches, getCacheCount, unregisterCache, memoize } from '../_shared/core/cache/index.esm.js';
|
|
21
|
+
import { matchGlobPattern, matchesAnyPattern, matchesExact } from '../_shared/core/patterns/glob/index.esm.js';
|
|
22
|
+
import { detectCaseSensitivity, isCaseSensitiveFs, getPlatformInfo, detectPlatform, isWindows } from '../_shared/core/platform/detect/index.esm.js';
|
|
23
|
+
import { LF, CRLF, getLineEnding, getPathSeparator, normalizeLineEndings, detectLineEnding, pathsEqual } from '../_shared/core/platform/line-endings/index.esm.js';
|
|
418
24
|
|
|
419
25
|
/**
|
|
420
26
|
* Global log level registry.
|
|
@@ -432,7 +38,7 @@ let globalLogLevel = null;
|
|
|
432
38
|
*
|
|
433
39
|
* @param level - The log level to set globally
|
|
434
40
|
*
|
|
435
|
-
* @example
|
|
41
|
+
* @example Enabling debug logging globally
|
|
436
42
|
* ```typescript
|
|
437
43
|
* import { setGlobalLogLevel } from '@hyperfrontend/project-scope/core'
|
|
438
44
|
*
|
|
@@ -450,6 +56,13 @@ function setGlobalLogLevel(level) {
|
|
|
450
56
|
* Get the current global log level.
|
|
451
57
|
*
|
|
452
58
|
* @returns The global log level, or null if not set
|
|
59
|
+
*
|
|
60
|
+
* @example Getting current log level
|
|
61
|
+
* ```typescript
|
|
62
|
+
* setGlobalLogLevel('debug')
|
|
63
|
+
* const level = getGlobalLogLevel()
|
|
64
|
+
* // => 'debug'
|
|
65
|
+
* ```
|
|
453
66
|
*/
|
|
454
67
|
function getGlobalLogLevel() {
|
|
455
68
|
return globalLogLevel;
|
|
@@ -457,6 +70,14 @@ function getGlobalLogLevel() {
|
|
|
457
70
|
/**
|
|
458
71
|
* Reset the global log level override.
|
|
459
72
|
* Each logger will retain its current level but new loggers will use their default.
|
|
73
|
+
*
|
|
74
|
+
* @example Resetting the global log level
|
|
75
|
+
* ```typescript
|
|
76
|
+
* setGlobalLogLevel('debug')
|
|
77
|
+
* // ... perform debugging ...
|
|
78
|
+
* resetGlobalLogLevel()
|
|
79
|
+
* // Global override removed, loggers use individual levels
|
|
80
|
+
* ```
|
|
460
81
|
*/
|
|
461
82
|
function resetGlobalLogLevel() {
|
|
462
83
|
globalLogLevel = null;
|
|
@@ -494,6 +115,13 @@ function isSensitiveKey(key) {
|
|
|
494
115
|
*
|
|
495
116
|
* @param obj - Object to sanitize
|
|
496
117
|
* @returns New object with sensitive values redacted
|
|
118
|
+
*
|
|
119
|
+
* @example Sanitizing sensitive data
|
|
120
|
+
* ```typescript
|
|
121
|
+
* const config = { apiKey: 'secret123', endpoint: 'https://api.example.com' }
|
|
122
|
+
* const safe = sanitize(config)
|
|
123
|
+
* // => { apiKey: '[REDACTED]', endpoint: 'https://api.example.com' }
|
|
124
|
+
* ```
|
|
497
125
|
*/
|
|
498
126
|
function sanitize(obj) {
|
|
499
127
|
if (obj === null || obj === undefined) {
|
|
@@ -544,7 +172,7 @@ function formatMessage(namespace, message, meta) {
|
|
|
544
172
|
* @param options - Logger configuration options
|
|
545
173
|
* @returns A configured scoped logger instance
|
|
546
174
|
*
|
|
547
|
-
* @example
|
|
175
|
+
* @example Creating a scoped logger
|
|
548
176
|
* ```typescript
|
|
549
177
|
* const logger = createScopedLogger('project-scope')
|
|
550
178
|
* logger.setLogLevel('debug')
|
|
@@ -581,7 +209,7 @@ function createScopedLogger(namespace, options = {}) {
|
|
|
581
209
|
* Default logger instance for the project-scope library.
|
|
582
210
|
* Use this for general logging within the library.
|
|
583
211
|
*
|
|
584
|
-
* @example
|
|
212
|
+
* @example Using the default logger
|
|
585
213
|
* ```typescript
|
|
586
214
|
* import { logger } from '@hyperfrontend/project-scope/core'
|
|
587
215
|
*
|
|
@@ -591,60 +219,330 @@ function createScopedLogger(namespace, options = {}) {
|
|
|
591
219
|
*/
|
|
592
220
|
const logger = createScopedLogger('project-scope');
|
|
593
221
|
|
|
594
|
-
const
|
|
222
|
+
const encodingLogger = createScopedLogger('project-scope:encoding');
|
|
223
|
+
/** UTF-8 BOM bytes */
|
|
224
|
+
const UTF8_BOM_BYTES = [0xef, 0xbb, 0xbf];
|
|
225
|
+
/** UTF-16 LE BOM bytes */
|
|
226
|
+
const UTF16_LE_BOM_BYTES = [0xff, 0xfe];
|
|
227
|
+
/** UTF-16 BE BOM bytes */
|
|
228
|
+
const UTF16_BE_BOM_BYTES = [0xfe, 0xff];
|
|
229
|
+
/** UTF-8 BOM string */
|
|
230
|
+
const UTF8_BOM = '\uFEFF';
|
|
595
231
|
/**
|
|
596
|
-
*
|
|
597
|
-
*
|
|
598
|
-
* @param message - The error message describing what went wrong
|
|
599
|
-
* @param code - The category code for this type of filesystem failure
|
|
600
|
-
* @param context - Additional context including path, operation, and cause
|
|
601
|
-
* @returns A configured Error object with code and context properties
|
|
232
|
+
* Common binary file signatures.
|
|
602
233
|
*/
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
}
|
|
609
|
-
|
|
610
|
-
}
|
|
234
|
+
const BINARY_SIGNATURES = [
|
|
235
|
+
{ signature: [0x89, 0x50, 0x4e, 0x47], description: 'PNG' },
|
|
236
|
+
{ signature: [0xff, 0xd8, 0xff], description: 'JPEG' },
|
|
237
|
+
{ signature: [0x47, 0x49, 0x46, 0x38], description: 'GIF' },
|
|
238
|
+
{ signature: [0x50, 0x4b, 0x03, 0x04], description: 'ZIP' },
|
|
239
|
+
{ signature: [0x1f, 0x8b], description: 'GZIP' },
|
|
240
|
+
{ signature: [0x42, 0x5a, 0x68], description: 'BZIP2' },
|
|
241
|
+
{ signature: [0x7f, 0x45, 0x4c, 0x46], description: 'ELF' },
|
|
242
|
+
{ signature: [0x4d, 0x5a], description: 'EXE' },
|
|
243
|
+
{ signature: [0x25, 0x50, 0x44, 0x46], description: 'PDF' },
|
|
244
|
+
];
|
|
611
245
|
/**
|
|
612
|
-
*
|
|
246
|
+
* Detect if content is likely text or binary with encoding information.
|
|
613
247
|
*
|
|
614
|
-
* @param
|
|
615
|
-
* @
|
|
616
|
-
* @returns File contents as string
|
|
617
|
-
* @throws {Error} If file doesn't exist or can't be read
|
|
248
|
+
* @param buffer - Buffer to analyze
|
|
249
|
+
* @returns Encoding information
|
|
618
250
|
*
|
|
619
|
-
* @example
|
|
251
|
+
* @example Detecting encoding and BOM info
|
|
620
252
|
* ```typescript
|
|
621
|
-
*
|
|
622
|
-
*
|
|
623
|
-
*
|
|
624
|
-
*
|
|
253
|
+
* const buffer = readFileSync('./document.txt')
|
|
254
|
+
* const info = detectEncodingInfo(buffer)
|
|
255
|
+
* if (info.type === 'text') {
|
|
256
|
+
* console.log(`Encoding: ${info.encoding}, BOM: ${info.hasBom}`)
|
|
257
|
+
* }
|
|
625
258
|
* ```
|
|
626
259
|
*/
|
|
627
|
-
function
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
260
|
+
function detectEncodingInfo(buffer) {
|
|
261
|
+
encodingLogger.debug('Detecting encoding info', { bufferSize: buffer.length });
|
|
262
|
+
if (buffer.length >= 3) {
|
|
263
|
+
if (buffer[0] === UTF8_BOM_BYTES[0] && buffer[1] === UTF8_BOM_BYTES[1] && buffer[2] === UTF8_BOM_BYTES[2]) {
|
|
264
|
+
encodingLogger.debug('Detected UTF-8 BOM');
|
|
265
|
+
return { type: 'text', encoding: 'utf-8', hasBom: true };
|
|
266
|
+
}
|
|
634
267
|
}
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
268
|
+
if (buffer.length >= 2) {
|
|
269
|
+
if (buffer[0] === UTF16_BE_BOM_BYTES[0] && buffer[1] === UTF16_BE_BOM_BYTES[1]) {
|
|
270
|
+
encodingLogger.debug('Detected UTF-16 BE BOM');
|
|
271
|
+
return { type: 'text', encoding: 'utf16le', hasBom: true };
|
|
272
|
+
}
|
|
273
|
+
if (buffer[0] === UTF16_LE_BOM_BYTES[0] && buffer[1] === UTF16_LE_BOM_BYTES[1]) {
|
|
274
|
+
encodingLogger.debug('Detected UTF-16 LE BOM');
|
|
275
|
+
return { type: 'text', encoding: 'utf16le', hasBom: true };
|
|
276
|
+
}
|
|
638
277
|
}
|
|
639
|
-
}
|
|
278
|
+
for (const { signature, description } of BINARY_SIGNATURES) {
|
|
279
|
+
if (buffer.length >= signature.length) {
|
|
280
|
+
let matches = true;
|
|
281
|
+
for (let i = 0; i < signature.length; i++) {
|
|
282
|
+
if (buffer[i] !== signature[i]) {
|
|
283
|
+
matches = false;
|
|
284
|
+
break;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
if (matches) {
|
|
288
|
+
encodingLogger.debug('Detected binary format by signature', { format: description });
|
|
289
|
+
return { type: 'binary', format: description };
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
const sampleSize = min(buffer.length, 8000);
|
|
294
|
+
for (let i = 0; i < sampleSize; i++) {
|
|
295
|
+
if (buffer[i] === 0) {
|
|
296
|
+
encodingLogger.debug('Detected binary content (null byte found)', { position: i });
|
|
297
|
+
return { type: 'binary' };
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
encodingLogger.debug('Detected text content (UTF-8 default)');
|
|
301
|
+
return { type: 'text', encoding: 'utf-8', hasBom: false };
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Detect file encoding from BOM or content analysis.
|
|
305
|
+
*
|
|
306
|
+
* @param buffer - Buffer to analyze
|
|
307
|
+
* @returns Detected encoding, defaults to 'utf-8'
|
|
308
|
+
*
|
|
309
|
+
* @example Detecting encoding from buffer
|
|
310
|
+
* ```typescript
|
|
311
|
+
* const buffer = readFileSync('./data.txt')
|
|
312
|
+
* const encoding = detectEncoding(buffer)
|
|
313
|
+
* const content = buffer.toString(encoding)
|
|
314
|
+
* ```
|
|
315
|
+
*/
|
|
316
|
+
function detectEncoding(buffer) {
|
|
317
|
+
if (buffer.length >= 3) {
|
|
318
|
+
if (buffer[0] === UTF8_BOM_BYTES[0] && buffer[1] === UTF8_BOM_BYTES[1] && buffer[2] === UTF8_BOM_BYTES[2]) {
|
|
319
|
+
return 'utf-8';
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
if (buffer.length >= 2) {
|
|
323
|
+
if (buffer[0] === UTF16_LE_BOM_BYTES[0] && buffer[1] === UTF16_LE_BOM_BYTES[1]) {
|
|
324
|
+
return 'utf16le';
|
|
325
|
+
}
|
|
326
|
+
if (buffer[0] === UTF16_BE_BOM_BYTES[0] && buffer[1] === UTF16_BE_BOM_BYTES[1]) {
|
|
327
|
+
return 'utf16le';
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
return 'utf-8';
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Check if buffer starts with a BOM.
|
|
334
|
+
*
|
|
335
|
+
* @param buffer - Buffer to check
|
|
336
|
+
* @returns True if buffer has a BOM
|
|
337
|
+
*
|
|
338
|
+
* @example Checking if buffer has BOM
|
|
339
|
+
* ```typescript
|
|
340
|
+
* const buffer = readFileSync('./file.txt')
|
|
341
|
+
* if (hasBom(buffer)) {
|
|
342
|
+
* // Strip BOM before processing
|
|
343
|
+
* }
|
|
344
|
+
* ```
|
|
345
|
+
*/
|
|
346
|
+
function hasBom(buffer) {
|
|
347
|
+
if (buffer.length >= 3) {
|
|
348
|
+
if (buffer[0] === UTF8_BOM_BYTES[0] && buffer[1] === UTF8_BOM_BYTES[1] && buffer[2] === UTF8_BOM_BYTES[2]) {
|
|
349
|
+
return true;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
if (buffer.length >= 2) {
|
|
353
|
+
if ((buffer[0] === UTF16_LE_BOM_BYTES[0] && buffer[1] === UTF16_LE_BOM_BYTES[1]) ||
|
|
354
|
+
(buffer[0] === UTF16_BE_BOM_BYTES[0] && buffer[1] === UTF16_BE_BOM_BYTES[1])) {
|
|
355
|
+
return true;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
return false;
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* Check if buffer represents text content.
|
|
362
|
+
*
|
|
363
|
+
* @param buffer - Buffer to check
|
|
364
|
+
* @returns True if the buffer appears to be text
|
|
365
|
+
*
|
|
366
|
+
* @example Checking if content is text
|
|
367
|
+
* ```typescript
|
|
368
|
+
* const buffer = readFileSync('./unknown-file')
|
|
369
|
+
* if (isTextFile(buffer)) {
|
|
370
|
+
* const content = buffer.toString('utf-8')
|
|
371
|
+
* }
|
|
372
|
+
* ```
|
|
373
|
+
*/
|
|
374
|
+
function isTextFile(buffer) {
|
|
375
|
+
return detectEncodingInfo(buffer).type === 'text';
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
const convertLogger = createScopedLogger('project-scope:encoding:convert');
|
|
379
|
+
/**
|
|
380
|
+
* Convert content to UTF-8 string.
|
|
381
|
+
*
|
|
382
|
+
* @param content - Buffer or string content
|
|
383
|
+
* @param sourceEncoding - Source encoding (auto-detected if not provided)
|
|
384
|
+
* @returns UTF-8 string
|
|
385
|
+
*
|
|
386
|
+
* @example Converting a buffer to UTF-8 string
|
|
387
|
+
* ```typescript
|
|
388
|
+
* const buffer = Buffer.from('Hello', 'utf-8')
|
|
389
|
+
* const text = toUtf8(buffer)
|
|
390
|
+
* // => 'Hello'
|
|
391
|
+
* ```
|
|
392
|
+
*/
|
|
393
|
+
function toUtf8(content, sourceEncoding = 'utf-8') {
|
|
394
|
+
if (typeof content === 'string') {
|
|
395
|
+
return content;
|
|
396
|
+
}
|
|
397
|
+
return content.toString(sourceEncoding);
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* Convert buffer to string with encoding detection.
|
|
401
|
+
*
|
|
402
|
+
* @param content - Buffer to convert
|
|
403
|
+
* @param encoding - Optional encoding override (auto-detected if not provided)
|
|
404
|
+
* @returns Converted string
|
|
405
|
+
* @throws {Error} If content is binary and cannot be converted
|
|
406
|
+
*
|
|
407
|
+
* @example Converting file buffer to string with auto-detection
|
|
408
|
+
* ```typescript
|
|
409
|
+
* const fileBuffer = readFileSync('./config.json')
|
|
410
|
+
* const content = bufferToString(fileBuffer)
|
|
411
|
+
* // => '{"key": "value"}'
|
|
412
|
+
* ```
|
|
413
|
+
*/
|
|
414
|
+
function bufferToString(content, encoding) {
|
|
415
|
+
convertLogger.debug('Converting buffer to string', { bufferSize: content.length, providedEncoding: encoding });
|
|
416
|
+
if (encoding) {
|
|
417
|
+
convertLogger.debug('Using provided encoding', { encoding });
|
|
418
|
+
return content.toString(encoding);
|
|
419
|
+
}
|
|
420
|
+
const info = detectEncodingInfo(content);
|
|
421
|
+
if (info.type === 'text') {
|
|
422
|
+
let offset = 0;
|
|
423
|
+
if (info.hasBom) {
|
|
424
|
+
offset = info.encoding === 'utf-8' ? 3 : 2;
|
|
425
|
+
convertLogger.debug('Stripping BOM from buffer', { encoding: info.encoding, bomOffset: offset });
|
|
426
|
+
}
|
|
427
|
+
return content.subarray(offset).toString(info.encoding);
|
|
428
|
+
}
|
|
429
|
+
convertLogger.warn('Cannot convert binary content to string', { format: info.type === 'binary' ? info.format : undefined });
|
|
430
|
+
throw createError('Cannot convert binary content to string');
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* Strip BOM from start of string if present.
|
|
434
|
+
*
|
|
435
|
+
* @param content - String that may have BOM
|
|
436
|
+
* @returns String without BOM
|
|
437
|
+
*
|
|
438
|
+
* @example Stripping BOM from a string
|
|
439
|
+
* ```typescript
|
|
440
|
+
* const withBom = '\ufeffHello World'
|
|
441
|
+
* const clean = stripBom(withBom)
|
|
442
|
+
* // => 'Hello World'
|
|
443
|
+
* ```
|
|
444
|
+
*/
|
|
445
|
+
function stripBom(content) {
|
|
446
|
+
if (content.charCodeAt(0) === 0xfeff) {
|
|
447
|
+
return content.slice(1);
|
|
448
|
+
}
|
|
449
|
+
return content;
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
* Add UTF-8 BOM to string if not present.
|
|
453
|
+
*
|
|
454
|
+
* @param content - String to add BOM to
|
|
455
|
+
* @returns String with BOM
|
|
456
|
+
*
|
|
457
|
+
* @example Adding UTF-8 BOM to content
|
|
458
|
+
* ```typescript
|
|
459
|
+
* const content = 'Hello World'
|
|
460
|
+
* const withBom = addBom(content)
|
|
461
|
+
* // => '\ufeffHello World'
|
|
462
|
+
* ```
|
|
463
|
+
*/
|
|
464
|
+
function addBom(content) {
|
|
465
|
+
if (content.charCodeAt(0) === 0xfeff) {
|
|
466
|
+
return content;
|
|
467
|
+
}
|
|
468
|
+
return UTF8_BOM + content;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
const fsLogger = createScopedLogger('project-scope:fs');
|
|
472
|
+
/**
|
|
473
|
+
* Create a file system error with code and context.
|
|
474
|
+
*
|
|
475
|
+
* @param message - The error message describing what went wrong
|
|
476
|
+
* @param code - The category code for this type of filesystem failure
|
|
477
|
+
* @param context - Additional context including path, operation, and cause
|
|
478
|
+
* @returns A configured Error object with code and context properties
|
|
479
|
+
*
|
|
480
|
+
* @example Creating a file system error
|
|
481
|
+
* ```typescript
|
|
482
|
+
* throw createFileSystemError(
|
|
483
|
+
* 'Cannot read file',
|
|
484
|
+
* 'FS_READ_ERROR',
|
|
485
|
+
* { path: './missing.txt', operation: 'read' }
|
|
486
|
+
* )
|
|
487
|
+
* ```
|
|
488
|
+
*/
|
|
489
|
+
function createFileSystemError(message, code, context) {
|
|
490
|
+
const error = createError(message);
|
|
491
|
+
defineProperties(error, {
|
|
492
|
+
code: { value: code, enumerable: true },
|
|
493
|
+
context: { value: context, enumerable: true },
|
|
494
|
+
});
|
|
495
|
+
return error;
|
|
496
|
+
}
|
|
497
|
+
/**
|
|
498
|
+
* Read file contents as string.
|
|
499
|
+
*
|
|
500
|
+
* @param filePath - Path to file
|
|
501
|
+
* @param encoding - File encoding (default: utf-8)
|
|
502
|
+
* @returns File contents as string
|
|
503
|
+
* @throws {Error} If file doesn't exist or can't be read
|
|
504
|
+
*
|
|
505
|
+
* @example Reading file contents
|
|
506
|
+
* ```typescript
|
|
507
|
+
* import { readFileContent } from '@hyperfrontend/project-scope'
|
|
508
|
+
*
|
|
509
|
+
* const content = readFileContent('./package.json')
|
|
510
|
+
* console.log(content) // JSON string
|
|
511
|
+
* ```
|
|
512
|
+
*/
|
|
513
|
+
function readFileContent(filePath, encoding = 'utf-8') {
|
|
514
|
+
if (!isSafePath(filePath)) {
|
|
515
|
+
throw createFileSystemError(`Unsafe file path: ${filePath}`, 'FS_READ_ERROR', { path: filePath, operation: 'read' });
|
|
516
|
+
}
|
|
517
|
+
if (!existsSync(filePath)) {
|
|
518
|
+
fsLogger.debug('File not found', { path: filePath });
|
|
519
|
+
throw createFileSystemError(`File not found: ${filePath}`, 'FS_NOT_FOUND', { path: filePath, operation: 'read' });
|
|
520
|
+
}
|
|
521
|
+
try {
|
|
522
|
+
return readFileSync(filePath, { encoding });
|
|
523
|
+
}
|
|
524
|
+
catch (error) {
|
|
525
|
+
fsLogger.warn('Failed to read file', { path: filePath });
|
|
526
|
+
throw createFileSystemError(`Failed to read file: ${filePath}`, 'FS_READ_ERROR', { path: filePath, operation: 'read', cause: error });
|
|
527
|
+
}
|
|
528
|
+
}
|
|
640
529
|
/**
|
|
641
530
|
* Read file contents as Buffer.
|
|
642
531
|
*
|
|
643
532
|
* @param filePath - Path to file
|
|
644
533
|
* @returns File contents as Buffer
|
|
645
534
|
* @throws {Error} If file doesn't exist or can't be read
|
|
535
|
+
*
|
|
536
|
+
* @example Reading file as buffer
|
|
537
|
+
* ```typescript
|
|
538
|
+
* const buffer = readFileBuffer('./image.png')
|
|
539
|
+
* console.log(buffer.length) // File size in bytes
|
|
540
|
+
* ```
|
|
646
541
|
*/
|
|
647
542
|
function readFileBuffer(filePath) {
|
|
543
|
+
if (!isSafePath(filePath)) {
|
|
544
|
+
throw createFileSystemError(`Unsafe file path: ${filePath}`, 'FS_READ_ERROR', { path: filePath, operation: 'read' });
|
|
545
|
+
}
|
|
648
546
|
if (!existsSync(filePath)) {
|
|
649
547
|
throw createFileSystemError(`File not found: ${filePath}`, 'FS_NOT_FOUND', { path: filePath, operation: 'read' });
|
|
650
548
|
}
|
|
@@ -661,9 +559,17 @@ function readFileBuffer(filePath) {
|
|
|
661
559
|
* @param filePath - Path to file
|
|
662
560
|
* @param encoding - File encoding (default: utf-8)
|
|
663
561
|
* @returns File contents or null if file doesn't exist
|
|
562
|
+
*
|
|
563
|
+
* @example Reading file if it exists
|
|
564
|
+
* ```typescript
|
|
565
|
+
* const content = readFileIfExists('./optional-config.json')
|
|
566
|
+
* if (content) {
|
|
567
|
+
* // File existed, use content
|
|
568
|
+
* }
|
|
569
|
+
* ```
|
|
664
570
|
*/
|
|
665
571
|
function readFileIfExists(filePath, encoding = 'utf-8') {
|
|
666
|
-
if (!existsSync(filePath)) {
|
|
572
|
+
if (!isSafePath(filePath) || !existsSync(filePath)) {
|
|
667
573
|
return null;
|
|
668
574
|
}
|
|
669
575
|
try {
|
|
@@ -682,7 +588,7 @@ function readFileIfExists(filePath, encoding = 'utf-8') {
|
|
|
682
588
|
* @returns Parsed JSON object
|
|
683
589
|
* @throws {Error} If file doesn't exist (when no default provided) or contains invalid JSON
|
|
684
590
|
*
|
|
685
|
-
* @example
|
|
591
|
+
* @example Reading JSON file
|
|
686
592
|
* ```typescript
|
|
687
593
|
* import { readJsonFile } from '@hyperfrontend/project-scope'
|
|
688
594
|
*
|
|
@@ -695,6 +601,9 @@ function readFileIfExists(filePath, encoding = 'utf-8') {
|
|
|
695
601
|
* ```
|
|
696
602
|
*/
|
|
697
603
|
function readJsonFile(filePath, options) {
|
|
604
|
+
if (!isSafePath(filePath)) {
|
|
605
|
+
throw createFileSystemError(`Unsafe file path: ${filePath}`, 'FS_READ_ERROR', { path: filePath, operation: 'read' });
|
|
606
|
+
}
|
|
698
607
|
if (!existsSync(filePath)) {
|
|
699
608
|
if (options && 'default' in options) {
|
|
700
609
|
fsLogger.debug('JSON file not found, using default', { path: filePath });
|
|
@@ -725,9 +634,16 @@ function readJsonFile(filePath, options) {
|
|
|
725
634
|
*
|
|
726
635
|
* @param filePath - Path to JSON file
|
|
727
636
|
* @returns Parsed JSON object or null if file doesn't exist or is invalid
|
|
637
|
+
*
|
|
638
|
+
* @example Reading JSON file if it exists
|
|
639
|
+
* ```typescript
|
|
640
|
+
* interface UserSettings { theme: string }
|
|
641
|
+
* const settings = readJsonFileIfExists<UserSettings>('./user-settings.json')
|
|
642
|
+
* const theme = settings?.theme ?? 'default'
|
|
643
|
+
* ```
|
|
728
644
|
*/
|
|
729
645
|
function readJsonFileIfExists(filePath) {
|
|
730
|
-
if (!existsSync(filePath)) {
|
|
646
|
+
if (!isSafePath(filePath) || !existsSync(filePath)) {
|
|
731
647
|
return null;
|
|
732
648
|
}
|
|
733
649
|
try {
|
|
@@ -739,194 +655,17 @@ function readJsonFileIfExists(filePath) {
|
|
|
739
655
|
}
|
|
740
656
|
}
|
|
741
657
|
|
|
742
|
-
const
|
|
743
|
-
/**
|
|
744
|
-
* Ensure directory exists, create recursively if not.
|
|
745
|
-
*
|
|
746
|
-
* @param dirPath - Directory path to ensure exists
|
|
747
|
-
*/
|
|
748
|
-
function ensureDir(dirPath) {
|
|
749
|
-
if (!existsSync(dirPath)) {
|
|
750
|
-
fsWriteLogger.debug('Creating directory recursively', { path: dirPath });
|
|
751
|
-
mkdirSync(dirPath, { recursive: true });
|
|
752
|
-
}
|
|
753
|
-
}
|
|
658
|
+
const fsDirLogger = createScopedLogger('project-scope:fs:dir');
|
|
754
659
|
/**
|
|
755
|
-
*
|
|
756
|
-
* Creates parent directories if needed.
|
|
660
|
+
* List immediate contents of a directory.
|
|
757
661
|
*
|
|
758
|
-
* @param
|
|
759
|
-
* @
|
|
760
|
-
* @
|
|
761
|
-
* @throws {Error} If write fails
|
|
662
|
+
* @param dirPath - Absolute or relative path to the directory
|
|
663
|
+
* @returns Array of entries with metadata for each file/directory
|
|
664
|
+
* @throws {Error} If directory doesn't exist or isn't a directory
|
|
762
665
|
*
|
|
763
|
-
* @example
|
|
666
|
+
* @example Listing directory contents
|
|
764
667
|
* ```typescript
|
|
765
|
-
* import {
|
|
766
|
-
*
|
|
767
|
-
* // Write a simple text file
|
|
768
|
-
* writeFileContent('./output/data.txt', 'Hello, World!')
|
|
769
|
-
*
|
|
770
|
-
* // Write with custom encoding
|
|
771
|
-
* writeFileContent('./output/data.txt', 'Content', { encoding: 'utf-8' })
|
|
772
|
-
* ```
|
|
773
|
-
*/
|
|
774
|
-
function writeFileContent(filePath, content, options) {
|
|
775
|
-
try {
|
|
776
|
-
fsWriteLogger.debug('Writing file content', { path: filePath, size: content.length, encoding: options?.encoding ?? 'utf-8' });
|
|
777
|
-
ensureDir(dirname(filePath));
|
|
778
|
-
writeFileSync(filePath, content, {
|
|
779
|
-
encoding: options?.encoding ?? 'utf-8',
|
|
780
|
-
mode: options?.mode,
|
|
781
|
-
});
|
|
782
|
-
fsWriteLogger.debug('File written successfully', { path: filePath });
|
|
783
|
-
}
|
|
784
|
-
catch (error) {
|
|
785
|
-
fsWriteLogger.warn('Failed to write file', { path: filePath, error: error instanceof Error ? error.message : String(error) });
|
|
786
|
-
throw createFileSystemError(`Failed to write file: ${filePath}`, 'FS_WRITE_ERROR', { path: filePath, operation: 'write', cause: error });
|
|
787
|
-
}
|
|
788
|
-
}
|
|
789
|
-
/**
|
|
790
|
-
* Write Buffer to file.
|
|
791
|
-
* Creates parent directories if needed.
|
|
792
|
-
*
|
|
793
|
-
* @param filePath - Absolute or relative path to the target file
|
|
794
|
-
* @param content - Buffer containing binary data to write
|
|
795
|
-
* @param options - Optional write configuration (mode)
|
|
796
|
-
* @throws {Error} If write fails
|
|
797
|
-
*/
|
|
798
|
-
function writeFileBuffer(filePath, content, options) {
|
|
799
|
-
try {
|
|
800
|
-
fsWriteLogger.debug('Writing file buffer', { path: filePath, size: content.length });
|
|
801
|
-
ensureDir(dirname(filePath));
|
|
802
|
-
writeFileSync(filePath, content, { mode: options?.mode });
|
|
803
|
-
fsWriteLogger.debug('Buffer written successfully', { path: filePath });
|
|
804
|
-
}
|
|
805
|
-
catch (error) {
|
|
806
|
-
fsWriteLogger.warn('Failed to write buffer', { path: filePath, error: error instanceof Error ? error.message : String(error) });
|
|
807
|
-
throw createFileSystemError(`Failed to write file: ${filePath}`, 'FS_WRITE_ERROR', { path: filePath, operation: 'write', cause: error });
|
|
808
|
-
}
|
|
809
|
-
}
|
|
810
|
-
/**
|
|
811
|
-
* Write JSON data to file with formatting.
|
|
812
|
-
* Creates parent directories if needed.
|
|
813
|
-
*
|
|
814
|
-
* @param filePath - Absolute or relative path to the target JSON file
|
|
815
|
-
* @param data - Object or value to serialize as JSON
|
|
816
|
-
* @param options - Optional write configuration (indent, encoding, mode)
|
|
817
|
-
* @throws {Error} If write fails
|
|
818
|
-
*
|
|
819
|
-
* @example
|
|
820
|
-
* ```typescript
|
|
821
|
-
* import { writeJsonFile } from '@hyperfrontend/project-scope'
|
|
822
|
-
*
|
|
823
|
-
* // Write object to JSON file
|
|
824
|
-
* writeJsonFile('./config.json', { port: 3000, debug: true })
|
|
825
|
-
*
|
|
826
|
-
* // Write with custom indentation
|
|
827
|
-
* writeJsonFile('./config.json', data, { indent: 4 })
|
|
828
|
-
* ```
|
|
829
|
-
*/
|
|
830
|
-
function writeJsonFile(filePath, data, options) {
|
|
831
|
-
try {
|
|
832
|
-
fsWriteLogger.debug('Writing JSON file', { path: filePath, indent: options?.indent ?? 2 });
|
|
833
|
-
const indent = options?.indent ?? 2;
|
|
834
|
-
const content = stringify(data, null, indent) + '\n';
|
|
835
|
-
writeFileContent(filePath, content, options);
|
|
836
|
-
fsWriteLogger.debug('JSON file written successfully', { path: filePath });
|
|
837
|
-
}
|
|
838
|
-
catch (error) {
|
|
839
|
-
if (error?.code === 'FS_WRITE_ERROR') {
|
|
840
|
-
throw error;
|
|
841
|
-
}
|
|
842
|
-
fsWriteLogger.warn('Failed to write JSON file', { path: filePath, error: error instanceof Error ? error.message : String(error) });
|
|
843
|
-
throw createFileSystemError(`Failed to write JSON file: ${filePath}`, 'FS_WRITE_ERROR', {
|
|
844
|
-
path: filePath,
|
|
845
|
-
operation: 'write',
|
|
846
|
-
cause: error,
|
|
847
|
-
});
|
|
848
|
-
}
|
|
849
|
-
}
|
|
850
|
-
|
|
851
|
-
/**
|
|
852
|
-
* Get file stats with error handling.
|
|
853
|
-
*
|
|
854
|
-
* @param filePath - Path to file
|
|
855
|
-
* @param followSymlinks - Whether to follow symlinks (default: true)
|
|
856
|
-
* @returns File stats or null if path doesn't exist
|
|
857
|
-
*/
|
|
858
|
-
function getFileStat(filePath, followSymlinks = true) {
|
|
859
|
-
if (!existsSync(filePath)) {
|
|
860
|
-
return null;
|
|
861
|
-
}
|
|
862
|
-
try {
|
|
863
|
-
const stat = followSymlinks ? statSync(filePath) : lstatSync(filePath);
|
|
864
|
-
return {
|
|
865
|
-
isFile: stat.isFile(),
|
|
866
|
-
isDirectory: stat.isDirectory(),
|
|
867
|
-
isSymlink: stat.isSymbolicLink(),
|
|
868
|
-
size: stat.size,
|
|
869
|
-
created: stat.birthtime,
|
|
870
|
-
modified: stat.mtime,
|
|
871
|
-
accessed: stat.atime,
|
|
872
|
-
mode: stat.mode,
|
|
873
|
-
};
|
|
874
|
-
}
|
|
875
|
-
catch {
|
|
876
|
-
return null;
|
|
877
|
-
}
|
|
878
|
-
}
|
|
879
|
-
/**
|
|
880
|
-
* Check if path is a file.
|
|
881
|
-
*
|
|
882
|
-
* @param filePath - Path to check
|
|
883
|
-
* @returns True if path is a file
|
|
884
|
-
*/
|
|
885
|
-
function isFile(filePath) {
|
|
886
|
-
const stats = getFileStat(filePath);
|
|
887
|
-
return stats?.isFile ?? false;
|
|
888
|
-
}
|
|
889
|
-
/**
|
|
890
|
-
* Check if path is a directory.
|
|
891
|
-
*
|
|
892
|
-
* @param dirPath - Path to check
|
|
893
|
-
* @returns True if path is a directory
|
|
894
|
-
*/
|
|
895
|
-
function isDirectory(dirPath) {
|
|
896
|
-
const stats = getFileStat(dirPath);
|
|
897
|
-
return stats?.isDirectory ?? false;
|
|
898
|
-
}
|
|
899
|
-
/**
|
|
900
|
-
* Check if path is a symbolic link.
|
|
901
|
-
*
|
|
902
|
-
* @param linkPath - Path to check
|
|
903
|
-
* @returns True if path is a symlink
|
|
904
|
-
*/
|
|
905
|
-
function isSymlink(linkPath) {
|
|
906
|
-
const stats = getFileStat(linkPath, false);
|
|
907
|
-
return stats?.isSymlink ?? false;
|
|
908
|
-
}
|
|
909
|
-
/**
|
|
910
|
-
* Check if path exists.
|
|
911
|
-
*
|
|
912
|
-
* @param filePath - Path to check
|
|
913
|
-
* @returns True if path exists
|
|
914
|
-
*/
|
|
915
|
-
function exists(filePath) {
|
|
916
|
-
return existsSync(filePath);
|
|
917
|
-
}
|
|
918
|
-
|
|
919
|
-
const fsDirLogger = createScopedLogger('project-scope:fs:dir');
|
|
920
|
-
/**
|
|
921
|
-
* List immediate contents of a directory.
|
|
922
|
-
*
|
|
923
|
-
* @param dirPath - Absolute or relative path to the directory
|
|
924
|
-
* @returns Array of entries with metadata for each file/directory
|
|
925
|
-
* @throws {Error} If directory doesn't exist or isn't a directory
|
|
926
|
-
*
|
|
927
|
-
* @example
|
|
928
|
-
* ```typescript
|
|
929
|
-
* import { readDirectory } from '@hyperfrontend/project-scope'
|
|
668
|
+
* import { readDirectory } from '@hyperfrontend/project-scope'
|
|
930
669
|
*
|
|
931
670
|
* const entries = readDirectory('./src')
|
|
932
671
|
* for (const entry of entries) {
|
|
@@ -971,7 +710,7 @@ function readDirectory(dirPath) {
|
|
|
971
710
|
* @param options - Configuration for depth limit, hidden files, and symlinks
|
|
972
711
|
* @returns Flat array of all entries found during traversal
|
|
973
712
|
*
|
|
974
|
-
* @example
|
|
713
|
+
* @example Recursive directory listing with options
|
|
975
714
|
* ```typescript
|
|
976
715
|
* import { readDirectoryRecursive } from '@hyperfrontend/project-scope'
|
|
977
716
|
*
|
|
@@ -1032,6 +771,15 @@ function readDirectoryRecursive(dirPath, options) {
|
|
|
1032
771
|
* @param dirPath - Path where the directory should be created
|
|
1033
772
|
* @param options - Creation options
|
|
1034
773
|
* @param options.recursive - Create parent directories if missing (default: true)
|
|
774
|
+
*
|
|
775
|
+
* @example Creating directories
|
|
776
|
+
* ```typescript
|
|
777
|
+
* // Create nested directories
|
|
778
|
+
* createDirectory('./output/reports/2024')
|
|
779
|
+
*
|
|
780
|
+
* // Create single directory without parents
|
|
781
|
+
* createDirectory('./logs', { recursive: false })
|
|
782
|
+
* ```
|
|
1035
783
|
*/
|
|
1036
784
|
function createDirectory(dirPath, options) {
|
|
1037
785
|
const recursive = options?.recursive ?? true;
|
|
@@ -1045,6 +793,15 @@ function createDirectory(dirPath, options) {
|
|
|
1045
793
|
* @param options - Removal configuration
|
|
1046
794
|
* @param options.recursive - Delete directory contents recursively
|
|
1047
795
|
* @param options.force - Ignore errors if directory doesn't exist
|
|
796
|
+
*
|
|
797
|
+
* @example Removing directories
|
|
798
|
+
* ```typescript
|
|
799
|
+
* // Remove directory and all contents
|
|
800
|
+
* removeDirectory('./temp', { recursive: true })
|
|
801
|
+
*
|
|
802
|
+
* // Safe removal (no error if missing)
|
|
803
|
+
* removeDirectory('./cache', { recursive: true, force: true })
|
|
804
|
+
* ```
|
|
1048
805
|
*/
|
|
1049
806
|
function removeDirectory(dirPath, options) {
|
|
1050
807
|
fsDirLogger.debug('Removing directory', { path: dirPath, recursive: options?.recursive, force: options?.force });
|
|
@@ -1054,227 +811,6 @@ function removeDirectory(dirPath, options) {
|
|
|
1054
811
|
});
|
|
1055
812
|
}
|
|
1056
813
|
|
|
1057
|
-
/**
|
|
1058
|
-
* Join path segments.
|
|
1059
|
-
* Uses platform-specific separators (e.g., / or \).
|
|
1060
|
-
*
|
|
1061
|
-
* @param paths - Path segments to join
|
|
1062
|
-
* @returns Joined path
|
|
1063
|
-
*/
|
|
1064
|
-
function join(...paths) {
|
|
1065
|
-
return join$1(...paths);
|
|
1066
|
-
}
|
|
1067
|
-
/**
|
|
1068
|
-
* Join path segments using POSIX separators (/).
|
|
1069
|
-
* Always uses forward slashes regardless of platform.
|
|
1070
|
-
*
|
|
1071
|
-
* @param paths - Path segments to join
|
|
1072
|
-
* @returns Joined path with forward slashes
|
|
1073
|
-
*/
|
|
1074
|
-
function joinPosix(...paths) {
|
|
1075
|
-
return posix.join(...paths);
|
|
1076
|
-
}
|
|
1077
|
-
|
|
1078
|
-
/**
|
|
1079
|
-
* Normalize path separators to forward slashes.
|
|
1080
|
-
*
|
|
1081
|
-
* @param filePath - Path to normalize
|
|
1082
|
-
* @returns Normalized path with forward slashes
|
|
1083
|
-
*/
|
|
1084
|
-
function normalizePath(filePath) {
|
|
1085
|
-
if (!filePath)
|
|
1086
|
-
return '';
|
|
1087
|
-
const normalized = normalize(filePath);
|
|
1088
|
-
return sep === '\\' ? normalized.replace(/\\/g, '/') : normalized;
|
|
1089
|
-
}
|
|
1090
|
-
/**
|
|
1091
|
-
* Convert path separators to forward slashes using POSIX style.
|
|
1092
|
-
* Resolves `.` and `..` segments for cross-platform configuration.
|
|
1093
|
-
*
|
|
1094
|
-
* @param filePath - The input path to convert
|
|
1095
|
-
* @returns Path with forward slashes and resolved segments
|
|
1096
|
-
*/
|
|
1097
|
-
function normalizeToForwardSlashes(filePath) {
|
|
1098
|
-
if (!filePath)
|
|
1099
|
-
return '';
|
|
1100
|
-
return normalize(filePath).split(sep).join('/');
|
|
1101
|
-
}
|
|
1102
|
-
/**
|
|
1103
|
-
* Convert path to use the operating system's native separator.
|
|
1104
|
-
*
|
|
1105
|
-
* @param filePath - The input path to convert
|
|
1106
|
-
* @returns Path with native separators (backslash on Windows, forward slash elsewhere)
|
|
1107
|
-
*/
|
|
1108
|
-
function normalizeToNative(filePath) {
|
|
1109
|
-
if (!filePath)
|
|
1110
|
-
return '';
|
|
1111
|
-
return normalize(filePath.replace(/[/\\]/g, sep));
|
|
1112
|
-
}
|
|
1113
|
-
/**
|
|
1114
|
-
* Strip any trailing forward or back slashes from a path.
|
|
1115
|
-
*
|
|
1116
|
-
* @param filePath - Path that may have trailing slashes
|
|
1117
|
-
* @returns Path with trailing slashes removed
|
|
1118
|
-
*/
|
|
1119
|
-
function removeTrailingSlash(filePath) {
|
|
1120
|
-
let i = filePath.length;
|
|
1121
|
-
while (i > 0 && (filePath[i - 1] === '/' || filePath[i - 1] === '\\')) {
|
|
1122
|
-
i--;
|
|
1123
|
-
}
|
|
1124
|
-
return filePath.slice(0, i);
|
|
1125
|
-
}
|
|
1126
|
-
/**
|
|
1127
|
-
* Append a forward slash to the path if not already present.
|
|
1128
|
-
*
|
|
1129
|
-
* @param filePath - Path to process
|
|
1130
|
-
* @returns Path with trailing forward slash
|
|
1131
|
-
*/
|
|
1132
|
-
function ensureTrailingSlash(filePath) {
|
|
1133
|
-
const normalized = removeTrailingSlash(filePath);
|
|
1134
|
-
return normalized + '/';
|
|
1135
|
-
}
|
|
1136
|
-
|
|
1137
|
-
/**
|
|
1138
|
-
* Resolve path segments to an absolute path.
|
|
1139
|
-
*
|
|
1140
|
-
* @param segments - Path segments to resolve
|
|
1141
|
-
* @returns Resolved absolute path with normalized separators
|
|
1142
|
-
*/
|
|
1143
|
-
function resolvePath(...segments) {
|
|
1144
|
-
return normalizePath(resolve(...segments));
|
|
1145
|
-
}
|
|
1146
|
-
/**
|
|
1147
|
-
* Resolve path relative to workspace root.
|
|
1148
|
-
*
|
|
1149
|
-
* @param workspaceRoot - Workspace root directory
|
|
1150
|
-
* @param segments - Path segments relative to workspace
|
|
1151
|
-
* @returns Resolved absolute path with normalized separators
|
|
1152
|
-
*/
|
|
1153
|
-
function resolveFromWorkspace(workspaceRoot, ...segments) {
|
|
1154
|
-
return normalizePath(resolve(workspaceRoot, ...segments));
|
|
1155
|
-
}
|
|
1156
|
-
/**
|
|
1157
|
-
* Resolve symlinks to real path.
|
|
1158
|
-
*
|
|
1159
|
-
* @param filePath - Path to resolve
|
|
1160
|
-
* @returns Real path or null if path doesn't exist
|
|
1161
|
-
*/
|
|
1162
|
-
function resolveRealPath(filePath) {
|
|
1163
|
-
if (!exists(filePath)) {
|
|
1164
|
-
return null;
|
|
1165
|
-
}
|
|
1166
|
-
try {
|
|
1167
|
-
return normalizePath(realpathSync(filePath));
|
|
1168
|
-
}
|
|
1169
|
-
catch {
|
|
1170
|
-
return null;
|
|
1171
|
-
}
|
|
1172
|
-
}
|
|
1173
|
-
/**
|
|
1174
|
-
* Compute the normalized path from source directory to target.
|
|
1175
|
-
*
|
|
1176
|
-
* @param from - Source path (base directory)
|
|
1177
|
-
* @param to - Target path to reach
|
|
1178
|
-
* @returns Relative path from source to target with forward slashes
|
|
1179
|
-
*/
|
|
1180
|
-
function relativePath(from, to) {
|
|
1181
|
-
return normalizePath(relative(from, to));
|
|
1182
|
-
}
|
|
1183
|
-
/**
|
|
1184
|
-
* Join path segments.
|
|
1185
|
-
*
|
|
1186
|
-
* @param segments - Path segments to join
|
|
1187
|
-
* @returns Joined path with normalized separators
|
|
1188
|
-
*/
|
|
1189
|
-
function joinPath(...segments) {
|
|
1190
|
-
return normalizePath(join$1(...segments));
|
|
1191
|
-
}
|
|
1192
|
-
/**
|
|
1193
|
-
* Check if path is absolute.
|
|
1194
|
-
*
|
|
1195
|
-
* @param filePath - Path to check
|
|
1196
|
-
* @returns True if path is absolute
|
|
1197
|
-
*/
|
|
1198
|
-
function isAbsolute(filePath) {
|
|
1199
|
-
return isAbsolute$1(filePath);
|
|
1200
|
-
}
|
|
1201
|
-
/**
|
|
1202
|
-
* Calculate offset from root (e.g., "../../../").
|
|
1203
|
-
*
|
|
1204
|
-
* @param filePath - Path to calculate offset for
|
|
1205
|
-
* @returns Relative offset path (e.g., "../../")
|
|
1206
|
-
*/
|
|
1207
|
-
function offsetFromRoot(filePath) {
|
|
1208
|
-
const segments = normalizePath(filePath).split('/').filter(Boolean);
|
|
1209
|
-
if (segments.length === 0)
|
|
1210
|
-
return '';
|
|
1211
|
-
return segments.map(() => '..').join('/') + '/';
|
|
1212
|
-
}
|
|
1213
|
-
|
|
1214
|
-
/**
|
|
1215
|
-
* Split path into segments.
|
|
1216
|
-
*
|
|
1217
|
-
* @param filePath - Path to split
|
|
1218
|
-
* @returns Array of path segments
|
|
1219
|
-
*/
|
|
1220
|
-
function pathSegments(filePath) {
|
|
1221
|
-
return filePath.split(/[/\\]/).filter((segment) => segment.length > 0);
|
|
1222
|
-
}
|
|
1223
|
-
/**
|
|
1224
|
-
* Get basename of path.
|
|
1225
|
-
*
|
|
1226
|
-
* @param filePath - Path to extract basename from
|
|
1227
|
-
* @param ext - Optional extension to strip
|
|
1228
|
-
* @returns Basename of path
|
|
1229
|
-
*/
|
|
1230
|
-
function getBasename(filePath, ext) {
|
|
1231
|
-
return basename(filePath, ext);
|
|
1232
|
-
}
|
|
1233
|
-
/**
|
|
1234
|
-
* Get directory name of path.
|
|
1235
|
-
*
|
|
1236
|
-
* @param filePath - Path to extract directory from
|
|
1237
|
-
* @returns Directory name
|
|
1238
|
-
*/
|
|
1239
|
-
function getDirname(filePath) {
|
|
1240
|
-
return normalizePath(dirname(filePath));
|
|
1241
|
-
}
|
|
1242
|
-
/**
|
|
1243
|
-
* Get file extension (including dot).
|
|
1244
|
-
*
|
|
1245
|
-
* @param filePath - Path to extract extension from
|
|
1246
|
-
* @returns Extension including dot (e.g., '.ts')
|
|
1247
|
-
*/
|
|
1248
|
-
function getExtension(filePath) {
|
|
1249
|
-
return extname(filePath);
|
|
1250
|
-
}
|
|
1251
|
-
/**
|
|
1252
|
-
* Get filename without extension.
|
|
1253
|
-
*
|
|
1254
|
-
* @param filePath - Path to extract name from
|
|
1255
|
-
* @returns Filename without extension
|
|
1256
|
-
*/
|
|
1257
|
-
function getFileNameWithoutExtension(filePath) {
|
|
1258
|
-
const parsed = parse$1(filePath);
|
|
1259
|
-
return parsed.name;
|
|
1260
|
-
}
|
|
1261
|
-
/**
|
|
1262
|
-
* Parse path into components.
|
|
1263
|
-
*
|
|
1264
|
-
* @param filePath - Path to parse
|
|
1265
|
-
* @returns Parsed path components
|
|
1266
|
-
*/
|
|
1267
|
-
function parsePath(filePath) {
|
|
1268
|
-
const parsed = parse$1(filePath);
|
|
1269
|
-
return {
|
|
1270
|
-
root: parsed.root,
|
|
1271
|
-
dir: normalizePath(parsed.dir),
|
|
1272
|
-
base: parsed.base,
|
|
1273
|
-
ext: parsed.ext,
|
|
1274
|
-
name: parsed.name,
|
|
1275
|
-
};
|
|
1276
|
-
}
|
|
1277
|
-
|
|
1278
814
|
const fsTraversalLogger = createScopedLogger('project-scope:fs:traversal');
|
|
1279
815
|
/**
|
|
1280
816
|
* Generic upward directory traversal.
|
|
@@ -1283,6 +819,15 @@ const fsTraversalLogger = createScopedLogger('project-scope:fs:traversal');
|
|
|
1283
819
|
* @param startPath - Starting directory
|
|
1284
820
|
* @param predicate - Function to test each directory
|
|
1285
821
|
* @returns First matching directory or null
|
|
822
|
+
*
|
|
823
|
+
* @example Finding directory containing README
|
|
824
|
+
* ```typescript
|
|
825
|
+
* // Find first directory containing a README
|
|
826
|
+
* const readmeDir = traverseUpward('./src/utils', (dir) =>
|
|
827
|
+
* existsSync(join(dir, 'README.md'))
|
|
828
|
+
* )
|
|
829
|
+
* // => '/project' or null
|
|
830
|
+
* ```
|
|
1286
831
|
*/
|
|
1287
832
|
function traverseUpward(startPath, predicate) {
|
|
1288
833
|
fsTraversalLogger.debug('Starting upward traversal', { startPath });
|
|
@@ -1308,6 +853,17 @@ function traverseUpward(startPath, predicate) {
|
|
|
1308
853
|
* @param startPath - Starting directory
|
|
1309
854
|
* @param markers - Array of marker file names to search for
|
|
1310
855
|
* @returns First directory containing any marker, or null
|
|
856
|
+
*
|
|
857
|
+
* @example Finding project root by marker files
|
|
858
|
+
* ```typescript
|
|
859
|
+
* // Find project root by looking for common marker files
|
|
860
|
+
* const projectRoot = locateByMarkers('./src/components', [
|
|
861
|
+
* 'package.json',
|
|
862
|
+
* 'nx.json',
|
|
863
|
+
* 'tsconfig.base.json'
|
|
864
|
+
* ])
|
|
865
|
+
* // => '/workspace/my-project'
|
|
866
|
+
* ```
|
|
1311
867
|
*/
|
|
1312
868
|
function locateByMarkers(startPath, markers) {
|
|
1313
869
|
fsTraversalLogger.debug('Locating by markers', { startPath, markers });
|
|
@@ -1323,912 +879,139 @@ function locateByMarkers(startPath, markers) {
|
|
|
1323
879
|
* @param startPath - Starting directory
|
|
1324
880
|
* @param test - Function to test if directory matches criteria
|
|
1325
881
|
* @returns Matching directory path or null
|
|
882
|
+
*
|
|
883
|
+
* @example Finding directory with specific config
|
|
884
|
+
* ```typescript
|
|
885
|
+
* // Find directory with a specific config
|
|
886
|
+
* const configDir = findUpwardWhere('./deep/nested/path', (dir) =>
|
|
887
|
+
* existsSync(join(dir, '.eslintrc.js'))
|
|
888
|
+
* )
|
|
889
|
+
* ```
|
|
1326
890
|
*/
|
|
1327
891
|
function findUpwardWhere(startPath, test) {
|
|
1328
892
|
fsTraversalLogger.debug('Finding upward where condition met', { startPath });
|
|
1329
893
|
return traverseUpward(startPath, test);
|
|
1330
894
|
}
|
|
1331
895
|
|
|
1332
|
-
const
|
|
1333
|
-
/** UTF-8 BOM bytes */
|
|
1334
|
-
const UTF8_BOM_BYTES = [0xef, 0xbb, 0xbf];
|
|
1335
|
-
/** UTF-16 LE BOM bytes */
|
|
1336
|
-
const UTF16_LE_BOM_BYTES = [0xff, 0xfe];
|
|
1337
|
-
/** UTF-16 BE BOM bytes */
|
|
1338
|
-
const UTF16_BE_BOM_BYTES = [0xfe, 0xff];
|
|
1339
|
-
/** UTF-8 BOM string */
|
|
1340
|
-
const UTF8_BOM = '\uFEFF';
|
|
896
|
+
const fsWriteLogger = createScopedLogger('project-scope:fs:write');
|
|
1341
897
|
/**
|
|
1342
|
-
*
|
|
898
|
+
* Ensure directory exists, create recursively if not.
|
|
899
|
+
*
|
|
900
|
+
* @param dirPath - Directory path to ensure exists
|
|
901
|
+
*
|
|
902
|
+
* @example Ensuring directory exists
|
|
903
|
+
* ```typescript
|
|
904
|
+
* ensureDir('./output/reports')
|
|
905
|
+
* // Directory now exists (created if missing)
|
|
906
|
+
* ```
|
|
1343
907
|
*/
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
{ signature: [0x50, 0x4b, 0x03, 0x04], description: 'ZIP' },
|
|
1349
|
-
{ signature: [0x1f, 0x8b], description: 'GZIP' },
|
|
1350
|
-
{ signature: [0x42, 0x5a, 0x68], description: 'BZIP2' },
|
|
1351
|
-
{ signature: [0x7f, 0x45, 0x4c, 0x46], description: 'ELF' },
|
|
1352
|
-
{ signature: [0x4d, 0x5a], description: 'EXE' },
|
|
1353
|
-
{ signature: [0x25, 0x50, 0x44, 0x46], description: 'PDF' },
|
|
1354
|
-
];
|
|
1355
|
-
/**
|
|
1356
|
-
* Detect if content is likely text or binary with encoding information.
|
|
1357
|
-
*
|
|
1358
|
-
* @param buffer - Buffer to analyze
|
|
1359
|
-
* @returns Encoding information
|
|
1360
|
-
*/
|
|
1361
|
-
function detectEncodingInfo(buffer) {
|
|
1362
|
-
encodingLogger.debug('Detecting encoding info', { bufferSize: buffer.length });
|
|
1363
|
-
if (buffer.length >= 3) {
|
|
1364
|
-
if (buffer[0] === UTF8_BOM_BYTES[0] && buffer[1] === UTF8_BOM_BYTES[1] && buffer[2] === UTF8_BOM_BYTES[2]) {
|
|
1365
|
-
encodingLogger.debug('Detected UTF-8 BOM');
|
|
1366
|
-
return { type: 'text', encoding: 'utf-8', hasBom: true };
|
|
1367
|
-
}
|
|
1368
|
-
}
|
|
1369
|
-
if (buffer.length >= 2) {
|
|
1370
|
-
if (buffer[0] === UTF16_BE_BOM_BYTES[0] && buffer[1] === UTF16_BE_BOM_BYTES[1]) {
|
|
1371
|
-
encodingLogger.debug('Detected UTF-16 BE BOM');
|
|
1372
|
-
return { type: 'text', encoding: 'utf16le', hasBom: true };
|
|
1373
|
-
}
|
|
1374
|
-
if (buffer[0] === UTF16_LE_BOM_BYTES[0] && buffer[1] === UTF16_LE_BOM_BYTES[1]) {
|
|
1375
|
-
encodingLogger.debug('Detected UTF-16 LE BOM');
|
|
1376
|
-
return { type: 'text', encoding: 'utf16le', hasBom: true };
|
|
1377
|
-
}
|
|
1378
|
-
}
|
|
1379
|
-
for (const { signature, description } of BINARY_SIGNATURES) {
|
|
1380
|
-
if (buffer.length >= signature.length) {
|
|
1381
|
-
let matches = true;
|
|
1382
|
-
for (let i = 0; i < signature.length; i++) {
|
|
1383
|
-
if (buffer[i] !== signature[i]) {
|
|
1384
|
-
matches = false;
|
|
1385
|
-
break;
|
|
1386
|
-
}
|
|
1387
|
-
}
|
|
1388
|
-
if (matches) {
|
|
1389
|
-
encodingLogger.debug('Detected binary format by signature', { format: description });
|
|
1390
|
-
return { type: 'binary', format: description };
|
|
1391
|
-
}
|
|
1392
|
-
}
|
|
1393
|
-
}
|
|
1394
|
-
const sampleSize = min(buffer.length, 8000);
|
|
1395
|
-
for (let i = 0; i < sampleSize; i++) {
|
|
1396
|
-
if (buffer[i] === 0) {
|
|
1397
|
-
encodingLogger.debug('Detected binary content (null byte found)', { position: i });
|
|
1398
|
-
return { type: 'binary' };
|
|
1399
|
-
}
|
|
1400
|
-
}
|
|
1401
|
-
encodingLogger.debug('Detected text content (UTF-8 default)');
|
|
1402
|
-
return { type: 'text', encoding: 'utf-8', hasBom: false };
|
|
1403
|
-
}
|
|
1404
|
-
/**
|
|
1405
|
-
* Detect file encoding from BOM or content analysis.
|
|
1406
|
-
*
|
|
1407
|
-
* @param buffer - Buffer to analyze
|
|
1408
|
-
* @returns Detected encoding, defaults to 'utf-8'
|
|
1409
|
-
*/
|
|
1410
|
-
function detectEncoding(buffer) {
|
|
1411
|
-
if (buffer.length >= 3) {
|
|
1412
|
-
if (buffer[0] === UTF8_BOM_BYTES[0] && buffer[1] === UTF8_BOM_BYTES[1] && buffer[2] === UTF8_BOM_BYTES[2]) {
|
|
1413
|
-
return 'utf-8';
|
|
1414
|
-
}
|
|
1415
|
-
}
|
|
1416
|
-
if (buffer.length >= 2) {
|
|
1417
|
-
if (buffer[0] === UTF16_LE_BOM_BYTES[0] && buffer[1] === UTF16_LE_BOM_BYTES[1]) {
|
|
1418
|
-
return 'utf16le';
|
|
1419
|
-
}
|
|
1420
|
-
if (buffer[0] === UTF16_BE_BOM_BYTES[0] && buffer[1] === UTF16_BE_BOM_BYTES[1]) {
|
|
1421
|
-
return 'utf16le';
|
|
1422
|
-
}
|
|
1423
|
-
}
|
|
1424
|
-
return 'utf-8';
|
|
1425
|
-
}
|
|
1426
|
-
/**
|
|
1427
|
-
* Check if buffer starts with a BOM.
|
|
1428
|
-
*
|
|
1429
|
-
* @param buffer - Buffer to check
|
|
1430
|
-
* @returns True if buffer has a BOM
|
|
1431
|
-
*/
|
|
1432
|
-
function hasBom(buffer) {
|
|
1433
|
-
if (buffer.length >= 3) {
|
|
1434
|
-
if (buffer[0] === UTF8_BOM_BYTES[0] && buffer[1] === UTF8_BOM_BYTES[1] && buffer[2] === UTF8_BOM_BYTES[2]) {
|
|
1435
|
-
return true;
|
|
1436
|
-
}
|
|
1437
|
-
}
|
|
1438
|
-
if (buffer.length >= 2) {
|
|
1439
|
-
if ((buffer[0] === UTF16_LE_BOM_BYTES[0] && buffer[1] === UTF16_LE_BOM_BYTES[1]) ||
|
|
1440
|
-
(buffer[0] === UTF16_BE_BOM_BYTES[0] && buffer[1] === UTF16_BE_BOM_BYTES[1])) {
|
|
1441
|
-
return true;
|
|
1442
|
-
}
|
|
1443
|
-
}
|
|
1444
|
-
return false;
|
|
1445
|
-
}
|
|
1446
|
-
/**
|
|
1447
|
-
* Check if buffer represents text content.
|
|
1448
|
-
*
|
|
1449
|
-
* @param buffer - Buffer to check
|
|
1450
|
-
* @returns True if the buffer appears to be text
|
|
1451
|
-
*/
|
|
1452
|
-
function isTextFile(buffer) {
|
|
1453
|
-
return detectEncodingInfo(buffer).type === 'text';
|
|
1454
|
-
}
|
|
1455
|
-
/**
|
|
1456
|
-
* Check if buffer represents binary content.
|
|
1457
|
-
*
|
|
1458
|
-
* @param buffer - Buffer to check
|
|
1459
|
-
* @returns True if the buffer appears to be binary
|
|
1460
|
-
*/
|
|
1461
|
-
function isBinaryFile(buffer) {
|
|
1462
|
-
return detectEncodingInfo(buffer).type === 'binary';
|
|
1463
|
-
}
|
|
1464
|
-
|
|
1465
|
-
const convertLogger = createScopedLogger('project-scope:encoding:convert');
|
|
1466
|
-
/**
|
|
1467
|
-
* Convert content to UTF-8 string.
|
|
1468
|
-
*
|
|
1469
|
-
* @param content - Buffer or string content
|
|
1470
|
-
* @param sourceEncoding - Source encoding (auto-detected if not provided)
|
|
1471
|
-
* @returns UTF-8 string
|
|
1472
|
-
*/
|
|
1473
|
-
function toUtf8(content, sourceEncoding = 'utf-8') {
|
|
1474
|
-
if (typeof content === 'string') {
|
|
1475
|
-
return content;
|
|
1476
|
-
}
|
|
1477
|
-
return content.toString(sourceEncoding);
|
|
1478
|
-
}
|
|
1479
|
-
/**
|
|
1480
|
-
* Convert buffer to string with encoding detection.
|
|
1481
|
-
*
|
|
1482
|
-
* @param content - Buffer to convert
|
|
1483
|
-
* @param encoding - Optional encoding override (auto-detected if not provided)
|
|
1484
|
-
* @returns Converted string
|
|
1485
|
-
* @throws {Error} If content is binary and cannot be converted
|
|
1486
|
-
*/
|
|
1487
|
-
function bufferToString(content, encoding) {
|
|
1488
|
-
convertLogger.debug('Converting buffer to string', { bufferSize: content.length, providedEncoding: encoding });
|
|
1489
|
-
if (encoding) {
|
|
1490
|
-
convertLogger.debug('Using provided encoding', { encoding });
|
|
1491
|
-
return content.toString(encoding);
|
|
1492
|
-
}
|
|
1493
|
-
const info = detectEncodingInfo(content);
|
|
1494
|
-
if (info.type === 'text') {
|
|
1495
|
-
let offset = 0;
|
|
1496
|
-
if (info.hasBom) {
|
|
1497
|
-
offset = info.encoding === 'utf-8' ? 3 : 2;
|
|
1498
|
-
convertLogger.debug('Stripping BOM from buffer', { encoding: info.encoding, bomOffset: offset });
|
|
1499
|
-
}
|
|
1500
|
-
return content.subarray(offset).toString(info.encoding);
|
|
1501
|
-
}
|
|
1502
|
-
convertLogger.warn('Cannot convert binary content to string', { format: info.type === 'binary' ? info.format : undefined });
|
|
1503
|
-
throw createError('Cannot convert binary content to string');
|
|
1504
|
-
}
|
|
1505
|
-
/**
|
|
1506
|
-
* Strip BOM from start of string if present.
|
|
1507
|
-
*
|
|
1508
|
-
* @param content - String that may have BOM
|
|
1509
|
-
* @returns String without BOM
|
|
1510
|
-
*/
|
|
1511
|
-
function stripBom(content) {
|
|
1512
|
-
if (content.charCodeAt(0) === 0xfeff) {
|
|
1513
|
-
return content.slice(1);
|
|
1514
|
-
}
|
|
1515
|
-
return content;
|
|
1516
|
-
}
|
|
1517
|
-
/**
|
|
1518
|
-
* Add UTF-8 BOM to string if not present.
|
|
1519
|
-
*
|
|
1520
|
-
* @param content - String to add BOM to
|
|
1521
|
-
* @returns String with BOM
|
|
1522
|
-
*/
|
|
1523
|
-
function addBom(content) {
|
|
1524
|
-
if (content.charCodeAt(0) === 0xfeff) {
|
|
1525
|
-
return content;
|
|
1526
|
-
}
|
|
1527
|
-
return UTF8_BOM + content;
|
|
1528
|
-
}
|
|
1529
|
-
|
|
1530
|
-
/**
|
|
1531
|
-
* Cached platform info (computed once).
|
|
1532
|
-
*/
|
|
1533
|
-
let cachedPlatformInfo = null;
|
|
1534
|
-
/**
|
|
1535
|
-
* Cached case sensitivity result.
|
|
1536
|
-
*/
|
|
1537
|
-
let cachedCaseSensitive = null;
|
|
1538
|
-
/**
|
|
1539
|
-
* Detect if file system is case sensitive.
|
|
1540
|
-
*
|
|
1541
|
-
* @returns True if file system is case-sensitive
|
|
1542
|
-
*/
|
|
1543
|
-
function detectCaseSensitivity() {
|
|
1544
|
-
if (cachedCaseSensitive !== null) {
|
|
1545
|
-
return cachedCaseSensitive;
|
|
1546
|
-
}
|
|
1547
|
-
if (process.platform === 'win32') {
|
|
1548
|
-
cachedCaseSensitive = false;
|
|
1549
|
-
return false;
|
|
1550
|
-
}
|
|
1551
|
-
if (process.platform === 'darwin') {
|
|
1552
|
-
cachedCaseSensitive = false;
|
|
1553
|
-
return false;
|
|
1554
|
-
}
|
|
1555
|
-
let secureTestDir = null;
|
|
1556
|
-
try {
|
|
1557
|
-
secureTestDir = mkdtempSync(join$1(tmpdir(), 'case-sensitivity-test-'));
|
|
1558
|
-
const testFile = join$1(secureTestDir, 'A');
|
|
1559
|
-
const testFileLower = join$1(secureTestDir, 'a');
|
|
1560
|
-
writeFileSync(testFile, '');
|
|
1561
|
-
cachedCaseSensitive = !existsSync(testFileLower);
|
|
1562
|
-
unlinkSync(testFile);
|
|
1563
|
-
}
|
|
1564
|
-
catch {
|
|
1565
|
-
cachedCaseSensitive = true;
|
|
1566
|
-
}
|
|
1567
|
-
finally {
|
|
1568
|
-
if (secureTestDir) {
|
|
1569
|
-
try {
|
|
1570
|
-
rmdirSync(secureTestDir);
|
|
1571
|
-
}
|
|
1572
|
-
catch {
|
|
1573
|
-
// Ignore cleanup errors
|
|
1574
|
-
}
|
|
1575
|
-
}
|
|
1576
|
-
}
|
|
1577
|
-
return cachedCaseSensitive;
|
|
1578
|
-
}
|
|
1579
|
-
/**
|
|
1580
|
-
* Check if file system is case-sensitive.
|
|
1581
|
-
*
|
|
1582
|
-
* @returns True if file system is case-sensitive
|
|
1583
|
-
*/
|
|
1584
|
-
function isCaseSensitiveFs() {
|
|
1585
|
-
return detectCaseSensitivity();
|
|
1586
|
-
}
|
|
1587
|
-
/**
|
|
1588
|
-
* Get comprehensive platform information.
|
|
1589
|
-
*
|
|
1590
|
-
* @returns Platform information object (cached after first call)
|
|
1591
|
-
*/
|
|
1592
|
-
function getPlatformInfo() {
|
|
1593
|
-
if (cachedPlatformInfo) {
|
|
1594
|
-
return cachedPlatformInfo;
|
|
1595
|
-
}
|
|
1596
|
-
const os = platform();
|
|
1597
|
-
const archInfo = arch();
|
|
1598
|
-
let osName;
|
|
1599
|
-
switch (os) {
|
|
1600
|
-
case 'win32':
|
|
1601
|
-
osName = 'win32';
|
|
1602
|
-
break;
|
|
1603
|
-
case 'darwin':
|
|
1604
|
-
osName = 'darwin';
|
|
1605
|
-
break;
|
|
1606
|
-
case 'linux':
|
|
1607
|
-
osName = 'linux';
|
|
1608
|
-
break;
|
|
1609
|
-
case 'freebsd':
|
|
1610
|
-
osName = 'freebsd';
|
|
1611
|
-
break;
|
|
1612
|
-
case 'sunos':
|
|
1613
|
-
osName = 'sunos';
|
|
1614
|
-
break;
|
|
1615
|
-
case 'aix':
|
|
1616
|
-
osName = 'aix';
|
|
1617
|
-
break;
|
|
1618
|
-
default:
|
|
1619
|
-
osName = 'other';
|
|
1620
|
-
}
|
|
1621
|
-
cachedPlatformInfo = {
|
|
1622
|
-
os: osName,
|
|
1623
|
-
arch: archInfo,
|
|
1624
|
-
nodeVersion: process.versions.node,
|
|
1625
|
-
isWindows: osName === 'win32',
|
|
1626
|
-
isMac: osName === 'darwin',
|
|
1627
|
-
isLinux: osName === 'linux',
|
|
1628
|
-
caseSensitive: detectCaseSensitivity(),
|
|
1629
|
-
pathSeparator: osName === 'win32' ? '\\' : '/',
|
|
1630
|
-
lineEnding: osName === 'win32' ? '\r\n' : '\n',
|
|
1631
|
-
};
|
|
1632
|
-
return cachedPlatformInfo;
|
|
1633
|
-
}
|
|
1634
|
-
/**
|
|
1635
|
-
* Detect current platform.
|
|
1636
|
-
*
|
|
1637
|
-
* @returns Platform information object
|
|
1638
|
-
*/
|
|
1639
|
-
function detectPlatform() {
|
|
1640
|
-
return getPlatformInfo();
|
|
1641
|
-
}
|
|
1642
|
-
/**
|
|
1643
|
-
* Check if running on Windows.
|
|
1644
|
-
*
|
|
1645
|
-
* @returns True if running on Windows
|
|
1646
|
-
*/
|
|
1647
|
-
function isWindows() {
|
|
1648
|
-
return process.platform === 'win32';
|
|
1649
|
-
}
|
|
1650
|
-
/**
|
|
1651
|
-
* Check if running on macOS.
|
|
1652
|
-
*
|
|
1653
|
-
* @returns True if running on macOS
|
|
1654
|
-
*/
|
|
1655
|
-
function isMac() {
|
|
1656
|
-
return process.platform === 'darwin';
|
|
1657
|
-
}
|
|
1658
|
-
/**
|
|
1659
|
-
* Check if running on Linux.
|
|
1660
|
-
*
|
|
1661
|
-
* @returns True if running on Linux
|
|
1662
|
-
*/
|
|
1663
|
-
function isLinux() {
|
|
1664
|
-
return process.platform === 'linux';
|
|
1665
|
-
}
|
|
1666
|
-
|
|
1667
|
-
/** Unix line ending */
|
|
1668
|
-
const LF = '\n';
|
|
1669
|
-
/** Windows line ending */
|
|
1670
|
-
const CRLF = '\r\n';
|
|
1671
|
-
/**
|
|
1672
|
-
* Get platform-appropriate line ending.
|
|
1673
|
-
*
|
|
1674
|
-
* @returns Line ending for current platform
|
|
1675
|
-
*/
|
|
1676
|
-
function getLineEnding() {
|
|
1677
|
-
return isWindows() ? CRLF : LF;
|
|
1678
|
-
}
|
|
1679
|
-
/**
|
|
1680
|
-
* Get platform-appropriate path separator.
|
|
1681
|
-
*
|
|
1682
|
-
* @returns Path separator for current platform
|
|
1683
|
-
*/
|
|
1684
|
-
function getPathSeparator() {
|
|
1685
|
-
return isWindows() ? '\\' : '/';
|
|
1686
|
-
}
|
|
1687
|
-
/**
|
|
1688
|
-
* Normalize line endings in content.
|
|
1689
|
-
*
|
|
1690
|
-
* @param content - Content to normalize
|
|
1691
|
-
* @param style - Target line ending style ('lf', 'crlf', or 'auto' for platform default)
|
|
1692
|
-
* @returns Content with normalized line endings
|
|
1693
|
-
*/
|
|
1694
|
-
function normalizeLineEndings(content, style = 'lf') {
|
|
1695
|
-
let target;
|
|
1696
|
-
if (style === 'auto') {
|
|
1697
|
-
target = isWindows() ? CRLF : LF;
|
|
1698
|
-
}
|
|
1699
|
-
else {
|
|
1700
|
-
target = style === 'crlf' ? CRLF : LF;
|
|
1701
|
-
}
|
|
1702
|
-
const normalized = content.replace(/\r\n/g, LF).replace(/\r/g, LF);
|
|
1703
|
-
if (target === LF) {
|
|
1704
|
-
return normalized;
|
|
1705
|
-
}
|
|
1706
|
-
return normalized.replace(/\n/g, target);
|
|
1707
|
-
}
|
|
1708
|
-
/**
|
|
1709
|
-
* Detect line ending style used in content.
|
|
1710
|
-
*
|
|
1711
|
-
* @param content - Content to analyze
|
|
1712
|
-
* @returns Detected line ending style
|
|
1713
|
-
*/
|
|
1714
|
-
function detectLineEnding(content) {
|
|
1715
|
-
const hasCRLF = content.includes(CRLF);
|
|
1716
|
-
const hasLFOnly = content.includes('\n') && content.replace(/\r\n/g, '').includes('\n');
|
|
1717
|
-
if (hasCRLF && hasLFOnly)
|
|
1718
|
-
return 'mixed';
|
|
1719
|
-
if (hasCRLF)
|
|
1720
|
-
return 'crlf';
|
|
1721
|
-
if (content.includes('\n'))
|
|
1722
|
-
return 'lf';
|
|
1723
|
-
return 'none';
|
|
1724
|
-
}
|
|
1725
|
-
/**
|
|
1726
|
-
* Compare paths with case sensitivity awareness.
|
|
1727
|
-
*
|
|
1728
|
-
* @param path1 - First path
|
|
1729
|
-
* @param path2 - Second path
|
|
1730
|
-
* @returns True if paths are equal (respecting case sensitivity)
|
|
1731
|
-
*/
|
|
1732
|
-
function pathsEqual(path1, path2) {
|
|
1733
|
-
const caseSensitive = detectCaseSensitivity();
|
|
1734
|
-
if (caseSensitive) {
|
|
1735
|
-
return path1 === path2;
|
|
908
|
+
function ensureDir(dirPath) {
|
|
909
|
+
if (!existsSync(dirPath)) {
|
|
910
|
+
fsWriteLogger.debug('Creating directory recursively', { path: dirPath });
|
|
911
|
+
mkdirSync(dirPath, { recursive: true });
|
|
1736
912
|
}
|
|
1737
|
-
return path1.toLowerCase() === path2.toLowerCase();
|
|
1738
913
|
}
|
|
1739
|
-
|
|
1740
914
|
/**
|
|
1741
|
-
*
|
|
915
|
+
* Write string content to file.
|
|
916
|
+
* Creates parent directories if needed.
|
|
1742
917
|
*
|
|
1743
|
-
* @param
|
|
1744
|
-
* @param
|
|
1745
|
-
* @param
|
|
1746
|
-
* @
|
|
918
|
+
* @param filePath - Absolute or relative path to the target file
|
|
919
|
+
* @param content - String content to write to the file
|
|
920
|
+
* @param options - Optional write configuration (encoding, mode)
|
|
921
|
+
* @throws {Error} If write fails
|
|
1747
922
|
*
|
|
1748
|
-
* @example
|
|
923
|
+
* @example Writing text content to file
|
|
1749
924
|
* ```typescript
|
|
1750
|
-
* import {
|
|
1751
|
-
*
|
|
1752
|
-
* throw createStructuredError(
|
|
1753
|
-
* 'Configuration file not found',
|
|
1754
|
-
* 'CONFIG_NOT_FOUND',
|
|
1755
|
-
* { path: './config.json', searched: ['./config.json', './settings.json'] }
|
|
1756
|
-
* )
|
|
1757
|
-
* ```
|
|
1758
|
-
*/
|
|
1759
|
-
function createStructuredError(message, code, context) {
|
|
1760
|
-
const error = createError(message);
|
|
1761
|
-
error.code = code;
|
|
1762
|
-
error.context = context ?? {};
|
|
1763
|
-
return error;
|
|
1764
|
-
}
|
|
1765
|
-
/**
|
|
1766
|
-
* Create a configuration-related error.
|
|
1767
|
-
*
|
|
1768
|
-
* @param message - The human-readable error message
|
|
1769
|
-
* @param code - The machine-readable error code for programmatic handling
|
|
1770
|
-
* @param context - Additional contextual information (e.g., file path, config key)
|
|
1771
|
-
* @returns Structured error instance tagged with type 'config'
|
|
1772
|
-
*/
|
|
1773
|
-
function createConfigError(message, code, context) {
|
|
1774
|
-
return createStructuredError(message, code, { ...context, type: 'config' });
|
|
1775
|
-
}
|
|
1776
|
-
/**
|
|
1777
|
-
* Create a filesystem-related error.
|
|
1778
|
-
*
|
|
1779
|
-
* @param message - The human-readable error message
|
|
1780
|
-
* @param code - The filesystem error code (e.g., ENOENT for not found, EACCES for access denied)
|
|
1781
|
-
* @param context - Additional contextual information (e.g., file path, operation attempted)
|
|
1782
|
-
* @returns Structured error instance tagged with type 'fs'
|
|
1783
|
-
*/
|
|
1784
|
-
function createFsError(message, code, context) {
|
|
1785
|
-
return createStructuredError(message, code, { ...context, type: 'fs' });
|
|
1786
|
-
}
|
|
1787
|
-
/**
|
|
1788
|
-
* Create a parsing-related error.
|
|
1789
|
-
*
|
|
1790
|
-
* @param message - The human-readable error message
|
|
1791
|
-
* @param code - The machine-readable error code for programmatic handling
|
|
1792
|
-
* @param context - Additional contextual information (e.g., file path, line/column numbers, expected format)
|
|
1793
|
-
* @returns Structured error instance tagged with type 'parse'
|
|
1794
|
-
*/
|
|
1795
|
-
function createParseError(message, code, context) {
|
|
1796
|
-
return createStructuredError(message, code, { ...context, type: 'parse' });
|
|
1797
|
-
}
|
|
1798
|
-
/**
|
|
1799
|
-
* Create a validation-related error.
|
|
1800
|
-
*
|
|
1801
|
-
* @param message - The human-readable error message
|
|
1802
|
-
* @param code - The machine-readable error code for programmatic handling
|
|
1803
|
-
* @param context - Additional contextual information (e.g., field name, actual vs expected values)
|
|
1804
|
-
* @returns Structured error instance tagged with type 'validation'
|
|
1805
|
-
*/
|
|
1806
|
-
function createValidationError(message, code, context) {
|
|
1807
|
-
return createStructuredError(message, code, { ...context, type: 'validation' });
|
|
1808
|
-
}
|
|
1809
|
-
|
|
1810
|
-
/**
|
|
1811
|
-
* Match path against glob pattern using safe character iteration.
|
|
1812
|
-
* Avoids regex to prevent ReDoS attacks.
|
|
1813
|
-
*
|
|
1814
|
-
* Supported patterns:
|
|
1815
|
-
* - * matches any characters except /
|
|
1816
|
-
* - ** matches any characters including /
|
|
1817
|
-
* - ? matches exactly one character except /
|
|
1818
|
-
* - {a,b,c} matches any of the alternatives
|
|
1819
|
-
*
|
|
1820
|
-
* @param path - The filesystem path to test against the pattern
|
|
1821
|
-
* @param pattern - The glob pattern to match against
|
|
1822
|
-
* @returns True if path matches pattern
|
|
925
|
+
* import { writeFileContent } from '@hyperfrontend/project-scope'
|
|
1823
926
|
*
|
|
1824
|
-
*
|
|
1825
|
-
*
|
|
1826
|
-
* import { matchGlobPattern } from '@hyperfrontend/project-scope'
|
|
927
|
+
* // Write a simple text file
|
|
928
|
+
* writeFileContent('./output/data.txt', 'Hello, World!')
|
|
1827
929
|
*
|
|
1828
|
-
*
|
|
1829
|
-
*
|
|
1830
|
-
* matchGlobPattern('config.json', '\*.{json,yaml}') // true
|
|
1831
|
-
* matchGlobPattern('src/index.ts', 'src/\*.ts') // true
|
|
930
|
+
* // Write with custom encoding
|
|
931
|
+
* writeFileContent('./output/data.txt', 'Content', { encoding: 'utf-8' })
|
|
1832
932
|
* ```
|
|
1833
933
|
*/
|
|
1834
|
-
function
|
|
1835
|
-
|
|
1836
|
-
}
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
* @param patternIdx - Current index in patternParts being examined
|
|
1844
|
-
* @returns True if remaining segments match
|
|
1845
|
-
*/
|
|
1846
|
-
function matchSegments(pathParts, patternParts, pathIdx, patternIdx) {
|
|
1847
|
-
if (pathIdx === pathParts.length && patternIdx === patternParts.length) {
|
|
1848
|
-
return true;
|
|
1849
|
-
}
|
|
1850
|
-
if (patternIdx >= patternParts.length) {
|
|
1851
|
-
return false;
|
|
1852
|
-
}
|
|
1853
|
-
const patternPart = patternParts[patternIdx];
|
|
1854
|
-
if (patternPart === '**') {
|
|
1855
|
-
for (let i = pathIdx; i <= pathParts.length; i++) {
|
|
1856
|
-
if (matchSegments(pathParts, patternParts, i, patternIdx + 1)) {
|
|
1857
|
-
return true;
|
|
1858
|
-
}
|
|
1859
|
-
}
|
|
1860
|
-
return false;
|
|
1861
|
-
}
|
|
1862
|
-
if (pathIdx >= pathParts.length) {
|
|
1863
|
-
return false;
|
|
1864
|
-
}
|
|
1865
|
-
const pathPart = pathParts[pathIdx];
|
|
1866
|
-
if (matchSegment(pathPart, patternPart)) {
|
|
1867
|
-
return matchSegments(pathParts, patternParts, pathIdx + 1, patternIdx + 1);
|
|
1868
|
-
}
|
|
1869
|
-
return false;
|
|
1870
|
-
}
|
|
1871
|
-
/**
|
|
1872
|
-
* Match a single path segment against a pattern segment.
|
|
1873
|
-
* Handles *, ?, and {a,b,c} patterns.
|
|
1874
|
-
*
|
|
1875
|
-
* @param text - The path segment text to match
|
|
1876
|
-
* @param pattern - The pattern segment to match against
|
|
1877
|
-
* @returns True if the text matches the pattern
|
|
1878
|
-
*/
|
|
1879
|
-
function matchSegment(text, pattern) {
|
|
1880
|
-
let textIdx = 0;
|
|
1881
|
-
let patternIdx = 0;
|
|
1882
|
-
while (patternIdx < pattern.length) {
|
|
1883
|
-
const char = pattern[patternIdx];
|
|
1884
|
-
if (char === '*') {
|
|
1885
|
-
patternIdx++;
|
|
1886
|
-
if (patternIdx === pattern.length) {
|
|
1887
|
-
return true;
|
|
1888
|
-
}
|
|
1889
|
-
for (let i = textIdx; i <= text.length; i++) {
|
|
1890
|
-
if (matchSegmentFrom(text, i, pattern, patternIdx)) {
|
|
1891
|
-
return true;
|
|
1892
|
-
}
|
|
1893
|
-
}
|
|
1894
|
-
return false;
|
|
1895
|
-
}
|
|
1896
|
-
else if (char === '?') {
|
|
1897
|
-
if (textIdx >= text.length) {
|
|
1898
|
-
return false;
|
|
1899
|
-
}
|
|
1900
|
-
textIdx++;
|
|
1901
|
-
patternIdx++;
|
|
1902
|
-
}
|
|
1903
|
-
else if (char === '{') {
|
|
1904
|
-
const closeIdx = findClosingBrace(pattern, patternIdx);
|
|
1905
|
-
if (closeIdx === -1) {
|
|
1906
|
-
if (textIdx >= text.length || text[textIdx] !== char) {
|
|
1907
|
-
return false;
|
|
1908
|
-
}
|
|
1909
|
-
textIdx++;
|
|
1910
|
-
patternIdx++;
|
|
1911
|
-
}
|
|
1912
|
-
else {
|
|
1913
|
-
const alternatives = extractAlternatives(pattern.slice(patternIdx + 1, closeIdx));
|
|
1914
|
-
for (const alt of alternatives) {
|
|
1915
|
-
if (matchSegmentFrom(text, textIdx, text.slice(0, textIdx) + alt + pattern.slice(closeIdx + 1), textIdx)) {
|
|
1916
|
-
return true;
|
|
1917
|
-
}
|
|
1918
|
-
}
|
|
1919
|
-
return false;
|
|
1920
|
-
}
|
|
1921
|
-
}
|
|
1922
|
-
else {
|
|
1923
|
-
if (textIdx >= text.length || text[textIdx] !== char) {
|
|
1924
|
-
return false;
|
|
1925
|
-
}
|
|
1926
|
-
textIdx++;
|
|
1927
|
-
patternIdx++;
|
|
1928
|
-
}
|
|
1929
|
-
}
|
|
1930
|
-
return textIdx === text.length;
|
|
1931
|
-
}
|
|
1932
|
-
/**
|
|
1933
|
-
* Helper to match from a specific position.
|
|
1934
|
-
*
|
|
1935
|
-
* @param text - The full text being matched
|
|
1936
|
-
* @param textIdx - The starting index in text to match from
|
|
1937
|
-
* @param pattern - The full pattern being matched
|
|
1938
|
-
* @param patternIdx - The starting index in pattern to match from
|
|
1939
|
-
* @returns True if the text matches the pattern from the given positions
|
|
1940
|
-
*/
|
|
1941
|
-
function matchSegmentFrom(text, textIdx, pattern, patternIdx) {
|
|
1942
|
-
const remainingText = text.slice(textIdx);
|
|
1943
|
-
const remainingPattern = pattern.slice(patternIdx);
|
|
1944
|
-
return matchSegment(remainingText, remainingPattern);
|
|
1945
|
-
}
|
|
1946
|
-
/**
|
|
1947
|
-
* Find closing brace for {a,b,c} pattern.
|
|
1948
|
-
*
|
|
1949
|
-
* @param pattern - The pattern string to search within
|
|
1950
|
-
* @param startIdx - The index of the opening brace
|
|
1951
|
-
* @returns The index of the matching closing brace, or -1 if not found
|
|
1952
|
-
*/
|
|
1953
|
-
function findClosingBrace(pattern, startIdx) {
|
|
1954
|
-
let depth = 0;
|
|
1955
|
-
for (let i = startIdx; i < pattern.length; i++) {
|
|
1956
|
-
if (pattern[i] === '{') {
|
|
1957
|
-
depth++;
|
|
1958
|
-
}
|
|
1959
|
-
else if (pattern[i] === '}') {
|
|
1960
|
-
depth--;
|
|
1961
|
-
if (depth === 0) {
|
|
1962
|
-
return i;
|
|
1963
|
-
}
|
|
1964
|
-
}
|
|
1965
|
-
}
|
|
1966
|
-
return -1;
|
|
1967
|
-
}
|
|
1968
|
-
/**
|
|
1969
|
-
* Extract alternatives from {a,b,c} pattern content.
|
|
1970
|
-
*
|
|
1971
|
-
* @param content - The content between braces (without the braces themselves)
|
|
1972
|
-
* @returns Array of alternative strings split by commas at depth 0
|
|
1973
|
-
*/
|
|
1974
|
-
function extractAlternatives(content) {
|
|
1975
|
-
const alternatives = [];
|
|
1976
|
-
let current = '';
|
|
1977
|
-
let depth = 0;
|
|
1978
|
-
for (let i = 0; i < content.length; i++) {
|
|
1979
|
-
const char = content[i];
|
|
1980
|
-
if (char === '{') {
|
|
1981
|
-
depth++;
|
|
1982
|
-
current += char;
|
|
1983
|
-
}
|
|
1984
|
-
else if (char === '}') {
|
|
1985
|
-
depth--;
|
|
1986
|
-
current += char;
|
|
1987
|
-
}
|
|
1988
|
-
else if (char === ',' && depth === 0) {
|
|
1989
|
-
alternatives.push(current);
|
|
1990
|
-
current = '';
|
|
1991
|
-
}
|
|
1992
|
-
else {
|
|
1993
|
-
current += char;
|
|
1994
|
-
}
|
|
934
|
+
function writeFileContent(filePath, content, options) {
|
|
935
|
+
try {
|
|
936
|
+
fsWriteLogger.debug('Writing file content', { path: filePath, size: content.length, encoding: options?.encoding ?? 'utf-8' });
|
|
937
|
+
ensureDir(dirname(filePath));
|
|
938
|
+
writeFileSync(filePath, content, {
|
|
939
|
+
encoding: options?.encoding ?? 'utf-8',
|
|
940
|
+
mode: options?.mode,
|
|
941
|
+
});
|
|
942
|
+
fsWriteLogger.debug('File written successfully', { path: filePath });
|
|
1995
943
|
}
|
|
1996
|
-
|
|
1997
|
-
|
|
944
|
+
catch (error) {
|
|
945
|
+
fsWriteLogger.warn('Failed to write file', { path: filePath, error: error instanceof Error ? error.message : String(error) });
|
|
946
|
+
throw createFileSystemError(`Failed to write file: ${filePath}`, 'FS_WRITE_ERROR', { path: filePath, operation: 'write', cause: error });
|
|
1998
947
|
}
|
|
1999
|
-
return alternatives;
|
|
2000
948
|
}
|
|
2001
949
|
/**
|
|
2002
|
-
*
|
|
2003
|
-
*
|
|
2004
|
-
* @param path - Path to test
|
|
2005
|
-
* @param patterns - Array of glob patterns
|
|
2006
|
-
* @returns True if path matches any pattern
|
|
2007
|
-
*/
|
|
2008
|
-
function matchesAnyPattern(path, patterns) {
|
|
2009
|
-
return patterns.some((pattern) => matchGlobPattern(path, pattern));
|
|
2010
|
-
}
|
|
2011
|
-
/**
|
|
2012
|
-
* Test if path exactly matches the pattern (no glob).
|
|
2013
|
-
*
|
|
2014
|
-
* @param path - Path to test
|
|
2015
|
-
* @param pattern - Exact pattern to match
|
|
2016
|
-
* @returns True if path equals pattern
|
|
2017
|
-
*/
|
|
2018
|
-
function matchesExact(path, pattern) {
|
|
2019
|
-
return path === pattern;
|
|
2020
|
-
}
|
|
2021
|
-
|
|
2022
|
-
/**
|
|
2023
|
-
* Global registry of all caches for bulk operations.
|
|
2024
|
-
*/
|
|
2025
|
-
const cacheRegistry = createSet();
|
|
2026
|
-
/**
|
|
2027
|
-
* Create a cache with optional TTL and size limits.
|
|
2028
|
-
*
|
|
2029
|
-
* The cache provides a simple key-value store with:
|
|
2030
|
-
* - Optional TTL (time-to-live) for automatic expiration
|
|
2031
|
-
* - Optional maxSize for limiting cache size with FIFO eviction
|
|
2032
|
-
* - Lazy expiration (entries are checked on access)
|
|
950
|
+
* Write Buffer to file.
|
|
951
|
+
* Creates parent directories if needed.
|
|
2033
952
|
*
|
|
2034
|
-
* @param
|
|
2035
|
-
* @
|
|
953
|
+
* @param filePath - Absolute or relative path to the target file
|
|
954
|
+
* @param content - Buffer containing binary data to write
|
|
955
|
+
* @param options - Optional write configuration (mode)
|
|
956
|
+
* @throws {Error} If write fails
|
|
2036
957
|
*
|
|
2037
|
-
* @example
|
|
958
|
+
* @example Writing binary buffer to file
|
|
2038
959
|
* ```typescript
|
|
2039
|
-
*
|
|
2040
|
-
*
|
|
2041
|
-
* cache.set('answer', 42)
|
|
2042
|
-
* cache.get('answer') // 42
|
|
2043
|
-
*
|
|
2044
|
-
* // Cache with TTL (expires after 60 seconds)
|
|
2045
|
-
* const ttlCache = createCache<string, object>({ ttl: 60000 })
|
|
2046
|
-
*
|
|
2047
|
-
* // Cache with max size (evicts oldest when full)
|
|
2048
|
-
* const lruCache = createCache<string, object>({ maxSize: 100 })
|
|
2049
|
-
*
|
|
2050
|
-
* // Combined options
|
|
2051
|
-
* const configCache = createCache<string, object>({
|
|
2052
|
-
* ttl: 30000,
|
|
2053
|
-
* maxSize: 50
|
|
2054
|
-
* })
|
|
960
|
+
* const imageBuffer = Buffer.from([0x89, 0x50, 0x4e, 0x47])
|
|
961
|
+
* writeFileBuffer('./output/image.png', imageBuffer)
|
|
2055
962
|
* ```
|
|
2056
963
|
*/
|
|
2057
|
-
function
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
*
|
|
2064
|
-
* @param entry - Cache entry to check
|
|
2065
|
-
* @returns True if entry is expired
|
|
2066
|
-
*/
|
|
2067
|
-
function isExpired(entry) {
|
|
2068
|
-
if (ttl === undefined)
|
|
2069
|
-
return false;
|
|
2070
|
-
// eslint-disable-next-line workspace/no-unsafe-builtin-methods -- Date.now() is needed for Jest fake timers compatibility
|
|
2071
|
-
return Date.now() - entry.timestamp > ttl;
|
|
2072
|
-
}
|
|
2073
|
-
/**
|
|
2074
|
-
* Evict oldest entries to make room for new ones.
|
|
2075
|
-
*/
|
|
2076
|
-
function evictIfNeeded() {
|
|
2077
|
-
if (maxSize === undefined)
|
|
2078
|
-
return;
|
|
2079
|
-
while (store.size >= maxSize && insertionOrder.length > 0) {
|
|
2080
|
-
const oldestKey = insertionOrder.shift();
|
|
2081
|
-
if (oldestKey !== undefined) {
|
|
2082
|
-
store.delete(oldestKey);
|
|
2083
|
-
}
|
|
2084
|
-
}
|
|
2085
|
-
}
|
|
2086
|
-
/**
|
|
2087
|
-
* Remove key from insertion order tracking.
|
|
2088
|
-
*
|
|
2089
|
-
* @param key - Key to remove from order tracking
|
|
2090
|
-
*/
|
|
2091
|
-
function removeFromOrder(key) {
|
|
2092
|
-
const index = insertionOrder.indexOf(key);
|
|
2093
|
-
if (index !== -1) {
|
|
2094
|
-
insertionOrder.splice(index, 1);
|
|
2095
|
-
}
|
|
964
|
+
function writeFileBuffer(filePath, content, options) {
|
|
965
|
+
try {
|
|
966
|
+
fsWriteLogger.debug('Writing file buffer', { path: filePath, size: content.length });
|
|
967
|
+
ensureDir(dirname(filePath));
|
|
968
|
+
writeFileSync(filePath, content, { mode: options?.mode });
|
|
969
|
+
fsWriteLogger.debug('Buffer written successfully', { path: filePath });
|
|
2096
970
|
}
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
if (!entry)
|
|
2101
|
-
return undefined;
|
|
2102
|
-
if (isExpired(entry)) {
|
|
2103
|
-
store.delete(key);
|
|
2104
|
-
removeFromOrder(key);
|
|
2105
|
-
return undefined;
|
|
2106
|
-
}
|
|
2107
|
-
return entry.value;
|
|
2108
|
-
},
|
|
2109
|
-
set(key, value) {
|
|
2110
|
-
if (store.has(key)) {
|
|
2111
|
-
removeFromOrder(key);
|
|
2112
|
-
}
|
|
2113
|
-
else {
|
|
2114
|
-
evictIfNeeded();
|
|
2115
|
-
}
|
|
2116
|
-
// eslint-disable-next-line workspace/no-unsafe-builtin-methods -- Date.now() is needed for Jest fake timers compatibility
|
|
2117
|
-
store.set(key, { value, timestamp: Date.now() });
|
|
2118
|
-
insertionOrder.push(key);
|
|
2119
|
-
},
|
|
2120
|
-
has(key) {
|
|
2121
|
-
const entry = store.get(key);
|
|
2122
|
-
if (!entry)
|
|
2123
|
-
return false;
|
|
2124
|
-
if (isExpired(entry)) {
|
|
2125
|
-
store.delete(key);
|
|
2126
|
-
removeFromOrder(key);
|
|
2127
|
-
return false;
|
|
2128
|
-
}
|
|
2129
|
-
return true;
|
|
2130
|
-
},
|
|
2131
|
-
delete(key) {
|
|
2132
|
-
removeFromOrder(key);
|
|
2133
|
-
return store.delete(key);
|
|
2134
|
-
},
|
|
2135
|
-
clear() {
|
|
2136
|
-
store.clear();
|
|
2137
|
-
insertionOrder.length = 0;
|
|
2138
|
-
},
|
|
2139
|
-
size() {
|
|
2140
|
-
return store.size;
|
|
2141
|
-
},
|
|
2142
|
-
keys() {
|
|
2143
|
-
return [...insertionOrder];
|
|
2144
|
-
},
|
|
2145
|
-
};
|
|
2146
|
-
cacheRegistry.add(cache);
|
|
2147
|
-
return freeze(cache);
|
|
2148
|
-
}
|
|
2149
|
-
/**
|
|
2150
|
-
* Clear all registered caches.
|
|
2151
|
-
*
|
|
2152
|
-
* Useful for testing or when a global state reset is needed.
|
|
2153
|
-
* This clears all caches created via `createCache()`.
|
|
2154
|
-
*
|
|
2155
|
-
* @example
|
|
2156
|
-
* ```typescript
|
|
2157
|
-
* // In tests
|
|
2158
|
-
* afterEach(() => {
|
|
2159
|
-
* clearAllCaches()
|
|
2160
|
-
* })
|
|
2161
|
-
* ```
|
|
2162
|
-
*/
|
|
2163
|
-
function clearAllCaches() {
|
|
2164
|
-
for (const cache of cacheRegistry) {
|
|
2165
|
-
cache.clear();
|
|
971
|
+
catch (error) {
|
|
972
|
+
fsWriteLogger.warn('Failed to write buffer', { path: filePath, error: error instanceof Error ? error.message : String(error) });
|
|
973
|
+
throw createFileSystemError(`Failed to write file: ${filePath}`, 'FS_WRITE_ERROR', { path: filePath, operation: 'write', cause: error });
|
|
2166
974
|
}
|
|
2167
975
|
}
|
|
2168
976
|
/**
|
|
2169
|
-
*
|
|
2170
|
-
*
|
|
2171
|
-
* Primarily used for testing.
|
|
2172
|
-
*
|
|
2173
|
-
* @returns Number of registered caches
|
|
2174
|
-
*/
|
|
2175
|
-
function getCacheCount() {
|
|
2176
|
-
return cacheRegistry.size;
|
|
2177
|
-
}
|
|
2178
|
-
/**
|
|
2179
|
-
* Unregister a cache from the global registry.
|
|
2180
|
-
*
|
|
2181
|
-
* Useful for cleanup in tests or when a cache is no longer needed.
|
|
2182
|
-
*
|
|
2183
|
-
* @param cache - Cache to unregister
|
|
2184
|
-
* @returns True if cache was unregistered
|
|
2185
|
-
*/
|
|
2186
|
-
function unregisterCache(cache) {
|
|
2187
|
-
return cacheRegistry.delete(cache);
|
|
2188
|
-
}
|
|
2189
|
-
/**
|
|
2190
|
-
* Create a memoized version of a function with caching.
|
|
2191
|
-
*
|
|
2192
|
-
* The memoized function caches results based on the first argument (key).
|
|
2193
|
-
* If additional arguments are needed, use the options.keyFn parameter.
|
|
977
|
+
* Write JSON data to file with formatting.
|
|
978
|
+
* Creates parent directories if needed.
|
|
2194
979
|
*
|
|
2195
|
-
* @param
|
|
2196
|
-
* @param
|
|
2197
|
-
* @
|
|
980
|
+
* @param filePath - Absolute or relative path to the target JSON file
|
|
981
|
+
* @param data - Object or value to serialize as JSON
|
|
982
|
+
* @param options - Optional write configuration (indent, encoding, mode)
|
|
983
|
+
* @throws {Error} If write fails
|
|
2198
984
|
*
|
|
2199
|
-
* @example
|
|
985
|
+
* @example Writing JSON data to file
|
|
2200
986
|
* ```typescript
|
|
2201
|
-
*
|
|
2202
|
-
* const detectTechStackMemo = memoize(
|
|
2203
|
-
* (path: string) => expensiveDetection(path),
|
|
2204
|
-
* { ttl: 60000 }
|
|
2205
|
-
* )
|
|
987
|
+
* import { writeJsonFile } from '@hyperfrontend/project-scope'
|
|
2206
988
|
*
|
|
2207
|
-
*
|
|
2208
|
-
*
|
|
989
|
+
* // Write object to JSON file
|
|
990
|
+
* writeJsonFile('./config.json', { port: 3000, debug: true })
|
|
2209
991
|
*
|
|
2210
|
-
* //
|
|
2211
|
-
*
|
|
992
|
+
* // Write with custom indentation
|
|
993
|
+
* writeJsonFile('./config.json', data, { indent: 4 })
|
|
2212
994
|
* ```
|
|
2213
995
|
*/
|
|
2214
|
-
function
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
const
|
|
2218
|
-
|
|
2219
|
-
|
|
996
|
+
function writeJsonFile(filePath, data, options) {
|
|
997
|
+
try {
|
|
998
|
+
fsWriteLogger.debug('Writing JSON file', { path: filePath, indent: options?.indent ?? 2 });
|
|
999
|
+
const indent = options?.indent ?? 2;
|
|
1000
|
+
const content = stringify(data, null, indent) + '\n';
|
|
1001
|
+
writeFileContent(filePath, content, options);
|
|
1002
|
+
fsWriteLogger.debug('JSON file written successfully', { path: filePath });
|
|
1003
|
+
}
|
|
1004
|
+
catch (error) {
|
|
1005
|
+
if (error?.code === 'FS_WRITE_ERROR') {
|
|
1006
|
+
throw error;
|
|
2220
1007
|
}
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
enumerable: true,
|
|
2229
|
-
});
|
|
2230
|
-
return memoized;
|
|
1008
|
+
fsWriteLogger.warn('Failed to write JSON file', { path: filePath, error: error instanceof Error ? error.message : String(error) });
|
|
1009
|
+
throw createFileSystemError(`Failed to write JSON file: ${filePath}`, 'FS_WRITE_ERROR', {
|
|
1010
|
+
path: filePath,
|
|
1011
|
+
operation: 'write',
|
|
1012
|
+
cause: error,
|
|
1013
|
+
});
|
|
1014
|
+
}
|
|
2231
1015
|
}
|
|
2232
1016
|
|
|
2233
|
-
export { BINARY_SIGNATURES, CRLF, LF, UTF16_BE_BOM_BYTES, UTF16_LE_BOM_BYTES, UTF8_BOM, UTF8_BOM_BYTES, addBom, bufferToString, clearAllCaches, createCache, createConfigError, createDirectory, createFileSystemError, createFsError, createParseError, createScopedLogger, createStructuredError, createValidationError, detectCaseSensitivity, detectEncoding, detectEncodingInfo, detectLineEnding, detectPlatform, ensureDir, ensureTrailingSlash, exists, findUpwardWhere, getBasename, getCacheCount, getDirname, getExtension, getFileNameWithoutExtension, getFileStat, getGlobalLogLevel, getLineEnding, getPathSeparator, getPlatformInfo, hasBom, isAbsolute,
|
|
2234
|
-
//# sourceMappingURL=index.esm.js.map
|
|
1017
|
+
export { BINARY_SIGNATURES, CRLF, LF, UTF16_BE_BOM_BYTES, UTF16_LE_BOM_BYTES, UTF8_BOM, UTF8_BOM_BYTES, addBom, bufferToString, clearAllCaches, createCache, createConfigError, createDirectory, createFileSystemError, createFsError, createParseError, createScopedLogger, createStructuredError, createValidationError, detectCaseSensitivity, detectEncoding, detectEncodingInfo, detectLineEnding, detectPlatform, ensureDir, ensureTrailingSlash, exists, findUpwardWhere, getBasename, getCacheCount, getDirname, getExtension, getFileNameWithoutExtension, getFileStat, getGlobalLogLevel, getLineEnding, getPathSeparator, getPlatformInfo, hasBom, isAbsolute, isCaseSensitiveFs, isDirectory, isFile, isSymlink, isTextFile, isWindows, join, joinPath, joinPosix, locateByMarkers, logger, matchGlobPattern, matchesAnyPattern, matchesExact, memoize, normalizeLineEndings, normalizePath, normalizeToForwardSlashes, normalizeToNative, offsetFromRoot, parsePath, pathSegments, pathsEqual, readDirectory, readDirectoryRecursive, readFileBuffer, readFileContent, readFileIfExists, readJsonFile, readJsonFileIfExists, relativePath, removeDirectory, removeTrailingSlash, resetGlobalLogLevel, resolveFromWorkspace, resolvePath, resolveRealPath, sanitize, setGlobalLogLevel, stripBom, toUtf8, traverseUpward, unregisterCache, writeFileBuffer, writeFileContent, writeJsonFile };
|