Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add explicit file extensions imports and make TypeScript checks for them #4217

Commits on Mar 12, 2023

  1. refactor: add extension to all relative imports

    ESM and Node.JS requires that all relative imports have a file
    extension. For example, `import x from "abc";` is invalid, as
    you instead need to do `import x from "abc.js";`.
    
    Vite allows it, but it causes issues with other bundlers/software
    for people that use Mermaid.
    aloisklink committed Mar 12, 2023
    Configuration menu
    Copy the full SHA
    d135578 View commit details
    Browse the repository at this point in the history
  2. build(tsc): use moduleResolution: "nodenext"

    Using `moduleResolution: "nodenext"` is the new recommended way of
    using TypeScript,
    see https://www.typescriptlang.org/tsconfig#moduleResolution
    aloisklink committed Mar 12, 2023
    Configuration menu
    Copy the full SHA
    c45af3d View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    253126a View commit details
    Browse the repository at this point in the history
  4. build(tsc): move emitDeclarationOnly to tsconfig

    Move the `--emitDeclarationOnly` away from the `tsc` CLI,
    and into the tsconfig.json file.
    aloisklink committed Mar 12, 2023
    Configuration menu
    Copy the full SHA
    e1e5927 View commit details
    Browse the repository at this point in the history
  5. build(tsc): allow importing with a .ts extension

    TypeScript version 5.0 added supported for importing files with a `.ts`
    extension, which is what Vite requires in order to import TypeScript
    files.
    aloisklink committed Mar 12, 2023
    Configuration menu
    Copy the full SHA
    5f8982f View commit details
    Browse the repository at this point in the history
  6. refactor: add .ts extension to imports

    Vite doesn't allow importing TypeScript files with
    `import xx from "xx.js";`. Instead, you must import the files
    with a `.ts` extension, e.g. `import xx from "xx.ts";`.
    
    Because this relies on the new `--allowImportingTsExtensions` option
    in TypeScript v5.0, most IDEs currently struggle to handle this.
    Hopefully, this will be fixed once TypeScript v5.0 is officially
    released!
    aloisklink committed Mar 12, 2023
    Configuration menu
    Copy the full SHA
    c9c8385 View commit details
    Browse the repository at this point in the history