diff --git a/eo2js/src/commands/link.js b/eo2js/src/commands/link.js index a4cbc29..6e55054 100644 --- a/eo2js/src/commands/link.js +++ b/eo2js/src/commands/link.js @@ -64,6 +64,17 @@ const link = function(options) { execSync('npm install', {cwd: project}) console.log(`Copying ${main} file...`) + const lock = path.resolve(project, 'package-lock.json') + if (!fs.existsSync(lock)) { + execSync('npm install', {cwd: project}) + if (options.dependency) { + fs.cpSync( + options.dependency, + path.resolve(project, 'node_modules/eo2js-runtime'), + {recursive: true} + ) + } + } fs.copyFileSync( path.resolve(options.resources, `js/${main}`), path.resolve(project, main) diff --git a/eo2js/test/commands/link.test.js b/eo2js/test/commands/link.test.js index eff85e7..18e19c7 100644 --- a/eo2js/test/commands/link.test.js +++ b/eo2js/test/commands/link.test.js @@ -1,6 +1,7 @@ const {runSync, assertFilesExist} = require('../helpers') const path = require('path'); const fs = require('fs'); +const assert = require('assert'); describe('link', function() { const home = path.resolve('temp/test-link') @@ -39,4 +40,14 @@ describe('link', function() { assertFilesExist(link('--tests'), project, ['node_modules/mocha']) done() }) + it('should not reinstall npm packages if package-lock.json exists', function(done) { + this.timeout(10000) + link() + const lockFilePath = path.resolve(project, 'package-lock.json') + const initialMtime = fs.statSync(lockFilePath).mtime + link() + const finalMtime = fs.statSync(lockFilePath).mtime + assert.strictEqual(initialMtime.getTime(), finalMtime.getTime(), 'package-lock.json was modified on second run') + done() + }) })