Skip to content

Commit 89b2c99

Browse files
authored
Merge pull request #766 from apancutt/master
2 parents ac82119 + 680c07b commit 89b2c99

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

index.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@ class ServerlessWebpack {
2626
this.options = options;
2727

2828
if (
29-
(_.has(this.serverless, 'service.custom.webpack') &&
30-
_.isString(this.serverless.service.custom.webpack) &&
31-
_.endsWith(this.serverless.service.custom.webpack, '.ts')) ||
32-
(_.has(this.serverless, 'service.custom.webpack.webpackConfig') &&
33-
_.endsWith(this.serverless.service.custom.webpack.webpackConfig, '.ts'))
29+
(
30+
(_.has(this.serverless, 'service.custom.webpack') &&
31+
_.isString(this.serverless.service.custom.webpack) &&
32+
_.endsWith(this.serverless.service.custom.webpack, '.ts')) ||
33+
(_.has(this.serverless, 'service.custom.webpack.webpackConfig') &&
34+
_.endsWith(this.serverless.service.custom.webpack.webpackConfig, '.ts'))
35+
) && !process[Symbol.for('ts-node.register.instance')]
3436
) {
3537
try {
3638
require('ts-node/register');

index.test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,15 @@ describe('ServerlessWebpack', () => {
8080
expect(Module._load).to.have.been.calledWith('ts-node/register');
8181
});
8282

83+
it('should not register ts-node if it has already been registered', () => {
84+
_.set(serverless, 'service.custom.webpack.webpackConfig', 'webpack.config.ts');
85+
process[Symbol.for('ts-node.register.instance')] = 'foo';
86+
new ServerlessWebpack(serverless, {});
87+
delete process[Symbol.for('ts-node.register.instance')];
88+
expect(Module._load).to.not.have.been.called;
89+
expect(Module._load).to.not.have.been.calledWith('ts-node/register');
90+
});
91+
8392
it('should throw an error if config use TS but ts-node was not added as dependency', () => {
8493
moduleStub.throws();
8594

0 commit comments

Comments
 (0)