ivogabe / gulp-typescript

A TypeScript compiler for gulp with incremental compilation support.
MIT License
839 stars 129 forks source link

tsc vs gulp-typescript output - Duplicate erros & Folder structure #570

Closed sudiptosen closed 6 years ago

sudiptosen commented 6 years ago

Hi,

I have a very simple tsconfig : Only intent is to output src and spec separately to an output folder. Then, I want to simply pipe(jasmine()) after every pipe(tsproject()) on a gulp-watch

Expected behavior:

Actual behavior: tsc runs and outputs as expected. I can run jasmine and all good.

When the gulp-typescript runs, I get a ton of these

node_modules/typescript/lib/lib.es2015.iterable.d.ts(439,11): error TS2451: Cannot redeclare block-scoped variable 'Float32Array'.
node_modules/typescript/lib/lib.es2015.iterable.d.ts(467,11): error TS2451: Cannot redeclare block-scoped variable 'Float64Array'.
.
.
.
node_modules/typescript/lib/lib.es2016.full.d.ts(1499,5): error TS2375: Duplicate number index signature.
node_modules/typescript/lib/lib.es2016.full.d.ts(1717,5): error TS2375: Duplicate number index signature.
node_modules/typescript/lib/lib.es2016.full.d.ts(1990,5): error TS2375: Duplicate number index signature.
node_modules/typescript/lib/lib.es2016.full.d.ts(2351,5): error TS2375: Duplicate number index signature.
n

gulpfile.js

let gulp = require("gulp");
let watch = require("gulp-watch");
let gulputil = require("gulp-util");
let gulpts = require("gulp-typescript");
let jasmine = require("gulp-jasmine");

let paths={
  srcAll: "./**/*.ts",
  src: "./src/**/*.ts",
  spec: "./spec/**/*.ts",
  specJs: "./output/**/*[Ss]pec.js",
  output: "./output"
};

gulp.task('default', ()=>{
  return watch([paths.src, paths.spec], ()=>{
    let tsProject1 = gulpts.createProject("tsconfig.json");

    gulp.src(paths.srcAll)
      .pipe(tsProject1())
      .pipe(gulp.dest(paths.output));

     gulp.src(paths.specJs)
       .pipe(jasmine());
  })
});

process.on('uncaughtException', (err)=>{
  console.log("Error detected.");
  console.log(err);
})

tsconfig.json


{
    "compilerOptions": {
      "target": "es5",
      "module": "commonjs",
       "lib": ["es2015"],
       "outDir": "./output",
      "strict": true,
      "esModuleInterop": true
    },
    "include": [
      "./src/**/*.ts",
      "./spec/**/*.ts"
    ],
    "exclude": ["node_modules", "output"]
  }```
ivogabe commented 6 years ago

gulp.src(paths.srcAll) will load all TypeScript files in your project, including lib (.d.ts) files from node_modules/typescript. Could you try to replace that with gulp.src(paths.src) or tsProject1.src()?

sudiptosen commented 6 years ago

Yes, you are right 👍 Thank you so much.

'tsProject1.src()' worked perfectly for me.

Cleaned up gulpfile and posting, might help someone.

gulpfile.js

let gulp = require("gulp");
let watch = require("gulp-watch");
let gulpts = require("gulp-typescript");
let jasmine = require("gulp-jasmine");
let gulputil = require("gulp-util");
let clean = require("gulp-clean");

let paths={
  src: "./src/**/*.ts",
  spec: "./spec/**/*.ts",
  specJs: "./output/**/*[Ss]pec.js",
  output: "./output"
};

gulp.task('default', ['build']);

let buildCounter = 0;

gulp.task('build', ['cleanup'], ()=>{
  let target  = [].concat(paths.src, paths.spec);
  runJasmine();
  gulputil.log("Watching for changes....");
  return watch(target, ()=>{
    gulputil.log("Starting build...");
    let tsProject = gulpts.createProject("tsconfig.json");
    tsProject.src()
      .pipe(tsProject())
      .pipe(gulp.dest(paths.output))
    .on('end', postBuild)
  })
});

process.on('uncaughtException', (err)=>{
  console.log("Error detected.");
  console.log(err);
});

gulp.task('cleanup', ()=>{
  gulp.src(paths.output)
    .pipe(clean());
});

function postBuild(){
  gulputil.log("------------------------------------------------------");
  gulputil.log("**** Finished Build# " + (++buildCounter) + " ****") ;
  gulputil.log("------------------------------------------------------");
  runJasmine();
}

function runJasmine(){
  // ==================================================================
  // Jasmine console reporter setup
  // ==================================================================
  const JasmineConsoleReporter = require('jasmine-console-reporter');
  const consoleReporter = new JasmineConsoleReporter({
    colors: 1,           // (0|false)|(1|true)|2
    cleanStack: 1,       // (0|false)|(1|true)|2|3
    verbosity: 4,        // (0|false)|1|2|(3|true)|4
    listStyle: 'indent', // "flat"|"indent"
    activity: false
  });
  // ==================================================================

  gulp.src(paths.specJs)
    .pipe(jasmine({
      reporter: consoleReporter
    }))
    .on('end', ()=> gulputil.log("Watching for changes...."));
}
sudiptosen commented 6 years ago

Thanks.