Skip to content

Commit 845f65d

Browse files
author
childish-sambino
authored
fix: pin 'tslib' to avoid issues when interacting with plugin-plugins (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.
1 parent 075aa23 commit 845f65d

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"inquirer": "^7.1.0",
1818
"qs": "^6.9.3",
1919
"semver": "^7.3.0",
20+
"tslib": "~1.11.2",
2021
"tsv": "^0.2.0",
2122
"twilio": "^3.43.1"
2223
},

src/services/require-install.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,16 @@ const requireInstall = async (packageName, command) => {
9494
}
9595

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

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

106105
// Force install the package in case it's a native module that needs rebuilding.
106+
const packageTag = targetVersion ? `${packageName}@${targetVersion}` : packageName;
107107
await plugins.yarn.exec(['add', '--force', packageTag], { cwd: pluginPath, verbose: false });
108108
} catch (error) {
109109
logger.debug(`Error installing ${packageName}: ${error}`);

test/services/require-install.test.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const tmp = require('tmp');
22
const { expect, test } = require('@twilio/cli-test');
33
const { getCommandPlugin, getPackageVersion, getDependencyVersion, checkVersion, requireInstall } = require('../../src/services/require-install');
4+
const { logger, LoggingLevel } = require('../../src/services/messaging/logging');
45
const corePJSON = require('../../package.json');
56

67
const TOP_PLUGIN = {
@@ -95,13 +96,24 @@ describe('services', () => {
9596
});
9697

9798
describe('requireInstall', () => {
99+
before(() => {
100+
logger.config.level = LoggingLevel.debug;
101+
});
102+
103+
after(() => {
104+
logger.config.level = LoggingLevel.info;
105+
});
106+
98107
test.it('can load existing packages', () => {
99108
expect(requireInstall('chai')).to.not.be.undefined;
100109
});
101110

102-
test.it('will attempt to install packages', async () => {
111+
test.stderr().it('will attempt to install packages', async ctx => {
103112
const command = { id: 'top-command', config };
104113
await expect(requireInstall('chai-dai', command)).to.be.rejected;
114+
expect(ctx.stderr).to.contain('Error loading chai-dai');
115+
expect(ctx.stderr).to.contain('Installing chai-dai');
116+
expect(ctx.stderr).to.contain('Error installing chai-dai');
105117
});
106118
});
107119
});

0 commit comments

Comments
 (0)