Skip to content

Commit

Permalink
core mode: add internalRuntimeVersion
Browse files Browse the repository at this point in the history
  • Loading branch information
samouri committed Aug 3, 2021
1 parent b31f614 commit 40eb85e
Show file tree
Hide file tree
Showing 19 changed files with 44 additions and 59 deletions.
4 changes: 2 additions & 2 deletions 3p/integration-lib.js
Expand Up @@ -24,7 +24,7 @@ import {installEmbedStateListener, manageWin} from './environment';
import {getAmpConfig, getEmbedType, getLocation} from './frame-metadata';

import {urls} from '../src/config';
import {internalRuntimeVersion} from '../src/internal-version';
import * as mode from '#core/mode';
import {
initLogConstructor,
isUserErrorMessage,
Expand Down Expand Up @@ -360,7 +360,7 @@ function lightweightErrorReport(e, isCanary) {
new Image().src =
urls.errorReporting +
'?3p=1&v=' +
encodeURIComponent(internalRuntimeVersion()) +
encodeURIComponent(mode.version()) +
'&m=' +
encodeURIComponent(e.message) +
'&ca=' +
Expand Down
6 changes: 3 additions & 3 deletions ads/google/a4a/utils.js
Expand Up @@ -28,7 +28,7 @@ import {getMode} from '../../../src/mode';
import {getOrCreateAdCid} from '../../../src/ad-cid';
import {getPageLayoutBoxBlocking} from '#core/dom/layout/page-layout-box';
import {getTimingDataSync} from '#service/variable-source';
import {internalRuntimeVersion} from '../../../src/internal-version';
import * as mode from '#core/mode';
import {parseJson} from '#core/types/object/json';
import {whenUpgradedToCustomElement} from '../../../src/amp-element-helpers';
import {createElementWithAttributes} from '#core/dom';
Expand Down Expand Up @@ -330,7 +330,7 @@ export function googlePageParameters(a4a, startTime) {
'is_amp': a4a.isXhrAllowed()
? AmpAdImplementation.AMP_AD_XHR_TO_IFRAME_OR_AMP
: AmpAdImplementation.AMP_AD_IFRAME_GET,
'amp_v': internalRuntimeVersion(),
'amp_v': mode.version(),
'd_imp': '1',
'c': getCorrelator(win, ampDoc, clientId),
'ga_cid': win.gaGlobal.cid || null,
Expand Down Expand Up @@ -834,7 +834,7 @@ export function addCsiSignalsToAmpAnalyticsConfig(
`&dt=${initTime}` +
(eids != 'null' ? `&e.${slotId}=${eids}` : '') +
(aexp ? `&aexp=${aexp}` : '') +
`&rls=${internalRuntimeVersion()}&adt.${slotId}=${adType}`;
`&rls=${mode.version()}&adt.${slotId}=${adType}`;
const isAmpSuffix = isVerifiedAmpCreative ? 'Friendly' : 'CrossDomain';
config['triggers']['continuousVisibleIniLoad'] = {
'on': 'ini-load',
Expand Down
4 changes: 2 additions & 2 deletions build-system/test-configs/dep-check-config.js
Expand Up @@ -99,12 +99,12 @@ exports.rules = [
'3p/**->src/core/types/string/url.js',
'3p/**->src/log.js',
'3p/**->src/core/dom/style.js',
'3p/**->src/core/mode/index.js',
'3p/**->src/url.js',
'3p/**->src/config.js',
'3p/**->src/mode.js',
'3p/**->src/core/types/object/json.js',
'3p/**->src/3p-frame-messaging.js',
'3p/**->src/internal-version.js',
'3p/polyfills.js->src/polyfills/math-sign.js',
'3p/polyfills.js->src/polyfills/object-assign.js',
'3p/polyfills.js->src/polyfills/object-values.js',
Expand Down Expand Up @@ -139,7 +139,7 @@ exports.rules = [
'ads/**->src/url.js',
'ads/**->src/core/dom/static-template.js',
'ads/**->src/core/dom/style.js',
'ads/**->src/internal-version.js',
'ads/**->src/core/mode/index.js',
// ads/google/a4a doesn't contain 3P ad code and should probably move
// somewhere else at some point
'ads/google/a4a/**->src/ad-cid.js',
Expand Down
2 changes: 1 addition & 1 deletion build-system/test-configs/forbidden-terms.js
Expand Up @@ -150,7 +150,7 @@ const forbiddenTermsGlobal = {
message:
'Do not use build constants directly. Instead, use the helpers in `#core/mode`.',
allowlist: [
'src/internal-version.js',
'src/core/mode/version.js',
'src/core/mode/minified.js',
'src/core/mode/prod.js',
'build-system/compile/build-constants.js',
Expand Down
Expand Up @@ -26,7 +26,7 @@ import {getBinaryType, isExperimentOn} from '#experiments';
import {getFlexibleAdSlotData} from './flexible-ad-slot-utils';
import {getOrCreateAdCid} from '../../../src/ad-cid';
import {getPageLayoutBoxBlocking} from '#core/dom/layout/page-layout-box';
import {internalRuntimeVersion} from '../../../src/internal-version';
import * as mode from '#core/mode';
import {stringHash32} from '#core/types/string';

/** @type {string} */
Expand Down Expand Up @@ -335,7 +335,7 @@ export class AmpAdNetworkValueimpressionImpl extends AmpA4A {
'is_amp': this.isXhrAllowed()
? AmpAdImplementation.AMP_AD_XHR_TO_IFRAME_OR_AMP
: AmpAdImplementation.AMP_AD_IFRAME_GET,
'amp_v': internalRuntimeVersion(),
'amp_v': mode.version(),
'd_imp': 1,
'c': getCorrelator(win, ampDoc, clientId),
'ga_cid': win.gaGlobal.cid || null,
Expand Down
4 changes: 2 additions & 2 deletions extensions/amp-addthis/0.1/amp-addthis.js
Expand Up @@ -66,7 +66,7 @@ import {
} from './addthis-utils/mode';
import {getOgImage} from './addthis-utils/meta';
import {getWidgetOverload} from './addthis-utils/get-widget-id-overloaded-with-json-for-anonymous-mode';
import {internalRuntimeVersion} from '../../../src/internal-version';
import * as mode from '#core/mode';
import {listen} from '../../../src/event-helper';
import {parseUrlDeprecated} from '../../../src/url';
import {setStyle} from '#core/dom/style';
Expand Down Expand Up @@ -302,7 +302,7 @@ class AmpAddThis extends AMP.BaseElement {
// Document has overly long cache age: go.amp.dev/issue/24848
// Adding AMP runtime version as a meaningless query param to force bust
// cached versions.
'src': `${ORIGIN}/dc/amp-addthis.html?_amp_=${internalRuntimeVersion()}`,
'src': `${ORIGIN}/dc/amp-addthis.html?_amp_=${mode.version()}`,
'id': this.widgetId_,
'pco': this.productCode_,
'containerClassName': this.containerClassName_,
Expand Down
7 changes: 2 additions & 5 deletions extensions/amp-analytics/0.1/iframe-transport.js
Expand Up @@ -19,7 +19,7 @@ import {createElementWithAttributes} from '#core/dom';
import {devAssert, user} from '../../../src/log';
import {getMode} from '../../../src/mode';
import {hasOwn} from '#core/types/object';
import {internalRuntimeVersion} from '../../../src/internal-version';
import * as mode from '#core/mode';
import {toggle} from '#core/dom/style';
import {urls} from '../../../src/config';

Expand Down Expand Up @@ -67,10 +67,7 @@ function getIframeTransportScriptUrl(ampWin, opt_forceProdUrl) {
const loc = ampWin.parent.location;
return `${loc.protocol}//${loc.host}/dist/iframe-transport-client-lib.js`;
}
return (
urls.thirdParty +
`/${internalRuntimeVersion()}/iframe-transport-client-v0.js`
);
return urls.thirdParty + `/${mode.version()}/iframe-transport-client-v0.js`;
}

/**
Expand Down
5 changes: 2 additions & 3 deletions extensions/amp-recaptcha-input/0.1/amp-recaptcha-service.js
Expand Up @@ -28,7 +28,6 @@ import {dict} from '#core/types/object';
import {getMode} from '../../../src/mode';
import {getServicePromiseForDoc} from '../../../src/service-helpers';
import {getSourceOrigin} from '../../../src/url';
import {internalRuntimeVersion} from '../../../src/internal-version';
import {listenFor, postMessage} from '../../../src/iframe-helper';
import {loadPromise} from '../../../src/event-helper';
import {removeElement} from '#core/dom';
Expand Down Expand Up @@ -301,7 +300,7 @@ export class AmpRecaptchaService {
winLocation.host +
'/dist.3p/' +
(mode.isMinified()
? `${internalRuntimeVersion()}/recaptcha`
? `${mode.version()}/recaptcha`
: 'current/recaptcha.max') +
'.html'
);
Expand Down Expand Up @@ -329,7 +328,7 @@ export class AmpRecaptchaService {
const recaptchaFrameSrc =
'https://' +
curlsSubdomain +
`.recaptcha.${urls.thirdPartyFrameHost}/${internalRuntimeVersion()}/` +
`.recaptcha.${urls.thirdPartyFrameHost}/${mode.version()}/` +
'recaptcha.html';
return recaptchaFrameSrc;
});
Expand Down
11 changes: 4 additions & 7 deletions src/3p-frame.js
Expand Up @@ -25,7 +25,6 @@ import {setStyle} from './core/dom/style';
import {dict} from './core/types/object';
import {tryParseJson} from './core/types/object/json';
import {getContextMetadata} from './iframe-attributes';
import {internalRuntimeVersion} from './internal-version';
import {dev, devAssert, user, userAssert} from './log';
import {getMode} from './mode';
import {assertHttpsUrl, parseUrlDeprecated} from './url';
Expand Down Expand Up @@ -213,9 +212,7 @@ export function getBootstrapUrl(type) {
: `./vendor/${type}.max`;
return filename + extension;
}
return `${
urls.thirdParty
}/${internalRuntimeVersion()}/vendor/${type}${extension}`;
return `${urls.thirdParty}/${mode.version()}/vendor/${type}${extension}`;
}

/**
Expand Down Expand Up @@ -285,7 +282,7 @@ export function getDefaultBootstrapBaseUrl(parentWindow, opt_srcFileBasename) {
return (
'https://' +
parentWindow.__AMP_DEFAULT_BOOTSTRAP_SUBDOMAIN +
`.${urls.thirdPartyFrameHost}/${internalRuntimeVersion()}/` +
`.${urls.thirdPartyFrameHost}/${mode.version()}/` +
`${srcFileBasename}.html`
);
}
Expand All @@ -302,7 +299,7 @@ export function getDevelopmentBootstrapBaseUrl(parentWindow, srcFileBasename) {
getAdsLocalhost(parentWindow) +
'/dist.3p/' +
(mode.isMinified()
? `${internalRuntimeVersion()}/${srcFileBasename}`
? `${mode.version()}/${srcFileBasename}`
: `current/${srcFileBasename}.max`) +
'.html'
);
Expand Down Expand Up @@ -389,7 +386,7 @@ function getCustomBootstrapBaseUrl(
parsed.origin,
meta
);
return `${url}?${internalRuntimeVersion()}`;
return `${url}?${mode.version()}`;
}

/**
Expand Down
10 changes: 4 additions & 6 deletions src/amp-shadow.js
Expand Up @@ -22,9 +22,10 @@
// src/polyfills.js must be the first import.
import './polyfills';

import * as mode from '#core/mode';

import {deactivateChunking} from './chunk';
import {doNotTrackImpression} from './impression';
import {internalRuntimeVersion} from './internal-version';
import {adoptShadowMode} from './runtime';
import {installDocService} from './service/ampdoc-impl';
import {
Expand Down Expand Up @@ -62,10 +63,7 @@ adoptShadowMode(self);
if (self.console) {
(console.info || console.log).call(
console,
`Powered by AMP ⚡ HTML shadows – Version ${internalRuntimeVersion()}`
`Powered by AMP ⚡ HTML shadows – Version ${mode.version()}`
);
}
self.document.documentElement.setAttribute(
'amp-version',
internalRuntimeVersion()
);
self.document.documentElement.setAttribute('amp-version', mode.version());
10 changes: 4 additions & 6 deletions src/amp.js
Expand Up @@ -21,13 +21,14 @@
// src/polyfills.js must be the first import.
import './polyfills';

import * as mode from '#core/mode';

import {installAutoLightboxExtension} from './auto-lightbox';
import {startupChunk} from './chunk';
import {TickLabel} from './core/constants/enums';
import {installErrorReporting} from './error-reporting';
import {fontStylesheetTimeout} from './font-stylesheet-timeout';
import {maybeTrackImpression} from './impression';
import {internalRuntimeVersion} from './internal-version';
import {getMode} from './mode';
import {preconnectToOrigin} from './preconnect';
import {installPullToRefreshBlocker} from './pull-to-refresh';
Expand Down Expand Up @@ -164,15 +165,12 @@ startupChunk(self.document, function initial() {
if (self.console) {
(console.info || console.log).call(
console,
`Powered by AMP ⚡ HTML – Version ${internalRuntimeVersion()}`,
`Powered by AMP ⚡ HTML – Version ${mode.version()}`,
self.location.href
);
}
// This code is eleminated in prod build through a babel transformer.
if (getMode().localDev) {
self.document.documentElement.setAttribute('esm', IS_ESM ? 1 : 0);
}
self.document.documentElement.setAttribute(
'amp-version',
internalRuntimeVersion()
);
self.document.documentElement.setAttribute('amp-version', mode.version());
1 change: 1 addition & 0 deletions src/core/mode/index.js
Expand Up @@ -18,3 +18,4 @@ export {isProd} from './prod';
export {isLocalDev} from './local-dev';
export {isMinified} from './minified';
export {isTest} from './test';
export {version} from './version';
4 changes: 2 additions & 2 deletions src/internal-version.js → src/core/mode/version.js
@@ -1,5 +1,5 @@
/**
* Copyright 2019 The AMP HTML Authors. All Rights Reserved.
* Copyright 2021 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.
Expand All @@ -23,6 +23,6 @@
*
* @return {string}
*/
export function internalRuntimeVersion() {
export function version() {
return INTERNAL_RUNTIME_VERSION;
}
7 changes: 4 additions & 3 deletions src/iframe-attributes.js
Expand Up @@ -13,13 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import * as mode from '#core/mode';

import {urls} from './config';
import {DomFingerprint} from './core/dom/fingerprint';
import {getLengthNumeral} from './core/dom/layout';
import {getPageLayoutBoxBlocking} from './core/dom/layout/page-layout-box';
import {dict} from './core/types/object';
import {experimentToggles, isCanary} from './experiments';
import {internalRuntimeVersion} from './internal-version';
import {getModeObject} from './mode-object';
import {Services} from './service';

Expand Down Expand Up @@ -70,10 +71,10 @@ export function getContextMetadata(
// Please also add new introduced variable
// name to the extern list.
attributes['_context'] = dict({
'ampcontextVersion': internalRuntimeVersion(),
'ampcontextVersion': mode.version(),
'ampcontextFilepath': `${
urls.thirdParty
}/${internalRuntimeVersion()}/ampcontext-v0.js`,
}/${mode.version()}/ampcontext-v0.js`,
'sourceUrl': docInfo.sourceUrl,
'referrer': referrer,
'canonicalUrl': docInfo.canonicalUrl,
Expand Down
9 changes: 3 additions & 6 deletions src/inabox/amp-inabox.js
Expand Up @@ -20,6 +20,7 @@

import '#polyfills';
import {TickLabel} from '#core/constants/enums';
import * as mode from '#core/mode';

import {Services} from '#service';
import {installDocService} from '#service/ampdoc-impl';
Expand All @@ -41,7 +42,6 @@ import {allowLongTasksInChunking, startupChunk} from '../chunk';
import {installErrorReporting} from '../error-reporting';
import {fontStylesheetTimeout} from '../font-stylesheet-timeout';
import {doNotTrackImpression} from '../impression';
import {internalRuntimeVersion} from '../internal-version';
import {getMode} from '../mode';
import {adopt} from '../runtime';
import {
Expand Down Expand Up @@ -141,11 +141,8 @@ startupChunk(self.document, function initial() {
if (self.console) {
(console.info || console.log).call(
console,
`Powered by AMP ⚡ HTML – Version ${internalRuntimeVersion()}`,
`Powered by AMP ⚡ HTML – Version ${mode.version()}`,
self.location.href
);
}
self.document.documentElement.setAttribute(
'amp-version',
internalRuntimeVersion()
);
self.document.documentElement.setAttribute('amp-version', mode.version());
3 changes: 1 addition & 2 deletions src/log.js
Expand Up @@ -27,7 +27,6 @@ import {
} from './core/error/message-helpers';
import {isArray} from './core/types';
import {once} from './core/types/function';
import {internalRuntimeVersion} from './internal-version';
import {getMode} from './mode';

const noop = () => {};
Expand Down Expand Up @@ -90,7 +89,7 @@ export function overrideLogLevel(level) {
* (Specific channel is irrelevant: message tables are invariant on internal version.)
* @return {string}
*/
const messageUrlRtv = () => `01${internalRuntimeVersion()}`;
const messageUrlRtv = () => `01${mode.version()}`;

/**
* Gets a URL to display a message on amp.dev.
Expand Down
5 changes: 2 additions & 3 deletions src/mode.js
Expand Up @@ -16,7 +16,6 @@

import * as coreMode from './core/mode';
import {parseQueryString} from './core/types/string/url';
import {internalRuntimeVersion} from './internal-version';

/**
* @typedef {{
Expand Down Expand Up @@ -77,7 +76,7 @@ function getMode_(win) {
geoOverride: hashQuery['amp-geo'],
test: coreMode.isTest(win),
log: hashQuery['log'],
version: internalRuntimeVersion(),
version: coreMode.version(),
rtvVersion: getRtvVersion(win),
};
}
Expand All @@ -97,7 +96,7 @@ function getRtvVersion(win) {
// We will default to production default `01` minor version for now.
// TODO(erwinmombay): decide whether internalRuntimeVersion should contain
// minor version.
rtvVersion = win.AMP_CONFIG?.v || `01${internalRuntimeVersion()}`;
rtvVersion = win.AMP_CONFIG?.v || `01${coreMode.version()}`;
}
return rtvVersion;
}
Expand Down

0 comments on commit 40eb85e

Please sign in to comment.