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

Gulp serve only serve either compiled or uncompiled version #8559

Merged
merged 14 commits into from
Apr 28, 2017

Conversation

zhouyx
Copy link
Contributor

@zhouyx zhouyx commented Apr 3, 2017

For #7581
Please let me know if the approach looks good in general.
Will get to integration test change in different PR. Also it would require some doc change.
Heroku would by default run max version. Can someone point to me where the config is for heroku?

export function calculateEntryPointScriptUrl(location, entryPoint, isLocalDev,
isTest) {
const base = calculateScriptBaseUrl(location, isLocalDev, isTest);
const serveMax = isLocalDev && isMax(location);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@choumx @jridgewell any ideas why we don't take isTest into consideration here?

Choose a reason for hiding this comment

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

Probably just an oversight (or deemed unnecessary). We'd also need isUsingCompiledJs to make sure we test min builds with --compiled here.

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 news is with this PR, gulp server will use min files with --compiled flag. we don't need to deal with isUsingCompiledJs anymore.

@@ -23,6 +23,18 @@ var nodemon = require('nodemon');
* Starts a simple http server at the repository root
*/
function serve() {
// Get the serve mode
if (argv.compiled) {
process.env.SERVE_MODE = 'min';
Copy link
Member

Choose a reason for hiding this comment

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

Could we make this changeable at runtime?

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 can add the check for app.use('/serve_mode=?') to change it at runtime. If this is what you mean?

@cramforce
Copy link
Member

cramforce commented Apr 4, 2017 via email

@zhouyx
Copy link
Contributor Author

zhouyx commented Apr 4, 2017

PTAL 👀

@zhouyx
Copy link
Contributor Author

zhouyx commented Apr 6, 2017

Ping~

@zhouyx zhouyx requested review from dvoytenko and removed request for lannka April 10, 2017 17:06
@zhouyx
Copy link
Contributor Author

zhouyx commented Apr 11, 2017

Friendly ping on this PR. @cramforce Do we still want to keep it? : )

@cramforce
Copy link
Member

I'm just waiting for others to review :)

@zhouyx
Copy link
Contributor Author

zhouyx commented Apr 11, 2017

LOLOL 😄 Ping @erwinmombay @lannka and @dvoytenko

@@ -28,9 +28,31 @@ var jsdom = require('jsdom');
var path = require('path');
var request = require('request');
var url = require('url');
var mode = process.env.SERVE_MODE;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you document here what's default is?

process.env.SERVE_MODE = newMode;
info = '<h2>Serve mode changed to ' + newMode + '</h2>';
} else {
info = '<h2>Serve mode ' + newMode + ' is not support. </h2>';
Copy link
Contributor

Choose a reason for hiding this comment

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

"ed"

@@ -486,19 +511,31 @@ app.use('/impression-proxy/', function(req, res) {
// Example:
// http://localhost:8000/max/s/www.washingtonpost.com/amphtml/news/post-politics/wp/2016/02/21/bernie-sanders-says-lower-turnout-contributed-to-his-nevada-loss-to-hillary-clinton/
app.use('/max/', function(req, res) {
if (mode != 'max') {
Copy link
Contributor

Choose a reason for hiding this comment

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

How about we just rename it /proxy/ or /cdn/? Then, we'll just need one and we can remove /min/

if (isTest || isMax(location) || isMin(location)) {
return `${location.protocol}//${location.host}/dist`;
}
return `${location.protocol}//${location.host}/dist`;
Copy link
Contributor

Choose a reason for hiding this comment

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

I really dislike isLocalDev being passed here. At the minimum, it kills the DCE. I suppose we can live with it, at least for this PR. But if it's easy to remove, let's do.

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 don't know a good way to remove isLocalDev here 😢

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree, DCE of localDev code can be a separate project :-). I do see many code can be DCEed if we simplify our isLocalDev logic here

return path.indexOf('.min') >= 0 || path.substr(0, 5) == '/min/';
export function calculateEntryPointScriptUrl(location, entryPoint, isLocalDev) {
const base = calculateScriptBaseUrl(location, isLocalDev);
// QQQ: why we don't use .max version for test here?
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

confirmed. removed.

@zhouyx
Copy link
Contributor Author

zhouyx commented Apr 13, 2017

addressed comments from @dvoytenko. PTAL
@jridgewell would you take a look at the change related to service worker once you're available.
@bpaduch will need you to review the change on developing.md.
Thanks a lot!

### Serve Mode
There are 3 serving modes:
- MAX mode serves unminified AMP. You want to use this during normal dev. `gulp` serves MAX mode by default.
- MIN mode serves minified AMP. This is closer to the prod setup. This is only avaialable after running `gulp dist --fortesting`. Serve MIN mode by adding `--compiled` to `gulp` command.
Copy link

Choose a reason for hiding this comment

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

correct spelling of "available"

There are 3 serving modes:
- MAX mode serves unminified AMP. You want to use this during normal dev. `gulp` serves MAX mode by default.
- MIN mode serves minified AMP. This is closer to the prod setup. This is only avaialable after running `gulp dist --fortesting`. Serve MIN mode by adding `--compiled` to `gulp` command.
- CDN mode serves prod. This file would not reflect your local changes. Serve CDN mode by adding `--cdn` to `gulp` command.
Copy link

Choose a reason for hiding this comment

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

"this file" - what file? Please clarify


For each example there are 3 modes:
To switch serving mode in runtime. please to to http://localhost:8000/serve_mode=$mode. $mode can be `max/min/cdn`.
Copy link

Choose a reason for hiding this comment

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

Rewrite as:

To switch serving modes during runtime, go to http://localhost:8000/serve_mode=$mode and set the $mode to one of the following values: max, min, or cdn.

@@ -84,15 +85,14 @@ For any public AMP document like: http://output.jsbin.com/pegizoq/quiet

You can access is with the local JS at

- normal sources: http://localhost:8000/max/output.jsbin.com/pegizoq/quiet
- minified: http://localhost:8000/min/output.jsbin.com/pegizoq/quiet
http://localhost:8000/proxy/output.jsbin.com/pegizoq/quiet
Copy link

Choose a reason for hiding this comment

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

Correct wording of this section to:

For any public AMP document like http://output.jsbin.com/pegizoq/quiet, you can access it with the local JS at http://localhost:8000/proxy/output.jsbin.com/pegizoq/quiet.


When accessing `min` urls make sure you run `gulp dist` with the `--fortesting`
Note local proxy will serve minified or unminified JS based on current serve mode. When serve mode is `cdn` local proxy will serve remote JS.
Copy link

Choose a reason for hiding this comment

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

Rewrite as follows:

**Note**: The local proxy will serve minified or unminified JS based on the current serve mode. When the serve mode is cdn, the local proxy will serve remote JS.

@zhouyx
Copy link
Contributor Author

zhouyx commented Apr 21, 2017

modified doc.
Ping @jridgewell to take a look. 😄

});

// Deprecate usage of .min.html/.max.html
app.use(['/examples/*.(min|max).html', '/test/manual/*.(min|max).html',
Copy link
Contributor

Choose a reason for hiding this comment

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

app.get


app.use(bodyParser.json());

app.use('/serve_mode=:mode', function (req, res, next) {
Copy link
Contributor

Choose a reason for hiding this comment

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

app.get

process.env.SERVE_MODE = newMode;
info = '<h2>Serve mode changed to ' + newMode + '</h2>';
} else {
info = '<h2>Serve mode ' + newMode + ' is not supported. </h2>';
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: res.status(400).send(info)

process.env.SERVE_MODE = 'cdn';
util.log(util.colors.green('Serving current prod js'));
} else {
process.env.SERVE_MODE = 'max';
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: to be consistent with the flags, can we name them: compiled|cdn|default?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But I think we are more familiar with min/max. And it's not obvious right now that default is max mode.

Copy link
Contributor

Choose a reason for hiding this comment

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

But I thought this whole PR is to get rid of min/max concept, and only stay with the "compiled" concept.

@@ -28,9 +28,32 @@ var jsdom = require('jsdom');
var path = require('path');
var request = require('request');
var url = require('url');
// SERVE_MODE is defaulted to be 'max' if not specified
var mode = process.env.SERVE_MODE;
Copy link
Contributor

Choose a reason for hiding this comment

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

how about just MODE?

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 like SERVE_MODE better because we already have SERVE_PORT SERVE_HOST...

// Require url from cdn
var filePath = 'https://cdn.ampproject.org/' + fileName;
request(filePath, function(error, response) {
res.send(response);
Copy link
Contributor

Choose a reason for hiding this comment

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

Check for the error.

// This will not be useful until extension-location.js change in prod
// Require url from cdn
request(filePath, function (error, response) {
res.send(response);
Copy link
Contributor

Choose a reason for hiding this comment

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

Check for the error.

}
if (mode == 'max') {
var fileUrl = req.url;
req.url = fileUrl.substr(0, fileUrl.length - 3) + '.max.js';
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: req.url = req.url.replace(/\.js$/, '.max.js')

Copy link
Contributor

@lannka lannka left a comment

Choose a reason for hiding this comment

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

could you also change inabox.host.html, to remove the max. in iframe src.

@zhouyx
Copy link
Contributor Author

zhouyx commented Apr 28, 2017

Done. Will finally merge this after travis pass 🤓

@zhouyx zhouyx merged commit eb802dc into ampproject:master Apr 28, 2017
<script async custom-element="amp-video" src="../../../dist/v0/amp-video-0.1.max.js"></script>
<script async custom-element="amp-anim" src="https://cdn.ampproject.org/v0/amp-anim-0.1.js"></script>
<script async custom-element="amp-audio" src="https://cdn.ampproject.org/v0/amp-audio-0.1.js"></script>
<script async custom-element="amp-video" src="https://cdn.ampproject.org//amp-video-0.1.js"></script>
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing v0 here?

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.

9 participants