Comparing version 0.9.17 to 1.0.0
@@ -5,42 +5,27 @@ /* jshint node: true, strict: true */ | ||
var jsdom = require("jsdom"); | ||
var PluginError = require('plugin-error'); | ||
var through2 = require("through2"); | ||
var pluginName = "gulp-dom"; | ||
var jsdom = require("jsdom"), | ||
utils = require("gulp-util"), | ||
PluginError = utils.PluginError, | ||
through2 = require("through2"), | ||
pluginName = "gulp-dom"; | ||
module.exports = function (mutator) { | ||
var stream = through2.obj(function(file, enc, callback) { | ||
if (file.isNull()) { | ||
return callback(null, file); | ||
} | ||
if (file.isNull()) { | ||
return callback(null, file); | ||
} | ||
if (file.isStream()) { | ||
return stream.emit("error", new PluginError(pluginName, "Streaming not supported")); | ||
} | ||
if (file.isStream()) { | ||
return stream.emit("error", new PluginError(pluginName, "Streaming not supported")); | ||
} | ||
if (file.isBuffer()) { | ||
if (file.isBuffer()) { | ||
var dom = new jsdom.JSDOM(file.contents.toString("utf8")); | ||
var mutated = mutator.call(dom.window.document); | ||
jsdom.env({ | ||
html: file.contents.toString("utf8"), | ||
done: function (errors, window) { | ||
if (errors) { | ||
return stream.emit("error", new PluginError(pluginName, "Error parsing document: " + file.path)); | ||
} | ||
file.contents = Buffer.from(typeof mutated === 'string' ? mutated : dom.serialize()); | ||
callback(null, file); | ||
var mutated = mutator.call(window.document); | ||
file.contents = new Buffer(typeof mutated === 'string' ? mutated : jsdom.serializeDocument(mutated)); | ||
callback(null, file); | ||
window.close(); | ||
} | ||
}); | ||
dom.window.close(); | ||
} | ||
}); | ||
@@ -47,0 +32,0 @@ |
{ | ||
"name": "gulp-dom", | ||
"version": "0.9.17", | ||
"version": "1.0.0", | ||
"description": "Gulp plugin for generic DOM manipulation", | ||
@@ -27,16 +27,16 @@ "main": "lib/dom.js", | ||
"devDependencies": { | ||
"jshint": "2.9.4", | ||
"mocha": "3.1.2", | ||
"request": "2.79.0", | ||
"jshint": "2.9.6", | ||
"mocha": "5.2.0", | ||
"request": "2.88.0", | ||
"dom-whitespace": "0.1.2", | ||
"vinyl-source-stream": "1.1.0", | ||
"vinyl-buffer": "1.0.0", | ||
"chai": "3.5.0", | ||
"gulp": "3.9.1" | ||
"vinyl-source-stream": "2.0.0", | ||
"vinyl-buffer": "1.0.1", | ||
"chai": "4.2.0", | ||
"gulp": "4.0.0" | ||
}, | ||
"dependencies": { | ||
"jsdom": "9.8.3", | ||
"gulp-util": "3.0.7", | ||
"through2": "2.0.1" | ||
"jsdom": "12.2.0", | ||
"plugin-error": "1.0.1", | ||
"through2": "2.0.3" | ||
} | ||
} |
@@ -7,4 +7,4 @@ # gulp-dom | ||
This [Gulp](http://gulpjs.com/) plugin is a simple wrapper around | ||
[jsdom](https://github.com/tmpvar/jsdom) making it possible to run DOM | ||
This [Gulp](http://gulpjs.com/) plugin is a simple wrapper around | ||
[jsdom](https://github.com/tmpvar/jsdom) making it possible to run DOM | ||
operations on any inbound HTML. | ||
@@ -22,3 +22,2 @@ | ||
## Installation | ||
@@ -31,22 +30,5 @@ | ||
### Note | ||
[Jsdom version 6.0.0](https://github.com/tmpvar/jsdom/blob/master/Changelog.md#600) | ||
require io.js version 2.0.0 or newer. Version 0.6.0 of this | ||
plugin depend on [jsdom version 6.0.0](https://github.com/tmpvar/jsdom/blob/master/Changelog.md#600) | ||
and therefor require io.js version 2.0.0 or newer. | ||
[Jsdom version 4.0.0](https://github.com/tmpvar/jsdom/blob/master/Changelog.md#400) | ||
does not support Node.js™ and requires io.js. Version 0.4.0 of this | ||
plugin depend on [jsdom version 4.0.0](https://github.com/tmpvar/jsdom/blob/master/Changelog.md#400) | ||
and therefor require io.js. | ||
For a working version of this plugin which works with Node.js™, please use | ||
version 0.3.x or older. | ||
## Basic example | ||
Example on adding a `data` attribute with a version number on the `body` tag of | ||
Example on adding a `data` attribute with a version number on the `body` tag of | ||
a HTML document: | ||
@@ -68,3 +50,2 @@ | ||
## Usage | ||
@@ -82,6 +63,6 @@ | ||
The plugin will take the provided HTML and parse it into a DOM document. The DOM | ||
The plugin will take the provided HTML and parse it into a DOM document. The DOM | ||
document is then set as `this` on the mutator function. | ||
A value must be returned by the mutator function and it is this returned value | ||
A value must be returned by the mutator function and it is this returned value | ||
which will be passed on to the next step in the gulp chain. | ||
@@ -101,3 +82,3 @@ | ||
By default it is expected that the mutator function returns a DOM document, but | ||
By default it is expected that the mutator function returns a DOM document, but | ||
any `String` value can be returned. If the default is being used, the returned | ||
@@ -107,7 +88,6 @@ DOM document will be serialized into a HTML document. | ||
If the mutator function shall return something else than a DOM document its | ||
important that serialization is turned off. Please see the | ||
important that serialization is turned off. Please see the | ||
[serialize attribute](#serialize) for further information. | ||
### serialize | ||
@@ -138,15 +118,13 @@ | ||
## A note on jsdom | ||
This plugin wraps [jsdom](https://github.com/tmpvar/jsdom). Though, this plugin | ||
does not enable all features provided by jsdom. The sole purpose for jsdom in | ||
does not enable all features provided by jsdom. The sole purpose for jsdom in | ||
this plugin is to parse a HTML document into a DOM so we can run operations on | ||
it. | ||
Features such as injecting scripts into the DOM which jsdom can do is not | ||
Features such as injecting scripts into the DOM which jsdom can do is not | ||
enabled in this plugin. | ||
## Tests | ||
@@ -158,8 +136,7 @@ | ||
Tests are written in [mocha](http://visionmedia.github.io/mocha/). | ||
Tests are written in [mocha](http://mochajs.org/). | ||
## License | ||
## License | ||
The MIT License (MIT) | ||
@@ -166,0 +143,0 @@ |
@@ -6,6 +6,4 @@ /* jshint node: true, strict: true */ | ||
var mocha = require('mocha'), | ||
assert = require('chai').assert, | ||
utils = require('gulp-util'), | ||
jsdom = require('jsdom'), | ||
var assert = require('chai').assert, | ||
Vinyl = require('vinyl'), | ||
dom = require('../'); | ||
@@ -16,7 +14,7 @@ | ||
function createFixture(markup) { | ||
return new utils.File({ | ||
return new Vinyl({ | ||
cwd: './', | ||
base: './', | ||
path: './', | ||
contents: new Buffer(markup) | ||
contents: Buffer.from(markup) | ||
}); | ||
@@ -34,4 +32,4 @@ } | ||
var mockFile = { | ||
isNull: function() { | ||
return true; | ||
isNull: function() { | ||
return true; | ||
} | ||
@@ -51,10 +49,10 @@ }; | ||
var mockFile = { | ||
isNull: function () { | ||
return false; | ||
isNull: function () { | ||
return false; | ||
}, | ||
isStream: function () { | ||
return true; | ||
isStream: function () { | ||
return true; | ||
} | ||
}; | ||
stream.on('error', function (err) { | ||
@@ -64,3 +62,3 @@ assert.equal(err.message, 'Streaming not supported'); | ||
}); | ||
stream.write(mockFile); | ||
@@ -67,0 +65,0 @@ }); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1
16137
19
218
154
+ Addedplugin-error@1.0.1
+ Addedabab@2.0.6(transitive)
+ Addedacorn@6.4.2(transitive)
+ Addedacorn-globals@4.3.4(transitive)
+ Addedacorn-walk@6.2.0(transitive)
+ Addedansi-colors@1.1.0(transitive)
+ Addedarr-diff@4.0.0(transitive)
+ Addedarr-union@3.1.0(transitive)
+ Addedassign-symbols@1.0.0(transitive)
+ Addedasync-limiter@1.0.1(transitive)
+ Addedbrowser-process-hrtime@1.0.0(transitive)
+ Addedcssstyle@1.4.0(transitive)
+ Addeddata-urls@1.1.0(transitive)
+ Addeddomexception@1.0.1(transitive)
+ Addedextend-shallow@3.0.2(transitive)
+ Addedis-extendable@1.0.1(transitive)
+ Addedis-plain-object@2.0.4(transitive)
+ Addedisobject@3.0.1(transitive)
+ Addedjsdom@12.2.0(transitive)
+ Addedlodash@4.17.21(transitive)
+ Addedlodash.sortby@4.7.0(transitive)
+ Addednwsapi@2.2.13(transitive)
+ Addedparse5@5.1.0(transitive)
+ Addedplugin-error@1.0.1(transitive)
+ Addedpn@1.1.0(transitive)
+ Addedprocess-nextick-args@2.0.1(transitive)
+ Addedreadable-stream@2.3.8(transitive)
+ Addedrequest-promise-core@1.1.4(transitive)
+ Addedrequest-promise-native@1.0.9(transitive)
+ Addedsafe-buffer@5.1.2(transitive)
+ Addedsaxes@3.1.11(transitive)
+ Addedstealthy-require@1.1.1(transitive)
+ Addedstring_decoder@1.1.1(transitive)
+ Addedthrough2@2.0.3(transitive)
+ Addedtr46@1.0.1(transitive)
+ Addedw3c-hr-time@1.0.2(transitive)
+ Addedwebidl-conversions@4.0.2(transitive)
+ Addedwhatwg-mimetype@2.3.0(transitive)
+ Addedwhatwg-url@7.1.0(transitive)
+ Addedws@6.2.3(transitive)
+ Addedxml-name-validator@3.0.0(transitive)
+ Addedxmlchars@2.2.0(transitive)
- Removedgulp-util@3.0.7
- Removedabab@1.0.4(transitive)
- Removedacorn@2.7.0(transitive)
- Removedacorn-globals@1.0.9(transitive)
- Removedansi-gray@0.1.1(transitive)
- Removedansi-regex@2.1.1(transitive)
- Removedansi-styles@2.2.1(transitive)
- Removedarray-differ@1.0.0(transitive)
- Removedarray-find-index@1.0.2(transitive)
- Removedarray-uniq@1.0.3(transitive)
- Removedbeeper@1.1.1(transitive)
- Removedcamelcase@2.1.1(transitive)
- Removedcamelcase-keys@2.1.0(transitive)
- Removedchalk@1.1.3(transitive)
- Removedclone@1.0.4(transitive)
- Removedclone-stats@0.0.1(transitive)
- Removedcolor-support@1.1.3(transitive)
- Removedcontent-type-parser@1.0.2(transitive)
- Removedcssstyle@0.2.37(transitive)
- Removedcurrently-unhandled@0.4.1(transitive)
- Removeddateformat@1.0.12(transitive)
- Removeddecamelize@1.2.0(transitive)
- Removedduplexer2@0.0.2(transitive)
- Removederror-ex@1.3.2(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedfancy-log@1.3.3(transitive)
- Removedfind-up@1.1.2(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedget-stdin@4.0.1(transitive)
- Removedglogg@1.0.2(transitive)
- Removedgraceful-fs@4.2.11(transitive)
- Removedgulp-util@3.0.7(transitive)
- Removedgulplog@1.0.0(transitive)
- Removedhas-ansi@2.0.0(transitive)
- Removedhas-gulplog@0.1.0(transitive)
- Removedhasown@2.0.2(transitive)
- Removedhosted-git-info@2.8.9(transitive)
- Removedindent-string@2.1.0(transitive)
- Removedis-arrayish@0.2.1(transitive)
- Removedis-core-module@2.15.1(transitive)
- Removedis-finite@1.1.0(transitive)
- Removedis-utf8@0.2.1(transitive)
- Removedisarray@0.0.1(transitive)
- Removedjsdom@9.8.3(transitive)
- Removedload-json-file@1.1.0(transitive)
- Removedlodash._basecopy@3.0.1(transitive)
- Removedlodash._basetostring@3.0.1(transitive)
- Removedlodash._basevalues@3.0.0(transitive)
- Removedlodash._getnative@3.9.1(transitive)
- Removedlodash._isiterateecall@3.0.9(transitive)
- Removedlodash._reescape@3.0.0(transitive)
- Removedlodash._reevaluate@3.0.0(transitive)
- Removedlodash._reinterpolate@3.0.0(transitive)
- Removedlodash._root@3.0.1(transitive)
- Removedlodash.escape@3.2.0(transitive)
- Removedlodash.isarguments@3.1.0(transitive)
- Removedlodash.isarray@3.0.4(transitive)
- Removedlodash.keys@3.1.2(transitive)
- Removedlodash.restparam@3.6.1(transitive)
- Removedlodash.template@3.6.2(transitive)
- Removedlodash.templatesettings@3.1.1(transitive)
- Removedloud-rejection@1.6.0(transitive)
- Removedmap-obj@1.0.1(transitive)
- Removedmeow@3.7.0(transitive)
- Removedminimist@1.2.8(transitive)
- Removedmultipipe@0.1.2(transitive)
- Removednormalize-package-data@2.5.0(transitive)
- Removednwmatcher@1.4.4(transitive)
- Removedobject-assign@3.0.04.1.1(transitive)
- Removedparse-json@2.2.0(transitive)
- Removedparse-node-version@1.0.1(transitive)
- Removedparse5@1.5.1(transitive)
- Removedpath-exists@2.1.0(transitive)
- Removedpath-parse@1.0.7(transitive)
- Removedpath-type@1.1.0(transitive)
- Removedpify@2.3.0(transitive)
- Removedpinkie@2.0.4(transitive)
- Removedpinkie-promise@2.0.1(transitive)
- Removedprocess-nextick-args@1.0.7(transitive)
- Removedread-pkg@1.1.0(transitive)
- Removedread-pkg-up@1.0.1(transitive)
- Removedreadable-stream@1.1.142.0.6(transitive)
- Removedredent@1.0.0(transitive)
- Removedrepeating@2.0.1(transitive)
- Removedreplace-ext@0.0.1(transitive)
- Removedresolve@1.22.8(transitive)
- Removedsax@1.4.1(transitive)
- Removedsemver@5.7.2(transitive)
- Removedsignal-exit@3.0.7(transitive)
- Removedsparkles@1.0.1(transitive)
- Removedspdx-correct@3.2.0(transitive)
- Removedspdx-exceptions@2.5.0(transitive)
- Removedspdx-expression-parse@3.0.1(transitive)
- Removedspdx-license-ids@3.0.20(transitive)
- Removedstring_decoder@0.10.31(transitive)
- Removedstrip-ansi@3.0.1(transitive)
- Removedstrip-bom@2.0.0(transitive)
- Removedstrip-indent@1.0.1(transitive)
- Removedsupports-color@2.0.0(transitive)
- Removedsupports-preserve-symlinks-flag@1.0.0(transitive)
- Removedthrough2@2.0.1(transitive)
- Removedtime-stamp@1.1.0(transitive)
- Removedtr46@0.0.3(transitive)
- Removedtrim-newlines@1.0.0(transitive)
- Removedvalidate-npm-package-license@3.0.4(transitive)
- Removedvinyl@0.5.3(transitive)
- Removedwebidl-conversions@3.0.1(transitive)
- Removedwhatwg-url@3.1.0(transitive)
- Removedxml-name-validator@2.0.1(transitive)
Updatedjsdom@12.2.0
Updatedthrough2@2.0.3