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

Fix postinstall failing on windows #770

Merged
merged 1 commit into from
May 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/optimizer/lib/fetchRuntimeParameters.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ async function fetchValidatorRules_(config) {
let rawRules = await cache.get('validator-rules');
let validatorRules;
if (!rawRules) {
config.log.debug('Downloading AMP validation rules');
validatorRules = await validatorRulesProvider.fetch();
config.log.debug('Downloaded AMP validation rules');
// We save the raw rules to make the validation rules JSON serializable
cache.set(KEY_VALIDATOR_RULES, validatorRules.raw);
} else {
Expand Down Expand Up @@ -136,8 +136,8 @@ async function fetchAmpRuntimeVersion_(context) {
const versionKey = context.ampUrlPrefix + '-' + context.lts;
let ampRuntimeData = await cache.get(versionKey);
if (!ampRuntimeData) {
context.config.log.debug('Downloading AMP runtime version');
ampRuntimeData = await fetchLatestRuntimeData_(context, versionKey);
context.config.log.debug('Downloaded AMP runtime v' + ampRuntimeData.version);
} else if (MaxAge.fromObject(ampRuntimeData.maxAge).isExpired()) {
// return the cached version, but update the cache in the background
fetchLatestRuntimeData_(versionKey, context);
Expand Down Expand Up @@ -197,12 +197,12 @@ async function downloadAmpRuntimeStyles_(config, runtimeCssUrl) {
styles = await cache.get(runtimeCssUrl);
}
if (!styles) {
config.log.debug(`Downloading AMP runtime styles from ${runtimeCssUrl}`);
const response = await config.fetch(runtimeCssUrl);
if (!response.ok) {
return null;
}
styles = await response.text();
config.log.debug(`Downloaded AMP runtime styles from ${runtimeCssUrl}`);
if (config.cache !== false) {
cache.set(runtimeCssUrl, styles);
}
Expand Down
1 change: 0 additions & 1 deletion packages/optimizer/lib/transformers/PreloadHeroImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class PreloadHeroImage {
constructor(config) {
this.log = config.log;
this.enabled = config.preloadHeroImage !== false && config.experimentPreloadHeroImage;
this.log.info('enabled', this.enabled);
}
async transform(root, params) {
if (!this.enabled || params.preloadHeroImage === false) {
Expand Down
28 changes: 28 additions & 0 deletions packages/optimizer/lib/warmup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Copyright 2020 The AMP HTML Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS-IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

const AmpOptimizer = require('../');
const ampOptimizer = AmpOptimizer.create();

async function warmupCaches() {
// run a dummy transformation to pre-fill the caches
await ampOptimizer.transformHtml('<h1>hello world</h1>', {
canonical: '.',
});
ampOptimizer.config.log.info('Downloading latest AMP runtime data');
}

warmupCaches();
5 changes: 2 additions & 3 deletions packages/optimizer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@
"directory": "packages/optimizer"
},
"scripts": {
"postinstall": "scripts/init.js"
"postinstall": "node lib/warmup.js"
},
"files": [
"index.js",
"lib",
"scripts"
"lib"
],
"keywords": [
"amp"
Expand Down
13 changes: 0 additions & 13 deletions packages/optimizer/scripts/init.js

This file was deleted.