How to use the source-map-url.getFrom function in source-map-url

To help you get started, we’ve selected a few source-map-url 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 vuejs / vue-cli / packages / @vue / cli-service / lib / webpack / InlineSourcePlugin.js View on Github external
resolveSourceMaps (compilation, assetName, asset) {
    let source = asset.source()
    const out = compilation.outputOptions
    // Get asset file absolute path
    const assetPath = path.join(out.path, assetName)
    // Extract original sourcemap URL from source string
    if (typeof source !== 'string') {
      source = source.toString()
    }
    const mapUrlOriginal = sourceMapUrl.getFrom(source)
    // Return unmodified source if map is unspecified, URL-encoded, or already relative to site root
    if (!mapUrlOriginal || mapUrlOriginal.indexOf('data:') === 0 || mapUrlOriginal.indexOf('/') === 0) {
      return source
    }
    // Figure out sourcemap file path *relative to the asset file path*
    const assetDir = path.dirname(assetPath)
    const mapPath = path.join(assetDir, mapUrlOriginal)
    const mapPathRelative = path.relative(out.path, mapPath)
    // Starting with Node 6, `path` module throws on `undefined`
    const publicPath = out.publicPath || ''
    // Prepend Webpack public URL path to source map relative path
    // Calling `slash` converts Windows backslashes to forward slashes
    const mapUrlCorrected = slash(path.join(publicPath, mapPathRelative))
    // Regex: exact original sourcemap URL, possibly '*/' (for CSS), then EOF, ignoring whitespace
    const regex = new RegExp(escapeRegex(mapUrlOriginal) + '(\\s*(?:\\*/)?\\s*$)')
    // Replace sourcemap URL and (if necessary) preserve closing '*/' and whitespace
github GoogleChrome / workbox / packages / workbox-build / src / inject-manifest.js View on Github external
// See https://github.com/GoogleChrome/workbox/issues/2230
    if (upath.resolve(options.swSrc) === upath.resolve(options.swDest)) {
      throw new Error(errors['same-src-and-dest'] + ' ' +
        options.injectionPoint);
    }
    throw new Error(errors['injection-point-not-found'] + ' ' +
      options.injectionPoint);
  }

  assert(injectionResults.length === 1, errors['multiple-injection-points'] +
    options.injectionPoint);

  const manifestString = stringify(manifestEntries);
  const filesToWrite = {};

  const url = sourceMapURL.getFrom(swFileContents);
  // If our swSrc file contains a sourcemap, we would invalidate that
  // mapping if we just replaced injectionPoint with the stringified manifest.
  // Instead, we need to update the swDest contents as well as the sourcemap
  // at the same time.
  // See https://github.com/GoogleChrome/workbox/issues/2235
  if (url) {
    const sourcemapSrcPath = upath.resolve(upath.dirname(options.swSrc), url);
    const sourcemapDestPath = upath.resolve(upath.dirname(options.swDest), url);

    let originalMap;
    try {
      originalMap = await fse.readJSON(sourcemapSrcPath, 'utf8');
    } catch (error) {
      throw new Error(`${errors['cant-find-sourcemap']} ${error.message}`);
    }
github sx1989827 / DOClever / node_modules / source-map-resolve / lib / source-map-resolve-node.js View on Github external
function resolveSourceMapHelper(code, codeUrl) {
  codeUrl = urix(codeUrl)

  var url = sourceMappingURL.getFrom(code)
  if (!url) {
    return null
  }

  var dataUri = url.match(dataUriRegex)
  if (dataUri) {
    var mimeType = dataUri[1]
    var lastParameter = dataUri[2] || ""
    var encoded = dataUri[3] || ""
    var data = {
      sourceMappingURL: url,
      url: null,
      sourcesRelativeTo: codeUrl,
      map: encoded
    }
    if (!jsonMimeTypeRegex.test(mimeType)) {
github wheeyls / critical-css-server / node_modules / source-map-resolve / lib / source-map-resolve-node.js View on Github external
function resolveSourceMapHelper(code, codeUrl) {
  codeUrl = urix(codeUrl)

  var url = sourceMappingURL.getFrom(code)
  if (!url) {
    return null
  }

  var dataUri = url.match(dataUriRegex)
  if (dataUri) {
    var mimeType = dataUri[1]
    var lastParameter = dataUri[2]
    var encoded = dataUri[3]
    if (!jsonMimeTypeRegex.test(mimeType)) {
      throw new Error("Unuseful data uri mime type: " + (mimeType || "text/plain"))
    }
    return {
      sourceMappingURL: url,
      url: null,
      sourcesRelativeTo: codeUrl,
github lautis / rollup-plugin-browserify-transform / src / index.js View on Github external
function parseSourceMap(code) {
  const map = sourceMapURL.getFrom(code)
  try {
    return JSON.parse(new Buffer(map.split(',', 2)[1], 'base64').toString())
  } catch(error) {
    return { mappings: '' }
  }
}
github lydell / source-map-resolve / lib / source-map-resolve-node.js View on Github external
function resolveSourceMapHelper(code, codeUrl) {
  codeUrl = urix(codeUrl)

  var url = sourceMappingURL.getFrom(code)
  if (!url) {
    return null
  }

  var dataUri = url.match(dataUriRegex)
  if (dataUri) {
    var mimeType = dataUri[1] || "text/plain"
    var lastParameter = dataUri[2] || ""
    var encoded = dataUri[3] || ""
    var data = {
      sourceMappingURL: url,
      url: null,
      sourcesRelativeTo: codeUrl,
      map: encoded
    }
    if (!jsonMimeTypeRegex.test(mimeType)) {

source-map-url

Tools for working with sourceMappingURL comments.

MIT
Latest version published 4 years ago

Package Health Score

52 / 100
Full package analysis