Skip to content
This repository has been archived by the owner on May 5, 2022. It is now read-only.

Do not work with "--allowJs" option #39

Open
qtuan opened this issue Apr 19, 2016 · 6 comments
Open

Do not work with "--allowJs" option #39

qtuan opened this issue Apr 19, 2016 · 6 comments

Comments

@qtuan
Copy link

qtuan commented Apr 19, 2016

Typescript 1.8 support --allowJs, but gulp-tsb seems to ignore it.

var tsb = require('gulp-tsb');

// create and keep compiler
var compilation = tsb.create({
    target: 'es5',
    module: 'commonjs',
    declaration: false,
    allowJs: true
});

gulp.task('build', function() {
    return gulp.src(['src/**/*.ts', 'src/**/*.js'])
        .pipe(compilation()) // <- new compilation
        .pipe(gulp.dest('dist/'));
});

Correct output files are still generated for respective source *.ts, but none is generated for the *.js files.
It works correctly when running tscon the command line.

@jrieken jrieken added the bug label Apr 28, 2016
jrieken added a commit that referenced this issue Apr 28, 2016
@jrieken jrieken removed the bug label Apr 28, 2016
@jrieken
Copy link
Owner

jrieken commented Apr 28, 2016

@qtuan I have added a test to check that the flag is passed on to TypeScript. The issue must be something else.

@qtuan
Copy link
Author

qtuan commented May 1, 2016

@jrieken Thanks for checking! Could you speculate what is wrong? I couldn't figure it out. Here is my test data:

// src/x.js
export class X {
    doSomeThing() {
        console.log('X doSomeThing');
    }
}
// src/a.ts
import {X} from './x';

export class A {
    constructor(private x: X) {}

    doSomeThing() {
        this.x.doSomeThing();
        console.log('A doSomeThing');
    }
}

Build script is same as in my original post.

> gulp build: only dist/a.js is generated
> tsc --target es5 --module commonjs --outDir dist --allowJs src/a.ts src/x.js: both dist/a.js and dist/x.js are generated

Version of installed packages: [email protected], [email protected]

@jrieken
Copy link
Owner

jrieken commented May 2, 2016

@qtuan Can you try to define the outDir when setting up the compiler? I believe TS ignores the allowJs option cos without an output dir it would overwrite the input files.

@qtuan
Copy link
Author

qtuan commented May 4, 2016

@jrieken Actually I tried outDir, and just try again, but it's still not working.

Another point I forget to mention, that I need to require('object.assign').shim() at top of my build script, otherwise gulp-tsb will throw error.

\typescript-build\node_modules\gulp-tsb\lib\index.js:28
        Object.assign(config, configOrName);
               ^
TypeError: undefined is not a function

My environment: node v0.12.7, [email protected]

@zenorbi
Copy link
Contributor

zenorbi commented Jan 6, 2017

The builder only allows for .ts and .tsx extensions:

if (/\.tsx?/i.test(path.extname(fileName))

This should be changed to also include .js files when allowJs: true.

getScriptFileNames(): string[] {
	const result: string[] = [];
	const libLocation = this.getDefaultLibLocation();
	const filter = this._settings.allowJs ? /\.?(ts|tsx|js)/i : /\.?(ts|tsx)/i;
	for (let fileName in this._snapshots) {
		if (filter.test(path.extname(fileName))
			&& normalize(path.dirname(fileName)) !== libLocation) {
			// only ts-files and not lib.d.ts-like files
			result.push(fileName);
		}
	}
	return result;
}

@BurtHarris
Copy link

@jrieken, this is a great enhancement to the build I believe I'm running into this same issue with it not generating output objects for .js files in the input stream, despite allowJs and outDir being set.

I see @zenorbi has a PR which sounds like it may fix it. What's the likelihood of getting this applied to the published version sometime soon?

Instrumentation from gulp.debug around the gulp-tsb step:

[21:47:35] Starting 'build.test.typescript'...
[21:47:35] src test\unit\applyDecorators.spec.js
[21:47:35] src test\unit\autobind.spec.js
[21:47:35] src test\unit\decorate.spec.js
[21:47:35] src test\unit\deprecate.spec.js
[21:47:35] src test\unit\enumerable.spec.js
[21:47:35] src test\unit\extendDescriptor.js
[21:47:35] src test\unit\lazy-initialize.spec.js
[21:47:35] src test\unit\nonconfigurable.spec.js
[21:47:35] src test\unit\nonenumerable.spec.js
[21:47:35] src test\unit\override.spec.js
[21:47:35] src test\unit\profile.spec.js
[21:47:35] src test\unit\readonly.spec.js
[21:47:35] src test\unit\suppress-warnings.spec.js
[21:47:35] src test\unit\time.spec.js
[21:47:35] src 14 items
[21:47:35] out 0 items
[21:47:35] Finished 'build.test.typescript' after 46 ms

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants