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