Skip to content

Commit

Permalink
Switching to npm prune/update on repo change, copying over node_modules
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanolson committed Apr 15, 2020
1 parent 23426e9 commit 97d5b93
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 19 deletions.
18 changes: 2 additions & 16 deletions js/CTSnapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,9 @@ const deleteDirectory = require( '../../perennial/js/common/deleteDirectory' );
const execute = require( '../../perennial/js/common/execute' );
const getRepoList = require( '../../perennial/js/common/getRepoList' );
const gitRevParse = require( '../../perennial/js/common/gitRevParse' );
const npmCommand = require( '../../perennial/js/common/npmCommand' );
const fs = require( 'fs' );
const _ = require( 'lodash' ); // eslint-disable-line

// constants
const copyOptions = { filter: path => path.indexOf( 'node_modules' ) < 0 };

class CTSnapshot {
/**
* Creates this snapshot.
Expand Down Expand Up @@ -76,8 +72,8 @@ class CTSnapshot {
}

for ( const repo of this.repos ) {
await copyDirectory( `${rootDir}/${repo}`, `${this.phetDir}/${repo}`, copyOptions );
await copyDirectory( `${rootDir}/${repo}`, `${this.phetioDir}/${repo}`, copyOptions );
await copyDirectory( `${rootDir}/${repo}`, `${this.phetDir}/${repo}`, {} );
await copyDirectory( `${rootDir}/${repo}`, `${this.phetioDir}/${repo}`, {} );
}

// @public {Array.<Object>}
Expand All @@ -100,16 +96,6 @@ class CTSnapshot {
} );
}

async npmInstall() {
const npmRepos = this.repos.filter( repo => fs.existsSync( `../${repo}/package.json` ) );
for ( const repo of npmRepos ) {
this.setSnapshotStatus( `Running npm update for ${repo}` );

await execute( npmCommand, [ 'update', `--cache=../npm-caches/${repo}`, '--tmp=../npm-tmp' ], `${this.phetDir}/${repo}` );
await execute( npmCommand, [ 'update', `--cache=../npm-caches/${repo}`, '--tmp=../npm-tmp' ], `${this.phetioDir}/${repo}` );
}
}

/**
* Removes the snapshot's files.
* @public
Expand Down
13 changes: 10 additions & 3 deletions js/local-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ const cloneMissingRepos = require( '../../perennial/js/common/cloneMissingRepos'
const getRepoList = require( '../../perennial/js/common/getRepoList' );
const gitPull = require( '../../perennial/js/common/gitPull' );
const isStale = require( '../../perennial/js/common/isStale' );
const npmUpdate = require( '../../perennial/js/common/npmUpdate' );
const CTSnapshot = require( './CTSnapshot' );
const fs = require( 'fs' );
const http = require( 'http' );
const _ = require( 'lodash' ); // eslint-disable-line
const path = require( 'path' );
Expand Down Expand Up @@ -297,7 +299,14 @@ const cycleSnapshots = async () => {
for ( const repo of staleRepos ) {
await gitPull( repo );
}
await cloneMissingRepos();
const clonedRepos = await cloneMissingRepos();

// npm prune/update on any changed repos, so we can keep our npm status good in our checked out version
for ( const repo of [ ...staleRepos, ...clonedRepos ] ) {
if ( fs.existsSync( `../${repo}/package.json` ) ) {
await npmUpdate( repo );
}
}
}
else {
winston.info( 'No stale repos' );
Expand All @@ -312,8 +321,6 @@ const cycleSnapshots = async () => {

snapshots.unshift( snapshot );

await snapshot.npmInstall();

const cutoffTimestamp = Date.now() - 1000 * 60 * 60 * 24 * NUMBER_OF_DAYS_TO_KEEP_SNAPSHOTS;
while ( snapshots.length > 70 || snapshots[ snapshots.length - 1 ].timestamp < cutoffTimestamp && !snapshots[ snapshots.length - 1 ].exists ) {
removeResultsForSnapshot( testResults, snapshots.pop() );
Expand Down

0 comments on commit 97d5b93

Please sign in to comment.