v12: Ditch CJS build

Abierto
#26,671 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
25/100
Tipo de issue
Refactorización
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
node.js, typescript

Línea de trabajo

Start by surveying Node.js versions that support require(esm), then inspect the repository’s CI matrices, package engines fields, documentation, runtime dependencies, and build and deployment configuration. Check whether any runtime dependency uses top-level await and identify an integration test that can catch it. Done means the supported Node.js versions and CI reflect the survey, the dependency constraint is guarded by a test, and builds no longer produce CJS.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

A common user request is to provide a default export from our SDKs: import Sentry from '@sentry/somesdk' rather than import * as Sentry from '@sentry/somesdk'.

However, this is quite annoying to do, for the fact that we build for both CJS and ESM, using the same types definitions, as typescript represents the default export quite differently between CJS and ESM. (For good reason; they're semantically different in very subtle ways that are impossible to represent 100% faithfully, even if these only become an issue in certain edge cases.)

Option 1: build types twice

This is definitely a possibility, and not terrible. It does increase our build times a tiny bit, but many projects do hybrid builds this way, and it's typically not that bad. It'll increase the download size of our packages by a modest amount, but the run-time cost stays what it is today.

As this is less good than Option 2 below, it's a known-mediocre fallback (maybe still better than "leave it, no change") if we run into problems.

Option 2: Ditch CJS

This has a ton of benefits. Faster CI (because we can cut out entire dimensions of several build/test matrices), smaller download size, etc. And, we can do it with only a very modest platform support coverage hit, because new Node versions all support require(esm).

The only hazard (apart from version support) is that if anything in the runtime dependency chain uses top-level await, it blows up.

Done when...
  • Survey node versions that support require(esm) to confirm we have the appetite to restrict our supported node versions to that list, and then do so. (Adjust CI matrices, engines fields, docs, etc.)
  • Ensure that none of our runtime dependencies use top-level await. This is probably fine, mostly the only runtime deps we have outside of this repo are either optional peer-deps that the user provides, @sentry/conventions, and @opentelemetry/api. But we should check, and have an integration test that'll fail if this changes. (Currently it seems safe.)
  • Update our build and deployment mechanisms to no longer build CJS.
Lenguaje dominante
TypeScript
Estrellas
8.8k
Forks
1.9k
Merge medio
1 d 8 h
PR fusionados (30 d)
744

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de getsentry/sentry-javascript

Todos los issues de getsentry/sentry-javascript

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.