dd-trace 6.24.0 → 6.26.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,284 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const childProcess = require('node:child_process')
|
|
4
|
-
const readline = require('node:readline')
|
|
5
|
-
|
|
6
|
-
const { getEnvironmentVariables } = require('../../dd-trace/src/config/helper')
|
|
7
|
-
|
|
8
|
-
const MAX_PENDING_REQUESTS = 1024
|
|
9
|
-
const MAX_STDERR_LENGTH = 16 * 1024
|
|
10
|
-
const LOAD_OPERATION = 0
|
|
11
|
-
const RESOLVE_OPERATION = 1
|
|
12
|
-
const RESOLVER_SOURCE = String.raw`
|
|
13
|
-
import { createReadStream, createWriteStream } from 'node:fs'
|
|
14
|
-
import readline from 'node:readline'
|
|
15
|
-
|
|
16
|
-
const requests = createReadStream(null, { fd: 3, autoClose: false })
|
|
17
|
-
const responses = createWriteStream(null, { fd: 4, autoClose: false })
|
|
18
|
-
const lines = readline.createInterface({ input: requests })
|
|
19
|
-
|
|
20
|
-
for await (const line of lines) {
|
|
21
|
-
let request
|
|
22
|
-
try {
|
|
23
|
-
request = JSON.parse(line)
|
|
24
|
-
const url = await import.meta.resolve(request.specifier, request.parentURL)
|
|
25
|
-
responses.write(JSON.stringify({ id: request.id, url }) + '\n')
|
|
26
|
-
} catch (error) {
|
|
27
|
-
responses.write(JSON.stringify({
|
|
28
|
-
error: {
|
|
29
|
-
code: error?.code,
|
|
30
|
-
message: String(error?.message ?? error),
|
|
31
|
-
},
|
|
32
|
-
id: request?.id,
|
|
33
|
-
}) + '\n')
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
responses.end()
|
|
37
|
-
`
|
|
38
|
-
|
|
39
|
-
/** @typedef {{ specifier: string, parentURL: string }} StarReexport */
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* @typedef {{ exportNames: Iterable<string>, starReexports?: StarReexport[] }} ModuleExports
|
|
43
|
-
*/
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* @typedef {Set<string>|ModuleExports} GetExportsValue
|
|
47
|
-
*/
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* @typedef {[typeof LOAD_OPERATION, URL, object] | [typeof RESOLVE_OPERATION, string, object]} GetExportsOperation
|
|
51
|
-
*/
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* @typedef {{ done: false, value: GetExportsOperation } | { done: true, value: GetExportsValue }} GetExportsResult
|
|
55
|
-
*/
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* @typedef {{
|
|
59
|
-
* next: (value?: unknown) => GetExportsResult,
|
|
60
|
-
* throw: (error?: unknown) => GetExportsResult,
|
|
61
|
-
* }} GetExportsGenerator
|
|
62
|
-
*/
|
|
63
|
-
|
|
64
|
-
class EsmResolver {
|
|
65
|
-
#child
|
|
66
|
-
#closed = false
|
|
67
|
-
#closedPromise
|
|
68
|
-
#failure
|
|
69
|
-
#nextId = 0
|
|
70
|
-
#pending = new Map()
|
|
71
|
-
#readline
|
|
72
|
-
#rejectClosed
|
|
73
|
-
#request
|
|
74
|
-
#resolveClosed
|
|
75
|
-
#stderr = ''
|
|
76
|
-
|
|
77
|
-
constructor () {
|
|
78
|
-
this.#closedPromise = new Promise((resolve, reject) => {
|
|
79
|
-
this.#resolveClosed = resolve
|
|
80
|
-
this.#rejectClosed = reject
|
|
81
|
-
})
|
|
82
|
-
// Mark lifecycle failures handled immediately. close() still returns the original promise.
|
|
83
|
-
this.#closedPromise.catch(() => {})
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* @param {string} specifier
|
|
88
|
-
* @param {URL|string} parentURL
|
|
89
|
-
* @returns {Promise<string>}
|
|
90
|
-
*/
|
|
91
|
-
resolve (specifier, parentURL) {
|
|
92
|
-
if (this.#closed) return Promise.reject(this.#failure ?? new Error('The ESM resolver is closed'))
|
|
93
|
-
if (this.#pending.size >= MAX_PENDING_REQUESTS) {
|
|
94
|
-
return Promise.reject(new Error(`The ESM resolver has more than ${MAX_PENDING_REQUESTS} pending requests`))
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
try {
|
|
98
|
-
this.#start()
|
|
99
|
-
} catch (error) {
|
|
100
|
-
this.#failure = error
|
|
101
|
-
this.#closed = true
|
|
102
|
-
this.#resolveClosed()
|
|
103
|
-
return Promise.reject(error)
|
|
104
|
-
}
|
|
105
|
-
const id = this.#nextId++
|
|
106
|
-
return new Promise((resolve, reject) => {
|
|
107
|
-
this.#pending.set(id, { reject, resolve })
|
|
108
|
-
this.#request.write(`${JSON.stringify({ id, parentURL: String(parentURL), specifier })}\n`, error => {
|
|
109
|
-
if (error) this.#rejectRequest(id, error)
|
|
110
|
-
})
|
|
111
|
-
})
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/** @returns {Promise<void>} */
|
|
115
|
-
close () {
|
|
116
|
-
if (!this.#closed) {
|
|
117
|
-
this.#closed = true
|
|
118
|
-
if (this.#child) this.#request.end()
|
|
119
|
-
else this.#resolveClosed()
|
|
120
|
-
}
|
|
121
|
-
return this.#closedPromise
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
#start () {
|
|
125
|
-
if (this.#child) return
|
|
126
|
-
const env = getEnvironmentVariables()
|
|
127
|
-
env.DD_CIVISIBILITY_ENABLED = 'false'
|
|
128
|
-
env.DD_INSTRUMENTATION_TELEMETRY_ENABLED = 'false'
|
|
129
|
-
env.DD_TRACE_ENABLED = 'false'
|
|
130
|
-
this.#child = childProcess.spawn(process.execPath, [
|
|
131
|
-
'--no-warnings',
|
|
132
|
-
'--experimental-import-meta-resolve',
|
|
133
|
-
'--input-type=module',
|
|
134
|
-
'--eval',
|
|
135
|
-
RESOLVER_SOURCE,
|
|
136
|
-
], {
|
|
137
|
-
env,
|
|
138
|
-
stdio: ['ignore', 'ignore', 'pipe', 'pipe', 'pipe'],
|
|
139
|
-
})
|
|
140
|
-
this.#request = this.#child.stdio[3]
|
|
141
|
-
this.#readline = readline.createInterface({ input: this.#child.stdio[4] })
|
|
142
|
-
this.#readline.on('line', this.#handleLine)
|
|
143
|
-
this.#request.once('error', this.#handleError)
|
|
144
|
-
this.#child.stdio[4].once('error', this.#handleError)
|
|
145
|
-
this.#child.stderr.on('data', this.#handleStderr)
|
|
146
|
-
this.#child.once('error', this.#handleError)
|
|
147
|
-
this.#child.once('close', this.#handleClose)
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/** @param {string} line */
|
|
151
|
-
#handleLine = (line) => {
|
|
152
|
-
let response
|
|
153
|
-
try {
|
|
154
|
-
response = JSON.parse(line)
|
|
155
|
-
} catch (error) {
|
|
156
|
-
this.#fail(new Error(`The ESM resolver returned malformed JSON: ${error.message}`))
|
|
157
|
-
return
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
const id = response?.id
|
|
161
|
-
if (!Number.isSafeInteger(id) || !this.#pending.has(id)) {
|
|
162
|
-
this.#fail(new Error('The ESM resolver returned an unknown request identifier'))
|
|
163
|
-
return
|
|
164
|
-
}
|
|
165
|
-
if (typeof response.url === 'string' && response.error === undefined) {
|
|
166
|
-
const request = this.#pending.get(id)
|
|
167
|
-
this.#pending.delete(id)
|
|
168
|
-
request.resolve(response.url)
|
|
169
|
-
return
|
|
170
|
-
}
|
|
171
|
-
if (typeof response.error?.message !== 'string' || response.url !== undefined) {
|
|
172
|
-
this.#rejectRequest(id, new Error('The ESM resolver returned a malformed response'))
|
|
173
|
-
return
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
const error = /** @type {Error & { code?: string }} */ (new Error(response.error.message))
|
|
177
|
-
if (typeof response.error.code === 'string') error.code = response.error.code
|
|
178
|
-
this.#rejectRequest(id, error)
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
/** @param {Buffer|string} chunk */
|
|
182
|
-
#handleStderr = (chunk) => {
|
|
183
|
-
if (this.#stderr.length >= MAX_STDERR_LENGTH) return
|
|
184
|
-
this.#stderr += String(chunk).slice(0, MAX_STDERR_LENGTH - this.#stderr.length)
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
/** @param {Error} error */
|
|
188
|
-
#handleError = (error) => {
|
|
189
|
-
this.#fail(error)
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* @param {number|null} code
|
|
194
|
-
* @param {string|null} signal
|
|
195
|
-
*/
|
|
196
|
-
#handleClose = (code, signal) => {
|
|
197
|
-
this.#readline?.close()
|
|
198
|
-
this.#closed = true
|
|
199
|
-
let error = this.#failure
|
|
200
|
-
if (!error && (code !== 0 || this.#pending.size > 0)) {
|
|
201
|
-
const reason = signal ? `signal ${signal}` : `status ${code}`
|
|
202
|
-
const stderr = this.#stderr.trim()
|
|
203
|
-
error = new Error(`The ESM resolver exited with ${reason}${stderr ? `: ${stderr}` : ''}`)
|
|
204
|
-
this.#failure = error
|
|
205
|
-
}
|
|
206
|
-
if (error) {
|
|
207
|
-
this.#rejectAll(error)
|
|
208
|
-
this.#rejectClosed(error)
|
|
209
|
-
} else {
|
|
210
|
-
this.#resolveClosed()
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* @param {number} id
|
|
216
|
-
* @param {Error} error
|
|
217
|
-
*/
|
|
218
|
-
#rejectRequest (id, error) {
|
|
219
|
-
const request = this.#pending.get(id)
|
|
220
|
-
if (!request) return
|
|
221
|
-
this.#pending.delete(id)
|
|
222
|
-
request.reject(error)
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
/** @param {Error} error */
|
|
226
|
-
#fail (error) {
|
|
227
|
-
if (this.#failure) return
|
|
228
|
-
this.#failure = error
|
|
229
|
-
this.#closed = true
|
|
230
|
-
this.#rejectAll(error)
|
|
231
|
-
this.#request?.destroy()
|
|
232
|
-
this.#child?.kill()
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
/** @param {Error} error */
|
|
236
|
-
#rejectAll (error) {
|
|
237
|
-
for (const request of this.#pending.values()) request.reject(error)
|
|
238
|
-
this.#pending.clear()
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
/** @returns {EsmResolver} */
|
|
243
|
-
function createEsmResolver () {
|
|
244
|
-
return new EsmResolver()
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
/**
|
|
248
|
-
* Drives the generator returned by import-in-the-middle >=3.1.0 export discovery.
|
|
249
|
-
*
|
|
250
|
-
* @param {GetExportsGenerator} exportsGenerator
|
|
251
|
-
* @param {(url: URL, context: object) => { source: string, format: string }} getSource
|
|
252
|
-
* @param {(specifier: string, context: object) => Promise<{ format: string, url: URL }>} resolve
|
|
253
|
-
* @returns {Promise<ModuleExports>}
|
|
254
|
-
*/
|
|
255
|
-
async function driveGetExportsGenerator (exportsGenerator, getSource, resolve) {
|
|
256
|
-
let next = exportsGenerator.next()
|
|
257
|
-
while (next.done === false) {
|
|
258
|
-
let result
|
|
259
|
-
let failure
|
|
260
|
-
let threw = false
|
|
261
|
-
|
|
262
|
-
try {
|
|
263
|
-
const operation = next.value
|
|
264
|
-
const operationType = operation[0]
|
|
265
|
-
|
|
266
|
-
if (operationType === LOAD_OPERATION) {
|
|
267
|
-
result = getSource(operation[1], operation[2])
|
|
268
|
-
} else if (operationType === RESOLVE_OPERATION) {
|
|
269
|
-
// eslint-disable-next-line no-await-in-loop
|
|
270
|
-
result = await resolve(operation[1], operation[2])
|
|
271
|
-
} else {
|
|
272
|
-
throw new Error(`Unsupported import-in-the-middle getExports operation: ${operationType}`)
|
|
273
|
-
}
|
|
274
|
-
} catch (error) {
|
|
275
|
-
threw = true
|
|
276
|
-
failure = error
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
next = threw ? exportsGenerator.throw(failure) : exportsGenerator.next(result)
|
|
280
|
-
}
|
|
281
|
-
return next.value instanceof Set ? { exportNames: next.value } : next.value
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
module.exports = { createEsmResolver, driveGetExportsGenerator }
|
|
@@ -1,318 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
// The content of this file is copied from the `import-in-the-middle` package with minor modifications (https://www.npmjs.com/package/import-in-the-middle)
|
|
4
|
-
const fs = require('node:fs')
|
|
5
|
-
const path = require('node:path')
|
|
6
|
-
const { fileURLToPath, pathToFileURL } = require('node:url')
|
|
7
|
-
|
|
8
|
-
const { createEsmResolver, driveGetExportsGenerator } = require('./resolver')
|
|
9
|
-
|
|
10
|
-
/** @typedef {ReturnType<typeof createEsmResolver>} EsmResolver */
|
|
11
|
-
|
|
12
|
-
const getExportsImporting = (url) => import(url).then(Object.keys)
|
|
13
|
-
let getExportsModulePromise
|
|
14
|
-
|
|
15
|
-
const loadGetExportsModule = () => {
|
|
16
|
-
if (!getExportsModulePromise) {
|
|
17
|
-
getExportsModulePromise = import('import-in-the-middle/lib/get-exports.mjs')
|
|
18
|
-
}
|
|
19
|
-
return getExportsModulePromise
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* @param {URL} srcUrl
|
|
24
|
-
* @param {object} context
|
|
25
|
-
* @param {(url: URL, context: object) => { source: string, format: string }} getSource
|
|
26
|
-
* @param {EsmResolver} resolver
|
|
27
|
-
* @returns {Promise<{
|
|
28
|
-
* exportNames: Iterable<string>,
|
|
29
|
-
* hasModuleExportsCJSDefault: boolean,
|
|
30
|
-
* starReexports?: Array<{ specifier: string, parentURL: string }>
|
|
31
|
-
* }>}
|
|
32
|
-
*/
|
|
33
|
-
const getExports = async (srcUrl, context, getSource, resolver) => {
|
|
34
|
-
const mod = await loadGetExportsModule()
|
|
35
|
-
const exportsGenerator = mod.getExports(srcUrl, context, getSource)
|
|
36
|
-
/**
|
|
37
|
-
* @param {string} specifier
|
|
38
|
-
* @param {{ parentURL: URL }} operationContext
|
|
39
|
-
* @returns {Promise<{ format: string, url: URL }>}
|
|
40
|
-
*/
|
|
41
|
-
const resolve = (specifier, operationContext) => resolveModule(specifier, operationContext, resolver)
|
|
42
|
-
const result = await driveGetExportsGenerator(exportsGenerator, getSource, resolve)
|
|
43
|
-
return {
|
|
44
|
-
exportNames: result.exportNames,
|
|
45
|
-
hasModuleExportsCJSDefault: mod.hasModuleExportsCJSDefault,
|
|
46
|
-
starReexports: result.starReexports,
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function isStarExportLine (line) {
|
|
51
|
-
return /^\* from /.test(line)
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function isBareSpecifier (specifier) {
|
|
55
|
-
// Relative and absolute paths are not bare specifiers.
|
|
56
|
-
if (
|
|
57
|
-
specifier.startsWith('.') ||
|
|
58
|
-
specifier.startsWith('/')) {
|
|
59
|
-
return false
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// Valid URLs are not bare specifiers. (file:, http:, node:, etc.)
|
|
63
|
-
|
|
64
|
-
if (URL.hasOwnProperty('canParse')) {
|
|
65
|
-
// eslint-disable-next-line n/no-unsupported-features/node-builtins
|
|
66
|
-
return !URL.canParse(specifier)
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
try {
|
|
70
|
-
// eslint-disable-next-line no-new
|
|
71
|
-
new URL(specifier)
|
|
72
|
-
return false
|
|
73
|
-
} catch {
|
|
74
|
-
return true
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* @param {string} modulePath
|
|
80
|
-
* @param {string} format
|
|
81
|
-
*/
|
|
82
|
-
function getModuleFormat (modulePath, format) {
|
|
83
|
-
if (modulePath.endsWith('.mts')) return 'module-typescript'
|
|
84
|
-
if (modulePath.endsWith('.cts')) return 'commonjs-typescript'
|
|
85
|
-
if (modulePath.endsWith('.ts')) return `${format}-typescript`
|
|
86
|
-
return format
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Resolves a module with the import conditions used by ESM instrumentation.
|
|
91
|
-
*
|
|
92
|
-
* @param {string} specifier
|
|
93
|
-
* @param {{ parentURL: URL }} context
|
|
94
|
-
* @param {EsmResolver} resolver
|
|
95
|
-
* @returns {Promise<{ format: string, url: URL }>}
|
|
96
|
-
*/
|
|
97
|
-
async function resolveModule (specifier, context, resolver) {
|
|
98
|
-
const url = new URL(await resolver.resolve(specifier, context.parentURL))
|
|
99
|
-
if (url.protocol === 'node:') return { format: 'builtin', url }
|
|
100
|
-
if (url.protocol !== 'file:') throw new Error(`Unsupported ESM resolution URL: ${url.href}`)
|
|
101
|
-
|
|
102
|
-
const resolved = fileURLToPath(url)
|
|
103
|
-
if (resolved.endsWith('.node')) {
|
|
104
|
-
throw new Error(`Unsupported ESM analysis target: ${resolved}`)
|
|
105
|
-
}
|
|
106
|
-
const format = isESMFile(resolved) ? 'module' : 'commonjs'
|
|
107
|
-
return { format, url }
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Generates the pieces of code for the proxy module before the path
|
|
112
|
-
*
|
|
113
|
-
* @param {object} moduleData
|
|
114
|
-
* @param {string} moduleData.path
|
|
115
|
-
* @param {boolean} [moduleData.internal]
|
|
116
|
-
* @param {object} moduleData.context
|
|
117
|
-
* @param {boolean} [moduleData.excludeDefault]
|
|
118
|
-
* @param {Map<string, string>} [moduleData.moduleSources]
|
|
119
|
-
* @param {EsmResolver} [moduleData.resolver]
|
|
120
|
-
* @param {(source: string, options: { loader: 'ts' }) => { code: string }} [moduleData.transform]
|
|
121
|
-
* @param {Set<string>} [activeModules]
|
|
122
|
-
* @returns {Promise<Map>}
|
|
123
|
-
*/
|
|
124
|
-
async function processModule (
|
|
125
|
-
{ path, internal = false, context, excludeDefault = false, moduleSources = new Map(), resolver, transform },
|
|
126
|
-
activeModules
|
|
127
|
-
) {
|
|
128
|
-
const ownsResolver = resolver === undefined
|
|
129
|
-
resolver ??= createEsmResolver()
|
|
130
|
-
try {
|
|
131
|
-
return await processModuleWithResolver(
|
|
132
|
-
{ path, internal, context, excludeDefault, moduleSources, transform },
|
|
133
|
-
activeModules,
|
|
134
|
-
resolver
|
|
135
|
-
)
|
|
136
|
-
} finally {
|
|
137
|
-
if (ownsResolver) await resolver.close()
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* @param {object} moduleData
|
|
143
|
-
* @param {string} moduleData.path
|
|
144
|
-
* @param {boolean} moduleData.internal
|
|
145
|
-
* @param {object} moduleData.context
|
|
146
|
-
* @param {boolean} moduleData.excludeDefault
|
|
147
|
-
* @param {Map<string, string>} moduleData.moduleSources
|
|
148
|
-
* @param {(source: string, options: { loader: 'ts' }) => { code: string }} [moduleData.transform]
|
|
149
|
-
* @param {Set<string>} [activeModules]
|
|
150
|
-
* @param {EsmResolver} resolver
|
|
151
|
-
* @returns {Promise<Map>}
|
|
152
|
-
*/
|
|
153
|
-
async function processModuleWithResolver (
|
|
154
|
-
{ path, internal, context, excludeDefault, moduleSources, transform },
|
|
155
|
-
activeModules,
|
|
156
|
-
resolver
|
|
157
|
-
) {
|
|
158
|
-
let moduleExports, srcUrl
|
|
159
|
-
if (internal) {
|
|
160
|
-
// we can not read and parse of internal modules
|
|
161
|
-
moduleExports = { exportNames: await getExportsImporting(path) }
|
|
162
|
-
} else {
|
|
163
|
-
context = { ...context, format: getModuleFormat(path, context.format) }
|
|
164
|
-
srcUrl = pathToFileURL(path)
|
|
165
|
-
const readSource = (url) => {
|
|
166
|
-
const modulePath = fileURLToPath(url)
|
|
167
|
-
let source = moduleSources.get(modulePath)
|
|
168
|
-
if (source === undefined) {
|
|
169
|
-
source = fs.readFileSync(modulePath, 'utf8')
|
|
170
|
-
moduleSources.set(modulePath, source)
|
|
171
|
-
}
|
|
172
|
-
return source
|
|
173
|
-
}
|
|
174
|
-
const loadSource = (url, { format }) => {
|
|
175
|
-
let source = readSource(url)
|
|
176
|
-
if (transform && (format === 'module-typescript' || format === 'commonjs-typescript')) {
|
|
177
|
-
source = transform(source, { loader: 'ts' }).code
|
|
178
|
-
format = format === 'module-typescript' ? 'module' : 'commonjs'
|
|
179
|
-
}
|
|
180
|
-
return { format, source }
|
|
181
|
-
}
|
|
182
|
-
readSource(srcUrl)
|
|
183
|
-
moduleExports = await getExports(srcUrl, context, loadSource, resolver)
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
const starExports = new Set()
|
|
187
|
-
const setters = new Map()
|
|
188
|
-
|
|
189
|
-
const addSetter = (name, setter, isStarExport = false) => {
|
|
190
|
-
if (setters.has(name)) {
|
|
191
|
-
if (isStarExport) {
|
|
192
|
-
// If there's already a matching star export, delete it
|
|
193
|
-
if (starExports.has(name)) {
|
|
194
|
-
setters.delete(name)
|
|
195
|
-
}
|
|
196
|
-
// and return so this is excluded
|
|
197
|
-
return
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
// if we already have this export but it is from a * export, overwrite it
|
|
201
|
-
if (starExports.has(name)) {
|
|
202
|
-
starExports.delete(name)
|
|
203
|
-
setters.set(name, setter)
|
|
204
|
-
}
|
|
205
|
-
} else {
|
|
206
|
-
// Store export * exports so we know they can be overridden by explicit
|
|
207
|
-
// named exports
|
|
208
|
-
if (isStarExport) {
|
|
209
|
-
starExports.add(name)
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
setters.set(name, setter)
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
let starReexports = moduleExports.starReexports
|
|
217
|
-
for (const n of moduleExports.exportNames) {
|
|
218
|
-
const isDefault = n === 'default' || (
|
|
219
|
-
n === 'module.exports' &&
|
|
220
|
-
moduleExports.hasModuleExportsCJSDefault &&
|
|
221
|
-
(context.format === 'commonjs' || context.format === 'commonjs-typescript')
|
|
222
|
-
)
|
|
223
|
-
if (isDefault && excludeDefault) continue
|
|
224
|
-
|
|
225
|
-
if (isStarExportLine(n)) {
|
|
226
|
-
starReexports ??= []
|
|
227
|
-
starReexports.push({ parentURL: srcUrl.href, specifier: n.slice('* from '.length) })
|
|
228
|
-
continue
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
const variableName = `$dd${Buffer.from(n).toString('hex')}`
|
|
232
|
-
const objectKey = JSON.stringify(n)
|
|
233
|
-
const reExportedName = n === 'default' ? n : objectKey
|
|
234
|
-
|
|
235
|
-
addSetter(n, `
|
|
236
|
-
let ${variableName}
|
|
237
|
-
try {
|
|
238
|
-
${variableName} = _[${objectKey}] = namespace[${objectKey}]
|
|
239
|
-
} catch (error) {
|
|
240
|
-
if (!(error instanceof ReferenceError)) throw error
|
|
241
|
-
}
|
|
242
|
-
export { ${variableName} as ${reExportedName} }
|
|
243
|
-
set[${objectKey}] = (v) => {
|
|
244
|
-
${variableName} = v
|
|
245
|
-
return true
|
|
246
|
-
}
|
|
247
|
-
get[${objectKey}] = () => ${variableName}
|
|
248
|
-
`)
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
if (starReexports) {
|
|
252
|
-
for (const { parentURL, specifier } of starReexports) {
|
|
253
|
-
const baseUrl = new URL(parentURL)
|
|
254
|
-
const resolvedSpecifier = isBareSpecifier(specifier) ? specifier : new URL(specifier, baseUrl).href
|
|
255
|
-
// The runtime's import conditions and the declaring module's URL own star-export resolution.
|
|
256
|
-
// eslint-disable-next-line no-await-in-loop
|
|
257
|
-
const result = await resolveModule(resolvedSpecifier, { parentURL: baseUrl }, resolver)
|
|
258
|
-
|
|
259
|
-
activeModules ??= new Set([srcUrl.href])
|
|
260
|
-
if (activeModules.has(result.url.href)) continue
|
|
261
|
-
activeModules.add(result.url.href)
|
|
262
|
-
|
|
263
|
-
// eslint-disable-next-line no-await-in-loop
|
|
264
|
-
const subSetters = await processModuleWithResolver({
|
|
265
|
-
path: result.format === 'builtin' ? result.url.href : fileURLToPath(result.url),
|
|
266
|
-
internal: result.format === 'builtin',
|
|
267
|
-
context: { ...context, format: result.format },
|
|
268
|
-
excludeDefault: true,
|
|
269
|
-
moduleSources,
|
|
270
|
-
transform,
|
|
271
|
-
}, activeModules, resolver)
|
|
272
|
-
activeModules.delete(result.url.href)
|
|
273
|
-
|
|
274
|
-
for (const [name, setter] of subSetters.entries()) {
|
|
275
|
-
addSetter(name, setter, true)
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
return setters
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
/**
|
|
284
|
-
* Determines if a file is a ESM module or CommonJS
|
|
285
|
-
*
|
|
286
|
-
* @param {string} fullPathToModule File to analize
|
|
287
|
-
* @param {string} [modulePackageJsonPath] Path of the package.json
|
|
288
|
-
* @param {object} [packageJson] The content of the module package.json
|
|
289
|
-
*/
|
|
290
|
-
function isESMFile (fullPathToModule, modulePackageJsonPath, packageJson = {}) {
|
|
291
|
-
if (fullPathToModule.endsWith('.mjs') || fullPathToModule.endsWith('.mts')) return true
|
|
292
|
-
if (fullPathToModule.endsWith('.cjs') || fullPathToModule.endsWith('.cts')) return false
|
|
293
|
-
|
|
294
|
-
const pathParts = fullPathToModule.split(path.sep)
|
|
295
|
-
do {
|
|
296
|
-
pathParts.pop()
|
|
297
|
-
|
|
298
|
-
const packageJsonPath = [...pathParts, 'package.json'].join(path.sep)
|
|
299
|
-
if (packageJsonPath === modulePackageJsonPath) {
|
|
300
|
-
return packageJson.type === 'module'
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
try {
|
|
304
|
-
const packageJsonContent = fs.readFileSync(packageJsonPath).toString()
|
|
305
|
-
const packageJson = JSON.parse(packageJsonContent)
|
|
306
|
-
return packageJson.type === 'module'
|
|
307
|
-
} catch {
|
|
308
|
-
// file does not exit, continue
|
|
309
|
-
}
|
|
310
|
-
} while (pathParts.length > 0)
|
|
311
|
-
|
|
312
|
-
return packageJson.type === 'module'
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
module.exports = {
|
|
316
|
-
isESMFile,
|
|
317
|
-
processModule,
|
|
318
|
-
}
|