Socket
Socket
Sign inDemoInstall

c8

Package Overview
Dependencies
Maintainers
2
Versions
88
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

c8 - npm Package Compare versions

Comparing version 7.4.0 to 7.5.0

7

CHANGELOG.md

@@ -5,2 +5,9 @@ # Changelog

## [7.5.0](https://www.github.com/bcoe/c8/compare/v7.4.0...v7.5.0) (2021-02-01)
### Features
* **all:** handle base64 inline source maps ([#283](https://www.github.com/bcoe/c8/issues/283)) ([3f12dd4](https://www.github.com/bcoe/c8/commit/3f12dd4cd4b903b396c60c9c6d76cdf990ec6cbe))
## [7.4.0](https://www.github.com/bcoe/c8/compare/v7.3.5...v7.4.0) (2020-12-31)

@@ -7,0 +14,0 @@

4

lib/report.js

@@ -188,4 +188,4 @@ const Exclude = require('test-exclude')

const sourceMap = getSourceMapFromFile(fullPath)
if (sourceMap !== undefined) {
this.sourceMapCache[`file://${fullPath}`] = { data: JSON.parse(readFileSync(sourceMap).toString()) }
if (sourceMap) {
this.sourceMapCache[`file://${fullPath}`] = { data: sourceMap }
}

@@ -192,0 +192,0 @@ emptyReports.push({

@@ -1,3 +0,32 @@

const { isAbsolute, join, dirname } = require('path')
/*
* Copyright Node.js contributors. All rights reserved.
*
* 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.
*/
// TODO(bcoe): this logic is ported from Node.js' internal source map
// helpers:
// https://github.com/nodejs/node/blob/master/lib/internal/source_map/source_map_cache.js
// we should to upstream and downstream fixes.
const { readFileSync } = require('fs')
const { fileURLToPath, pathToFileURL } = require('url')
const util = require('util')
const debuglog = util.debuglog('c8')
/**

@@ -10,17 +39,63 @@ * Extract the sourcemap url from a source file

*/
function getSourceMapFromFile (file) {
const fileBody = readFileSync(file).toString()
const sourceMapLineRE = /\/\/[#@] ?sourceMappingURL=([^\s'"]+)\s*$/mg
function getSourceMapFromFile (filename) {
const fileBody = readFileSync(filename).toString()
const sourceMapLineRE = /\/[*/]#\s+sourceMappingURL=(?<sourceMappingURL>[^\s]+)/
const results = fileBody.match(sourceMapLineRE)
if (results !== null) {
const sourceMap = results[results.length - 1].split('=')[1]
if (isAbsolute(sourceMap)) {
return sourceMap.trim()
} else {
const base = dirname(file)
return join(base, sourceMap).trim()
const sourceMappingURL = results.groups.sourceMappingURL
const sourceMap = dataFromUrl(pathToFileURL(filename), sourceMappingURL)
return sourceMap
} else {
return null
}
}
function dataFromUrl (sourceURL, sourceMappingURL) {
try {
const url = new URL(sourceMappingURL)
switch (url.protocol) {
case 'data:':
return sourceMapFromDataUrl(url.pathname)
default:
return null
}
} catch (err) {
debuglog(err)
// If no scheme is present, we assume we are dealing with a file path.
const mapURL = new URL(sourceMappingURL, sourceURL).href
return sourceMapFromFile(mapURL)
}
}
function sourceMapFromFile (mapURL) {
try {
const content = readFileSync(fileURLToPath(mapURL), 'utf8')
return JSON.parse(content)
} catch (err) {
debuglog(err)
return null
}
}
// data:[<mediatype>][;base64],<data> see:
// https://tools.ietf.org/html/rfc2397#section-2
function sourceMapFromDataUrl (url) {
const { 0: format, 1: data } = url.split(',')
const splitFormat = format.split(';')
const contentType = splitFormat[0]
const base64 = splitFormat[splitFormat.length - 1] === 'base64'
if (contentType === 'application/json') {
const decodedData = base64 ? Buffer.from(data, 'base64').toString('utf8') : data
try {
return JSON.parse(decodedData)
} catch (err) {
debuglog(err)
return null
}
} else {
debuglog(`unexpected content-type ${contentType}`)
return null
}
}
module.exports = getSourceMapFromFile
{
"name": "c8",
"version": "7.4.0",
"version": "7.5.0",
"description": "output coverage reports using Node.js' built in coverage",

@@ -5,0 +5,0 @@ "main": "./index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc