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

Incorrect Declaration Map Source #135

Closed
Braden1996 opened this issue Jun 8, 2019 · 2 comments · May be fixed by #488
Closed

Incorrect Declaration Map Source #135

Braden1996 opened this issue Jun 8, 2019 · 2 comments · May be fixed by #488
Labels
kind: bug Something isn't working scope: upstream Issue in upstream dependency solution: duplicate This issue or pull request already exists topic: rollup-plugin-typescript2 Issues and PRs relating to rpts2

Comments

@Braden1996
Copy link

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
@swyxio
Copy link
Collaborator

swyxio commented Jun 9, 2019

i think this is because tsdx is meant to be for libraries you publish, where this is typically the default behavior (in particular, you might not publish the typescript source files). you might just be using tsdx beyond its intended purpose.

however it might allow you to extend rollup config in future if jared wants this #110 so you can apply whatever you want

@swyxio
Copy link
Collaborator

swyxio commented Aug 26, 2019

hey @Braden1996 could you please review #183 and see if your rollup config works here? if you'd like some stuff included by default (e.g. sourcemaps plugin?) please mention there too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: bug Something isn't working scope: upstream Issue in upstream dependency solution: duplicate This issue or pull request already exists topic: rollup-plugin-typescript2 Issues and PRs relating to rpts2
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants