-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Conversation
export function calculateEntryPointScriptUrl(location, entryPoint, isLocalDev, | ||
isTest) { | ||
const base = calculateScriptBaseUrl(location, isLocalDev, isTest); | ||
const serveMax = isLocalDev && isMax(location); |
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.
@choumx @jridgewell any ideas why we don't take isTest
into consideration here?
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.
Probably just an oversight (or deemed unnecessary). We'd also need isUsingCompiledJs
to make sure we test min builds with --compiled
here.
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 news is with this PR, gulp server will use min files with --compiled
flag. we don't need to deal with isUsingCompiledJs
anymore.
build-system/tasks/serve.js
Outdated
@@ -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'; |
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.
Could we make this changeable at runtime?
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 can add the check for app.use('/serve_mode=?')
to change it at runtime. If this is what you mean?
Yep.
…On Tue, Apr 4, 2017 at 10:33 AM, Yuxuan Zhou ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In build-system/tasks/serve.js
<#8559 (comment)>:
> @@ -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';
I can add the check for app.use('/serve_mode=?') to change it at runtime.
If this is what you mean?
—
You are receiving this because your review was requested.
Reply to this email directly, view it on GitHub
<#8559 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAFeT9YiXgAnBk3ph9zgcfPHEC4P_AF3ks5rsn7ogaJpZM4MyDcK>
.
|
PTAL 👀 |
Ping~ |
Friendly ping on this PR. @cramforce Do we still want to keep it? : ) |
I'm just waiting for others to review :) |
LOLOL 😄 Ping @erwinmombay @lannka and @dvoytenko |
build-system/app.js
Outdated
@@ -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; |
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.
Can you document here what's default is?
build-system/app.js
Outdated
process.env.SERVE_MODE = newMode; | ||
info = '<h2>Serve mode changed to ' + newMode + '</h2>'; | ||
} else { | ||
info = '<h2>Serve mode ' + newMode + ' is not support. </h2>'; |
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.
"ed"
build-system/app.js
Outdated
@@ -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') { |
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.
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`; |
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 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.
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 don't know a good way to remove isLocalDev
here 😢
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.
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
src/service/extension-location.js
Outdated
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? |
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.
Remove?
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.
confirmed. removed.
addressed comments from @dvoytenko. PTAL |
contributing/DEVELOPING.md
Outdated
### 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. |
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.
correct spelling of "available"
contributing/DEVELOPING.md
Outdated
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. |
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.
"this file" - what file? Please clarify
contributing/DEVELOPING.md
Outdated
|
||
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`. |
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.
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
.
contributing/DEVELOPING.md
Outdated
@@ -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 |
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.
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.
contributing/DEVELOPING.md
Outdated
|
||
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. |
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.
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.
modified doc. |
build-system/app.js
Outdated
}); | ||
|
||
// Deprecate usage of .min.html/.max.html | ||
app.use(['/examples/*.(min|max).html', '/test/manual/*.(min|max).html', |
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.
app.get
build-system/app.js
Outdated
|
||
app.use(bodyParser.json()); | ||
|
||
app.use('/serve_mode=:mode', function (req, res, next) { |
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.
app.get
build-system/app.js
Outdated
process.env.SERVE_MODE = newMode; | ||
info = '<h2>Serve mode changed to ' + newMode + '</h2>'; | ||
} else { | ||
info = '<h2>Serve mode ' + newMode + ' is not supported. </h2>'; |
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.
nit: res.status(400).send(info)
build-system/tasks/serve.js
Outdated
process.env.SERVE_MODE = 'cdn'; | ||
util.log(util.colors.green('Serving current prod js')); | ||
} else { | ||
process.env.SERVE_MODE = 'max'; |
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.
nit: to be consistent with the flags, can we name them: compiled|cdn|default
?
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.
But I think we are more familiar with min
/max
. And it's not obvious right now that default
is max
mode.
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.
But I thought this whole PR is to get rid of min/max concept, and only stay with the "compiled" concept.
build-system/app.js
Outdated
@@ -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; |
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.
how about just MODE
?
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 like SERVE_MODE
better because we already have SERVE_PORT
SERVE_HOST
...
build-system/app.js
Outdated
// Require url from cdn | ||
var filePath = 'https://cdn.ampproject.org/' + fileName; | ||
request(filePath, function(error, response) { | ||
res.send(response); |
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.
Check for the error.
build-system/app.js
Outdated
// This will not be useful until extension-location.js change in prod | ||
// Require url from cdn | ||
request(filePath, function (error, response) { | ||
res.send(response); |
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.
Check for the error.
build-system/app.js
Outdated
} | ||
if (mode == 'max') { | ||
var fileUrl = req.url; | ||
req.url = fileUrl.substr(0, fileUrl.length - 3) + '.max.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.
Nit: req.url = req.url.replace(/\.js$/, '.max.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.
could you also change inabox.host.html, to remove the max.
in iframe src.
Done. Will finally merge this after travis pass 🤓 |
<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> |
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.
Missing v0 here?
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?