Current Dev State

This commit is contained in:
Tim Lorsbach
2025-06-23 20:13:54 +02:00
parent b4f9bb277d
commit ded50edaa2
22617 changed files with 4345095 additions and 174 deletions

View File

@ -0,0 +1,15 @@
## ISC License
Copyright (c) 2014, Florian Reiterer
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

View File

@ -0,0 +1,407 @@
## gulp-sourcemaps [![NPM version][npm-image]][npm-url] [![build status][travis-image]][travis-url] [![Test coverage][coveralls-image]][coveralls-url]
### Branching
__2.X now supports node 0.10+ due to switching out a dependency.__
### Usage
#### Write inline source maps
Inline source maps are embedded in the source file.
Example:
```javascript
var gulp = require('gulp');
var plugin1 = require('gulp-plugin1');
var plugin2 = require('gulp-plugin2');
var sourcemaps = require('gulp-sourcemaps');
gulp.task('javascript', function() {
gulp.src('src/**/*.js')
.pipe(sourcemaps.init())
.pipe(plugin1())
.pipe(plugin2())
.pipe(sourcemaps.write())
.pipe(gulp.dest('dist'));
});
```
All plugins between `sourcemaps.init()` and `sourcemaps.write()` need to have support for `gulp-sourcemaps`. You can find a list of such plugins in the [wiki](https://github.com/gulp-sourcemaps/gulp-sourcemaps/wiki/Plugins-with-gulp-sourcemaps-support).
#### Write external source map files
To write external source map files, pass a path relative to the destination to `sourcemaps.write()`.
Example:
```javascript
var gulp = require('gulp');
var plugin1 = require('gulp-plugin1');
var plugin2 = require('gulp-plugin2');
var sourcemaps = require('gulp-sourcemaps');
gulp.task('javascript', function() {
gulp.src('src/**/*.js')
.pipe(sourcemaps.init())
.pipe(plugin1())
.pipe(plugin2())
.pipe(sourcemaps.write('../maps'))
.pipe(gulp.dest('dist'));
});
```
#### Load existing source maps
To load existing source maps, pass the option `loadMaps: true` to `sourcemaps.init()`.
Example:
```javascript
var gulp = require('gulp');
var plugin1 = require('gulp-plugin1');
var plugin2 = require('gulp-plugin2');
var sourcemaps = require('gulp-sourcemaps');
gulp.task('javascript', function() {
gulp.src('src/**/*.js')
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(plugin1())
.pipe(plugin2())
.pipe(sourcemaps.write())
.pipe(gulp.dest('dist'));
});
```
#### Handle large files
To handle large files, pass the option `largeFile: true` to `sourcemaps.init()`.
Example:
```javascript
var gulp = require('gulp');
var plugin1 = require('gulp-plugin1');
var plugin2 = require('gulp-plugin2');
var sourcemaps = require('gulp-sourcemaps');
gulp.task('javascript', function() {
gulp.src('src/**/*.js')
.pipe(sourcemaps.init({largeFile: true}))
.pipe(plugin1())
.pipe(plugin2())
.pipe(sourcemaps.write())
.pipe(gulp.dest('dist'));
});
```
#### Handle source files from different directories
Use the `base` option on `gulp.src` to make sure all files are relative to a common base directory.
Example:
```javascript
var gulp = require('gulp');
var plugin1 = require('gulp-plugin1');
var plugin2 = require('gulp-plugin2');
var sourcemaps = require('gulp-sourcemaps');
gulp.task('javascript', function() {
gulp.src(['src/test.js', 'src/testdir/test2.js'], { base: 'src' })
.pipe(sourcemaps.init())
.pipe(plugin1())
.pipe(plugin2())
.pipe(sourcemaps.write('../maps'))
.pipe(gulp.dest('dist'));
});
```
#### Alter `sources` property on sourcemaps
The exported `mapSources` method gives full control over the source paths. It takes a function that is called for every source and receives the default source path as a parameter and the original vinyl file.
Example:
```javascript
gulp.task('javascript', function() {
var stream = gulp.src('src/**/*.js')
.pipe(sourcemaps.init())
.pipe(plugin1())
.pipe(plugin2())
// be careful with the sources returned otherwise contents might not be loaded properly
.pipe(sourcemaps.mapSources(function(sourcePath, file) {
// source paths are prefixed with '../src/'
return '../src/' + sourcePath;
}))
.pipe(sourcemaps.write('../maps')
.pipe(gulp.dest('public/scripts'));
});
```
#### Generate Identity Sourcemap
The exported `identityMap` method allows you to generate a full valid source map encoding no changes (slower, only for Javascript and CSS) instead of the default empty source map (no mappings, fast). __Use this option if you get missing or incorrect mappings, e.g. when debugging.__
Example:
```javascript
gulp.task('javascript', function() {
var stream = gulp.src('src/**/*.js')
.pipe(sourcemaps.init())
// An identity sourcemap will be generated at this step
.pipe(sourcemaps.identityMap())
.pipe(plugin1())
.pipe(plugin2())
.pipe(sourcemaps.write('../maps')
.pipe(gulp.dest('public/scripts'));
});
```
### Init Options
- `loadMaps`
Set to true to load existing maps for source files. Supports the following:
- inline source maps
- source map files referenced by a `sourceMappingURL=` comment
- source map files with the same name (plus .map) in the same directory
- `identityMap`
__This option is deprecated. Upgrade to use our [`sourcemap.identityMap`](#generate-identity-sourcemap) API.__
### Write Options
- `addComment`
By default a comment containing / referencing the source map is added. Set this to `false` to disable the comment (e.g. if you want to load the source maps by header).
Example:
```javascript
gulp.task('javascript', function() {
var stream = gulp.src('src/**/*.js')
.pipe(sourcemaps.init())
.pipe(plugin1())
.pipe(plugin2())
.pipe(sourcemaps.write('../maps', {addComment: false}))
.pipe(gulp.dest('dist'));
});
```
- `includeContent`
By default the source maps include the source code. Pass `false` to use the original files.
Including the content is the recommended way, because it "just works". When setting this to `false` you have to host the source files and set the correct `sourceRoot`.
- `sourceRoot`
Set the location where the source files are hosted (use this when `includeContent` is set to `false`). This is usually a URL (or an absolute URL path), not a local file system path.
By default the source root is '' or in case `destPath` is set, the relative path from the source map to the source base directory (this should work for many dev environments).
If a relative path is used (empty string or one starting with a `.`), it is interpreted as a path relative to the destination. The plugin rewrites it to a path relative to each source map.
Example:
```javascript
gulp.task('javascript', function() {
var stream = gulp.src('src/**/*.js')
.pipe(sourcemaps.init())
.pipe(plugin1())
.pipe(plugin2())
.pipe(sourcemaps.write({includeContent: false, sourceRoot: '/src'}))
.pipe(gulp.dest('dist'));
});
```
Example (using a function):
```javascript
gulp.task('javascript', function() {
var stream = gulp.src('src/**/*.js')
.pipe(sourcemaps.init())
.pipe(plugin1())
.pipe(plugin2())
.pipe(sourcemaps.write({
includeContent: false,
sourceRoot: function(file) {
return '/src';
}
}))
.pipe(gulp.dest('dist'));
});
```
Example (relative path):
```javascript
gulp.task('javascript', function() {
var stream = gulp.src('src/**/*.js')
.pipe(sourcemaps.init())
.pipe(plugin1())
.pipe(plugin2())
.pipe(sourcemaps.write('.', {includeContent: false, sourceRoot: '../src'}))
.pipe(gulp.dest('dist'));
});
```
In this case for a file written to `dist/subdir/example.js`, the source map is written to `dist/subdir/example.js.map` and the sourceRoot will be `../../src` (resulting in the full source path `../../src/subdir/example.js`).
- `destPath`
Set the destination path (the same you pass to `gulp.dest()`). If the source map destination path is not a subpath of the destination path, this is needed to get the correct path in the `file` property of the source map.
In addition, it allows to automatically set a relative `sourceRoot` if none is set explicitly.
- `sourceMappingURLPrefix`
Specify a prefix to be prepended onto the source map URL when writing external source maps. Relative paths will have their leading dots stripped.
Example:
```javascript
gulp.task('javascript', function() {
var stream = gulp.src('src/**/*.js')
.pipe(sourcemaps.init())
.pipe(plugin1())
.pipe(plugin2())
.pipe(sourcemaps.write('../maps', {
sourceMappingURLPrefix: 'https://asset-host.example.com/assets'
}))
.pipe(gulp.dest('public/scripts'));
});
```
This will result in a source mapping URL comment like `sourceMappingURL=https://asset-host.example.com/assets/maps/helloworld.js.map`.
- `sourceMappingURL`
If you need full control over the source map URL you can pass a function to this option. The output of the function must be the full URL to the source map (in function of the output file).
Example:
```javascript
gulp.task('javascript', function() {
var stream = gulp.src('src/**/*.js')
.pipe(sourcemaps.init())
.pipe(plugin1())
.pipe(plugin2())
.pipe(sourcemaps.write('../maps', {
sourceMappingURL: function(file) {
return 'https://asset-host.example.com/' + file.relative + '.map';
}
}))
.pipe(gulp.dest('public/scripts'));
});
```
This will result in a source mapping URL comment like `sourceMappingURL=https://asset-host.example.com/helloworld.js.map`.
- `mapFile`
This option allows to rename the map file. It takes a function that is called for every map and receives the default map path as a parameter.
Example:
```javascript
gulp.task('javascript', function() {
var stream = gulp.src('src/**/*.js')
.pipe(sourcemaps.init())
.pipe(plugin1())
.pipe(plugin2())
.pipe(sourcemaps.write('../maps', {
mapFile: function(mapFilePath) {
// source map files are named *.map instead of *.js.map
return mapFilePath.replace('.js.map', '.map');
}
}))
.pipe(gulp.dest('public/scripts'));
});
```
- `mapSources`
__This option is deprecated. Upgrade to use our [`sourcemap.mapSources`](#alter-sources-property-on-sourcemaps) API.__
- `charset`
Sets the charset for inline source maps. Default: `utf8`
- `clone`
Clones the original file for creation of the map file. Could be important if file history is important. See [file.clone()](https://github.com/gulpjs/vinyl#filecloneoptions) for possible options. Default: `{deep:false, contents:false}`
### Plugin developers only:
- **How to add source map support to plugins**
- Generate a source map for the transformation the plugin is applying
- **Important**: Make sure the paths in the generated source map (`file` and `sources`) are relative to `file.base` (e.g. use `file.relative`).
- Apply this source map to the vinyl `file`. E.g. by using [vinyl-sourcemaps-apply](https://github.com/gulp-sourcemaps/vinyl-sourcemaps-apply).
This combines the source map of this plugin with the source maps coming from plugins further up the chain.
- Add your plugin to the [wiki page](https://github.com/gulp-sourcemaps/gulp-sourcemaps/wiki/Plugins-with-gulp-sourcemaps-support)
#### Example:
```js
var through = require('through2');
var applySourceMap = require('vinyl-sourcemaps-apply');
var myTransform = require('myTransform');
module.exports = function(options) {
function transform(file, encoding, callback) {
// generate source maps if plugin source-map present
if (file.sourceMap) {
options.makeSourceMaps = true;
}
// do normal plugin logic
var result = myTransform(file.contents, options);
file.contents = new Buffer(result.code);
// apply source map to the chain
if (file.sourceMap) {
applySourceMap(file, result.map);
}
this.push(file);
callback();
}
return through.obj(transform);
};
```
- **Very sourcemaps is working**
See example below or refer to [test/write.js](./test/write.js)
#### Example:
```js
var stream = plugin();
var init = sourcemaps.init();
var write = sourcemaps.write();
init.pipe(stream).pipe(write);
write.on('data', function (file) {
assert(...);
cb();
});
init.write(new gutil.File(...));
init.end();
```
### Debugging
All debugging output relys on [visionmedia/debug](https://github.com/visionmedia/debug). Fllow the directions to set the
environment variable ``$DEBUG`.
For a few examples of debug you could use:
```sh
DEBUG='gulp-sourcemaps:*' #everything
DEBUG='gulp-sourcemaps:init' #init/index.js
DEBUG='gulp-sourcemaps:init:*' #init/index.internals.js
DEBUG='gulp-sourcemaps:write:' #write/index.js
DEBUG='gulp-sourcemaps:write:*' #write/index.internals.js
DEBUG='gulp-sourcemaps:write:,gulp-sourcemaps:init:**' #write/index.internals.js and init/index.internals.js
```
[npm-image]: https://img.shields.io/npm/v/gulp-sourcemaps.svg
[npm-url]: https://www.npmjs.com/package/gulp-sourcemaps
[travis-image]: https://img.shields.io/travis/gulp-sourcemaps/gulp-sourcemaps.svg
[travis-url]: https://travis-ci.org/gulp-sourcemaps/gulp-sourcemaps
[coveralls-image]: https://img.shields.io/coveralls/gulp-sourcemaps/gulp-sourcemaps.svg
[coveralls-url]: https://coveralls.io/r/gulp-sourcemaps/gulp-sourcemaps?branch=master

View File

@ -0,0 +1,8 @@
'use strict';
module.exports = {
init: require('./src/init'),
write: require('./src/write'),
mapSources: require('@gulp-sourcemaps/map-sources'),
identityMap: require('@gulp-sourcemaps/identity-map')
};

View File

@ -0,0 +1,163 @@
## Change Log
### v1.1.1 (2016/01/18 23:23 +00:00)
- [3990e00](https://github.com/gulpjs/vinyl/commit/3990e007b004c809a53670c00566afb157fa56b6) 1.1.1
- [2d3e984](https://github.com/gulpjs/vinyl/commit/2d3e98447a42285b593e1b261984b87b171e7313) chore: add NPM script for changelog (@T1st3)
- [f70c395](https://github.com/gulpjs/vinyl/commit/f70c395085fc3952cf72c061c851f5b0d4676030) docs: add CHANGELOG.md (@T1st3)
- [#74](https://github.com/gulpjs/vinyl/pull/74) Fix isVinyl for falsy values (@erikkemperman)
- [3e8b132](https://github.com/gulpjs/vinyl/commit/3e8b132cd87bf5ab536ff7a4c6d660e33f5990b4) Fix isVinyl for falsy values (@erikkemperman)
- [#73](https://github.com/gulpjs/vinyl/pull/73) Readme: use SVG images. (@d10)
- [193e3d2](https://github.com/gulpjs/vinyl/commit/193e3d25f68c97593e011981e49db2c3e7a47d91) Readme: use SVG images. (@d10)
- [#67](https://github.com/gulpjs/vinyl/pull/67) Set Travis to sudo:false and add node 0.12/4.x (@pdehaan)
- [c33d85a](https://github.com/gulpjs/vinyl/commit/c33d85ab1d63fbcd272f7fb91d666006dab76d99) Set Travis to sudo:false and add node 0.12/4.x (@pdehaan)
### v1.1.0 (2015/10/23 06:33 +00:00)
- [51052ad](https://github.com/gulpjs/vinyl/commit/51052add24bb1c771bf5912809b47d4d53288c48) 1.1.0
- [#64](https://github.com/gulpjs/vinyl/pull/64) File.stem for basename without suffix (@soslan)
- [e505375](https://github.com/gulpjs/vinyl/commit/e5053756a49ea8800cd5da12fc0eefce859ccf61) Following JSCS rules in File.stem (@soslan)
- [d45f478](https://github.com/gulpjs/vinyl/commit/d45f478c7af3f2e956e57ce6d7550d64e3b7dbfb) Following JSCS rules (@soslan)
- [#66](https://github.com/gulpjs/vinyl/pull/66) Replace JSHint with ESLint (@pdehaan)
- [c5549f7](https://github.com/gulpjs/vinyl/commit/c5549f7002ae580fa9a7f7df490d6e3911af2285) Bump to eslint-config-gulp@2 (@pdehaan)
- [f6a5512](https://github.com/gulpjs/vinyl/commit/f6a55125e7230621ecae1f395da202140baaee1d) Replace JSHint with ESLint (@pdehaan)
- [#65](https://github.com/gulpjs/vinyl/pull/65) Add JSCS to repo (@pdehaan)
- [f9a0101](https://github.com/gulpjs/vinyl/commit/f9a0101d013356056293d21356d4cb443613b0be) Comments should start with uppercase letters (per JSCS) (@pdehaan)
- [6506478](https://github.com/gulpjs/vinyl/commit/650647833e3cea8d005a3ab1810ecd285418fa1e) Add JSCS to repo (@pdehaan)
- [ae3778c](https://github.com/gulpjs/vinyl/commit/ae3778c536a898fe47bbb37e5932b300123b28b8) Documentation for File.stem (@soslan)
- [e2246af](https://github.com/gulpjs/vinyl/commit/e2246af8aad6df348557f9d1df5001c30ff83774) add stem property to File (@soslan)
- [#63](https://github.com/gulpjs/vinyl/pull/63) Fix broken badge URLs in README.md (@tatsuyafw)
- [032ae7c](https://github.com/gulpjs/vinyl/commit/032ae7c5c59b72dc58041a14449d8d66af053023) Use reference links (@tatsuyafw)
- [652bc3b](https://github.com/gulpjs/vinyl/commit/652bc3bd3cc7a6af5d21d8d759a01cee3ce46acf) Fix some broken links in README.md (@tatsuyafw)
### v1.0.0 (2015/09/25 22:40 +00:00)
- [dbe943d](https://github.com/gulpjs/vinyl/commit/dbe943dad575b04995f38a35bd27962f54dc8217) 1.0.0 (@contra)
- [0b64336](https://github.com/gulpjs/vinyl/commit/0b643367289db0cfefc6c628eff2be4ee019405c) correct url (@contra)
- [#60](https://github.com/gulpjs/vinyl/pull/60) remove <br> from README.md (@bobintornado)
- [d9ae5ea](https://github.com/gulpjs/vinyl/commit/d9ae5eab010fd15094c8a0260a25d1244f17df79) remove <br> from README.md (@bobintornado)
### v0.5.3 (2015/09/03 00:20 +00:00)
- [6f19648](https://github.com/gulpjs/vinyl/commit/6f19648bd67040bfd0dc755ad031e1e5e0b58429) 0.5.3 (@contra)
- [0fe8da7](https://github.com/gulpjs/vinyl/commit/0fe8da757a862bb956d88dec03ab6f99ca895f7f) add isVinyl function (@contra)
### v0.5.1 (2015/08/04 21:26 +00:00)
- [81692ec](https://github.com/gulpjs/vinyl/commit/81692ece22eb3b927dba74fedb54a2acb65a36eb) 0.5.1 (@contra)
- [#58](https://github.com/gulpjs/vinyl/pull/58) use Buffer.isBuffer instead of instanceof (@whyrusleeping)
- [7293a71](https://github.com/gulpjs/vinyl/commit/7293a71b9daf177d9b9f600f3acf00a73b95107c) condense isBuffer module to a one liner (@whyrusleeping)
- [e7208e2](https://github.com/gulpjs/vinyl/commit/e7208e2c27029405c7c9cf9c9a3263cdf1e0dfb8) also remove old comment (@whyrusleeping)
- [b4ac64b](https://github.com/gulpjs/vinyl/commit/b4ac64b85ce28093f576db4f006264438f546cb8) use Buffer.isBuffer instead of instanceof (@whyrusleeping)
- [#54](https://github.com/gulpjs/vinyl/pull/54) Fix file clone options (@danielhusar)
- [4b42095](https://github.com/gulpjs/vinyl/commit/4b42095d8e0cb4351a503da67752da15e6b59570) Fix file clone options (@danielhusar)
- [04f681e](https://github.com/gulpjs/vinyl/commit/04f681e4af8ffb99ea3a0a3eab1cc79793887560) closes #50 and #51 (@contra)
### v0.5.0 (2015/06/03 23:44 +00:00)
- [8fea984](https://github.com/gulpjs/vinyl/commit/8fea9843e6b2aca820ccfee394927ca073f88a05) 0.5.0 (@contra)
- [#52](https://github.com/gulpjs/vinyl/pull/52) Add explicit newlines to readme (@jeremyruppel)
- [027142c](https://github.com/gulpjs/vinyl/commit/027142cf62a3f0a68f4659a612ee782b24c00198) Add explicit newlines to readme (@jeremyruppel)
- [#46](https://github.com/gulpjs/vinyl/pull/46) Add dirname, basename and extname getters (@jeremyruppel)
- [e09817f](https://github.com/gulpjs/vinyl/commit/e09817f15e4ddfc28e1b3452bbca5e2ba1fc2f19) Add dirname, basename and extname accessors (@jeremyruppel)
- [#49](https://github.com/gulpjs/vinyl/pull/49) update license attribute (@pgilad)
- [e5b2670](https://github.com/gulpjs/vinyl/commit/e5b2670af205ca0fb6f589a396b89ab2845a91ac) update license attribut (@pgilad)
- [55f90e3](https://github.com/gulpjs/vinyl/commit/55f90e3763af84c7eb599bd6403dbe14f63d5513) dep updates (@contra)
- [#48](https://github.com/gulpjs/vinyl/pull/48) Update docs for `path` and `history` (@jmm)
- [231f32a](https://github.com/gulpjs/vinyl/commit/231f32a375aa9147d0a41ffd1ace773c45e66ee5) Document `path`. (@jmm)
- [93df183](https://github.com/gulpjs/vinyl/commit/93df18374b62de32c76862baf73e92f33b04882a) Document `options.history`. (@jmm)
- [2ed6a01](https://github.com/gulpjs/vinyl/commit/2ed6a012c03a78b46f9d41034969898a15fdfe15) Correct `options.path` default value docs. (@jmm)
- [edf1ecb](https://github.com/gulpjs/vinyl/commit/edf1ecb0698f355e137f9361a9a9a2581ca485e5) Document `history`. (@jmm)
- [#45](https://github.com/gulpjs/vinyl/pull/45) Update dependencies and devDependencies (@shinnn)
- [f1f9dfb](https://github.com/gulpjs/vinyl/commit/f1f9dfbb1346b608226e5847161bf48e0caa2c1e) update test script (@shinnn)
- [0737ef4](https://github.com/gulpjs/vinyl/commit/0737ef489f9cfffa2494b06edaab9a032f00eb7e) update dependencies and devDependencies (@shinnn)
- [#43](https://github.com/gulpjs/vinyl/pull/43) Document `file.clone()` arguments (@pascalduez)
- [3c5e95d](https://github.com/gulpjs/vinyl/commit/3c5e95d5f482ea9f28dd2d78b83166723cd121bb) Document `file.clone()` arguments (@pascalduez)
### v0.4.6 (2014/12/03 06:15 +00:00)
- [8255a5f](https://github.com/gulpjs/vinyl/commit/8255a5f1de7fecb1cd5e7ba7ac1ec997395f6be1) 0.4.6 (@contra)
- [37dafeb](https://github.com/gulpjs/vinyl/commit/37dafeb8cb0b33424e77fe67a094517925be2bef) dep update (@contra)
### v0.4.5 (2014/11/13 23:23 +00:00)
- [a7a8c68](https://github.com/gulpjs/vinyl/commit/a7a8c68a1df914b1f486a54a97b68e9186699d33) 0.4.5 (@contra)
- [ec094b4](https://github.com/gulpjs/vinyl/commit/ec094b43e36512894142baacef26dfffc5827114) reduce size by switching off lodash (@contra)
### v0.4.4 (2014/11/13 22:59 +00:00)
- [61834c9](https://github.com/gulpjs/vinyl/commit/61834c9429f2e6883a18f377bc5893031ea1c94f) 0.4.4 (@contra)
- [fd887b3](https://github.com/gulpjs/vinyl/commit/fd887b3d21ed47c2b4cf40b0c0ed7b2df9048b09) ignore some files for size reasons (@contra)
- [#37](https://github.com/gulpjs/vinyl/pull/37) Don't package coverage into NPM (@Dapperbot)
- [9b811b8](https://github.com/gulpjs/vinyl/commit/9b811b86529e2b4b0cc20936a6697b3d9df503a2) Don't package coverage into NPM (@lotyrin)
### v0.4.3 (2014/09/01 18:17 +00:00)
- [6eae432](https://github.com/gulpjs/vinyl/commit/6eae432519b007c313a8df83b093adfb97a2944c) 0.4.3 (@contra)
- [d220c85](https://github.com/gulpjs/vinyl/commit/d220c857259f0070ab38c7b50d90f184a919e472) fix funky history passing, closes #35 (@contra)
### v0.4.2 (2014/08/29 15:58 +00:00)
- [f33d6d5](https://github.com/gulpjs/vinyl/commit/f33d6d5c1b9d1f83e238521651114beb90a01019) 0.4.2 (@contra)
- [cd0d042](https://github.com/gulpjs/vinyl/commit/cd0d04272297363f27f8456818dbf675618939c3) remove native clone (@contra)
- [e4d8b99](https://github.com/gulpjs/vinyl/commit/e4d8b99c21a50700afd17173e1f3a2076e6fe860) minor speed enhancements (@contra)
- [2353e39](https://github.com/gulpjs/vinyl/commit/2353e3996ac67629da92c2af906bdfdbc6978065) minor speed ups (@contra)
### v0.4.1 (2014/08/29 14:34 +00:00)
- [0014b9b](https://github.com/gulpjs/vinyl/commit/0014b9bf4166fb5cbe94c439201752cda7991a70) 0.4.1 (@contra)
- [0142513](https://github.com/gulpjs/vinyl/commit/0142513b0727ad6a018b0944fea2bb4966d8bbfa) fix history cloning bug (@contra)
### v0.4.0 (2014/08/29 07:07 +00:00)
- [80d3f61](https://github.com/gulpjs/vinyl/commit/80d3f61445b347fc1c34f462f0ab800644e90e04) 0.4.0 (@contra)
- [#33](https://github.com/gulpjs/vinyl/pull/33) Clone stream (@popomore)
- [d37b57b](https://github.com/gulpjs/vinyl/commit/d37b57bba0aa1fba18d9fecec3513ac4e61b27cd) coverage 100% :sparkles: (@popomore)
- [b5a62f0](https://github.com/gulpjs/vinyl/commit/b5a62f0ede71bdeae957e8653e6ccbdca998879c) fix testcase and delete duplicate testcase (@popomore)
- [fb1b15d](https://github.com/gulpjs/vinyl/commit/fb1b15da472647743eb4e829b99f64d6d9f751fa) Adding more test (@nfroidure)
- [acea889](https://github.com/gulpjs/vinyl/commit/acea8894e9d983d8037641b4ff6f08b666056979) Fixing the clone method (@nfroidure)
- [#32](https://github.com/gulpjs/vinyl/pull/32) improve clone (@popomore)
- [037e830](https://github.com/gulpjs/vinyl/commit/037e8300b75fdddf9c3e003fd205da7ec13b9157) object should multiline (@popomore)
- [7724121](https://github.com/gulpjs/vinyl/commit/7724121194a4ac94fb23a0048ff926d00a784ecc) pass jshint (@popomore)
- [f76a921](https://github.com/gulpjs/vinyl/commit/f76a9211b8b495d81074884d8ea6454a20bba349) use node-v8-clone for performance, fallback to lodash #29 (@popomore)
- [7638f07](https://github.com/gulpjs/vinyl/commit/7638f072bf33a427ec8324a0fb463f73cb9fc8f2) option to not clone buffer #16 (@popomore)
- [6bfd73c](https://github.com/gulpjs/vinyl/commit/6bfd73cc459907a06ce9affc373599ffb8130c08) copy all attributes deeply #29 (@popomore)
- [b34f813](https://github.com/gulpjs/vinyl/commit/b34f8135d47e0a2ba3be6f769729ba66931b3234) add testcase for clone history (@popomore)
- [a913edf](https://github.com/gulpjs/vinyl/commit/a913edf1dd91c5bdcfc9ff3149a94eae131006aa) fix mixed quote and unused variable (@popomore)
### v0.3.3 (2014/08/28 13:50 +00:00)
- [c801d3d](https://github.com/gulpjs/vinyl/commit/c801d3dc354383cf2656338d63908ec2983e3612) 0.3.3 (@contra)
- [f13970e](https://github.com/gulpjs/vinyl/commit/f13970e3cc5d1d730f94316daeee5b5c0e6c00f3) fix jshint on tests (@contra)
- [6186101](https://github.com/gulpjs/vinyl/commit/61861017bc22a786a026730cf5c55d23c657abea) closes #31 (@contra)
- [#24](https://github.com/gulpjs/vinyl/pull/24) path get/set for recording path change (@popomore)
- [6eab1c4](https://github.com/gulpjs/vinyl/commit/6eab1c4f1376aec901d8869d3d410953f1c93e9f) done (@contra)
### v0.3.2 (2014/07/30 23:22 +00:00)
- [44ef836](https://github.com/gulpjs/vinyl/commit/44ef8369e1a0a7ba01da4608d01166c5a5d8cbe1) 0.3.2 (@contra)
- [ae28ff2](https://github.com/gulpjs/vinyl/commit/ae28ff200c034e9a40babb38886cdc7ef97a0f25) oops, thats what i get for coding from a car (@contra)
### v0.3.1 (2014/07/30 22:35 +00:00)
- [03b7578](https://github.com/gulpjs/vinyl/commit/03b75789e58b43bdaef9ca166e4062b8ccfdefb9) 0.3.1 (@contra)
- [64850ff](https://github.com/gulpjs/vinyl/commit/64850ffdf4d31b35ac1160d0d495644cadd52914) fix deep deps, closes #28 (@contra)
### v0.3.0 (2014/07/19 04:57 +00:00)
- [dcb77f3](https://github.com/gulpjs/vinyl/commit/dcb77f3246d1011a430c20f883eb89c520206ca6) 0.3.0 (@contra)
- [#27](https://github.com/gulpjs/vinyl/pull/27) Clone custom properties (@vweevers)
- [95710de](https://github.com/gulpjs/vinyl/commit/95710de62f4c1234a244a6818b5e39d92ea7b9a8) fix relative path test for windows (@vweevers)
- [e493187](https://github.com/gulpjs/vinyl/commit/e493187b3f2fd1485077f09e73e669407ac077d3) clone custom properties (@laurelnaiad)
- [e50ceac](https://github.com/gulpjs/vinyl/commit/e50ceacfc3daa825e111976ba4192cb93c80bfe2) throw when set path is null (@popomore)
- [7c71bf3](https://github.com/gulpjs/vinyl/commit/7c71bf3d806a98730a0ce5edd56c0b8f1f42e8f0) remove initialize of this.path (@popomore)
- [d95023f](https://github.com/gulpjs/vinyl/commit/d95023f6604a990d38e4f5b332c7916ceb012366) delete this._path :tongue: (@popomore)
- [f3f9be0](https://github.com/gulpjs/vinyl/commit/f3f9be0f3d76b4125353cd936731f70015d44284) path get/set for recording path change #19 (@popomore)
- [#21](https://github.com/gulpjs/vinyl/pull/21) LICENSE: Remove executable mode (@felixrabe)
- [#22](https://github.com/gulpjs/vinyl/pull/22) Travis: Dump node 0.9 - travis-ci/travis-ci#2251 (@felixrabe)
- [70a2193](https://github.com/gulpjs/vinyl/commit/70a219346c00e0db6be1a0aa55c183e7d5b80ad1) Travis: Dump node 0.9 - travis-ci/travis-ci#2251 (@felixrabe)
- [460eed5](https://github.com/gulpjs/vinyl/commit/460eed58de9cb04d44e35b6bebbfbaea9146015f) LICENSE: Remove executable mode (@felixrabe)
- [#18](https://github.com/gulpjs/vinyl/pull/18) fix typo (@vvakame)
- [1783e7f](https://github.com/gulpjs/vinyl/commit/1783e7f031ecfb118ee9b43971a72be264caa144) fix typo (@vvakame)
- [#11](https://github.com/gulpjs/vinyl/pull/11) Correct README about pipe's end option. (@shuhei)
- [1824ec9](https://github.com/gulpjs/vinyl/commit/1824ec9cefd276557b7338dfdbd54922599f020a) Correct README about pipe's end option. (@shuhei)
- [f49b9c3](https://github.com/gulpjs/vinyl/commit/f49b9c325229754229726ed530c579e4ac23252b) remove dead line (@contra)
- [1ca8e46](https://github.com/gulpjs/vinyl/commit/1ca8e463259c2a395d5d41b528b04a89a953f6b7) dep update, new coveralls stuff (@contra)
- [f00767b](https://github.com/gulpjs/vinyl/commit/f00767bf8b61ca8a7b25f3ebd3dde297fa2dafd7) bump (@contra)
- [#8](https://github.com/gulpjs/vinyl/pull/8) Correct File.clone() treatment of File.stats (@hughsk)
- [bc3acf7](https://github.com/gulpjs/vinyl/commit/bc3acf7b1ed712d70e7d8cb4f6e5248124743ec7) Add test for new File.clone() functionality (@hughsk)
- [dd668fb](https://github.com/gulpjs/vinyl/commit/dd668fb5aaed02cfb0f63a58f027c937dd7e0467) Use clone-stats module to clone fs.Stats instances. (@hughsk)
- [b6244c5](https://github.com/gulpjs/vinyl/commit/b6244c52d3bf9bd87bd6b926f0486f407627f7e0) Correct File.clone() treatment of File.stats (@hughsk)
- [796ba8b](https://github.com/gulpjs/vinyl/commit/796ba8b5ddd658fed3393c7d0a0d7bea7befa1b1) 0.2.1 - fixes #2 (@contra)
- [bffa6a4](https://github.com/gulpjs/vinyl/commit/bffa6a4e323e18e084b5b1444b4537aa3fb3e109) vinyl-fs movement? (@contra)
- [cfaa0a0](https://github.com/gulpjs/vinyl/commit/cfaa0a02b7794e493f600d1d36b288294a278e6c) fix isDirectory tests (@contra)
- [05d1f1b](https://github.com/gulpjs/vinyl/commit/05d1f1b741960cce8e8d2702d326ebb0187935ad) add isDirectory (@contra)
- [76580e5](https://github.com/gulpjs/vinyl/commit/76580e573870885580ac00dd9175e562d008cb81) bump to 0.1.0 (@contra)
- [f7a15c4](https://github.com/gulpjs/vinyl/commit/f7a15c41ac5e82de930e161f6b109ae3336d337b) readme 0.9+ (@contra)
- [fc7f192](https://github.com/gulpjs/vinyl/commit/fc7f1925b2a18466f19db062ad28df02f1db823b) drop 0.8 support (@contra)
- [c004b6c](https://github.com/gulpjs/vinyl/commit/c004b6c857d03a292e8ecd5020ad0420d82dbf1e) target 0.8+ (@contra)
- [edf20bd](https://github.com/gulpjs/vinyl/commit/edf20bd8563fca6e8a568b9d08fb728f6705573c) add small example (@contra)
- [d8c63fe](https://github.com/gulpjs/vinyl/commit/d8c63fe0fd16cf13db2d9a6452c979ec12779428) 0.0.1 (@contra)

View File

@ -0,0 +1,20 @@
Copyright (c) 2013 Fractal <contact@wearefractal.com>
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.

View File

@ -0,0 +1,265 @@
# vinyl [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Coveralls Status][coveralls-image]][coveralls-url] [![Dependency Status][depstat-image]][depstat-url]
## Information
<table><tr><td>Package</td><td>vinyl</td></tr><tr><td>Description</td><td>A virtual file format</td></tr><tr><td>Node Version</td><td>>= 0.9</td></tr></table>
## What is this?
Read this for more info about how this plays into the grand scheme of things [https://medium.com/@eschoff/3828e8126466](https://medium.com/@eschoff/3828e8126466)
## File
```javascript
var File = require('vinyl');
var coffeeFile = new File({
cwd: "/",
base: "/test/",
path: "/test/file.coffee",
contents: new Buffer("test = 123")
});
```
### isVinyl
When checking if an object is a vinyl file, you should not use instanceof. Use the isVinyl function instead.
```js
var File = require('vinyl');
var dummy = new File({stuff});
var notAFile = {};
File.isVinyl(dummy); // true
File.isVinyl(notAFile); // false
```
### isCustomProp
Vinyl checks if a property is not managed internally, such as `sourceMap`. This is than used in `constructor(options)` when setting, and `clone()` when copying properties.
```js
var File = require('vinyl');
File.isCustomProp('sourceMap'); // true
File.isCustomProp('path'); // false -> internal getter/setter
```
Read more in [Extending Vinyl](#extending-vinyl).
### constructor(options)
#### options.cwd
Type: `String`<br><br>Default: `process.cwd()`
#### options.base
Used for relative pathing. Typically where a glob starts.
Type: `String`<br><br>Default: `options.cwd`
#### options.path
Full path to the file.
Type: `String`<br><br>Default: `undefined`
#### options.history
Path history. Has no effect if `options.path` is passed.
Type: `Array`<br><br>Default: `options.path ? [options.path] : []`
#### options.stat
The result of an fs.stat call. See [fs.Stats](http://nodejs.org/api/fs.html#fs_class_fs_stats) for more information.
Type: `fs.Stats`<br><br>Default: `null`
#### options.contents
File contents.
Type: `Buffer, Stream, or null`<br><br>Default: `null`
#### options.{custom}
Any other option properties will just be assigned to the new File object.
```js
var File = require('vinyl');
var file = new File({foo: 'bar'});
file.foo === 'bar'; // true
```
### isBuffer()
Returns true if file.contents is a Buffer.
### isStream()
Returns true if file.contents is a Stream.
### isNull()
Returns true if file.contents is null.
### clone([opt])
Returns a new File object with all attributes cloned.<br>By default custom attributes are deep-cloned.
If opt or opt.deep is false, custom attributes will not be deep-cloned.
If opt.contents is false, it will copy file.contents Buffer's reference.
### pipe(stream[, opt])
If file.contents is a Buffer, it will write it to the stream.
If file.contents is a Stream, it will pipe it to the stream.
If file.contents is null, it will do nothing.
If opt.end is false, the destination stream will not be ended (same as node core).
Returns the stream.
### inspect()
Returns a pretty String interpretation of the File. Useful for console.log.
### contents
The [Stream](https://nodejs.org/api/stream.html#stream_stream) or [Buffer](https://nodejs.org/api/buffer.html#buffer_class_buffer) of the file as it was passed in via options, or as the result of modification.
For example:
```js
if (file.isBuffer()) {
console.log(file.contents.toString()); // logs out the string of contents
}
```
### path
Absolute pathname string or `undefined`. Setting to a different value pushes the old value to `history`.
### history
Array of `path` values the file object has had, from `history[0]` (original) through `history[history.length - 1]` (current). `history` and its elements should normally be treated as read-only and only altered indirectly by setting `path`.
### relative
Returns path.relative for the file base and file path.
Example:
```javascript
var file = new File({
cwd: "/",
base: "/test/",
path: "/test/file.coffee"
});
console.log(file.relative); // file.coffee
```
### dirname
Gets and sets path.dirname for the file path.
Example:
```javascript
var file = new File({
cwd: "/",
base: "/test/",
path: "/test/file.coffee"
});
console.log(file.dirname); // /test
file.dirname = '/specs';
console.log(file.dirname); // /specs
console.log(file.path); // /specs/file.coffee
```
### basename
Gets and sets path.basename for the file path.
Example:
```javascript
var file = new File({
cwd: "/",
base: "/test/",
path: "/test/file.coffee"
});
console.log(file.basename); // file.coffee
file.basename = 'file.js';
console.log(file.basename); // file.js
console.log(file.path); // /test/file.js
```
### stem
Gets and sets stem (filename without suffix) for the file path.
Example:
```javascript
var file = new File({
cwd: "/",
base: "/test/",
path: "/test/file.coffee"
});
console.log(file.stem); // file
file.stem = 'foo';
console.log(file.stem); // foo
console.log(file.path); // /test/foo.coffee
```
### extname
Gets and sets path.extname for the file path.
Example:
```javascript
var file = new File({
cwd: "/",
base: "/test/",
path: "/test/file.coffee"
});
console.log(file.extname); // .coffee
file.extname = '.js';
console.log(file.extname); // .js
console.log(file.path); // /test/file.js
```
## Extending Vinyl
When extending Vinyl into your own class with extra features, you need to think about a few things.
When you have your own properties that are managed internally, you need to extend the static `isCustomProp` method to return `false` when one of these properties is queried.
```js
const File = require('vinyl');
const builtInProps = ['foo', '_foo'];
class SuperFile extends File {
constructor(options) {
super(options);
this._foo = 'example internal read-only value';
}
get foo() {
return this._foo;
}
static isCustomProp(name) {
return super.isCustomProp(name) && builtInProps.indexOf(name) === -1;
}
}
```
This makes properties `foo` and `_foo` ignored when cloning, and when passed in options to `constructor(options)` so they don't get assigned to the new object.
Same goes for `clone()`. If you have your own internal stuff that needs special handling during cloning, you should extend it to do so.
[npm-url]: https://npmjs.org/package/vinyl
[npm-image]: https://badge.fury.io/js/vinyl.svg
[travis-url]: https://travis-ci.org/gulpjs/vinyl
[travis-image]: https://travis-ci.org/gulpjs/vinyl.svg?branch=master
[coveralls-url]: https://coveralls.io/github/gulpjs/vinyl
[coveralls-image]: https://coveralls.io/repos/github/gulpjs/vinyl/badge.svg
[depstat-url]: https://david-dm.org/gulpjs/vinyl
[depstat-image]: https://david-dm.org/gulpjs/vinyl.svg

View File

@ -0,0 +1,270 @@
var path = require('path');
var clone = require('clone');
var cloneStats = require('clone-stats');
var cloneBuffer = require('./lib/cloneBuffer');
var isBuffer = require('./lib/isBuffer');
var isStream = require('./lib/isStream');
var isNull = require('./lib/isNull');
var inspectStream = require('./lib/inspectStream');
var Stream = require('stream');
var replaceExt = require('replace-ext');
var builtInFields = [
'_contents', 'contents', 'stat', 'history', 'path', 'base', 'cwd',
];
function File(file) {
var self = this;
if (!file) {
file = {};
}
// Record path change
var history = file.path ? [file.path] : file.history;
this.history = history || [];
this.cwd = file.cwd || process.cwd();
this.base = file.base || this.cwd;
// Stat = files stats object
this.stat = file.stat || null;
// Contents = stream, buffer, or null if not read
this.contents = file.contents || null;
this._isVinyl = true;
// Set custom properties
Object.keys(file).forEach(function(key) {
if (self.constructor.isCustomProp(key)) {
self[key] = file[key];
}
});
}
File.prototype.isBuffer = function() {
return isBuffer(this.contents);
};
File.prototype.isStream = function() {
return isStream(this.contents);
};
File.prototype.isNull = function() {
return isNull(this.contents);
};
// TODO: Should this be moved to vinyl-fs?
File.prototype.isDirectory = function() {
return this.isNull() && this.stat && this.stat.isDirectory();
};
File.prototype.clone = function(opt) {
var self = this;
if (typeof opt === 'boolean') {
opt = {
deep: opt,
contents: true,
};
} else if (!opt) {
opt = {
deep: true,
contents: true,
};
} else {
opt.deep = opt.deep === true;
opt.contents = opt.contents !== false;
}
// Clone our file contents
var contents;
if (this.isStream()) {
contents = this.contents.pipe(new Stream.PassThrough());
this.contents = this.contents.pipe(new Stream.PassThrough());
} else if (this.isBuffer()) {
contents = opt.contents ? cloneBuffer(this.contents) : this.contents;
}
var file = new this.constructor({
cwd: this.cwd,
base: this.base,
stat: (this.stat ? cloneStats(this.stat) : null),
history: this.history.slice(),
contents: contents,
});
// Clone our custom properties
Object.keys(this).forEach(function(key) {
if (self.constructor.isCustomProp(key)) {
file[key] = opt.deep ? clone(self[key], true) : self[key];
}
});
return file;
};
File.prototype.pipe = function(stream, opt) {
if (!opt) {
opt = {};
}
if (typeof opt.end === 'undefined') {
opt.end = true;
}
if (this.isStream()) {
return this.contents.pipe(stream, opt);
}
if (this.isBuffer()) {
if (opt.end) {
stream.end(this.contents);
} else {
stream.write(this.contents);
}
return stream;
}
// Check if isNull
if (opt.end) {
stream.end();
}
return stream;
};
File.prototype.inspect = function() {
var inspect = [];
// Use relative path if possible
var filePath = (this.base && this.path) ? this.relative : this.path;
if (filePath) {
inspect.push('"' + filePath + '"');
}
if (this.isBuffer()) {
inspect.push(this.contents.inspect());
}
if (this.isStream()) {
inspect.push(inspectStream(this.contents));
}
return '<File ' + inspect.join(' ') + '>';
};
File.isCustomProp = function(key) {
return builtInFields.indexOf(key) === -1;
};
File.isVinyl = function(file) {
return (file && file._isVinyl === true) || false;
};
// Virtual attributes
// Or stuff with extra logic
Object.defineProperty(File.prototype, 'contents', {
get: function() {
return this._contents;
},
set: function(val) {
if (!isBuffer(val) && !isStream(val) && !isNull(val)) {
throw new Error('File.contents can only be a Buffer, a Stream, or null.');
}
this._contents = val;
},
});
// TODO: Should this be moved to vinyl-fs?
Object.defineProperty(File.prototype, 'relative', {
get: function() {
if (!this.base) {
throw new Error('No base specified! Can not get relative.');
}
if (!this.path) {
throw new Error('No path specified! Can not get relative.');
}
return path.relative(this.base, this.path);
},
set: function() {
throw new Error('File.relative is generated from the base and path attributes. Do not modify it.');
},
});
Object.defineProperty(File.prototype, 'dirname', {
get: function() {
if (!this.path) {
throw new Error('No path specified! Can not get dirname.');
}
return path.dirname(this.path);
},
set: function(dirname) {
if (!this.path) {
throw new Error('No path specified! Can not set dirname.');
}
this.path = path.join(dirname, path.basename(this.path));
},
});
Object.defineProperty(File.prototype, 'basename', {
get: function() {
if (!this.path) {
throw new Error('No path specified! Can not get basename.');
}
return path.basename(this.path);
},
set: function(basename) {
if (!this.path) {
throw new Error('No path specified! Can not set basename.');
}
this.path = path.join(path.dirname(this.path), basename);
},
});
// Property for getting/setting stem of the filename.
Object.defineProperty(File.prototype, 'stem', {
get: function() {
if (!this.path) {
throw new Error('No path specified! Can not get stem.');
}
return path.basename(this.path, this.extname);
},
set: function(stem) {
if (!this.path) {
throw new Error('No path specified! Can not set stem.');
}
this.path = path.join(path.dirname(this.path), stem + this.extname);
},
});
Object.defineProperty(File.prototype, 'extname', {
get: function() {
if (!this.path) {
throw new Error('No path specified! Can not get extname.');
}
return path.extname(this.path);
},
set: function(extname) {
if (!this.path) {
throw new Error('No path specified! Can not set extname.');
}
this.path = replaceExt(this.path, extname);
},
});
Object.defineProperty(File.prototype, 'path', {
get: function() {
return this.history[this.history.length - 1];
},
set: function(path) {
if (typeof path !== 'string') {
throw new Error('path should be string');
}
// Record history only when path changed
if (path && path !== this.path) {
this.history.push(path);
}
},
});
module.exports = File;

View File

@ -0,0 +1,7 @@
var Buffer = require('buffer').Buffer;
module.exports = function(buf) {
var out = new Buffer(buf.length);
buf.copy(out);
return out;
};

View File

@ -0,0 +1,15 @@
var isStream = require('./isStream');
module.exports = function(stream) {
if (!isStream(stream)) {
return;
}
var streamType = stream.constructor.name;
// Avoid StreamStream
if (streamType === 'Stream') {
streamType = '';
}
return '<' + streamType + 'Stream>';
};

View File

@ -0,0 +1 @@
module.exports = require('buffer').Buffer.isBuffer;

View File

@ -0,0 +1,3 @@
module.exports = function(v) {
return v === null;
};

View File

@ -0,0 +1,5 @@
var Stream = require('stream').Stream;
module.exports = function(o) {
return !!o && o instanceof Stream;
};

View File

@ -0,0 +1,79 @@
{
"_from": "vinyl@1.X",
"_id": "vinyl@1.2.0",
"_inBundle": false,
"_integrity": "sha1-XIgDbPVl5d8FVYv8kR+GVt8hiIQ=",
"_location": "/gulp-sourcemaps/vinyl",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "vinyl@1.X",
"name": "vinyl",
"escapedName": "vinyl",
"rawSpec": "1.X",
"saveSpec": null,
"fetchSpec": "1.X"
},
"_requiredBy": [
"/gulp-sourcemaps"
],
"_resolved": "https://registry.npmjs.org/vinyl/-/vinyl-1.2.0.tgz",
"_shasum": "5c88036cf565e5df05558bfc911f8656df218884",
"_spec": "vinyl@1.X",
"_where": "/home/manfred/enviPath/ketcher2/ketcher/node_modules/gulp-sourcemaps",
"author": {
"name": "Fractal",
"email": "contact@wearefractal.com",
"url": "http://wearefractal.com/"
},
"bugs": {
"url": "https://github.com/gulpjs/vinyl/issues"
},
"bundleDependencies": false,
"dependencies": {
"clone": "^1.0.0",
"clone-stats": "^0.0.1",
"replace-ext": "0.0.1"
},
"deprecated": false,
"description": "A virtual file format",
"devDependencies": {
"buffer-equal": "0.0.1",
"eslint": "^1.7.3",
"eslint-config-gulp": "^2.0.0",
"event-stream": "^3.1.0",
"github-changes": "^1.0.1",
"istanbul": "^0.3.0",
"istanbul-coveralls": "^1.0.1",
"jscs": "^2.3.5",
"jscs-preset-gulp": "^1.0.0",
"lodash.templatesettings": "^3.1.0",
"mocha": "^2.0.0",
"rimraf": "^2.2.5",
"should": "^7.0.0"
},
"engines": {
"node": ">= 0.9"
},
"files": [
"index.js",
"lib"
],
"homepage": "http://github.com/gulpjs/vinyl",
"license": "MIT",
"main": "./index.js",
"name": "vinyl",
"repository": {
"type": "git",
"url": "git://github.com/gulpjs/vinyl.git"
},
"scripts": {
"changelog": "github-changes -o gulpjs -r vinyl -b master -f ./CHANGELOG.md --order-semver --use-commit-body",
"coveralls": "istanbul cover _mocha && istanbul-coveralls",
"lint": "eslint . && jscs *.js lib/ test/",
"pretest": "npm run lint",
"test": "mocha"
},
"version": "1.2.0"
}

View File

@ -0,0 +1,103 @@
{
"_from": "gulp-sourcemaps@2.6.0",
"_id": "gulp-sourcemaps@2.6.0",
"_inBundle": false,
"_integrity": "sha1-fMzomaijv8oVk6M0jQ+/Qd0/UeU=",
"_location": "/gulp-sourcemaps",
"_phantomChildren": {
"clone": "1.0.2",
"clone-stats": "0.0.1",
"replace-ext": "0.0.1"
},
"_requested": {
"type": "version",
"registry": true,
"raw": "gulp-sourcemaps@2.6.0",
"name": "gulp-sourcemaps",
"escapedName": "gulp-sourcemaps",
"rawSpec": "2.6.0",
"saveSpec": null,
"fetchSpec": "2.6.0"
},
"_requiredBy": [
"#DEV:/"
],
"_resolved": "https://registry.npmjs.org/gulp-sourcemaps/-/gulp-sourcemaps-2.6.0.tgz",
"_shasum": "7ccce899a8a3bfca1593a3348d0fbf41dd3f51e5",
"_spec": "gulp-sourcemaps@2.6.0",
"_where": "/home/manfred/enviPath/ketcher2/ketcher",
"author": {
"name": "Florian Reiterer",
"email": "me@florianreiterer.com"
},
"bugs": {
"url": "https://github.com/gulp-sourcemaps/gulp-sourcemaps/issues"
},
"bundleDependencies": false,
"dependencies": {
"@gulp-sourcemaps/identity-map": "1.X",
"@gulp-sourcemaps/map-sources": "1.X",
"acorn": "4.X",
"convert-source-map": "1.X",
"css": "2.X",
"debug-fabulous": "0.1.X",
"detect-newline": "2.X",
"graceful-fs": "4.X",
"source-map": "0.X",
"strip-bom-string": "1.X",
"through2": "2.X",
"vinyl": "1.X"
},
"deprecated": false,
"description": "Source map support for Gulp.js",
"devDependencies": {
"bootstrap": "3.3.7",
"coveralls": "2.X",
"faucet": "0.0.X",
"gulp": "3.X",
"gulp-concat": "2.X",
"gulp-if": "2.0.2",
"gulp-less": "3.3.0",
"gulp-load-plugins": "1.X",
"hook-std": "0.2.X",
"http-server": "0.9.0",
"istanbul": "0.X",
"jshint": "2.X",
"lodash": "4.17.4",
"mississippi": "^1.3.0",
"object-assign": "^4.1.0",
"tape": "4.X",
"yargs": "6.6.0"
},
"engines": {
"node": ">=4"
},
"files": [
"index.js",
"src"
],
"homepage": "http://github.com/gulp-sourcemaps/gulp-sourcemaps",
"keywords": [
"gulpplugin",
"gulp",
"source maps",
"sourcemaps"
],
"license": "ISC",
"main": "index.js",
"name": "gulp-sourcemaps",
"repository": {
"type": "git",
"url": "git://github.com/gulp-sourcemaps/gulp-sourcemaps.git"
},
"scripts": {
"cover": "istanbul cover --dir reports/coverage tape \"test/*.js\"",
"coveralls": "istanbul cover tape \"test/*.js\" --report lcovonly && cat ./coverage/lcov.info | coveralls && rm -rf ./coverage",
"lint": "jshint ./src/**/*.js test/*.js",
"serve": "http-server",
"tap": "tape test/*.js",
"test": "npm run lint && faucet test/*.js $@",
"test:int": "rm -rf ./tmp && tape ./test/integration.js"
},
"version": "2.6.0"
}

View File

@ -0,0 +1 @@
module.exports = require('debug-fabulous').spawnable(require('../package.json').name);

View File

@ -0,0 +1,121 @@
'use strict';
var utils = require('../utils');
var rootDebug = require('../debug');
var convert = require('convert-source-map');
var stripBom = require('strip-bom-string');
var urlRegex = utils.urlRegex;
var fs = require('graceful-fs');
var path = require('path');
var unixStylePath = utils.unixStylePath;
module.exports = function(options, file, fileContent) {
function loadMaps() {
var sources = {
path: '',
map: null,
content: fileContent,
preExistingComment: null
};
_getInlineSources(sources);
if (!sources.map) // ahh not inline, so try file
_getFileSources(sources);
_fixSources(sources);
return sources;
}
function _fixSources(sources) {
var debug = rootDebug.spawn('init:internals:loadMaps:_fixSources');
// fix source paths and sourceContent for imported source map
if (sources.map) {
sources.map.sourcesContent = sources.map.sourcesContent || [];
sources.map.sources.forEach(function(source, i) {
if (source.match(urlRegex)) {
sources.map.sourcesContent[i] = sources.map.sourcesContent[i] || null;
return;
}
var absPath = path.resolve(sources.path, source);
sources.map.sources[i] = unixStylePath(path.relative(file.base, absPath));
if (!sources.map.sourcesContent[i]) {
var sourceContent = null;
if (sources.map.sourceRoot) {
if (sources.map.sourceRoot.match(urlRegex)) {
sources.map.sourcesContent[i] = null;
return;
}
absPath = path.resolve(sources.path, sources.map.sourceRoot, source);
}
// if current file: use content
if (absPath === file.path) {
sourceContent = sources.content;
} else { //attempt load content from file
try {
debug(function() { return 'No source content for "' + source + '". Loading from file.'; });
sourceContent = stripBom(fs.readFileSync(absPath, 'utf8'));
} catch (e) {
debug(function() { return 'warn: source file not found: ' + absPath; });
}
}
sources.map.sourcesContent[i] = sourceContent;
}
});
// remove source map comment from source
file.contents = new Buffer(sources.content, 'utf8');
}
}
function _getInlineSources(sources) {
var debug = rootDebug.spawn('init:internals:loadMaps:_getInlineSources');
sources.preExistingComment = utils.getInlinePreExisting(sources.content);
// Try to read inline source map
sources.map = convert.fromSource(sources.content, options.largeFile);
if (!sources.map)
return sources;
sources.map = sources.map.toObject();
// sources in map are relative to the source file
sources.path = path.dirname(file.path);
if (!options.largeFile) {
debug('comment REMOVED');
sources.content = convert.removeComments(sources.content);
}
}
function _getFileSources(sources) {
// look for source map comment referencing a source map file
var mapComment = convert.mapFileCommentRegex.exec(sources.content);
var mapFile;
if (mapComment) {
sources.preExistingComment = mapComment[1] || mapComment[2];
mapFile = path.resolve(path.dirname(file.path), sources.preExistingComment);
sources.content = convert.removeMapFileComments(sources.content);
// if no comment try map file with same name as source file
} else {
mapFile = file.path + '.map';
}
// sources in external map are relative to map file
sources.path = path.dirname(mapFile);
try {
sources.map = JSON.parse(stripBom(fs.readFileSync(mapFile, 'utf8')));
} catch (e) {} //should we really swallow this error?
}
return {
loadMaps: loadMaps
};
};

View File

@ -0,0 +1,141 @@
'use strict';
var utils = require('../utils');
var unixStylePath = utils.unixStylePath;
var through = require('through2');
var path = require('path');
var acorn = require('acorn');
var SourceMapGenerator = require('source-map').SourceMapGenerator;
var css = require('css');
var initInternals = require('./index.internals');
/**
* Initialize source mapping chain
*/
function init(options) {
var debug = require('../debug').spawn('init');
function sourceMapInit(file, encoding, callback) {
/*jshint validthis:true */
// pass through if file is null or already has a source map
if (file.isNull() || file.sourceMap) {
this.push(file);
return callback();
}
if (file.isStream()) {
return callback(new Error(utils.PLUGIN_NAME + '-init: Streaming not supported'));
}
if (options === undefined) {
options = {};
}
debug(function() {
return options;
});
var fileContent = file.contents.toString();
var sourceMap, preExistingComment;
var internals = initInternals(options, file, fileContent);
if (options.loadMaps) {
var result = internals.loadMaps();
sourceMap = result.map;
fileContent = result.content;
preExistingComment = result.preExistingComment;
}
if (!sourceMap && options.identityMap) {
debug(function() { return '**identityMap option is deprecated, update to use sourcemap.identityMap stream**'; });
debug(function() {
return 'identityMap';
});
var fileType = path.extname(file.path);
var source = unixStylePath(file.relative);
var generator = new SourceMapGenerator({file: source});
if (fileType === '.js') {
var tokenizer = acorn.tokenizer(fileContent, {locations: true});
while (true) {
var token = tokenizer.getToken();
if (token.type.label === "eof")
break;
var mapping = {
original: token.loc.start,
generated: token.loc.start,
source: source
};
if (token.type.label === 'name') {
mapping.name = token.value;
}
generator.addMapping(mapping);
}
generator.setSourceContent(source, fileContent);
sourceMap = generator.toJSON();
} else if (fileType === '.css') {
debug('css');
var ast = css.parse(fileContent, {silent: true});
debug(function() {
return ast;
});
var registerTokens = function(ast) {
if (ast.position) {
generator.addMapping({original: ast.position.start, generated: ast.position.start, source: source});
}
function logAst(key, ast) {
debug(function() {
return 'key: ' + key;
});
debug(function() {
return ast[key];
});
}
for (var key in ast) {
logAst(key, ast);
if (key !== "position") {
if (Object.prototype.toString.call(ast[key]) === '[object Object]') {
registerTokens(ast[key]);
} else if (Array.isArray(ast[key])) {
debug(function() {
return "@@@@ ast[key] isArray @@@@";
});
for (var i = 0; i < ast[key].length; i++) {
registerTokens(ast[key][i]);
}
}
}
}
};
registerTokens(ast);
generator.setSourceContent(source, fileContent);
sourceMap = generator.toJSON();
}
}
if (!sourceMap) {
// Make an empty source map
sourceMap = {
version: 3,
names: [],
mappings: '',
sources: [unixStylePath(file.relative)],
sourcesContent: [fileContent]
};
}
else if(preExistingComment !== null && typeof preExistingComment !== 'undefined')
sourceMap.preExistingComment = preExistingComment;
sourceMap.file = unixStylePath(file.relative);
file.sourceMap = sourceMap;
this.push(file);
callback();
}
return through.obj(sourceMapInit);
}
module.exports = init;

View File

@ -0,0 +1,74 @@
'use strict';
var path = require('path'),
detectNewline = require('detect-newline');
function unixStylePath(filePath) {
return filePath.split(path.sep).join('/');
}
var PLUGIN_NAME = require('../package.json').name;
var urlRegex = /^(https?|webpack(-[^:]+)?):\/\//;
var debug = require('./debug').spawn('utils');
/*
So reusing the same ref for a regex (with global (g)) is from a poor decision in js.
See http://stackoverflow.com/questions/10229144/bug-with-regexp-in-javascript-when-do-global-search
So we either need to use a new instance of a regex everywhere.
*/
var sourceMapUrlRegEx = function(){ return /\/\/\# sourceMappingURL\=.*/g;};
var getCommentFormatter = function (file) {
var extension = file.relative.split('.').pop(),
fileContents = file.contents.toString(),
newline = detectNewline.graceful(fileContents || ''),
commentFormatter = function(url) {
return '';
};
if (file.sourceMap.preExistingComment){
debug(function() { return 'preExistingComment commentFormatter'; });
commentFormatter = function(url) {
return "//# sourceMappingURL=" + url + newline;
};
return commentFormatter;
}
switch (extension) {
case 'css':
debug(function() { return 'css commentFormatter';});
commentFormatter = function(url) {
return newline + "/*# sourceMappingURL=" + url + " */" + newline;
};
break;
case 'js':
debug(function() { return 'js commentFormatter'; });
commentFormatter = function(url) {
return newline + "//# sourceMappingURL=" + url + newline;
};
break;
default:
debug(function() { return 'unknown commentFormatter'; });
}
return commentFormatter;
};
var getInlinePreExisting = function(fileContent){
if(sourceMapUrlRegEx().test(fileContent)){
debug(function() { return 'has preExisting'; });
return fileContent.match(sourceMapUrlRegEx())[0];
}
};
module.exports = {
unixStylePath: unixStylePath,
PLUGIN_NAME: PLUGIN_NAME,
urlRegex: urlRegex,
sourceMapUrlRegEx: sourceMapUrlRegEx,
getCommentFormatter: getCommentFormatter,
getInlinePreExisting: getInlinePreExisting
};

View File

@ -0,0 +1,179 @@
'use strict';
module.exports = function(destPath, options) {
var utils = require('../utils');
var unixStylePath = utils.unixStylePath;
var fs = require('graceful-fs');
var path = require('path');
var stripBom = require('strip-bom-string');
var rootDebug = require('../debug').spawn('write:internals');
rootDebug(function() { return "options"; });
rootDebug(function() { return options; });
function setSourceRoot(file) {
var debug = rootDebug.spawn('setSourceRoot');
var sourceMap = file.sourceMap;
if (typeof options.sourceRoot === 'function') {
debug(function() { return 'is function'; });
sourceMap.sourceRoot = options.sourceRoot(file);
} else {
debug(function() { return 'from options'; });
sourceMap.sourceRoot = options.sourceRoot;
}
if (sourceMap.sourceRoot === null) {
debug(function() { return 'undefined'; });
sourceMap.sourceRoot = undefined;
}
}
function mapSources(file) {
var debug = rootDebug.spawn('mapSources');
//NOTE: make sure source mapping happens after content has been loaded
if (options.mapSources && typeof options.mapSources === 'function') {
debug(function() { return '**Option is deprecated, update to use sourcemap.mapSources stream**'; });
debug(function() { return 'function'; });
file.sourceMap.sources = file.sourceMap.sources.map(function (filePath) {
return options.mapSources(filePath, file);
});
return;
}
debug(function() { return "file.path: " + file.path; });
debug(function() { return "file.cwd: " + file.cwd; });
debug(function() { return "file.base: " + file.base; });
file.sourceMap.sources = file.sourceMap.sources.map(function(filePath) {
// keep the references files like ../node_modules within the sourceRoot
debug(function() { return "filePath: " + filePath; });
if (options.mapSourcesAbsolute === true){
debug(function() { return 'mapSourcesAbsolute'; });
if (!file.dirname){
debug(function() { return '!file.dirname'; });
filePath = path.join(file.base, filePath).replace(file.cwd, '');
} else {
debug(function() { return 'file.dirname: ' + file.dirname; });
filePath = path.resolve(file.dirname, filePath).replace(file.cwd, '');
}
}
return unixStylePath(filePath);
});
}
function loadContent(file) {
var debug = rootDebug.spawn('loadContent');
var sourceMap = file.sourceMap;
if (options.includeContent) {
sourceMap.sourcesContent = sourceMap.sourcesContent || [];
// load missing source content
for (var i = 0; i < sourceMap.sources.length; i++) {
if (!sourceMap.sourcesContent[i]) {
var sourcePath = path.resolve(file.base, sourceMap.sources[i]);
try {
debug('No source content for "' + sourceMap.sources[i] + '". Loading from file.');
sourceMap.sourcesContent[i] = stripBom(fs.readFileSync(sourcePath, 'utf8'));
}
catch (e) {
debug('source file not found: ' + sourcePath);
}
}
}
} else {
delete sourceMap.sourcesContent;
}
}
function mapDestPath(file, stream) {
var debug = rootDebug.spawn('mapDestPath');
var sourceMap = file.sourceMap;
var comment,
commentFormatter = utils.getCommentFormatter(file);
if (destPath === undefined || destPath === null) {
// encode source map into comment
var base64Map = new Buffer(JSON.stringify(sourceMap)).toString('base64');
comment = commentFormatter('data:application/json;charset=' + options.charset + ';base64,' + base64Map);
} else {
var mapFile = path.join(destPath, file.relative) + '.map';
// custom map file name
if (options.mapFile && typeof options.mapFile === 'function') {
mapFile = options.mapFile(mapFile);
}
var sourceMapPath = path.join(file.base, mapFile);
// if explicit destination path is set
if (options.destPath) {
var destSourceMapPath = path.join(file.cwd, options.destPath, mapFile);
var destFilePath = path.join(file.cwd, options.destPath, file.relative);
sourceMap.file = unixStylePath(path.relative(path.dirname(destSourceMapPath), destFilePath));
if (sourceMap.sourceRoot === undefined) {
sourceMap.sourceRoot = unixStylePath(path.relative(path.dirname(destSourceMapPath), file.base));
} else if (sourceMap.sourceRoot === '' || (sourceMap.sourceRoot && sourceMap.sourceRoot[0] === '.')) {
sourceMap.sourceRoot = unixStylePath(path.join(path.relative(path.dirname(destSourceMapPath), file.base), sourceMap.sourceRoot));
}
} else {
// best effort, can be incorrect if options.destPath not set
sourceMap.file = unixStylePath(path.relative(path.dirname(sourceMapPath), file.path));
if (sourceMap.sourceRoot === '' || (sourceMap.sourceRoot && sourceMap.sourceRoot[0] === '.')) {
sourceMap.sourceRoot = unixStylePath(path.join(path.relative(path.dirname(sourceMapPath), file.base), sourceMap.sourceRoot));
}
}
var sourceMapFile;
sourceMapFile = file.clone(options.clone || {deep:false, contents:false});
sourceMapFile.path = sourceMapPath;
sourceMapFile.contents = new Buffer(JSON.stringify(sourceMap));
sourceMapFile.stat = {
isFile: function () { return true; },
isDirectory: function () { return false; },
isBlockDevice: function () { return false; },
isCharacterDevice: function () { return false; },
isSymbolicLink: function () { return false; },
isFIFO: function () { return false; },
isSocket: function () { return false; }
};
stream.push(sourceMapFile);
var sourceMapPathRelative = path.relative(path.dirname(file.path), sourceMapPath);
if (options.sourceMappingURLPrefix) {
var prefix = '';
if (typeof options.sourceMappingURLPrefix === 'function') {
prefix = options.sourceMappingURLPrefix(file);
} else {
prefix = options.sourceMappingURLPrefix;
}
sourceMapPathRelative = prefix + path.join('/', sourceMapPathRelative);
}
debug(function() { return "destPath comment"; });
comment = commentFormatter(unixStylePath(sourceMapPathRelative));
if (options.sourceMappingURL && typeof options.sourceMappingURL === 'function') {
debug(function() { return "options.sourceMappingURL comment"; });
comment = commentFormatter(options.sourceMappingURL(file));
}
}
// append source map comment
if (options.addComment){
file.contents = Buffer.concat([file.contents, new Buffer(comment)]);
}
}
return {
setSourceRoot: setSourceRoot,
loadContent: loadContent,
mapSources: mapSources,
mapDestPath: mapDestPath
};
};

View File

@ -0,0 +1,70 @@
'use strict';
var utils = require('../utils');
var through = require('through2');
var unixStylePath = utils.unixStylePath;
var internalsInit = require('./index.internals');
/**
* Write the source map
*
* @param options options to change the way the source map is written
*
*/
function write(destPath, options) {
var debug = require('../debug').spawn('write');
debug(function() { return "destPath"; });
debug(function() { return destPath; });
debug(function() { return "original options";});
debug(function() { return options; });
if (options === undefined && typeof destPath !== 'string') {
options = destPath;
destPath = undefined;
}
options = options || {};
// set defaults for options if unset
if (options.includeContent === undefined)
options.includeContent = true;
if (options.addComment === undefined)
options.addComment = true;
if (options.charset === undefined)
options.charset = "utf8";
debug(function() { return "derrived options"; });
debug(function() { return options; });
var internals = internalsInit(destPath, options);
function sourceMapWrite(file, encoding, callback) {
/*jshint validthis:true */
if (file.isNull() || !file.sourceMap) {
this.push(file);
return callback();
}
if (file.isStream()) {
return callback(new Error(utils.PLUGIN_NAME + '-write: Streaming not supported'));
}
// fix paths if Windows style paths
file.sourceMap.file = unixStylePath(file.relative);
internals.setSourceRoot(file);
internals.loadContent(file);
internals.mapSources(file);
internals.mapDestPath(file, this);
this.push(file);
callback();
}
return through.obj(sourceMapWrite);
}
module.exports = write;