Skip to content

Commit

Permalink
Fix build errors for serverless > 1.17.0 (#36)
Browse files Browse the repository at this point in the history
* Fix function artifact now under package property
* Fix single function deployment by cleaning .webpack folder later in the deploy hooks

Note: this drops support for serverless < 1.18.0

Closes #37
  • Loading branch information
cardoni authored and jogold committed Aug 10, 2017
1 parent d3ef522 commit 3eaca8d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
10 changes: 8 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ class ServerlessPluginWebpack {
this.hooks = {
'before:package:createDeploymentArtifacts': () => this.webpackBundle('service'),
'after:package:createDeploymentArtifacts': () => this.restoreAndCopy('service'),
'after:package:finalize': () => this.clean(),
'before:deploy:function:packageFunction': () => this.webpackBundle('function'),
'after:deploy:function:packageFunction': () => this.restoreAndCopy('function'),
'after:deploy:function:deploy': () => this.clean(),
};
}

Expand Down Expand Up @@ -69,7 +71,7 @@ class ServerlessPluginWebpack {
// Restore service path
this.serverless.config.servicePath = this.originalServicePath;

// Copy .webpack/.serverless to .serverless and remove .webpack
// Copy .webpack/.serverless to .serverless and set artifacts
const src = path.join(this.originalServicePath, webpackFolder, serverlessFolder);
const dest = path.join(this.originalServicePath, serverlessFolder);
return fs.copy(src, dest)
Expand All @@ -80,9 +82,13 @@ class ServerlessPluginWebpack {
this.serverless.service.functions
);
}
return fs.remove(path.join(this.originalServicePath, webpackFolder));
return Promise.resolve();
});
}

clean() {
return fs.remove(path.join(this.originalServicePath, webpackFolder));
}
}

module.exports = ServerlessPluginWebpack;
2 changes: 1 addition & 1 deletion src/lib/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const setFnsPackage = R.map(

const setFnsArtifacts = (serverlessPath, fns) => R.map(
R.over(
R.lensProp('artifact'),
R.lensPath(['package', 'artifact']),
artifact => path.join(serverlessPath, path.basename(artifact))
),
fns
Expand Down
12 changes: 6 additions & 6 deletions test/service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ test('setFnsPackage', () => {

test('setArtifacts', () => {
const artifactFns = {
firstGet: { artifact: '/.serverless/.webpack/service-dev-firstGet.zip' },
secondGet: { artifact: '/.serverless/.webpack/service-dev-secondGet.zip' },
post: { artifact: '/.serverless/.webpack/service-dev-post.zip' },
firstGet: { package: { artifact: '/.serverless/.webpack/service-dev-firstGet.zip' } },
secondGet: { package: { artifact: '/.serverless/.webpack/service-dev-secondGet.zip' } },
post: { package: { artifact: '/.serverless/.webpack/service-dev-post.zip' } },
};

const modifiedArtifactFns = {
firstGet: { artifact: path.join('/.serverless', 'service-dev-firstGet.zip') },
secondGet: { artifact: path.join('/.serverless', 'service-dev-secondGet.zip') },
post: { artifact: path.join('/.serverless', 'service-dev-post.zip') },
firstGet: { package: { artifact: path.join('/.serverless', 'service-dev-firstGet.zip') } },
secondGet: { package: { artifact: path.join('/.serverless', 'service-dev-secondGet.zip') } },
post: { package: { artifact: path.join('/.serverless', 'service-dev-post.zip') } },
};
expect(service.setFnsArtifacts('/.serverless', artifactFns)).toEqual(modifiedArtifactFns);
});

0 comments on commit 3eaca8d

Please sign in to comment.