Skip to content

Incorrect order of extend()ing compilerOptions  #27

Closed

Description

@terasaka2k

In ts-node.ts around line 80,

  config.compilerOptions = extend({
    target: 'es5',
    module: 'commonjs'
  }, config.compilerOptions, {
    sourceMap: true,
    inlineSourceMap: false,
    inlineSources: false,
    declaration: false
  })

should be

  config.compilerOptions = extend({
    sourceMap: true,
    inlineSourceMap: false,
    inlineSources: false,
    declaration: false
  }, config.compilerOptions, {
    target: 'es5',
    module: 'commonjs'
  })

for { target: 'es5', module: 'commonjs' } to take precedence over user's options, which potentially may be intended for latest browsers environments.

Activity

  1. blakeembrey commented on Nov 6, 2015

    @blakeembrey
    Member

    @terasaka2k This is correct. The sourceMap options need to override the user settings, there's specially handling for it. The user, however, could output ES6 or ES3 if they so wished. Same with the module environment.

    Edit: Accidentally hit enter.

  2. darthtrevino commented on Jan 26, 2016

    @darthtrevino

    Consider this use case: I'm using webpack to chain the typescript-loader and the babel-loader together to take advantage of babel's hook runtime for things like HMR. I want my tsconfig.json to target ES6 and let the babel-loader transpile from ES6 to ES5 for browsers.

    However, in my server code, I want to go straight from TS to ES5. I would like to be able to do this:

    # index.js - server entry point
    require('ts-node').register({
        compilerOptions: {
            target: 'es5'
        }
    })
    

    And then what I would expect to happen in ts-node would be something like:

    const defaultConfig = { target: 'es5', module: 'commonjs' };
    const tsConfigFromFile = readFromTsConfigJson();
    Object.assign({}, defaultConfig, tsConfigFromFile, tsConfigFromArgs)
    
  3. blakeembrey commented on Jan 26, 2016

    @blakeembrey
    Member

    @darthtrevino I'm not sure who you're responding to, but that's how it works already and the reason I closed the issue. However, there's no compilerOptions pass in to ts-node, it's all from tsconfig.json.

  4. blakeembrey commented on Jan 26, 2016

    @blakeembrey
    Member

    It sounds like you're actually after a different feature? The ability to pass in compiler options that override tsconfig.json?

  5. darthtrevino commented on Jan 26, 2016

    @darthtrevino

    Correct

  6. blakeembrey commented on Jan 26, 2016

    @blakeembrey
    Member
  7. darthtrevino commented on Jan 26, 2016

    @darthtrevino

    Sweet! Thanks @blakeembrey !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions