question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

paths remapping is not done for type declarations

See original GitHub issue

Is it possible to use this plugin together with rollup-plugin-alias to replace mapped paths with their “true” paths and if not, would you have a recommendation for a plugin which could do that? I found this. But unfortunately it doesn’t resolve my problem or answers my question.

What I am trying to do; I am trying to replace the mapped paths / path aliases (i.e. @src) with the correct path in the transpiled type files. I’ve tried with the setup below and everything compiles fine. However, my type declaration files that contain a reference to a mapped path are not replaced. So to give an example, I have a Callable.d.ts file after transpilation that looks like

import { Instantiable, Instance } from '@src/Support/types';
declare class Callable<T> {
    private _target;
    private _method?;
    private _isStatic;
    constructor(target: Instantiable<T> | Instance<T>, method?: string, isStatic?: boolean);
    readonly target: Instantiable<T> | Instance<T>;
    readonly method: string | undefined;
    readonly isStatic: boolean;
    asArray(): [Instantiable<T> | Instance<T>, string | undefined, boolean];
    call(args: any[]): any;
}
export default Callable;

instead of

import { Instantiable, Instance } from '../Support/types';
declare class Callable<T> {
    private _target;
    private _method?;
    private _isStatic;
    constructor(target: Instantiable<T> | Instance<T>, method?: string, isStatic?: boolean);
    readonly target: Instantiable<T> | Instance<T>;
    readonly method: string | undefined;
    readonly isStatic: boolean;
    asArray(): [Instantiable<T> | Instance<T>, string | undefined, boolean];
    call(args: any[]): any;
}
export default Callable;

My tsconfig.json, rollup.config.js files and src folder are located at the same (top) level.

Versions

  • typescript: 3.2.2
  • rollup: 0.68.0
  • rollup-plugin-typescript2: 0.18.1

rollup.config.js

import path from 'path';
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import alias from 'rollup-plugin-alias';
import sourceMaps from 'rollup-plugin-sourcemaps';
import typescript from 'rollup-plugin-typescript2';
import {eslint} from 'rollup-plugin-eslint';
import {terser} from 'rollup-plugin-terser';
import pkg from './package.json';

export default {
    input: 'src/index.ts',
    output: {file: pkg.module, format: 'es', sourcemap: true},
    external: [
        ...Object.keys(pkg.dependencies || {}),
        ...Object.keys(pkg.peerDependencies || {}),
    ],
    watch: {
        include: 'src/**'
    },
    plugins: [
        eslint(),
        resolve(),
        commonjs(),
        alias({
            resolve: ['.ts'],
            '@src': path.resolve(__dirname, './src')
        }),
        typescript({
            typescript: require('typescript'),
            rollupCommonJSResolveHack: true
        }),
        sourceMaps(),
        terser()
    ]
};

tsconfig.json

{
    "compilerOptions": {
        "baseUrl": ".",
        "paths": {
            "@src/*": ["src/*"]
        },
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "moduleResolution": "node",
        "target": "es6",
        "module": "es6",
        "lib": ["es5", "es6", "es7", "dom"],
        "removeComments": true,
        "strict": true,
        "sourceMap": true,
        "declaration": true,
        "declarationDir": "./dist",
        "outDir": "./dist",
        "suppressImplicitAnyIndexErrors": true
    },
    "include": [
        "src/**/*"
    ],
    "exclude": [
        "node_modules",
        "dist"
    ]
}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
developer239commented, May 13, 2022
// tsconfig.build.json

// ...
"moduleResolution": "node",
"plugins": [
  {
    "transform": "@zerollup/ts-transform-paths",
    "exclude": ["*"]
  }
]
// ...
// rollup.config.js

/* eslint-disable import/no-default-export */
import cleaner from 'rollup-plugin-cleaner'
import typescript from 'rollup-plugin-typescript2'
import ttypescript from 'ttypescript'

export default {
  input: `./src/index.ts`,
  output: [
    { file: 'lib/index.js' },
  ],
  plugins: [
    cleaner({
      targets: ['./lib'],
    }),
    typescript({
      tsconfig: 'tsconfig.build.json',
      typescript: ttypescript
    }),
  ],
}
2reactions
viT-1commented, Aug 22, 2019

Another way is try to configure rollup-plugin-typescript2 with typescript: ttypescript and tsconfig.json > compilerOptions > "plugins": [{ "transform": "typescript-transform-paths" }]

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use paths in tsconfig.json? - Stack Overflow
This can be set up on your tsconfig.json file, as it is a TS feature. You can do like this: "compilerOptions": { "baseUrl":...
Read more >
Path maps cannot be resolved by tsc / Works as intended
It took me some time to find out why ts-node would successfully remap those paths and the tsc compiled js code wouldn't.
Read more >
Stream view configuration - Perforce
The Views area contains Paths, Remapped, and Ignored. ... Stream path types ... Stream views do not allow positional specifiers (%%1) or overlay...
Read more >
ts-node - npm
This means "paths" are intended to describe mappings that the build tool or runtime already performs, not to tell the build tool or...
Read more >
<script type="importmap"> - HTML: HyperText Markup Language
Module specifier keys do not have to be single word names ("bare names"). They can also contain or end with path separators, or...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found