Skip to content
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

Merged
merged 43 commits into from
Jan 20, 2017
Merged

[GPT-432] Package server webpack #346

merged 43 commits into from
Jan 20, 2017

Conversation

nickbalestra
Copy link
Contributor

@nickbalestra nickbalestra commented Jan 10, 2017

@matteofigus matteofigus changed the title Package server webpack [don't merge yet] Package server webpack Jan 10, 2017
@matthewdavidson
Copy link
Contributor

Looking good so far @nickbalestra! I know this is still WIP but some quick comments on the webpack config:

  • I suspect we will need libraryTarget: 'commonjs2' specified in the output section, otherwise the oc-registry will have nothing to consume
  • In order to avoid packaging up npm dependencies and delegate resolving to the oc-registry, we should configure something along these lines:externals: /^[a-z@][a-z\-\/0-9]+$/, (regex not tested thoroughly).

@nickbalestra
Copy link
Contributor Author

nickbalestra commented Jan 11, 2017

@matthewdavidson yes, thanks 💯 for reminding the commonjs2 target !
For the externals your regex seems fine, perhaps a simple alternative could be just /^[^\.\/]+$/ ? But I guess some more name-validation as you are doing won't hurt 💅

@nickbalestra
Copy link
Contributor Author

@matthewdavidson added libraryTarget and externals. @matteofigus need to add some integration tests for them, and then we'll probably be ready for a first review

@nickbalestra nickbalestra force-pushed the package-server-webpack branch 2 times, most recently from 2af7991 to cde708d Compare January 12, 2017 16:39
@nickbalestra
Copy link
Contributor Author

Quick update you on the status of this pr:

  • Need to investigate why some tests fails on windows.
  • Add unit tests (all the integration tests are in place).
  • Clean legacy code

@nickbalestra
Copy link
Contributor Author

nickbalestra commented Jan 13, 2017

@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;
Copy link
Contributor Author

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 nice catch

@nickbalestra nickbalestra force-pushed the package-server-webpack branch 2 times, most recently from a31e10a to 843b471 Compare January 13, 2017 18:15
@nickbalestra nickbalestra changed the title [don't merge yet] Package server webpack Package server webpack Jan 13, 2017
@nickbalestra nickbalestra changed the title Package server webpack [GPT-432] Package server webpack Jan 16, 2017
Copy link
Contributor

@matthewdavidson matthewdavidson left a 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'
},
Copy link
Contributor

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch!

@nickbalestra
Copy link
Contributor Author

nickbalestra commented Jan 18, 2017 via email

@nickbalestra nickbalestra force-pushed the package-server-webpack branch 2 times, most recently from a10342b to fd38f7e Compare January 18, 2017 10:26
@@ -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"
Copy link
Contributor

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?

Copy link
Member

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

Copy link
Contributor Author

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?

Copy link
Member

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
Copy link
Contributor

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

Copy link
Contributor Author

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?

Copy link
Member

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 ;)

@nickbalestra nickbalestra mentioned this pull request Jan 19, 2017
1 task
Copy link
Member

@matteofigus matteofigus left a 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));
Copy link
Member

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);
Copy link
Member

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));
Copy link
Member

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;
Copy link
Member

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();
});
Copy link
Member

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;

Copy link
Contributor Author

@nickbalestra nickbalestra Jan 20, 2017

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(){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo ("and" and "depenencies")

Copy link
Contributor Author

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){
Copy link
Member

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));
Copy link
Member

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(){
Copy link
Member

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'
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙈 🙊

@matteofigus matteofigus merged commit 81cdaed into master Jan 20, 2017
@matteofigus matteofigus deleted the package-server-webpack branch January 20, 2017 11:36
@matteofigus
Copy link
Member

gif

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants