dd-trace 5.135.0 → 5.137.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/README.md +3 -0
- package/ci/cypress/support.js +2 -1
- package/ci/init.js +2 -22
- package/ci/vitest-no-worker-init-node-setup.mjs +2 -1
- package/ci/vitest-no-worker-init-runner-setup.mjs +2 -1
- package/ci/vitest-no-worker-init-setup.mjs +729 -724
- package/ci/vitest-no-worker-init-v5-setup.mjs +2 -1
- package/ext/exporters.js +0 -1
- package/index.d.ts +105 -5
- package/initialize.mjs +5 -2
- package/package.json +41 -36
- package/packages/datadog-esbuild/index.js +16 -70
- package/packages/datadog-esbuild/src/log.js +2 -29
- package/packages/datadog-instrumentations/src/ai.js +6 -1
- package/packages/datadog-instrumentations/src/aws-lambda.js +88 -0
- package/packages/datadog-instrumentations/src/cucumber.js +5 -2
- package/packages/datadog-instrumentations/src/cypress-config.js +20 -9
- package/packages/datadog-instrumentations/src/elevenlabs/activity.js +114 -0
- package/packages/datadog-instrumentations/src/elevenlabs/audio.js +104 -0
- package/packages/datadog-instrumentations/src/elevenlabs/index.js +288 -0
- package/packages/datadog-instrumentations/src/elevenlabs/session.js +444 -0
- package/packages/datadog-instrumentations/src/graphql.js +20 -17
- package/packages/datadog-instrumentations/src/helpers/bundler-esm-exports.js +582 -0
- package/packages/datadog-instrumentations/src/helpers/bundler-log.js +38 -0
- package/packages/datadog-instrumentations/src/helpers/bundler-transform.js +576 -0
- package/packages/datadog-instrumentations/src/helpers/bundler-utils.js +104 -0
- package/packages/datadog-instrumentations/src/helpers/fetch.js +51 -6
- package/packages/datadog-instrumentations/src/helpers/hook.js +29 -1
- package/packages/datadog-instrumentations/src/helpers/hooks.js +3 -7
- package/packages/datadog-instrumentations/src/helpers/lambda-handler.js +189 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/index.js +8 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentation-registry.js +26 -1
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/async-mutex.js +41 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/elevenlabs.js +25 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/graphql.js +0 -36
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/modelcontextprotocol-client.js +30 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/modelcontextprotocol-server.js +23 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/next.js +61 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/openai-agents-realtime.js +23 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/postgres.js +33 -4
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/trpc.js +148 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/target-patterns.json +80 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/targets.json +23 -3
- package/packages/datadog-instrumentations/src/helpers/rewriter/transforms/postgres.js +122 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/transforms.js +59 -2
- package/packages/datadog-instrumentations/src/ioredis.js +101 -3
- package/packages/datadog-instrumentations/src/microgateway-core.js +1 -2
- package/packages/datadog-instrumentations/src/modelcontextprotocol-client.js +21 -0
- package/packages/datadog-instrumentations/src/modelcontextprotocol-sdk.js +7 -1
- package/packages/datadog-instrumentations/src/modelcontextprotocol-server.js +41 -0
- package/packages/datadog-instrumentations/src/next.js +203 -26
- package/packages/datadog-instrumentations/src/openai-agents-realtime.js +149 -0
- package/packages/datadog-instrumentations/src/openai-realtime/audio-accumulator.js +27 -0
- package/packages/datadog-instrumentations/src/openai-realtime/index.js +17 -6
- package/packages/datadog-instrumentations/src/openai-realtime/server-playback.js +887 -0
- package/packages/datadog-instrumentations/src/openai-realtime/session.js +150 -25
- package/packages/datadog-instrumentations/src/openai-realtime/turns.js +29 -2
- package/packages/datadog-instrumentations/src/otel-sdk-trace.js +11 -9
- package/packages/datadog-instrumentations/src/router.js +35 -12
- package/packages/datadog-instrumentations/src/vitest-main.js +10 -2
- package/packages/datadog-instrumentations/src/webdriverio.js +12 -12
- package/packages/datadog-plugin-async-mutex/src/index.js +50 -0
- package/packages/datadog-plugin-aws-lambda/src/arn.js +41 -0
- package/packages/datadog-plugin-aws-lambda/src/event-type-guards.js +170 -0
- package/packages/datadog-plugin-aws-lambda/src/index.js +106 -0
- package/packages/datadog-plugin-aws-lambda/src/trigger.js +339 -0
- package/packages/datadog-plugin-aws-sdk/src/services/dynamodb.js +7 -0
- package/packages/datadog-plugin-aws-sdk/src/services/kinesis.js +32 -10
- package/packages/datadog-plugin-aws-sdk/src/services/lambda.js +10 -1
- package/packages/datadog-plugin-aws-sdk/src/services/sqs.js +4 -0
- package/packages/datadog-plugin-aws-sdk/src/services/stepfunctions.js +3 -0
- package/packages/datadog-plugin-cypress/src/cypress-plugin.js +50 -13
- package/packages/datadog-plugin-cypress/src/support.mjs +1353 -0
- package/packages/datadog-plugin-elevenlabs/src/index.js +69 -0
- package/packages/datadog-plugin-express/src/code_origin.js +2 -2
- package/packages/datadog-plugin-fastify/src/code_origin.js +2 -2
- package/packages/datadog-plugin-google-cloud-pubsub/src/consumer.js +20 -7
- package/packages/datadog-plugin-google-cloud-pubsub/src/producer.js +21 -52
- package/packages/datadog-plugin-google-cloud-pubsub/src/pubsub-push-subscription.js +11 -2
- package/packages/datadog-plugin-google-cloud-pubsub/src/pubsub-request-context.js +25 -4
- package/packages/datadog-plugin-google-cloud-pubsub/src/resource-names.js +24 -0
- package/packages/datadog-plugin-graphql/src/tools/transforms.js +1 -0
- package/packages/datadog-plugin-http/src/client.js +34 -10
- package/packages/datadog-plugin-http2/src/client.js +40 -14
- package/packages/datadog-plugin-modelcontextprotocol-sdk/src/tracing.js +28 -2
- package/packages/datadog-plugin-modelcontextprotocol-sdk/src/utils.js +1 -0
- package/packages/datadog-plugin-mongodb-core/src/query.js +17 -1
- package/packages/datadog-plugin-next/src/index.js +112 -14
- package/packages/datadog-plugin-postgres/src/index.js +118 -41
- package/packages/datadog-plugin-prisma/src/datadog-tracing-helper.js +5 -3
- package/packages/datadog-plugin-supabase/src/supabase-auth-js-gotrueclient-getuser.js +18 -8
- package/packages/datadog-plugin-supabase/src/supabase-functions-js-functionsclient-invoke.js +49 -13
- package/packages/datadog-plugin-supabase/src/supabase-storage-js-handle-request.js +34 -9
- package/packages/datadog-plugin-trpc/src/index.js +15 -0
- package/packages/datadog-plugin-trpc/src/procedure.js +48 -0
- package/packages/datadog-plugin-trpc/src/request.js +81 -0
- package/packages/datadog-plugin-undici/src/index.js +22 -7
- package/packages/datadog-plugin-vitest/src/index.js +3 -2
- package/packages/datadog-plugin-ws/src/close.js +3 -5
- package/packages/datadog-plugin-ws/src/producer.js +1 -4
- package/packages/datadog-plugin-ws/src/receiver.js +3 -5
- package/packages/datadog-plugin-ws/src/server.js +44 -13
- package/packages/datadog-turbopack/index.js +4 -28
- package/packages/datadog-turbopack/src/loader.js +14 -452
- package/packages/datadog-vite/index.js +537 -0
- package/packages/datadog-vite/src/log.js +5 -0
- package/packages/datadog-webpack/index.js +3 -55
- package/packages/datadog-webpack/src/log.js +2 -29
- package/packages/dd-trace/src/aiguard/evaluation.js +62 -1
- package/packages/dd-trace/src/aiguard/index.js +1 -1
- package/packages/dd-trace/src/aiguard/integrations/index.js +6 -5
- package/packages/dd-trace/src/aiguard/sdk.js +8 -2
- package/packages/dd-trace/src/aiguard/tags.js +2 -0
- package/packages/dd-trace/src/appsec/blocking/index.js +21 -1
- package/packages/dd-trace/src/appsec/channels.js +7 -0
- package/packages/dd-trace/src/appsec/downstream_requests.js +105 -0
- package/packages/dd-trace/src/appsec/graphql.js +89 -7
- package/packages/dd-trace/src/appsec/handlers/auth.js +1 -3
- package/packages/dd-trace/src/appsec/handlers/http-request.js +60 -65
- package/packages/dd-trace/src/appsec/handlers/http-response.js +61 -7
- package/packages/dd-trace/src/appsec/handlers/payments.js +23 -27
- package/packages/dd-trace/src/appsec/index.js +6 -0
- package/packages/dd-trace/src/appsec/lambda.js +17 -17
- package/packages/dd-trace/src/appsec/rasp/command_injection.js +4 -4
- package/packages/dd-trace/src/appsec/rasp/index.js +8 -1
- package/packages/dd-trace/src/appsec/rasp/lfi.js +2 -2
- package/packages/dd-trace/src/appsec/rasp/sql_injection.js +7 -17
- package/packages/dd-trace/src/appsec/rasp/ssrf.js +80 -16
- package/packages/dd-trace/src/appsec/rasp/utils.js +33 -3
- package/packages/dd-trace/src/appsec/recommended.json +1358 -94
- package/packages/dd-trace/src/appsec/reporter.js +9 -0
- package/packages/dd-trace/src/appsec/sdk/set_user.js +3 -3
- package/packages/dd-trace/src/appsec/sdk/track_event.js +4 -4
- package/packages/dd-trace/src/appsec/sdk/user_blocking.js +1 -1
- package/packages/dd-trace/src/appsec/user_tracking.js +6 -8
- package/packages/dd-trace/src/appsec/waf/index.js +65 -6
- package/packages/dd-trace/src/appsec/waf/waf_context_wrapper.js +33 -38
- package/packages/dd-trace/src/appsec/waf/waf_manager.js +18 -2
- package/packages/dd-trace/src/before-exit.js +32 -0
- package/packages/dd-trace/src/bootstrap.js +5 -3
- package/packages/dd-trace/src/ci-visibility/early-flake-detection/get-known-tests.js +15 -2
- package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +12 -34
- package/packages/dd-trace/src/ci-visibility/exporters/git/git_metadata.js +41 -13
- package/packages/dd-trace/src/ci-visibility/exporters/request.js +2 -3
- package/packages/dd-trace/src/ci-visibility/intelligent-test-runner/get-skippable-suites.js +1 -2
- package/packages/dd-trace/src/ci-visibility/requests/get-library-configuration.js +1 -1
- package/packages/dd-trace/src/ci-visibility/telemetry.js +6 -0
- package/packages/dd-trace/src/ci-visibility/test-management/get-test-management-tests.js +1 -1
- package/packages/dd-trace/src/ci-visibility/test-optimization-http-cache-schema.js +9 -134
- package/packages/dd-trace/src/ci-visibility/test-optimization-http-cache.js +11 -156
- package/packages/dd-trace/src/config/config-types.d.ts +3 -0
- package/packages/dd-trace/src/config/defaults.js +5 -0
- package/packages/dd-trace/src/config/generated-config-types.d.ts +46 -4
- package/packages/dd-trace/src/config/index.js +63 -31
- package/packages/dd-trace/src/config/parsers.js +44 -0
- package/packages/dd-trace/src/config/remote-config-layers.js +38 -0
- package/packages/dd-trace/src/config/remote_config.js +2 -1
- package/packages/dd-trace/src/config/supported-configurations.json +172 -10
- package/packages/dd-trace/src/constants.js +1 -0
- package/packages/dd-trace/src/datastreams/fnv.js +27 -0
- package/packages/dd-trace/src/datastreams/pathway.js +113 -28
- package/packages/dd-trace/src/datastreams/processor.js +5 -4
- package/packages/dd-trace/src/debugger/config.js +1 -1
- package/packages/dd-trace/src/debugger/devtools_client/request-options.js +7 -9
- package/packages/dd-trace/src/debugger/devtools_client/send.js +1 -1
- package/packages/dd-trace/src/debugger/devtools_client/state.js +3 -1
- package/packages/dd-trace/src/debugger/devtools_client/tags.js +1 -1
- package/packages/dd-trace/src/debugger/index.js +2 -2
- package/packages/dd-trace/src/debugger/inspect-segment.js +3 -2
- package/packages/dd-trace/src/debugger/pause-duration-histogram.js +6 -2
- package/packages/dd-trace/src/debugger/probe_sampler.js +39 -17
- package/packages/dd-trace/src/debugger/unsupported-runtime.js +2 -0
- package/packages/dd-trace/src/exporter.js +0 -11
- package/packages/dd-trace/src/exporters/common/request.js +81 -48
- package/packages/dd-trace/src/exporters/common/retry.js +12 -7
- package/packages/dd-trace/src/exporters/common/url.js +1 -1
- package/packages/dd-trace/src/git_metadata.js +2 -1
- package/packages/dd-trace/src/id.js +1 -1
- package/packages/dd-trace/src/index.js +6 -3
- package/packages/dd-trace/src/lambda/facade.js +75 -0
- package/packages/dd-trace/src/lambda/handler.js +3 -41
- package/packages/dd-trace/src/lambda/index.js +38 -15
- package/packages/dd-trace/src/lambda/runtime/patch.js +19 -3
- package/packages/dd-trace/src/lambda/wrap.js +44 -0
- package/packages/dd-trace/src/llmobs/constants/tags.js +2 -0
- package/packages/dd-trace/src/llmobs/experiments/experiment.js +10 -5
- package/packages/dd-trace/src/llmobs/plugins/elevenlabs.js +96 -0
- package/packages/dd-trace/src/llmobs/plugins/genai/util.js +19 -6
- package/packages/dd-trace/src/llmobs/plugins/modelcontextprotocol-sdk/index.js +54 -3
- package/packages/dd-trace/src/llmobs/plugins/modelcontextprotocol-sdk/utils.js +81 -1
- package/packages/dd-trace/src/llmobs/plugins/openai/realtime.js +38 -11
- package/packages/dd-trace/src/llmobs/plugins/vertexai.js +10 -2
- package/packages/dd-trace/src/llmobs/sdk.js +19 -0
- package/packages/dd-trace/src/llmobs/span_processor.js +9 -0
- package/packages/dd-trace/src/llmobs/tagger.js +22 -0
- package/packages/dd-trace/src/log/channels.js +4 -0
- package/packages/dd-trace/src/log/writer.js +6 -1
- package/packages/dd-trace/src/openfeature/agentless_configuration_source.js +7 -0
- package/packages/dd-trace/src/openfeature/configuration_source.js +55 -27
- package/packages/dd-trace/src/openfeature/flag-selection.js +152 -0
- package/packages/dd-trace/src/openfeature/flagging_provider.js +19 -1
- package/packages/dd-trace/src/openfeature/writers/base.js +1 -3
- package/packages/dd-trace/src/opentelemetry/logs/index.js +11 -0
- package/packages/dd-trace/src/opentelemetry/logs/otlp_http_log_exporter.js +1 -1
- package/packages/dd-trace/src/opentelemetry/metrics/index.js +7 -1
- package/packages/dd-trace/src/opentelemetry/metrics/otlp_http_metric_exporter.js +1 -1
- package/packages/dd-trace/src/opentelemetry/metrics/otlp_span_stats_exporter.js +4 -1
- package/packages/dd-trace/src/opentelemetry/otlp/otlp_http_exporter_base.js +19 -1
- package/packages/dd-trace/src/opentelemetry/span-ending-hook.js +5 -1
- package/packages/dd-trace/src/opentelemetry/span-helpers.js +6 -1
- package/packages/dd-trace/src/opentelemetry/span.js +2 -2
- package/packages/dd-trace/src/opentelemetry/startup-config.js +174 -0
- package/packages/dd-trace/src/opentelemetry/trace/otlp_http_trace_exporter.js +1 -1
- package/packages/dd-trace/src/opentelemetry/trace/otlp_transformer.js +7 -1
- package/packages/dd-trace/src/opentracing/propagation/tracestate.js +77 -23
- package/packages/dd-trace/src/opentracing/tracer.js +24 -0
- package/packages/dd-trace/src/otel-thread-ctx.js +28 -31
- package/packages/dd-trace/src/plugin_manager.js +34 -7
- package/packages/dd-trace/src/plugins/ci_plugin.js +143 -17
- package/packages/dd-trace/src/plugins/index.js +8 -0
- package/packages/dd-trace/src/plugins/plugin.js +4 -2
- package/packages/dd-trace/src/plugins/tracing.js +1 -1
- package/packages/dd-trace/src/plugins/util/ci.js +52 -1
- package/packages/dd-trace/src/plugins/util/git-cache.js +4 -4
- package/packages/dd-trace/src/plugins/util/git.js +263 -82
- package/packages/dd-trace/src/plugins/util/http-otel-semantics.js +80 -56
- package/packages/dd-trace/src/plugins/util/inferred_proxy.js +12 -4
- package/packages/dd-trace/src/plugins/util/status-validator.js +23 -10
- package/packages/dd-trace/src/plugins/util/tags.js +6 -0
- package/packages/dd-trace/src/plugins/util/test.js +92 -40
- package/packages/dd-trace/src/plugins/util/url.js +18 -7
- package/packages/dd-trace/src/plugins/util/user-provided-git.js +6 -6
- package/packages/dd-trace/src/plugins/util/web.js +65 -10
- package/packages/dd-trace/src/process-tags/index.js +1 -1
- package/packages/dd-trace/src/profiler.js +74 -12
- package/packages/dd-trace/src/profiling/profiler.js +30 -2
- package/packages/dd-trace/src/profiling/profilers/space.js +3 -1
- package/packages/dd-trace/src/profiling/profilers/wall.js +4 -4
- package/packages/dd-trace/src/profiling/remote-config.js +354 -0
- package/packages/dd-trace/src/profiling/runtime-capabilities.js +11 -0
- package/packages/dd-trace/src/profiling/webspan-utils.js +6 -5
- package/packages/dd-trace/src/propagation-hash/index.js +7 -0
- package/packages/dd-trace/src/proxy.js +46 -54
- package/packages/dd-trace/src/span_processor.js +20 -0
- package/packages/dd-trace/src/startup-log.js +8 -6
- package/packages/dd-trace/src/telemetry/metrics.js +2 -1
- package/packages/dd-trace/src/tracer.js +0 -2
- package/packages/dd-trace/src/web-tags-cache.js +8 -9
- package/register.js +2 -1
- package/vendor/dist/@apm-js-collab/code-transformer/LICENSE +489 -0
- package/vendor/dist/@datadog/flagging-core/LICENSE +221 -0
- package/vendor/dist/@datadog/flagging-core/index.js +1 -0
- package/vendor/dist/@datadog/openfeature-node-server/LICENSE +21 -1
- package/vendor/dist/@datadog/openfeature-node-server/rules-based/LICENSE +3 -1
- package/vendor/dist/@datadog/sketches-js/LICENSE +263 -0
- package/vendor/dist/@datadog/source-map/LICENSE +1 -0
- package/vendor/dist/@isaacs/ttlcache/LICENSE +13 -0
- package/vendor/dist/@opentelemetry/core/LICENSE +220 -1
- package/vendor/dist/@opentelemetry/core/index.js +1 -1
- package/vendor/dist/crypto-randomuuid/LICENSE +3 -0
- package/vendor/dist/escape-string-regexp/LICENSE +13 -0
- package/vendor/dist/esquery/LICENSE +2 -0
- package/vendor/dist/https-proxy-agent/LICENSE +80 -1
- package/vendor/dist/istanbul-lib-coverage/LICENSE +2 -0
- package/vendor/dist/jest-docblock/LICENSE +16 -0
- package/vendor/dist/jsonpath-plus/LICENSE +13 -0
- package/vendor/dist/limiter/LICENSE +2 -0
- package/vendor/dist/lodash.sortby/LICENSE +2 -0
- package/vendor/dist/lru-cache/LICENSE +13 -0
- package/vendor/dist/meriyah/LICENSE +13 -0
- package/vendor/dist/module-details-from-path/LICENSE +2 -0
- package/vendor/dist/mutexify/promise/LICENSE +28 -0
- package/vendor/dist/pprof-format/LICENSE +13 -0
- package/vendor/dist/pprof-format/index.js +1 -1
- package/vendor/dist/protobufjs/LICENSE +219 -0
- package/vendor/dist/protobufjs/minimal/LICENSE +219 -0
- package/vendor/dist/proxy-from-env/LICENSE +13 -0
- package/vendor/dist/retry/LICENSE +2 -0
- package/vendor/dist/rfdc/LICENSE +2 -0
- package/vendor/dist/semifies/LICENSE +3 -1
- package/vendor/dist/shell-quote/LICENSE +3 -1
- package/vendor/dist/source-map/LICENSE +1 -0
- package/vendor/dist/source-map/lib/util/LICENSE +1 -0
- package/vendor/dist/tlhunter-sorted-set/LICENSE +2 -0
- package/vendor/dist/ttl-set/LICENSE +28 -0
- package/vite.d.ts +7 -0
- package/vite.js +3 -0
- package/ci/diagnose.js +0 -2215
- package/ci/runbook.md +0 -299
- package/ci/test-optimization-validation/approval-artifacts.js +0 -175
- package/ci/test-optimization-validation/approval.js +0 -386
- package/ci/test-optimization-validation/artifact-id.js +0 -18
- package/ci/test-optimization-validation/blocker-category.js +0 -24
- package/ci/test-optimization-validation/bounded-json.js +0 -120
- package/ci/test-optimization-validation/ci-command-candidate.js +0 -77
- package/ci/test-optimization-validation/ci-discovery.js +0 -192
- package/ci/test-optimization-validation/ci-package-scripts.js +0 -169
- package/ci/test-optimization-validation/ci-remediation.js +0 -283
- package/ci/test-optimization-validation/cli.js +0 -954
- package/ci/test-optimization-validation/command-blocker.js +0 -377
- package/ci/test-optimization-validation/command-output-policy.js +0 -188
- package/ci/test-optimization-validation/command-runner.js +0 -649
- package/ci/test-optimization-validation/environment.js +0 -88
- package/ci/test-optimization-validation/executable-approval.js +0 -47
- package/ci/test-optimization-validation/executable.js +0 -244
- package/ci/test-optimization-validation/execution-lock.js +0 -70
- package/ci/test-optimization-validation/framework-adapters/cucumber-validation.json +0 -3
- package/ci/test-optimization-validation/framework-adapters/cucumber.js +0 -767
- package/ci/test-optimization-validation/framework-adapters/cypress.js +0 -99
- package/ci/test-optimization-validation/framework-adapters/playwright.js +0 -175
- package/ci/test-optimization-validation/framework-adapters/vitest.js +0 -513
- package/ci/test-optimization-validation/generated-file-policy.js +0 -63
- package/ci/test-optimization-validation/generated-files.js +0 -425
- package/ci/test-optimization-validation/generated-test-contract.js +0 -284
- package/ci/test-optimization-validation/generated-verifier.js +0 -235
- package/ci/test-optimization-validation/literal-environment.js +0 -56
- package/ci/test-optimization-validation/literal-glob.js +0 -52
- package/ci/test-optimization-validation/manifest-loader.js +0 -116
- package/ci/test-optimization-validation/manifest-scaffold.js +0 -1276
- package/ci/test-optimization-validation/manifest-schema.js +0 -695
- package/ci/test-optimization-validation/offline-fixtures.js +0 -335
- package/ci/test-optimization-validation/offline-output.js +0 -406
- package/ci/test-optimization-validation/package-check.js +0 -97
- package/ci/test-optimization-validation/payload-normalizer.js +0 -72
- package/ci/test-optimization-validation/plan-writer.js +0 -541
- package/ci/test-optimization-validation/preflight-runner.js +0 -186
- package/ci/test-optimization-validation/project-build-artifact.js +0 -31
- package/ci/test-optimization-validation/redaction.js +0 -319
- package/ci/test-optimization-validation/report-writer.js +0 -666
- package/ci/test-optimization-validation/result-semantics.js +0 -103
- package/ci/test-optimization-validation/runner-command.js +0 -264
- package/ci/test-optimization-validation/runner-contract.js +0 -695
- package/ci/test-optimization-validation/safe-files.js +0 -202
- package/ci/test-optimization-validation/scenarios/auto-test-retries.js +0 -171
- package/ci/test-optimization-validation/scenarios/basic-reporting.js +0 -407
- package/ci/test-optimization-validation/scenarios/ci-wiring.js +0 -666
- package/ci/test-optimization-validation/scenarios/early-flake-detection.js +0 -142
- package/ci/test-optimization-validation/scenarios/helpers.js +0 -621
- package/ci/test-optimization-validation/scenarios/test-management.js +0 -219
- package/ci/test-optimization-validation/source-text.js +0 -84
- package/ci/test-optimization-validation/static-diagnosis.js +0 -166
- package/ci/test-optimization-validation/test-output.js +0 -120
- package/ci/test-optimization-validation/validation-blocker.js +0 -21
- package/ci/validate-test-optimization.js +0 -3
- package/packages/datadog-esbuild/src/resolver.js +0 -284
- package/packages/datadog-esbuild/src/utils.js +0 -318
- package/packages/datadog-plugin-cypress/src/support.js +0 -1348
- package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/index.js +0 -156
- package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/msgpack-to-json.js +0 -287
- package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/payload-projection.js +0 -84
- package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/sink.js +0 -368
- package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/writer.js +0 -59
|
@@ -1,35 +1,10 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const fs = require('node:fs')
|
|
4
|
-
const Module = require('node:module')
|
|
5
|
-
const path = require('node:path')
|
|
6
4
|
|
|
7
|
-
const
|
|
8
|
-
'../../datadog-instrumentations/src/helpers/extract-package-and-module-path'
|
|
9
|
-
)
|
|
10
|
-
const hooks = require('../../datadog-instrumentations/src/helpers/hooks')
|
|
11
|
-
const instrumentations = require('../../datadog-instrumentations/src/helpers/instrumentations')
|
|
12
|
-
const { filename, matchesInstrumentation } = require('../../datadog-instrumentations/src/helpers/instrumentation-utils')
|
|
13
|
-
const { createBundlerRewriter } = require('../../datadog-instrumentations/src/helpers/rewriter')
|
|
14
|
-
const {
|
|
15
|
-
getRewriteTarget,
|
|
16
|
-
getRewriteTargetNames,
|
|
17
|
-
} = require('../../datadog-instrumentations/src/helpers/rewriter/targets')
|
|
18
|
-
const { isESMFile } = require('../../datadog-esbuild/src/utils')
|
|
5
|
+
const { instrument } = require('../../datadog-instrumentations/src/helpers/bundler-transform')
|
|
19
6
|
const { SYNTHETIC_EXTENSION } = require('./constants')
|
|
20
7
|
|
|
21
|
-
const CHANNEL = 'dd-trace:bundler:load'
|
|
22
|
-
const ARGUMENTS_BINDING = 1
|
|
23
|
-
const MODULE_BINDING = 2
|
|
24
|
-
const REQUIRE_BINDING = 4
|
|
25
|
-
const COMMONJS_BINDINGS = MODULE_BINDING | REQUIRE_BINDING
|
|
26
|
-
const targetPackages = new Set(Object.keys(hooks))
|
|
27
|
-
for (const name of getRewriteTargetNames()) targetPackages.add(name)
|
|
28
|
-
const entrypoints = new Map()
|
|
29
|
-
const loadedHooks = new Set()
|
|
30
|
-
const packageCache = new Map()
|
|
31
|
-
const rewriters = new Map()
|
|
32
|
-
|
|
33
8
|
/**
|
|
34
9
|
* @typedef {object} LoaderContext
|
|
35
10
|
* @property {(error: Error|undefined, code?: string, sourceMap?: string|object) => void} callback
|
|
@@ -37,16 +12,6 @@ const rewriters = new Map()
|
|
|
37
12
|
* @property {string} resourcePath
|
|
38
13
|
*/
|
|
39
14
|
|
|
40
|
-
/**
|
|
41
|
-
* @typedef {object} PackageInfo
|
|
42
|
-
* @property {string} [entrypoint]
|
|
43
|
-
* @property {boolean} esm
|
|
44
|
-
* @property {string} moduleName
|
|
45
|
-
* @property {string} name
|
|
46
|
-
* @property {string} packageJsonPath
|
|
47
|
-
* @property {string} version
|
|
48
|
-
*/
|
|
49
|
-
|
|
50
15
|
/**
|
|
51
16
|
* Instruments a resolved foreign Node.js module.
|
|
52
17
|
*
|
|
@@ -55,71 +20,22 @@ const rewriters = new Map()
|
|
|
55
20
|
* @param {string|object} [inputSourceMap]
|
|
56
21
|
*/
|
|
57
22
|
module.exports = function loader (source, inputSourceMap) {
|
|
23
|
+
let result
|
|
58
24
|
try {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
this.
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const rewriteTarget = getRewriteTarget(resourcePath)
|
|
68
|
-
const packageInfo = getPackageInfo(
|
|
69
|
-
nativeResourcePath,
|
|
70
|
-
extracted.pkg,
|
|
71
|
-
/** @type {string} */ (extracted.path),
|
|
72
|
-
path.normalize(/** @type {string} */ (extracted.pkgJson))
|
|
73
|
-
)
|
|
74
|
-
const esm = packageInfo.esm
|
|
75
|
-
const publications = esm ? [] : getPublications(resourcePath, packageInfo)
|
|
76
|
-
if (!rewriteTarget && publications.length === 0) {
|
|
77
|
-
this.callback(undefined, source, inputSourceMap)
|
|
78
|
-
return
|
|
79
|
-
}
|
|
80
|
-
if (publications.length > 0 && hasUnsafeCommonJsBindings(source)) {
|
|
81
|
-
this.emitWarning?.(new Error(`Skipped CommonJS publication for unsafe wrapper bindings in ${resourcePath}`))
|
|
82
|
-
this.callback(undefined, source, inputSourceMap)
|
|
83
|
-
return
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const dcModule = relativeImport(path.dirname(nativeResourcePath), require.resolve('dc-polyfill'))
|
|
87
|
-
let code = source
|
|
88
|
-
let sourceMap = inputSourceMap
|
|
89
|
-
let rewritten = false
|
|
90
|
-
if (rewriteTarget) {
|
|
91
|
-
const rewrite = getRewriter(dcModule)
|
|
92
|
-
const result = rewrite(
|
|
93
|
-
source,
|
|
94
|
-
resourcePath,
|
|
95
|
-
esm ? 'module' : 'commonjs',
|
|
96
|
-
rewriteTarget,
|
|
97
|
-
inputSourceMap
|
|
98
|
-
)
|
|
99
|
-
code = /** @type {string} */ (result.code)
|
|
100
|
-
sourceMap = result.map
|
|
101
|
-
rewritten = code !== source
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
if (publications.length > 0) code = appendCommonJsPublications(code, publications, dcModule)
|
|
105
|
-
if (rewritten && publications.length === 0 && (rewriteTarget.activate || hooks[rewriteTarget.moduleName])) {
|
|
106
|
-
if (!esm && hasUnsafeCommonJsBindings(code)) {
|
|
107
|
-
this.emitWarning?.(new Error(`Skipped CommonJS activation for unsafe wrapper bindings in ${resourcePath}`))
|
|
108
|
-
this.callback(undefined, source, inputSourceMap)
|
|
109
|
-
return
|
|
110
|
-
}
|
|
111
|
-
code = appendActivation(code, {
|
|
112
|
-
package: rewriteTarget.moduleName,
|
|
113
|
-
path: filename(rewriteTarget.moduleName, rewriteTarget.filePath),
|
|
114
|
-
version: packageInfo.version,
|
|
115
|
-
}, dcModule, esm)
|
|
116
|
-
}
|
|
117
|
-
this.callback(undefined, code, sourceMap)
|
|
25
|
+
result = instrument({
|
|
26
|
+
source,
|
|
27
|
+
resourcePath: getResourcePath(this),
|
|
28
|
+
inputSourceMap,
|
|
29
|
+
warn: this.emitWarning?.bind(this),
|
|
30
|
+
})
|
|
118
31
|
} catch (error) {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
32
|
+
try {
|
|
33
|
+
this.emitWarning?.(error instanceof Error ? error : new Error(String(error)))
|
|
34
|
+
} catch {
|
|
35
|
+
// A warning must not prevent the loader from returning the original source.
|
|
36
|
+
}
|
|
122
37
|
}
|
|
38
|
+
this.callback(undefined, result?.code ?? source, result ? result.map : inputSourceMap)
|
|
123
39
|
}
|
|
124
40
|
|
|
125
41
|
/**
|
|
@@ -132,357 +48,3 @@ function getResourcePath (context) {
|
|
|
132
48
|
const extensionlessPath = resourcePath.slice(0, -SYNTHETIC_EXTENSION.length)
|
|
133
49
|
return fs.existsSync(extensionlessPath) ? extensionlessPath : resourcePath
|
|
134
50
|
}
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* @param {string} nativeResourcePath
|
|
138
|
-
* @param {string} name
|
|
139
|
-
* @param {string} modulePath
|
|
140
|
-
* @param {string} packageJsonPath
|
|
141
|
-
* @returns {PackageInfo}
|
|
142
|
-
*/
|
|
143
|
-
function getPackageInfo (nativeResourcePath, name, modulePath, packageJsonPath) {
|
|
144
|
-
let cached = packageCache.get(packageJsonPath)
|
|
145
|
-
if (!cached) {
|
|
146
|
-
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'))
|
|
147
|
-
cached = { packageJson, version: packageJson.version }
|
|
148
|
-
packageCache.set(packageJsonPath, cached)
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
return {
|
|
152
|
-
esm: isESMFile(nativeResourcePath, packageJsonPath, cached.packageJson),
|
|
153
|
-
moduleName: filename(name, modulePath),
|
|
154
|
-
name,
|
|
155
|
-
packageJsonPath,
|
|
156
|
-
version: cached.version,
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* @param {string} resourcePath
|
|
162
|
-
* @param {PackageInfo} packageInfo
|
|
163
|
-
* @returns {Array<{ package: string, path: string, version: string }>}
|
|
164
|
-
*/
|
|
165
|
-
function getPublications (resourcePath, packageInfo) {
|
|
166
|
-
loadPackageHook(packageInfo.name)
|
|
167
|
-
const entries = instrumentations[packageInfo.name]
|
|
168
|
-
if (!entries) return []
|
|
169
|
-
|
|
170
|
-
const publications = []
|
|
171
|
-
const paths = new Set()
|
|
172
|
-
for (const entry of entries) {
|
|
173
|
-
if (!entry.file && !entry.filePattern) {
|
|
174
|
-
packageInfo.entrypoint ??= getCommonJsEntrypoint(packageInfo.name, packageInfo.packageJsonPath)
|
|
175
|
-
}
|
|
176
|
-
const moduleName = entry.file || entry.filePattern
|
|
177
|
-
? packageInfo.moduleName
|
|
178
|
-
: resourcePath === packageInfo.entrypoint ? packageInfo.name : undefined
|
|
179
|
-
if (!moduleName || paths.has(moduleName) ||
|
|
180
|
-
!matchesInstrumentation(packageInfo.name, packageInfo.version, moduleName, entry)) continue
|
|
181
|
-
|
|
182
|
-
paths.add(moduleName)
|
|
183
|
-
publications.push({ package: packageInfo.name, path: moduleName, version: packageInfo.version })
|
|
184
|
-
}
|
|
185
|
-
return publications
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* @param {string} name
|
|
190
|
-
* @param {string} packageJsonPath
|
|
191
|
-
*/
|
|
192
|
-
function getCommonJsEntrypoint (name, packageJsonPath) {
|
|
193
|
-
const cached = entrypoints.get(packageJsonPath)
|
|
194
|
-
if (cached) return cached
|
|
195
|
-
|
|
196
|
-
const packageRequire = Module.createRequire(packageJsonPath)
|
|
197
|
-
let entrypoint
|
|
198
|
-
try {
|
|
199
|
-
entrypoint = packageRequire.resolve(name)
|
|
200
|
-
} catch {
|
|
201
|
-
entrypoint = packageRequire.resolve(path.dirname(packageJsonPath))
|
|
202
|
-
}
|
|
203
|
-
const resolved = fs.realpathSync(entrypoint).replaceAll('\\', '/')
|
|
204
|
-
entrypoints.set(packageJsonPath, resolved)
|
|
205
|
-
return resolved
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
/**
|
|
209
|
-
* @param {string} name
|
|
210
|
-
*/
|
|
211
|
-
function loadPackageHook (name) {
|
|
212
|
-
if (loadedHooks.has(name)) return
|
|
213
|
-
const hook = hooks[name]
|
|
214
|
-
const load = hook?.fn ?? hook
|
|
215
|
-
if (typeof load === 'function') load()
|
|
216
|
-
loadedHooks.add(name)
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
/**
|
|
220
|
-
* @param {string} dcModule
|
|
221
|
-
* @returns {ReturnType<typeof createBundlerRewriter>}
|
|
222
|
-
*/
|
|
223
|
-
function getRewriter (dcModule) {
|
|
224
|
-
const cached = rewriters.get(dcModule)
|
|
225
|
-
if (cached) return cached
|
|
226
|
-
const rewrite = createBundlerRewriter(dcModule)
|
|
227
|
-
rewriters.set(dcModule, rewrite)
|
|
228
|
-
return rewrite
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
/**
|
|
232
|
-
* @param {string} source
|
|
233
|
-
*/
|
|
234
|
-
function hasUnsafeCommonJsBindings (source) {
|
|
235
|
-
try {
|
|
236
|
-
const { parse } = require('../../datadog-instrumentations/src/helpers/rewriter/compiler')
|
|
237
|
-
if (source.startsWith('#!')) source = `//${source.slice(2)}`
|
|
238
|
-
const program = parse(Module.wrap(source))
|
|
239
|
-
const wrapper = program.body[0]?.expression
|
|
240
|
-
return wrapper?.type !== 'FunctionExpression' || hasUnsafeNode(wrapper.body, 0, 0)
|
|
241
|
-
} catch {
|
|
242
|
-
return true
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
/**
|
|
247
|
-
* @param {object} node
|
|
248
|
-
* @param {number} functionDepth
|
|
249
|
-
* @param {number} shadowedBindings
|
|
250
|
-
* @param {object} [parent]
|
|
251
|
-
* @param {string} [parentKey]
|
|
252
|
-
*/
|
|
253
|
-
function hasUnsafeNode (node, functionDepth, shadowedBindings, parent, parentKey) {
|
|
254
|
-
if (functionDepth === 0 && hasCommonJsDeclaration(node, parent)) return true
|
|
255
|
-
if (node.type === 'AssignmentExpression' && mutatesCommonJsBinding(node.left, shadowedBindings)) return true
|
|
256
|
-
if (node.type === 'UpdateExpression' && mutatesCommonJsBinding(node.argument, shadowedBindings)) return true
|
|
257
|
-
if ((node.type === 'ForInStatement' || node.type === 'ForOfStatement') &&
|
|
258
|
-
mutatesCommonJsBinding(node.left, shadowedBindings)) return true
|
|
259
|
-
if (node.type === 'CallExpression' && node.callee?.type === 'Identifier' && node.callee.name === 'eval') return true
|
|
260
|
-
if (!(shadowedBindings & ARGUMENTS_BINDING) && node.type === 'Identifier' && node.name === 'arguments' &&
|
|
261
|
-
isReferencedIdentifier(parent, parentKey)) return true
|
|
262
|
-
|
|
263
|
-
const nestedFunction = node.type === 'ArrowFunctionExpression' || node.type === 'FunctionDeclaration' ||
|
|
264
|
-
node.type === 'FunctionExpression'
|
|
265
|
-
if (nestedFunction) {
|
|
266
|
-
functionDepth++
|
|
267
|
-
shadowedBindings |= getFunctionBindings(node)
|
|
268
|
-
}
|
|
269
|
-
shadowedBindings |= getLexicalBindings(node)
|
|
270
|
-
|
|
271
|
-
for (const key of Object.keys(node)) {
|
|
272
|
-
if ((node.type === 'VariableDeclarator' && key === 'id') ||
|
|
273
|
-
(node.type === 'CatchClause' && key === 'param')) continue
|
|
274
|
-
const value = node[key]
|
|
275
|
-
if (Array.isArray(value)) {
|
|
276
|
-
for (const child of value) {
|
|
277
|
-
if (child?.type && hasUnsafeNode(child, functionDepth, shadowedBindings, node, key)) return true
|
|
278
|
-
}
|
|
279
|
-
} else if (value?.type && hasUnsafeNode(value, functionDepth, shadowedBindings, node, key)) {
|
|
280
|
-
return true
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
return false
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
/**
|
|
287
|
-
* @param {object} node
|
|
288
|
-
* @param {object} [parent]
|
|
289
|
-
*/
|
|
290
|
-
function hasCommonJsDeclaration (node, parent) {
|
|
291
|
-
if (node.type === 'VariableDeclarator') {
|
|
292
|
-
return parent?.kind === 'var' && Boolean(getBindingMask(node.id) & COMMONJS_BINDINGS)
|
|
293
|
-
}
|
|
294
|
-
if (node.type === 'FunctionDeclaration') {
|
|
295
|
-
return Boolean(getBindingMask(node.id) & COMMONJS_BINDINGS)
|
|
296
|
-
}
|
|
297
|
-
return false
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
/**
|
|
301
|
-
* @param {object} node
|
|
302
|
-
* @param {number} shadowedBindings
|
|
303
|
-
*/
|
|
304
|
-
function mutatesCommonJsBinding (node, shadowedBindings) {
|
|
305
|
-
return Boolean(getBindingMask(node) & COMMONJS_BINDINGS & ~shadowedBindings)
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
/**
|
|
309
|
-
* @param {object} node
|
|
310
|
-
*/
|
|
311
|
-
function getBindingMask (node) {
|
|
312
|
-
if (!node) return 0
|
|
313
|
-
if (node.type === 'Identifier') {
|
|
314
|
-
if (node.name === 'arguments') return ARGUMENTS_BINDING
|
|
315
|
-
if (node.name === 'module') return MODULE_BINDING
|
|
316
|
-
return node.name === 'require' ? REQUIRE_BINDING : 0
|
|
317
|
-
}
|
|
318
|
-
if (node.type === 'AssignmentPattern') return getBindingMask(node.left)
|
|
319
|
-
if (node.type === 'RestElement') return getBindingMask(node.argument)
|
|
320
|
-
if (node.type === 'ArrayPattern') {
|
|
321
|
-
let bindings = 0
|
|
322
|
-
for (const element of node.elements) bindings |= getBindingMask(element)
|
|
323
|
-
return bindings
|
|
324
|
-
}
|
|
325
|
-
if (node.type === 'ObjectPattern') {
|
|
326
|
-
let bindings = 0
|
|
327
|
-
for (const property of node.properties) {
|
|
328
|
-
bindings |= getBindingMask(property.type === 'RestElement' ? property.argument : property.value)
|
|
329
|
-
}
|
|
330
|
-
return bindings
|
|
331
|
-
}
|
|
332
|
-
return 0
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
/**
|
|
336
|
-
* @param {object} node
|
|
337
|
-
*/
|
|
338
|
-
function getFunctionBindings (node) {
|
|
339
|
-
let bindings = node.type === 'ArrowFunctionExpression' ? 0 : ARGUMENTS_BINDING
|
|
340
|
-
bindings |= getBindingMask(node.id)
|
|
341
|
-
for (const param of node.params) bindings |= getBindingMask(param)
|
|
342
|
-
return bindings | getVarBindings(node.body)
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
/**
|
|
346
|
-
* @param {object} node
|
|
347
|
-
*/
|
|
348
|
-
function getVarBindings (node) {
|
|
349
|
-
if (node.type === 'ArrowFunctionExpression' || node.type === 'FunctionDeclaration' ||
|
|
350
|
-
node.type === 'FunctionExpression' || node.type === 'ClassDeclaration' || node.type === 'ClassExpression') return 0
|
|
351
|
-
|
|
352
|
-
let bindings = 0
|
|
353
|
-
if (node.type === 'VariableDeclaration' && node.kind === 'var') {
|
|
354
|
-
for (const declaration of node.declarations) bindings |= getBindingMask(declaration.id)
|
|
355
|
-
}
|
|
356
|
-
for (const key of Object.keys(node)) {
|
|
357
|
-
const value = node[key]
|
|
358
|
-
if (Array.isArray(value)) {
|
|
359
|
-
for (const child of value) {
|
|
360
|
-
if (child?.type) bindings |= getVarBindings(child)
|
|
361
|
-
}
|
|
362
|
-
} else if (value?.type) {
|
|
363
|
-
bindings |= getVarBindings(value)
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
return bindings
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
/**
|
|
370
|
-
* @param {object} node
|
|
371
|
-
*/
|
|
372
|
-
function getLexicalBindings (node) {
|
|
373
|
-
let bindings = 0
|
|
374
|
-
if (node.type === 'BlockStatement') {
|
|
375
|
-
for (const statement of node.body) bindings |= getStatementBindings(statement)
|
|
376
|
-
} else if (node.type === 'SwitchStatement') {
|
|
377
|
-
for (const switchCase of node.cases) {
|
|
378
|
-
for (const statement of switchCase.consequent) bindings |= getStatementBindings(statement)
|
|
379
|
-
}
|
|
380
|
-
} else if (node.type === 'CatchClause') {
|
|
381
|
-
bindings = getBindingMask(node.param)
|
|
382
|
-
} else if (node.type === 'ForStatement') {
|
|
383
|
-
bindings = getLexicalDeclarationBindings(node.init)
|
|
384
|
-
} else if (node.type === 'ForInStatement' || node.type === 'ForOfStatement') {
|
|
385
|
-
bindings = getLexicalDeclarationBindings(node.left)
|
|
386
|
-
} else if (node.type === 'ClassExpression') {
|
|
387
|
-
bindings = getBindingMask(node.id)
|
|
388
|
-
}
|
|
389
|
-
return bindings
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
/**
|
|
393
|
-
* @param {object} node
|
|
394
|
-
*/
|
|
395
|
-
function getStatementBindings (node) {
|
|
396
|
-
if (node.type === 'VariableDeclaration') return getLexicalDeclarationBindings(node)
|
|
397
|
-
if (node.type === 'FunctionDeclaration' || node.type === 'ClassDeclaration') return getBindingMask(node.id)
|
|
398
|
-
return 0
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
/**
|
|
402
|
-
* @param {object} [node]
|
|
403
|
-
*/
|
|
404
|
-
function getLexicalDeclarationBindings (node) {
|
|
405
|
-
if (node?.type !== 'VariableDeclaration' || node.kind === 'var') return 0
|
|
406
|
-
let bindings = 0
|
|
407
|
-
for (const declaration of node.declarations) bindings |= getBindingMask(declaration.id)
|
|
408
|
-
return bindings
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
/**
|
|
412
|
-
* @param {object} parent
|
|
413
|
-
* @param {string} parentKey
|
|
414
|
-
*/
|
|
415
|
-
function isReferencedIdentifier (parent, parentKey) {
|
|
416
|
-
if (parent.type === 'MemberExpression' && parentKey === 'property' && !parent.computed) return false
|
|
417
|
-
if ((parent.type === 'Property' || parent.type === 'MethodDefinition' || parent.type === 'PropertyDefinition') &&
|
|
418
|
-
parentKey === 'key' && !parent.computed) {
|
|
419
|
-
return parent.type === 'Property' && parent.shorthand
|
|
420
|
-
}
|
|
421
|
-
return parentKey !== 'label'
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
/**
|
|
425
|
-
* @param {string} source
|
|
426
|
-
* @param {Array<{ package: string, path: string, version: string }>} payloads
|
|
427
|
-
* @param {string} dcModule
|
|
428
|
-
*/
|
|
429
|
-
function appendCommonJsPublications (source, payloads, dcModule) {
|
|
430
|
-
let publications = ''
|
|
431
|
-
let index = 0
|
|
432
|
-
for (const payload of payloads) {
|
|
433
|
-
publications += ` const payload${index} = {
|
|
434
|
-
module: module.exports,
|
|
435
|
-
package: ${JSON.stringify(payload.package)},
|
|
436
|
-
path: ${JSON.stringify(payload.path)},
|
|
437
|
-
version: ${JSON.stringify(payload.version)},
|
|
438
|
-
}
|
|
439
|
-
channel.publish(payload${index})
|
|
440
|
-
module.exports = payload${index++}.module
|
|
441
|
-
`
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
return `${source}
|
|
445
|
-
{
|
|
446
|
-
const dc = require(${JSON.stringify(dcModule)})
|
|
447
|
-
const channel = dc.channel('${CHANNEL}')
|
|
448
|
-
if (channel.hasSubscribers) {
|
|
449
|
-
${publications} }
|
|
450
|
-
}
|
|
451
|
-
`
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
/**
|
|
455
|
-
* @param {string} source
|
|
456
|
-
* @param {{ package: string, path: string, version: string }} payload
|
|
457
|
-
* @param {string} dcModule
|
|
458
|
-
* @param {boolean} esm
|
|
459
|
-
*/
|
|
460
|
-
function appendActivation (source, payload, dcModule, esm) {
|
|
461
|
-
if (esm) {
|
|
462
|
-
return `${source}
|
|
463
|
-
import ddTraceTurbopackDc from ${JSON.stringify(dcModule)}
|
|
464
|
-
{
|
|
465
|
-
const channel = ddTraceTurbopackDc.channel('${CHANNEL}')
|
|
466
|
-
if (channel.hasSubscribers) channel.publish(${JSON.stringify({ activate: true, ...payload })})
|
|
467
|
-
}
|
|
468
|
-
`
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
return `${source}
|
|
472
|
-
{
|
|
473
|
-
const dc = require(${JSON.stringify(dcModule)})
|
|
474
|
-
const channel = dc.channel('${CHANNEL}')
|
|
475
|
-
if (channel.hasSubscribers) channel.publish(${JSON.stringify({ activate: true, ...payload })})
|
|
476
|
-
}
|
|
477
|
-
`
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
/**
|
|
481
|
-
* @param {string} from
|
|
482
|
-
* @param {string} to
|
|
483
|
-
*/
|
|
484
|
-
function relativeImport (from, to) {
|
|
485
|
-
let value = path.relative(from, to).replaceAll('\\', '/')
|
|
486
|
-
if (!value.startsWith('.')) value = `./${value}`
|
|
487
|
-
return value
|
|
488
|
-
}
|