nuclie 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +516 -0
- package/dist/ai/analyzer.d.ts +29 -0
- package/dist/ai/analyzer.js +202 -0
- package/dist/ai/chat/cli.d.ts +3 -0
- package/dist/ai/chat/cli.js +38 -0
- package/dist/ai/client.d.ts +17 -0
- package/dist/ai/client.js +68 -0
- package/dist/ai/cloud/api.d.ts +28 -0
- package/dist/ai/cloud/api.js +118 -0
- package/dist/ai/cloud/modelSync.d.ts +18 -0
- package/dist/ai/cloud/modelSync.js +104 -0
- package/dist/ai/cloud/telemetry.d.ts +14 -0
- package/dist/ai/cloud/telemetry.js +23 -0
- package/dist/ai/config.d.ts +14 -0
- package/dist/ai/config.js +9 -0
- package/dist/ai/core/errorMemory.d.ts +14 -0
- package/dist/ai/core/errorMemory.js +36 -0
- package/dist/ai/dashboard/cli.d.ts +3 -0
- package/dist/ai/dashboard/cli.js +32 -0
- package/dist/ai/healer/applier.d.ts +9 -0
- package/dist/ai/healer/applier.js +74 -0
- package/dist/ai/healer/cli.d.ts +3 -0
- package/dist/ai/healer/cli.js +57 -0
- package/dist/ai/healer/collector.d.ts +16 -0
- package/dist/ai/healer/collector.js +41 -0
- package/dist/ai/healer/fixer.d.ts +12 -0
- package/dist/ai/healer/fixer.js +40 -0
- package/dist/ai/healer/llm.d.ts +9 -0
- package/dist/ai/healer/llm.js +20 -0
- package/dist/ai/healer/parser.d.ts +16 -0
- package/dist/ai/healer/parser.js +67 -0
- package/dist/ai/learning/evolver.d.ts +8 -0
- package/dist/ai/learning/evolver.js +24 -0
- package/dist/ai/llm/fixGenerator.d.ts +9 -0
- package/dist/ai/llm/fixGenerator.js +21 -0
- package/dist/ai/llm/ollama.d.ts +10 -0
- package/dist/ai/llm/ollama.js +56 -0
- package/dist/ai/local/fixStore.d.ts +19 -0
- package/dist/ai/local/fixStore.js +105 -0
- package/dist/ai/optimizer/analyzer.d.ts +9 -0
- package/dist/ai/optimizer/analyzer.js +65 -0
- package/dist/ai/optimizer/engine.d.ts +16 -0
- package/dist/ai/optimizer/engine.js +51 -0
- package/dist/ai/optimizer/llm.d.ts +8 -0
- package/dist/ai/optimizer/llm.js +14 -0
- package/dist/ai/optimizer/profiler.d.ts +11 -0
- package/dist/ai/optimizer/profiler.js +111 -0
- package/dist/ai/optimizer/rules.d.ts +12 -0
- package/dist/ai/optimizer/rules.js +37 -0
- package/dist/ai/patterns/common.d.ts +8 -0
- package/dist/ai/patterns/common.js +181 -0
- package/dist/ai/reporter/assembler.d.ts +11 -0
- package/dist/ai/reporter/assembler.js +10 -0
- package/dist/ai/reporter/generator.d.ts +4 -0
- package/dist/ai/reporter/generator.js +42 -0
- package/dist/ai/reporter/narrator.d.ts +8 -0
- package/dist/ai/reporter/narrator.js +29 -0
- package/dist/ai/schema.d.ts +104 -0
- package/dist/ai/schema.js +45 -0
- package/dist/ai/telemetry.d.ts +14 -0
- package/dist/ai/telemetry.js +96 -0
- package/dist/audit/a11y.d.ts +5 -0
- package/dist/audit/a11y.js +123 -0
- package/dist/audit/best-practices.d.ts +5 -0
- package/dist/audit/best-practices.js +68 -0
- package/dist/audit/build-integration.d.ts +59 -0
- package/dist/audit/build-integration.js +138 -0
- package/dist/audit/core.d.ts +62 -0
- package/dist/audit/core.js +327 -0
- package/dist/audit/index.d.ts +4 -0
- package/dist/audit/index.js +60 -0
- package/dist/audit/perf.d.ts +5 -0
- package/dist/audit/perf.js +69 -0
- package/dist/audit/seo.d.ts +5 -0
- package/dist/audit/seo.js +63 -0
- package/dist/audit/types.d.ts +35 -0
- package/dist/audit/types.js +1 -0
- package/dist/audit-stub/types.d.ts +25 -0
- package/dist/audit-stub/types.js +1 -0
- package/dist/build/bundle-stats.d.ts +2 -0
- package/dist/build/bundle-stats.js +42 -0
- package/dist/build/bundler.d.ts +46 -0
- package/dist/build/bundler.js +31 -0
- package/dist/build/index.d.ts +36 -0
- package/dist/build/index.js +69 -0
- package/dist/build/pipeline.d.ts +31 -0
- package/dist/build/pipeline.js +68 -0
- package/dist/builder/server.d.ts +11 -0
- package/dist/builder/server.js +253 -0
- package/dist/cache/incremental.d.ts +75 -0
- package/dist/cache/incremental.js +200 -0
- package/dist/cache/index.d.ts +17 -0
- package/dist/cache/index.js +186 -0
- package/dist/cache/rocksdb.d.ts +18 -0
- package/dist/cache/rocksdb.js +63 -0
- package/dist/cli/css-cli.d.ts +5 -0
- package/dist/cli/css-cli.js +112 -0
- package/dist/cli/inspect.d.ts +1 -0
- package/dist/cli/inspect.js +94 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +586 -0
- package/dist/commands/analyze.d.ts +1 -0
- package/dist/commands/analyze.js +295 -0
- package/dist/commands/doctor.d.ts +21 -0
- package/dist/commands/doctor.js +364 -0
- package/dist/commands/ssr.d.ts +12 -0
- package/dist/commands/ssr.js +30 -0
- package/dist/commands/verify.d.ts +38 -0
- package/dist/commands/verify.js +459 -0
- package/dist/config/index.d.ts +145 -0
- package/dist/config/index.js +227 -0
- package/dist/config/live-config.d.ts +22 -0
- package/dist/config/live-config.js +88 -0
- package/dist/core/__tests__/permissions.test.d.ts +1 -0
- package/dist/core/__tests__/permissions.test.js +16 -0
- package/dist/core/__tests__/universal-transformer.test.d.ts +1 -0
- package/dist/core/__tests__/universal-transformer.test.js +27 -0
- package/dist/core/build/globalOptimizer.d.ts +8 -0
- package/dist/core/build/globalOptimizer.js +21 -0
- package/dist/core/build/incremental.d.ts +13 -0
- package/dist/core/build/incremental.js +29 -0
- package/dist/core/bundler-rolldown.d.ts +42 -0
- package/dist/core/bundler-rolldown.js +100 -0
- package/dist/core/cache/lazy-init.d.ts +50 -0
- package/dist/core/cache/lazy-init.js +153 -0
- package/dist/core/cache-manager.d.ts +51 -0
- package/dist/core/cache-manager.js +149 -0
- package/dist/core/css/engine.d.ts +37 -0
- package/dist/core/css/engine.js +113 -0
- package/dist/core/css-framework-detector.d.ts +10 -0
- package/dist/core/css-framework-detector.js +169 -0
- package/dist/core/detection/files.d.ts +2 -0
- package/dist/core/detection/files.js +77 -0
- package/dist/core/detection/index.d.ts +8 -0
- package/dist/core/detection/index.js +39 -0
- package/dist/core/detection/resolver.d.ts +2 -0
- package/dist/core/detection/resolver.js +116 -0
- package/dist/core/detection/scanner.d.ts +4 -0
- package/dist/core/detection/scanner.js +145 -0
- package/dist/core/detection/types.d.ts +33 -0
- package/dist/core/detection/types.js +12 -0
- package/dist/core/engine/cache.d.ts +18 -0
- package/dist/core/engine/cache.js +72 -0
- package/dist/core/engine/config.d.ts +11 -0
- package/dist/core/engine/config.js +158 -0
- package/dist/core/engine/emit.d.ts +8 -0
- package/dist/core/engine/emit.js +60 -0
- package/dist/core/engine/events.d.ts +13 -0
- package/dist/core/engine/events.js +35 -0
- package/dist/core/engine/execute.d.ts +5 -0
- package/dist/core/engine/execute.js +226 -0
- package/dist/core/engine/hash.d.ts +8 -0
- package/dist/core/engine/hash.js +39 -0
- package/dist/core/engine/index.d.ts +49 -0
- package/dist/core/engine/index.js +156 -0
- package/dist/core/engine/optimize.d.ts +2 -0
- package/dist/core/engine/optimize.js +99 -0
- package/dist/core/engine/plan.d.ts +9 -0
- package/dist/core/engine/plan.js +196 -0
- package/dist/core/engine/types.d.ts +120 -0
- package/dist/core/engine/types.js +1 -0
- package/dist/core/errors/hero-errors.d.ts +57 -0
- package/dist/core/errors/hero-errors.js +269 -0
- package/dist/core/framework-detector.d.ts +20 -0
- package/dist/core/framework-detector.js +148 -0
- package/dist/core/graph/js-graph-analyzer.d.ts +51 -0
- package/dist/core/graph/js-graph-analyzer.js +178 -0
- package/dist/core/graph/serializer.d.ts +7 -0
- package/dist/core/graph/serializer.js +24 -0
- package/dist/core/interop/analyze.d.ts +8 -0
- package/dist/core/interop/analyze.js +82 -0
- package/dist/core/interop/analyze_ast.d.ts +9 -0
- package/dist/core/interop/analyze_ast.js +174 -0
- package/dist/core/interop/index.d.ts +19 -0
- package/dist/core/interop/index.js +36 -0
- package/dist/core/interop/resolve.d.ts +9 -0
- package/dist/core/interop/resolve.js +55 -0
- package/dist/core/interop/types.d.ts +28 -0
- package/dist/core/interop/types.js +2 -0
- package/dist/core/interop/wrapper.d.ts +11 -0
- package/dist/core/interop/wrapper.js +50 -0
- package/dist/core/parser-bun.d.ts +54 -0
- package/dist/core/parser-bun.js +86 -0
- package/dist/core/permissions.d.ts +16 -0
- package/dist/core/permissions.js +47 -0
- package/dist/core/pipeline/framework-pipeline.d.ts +71 -0
- package/dist/core/pipeline/framework-pipeline.js +113 -0
- package/dist/core/plugins/index.d.ts +5 -0
- package/dist/core/plugins/index.js +5 -0
- package/dist/core/plugins/manager.d.ts +30 -0
- package/dist/core/plugins/manager.js +123 -0
- package/dist/core/plugins/sandbox_js.d.ts +9 -0
- package/dist/core/plugins/sandbox_js.js +37 -0
- package/dist/core/plugins/sandbox_wasm.d.ts +10 -0
- package/dist/core/plugins/sandbox_wasm.js +68 -0
- package/dist/core/plugins/types.d.ts +37 -0
- package/dist/core/plugins/types.js +2 -0
- package/dist/core/plugins/validation.d.ts +8 -0
- package/dist/core/plugins/validation.js +30 -0
- package/dist/core/sandbox.d.ts +9 -0
- package/dist/core/sandbox.js +79 -0
- package/dist/core/steps/css-optimization.d.ts +65 -0
- package/dist/core/steps/css-optimization.js +318 -0
- package/dist/core/steps.d.ts +7 -0
- package/dist/core/steps.js +17 -0
- package/dist/core/transform/batchTransformer.d.ts +12 -0
- package/dist/core/transform/batchTransformer.js +24 -0
- package/dist/core/transform/transformer.d.ts +9 -0
- package/dist/core/transform/transformer.js +189 -0
- package/dist/core/universal-transformer.d.ts +81 -0
- package/dist/core/universal-transformer.js +780 -0
- package/dist/create/index.d.ts +25 -0
- package/dist/create/index.js +584 -0
- package/dist/create/ui.d.ts +13 -0
- package/dist/create/ui.js +218 -0
- package/dist/create-nuclie/cli.d.ts +7 -0
- package/dist/create-nuclie/cli.js +73 -0
- package/dist/create-nuclie/templates.d.ts +18 -0
- package/dist/create-nuclie/templates.js +73 -0
- package/dist/create-nuclie.d.ts +2 -0
- package/dist/create-nuclie.js +7 -0
- package/dist/dashboard/metrics.d.ts +31 -0
- package/dist/dashboard/metrics.js +59 -0
- package/dist/dashboard/server/router.d.ts +52 -0
- package/dist/dashboard/server/router.js +36 -0
- package/dist/dev/__tests__/preBundler.test.d.ts +1 -0
- package/dist/dev/__tests__/preBundler.test.js +51 -0
- package/dist/dev/configWatcher.d.ts +10 -0
- package/dist/dev/configWatcher.js +42 -0
- package/dist/dev/devServer.d.ts +2 -0
- package/dist/dev/devServer.js +1398 -0
- package/dist/dev/devServer.minimal.d.ts +8 -0
- package/dist/dev/devServer.minimal.js +122 -0
- package/dist/dev/federation-dev.d.ts +14 -0
- package/dist/dev/federation-dev.js +69 -0
- package/dist/dev/hmr-engine.d.ts +12 -0
- package/dist/dev/hmr-engine.js +66 -0
- package/dist/dev/hmr-v2.d.ts +40 -0
- package/dist/dev/hmr-v2.js +87 -0
- package/dist/dev/hmrThrottle.d.ts +13 -0
- package/dist/dev/hmrThrottle.js +56 -0
- package/dist/dev/overlay/overlay-client.d.ts +7 -0
- package/dist/dev/overlay/overlay-client.js +53 -0
- package/dist/dev/overlay/overlay-ui.d.ts +17 -0
- package/dist/dev/overlay/overlay-ui.js +133 -0
- package/dist/dev/preBundler.d.ts +17 -0
- package/dist/dev/preBundler.js +343 -0
- package/dist/dev/statusHandler.d.ts +11 -0
- package/dist/dev/statusHandler.js +44 -0
- package/dist/dev/types.d.ts +30 -0
- package/dist/dev/types.js +1 -0
- package/dist/dev/watcher.d.ts +11 -0
- package/dist/dev/watcher.js +40 -0
- package/dist/dev-server-manual.d.ts +5 -0
- package/dist/dev-server-manual.js +24 -0
- package/dist/dev-server.d.ts +25 -0
- package/dist/dev-server.js +255 -0
- package/dist/env/api.d.ts +27 -0
- package/dist/env/api.js +36 -0
- package/dist/fix/ast-transforms.d.ts +81 -0
- package/dist/fix/ast-transforms.js +449 -0
- package/dist/hmr/classifier.d.ts +51 -0
- package/dist/hmr/classifier.js +232 -0
- package/dist/hmr/index.d.ts +5 -0
- package/dist/hmr/index.js +5 -0
- package/dist/hmr/overlay.d.ts +39 -0
- package/dist/hmr/overlay.js +285 -0
- package/dist/index.d.ts +46 -0
- package/dist/index.js +57 -0
- package/dist/init/bootstrap.d.ts +1 -0
- package/dist/init/bootstrap.js +106 -0
- package/dist/init/index.d.ts +1 -0
- package/dist/init/index.js +74 -0
- package/dist/init/templates.d.ts +2 -0
- package/dist/init/templates.js +227 -0
- package/dist/main.d.ts +1 -0
- package/dist/main.js +3 -0
- package/dist/marketplace/client.d.ts +25 -0
- package/dist/marketplace/client.js +73 -0
- package/dist/marketplace/db.d.ts +24 -0
- package/dist/marketplace/db.js +57 -0
- package/dist/marketplace/plugin-adapter.d.ts +14 -0
- package/dist/marketplace/plugin-adapter.js +85 -0
- package/dist/marketplace/server.d.ts +66 -0
- package/dist/marketplace/server.js +97 -0
- package/dist/meta-frameworks/base-router.d.ts +63 -0
- package/dist/meta-frameworks/base-router.js +259 -0
- package/dist/meta-frameworks/index.d.ts +8 -0
- package/dist/meta-frameworks/index.js +8 -0
- package/dist/meta-frameworks/nextjs/router.d.ts +35 -0
- package/dist/meta-frameworks/nextjs/router.js +176 -0
- package/dist/meta-frameworks/nuxt/router.d.ts +22 -0
- package/dist/meta-frameworks/nuxt/router.js +84 -0
- package/dist/meta-frameworks/remix/router.d.ts +28 -0
- package/dist/meta-frameworks/remix/router.js +136 -0
- package/dist/meta-frameworks/ssr/react-renderer.d.ts +24 -0
- package/dist/meta-frameworks/ssr/react-renderer.js +53 -0
- package/dist/meta-frameworks/ssr/server.d.ts +92 -0
- package/dist/meta-frameworks/ssr/server.js +312 -0
- package/dist/meta-frameworks/ssr/vue-renderer.d.ts +11 -0
- package/dist/meta-frameworks/ssr/vue-renderer.js +35 -0
- package/dist/meta-frameworks/types.d.ts +76 -0
- package/dist/meta-frameworks/types.js +5 -0
- package/dist/migrate/analyzer.d.ts +46 -0
- package/dist/migrate/analyzer.js +254 -0
- package/dist/migrate/cli.d.ts +10 -0
- package/dist/migrate/cli.js +63 -0
- package/dist/migrate/generator.d.ts +32 -0
- package/dist/migrate/generator.js +214 -0
- package/dist/native/cache.d.ts +86 -0
- package/dist/native/cache.js +154 -0
- package/dist/native/index.d.ts +4 -0
- package/dist/native/index.js +56 -0
- package/dist/native/orchestrator.d.ts +78 -0
- package/dist/native/orchestrator.js +107 -0
- package/dist/native/wasm.d.ts +22 -0
- package/dist/native/wasm.js +33 -0
- package/dist/nuclie_native.node +0 -0
- package/dist/plugins/assets.d.ts +2 -0
- package/dist/plugins/assets.js +50 -0
- package/dist/plugins/compat/adapter.d.ts +33 -0
- package/dist/plugins/compat/adapter.js +102 -0
- package/dist/plugins/compat/deferred.d.ts +17 -0
- package/dist/plugins/compat/deferred.js +28 -0
- package/dist/plugins/compat/index.d.ts +11 -0
- package/dist/plugins/compat/index.js +11 -0
- package/dist/plugins/compat/rollup.d.ts +19 -0
- package/dist/plugins/compat/rollup.js +76 -0
- package/dist/plugins/compat/tier-a.d.ts +60 -0
- package/dist/plugins/compat/tier-a.js +132 -0
- package/dist/plugins/compat/tier-b.d.ts +34 -0
- package/dist/plugins/compat/tier-b.js +90 -0
- package/dist/plugins/compat/tier-c.d.ts +48 -0
- package/dist/plugins/compat/tier-c.js +49 -0
- package/dist/plugins/compat/webpack.d.ts +26 -0
- package/dist/plugins/compat/webpack.js +77 -0
- package/dist/plugins/core/linker.d.ts +8 -0
- package/dist/plugins/core/linker.js +51 -0
- package/dist/plugins/css/bootstrap.d.ts +25 -0
- package/dist/plugins/css/bootstrap.js +110 -0
- package/dist/plugins/css/bulma.d.ts +23 -0
- package/dist/plugins/css/bulma.js +75 -0
- package/dist/plugins/css/css-modules.d.ts +19 -0
- package/dist/plugins/css/css-modules.js +96 -0
- package/dist/plugins/css/css-optimizer.d.ts +43 -0
- package/dist/plugins/css/css-optimizer.js +155 -0
- package/dist/plugins/css/emotion.d.ts +35 -0
- package/dist/plugins/css/emotion.js +109 -0
- package/dist/plugins/css/less.d.ts +6 -0
- package/dist/plugins/css/less.js +33 -0
- package/dist/plugins/css/material.d.ts +24 -0
- package/dist/plugins/css/material.js +97 -0
- package/dist/plugins/css/postcss.d.ts +2 -0
- package/dist/plugins/css/postcss.js +96 -0
- package/dist/plugins/css/sass.d.ts +6 -0
- package/dist/plugins/css/sass.js +36 -0
- package/dist/plugins/css/styled-components.d.ts +33 -0
- package/dist/plugins/css/styled-components.js +94 -0
- package/dist/plugins/css/stylus.d.ts +6 -0
- package/dist/plugins/css/stylus.js +41 -0
- package/dist/plugins/css/tailwind.d.ts +9 -0
- package/dist/plugins/css/tailwind.js +132 -0
- package/dist/plugins/css-in-js.d.ts +10 -0
- package/dist/plugins/css-in-js.js +24 -0
- package/dist/plugins/edge.d.ts +7 -0
- package/dist/plugins/edge.js +38 -0
- package/dist/plugins/esbuildAdapter.d.ts +3 -0
- package/dist/plugins/esbuildAdapter.js +77 -0
- package/dist/plugins/federation_next.d.ts +16 -0
- package/dist/plugins/federation_next.js +78 -0
- package/dist/plugins/framework-plugins.d.ts +3 -0
- package/dist/plugins/framework-plugins.js +40 -0
- package/dist/plugins/frameworks/index.d.ts +8 -0
- package/dist/plugins/frameworks/index.js +10 -0
- package/dist/plugins/frameworks/lit.d.ts +36 -0
- package/dist/plugins/frameworks/lit.js +114 -0
- package/dist/plugins/frameworks/react.d.ts +38 -0
- package/dist/plugins/frameworks/react.js +144 -0
- package/dist/plugins/frameworks/solid.d.ts +36 -0
- package/dist/plugins/frameworks/solid.js +108 -0
- package/dist/plugins/frameworks/svelte.d.ts +43 -0
- package/dist/plugins/frameworks/svelte.js +144 -0
- package/dist/plugins/frameworks/vue.d.ts +43 -0
- package/dist/plugins/frameworks/vue.js +240 -0
- package/dist/plugins/governance.d.ts +36 -0
- package/dist/plugins/governance.js +50 -0
- package/dist/plugins/html.d.ts +2 -0
- package/dist/plugins/html.js +49 -0
- package/dist/plugins/implementations/analytics.d.ts +7 -0
- package/dist/plugins/implementations/analytics.js +15 -0
- package/dist/plugins/implementations/apollo.d.ts +7 -0
- package/dist/plugins/implementations/apollo.js +15 -0
- package/dist/plugins/implementations/audit.d.ts +7 -0
- package/dist/plugins/implementations/audit.js +30 -0
- package/dist/plugins/implementations/auto-fix.d.ts +7 -0
- package/dist/plugins/implementations/auto-fix.js +15 -0
- package/dist/plugins/implementations/avif.d.ts +7 -0
- package/dist/plugins/implementations/avif.js +27 -0
- package/dist/plugins/implementations/babel.d.ts +7 -0
- package/dist/plugins/implementations/babel.js +15 -0
- package/dist/plugins/implementations/bundle-analyzer.d.ts +7 -0
- package/dist/plugins/implementations/bundle-analyzer.js +21 -0
- package/dist/plugins/implementations/bundle-size.d.ts +7 -0
- package/dist/plugins/implementations/bundle-size.js +21 -0
- package/dist/plugins/implementations/checker.d.ts +7 -0
- package/dist/plugins/implementations/checker.js +15 -0
- package/dist/plugins/implementations/chromatic.d.ts +7 -0
- package/dist/plugins/implementations/chromatic.js +15 -0
- package/dist/plugins/implementations/cloudflare.d.ts +7 -0
- package/dist/plugins/implementations/cloudflare.js +15 -0
- package/dist/plugins/implementations/code-split.d.ts +7 -0
- package/dist/plugins/implementations/code-split.js +21 -0
- package/dist/plugins/implementations/compression.d.ts +7 -0
- package/dist/plugins/implementations/compression.js +21 -0
- package/dist/plugins/implementations/copy.d.ts +7 -0
- package/dist/plugins/implementations/copy.js +15 -0
- package/dist/plugins/implementations/critical-css.d.ts +7 -0
- package/dist/plugins/implementations/critical-css.js +25 -0
- package/dist/plugins/implementations/crypto-sign.d.ts +7 -0
- package/dist/plugins/implementations/crypto-sign.js +30 -0
- package/dist/plugins/implementations/css-framework.d.ts +7 -0
- package/dist/plugins/implementations/css-framework.js +25 -0
- package/dist/plugins/implementations/css.d.ts +7 -0
- package/dist/plugins/implementations/css.js +25 -0
- package/dist/plugins/implementations/cypress.d.ts +7 -0
- package/dist/plugins/implementations/cypress.js +15 -0
- package/dist/plugins/implementations/determinism.d.ts +7 -0
- package/dist/plugins/implementations/determinism.js +21 -0
- package/dist/plugins/implementations/edge.d.ts +8 -0
- package/dist/plugins/implementations/edge.js +35 -0
- package/dist/plugins/implementations/env-validation.d.ts +7 -0
- package/dist/plugins/implementations/env-validation.js +30 -0
- package/dist/plugins/implementations/eslint.d.ts +7 -0
- package/dist/plugins/implementations/eslint.js +15 -0
- package/dist/plugins/implementations/federation.d.ts +7 -0
- package/dist/plugins/implementations/federation.js +15 -0
- package/dist/plugins/implementations/file.d.ts +7 -0
- package/dist/plugins/implementations/file.js +27 -0
- package/dist/plugins/implementations/font-subset.d.ts +7 -0
- package/dist/plugins/implementations/font-subset.js +27 -0
- package/dist/plugins/implementations/fonts.d.ts +7 -0
- package/dist/plugins/implementations/fonts.js +27 -0
- package/dist/plugins/implementations/formatjs.d.ts +7 -0
- package/dist/plugins/implementations/formatjs.js +18 -0
- package/dist/plugins/implementations/graphql.d.ts +7 -0
- package/dist/plugins/implementations/graphql.js +15 -0
- package/dist/plugins/implementations/hmr-classify.d.ts +7 -0
- package/dist/plugins/implementations/hmr-classify.js +21 -0
- package/dist/plugins/implementations/html.d.ts +7 -0
- package/dist/plugins/implementations/html.js +15 -0
- package/dist/plugins/implementations/i18n.d.ts +7 -0
- package/dist/plugins/implementations/i18n.js +15 -0
- package/dist/plugins/implementations/icon.d.ts +7 -0
- package/dist/plugins/implementations/icon.js +27 -0
- package/dist/plugins/implementations/imagemin.d.ts +7 -0
- package/dist/plugins/implementations/imagemin.js +27 -0
- package/dist/plugins/implementations/inspect.d.ts +7 -0
- package/dist/plugins/implementations/inspect.js +15 -0
- package/dist/plugins/implementations/jest.d.ts +7 -0
- package/dist/plugins/implementations/jest.js +19 -0
- package/dist/plugins/implementations/jotai.d.ts +8 -0
- package/dist/plugins/implementations/jotai.js +35 -0
- package/dist/plugins/implementations/lazy-load.d.ts +7 -0
- package/dist/plugins/implementations/lazy-load.js +21 -0
- package/dist/plugins/implementations/legacy.d.ts +7 -0
- package/dist/plugins/implementations/legacy.js +15 -0
- package/dist/plugins/implementations/lighthouse.d.ts +7 -0
- package/dist/plugins/implementations/lighthouse.js +21 -0
- package/dist/plugins/implementations/manifest.d.ts +7 -0
- package/dist/plugins/implementations/manifest.js +15 -0
- package/dist/plugins/implementations/markdown.d.ts +7 -0
- package/dist/plugins/implementations/markdown.js +15 -0
- package/dist/plugins/implementations/md.d.ts +7 -0
- package/dist/plugins/implementations/md.js +15 -0
- package/dist/plugins/implementations/mdx.d.ts +7 -0
- package/dist/plugins/implementations/mdx.js +15 -0
- package/dist/plugins/implementations/meta-tags.d.ts +7 -0
- package/dist/plugins/implementations/meta-tags.js +15 -0
- package/dist/plugins/implementations/mini-css-extract-plugin.d.ts +7 -0
- package/dist/plugins/implementations/mini-css-extract-plugin.js +25 -0
- package/dist/plugins/implementations/mobx.d.ts +8 -0
- package/dist/plugins/implementations/mobx.js +35 -0
- package/dist/plugins/implementations/mock.d.ts +7 -0
- package/dist/plugins/implementations/mock.js +15 -0
- package/dist/plugins/implementations/msw.d.ts +7 -0
- package/dist/plugins/implementations/msw.js +19 -0
- package/dist/plugins/implementations/nanostores.d.ts +7 -0
- package/dist/plugins/implementations/nanostores.js +18 -0
- package/dist/plugins/implementations/netlify.d.ts +7 -0
- package/dist/plugins/implementations/netlify.js +15 -0
- package/dist/plugins/implementations/observability.d.ts +7 -0
- package/dist/plugins/implementations/observability.js +15 -0
- package/dist/plugins/implementations/og-image.d.ts +7 -0
- package/dist/plugins/implementations/og-image.js +15 -0
- package/dist/plugins/implementations/pages.d.ts +7 -0
- package/dist/plugins/implementations/pages.js +15 -0
- package/dist/plugins/implementations/pinia.d.ts +8 -0
- package/dist/plugins/implementations/pinia.js +35 -0
- package/dist/plugins/implementations/plausible.d.ts +7 -0
- package/dist/plugins/implementations/plausible.js +18 -0
- package/dist/plugins/implementations/playwright.d.ts +7 -0
- package/dist/plugins/implementations/playwright.js +15 -0
- package/dist/plugins/implementations/postcss.d.ts +7 -0
- package/dist/plugins/implementations/postcss.js +25 -0
- package/dist/plugins/implementations/posthog.d.ts +7 -0
- package/dist/plugins/implementations/posthog.js +18 -0
- package/dist/plugins/implementations/prebundle.d.ts +7 -0
- package/dist/plugins/implementations/prebundle.js +21 -0
- package/dist/plugins/implementations/prefetch.d.ts +7 -0
- package/dist/plugins/implementations/prefetch.js +21 -0
- package/dist/plugins/implementations/preload.d.ts +7 -0
- package/dist/plugins/implementations/preload.js +21 -0
- package/dist/plugins/implementations/prisma.d.ts +7 -0
- package/dist/plugins/implementations/prisma.js +15 -0
- package/dist/plugins/implementations/pwa.d.ts +7 -0
- package/dist/plugins/implementations/pwa.js +15 -0
- package/dist/plugins/implementations/qr-code.d.ts +7 -0
- package/dist/plugins/implementations/qr-code.js +19 -0
- package/dist/plugins/implementations/razorpay.d.ts +7 -0
- package/dist/plugins/implementations/razorpay.js +19 -0
- package/dist/plugins/implementations/react-i18next.d.ts +7 -0
- package/dist/plugins/implementations/react-i18next.js +18 -0
- package/dist/plugins/implementations/react-query.d.ts +8 -0
- package/dist/plugins/implementations/react-query.js +35 -0
- package/dist/plugins/implementations/react.d.ts +8 -0
- package/dist/plugins/implementations/react.js +35 -0
- package/dist/plugins/implementations/recoil.d.ts +8 -0
- package/dist/plugins/implementations/recoil.js +35 -0
- package/dist/plugins/implementations/redux.d.ts +8 -0
- package/dist/plugins/implementations/redux.js +35 -0
- package/dist/plugins/implementations/relay.d.ts +7 -0
- package/dist/plugins/implementations/relay.js +15 -0
- package/dist/plugins/implementations/repro.d.ts +7 -0
- package/dist/plugins/implementations/repro.js +15 -0
- package/dist/plugins/implementations/robots.d.ts +7 -0
- package/dist/plugins/implementations/robots.js +15 -0
- package/dist/plugins/implementations/root-cause.d.ts +7 -0
- package/dist/plugins/implementations/root-cause.js +15 -0
- package/dist/plugins/implementations/rss.d.ts +7 -0
- package/dist/plugins/implementations/rss.js +15 -0
- package/dist/plugins/implementations/sass.d.ts +7 -0
- package/dist/plugins/implementations/sass.js +25 -0
- package/dist/plugins/implementations/sentry.d.ts +7 -0
- package/dist/plugins/implementations/sentry.js +15 -0
- package/dist/plugins/implementations/sitemap.d.ts +7 -0
- package/dist/plugins/implementations/sitemap.js +15 -0
- package/dist/plugins/implementations/solid.d.ts +8 -0
- package/dist/plugins/implementations/solid.js +35 -0
- package/dist/plugins/implementations/sprite.d.ts +7 -0
- package/dist/plugins/implementations/sprite.js +27 -0
- package/dist/plugins/implementations/ssr.d.ts +8 -0
- package/dist/plugins/implementations/ssr.js +35 -0
- package/dist/plugins/implementations/storybook.d.ts +7 -0
- package/dist/plugins/implementations/storybook.js +15 -0
- package/dist/plugins/implementations/stripe.d.ts +7 -0
- package/dist/plugins/implementations/stripe.js +19 -0
- package/dist/plugins/implementations/style.d.ts +7 -0
- package/dist/plugins/implementations/style.js +25 -0
- package/dist/plugins/implementations/svelte.d.ts +8 -0
- package/dist/plugins/implementations/svelte.js +35 -0
- package/dist/plugins/implementations/tailwind.d.ts +7 -0
- package/dist/plugins/implementations/tailwind.js +25 -0
- package/dist/plugins/implementations/tanstack-query.d.ts +7 -0
- package/dist/plugins/implementations/tanstack-query.js +18 -0
- package/dist/plugins/implementations/terser.d.ts +7 -0
- package/dist/plugins/implementations/terser.js +21 -0
- package/dist/plugins/implementations/testing-library-react.d.ts +7 -0
- package/dist/plugins/implementations/testing-library-react.js +19 -0
- package/dist/plugins/implementations/testing-library.d.ts +7 -0
- package/dist/plugins/implementations/testing-library.js +15 -0
- package/dist/plugins/implementations/tree-shake.d.ts +7 -0
- package/dist/plugins/implementations/tree-shake.js +21 -0
- package/dist/plugins/implementations/trpc.d.ts +7 -0
- package/dist/plugins/implementations/trpc.js +15 -0
- package/dist/plugins/implementations/ts.d.ts +7 -0
- package/dist/plugins/implementations/ts.js +15 -0
- package/dist/plugins/implementations/typescript.d.ts +7 -0
- package/dist/plugins/implementations/typescript.js +15 -0
- package/dist/plugins/implementations/unocss.d.ts +7 -0
- package/dist/plugins/implementations/unocss.js +25 -0
- package/dist/plugins/implementations/upi-payment.d.ts +7 -0
- package/dist/plugins/implementations/upi-payment.js +19 -0
- package/dist/plugins/implementations/url.d.ts +7 -0
- package/dist/plugins/implementations/url.js +27 -0
- package/dist/plugins/implementations/vercel.d.ts +7 -0
- package/dist/plugins/implementations/vercel.js +15 -0
- package/dist/plugins/implementations/visualizer.d.ts +7 -0
- package/dist/plugins/implementations/visualizer.js +15 -0
- package/dist/plugins/implementations/vite-svg-loader.d.ts +7 -0
- package/dist/plugins/implementations/vite-svg-loader.js +27 -0
- package/dist/plugins/implementations/vitest.d.ts +7 -0
- package/dist/plugins/implementations/vitest.js +15 -0
- package/dist/plugins/implementations/vue-i18n-next.d.ts +7 -0
- package/dist/plugins/implementations/vue-i18n-next.js +18 -0
- package/dist/plugins/implementations/vue-i18n.d.ts +7 -0
- package/dist/plugins/implementations/vue-i18n.js +15 -0
- package/dist/plugins/implementations/vue-layouts.d.ts +8 -0
- package/dist/plugins/implementations/vue-layouts.js +35 -0
- package/dist/plugins/implementations/vue.d.ts +8 -0
- package/dist/plugins/implementations/vue.js +35 -0
- package/dist/plugins/implementations/vuex.d.ts +8 -0
- package/dist/plugins/implementations/vuex.js +35 -0
- package/dist/plugins/implementations/wasm-sandbox.d.ts +7 -0
- package/dist/plugins/implementations/wasm-sandbox.js +30 -0
- package/dist/plugins/implementations/webp.d.ts +7 -0
- package/dist/plugins/implementations/webp.js +27 -0
- package/dist/plugins/implementations/windicss.d.ts +7 -0
- package/dist/plugins/implementations/windicss.js +25 -0
- package/dist/plugins/implementations/workbox.d.ts +7 -0
- package/dist/plugins/implementations/workbox.js +15 -0
- package/dist/plugins/implementations/xstate.d.ts +7 -0
- package/dist/plugins/implementations/xstate.js +18 -0
- package/dist/plugins/implementations/zod.d.ts +7 -0
- package/dist/plugins/implementations/zod.js +15 -0
- package/dist/plugins/implementations/zustand-devtools.d.ts +7 -0
- package/dist/plugins/implementations/zustand-devtools.js +18 -0
- package/dist/plugins/implementations/zustand.d.ts +8 -0
- package/dist/plugins/implementations/zustand.js +35 -0
- package/dist/plugins/index.d.ts +49 -0
- package/dist/plugins/index.js +117 -0
- package/dist/plugins/js-transform.d.ts +2 -0
- package/dist/plugins/js-transform.js +49 -0
- package/dist/plugins/json.d.ts +2 -0
- package/dist/plugins/json.js +34 -0
- package/dist/plugins/pluginWorker.mjs +95 -0
- package/dist/plugins/ported/adapter.d.ts +92 -0
- package/dist/plugins/ported/adapter.js +226 -0
- package/dist/plugins/registry.d.ts +51 -0
- package/dist/plugins/registry.js +151 -0
- package/dist/plugins/reporter.d.ts +5 -0
- package/dist/plugins/reporter.js +47 -0
- package/dist/plugins/samplePlugin.mjs +4 -0
- package/dist/plugins/sandbox.d.ts +12 -0
- package/dist/plugins/sandbox.js +126 -0
- package/dist/plugins/signer.d.ts +53 -0
- package/dist/plugins/signer.js +109 -0
- package/dist/plugins/static.d.ts +2 -0
- package/dist/plugins/static.js +47 -0
- package/dist/plugins/svelte.d.ts +7 -0
- package/dist/plugins/svelte.js +27 -0
- package/dist/plugins/testSandbox.d.ts +1 -0
- package/dist/plugins/testSandbox.js +14 -0
- package/dist/plugins/verify.d.ts +3 -0
- package/dist/plugins/verify.js +113 -0
- package/dist/plugins/vue.d.ts +7 -0
- package/dist/plugins/vue.js +86 -0
- package/dist/plugins/wasm-runtime.d.ts +15 -0
- package/dist/plugins/wasm-runtime.js +33 -0
- package/dist/plugins/wasm.d.ts +5 -0
- package/dist/plugins/wasm.js +44 -0
- package/dist/polyfills/corejs.d.ts +9 -0
- package/dist/polyfills/corejs.js +18 -0
- package/dist/presets/core.d.ts +111 -0
- package/dist/presets/core.js +239 -0
- package/dist/presets/frameworks.d.ts +34 -0
- package/dist/presets/frameworks.js +270 -0
- package/dist/presets/index.d.ts +8 -0
- package/dist/presets/index.js +3 -0
- package/dist/presets/infrastructure.d.ts +2 -0
- package/dist/presets/infrastructure.js +33 -0
- package/dist/presets/spa.d.ts +2 -0
- package/dist/presets/spa.js +15 -0
- package/dist/presets/ssg.d.ts +2 -0
- package/dist/presets/ssg.js +9 -0
- package/dist/presets/ssr.d.ts +2 -0
- package/dist/presets/ssr.js +13 -0
- package/dist/repro/dashboard.d.ts +83 -0
- package/dist/repro/dashboard.js +251 -0
- package/dist/repro/github.d.ts +26 -0
- package/dist/repro/github.js +73 -0
- package/dist/resolve/css-precedence.d.ts +16 -0
- package/dist/resolve/css-precedence.js +56 -0
- package/dist/resolve/graph.d.ts +48 -0
- package/dist/resolve/graph.js +232 -0
- package/dist/resolve/utils.d.ts +13 -0
- package/dist/resolve/utils.js +53 -0
- package/dist/runtime/client.d.ts +9 -0
- package/dist/runtime/client.js +218 -0
- package/dist/runtime/error-overlay.d.ts +15 -0
- package/dist/runtime/error-overlay.js +327 -0
- package/dist/runtime/federation-fallback.d.ts +67 -0
- package/dist/runtime/federation-fallback.js +225 -0
- package/dist/runtime/federation.d.ts +27 -0
- package/dist/runtime/federation.js +210 -0
- package/dist/runtime/federation_runtime.js +90 -0
- package/dist/runtime/hmr-client.d.ts +5 -0
- package/dist/runtime/hmr-client.js +70 -0
- package/dist/security/anomaly.d.ts +41 -0
- package/dist/security/anomaly.js +77 -0
- package/dist/server/security-headers.d.ts +37 -0
- package/dist/server/security-headers.js +110 -0
- package/dist/ssr/adapters/edge.d.ts +12 -0
- package/dist/ssr/adapters/edge.js +26 -0
- package/dist/ssr/adapters/index.d.ts +23 -0
- package/dist/ssr/adapters/index.js +58 -0
- package/dist/ssr/app-router.d.ts +24 -0
- package/dist/ssr/app-router.js +70 -0
- package/dist/ssr/edge/handlers.d.ts +24 -0
- package/dist/ssr/edge/handlers.js +48 -0
- package/dist/ssr/image.d.ts +24 -0
- package/dist/ssr/image.js +38 -0
- package/dist/ssr/isr.d.ts +14 -0
- package/dist/ssr/isr.js +29 -0
- package/dist/ssr/rsc.d.ts +19 -0
- package/dist/ssr/rsc.js +33 -0
- package/dist/ssr/streaming.d.ts +31 -0
- package/dist/ssr/streaming.js +78 -0
- package/dist/ssr/universal-engine.d.ts +36 -0
- package/dist/ssr/universal-engine.js +139 -0
- package/dist/templates/manager.d.ts +28 -0
- package/dist/templates/manager.js +162 -0
- package/dist/templates/starters/angular-spa.d.ts +6 -0
- package/dist/templates/starters/angular-spa.js +149 -0
- package/dist/templates/starters/edge.d.ts +6 -0
- package/dist/templates/starters/edge.js +93 -0
- package/dist/templates/starters/fintech.d.ts +6 -0
- package/dist/templates/starters/fintech.js +211 -0
- package/dist/templates/starters/monorepo.d.ts +6 -0
- package/dist/templates/starters/monorepo.js +133 -0
- package/dist/templates/starters/nextjs-app.d.ts +13 -0
- package/dist/templates/starters/nextjs-app.js +116 -0
- package/dist/templates/starters/preact-spa.d.ts +6 -0
- package/dist/templates/starters/preact-spa.js +97 -0
- package/dist/templates/starters/premium-dashboard.d.ts +6 -0
- package/dist/templates/starters/premium-dashboard.js +762 -0
- package/dist/templates/starters/react-spa.d.ts +6 -0
- package/dist/templates/starters/react-spa.js +152 -0
- package/dist/templates/starters/react-ssr.d.ts +6 -0
- package/dist/templates/starters/react-ssr.js +190 -0
- package/dist/templates/starters/remix-app.d.ts +12 -0
- package/dist/templates/starters/remix-app.js +108 -0
- package/dist/templates/starters/solid-spa.d.ts +6 -0
- package/dist/templates/starters/solid-spa.js +158 -0
- package/dist/templates/starters/svelte-spa.d.ts +6 -0
- package/dist/templates/starters/svelte-spa.js +147 -0
- package/dist/templates/starters/vue-spa.d.ts +6 -0
- package/dist/templates/starters/vue-spa.js +136 -0
- package/dist/test/api.d.ts +58 -0
- package/dist/test/api.js +154 -0
- package/dist/test/coverage.d.ts +1 -0
- package/dist/test/coverage.js +134 -0
- package/dist/test/determinism.d.ts +1 -0
- package/dist/test/determinism.js +122 -0
- package/dist/test/regression.d.ts +1 -0
- package/dist/test/regression.js +30 -0
- package/dist/test/runner.d.ts +1 -0
- package/dist/test/runner.js +159 -0
- package/dist/test-server.d.ts +1 -0
- package/dist/test-server.js +22 -0
- package/dist/ui/terminal-warnings.d.ts +10 -0
- package/dist/ui/terminal-warnings.js +26 -0
- package/dist/ui/types.d.ts +13 -0
- package/dist/ui/types.js +5 -0
- package/dist/ui/warning-detector.d.ts +46 -0
- package/dist/ui/warning-detector.js +178 -0
- package/dist/ui/warning-library.d.ts +51 -0
- package/dist/ui/warning-library.js +283 -0
- package/dist/utils/interactive.d.ts +2 -0
- package/dist/utils/interactive.js +37 -0
- package/dist/utils/logger.d.ts +26 -0
- package/dist/utils/logger.js +130 -0
- package/dist/utils/path-normalize.d.ts +24 -0
- package/dist/utils/path-normalize.js +37 -0
- package/dist/visual/chart-generator.d.ts +11 -0
- package/dist/visual/chart-generator.js +30 -0
- package/dist/visual/client/renderer.d.ts +31 -0
- package/dist/visual/client/renderer.js +98 -0
- package/dist/visual/federation-editor.d.ts +1 -0
- package/dist/visual/federation-editor.js +231 -0
- package/dist/visual/graph-engine.d.ts +38 -0
- package/dist/visual/graph-engine.js +64 -0
- package/dist/visual/graph-ui.d.ts +2 -0
- package/dist/visual/graph-ui.js +119 -0
- package/dist/visual/graph-visualizer.d.ts +69 -0
- package/dist/visual/graph-visualizer.js +282 -0
- package/dist/visual/root-cause.d.ts +83 -0
- package/dist/visual/root-cause.js +265 -0
- package/package.json +169 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export class ShortIdMap {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.map = new Map();
|
|
4
|
+
this.counter = 0;
|
|
5
|
+
}
|
|
6
|
+
get(path, isProduction = true) {
|
|
7
|
+
if (!isProduction)
|
|
8
|
+
return path;
|
|
9
|
+
if (!this.map.has(path)) {
|
|
10
|
+
this.map.set(path, `n${this.counter++}`);
|
|
11
|
+
}
|
|
12
|
+
return this.map.get(path);
|
|
13
|
+
}
|
|
14
|
+
toRuntime() {
|
|
15
|
+
return `const __nuclie_map = ${JSON.stringify(Object.fromEntries(this.map))};`;
|
|
16
|
+
}
|
|
17
|
+
getInverse(shortId) {
|
|
18
|
+
for (const [key, value] of this.map.entries()) {
|
|
19
|
+
if (value === shortId)
|
|
20
|
+
return key;
|
|
21
|
+
}
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ExportMap } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Analyzes source code (via regex/string scan for now, AST later) to determine exports.
|
|
4
|
+
*
|
|
5
|
+
* NOTE: This is a simplified "light" parser for the verification phase.
|
|
6
|
+
* In production (Module 5+), this would use `oxc-parser` or `swc` for full AST.
|
|
7
|
+
*/
|
|
8
|
+
export declare function analyzeExports(content: string, format: 'esm' | 'cjs'): ExportMap;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// Phase 2: Static Export & Live Binding Analysis
|
|
2
|
+
/**
|
|
3
|
+
* Analyzes source code (via regex/string scan for now, AST later) to determine exports.
|
|
4
|
+
*
|
|
5
|
+
* NOTE: This is a simplified "light" parser for the verification phase.
|
|
6
|
+
* In production (Module 5+), this would use `oxc-parser` or `swc` for full AST.
|
|
7
|
+
*/
|
|
8
|
+
export function analyzeExports(content, format) {
|
|
9
|
+
const exports = {
|
|
10
|
+
named: new Set(),
|
|
11
|
+
hasDefault: false,
|
|
12
|
+
isDynamic: false,
|
|
13
|
+
liveBindings: false,
|
|
14
|
+
reexports: {}
|
|
15
|
+
};
|
|
16
|
+
if (format === 'esm') {
|
|
17
|
+
analyzeESM(content, exports);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
analyzeCJS(content, exports);
|
|
21
|
+
}
|
|
22
|
+
// Report simplified findings
|
|
23
|
+
if (exports.named.size > 0 || exports.hasDefault) {
|
|
24
|
+
// explainReporter.report('interop', 'analysis', `Analyzed exports`, { named: exports.named.size, default: exports.hasDefault });
|
|
25
|
+
}
|
|
26
|
+
return exports;
|
|
27
|
+
}
|
|
28
|
+
function analyzeESM(content, map) {
|
|
29
|
+
// 1. Default Export
|
|
30
|
+
if (/export\s+default\s/.test(content)) {
|
|
31
|
+
map.hasDefault = true;
|
|
32
|
+
}
|
|
33
|
+
// 2. Named Exports (const, function, class)
|
|
34
|
+
// regex is naive but sufficient for proof
|
|
35
|
+
const namedRegex = /export\s+(?:const|let|var|function|class)\s+([a-zA-Z0-9_$]+)/g;
|
|
36
|
+
let match;
|
|
37
|
+
while ((match = namedRegex.exec(content)) !== null) {
|
|
38
|
+
map.named.add(match[1]);
|
|
39
|
+
if (match[0].includes('let') || match[0].includes('var')) {
|
|
40
|
+
map.liveBindings = true;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
// 3. Named Export List: export { foo, bar }
|
|
44
|
+
const listRegex = /export\s*\{([^}]+)\}/g;
|
|
45
|
+
while ((match = listRegex.exec(content)) !== null) {
|
|
46
|
+
const body = match[1];
|
|
47
|
+
body.split(',').forEach(part => {
|
|
48
|
+
const name = part.trim().split(/\s+as\s+/)[1] || part.trim();
|
|
49
|
+
if (name)
|
|
50
|
+
map.named.add(name);
|
|
51
|
+
});
|
|
52
|
+
map.liveBindings = true; // export {} can export let/var binding
|
|
53
|
+
}
|
|
54
|
+
// 4. Re-exports: export * from ...
|
|
55
|
+
if (/export\s*\*\s*from/.test(content)) {
|
|
56
|
+
map.isDynamic = true; // '*' is effectively dynamic unless we resolve the other file
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function analyzeCJS(content, map) {
|
|
60
|
+
// 1. module.exports = ...
|
|
61
|
+
if (/module\.exports\s*=\s*/.test(content)) {
|
|
62
|
+
map.hasDefault = true;
|
|
63
|
+
// If assigning object literal, might have named properties too?
|
|
64
|
+
// Simplistic assumption: Default only for now unless we statically analyze object structure.
|
|
65
|
+
// Actually, if it's `module.exports = { foo }`, that's default.foo.
|
|
66
|
+
}
|
|
67
|
+
// 2. exports.foo = ...
|
|
68
|
+
const namedRegex = /exports\.([a-zA-Z0-9_$]+)\s*=/g;
|
|
69
|
+
let match;
|
|
70
|
+
while ((match = namedRegex.exec(content)) !== null) {
|
|
71
|
+
map.named.add(match[1]);
|
|
72
|
+
}
|
|
73
|
+
// 3. Object.defineProperty(exports, ...) - Live bindings!
|
|
74
|
+
if (content.includes('Object.defineProperty') && content.includes('get')) {
|
|
75
|
+
map.liveBindings = true;
|
|
76
|
+
}
|
|
77
|
+
// 4. Dynamic/Re-exports
|
|
78
|
+
if (content.includes('require(')) {
|
|
79
|
+
// CJS is inherently dynamic
|
|
80
|
+
map.isDynamic = true;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ExportMap } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Uses Acorn (ESTree) to analyze exports precisely.
|
|
4
|
+
*
|
|
5
|
+
* Capability Matrix:
|
|
6
|
+
* - ESM: export const, export default, export {}, export *
|
|
7
|
+
* - CJS: module.exports =, exports.foo =, Object.defineProperty(exports)
|
|
8
|
+
*/
|
|
9
|
+
export declare function analyzeExportsAST(content: string, format: 'esm' | 'cjs'): ExportMap;
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { parse } from 'acorn';
|
|
2
|
+
// Phase A: AST-Based Export Analysis
|
|
3
|
+
/**
|
|
4
|
+
* Uses Acorn (ESTree) to analyze exports precisely.
|
|
5
|
+
*
|
|
6
|
+
* Capability Matrix:
|
|
7
|
+
* - ESM: export const, export default, export {}, export *
|
|
8
|
+
* - CJS: module.exports =, exports.foo =, Object.defineProperty(exports)
|
|
9
|
+
*/
|
|
10
|
+
export function analyzeExportsAST(content, format) {
|
|
11
|
+
const exports = {
|
|
12
|
+
named: new Set(),
|
|
13
|
+
hasDefault: false,
|
|
14
|
+
isDynamic: false,
|
|
15
|
+
liveBindings: false,
|
|
16
|
+
reexports: {}
|
|
17
|
+
};
|
|
18
|
+
try {
|
|
19
|
+
// Parse with Acorn
|
|
20
|
+
// We use sourceType: 'module' for ESM, 'script' for CJS (though commonjs is looser)
|
|
21
|
+
const ast = parse(content, {
|
|
22
|
+
ecmaVersion: 'latest',
|
|
23
|
+
sourceType: format === 'esm' ? 'module' : 'script',
|
|
24
|
+
locations: false
|
|
25
|
+
});
|
|
26
|
+
if (format === 'esm') {
|
|
27
|
+
walkESM(ast, exports);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
walkCJS(ast, exports);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
catch (e) {
|
|
34
|
+
// Fallback or error?
|
|
35
|
+
// For interop, syntax error means module is broken anyway.
|
|
36
|
+
// We might fallback to regex or simple detection if it's strange syntax (e.g. flow)
|
|
37
|
+
// console.warn('AST Parse failed, module might rely on unknown syntax', e.message);
|
|
38
|
+
// We leave map empty -> dynamic
|
|
39
|
+
exports.isDynamic = true;
|
|
40
|
+
}
|
|
41
|
+
return exports;
|
|
42
|
+
}
|
|
43
|
+
function walkESM(ast, map) {
|
|
44
|
+
for (const node of ast.body) {
|
|
45
|
+
if (node.type === 'ExportDefaultDeclaration') {
|
|
46
|
+
map.hasDefault = true;
|
|
47
|
+
}
|
|
48
|
+
else if (node.type === 'ExportNamedDeclaration') {
|
|
49
|
+
if (node.declaration) {
|
|
50
|
+
// export const foo = ...
|
|
51
|
+
if (node.declaration.declarations) {
|
|
52
|
+
for (const decl of node.declaration.declarations) {
|
|
53
|
+
if (decl.id.type === 'Identifier') {
|
|
54
|
+
map.named.add(decl.id.name);
|
|
55
|
+
if (node.declaration.kind !== 'const')
|
|
56
|
+
map.liveBindings = true;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
// export function foo() {}
|
|
61
|
+
else if (node.declaration.id) {
|
|
62
|
+
map.named.add(node.declaration.id.name);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (node.specifiers) {
|
|
66
|
+
// export { foo, bar }
|
|
67
|
+
for (const spec of node.specifiers) {
|
|
68
|
+
const exportedName = spec.exported.name;
|
|
69
|
+
map.named.add(exportedName);
|
|
70
|
+
// Identifying if local binding is mutable requires scope analysis.
|
|
71
|
+
// Assume 'live' for safety if re-exporting locals?
|
|
72
|
+
// Actually specifiers map local->export.
|
|
73
|
+
// For now, assume safe.
|
|
74
|
+
map.liveBindings = true; // export {} likely means re-export or live binding
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (node.source) {
|
|
78
|
+
// export { foo } from 'bar'
|
|
79
|
+
// This is a re-export
|
|
80
|
+
// We track it as named? Yes.
|
|
81
|
+
// Also track re-export source
|
|
82
|
+
// map.reexports[...] = ...
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
else if (node.type === 'ExportAllDeclaration') {
|
|
86
|
+
// export * from 'foo'
|
|
87
|
+
map.isDynamic = true;
|
|
88
|
+
if (node.source && node.source.value) {
|
|
89
|
+
map.reexports['*'] = node.source.value;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function walkCJS(ast, map) {
|
|
95
|
+
// Simple walker for generic CJS patterns at top level
|
|
96
|
+
// In CJS, assignments can be nested. A full walk is needed.
|
|
97
|
+
// For MVP/Phase A, we walk specific top-level statements or block statements.
|
|
98
|
+
// We'll implemented a tiny recursive walker since Acorn output is tree
|
|
99
|
+
const visit = (node) => {
|
|
100
|
+
if (!node)
|
|
101
|
+
return;
|
|
102
|
+
// Detect: module.exports = ...
|
|
103
|
+
if (node.type === 'ExpressionStatement' && node.expression.type === 'AssignmentExpression') {
|
|
104
|
+
const left = node.expression.left;
|
|
105
|
+
// module.exports = ...
|
|
106
|
+
if (left.type === 'MemberExpression' &&
|
|
107
|
+
left.object.name === 'module' &&
|
|
108
|
+
left.property.name === 'exports') {
|
|
109
|
+
map.hasDefault = true;
|
|
110
|
+
// If right side is object literal, extract keys?
|
|
111
|
+
if (node.expression.right.type === 'ObjectExpression') {
|
|
112
|
+
node.expression.right.properties.forEach((p) => {
|
|
113
|
+
if (p.key.name)
|
|
114
|
+
map.named.add(p.key.name);
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
// assigning function or dynamic var
|
|
119
|
+
// treat as default, but potentially dynamic named?
|
|
120
|
+
// CJS often does module.exports = function() {}; module.exports.foo = ...
|
|
121
|
+
// So we must continue scanning.
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
// exports.foo = ...
|
|
125
|
+
else if (left.type === 'MemberExpression' &&
|
|
126
|
+
left.object.name === 'exports') {
|
|
127
|
+
if (left.property.name)
|
|
128
|
+
map.named.add(left.property.name);
|
|
129
|
+
}
|
|
130
|
+
// module.exports.foo = ...
|
|
131
|
+
else if (left.type === 'MemberExpression' &&
|
|
132
|
+
left.object.type === 'MemberExpression' &&
|
|
133
|
+
left.object.object.name === 'module' &&
|
|
134
|
+
left.object.property.name === 'exports') {
|
|
135
|
+
if (left.property.name)
|
|
136
|
+
map.named.add(left.property.name);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
// Detect: Object.defineProperty(exports, 'foo', ...)
|
|
140
|
+
if (node.type === 'ExpressionStatement' &&
|
|
141
|
+
node.expression.type === 'CallExpression') {
|
|
142
|
+
const callee = node.expression.callee;
|
|
143
|
+
if (callee.type === 'MemberExpression' &&
|
|
144
|
+
callee.object.name === 'Object' &&
|
|
145
|
+
callee.property.name === 'defineProperty') {
|
|
146
|
+
const args = node.expression.arguments;
|
|
147
|
+
if (args.length >= 3) {
|
|
148
|
+
const target = args[0].name; // exports
|
|
149
|
+
const prop = args[1].value; // 'foo'
|
|
150
|
+
const desc = args[2];
|
|
151
|
+
if ((target === 'exports' || target === 'module.exports') && prop) {
|
|
152
|
+
map.named.add(prop);
|
|
153
|
+
// Check for getter
|
|
154
|
+
const hasGetter = desc.properties?.some((p) => p.key.name === 'get');
|
|
155
|
+
if (hasGetter)
|
|
156
|
+
map.liveBindings = true;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
// Detect: require(...)
|
|
161
|
+
if (callee.name === 'require') {
|
|
162
|
+
map.isDynamic = true;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
// Recurse
|
|
166
|
+
if (node.body) {
|
|
167
|
+
if (Array.isArray(node.body))
|
|
168
|
+
node.body.forEach(visit);
|
|
169
|
+
else
|
|
170
|
+
visit(node.body);
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
ast.body.forEach(visit);
|
|
174
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ExportMap, ModuleFormat } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Interop Engine (ESM/CJS bridging)
|
|
4
|
+
*
|
|
5
|
+
* @internal - This ensures module compatibility. Not for public use.
|
|
6
|
+
*/
|
|
7
|
+
export declare class InteropEngine {
|
|
8
|
+
private rootDir;
|
|
9
|
+
constructor(rootDir: string);
|
|
10
|
+
processModule(filePath: string, pkgJson?: any): Promise<{
|
|
11
|
+
format: ModuleFormat;
|
|
12
|
+
exports: ExportMap;
|
|
13
|
+
wrapper?: string;
|
|
14
|
+
}>;
|
|
15
|
+
}
|
|
16
|
+
export * from './types.js';
|
|
17
|
+
export * from './resolve.js';
|
|
18
|
+
export * from './analyze_ast.js';
|
|
19
|
+
export * from './wrapper.js';
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { detectModuleFormat } from './resolve.js';
|
|
2
|
+
import { analyzeExportsAST } from './analyze_ast.js'; // Use AST now
|
|
3
|
+
import { explainReporter } from '../engine/events.js';
|
|
4
|
+
import fs from 'fs/promises';
|
|
5
|
+
// Phase 10: Main Interop Logic (Upgraded)
|
|
6
|
+
/**
|
|
7
|
+
* Interop Engine (ESM/CJS bridging)
|
|
8
|
+
*
|
|
9
|
+
* @internal - This ensures module compatibility. Not for public use.
|
|
10
|
+
*/
|
|
11
|
+
export class InteropEngine {
|
|
12
|
+
constructor(rootDir) {
|
|
13
|
+
this.rootDir = rootDir;
|
|
14
|
+
}
|
|
15
|
+
async processModule(filePath, pkgJson) {
|
|
16
|
+
// 1. Detect Format
|
|
17
|
+
const format = await detectModuleFormat(filePath, pkgJson);
|
|
18
|
+
explainReporter.report('interop', 'format', `Detected ${format} for ${filePath}`);
|
|
19
|
+
// 2. Analyze Exports (AST)
|
|
20
|
+
let map;
|
|
21
|
+
try {
|
|
22
|
+
const content = await fs.readFile(filePath, 'utf-8');
|
|
23
|
+
map = analyzeExportsAST(content, format === 'unknown' ? 'cjs' : format);
|
|
24
|
+
}
|
|
25
|
+
catch (e) {
|
|
26
|
+
// If file read/parse fails (e.g. JSON or binary), fallback safe defaults
|
|
27
|
+
map = { named: new Set(), hasDefault: true, isDynamic: true, liveBindings: false, reexports: {} };
|
|
28
|
+
}
|
|
29
|
+
return { format, exports: map };
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
// Re-export all for consumption
|
|
33
|
+
export * from './types.js';
|
|
34
|
+
export * from './resolve.js';
|
|
35
|
+
export * from './analyze_ast.js'; // Export AST analyzer
|
|
36
|
+
export * from './wrapper.js';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ModuleFormat, ConditionalExport } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Detects module format based on file extension and package.json 'type'.
|
|
4
|
+
*/
|
|
5
|
+
export declare function detectModuleFormat(filePath: string, pkgJson?: any): Promise<ModuleFormat>;
|
|
6
|
+
/**
|
|
7
|
+
* Resolves conditional exports from package.json based on environment conditions.
|
|
8
|
+
*/
|
|
9
|
+
export declare function resolveConditionalExports(exports: ConditionalExport | undefined, conditions: Set<string>): string | undefined;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
// Phase 1: Module Format & Conditional Export Resolution
|
|
3
|
+
/**
|
|
4
|
+
* Detects module format based on file extension and package.json 'type'.
|
|
5
|
+
*/
|
|
6
|
+
export async function detectModuleFormat(filePath, pkgJson) {
|
|
7
|
+
const ext = path.extname(filePath);
|
|
8
|
+
if (ext === '.mjs')
|
|
9
|
+
return 'esm';
|
|
10
|
+
if (ext === '.cjs')
|
|
11
|
+
return 'cjs';
|
|
12
|
+
if (ext === '.json')
|
|
13
|
+
return 'json';
|
|
14
|
+
if (ext === '.js' || ext === '.jsx' || ext === '.ts' || ext === '.tsx') {
|
|
15
|
+
if (pkgJson && pkgJson.type === 'module')
|
|
16
|
+
return 'esm';
|
|
17
|
+
// Default to CJS for .js unless type: module
|
|
18
|
+
// But for .ts, it is usually treated as ESM source or transpiled to target.
|
|
19
|
+
// For interop purposes, we treat source as ESM usually.
|
|
20
|
+
// Let's rely on package.json for ambiguity.
|
|
21
|
+
return 'cjs';
|
|
22
|
+
}
|
|
23
|
+
return 'unknown';
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Resolves conditional exports from package.json based on environment conditions.
|
|
27
|
+
*/
|
|
28
|
+
export function resolveConditionalExports(exports, conditions) {
|
|
29
|
+
if (!exports)
|
|
30
|
+
return undefined;
|
|
31
|
+
if (typeof exports === 'string') {
|
|
32
|
+
return exports;
|
|
33
|
+
}
|
|
34
|
+
if (Array.isArray(exports)) {
|
|
35
|
+
// Fallback array: return first match
|
|
36
|
+
for (const item of exports) {
|
|
37
|
+
const result = resolveConditionalExports(item, conditions);
|
|
38
|
+
if (result)
|
|
39
|
+
return result;
|
|
40
|
+
}
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
if (typeof exports === 'object') {
|
|
44
|
+
for (const key of Object.keys(exports)) {
|
|
45
|
+
if (conditions.has(key)) {
|
|
46
|
+
return resolveConditionalExports(exports[key], conditions);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
// "default" condition usually last in object keys (or should be checked explicitly if logic requires key order)
|
|
50
|
+
// Node.js specs say object iteration order is not guaranteed for keys strictly,
|
|
51
|
+
// but traditionally we check strict string matching conditions.
|
|
52
|
+
// If "default" is in conditions, it will match.
|
|
53
|
+
}
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export type ModuleFormat = 'esm' | 'cjs' | 'json' | 'unknown';
|
|
2
|
+
export type ExportMap = {
|
|
3
|
+
named: Set<string>;
|
|
4
|
+
hasDefault: boolean;
|
|
5
|
+
isDynamic: boolean;
|
|
6
|
+
liveBindings: boolean;
|
|
7
|
+
reexports: Record<string, string>;
|
|
8
|
+
};
|
|
9
|
+
export type InteropStats = {
|
|
10
|
+
wrappersGenerated: number;
|
|
11
|
+
treeShakeableWrappers: number;
|
|
12
|
+
bytesOverhead: number;
|
|
13
|
+
problematicModules: string[];
|
|
14
|
+
};
|
|
15
|
+
export interface InteropAnalysis {
|
|
16
|
+
format: ModuleFormat;
|
|
17
|
+
exports: ExportMap;
|
|
18
|
+
conditionSelected?: string;
|
|
19
|
+
wrapperContent?: string;
|
|
20
|
+
}
|
|
21
|
+
export type ConditionalExport = string | {
|
|
22
|
+
[condition: string]: ConditionalExport;
|
|
23
|
+
} | ConditionalExport[];
|
|
24
|
+
export interface CanonicalModuleShape {
|
|
25
|
+
namespace: Record<string, any>;
|
|
26
|
+
defaultExport: any;
|
|
27
|
+
liveBindings: boolean;
|
|
28
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ExportMap } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Generates semantic wrapper code to bridge CJS/ESM gap.
|
|
4
|
+
*
|
|
5
|
+
* Rules:
|
|
6
|
+
* - Deterministic output hash
|
|
7
|
+
* - Preserves named exports
|
|
8
|
+
* - Preserves default export
|
|
9
|
+
* - Preserves live bindings (using getters)
|
|
10
|
+
*/
|
|
11
|
+
export declare function generateInteropWrapper(moduleId: string, importPath: string, exports: ExportMap, targetFormat: 'esm' | 'cjs'): string;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// Phase 4: Deterministic Interop Wrapper Generation
|
|
2
|
+
/**
|
|
3
|
+
* Generates semantic wrapper code to bridge CJS/ESM gap.
|
|
4
|
+
*
|
|
5
|
+
* Rules:
|
|
6
|
+
* - Deterministic output hash
|
|
7
|
+
* - Preserves named exports
|
|
8
|
+
* - Preserves default export
|
|
9
|
+
* - Preserves live bindings (using getters)
|
|
10
|
+
*/
|
|
11
|
+
export function generateInteropWrapper(moduleId, importPath, exports, targetFormat) {
|
|
12
|
+
if (targetFormat === 'esm') {
|
|
13
|
+
// Wrap CJS in ESM
|
|
14
|
+
// We assume the underlying CJS module is importable via `import * as cjs from ...` or default import
|
|
15
|
+
// Node's native ESM interop gives us a "default" that is module.exports.
|
|
16
|
+
const lines = [];
|
|
17
|
+
// Import raw
|
|
18
|
+
lines.push(`import cjs from '${importPath}';`);
|
|
19
|
+
// Re-export default
|
|
20
|
+
lines.push(`export default cjs;`);
|
|
21
|
+
// Re-export named
|
|
22
|
+
if (exports.named.size > 0) {
|
|
23
|
+
const names = Array.from(exports.named).sort();
|
|
24
|
+
if (exports.liveBindings) {
|
|
25
|
+
// Use getters for live bindings
|
|
26
|
+
// Actually syntax `export const foo = cjs.foo` is value-copy (dead binding).
|
|
27
|
+
// To proxy live binding, we need: `export var foo; ... update logic` or just getters?
|
|
28
|
+
// ESM exports are live bindings inherently.
|
|
29
|
+
// We can use `export { foo } from ...` doesn't work for CJS default props.
|
|
30
|
+
// Correct approach for maximum compat but NO live binding proxying easily in static ESM wrapper
|
|
31
|
+
// unless we iterate keys.
|
|
32
|
+
// Static named exports:
|
|
33
|
+
names.forEach(name => {
|
|
34
|
+
lines.push(`export const ${name} = cjs.${name};`);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
names.forEach(name => {
|
|
39
|
+
lines.push(`export const ${name} = cjs.${name};`);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
// Determinism: Code is sorted by logic. simple string join.
|
|
44
|
+
return lines.join('\n');
|
|
45
|
+
}
|
|
46
|
+
// Wrap ESM in CJS
|
|
47
|
+
// Not typically needed if target environment handles it, but for bundling to CJS target:
|
|
48
|
+
// `const esm = require(...)`
|
|
49
|
+
return `const esm = require('${importPath}'); module.exports = esm.default || esm;`;
|
|
50
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bun.js Parser & Transformer
|
|
3
|
+
* Day 3: Module 1 - Speed Mastery
|
|
4
|
+
*
|
|
5
|
+
* Provides ultra-fast parsing and transformation using Bun's native API.
|
|
6
|
+
* Falls back to SWC/esbuild if not running in Bun runtime.
|
|
7
|
+
*/
|
|
8
|
+
interface BunTranspilerOptions {
|
|
9
|
+
loader?: 'js' | 'jsx' | 'ts' | 'tsx';
|
|
10
|
+
target?: 'browser' | 'bun' | 'node';
|
|
11
|
+
define?: Record<string, string>;
|
|
12
|
+
exports?: 'auto' | 'default' | 'named';
|
|
13
|
+
platform?: 'browser' | 'bun' | 'node';
|
|
14
|
+
}
|
|
15
|
+
interface BunTranspiler {
|
|
16
|
+
transform(code: string, options?: BunTranspilerOptions): Promise<string>;
|
|
17
|
+
transformSync(code: string, loader?: 'js' | 'jsx' | 'ts' | 'tsx'): string;
|
|
18
|
+
scan(code: string): {
|
|
19
|
+
exports: string[];
|
|
20
|
+
imports: any[];
|
|
21
|
+
};
|
|
22
|
+
scanImports(code: string): any[];
|
|
23
|
+
}
|
|
24
|
+
declare global {
|
|
25
|
+
var Bun: {
|
|
26
|
+
Transpiler: new (options?: BunTranspilerOptions) => BunTranspiler;
|
|
27
|
+
version: string;
|
|
28
|
+
spawn: any;
|
|
29
|
+
write: any;
|
|
30
|
+
file: any;
|
|
31
|
+
} | undefined;
|
|
32
|
+
}
|
|
33
|
+
export declare class BunParser {
|
|
34
|
+
private transpiler;
|
|
35
|
+
private isBunRuntime;
|
|
36
|
+
constructor();
|
|
37
|
+
/**
|
|
38
|
+
* specialized transform for specific loaders
|
|
39
|
+
*/
|
|
40
|
+
transform(code: string, filePath: string, options: {
|
|
41
|
+
isDev: boolean;
|
|
42
|
+
define?: Record<string, string>;
|
|
43
|
+
}): Promise<{
|
|
44
|
+
code: string;
|
|
45
|
+
map?: string;
|
|
46
|
+
}>;
|
|
47
|
+
private getLoader;
|
|
48
|
+
/**
|
|
49
|
+
* Check if we are running in Bun
|
|
50
|
+
*/
|
|
51
|
+
isBun(): boolean;
|
|
52
|
+
}
|
|
53
|
+
export declare const bunParser: BunParser;
|
|
54
|
+
export {};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bun.js Parser & Transformer
|
|
3
|
+
* Day 3: Module 1 - Speed Mastery
|
|
4
|
+
*
|
|
5
|
+
* Provides ultra-fast parsing and transformation using Bun's native API.
|
|
6
|
+
* Falls back to SWC/esbuild if not running in Bun runtime.
|
|
7
|
+
*/
|
|
8
|
+
import * as path from 'path';
|
|
9
|
+
import { log } from '../utils/logger.js';
|
|
10
|
+
export class BunParser {
|
|
11
|
+
constructor() {
|
|
12
|
+
this.transpiler = null;
|
|
13
|
+
this.isBunRuntime = typeof Bun !== 'undefined';
|
|
14
|
+
if (this.isBunRuntime) {
|
|
15
|
+
this.transpiler = new Bun.Transpiler({
|
|
16
|
+
loader: 'tsx', // Default loader, can be overridden per file
|
|
17
|
+
target: 'browser'
|
|
18
|
+
});
|
|
19
|
+
log.info(`🚀 using native Bun parser v${Bun.version}`);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
// Node.js runtime: Use SWC transpiler (built-in dependency)
|
|
23
|
+
// This is the expected behavior for non-Bun runtimes
|
|
24
|
+
log.debug('Node.js runtime detected. Using SWC transpiler.');
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* specialized transform for specific loaders
|
|
29
|
+
*/
|
|
30
|
+
async transform(code, filePath, options) {
|
|
31
|
+
const ext = path.extname(filePath);
|
|
32
|
+
const loader = this.getLoader(ext);
|
|
33
|
+
if (this.isBunRuntime && this.transpiler) {
|
|
34
|
+
try {
|
|
35
|
+
// Use native Bun.transpiler (Ultra fast)
|
|
36
|
+
// Use transformSync for synchronous, faster execution
|
|
37
|
+
// Bun's transpiler.transform() expects (code, loader) not (code, {loader})
|
|
38
|
+
const result = this.transpiler.transformSync(code, loader);
|
|
39
|
+
// Bun transpiler doesn't return source maps directly in transform() yet in all versions
|
|
40
|
+
// newer versions do. Assuming string output for now.
|
|
41
|
+
return { code: result, map: undefined };
|
|
42
|
+
}
|
|
43
|
+
catch (err) {
|
|
44
|
+
log.error(`Bun transform failed for ${filePath}: ${err.message}`);
|
|
45
|
+
throw err;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
// Not running in Bun runtime
|
|
50
|
+
// Per MODULE 1 plan: "Keep SWC as fallback for edge cases"
|
|
51
|
+
// Spawning Bun subprocess is too slow (~10ms per file)
|
|
52
|
+
// Use esbuild directly instead (same as v1.0 fallback)
|
|
53
|
+
const esbuild = await import('esbuild');
|
|
54
|
+
try {
|
|
55
|
+
const result = await esbuild.transform(code, {
|
|
56
|
+
loader: loader,
|
|
57
|
+
target: 'es2020',
|
|
58
|
+
format: 'esm'
|
|
59
|
+
});
|
|
60
|
+
return {
|
|
61
|
+
code: result.code,
|
|
62
|
+
map: result.map
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
catch (err) {
|
|
66
|
+
log.error(`esbuild fallback failed for ${filePath}: ${err.message}`);
|
|
67
|
+
throw err;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
getLoader(ext) {
|
|
72
|
+
switch (ext) {
|
|
73
|
+
case '.ts': return 'ts';
|
|
74
|
+
case '.tsx': return 'tsx';
|
|
75
|
+
case '.jsx': return 'jsx';
|
|
76
|
+
default: return 'js';
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Check if we are running in Bun
|
|
81
|
+
*/
|
|
82
|
+
isBun() {
|
|
83
|
+
return this.isBunRuntime;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
export const bunParser = new BunParser();
|