aboutsummaryrefslogtreecommitdiff
path: root/node_modules/vinyl-fs/lib/src
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2016-10-10 03:43:44 +0200
committerFlorian Dold <florian.dold@gmail.com>2016-10-10 03:43:44 +0200
commitabd94a7f5a50f43c797a11b53549ae48fff667c3 (patch)
treeab8ed457f65cdd72e13e0571d2975729428f1551 /node_modules/vinyl-fs/lib/src
parenta0247c6a3fd6a09a41a7e35a3441324c4dcb58be (diff)
add node_modules to address #4364
Diffstat (limited to 'node_modules/vinyl-fs/lib/src')
-rw-r--r--node_modules/vinyl-fs/lib/src/getContents/bufferFile.js22
-rw-r--r--node_modules/vinyl-fs/lib/src/getContents/index.js31
-rw-r--r--node_modules/vinyl-fs/lib/src/getContents/readDir.js8
-rw-r--r--node_modules/vinyl-fs/lib/src/getContents/readSymbolicLink.js18
-rw-r--r--node_modules/vinyl-fs/lib/src/getContents/streamFile.js26
-rw-r--r--node_modules/vinyl-fs/lib/src/index.js62
-rw-r--r--node_modules/vinyl-fs/lib/src/wrapWithVinylFile.js51
7 files changed, 218 insertions, 0 deletions
diff --git a/node_modules/vinyl-fs/lib/src/getContents/bufferFile.js b/node_modules/vinyl-fs/lib/src/getContents/bufferFile.js
new file mode 100644
index 000000000..894dd9cea
--- /dev/null
+++ b/node_modules/vinyl-fs/lib/src/getContents/bufferFile.js
@@ -0,0 +1,22 @@
+'use strict';
+
+var fs = require('graceful-fs');
+var stripBom = require('strip-bom');
+
+function bufferFile(file, opt, cb) {
+ fs.readFile(file.path, function(err, data) {
+ if (err) {
+ return cb(err);
+ }
+
+ if (opt.stripBOM) {
+ file.contents = stripBom(data);
+ } else {
+ file.contents = data;
+ }
+
+ cb(null, file);
+ });
+}
+
+module.exports = bufferFile;
diff --git a/node_modules/vinyl-fs/lib/src/getContents/index.js b/node_modules/vinyl-fs/lib/src/getContents/index.js
new file mode 100644
index 000000000..c1c8c159d
--- /dev/null
+++ b/node_modules/vinyl-fs/lib/src/getContents/index.js
@@ -0,0 +1,31 @@
+'use strict';
+
+var through2 = require('through2');
+var readDir = require('./readDir');
+var readSymbolicLink = require('./readSymbolicLink');
+var bufferFile = require('./bufferFile');
+var streamFile = require('./streamFile');
+
+function getContents(opt) {
+ return through2.obj(opt, function(file, enc, cb) {
+ // Don't fail to read a directory
+ if (file.isDirectory()) {
+ return readDir(file, opt, cb);
+ }
+
+ // Process symbolic links included with `followSymlinks` option
+ if (file.stat && file.stat.isSymbolicLink()) {
+ return readSymbolicLink(file, opt, cb);
+ }
+
+ // Read and pass full contents
+ if (opt.buffer !== false) {
+ return bufferFile(file, opt, cb);
+ }
+
+ // Don't buffer anything - just pass streams
+ return streamFile(file, opt, cb);
+ });
+}
+
+module.exports = getContents;
diff --git a/node_modules/vinyl-fs/lib/src/getContents/readDir.js b/node_modules/vinyl-fs/lib/src/getContents/readDir.js
new file mode 100644
index 000000000..a800d4738
--- /dev/null
+++ b/node_modules/vinyl-fs/lib/src/getContents/readDir.js
@@ -0,0 +1,8 @@
+'use strict';
+
+function readDir(file, opt, cb) {
+ // Do nothing for now
+ cb(null, file);
+}
+
+module.exports = readDir;
diff --git a/node_modules/vinyl-fs/lib/src/getContents/readSymbolicLink.js b/node_modules/vinyl-fs/lib/src/getContents/readSymbolicLink.js
new file mode 100644
index 000000000..794077a62
--- /dev/null
+++ b/node_modules/vinyl-fs/lib/src/getContents/readSymbolicLink.js
@@ -0,0 +1,18 @@
+'use strict';
+
+var fs = require('graceful-fs');
+
+function readLink(file, opt, cb) {
+ fs.readlink(file.path, function(err, target) {
+ if (err) {
+ return cb(err);
+ }
+
+ // Store the link target path
+ file.symlink = target;
+
+ return cb(null, file);
+ });
+}
+
+module.exports = readLink;
diff --git a/node_modules/vinyl-fs/lib/src/getContents/streamFile.js b/node_modules/vinyl-fs/lib/src/getContents/streamFile.js
new file mode 100644
index 000000000..43dc12635
--- /dev/null
+++ b/node_modules/vinyl-fs/lib/src/getContents/streamFile.js
@@ -0,0 +1,26 @@
+'use strict';
+
+var fs = require('graceful-fs');
+var stripBom = require('strip-bom-stream');
+var lazystream = require('lazystream');
+
+function streamFile(file, opt, cb) {
+ if (typeof opt === 'function') {
+ cb = opt;
+ opt = {};
+ }
+
+ var filePath = file.path;
+
+ file.contents = new lazystream.Readable(function() {
+ return fs.createReadStream(filePath);
+ });
+
+ if (opt.stripBOM) {
+ file.contents = file.contents.pipe(stripBom());
+ }
+
+ cb(null, file);
+}
+
+module.exports = streamFile;
diff --git a/node_modules/vinyl-fs/lib/src/index.js b/node_modules/vinyl-fs/lib/src/index.js
new file mode 100644
index 000000000..06cbe754d
--- /dev/null
+++ b/node_modules/vinyl-fs/lib/src/index.js
@@ -0,0 +1,62 @@
+'use strict';
+
+var assign = require('object-assign');
+var through2 = require('through2');
+var gs = require('glob-stream');
+var duplexify = require('duplexify');
+var merge = require('merge-stream');
+var sourcemaps = require('gulp-sourcemaps');
+var filterSince = require('../filterSince');
+var isValidGlob = require('is-valid-glob');
+
+var getContents = require('./getContents');
+var wrapWithVinylFile = require('./wrapWithVinylFile');
+
+function src(glob, opt) {
+ var options = assign({
+ read: true,
+ buffer: true,
+ stripBOM: true,
+ sourcemaps: false,
+ passthrough: false,
+ followSymlinks: true,
+ }, opt);
+
+ // Don't pass `read` option on to through2
+ var read = options.read !== false;
+ options.read = undefined;
+
+ var inputPass;
+
+ if (!isValidGlob(glob)) {
+ throw new Error('Invalid glob argument: ' + glob);
+ }
+
+ var globStream = gs.create(glob, options);
+
+ var outputStream = globStream
+ .pipe(wrapWithVinylFile(options));
+
+ if (options.since != null) {
+ outputStream = outputStream
+ .pipe(filterSince(options.since));
+ }
+
+ if (read) {
+ outputStream = outputStream
+ .pipe(getContents(options));
+ }
+
+ if (options.passthrough === true) {
+ inputPass = through2.obj(options);
+ outputStream = duplexify.obj(inputPass, merge(outputStream, inputPass));
+ }
+ if (options.sourcemaps === true) {
+ outputStream = outputStream
+ .pipe(sourcemaps.init({ loadMaps: true }));
+ }
+ globStream.on('error', outputStream.emit.bind(outputStream, 'error'));
+ return outputStream;
+}
+
+module.exports = src;
diff --git a/node_modules/vinyl-fs/lib/src/wrapWithVinylFile.js b/node_modules/vinyl-fs/lib/src/wrapWithVinylFile.js
new file mode 100644
index 000000000..5e6290e59
--- /dev/null
+++ b/node_modules/vinyl-fs/lib/src/wrapWithVinylFile.js
@@ -0,0 +1,51 @@
+'use strict';
+
+var through2 = require('through2');
+var fs = require('graceful-fs');
+var File = require('vinyl');
+
+function wrapWithVinylFile(options) {
+
+ // A stat property is exposed on file objects as a (wanted) side effect
+ function resolveFile(globFile, enc, cb) {
+ fs.lstat(globFile.path, function(err, stat) {
+ if (err) {
+ return cb(err);
+ }
+
+ globFile.stat = stat;
+
+ if (!stat.isSymbolicLink() || !options.followSymlinks) {
+ var vinylFile = new File(globFile);
+ if (globFile.originalSymlinkPath) {
+ // If we reach here, it means there is at least one
+ // symlink on the path and we need to rewrite the path
+ // to its original value.
+ // Updated file stats will tell getContents() to actually read it.
+ vinylFile.path = globFile.originalSymlinkPath;
+ }
+ return cb(null, vinylFile);
+ }
+
+ fs.realpath(globFile.path, function(err, filePath) {
+ if (err) {
+ return cb(err);
+ }
+
+ if (!globFile.originalSymlinkPath) {
+ // Store the original symlink path before the recursive call
+ // to later rewrite it back.
+ globFile.originalSymlinkPath = globFile.path;
+ }
+ globFile.path = filePath;
+
+ // Recurse to get real file stat
+ resolveFile(globFile, enc, cb);
+ });
+ });
+ }
+
+ return through2.obj(options, resolveFile);
+}
+
+module.exports = wrapWithVinylFile;