Skip to content

Sucrase integration #1851

@cspotcode

Description

@cspotcode

This issue tracks the work necessary on the ts-node side to offer first-class support for a sucrase transpiler.

Related to:
alangpierce/sucrase#726
alangpierce/sucrase#729

User should be able to ts-node --sucrase or add "sucrase": true to tsconfig, just as they can do for swc.

I will maintain a to-do list of tasks based on conversations with @alangpierce.

Interface between ts-node and sucrase (WIP)

These are the bits to lock down into a non-breaking interface of sorts, between sucrase and ts-node

  • What module specifier should ts-node require() when user enables "sucrase": true?
    • basically, this is the value of the "transpiler" option, but I think we do a bit of project-local and global fallback require() conveniences to make things "just work"
  • What is the name of the module, if different than above?
    • e.g when we fail to require('sucrase/ts-node-plugin') then we should suggest that users add sucrase` to their package.json
    • we must(?) also declare optional peerDep for strict package managers
  • way for transpiler to return diagnostics
    • errors and warnings
    • from both create() and transpile()
  • way for transpiler to indicate REPL continuation / recoverable input

TODOs (WIP)

  • Add "sucrase" option to config
  • Add --sucrase flag to CLI
  • Add --sucrase flag to CLI --help
  • Redo docs to describe SWC and sucrase under same umbrella
  • make @internal transpiler API bits public
    • /** @category Transpiler */
      export interface CreateTranspilerOptions {
      // TODO this is confusing because its only a partial Service. Rename?
      // Careful: must avoid stripInternal breakage by guarding with Extract<>
      service: Pick<
      Service,
      Extract<'config' | 'options' | 'projectLocalResolveHelper', keyof Service>
      >;
      /**
      * If `"transpiler"` option is declared in an "extends" tsconfig, this path might be different than
      * the `projectLocalResolveHelper`
      *
      * @internal
      */
      transpilerConfigLocalResolveHelper: ProjectLocalResolveHelper;
      /**
      * When using `module: nodenext` or `module: node12`, there are two possible styles of emit:
      * - CommonJS with dynamic imports preserved (not transformed into `require()` calls)
      * - ECMAScript modules with `import foo = require()` transformed into `require = createRequire(); const foo = require()`
      * @internal
      */
      nodeModuleEmitKind?: NodeModuleEmitKind;
      }
    • nodeModuleEmitKind
  • figure out how sucrase should send us diagnostics: errors or warnings
    • either from create() or transpile() calls
    • let plugins declare their own "name" to namespace the diagnostics: e.g. TSNODE-SUCRASE-123
    • Maybe becomes part of the interface described above, or maybe merely part of the transpiler API
  • accept sourcemap as object in transpiler API
  • expose api version? to make future breaks easier to detect by plugins?

Metadata

Metadata

Assignees

No one assigned

    Labels

    researchNeeds design work, investigation, or prototyping. Implementation uncertain.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions