From fe63f3d180f1ae1533ed67c768ab7f93048696c2 Mon Sep 17 00:00:00 2001 From: Artem Vasiliev Date: Wed, 21 Mar 2018 10:04:18 +0300 Subject: [PATCH 1/3] feat: allow to use `yarn add folder` as currentModuleInstall --- README.md | 3 +- src/dont-break.js | 91 +++++++++++++++++++++++++---------------------- 2 files changed, 50 insertions(+), 44 deletions(-) diff --git a/README.md b/README.md index 4bc478a..346df7e 100644 --- a/README.md +++ b/README.md @@ -250,7 +250,7 @@ By default it equals to "test" command. ### Current module installation method To test dependent package dont-break installs current module inside the dependent package directory. By default it uses -`cd $DEPENDENT_PACKAGE_DIR && npm install $CURRENT_MODULE_DIR`. Other options are +`npm install $CURRENT_MODULE_DIR`. Other options are [npm-link](https://docs.npmjs.com/cli/link) and [yarn-link](https://yarnpkg.com/lang/en/docs/cli/link/). They can be helpful in some cases, e.g. if you need to use `npm install` or `yarn` in postinstall command. To use `npm link` method specify {"currentModuleInstall": "npm-link"}: @@ -260,7 +260,6 @@ specify {"currentModuleInstall": "npm-link"}: "projects": ["packageA", "packageB"] } ``` -Default value is {"currentModuleInstall": "npm-install"}. ### Env vars exported to called scripts Following env vars are available for use in scripts called by executed steps: diff --git a/src/dont-break.js b/src/dont-break.js index bfd9939..13c17a9 100644 --- a/src/dont-break.js +++ b/src/dont-break.js @@ -134,34 +134,6 @@ var linkCurrentModule = _.memoize(function (thisFolder, linkCmd) { }) }) -function installCurrentModuleToDependent (sourceFolder, dependentFolder, currentModuleInstallMethod) { - la(check.unemptyString(dependentFolder), 'expected dependent folder', dependentFolder) - - debug('testing the current module in %s', dependentFolder) - debug('current module folder %s', sourceFolder) - - if (currentModuleInstallMethod === 'npm-install') { - return install({ prefix: dependentFolder, name: sourceFolder }) - .then(function () { - return dependentFolder - }) - } else { - var pkgName = currentPackageName() - var linkCmd = currentModuleInstallMethod.replace('-', ' ') - return linkCurrentModule(sourceFolder, linkCmd) - .then(function () { - return runInFolder(dependentFolder, `${linkCmd} ${pkgName}`, { - success: `linked ${pkgName}`, - failure: `linking ${pkgName} failed` - }) - }) - .finally(chdir.from) - .then(function () { - return dependentFolder - }) - } -} - function getDependencyName (dependent) { if (isRepoUrl(dependent)) { debug('dependent is git repo url %s', dependent) @@ -182,18 +154,6 @@ function getDependentVersion (pkg, name) { } } -function postInstallInFolder (dependentFolder, command, sourceFolder) { - if (command) { - command = command.replace('$CURRENT_MODULE_DIR', sourceFolder) - return runInFolder(dependentFolder, command, { - success: 'postinstall succeeded', - failure: 'postinstall did not work' - }) - } else { - return dependentFolder - } -} - function testDependent (options, dependent, config) { var moduleTestCommand var modulePostinstallCommand @@ -203,7 +163,7 @@ function testDependent (options, dependent, config) { dependent = {name: dependent.trim()} } - dependent = Object.assign({pretest: true, currentModuleInstall: 'npm-install'}, config, dependent) + dependent = Object.assign({pretest: true, currentModuleInstall: 'npm install $CURRENT_MODULE_DIR'}, config, dependent) moduleTestCommand = dependent.test modulePostinstallCommand = dependent.postinstall || 'npm install' testWithPreviousVersion = dependent.pretest @@ -238,6 +198,53 @@ function testDependent (options, dependent, config) { process.env.CURRENT_MODULE_NAME = pkg.name process.env.CURRENT_MODULE_DIR = cwd + function expandCommandVars (command) { + command = command.replace('$CURRENT_MODULE_DIR', cwd) + command = command.replace('$CURRENT_MODULE_NAME', pkg.name) + return command + } + + function postInstallInFolder (dependentFolder, command) { + if (command) { + command = expandCommandVars(command) + return runInFolder(dependentFolder, command, { + success: 'postinstall succeeded', + failure: 'postinstall did not work' + }) + } else { + return dependentFolder + } + } + + function installCurrentModuleToDependent (sourceFolder, dependentFolder, currentModuleInstallMethod) { + la(check.unemptyString(dependentFolder), 'expected dependent folder', dependentFolder) + + debug('testing the current module in %s', dependentFolder) + debug('current module folder %s', sourceFolder) + + var pkgName = currentPackageName() + if (['yarn-link', 'npm-link'].includes(currentModuleInstallMethod)) { + var linkCmd = currentModuleInstallMethod.replace('-', ' ') + return linkCurrentModule(sourceFolder, linkCmd) + .then(function () { + return runInFolder(dependentFolder, `${linkCmd} ${pkgName}`, { + success: `linked ${pkgName}`, + failure: `linking ${pkgName} failed` + }) + }) + .finally(chdir.from) + .then(function () { + return dependentFolder + }) + } else { + currentModuleInstallMethod = expandCommandVars(currentModuleInstallMethod) + return runInFolder(dependentFolder, `${currentModuleInstallMethod}`, { + success: `installed ${pkgName}`, + failure: `installing ${pkgName} failed` + }) + } + } + var depName = pkg.name + '-v' + pkg.version + '-against-' + moduleName var safeName = _.kebabCase(_.deburr(depName)) debug('original name "%s", safe "%s"', depName, safeName) @@ -253,7 +260,7 @@ function testDependent (options, dependent, config) { cmd: dependentInstall } - var postInstallModuleInFolder = _.partialRight(postInstallInFolder, modulePostinstallCommand, cwd) + var postInstallModuleInFolder = _.partialRight(postInstallInFolder, modulePostinstallCommand) var res = install(installOptions) .timeout(timeoutSeconds * 1000, 'install timed out for ' + moduleName) From ba707cb37f2fae6dd85835bee3673a820f62cbb7 Mon Sep 17 00:00:00 2001 From: Artem Vasiliev Date: Wed, 21 Mar 2018 10:12:14 +0300 Subject: [PATCH 2/3] chore(docs): clarified re currentModuleInstall --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 346df7e..7fedb04 100644 --- a/README.md +++ b/README.md @@ -250,10 +250,10 @@ By default it equals to "test" command. ### Current module installation method To test dependent package dont-break installs current module inside the dependent package directory. By default it uses -`npm install $CURRENT_MODULE_DIR`. Other options are -[npm-link](https://docs.npmjs.com/cli/link) and [yarn-link](https://yarnpkg.com/lang/en/docs/cli/link/). They can be -helpful in some cases, e.g. if you need to use `npm install` or `yarn` in postinstall command. To use `npm link` method -specify {"currentModuleInstall": "npm-link"}: +`npm install $CURRENT_MODULE_DIR`. You can enter your command there, e.g. `yarn add $CURRENT_MODULE_DIR`. There are +also pre-configured option options [npm-link](https://docs.npmjs.com/cli/link) and +[yarn-link](https://yarnpkg.com/lang/en/docs/cli/link/). They can be helpful in some cases, e.g. if you need to use +`npm install` or `yarn` in postinstall command. To use `npm link` method specify {"currentModuleInstall": "npm-link"}: ``` { "currentModuleInstall": "npm-link", From a00ce9c1999f575114e11371bfb0a7c7fb8be708 Mon Sep 17 00:00:00 2001 From: Artem Vasiliev Date: Wed, 21 Mar 2018 10:15:48 +0300 Subject: [PATCH 3/3] fix: Node4-compatible version --- src/dont-break.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dont-break.js b/src/dont-break.js index 13c17a9..3b58848 100644 --- a/src/dont-break.js +++ b/src/dont-break.js @@ -223,7 +223,7 @@ function testDependent (options, dependent, config) { debug('current module folder %s', sourceFolder) var pkgName = currentPackageName() - if (['yarn-link', 'npm-link'].includes(currentModuleInstallMethod)) { + if (_.includes(['yarn-link', 'npm-link'], currentModuleInstallMethod)) { var linkCmd = currentModuleInstallMethod.replace('-', ' ') return linkCurrentModule(sourceFolder, linkCmd) .then(function () {