From 1c18a072b680f61e25e580245bb919c65c37ad89 Mon Sep 17 00:00:00 2001 From: Tim van der Lippe Date: Thu, 28 Jun 2018 12:31:16 +0200 Subject: [PATCH 1/3] [polyserve] Do not compile for request urls with ?nocompile --- packages/polyserve/src/compile-middleware.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/polyserve/src/compile-middleware.ts b/packages/polyserve/src/compile-middleware.ts index a5e1a3304..4427a8828 100644 --- a/packages/polyserve/src/compile-middleware.ts +++ b/packages/polyserve/src/compile-middleware.ts @@ -38,6 +38,8 @@ const compileMimeTypes = [htmlMimeType, ...javaScriptMimeTypes]; // but not their tests. export const isPolyfill = /(^|\/)webcomponentsjs\/[^\/]+$/; +const shouldNotCompile = /\?nocompile$/; + function getContentType(response: Response) { const contentTypeHeader = response.get('Content-Type'); return contentTypeHeader && parseContentType(contentTypeHeader).type; @@ -72,6 +74,9 @@ export function babelCompile( if (isPolyfill.test(request.url)) { return false; } + if (shouldNotCompile.test(request.url)) { + return false; + } if (!compileMimeTypes.includes(getContentType(response))) { return false; } From 8d6335af35b477304cb122f0c1a54bb6c4cfe8a2 Mon Sep 17 00:00:00 2001 From: Tim van der Lippe Date: Sat, 30 Jun 2018 23:41:20 +0200 Subject: [PATCH 2/3] Use request.query instead --- packages/polyserve/src/compile-middleware.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/polyserve/src/compile-middleware.ts b/packages/polyserve/src/compile-middleware.ts index 4427a8828..536438d40 100644 --- a/packages/polyserve/src/compile-middleware.ts +++ b/packages/polyserve/src/compile-middleware.ts @@ -38,8 +38,6 @@ const compileMimeTypes = [htmlMimeType, ...javaScriptMimeTypes]; // but not their tests. export const isPolyfill = /(^|\/)webcomponentsjs\/[^\/]+$/; -const shouldNotCompile = /\?nocompile$/; - function getContentType(response: Response) { const contentTypeHeader = response.get('Content-Type'); return contentTypeHeader && parseContentType(contentTypeHeader).type; @@ -74,7 +72,7 @@ export function babelCompile( if (isPolyfill.test(request.url)) { return false; } - if (shouldNotCompile.test(request.url)) { + if ('nocompile' in request.query) { return false; } if (!compileMimeTypes.includes(getContentType(response))) { From 8c800735629d12cff87d5a324a4ec072e38d7c7e Mon Sep 17 00:00:00 2001 From: Tim van der Lippe Date: Sat, 30 Jun 2018 23:50:37 +0200 Subject: [PATCH 3/3] [ci skip] Add Changelog --- packages/polyserve/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/polyserve/CHANGELOG.md b/packages/polyserve/CHANGELOG.md index 7b6082214..8dc0317e4 100644 --- a/packages/polyserve/CHANGELOG.md +++ b/packages/polyserve/CHANGELOG.md @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). +* Allow file requests to specify `?nocompile` to prevent any compilation ## [0.27.12] (2018-06-28) * Updated dependencies.