Code Monkey home page Code Monkey logo

vinyl-sourcemaps-apply's Introduction

gulp-sourcemaps

NPM version Downloads Travis Build Status AppVeyor Build Status Coveralls Status

Sourcemap support for gulpjs.

Usage

All the examples here works with Gulp 4. To see examples related to Gulp 3, you can read them here.

Write inline source maps

Inline source maps are embedded in the source file.

Example:

var gulp = require('gulp');
var plugin1 = require('gulp-plugin1');
var plugin2 = require('gulp-plugin2');
var sourcemaps = require('gulp-sourcemaps');

function javascript() {
  gulp.src('src/**/*.js')
    .pipe(sourcemaps.init())
      .pipe(plugin1())
      .pipe(plugin2())
    .pipe(sourcemaps.write())
    .pipe(gulp.dest('dist'));
};


exports.javascript = javascript;

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.

Write external source map files

To write external source map files, pass a path relative to the destination to sourcemaps.write().

Example:

var gulp = require('gulp');
var plugin1 = require('gulp-plugin1');
var plugin2 = require('gulp-plugin2');
var sourcemaps = require('gulp-sourcemaps');

function javascript() {
  gulp.src('src/**/*.js')
    .pipe(sourcemaps.init())
      .pipe(plugin1())
      .pipe(plugin2())
    .pipe(sourcemaps.write('../maps'))
    .pipe(gulp.dest('dist'));
};

exports.javascript = javascript;

Load existing source maps

To load existing source maps, pass the option loadMaps: true to sourcemaps.init().

Example:

var gulp = require('gulp');
var plugin1 = require('gulp-plugin1');
var plugin2 = require('gulp-plugin2');
var sourcemaps = require('gulp-sourcemaps');

function javascript() {
  gulp.src('src/**/*.js')
    .pipe(sourcemaps.init({loadMaps: true}))
      .pipe(plugin1())
      .pipe(plugin2())
    .pipe(sourcemaps.write())
    .pipe(gulp.dest('dist'));
};

exports.javascript = javascript;

Handle large files

To handle large files, pass the option largeFile: true to sourcemaps.init().

Example:

var gulp = require('gulp');
var plugin1 = require('gulp-plugin1');
var plugin2 = require('gulp-plugin2');
var sourcemaps = require('gulp-sourcemaps');

function javascript() {
  gulp.src('src/**/*.js')
    .pipe(sourcemaps.init({largeFile: true}))
      .pipe(plugin1())
      .pipe(plugin2())
    .pipe(sourcemaps.write())
    .pipe(gulp.dest('dist'));
};

exports.javascript = javascript;

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:

var gulp = require('gulp');
var plugin1 = require('gulp-plugin1');
var plugin2 = require('gulp-plugin2');
var sourcemaps = require('gulp-sourcemaps');

function javascript() {
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'));
};

exports.javascript = javascript;

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:

function javascript() {
  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'));
};

exports.javascript = javascript;

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:

function javascript() {
  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'));
};

exports.javascript = javascript;

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 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:

    function javascript() {
      var stream = gulp.src('src/**/*.js')
        .pipe(sourcemaps.init())
          .pipe(plugin1())
          .pipe(plugin2())
        .pipe(sourcemaps.write('../maps', {addComment: false}))
        .pipe(gulp.dest('dist'));
    };
    
    exports.javascript = javascript;
  • 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:

    function javascript() {
      var stream = gulp.src('src/**/*.js')
        .pipe(sourcemaps.init())
          .pipe(plugin1())
          .pipe(plugin2())
        .pipe(sourcemaps.write({includeContent: false, sourceRoot: '/src'}))
        .pipe(gulp.dest('dist'));
    };
    
    exports.javascript = javascript;

    Example (using a function):

    function javascript() {
      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'));
    };
    
    exports.javascript = javascript;

    Example (relative path):

    function javascript() {
      var stream = gulp.src('src/**/*.js')
        .pipe(sourcemaps.init())
          .pipe(plugin1())
          .pipe(plugin2())
        .pipe(sourcemaps.write('.', {includeContent: false, sourceRoot: '../src'}))
        .pipe(gulp.dest('dist'));
    };
    
    exports.javascript = javascript;

    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 sub path 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:

    function javascript() {
      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'));
    };
    
    exports.javascript = javascript;

    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:

    function javascript() {
      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'));
    };
    
    exports.javascript = javascript;

    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:

    function javascript() {
      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'));
    };
    
    exports.javascript = javascript;
  • mapSources

    This option is deprecated. Upgrade to use our sourcemap.mapSources 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() 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. 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

    Example:

    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);
    };
    • Verify sourcemaps are working

      See example below or refer to test/write.js

    Example:

    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 relies on visionmedia/debug. Follow the directions to set the environment variable $DEBUG.

For a few examples of debug you could use:

  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

vinyl-sourcemaps-apply's People

Contributors

floridoo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

vinyl-sourcemaps-apply's Issues

new assertProperty check too strict

Hi floridoo,

I just submitted a PR to make the assertProperty function robust to e.g. empty strings. Could you also publish a new version on NPM?

Rogier

Strange bug merging sourcemaps

Hi,

I'm trying to write a gulp plugin allowing to apply regexp with a sourcemap support. As far as I know I'm producing valid sourcemaps in my module but the resulting sourcemaps after merge in applySourceMap are wrong.

I used my plugin twice in a row to create the bug. Here is my test case:

gulp.src('test.js')
  .pipe(gulpSourceMaps.init())
  .pipe(module.exports(/^/, "(function() {"))
  .pipe(module.exports(/$/, "})();"))
  .pipe(gulpSourceMaps.write('.', {addComment: false}))
  .pipe(gulp.dest('build/'))
;

test.js looks like:

'use strict';

console.log('this is a test');

After the first call to the plugin here is the resulting source map structure:

{ version: 3,
  sources: [ 'replace-43237791-afa7-49f9-a334-b8f3d92ccf5c', 'test.js' ],
  names: [],
  mappings: 'AAAA,aCAA;AAAA;AAAA',
  file: 'test.js',
  sourcesContent: 
   [ '(function() {',
     '\'use strict\';\n\nconsole.log(\'this is a test\');\n' ] }

This looks good to me.

The second call to the plugin creates the following result:

{ version: 3,
  sources: [ 'test.js', 'replace-b9687322-214c-4721-8ca8-1fe8b13552f4' ],
  names: [],
  mappings: 'AAAA;AAAA;AAAA;ACAA',
  file: 'test.js',
  sourcesContent: 
   [ '(function() {\'use strict\';\n\nconsole.log(\'this is a test\');\n',
     '})();' ] }

This stills seems right to me. But here is the result after applySourceMap on the two maps:

{ version: 3,
  sources: 
   [ 'replace-43237791-afa7-49f9-a334-b8f3d92ccf5c',
     'replace-b9687322-214c-4721-8ca8-1fe8b13552f4' ],
  names: [],
  mappings: 'AAAA;AAAA;AAAA;ACAA',
  file: 'test.js',
  sourcesContent: [ '(function() {', '})();' ] }

There is no test.js in the resulting sourcemap and the mapping is a copy/paste from the second call without anything looking like the mapping generated by the first.

Any ideas on what I might have done wrong?

Add LICENSE file

Can you please add a LICENSE file like that seen in other libraries? Legal department needs this.

Inconsistent Source Map generation based on file path depth

Hi! I'm new to GitHub and I look forward to working with you!

Quite a few details already exist in pull request: sindresorhus/gulp-autoprefixer#66

Right now I can't pin point a cause between PostCSS, gulp-autoprefixer, and vinyl-sourcemaps-apply. @sindresorhus suggested I move the conversation here.

I've just started looking at the source code for this repository, I'll hopefully have more to say than "my stuff is broke!" with in a couple days. I wanted to get the conversation started, since during the week we are all extra busy. This way it may at least be sitting in the back of your mind.

I'll re-post some of the details here to keep everything in one place.

The problem doesn't happen for files at the top level.

Consider the following is the project folder structure.

source/
    sub-directory/
        app.scss
    top.scss
gulpfile.js
package.json

npm i --save-dev gulp gulp-autoprefixer gulp-load-plugins gulp-plumber gulp-sass gulp-sourcemaps

{
  "private":true,
  "name": "test-sourcemaps",
  "version": "1.0.0",
  "devDependencies": {
    "gulp": "^3.9.1",
    "gulp-autoprefixer": "^3.1.0",
    "gulp-load-plugins": "^1.2.4",
    "gulp-plumber": "^1.1.0",
    "gulp-sass": "^2.3.2",
    "gulp-sourcemaps": "^1.6.0"
  }
}
/* ./gulpfile.js */
const gulp            = require('gulp')
    , gulpLoadPlugins = require('gulp-load-plugins')
    , $               = gulpLoadPlugins()
;

gulp.task('default', (callback)=>{
    return gulp.src('source/**/*.scss', {
            base: 'source'
        })
        .pipe($.sourcemaps.init())
        .pipe($.sass.sync({
            outputStyle: 'expanded',
            precision: 10,
            includePaths: ['.']
        }).on('error', $.sass.logError))
        .pipe($.autoprefixer())
        .pipe($.sourcemaps.write('.', {
            includeContent: false
        }))
        .pipe(gulp.dest('dist/'))
    ;
});
/* ./source/top.scss */
$bgColor: cyan;

body{
    background:$bgColor;
}
/* ./source/sub-directory/app.scss */
$bgColor: lime;

body{
    background:$bgColor;
}

Modify gulp-autoprefixer to track it: https://github.com/sindresorhus/gulp-autoprefixer/blob/v3.1.0/index.js

          if (file.isStream()) {
              cb(new gutil.PluginError('gulp-autoprefixer', 'Streaming not supported'));
              return;
          }

          postcss(autoprefixer(opts)).process(file.contents.toString(), {
              map: file.sourceMap ? {annotation: false} : false,
              from: file.path,
              to: file.path
          }).then(function (res) {
              file.contents = new Buffer(res.css);

++            console.log('GULP-AUTOPREFIXER #1');
++            console.log(file.sourceMap);
              if (res.map && file.sourceMap) {
                  applySourceMap(file, res.map.toString());
              }
++            console.log('GULP-AUTOPREFIXER #2');
++            console.log(file.sourceMap);

The console will display the following: (using diff for convenient highlighting.)

  GULP-AUTOPREFIXER #1
  { version: 3,
    file: 'top.css',
    sources: [ 'top.scss' ],
    sourcesContent: [ '$bgColor : cyan;\r\n\r\nbody{\r\n    background:$bgColor;\r\n}' ],
    mappings: 'AAEA,AAAA,IAAI,CAAA;EACA,UAAU,EAHH,IAAI;CAId',
    names: [] }
  GULP-AUTOPREFIXER #2
  { version: 3,
    sources: [ 'top.scss' ],
    names: [],
    mappings: 'AAEA;EACI,iBAHW;CAId',
    file: 'top.css',
    sourcesContent: [ '$bgColor : cyan;\r\n\r\nbody{\r\n    background:$bgColor;\r\n}' ] }
  GULP-AUTOPREFIXER #1
  { version: 3,
    file: 'sub-directory/app.css',
++  sources: [ 'sub-directory/app.scss' ],
++  sourcesContent: [ '$bgColor : lime;\r\n\r\nbody{\r\n    background:$bgColor;\r\n}' ],
    mappings: 'AAEA,AAAA,IAAI,CAAA;EACA,UAAU,EAHH,IAAI;CAId',
    names: [] }
  GULP-AUTOPREFIXER #2
  { version: 3,
--  sources: [ 'app.css' ],
    names: [],
    mappings: 'AAAA;EACE,iBAAiB;CAClB',
    file: 'app.css',
--  sourcesContent: [ 'body {\n  background: lime;\n}\n' ] }

We get the following:

top.css.map

{"version":3,"sources":["top.scss"],"names":[],"mappings":"AAEA;EACI,iBAHW;CAId","file":"top.css"}

app.css.map

{"version":3,"sources":["app.css"],"names":[],"mappings":"AAAA;EACE,iBAAiB;CAClB","file":"sub-directory/app.css"}

top.css.map still points to the SASS file, while app.css.map thinks that the output from Autoprefixer is the source.

"/some/thing.scss" is not in the SourceMap

I am not sure what's going on but when I use node-sass and I try to apply a map on multiple steps it starts to throw errors on file paths.

{
  "version":3,
  "sources":[
    "shared.scss",
    "_variables.scss",
    "../../node_modules/bourbon/app/assets/stylesheets/css3/_font-face.scss",
    "../../node_modules/bourbon/app/assets/stylesheets/helpers/_font-source-declaration.scss"
  ],
  "names":[

  ],
  "mappings":"...",
  "file":"bundle.min.css",
  "sourcesContent":[
    "...",
    "...",
    "@mixin font-face(\n  $font-family,\n  $file-path,\n  $weight: normal,\n  $style: normal,\n  $asset-pipeline: $asset-pipeline,\n  $file-formats: eot woff2 woff ttf svg) {\n\n  $font-url-prefix: font-url-prefixer($asset-pipeline);\n\n  @font-face {\n    font-family: $font-family;\n    font-style: $style;\n    font-weight: $weight;\n\n    src: font-source-declaration(\n      $font-family,\n      $file-path,\n      $asset-pipeline,\n      $file-formats,\n      $font-url-prefix\n    );\n  }\n}\n",
    "// Used for creating the source string for fonts using @font-face\n// Reference: http://goo.gl/Ru1bKP\n\n@function font-url-prefixer($asset-pipeline) {\n  @if $asset-pipeline == true {\n    @return font-url;\n  } @else {\n    @return url;\n  }\n}\n\n@function font-source-declaration(\n  $font-family,\n  $file-path,\n  $asset-pipeline,\n  $file-formats,\n  $font-url) {\n\n  $src: ();\n\n  $formats-map: (\n    eot:   \"#{$file-path}.eot?#iefix\" format(\"embedded-opentype\"),\n    woff2: \"#{$file-path}.woff2\" format(\"woff2\"),\n    woff:  \"#{$file-path}.woff\" format(\"woff\"),\n    ttf:   \"#{$file-path}.ttf\" format(\"truetype\"),\n    svg:   \"#{$file-path}.svg##{$font-family}\" format(\"svg\")\n  );\n\n  @each $key, $values in $formats-map {\n    @if contains($file-formats, $key) {\n      $file-path: nth($values, 1);\n      $font-format: nth($values, 2);\n\n      @if $asset-pipeline == true {\n        $src: append($src, font-url($file-path) $font-format, comma);\n      } @else {\n        $src: append($src, url($file-path) $font-format, comma);\n      }\n    }\n  }\n\n  @return $src;\n}\n"
  ],
  "sourceRoot":"/source/"
}

I get:

Error: "/node_modules/bourbon/app/assets/stylesheets/css3/_font-face.scss" is not in the SourceMap.
    at SourceMapConsumer_sourceContentFor [as sourceContentFor] (/Volumes/WS/archive/.../webapp/node_modules/source-map/lib/source-map-consumer.js:703:15)
    at SourceMapGenerator.<anonymous> (/Volumes/WS/archive/.../webapp/node_modules/source-map/lib/source-map-generator.js:229:42)
    at Array.forEach (native)
    at SourceMapGenerator_applySourceMap [as applySourceMap] (/Volumes/WS/archive/.../webapp/node_modules/source-map/lib/source-map-generator.js:228:34)
    at applySourceMap (/Volumes/WS/archive/.../webapp/node_modules/vinyl-sourcemaps-apply/index.js:27:15)
    at Transform.<anonymous> (/Volumes/WS/archive/.../webapp/node_modules/gulp-cssnano/index.js:29:21)
    at process._tickCallback (internal/process/next_tick.js:103:7)

when I run

gulp.task('css', () => {
  return gulp.src([
    'app/styles/shared.scss',
    'app/containers/**/**.scss',
    'app/components/**/**.scss'
  ])
    .pipe(plugins.sourcemaps.init({ loadMaps: true }))
    .pipe(plugins.sass({ includePaths: bourbon.includePaths }))
    .pipe(plugins.concat('bundle.min.css'))
    .pipe(plugins.sourcemaps.write('.'))
    .pipe(gulp.dest('app'))
})

gulp.task('minify:css', () => {
  return gulp.src('app/bundle.min.css')
    .pipe(plugins.sourcemaps.init({ loadMaps: true }))
    .pipe(plugins.cssnano())
    .pipe(plugins.sourcemaps.write('.'))
    .pipe(gulp.dest('dist'))
})

and the failing line is: https://github.com/ben-eb/gulp-cssnano/blob/master/index.js#L29

v0.1.2 is a breaking change

Looks like this commit that adds assertions is actually a breaking change:

1bee9f5

Now gulp-less no longer works since it was (and still is) not passing a "file" property. Took me a while to track this down.

I was able to work around by using specifically 0.1.1 in my package.json which causes npm to dedupe the deep dependency on this library in gulp-less and use my version I install; so it works. But really this should have bumped the major version since it is not backwards compat.

LESS files that only contain comments cause an error to be thrown

I have a couple of LESS files in my project that only contain a comment:

/* TODO: Add styles for component: hello-world */

And this now causes the following error to be thrown

error : Source map to be applied is missing the "mappings" property
at assertProperty (root\node_modules\gulp-less\node_modules\vinyl-sourcemaps-apply\index.js:32:13)
at applySourceMap (root\node_modules\gulp-less\node_modules\vinyl-sourcemaps-apply\index.js:12:3)
at root\node_modules\gulp-less\index.js:66:13
at root\node_modules\gulp-less\node_modules\less\lib\less\index.js:29:17
at Object.finish as _finish
at Object.tree.importVisitor.run (root\node_modules\gulp-less\node_modules\less\lib\less\import-visitor.js:34:22)
at Object.Parser.parser.parse (root\node_modules\gulp-less\node_modules\less\lib\less\parser.js:675:22)
at Object.less.render (root\node_modules\gulp-less\node_modules\less\lib\less\index.js:22:20)
at Transform._transform (root\node_modules\gulp-less\index.js:42:10)
at Transform._read (root\node_modules\gulp-less\node_modules\through2\node_modules\readable-stream\lib_stream_transform.js:184:10)

If I remove the comments and make it an empty file, it works fine. However, if I also change the assertProperty method from:

function assertProperty(sourceMap, propertyName) {
  if (!sourceMap[propertyName]) {
    var e = new Error('Source map to be applied is missing the \"' + propertyName + '\" property');
    throw e;
  }
}

to:

function assertProperty(sourceMap, propertyName) {
  // protect against falsey values by using typeof, instead
  if (typeof sourceMap[propertyName] === 'undefined') {
    var e = new Error('Source map to be applied is missing the \"' + propertyName + '\" property');
    throw e;
  }
}

Then that also works fine. The problem is that the value, an empty string, is coming through as falsey. I believe that checking for an undefined property is what is actually intended here. My sincerest apologies for the lack of a pull request, I'm new to GitHub.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.