Skip to content

Commit

Permalink
convert to ES modules (#354)
Browse files Browse the repository at this point in the history
* convert to ES modules
  • Loading branch information
connorjclark authored Jul 29, 2022
1 parent 5a4e409 commit 8073f1c
Show file tree
Hide file tree
Showing 94 changed files with 1,440 additions and 594 deletions.
20 changes: 10 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ jobs:
steps:
- name: git clone
uses: actions/checkout@v2
- name: Use Node.js 12.x
- name: Use Node.js 14.x
uses: actions/setup-node@v1
with:
node-version: 12.x
node-version: 14.x
- run: yarn install --frozen-lockfile --network-timeout 1000000
- run: yarn lint

This comment has been minimized.

Copy link
@facebook032

Expand All @@ -23,10 +23,10 @@ jobs:
steps:
- name: git clone
uses: actions/checkout@v2
- name: Use Node.js 12.x
- name: Use Node.js 14.x
uses: actions/setup-node@v1
with:
node-version: 12.x
node-version: 14.x
- run: yarn install --frozen-lockfile --network-timeout 1000000
- run: yarn type-check

Expand All @@ -36,10 +36,10 @@ jobs:
steps:
- name: git clone
uses: actions/checkout@v2
- name: Use Node.js 12.x
- name: Use Node.js 14.x
uses: actions/setup-node@v1
with:
node-version: 12.x
node-version: 14.x
- run: yarn install --frozen-lockfile --network-timeout 1000000
- run: yarn test

Expand All @@ -49,10 +49,10 @@ jobs:
steps:
- name: git clone
uses: actions/checkout@v2
- name: Use Node.js 12.x
- name: Use Node.js 14.x
uses: actions/setup-node@v1
with:
node-version: 12.x
node-version: 14.x
- run: yarn install --frozen-lockfile --network-timeout 1000000
- run: sudo apt-get install xvfb
- name: Run smoke tests
Expand All @@ -64,10 +64,10 @@ jobs:
steps:
- name: git clone
uses: actions/checkout@v2
- name: Use Node.js 12.x
- name: Use Node.js 14.x
uses: actions/setup-node@v1
with:
node-version: 12.x
node-version: 14.x
- name: npm install
run: npm install
- name: Install Lighthouse CI
Expand Down
4 changes: 3 additions & 1 deletion config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* https://github.com/GoogleChrome/lighthouse/tree/master/lighthouse-core/config
* @const {LH.Config}
*/
module.exports = {
const config = {
extends: 'lighthouse:default',
plugins: ['lighthouse-plugin-publisher-ads'],
passes: [
Expand All @@ -29,3 +29,5 @@ module.exports = {
},
],
};

export default config;
3 changes: 2 additions & 1 deletion index.js → index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ async function main() {
}

// @ts-ignore let LH handle the CLI
await require('lighthouse/lighthouse-cli/bin.js').begin();
const {begin} = await import('lighthouse/lighthouse-cli/bin.js');
await begin();
}

if (require.main == module) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,13 @@ module.exports = {
node: true,
mocha: true,
},
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 2018,
ecmaVersion: 2020,
ecmaFeatures: {
globalReturn: true,
jsx: false,
},
sourceType: 'script',
},
rules: {
Expand All @@ -29,6 +34,7 @@ module.exports = {
{'MemberExpression': 2},
],
'max-len': ['error', 80, {
ignorePattern: '^import |/override',
ignoreStrings: true,
ignoreUrls: true,
}],
Expand Down
22 changes: 11 additions & 11 deletions lighthouse-plugin-publisher-ads/audits/ad-blocking-tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.

const AdRequestTime = require('../computed/ad-request-time');
const i18n = require('lighthouse/lighthouse-core/lib/i18n/i18n.js');
const LongTasks = require('../computed/long-tasks');
const {auditNotApplicable} = require('../messages/common-strings');
const {Audit} = require('lighthouse');
const {getAttributableUrl} = require('../utils/tasks');
const {isAdScript} = require('../utils/resource-classification');
import AdRequestTime from '../computed/ad-request-time.js';

import * as i18n from 'lighthouse/lighthouse-core/lib/i18n/i18n.js';
import LongTasks from '../computed/long-tasks.js';
import {auditNotApplicable} from '../messages/common-strings.js';
import {Audit} from 'lighthouse';
import {getAttributableUrl} from '../utils/tasks.js';
import {isAdScript} from '../utils/resource-classification.js';

const UIStrings = {
/* Title of the audit */
Expand All @@ -31,7 +32,7 @@ const UIStrings = {
columnDuration: 'Duration',
};

const str_ = i18n.createMessageInstanceIdFn(__filename, UIStrings);
const str_ = i18n.createMessageInstanceIdFn(import.meta.url, UIStrings);
/**
* @typedef {Object} TaskDetails
* @property {number} startTime
Expand Down Expand Up @@ -70,7 +71,6 @@ const HEADINGS = [
class AdBlockingTasks extends Audit {
/**
* @return {LH.Audit.Meta}
* @override
*/
static get meta() {
return {
Expand Down Expand Up @@ -170,5 +170,5 @@ class AdBlockingTasks extends Audit {
}
}

module.exports = AdBlockingTasks;
module.exports.UIStrings = UIStrings;
export default AdBlockingTasks;
export {UIStrings};
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@
// See the License for the specific language governing permissions and
// limitations under the License.

const i18n = require('lighthouse/lighthouse-core/lib/i18n/i18n.js');
const NetworkRecords = require('lighthouse/lighthouse-core/computed/network-records.js');
import * as i18n from 'lighthouse/lighthouse-core/lib/i18n/i18n.js';

import NetworkRecords from 'lighthouse/lighthouse-core/computed/network-records.js';

// @ts-ignore
const {auditNotApplicable} = require('../messages/common-strings');
const {Audit} = require('lighthouse');
const {getTimingsByRecord} = require('../utils/network-timing');
const {isAdTag} = require('../utils/resource-classification');
import {auditNotApplicable} from '../messages/common-strings.js';

import {Audit} from 'lighthouse';
import {getTimingsByRecord} from '../utils/network-timing.js';
import {isAdTag} from '../utils/resource-classification.js';

const UIStrings = {
title: 'Minimal render-blocking resources found',
Expand All @@ -38,7 +41,7 @@ const UIStrings = {
/** @typedef {LH.Artifacts.NetworkRequest} NetworkRequest */
/** @typedef {LH.Gatherer.Simulation.NodeTiming} NodeTiming */

const str_ = i18n.createMessageInstanceIdFn(__filename, UIStrings);
const str_ = i18n.createMessageInstanceIdFn(import.meta.url, UIStrings);

const THRESHOLD_MS = 100;

Expand Down Expand Up @@ -70,7 +73,6 @@ const HEADINGS = [
class AdRenderBlockingResources extends Audit {
/**
* @return {LH.Audit.Meta}
* @override
*/
static get meta() {
return {
Expand Down Expand Up @@ -165,5 +167,5 @@ class AdRenderBlockingResources extends Audit {
}
}

module.exports = AdRenderBlockingResources;
module.exports.UIStrings = UIStrings;
export default AdRenderBlockingResources;
export {UIStrings};
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.

const i18n = require('lighthouse/lighthouse-core/lib/i18n/i18n.js');
const {auditNotApplicable} = require('../messages/common-strings');
const {Audit} = require('lighthouse');
const {computeAdRequestWaterfall} = require('../utils/graph');
import * as i18n from 'lighthouse/lighthouse-core/lib/i18n/i18n.js';

import {auditNotApplicable} from '../messages/common-strings.js';
import {Audit} from 'lighthouse';
import {computeAdRequestWaterfall} from '../utils/graph.js';

/** @typedef {LH.Gatherer.Simulation.NodeTiming} NodeTiming */
/** @typedef {import('../utils/graph').SimpleRequest} SimpleRequest */
/** @typedef {import('../utils/graph.js').SimpleRequest} SimpleRequest */

const UIStrings = {
title: 'Ad request waterfall',
Expand All @@ -35,7 +36,7 @@ const UIStrings = {
columnEndTime: 'End',
};

const str_ = i18n.createMessageInstanceIdFn(__filename, UIStrings);
const str_ = i18n.createMessageInstanceIdFn(import.meta.url, UIStrings);

/**
* Table headings for audits details sections.
Expand Down Expand Up @@ -118,7 +119,6 @@ function computeIdleTimes(blockingRequests) {
class AdRequestCriticalPath extends Audit {
/**
* @return {LH.Audit.Meta}
* @override
*/
static get meta() {
return {
Expand Down Expand Up @@ -173,5 +173,5 @@ class AdRequestCriticalPath extends Audit {
}
}

module.exports = AdRequestCriticalPath;
module.exports.UIStrings = UIStrings;
export default AdRequestCriticalPath;
export {UIStrings};
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.

const ComputedAdRequestTime = require('../computed/ad-request-time');
const i18n = require('lighthouse/lighthouse-core/lib/i18n/i18n.js');
const {auditNotApplicable, runWarning} = require('../messages/common-strings');
const {Audit} = require('lighthouse');
import ComputedAdRequestTime from '../computed/ad-request-time.js';

import * as i18n from 'lighthouse/lighthouse-core/lib/i18n/i18n.js';
import {auditNotApplicable, runWarning} from '../messages/common-strings.js';
import {Audit} from 'lighthouse';

const UIStrings = {
title: 'First ad request time',
Expand All @@ -29,15 +30,14 @@ const UIStrings = {
displayValue: '{timeInMs, number, seconds} s',
};

const str_ = i18n.createMessageInstanceIdFn(__filename, UIStrings);
const str_ = i18n.createMessageInstanceIdFn(import.meta.url, UIStrings);

/**
* Audit to determine time for first ad request relative to page start.
*/
class AdRequestFromPageStart extends Audit {
/**
* @return {LH.Audit.Meta}
* @override
*/
static get meta() {
return {
Expand Down Expand Up @@ -102,5 +102,5 @@ class AdRequestFromPageStart extends Audit {
}
}

module.exports = AdRequestFromPageStart;
module.exports.UIStrings = UIStrings;
export default AdRequestFromPageStart;
export {UIStrings};
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.

const ComputedAdRequestTime = require('../computed/ad-request-time');
const ComputedTagLoadTime = require('../computed/tag-load-time');
const i18n = require('lighthouse/lighthouse-core/lib/i18n/i18n.js');
const {auditNotApplicable} = require('../messages/common-strings');
const {Audit} = require('lighthouse');
import ComputedAdRequestTime from '../computed/ad-request-time.js';

import ComputedTagLoadTime from '../computed/tag-load-time.js';
import * as i18n from 'lighthouse/lighthouse-core/lib/i18n/i18n.js';
import {auditNotApplicable} from '../messages/common-strings.js';
import {Audit} from 'lighthouse';

const UIStrings = {
title: 'Latency of first ad request, from tag load',
Expand All @@ -28,15 +29,14 @@ const UIStrings = {
displayValue: '{timeInMs, number, seconds} s',
};

const str_ = i18n.createMessageInstanceIdFn(__filename, UIStrings);
const str_ = i18n.createMessageInstanceIdFn(import.meta.url, UIStrings);

/**
* Audit to determine time for first ad request relative to tag load.
*/
class AdRequestFromTagLoad extends Audit {
/**
* @return {LH.Audit.Meta}
* @override
*/
static get meta() {
return {
Expand Down Expand Up @@ -105,5 +105,5 @@ class AdRequestFromTagLoad extends Audit {
}
}

module.exports = AdRequestFromTagLoad;
module.exports.UIStrings = UIStrings;
export default AdRequestFromTagLoad;
export {UIStrings};
16 changes: 8 additions & 8 deletions lighthouse-plugin-publisher-ads/audits/ad-top-of-viewport.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.

const i18n = require('lighthouse/lighthouse-core/lib/i18n/i18n.js');
const {auditNotApplicable} = require('../messages/common-strings');
const {Audit} = require('lighthouse');
const {isAdIframe} = require('../utils/resource-classification');
import * as i18n from 'lighthouse/lighthouse-core/lib/i18n/i18n.js';

import {auditNotApplicable} from '../messages/common-strings.js';
import {Audit} from 'lighthouse';
import {isAdIframe} from '../utils/resource-classification.js';

const UIStrings = {
title: 'No ad found at the very top of the viewport',
Expand All @@ -30,7 +31,7 @@ const UIStrings = {
columnSlot: 'Top Slot ID',
};

const str_ = i18n.createMessageInstanceIdFn(__filename, UIStrings);
const str_ = i18n.createMessageInstanceIdFn(import.meta.url, UIStrings);


const SCROLL_PX_THRESHOLD = 100;
Expand All @@ -48,7 +49,6 @@ const HEADINGS = [
class AdTopOfViewport extends Audit {
/**
* @return {AuditMetadata}
* @override
*/
static get meta() {
return {
Expand Down Expand Up @@ -105,5 +105,5 @@ class AdTopOfViewport extends Audit {
}
}

module.exports = AdTopOfViewport;
module.exports.UIStrings = UIStrings;
export default AdTopOfViewport;
export {UIStrings};
Loading

0 comments on commit 8073f1c

Please sign in to comment.