Skip to content

Incorrect Declaration Map Source #135

@Braden1996

Description

@Braden1996

Current Behavior

I am currently using tsdx to run the core package within my monorepo. When I import something from the core package and click through in my editor I end up in the declaration file - not the source file as I would expect.

Source file (packages/core/src/):

import base from './palette.json';

const use = {
  background: {
    primary: base.aliceBlue,
    secondary: base.white,
    tertiary: base.mirage,
  },
  text: {
    primary: base.mineShaft,
  },
};

const colors = { base, use };

export default colors;

Declaration file (packages/core/dist/config/colors.d.ts.map):

{"version":3,"file":"colors.d.ts","sourceRoot":"","sources":["colors.ts"],"names":[],"mappings":"AAiBA,QAAA,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;CAAgB,CAAC;AAE7B,eAAe,MAAM,CAAC"}

Expected behavior

When I click-through on a variable imported from a tsdx package, I am taken to the source file - rather than the definition file.

Declaration file (packages/core/dist/config/colors.d.ts.map):

{"version":3,"file":"colors.d.ts","sourceRoot":"","sources":["../../src/config/colors.ts"],"names":[],"mappings":"AAiBA,QAAA,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;CAAgB,CAAC;AAE7B,eAAe,MAAM,CAAC"}

Suggested solution(s)

I have this working using the following rollup config, not sure how well this transfers to tsdx:

import camelCase from 'lodash.camelcase';
import commonjs from 'rollup-plugin-commonjs';
import json from 'rollup-plugin-json';
import resolve from 'rollup-plugin-node-resolve';
import sourceMaps from 'rollup-plugin-sourcemaps';
import typescript from 'rollup-plugin-typescript2';
import ts from 'typescript';

const pkg = require('./package.json');

const libraryName = 'vulk-core';

export default {
  input: `src/${libraryName}.ts`,
  output: [
    {
      file: pkg.main,
      name: camelCase(libraryName),
      format: 'umd',
      sourcemap: true,
    },
    { file: pkg.module, format: 'es', sourcemap: true },
  ],
  // Indicate here external modules you don't wanna include in your bundle (i.e.: 'lodash')
  external: [],
  watch: {
    include: 'src/**',
  },
  plugins: [
    // Allow json resolution
    json(),
    // Compile TypeScript files
    typescript({
      useTsconfigDeclarationDir: true,
      typescript: ts,
    }),
    // Allow bundling cjs modules (unlike webpack, rollup doesn't understand cjs)
    commonjs(),
    // Allow node_modules resolution, so you can use 'external' to control
    // which external modules to include in the bundle
    // https://github.com/rollup/rollup-plugin-node-resolve#usage
    resolve(),

    // Resolve source maps to the original source
    sourceMaps(),
  ],
};

Your environment

Software Version(s)
TSDX 0.5.11
TypeScript 3.4.5
Browser N/A
npm/Yarn yarn (with workspaces)
Operating System MacOs

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions