first commit
This commit is contained in:
8
node_modules/sorcery/src/utils/atob.js
generated
vendored
Normal file
8
node_modules/sorcery/src/utils/atob.js
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Decodes a base64 string
|
||||
* @param {string} base64 - the string to decode
|
||||
* @returns {string}
|
||||
*/
|
||||
export default function atob ( base64 ) {
|
||||
return new Buffer( base64, 'base64' ).toString( 'utf8' );
|
||||
}
|
8
node_modules/sorcery/src/utils/btoa.js
generated
vendored
Normal file
8
node_modules/sorcery/src/utils/btoa.js
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Encodes a string as base64
|
||||
* @param {string} str - the string to encode
|
||||
* @returns {string}
|
||||
*/
|
||||
export default function btoa ( str ) {
|
||||
return new Buffer( str ).toString( 'base64' );
|
||||
}
|
21
node_modules/sorcery/src/utils/getMap.js
generated
vendored
Normal file
21
node_modules/sorcery/src/utils/getMap.js
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
import { Promise } from 'sander';
|
||||
import getMapFromUrl from './getMapFromUrl.js';
|
||||
import getSourceMappingUrl from './getSourceMappingUrl.js';
|
||||
|
||||
export default function getMap ( node, sourceMapByPath, sync ) {
|
||||
if ( node.file in sourceMapByPath ) {
|
||||
const map = sourceMapByPath[ node.file ];
|
||||
return sync ? map : Promise.resolve( map );
|
||||
}
|
||||
|
||||
else {
|
||||
const url = getSourceMappingUrl( node.content );
|
||||
|
||||
if ( !url ) {
|
||||
node.isOriginalSource = true;
|
||||
return sync ? null : Promise.resolve( null );
|
||||
}
|
||||
|
||||
return getMapFromUrl( url, node.file, sync );
|
||||
}
|
||||
}
|
44
node_modules/sorcery/src/utils/getMapFromUrl.js
generated
vendored
Normal file
44
node_modules/sorcery/src/utils/getMapFromUrl.js
generated
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
import { dirname, resolve } from 'path';
|
||||
import { readFile, readFileSync, Promise } from 'sander';
|
||||
import atob from './atob.js';
|
||||
import SOURCEMAPPING_URL from './sourceMappingURL.js';
|
||||
|
||||
function parseJSON ( json, url ) {
|
||||
try {
|
||||
return JSON.parse( json );
|
||||
} catch ( err ) {
|
||||
throw new Error( `Could not parse sourcemap (${url}): ${err.message}` );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns a sourceMappingURL into a sourcemap
|
||||
* @param {string} url - the sourceMappingURL. Can be a
|
||||
base64-encoded data URI
|
||||
* @param {string} base - the URL against which relative URLS
|
||||
should be resolved
|
||||
* @param {boolean} sync - if `true`, return a promise, otherwise
|
||||
return the sourcemap
|
||||
* @returns {object} - a version 3 sourcemap
|
||||
*/
|
||||
export default function getMapFromUrl ( url, base, sync ) {
|
||||
if ( /^data:/.test( url ) ) { // TODO beef this up
|
||||
const match = /base64,(.+)$/.exec( url );
|
||||
|
||||
if ( !match ) {
|
||||
throw new Error( `${SOURCEMAPPING_URL} is not base64-encoded` );
|
||||
}
|
||||
|
||||
const json = atob( match[1] );
|
||||
const map = parseJSON( json, `data URI in ${base}` );
|
||||
return sync ? map : Promise.resolve( map );
|
||||
}
|
||||
|
||||
url = resolve( dirname( base ), decodeURI( url ) );
|
||||
|
||||
if ( sync ) {
|
||||
return parseJSON( readFileSync( url, { encoding: 'utf-8' }), url );
|
||||
} else {
|
||||
return readFile( url, { encoding: 'utf-8' }).then( json => parseJSON( json, url ) );
|
||||
}
|
||||
}
|
25
node_modules/sorcery/src/utils/getSourceMappingUrl.js
generated
vendored
Normal file
25
node_modules/sorcery/src/utils/getSourceMappingUrl.js
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
import SOURCEMAPPING_URL from './sourceMappingURL.js';
|
||||
|
||||
export default function getSourceMappingUrl ( str ) {
|
||||
var index, substring, url, match;
|
||||
|
||||
// assume we want the last occurence
|
||||
index = str.lastIndexOf( `${SOURCEMAPPING_URL}=` );
|
||||
|
||||
if ( index === -1 ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
substring = str.substring( index + 17 );
|
||||
match = /^[^\r\n]+/.exec( substring );
|
||||
|
||||
url = match ? match[0] : null;
|
||||
|
||||
// possibly a better way to do this, but we don't want to exclude whitespace
|
||||
// from the sourceMappingURL because it might not have been correctly encoded
|
||||
if ( url && url.slice( -2 ) === '*/' ) {
|
||||
url = url.slice( 0, -2 ).trim();
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
5
node_modules/sorcery/src/utils/slash.js
generated
vendored
Normal file
5
node_modules/sorcery/src/utils/slash.js
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
export default function slash ( path ) {
|
||||
return typeof path === 'string' ?
|
||||
path.replace( /\\/g, '/' ) :
|
||||
path;
|
||||
}
|
6
node_modules/sorcery/src/utils/sourceMappingURL.js
generated
vendored
Normal file
6
node_modules/sorcery/src/utils/sourceMappingURL.js
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
// this looks ridiculous, but it prevents sourcemap tooling from mistaking
|
||||
// this for an actual sourceMappingURL
|
||||
let SOURCEMAPPING_URL = 'sourceMa';
|
||||
SOURCEMAPPING_URL += 'ppingURL';
|
||||
|
||||
export default SOURCEMAPPING_URL;
|
Reference in New Issue
Block a user