Skip to content

tsify 0.15.5 compiles all ts files even if they're not imported #143

Closed

Description

@thunderkid

I'm using browserify/tsify within a gulp file. It starts off by compiling some file passed from the command line - tsStartFile. Everything is fine with tsify 0.15.4. But with 0.15.5, instead of just starting with tsStartFile and working recursively outward through all imported .ts files, it seems to compile every single .ts file it can find beneath the starting directory. Aside from being inefficient, this can cause problems if you have non-compiling .ts fragments that you're working on in some subdirectory - you'll get a bunch of syntax errors and compilaton will stop. Right now I've just reverted to 0.15.4.

This is the relevant part of my gulp file:

    var bundler = browserify({basedir: './', debug: true, cache: {}, packageCache: {}, fullPaths: true})
        .add(tsStartFile)
        .plugin(tsify, { target: 'es5', noImplicitAny: false, jsx: 'react'});

    var uglify = $.if(isProduction, $.streamify($.uglify({mangle: true, mangle_properties: true}).on('error', logError)));      // minification. mangle_properties doesn't seem to work.

    return bundler.bundle()
            .on('error', logError) 
            .pipe(source(tsOutputFile))
            .pipe(uglify)
            .pipe(gulp.dest(outputDir));

Activity

  1. LPGhatguy commented on May 17, 2016

    @LPGhatguy
    Contributor

    Do you have a tsconfig.json file in the root of your project?

  2. thunderkid commented on May 17, 2016

    @thunderkid
    Author

    Yes. It's this:

    {
        "compilerOptions": {
            "target": "es5",
            "module": "commonjs",
            "jsx": "react",
            "noImplicitAny": false,
            "removeComments": false,
            "preserveConstEnums": true,
            "outDir": "./temp/compiledTs/",
            "sourceMap": true,
            "experimentalDecorators": true
        },
        "exclude": [
            "node_modules"
        ]
    }
    
  3. LPGhatguy commented on May 17, 2016

    @LPGhatguy
    Contributor

    This might be the same issue as #142, which is a problem that my team ran into. The compiler is loading files according to tsconfig.json and the files specified in Gulp, which causes all sorts of problems.

  4. thunderkid commented on May 17, 2016

    @thunderkid
    Author

    But I don't see where my tsconfig.json is telling it to load any particular ts files.

  5. LPGhatguy commented on May 18, 2016

    @LPGhatguy
    Contributor

    By setting the exclude setting, all files not in the exclude list are implicitly added and marked for compilation.

  6. smrq commented on May 19, 2016

    @smrq
    Member

    I recognize this behavior may be counter-intuitive for some users, but that's how tsc works, which is why tsify now behaves this way.

    Ultimately, there are two competing interpretations of which files to compile, one of which comes from the Browserify camp, and the other of which comes from the TypeScript camp. Browserify users expect the passed-in files and their dependencies to be used, and no others. TypeScript users expect the files and exclude configurations from tsconfig.json to be respected. Under this second interpretation, the files passed in represent only the entry point(s) to your program. This interpretation is critical when dealing with *.d.ts files -- they are not directly depended upon, but their inclusion in the compilation unit is necessary.

    My goal is to provide as thin as possible a layer on top of the TypeScript compiler in order to enable the bundling of CommonJS dependencies that Browserify provides. To that end, I'm attempting to follow the conventions set by TypeScript rather than Browserify if there is a conflict.

    Ultimately, if you have a tsconfig.json, I think it's important to respect its contents with this tool.

    I reverted the changes and re-released with a major version bump because this was a breaking change for some users.

  7. azarus commented on Jul 14, 2017

    @azarus

    Sigh.....

  8. cartant commented on Jul 15, 2017

    @cartant
    Contributor

    @azarus This is a pretty old issue and with TypeScript 2.0 and later the files, include and exclude options can be used together, so things are not as inflexible as they once were. Additionally, it's now easy to use multiple tsconfig.json files without duplication with the extends option - so you can use a config file with an empty files array for tsify and another config file for some other tool - e.g. for TSLint.

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