@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/vfs/index.esm.js
CHANGED
|
@@ -1,419 +1,19 @@
|
|
|
1
|
-
import { existsSync,
|
|
1
|
+
import { existsSync, statSync, lstatSync, readdirSync, mkdirSync, unlinkSync, rmSync, writeFileSync, chmodSync, readFileSync, readlinkSync } from 'node:fs';
|
|
2
2
|
import { join, normalize, sep, isAbsolute as isAbsolute$1, relative, resolve, dirname } from 'node:path';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* (Safe copy) Creates a new Error using the captured Error constructor.
|
|
19
|
-
* Use this instead of `new Error()`.
|
|
20
|
-
*
|
|
21
|
-
* @param message - Optional error message.
|
|
22
|
-
* @param options - Optional error options.
|
|
23
|
-
* @returns A new Error instance.
|
|
24
|
-
*/
|
|
25
|
-
const createError = (message, options) => _Reflect$2.construct(_Error, [message, options]);
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Safe copies of JSON built-in methods.
|
|
29
|
-
*
|
|
30
|
-
* These references are captured at module initialization time to protect against
|
|
31
|
-
* prototype pollution attacks. Import only what you need for tree-shaking.
|
|
32
|
-
*
|
|
33
|
-
* @module @hyperfrontend/immutable-api-utils/built-in-copy/json
|
|
34
|
-
*/
|
|
35
|
-
const _JSON = globalThis.JSON;
|
|
36
|
-
/**
|
|
37
|
-
* (Safe copy) Converts a JavaScript value to a JavaScript Object Notation (JSON) string.
|
|
38
|
-
*/
|
|
39
|
-
const stringify = _JSON.stringify;
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Safe copies of Object built-in methods.
|
|
43
|
-
*
|
|
44
|
-
* These references are captured at module initialization time to protect against
|
|
45
|
-
* prototype pollution attacks. Import only what you need for tree-shaking.
|
|
46
|
-
*
|
|
47
|
-
* @module @hyperfrontend/immutable-api-utils/built-in-copy/object
|
|
48
|
-
*/
|
|
49
|
-
const _Object = globalThis.Object;
|
|
50
|
-
/**
|
|
51
|
-
* (Safe copy) Prevents modification of existing property attributes and values,
|
|
52
|
-
* and prevents the addition of new properties.
|
|
53
|
-
*/
|
|
54
|
-
const freeze = _Object.freeze;
|
|
55
|
-
/**
|
|
56
|
-
* (Safe copy) Returns the names of the enumerable string properties and methods of an object.
|
|
57
|
-
*/
|
|
58
|
-
const keys = _Object.keys;
|
|
59
|
-
/**
|
|
60
|
-
* (Safe copy) Returns an array of key/values of the enumerable own properties of an object.
|
|
61
|
-
*/
|
|
62
|
-
const entries = _Object.entries;
|
|
63
|
-
/**
|
|
64
|
-
* (Safe copy) Adds one or more properties to an object, and/or modifies attributes of existing properties.
|
|
65
|
-
*/
|
|
66
|
-
const defineProperties = _Object.defineProperties;
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Safe copies of Array built-in static methods.
|
|
70
|
-
*
|
|
71
|
-
* These references are captured at module initialization time to protect against
|
|
72
|
-
* prototype pollution attacks. Import only what you need for tree-shaking.
|
|
73
|
-
*
|
|
74
|
-
* @module @hyperfrontend/immutable-api-utils/built-in-copy/array
|
|
75
|
-
*/
|
|
76
|
-
const _Array = globalThis.Array;
|
|
77
|
-
/**
|
|
78
|
-
* (Safe copy) Determines whether the passed value is an Array.
|
|
79
|
-
*/
|
|
80
|
-
const isArray = _Array.isArray;
|
|
81
|
-
/**
|
|
82
|
-
* (Safe copy) Creates an array from an array-like or iterable object.
|
|
83
|
-
*/
|
|
84
|
-
const from = _Array.from;
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Safe copies of Console built-in methods.
|
|
88
|
-
*
|
|
89
|
-
* These references are captured at module initialization time to protect against
|
|
90
|
-
* prototype pollution attacks. Import only what you need for tree-shaking.
|
|
91
|
-
*
|
|
92
|
-
* @module @hyperfrontend/immutable-api-utils/built-in-copy/console
|
|
93
|
-
*/
|
|
94
|
-
const _console = globalThis.console;
|
|
95
|
-
/**
|
|
96
|
-
* (Safe copy) Outputs a message to the console.
|
|
97
|
-
*/
|
|
98
|
-
const log = _console.log.bind(_console);
|
|
99
|
-
/**
|
|
100
|
-
* (Safe copy) Outputs a warning message to the console.
|
|
101
|
-
*/
|
|
102
|
-
const warn = _console.warn.bind(_console);
|
|
103
|
-
/**
|
|
104
|
-
* (Safe copy) Outputs an error message to the console.
|
|
105
|
-
*/
|
|
106
|
-
const error = _console.error.bind(_console);
|
|
107
|
-
/**
|
|
108
|
-
* (Safe copy) Outputs an informational message to the console.
|
|
109
|
-
*/
|
|
110
|
-
const info = _console.info.bind(_console);
|
|
111
|
-
/**
|
|
112
|
-
* (Safe copy) Outputs a debug message to the console.
|
|
113
|
-
*/
|
|
114
|
-
const debug = _console.debug.bind(_console);
|
|
115
|
-
/**
|
|
116
|
-
* (Safe copy) Outputs a stack trace to the console.
|
|
117
|
-
*/
|
|
118
|
-
_console.trace.bind(_console);
|
|
119
|
-
/**
|
|
120
|
-
* (Safe copy) Displays an interactive listing of the properties of a specified object.
|
|
121
|
-
*/
|
|
122
|
-
_console.dir.bind(_console);
|
|
123
|
-
/**
|
|
124
|
-
* (Safe copy) Displays tabular data as a table.
|
|
125
|
-
*/
|
|
126
|
-
_console.table.bind(_console);
|
|
127
|
-
/**
|
|
128
|
-
* (Safe copy) Writes an error message to the console if the assertion is false.
|
|
129
|
-
*/
|
|
130
|
-
_console.assert.bind(_console);
|
|
131
|
-
/**
|
|
132
|
-
* (Safe copy) Clears the console.
|
|
133
|
-
*/
|
|
134
|
-
_console.clear.bind(_console);
|
|
135
|
-
/**
|
|
136
|
-
* (Safe copy) Logs the number of times that this particular call to count() has been called.
|
|
137
|
-
*/
|
|
138
|
-
_console.count.bind(_console);
|
|
139
|
-
/**
|
|
140
|
-
* (Safe copy) Resets the counter used with console.count().
|
|
141
|
-
*/
|
|
142
|
-
_console.countReset.bind(_console);
|
|
143
|
-
/**
|
|
144
|
-
* (Safe copy) Creates a new inline group in the console.
|
|
145
|
-
*/
|
|
146
|
-
_console.group.bind(_console);
|
|
147
|
-
/**
|
|
148
|
-
* (Safe copy) Creates a new inline group in the console that is initially collapsed.
|
|
149
|
-
*/
|
|
150
|
-
_console.groupCollapsed.bind(_console);
|
|
151
|
-
/**
|
|
152
|
-
* (Safe copy) Exits the current inline group.
|
|
153
|
-
*/
|
|
154
|
-
_console.groupEnd.bind(_console);
|
|
155
|
-
/**
|
|
156
|
-
* (Safe copy) Starts a timer with a name specified as an input parameter.
|
|
157
|
-
*/
|
|
158
|
-
_console.time.bind(_console);
|
|
159
|
-
/**
|
|
160
|
-
* (Safe copy) Stops a timer that was previously started.
|
|
161
|
-
*/
|
|
162
|
-
_console.timeEnd.bind(_console);
|
|
163
|
-
/**
|
|
164
|
-
* (Safe copy) Logs the current value of a timer that was previously started.
|
|
165
|
-
*/
|
|
166
|
-
_console.timeLog.bind(_console);
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* Safe copies of Set built-in via factory function.
|
|
170
|
-
*
|
|
171
|
-
* Since constructors cannot be safely captured via Object.assign, this module
|
|
172
|
-
* provides a factory function that uses Reflect.construct internally.
|
|
173
|
-
*
|
|
174
|
-
* These references are captured at module initialization time to protect against
|
|
175
|
-
* prototype pollution attacks. Import only what you need for tree-shaking.
|
|
176
|
-
*
|
|
177
|
-
* @module @hyperfrontend/immutable-api-utils/built-in-copy/set
|
|
178
|
-
*/
|
|
179
|
-
const _Set = globalThis.Set;
|
|
180
|
-
const _Reflect$1 = globalThis.Reflect;
|
|
181
|
-
/**
|
|
182
|
-
* (Safe copy) Creates a new Set using the captured Set constructor.
|
|
183
|
-
* Use this instead of `new Set()`.
|
|
184
|
-
*
|
|
185
|
-
* @param iterable - Optional iterable of values.
|
|
186
|
-
* @returns A new Set instance.
|
|
187
|
-
*/
|
|
188
|
-
const createSet = (iterable) => _Reflect$1.construct(_Set, iterable ? [iterable] : []);
|
|
189
|
-
|
|
190
|
-
const registeredClasses = [];
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* Returns the data type of the target.
|
|
194
|
-
* Uses native `typeof` operator, however, makes distinction between `null`, `array`, and `object`.
|
|
195
|
-
* Also, when classes are registered via `registerClass`, it checks if objects are instance of any known registered class.
|
|
196
|
-
*
|
|
197
|
-
* @param target - The target to get the data type of.
|
|
198
|
-
* @returns The data type of the target.
|
|
199
|
-
*/
|
|
200
|
-
const getType = (target) => {
|
|
201
|
-
if (target === null)
|
|
202
|
-
return 'null';
|
|
203
|
-
const nativeDataType = typeof target;
|
|
204
|
-
if (nativeDataType === 'object') {
|
|
205
|
-
if (isArray(target))
|
|
206
|
-
return 'array';
|
|
207
|
-
for (const registeredClass of registeredClasses) {
|
|
208
|
-
if (target instanceof registeredClass)
|
|
209
|
-
return registeredClass.name;
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
return nativeDataType;
|
|
213
|
-
};
|
|
214
|
-
|
|
215
|
-
/**
|
|
216
|
-
* Safe copies of Map built-in via factory function.
|
|
217
|
-
*
|
|
218
|
-
* Since constructors cannot be safely captured via Object.assign, this module
|
|
219
|
-
* provides a factory function that uses Reflect.construct internally.
|
|
220
|
-
*
|
|
221
|
-
* These references are captured at module initialization time to protect against
|
|
222
|
-
* prototype pollution attacks. Import only what you need for tree-shaking.
|
|
223
|
-
*
|
|
224
|
-
* @module @hyperfrontend/immutable-api-utils/built-in-copy/map
|
|
225
|
-
*/
|
|
226
|
-
const _Map = globalThis.Map;
|
|
227
|
-
const _Reflect = globalThis.Reflect;
|
|
228
|
-
/**
|
|
229
|
-
* (Safe copy) Creates a new Map using the captured Map constructor.
|
|
230
|
-
* Use this instead of `new Map()`.
|
|
231
|
-
*
|
|
232
|
-
* @param iterable - Optional iterable of key-value pairs.
|
|
233
|
-
* @returns A new Map instance.
|
|
234
|
-
*/
|
|
235
|
-
const createMap = (iterable) => _Reflect.construct(_Map, iterable ? [iterable] : []);
|
|
236
|
-
|
|
237
|
-
/**
|
|
238
|
-
* Safe copies of Math built-in methods.
|
|
239
|
-
*
|
|
240
|
-
* These references are captured at module initialization time to protect against
|
|
241
|
-
* prototype pollution attacks. Import only what you need for tree-shaking.
|
|
242
|
-
*
|
|
243
|
-
* @module @hyperfrontend/immutable-api-utils/built-in-copy/math
|
|
244
|
-
*/
|
|
245
|
-
const _Math = globalThis.Math;
|
|
246
|
-
/**
|
|
247
|
-
* (Safe copy) Returns the larger of zero or more numbers.
|
|
248
|
-
*/
|
|
249
|
-
const max = _Math.max;
|
|
250
|
-
/**
|
|
251
|
-
* (Safe copy) Returns the smaller of zero or more numbers.
|
|
252
|
-
*/
|
|
253
|
-
const min = _Math.min;
|
|
254
|
-
|
|
255
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
256
|
-
/**
|
|
257
|
-
* Creates a wrapper function that only executes the wrapped function if the condition function returns true.
|
|
258
|
-
*
|
|
259
|
-
* @param func - The function to be conditionally executed.
|
|
260
|
-
* @param conditionFunc - A function that returns a boolean, determining if `func` should be executed.
|
|
261
|
-
* @returns A wrapped version of `func` that executes conditionally.
|
|
262
|
-
*/
|
|
263
|
-
function createConditionalExecutionFunction(func, conditionFunc) {
|
|
264
|
-
return function (...args) {
|
|
265
|
-
if (conditionFunc()) {
|
|
266
|
-
return func(...args);
|
|
267
|
-
}
|
|
268
|
-
};
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
272
|
-
/**
|
|
273
|
-
* Creates a wrapper function that silently ignores any errors thrown by the wrapped void function.
|
|
274
|
-
* This function is specifically for wrapping functions that do not return a value (void functions).
|
|
275
|
-
* Exceptions are swallowed without any logging or handling.
|
|
276
|
-
*
|
|
277
|
-
* @param func - The void function to be wrapped.
|
|
278
|
-
* @returns A wrapped version of the input function that ignores errors.
|
|
279
|
-
*/
|
|
280
|
-
function createErrorIgnoringFunction(func) {
|
|
281
|
-
return function (...args) {
|
|
282
|
-
try {
|
|
283
|
-
func(...args);
|
|
284
|
-
}
|
|
285
|
-
catch {
|
|
286
|
-
// Deliberately swallowing/ignoring the exception
|
|
287
|
-
}
|
|
288
|
-
};
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
292
|
-
/**
|
|
293
|
-
* A no-operation function (noop) that does nothing regardless of the arguments passed.
|
|
294
|
-
* It is designed to be as permissive as possible in its typing without using the `Function` keyword.
|
|
295
|
-
*
|
|
296
|
-
* @param args - Any arguments passed to the function (ignored)
|
|
297
|
-
*/
|
|
298
|
-
const noop = (...args) => {
|
|
299
|
-
// Intentionally does nothing
|
|
300
|
-
};
|
|
301
|
-
|
|
302
|
-
const logLevels = ['none', 'error', 'warn', 'log', 'info', 'debug'];
|
|
303
|
-
const priority = {
|
|
304
|
-
error: 4,
|
|
305
|
-
warn: 3,
|
|
306
|
-
log: 2,
|
|
307
|
-
info: 1,
|
|
308
|
-
debug: 0,
|
|
309
|
-
};
|
|
310
|
-
/**
|
|
311
|
-
* Validates whether a given string is a valid log level.
|
|
312
|
-
*
|
|
313
|
-
* @param level - The log level to validate
|
|
314
|
-
* @returns True if the level is valid, false otherwise
|
|
315
|
-
*/
|
|
316
|
-
function isValidLogLevel(level) {
|
|
317
|
-
return logLevels.includes(level);
|
|
318
|
-
}
|
|
319
|
-
/**
|
|
320
|
-
* Creates a log level configuration manager for controlling logging behavior.
|
|
321
|
-
* Provides methods to get, set, and evaluate log levels based on priority.
|
|
322
|
-
*
|
|
323
|
-
* @param level - The initial log level (defaults to 'error')
|
|
324
|
-
* @returns A configuration object with log level management methods
|
|
325
|
-
* @throws {Error} When the provided level is not a valid log level
|
|
326
|
-
*/
|
|
327
|
-
function createLogLevelConfig(level = 'error') {
|
|
328
|
-
if (!isValidLogLevel(level)) {
|
|
329
|
-
throw createError('Cannot create log level configuration with a valid default log level');
|
|
330
|
-
}
|
|
331
|
-
const state = { level };
|
|
332
|
-
const getLogLevel = () => state.level;
|
|
333
|
-
const setLogLevel = (level) => {
|
|
334
|
-
if (!isValidLogLevel(level)) {
|
|
335
|
-
throw createError(`Cannot set value '${level}' level. Expected levels are ${logLevels}.`);
|
|
336
|
-
}
|
|
337
|
-
state.level = level;
|
|
338
|
-
};
|
|
339
|
-
const shouldLog = (level) => {
|
|
340
|
-
if (state.level === 'none' || level === 'none' || !isValidLogLevel(level)) {
|
|
341
|
-
return false;
|
|
342
|
-
}
|
|
343
|
-
return priority[level] >= priority[state.level];
|
|
344
|
-
};
|
|
345
|
-
return freeze({
|
|
346
|
-
getLogLevel,
|
|
347
|
-
setLogLevel,
|
|
348
|
-
shouldLog,
|
|
349
|
-
});
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
/**
|
|
353
|
-
* Creates a logger instance with configurable log level filtering.
|
|
354
|
-
* Each log function is wrapped to respect the current log level setting.
|
|
355
|
-
*
|
|
356
|
-
* @param error - Function to handle error-level logs (required)
|
|
357
|
-
* @param warn - Function to handle warning-level logs (optional, defaults to noop)
|
|
358
|
-
* @param log - Function to handle standard logs (optional, defaults to noop)
|
|
359
|
-
* @param info - Function to handle info-level logs (optional, defaults to noop)
|
|
360
|
-
* @param debug - Function to handle debug-level logs (optional, defaults to noop)
|
|
361
|
-
* @returns A frozen logger object with log methods and level control
|
|
362
|
-
* @throws {ErrorLevelFn} When any provided log function is invalid
|
|
363
|
-
*/
|
|
364
|
-
function createLogger(error, warn = noop, log = noop, info = noop, debug = noop) {
|
|
365
|
-
if (notValidLogFn(error)) {
|
|
366
|
-
throw createError(notFnMsg('error'));
|
|
367
|
-
}
|
|
368
|
-
if (notValidLogFn(warn)) {
|
|
369
|
-
throw createError(notFnMsg('warn'));
|
|
370
|
-
}
|
|
371
|
-
if (notValidLogFn(log)) {
|
|
372
|
-
throw createError(notFnMsg('log'));
|
|
373
|
-
}
|
|
374
|
-
if (notValidLogFn(info)) {
|
|
375
|
-
throw createError(notFnMsg('info'));
|
|
376
|
-
}
|
|
377
|
-
if (notValidLogFn(debug)) {
|
|
378
|
-
throw createError(notFnMsg('debug'));
|
|
379
|
-
}
|
|
380
|
-
const { setLogLevel, getLogLevel, shouldLog } = createLogLevelConfig();
|
|
381
|
-
const wrapLogFn = (fn, level) => {
|
|
382
|
-
if (fn === noop)
|
|
383
|
-
return fn;
|
|
384
|
-
const condition = () => shouldLog(level);
|
|
385
|
-
return createConditionalExecutionFunction(createErrorIgnoringFunction(fn), condition);
|
|
386
|
-
};
|
|
387
|
-
return freeze({
|
|
388
|
-
error: wrapLogFn(error, 'error'),
|
|
389
|
-
warn: wrapLogFn(warn, 'warn'),
|
|
390
|
-
log: wrapLogFn(log, 'log'),
|
|
391
|
-
info: wrapLogFn(info, 'info'),
|
|
392
|
-
debug: wrapLogFn(debug, 'debug'),
|
|
393
|
-
setLogLevel,
|
|
394
|
-
getLogLevel,
|
|
395
|
-
});
|
|
396
|
-
}
|
|
397
|
-
/**
|
|
398
|
-
* Validates whether a given value is a valid log function.
|
|
399
|
-
*
|
|
400
|
-
* @param fn - The value to validate
|
|
401
|
-
* @returns True if the value is not a function (invalid), false if it is valid
|
|
402
|
-
*/
|
|
403
|
-
function notValidLogFn(fn) {
|
|
404
|
-
return getType(fn) !== 'function' && fn !== noop;
|
|
405
|
-
}
|
|
406
|
-
/**
|
|
407
|
-
* Generates an error message for invalid log function parameters.
|
|
408
|
-
*
|
|
409
|
-
* @param label - The name of the log function that failed validation
|
|
410
|
-
* @returns A formatted error message string
|
|
411
|
-
*/
|
|
412
|
-
function notFnMsg(label) {
|
|
413
|
-
return `Cannot create a logger when ${label} is not a function`;
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
createLogger(error, warn, log, info, debug);
|
|
3
|
+
import { createError } from '../_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/error/index.esm.js';
|
|
4
|
+
import { isArray, from } from '../_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/array/index.esm.js';
|
|
5
|
+
import { error, warn, log, info, debug } from '../_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/console/index.esm.js';
|
|
6
|
+
import { stringify } from '../_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/json/index.esm.js';
|
|
7
|
+
import { freeze, entries, keys, defineProperties } from '../_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/object/index.esm.js';
|
|
8
|
+
import { createSet } from '../_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/set/index.esm.js';
|
|
9
|
+
import { createLogger } from '../_dependencies/@hyperfrontend/logging/index.esm.js';
|
|
10
|
+
import { max, min } from '../_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/math/index.esm.js';
|
|
11
|
+
import { createMap } from '../_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/map/index.esm.js';
|
|
12
|
+
import { isFile, isDirectory, exists } from '../_shared/core/fs/stat/index.esm.js';
|
|
13
|
+
import { normalizePath, removeTrailingSlash } from '../_shared/core/path/normalize/index.esm.js';
|
|
14
|
+
import { resolvePath, relativePath, joinPath, isAbsolute } from '../_shared/core/path/resolve/index.esm.js';
|
|
15
|
+
import { getDirname } from '../_shared/core/path/segments/index.esm.js';
|
|
16
|
+
import { Mode } from '../_shared/vfs/types/index.esm.js';
|
|
417
17
|
|
|
418
18
|
/**
|
|
419
19
|
* Global log level registry.
|
|
@@ -453,6 +53,13 @@ function isSensitiveKey(key) {
|
|
|
453
53
|
*
|
|
454
54
|
* @param obj - Object to sanitize
|
|
455
55
|
* @returns New object with sensitive values redacted
|
|
56
|
+
*
|
|
57
|
+
* @example Sanitizing sensitive data
|
|
58
|
+
* ```typescript
|
|
59
|
+
* const config = { apiKey: 'secret123', endpoint: 'https://api.example.com' }
|
|
60
|
+
* const safe = sanitize(config)
|
|
61
|
+
* // => { apiKey: '[REDACTED]', endpoint: 'https://api.example.com' }
|
|
62
|
+
* ```
|
|
456
63
|
*/
|
|
457
64
|
function sanitize(obj) {
|
|
458
65
|
if (obj === null || obj === undefined) {
|
|
@@ -503,7 +110,7 @@ function formatMessage(namespace, message, meta) {
|
|
|
503
110
|
* @param options - Logger configuration options
|
|
504
111
|
* @returns A configured scoped logger instance
|
|
505
112
|
*
|
|
506
|
-
* @example
|
|
113
|
+
* @example Creating a scoped logger
|
|
507
114
|
* ```typescript
|
|
508
115
|
* const logger = createScopedLogger('project-scope')
|
|
509
116
|
* logger.setLogLevel('debug')
|
|
@@ -540,7 +147,7 @@ function createScopedLogger(namespace, options = {}) {
|
|
|
540
147
|
* Default logger instance for the project-scope library.
|
|
541
148
|
* Use this for general logging within the library.
|
|
542
149
|
*
|
|
543
|
-
* @example
|
|
150
|
+
* @example Using the default logger
|
|
544
151
|
* ```typescript
|
|
545
152
|
* import { logger } from '@hyperfrontend/project-scope/core'
|
|
546
153
|
*
|
|
@@ -558,6 +165,15 @@ createScopedLogger('project-scope:fs');
|
|
|
558
165
|
* @param code - The category code for this type of filesystem failure
|
|
559
166
|
* @param context - Additional context including path, operation, and cause
|
|
560
167
|
* @returns A configured Error object with code and context properties
|
|
168
|
+
*
|
|
169
|
+
* @example Creating a file system error
|
|
170
|
+
* ```typescript
|
|
171
|
+
* throw createFileSystemError(
|
|
172
|
+
* 'Cannot read file',
|
|
173
|
+
* 'FS_READ_ERROR',
|
|
174
|
+
* { path: './missing.txt', operation: 'read' }
|
|
175
|
+
* )
|
|
176
|
+
* ```
|
|
561
177
|
*/
|
|
562
178
|
function createFileSystemError(message, code, context) {
|
|
563
179
|
const error = createError(message);
|
|
@@ -568,77 +184,6 @@ function createFileSystemError(message, code, context) {
|
|
|
568
184
|
return error;
|
|
569
185
|
}
|
|
570
186
|
|
|
571
|
-
const fsWriteLogger = createScopedLogger('project-scope:fs:write');
|
|
572
|
-
/**
|
|
573
|
-
* Ensure directory exists, create recursively if not.
|
|
574
|
-
*
|
|
575
|
-
* @param dirPath - Directory path to ensure exists
|
|
576
|
-
*/
|
|
577
|
-
function ensureDir(dirPath) {
|
|
578
|
-
if (!existsSync(dirPath)) {
|
|
579
|
-
fsWriteLogger.debug('Creating directory recursively', { path: dirPath });
|
|
580
|
-
mkdirSync(dirPath, { recursive: true });
|
|
581
|
-
}
|
|
582
|
-
}
|
|
583
|
-
|
|
584
|
-
/**
|
|
585
|
-
* Get file stats with error handling.
|
|
586
|
-
*
|
|
587
|
-
* @param filePath - Path to file
|
|
588
|
-
* @param followSymlinks - Whether to follow symlinks (default: true)
|
|
589
|
-
* @returns File stats or null if path doesn't exist
|
|
590
|
-
*/
|
|
591
|
-
function getFileStat(filePath, followSymlinks = true) {
|
|
592
|
-
if (!existsSync(filePath)) {
|
|
593
|
-
return null;
|
|
594
|
-
}
|
|
595
|
-
try {
|
|
596
|
-
const stat = followSymlinks ? statSync(filePath) : lstatSync(filePath);
|
|
597
|
-
return {
|
|
598
|
-
isFile: stat.isFile(),
|
|
599
|
-
isDirectory: stat.isDirectory(),
|
|
600
|
-
isSymlink: stat.isSymbolicLink(),
|
|
601
|
-
size: stat.size,
|
|
602
|
-
created: stat.birthtime,
|
|
603
|
-
modified: stat.mtime,
|
|
604
|
-
accessed: stat.atime,
|
|
605
|
-
mode: stat.mode,
|
|
606
|
-
};
|
|
607
|
-
}
|
|
608
|
-
catch {
|
|
609
|
-
return null;
|
|
610
|
-
}
|
|
611
|
-
}
|
|
612
|
-
/**
|
|
613
|
-
* Check if path is a file.
|
|
614
|
-
*
|
|
615
|
-
* @param filePath - Path to check
|
|
616
|
-
* @returns True if path is a file
|
|
617
|
-
*/
|
|
618
|
-
function isFile(filePath) {
|
|
619
|
-
const stats = getFileStat(filePath);
|
|
620
|
-
return stats?.isFile ?? false;
|
|
621
|
-
}
|
|
622
|
-
/**
|
|
623
|
-
* Check if path is a directory.
|
|
624
|
-
*
|
|
625
|
-
* @param dirPath - Path to check
|
|
626
|
-
* @returns True if path is a directory
|
|
627
|
-
*/
|
|
628
|
-
function isDirectory(dirPath) {
|
|
629
|
-
const stats = getFileStat(dirPath);
|
|
630
|
-
return stats?.isDirectory ?? false;
|
|
631
|
-
}
|
|
632
|
-
/**
|
|
633
|
-
* Check if path exists.
|
|
634
|
-
*
|
|
635
|
-
* @param filePath - Path to check
|
|
636
|
-
* @returns True if path exists
|
|
637
|
-
*/
|
|
638
|
-
function exists(filePath) {
|
|
639
|
-
return existsSync(filePath);
|
|
640
|
-
}
|
|
641
|
-
|
|
642
187
|
const fsDirLogger = createScopedLogger('project-scope:fs:dir');
|
|
643
188
|
/**
|
|
644
189
|
* List immediate contents of a directory.
|
|
@@ -647,7 +192,7 @@ const fsDirLogger = createScopedLogger('project-scope:fs:dir');
|
|
|
647
192
|
* @returns Array of entries with metadata for each file/directory
|
|
648
193
|
* @throws {Error} If directory doesn't exist or isn't a directory
|
|
649
194
|
*
|
|
650
|
-
* @example
|
|
195
|
+
* @example Listing directory contents
|
|
651
196
|
* ```typescript
|
|
652
197
|
* import { readDirectory } from '@hyperfrontend/project-scope'
|
|
653
198
|
*
|
|
@@ -688,246 +233,579 @@ function readDirectory(dirPath) {
|
|
|
688
233
|
}
|
|
689
234
|
}
|
|
690
235
|
|
|
236
|
+
createScopedLogger('project-scope:fs:traversal');
|
|
237
|
+
|
|
238
|
+
const fsWriteLogger = createScopedLogger('project-scope:fs:write');
|
|
691
239
|
/**
|
|
692
|
-
*
|
|
240
|
+
* Ensure directory exists, create recursively if not.
|
|
693
241
|
*
|
|
694
|
-
* @param
|
|
695
|
-
* @returns Normalized path with forward slashes
|
|
696
|
-
*/
|
|
697
|
-
function normalizePath(filePath) {
|
|
698
|
-
if (!filePath)
|
|
699
|
-
return '';
|
|
700
|
-
const normalized = normalize(filePath);
|
|
701
|
-
return sep === '\\' ? normalized.replace(/\\/g, '/') : normalized;
|
|
702
|
-
}
|
|
703
|
-
/**
|
|
704
|
-
* Strip any trailing forward or back slashes from a path.
|
|
242
|
+
* @param dirPath - Directory path to ensure exists
|
|
705
243
|
*
|
|
706
|
-
* @
|
|
707
|
-
*
|
|
244
|
+
* @example Ensuring directory exists
|
|
245
|
+
* ```typescript
|
|
246
|
+
* ensureDir('./output/reports')
|
|
247
|
+
* // Directory now exists (created if missing)
|
|
248
|
+
* ```
|
|
708
249
|
*/
|
|
709
|
-
function
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
250
|
+
function ensureDir(dirPath) {
|
|
251
|
+
if (!existsSync(dirPath)) {
|
|
252
|
+
fsWriteLogger.debug('Creating directory recursively', { path: dirPath });
|
|
253
|
+
mkdirSync(dirPath, { recursive: true });
|
|
713
254
|
}
|
|
714
|
-
return filePath.slice(0, i);
|
|
715
255
|
}
|
|
716
256
|
|
|
257
|
+
const vfsLogger = createScopedLogger('project-scope:vfs');
|
|
717
258
|
/**
|
|
718
|
-
*
|
|
259
|
+
* Commit buffered changes to disk.
|
|
719
260
|
*
|
|
720
|
-
* @param
|
|
721
|
-
* @
|
|
722
|
-
|
|
723
|
-
function resolvePath(...segments) {
|
|
724
|
-
return normalizePath(resolve(...segments));
|
|
725
|
-
}
|
|
726
|
-
/**
|
|
727
|
-
* Compute the normalized path from source directory to target.
|
|
261
|
+
* @param tree - Virtual file system tree with pending modifications
|
|
262
|
+
* @param options - Configuration for dry-run and verbosity
|
|
263
|
+
* @returns Result of the commit operation
|
|
728
264
|
*
|
|
729
|
-
* @
|
|
730
|
-
*
|
|
731
|
-
*
|
|
732
|
-
*/
|
|
733
|
-
function relativePath(from, to) {
|
|
734
|
-
return normalizePath(relative(from, to));
|
|
735
|
-
}
|
|
736
|
-
/**
|
|
737
|
-
* Join path segments.
|
|
265
|
+
* @example Committing changes to disk
|
|
266
|
+
* ```typescript
|
|
267
|
+
* import { createTree, commitChanges } from '@hyperfrontend/project-scope'
|
|
738
268
|
*
|
|
739
|
-
*
|
|
740
|
-
*
|
|
741
|
-
*/
|
|
742
|
-
function joinPath(...segments) {
|
|
743
|
-
return normalizePath(join(...segments));
|
|
744
|
-
}
|
|
745
|
-
/**
|
|
746
|
-
* Check if path is absolute.
|
|
269
|
+
* const tree = createTree('./my-project')
|
|
270
|
+
* tree.write('src/new-file.ts', 'export const hello = "world"')
|
|
747
271
|
*
|
|
748
|
-
*
|
|
749
|
-
*
|
|
750
|
-
|
|
751
|
-
function isAbsolute(filePath) {
|
|
752
|
-
return isAbsolute$1(filePath);
|
|
753
|
-
}
|
|
754
|
-
|
|
755
|
-
/**
|
|
756
|
-
* Get directory name of path.
|
|
272
|
+
* // Preview changes without writing
|
|
273
|
+
* const preview = commitChanges(tree, { dryRun: true })
|
|
274
|
+
* console.log('Would create:', preview.created, 'files')
|
|
757
275
|
*
|
|
758
|
-
*
|
|
759
|
-
*
|
|
276
|
+
* // Actually commit changes
|
|
277
|
+
* const result = commitChanges(tree)
|
|
278
|
+
* console.log('Created:', result.created, 'Updated:', result.updated)
|
|
279
|
+
* ```
|
|
760
280
|
*/
|
|
761
|
-
function
|
|
762
|
-
|
|
281
|
+
function commitChanges(tree, options) {
|
|
282
|
+
const changes = tree.listChanges();
|
|
283
|
+
const appliedChanges = [];
|
|
284
|
+
if (options?.verbose) {
|
|
285
|
+
vfsLogger.setLogLevel('debug');
|
|
286
|
+
}
|
|
287
|
+
vfsLogger.debug('Committing changes', { changeCount: changes.length, dryRun: options?.dryRun });
|
|
288
|
+
const result = {
|
|
289
|
+
created: 0,
|
|
290
|
+
updated: 0,
|
|
291
|
+
deleted: 0,
|
|
292
|
+
changes: [],
|
|
293
|
+
dryRun: options?.dryRun ?? false,
|
|
294
|
+
};
|
|
295
|
+
if (options?.dryRun) {
|
|
296
|
+
for (const change of changes) {
|
|
297
|
+
switch (change.type) {
|
|
298
|
+
case 'CREATE':
|
|
299
|
+
result.created++;
|
|
300
|
+
break;
|
|
301
|
+
case 'UPDATE':
|
|
302
|
+
result.updated++;
|
|
303
|
+
break;
|
|
304
|
+
case 'DELETE':
|
|
305
|
+
result.deleted++;
|
|
306
|
+
break;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
result.changes = changes;
|
|
310
|
+
return result;
|
|
311
|
+
}
|
|
312
|
+
const sortedChanges = [...changes].sort((a, b) => {
|
|
313
|
+
const order = { DELETE: 0, CREATE: 1, UPDATE: 2 };
|
|
314
|
+
return order[a.type] - order[b.type];
|
|
315
|
+
});
|
|
316
|
+
for (const change of sortedChanges) {
|
|
317
|
+
const absPath = join(tree.root, change.path);
|
|
318
|
+
try {
|
|
319
|
+
switch (change.type) {
|
|
320
|
+
case 'CREATE':
|
|
321
|
+
case 'UPDATE':
|
|
322
|
+
/* istanbul ignore if -- content is always defined for CREATE/UPDATE from tree.write() */
|
|
323
|
+
if (change.content !== undefined) {
|
|
324
|
+
const dir = dirname(absPath);
|
|
325
|
+
ensureDir(dir);
|
|
326
|
+
writeFileSync(absPath, change.content);
|
|
327
|
+
if (change.mode !== undefined) {
|
|
328
|
+
chmodSync(absPath, change.mode);
|
|
329
|
+
}
|
|
330
|
+
if (change.type === 'CREATE') {
|
|
331
|
+
result.created++;
|
|
332
|
+
}
|
|
333
|
+
else {
|
|
334
|
+
result.updated++;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
break;
|
|
338
|
+
case 'DELETE':
|
|
339
|
+
if (exists(absPath)) {
|
|
340
|
+
try {
|
|
341
|
+
unlinkSync(absPath);
|
|
342
|
+
}
|
|
343
|
+
catch {
|
|
344
|
+
rmSync(absPath, { recursive: true });
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
result.deleted++;
|
|
348
|
+
break;
|
|
349
|
+
}
|
|
350
|
+
appliedChanges.push(change);
|
|
351
|
+
if (options?.verbose) {
|
|
352
|
+
const prefix = change.type === 'CREATE' ? '+' : change.type === 'DELETE' ? '-' : '~';
|
|
353
|
+
vfsLogger.info(`${prefix} ${change.path}`);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
catch (error) {
|
|
357
|
+
vfsLogger.error('Commit failed', { path: change.path, type: change.type });
|
|
358
|
+
const message = error instanceof Error
|
|
359
|
+
? `Failed to ${change.type.toLowerCase()} ${change.path}: ${error.message}`
|
|
360
|
+
: `Failed to ${change.type.toLowerCase()} ${change.path}`;
|
|
361
|
+
throw createError(message);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
result.changes = appliedChanges;
|
|
365
|
+
tree.clearChanges();
|
|
366
|
+
return result;
|
|
763
367
|
}
|
|
764
|
-
|
|
765
|
-
createScopedLogger('project-scope:fs:traversal');
|
|
766
|
-
|
|
767
368
|
/**
|
|
768
|
-
*
|
|
369
|
+
* Discard all pending changes.
|
|
370
|
+
*
|
|
371
|
+
* @param tree - Virtual file system tree
|
|
372
|
+
*
|
|
373
|
+
* @example Rolling back pending changes
|
|
374
|
+
* ```typescript
|
|
375
|
+
* import { createTree, rollbackChanges } from '@hyperfrontend/project-scope'
|
|
376
|
+
*
|
|
377
|
+
* const tree = createTree('/workspace')
|
|
378
|
+
* tree.write('new-file.ts', 'content')
|
|
379
|
+
* // Decide to abort - discard all pending changes
|
|
380
|
+
* rollbackChanges(tree)
|
|
381
|
+
* ```
|
|
769
382
|
*/
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
/** Fail if file exists */
|
|
774
|
-
ExclusiveCreate: 'exclusive',
|
|
775
|
-
/** Skip if file exists */
|
|
776
|
-
SkipIfExists: 'skip',
|
|
777
|
-
});
|
|
383
|
+
function rollbackChanges(tree) {
|
|
384
|
+
tree.clearChanges();
|
|
385
|
+
}
|
|
778
386
|
|
|
779
|
-
const
|
|
387
|
+
const diffLogger = createScopedLogger('project-scope:vfs:diff');
|
|
388
|
+
const DEFAULT_CONTEXT_LINES = 3;
|
|
780
389
|
/**
|
|
781
|
-
*
|
|
782
|
-
*
|
|
783
|
-
* Supports transactional modifications - all changes are buffered
|
|
784
|
-
* in memory and can be committed atomically or rolled back.
|
|
390
|
+
* Compute the Longest Common Subsequence (LCS) table for two arrays of lines.
|
|
391
|
+
* Uses dynamic programming for O(n*m) time complexity.
|
|
785
392
|
*
|
|
786
|
-
* @param
|
|
787
|
-
* @param
|
|
788
|
-
* @returns
|
|
393
|
+
* @param oldLines - Lines from the original file version
|
|
394
|
+
* @param newLines - Lines from the new file version
|
|
395
|
+
* @returns Two-dimensional LCS table for backtracking
|
|
789
396
|
*/
|
|
790
|
-
function
|
|
791
|
-
const
|
|
792
|
-
const
|
|
793
|
-
const
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
*/
|
|
803
|
-
function normalizeFilePath(filePath) {
|
|
804
|
-
const normalized = isAbsolute(filePath) ? relativePath(_root, filePath) : normalizePath(filePath);
|
|
805
|
-
const absoluteResolved = resolvePath(_root, normalized);
|
|
806
|
-
if (!absoluteResolved.startsWith(_root + '/') && absoluteResolved !== _root) {
|
|
807
|
-
throw createError(`Path escapes tree root: ${filePath}`);
|
|
397
|
+
function computeLcsTable(oldLines, newLines) {
|
|
398
|
+
const m = oldLines.length;
|
|
399
|
+
const n = newLines.length;
|
|
400
|
+
const table = from({ length: m + 1 }, () => Array(n + 1).fill(0));
|
|
401
|
+
for (let i = 1; i <= m; i++) {
|
|
402
|
+
for (let j = 1; j <= n; j++) {
|
|
403
|
+
if (oldLines[i - 1] === newLines[j - 1]) {
|
|
404
|
+
table[i][j] = table[i - 1][j - 1] + 1;
|
|
405
|
+
}
|
|
406
|
+
else {
|
|
407
|
+
table[i][j] = max(table[i - 1][j], table[i][j - 1]);
|
|
408
|
+
}
|
|
808
409
|
}
|
|
809
|
-
return normalized;
|
|
810
|
-
}
|
|
811
|
-
/**
|
|
812
|
-
* Get absolute path on disk.
|
|
813
|
-
*
|
|
814
|
-
* @param filePath - Relative path from root
|
|
815
|
-
* @returns Absolute path on disk
|
|
816
|
-
*/
|
|
817
|
-
function absolutePath(filePath) {
|
|
818
|
-
return joinPath(_root, normalizeFilePath(filePath));
|
|
819
410
|
}
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
411
|
+
return table;
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
414
|
+
* Backtrack through LCS table to produce diff operations.
|
|
415
|
+
*
|
|
416
|
+
* @param table - Two-dimensional LCS table from computeLcsTable
|
|
417
|
+
* @param oldLines - Lines from the original file version
|
|
418
|
+
* @param newLines - Lines from the new file version
|
|
419
|
+
* @returns Array of diff operations (unfiltered, includes all lines)
|
|
420
|
+
*/
|
|
421
|
+
function backtrackLcs(table, oldLines, newLines) {
|
|
422
|
+
const result = [];
|
|
423
|
+
let i = oldLines.length;
|
|
424
|
+
let j = newLines.length;
|
|
425
|
+
while (i > 0 || j > 0) {
|
|
426
|
+
if (i > 0 && j > 0 && oldLines[i - 1] === newLines[j - 1]) {
|
|
427
|
+
result.unshift({ type: 'same', oldIdx: i - 1, newIdx: j - 1, content: oldLines[i - 1] });
|
|
428
|
+
i--;
|
|
429
|
+
j--;
|
|
831
430
|
}
|
|
832
|
-
|
|
833
|
-
|
|
431
|
+
else if (j > 0 && (i === 0 || table[i][j - 1] >= table[i - 1][j])) {
|
|
432
|
+
result.unshift({ type: 'add', oldIdx: i - 1, newIdx: j - 1, content: newLines[j - 1] });
|
|
433
|
+
j--;
|
|
834
434
|
}
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
*
|
|
839
|
-
* @param normalPath - Already normalized path to symlink
|
|
840
|
-
* @throws {Error} If symlink target escapes tree root or followSymlinks is disabled
|
|
841
|
-
*/
|
|
842
|
-
function validateSymlink(normalPath) {
|
|
843
|
-
const absPath = absolutePath(normalPath);
|
|
844
|
-
if (!isSymlinkNormalizedPath(normalPath)) {
|
|
845
|
-
return;
|
|
435
|
+
else {
|
|
436
|
+
result.unshift({ type: 'remove', oldIdx: i - 1, newIdx: -1, content: oldLines[i - 1] });
|
|
437
|
+
i--;
|
|
846
438
|
}
|
|
847
|
-
|
|
848
|
-
|
|
439
|
+
}
|
|
440
|
+
return result;
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* Convert raw diff operations to DiffLine array with context filtering.
|
|
444
|
+
*
|
|
445
|
+
* @param operations - Raw diff operations
|
|
446
|
+
* @param contextLines - Number of context lines to include
|
|
447
|
+
* @returns Filtered DiffLine array
|
|
448
|
+
*/
|
|
449
|
+
function operationsToDiffLines(operations, contextLines) {
|
|
450
|
+
const include = new Array(operations.length).fill(false);
|
|
451
|
+
for (let i = 0; i < operations.length; i++) {
|
|
452
|
+
if (operations[i].type !== 'same') {
|
|
453
|
+
for (let j = max(0, i - contextLines); j <= min(operations.length - 1, i + contextLines); j++) {
|
|
454
|
+
include[j] = true;
|
|
455
|
+
}
|
|
849
456
|
}
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
457
|
+
}
|
|
458
|
+
const lines = [];
|
|
459
|
+
let oldLineNum = 1;
|
|
460
|
+
let newLineNum = 1;
|
|
461
|
+
for (let i = 0; i < operations.length; i++) {
|
|
462
|
+
const op = operations[i];
|
|
463
|
+
if (include[i]) {
|
|
464
|
+
if (op.type === 'same') {
|
|
465
|
+
lines.push({ type: 'context', line: oldLineNum, content: op.content });
|
|
466
|
+
oldLineNum++;
|
|
467
|
+
newLineNum++;
|
|
855
468
|
}
|
|
856
|
-
else {
|
|
857
|
-
|
|
858
|
-
|
|
469
|
+
else if (op.type === 'remove') {
|
|
470
|
+
lines.push({ type: 'remove', line: oldLineNum, content: op.content });
|
|
471
|
+
oldLineNum++;
|
|
859
472
|
}
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
473
|
+
else {
|
|
474
|
+
lines.push({ type: 'add', line: newLineNum, content: op.content });
|
|
475
|
+
newLineNum++;
|
|
863
476
|
}
|
|
864
477
|
}
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
}
|
|
870
|
-
if (error instanceof Error && error.message.includes('followSymlinks is disabled')) {
|
|
871
|
-
throw error;
|
|
478
|
+
else {
|
|
479
|
+
if (op.type === 'same') {
|
|
480
|
+
oldLineNum++;
|
|
481
|
+
newLineNum++;
|
|
872
482
|
}
|
|
873
|
-
|
|
483
|
+
else if (op.type === 'remove') {
|
|
484
|
+
/* istanbul ignore next -- unreachable: remove operations always have include=true */
|
|
485
|
+
oldLineNum++;
|
|
486
|
+
}
|
|
487
|
+
else {
|
|
488
|
+
/* istanbul ignore next -- unreachable: add operations always have include=true */
|
|
489
|
+
newLineNum++;
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
return lines;
|
|
494
|
+
}
|
|
495
|
+
/**
|
|
496
|
+
* Split buffer content into lines.
|
|
497
|
+
*
|
|
498
|
+
* @param content - File content as Buffer, or undefined for empty
|
|
499
|
+
* @returns Array of string lines from the buffer
|
|
500
|
+
*/
|
|
501
|
+
function bufferToLines(content) {
|
|
502
|
+
if (!content)
|
|
503
|
+
return [];
|
|
504
|
+
const text = content.toString('utf-8');
|
|
505
|
+
return text.split('\n');
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
508
|
+
* Generate a diff for a single file change.
|
|
509
|
+
*
|
|
510
|
+
* @example Generating a diff for a file change
|
|
511
|
+
* ```typescript
|
|
512
|
+
* const change: FileChange = {
|
|
513
|
+
* path: 'src/app.ts',
|
|
514
|
+
* type: 'UPDATE',
|
|
515
|
+
* originalContent: Buffer.from('const x = 1;\n'),
|
|
516
|
+
* content: Buffer.from('const x = 2;\n'),
|
|
517
|
+
* }
|
|
518
|
+
* const diff = generateDiff(change)
|
|
519
|
+
* // { path: 'src/app.ts', additions: 1, deletions: 1, lines: [...] }
|
|
520
|
+
* ```
|
|
521
|
+
*
|
|
522
|
+
* @param change - File change to diff
|
|
523
|
+
* @param options - Configuration for diff generation including context lines
|
|
524
|
+
* @returns FileDiff object
|
|
525
|
+
*/
|
|
526
|
+
function generateDiff(change, options = {}) {
|
|
527
|
+
const contextLines = options.contextLines ?? DEFAULT_CONTEXT_LINES;
|
|
528
|
+
diffLogger.debug('generateDiff', { path: change.path, type: change.type, contextLines });
|
|
529
|
+
const oldLines = bufferToLines(change.originalContent);
|
|
530
|
+
const newLines = bufferToLines(change.content);
|
|
531
|
+
if (change.type === 'CREATE') {
|
|
532
|
+
const lines = newLines
|
|
533
|
+
.filter((line) => line !== '' || newLines.indexOf(line) !== newLines.length - 1 || newLines.length === 1)
|
|
534
|
+
.map((content, idx) => ({
|
|
535
|
+
type: 'add',
|
|
536
|
+
line: idx + 1,
|
|
537
|
+
content,
|
|
538
|
+
}));
|
|
539
|
+
const filteredLines = lines.filter((l, i) => !(i === lines.length - 1 && l.content === '' && lines.length > 1));
|
|
540
|
+
return {
|
|
541
|
+
path: change.path,
|
|
542
|
+
lines: filteredLines,
|
|
543
|
+
additions: filteredLines.length,
|
|
544
|
+
deletions: 0,
|
|
545
|
+
};
|
|
546
|
+
}
|
|
547
|
+
if (change.type === 'DELETE') {
|
|
548
|
+
const lines = oldLines.map((content, idx) => ({
|
|
549
|
+
type: 'remove',
|
|
550
|
+
line: idx + 1,
|
|
551
|
+
content,
|
|
552
|
+
}));
|
|
553
|
+
const filteredLines = lines.filter((l, i) => !(i === lines.length - 1 && l.content === '' && lines.length > 1));
|
|
554
|
+
return {
|
|
555
|
+
path: change.path,
|
|
556
|
+
lines: filteredLines,
|
|
557
|
+
additions: 0,
|
|
558
|
+
deletions: filteredLines.length,
|
|
559
|
+
};
|
|
560
|
+
}
|
|
561
|
+
const table = computeLcsTable(oldLines, newLines);
|
|
562
|
+
const operations = backtrackLcs(table, oldLines, newLines);
|
|
563
|
+
const lines = operationsToDiffLines(operations, contextLines);
|
|
564
|
+
const additions = lines.filter((l) => l.type === 'add').length;
|
|
565
|
+
const deletions = lines.filter((l) => l.type === 'remove').length;
|
|
566
|
+
return {
|
|
567
|
+
path: change.path,
|
|
568
|
+
lines,
|
|
569
|
+
additions,
|
|
570
|
+
deletions,
|
|
571
|
+
};
|
|
572
|
+
}
|
|
573
|
+
/**
|
|
574
|
+
* Format a FileDiff as a unified diff string.
|
|
575
|
+
*
|
|
576
|
+
* @example Formatting a unified diff
|
|
577
|
+
* ```typescript
|
|
578
|
+
* const formatted = formatUnifiedDiff(diff)
|
|
579
|
+
* console.log(formatted)
|
|
580
|
+
* // --- a/src/app.ts
|
|
581
|
+
* // +++ b/src/app.ts
|
|
582
|
+
* // @@ -1,3 +1,3 @@
|
|
583
|
+
* // const x = 1;
|
|
584
|
+
* // -const y = 2;
|
|
585
|
+
* // +const y = 3;
|
|
586
|
+
* // const z = 4;
|
|
587
|
+
* ```
|
|
588
|
+
*
|
|
589
|
+
* @param diff - FileDiff to format
|
|
590
|
+
* @returns Unified diff string
|
|
591
|
+
*/
|
|
592
|
+
function formatUnifiedDiff(diff) {
|
|
593
|
+
const lines = [];
|
|
594
|
+
lines.push(`--- a/${diff.path}`);
|
|
595
|
+
lines.push(`+++ b/${diff.path}`);
|
|
596
|
+
if (diff.lines.length === 0) {
|
|
597
|
+
return lines.join('\n');
|
|
598
|
+
}
|
|
599
|
+
const hunks = [];
|
|
600
|
+
const currentHunk = [];
|
|
601
|
+
for (const line of diff.lines) {
|
|
602
|
+
currentHunk.push(line);
|
|
603
|
+
}
|
|
604
|
+
if (currentHunk.length > 0) {
|
|
605
|
+
hunks.push(currentHunk);
|
|
606
|
+
}
|
|
607
|
+
for (const hunk of hunks) {
|
|
608
|
+
const contextAndRemove = hunk.filter((l) => l.type === 'context' || l.type === 'remove');
|
|
609
|
+
const contextAndAdd = hunk.filter((l) => l.type === 'context' || l.type === 'add');
|
|
610
|
+
const oldStart = hunk.find((l) => l.type === 'context' || l.type === 'remove')?.line ?? 1;
|
|
611
|
+
const newStart = hunk.find((l) => l.type === 'context' || l.type === 'add')?.line ?? 1;
|
|
612
|
+
const oldCount = contextAndRemove.length;
|
|
613
|
+
const newCount = contextAndAdd.length;
|
|
614
|
+
lines.push(`@@ -${oldStart},${oldCount} +${newStart},${newCount} @@`);
|
|
615
|
+
for (const line of hunk) {
|
|
616
|
+
const prefix = line.type === 'add' ? '+' : line.type === 'remove' ? '-' : ' ';
|
|
617
|
+
lines.push(`${prefix}${line.content}`);
|
|
874
618
|
}
|
|
875
619
|
}
|
|
620
|
+
return lines.join('\n');
|
|
621
|
+
}
|
|
622
|
+
/**
|
|
623
|
+
* Generate diffs for all changes in a tree.
|
|
624
|
+
*
|
|
625
|
+
* @example Generating diffs for all changes
|
|
626
|
+
* ```typescript
|
|
627
|
+
* const tree = createTree('/workspace')
|
|
628
|
+
* tree.write('new.txt', 'hello')
|
|
629
|
+
* tree.delete('old.txt')
|
|
630
|
+
*
|
|
631
|
+
* const diffs = generateAllDiffs(tree)
|
|
632
|
+
* for (const diff of diffs) {
|
|
633
|
+
* console.log(formatUnifiedDiff(diff))
|
|
634
|
+
* }
|
|
635
|
+
* ```
|
|
636
|
+
*
|
|
637
|
+
* @param tree - Tree to generate diffs for
|
|
638
|
+
* @param options - Diff options
|
|
639
|
+
* @returns Array of FileDiff objects
|
|
640
|
+
*/
|
|
641
|
+
function generateAllDiffs(tree, options = {}) {
|
|
642
|
+
const changes = tree.listChanges();
|
|
643
|
+
diffLogger.debug('generateAllDiffs', { changeCount: changes.length });
|
|
644
|
+
return changes.map((change) => generateDiff(change, options));
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
const fsTreeLogger = createScopedLogger('project-scope:vfs:tree');
|
|
648
|
+
/**
|
|
649
|
+
* Create a file system-backed tree implementation.
|
|
650
|
+
*
|
|
651
|
+
* Supports transactional modifications - all changes are buffered
|
|
652
|
+
* in memory and can be committed atomically or rolled back.
|
|
653
|
+
*
|
|
654
|
+
* @param root - Absolute path to the workspace root directory
|
|
655
|
+
* @param options - Configuration for verbose logging
|
|
656
|
+
* @returns A Tree instance
|
|
657
|
+
*
|
|
658
|
+
* @example Creating and using a file system tree
|
|
659
|
+
* ```typescript
|
|
660
|
+
* import { createFsTree, commitChanges } from '@hyperfrontend/project-scope'
|
|
661
|
+
*
|
|
662
|
+
* const tree = createFsTree('/workspace')
|
|
663
|
+
* tree.write('src/new-file.ts', 'export const value = 42')
|
|
664
|
+
* tree.delete('old-file.ts')
|
|
665
|
+
* commitChanges(tree) // Atomically apply all changes to disk
|
|
666
|
+
* ```
|
|
667
|
+
*/
|
|
668
|
+
function createFsTree(root, options) {
|
|
669
|
+
const _root = removeTrailingSlash(normalizePath(root));
|
|
670
|
+
const _changes = createMap();
|
|
671
|
+
const _isVerbose = options?.verbose ?? false;
|
|
672
|
+
const _followSymlinks = options?.followSymlinks ?? true;
|
|
673
|
+
fsTreeLogger.debug('Creating VFS tree', { root: _root, verbose: _isVerbose, followSymlinks: _followSymlinks });
|
|
876
674
|
/**
|
|
877
|
-
*
|
|
675
|
+
* Normalize path to be relative from root.
|
|
878
676
|
*
|
|
879
|
-
* @param
|
|
880
|
-
* @returns
|
|
677
|
+
* @param filePath - Path to normalize
|
|
678
|
+
* @returns Normalized relative path
|
|
679
|
+
* @throws {Error} if path traverses outside the tree root
|
|
881
680
|
*/
|
|
882
|
-
function
|
|
883
|
-
const
|
|
884
|
-
|
|
681
|
+
function normalizeFilePath(filePath) {
|
|
682
|
+
const normalized = isAbsolute(filePath) ? relativePath(_root, filePath) : normalizePath(filePath);
|
|
683
|
+
const absoluteResolved = resolvePath(_root, normalized);
|
|
684
|
+
if (!absoluteResolved.startsWith(_root + '/') && absoluteResolved !== _root) {
|
|
685
|
+
throw createError(`Path escapes tree root: ${filePath}`);
|
|
686
|
+
}
|
|
687
|
+
return normalized;
|
|
885
688
|
}
|
|
886
689
|
/**
|
|
887
|
-
*
|
|
690
|
+
* Get absolute path on disk.
|
|
888
691
|
*
|
|
889
|
-
* @param
|
|
890
|
-
* @returns
|
|
692
|
+
* @param filePath - Relative path from root
|
|
693
|
+
* @returns Absolute path on disk
|
|
891
694
|
*/
|
|
892
|
-
function
|
|
893
|
-
|
|
695
|
+
function absolutePath(filePath) {
|
|
696
|
+
return joinPath(_root, normalizeFilePath(filePath));
|
|
697
|
+
}
|
|
698
|
+
/**
|
|
699
|
+
* Check if a normalized path is a symbolic link.
|
|
700
|
+
*
|
|
701
|
+
* @param normalPath - Already normalized path
|
|
702
|
+
* @returns True if path is a symlink
|
|
703
|
+
*/
|
|
704
|
+
function isSymlinkNormalizedPath(normalPath) {
|
|
894
705
|
const absPath = absolutePath(normalPath);
|
|
895
|
-
if (!isFile(absPath)) {
|
|
896
|
-
return null;
|
|
897
|
-
}
|
|
898
706
|
try {
|
|
899
|
-
|
|
707
|
+
const stats = lstatSync(absPath);
|
|
708
|
+
return stats.isSymbolicLink();
|
|
900
709
|
}
|
|
901
710
|
catch {
|
|
902
|
-
return
|
|
711
|
+
return false;
|
|
903
712
|
}
|
|
904
713
|
}
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
}
|
|
929
|
-
|
|
930
|
-
|
|
714
|
+
/**
|
|
715
|
+
* Validate that a symlink target stays within tree bounds.
|
|
716
|
+
*
|
|
717
|
+
* @param normalPath - Already normalized path to symlink
|
|
718
|
+
* @throws {Error} If symlink target escapes tree root or followSymlinks is disabled
|
|
719
|
+
*/
|
|
720
|
+
function validateSymlink(normalPath) {
|
|
721
|
+
const absPath = absolutePath(normalPath);
|
|
722
|
+
if (!isSymlinkNormalizedPath(normalPath)) {
|
|
723
|
+
return;
|
|
724
|
+
}
|
|
725
|
+
if (!_followSymlinks) {
|
|
726
|
+
throw createError(`Cannot access symlink when followSymlinks is disabled: ${normalPath}`);
|
|
727
|
+
}
|
|
728
|
+
try {
|
|
729
|
+
const target = readlinkSync(absPath);
|
|
730
|
+
let targetAbsolute;
|
|
731
|
+
if (isAbsolute(target)) {
|
|
732
|
+
targetAbsolute = target;
|
|
733
|
+
}
|
|
734
|
+
else {
|
|
735
|
+
const symlinkDir = getDirname(absPath);
|
|
736
|
+
targetAbsolute = resolvePath(symlinkDir, target);
|
|
737
|
+
}
|
|
738
|
+
const normalizedTarget = normalizePath(targetAbsolute);
|
|
739
|
+
if (!normalizedTarget.startsWith(_root + '/') && normalizedTarget !== _root) {
|
|
740
|
+
throw createError(`Symlink target escapes tree root: ${normalPath} -> ${target}`);
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
catch (error) {
|
|
744
|
+
/* istanbul ignore else -- other errors are rare edge cases (e.g., permission denied) */
|
|
745
|
+
if (error instanceof Error && error.message.includes('Symlink target escapes')) {
|
|
746
|
+
throw error;
|
|
747
|
+
}
|
|
748
|
+
if (error instanceof Error && error.message.includes('followSymlinks is disabled')) {
|
|
749
|
+
throw error;
|
|
750
|
+
}
|
|
751
|
+
throw createError(`Failed to validate symlink: ${normalPath}`);
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
/**
|
|
755
|
+
* Check if path exists on disk (not considering buffered changes).
|
|
756
|
+
*
|
|
757
|
+
* @param normalPath - Normalized path to check
|
|
758
|
+
* @returns True if exists on disk
|
|
759
|
+
*/
|
|
760
|
+
function existsOnDisk(normalPath) {
|
|
761
|
+
const absPath = absolutePath(normalPath);
|
|
762
|
+
return exists(absPath);
|
|
763
|
+
}
|
|
764
|
+
/**
|
|
765
|
+
* Read from disk (not considering buffered changes).
|
|
766
|
+
*
|
|
767
|
+
* @param normalPath - Normalized path to read
|
|
768
|
+
* @returns File content or null
|
|
769
|
+
*/
|
|
770
|
+
function readFromDisk(normalPath) {
|
|
771
|
+
validateSymlink(normalPath);
|
|
772
|
+
const absPath = absolutePath(normalPath);
|
|
773
|
+
if (!isFile(absPath)) {
|
|
774
|
+
return null;
|
|
775
|
+
}
|
|
776
|
+
try {
|
|
777
|
+
return readFileSync(absPath);
|
|
778
|
+
}
|
|
779
|
+
catch {
|
|
780
|
+
return null;
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
const tree = {
|
|
784
|
+
get root() {
|
|
785
|
+
return _root;
|
|
786
|
+
},
|
|
787
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
788
|
+
read(filePath, encoding) {
|
|
789
|
+
const normalPath = normalizeFilePath(filePath);
|
|
790
|
+
const change = _changes.get(normalPath);
|
|
791
|
+
if (change) {
|
|
792
|
+
if (change.type === 'DELETE') {
|
|
793
|
+
return null;
|
|
794
|
+
}
|
|
795
|
+
if (change.content !== null) {
|
|
796
|
+
return encoding ? change.content.toString(encoding) : change.content;
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
validateSymlink(normalPath);
|
|
800
|
+
const absPath = absolutePath(normalPath);
|
|
801
|
+
if (!exists(absPath)) {
|
|
802
|
+
return null;
|
|
803
|
+
}
|
|
804
|
+
if (!isFile(absPath)) {
|
|
805
|
+
return null;
|
|
806
|
+
}
|
|
807
|
+
try {
|
|
808
|
+
const content = readFileSync(absPath);
|
|
931
809
|
return encoding ? content.toString(encoding) : content;
|
|
932
810
|
}
|
|
933
811
|
catch {
|
|
@@ -1034,516 +912,143 @@ function createFsTree(root, options) {
|
|
|
1034
912
|
for (const entry of entries) {
|
|
1035
913
|
childSet.add(entry.name);
|
|
1036
914
|
}
|
|
1037
|
-
}
|
|
1038
|
-
}
|
|
1039
|
-
catch {
|
|
1040
|
-
// Directory doesn't exist on disk
|
|
1041
|
-
}
|
|
1042
|
-
const prefix = normalPath === '.' || normalPath === '' ? '' : normalPath + '/';
|
|
1043
|
-
for (const [changedPath, change] of _changes) {
|
|
1044
|
-
if (prefix === '') {
|
|
1045
|
-
const childName = changedPath.split('/')[0];
|
|
1046
|
-
if (change.type === 'DELETE' && !changedPath.includes('/')) {
|
|
1047
|
-
childSet.delete(childName);
|
|
1048
|
-
}
|
|
1049
|
-
else if (change.type !== 'DELETE') {
|
|
1050
|
-
childSet.add(childName);
|
|
1051
|
-
}
|
|
1052
|
-
continue;
|
|
1053
|
-
}
|
|
1054
|
-
if (!changedPath.startsWith(prefix)) {
|
|
1055
|
-
continue;
|
|
1056
|
-
}
|
|
1057
|
-
const relativePath = changedPath.slice(prefix.length);
|
|
1058
|
-
const childName = relativePath.split('/')[0];
|
|
1059
|
-
if (change.type === 'DELETE') {
|
|
1060
|
-
if (!relativePath.includes('/')) {
|
|
1061
|
-
childSet.delete(childName);
|
|
1062
|
-
}
|
|
1063
|
-
}
|
|
1064
|
-
else {
|
|
1065
|
-
childSet.add(childName);
|
|
1066
|
-
}
|
|
1067
|
-
}
|
|
1068
|
-
return from(childSet).sort();
|
|
1069
|
-
},
|
|
1070
|
-
listChanges() {
|
|
1071
|
-
const changes = [];
|
|
1072
|
-
for (const [path, record] of _changes) {
|
|
1073
|
-
changes.push({
|
|
1074
|
-
path,
|
|
1075
|
-
type: record.type,
|
|
1076
|
-
content: record.content ?? undefined,
|
|
1077
|
-
originalContent: record.originalContent ?? undefined,
|
|
1078
|
-
mode: record.permissions,
|
|
1079
|
-
});
|
|
1080
|
-
}
|
|
1081
|
-
return changes.sort((a, b) => a.path.localeCompare(b.path));
|
|
1082
|
-
},
|
|
1083
|
-
changePermissions(filePath, mode) {
|
|
1084
|
-
const normalPath = normalizeFilePath(filePath);
|
|
1085
|
-
if (!this.exists(normalPath)) {
|
|
1086
|
-
throw createError(`File not found: ${normalPath}`);
|
|
1087
|
-
}
|
|
1088
|
-
const existingChange = _changes.get(normalPath);
|
|
1089
|
-
if (existingChange) {
|
|
1090
|
-
existingChange.permissions = mode;
|
|
1091
|
-
}
|
|
1092
|
-
else {
|
|
1093
|
-
const content = readFromDisk(normalPath);
|
|
1094
|
-
_changes.set(normalPath, {
|
|
1095
|
-
type: 'UPDATE',
|
|
1096
|
-
content,
|
|
1097
|
-
originalContent: content,
|
|
1098
|
-
permissions: mode,
|
|
1099
|
-
});
|
|
1100
|
-
}
|
|
1101
|
-
},
|
|
1102
|
-
changeFile(filePath, transform) {
|
|
1103
|
-
const content = this.read(filePath);
|
|
1104
|
-
if (content === null) {
|
|
1105
|
-
throw createError(`File not found: ${filePath}`);
|
|
1106
|
-
}
|
|
1107
|
-
const newContent = transform(content);
|
|
1108
|
-
this.write(filePath, newContent);
|
|
1109
|
-
},
|
|
1110
|
-
clearChanges() {
|
|
1111
|
-
_changes.clear();
|
|
1112
|
-
},
|
|
1113
|
-
};
|
|
1114
|
-
return tree;
|
|
1115
|
-
}
|
|
1116
|
-
|
|
1117
|
-
const factoryLogger = createScopedLogger('project-scope:vfs:factory');
|
|
1118
|
-
/**
|
|
1119
|
-
* Create a virtual file system tree.
|
|
1120
|
-
*
|
|
1121
|
-
* @param root - Root directory path
|
|
1122
|
-
* @param options - Tree creation options
|
|
1123
|
-
* @returns A new Tree instance
|
|
1124
|
-
* @throws {Error} If root doesn't exist or isn't a directory
|
|
1125
|
-
*
|
|
1126
|
-
* @example
|
|
1127
|
-
* ```typescript
|
|
1128
|
-
* import { createTree } from '@hyperfrontend/project-scope'
|
|
1129
|
-
*
|
|
1130
|
-
* const tree = createTree('./my-project')
|
|
1131
|
-
*
|
|
1132
|
-
* // Read files from tree
|
|
1133
|
-
* const content = tree.read('src/index.ts', 'utf-8')
|
|
1134
|
-
*
|
|
1135
|
-
* // Make changes (buffered in memory)
|
|
1136
|
-
* tree.write('src/new-file.ts', 'export const x = 1')
|
|
1137
|
-
*
|
|
1138
|
-
* // List pending changes
|
|
1139
|
-
* console.log(tree.listChanges())
|
|
1140
|
-
* ```
|
|
1141
|
-
*/
|
|
1142
|
-
function createTree(root, options) {
|
|
1143
|
-
const normalizedRoot = normalizePath(root);
|
|
1144
|
-
factoryLogger.debug('createTree', { root: normalizedRoot });
|
|
1145
|
-
if (!exists(normalizedRoot)) {
|
|
1146
|
-
factoryLogger.warn('createTree failed: root does not exist', { root: normalizedRoot });
|
|
1147
|
-
throw createError(`Root directory does not exist: ${normalizedRoot}`);
|
|
1148
|
-
}
|
|
1149
|
-
if (!isDirectory(normalizedRoot)) {
|
|
1150
|
-
factoryLogger.warn('createTree failed: root is not a directory', { root: normalizedRoot });
|
|
1151
|
-
throw createError(`Root path is not a directory: ${normalizedRoot}`);
|
|
1152
|
-
}
|
|
1153
|
-
return createFsTree(normalizedRoot, options);
|
|
1154
|
-
}
|
|
1155
|
-
/**
|
|
1156
|
-
* Create a tree from disk.
|
|
1157
|
-
*
|
|
1158
|
-
* Convenience alias for createTree.
|
|
1159
|
-
*
|
|
1160
|
-
* @param root - Root directory path
|
|
1161
|
-
* @param options - Tree creation options
|
|
1162
|
-
* @returns A new Tree instance backed by disk
|
|
1163
|
-
*/
|
|
1164
|
-
function createTreeFromDisk(root, options) {
|
|
1165
|
-
return createTree(root, options);
|
|
1166
|
-
}
|
|
1167
|
-
|
|
1168
|
-
const vfsLogger = createScopedLogger('project-scope:vfs');
|
|
1169
|
-
/**
|
|
1170
|
-
* Commit buffered changes to disk.
|
|
1171
|
-
*
|
|
1172
|
-
* @param tree - Virtual file system tree with pending modifications
|
|
1173
|
-
* @param options - Configuration for dry-run and verbosity
|
|
1174
|
-
* @returns Result of the commit operation
|
|
1175
|
-
*
|
|
1176
|
-
* @example
|
|
1177
|
-
* ```typescript
|
|
1178
|
-
* import { createTree, commitChanges } from '@hyperfrontend/project-scope'
|
|
1179
|
-
*
|
|
1180
|
-
* const tree = createTree('./my-project')
|
|
1181
|
-
* tree.write('src/new-file.ts', 'export const hello = "world"')
|
|
1182
|
-
*
|
|
1183
|
-
* // Preview changes without writing
|
|
1184
|
-
* const preview = commitChanges(tree, { dryRun: true })
|
|
1185
|
-
* console.log('Would create:', preview.created, 'files')
|
|
1186
|
-
*
|
|
1187
|
-
* // Actually commit changes
|
|
1188
|
-
* const result = commitChanges(tree)
|
|
1189
|
-
* console.log('Created:', result.created, 'Updated:', result.updated)
|
|
1190
|
-
* ```
|
|
1191
|
-
*/
|
|
1192
|
-
function commitChanges(tree, options) {
|
|
1193
|
-
const changes = tree.listChanges();
|
|
1194
|
-
const appliedChanges = [];
|
|
1195
|
-
if (options?.verbose) {
|
|
1196
|
-
vfsLogger.setLogLevel('debug');
|
|
1197
|
-
}
|
|
1198
|
-
vfsLogger.debug('Committing changes', { changeCount: changes.length, dryRun: options?.dryRun });
|
|
1199
|
-
const result = {
|
|
1200
|
-
created: 0,
|
|
1201
|
-
updated: 0,
|
|
1202
|
-
deleted: 0,
|
|
1203
|
-
changes: [],
|
|
1204
|
-
dryRun: options?.dryRun ?? false,
|
|
1205
|
-
};
|
|
1206
|
-
if (options?.dryRun) {
|
|
1207
|
-
for (const change of changes) {
|
|
1208
|
-
switch (change.type) {
|
|
1209
|
-
case 'CREATE':
|
|
1210
|
-
result.created++;
|
|
1211
|
-
break;
|
|
1212
|
-
case 'UPDATE':
|
|
1213
|
-
result.updated++;
|
|
1214
|
-
break;
|
|
1215
|
-
case 'DELETE':
|
|
1216
|
-
result.deleted++;
|
|
1217
|
-
break;
|
|
1218
|
-
}
|
|
1219
|
-
}
|
|
1220
|
-
result.changes = changes;
|
|
1221
|
-
return result;
|
|
1222
|
-
}
|
|
1223
|
-
const sortedChanges = [...changes].sort((a, b) => {
|
|
1224
|
-
const order = { DELETE: 0, CREATE: 1, UPDATE: 2 };
|
|
1225
|
-
return order[a.type] - order[b.type];
|
|
1226
|
-
});
|
|
1227
|
-
for (const change of sortedChanges) {
|
|
1228
|
-
const absPath = join(tree.root, change.path);
|
|
1229
|
-
try {
|
|
1230
|
-
switch (change.type) {
|
|
1231
|
-
case 'CREATE':
|
|
1232
|
-
case 'UPDATE':
|
|
1233
|
-
/* istanbul ignore if -- content is always defined for CREATE/UPDATE from tree.write() */
|
|
1234
|
-
if (change.content !== undefined) {
|
|
1235
|
-
const dir = dirname(absPath);
|
|
1236
|
-
ensureDir(dir);
|
|
1237
|
-
writeFileSync(absPath, change.content);
|
|
1238
|
-
if (change.mode !== undefined) {
|
|
1239
|
-
chmodSync(absPath, change.mode);
|
|
1240
|
-
}
|
|
1241
|
-
if (change.type === 'CREATE') {
|
|
1242
|
-
result.created++;
|
|
1243
|
-
}
|
|
1244
|
-
else {
|
|
1245
|
-
result.updated++;
|
|
1246
|
-
}
|
|
1247
|
-
}
|
|
1248
|
-
break;
|
|
1249
|
-
case 'DELETE':
|
|
1250
|
-
if (exists(absPath)) {
|
|
1251
|
-
try {
|
|
1252
|
-
unlinkSync(absPath);
|
|
1253
|
-
}
|
|
1254
|
-
catch {
|
|
1255
|
-
rmSync(absPath, { recursive: true });
|
|
1256
|
-
}
|
|
1257
|
-
}
|
|
1258
|
-
result.deleted++;
|
|
1259
|
-
break;
|
|
1260
|
-
}
|
|
1261
|
-
appliedChanges.push(change);
|
|
1262
|
-
if (options?.verbose) {
|
|
1263
|
-
const prefix = change.type === 'CREATE' ? '+' : change.type === 'DELETE' ? '-' : '~';
|
|
1264
|
-
vfsLogger.info(`${prefix} ${change.path}`);
|
|
1265
|
-
}
|
|
1266
|
-
}
|
|
1267
|
-
catch (error) {
|
|
1268
|
-
vfsLogger.error('Commit failed', { path: change.path, type: change.type });
|
|
1269
|
-
const message = error instanceof Error
|
|
1270
|
-
? `Failed to ${change.type.toLowerCase()} ${change.path}: ${error.message}`
|
|
1271
|
-
: `Failed to ${change.type.toLowerCase()} ${change.path}`;
|
|
1272
|
-
throw createError(message);
|
|
1273
|
-
}
|
|
1274
|
-
}
|
|
1275
|
-
result.changes = appliedChanges;
|
|
1276
|
-
tree.clearChanges();
|
|
1277
|
-
return result;
|
|
1278
|
-
}
|
|
1279
|
-
/**
|
|
1280
|
-
* Discard all pending changes.
|
|
1281
|
-
*
|
|
1282
|
-
* @param tree - Virtual file system tree
|
|
1283
|
-
*/
|
|
1284
|
-
function rollbackChanges(tree) {
|
|
1285
|
-
tree.clearChanges();
|
|
1286
|
-
}
|
|
1287
|
-
|
|
1288
|
-
const diffLogger = createScopedLogger('project-scope:vfs:diff');
|
|
1289
|
-
const DEFAULT_CONTEXT_LINES = 3;
|
|
1290
|
-
/**
|
|
1291
|
-
* Compute the Longest Common Subsequence (LCS) table for two arrays of lines.
|
|
1292
|
-
* Uses dynamic programming for O(n*m) time complexity.
|
|
1293
|
-
*
|
|
1294
|
-
* @param oldLines - Lines from the original file version
|
|
1295
|
-
* @param newLines - Lines from the new file version
|
|
1296
|
-
* @returns Two-dimensional LCS table for backtracking
|
|
1297
|
-
*/
|
|
1298
|
-
function computeLcsTable(oldLines, newLines) {
|
|
1299
|
-
const m = oldLines.length;
|
|
1300
|
-
const n = newLines.length;
|
|
1301
|
-
const table = from({ length: m + 1 }, () => Array(n + 1).fill(0));
|
|
1302
|
-
for (let i = 1; i <= m; i++) {
|
|
1303
|
-
for (let j = 1; j <= n; j++) {
|
|
1304
|
-
if (oldLines[i - 1] === newLines[j - 1]) {
|
|
1305
|
-
table[i][j] = table[i - 1][j - 1] + 1;
|
|
1306
|
-
}
|
|
1307
|
-
else {
|
|
1308
|
-
table[i][j] = max(table[i - 1][j], table[i][j - 1]);
|
|
1309
|
-
}
|
|
1310
|
-
}
|
|
1311
|
-
}
|
|
1312
|
-
return table;
|
|
1313
|
-
}
|
|
1314
|
-
/**
|
|
1315
|
-
* Backtrack through LCS table to produce diff operations.
|
|
1316
|
-
*
|
|
1317
|
-
* @param table - Two-dimensional LCS table from computeLcsTable
|
|
1318
|
-
* @param oldLines - Lines from the original file version
|
|
1319
|
-
* @param newLines - Lines from the new file version
|
|
1320
|
-
* @returns Array of diff operations (unfiltered, includes all lines)
|
|
1321
|
-
*/
|
|
1322
|
-
function backtrackLcs(table, oldLines, newLines) {
|
|
1323
|
-
const result = [];
|
|
1324
|
-
let i = oldLines.length;
|
|
1325
|
-
let j = newLines.length;
|
|
1326
|
-
while (i > 0 || j > 0) {
|
|
1327
|
-
if (i > 0 && j > 0 && oldLines[i - 1] === newLines[j - 1]) {
|
|
1328
|
-
result.unshift({ type: 'same', oldIdx: i - 1, newIdx: j - 1, content: oldLines[i - 1] });
|
|
1329
|
-
i--;
|
|
1330
|
-
j--;
|
|
1331
|
-
}
|
|
1332
|
-
else if (j > 0 && (i === 0 || table[i][j - 1] >= table[i - 1][j])) {
|
|
1333
|
-
result.unshift({ type: 'add', oldIdx: i - 1, newIdx: j - 1, content: newLines[j - 1] });
|
|
1334
|
-
j--;
|
|
1335
|
-
}
|
|
1336
|
-
else {
|
|
1337
|
-
result.unshift({ type: 'remove', oldIdx: i - 1, newIdx: -1, content: oldLines[i - 1] });
|
|
1338
|
-
i--;
|
|
1339
|
-
}
|
|
1340
|
-
}
|
|
1341
|
-
return result;
|
|
1342
|
-
}
|
|
1343
|
-
/**
|
|
1344
|
-
* Convert raw diff operations to DiffLine array with context filtering.
|
|
1345
|
-
*
|
|
1346
|
-
* @param operations - Raw diff operations
|
|
1347
|
-
* @param contextLines - Number of context lines to include
|
|
1348
|
-
* @returns Filtered DiffLine array
|
|
1349
|
-
*/
|
|
1350
|
-
function operationsToDiffLines(operations, contextLines) {
|
|
1351
|
-
const include = new Array(operations.length).fill(false);
|
|
1352
|
-
for (let i = 0; i < operations.length; i++) {
|
|
1353
|
-
if (operations[i].type !== 'same') {
|
|
1354
|
-
for (let j = max(0, i - contextLines); j <= min(operations.length - 1, i + contextLines); j++) {
|
|
1355
|
-
include[j] = true;
|
|
1356
|
-
}
|
|
1357
|
-
}
|
|
1358
|
-
}
|
|
1359
|
-
const lines = [];
|
|
1360
|
-
let oldLineNum = 1;
|
|
1361
|
-
let newLineNum = 1;
|
|
1362
|
-
for (let i = 0; i < operations.length; i++) {
|
|
1363
|
-
const op = operations[i];
|
|
1364
|
-
if (include[i]) {
|
|
1365
|
-
if (op.type === 'same') {
|
|
1366
|
-
lines.push({ type: 'context', line: oldLineNum, content: op.content });
|
|
1367
|
-
oldLineNum++;
|
|
1368
|
-
newLineNum++;
|
|
915
|
+
}
|
|
1369
916
|
}
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
oldLineNum++;
|
|
917
|
+
catch {
|
|
918
|
+
// Directory doesn't exist on disk
|
|
1373
919
|
}
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
920
|
+
const prefix = normalPath === '.' || normalPath === '' ? '' : normalPath + '/';
|
|
921
|
+
for (const [changedPath, change] of _changes) {
|
|
922
|
+
if (prefix === '') {
|
|
923
|
+
const childName = changedPath.split('/')[0];
|
|
924
|
+
if (change.type === 'DELETE' && !changedPath.includes('/')) {
|
|
925
|
+
childSet.delete(childName);
|
|
926
|
+
}
|
|
927
|
+
else if (change.type !== 'DELETE') {
|
|
928
|
+
childSet.add(childName);
|
|
929
|
+
}
|
|
930
|
+
continue;
|
|
931
|
+
}
|
|
932
|
+
if (!changedPath.startsWith(prefix)) {
|
|
933
|
+
continue;
|
|
934
|
+
}
|
|
935
|
+
const relativePath = changedPath.slice(prefix.length);
|
|
936
|
+
const childName = relativePath.split('/')[0];
|
|
937
|
+
if (change.type === 'DELETE') {
|
|
938
|
+
if (!relativePath.includes('/')) {
|
|
939
|
+
childSet.delete(childName);
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
else {
|
|
943
|
+
childSet.add(childName);
|
|
944
|
+
}
|
|
1377
945
|
}
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
946
|
+
return from(childSet).sort();
|
|
947
|
+
},
|
|
948
|
+
listChanges() {
|
|
949
|
+
const changes = [];
|
|
950
|
+
for (const [path, record] of _changes) {
|
|
951
|
+
changes.push({
|
|
952
|
+
path,
|
|
953
|
+
type: record.type,
|
|
954
|
+
content: record.content ?? undefined,
|
|
955
|
+
originalContent: record.originalContent ?? undefined,
|
|
956
|
+
mode: record.permissions,
|
|
957
|
+
});
|
|
1383
958
|
}
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
959
|
+
return changes.sort((a, b) => a.path.localeCompare(b.path));
|
|
960
|
+
},
|
|
961
|
+
changePermissions(filePath, mode) {
|
|
962
|
+
const normalPath = normalizeFilePath(filePath);
|
|
963
|
+
if (!this.exists(normalPath)) {
|
|
964
|
+
throw createError(`File not found: ${normalPath}`);
|
|
965
|
+
}
|
|
966
|
+
const existingChange = _changes.get(normalPath);
|
|
967
|
+
if (existingChange) {
|
|
968
|
+
existingChange.permissions = mode;
|
|
1387
969
|
}
|
|
1388
970
|
else {
|
|
1389
|
-
|
|
1390
|
-
|
|
971
|
+
const content = readFromDisk(normalPath);
|
|
972
|
+
_changes.set(normalPath, {
|
|
973
|
+
type: 'UPDATE',
|
|
974
|
+
content,
|
|
975
|
+
originalContent: content,
|
|
976
|
+
permissions: mode,
|
|
977
|
+
});
|
|
1391
978
|
}
|
|
1392
|
-
}
|
|
1393
|
-
|
|
1394
|
-
|
|
979
|
+
},
|
|
980
|
+
changeFile(filePath, transform) {
|
|
981
|
+
const content = this.read(filePath);
|
|
982
|
+
if (content === null) {
|
|
983
|
+
throw createError(`File not found: ${filePath}`);
|
|
984
|
+
}
|
|
985
|
+
const newContent = transform(content);
|
|
986
|
+
this.write(filePath, newContent);
|
|
987
|
+
},
|
|
988
|
+
clearChanges() {
|
|
989
|
+
_changes.clear();
|
|
990
|
+
},
|
|
991
|
+
};
|
|
992
|
+
return tree;
|
|
1395
993
|
}
|
|
994
|
+
|
|
995
|
+
const factoryLogger = createScopedLogger('project-scope:vfs:factory');
|
|
1396
996
|
/**
|
|
1397
|
-
*
|
|
997
|
+
* Create a virtual file system tree.
|
|
1398
998
|
*
|
|
1399
|
-
* @param
|
|
1400
|
-
* @
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
if (!content)
|
|
1404
|
-
return [];
|
|
1405
|
-
const text = content.toString('utf-8');
|
|
1406
|
-
return text.split('\n');
|
|
1407
|
-
}
|
|
1408
|
-
/**
|
|
1409
|
-
* Generate a diff for a single file change.
|
|
999
|
+
* @param root - Root directory path
|
|
1000
|
+
* @param options - Tree creation options
|
|
1001
|
+
* @returns A new Tree instance
|
|
1002
|
+
* @throws {Error} If root doesn't exist or isn't a directory
|
|
1410
1003
|
*
|
|
1411
|
-
* @example
|
|
1004
|
+
* @example Creating a virtual tree
|
|
1412
1005
|
* ```typescript
|
|
1413
|
-
*
|
|
1414
|
-
* path: 'src/app.ts',
|
|
1415
|
-
* type: 'UPDATE',
|
|
1416
|
-
* originalContent: Buffer.from('const x = 1;\n'),
|
|
1417
|
-
* content: Buffer.from('const x = 2;\n'),
|
|
1418
|
-
* }
|
|
1419
|
-
* const diff = generateDiff(change)
|
|
1420
|
-
* // { path: 'src/app.ts', additions: 1, deletions: 1, lines: [...] }
|
|
1421
|
-
* ```
|
|
1006
|
+
* import { createTree } from '@hyperfrontend/project-scope'
|
|
1422
1007
|
*
|
|
1423
|
-
*
|
|
1424
|
-
* @param options - Configuration for diff generation including context lines
|
|
1425
|
-
* @returns FileDiff object
|
|
1426
|
-
*/
|
|
1427
|
-
function generateDiff(change, options = {}) {
|
|
1428
|
-
const contextLines = options.contextLines ?? DEFAULT_CONTEXT_LINES;
|
|
1429
|
-
diffLogger.debug('generateDiff', { path: change.path, type: change.type, contextLines });
|
|
1430
|
-
const oldLines = bufferToLines(change.originalContent);
|
|
1431
|
-
const newLines = bufferToLines(change.content);
|
|
1432
|
-
if (change.type === 'CREATE') {
|
|
1433
|
-
const lines = newLines
|
|
1434
|
-
.filter((line) => line !== '' || newLines.indexOf(line) !== newLines.length - 1 || newLines.length === 1)
|
|
1435
|
-
.map((content, idx) => ({
|
|
1436
|
-
type: 'add',
|
|
1437
|
-
line: idx + 1,
|
|
1438
|
-
content,
|
|
1439
|
-
}));
|
|
1440
|
-
const filteredLines = lines.filter((l, i) => !(i === lines.length - 1 && l.content === '' && lines.length > 1));
|
|
1441
|
-
return {
|
|
1442
|
-
path: change.path,
|
|
1443
|
-
lines: filteredLines,
|
|
1444
|
-
additions: filteredLines.length,
|
|
1445
|
-
deletions: 0,
|
|
1446
|
-
};
|
|
1447
|
-
}
|
|
1448
|
-
if (change.type === 'DELETE') {
|
|
1449
|
-
const lines = oldLines.map((content, idx) => ({
|
|
1450
|
-
type: 'remove',
|
|
1451
|
-
line: idx + 1,
|
|
1452
|
-
content,
|
|
1453
|
-
}));
|
|
1454
|
-
const filteredLines = lines.filter((l, i) => !(i === lines.length - 1 && l.content === '' && lines.length > 1));
|
|
1455
|
-
return {
|
|
1456
|
-
path: change.path,
|
|
1457
|
-
lines: filteredLines,
|
|
1458
|
-
additions: 0,
|
|
1459
|
-
deletions: filteredLines.length,
|
|
1460
|
-
};
|
|
1461
|
-
}
|
|
1462
|
-
const table = computeLcsTable(oldLines, newLines);
|
|
1463
|
-
const operations = backtrackLcs(table, oldLines, newLines);
|
|
1464
|
-
const lines = operationsToDiffLines(operations, contextLines);
|
|
1465
|
-
const additions = lines.filter((l) => l.type === 'add').length;
|
|
1466
|
-
const deletions = lines.filter((l) => l.type === 'remove').length;
|
|
1467
|
-
return {
|
|
1468
|
-
path: change.path,
|
|
1469
|
-
lines,
|
|
1470
|
-
additions,
|
|
1471
|
-
deletions,
|
|
1472
|
-
};
|
|
1473
|
-
}
|
|
1474
|
-
/**
|
|
1475
|
-
* Format a FileDiff as a unified diff string.
|
|
1008
|
+
* const tree = createTree('./my-project')
|
|
1476
1009
|
*
|
|
1477
|
-
*
|
|
1478
|
-
*
|
|
1479
|
-
* const formatted = formatUnifiedDiff(diff)
|
|
1480
|
-
* console.log(formatted)
|
|
1481
|
-
* // --- a/src/app.ts
|
|
1482
|
-
* // +++ b/src/app.ts
|
|
1483
|
-
* // @@ -1,3 +1,3 @@
|
|
1484
|
-
* // const x = 1;
|
|
1485
|
-
* // -const y = 2;
|
|
1486
|
-
* // +const y = 3;
|
|
1487
|
-
* // const z = 4;
|
|
1488
|
-
* ```
|
|
1010
|
+
* // Read files from tree
|
|
1011
|
+
* const content = tree.read('src/index.ts', 'utf-8')
|
|
1489
1012
|
*
|
|
1490
|
-
*
|
|
1491
|
-
*
|
|
1013
|
+
* // Make changes (buffered in memory)
|
|
1014
|
+
* tree.write('src/new-file.ts', 'export const x = 1')
|
|
1015
|
+
*
|
|
1016
|
+
* // List pending changes
|
|
1017
|
+
* console.log(tree.listChanges())
|
|
1018
|
+
* ```
|
|
1492
1019
|
*/
|
|
1493
|
-
function
|
|
1494
|
-
const
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
}
|
|
1500
|
-
const hunks = [];
|
|
1501
|
-
const currentHunk = [];
|
|
1502
|
-
for (const line of diff.lines) {
|
|
1503
|
-
currentHunk.push(line);
|
|
1504
|
-
}
|
|
1505
|
-
if (currentHunk.length > 0) {
|
|
1506
|
-
hunks.push(currentHunk);
|
|
1020
|
+
function createTree(root, options) {
|
|
1021
|
+
const normalizedRoot = normalizePath(root);
|
|
1022
|
+
factoryLogger.debug('createTree', { root: normalizedRoot });
|
|
1023
|
+
if (!exists(normalizedRoot)) {
|
|
1024
|
+
factoryLogger.warn('createTree failed: root does not exist', { root: normalizedRoot });
|
|
1025
|
+
throw createError(`Root directory does not exist: ${normalizedRoot}`);
|
|
1507
1026
|
}
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
const oldStart = hunk.find((l) => l.type === 'context' || l.type === 'remove')?.line ?? 1;
|
|
1512
|
-
const newStart = hunk.find((l) => l.type === 'context' || l.type === 'add')?.line ?? 1;
|
|
1513
|
-
const oldCount = contextAndRemove.length;
|
|
1514
|
-
const newCount = contextAndAdd.length;
|
|
1515
|
-
lines.push(`@@ -${oldStart},${oldCount} +${newStart},${newCount} @@`);
|
|
1516
|
-
for (const line of hunk) {
|
|
1517
|
-
const prefix = line.type === 'add' ? '+' : line.type === 'remove' ? '-' : ' ';
|
|
1518
|
-
lines.push(`${prefix}${line.content}`);
|
|
1519
|
-
}
|
|
1027
|
+
if (!isDirectory(normalizedRoot)) {
|
|
1028
|
+
factoryLogger.warn('createTree failed: root is not a directory', { root: normalizedRoot });
|
|
1029
|
+
throw createError(`Root path is not a directory: ${normalizedRoot}`);
|
|
1520
1030
|
}
|
|
1521
|
-
return
|
|
1031
|
+
return createFsTree(normalizedRoot, options);
|
|
1522
1032
|
}
|
|
1523
1033
|
/**
|
|
1524
|
-
*
|
|
1034
|
+
* Create a tree from disk.
|
|
1035
|
+
*
|
|
1036
|
+
* Convenience alias for createTree.
|
|
1037
|
+
*
|
|
1038
|
+
* @param root - Root directory path
|
|
1039
|
+
* @param options - Tree creation options
|
|
1040
|
+
* @returns A new Tree instance backed by disk
|
|
1525
1041
|
*
|
|
1526
|
-
* @example
|
|
1042
|
+
* @example Creating a tree from disk
|
|
1527
1043
|
* ```typescript
|
|
1528
|
-
*
|
|
1529
|
-
* tree.write('new.txt', 'hello')
|
|
1530
|
-
* tree.delete('old.txt')
|
|
1044
|
+
* import { createTreeFromDisk } from '@hyperfrontend/project-scope'
|
|
1531
1045
|
*
|
|
1532
|
-
* const
|
|
1533
|
-
*
|
|
1534
|
-
* console.log(formatUnifiedDiff(diff))
|
|
1535
|
-
* }
|
|
1046
|
+
* const tree = createTreeFromDisk('/path/to/project', { verbose: true })
|
|
1047
|
+
* const files = tree.children('/src')
|
|
1536
1048
|
* ```
|
|
1537
|
-
*
|
|
1538
|
-
* @param tree - Tree to generate diffs for
|
|
1539
|
-
* @param options - Diff options
|
|
1540
|
-
* @returns Array of FileDiff objects
|
|
1541
1049
|
*/
|
|
1542
|
-
function
|
|
1543
|
-
|
|
1544
|
-
diffLogger.debug('generateAllDiffs', { changeCount: changes.length });
|
|
1545
|
-
return changes.map((change) => generateDiff(change, options));
|
|
1050
|
+
function createTreeFromDisk(root, options) {
|
|
1051
|
+
return createTree(root, options);
|
|
1546
1052
|
}
|
|
1547
1053
|
|
|
1548
1054
|
export { Mode, commitChanges, createFsTree, createTree, createTreeFromDisk, formatUnifiedDiff, generateAllDiffs, generateDiff, rollbackChanges };
|
|
1549
|
-
//# sourceMappingURL=index.esm.js.map
|