Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gulp-typescript

Package Overview
Dependencies
Maintainers
1
Versions
72
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gulp-typescript - npm Package Compare versions

Comparing version 3.2.3 to 4.0.0-alpha.1

47

package.json
{
"name": "gulp-typescript",
"version": "3.2.3",
"version": "4.0.0-alpha.1",
"description": "A typescript compiler for gulp with incremental compilation support.",

@@ -54,2 +54,6 @@ "homepage": "https://github.com/ivogabe/gulp-typescript",

"email": "yuisu@microsoft.com"
},
{
"name": "Rogier Schouten",
"email": "github@workingcode.ninja"
}

@@ -61,24 +65,25 @@ ],

"dependencies": {
"gulp-util": "~3.0.7",
"source-map": "~0.5.3",
"through2": "~2.0.1",
"vinyl-fs": "~2.4.3"
"ansi-colors": "^1.0.1",
"plugin-error": "^0.1.2",
"source-map": "^0.6.1",
"through2": "^2.0.3",
"vinyl-fs": "^3.0.0"
},
"devDependencies": {
"@types/chalk": "0.4.31",
"@types/gulp-util": "3.0.31",
"@types/node": "7.0.22",
"@types/source-map": "0.5.0",
"@types/through2": "2.0.33",
"@types/vinyl": "2.0.0",
"@types/vinyl-fs": "2.4.5",
"gulp": "~3.9.1",
"gulp-concat": "~2.6.0",
"gulp-diff": "~1.0.0",
"gulp-header": "~1.7.1",
"gulp-plumber": "~1.1.0",
"gulp-sourcemaps": "~1.6.0",
"merge-stream": "~1.0.0",
"rimraf": "~2.5.2",
"typescript": "2.4.1"
"@types/ansi-colors": "^1.0.0",
"@types/node": "^8.5.2",
"@types/plugin-error": "^0.1.0",
"@types/source-map": "^0.5.2",
"@types/through2": "^2.0.33",
"@types/vinyl": "^2.0.2",
"@types/vinyl-fs": "^2.4.8",
"gulp": "^3.9.1",
"gulp-concat": "^2.6.1",
"gulp-diff": "^1.0.0",
"gulp-header": "^1.8.9",
"gulp-plumber": "^1.1.0",
"gulp-sourcemaps": "^2.6.2",
"merge-stream": "^1.0.1",
"rimraf": "^2.6.2",
"typescript": "2.6.2"
},

@@ -85,0 +90,0 @@ "peerDependencies": {

@@ -64,2 +64,12 @@ gulp-typescript

API overview
------------
gulp-typescript can be imported using `const ts = require('gulp-typescript');`. It provides the following functions:
- `ts(options?)` - Returns a gulp stream that compiles TypeScript files using the specified options.
- `ts.createProject(options?)`, `ts.createProject(tsconfig filename, options?)` - Returns a project. The intended usage is to create a project outside of a task with `const tsProject = ts.createProject(..);`. Within a task, `tsProject()` can be used to compile a stream of TypeScript files.
- `tsProject.src()` - Returns a stream containing the source files (.ts) from a tsconfig file. It can only be used if you create a project with a `tsconfig.json` file. It is a replacement for `gulp.src(..)`.
Both `ts(..)` and `tsProject()` provide sub-streams that only contain the JavaScript or declaration files. An example is shown later in the readme.
Basic Usage

@@ -104,7 +114,7 @@ ----------

You need to set the `declaration` option to generate definition files.
If you don't need the definition files, you can use a configuration as seen in the first example.
If you don't need the definition files, you can use a configuration as seen in the first example, and you don't need to store the result into a variable as `tsResult`.
Incremental compilation
-----------------------
Instead of calling `ts(options)`, you can create a project first, and then call `tsProject()`. An example:
Instead of calling `ts(options)`, you can create a project first outside of the task. Inside the task, you should then use `tsProject()`. An example:
```javascript

@@ -120,9 +130,5 @@ var gulp = require('gulp');

gulp.task('scripts', function() {
var tsResult = gulp.src('lib/*.ts')
.pipe(tsProject());
return merge([ // Merge the two output streams, so this task is finished when the IO of both operations is done.
tsResult.dts.pipe(gulp.dest('release/definitions')),
tsResult.js.pipe(gulp.dest('release/js'))
]);
return gulp.src('lib/*.ts')
.pipe(tsProject())
.pipe(gulp.dest('dist'));
});

@@ -137,3 +143,3 @@

You must create the project outside of the task. You can't use the same project in multiple tasks.
Instead, create multiple projects or use a single task to compile your sources.
Instead, create multiple projects or use a single task to compile your sources. Usually it is not worth to create different tasks for the client side, backend or tests.

@@ -182,4 +188,3 @@ Using `tsconfig.json`

----------
Example of ```gulpfile.js``` which will compile typescript to javascript as well as generate
associated sourcemap.
gulp-typescript supports source maps by the usage of the gulp-sourcemaps plugin. Configuring the paths of source maps can be hard. The easiest way to get working source maps is to inline the sources of your TypeScript files in the source maps. This will of course increase the size of the source maps. The following example demonstrates this approach:

@@ -192,14 +197,34 @@ ```javascript

gulp.task('scripts', function() {
var tsResult = gulp.src('lib/*.ts')
return gulp.src('lib/*.ts')
.pipe(sourcemaps.init()) // This means sourcemaps will be generated
.pipe(ts({
// ...
}));
return tsResult.js
}))
.pipe( ... ) // You can use other plugins that also support gulp-sourcemaps
.pipe(sourcemaps.write()) // Now the sourcemaps are added to the .js file
.pipe(gulp.dest('release/js'));
.pipe(gulp.dest('dist'));
});
```
When you are not inlining the source content, you should specify the `sourceRoot` property. It can be configured with the following rule:
- If you don't provide the `outDir` option to TypeScript, the `sourceRoot` option of gulp-sourcemaps should be the relative path from the `gulp.dest` path to the source directory (from `gulp.src`)
- If you set the `outDir` option to the same value as the directory in `gulp.dest`, you should set the `sourceRoot` to `./`.
- If you set the `outDir` option to a different value, there is no easy rule to configure gulp-sourcemaps. I'd advise to change the value of outDir if possible.
Furthermore you should set `includeContent: false`. Here's an example where `outDir` isn't set:
```js
gulp.task('scripts', function() {
return gulp.src('lib/*.ts')
.pipe(sourcemaps.init())
.pipe(ts({
// ...
}))
.pipe(sourcemaps.write('.', { includeContent: false, sourceRoot: '../lib' }))
.pipe(gulp.dest('dist'));
});
```
Some examples can be found in [ivogabe/gulp-typescript-sourcemaps-demo](https://github.com/ivogabe/gulp-typescript-sourcemaps-demo).
For more information, see [gulp-sourcemaps](https://github.com/floridoo/gulp-sourcemaps).

@@ -206,0 +231,0 @@

@@ -11,3 +11,3 @@ "use strict";

*/
var ProjectCompiler = (function () {
var ProjectCompiler = /** @class */ (function () {
function ProjectCompiler() {

@@ -26,3 +26,3 @@ }

if (!this.project.input.firstSourceFile) {
this.project.output.finish(reporter_1.emptyCompilationResult());
this.project.output.finish(reporter_1.emptyCompilationResult(this.project.options.noEmit));
return;

@@ -41,3 +41,3 @@ }

this.program = this.project.typescript.createProgram(rootFilenames, this.project.options, this.host, this.program);
var result = reporter_1.emptyCompilationResult();
var result = reporter_1.emptyCompilationResult(this.project.options.noEmit);
result.optionsErrors = this.reportDiagnostics(this.program.getOptionsDiagnostics());

@@ -162,3 +162,3 @@ result.syntaxErrors = this.reportDiagnostics(this.program.getSyntacticDiagnostics());

exports.ProjectCompiler = ProjectCompiler;
var FileCompiler = (function () {
var FileCompiler = /** @class */ (function () {
function FileCompiler() {

@@ -172,3 +172,3 @@ this.output = {};

this.project.input.noParse = true;
this.compilationResult = reporter_1.emptyCompilationResult();
this.compilationResult = reporter_1.emptyCompilationResult(this.project.options.noEmit);
};

@@ -202,3 +202,3 @@ FileCompiler.prototype.write = function (file, fileName, diagnostics, content, sourceMap) {

if (mapString.substring(0, start.length) !== start) {
console.error('Couldn\'t read the sourceMap generated by TypeScript. This is likely an issue with gulp-typescript.');
console.log('Couldn\'t read the sourceMap generated by TypeScript. This is likely an issue with gulp-typescript.');
return;

@@ -205,0 +205,0 @@ }

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var utils = require("./utils");
var Host = (function () {
var Host = /** @class */ (function () {
function Host(typescript, currentDirectory, input, options) {

@@ -6,0 +6,0 @@ var _this = this;

@@ -0,4 +1,5 @@

/// <reference types="vinyl" />
import * as ts from 'typescript';
import * as utils from './utils';
import { VinylFile } from './types';
import * as VinylFile from 'vinyl';
export declare enum FileChangeState {

@@ -5,0 +6,0 @@ New = 0,

@@ -60,3 +60,3 @@ "use strict";

})(File = exports.File || (exports.File = {}));
var FileDictionary = (function () {
var FileDictionary = /** @class */ (function () {
function FileDictionary(typescript) {

@@ -142,3 +142,3 @@ this.files = {};

exports.FileDictionary = FileDictionary;
var FileCache = (function () {
var FileCache = /** @class */ (function () {
function FileCache(typescript, options) {

@@ -145,0 +145,0 @@ this.previous = undefined;

@@ -91,2 +91,4 @@ "use strict";

fileName = fileNameOrSettings;
tsConfigFileName = path.resolve(process.cwd(), fileName);
projectDirectory = path.dirname(tsConfigFileName);
if (settings === undefined)

@@ -105,5 +107,3 @@ settings = {};

compilerOptions = settingsResult.options;
if (fileName) {
tsConfigFileName = path.resolve(process.cwd(), fileNameOrSettings);
projectDirectory = path.dirname(tsConfigFileName);
if (fileName !== undefined) {
var tsConfig = typescript.readConfigFile(tsConfigFileName, typescript.sys.readFile);

@@ -110,0 +110,0 @@ if (tsConfig.error) {

@@ -5,5 +5,5 @@ "use strict";

var sourceMap = require("source-map");
var gutil = require("gulp-util");
var VinylFile = require("vinyl");
var utils = require("./utils");
var Output = (function () {
var Output = /** @class */ (function () {
function Output(_project, streamFull, streamJs, streamDts) {

@@ -16,3 +16,3 @@ this.project = _project;

Output.prototype.writeJs = function (base, fileName, content, sourceMapContent, cwd, original) {
var file = new gutil.File({
var file = new VinylFile({
path: fileName,

@@ -30,3 +30,3 @@ contents: new Buffer(content),

Output.prototype.writeDts = function (base, fileName, content, cwd) {
var file = new gutil.File({
var file = new VinylFile({
path: fileName,

@@ -86,4 +86,2 @@ contents: new Buffer(content),

this.streamFull.emit('finish');
this.streamJs.emit('finish');
this.streamDts.emit('finish');
this.streamFull.push(null);

@@ -90,0 +88,0 @@ this.streamJs.push(null);

@@ -25,3 +25,3 @@ "use strict";

var path = require("path");
var gutil = require("gulp-util");
var PluginError = require("plugin-error");
var utils = require("./utils");

@@ -99,3 +99,3 @@ var reporter_1 = require("./reporter");

}
var CompileStream = (function (_super) {
var CompileStream = /** @class */ (function (_super) {
__extends(CompileStream, _super);

@@ -120,3 +120,3 @@ function CompileStream(project) {

if (file.isStream()) {
return cb(new gutil.PluginError('gulp-typescript', 'Streaming not supported'));
return cb(new PluginError('gulp-typescript', 'Streaming not supported'));
}

@@ -143,3 +143,3 @@ var inputFile = this.project.input.addGulp(file);

}(stream.Duplex));
var CompileOutputStream = (function (_super) {
var CompileOutputStream = /** @class */ (function (_super) {
__extends(CompileOutputStream, _super);

@@ -146,0 +146,0 @@ function CompileOutputStream() {

@@ -0,3 +1,4 @@

/// <reference types="vinyl" />
import * as ts from 'typescript';
import { VinylFile } from './types';
import * as VinylFile from 'vinyl';
export interface TypeScriptError extends Error {

@@ -31,5 +32,6 @@ fullFilename?: string;

emitErrors: number;
noEmit: boolean;
emitSkipped: boolean;
}
export declare function emptyCompilationResult(): CompilationResult;
export declare function emptyCompilationResult(noEmit: boolean): CompilationResult;
export interface Reporter {

@@ -36,0 +38,0 @@ error?: (error: TypeScriptError, typescript: typeof ts) => void;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var gutil = require("gulp-util");
function emptyCompilationResult() {
var colors = require("ansi-colors");
function emptyCompilationResult(noEmit) {
return {

@@ -13,2 +13,3 @@ transpileErrors: 0,

emitErrors: 0,
noEmit: noEmit,
emitSkipped: false

@@ -23,3 +24,3 @@ };

return;
gutil.log('TypeScript:', gutil.colors.magenta(count.toString()), (type !== '' ? type + ' ' : '') + (count === 1 ? 'error' : 'errors'));
console.log('TypeScript:', colors.magenta(count.toString()), (type !== '' ? type + ' ' : '') + (count === 1 ? 'error' : 'errors'));
hasError = true;

@@ -34,8 +35,10 @@ };

showErrorCount(results.emitErrors, 'emit');
if (results.emitSkipped) {
gutil.log('TypeScript: emit', gutil.colors.red('failed'));
if (!results.noEmit) {
if (results.emitSkipped) {
console.log('TypeScript: emit', colors.red('failed'));
}
else if (hasError) {
console.log('TypeScript: emit', colors.cyan('succeeded'), '(with errors)');
}
}
else if (hasError) {
gutil.log('TypeScript: emit', gutil.colors.cyan('succeeded'), '(with errors)');
}
}

@@ -49,3 +52,3 @@ function nullReporter() {

error: function (error) {
console.error(error.message);
console.log(error.message);
},

@@ -61,3 +64,3 @@ finish: defaultFinishHandler

if (error.tsFile) {
console.error('[' + gutil.colors.gray('gulp-typescript') + '] ' + gutil.colors.red(error.fullFilename
console.log('[' + colors.gray('gulp-typescript') + '] ' + colors.red(error.fullFilename
+ '(' + error.startPosition.line + ',' + error.startPosition.character + '): ')

@@ -67,3 +70,3 @@ + 'error TS' + error.diagnostic.code + ' ' + typescript.flattenDiagnosticMessageText(error.diagnostic.messageText, '\n'));

else {
console.error(error.message);
console.log(error.message);
}

@@ -79,7 +82,7 @@ },

error: function (error, typescript) {
console.error('[' + gutil.colors.gray('gulp-typescript') + '] '
+ gutil.colors.bgRed(error.diagnostic.code + '')
+ ' ' + gutil.colors.red(typescript.flattenDiagnosticMessageText(error.diagnostic.messageText, '\n')));
console.log('[' + colors.gray('gulp-typescript') + '] '
+ colors.bgred(error.diagnostic.code + '')
+ ' ' + colors.red(typescript.flattenDiagnosticMessageText(error.diagnostic.messageText, '\n')));
if (error.tsFile) {
console.error('> ' + gutil.colors.gray('file: ') + (fullFilename ? error.fullFilename : error.relativeFilename) + gutil.colors.gray(':'));
console.log('> ' + colors.gray('file: ') + (fullFilename ? error.fullFilename : error.relativeFilename) + colors.gray(':'));
var lines_1 = error.tsFile.text.split(/(?:\r\n|\r|\n)/);

@@ -90,5 +93,5 @@ var logLine = function (lineIndex, errorStart, errorEnd) {

errorEnd = line.length;
console.error('> ' + gutil.colors.gray('[' + lineIndex + '] ')
console.log('> ' + colors.gray('[' + lineIndex + '] ')
+ line.substring(0, errorStart)
+ gutil.colors.red(line.substring(errorStart, errorEnd))
+ colors.red(line.substring(errorStart, errorEnd))
+ line.substring(errorEnd));

@@ -95,0 +98,0 @@ };

@@ -7,23 +7,1 @@ export interface TsConfig {

}
export interface VinylFile {
cwd: string;
base: string;
path: string;
stat: {};
contents: {};
sourceMap?: any;
relative: string;
isBuffer(): boolean;
isStream(): boolean;
isNull(): boolean;
isDirectory(): boolean;
}
export interface RawSourceMap {
file: string;
sourceRoot?: string;
version: number;
sources: string[];
names: string[];
sourcesContent?: string[];
mappings: string;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var path = require("path");
var gutil = require("gulp-util");
var colors = require("ansi-colors");
function forwardSlashes(fileName) {

@@ -96,3 +96,3 @@ return fileName.replace(/\\/g, '/');

};
err.message = gutil.colors.red(fileName + '(' + (startPos.line + 1) + ',' + (startPos.character + 1) + '): ').toString()
err.message = colors.red(fileName + '(' + (startPos.line + 1) + ',' + (startPos.character + 1) + '): ').toString()
+ codeAndMessageText;

@@ -104,14 +104,14 @@ return err;

message(title, alternative, description);
console.log(' ' + gutil.colors.gray('More information: ' + gutil.colors.underline('http://dev.ivogabe.com/gulp-typescript-3/')));
console.log(' ' + colors.gray('More information: ' + colors.underline('http://dev.ivogabe.com/gulp-typescript-3/')));
}
exports.deprecate = deprecate;
function message(title, alternative, description) {
console.log(gutil.colors.red('gulp-typescript').toString() +
gutil.colors.gray(': ') +
console.log(colors.red('gulp-typescript').toString() +
colors.gray(': ') +
title +
gutil.colors.gray(' - ') +
colors.gray(' - ') +
alternative);
if (description)
console.log(' ' + gutil.colors.gray(description.replace(/\n/g, '\n ')));
console.log(' ' + colors.gray(description.replace(/\n/g, '\n ')));
}
exports.message = message;

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc