forked from public/fvtt-cthulhu-eternal
Initial import with skill sheet working
This commit is contained in:
21
node_modules/vinyl-fs/LICENSE
generated
vendored
Normal file
21
node_modules/vinyl-fs/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013-2020, 2023 Blaine Bublitz <blaine.bublitz@gmail.com> and Eric Schoffstall <yo@contra.io>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
366
node_modules/vinyl-fs/README.md
generated
vendored
Normal file
366
node_modules/vinyl-fs/README.md
generated
vendored
Normal file
@@ -0,0 +1,366 @@
|
||||
<p align="center">
|
||||
<a href="https://gulpjs.com">
|
||||
<img height="257" width="114" src="https://raw.githubusercontent.com/gulpjs/artwork/master/gulp-2x.png">
|
||||
</a>
|
||||
</p>
|
||||
|
||||
# vinyl-fs
|
||||
|
||||
[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][ci-image]][ci-url] [![Coveralls Status][coveralls-image]][coveralls-url]
|
||||
|
||||
[Vinyl][vinyl] adapter for the file system.
|
||||
|
||||
## What is Vinyl?
|
||||
|
||||
[Vinyl][vinyl] is a very simple metadata object that describes a file. When you think of a file, two attributes come to mind: `path` and `contents`. These are the main attributes on a [Vinyl][vinyl] object. A file does not necessarily represent something on your computer’s file system. You have files on S3, FTP, Dropbox, Box, CloudThingly.io and other services. [Vinyl][vinyl] can be used to describe files from all of these sources.
|
||||
|
||||
## What is a Vinyl Adapter?
|
||||
|
||||
While Vinyl provides a clean way to describe a file, we now need a way to access these files. Each file source needs what we call a "Vinyl adapter". A Vinyl adapter simply exposes a `src(globs)` and a `dest(folder)` method. Each return a stream. The `src` stream produces Vinyl objects, and the `dest` stream consumes Vinyl objects. Vinyl adapters can expose extra methods that might be specific to their input/output medium, such as the `symlink` method `vinyl-fs` provides.
|
||||
|
||||
## Usage
|
||||
|
||||
```javascript
|
||||
var map = require('map-stream');
|
||||
var vfs = require('vinyl-fs');
|
||||
|
||||
var log = function (file, cb) {
|
||||
console.log(file.path);
|
||||
cb(null, file);
|
||||
};
|
||||
|
||||
vfs
|
||||
.src(['./js/**/*.js', '!./js/vendor/*.js'])
|
||||
.pipe(map(log))
|
||||
.pipe(vfs.dest('./output'));
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### `src(globs[, options])`
|
||||
|
||||
Takes a glob string or an array of glob strings as the first argument and an options object as the second.
|
||||
Returns a stream of [vinyl] `File` objects.
|
||||
|
||||
**Note: UTF-8 BOM will be removed from all UTF-8 files read with `.src` unless disabled in the options.**
|
||||
|
||||
#### Globs
|
||||
|
||||
Globs are executed in order, so negations should follow positive globs.
|
||||
|
||||
For example:
|
||||
|
||||
```js
|
||||
fs.src(['!b*', '*']);
|
||||
```
|
||||
|
||||
would not exclude any files, but the following would exclude all files starting with "b":
|
||||
|
||||
```js
|
||||
fs.src(['*', '!b*']);
|
||||
```
|
||||
|
||||
#### Options
|
||||
|
||||
- Values passed to the options must be of the expected type, otherwise they will be ignored.
|
||||
- All options can be passed a function instead of a value. The function will be called with the [vinyl] `File` object as its only argument and must return a value of the expected type for that option.
|
||||
|
||||
##### `options.buffer`
|
||||
|
||||
Whether or not you want to buffer the file contents into memory. Setting to `false` will make `file.contents` a paused Stream.
|
||||
|
||||
Type: `Boolean`
|
||||
|
||||
Default: `true`
|
||||
|
||||
##### `options.read`
|
||||
|
||||
Whether or not you want the file to be read at all. Useful for stuff like removing files. Setting to `false` will make `file.contents = null` and will disable writing the file to disk via `.dest()`.
|
||||
|
||||
Type: `Boolean`
|
||||
|
||||
Default: `true`
|
||||
|
||||
##### `options.since`
|
||||
|
||||
Only streams files that have been modified since the time specified.
|
||||
|
||||
Type: `Date` or `Number`
|
||||
|
||||
Default: `undefined`
|
||||
|
||||
##### `options.removeBOM`
|
||||
|
||||
Causes the BOM to be removed on UTF-8 encoded files. Set to `false` if you need the BOM for some reason.
|
||||
|
||||
Type: `Boolean`
|
||||
|
||||
Default: `true`
|
||||
|
||||
##### `options.encoding`
|
||||
|
||||
Optionally transcode from the given encoding. The default is `'utf8'`. We use
|
||||
[iconv-lite], please refer to its Wiki for a list of supported encodings. You
|
||||
can set this to `false` to avoid any transcoding, and effectively just pass
|
||||
around raw binary data.
|
||||
|
||||
Type: `String` or `Boolean`
|
||||
|
||||
Default: `'utf8'`
|
||||
|
||||
##### `options.sourcemaps`
|
||||
|
||||
Enables sourcemap support on files passed through the stream. Will load inline sourcemaps and resolve sourcemap links from files.
|
||||
|
||||
Type: `Boolean`
|
||||
|
||||
Default: `false`
|
||||
|
||||
##### `options.resolveSymlinks`
|
||||
|
||||
Whether or not to recursively resolve symlinks to their targets. Set to `false` to preserve them as symlinks and make `file.symlink` equal the original symlink's target path.
|
||||
|
||||
Type: `Boolean`
|
||||
|
||||
Default: `true`
|
||||
|
||||
##### `options.dot`
|
||||
|
||||
Whether or not you want globs to match on dot files (e.g. `.gitignore`).
|
||||
|
||||
**Note: This option is not resolved from a function because it is passed verbatim to anymatch.**
|
||||
|
||||
Type: `Boolean`
|
||||
|
||||
Default: `false`
|
||||
|
||||
##### other
|
||||
|
||||
Any glob-related options are documented in [glob-stream] and [anymatch] and are forwarded verbatim.
|
||||
|
||||
### `dest(folder[, options])`
|
||||
|
||||
Takes a folder path string or a function as the first argument and an options object as the second. If given a function, it will be called with each [vinyl] `File` object and must return a folder path.
|
||||
Returns a stream that accepts [vinyl] `File` objects, writes them to disk at the folder/cwd specified, and passes them downstream so you can keep piping these around.
|
||||
|
||||
Once the file is written to disk, an attempt is made to determine if the `stat.mode`, `stat.mtime` and `stat.atime` of the [vinyl] `File` object differ from the file on the filesystem.
|
||||
If they differ and the running process owns the file, the corresponding filesystem metadata is updated.
|
||||
If they don't differ or the process doesn't own the file, the attempt is skipped silently.
|
||||
**This functionality is disabled on Windows operating systems or any other OS that doesn't support `process.getuid` or `process.geteuid` in node. This is due to Windows having very unexpected results through usage of `fs.fchmod` and `fs.futimes`.**
|
||||
|
||||
**Note: The `fs.futimes()` method internally converts `stat.mtime` and `stat.atime` timestamps to seconds; this division by `1000` may cause some loss of precision in 32-bit Node.js.**
|
||||
|
||||
If the file has a `symlink` attribute specifying a target path, then a symlink will be created.
|
||||
|
||||
**Note: The file will be modified after being written to this stream.**
|
||||
|
||||
- `cwd`, `base`, and `path` will be overwritten to match the folder.
|
||||
- `stat` will be updated to match the file on the filesystem.
|
||||
- `contents` will have it's position reset to the beginning if it is a stream.
|
||||
|
||||
#### Options
|
||||
|
||||
- Values passed to the options must be of the expected type, otherwise they will be ignored.
|
||||
- All options can be passed a function instead of a value. The function will be called with the [vinyl] `File` object as its only argument and must return a value of the expected type for that option.
|
||||
|
||||
##### `options.cwd`
|
||||
|
||||
The working directory the folder is relative to.
|
||||
|
||||
Type: `String`
|
||||
|
||||
Default: `process.cwd()`
|
||||
|
||||
##### `options.mode`
|
||||
|
||||
The mode the files should be created with. This option is only resolved if the [vinyl] `File` is not symbolic.
|
||||
|
||||
Type: `Number`
|
||||
|
||||
Default: The `mode` of the input file (`file.stat.mode`) if any, or the process mode if the input file has no `mode` property.
|
||||
|
||||
##### `options.dirMode`
|
||||
|
||||
The mode directories should be created with.
|
||||
|
||||
Type: `Number`
|
||||
|
||||
Default: The process `mode`.
|
||||
|
||||
##### `options.overwrite`
|
||||
|
||||
Whether or not existing files with the same path should be overwritten.
|
||||
|
||||
Type: `Boolean`
|
||||
|
||||
Default: `true` (always overwrite existing files)
|
||||
|
||||
##### `options.append`
|
||||
|
||||
Whether or not new data should be appended after existing file contents (if any).
|
||||
|
||||
Type: `Boolean`
|
||||
|
||||
Default: `false` (always replace existing contents, if any)
|
||||
|
||||
##### `options.encoding`
|
||||
|
||||
Optionally transcode to the given encoding. The default is `'utf8'`. We use
|
||||
[iconv-lite], please refer to its Wiki for a list of supported encodings. You
|
||||
can set this to `false` to avoid any transcoding, and effectively just pass
|
||||
around raw binary data.
|
||||
|
||||
Type: `String` or `Boolean`
|
||||
|
||||
Default: `'utf8'`.
|
||||
|
||||
##### `options.sourcemaps`
|
||||
|
||||
Enables sourcemap support on files passed through the stream. Will write inline soucemaps if specified as `true`.
|
||||
Specifying a `String` path will write external sourcemaps at the given path.
|
||||
|
||||
Examples:
|
||||
|
||||
```js
|
||||
// Write as inline comments
|
||||
vfs.dest('./', { sourcemaps: true });
|
||||
|
||||
// Write as files in the same folder
|
||||
vfs.dest('./', { sourcemaps: '.' });
|
||||
```
|
||||
|
||||
Type: `Boolean` or `String`
|
||||
|
||||
Default: `undefined` (do not write sourcemaps)
|
||||
|
||||
##### `options.relativeSymlinks`
|
||||
|
||||
When creating a symlink, whether or not the created symlink should be relative. If `false`, the symlink will be absolute.
|
||||
|
||||
**Note: This option will be ignored if a `junction` is being created, as they must be absolute.**
|
||||
|
||||
Type: `Boolean`
|
||||
|
||||
Default: `false`
|
||||
|
||||
##### `options.useJunctions`
|
||||
|
||||
When creating a symlink, whether or not a directory symlink should be created as a `junction`.
|
||||
This option is only relevant on Windows and ignored elsewhere. Please refer to the [Symbolic Links on Windows][symbolic-caveats] section below.
|
||||
|
||||
Type: `Boolean`
|
||||
|
||||
Default: `true`
|
||||
|
||||
### `symlink(folder[, options])`
|
||||
|
||||
Takes a folder path string or a function as the first argument and an options object as the second. If given a function, it will be called with each [vinyl] `File` object and must return a folder path.
|
||||
Returns a stream that accepts [vinyl] `File` objects, creates a symbolic link (i.e. symlink) at the folder/cwd specified, and passes them downstream so you can keep piping these around.
|
||||
|
||||
**Note: The file will be modified after being written to this stream.**
|
||||
|
||||
- `cwd`, `base`, and `path` will be overwritten to match the folder.
|
||||
- `stat` will be updated to match the symlink on the filesystem.
|
||||
- `contents` will be set to `null`.
|
||||
- `symlink` will be added or replaced to be the original path.
|
||||
|
||||
**Note: On Windows, directory links are created using Junctions by default. Use the `useJunctions` option to disable this behavior.**
|
||||
|
||||
#### Options
|
||||
|
||||
- Values passed to the options must be of the expected type, otherwise they will be ignored.
|
||||
- All options can be passed a function instead of a value. The function will be called with the [vinyl] `File` object as its only argument and must return a value of the expected type for that option.
|
||||
|
||||
##### `options.cwd`
|
||||
|
||||
The working directory the folder is relative to.
|
||||
|
||||
Type: `String`
|
||||
|
||||
Default: `process.cwd()`
|
||||
|
||||
##### `options.dirMode`
|
||||
|
||||
The mode directories should be created with.
|
||||
|
||||
Type: `Number`
|
||||
|
||||
Default: The process mode.
|
||||
|
||||
##### `options.overwrite`
|
||||
|
||||
Whether or not existing files with the same path should be overwritten.
|
||||
|
||||
Type: `Boolean`
|
||||
|
||||
Default: `true` (always overwrite existing files)
|
||||
|
||||
##### `options.relativeSymlinks`
|
||||
|
||||
Whether or not the created symlinks should be relative. If `false`, the symlink will be absolute.
|
||||
|
||||
**Note: This option will be ignored if a `junction` is being created, as they must be absolute.**
|
||||
|
||||
Type: `Boolean`
|
||||
|
||||
Default: `false`
|
||||
|
||||
##### `options.useJunctions`
|
||||
|
||||
When creating a symlink, whether or not a directory symlink should be created as a `junction`.
|
||||
This option is only relevant on Windows and ignored elsewhere. Please refer to the [Symbolic Links on Windows][symbolic-caveats] section below.
|
||||
|
||||
Type: `Boolean`
|
||||
|
||||
Default: `true`
|
||||
|
||||
#### Symbolic Links on Windows
|
||||
|
||||
When creating symbolic links on Windows, we pass a `type` argument to Node's
|
||||
`fs` module which specifies the kind of target we link to (one of `'file'`,
|
||||
`'dir'` or `'junction'`). Specifically, this will be `'file'` when the target
|
||||
is a regular file, `'junction'` if the target is a directory, or `'dir'` if
|
||||
the target is a directory and the user overrides the `useJunctions` option
|
||||
default.
|
||||
|
||||
However, if the user tries to make a "dangling" link (pointing to a non-existent
|
||||
target) we won't be able to determine automatically which type we should use.
|
||||
In these cases, `vinyl-fs` will behave slightly differently depending on
|
||||
whether the dangling link is being created via `symlink()` or via `dest()`.
|
||||
|
||||
For dangling links created via `symlink()`, the incoming vinyl represents the
|
||||
target and so we will look to its stats to guess the desired type. In
|
||||
particular, if `isDirectory()` returns false then we'll create a `'file'` type
|
||||
link, otherwise we will create a `'junction'` or a `'dir'` type link depending
|
||||
on the value of the `useJunctions` option.
|
||||
|
||||
For dangling links created via `dest()`, the incoming vinyl represents the link -
|
||||
typically read off disk via `src()` with the `resolveSymlinks` option set to
|
||||
false. In this case, we won't be able to make any reasonable guess as to the
|
||||
type of link and we default to using `'file'`, which may cause unexpected behavior
|
||||
if you are creating a "dangling" link to a directory. It is advised to avoid this
|
||||
scenario.
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
|
||||
<!-- prettier-ignore-start -->
|
||||
[downloads-image]: https://img.shields.io/npm/dm/vinyl-fs.svg?style=flat-square
|
||||
[npm-url]: https://www.npmjs.com/package/vinyl-fs
|
||||
[npm-image]: https://img.shields.io/npm/v/vinyl-fs.svg?style=flat-square
|
||||
|
||||
[ci-url]: https://github.com/gulpjs/vinyl-fs/actions?query=workflow:dev
|
||||
[ci-image]: https://img.shields.io/github/actions/workflow/status/gulpjs/vinyl-fs/dev.yml??branch=master&style=flat-square
|
||||
|
||||
[coveralls-url]: https://coveralls.io/r/gulpjs/vinyl-fs
|
||||
[coveralls-image]: https://img.shields.io/coveralls/gulpjs/vinyl-fs.svg?style=flat-square
|
||||
<!-- prettier-ignore-end -->
|
||||
|
||||
<!-- prettier-ignore-start -->
|
||||
[symbolic-caveats]: #symbolic-links-on-windows
|
||||
[glob-stream]: https://github.com/gulpjs/glob-stream
|
||||
[anymatch]: https://github.com/micromatch/anymatch
|
||||
[vinyl]: https://github.com/gulpjs/vinyl
|
||||
[iconv-lite]: https://github.com/ashtuchkin/iconv-lite
|
||||
<!-- prettier-ignore-end -->
|
7
node_modules/vinyl-fs/index.js
generated
vendored
Normal file
7
node_modules/vinyl-fs/index.js
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
src: require('./lib/src'),
|
||||
dest: require('./lib/dest'),
|
||||
symlink: require('./lib/symlink'),
|
||||
};
|
107
node_modules/vinyl-fs/lib/codecs.js
generated
vendored
Normal file
107
node_modules/vinyl-fs/lib/codecs.js
generated
vendored
Normal file
@@ -0,0 +1,107 @@
|
||||
'use strict';
|
||||
|
||||
/* eslint-disable new-cap */
|
||||
|
||||
var iconv = require('iconv-lite');
|
||||
// TODO: Reaching into iconv-lite is fragile
|
||||
var StripBOM = require('iconv-lite/lib/bom-handling').StripBOM;
|
||||
var Transform = require('streamx').Transform;
|
||||
|
||||
var DEFAULT_ENCODING = require('./constants').DEFAULT_ENCODING;
|
||||
|
||||
function Codec(codec, encoding) {
|
||||
this.codec = codec;
|
||||
this.enc = codec.enc || encoding;
|
||||
this.bomAware = codec.bomAware || false;
|
||||
}
|
||||
|
||||
function getEncoder(codec) {
|
||||
return new codec.encoder(null, codec);
|
||||
}
|
||||
|
||||
Codec.prototype.encode = function (str) {
|
||||
var encoder = getEncoder(this.codec);
|
||||
var buf = encoder.write(str);
|
||||
var end = encoder.end();
|
||||
return end && end.length > 0 ? Buffer.concat(buf, end) : buf;
|
||||
};
|
||||
|
||||
Codec.prototype.encodeStream = function () {
|
||||
var encoder = getEncoder(this.codec);
|
||||
return new Transform({
|
||||
transform: function (str, cb) {
|
||||
var buf = encoder.write(str);
|
||||
if (buf && buf.length) {
|
||||
this.push(buf);
|
||||
}
|
||||
cb();
|
||||
},
|
||||
flush: function (cb) {
|
||||
var buf = encoder.end();
|
||||
if (buf && buf.length) {
|
||||
this.push(buf);
|
||||
}
|
||||
cb();
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
function getDecoder(codec) {
|
||||
return new codec.decoder(null, codec);
|
||||
}
|
||||
|
||||
Codec.prototype.decode = function (buf, options) {
|
||||
var decoder = getDecoder(this.codec);
|
||||
if (options && options.removeBOM) {
|
||||
decoder = new StripBOM(decoder);
|
||||
}
|
||||
var str = decoder.write(buf);
|
||||
var end = decoder.end();
|
||||
return end ? str + end : str;
|
||||
};
|
||||
|
||||
Codec.prototype.decodeStream = function (options) {
|
||||
var decoder = getDecoder(this.codec);
|
||||
if (options && options.removeBOM) {
|
||||
decoder = new StripBOM(decoder);
|
||||
}
|
||||
return new Transform({
|
||||
transform: function (buf, cb) {
|
||||
var str = decoder.write(buf);
|
||||
if (str && str.length) {
|
||||
this.push(str);
|
||||
}
|
||||
cb();
|
||||
},
|
||||
flush: function (cb) {
|
||||
var str = decoder.end();
|
||||
if (str && str.length) {
|
||||
this.push(str);
|
||||
}
|
||||
cb();
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
var cache = {};
|
||||
|
||||
function getCodec(encoding) {
|
||||
var codec = cache[encoding];
|
||||
if (!!codec || !encoding || Object.hasOwnProperty.call(cache, encoding)) {
|
||||
return codec;
|
||||
}
|
||||
|
||||
try {
|
||||
codec = new Codec(iconv.getCodec(encoding), encoding);
|
||||
} catch (err) {
|
||||
// Unsupported codec
|
||||
}
|
||||
|
||||
cache[encoding] = codec;
|
||||
return codec;
|
||||
}
|
||||
|
||||
// Pre-load default encoding
|
||||
getCodec(DEFAULT_ENCODING);
|
||||
|
||||
module.exports = getCodec;
|
7
node_modules/vinyl-fs/lib/constants.js
generated
vendored
Normal file
7
node_modules/vinyl-fs/lib/constants.js
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
MASK_MODE: parseInt('7777', 8),
|
||||
DEFAULT_FILE_MODE: parseInt('0666', 8),
|
||||
DEFAULT_ENCODING: 'utf8',
|
||||
};
|
47
node_modules/vinyl-fs/lib/dest/index.js
generated
vendored
Normal file
47
node_modules/vinyl-fs/lib/dest/index.js
generated
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
'use strict';
|
||||
|
||||
var lead = require('lead');
|
||||
var composer = require('stream-composer');
|
||||
var mkdirpStream = require('fs-mkdirp-stream');
|
||||
var createResolver = require('resolve-options');
|
||||
|
||||
var config = require('./options');
|
||||
var prepare = require('./prepare');
|
||||
var sourcemap = require('./sourcemap');
|
||||
var writeContents = require('./write-contents');
|
||||
|
||||
var folderConfig = {
|
||||
outFolder: {
|
||||
type: 'string',
|
||||
},
|
||||
};
|
||||
|
||||
function dest(outFolder, opt) {
|
||||
if (!outFolder) {
|
||||
throw new Error(
|
||||
'Invalid dest() folder argument.' +
|
||||
' Please specify a non-empty string or a function.'
|
||||
);
|
||||
}
|
||||
|
||||
var optResolver = createResolver(config, opt);
|
||||
var folderResolver = createResolver(folderConfig, { outFolder: outFolder });
|
||||
|
||||
function dirpath(file, callback) {
|
||||
var dirMode = optResolver.resolve('dirMode', file);
|
||||
|
||||
callback(null, file.dirname, dirMode);
|
||||
}
|
||||
|
||||
var saveStream = composer.pipeline(
|
||||
prepare(folderResolver, optResolver),
|
||||
sourcemap(optResolver),
|
||||
mkdirpStream(dirpath),
|
||||
writeContents(optResolver)
|
||||
);
|
||||
|
||||
// Sink the output stream to start flowing
|
||||
return lead(saveStream);
|
||||
}
|
||||
|
||||
module.exports = dest;
|
47
node_modules/vinyl-fs/lib/dest/options.js
generated
vendored
Normal file
47
node_modules/vinyl-fs/lib/dest/options.js
generated
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
'use strict';
|
||||
|
||||
var DEFAULT_ENCODING = require('../constants').DEFAULT_ENCODING;
|
||||
|
||||
var config = {
|
||||
cwd: {
|
||||
type: 'string',
|
||||
default: process.cwd,
|
||||
},
|
||||
mode: {
|
||||
type: 'number',
|
||||
default: function (file) {
|
||||
return file.stat ? file.stat.mode : null;
|
||||
},
|
||||
},
|
||||
dirMode: {
|
||||
type: 'number',
|
||||
},
|
||||
overwrite: {
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
},
|
||||
append: {
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
},
|
||||
encoding: {
|
||||
type: ['string', 'boolean'],
|
||||
default: DEFAULT_ENCODING,
|
||||
},
|
||||
sourcemaps: {
|
||||
type: ['string', 'boolean'],
|
||||
default: false,
|
||||
},
|
||||
// Symlink options
|
||||
relativeSymlinks: {
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
},
|
||||
// This option is ignored on non-Windows platforms
|
||||
useJunctions: {
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = config;
|
50
node_modules/vinyl-fs/lib/dest/prepare.js
generated
vendored
Normal file
50
node_modules/vinyl-fs/lib/dest/prepare.js
generated
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
'use strict';
|
||||
|
||||
var path = require('path');
|
||||
|
||||
var fs = require('graceful-fs');
|
||||
var Vinyl = require('vinyl');
|
||||
var Transform = require('streamx').Transform;
|
||||
|
||||
function prepareWrite(folderResolver, optResolver) {
|
||||
if (!folderResolver) {
|
||||
throw new Error('Invalid output folder');
|
||||
}
|
||||
|
||||
function normalize(file, cb) {
|
||||
if (!Vinyl.isVinyl(file)) {
|
||||
return cb(new Error('Received a non-Vinyl object in `dest()`'));
|
||||
}
|
||||
|
||||
// TODO: Remove this after people upgrade vinyl/transition from gulp-util
|
||||
if (typeof file.isSymbolic !== 'function') {
|
||||
file = new Vinyl(file);
|
||||
}
|
||||
|
||||
var outFolderPath = folderResolver.resolve('outFolder', file);
|
||||
if (!outFolderPath) {
|
||||
return cb(new Error('Invalid output folder'));
|
||||
}
|
||||
var cwd = path.resolve(optResolver.resolve('cwd', file));
|
||||
var basePath = path.resolve(cwd, outFolderPath);
|
||||
var writePath = path.resolve(basePath, file.relative);
|
||||
|
||||
// Wire up new properties
|
||||
file.cwd = cwd;
|
||||
file.base = basePath;
|
||||
file.path = writePath;
|
||||
if (!file.isSymbolic()) {
|
||||
var mode = optResolver.resolve('mode', file);
|
||||
file.stat = file.stat || new fs.Stats();
|
||||
file.stat.mode = mode;
|
||||
}
|
||||
|
||||
cb(null, file);
|
||||
}
|
||||
|
||||
return new Transform({
|
||||
transform: normalize,
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = prepareWrite;
|
39
node_modules/vinyl-fs/lib/dest/sourcemap.js
generated
vendored
Normal file
39
node_modules/vinyl-fs/lib/dest/sourcemap.js
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
'use strict';
|
||||
|
||||
var Transform = require('streamx').Transform;
|
||||
var sourcemap = require('vinyl-sourcemap');
|
||||
|
||||
function sourcemapStream(optResolver) {
|
||||
function saveSourcemap(file, callback) {
|
||||
var self = this;
|
||||
|
||||
var srcMap = optResolver.resolve('sourcemaps', file);
|
||||
|
||||
if (!srcMap) {
|
||||
return callback(null, file);
|
||||
}
|
||||
|
||||
var srcMapLocation = typeof srcMap === 'string' ? srcMap : undefined;
|
||||
|
||||
sourcemap.write(file, srcMapLocation, onWrite);
|
||||
|
||||
function onWrite(sourcemapErr, updatedFile, sourcemapFile) {
|
||||
if (sourcemapErr) {
|
||||
return callback(sourcemapErr);
|
||||
}
|
||||
|
||||
self.push(updatedFile);
|
||||
if (sourcemapFile) {
|
||||
self.push(sourcemapFile);
|
||||
}
|
||||
|
||||
callback();
|
||||
}
|
||||
}
|
||||
|
||||
return new Transform({
|
||||
transform: saveSourcemap,
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = sourcemapStream;
|
59
node_modules/vinyl-fs/lib/dest/write-contents/index.js
generated
vendored
Normal file
59
node_modules/vinyl-fs/lib/dest/write-contents/index.js
generated
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
'use strict';
|
||||
|
||||
var Transform = require('streamx').Transform;
|
||||
|
||||
var writeDir = require('./write-dir');
|
||||
var writeStream = require('./write-stream');
|
||||
var writeBuffer = require('./write-buffer');
|
||||
var writeSymbolicLink = require('./write-symbolic-link');
|
||||
|
||||
var fo = require('../../file-operations');
|
||||
|
||||
function writeContents(optResolver) {
|
||||
function writeFile(file, callback) {
|
||||
// Write it as a symlink
|
||||
if (file.isSymbolic()) {
|
||||
return writeSymbolicLink(file, optResolver, onWritten);
|
||||
}
|
||||
|
||||
// If directory then mkdirp it
|
||||
if (file.isDirectory()) {
|
||||
return writeDir(file, optResolver, onWritten);
|
||||
}
|
||||
|
||||
// Stream it to disk yo
|
||||
if (file.isStream()) {
|
||||
return writeStream(file, optResolver, onWritten);
|
||||
}
|
||||
|
||||
// Write it like normal
|
||||
if (file.isBuffer()) {
|
||||
return writeBuffer(file, optResolver, onWritten);
|
||||
}
|
||||
|
||||
// If no contents then do nothing
|
||||
if (file.isNull()) {
|
||||
return onWritten();
|
||||
}
|
||||
|
||||
// This is invoked by the various writeXxx modules when they've finished
|
||||
// writing the contents.
|
||||
function onWritten(writeErr) {
|
||||
var flags = fo.getFlags({
|
||||
overwrite: optResolver.resolve('overwrite', file),
|
||||
append: optResolver.resolve('append', file),
|
||||
});
|
||||
if (fo.isFatalOverwriteError(writeErr, flags)) {
|
||||
return callback(writeErr);
|
||||
}
|
||||
|
||||
callback(null, file);
|
||||
}
|
||||
}
|
||||
|
||||
return new Transform({
|
||||
transform: writeFile,
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = writeContents;
|
46
node_modules/vinyl-fs/lib/dest/write-contents/write-buffer.js
generated
vendored
Normal file
46
node_modules/vinyl-fs/lib/dest/write-contents/write-buffer.js
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
'use strict';
|
||||
|
||||
var fo = require('../../file-operations');
|
||||
var getCodec = require('../../codecs');
|
||||
var DEFAULT_ENCODING = require('../../constants').DEFAULT_ENCODING;
|
||||
|
||||
function writeBuffer(file, optResolver, onWritten) {
|
||||
var flags = fo.getFlags({
|
||||
overwrite: optResolver.resolve('overwrite', file),
|
||||
append: optResolver.resolve('append', file),
|
||||
});
|
||||
|
||||
var encoding = optResolver.resolve('encoding', file);
|
||||
var codec = getCodec(encoding);
|
||||
if (encoding && !codec) {
|
||||
return onWritten(new Error('Unsupported encoding: ' + encoding));
|
||||
}
|
||||
|
||||
var opt = {
|
||||
mode: file.stat.mode,
|
||||
flags: flags,
|
||||
};
|
||||
|
||||
var contents = file.contents;
|
||||
|
||||
if (encoding && codec.enc !== DEFAULT_ENCODING) {
|
||||
contents = getCodec(DEFAULT_ENCODING).decode(contents);
|
||||
contents = codec.encode(contents);
|
||||
}
|
||||
|
||||
fo.writeFile(file.path, contents, opt, onWriteFile);
|
||||
|
||||
function onWriteFile(writeErr, fd) {
|
||||
if (writeErr) {
|
||||
return fo.closeFd(writeErr, fd, onWritten);
|
||||
}
|
||||
|
||||
fo.updateMetadata(fd, file, onUpdate);
|
||||
|
||||
function onUpdate(updateErr) {
|
||||
fo.closeFd(updateErr, fd, onWritten);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = writeBuffer;
|
50
node_modules/vinyl-fs/lib/dest/write-contents/write-dir.js
generated
vendored
Normal file
50
node_modules/vinyl-fs/lib/dest/write-contents/write-dir.js
generated
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
'use strict';
|
||||
|
||||
var fs = require('graceful-fs');
|
||||
|
||||
var mkdirp = require('fs-mkdirp-stream/mkdirp');
|
||||
|
||||
var fo = require('../../file-operations');
|
||||
|
||||
function writeDir(file, optResolver, onWritten) {
|
||||
mkdirp(file.path, file.stat.mode, onMkdirp);
|
||||
|
||||
function onMkdirp(mkdirpErr) {
|
||||
if (mkdirpErr) {
|
||||
return onWritten(mkdirpErr);
|
||||
}
|
||||
|
||||
fs.open(file.path, 'r', onOpen);
|
||||
}
|
||||
|
||||
function onOpen(openErr, fd) {
|
||||
// If we don't have access, just move along
|
||||
if (isInaccessible(openErr)) {
|
||||
return fo.closeFd(null, fd, onWritten);
|
||||
}
|
||||
|
||||
if (openErr) {
|
||||
return fo.closeFd(openErr, fd, onWritten);
|
||||
}
|
||||
|
||||
fo.updateMetadata(fd, file, onUpdate);
|
||||
|
||||
function onUpdate(updateErr) {
|
||||
fo.closeFd(updateErr, fd, onWritten);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function isInaccessible(err) {
|
||||
if (!err) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (err.code === 'EACCES') {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
module.exports = writeDir;
|
68
node_modules/vinyl-fs/lib/dest/write-contents/write-stream.js
generated
vendored
Normal file
68
node_modules/vinyl-fs/lib/dest/write-contents/write-stream.js
generated
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
'use strict';
|
||||
|
||||
var pipeline = require('streamx').pipeline;
|
||||
|
||||
var fo = require('../../file-operations');
|
||||
var getCodec = require('../../codecs');
|
||||
var DEFAULT_ENCODING = require('../../constants').DEFAULT_ENCODING;
|
||||
var readStream = require('../../src/read-contents/read-stream');
|
||||
|
||||
function writeStream(file, optResolver, onWritten) {
|
||||
var flags = fo.getFlags({
|
||||
overwrite: optResolver.resolve('overwrite', file),
|
||||
append: optResolver.resolve('append', file),
|
||||
});
|
||||
|
||||
var encoding = optResolver.resolve('encoding', file);
|
||||
var codec = getCodec(encoding);
|
||||
if (encoding && !codec) {
|
||||
return onWritten(new Error('Unsupported encoding: ' + encoding));
|
||||
}
|
||||
|
||||
var opt = {
|
||||
mode: file.stat.mode,
|
||||
// TODO: need to test this
|
||||
flags: flags,
|
||||
};
|
||||
|
||||
// TODO: is this the best API?
|
||||
var outStream = fo.createWriteStream(file.path, opt, onFlush);
|
||||
|
||||
// TODO: should this use a clone?
|
||||
var streams = [file.contents];
|
||||
|
||||
if (encoding && encoding.enc !== DEFAULT_ENCODING) {
|
||||
streams.push(getCodec(DEFAULT_ENCODING).decodeStream());
|
||||
streams.push(codec.encodeStream());
|
||||
}
|
||||
|
||||
streams.push(outStream);
|
||||
|
||||
pipeline(streams, onWritten);
|
||||
|
||||
// Cleanup
|
||||
function onFlush(fd, callback) {
|
||||
// TODO: this is doing sync stuff & the callback seems unnecessary
|
||||
readStream(file, { resolve: resolve }, complete);
|
||||
|
||||
function resolve(key) {
|
||||
if (key === 'encoding') {
|
||||
return encoding;
|
||||
}
|
||||
if (key === 'removeBOM') {
|
||||
return false;
|
||||
}
|
||||
throw new Error("Eek! stub resolver doesn't have " + key);
|
||||
}
|
||||
|
||||
function complete() {
|
||||
if (typeof fd !== 'number') {
|
||||
return callback();
|
||||
}
|
||||
|
||||
fo.updateMetadata(fd, file, callback);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = writeStream;
|
77
node_modules/vinyl-fs/lib/dest/write-contents/write-symbolic-link.js
generated
vendored
Normal file
77
node_modules/vinyl-fs/lib/dest/write-contents/write-symbolic-link.js
generated
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
'use strict';
|
||||
|
||||
var os = require('os');
|
||||
var path = require('path');
|
||||
|
||||
var fo = require('../../file-operations');
|
||||
|
||||
var isWindows = os.platform() === 'win32';
|
||||
|
||||
function writeSymbolicLink(file, optResolver, onWritten) {
|
||||
if (!file.symlink) {
|
||||
return onWritten(new Error('Missing symlink property on symbolic vinyl'));
|
||||
}
|
||||
|
||||
var isRelative = optResolver.resolve('relativeSymlinks', file);
|
||||
var flags = fo.getFlags({
|
||||
overwrite: optResolver.resolve('overwrite', file),
|
||||
append: optResolver.resolve('append', file),
|
||||
});
|
||||
|
||||
if (!isWindows) {
|
||||
// On non-Windows, just use 'file'
|
||||
return createLinkWithType('file');
|
||||
}
|
||||
|
||||
fo.reflectStat(file.symlink, file, onReflect);
|
||||
|
||||
function onReflect(statErr) {
|
||||
if (statErr && statErr.code !== 'ENOENT') {
|
||||
return onWritten(statErr);
|
||||
}
|
||||
|
||||
// This option provides a way to create a Junction instead of a
|
||||
// Directory symlink on Windows. This comes with the following caveats:
|
||||
// * NTFS Junctions cannot be relative.
|
||||
// * NTFS Junctions MUST be directories.
|
||||
// * NTFS Junctions must be on the same file system.
|
||||
// * Most products CANNOT detect a directory is a Junction:
|
||||
// This has the side effect of possibly having a whole directory
|
||||
// deleted when a product is deleting the Junction directory.
|
||||
// For example, JetBrains product lines will delete the entire contents
|
||||
// of the TARGET directory because the product does not realize it's
|
||||
// a symlink as the JVM and Node return false for isSymlink.
|
||||
|
||||
// This function is Windows only, so we don't need to check again
|
||||
var useJunctions = optResolver.resolve('useJunctions', file);
|
||||
|
||||
var dirType = useJunctions ? 'junction' : 'dir';
|
||||
// Dangling links are always 'file'
|
||||
var type = !statErr && file.isDirectory() ? dirType : 'file';
|
||||
|
||||
createLinkWithType(type);
|
||||
}
|
||||
|
||||
function createLinkWithType(type) {
|
||||
// This is done after prepare() to use the adjusted file.base property
|
||||
if (isRelative && type !== 'junction') {
|
||||
file.symlink = path.relative(file.base, file.symlink);
|
||||
}
|
||||
|
||||
var opts = {
|
||||
flags: flags,
|
||||
type: type,
|
||||
};
|
||||
fo.symlink(file.symlink, file.path, opts, onSymlink);
|
||||
|
||||
function onSymlink(symlinkErr) {
|
||||
if (symlinkErr) {
|
||||
return onWritten(symlinkErr);
|
||||
}
|
||||
|
||||
fo.reflectLinkStat(file.path, file, onWritten);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = writeSymbolicLink;
|
459
node_modules/vinyl-fs/lib/file-operations.js
generated
vendored
Normal file
459
node_modules/vinyl-fs/lib/file-operations.js
generated
vendored
Normal file
@@ -0,0 +1,459 @@
|
||||
'use strict';
|
||||
|
||||
var fs = require('graceful-fs');
|
||||
var date = require('value-or-function').date;
|
||||
var Writable = require('streamx').Writable;
|
||||
|
||||
var constants = require('./constants');
|
||||
|
||||
var APPEND_MODE_REGEXP = /a/;
|
||||
|
||||
function closeFd(propagatedErr, fd, callback) {
|
||||
if (typeof fd !== 'number') {
|
||||
return callback(propagatedErr);
|
||||
}
|
||||
|
||||
fs.close(fd, onClosed);
|
||||
|
||||
function onClosed(closeErr) {
|
||||
if (propagatedErr || closeErr) {
|
||||
return callback(propagatedErr || closeErr);
|
||||
}
|
||||
|
||||
callback();
|
||||
}
|
||||
}
|
||||
|
||||
function isValidUnixId(id) {
|
||||
if (typeof id !== 'number') {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (id < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function getFlags(options) {
|
||||
var flags = !options.append ? 'w' : 'a';
|
||||
if (!options.overwrite) {
|
||||
flags += 'x';
|
||||
}
|
||||
return flags;
|
||||
}
|
||||
|
||||
function isFatalOverwriteError(err, flags) {
|
||||
if (!err) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (err.code === 'EEXIST' && flags[1] === 'x') {
|
||||
// Handle scenario for file overwrite failures.
|
||||
return false;
|
||||
}
|
||||
|
||||
// Otherwise, this is a fatal error
|
||||
return true;
|
||||
}
|
||||
|
||||
function isFatalUnlinkError(err) {
|
||||
if (!err || err.code === 'ENOENT') {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function getModeDiff(fsMode, vinylMode) {
|
||||
var modeDiff = 0;
|
||||
|
||||
if (typeof vinylMode === 'number') {
|
||||
modeDiff = (vinylMode ^ fsMode) & constants.MASK_MODE;
|
||||
}
|
||||
|
||||
return modeDiff;
|
||||
}
|
||||
|
||||
function getTimesDiff(fsStat, vinylStat) {
|
||||
var mtime = date(vinylStat.mtime) || 0;
|
||||
if (!mtime) {
|
||||
return;
|
||||
}
|
||||
|
||||
var atime = date(vinylStat.atime) || 0;
|
||||
if (+mtime === +fsStat.mtime && +atime === +fsStat.atime) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!atime) {
|
||||
atime = date(fsStat.atime) || undefined;
|
||||
}
|
||||
|
||||
var timesDiff = {
|
||||
mtime: vinylStat.mtime,
|
||||
atime: atime,
|
||||
};
|
||||
|
||||
return timesDiff;
|
||||
}
|
||||
|
||||
function getOwnerDiff(fsStat, vinylStat) {
|
||||
if (!isValidUnixId(vinylStat.uid) && !isValidUnixId(vinylStat.gid)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
(!isValidUnixId(fsStat.uid) && !isValidUnixId(vinylStat.uid)) ||
|
||||
(!isValidUnixId(fsStat.gid) && !isValidUnixId(vinylStat.gid))
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
var uid = fsStat.uid; // Default to current uid.
|
||||
if (isValidUnixId(vinylStat.uid)) {
|
||||
uid = vinylStat.uid;
|
||||
}
|
||||
|
||||
var gid = fsStat.gid; // Default to current gid.
|
||||
if (isValidUnixId(vinylStat.gid)) {
|
||||
gid = vinylStat.gid;
|
||||
}
|
||||
|
||||
if (uid === fsStat.uid && gid === fsStat.gid) {
|
||||
return;
|
||||
}
|
||||
|
||||
var ownerDiff = {
|
||||
uid: uid,
|
||||
gid: gid,
|
||||
};
|
||||
|
||||
return ownerDiff;
|
||||
}
|
||||
|
||||
function isOwner(fsStat) {
|
||||
var hasGetuid = typeof process.getuid === 'function';
|
||||
var hasGeteuid = typeof process.geteuid === 'function';
|
||||
|
||||
// If we don't have either, assume we don't have permissions.
|
||||
// This should only happen on Windows.
|
||||
// Windows basically noops fchmod and errors on futimes called on directories.
|
||||
if (!hasGeteuid && !hasGetuid) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var uid;
|
||||
if (hasGeteuid) {
|
||||
uid = process.geteuid();
|
||||
} else {
|
||||
uid = process.getuid();
|
||||
}
|
||||
|
||||
if (fsStat.uid !== uid && uid !== 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Node 10 on Windows fails with EPERM if you stat a symlink to a directory so we recursively readlink before we reflect stats
|
||||
// TODO: Remove this indirection when we drop Node 10 support
|
||||
function findSymlinkHardpath(path, callback) {
|
||||
fs.readlink(path, onReadlink);
|
||||
|
||||
function onReadlink(readlinkErr, resolvedPath) {
|
||||
if (readlinkErr) {
|
||||
return callback(readlinkErr);
|
||||
}
|
||||
|
||||
fs.lstat(resolvedPath, onLstat);
|
||||
|
||||
function onLstat(lstatErr, stat) {
|
||||
if (lstatErr) {
|
||||
return callback(lstatErr);
|
||||
}
|
||||
|
||||
if (stat.isSymbolicLink()) {
|
||||
return findSymlinkHardpath(resolvedPath, callback);
|
||||
}
|
||||
|
||||
callback(null, resolvedPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function reflectStat(path, file, callback) {
|
||||
// Set file.stat to the reflect current state on disk
|
||||
fs.stat(path, onStat);
|
||||
|
||||
function onStat(statErr, stat) {
|
||||
if (statErr) {
|
||||
return callback(statErr);
|
||||
}
|
||||
|
||||
file.stat = stat;
|
||||
callback();
|
||||
}
|
||||
}
|
||||
|
||||
function reflectLinkStat(path, file, callback) {
|
||||
// Set file.stat to the reflect current state on disk
|
||||
fs.lstat(path, onLstat);
|
||||
|
||||
function onLstat(lstatErr, stat) {
|
||||
if (lstatErr) {
|
||||
return callback(lstatErr);
|
||||
}
|
||||
|
||||
file.stat = stat;
|
||||
callback();
|
||||
}
|
||||
}
|
||||
|
||||
function updateMetadata(fd, file, callback) {
|
||||
fs.fstat(fd, onStat);
|
||||
|
||||
function onStat(statErr, stat) {
|
||||
if (statErr) {
|
||||
return callback(statErr);
|
||||
}
|
||||
|
||||
// Check if mode needs to be updated
|
||||
var modeDiff = getModeDiff(stat.mode, file.stat.mode);
|
||||
|
||||
// Check if atime/mtime need to be updated
|
||||
var timesDiff = getTimesDiff(stat, file.stat);
|
||||
|
||||
// Check if uid/gid need to be updated
|
||||
var ownerDiff = getOwnerDiff(stat, file.stat);
|
||||
|
||||
// Set file.stat to the reflect current state on disk
|
||||
Object.assign(file.stat, stat);
|
||||
|
||||
// Nothing to do
|
||||
if (!modeDiff && !timesDiff && !ownerDiff) {
|
||||
return callback();
|
||||
}
|
||||
|
||||
// Check access, `futimes`, `fchmod` & `fchown` only work if we own
|
||||
// the file, or if we are effectively root (`fchown` only when root).
|
||||
if (!isOwner(stat)) {
|
||||
return callback();
|
||||
}
|
||||
|
||||
if (modeDiff) {
|
||||
return mode();
|
||||
}
|
||||
if (timesDiff) {
|
||||
return times();
|
||||
}
|
||||
owner();
|
||||
|
||||
function mode() {
|
||||
var mode = stat.mode ^ modeDiff;
|
||||
|
||||
fs.fchmod(fd, mode, onFchmod);
|
||||
|
||||
function onFchmod(fchmodErr) {
|
||||
if (!fchmodErr) {
|
||||
file.stat.mode = mode;
|
||||
}
|
||||
if (timesDiff) {
|
||||
return times(fchmodErr);
|
||||
}
|
||||
if (ownerDiff) {
|
||||
return owner(fchmodErr);
|
||||
}
|
||||
callback(fchmodErr);
|
||||
}
|
||||
}
|
||||
|
||||
function times(propagatedErr) {
|
||||
fs.futimes(fd, timesDiff.atime, timesDiff.mtime, onFutimes);
|
||||
|
||||
function onFutimes(futimesErr) {
|
||||
if (!futimesErr) {
|
||||
file.stat.atime = timesDiff.atime;
|
||||
file.stat.mtime = timesDiff.mtime;
|
||||
}
|
||||
// If a filesystem doesn't implement futimes, we don't callback with the error.
|
||||
// Instead we update the stats to match filesystem and clear the error.
|
||||
if (futimesErr && futimesErr.code === 'ENOSYS') {
|
||||
file.stat.atime = stat.atime;
|
||||
file.stat.mtime = stat.mtime;
|
||||
futimesErr = null;
|
||||
}
|
||||
if (ownerDiff) {
|
||||
return owner(propagatedErr || futimesErr);
|
||||
}
|
||||
callback(propagatedErr || futimesErr);
|
||||
}
|
||||
}
|
||||
|
||||
function owner(propagatedErr) {
|
||||
fs.fchown(fd, ownerDiff.uid, ownerDiff.gid, onFchown);
|
||||
|
||||
function onFchown(fchownErr) {
|
||||
if (!fchownErr) {
|
||||
file.stat.uid = ownerDiff.uid;
|
||||
file.stat.gid = ownerDiff.gid;
|
||||
}
|
||||
callback(propagatedErr || fchownErr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function symlink(srcPath, destPath, opts, callback) {
|
||||
// Because fs.symlink does not allow atomic overwrite option with flags, we
|
||||
// delete and recreate if the link already exists and overwrite is true.
|
||||
if (opts.flags === 'w') {
|
||||
// TODO What happens when we call unlink with windows junctions?
|
||||
fs.unlink(destPath, onUnlink);
|
||||
} else {
|
||||
fs.symlink(srcPath, destPath, opts.type, onSymlink);
|
||||
}
|
||||
|
||||
function onUnlink(unlinkErr) {
|
||||
if (isFatalUnlinkError(unlinkErr)) {
|
||||
return callback(unlinkErr);
|
||||
}
|
||||
fs.symlink(srcPath, destPath, opts.type, onSymlink);
|
||||
}
|
||||
|
||||
function onSymlink(symlinkErr) {
|
||||
if (isFatalOverwriteError(symlinkErr, opts.flags)) {
|
||||
return callback(symlinkErr);
|
||||
}
|
||||
callback();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Custom writeFile implementation because we need access to the
|
||||
file descriptor after the write is complete.
|
||||
Most of the implementation taken from node core.
|
||||
*/
|
||||
function writeFile(filepath, data, options, callback) {
|
||||
if (typeof options === 'function') {
|
||||
callback = options;
|
||||
options = {};
|
||||
}
|
||||
|
||||
if (!Buffer.isBuffer(data)) {
|
||||
return callback(new TypeError('Data must be a Buffer'));
|
||||
}
|
||||
|
||||
if (!options) {
|
||||
options = {};
|
||||
}
|
||||
|
||||
// Default the same as node
|
||||
var mode = options.mode || constants.DEFAULT_FILE_MODE;
|
||||
var flags = options.flags || 'w';
|
||||
var position = APPEND_MODE_REGEXP.test(flags) ? null : 0;
|
||||
|
||||
fs.open(filepath, flags, mode, onOpen);
|
||||
|
||||
function onOpen(openErr, fd) {
|
||||
if (openErr) {
|
||||
return onComplete(openErr);
|
||||
}
|
||||
|
||||
fs.write(fd, data, 0, data.length, position, onComplete);
|
||||
|
||||
function onComplete(writeErr) {
|
||||
callback(writeErr, fd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function noopFlush(fd, cb) {
|
||||
cb();
|
||||
}
|
||||
|
||||
function createWriteStream(path, options, flush) {
|
||||
if (typeof options === 'function') {
|
||||
flush = options;
|
||||
options = null;
|
||||
}
|
||||
|
||||
options = options || {};
|
||||
flush = flush || noopFlush;
|
||||
|
||||
var mode = options.mode || constants.DEFAULT_FILE_MODE;
|
||||
var flags = options.flags || 'w';
|
||||
|
||||
var fd = null;
|
||||
|
||||
return new Writable({
|
||||
mapWritable: function (data) {
|
||||
if (typeof data === 'string') {
|
||||
return Buffer.from(data);
|
||||
} else {
|
||||
return data;
|
||||
}
|
||||
},
|
||||
open: function (cb) {
|
||||
fs.open(path, flags, mode, onOpen);
|
||||
|
||||
function onOpen(openErr, openedFd) {
|
||||
if (openErr) {
|
||||
cb(openErr);
|
||||
return;
|
||||
}
|
||||
|
||||
fd = openedFd;
|
||||
cb();
|
||||
}
|
||||
},
|
||||
destroy: function (cb) {
|
||||
if (fd) {
|
||||
fs.close(fd, onClose);
|
||||
} else {
|
||||
onClose();
|
||||
}
|
||||
|
||||
function onClose(closeErr) {
|
||||
fd = null;
|
||||
cb(closeErr);
|
||||
}
|
||||
},
|
||||
write: function (data, cb) {
|
||||
fs.write(fd, data, 0, data.length, null, onWrite);
|
||||
|
||||
function onWrite(writeErr) {
|
||||
if (writeErr) {
|
||||
cb(writeErr);
|
||||
return;
|
||||
}
|
||||
|
||||
cb();
|
||||
}
|
||||
},
|
||||
final: function (cb) {
|
||||
flush(fd, cb);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
closeFd: closeFd,
|
||||
isValidUnixId: isValidUnixId,
|
||||
getFlags: getFlags,
|
||||
isFatalOverwriteError: isFatalOverwriteError,
|
||||
isFatalUnlinkError: isFatalUnlinkError,
|
||||
getModeDiff: getModeDiff,
|
||||
getTimesDiff: getTimesDiff,
|
||||
getOwnerDiff: getOwnerDiff,
|
||||
isOwner: isOwner,
|
||||
findSymlinkHardpath: findSymlinkHardpath,
|
||||
reflectStat: reflectStat,
|
||||
reflectLinkStat: reflectLinkStat,
|
||||
updateMetadata: updateMetadata,
|
||||
symlink: symlink,
|
||||
writeFile: writeFile,
|
||||
createWriteStream: createWriteStream,
|
||||
};
|
46
node_modules/vinyl-fs/lib/src/index.js
generated
vendored
Normal file
46
node_modules/vinyl-fs/lib/src/index.js
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
'use strict';
|
||||
|
||||
var gs = require('glob-stream');
|
||||
var pipeline = require('streamx').pipeline;
|
||||
var toThrough = require('to-through');
|
||||
var isValidGlob = require('is-valid-glob');
|
||||
var normalizePath = require('normalize-path');
|
||||
var createResolver = require('resolve-options');
|
||||
|
||||
var config = require('./options');
|
||||
var prepare = require('./prepare');
|
||||
var wrapVinyl = require('./wrap-vinyl');
|
||||
var sourcemap = require('./sourcemap');
|
||||
var readContents = require('./read-contents');
|
||||
var resolveSymlinks = require('./resolve-symlinks');
|
||||
|
||||
function normalize(glob) {
|
||||
return normalizePath(glob, false);
|
||||
}
|
||||
|
||||
function src(glob, opt) {
|
||||
var optResolver = createResolver(config, opt);
|
||||
|
||||
if (!isValidGlob(glob)) {
|
||||
throw new Error('Invalid glob argument: ' + glob);
|
||||
}
|
||||
|
||||
if (!Array.isArray(glob)) {
|
||||
glob = [glob];
|
||||
}
|
||||
|
||||
glob = glob.map(normalize);
|
||||
|
||||
var outputStream = pipeline(
|
||||
gs(glob, opt),
|
||||
wrapVinyl(optResolver),
|
||||
resolveSymlinks(optResolver),
|
||||
prepare(optResolver),
|
||||
readContents(optResolver),
|
||||
sourcemap(optResolver)
|
||||
);
|
||||
|
||||
return toThrough(outputStream);
|
||||
}
|
||||
|
||||
module.exports = src;
|
35
node_modules/vinyl-fs/lib/src/options.js
generated
vendored
Normal file
35
node_modules/vinyl-fs/lib/src/options.js
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
'use strict';
|
||||
|
||||
var DEFAULT_ENCODING = require('../constants').DEFAULT_ENCODING;
|
||||
|
||||
var config = {
|
||||
buffer: {
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
},
|
||||
read: {
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
},
|
||||
since: {
|
||||
type: 'date',
|
||||
},
|
||||
removeBOM: {
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
},
|
||||
encoding: {
|
||||
type: ['string', 'boolean'],
|
||||
default: DEFAULT_ENCODING,
|
||||
},
|
||||
sourcemaps: {
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
},
|
||||
resolveSymlinks: {
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = config;
|
24
node_modules/vinyl-fs/lib/src/prepare.js
generated
vendored
Normal file
24
node_modules/vinyl-fs/lib/src/prepare.js
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
'use strict';
|
||||
|
||||
var Transform = require('streamx').Transform;
|
||||
|
||||
function prepareRead(optResolver) {
|
||||
function normalize(file, callback) {
|
||||
var since = optResolver.resolve('since', file);
|
||||
|
||||
if (file.stat) {
|
||||
// Skip this file if since option is set and current file is too old
|
||||
if (Math.max(file.stat.mtime, file.stat.ctime) <= since) {
|
||||
return callback();
|
||||
}
|
||||
}
|
||||
|
||||
return callback(null, file);
|
||||
}
|
||||
|
||||
return new Transform({
|
||||
transform: normalize,
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = prepareRead;
|
52
node_modules/vinyl-fs/lib/src/read-contents/index.js
generated
vendored
Normal file
52
node_modules/vinyl-fs/lib/src/read-contents/index.js
generated
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
'use strict';
|
||||
|
||||
var Transform = require('streamx').Transform;
|
||||
|
||||
var readDir = require('./read-dir');
|
||||
var readStream = require('./read-stream');
|
||||
var readBuffer = require('./read-buffer');
|
||||
var readSymbolicLink = require('./read-symbolic-link');
|
||||
|
||||
function readContents(optResolver) {
|
||||
function readFile(file, callback) {
|
||||
// Skip reading contents if read option says so
|
||||
var read = optResolver.resolve('read', file);
|
||||
if (!read) {
|
||||
return callback(null, file);
|
||||
}
|
||||
|
||||
// Don't fail to read a directory
|
||||
if (file.isDirectory()) {
|
||||
return readDir(file, optResolver, onRead);
|
||||
}
|
||||
|
||||
// Process symbolic links included with `resolveSymlinks` option
|
||||
if (file.stat && file.stat.isSymbolicLink()) {
|
||||
return readSymbolicLink(file, optResolver, onRead);
|
||||
}
|
||||
|
||||
// Read and pass full contents
|
||||
var buffer = optResolver.resolve('buffer', file);
|
||||
if (buffer) {
|
||||
return readBuffer(file, optResolver, onRead);
|
||||
}
|
||||
|
||||
// Don't buffer anything - just pass streams
|
||||
return readStream(file, optResolver, onRead);
|
||||
|
||||
// This is invoked by the various readXxx modules when they've finished
|
||||
// reading the contents.
|
||||
function onRead(readErr) {
|
||||
if (readErr) {
|
||||
return callback(readErr);
|
||||
}
|
||||
callback(null, file);
|
||||
}
|
||||
}
|
||||
|
||||
return new Transform({
|
||||
transform: readFile,
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = readContents;
|
37
node_modules/vinyl-fs/lib/src/read-contents/read-buffer.js
generated
vendored
Normal file
37
node_modules/vinyl-fs/lib/src/read-contents/read-buffer.js
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
'use strict';
|
||||
|
||||
var fs = require('graceful-fs');
|
||||
|
||||
var getCodec = require('../../codecs');
|
||||
var DEFAULT_ENCODING = require('../../constants').DEFAULT_ENCODING;
|
||||
|
||||
function bufferFile(file, optResolver, onRead) {
|
||||
var encoding = optResolver.resolve('encoding', file);
|
||||
var codec = getCodec(encoding);
|
||||
if (encoding && !codec) {
|
||||
return onRead(new Error('Unsupported encoding: ' + encoding));
|
||||
}
|
||||
|
||||
fs.readFile(file.path, onReadFile);
|
||||
|
||||
function onReadFile(readErr, contents) {
|
||||
if (readErr) {
|
||||
return onRead(readErr);
|
||||
}
|
||||
|
||||
if (encoding) {
|
||||
var removeBOM = codec.bomAware && optResolver.resolve('removeBOM', file);
|
||||
|
||||
if (removeBOM || codec.enc !== DEFAULT_ENCODING) {
|
||||
contents = codec.decode(contents, { removeBOM: removeBOM });
|
||||
contents = getCodec(DEFAULT_ENCODING).encode(contents);
|
||||
}
|
||||
}
|
||||
|
||||
file.contents = contents;
|
||||
|
||||
onRead();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = bufferFile;
|
8
node_modules/vinyl-fs/lib/src/read-contents/read-dir.js
generated
vendored
Normal file
8
node_modules/vinyl-fs/lib/src/read-contents/read-dir.js
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
'use strict';
|
||||
|
||||
function readDir(file, optResolver, onRead) {
|
||||
// Do nothing for now
|
||||
onRead();
|
||||
}
|
||||
|
||||
module.exports = readDir;
|
46
node_modules/vinyl-fs/lib/src/read-contents/read-stream.js
generated
vendored
Normal file
46
node_modules/vinyl-fs/lib/src/read-contents/read-stream.js
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
'use strict';
|
||||
|
||||
var fs = require('graceful-fs');
|
||||
var Composer = require('stream-composer');
|
||||
|
||||
var getCodec = require('../../codecs');
|
||||
var DEFAULT_ENCODING = require('../../constants').DEFAULT_ENCODING;
|
||||
|
||||
function streamFile(file, optResolver, onRead) {
|
||||
var encoding = optResolver.resolve('encoding', file);
|
||||
var codec = getCodec(encoding);
|
||||
if (encoding && !codec) {
|
||||
return onRead(new Error('Unsupported encoding: ' + encoding));
|
||||
}
|
||||
|
||||
var filePath = file.path;
|
||||
|
||||
file.contents = new Composer({
|
||||
open: function (cb) {
|
||||
var contents = fs.createReadStream(filePath);
|
||||
var streams = [contents];
|
||||
|
||||
if (encoding) {
|
||||
var removeBOM =
|
||||
codec.bomAware && optResolver.resolve('removeBOM', file);
|
||||
|
||||
if (removeBOM || codec.enc !== DEFAULT_ENCODING) {
|
||||
streams.push(codec.decodeStream({ removeBOM: removeBOM }));
|
||||
streams.push(getCodec(DEFAULT_ENCODING).encodeStream());
|
||||
}
|
||||
}
|
||||
|
||||
if (streams.length > 1) {
|
||||
this.setPipeline(streams);
|
||||
} else {
|
||||
this.setReadable(contents);
|
||||
}
|
||||
|
||||
cb();
|
||||
},
|
||||
});
|
||||
|
||||
onRead();
|
||||
}
|
||||
|
||||
module.exports = streamFile;
|
20
node_modules/vinyl-fs/lib/src/read-contents/read-symbolic-link.js
generated
vendored
Normal file
20
node_modules/vinyl-fs/lib/src/read-contents/read-symbolic-link.js
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
'use strict';
|
||||
|
||||
var fs = require('graceful-fs');
|
||||
|
||||
function readLink(file, optResolver, onRead) {
|
||||
fs.readlink(file.path, onReadlink);
|
||||
|
||||
function onReadlink(readErr, target) {
|
||||
if (readErr) {
|
||||
return onRead(readErr);
|
||||
}
|
||||
|
||||
// Store the link target path
|
||||
file.symlink = target;
|
||||
|
||||
onRead();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = readLink;
|
44
node_modules/vinyl-fs/lib/src/resolve-symlinks.js
generated
vendored
Normal file
44
node_modules/vinyl-fs/lib/src/resolve-symlinks.js
generated
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
'use strict';
|
||||
|
||||
var Transform = require('streamx').Transform;
|
||||
var fo = require('../file-operations');
|
||||
|
||||
function resolveSymlinks(optResolver) {
|
||||
// A stat property is exposed on file objects as a (wanted) side effect
|
||||
function resolveFile(file, callback) {
|
||||
fo.reflectLinkStat(file.path, file, onReflect);
|
||||
|
||||
function onReflect(statErr) {
|
||||
if (statErr) {
|
||||
return callback(statErr);
|
||||
}
|
||||
|
||||
if (!file.stat.isSymbolicLink()) {
|
||||
return callback(null, file);
|
||||
}
|
||||
|
||||
var resolveSymlinks = optResolver.resolve('resolveSymlinks', file);
|
||||
|
||||
if (!resolveSymlinks) {
|
||||
return callback(null, file);
|
||||
}
|
||||
|
||||
fo.findSymlinkHardpath(file.path, onSymlinkHardpath);
|
||||
}
|
||||
|
||||
function onSymlinkHardpath(readlinkErr, path) {
|
||||
if (readlinkErr) {
|
||||
return callback(readlinkErr);
|
||||
}
|
||||
|
||||
// Get target's stats
|
||||
fo.reflectStat(path, file, onReflect);
|
||||
}
|
||||
}
|
||||
|
||||
return new Transform({
|
||||
transform: resolveFile,
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = resolveSymlinks;
|
30
node_modules/vinyl-fs/lib/src/sourcemap.js
generated
vendored
Normal file
30
node_modules/vinyl-fs/lib/src/sourcemap.js
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
'use strict';
|
||||
|
||||
var Transform = require('streamx').Transform;
|
||||
var sourcemap = require('vinyl-sourcemap');
|
||||
|
||||
function sourcemapStream(optResolver) {
|
||||
function addSourcemap(file, callback) {
|
||||
var srcMap = optResolver.resolve('sourcemaps', file);
|
||||
|
||||
if (!srcMap) {
|
||||
return callback(null, file);
|
||||
}
|
||||
|
||||
sourcemap.add(file, onAdd);
|
||||
|
||||
function onAdd(sourcemapErr, updatedFile) {
|
||||
if (sourcemapErr) {
|
||||
return callback(sourcemapErr);
|
||||
}
|
||||
|
||||
callback(null, updatedFile);
|
||||
}
|
||||
}
|
||||
|
||||
return new Transform({
|
||||
transform: addSourcemap,
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = sourcemapStream;
|
18
node_modules/vinyl-fs/lib/src/wrap-vinyl.js
generated
vendored
Normal file
18
node_modules/vinyl-fs/lib/src/wrap-vinyl.js
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
'use strict';
|
||||
|
||||
var File = require('vinyl');
|
||||
var Transform = require('streamx').Transform;
|
||||
|
||||
function wrapVinyl() {
|
||||
function wrapFile(globFile, callback) {
|
||||
var file = new File(globFile);
|
||||
|
||||
callback(null, file);
|
||||
}
|
||||
|
||||
return new Transform({
|
||||
transform: wrapFile,
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = wrapVinyl;
|
45
node_modules/vinyl-fs/lib/symlink/index.js
generated
vendored
Normal file
45
node_modules/vinyl-fs/lib/symlink/index.js
generated
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
'use strict';
|
||||
|
||||
var lead = require('lead');
|
||||
var composer = require('stream-composer');
|
||||
var mkdirpStream = require('fs-mkdirp-stream');
|
||||
var createResolver = require('resolve-options');
|
||||
|
||||
var config = require('./options');
|
||||
var prepare = require('./prepare');
|
||||
var linkFile = require('./link-file');
|
||||
|
||||
var folderConfig = {
|
||||
outFolder: {
|
||||
type: 'string',
|
||||
},
|
||||
};
|
||||
|
||||
function symlink(outFolder, opt) {
|
||||
if (!outFolder) {
|
||||
throw new Error(
|
||||
'Invalid symlink() folder argument.' +
|
||||
' Please specify a non-empty string or a function.'
|
||||
);
|
||||
}
|
||||
|
||||
var optResolver = createResolver(config, opt);
|
||||
var folderResolver = createResolver(folderConfig, { outFolder: outFolder });
|
||||
|
||||
function dirpath(file, callback) {
|
||||
var dirMode = optResolver.resolve('dirMode', file);
|
||||
|
||||
callback(null, file.dirname, dirMode);
|
||||
}
|
||||
|
||||
var stream = composer.pipeline(
|
||||
prepare(folderResolver, optResolver),
|
||||
mkdirpStream(dirpath),
|
||||
linkFile(optResolver)
|
||||
);
|
||||
|
||||
// Sink the stream to start flowing
|
||||
return lead(stream);
|
||||
}
|
||||
|
||||
module.exports = symlink;
|
90
node_modules/vinyl-fs/lib/symlink/link-file.js
generated
vendored
Normal file
90
node_modules/vinyl-fs/lib/symlink/link-file.js
generated
vendored
Normal file
@@ -0,0 +1,90 @@
|
||||
'use strict';
|
||||
|
||||
var os = require('os');
|
||||
var path = require('path');
|
||||
|
||||
var Transform = require('streamx').Transform;
|
||||
|
||||
var fo = require('../file-operations');
|
||||
|
||||
var isWindows = os.platform() === 'win32';
|
||||
|
||||
function linkStream(optResolver) {
|
||||
function linkFile(file, callback) {
|
||||
var isRelative = optResolver.resolve('relativeSymlinks', file);
|
||||
var flags = fo.getFlags({
|
||||
overwrite: optResolver.resolve('overwrite', file),
|
||||
append: false,
|
||||
});
|
||||
|
||||
if (!isWindows) {
|
||||
// On non-Windows, just use 'file'
|
||||
return createLinkWithType('file');
|
||||
}
|
||||
|
||||
fo.reflectStat(file.symlink, file, onReflectTarget);
|
||||
|
||||
function onReflectTarget(statErr) {
|
||||
if (statErr && statErr.code !== 'ENOENT') {
|
||||
return callback(statErr);
|
||||
}
|
||||
// If target doesn't exist, the vinyl will still carry the target stats.
|
||||
// Let's use those to determine which kind of dangling link to create.
|
||||
|
||||
// This option provides a way to create a Junction instead of a
|
||||
// Directory symlink on Windows. This comes with the following caveats:
|
||||
// * NTFS Junctions cannot be relative.
|
||||
// * NTFS Junctions MUST be directories.
|
||||
// * NTFS Junctions must be on the same file system.
|
||||
// * Most products CANNOT detect a directory is a Junction:
|
||||
// This has the side effect of possibly having a whole directory
|
||||
// deleted when a product is deleting the Junction directory.
|
||||
// For example, JetBrains product lines will delete the entire contents
|
||||
// of the TARGET directory because the product does not realize it's
|
||||
// a symlink as the JVM and Node return false for isSymlink.
|
||||
|
||||
// This function is Windows only, so we don't need to check again
|
||||
var useJunctions = optResolver.resolve('useJunctions', file);
|
||||
|
||||
var dirType = useJunctions ? 'junction' : 'dir';
|
||||
var type = !statErr && file.isDirectory() ? dirType : 'file';
|
||||
|
||||
createLinkWithType(type);
|
||||
}
|
||||
|
||||
function createLinkWithType(type) {
|
||||
// This is done after prepare() to use the adjusted file.base property
|
||||
if (isRelative && type !== 'junction') {
|
||||
file.symlink = path.relative(file.base, file.symlink);
|
||||
}
|
||||
|
||||
var opts = {
|
||||
flags: flags,
|
||||
type: type,
|
||||
};
|
||||
fo.symlink(file.symlink, file.path, opts, onSymlink);
|
||||
}
|
||||
|
||||
function onSymlink(symlinkErr) {
|
||||
if (symlinkErr) {
|
||||
return callback(symlinkErr);
|
||||
}
|
||||
|
||||
fo.reflectLinkStat(file.path, file, onReflectLink);
|
||||
}
|
||||
|
||||
function onReflectLink(reflectErr) {
|
||||
if (reflectErr) {
|
||||
return callback(reflectErr);
|
||||
}
|
||||
|
||||
callback(null, file);
|
||||
}
|
||||
}
|
||||
|
||||
return new Transform({
|
||||
transform: linkFile,
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = linkStream;
|
26
node_modules/vinyl-fs/lib/symlink/options.js
generated
vendored
Normal file
26
node_modules/vinyl-fs/lib/symlink/options.js
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
'use strict';
|
||||
|
||||
var config = {
|
||||
cwd: {
|
||||
type: 'string',
|
||||
default: process.cwd,
|
||||
},
|
||||
dirMode: {
|
||||
type: 'number',
|
||||
},
|
||||
overwrite: {
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
},
|
||||
relativeSymlinks: {
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
},
|
||||
// This option is ignored on non-Windows platforms
|
||||
useJunctions: {
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = config;
|
54
node_modules/vinyl-fs/lib/symlink/prepare.js
generated
vendored
Normal file
54
node_modules/vinyl-fs/lib/symlink/prepare.js
generated
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
'use strict';
|
||||
|
||||
var path = require('path');
|
||||
|
||||
var fs = require('graceful-fs');
|
||||
var Vinyl = require('vinyl');
|
||||
var Transform = require('streamx').Transform;
|
||||
|
||||
function prepareSymlink(folderResolver, optResolver) {
|
||||
if (!folderResolver) {
|
||||
throw new Error('Invalid output folder');
|
||||
}
|
||||
|
||||
function normalize(file, cb) {
|
||||
if (!Vinyl.isVinyl(file)) {
|
||||
return cb(new Error('Received a non-Vinyl object in `symlink()`'));
|
||||
}
|
||||
|
||||
// TODO: Remove this after people upgrade vinyl/transition from gulp-util
|
||||
if (typeof file.isSymbolic !== 'function') {
|
||||
file = new Vinyl(file);
|
||||
}
|
||||
|
||||
var cwd = path.resolve(optResolver.resolve('cwd', file));
|
||||
|
||||
var outFolderPath = folderResolver.resolve('outFolder', file);
|
||||
if (!outFolderPath) {
|
||||
return cb(new Error('Invalid output folder'));
|
||||
}
|
||||
var basePath = path.resolve(cwd, outFolderPath);
|
||||
var writePath = path.resolve(basePath, file.relative);
|
||||
|
||||
// Wire up new properties
|
||||
// Note: keep the target stats for now, we may need them in link-file
|
||||
file.stat = file.stat || new fs.Stats();
|
||||
file.cwd = cwd;
|
||||
file.base = basePath;
|
||||
// This is the path we are linking *TO*
|
||||
// Use `file.symlink` if it was set in the pipeline
|
||||
file.symlink = file.symlink || file.path;
|
||||
file.path = writePath;
|
||||
// We have to set contents to null for a link
|
||||
// Otherwise `isSymbolic()` returns false
|
||||
file.contents = null;
|
||||
|
||||
cb(null, file);
|
||||
}
|
||||
|
||||
return new Transform({
|
||||
transform: normalize,
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = prepareSymlink;
|
70
node_modules/vinyl-fs/package.json
generated
vendored
Normal file
70
node_modules/vinyl-fs/package.json
generated
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
{
|
||||
"name": "vinyl-fs",
|
||||
"version": "4.0.0",
|
||||
"description": "Vinyl adapter for the file system.",
|
||||
"author": "Gulp Team <team@gulpjs.com> (https://gulpjs.com/)",
|
||||
"contributors": [
|
||||
"Eric Schoffstall <yo@contra.io>",
|
||||
"Blaine Bublitz <blaine.bublitz@gmail.com>"
|
||||
],
|
||||
"repository": "gulpjs/vinyl-fs",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=10.13.0"
|
||||
},
|
||||
"main": "index.js",
|
||||
"files": [
|
||||
"LICENSE",
|
||||
"index.js",
|
||||
"lib"
|
||||
],
|
||||
"scripts": {
|
||||
"lint": "eslint .",
|
||||
"pretest": "npm run lint",
|
||||
"test": "nyc mocha --async-only"
|
||||
},
|
||||
"dependencies": {
|
||||
"fs-mkdirp-stream": "^2.0.1",
|
||||
"glob-stream": "^8.0.0",
|
||||
"graceful-fs": "^4.2.11",
|
||||
"iconv-lite": "^0.6.3",
|
||||
"is-valid-glob": "^1.0.0",
|
||||
"lead": "^4.0.0",
|
||||
"normalize-path": "3.0.0",
|
||||
"resolve-options": "^2.0.0",
|
||||
"stream-composer": "^1.0.2",
|
||||
"streamx": "^2.14.0",
|
||||
"to-through": "^3.0.0",
|
||||
"value-or-function": "^4.0.0",
|
||||
"vinyl": "^3.0.0",
|
||||
"vinyl-sourcemap": "^2.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"eslint": "^7.32.0",
|
||||
"eslint-config-gulp": "^5.0.1",
|
||||
"expect": "^27.5.1",
|
||||
"mocha": "^8.4.0",
|
||||
"nyc": "^15.1.0",
|
||||
"readable-stream": "3.6.0",
|
||||
"rimraf": "^3.0.2",
|
||||
"sinon": "^15.0.2"
|
||||
},
|
||||
"nyc": {
|
||||
"reporter": [
|
||||
"lcov",
|
||||
"text-summary"
|
||||
]
|
||||
},
|
||||
"prettier": {
|
||||
"singleQuote": true
|
||||
},
|
||||
"keywords": [
|
||||
"gulp",
|
||||
"vinyl-adapter",
|
||||
"vinyl",
|
||||
"file",
|
||||
"file system",
|
||||
"fs",
|
||||
"streams"
|
||||
]
|
||||
}
|
Reference in New Issue
Block a user