How to use the source-map-support.retrieveSourceMap function in source-map-support

To help you get started, we’ve selected a few source-map-support 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 ozum / joi18n / node_modules / lab / lib / reporters / html.js View on Github external
context.coverage.cov.files = context.coverage.cov.files.map(async (file) => {

        if (!file.sourcemaps) {
            // return untouched file
            return file;
        }

        const descriptors = {};
        const generatedContent = Object.keys(file.source).map((k) => file.source[k].source).join('\n');

        // Rather than relying on generated content, get the nodes tree from sourcemap consumer
        const sourcemap = SourceMapSupport.retrieveSourceMap(file.filename).map;
        const smc = await new SourceMapConsumer(sourcemap);

        // For each original files that might have been transformed into this generate content, store a new descriptor
        SourceNode.fromStringWithSourceMap(generatedContent, smc).walkSourceContents((sourceFile, content) => {

            descriptors[sourceFile] = {
                generated: file.filename,
                filename: sourceFile,
                source: {}
            };

            content.split('\n').forEach((line, number) => {

                descriptors[sourceFile].source[number + 1] = {
                    source: line,
                    // consider line covered by default
github hapijs / lab / lib / coverage.js View on Github external
const ret = {
        // Ensure folder separator to be url-friendly
        filename: filename.replace(Path.join(process.cwd(), '/').replace(/\\/g, '/'), ''),
        percent: 0,
        hits: 0,
        misses: 0,
        sloc: data.sloc,
        source: {},
        externals: internals.external(filename)
    };

    // Use sourcemap consumer rather than SourceMapSupport.mapSourcePosition itself which perform path transformations

    let sourcemap = null;
    if (options.sourcemaps) {
        sourcemap = SourceMapSupport.retrieveSourceMap(ret.filename);
        if (!sourcemap) {
            const smre = /\/\/\#.*data:application\/json[^,]+base64,.*\r?\n?$/;
            let sourceIndex = data.source.length - 1;
            while (sourceIndex >= 0 && !smre.test(data.source[sourceIndex])) {
                sourceIndex--;
            }

            if (sourceIndex >= 0) {
                const re = /(?:\/\/[@#][ \t]+sourceMappingURL=([^\s'"]+?)[ \t]*$)|(?:\/\*[@#][ \t]+sourceMappingURL=([^\*]+?)[ \t]*(?:\*\/)[ \t]*$)/mg;
                let lastMatch;
                let match;
                while (match = re.exec(data.source[sourceIndex])) {
                    lastMatch = match;
                }

                sourcemap = {
github hapijs / lab / lib / reporters / html.js View on Github external
context.coverage.cov.files = context.coverage.cov.files.map(async (file) => {

        if (!file.sourcemaps) {
            // return untouched file
            return file;
        }

        const descriptors = {};
        const generatedContent = Object.keys(file.source).map((k) => file.source[k].source).join('\n');

        // Rather than relying on generated content, get the nodes tree from sourcemap consumer
        const sourcemap = SourceMapSupport.retrieveSourceMap(file.filename).map;
        const smc = await new SourceMap.SourceMapConsumer(sourcemap);

        // For each original files that might have been transformed into this generate content, store a new descriptor
        SourceMap.SourceNode.fromStringWithSourceMap(generatedContent, smc).walkSourceContents((sourceFile, content) => {

            descriptors[sourceFile] = {
                generated: file.filename,
                filename: sourceFile,
                source: {}
            };

            content.split('\n').forEach((line, number) => {

                descriptors[sourceFile].source[number + 1] = {
                    source: line,
                    // consider line covered by default
github roblav96 / robinhood.tools / src / server / adapters / utils.ts View on Github external
}).forEach(function(file) {
		let full = path.resolve(dirName, file)
		let src = sourcemaps.retrieveSourceMap(full).url
		if (src.endsWith('.map')) src = src.slice(0, -4);
		src = src.replace('/dist/', '/src/').replace('.js', '.ts')
		if (!fs.existsSync(src)) return;
		if (!filter || filter(path.basename(src))) require(full);
	})
}
github imodeljs / imodeljs / tools / certa / src / runners / chrome / webserver.ts View on Github external
app.use("/@/", (_req, resp) => {
  const filePath = _req.originalUrl.replace(/^\/@\//, "");
  const sourceMap = require("source-map-support").retrieveSourceMap(filePath);
  resp.sendFile(path.resolve("/", filePath), {
    headers: (sourceMap) && {
      "X-SourceMap": `/@/${sourceMap.url}`,
    },
  });
});
github roblav96 / robinhood.tools / src / server / adapters / utils.ts View on Github external
}).forEach(function(file) {
		let full = path.resolve(dirName, file)
		let src = sourcemaps.retrieveSourceMap(full).url
		if (src.endsWith('.map')) src = src.slice(0, -4);
		src = src.replace('/dist/', '/src/').replace('.js', '.ts')
		if (!fs.existsSync(src)) return;
		if (!filter || filter(path.basename(src))) require(full);
	})
}

source-map-support

Fixes stack traces for files with source maps

MIT
Latest version published 2 years ago

Package Health Score

71 / 100
Full package analysis

Similar packages