Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ function validate( opts, options ) {
if ( hasOwnProp( options, 'token' ) ) {
opts.token = options.token;
if ( !isString( opts.token ) ) {
return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'token', opts.token ) );
return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'token', opts.token ) );
}
}
if ( hasOwnProp( options, 'useragent' ) ) {
opts.useragent = options.useragent;
if ( !isString( opts.useragent ) ) {
return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'useragent', opts.useragent ) );
return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'useragent', opts.useragent ) );
}
}
return null;
Expand Down
147 changes: 77 additions & 70 deletions lib/node_modules/@stdlib/_tools/scripts/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

var debug = logger( 'scripts:transform' );
var pkg = ENV[ 'STDLIB_PKG' ];
var inputSourceMap = JSON.parse( readFileSync( ENV[ 'STDLIB_INPUT_SOURCE_MAP' ], 'utf8' ) );

Check warning on line 37 in lib/node_modules/@stdlib/_tools/scripts/transform.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected sync method: 'readFileSync'
var prefix = pkg2id( pkg );
var RE_INDENT = /(\r?\n) +/g;
var ERROR_NAMES = [
Expand All @@ -48,6 +48,83 @@
];


// FUNCTIONS //

/**
* Tests whether a variable declaration is for the `@stdlib/string-format` require.
*
* @private
* @param {Object} path - AST node path
* @returns {boolean} boolean indicating whether a variable declaration is for the `@stdlib/string-format` require
*/
function onStringFormat( path ) {
var node = path.node;
return (
node.init &&
node.init.type === 'CallExpression' &&
node.init.callee.name === 'require' &&
node.init.arguments[0].value === '@stdlib/string-format'
);
}

/**
* Returns false if the node index is equal to zero and true otherwise.
*
* @private
* @param {Object} path - AST node path
* @param {number} idx - node index
* @returns {boolean} boolean indicating whether to keep the node
*/
function dropFirst( path, idx ) {
return idx !== 0;
}

/**
* Deletes the comments associated with a given node.
*
* @private
* @param {Object} path - AST node path
* @returns {void}
*/
function deleteComment( path ) {
var i;
if ( path.node.comments ) {
for ( i = 0; i < path.node.comments.length; i++ ) {
if ( contains( path.node.comments[ i ].value, '@license Apache-2.0' ) ) {
path.node.comments[ i ].value = '* @license Apache-2.0 ';
}
}
}
}

/**
* Rewrites a `require` statement to include the `/dist` directory if the module being required starts with `@stdlib`.
*
* @private
* @param {Object} path - AST node path
* @returns {void}
*/
function rewriteRequire( path ) {
if ( startsWith( path.value.arguments[ 0 ].value, '@stdlib' ) ) {
path.value.arguments[ 0 ].value += '/dist';
}
}

/**
* Tests whether a path is a require call for `@stdlib/error-tools-fmtprodmsg`.
*
* @private
* @param {Object} path - AST node path
* @returns {boolean} boolean indicating whether a path is a require call for `@stdlib/error-tools-fmtprodmsg`
*/
function hasRequire( path ) {
return (
path.value.callee.name === 'require' &&
path.value.arguments[ 0 ].value === '@stdlib/error-tools-fmtprodmsg'
);
}


// MAIN //

/**
Expand Down Expand Up @@ -121,21 +198,6 @@

return replace( out, RE_INDENT, '\n' );

/**
* Tests whether a variable declaration is for the `@stdlib/string-format` require.
*
* @private
* @param {Object} path - AST node path
* @returns {boolean} boolean indicating whether a variable declaration is for the `@stdlib/string-format` require
*/
function onStringFormat( path ) {
var node = path.node;
return node.init &&
node.init.type === 'CallExpression' &&
node.init.callee.name === 'require' &&
node.init.arguments[0].value === '@stdlib/string-format';
}

/**
* Assigns the variable name for the `@stdlib/string-format` require.
*
Expand All @@ -147,49 +209,6 @@
formatVar = path.node.id.name;
}

/**
* Returns false if the node index is equal to zero and true otherwise.
*
* @private
* @param {Object} path - AST node path
* @param {number} idx - node index
* @returns {boolean} boolean indicating whether to keep the node
*/
function dropFirst( path, idx ) {
return idx !== 0;
}

/**
* Deletes the comments associated with a given node.
*
* @private
* @param {Object} path - AST node path
* @returns {void}
*/
function deleteComment( path ) {
var i;
if ( path.node.comments ) {
for ( i = 0; i < path.node.comments.length; i++ ) {
if ( contains( path.node.comments[ i ].value, '@license Apache-2.0' ) ) {
path.node.comments[ i ].value = '* @license Apache-2.0 ';
}
}
}
}

/**
* Rewrites a `require` statement to include the `/dist` directory if the module being required starts with `@stdlib`.
*
* @private
* @param {Object} path - AST node path
* @returns {void}
*/
function rewriteRequire( path ) {
if ( startsWith( path.value.arguments[0].value, '@stdlib' ) ) {
path.value.arguments[0].value += '/dist';
}
}

/**
* Callback invoked upon finding a string literal.
*
Expand Down Expand Up @@ -243,23 +262,11 @@
]))
]);
debug( 'Adding `require` call to `@stdlib/error-tools-fmtprodmsg`...' );
j( root.find( j.Declaration ).at( 0 ).get() ).insertBefore( formatRequire );

Check warning on line 265 in lib/node_modules/@stdlib/_tools/scripts/transform.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

This line has a length of 96. Maximum allowed is 80
}
}
}
}

/**
* Tests whether a path is a require call for `@stdlib/error-tools-fmtprodmsg`.
*
* @private
* @param {Object} path - AST node path
* @returns {boolean} boolean indicating whether a path is a require call for `@stdlib/error-tools-fmtprodmsg`
*/
function hasRequire( path ) {
return path.value.callee.name === 'require' &&
path.value.arguments[ 0 ].value === '@stdlib/error-tools-fmtprodmsg';
}
}


Expand Down