Skip to content

Commit

Permalink
fix: pin 'tslib' to avoid issues when interacting with plugin-plugins (
Browse files Browse the repository at this point in the history
…twilio#88)

The 'plugin-plugins' module was not loading properly because of some bug in 'tslib-1.12.0'. Users would see the error `TypeError: Plugins is not a constructor` when attempting to install a runtime dependency. The test has been updated to catch the issue in the future.
  • Loading branch information
childish-sambino authored May 19, 2020
1 parent 075aa23 commit 845f65d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"inquirer": "^7.1.0",
"qs": "^6.9.3",
"semver": "^7.3.0",
"tslib": "~1.11.2",
"tsv": "^0.2.0",
"twilio": "^3.43.1"
},
Expand Down
8 changes: 4 additions & 4 deletions src/services/require-install.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,16 @@ const requireInstall = async (packageName, command) => {
}

// If we're here, attempt to install the package in the plugin's runtime modules path.
try {
logger.warn(`Installing ${packageName} ...`);
const packageTag = targetVersion ? `${packageName}@${targetVersion}` : packageName;
const plugins = new Plugins({ dataDir: pluginPath, cacheDir: pluginPath });
logger.warn(`Installing ${packageName} ...`);
const plugins = new Plugins({ dataDir: pluginPath, cacheDir: pluginPath });

try {
// Init the PJSON in case it doesn't exist. This is required by yarn or it
// moves up the dir tree until it finds one.
await plugins.createPJSON();

// Force install the package in case it's a native module that needs rebuilding.
const packageTag = targetVersion ? `${packageName}@${targetVersion}` : packageName;
await plugins.yarn.exec(['add', '--force', packageTag], { cwd: pluginPath, verbose: false });
} catch (error) {
logger.debug(`Error installing ${packageName}: ${error}`);
Expand Down
14 changes: 13 additions & 1 deletion test/services/require-install.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const tmp = require('tmp');
const { expect, test } = require('@twilio/cli-test');
const { getCommandPlugin, getPackageVersion, getDependencyVersion, checkVersion, requireInstall } = require('../../src/services/require-install');
const { logger, LoggingLevel } = require('../../src/services/messaging/logging');
const corePJSON = require('../../package.json');

const TOP_PLUGIN = {
Expand Down Expand Up @@ -95,13 +96,24 @@ describe('services', () => {
});

describe('requireInstall', () => {
before(() => {
logger.config.level = LoggingLevel.debug;
});

after(() => {
logger.config.level = LoggingLevel.info;
});

test.it('can load existing packages', () => {
expect(requireInstall('chai')).to.not.be.undefined;
});

test.it('will attempt to install packages', async () => {
test.stderr().it('will attempt to install packages', async ctx => {
const command = { id: 'top-command', config };
await expect(requireInstall('chai-dai', command)).to.be.rejected;
expect(ctx.stderr).to.contain('Error loading chai-dai');
expect(ctx.stderr).to.contain('Installing chai-dai');
expect(ctx.stderr).to.contain('Error installing chai-dai');
});
});
});
Expand Down

0 comments on commit 845f65d

Please sign in to comment.