Skip to content

Commit

Permalink
Merge pull request #766 from apancutt/master
Browse files Browse the repository at this point in the history
  • Loading branch information
j0k3r authored Apr 6, 2021
2 parents ac82119 + 680c07b commit 89b2c99
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
12 changes: 7 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ class ServerlessWebpack {
this.options = options;

if (
(_.has(this.serverless, 'service.custom.webpack') &&
_.isString(this.serverless.service.custom.webpack) &&
_.endsWith(this.serverless.service.custom.webpack, '.ts')) ||
(_.has(this.serverless, 'service.custom.webpack.webpackConfig') &&
_.endsWith(this.serverless.service.custom.webpack.webpackConfig, '.ts'))
(
(_.has(this.serverless, 'service.custom.webpack') &&
_.isString(this.serverless.service.custom.webpack) &&
_.endsWith(this.serverless.service.custom.webpack, '.ts')) ||
(_.has(this.serverless, 'service.custom.webpack.webpackConfig') &&
_.endsWith(this.serverless.service.custom.webpack.webpackConfig, '.ts'))
) && !process[Symbol.for('ts-node.register.instance')]
) {
try {
require('ts-node/register');
Expand Down
9 changes: 9 additions & 0 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ describe('ServerlessWebpack', () => {
expect(Module._load).to.have.been.calledWith('ts-node/register');
});

it('should not register ts-node if it has already been registered', () => {
_.set(serverless, 'service.custom.webpack.webpackConfig', 'webpack.config.ts');
process[Symbol.for('ts-node.register.instance')] = 'foo';
new ServerlessWebpack(serverless, {});
delete process[Symbol.for('ts-node.register.instance')];
expect(Module._load).to.not.have.been.called;
expect(Module._load).to.not.have.been.calledWith('ts-node/register');
});

it('should throw an error if config use TS but ts-node was not added as dependency', () => {
moduleStub.throws();

Expand Down

0 comments on commit 89b2c99

Please sign in to comment.