Skip to content

Commit 0e1a585

Browse files
committed
Have event.json working as a local source of data
1 parent 2b9be3f commit 0e1a585

File tree

3 files changed

+38
-8
lines changed

3 files changed

+38
-8
lines changed

lib/RuntimeWebpack.js

+36
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ module.exports = function(S) {
135135
.then((webpackConfig) => this._webpackCompile(R.merge(webpackConfig, {
136136
entry: path.join(pathDist, webpackConfig.entry),
137137
})))
138+
.then((stats) =>
139+
this.createDistDir(path.join(pathDist, 'node_modules'))
140+
.then((modulesDist) => this._copyExternalModules(stats, modulesDist))
141+
)
138142
.then(() => pathDist);
139143
});
140144
}
@@ -192,6 +196,38 @@ module.exports = function(S) {
192196
});
193197
}
194198

199+
_copyExternalModules(stats, pathDist) {
200+
const options = {
201+
hash: false,
202+
version: false,
203+
timings: false,
204+
assets: false,
205+
chunks: false,
206+
modules: true,
207+
reasons: false,
208+
children: false,
209+
source: false,
210+
errors: false,
211+
errorDetails: false,
212+
warnings: false,
213+
publicPath: false,
214+
exclude: [/^(?!external )/],
215+
};
216+
217+
const natives = process.binding('natives');
218+
const projectPath = S.config.projectPath;
219+
const externalModules = stats.toJson(options).modules;
220+
const moduleNames = externalModules
221+
.map(module => /external "(.+)"/.exec(module.identifier)[1])
222+
// exclude aws-sdk since it is provided by lambda
223+
// also exclude native node.js modules
224+
.filter(id => id !== 'aws-sdk' && !natives[id]);
225+
return Promise.all(moduleNames.map(moduleName => {
226+
const modulePath = path.join(projectPath, 'node_modules', moduleName);
227+
SCli.log('Copy module: ' + moduleName);
228+
return fs.copy(modulePath, path.join(pathDist, moduleName));
229+
}));
230+
}
195231

196232
/**
197233
* Get Handler

lib/webpack-runner.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ const runFunc = (fn, name, event) => {
4848
try {
4949
const result = fn(event, ctx);
5050

51-
if (result && typeof result.then == 'function') {
51+
if (result && typeof result.then === 'function') {
5252
result.then(ctx.succeed).catch(ctx.fail);
5353
return;
5454
}

package.json

+1-7
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,11 @@
2424
},
2525
"homepage": "https://github.com/elastic-coders/serverless-runtime-webpack#readme",
2626
"dependencies": {
27-
"babel-core": "^6.7.4",
28-
"babel-loader": "^6.2.4",
29-
"babel-polyfill": "^6.7.4",
30-
"babel-preset-es2015": "^6.6.0",
31-
"babel-preset-stage-0": "^6.5.0",
3227
"bluebird": "^3.3.4",
3328
"chalk": "^1.1.3",
3429
"glob": "^7.0.3",
3530
"lodash": "^4.8.2",
3631
"ramda": "^0.20.1",
37-
"source-map-support": "^0.4.0",
38-
"webpack": "^1.12.14"
32+
"webpack": "^1.13.0"
3933
}
4034
}

0 commit comments

Comments
 (0)