How to use merge-source-map - 10 common examples

To help you get started, we’ve selected a few merge-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 vuejs / vue-next / packages / compiler-sfc / src / stylePreprocessors.ts View on Github external
let error: Error | null = null
    nodeLess.render(
      source,
      { ...options, syncImport: true },
      (err: Error | null, output: any) => {
        error = err
        result = output
      }
    )

    if (error) return { code: '', errors: [error] }

    if (map) {
      return {
        code: result.css.toString(),
        map: merge(map, result.map),
        errors: []
      }
    }

    return { code: result.css.toString(), errors: [] }
  }
}
github steelbrain / pundle / packages / pundle-api / src / context / index.js View on Github external
'RESOLVE_FAILED',
            `Transformer '${transformer.name}' returned invalid result: ${error.errors.join(', ')}`,
          )
        }
        throw error
      }

      let newSourceMap = null
      if (transformed.sourceMap === false) {
        newSourceMap = false
      } else if (result.sourceMap === false) {
        newSourceMap = false
      } else if (result.sourceMap && !transformed.sourceMap) {
        newSourceMap = result.sourceMap
      } else if (result.sourceMap && transformed.sourceMap) {
        newSourceMap = mergeSourceMap(transformed.sourceMap, result.sourceMap)
      }
      transformed = { sourceMap: newSourceMap, contents: result.contents }
    }

    const transformedSourceMap = transformed.sourceMap
    if (transformedSourceMap && Array.isArray(transformedSourceMap.sources)) {
      const sourceIndex = transformedSourceMap.sources.findIndex(source => source && filePath.endsWith(source))
      if (sourceIndex !== -1) {
        if (!transformedSourceMap.sourcesContent) {
          transformedSourceMap.sourcesContent = []
        }
        transformedSourceMap.sourcesContent[sourceIndex] = typeof contents === 'string' ? contents : contents.toString()
      }
    }

    return {
github steelbrain / pundle / packages / pundle-loader-css / src / index.js View on Github external
const aggregatedRoot = rootsArr.slice(1).reduce((entry, curr) => entry.append(curr), rootsArr[0])

      if (options.scoped) {
        aggregatedRoot.nodes.forEach(node => {
          node.selector = `${node.selector}.${randomId}`
        })
      }

      const results = aggregatedRoot.toResult({
        map: options.sourceMap ? { inline: false, annotation: false } : false,
      })
      let css = results.css

      if (results.map) {
        const currentSourceMap = results.map.toJSON()
        const sourceMap = file.sourceMap ? mergeSourceMap(file.sourceMap, currentSourceMap) : currentSourceMap
        css += `\n${sourceMapToComment(sourceMap, { type: 'css' })}`
      }

      const processModule = await context.resolveSimple('process', file.filePath)
      const ast = template.ast`
        ${file.imports.map(i => `require(${JSON.stringify(i)})`).join('\n')}
        var style = document.createElement('style')
        style.type = 'text/css'
        if (require(${JSON.stringify(processModule)}).env.NODE_ENV === "development" && module.hot && module.hot.dispose) {
          module.hot.dispose(function() {
            style.remove()
          })
        }
        style.textContent = ${JSON.stringify(css)}
        document.head.appendChild(style)
        module.exports = ${JSON.stringify(options.scoped ? randomId : null)}
github steelbrain / pundle / packages / pundle-chunk-transformer-uglify / src / index.js View on Github external
...options,
        compress: {
          defaults: false,
          ...options.compress,
        },
      })
      if (error) {
        throw new Error(error)
      }

      return {
        contents: code,
        sourceMap:
          sourceMap && map
            ? {
                contents: JSON.stringify(mergeSourceMap(sourceMap.contents, map)),
              }
            : null,
      }
    },
  })
github vuejs / vue-next / packages / compiler-sfc / src / stylePreprocessors.ts View on Github external
const nodeSass = require('sass')
    const finalOptions = {
      ...options,
      data: source,
      file: options.filename,
      outFile: options.filename,
      sourceMap: !!map
    }

    try {
      const result = nodeSass.renderSync(finalOptions)

      if (map) {
        return {
          code: result.css.toString(),
          map: merge(map, JSON.parse(result.map.toString())),
          errors: []
        }
      }

      return { code: result.css.toString(), errors: [] }
    } catch (e) {
      return { code: '', errors: [e] }
    }
  }
}
github steelbrain / pundle / packages / pundle-api / src / File.js View on Github external
mergeTransformation(contents: string, sourceMap: ?Object): void {
    if (this.sourceMap && !sourceMap) {
      this.sourceMap = null
    } else if (!this.sourceMap && sourceMap) {
      this.sourceMap = sourceMap
    } else if (this.sourceMap && sourceMap) {
      this.sourceMap = mergeSourceMap(this.sourceMap, sourceMap)
    }

    const newSourceMap = this.sourceMap
    if (newSourceMap) {
      newSourceMap.sources = [this.fileName]
      newSourceMap.sourcesContent = [this.sourceContents.toString('utf8')]
    }
    this.contents = contents
  }
  addChunk(entry: Chunk): void {
github steelbrain / pundle / packages / api / src / file.js View on Github external
mergeTransformation(contents: string, sourceMap: ?Object): void {
    if (this.sourceMap && !sourceMap) {
      this.sourceMap = null
    } else if (!this.sourceMap && sourceMap) {
      this.sourceMap = sourceMap
    } else if (this.sourceMap && sourceMap) {
      this.sourceMap = mergeSourceMap(this.sourceMap, sourceMap)
    }
    this.contents = contents
  }
  serialize(): Object {
github steelbrain / pundle / packages / pundle / src / context / helpers.js View on Github external
export function mergeResult(file: File, result: ?{ contents: string, sourceMap: ?Object }): void {
  if (!result) {
    return
  }
  if (file.sourceMap && !result.sourceMap) {
    file.sourceMap = null
  } else if (file.sourceMap && result.sourceMap) {
    file.sourceMap = mergeSourceMap(file.sourceMap, result.sourceMap)
  } else if (!file.sourceMap && result.sourceMap) {
    file.sourceMap = result.sourceMap
  }
  file.contents = result.contents
}
github vuejs / vue-next / packages / compiler-sfc / src / stylePreprocessors.ts View on Github external
render(source, map, options) {
    const nodeStylus = require('stylus')
    try {
      const ref = nodeStylus(source)
      Object.keys(options).forEach(key => ref.set(key, options[key]))
      if (map) ref.set('sourcemap', { inline: false, comment: false })

      const result = ref.render()
      if (map) {
        return {
          code: result,
          map: merge(map, ref.sourcemap),
          errors: []
        }
      }

      return { code: result, errors: [] }
    } catch (e) {
      return { code: '', errors: [e] }
    }
  }
}
github steelbrain / pundle / packages / api / src / context / helpers.js View on Github external
export function mergeResult(file: { contents: string, sourceMap: ?Object }, result: ?{ contents: string, sourceMap: ?Object }): void {
  if (!result) {
    return
  }
  if (file.sourceMap && !result.sourceMap) {
    file.sourceMap = null
  } else if (file.sourceMap && result.sourceMap) {
    file.sourceMap = mergeSourceMap(file.sourceMap, result.sourceMap)
  } else if (!file.sourceMap && result.sourceMap) {
    file.sourceMap = result.sourceMap
  }
  file.contents = result.contents
}

merge-source-map

Merge old source map and new source map in multi-transform flow

MIT
Latest version published 7 years ago

Package Health Score

65 / 100
Full package analysis

Popular merge-source-map functions