Skip to content

Commit

Permalink
build: memoize npmVersion for devDependencies
Browse files Browse the repository at this point in the history
The current iteration of the publish_packages script is very slow. The
main culprit is the `npm view` command, which is executed for each
internal dependency and devDependency of every standalone package. This
command is slow because it requires a network request to the npm
registry. This commit adds a memoization layer to the script, which
caches the results of the `npm view` command. In doing so, we have to
separate the memoization cache for dependencies and devDependencies
because the topological sort of the dependency graph is performed only
for production dependencies and thus a first call to `npm view` for a
devDependency is not guaranteed to reflect the latest version of the
dependency that was published to the npm registry during the current
execution of the script.
  • Loading branch information
Planeshifter committed Sep 24, 2023
1 parent f5f669f commit 6893e6e
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/node_modules/@stdlib/_tools/scripts/publish_packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ var readJSON = require( '@stdlib/fs/read-json' ).sync;
var existsSync = require( '@stdlib/fs/exists' ).sync;
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
var contains = require( '@stdlib/assert/contains' );
var memoize = require( '@stdlib/utils/memoize' );
var repeat = require( '@stdlib/string/repeat' );
var trim = require( '@stdlib/string/trim' );
var copy = require( '@stdlib/utils/copy' );
Expand Down Expand Up @@ -324,6 +325,8 @@ var BASIC_GITHUB_TOPICS = [
'node-js'
];
var RE_ALLOWED_TOPIC_CHARS = /^[A-Z0-9-]+$/i;
var memoizedNPMversionForDeps = memoize( npmVersion );
var memoizedNPMversionForDevDeps = memoize( npmVersion );

Check warning on line 329 in lib/node_modules/@stdlib/_tools/scripts/publish_packages.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Identifier name 'memoizedNPMversionForDevDeps' is too long (> 25)


// FUNCTIONS //
Expand Down Expand Up @@ -387,7 +390,7 @@ function populateDeps( pkgJSON, deps, devDeps, mainJSON, useGitHub ) {
if ( useGitHub ) {
out.dependencies[ dep ] = 'github:stdlib-js/' + replace( dep, '@stdlib/', '' ) + '#main';
} else {
out.dependencies[ dep ] = npmVersion( dep );
out.dependencies[ dep ] = memoizedNPMversionForDeps( dep );
}
}
} else {
Expand All @@ -409,7 +412,7 @@ function populateDeps( pkgJSON, deps, devDeps, mainJSON, useGitHub ) {
if ( useGitHub ) {
out.devDependencies[ dep ] = 'github:stdlib-js/' + replace( dep, '@stdlib/', '' ) + '#main';
} else {
out.devDependencies[ dep ] = npmVersion( dep );
out.devDependencies[ dep ] = memoizedNPMversionForDevDeps( dep );

Check warning on line 415 in lib/node_modules/@stdlib/_tools/scripts/publish_packages.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

This line has a length of 89. Maximum allowed is 80
}
}
} else {
Expand Down

0 comments on commit 6893e6e

Please sign in to comment.