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