Skip to content

Commit

Permalink
Migrate away from deprecated gulp-util
Browse files Browse the repository at this point in the history
Fixes #46
  • Loading branch information
Kagami committed Dec 29, 2017
1 parent edeac0f commit 002e043
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"use strict";

var gutil = require("gulp-util");
var through = require("through2");
var ngAnnotate = require("ng-annotate");
var applySourceMap = require("vinyl-sourcemaps-apply");
var merge = require("merge");
var BufferStreams = require("bufferstreams");
var PluginError = require("plugin-error");

var PLUGIN_NAME = "gulp-ng-annotate";

Expand All @@ -17,7 +17,7 @@ function transform(file, input, opts) {
if (file.path) {
filename = file.relative + ": ";
}
throw new gutil.PluginError(PLUGIN_NAME, filename + res.errors.join("\n"));
throw new PluginError(PLUGIN_NAME, filename + res.errors.join("\n"));
}

if (opts.map && file.sourceMap) {
Expand Down Expand Up @@ -63,7 +63,7 @@ module.exports = function (options) {
// Dealing with stream input.
} else {
file.contents = file.contents.pipe(new BufferStreams(function(err, buf, cb) {
if (err) return cb(new gutil.PluginError(PLUGIN_NAME, err));
if (err) return cb(new PluginError(PLUGIN_NAME, err));
try {
var transformed = transform(file, buf, opts)
} catch (e) {
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@
"homepage": "https://github.com/Kagami/gulp-ng-annotate",
"dependencies": {
"bufferstreams": "^1.1.0",
"gulp-util": "^3.0.7",
"merge": "^1.2.0",
"ng-annotate": "^1.2.1",
"plugin-error": "^0.1.2",
"through2": "^2.0.1",
"vinyl-sourcemaps-apply": "^0.2.1"
},
"devDependencies": {
"gulp-sourcemaps": "*",
"mocha": "*"
"mocha": "*",
"vinyl": "^2.1.0"
}
}
25 changes: 13 additions & 12 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

var Readable = require("stream").Readable;
var assert = require("assert");
var gutil = require("gulp-util");
var ngAnnotate = require("./index");
var sourcemaps = require("gulp-sourcemaps");
var Vinyl = require("vinyl");
var PluginError = require("plugin-error");

var ORIGINAL = 'angular.module("test"); m.directive("foo", function($a, $b) {});';
var TRANSFORMED = 'angular.module("test"); m.directive("foo", ["$a", "$b", function($a, $b) {}]);';
Expand All @@ -19,7 +20,7 @@ describe("gulp-ng-annotate", function() {
done();
});

stream.write(new gutil.File({contents: new Buffer(ORIGINAL)}));
stream.write(new Vinyl({contents: new Buffer(ORIGINAL)}));
});

it("should not touch already annotated declarations", function (done) {
Expand All @@ -30,16 +31,16 @@ describe("gulp-ng-annotate", function() {
done();
});

stream.write(new gutil.File({contents: new Buffer(TRANSFORMED)}));
stream.write(new Vinyl({contents: new Buffer(TRANSFORMED)}));
});

it("should emit PluginError on bad input", function (done) {
var stream = ngAnnotate();

try {
stream.write(new gutil.File({contents: new Buffer(BAD_INPUT)}));
stream.write(new Vinyl({contents: new Buffer(BAD_INPUT)}));
} catch (err) {
assert(err instanceof gutil.PluginError);
assert(err instanceof PluginError);
assert.equal(err.message.slice(0, 7), "error: ")
done();
}
Expand All @@ -53,24 +54,24 @@ describe("gulp-ng-annotate", function() {
done();
});

stream.write(new gutil.File({contents: new Buffer(TRANSFORMED)}));
stream.write(new Vinyl({contents: new Buffer(TRANSFORMED)}));
});

it("should show filename on error", function (done) {
var stream = ngAnnotate();

try {
stream.write(new gutil.File({path: "1.js", contents: new Buffer(BAD_INPUT)}));
stream.write(new Vinyl({path: "1.js", contents: new Buffer(BAD_INPUT)}));
} catch (err) {
assert(err instanceof gutil.PluginError);
assert(err instanceof PluginError);
assert.equal(err.message.slice(0, 13), "1.js: error: ")
done();
}
});

it("should support source maps", function (done) {
var stream = sourcemaps.init()
stream.write(new gutil.File({path: "1.js", contents: new Buffer(ORIGINAL)}));
stream.write(new Vinyl({path: "1.js", contents: new Buffer(ORIGINAL)}));
stream.pipe(ngAnnotate()).on("data", function (data) {
assert.equal(data.contents.toString(), TRANSFORMED);
assert.deepEqual(data.sourceMap.sourcesContent, [ORIGINAL]);
Expand All @@ -81,7 +82,7 @@ describe("gulp-ng-annotate", function() {

it("should allow to skip source map generation", function (done) {
var stream = sourcemaps.init()
stream.write(new gutil.File({path: "1.js", contents: new Buffer(ORIGINAL)}));
stream.write(new Vinyl({path: "1.js", contents: new Buffer(ORIGINAL)}));
stream.pipe(ngAnnotate({map: false})).on("data", function (data) {
assert.equal(data.sourceMap.mappings, "");
done();
Expand All @@ -90,7 +91,7 @@ describe("gulp-ng-annotate", function() {

it("should preserve file attribute in the sourcemap object", function (done) {
var stream = sourcemaps.init()
stream.write(new gutil.File({path: "1.js", contents: new Buffer(ORIGINAL)}));
stream.write(new Vinyl({path: "1.js", contents: new Buffer(ORIGINAL)}));
stream.pipe(ngAnnotate()).on("data", function (data) {
assert.equal(data.sourceMap.file, "1.js");
done();
Expand All @@ -110,6 +111,6 @@ describe("gulp-ng-annotate", function() {
});
});

stream.write(new gutil.File({contents: contentsStream}));
stream.write(new Vinyl({contents: contentsStream}));
});
});

0 comments on commit 002e043

Please sign in to comment.