How to use the convert-source-map.removeMapFileComments function in convert-source-map

To help you get started, we’ve selected a few convert-source-map examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sindresorhus / gulp-ruby-sass / index.js View on Github external
next();
						return;
					}

					// Rewrite file paths so gulp thinks the file came from cwd, not the
					// intermediate directory
					const vinylFile = new Vinyl({
						cwd: process.cwd(),
						base,
						path: replaceLocation(file, intermediateDir, base)
					});

					// Sourcemap integration
					if (options.sourcemap === 'file' && pathExists.sync(file + '.map')) {
						// Remove sourcemap comment; gulp-sourcemaps will add it back in
						data = Buffer.from(convert.removeMapFileComments(data.toString()));
						const sourceMapObject = JSON.parse(fs.readFileSync(file + '.map', 'utf8'));

						// Create relative paths for sources
						sourceMapObject.sources = sourceMapObject.sources.map(sourcePath => {
							const absoluteSourcePath = decodeURI(path.resolve(
								'/',
								sourcePath.replace('file:///', '')
							));
							return path.relative(base, absoluteSourcePath);
						});

						vinylFile.sourceMap = sourceMapObject;
					}

					vinylFile.contents = data;
					stream.push(vinylFile);
github gulpjs / vinyl-sourcemap / lib / helpers.js View on Github external
state.map = state.map.toObject();
    // Sources in map are relative to the source file
    state.path = file.dirname;
    state.content = convert.removeComments(state.content);
    // Remove source map comment from source
    file.contents = new Buffer(state.content, 'utf8');
    return callback();
  }

  // Look for source map comment referencing a source map file
  var mapComment = convert.mapFileCommentRegex.exec(state.content);

  var mapFile;
  if (mapComment) {
    mapFile = path.resolve(file.dirname, mapComment[1] || mapComment[2]);
    state.content = convert.removeMapFileComments(state.content);
    // Remove source map comment from source
    file.contents = new Buffer(state.content, 'utf8');
  } else {
    // If no comment try map file with same name as source file
    mapFile = file.path + '.map';
  }

  // Sources in external map are relative to map file
  state.path = path.dirname(mapFile);

  fs.readFile(mapFile, onRead);

  function onRead(err, data) {
    if (err) {
      return callback();
    }
github polyfills / ecstacy / lib / css.js View on Github external
CSS.prototype._transform = function (code, map, transforms) {
  var processor = postcss()()
  transforms.forEach(function (transform) {
    processor.use(transform.transform())
  })
  var useSourcemaps = this.sourcemaps
  var result = processor.process(code, useSourcemaps ? {
    map: map
      ? { prev: map }
      : true,
    from: this.name + '.css',
    to: this.name + '.css',
  } : {})
  return {
    code: convert.removeMapFileComments(result.css),
    map: useSourcemaps
      ? JSON.stringify(result.map) // test to make sure it's not a string already
      : ''
  }
}
github linkedin / css-blocks / packages / webpack-plugin / src / CssAssets.ts View on Github external
function assetAsSource(contents: string, filename: string): Source {
    let sourcemap: convertSourceMap.SourceMapConverter | undefined;
    if (/sourceMappingURL/.test(contents)) {
        sourcemap = convertSourceMap.fromSource(contents) ||
            convertSourceMap.fromMapFileComment(contents, path.dirname(filename));
    }
    if (sourcemap) {
        let sm: RawSourceMap = sourcemap.toObject();
        contents = convertSourceMap.removeComments(contents);
        contents = convertSourceMap.removeMapFileComments(contents);
        return new SourceMapSource(contents, filename, sm);
    } else {
        return new RawSource(contents);
    }
}
github jallajs / jalla / lib / style.js View on Github external
async function compile (files, plugins, opts) {
    var content = files.map((file) => `@import "${file}";`).join('\n')
    var result = await postcss(plugins).process(content, opts)
    var css = result.css
    if (state.env !== 'development') css = sourcemap.removeMapFileComments(css)
    css = Buffer.from(css)
    var map = result.map && Buffer.from(JSON.stringify(result.map, null, 2))

    result.messages.forEach(function (message) {
      if (message.type === 'dependency') {
        if (!/node_modules/.test(message.file)) {
          emit('dep', message.file)
        }
      } else {
        emit(message.type, message.text)
      }
    })

    return { css, map }
  }
github olov / ng-annotate / generate-sourcemap.js View on Github external
module.exports = function generateSourcemap(result, src, nodePositions, fragments, mapOpts) {
    const existingMap = convertSourceMap.fromSource(src);
    src = convertSourceMap.removeMapFileComments(src);

    const mapper = new SourceMapper(src, nodePositions, fragments, mapOpts.inFile, mapOpts.sourceRoot);
    mapper.calculateMappings();

    if (mapOpts.inline) {
        if (existingMap)
            mapper.applySourceMap(new SourceMapConsumer(existingMap.toObject()));

        result.src = convertSourceMap.removeMapFileComments(result.src) +
            os.EOL +
            convertSourceMap.fromJSON(mapper.generate()).toComment();
    } else {
        result.map = mapper.generate();
    }
}
github kratiahuja / fastboot-transform / src / index.js View on Github external
return map(tree, '**/*.js', (content) => {
    content = convert.removeMapFileComments(content);
    return `if (typeof FastBoot === 'undefined') {\n${content}\n}`;
  });
}
github plasma-umass / Stopify / stopify-ide / ts / compilers / utils.ts View on Github external
    .then(src => fsExtra.writeFile(srcPath, smc.removeMapFileComments(src), { encoding: 'utf-8' }))
    .then(() => fs.appendFile(srcPath, inline, { encoding: 'utf-8' }))
github dumberjs / dumber / lib / shared.js View on Github external
function stripSourceMappingUrl(contents) {
  return convert.removeMapFileComments(convert.removeComments(contents));
}
github download-online-video / chrome-avgle-helper / build / build.js View on Github external
function afterBundle(isFirstBundle, error, buffer) {
					if (error) {
						if (isFirstBundle) onFatal(`browserify bundle "${fromName}" failed!`, error);
						return log.error(`browserify bundle "${fromName}" failed!`, error);
					}
					let code = String(buffer);
					let map = JSON.parse(sourceMapConvert.fromSource(code).toJSON());
					code = sourceMapConvert.removeMapFileComments(code);

					let babelResult = pipeToBabel(code, map);
					if (babelResult.error) {
						if (isFirstBundle) return onFatal(`build "${fromName}" failed!`, error);
						return log.error(`build "${fromName}" failed!`, error);
					}
					code = babelResult.code;
					map = babelResult.map;
					writeTextFile(to, code);
					writeTextFile(to, code)
						.then(() => writeTextFile(sourceMapTo, JSON.stringify(map, null, '\t')))
						.then(() => log.info(`build "${fromName}" to "${toName}"`))
						.catch(onFatal)
						.then(() => isFirstBundle ? resolve() : null);
				}
				function pipeToBabel(code, inputSourcesMap) {