-
Notifications
You must be signed in to change notification settings - Fork 122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[GPT-432] Package server webpack #346
Conversation
nickbalestra
commented
Jan 10, 2017
•
edited
Loading
edited
- Support for local requires in server.js as per Consider support for local requires in server.js #340
- ES2015 support in server.js as per ES2015 support in server.js #339
- webpack v1 for prod (until we drop support for node 0.12/0.10 && webpack2 exit rc)
- Production-grade ouput
- Uglify
- Wrap do/while/for;; loops against infinite loops risk
- Check missing dependencies
- Integration Tests
- Unit Tests
- cleanup legacy
0ab4fc1
to
14acc12
Compare
Looking good so far @nickbalestra! I know this is still WIP but some quick comments on the webpack config:
|
@matthewdavidson yes, thanks 💯 for reminding the |
@matthewdavidson added |
2af7991
to
cde708d
Compare
Quick update you on the status of this pr:
|
c7eddb7
to
14d4787
Compare
@matteofigus @matthewdavidson should be ready to go for a review. |
var regex = handler[1]; | ||
it('should match npm module names', function() { | ||
expect(regex.test('lodash')).to.be.true; | ||
expect(regex.test('lodash/fp/curryN')).to.be.true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@matthewdavidson that helped me fine an exception to our regularExpression for the webpack externals
:
A relative path from an npm module can in fact contain upperCase letters
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 nice catch
a31e10a
to
843b471
Compare
843b471
to
3e83569
Compare
b224c5f
to
eae270a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've tried this out on one of our components and it all works as expected.
i.e. listed "oc": "opentable/oc#05bea7c48719824248b0777dcb25a67491eeccf4"
in package.json
and modified server.js
to use es6 & local requires.
🎉
path: '/build', | ||
filename: params.fileName, | ||
libraryTarget: 'commonjs2' | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be be setting target: 'node',
here? (see https://webpack.github.io/docs/configuration.html#target)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch!
Thanks Matthew!
Will do some more extensive tests today on some of our most complex components as well. Then we should be ready to ship
… On 18 Jan 2017, at 05:27, Matthew Davidson ***@***.***> wrote:
@matthewdavidson commented on this pull request.
We've tried this out on one of our components and it all works as expected.
i.e. listed "oc": "opentable/oc#05bea7c48719824248b0777dcb25a67491eeccf4" in package.json and modified server.js to use es6 & local requires.
🎉
In src/cli/domain/package-server-script/bundle/config/index.js:
> +/*jshint camelcase:false */
+'use strict';
+
+var webpack = require('webpack');
+var path = require('path');
+var wrapLoops = require('./wrapLoops');
+var externalDependenciesHandlers = require('./externalDependenciesHandlers');
+
+module.exports = function webpackConfigGenerator(params){
+ return {
+ entry: params.dataPath,
+ output: {
+ path: '/build',
+ filename: params.fileName,
+ libraryTarget: 'commonjs2'
+ },
Should be be setting target: 'node', here? (see https://webpack.github.io/docs/configuration.html#target)
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
a10342b
to
fd38f7e
Compare
@@ -78,6 +83,7 @@ | |||
"targz": "1.0.1", | |||
"uglify-js": "2.6.4", | |||
"underscore": "1.8.3", | |||
"watch": "0.19.1" | |||
"watch": "0.19.1", | |||
"webpack": "1.14.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Worth upgrading to 2.0 since the new hot sauce has been released... Maybe too soon?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's out of beta I 👍 on this, unless it requires a significant amount of work so that we want to keep it to the next PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, and thats great news 🎉
Although, until we finally drop ourself support for node 0.10&co I will suggest we stick to v1. I'll prepare a v2 upgrade on a separate PR, what you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'presets': [ | ||
[require.resolve('babel-preset-env'), { | ||
'targets': { | ||
'node': 0.10 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know why we are doing this but is there a plan to move away from 0.10... LTS has even ran out on it: https://github.com/nodejs/LTS
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know. This should be a short term pain though. I was planning to update this with the wepack2 upgrade as by tame we'll merge that mean we don't have any more 0.10&co to support. After that we my want to consider adding some global config to oc where you could set that target info there. Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's fine if we go for node 4 with this. Node 0.10 is supported but we can remove support as soon as we merge this as a subsequent PR ;)
956b6e4
to
dbf4714
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of little changes and then I think we're ready to go
return uglifyJs.minify(code, { fromString: true }).code; | ||
} catch (e){ | ||
if(!!e.line && !!e.col){ | ||
throw new Error(format(strings.errors.cli.SERVERJS_PARSING_ERROR, fileName, e.line, e.col, e.message)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove this SERVERJS_PARSING_ERROR
if(ext === ''){ | ||
required += '.json'; | ||
} else if(ext !== '.json'){ | ||
throw new Error(strings.errors.cli.SERVERJS_REQUIRE_JS_NOT_ALLOWED); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same for SERVERJS_REQUIRE_JS_NOT_ALLOWED
|
||
var requiredPath = path.resolve(componentPath, required); | ||
if(!fs.existsSync(requiredPath)){ | ||
throw new Error(format(strings.errors.cli.SERVERJS_REQUIRE_JSON_NOT_FOUND, required)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here too SERVERJS_REQUIRE_JSON_NOT_FOUND
compiler.outputFileSystem = memoryFs; | ||
|
||
compiler.run(function(error, stats){ | ||
var sofError; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo
fs.writeFileSync(path.resolve(componentPath, 'user.json'), jsonContent); | ||
fs.writeFileSync(path.resolve(componentPath, serverName), serverContent); | ||
done(); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should add an afterEach for ensuring that other requires to same (changed?) file don't get the cached version
require.cache[path.resolve(publishPath, res.src)] = null;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sweet one, thanks for that!!! 🥇
); | ||
}); | ||
|
||
describe('end required depenencies is not present in the package.json', function(){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo ("and" and "depenencies")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💅
done(); | ||
}); | ||
|
||
it('should throw an error when the dependency is not present in the package.json', function(done){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to keep consistency, can we do a describe for "when the dependency is not present in the package.json" and then a nested it for "should throw an error"?
} | ||
try { | ||
var name = 'John'; | ||
var bundle = require(path.resolve(publishPath, res.src)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as before for an afterEach that contains the require cache invalidation
}); | ||
|
||
it('should wrap the do loop with an iterator limit (and convert it to a for loop)', function(){ | ||
expect(fsMock.writeFile.firstCall.args[1]).to.contain('for(var i=1e9;;){if(i<=0)throw new Error(\"loop exceeded maximum allowed iterations\");t=342,i--}'); | ||
it('should return a proper confifuration options for webpack', function(){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"confifuration" typo
webpack: { stats: 'none' }, | ||
dependencies: {}, | ||
fileName: 'server.js', | ||
dataPath: '/Users/nbalestra/dev/oc/test/integration/cli-domain-package-server-script/component/server.js' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better if we do a readable example like /path/to/server.js
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙈 🙊