@parcel/source-map
Advanced tools
Comparing version 2.0.0-alpha.4.11 to 2.0.0-alpha.4.12
@@ -14,3 +14,3 @@ "use strict"; | ||
const bindings = require("node-gyp-build")(_path.default.join(__dirname, "..")); | ||
const bindings = require('node-gyp-build')(_path.default.join(__dirname, '..')); | ||
@@ -17,0 +17,0 @@ class NodeSourceMap extends _SourceMap.default { |
@@ -16,2 +16,6 @@ "use strict"; | ||
/** | ||
* @private | ||
*/ | ||
/** | ||
* Generates an empty map from the provided fileName and sourceContent | ||
@@ -24,3 +28,3 @@ * | ||
static generateEmptyMap(sourceName, sourceContent, lineOffset = 0) { | ||
throw new Error("SourceMap.generateEmptyMap() must be implemented when extending SourceMap"); | ||
throw new Error('SourceMap.generateEmptyMap() must be implemented when extending SourceMap'); | ||
} | ||
@@ -42,13 +46,20 @@ /** | ||
* Appends raw VLQ mappings to the sourcemaps | ||
* | ||
* @param mappings a string containing the Base64 encoded VLQ Mappings | ||
* @param sources an array of source filepaths used in the raw sourcemap | ||
* @param names an array of the names used in the raw sourcemap | ||
* @param lineOffset an offset that gets added to the sourceLine index of each mapping | ||
* @param columnOffset an offset that gets added to the sourceColumn index of each mapping | ||
*/ | ||
addRawMappings(mappings, sources, names, lineOffset = 0, columnOffset = 0) { | ||
this.sourceMapInstance.addRawMappings(mappings, sources, names, lineOffset, columnOffset); | ||
addRawMappings(map, lineOffset = 0, columnOffset = 0) { | ||
let { | ||
sourcesContent, | ||
sources = [], | ||
mappings, | ||
names = [] | ||
} = map; | ||
if (!sourcesContent) { | ||
sourcesContent = sources.map(() => ''); | ||
} else { | ||
sourcesContent = sourcesContent.map(content => content ? content : ''); | ||
} | ||
this.sourceMapInstance.addRawMappings(mappings, sources, sourcesContent.map(content => content ? content : ''), names, lineOffset, columnOffset); | ||
return this; | ||
@@ -81,6 +92,6 @@ } | ||
addIndexedMapping(mapping, lineOffset = 0, columnOffset = 0) { | ||
let hasValidOriginal = mapping.original && typeof mapping.original.line === "number" && !isNaN(mapping.original.line) && typeof mapping.original.column === "number" && !isNaN(mapping.original.column); | ||
let hasValidOriginal = mapping.original && typeof mapping.original.line === 'number' && !isNaN(mapping.original.line) && typeof mapping.original.column === 'number' && !isNaN(mapping.original.column); | ||
this.sourceMapInstance.addIndexedMapping(mapping.generated.line + lineOffset - 1, mapping.generated.column + columnOffset, // $FlowFixMe | ||
hasValidOriginal ? mapping.original.line - 1 : -1, // $FlowFixMe | ||
hasValidOriginal ? mapping.original.column : -1, mapping.source || "", mapping.name || ""); | ||
hasValidOriginal ? mapping.original.column : -1, mapping.source || '', mapping.name || ''); | ||
} | ||
@@ -172,2 +183,24 @@ /** | ||
/** | ||
* Set the sourceContent for a certain file | ||
* this is optional and is only recommended for files that we cannot read in at the end when we serialise the sourcemap | ||
* | ||
* @param {string} sourceName the path of the sourceFile | ||
* @param {string} sourceContent the content of the sourceFile | ||
*/ | ||
setSourceContent(sourceName, sourceContent) { | ||
return this.sourceMapInstance.setSourceContent(sourceName, sourceContent); | ||
} | ||
/** | ||
* Get the content of a source file if it is inlined as part of the source-map | ||
* | ||
* @param {string} sourceName | ||
*/ | ||
getSourceContent(sourceName) { | ||
return this.sourceMapInstance.getSourceContent(sourceName); | ||
} | ||
/** | ||
* Get the index in the names array for a certain name | ||
@@ -253,3 +286,3 @@ * | ||
findClosestMapping(line, column) { | ||
throw new Error("SourceMap.findClosestMapping() must be implemented when extending SourceMap"); | ||
throw new Error('SourceMap.findClosestMapping() must be implemented when extending SourceMap'); | ||
} | ||
@@ -262,3 +295,3 @@ /** | ||
toBuffer() { | ||
throw new Error("SourceMap.toBuffer() must be implemented when extending SourceMap"); | ||
throw new Error('SourceMap.toBuffer() must be implemented when extending SourceMap'); | ||
} | ||
@@ -279,3 +312,3 @@ /** | ||
delete() { | ||
throw new Error("SourceMap.delete() must be implemented when extending SourceMap"); | ||
throw new Error('SourceMap.delete() must be implemented when extending SourceMap'); | ||
} | ||
@@ -282,0 +315,0 @@ /** |
@@ -14,7 +14,7 @@ "use strict"; | ||
function generateInlineMap(map) { | ||
return `data:application/json;charset=utf-8;base64,${Buffer.from(map).toString("base64")}`; | ||
return `data:application/json;charset=utf-8;base64,${Buffer.from(map).toString('base64')}`; | ||
} | ||
function normalisePath(filepath) { | ||
return filepath.replace(/\\/g, "/"); | ||
return filepath.replace(/\\/g, '/'); | ||
} | ||
@@ -26,3 +26,3 @@ | ||
if (filepath[0] === "/") { | ||
if (filepath[0] === '/') { | ||
filepath = normalisePath(_path.default.relative(rootDir, filepath)); | ||
@@ -32,3 +32,3 @@ } // Prefix relative paths with ./ as it makes it more clear and probably prevents issues | ||
if (filepath[0] !== ".") { | ||
if (filepath[0] !== '.') { | ||
filepath = `./${filepath}`; | ||
@@ -46,6 +46,7 @@ } | ||
rootDir, | ||
format = "string" | ||
format = 'string' | ||
}) { | ||
let root = normalisePath(rootDir || "/"); | ||
let root = normalisePath(rootDir || '/'); | ||
let resultMap = { ...map, | ||
sourcesContent: map.sourcesContent ? map.sourcesContent.map(content => content ? content : null) : [], | ||
version: 3, | ||
@@ -59,16 +60,25 @@ file, | ||
if (inlineSources && fs) { | ||
resultMap.sourcesContent = await Promise.all(resultMap.sources.map(async sourceName => { | ||
try { | ||
return await fs.readFile(_path.default.resolve(root, sourceName), "utf-8"); | ||
} catch (e) { | ||
return null; | ||
if (resultMap.sourcesContent.length < resultMap.sources.length) { | ||
resultMap.sourcesContent.push(...new Array(resultMap.sources.length - resultMap.sourcesContent.length).fill(null)); | ||
} | ||
if (fs) { | ||
resultMap.sourcesContent = await Promise.all(resultMap.sourcesContent.map(async (content, index) => { | ||
let sourceName = map.sources[index]; // If sourceName starts with `..` it is outside rootDir, in this case we likely cannot access this file from the browser or packaged node_module | ||
// Because of this we have to include the sourceContent to ensure you can always see the sourcecontent for each mapping. | ||
if (!content && (inlineSources || sourceName.startsWith('..'))) { | ||
try { | ||
return await fs.readFile(_path.default.resolve(root, sourceName), 'utf-8'); | ||
} catch (e) {} | ||
} | ||
return content; | ||
})); | ||
} | ||
if (format === "inline" || format === "string") { | ||
if (format === 'inline' || format === 'string') { | ||
let stringifiedMap = JSON.stringify(resultMap); | ||
if (format === "inline") { | ||
if (format === 'inline') { | ||
return generateInlineMap(stringifiedMap); | ||
@@ -75,0 +85,0 @@ } |
@@ -65,7 +65,22 @@ "use strict"; | ||
addRawMappings(mappings, sources, names, lineOffset = 0, columnOffset = 0) { | ||
addRawMappings(map, lineOffset = 0, columnOffset = 0) { | ||
let { | ||
sourcesContent, | ||
sources = [], | ||
mappings, | ||
names = [] | ||
} = map; | ||
if (!sourcesContent) { | ||
sourcesContent = sources.map(() => ''); | ||
} else { | ||
sourcesContent = sourcesContent.map(content => content ? content : ''); | ||
} | ||
let sourcesVector = arrayToEmbind(Module.VectorString, sources); | ||
let namesVector = arrayToEmbind(Module.VectorString, names); | ||
this.sourceMapInstance.addRawMappings(mappings, sourcesVector, namesVector, lineOffset, columnOffset); | ||
let sourcesContentVector = arrayToEmbind(Module.VectorString, sourcesContent); | ||
this.sourceMapInstance.addRawMappings(mappings, sourcesVector, sourcesContentVector, namesVector, lineOffset, columnOffset); | ||
sourcesVector.delete(); | ||
sourcesContentVector.delete(); | ||
namesVector.delete(); | ||
@@ -92,2 +107,3 @@ return this; | ||
sources: arrayFromEmbind(this.sourceMapInstance.getSources()), | ||
sourcesContent: arrayFromEmbind(this.sourceMapInstance.getSourcesContent()), | ||
names: arrayFromEmbind(this.sourceMapInstance.getNames()) | ||
@@ -101,6 +117,8 @@ }; | ||
sources: arrayFromEmbind(this.sourceMapInstance.getSources()), | ||
sourcesContent: arrayFromEmbind(this.sourceMapInstance.getSourcesContent()), | ||
names: arrayFromEmbind(this.sourceMapInstance.getNames()) | ||
}; | ||
} | ||
} // $FlowFixMe don't know how we'll handle this yet... | ||
toBuffer() { | ||
@@ -107,0 +125,0 @@ return new Uint8Array(this.sourceMapInstance.toBuffer()); |
{ | ||
"name": "@parcel/source-map", | ||
"version": "2.0.0-alpha.4.11", | ||
"version": "2.0.0-alpha.4.12", | ||
"main": "./dist/node.js", | ||
@@ -14,3 +14,3 @@ "browser": "./dist/wasm-browser.js", | ||
"benchmark:wasm": "cross-env BACKEND=wasm node ./bench/run", | ||
"compile-wasm": "make -j4", | ||
"compile-wasm": "make clean && make -j4", | ||
"transpile": "babel ./src/*.js --out-dir ./dist && flow-copy-source -v src dist", | ||
@@ -24,4 +24,15 @@ "prebuild": "prebuildify -t 10.20.1 --napi --strip --tag-libc", | ||
"typecheck": "flow", | ||
"format": "prettier --write \"./**/*.{js,md,mdx}\"", | ||
"compile-schema": "./flatc --cpp -o ./src ./src/sourcemap-schema.fbs" | ||
}, | ||
"husky": { | ||
"hooks": { | ||
"pre-commit": "lint-staged" | ||
} | ||
}, | ||
"lint-staged": { | ||
"*.{js,json,md}": [ | ||
"prettier --write" | ||
] | ||
}, | ||
"files": [ | ||
@@ -57,8 +68,11 @@ "binding.gyp", | ||
"flow-copy-source": "^2.0.9", | ||
"fs-extra": "^9.0.1", | ||
"husky": "^4.2.5", | ||
"lint-staged": "^10.2.9", | ||
"mocha": "^7.1.2", | ||
"prebuildify": "^3.0.4", | ||
"prettier": "^2.0.5", | ||
"source-map": "^0.7.3", | ||
"tiny-benchy": "^1.0.0", | ||
"prettier": "^2.0.5" | ||
"tiny-benchy": "^1.0.0" | ||
} | ||
} |
@@ -5,2 +5,4 @@ # Parcel's source-map library | ||
To learn more about how sourcemaps are formatted and how they work, you can have a look at the [SourceMap Specification](https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k). | ||
## How to use this library? | ||
@@ -18,5 +20,5 @@ | ||
To create a sourcemap from an existing sourcemap you have to ensure it is a JS Object first by asking for the object version from whichever transpiler you're running or by parsing the serialised map using `JSON.parse`. | ||
To create a sourcemap from an existing sourcemap you have to ensure it is a JS Object first by asking for the object version from whichever transpiler you're running or by parsing the serialised map using `JSON.parse` or any other JSON parser. | ||
After this you can call the function `addRawMappings(mappings, sources, names, lineOffset, columnOffset)` this function takes in the parameters `mappings`, `sources`, `names`, `lineOffset` and `columnOffset`. These correspond to the mappings, sources and names fields in the sourcemap object. The line and column offset are optional parameters used for offsetting the generated line and column. (this can be used when post-processing or wrapping the code linked to the sourcemap, in Parcel this is used when combining maps). | ||
After this you can call the function `addRawMappings(map, lineOffset, columnOffset)` this function takes in the parameters `map`, `lineOffset` and `columnOffset`. The map argument corresponds to the sourcemap object. The line and column offset are optional parameters used for offsetting the generated line and column. (this can be used when post-processing or wrapping the code linked to the sourcemap, in Parcel this is used when combining maps). | ||
@@ -37,3 +39,3 @@ Example: | ||
let sourcemap = new SourceMap(); | ||
sourcemap.addRawMappings(RAW_SOURCEMAP.mappings, RAW_SOURCEMAP.sources, RAW_SOURCEMAP.names); | ||
sourcemap.addRawMappings(RAW_SOURCEMAP); | ||
@@ -40,0 +42,0 @@ // This function removes the underlying references in the native code |
// @flow | ||
import type { | ||
ParsedMap, | ||
VLQMap, | ||
SourceMapStringifyOptions, | ||
IndexedMapping, | ||
} from "./types"; | ||
import path from "path"; | ||
import SourceMap from "./SourceMap"; | ||
import type { ParsedMap, VLQMap, SourceMapStringifyOptions, IndexedMapping } from './types'; | ||
import path from 'path'; | ||
import SourceMap from './SourceMap'; | ||
const bindings = require("node-gyp-build")(path.join(__dirname, "..")); | ||
const bindings = require('node-gyp-build')(path.join(__dirname, '..')); | ||
@@ -31,7 +26,3 @@ export default class NodeSourceMap extends SourceMap { | ||
static generateEmptyMap( | ||
sourceName: string, | ||
sourceContent: string, | ||
lineOffset: number = 0 | ||
): NodeSourceMap { | ||
static generateEmptyMap(sourceName: string, sourceContent: string, lineOffset: number = 0): NodeSourceMap { | ||
let map = new NodeSourceMap(); | ||
@@ -38,0 +29,0 @@ map.addEmptyMap(sourceName, sourceContent, lineOffset); |
// @flow | ||
import type { | ||
ParsedMap, | ||
VLQMap, | ||
SourceMapStringifyOptions, | ||
IndexedMapping, | ||
} from "./types"; | ||
import type { ParsedMap, VLQMap, SourceMapStringifyOptions, IndexedMapping } from './types'; | ||
import path from "path"; | ||
import { generateInlineMap, partialVlqMapToSourceMap } from "./utils"; | ||
import path from 'path'; | ||
import { generateInlineMap, partialVlqMapToSourceMap } from './utils'; | ||
export default class SourceMap { | ||
/** | ||
* @private | ||
*/ | ||
sourceMapInstance: any; | ||
@@ -22,10 +20,4 @@ | ||
*/ | ||
static generateEmptyMap( | ||
sourceName: string, | ||
sourceContent: string, | ||
lineOffset: number = 0 | ||
): SourceMap { | ||
throw new Error( | ||
"SourceMap.generateEmptyMap() must be implemented when extending SourceMap" | ||
); | ||
static generateEmptyMap(sourceName: string, sourceContent: string, lineOffset: number = 0): SourceMap { | ||
throw new Error('SourceMap.generateEmptyMap() must be implemented when extending SourceMap'); | ||
} | ||
@@ -40,7 +32,3 @@ | ||
*/ | ||
addEmptyMap( | ||
sourceName: string, | ||
sourceContent: string, | ||
lineOffset: number = 0 | ||
): SourceMap { | ||
addEmptyMap(sourceName: string, sourceContent: string, lineOffset: number = 0): SourceMap { | ||
this.sourceMapInstance.addEmptyMap(sourceName, sourceContent, lineOffset); | ||
@@ -52,19 +40,14 @@ return this; | ||
* Appends raw VLQ mappings to the sourcemaps | ||
* | ||
* @param mappings a string containing the Base64 encoded VLQ Mappings | ||
* @param sources an array of source filepaths used in the raw sourcemap | ||
* @param names an array of the names used in the raw sourcemap | ||
* @param lineOffset an offset that gets added to the sourceLine index of each mapping | ||
* @param columnOffset an offset that gets added to the sourceColumn index of each mapping | ||
*/ | ||
addRawMappings( | ||
mappings: string, | ||
sources: Array<string>, | ||
names: Array<string>, | ||
lineOffset: number = 0, | ||
columnOffset: number = 0 | ||
): SourceMap { | ||
addRawMappings(map: VLQMap, lineOffset: number = 0, columnOffset: number = 0): SourceMap { | ||
let { sourcesContent, sources = [], mappings, names = [] } = map; | ||
if (!sourcesContent) { | ||
sourcesContent = sources.map(() => ''); | ||
} else { | ||
sourcesContent = sourcesContent.map((content) => (content ? content : '')); | ||
} | ||
this.sourceMapInstance.addRawMappings( | ||
mappings, | ||
sources, | ||
sourcesContent.map((content) => (content ? content : '')), | ||
names, | ||
@@ -85,7 +68,3 @@ lineOffset, | ||
*/ | ||
addBufferMappings( | ||
buffer: Buffer, | ||
lineOffset: number = 0, | ||
columnOffset: number = 0 | ||
): SourceMap { | ||
addBufferMappings(buffer: Buffer, lineOffset: number = 0, columnOffset: number = 0): SourceMap { | ||
this.sourceMapInstance.addBufferMappings(buffer, lineOffset, columnOffset); | ||
@@ -103,12 +82,8 @@ return this; | ||
*/ | ||
addIndexedMapping( | ||
mapping: IndexedMapping<string>, | ||
lineOffset?: number = 0, | ||
columnOffset?: number = 0 | ||
): void { | ||
addIndexedMapping(mapping: IndexedMapping<string>, lineOffset?: number = 0, columnOffset?: number = 0): void { | ||
let hasValidOriginal = | ||
mapping.original && | ||
typeof mapping.original.line === "number" && | ||
typeof mapping.original.line === 'number' && | ||
!isNaN(mapping.original.line) && | ||
typeof mapping.original.column === "number" && | ||
typeof mapping.original.column === 'number' && | ||
!isNaN(mapping.original.column); | ||
@@ -123,4 +98,4 @@ | ||
hasValidOriginal ? mapping.original.column : -1, | ||
mapping.source || "", | ||
mapping.name || "" | ||
mapping.source || '', | ||
mapping.name || '' | ||
); | ||
@@ -210,2 +185,22 @@ } | ||
/** | ||
* Set the sourceContent for a certain file | ||
* this is optional and is only recommended for files that we cannot read in at the end when we serialise the sourcemap | ||
* | ||
* @param {string} sourceName the path of the sourceFile | ||
* @param {string} sourceContent the content of the sourceFile | ||
*/ | ||
setSourceContent(sourceName: string, sourceContent: string): void { | ||
return this.sourceMapInstance.setSourceContent(sourceName, sourceContent); | ||
} | ||
/** | ||
* Get the content of a source file if it is inlined as part of the source-map | ||
* | ||
* @param {string} sourceName | ||
*/ | ||
getSourceContent(sourceName: string): string { | ||
return this.sourceMapInstance.getSourceContent(sourceName); | ||
} | ||
/** | ||
* Get the index in the names array for a certain name | ||
@@ -236,5 +231,3 @@ * | ||
*/ | ||
indexedMappingToStringMapping( | ||
mapping: ?IndexedMapping<number> | ||
): ?IndexedMapping<string> { | ||
indexedMappingToStringMapping(mapping: ?IndexedMapping<number>): ?IndexedMapping<string> { | ||
if (!mapping) return mapping; | ||
@@ -287,5 +280,3 @@ | ||
findClosestMapping(line: number, column: number): ?IndexedMapping<string> { | ||
throw new Error( | ||
"SourceMap.findClosestMapping() must be implemented when extending SourceMap" | ||
); | ||
throw new Error('SourceMap.findClosestMapping() must be implemented when extending SourceMap'); | ||
} | ||
@@ -297,5 +288,3 @@ | ||
toBuffer(): Buffer { | ||
throw new Error( | ||
"SourceMap.toBuffer() must be implemented when extending SourceMap" | ||
); | ||
throw new Error('SourceMap.toBuffer() must be implemented when extending SourceMap'); | ||
} | ||
@@ -314,5 +303,3 @@ | ||
delete() { | ||
throw new Error( | ||
"SourceMap.delete() must be implemented when extending SourceMap" | ||
); | ||
throw new Error('SourceMap.delete() must be implemented when extending SourceMap'); | ||
} | ||
@@ -325,7 +312,5 @@ | ||
*/ | ||
async stringify( | ||
options: SourceMapStringifyOptions | ||
): Promise<string | VLQMap> { | ||
async stringify(options: SourceMapStringifyOptions): Promise<string | VLQMap> { | ||
return partialVlqMapToSourceMap(this.toVLQ(), options); | ||
} | ||
} |
@@ -19,2 +19,3 @@ // @flow | ||
mappings: Array<IndexedMapping<number>>, | ||
sourcesContent: Array<string | null>, | ||
|}; | ||
@@ -24,2 +25,3 @@ | ||
sources: Array<string>, | ||
sourcesContent?: Array<string | null>, | ||
names: Array<string>, | ||
@@ -30,3 +32,2 @@ mappings: string, | ||
sourceRoot?: string, | ||
sourcesContent?: Array<any>, | ||
... | ||
@@ -40,5 +41,5 @@ }; | ||
inlineSources?: boolean, | ||
fs?: any, | ||
format?: "inline" | "string" | "object", | ||
fs?: { readFile(path: string, encoding: string): Promise<string>, ... }, | ||
format?: 'inline' | 'string' | 'object', | ||
... | ||
}; |
// @flow | ||
import type { VLQMap, SourceMapStringifyOptions } from "./types"; | ||
import type { VLQMap, SourceMapStringifyOptions } from './types'; | ||
import path from "path"; | ||
import path from 'path'; | ||
export function generateInlineMap(map: string): string { | ||
return `data:application/json;charset=utf-8;base64,${Buffer.from( | ||
map | ||
).toString("base64")}`; | ||
return `data:application/json;charset=utf-8;base64,${Buffer.from(map).toString('base64')}`; | ||
} | ||
function normalisePath(filepath: string): string { | ||
return filepath.replace(/\\/g, "/"); | ||
return filepath.replace(/\\/g, '/'); | ||
} | ||
@@ -21,3 +19,3 @@ | ||
// Make root paths relative to the rootDir | ||
if (filepath[0] === "/") { | ||
if (filepath[0] === '/') { | ||
filepath = normalisePath(path.relative(rootDir, filepath)); | ||
@@ -27,3 +25,3 @@ } | ||
// Prefix relative paths with ./ as it makes it more clear and probably prevents issues | ||
if (filepath[0] !== ".") { | ||
if (filepath[0] !== '.') { | ||
filepath = `./${filepath}`; | ||
@@ -37,14 +35,8 @@ } | ||
map: VLQMap, | ||
{ | ||
fs, | ||
file, | ||
sourceRoot, | ||
inlineSources, | ||
rootDir, | ||
format = "string", | ||
}: SourceMapStringifyOptions | ||
{ fs, file, sourceRoot, inlineSources, rootDir, format = 'string' }: SourceMapStringifyOptions | ||
): Promise<VLQMap | string> { | ||
let root = normalisePath(rootDir || "/"); | ||
let root = normalisePath(rootDir || '/'); | ||
let resultMap = { | ||
...map, | ||
sourcesContent: map.sourcesContent ? map.sourcesContent.map((content) => (content ? content : null)) : [], | ||
version: 3, | ||
@@ -59,10 +51,19 @@ file, | ||
if (inlineSources && fs) { | ||
if (resultMap.sourcesContent.length < resultMap.sources.length) { | ||
resultMap.sourcesContent.push(...new Array(resultMap.sources.length - resultMap.sourcesContent.length).fill(null)); | ||
} | ||
if (fs) { | ||
resultMap.sourcesContent = await Promise.all( | ||
resultMap.sources.map(async (sourceName) => { | ||
try { | ||
return await fs.readFile(path.resolve(root, sourceName), "utf-8"); | ||
} catch (e) { | ||
return null; | ||
resultMap.sourcesContent.map(async (content, index): Promise<string | null> => { | ||
let sourceName = map.sources[index]; | ||
// If sourceName starts with `..` it is outside rootDir, in this case we likely cannot access this file from the browser or packaged node_module | ||
// Because of this we have to include the sourceContent to ensure you can always see the sourcecontent for each mapping. | ||
if (!content && (inlineSources || sourceName.startsWith('..'))) { | ||
try { | ||
return await fs.readFile(path.resolve(root, sourceName), 'utf-8'); | ||
} catch (e) {} | ||
} | ||
return content; | ||
}) | ||
@@ -72,5 +73,5 @@ ); | ||
if (format === "inline" || format === "string") { | ||
if (format === 'inline' || format === 'string') { | ||
let stringifiedMap = JSON.stringify(resultMap); | ||
if (format === "inline") { | ||
if (format === 'inline') { | ||
return generateInlineMap(stringifiedMap); | ||
@@ -77,0 +78,0 @@ } |
@@ -1,5 +0,5 @@ | ||
import SourceMap, { init as _init } from "./wasm.js"; | ||
import RawModule from "../wasm-browser/source-map.js"; | ||
import SourceMap, { init as _init } from './wasm.js'; | ||
import RawModule from '../wasm-browser/source-map.js'; | ||
export default SourceMap; | ||
export const init = _init(RawModule); |
@@ -1,5 +0,5 @@ | ||
import SourceMap, { init as _init } from "./wasm.js"; | ||
import RawModule from "../wasm-node/source-map.js"; | ||
import SourceMap, { init as _init } from './wasm.js'; | ||
import RawModule from '../wasm-node/source-map.js'; | ||
export default SourceMap; | ||
export const init = _init(RawModule); |
// @flow | ||
import type { | ||
ParsedMap, | ||
VLQMap, | ||
SourceMapStringifyOptions, | ||
IndexedMapping, | ||
} from "./types"; | ||
import path from "path"; | ||
import SourceMap from "./SourceMap"; | ||
import type { ParsedMap, VLQMap, SourceMapStringifyOptions, IndexedMapping } from './types'; | ||
import path from 'path'; | ||
import SourceMap from './SourceMap'; | ||
@@ -49,7 +44,3 @@ let Module; | ||
static generateEmptyMap( | ||
sourceName: string, | ||
sourceContent: string, | ||
lineOffset: number = 0 | ||
): WasmSourceMap { | ||
static generateEmptyMap(sourceName: string, sourceContent: string, lineOffset: number = 0): WasmSourceMap { | ||
let map = new WasmSourceMap(); | ||
@@ -61,13 +52,19 @@ map.addEmptyMap(sourceName, sourceContent, lineOffset); | ||
addRawMappings( | ||
mappings: string, | ||
sources: Array<string>, | ||
names: Array<string>, | ||
map: VLQMap, | ||
lineOffset: number = 0, | ||
columnOffset: number = 0 | ||
) { | ||
let { sourcesContent, sources = [], mappings, names = [] } = map; | ||
if (!sourcesContent) { | ||
sourcesContent = sources.map(() => ''); | ||
} else { | ||
sourcesContent = sourcesContent.map((content) => (content ? content : '')); | ||
} | ||
let sourcesVector = arrayToEmbind(Module.VectorString, sources); | ||
let namesVector = arrayToEmbind(Module.VectorString, names); | ||
let sourcesContentVector = arrayToEmbind(Module.VectorString, sourcesContent); | ||
this.sourceMapInstance.addRawMappings( | ||
mappings, | ||
sourcesVector, | ||
sourcesContentVector, | ||
namesVector, | ||
@@ -77,6 +74,5 @@ lineOffset, | ||
); | ||
sourcesVector.delete(); | ||
sourcesContentVector.delete(); | ||
namesVector.delete(); | ||
return this; | ||
@@ -96,6 +92,3 @@ } | ||
getMap(): ParsedMap { | ||
let mappings = arrayFromEmbind( | ||
this.sourceMapInstance.getMappings(), | ||
patchMapping | ||
); | ||
let mappings = arrayFromEmbind(this.sourceMapInstance.getMappings(), patchMapping); | ||
@@ -105,2 +98,3 @@ return { | ||
sources: arrayFromEmbind(this.sourceMapInstance.getSources()), | ||
sourcesContent: arrayFromEmbind(this.sourceMapInstance.getSourcesContent()), | ||
names: arrayFromEmbind(this.sourceMapInstance.getNames()), | ||
@@ -114,2 +108,3 @@ }; | ||
sources: arrayFromEmbind(this.sourceMapInstance.getSources()), | ||
sourcesContent: arrayFromEmbind(this.sourceMapInstance.getSourcesContent()), | ||
names: arrayFromEmbind(this.sourceMapInstance.getNames()), | ||
@@ -119,2 +114,3 @@ }; | ||
// $FlowFixMe don't know how we'll handle this yet... | ||
toBuffer(): Uint8Array { | ||
@@ -121,0 +117,0 @@ return new Uint8Array(this.sourceMapInstance.toBuffer()); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1541387
1565
128
15