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

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

Closed
thunderkid opened this issue May 17, 2016 · 8 comments
Closed

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

thunderkid opened this issue May 17, 2016 · 8 comments
Labels

Comments

@thunderkid
Copy link

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));

@LPGhatguy
Copy link
Contributor

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

@thunderkid
Copy link
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"
    ]
}

@LPGhatguy
Copy link
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.

@thunderkid
Copy link
Author

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

@LPGhatguy
Copy link
Contributor

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

@smrq
Copy link
Member

smrq commented May 19, 2016

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.

@azarus
Copy link

azarus commented Jul 14, 2017

Sigh.....

@cartant
Copy link
Contributor

cartant commented Jul 15, 2017

@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
Labels
Projects
None yet
Development

No branches or pull requests

5 participants