Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@parcel/source-map

Package Overview
Dependencies
Maintainers
1
Versions
90
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@parcel/source-map - npm Package Compare versions

Comparing version 2.0.0-alpha.4.13 to 2.0.0-alpha.4.14

35

dist/node.js

@@ -12,2 +12,4 @@ "use strict";

var _utils = require("./utils");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -18,7 +20,25 @@

class NodeSourceMap extends _SourceMap.default {
constructor() {
super();
constructor(projectRoot = '/') {
super(projectRoot);
this.sourceMapInstance = new bindings.SourceMap();
}
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.map(source => source ? (0, _utils.relatifyPath)(source, this.projectRoot) : ''), sourcesContent.map(content => content ? content : ''), names, lineOffset, columnOffset);
return this;
}
toBuffer() {

@@ -36,5 +56,10 @@ return this.sourceMapInstance.toBuffer();

static generateEmptyMap(sourceName, sourceContent, lineOffset = 0) {
let map = new NodeSourceMap();
map.addEmptyMap(sourceName, sourceContent, lineOffset);
static generateEmptyMap({
projectRoot,
sourceName,
sourceContent,
lineOffset = 0
}) {
let map = new NodeSourceMap(projectRoot);
map.addEmptyMap((0, _utils.relatifyPath)(sourceName, projectRoot), sourceContent, lineOffset);
return map;

@@ -41,0 +66,0 @@ }

57

dist/SourceMap.js

@@ -20,2 +20,14 @@ "use strict";

/**
* @private
*/
/**
* Construct a SourceMap instance
*
* @param projectRoot root directory of the project, this is to ensure all source paths are relative to this path
*/
constructor(projectRoot = '/') {
this.projectRoot = (0, _utils.normalizePath)(projectRoot);
}
/**
* Generates an empty map from the provided fileName and sourceContent

@@ -27,3 +39,10 @@ *

*/
static generateEmptyMap(sourceName, sourceContent, lineOffset = 0) {
static generateEmptyMap({
projectRoot,
sourceName,
sourceContent,
lineOffset = 0
}) {
throw new Error('SourceMap.generateEmptyMap() must be implemented when extending SourceMap');

@@ -50,17 +69,3 @@ }

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;
throw new Error('SourceMap.addRawMappings() must be implemented when extending SourceMap');
}

@@ -95,3 +100,3 @@ /**

hasValidOriginal ? mapping.original.line - 1 : -1, // $FlowFixMe
hasValidOriginal ? mapping.original.column : -1, mapping.source || '', mapping.name || '');
hasValidOriginal ? mapping.original.column : -1, mapping.source ? (0, _utils.relatifyPath)(mapping.source, this.projectRoot) : '', mapping.name || '');
}

@@ -149,3 +154,3 @@ /**

addSource(source) {
return this.sourceMapInstance.addSource(source);
return this.sourceMapInstance.addSource((0, _utils.relatifyPath)(source, this.projectRoot));
}

@@ -171,3 +176,3 @@ /**

getSourceIndex(source) {
return this.sourceMapInstance.getSourceIndex(source);
return this.sourceMapInstance.getSourceIndex((0, _utils.relatifyPath)(source, this.projectRoot));
}

@@ -188,4 +193,4 @@ /**

*
* @param {string} sourceName the path of the sourceFile
* @param {string} sourceContent the content of the sourceFile
* @param sourceName the path of the sourceFile
* @param sourceContent the content of the sourceFile
*/

@@ -195,3 +200,3 @@

setSourceContent(sourceName, sourceContent) {
return this.sourceMapInstance.setSourceContent(sourceName, sourceContent);
return this.sourceMapInstance.setSourceContent((0, _utils.relatifyPath)(sourceName, this.projectRoot), sourceContent);
}

@@ -201,3 +206,3 @@ /**

*
* @param {string} sourceName
* @param sourceName filename
*/

@@ -207,3 +212,3 @@

getSourceContent(sourceName) {
return this.sourceMapInstance.getSourceContent(sourceName);
return this.sourceMapInstance.getSourceContent((0, _utils.relatifyPath)(sourceName, this.projectRoot));
}

@@ -325,3 +330,5 @@ /**

async stringify(options) {
return (0, _utils.partialVlqMapToSourceMap)(this.toVLQ(), options);
return (0, _utils.partialVlqMapToSourceMap)(this.toVLQ(), { ...options,
rootDir: this.projectRoot || options.rootDir
});
}

@@ -328,0 +335,0 @@

@@ -7,2 +7,4 @@ "use strict";

exports.generateInlineMap = generateInlineMap;
exports.normalizePath = normalizePath;
exports.relatifyPath = relatifyPath;
exports.partialVlqMapToSourceMap = partialVlqMapToSourceMap;

@@ -18,4 +20,10 @@

function normalisePath(filepath) {
return filepath.replace(/\\/g, '/');
function normalizePath(filepath) {
filepath = filepath.replace(/\\/g, '/'); // Prefix relative paths with ./ as it makes it more clear and probably prevents issues
if (filepath.length > 0 && filepath[0] !== '.' && !_path.default.isAbsolute(filepath)) {
filepath = `./${filepath}`;
}
return filepath;
}

@@ -25,11 +33,6 @@

// Sourcemaps are made for web, so replace backslashes with regular slashes
filepath = normalisePath(filepath); // Make root paths relative to the rootDir
filepath = normalizePath(filepath); // Make root paths relative to the rootDir
if (filepath[0] === '/') {
filepath = normalisePath(_path.default.relative(rootDir, filepath));
} // Prefix relative paths with ./ as it makes it more clear and probably prevents issues
if (filepath[0] !== '.') {
filepath = `./${filepath}`;
filepath = normalizePath(_path.default.relative(rootDir, filepath));
}

@@ -48,3 +51,2 @@

}) {
let root = normalisePath(rootDir || '/');
let resultMap = { ...map,

@@ -56,5 +58,2 @@ sourcesContent: map.sourcesContent ? map.sourcesContent.map(content => content ? content : null) : [],

};
resultMap.sources = resultMap.sources.map(sourceFilePath => {
return relatifyPath(sourceFilePath, root);
});

@@ -72,3 +71,3 @@ if (resultMap.sourcesContent.length < resultMap.sources.length) {

try {
return await fs.readFile(_path.default.resolve(root, sourceName), 'utf-8');
return await fs.readFile(_path.default.resolve(rootDir || '/', sourceName), 'utf-8');
} catch (e) {}

@@ -75,0 +74,0 @@ }

@@ -13,2 +13,4 @@ "use strict";

var _utils = require("./utils");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -55,10 +57,15 @@

class WasmSourceMap extends _SourceMap.default {
constructor() {
super();
constructor(projectRoot = '/') {
super(projectRoot);
this.sourceMapInstance = new Module.SourceMap();
}
static generateEmptyMap(sourceName, sourceContent, lineOffset = 0) {
let map = new WasmSourceMap();
map.addEmptyMap(sourceName, sourceContent, lineOffset);
static generateEmptyMap({
projectRoot,
sourceName,
sourceContent,
lineOffset = 0
}) {
let map = new WasmSourceMap(projectRoot);
map.addEmptyMap((0, _utils.relatifyPath)(sourceName, projectRoot), sourceContent, lineOffset);
return map;

@@ -74,2 +81,3 @@ }

} = map;
sources = sources.map(source => source ? (0, _utils.relatifyPath)(source, this.projectRoot) : '');

@@ -76,0 +84,0 @@ if (!sourcesContent) {

{
"name": "@parcel/source-map",
"version": "2.0.0-alpha.4.13",
"version": "2.0.0-alpha.4.14",
"main": "./dist/node.js",

@@ -19,2 +19,3 @@ "browser": "./dist/wasm-browser.js",

"rebuild": "rm -rf build && yarn build:dev",
"rebuild-all": "yarn transpile && yarn compile-wasm && yarn rebuild",
"install": "node-gyp-build",

@@ -56,3 +57,3 @@ "prepublish": "npm run transpile",

"dependencies": {
"node-addon-api": "^2.0.0",
"node-addon-api": "^3.0.0",
"node-gyp-build": "^4.2.2"

@@ -72,3 +73,3 @@ },

"mocha": "^7.1.2",
"prebuildify": "^3.0.4",
"prebuildify": "^4.0.0",
"prettier": "^2.0.5",

@@ -75,0 +76,0 @@ "source-map": "^0.7.3",

// @flow
import type { ParsedMap, VLQMap, SourceMapStringifyOptions, IndexedMapping } from './types';
import type { ParsedMap, VLQMap, SourceMapStringifyOptions, IndexedMapping, GenerateEmptyMapOptions } from './types';
import path from 'path';
import SourceMap from './SourceMap';
import { relatifyPath } from './utils';

@@ -9,7 +10,25 @@ const bindings = require('node-gyp-build')(path.join(__dirname, '..'));

export default class NodeSourceMap extends SourceMap {
constructor() {
super();
constructor(projectRoot: string = '/') {
super(projectRoot);
this.sourceMapInstance = new bindings.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.map((source) => (source ? relatifyPath(source, this.projectRoot) : '')),
sourcesContent.map((content) => (content ? content : '')),
names,
lineOffset,
columnOffset
);
return this;
}
toBuffer(): Buffer {

@@ -27,5 +46,10 @@ return this.sourceMapInstance.toBuffer();

static generateEmptyMap(sourceName: string, sourceContent: string, lineOffset: number = 0): NodeSourceMap {
let map = new NodeSourceMap();
map.addEmptyMap(sourceName, sourceContent, lineOffset);
static generateEmptyMap({
projectRoot,
sourceName,
sourceContent,
lineOffset = 0,
}: GenerateEmptyMapOptions): NodeSourceMap {
let map = new NodeSourceMap(projectRoot);
map.addEmptyMap(relatifyPath(sourceName, projectRoot), sourceContent, lineOffset);
return map;

@@ -32,0 +56,0 @@ }

// @flow
import type { ParsedMap, VLQMap, SourceMapStringifyOptions, IndexedMapping } from './types';
import type { ParsedMap, VLQMap, SourceMapStringifyOptions, IndexedMapping, GenerateEmptyMapOptions } from './types';
import path from 'path';
import { generateInlineMap, partialVlqMapToSourceMap } from './utils';
import { generateInlineMap, partialVlqMapToSourceMap, relatifyPath, normalizePath } from './utils';

@@ -14,2 +14,16 @@ export default class SourceMap {

/**
* @private
*/
projectRoot: string;
/**
* Construct a SourceMap instance
*
* @param projectRoot root directory of the project, this is to ensure all source paths are relative to this path
*/
constructor(projectRoot: string = '/') {
this.projectRoot = normalizePath(projectRoot);
}
/**
* Generates an empty map from the provided fileName and sourceContent

@@ -21,3 +35,8 @@ *

*/
static generateEmptyMap(sourceName: string, sourceContent: string, lineOffset: number = 0): SourceMap {
static generateEmptyMap({
projectRoot,
sourceName,
sourceContent,
lineOffset = 0,
}: GenerateEmptyMapOptions): SourceMap {
throw new Error('SourceMap.generateEmptyMap() must be implemented when extending SourceMap');

@@ -42,17 +61,3 @@ }

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,
lineOffset,
columnOffset
);
return this;
throw new Error('SourceMap.addRawMappings() must be implemented when extending SourceMap');
}

@@ -96,3 +101,3 @@

hasValidOriginal ? mapping.original.column : -1,
mapping.source || '',
mapping.source ? relatifyPath(mapping.source, this.projectRoot) : '',
mapping.name || ''

@@ -151,3 +156,3 @@ );

addSource(source: string): number {
return this.sourceMapInstance.addSource(source);
return this.sourceMapInstance.addSource(relatifyPath(source, this.projectRoot));
}

@@ -171,3 +176,3 @@

getSourceIndex(source: string): number {
return this.sourceMapInstance.getSourceIndex(source);
return this.sourceMapInstance.getSourceIndex(relatifyPath(source, this.projectRoot));
}

@@ -188,7 +193,7 @@

*
* @param {string} sourceName the path of the sourceFile
* @param {string} sourceContent the content of the sourceFile
* @param sourceName the path of the sourceFile
* @param sourceContent the content of the sourceFile
*/
setSourceContent(sourceName: string, sourceContent: string): void {
return this.sourceMapInstance.setSourceContent(sourceName, sourceContent);
return this.sourceMapInstance.setSourceContent(relatifyPath(sourceName, this.projectRoot), sourceContent);
}

@@ -199,6 +204,6 @@

*
* @param {string} sourceName
* @param sourceName filename
*/
getSourceContent(sourceName: string): string {
return this.sourceMapInstance.getSourceContent(sourceName);
return this.sourceMapInstance.getSourceContent(relatifyPath(sourceName, this.projectRoot));
}

@@ -310,4 +315,7 @@

async stringify(options: SourceMapStringifyOptions): Promise<string | VLQMap> {
return partialVlqMapToSourceMap(this.toVLQ(), options);
return partialVlqMapToSourceMap(this.toVLQ(), {
...options,
rootDir: this.projectRoot || options.rootDir,
});
}
}

@@ -36,7 +36,18 @@ // @flow

sourceRoot?: string,
rootDir?: string,
inlineSources?: boolean,
fs?: { readFile(path: string, encoding: string): Promise<string>, ... },
format?: 'inline' | 'string' | 'object',
/**
* @private
*/
rootDir?: string,
...
};
export type GenerateEmptyMapOptions = {
projectRoot: string,
sourceName: string,
sourceContent: string,
lineOffset?: number,
...
};

@@ -10,20 +10,22 @@ // @flow

function normalisePath(filepath: string): string {
return filepath.replace(/\\/g, '/');
export function normalizePath(filepath: string): string {
filepath = filepath.replace(/\\/g, '/');
// Prefix relative paths with ./ as it makes it more clear and probably prevents issues
if (filepath.length > 0 && filepath[0] !== '.' && !path.isAbsolute(filepath)) {
filepath = `./${filepath}`;
}
return filepath;
}
function relatifyPath(filepath: string, rootDir: string): string {
export function relatifyPath(filepath: string, rootDir: string): string {
// Sourcemaps are made for web, so replace backslashes with regular slashes
filepath = normalisePath(filepath);
filepath = normalizePath(filepath);
// Make root paths relative to the rootDir
if (filepath[0] === '/') {
filepath = normalisePath(path.relative(rootDir, filepath));
filepath = normalizePath(path.relative(rootDir, filepath));
}
// Prefix relative paths with ./ as it makes it more clear and probably prevents issues
if (filepath[0] !== '.') {
filepath = `./${filepath}`;
}
return filepath;

@@ -36,3 +38,2 @@ }

): Promise<VLQMap | string> {
let root = normalisePath(rootDir || '/');
let resultMap = {

@@ -46,6 +47,2 @@ ...map,

resultMap.sources = resultMap.sources.map((sourceFilePath) => {
return relatifyPath(sourceFilePath, root);
});
if (resultMap.sourcesContent.length < resultMap.sources.length) {

@@ -63,3 +60,3 @@ resultMap.sourcesContent.push(...new Array(resultMap.sources.length - resultMap.sourcesContent.length).fill(null));

try {
return await fs.readFile(path.resolve(root, sourceName), 'utf-8');
return await fs.readFile(path.resolve(rootDir || '/', sourceName), 'utf-8');
} catch (e) {}

@@ -66,0 +63,0 @@ }

// @flow
import type { ParsedMap, VLQMap, SourceMapStringifyOptions, IndexedMapping } from './types';
import type { ParsedMap, VLQMap, SourceMapStringifyOptions, IndexedMapping, GenerateEmptyMapOptions } from './types';
import path from 'path';
import SourceMap from './SourceMap';
import {relatifyPath} from './utils';

@@ -39,10 +40,15 @@ let Module;

export default class WasmSourceMap extends SourceMap {
constructor() {
super();
constructor(projectRoot: string = '/') {
super(projectRoot);
this.sourceMapInstance = new Module.SourceMap();
}
static generateEmptyMap(sourceName: string, sourceContent: string, lineOffset: number = 0): WasmSourceMap {
let map = new WasmSourceMap();
map.addEmptyMap(sourceName, sourceContent, lineOffset);
static generateEmptyMap({
projectRoot,
sourceName,
sourceContent,
lineOffset = 0,
}: GenerateEmptyMapOptions): WasmSourceMap {
let map = new WasmSourceMap(projectRoot);
map.addEmptyMap(relatifyPath(sourceName, projectRoot), sourceContent, lineOffset);
return map;

@@ -57,2 +63,3 @@ }

let { sourcesContent, sources = [], mappings, names = [] } = map;
sources = sources.map((source) => (source ? relatifyPath(source, this.projectRoot) : ''));
if (!sourcesContent) {

@@ -59,0 +66,0 @@ sourcesContent = sources.map(() => '');

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

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