-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
misc: convert lighthouse-core/scripts to ES modules #13121
Changes from 8 commits
ba34039
e722927
8bde7be
e2719ff
d18d7b6
c9327b8
aea3fb3
a04f2c9
3bb245e
3bb604b
361c16c
80ee57e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* @license Copyright 2021 The Lighthouse 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. | ||
*/ | ||
'use strict'; | ||
|
||
module.exports = { | ||
env: { | ||
browser: true, | ||
}, | ||
rules: { | ||
// TODO(esmodules): move to root eslint when all code is ESM | ||
// or when this is resolved: https://github.com/import-js/eslint-plugin-import/issues/2214 | ||
'import/order': [2, { | ||
'groups': [ | ||
'builtin', | ||
'external', | ||
['sibling', 'parent'], | ||
'index', | ||
'object', | ||
'type', | ||
], | ||
'newlines-between': 'always', | ||
}], | ||
}, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file may later find its way into There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Definitely will though I imagine might need more context/bundle awareness |
||
* @license Copyright 2021 The Lighthouse 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. | ||
*/ | ||
'use strict'; | ||
|
||
import module from 'module'; | ||
|
||
const require = module.createRequire(import.meta.url); | ||
|
||
/** | ||
* Commonjs equivalent of `require.resolve`. | ||
* @param {string} packageName | ||
*/ | ||
export function resolveModulePath(packageName) { | ||
return require.resolve(packageName); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,17 +8,21 @@ | |
|
||
/* eslint-disable no-console, max-len */ | ||
|
||
const fs = require('fs'); | ||
const glob = require('glob'); | ||
const path = require('path'); | ||
const expect = require('expect'); | ||
const tsc = require('typescript'); | ||
const MessageParser = require('intl-messageformat-parser').default; | ||
const Util = require('../../../lighthouse-core/util-commonjs.js'); | ||
const {collectAndBakeCtcStrings} = require('./bake-ctc-to-lhl.js'); | ||
const {pruneObsoleteLhlMessages} = require('./prune-obsolete-lhl-messages.js'); | ||
const {countTranslatedMessages} = require('./count-translated.js'); | ||
const {LH_ROOT} = require('../../../root.js'); | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
|
||
import glob from 'glob'; | ||
import expect from 'expect'; | ||
import tsc from 'typescript'; | ||
import MessageParser from 'intl-messageformat-parser'; | ||
import esMain from 'es-main'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. need to add this to our dev deps There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
haha oh right |
||
|
||
import Util from '../../../lighthouse-core/util-commonjs.js'; | ||
import {collectAndBakeCtcStrings} from './bake-ctc-to-lhl.js'; | ||
import {pruneObsoleteLhlMessages} from './prune-obsolete-lhl-messages.js'; | ||
import {countTranslatedMessages} from './count-translated.js'; | ||
import {LH_ROOT} from '../../../root.js'; | ||
import {resolveModulePath} from '../esm-utils.js'; | ||
|
||
const UISTRINGS_REGEX = /UIStrings = .*?\};\n/s; | ||
|
||
|
@@ -30,7 +34,7 @@ const foldersWithStrings = [ | |
`${LH_ROOT}/lighthouse-core`, | ||
`${LH_ROOT}/report/renderer`, | ||
`${LH_ROOT}/lighthouse-treemap`, | ||
path.dirname(require.resolve('lighthouse-stack-packs')) + '/packs', | ||
path.dirname(resolveModulePath('lighthouse-stack-packs')) + '/packs', | ||
]; | ||
|
||
const ignoredPathComponents = [ | ||
|
@@ -722,14 +726,14 @@ async function main() { | |
} | ||
|
||
// Test if called from the CLI or as a module. | ||
if (require.main === module) { | ||
if (esMain(import.meta)) { | ||
main().catch(err => { | ||
console.error(err.stack); | ||
process.exit(1); | ||
}); | ||
} | ||
|
||
module.exports = { | ||
export { | ||
parseUIStrings, | ||
createPsuedoLocaleStrings, | ||
convertMessageToCtc, | ||
|
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.
drive by changes... I was hoping these changes would be enough to pass Node's commonjs named exports heuristics, but it was not. Anyhow, these properties don't need to use renaming syntax.