Skip to content

Commit

Permalink
chore: support type only import in custom linter
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack-Works committed Mar 24, 2020
1 parent 80f0c63 commit 2f72848
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 21 deletions.
6 changes: 3 additions & 3 deletions public/firefoxFix.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,18 @@
const PatchThisOfDescriptorToGlobal = (desc, global) => {
const { get, set, value } = desc
if (get)
desc.get = function() {
desc.get = function () {
if (this === globalThis) return get.apply(window)
return get.apply(this)
}
if (set)
desc.set = function(val) {
desc.set = function (val) {
if (this === globalThis) return set.apply(global, val)
return set.apply(this, val)
}
if (value && typeof value === 'function') {
const desc2 = Object.getOwnPropertyDescriptors(value)
desc.value = function(...args) {
desc.value = function (...args) {
if (new.target) return Reflect.construct(value, args, new.target)
return Reflect.apply(value, this === globalThis ? global : this, args)
}
Expand Down
7 changes: 4 additions & 3 deletions scripts/import-linter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ if (diags) {
}

function getChecker(): (path: string) => string | null {
return x => {
return (x) => {
if (x.includes('@material-ui')) {
return `@material-ui appears in the import chain!
To write a cross context file, use safeMUI() inside the function to import them conditionally.
Expand Down Expand Up @@ -55,6 +55,7 @@ function checkReferenceRecursive(
for (const dependency of file.getImportDeclarations()) {
let isTypeOnlyImport = true

if (dependency.compilerNode?.importClause.isTypeOnly) continue
// We consider default import and ns import is not type only import
if (dependency.getDefaultImport() || dependency.getNamespaceImport()) {
isTypeOnlyImport = false
Expand Down Expand Up @@ -97,7 +98,7 @@ function checkReferenceRecursive(
esModuleStyleImport.push(path)
}
const nodeStyleRequires: string[] = []
file.transform(traversal => {
file.transform((traversal) => {
const node = traversal.visitChildren()
// require('...')
if (!ts.ts.isCallExpression(node)) return node
Expand Down Expand Up @@ -125,7 +126,7 @@ function checkReferenceRecursive(
if (diag) {
console.error(`${diag}
Import chain:
${nextRefChain.map(x => ' => ' + x).join('\n')}
${nextRefChain.map((x) => ' => ' + x).join('\n')}
`)
hasDiagnostics = true
}
Expand Down
6 changes: 3 additions & 3 deletions scripts/jest-global-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ module.exports = async () => {
}

function addAsmCryptoForTest(cb) {
var download = function(url, dest, cb) {
var download = function (url, dest, cb) {
var file = fs.createWriteStream(dest)
var request = http.get(url, function(response) {
var request = http.get(url, function (response) {
response.pipe(file)
file.on('finish', function() {
file.on('finish', function () {
file.close(cb)
})
})
Expand Down
2 changes: 1 addition & 1 deletion scripts/puppeteer-repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const pptOpts = {
function findChrome() {
try {
const clBase = path.join(require.resolve('chrome-launcher'), '..')
global.clInt = x => require(path.join(clBase, `${x}.js`))
global.clInt = (x) => require(path.join(clBase, `${x}.js`))
return clInt('chrome-finder')[clInt('utils').getPlatform()]()[0]
} catch (e) {
console.error(e)
Expand Down
22 changes: 11 additions & 11 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin')
const ForkTsCheckerNotifierWebpackPlugin = require('fork-ts-checker-notifier-webpack-plugin')
const git = require('@nice-labs/git-rev').default

const src = file => path.join(__dirname, file)
const src = (file) => path.join(__dirname, file)
/**
* Polyfills that needs to be copied to dist
*/
Expand Down Expand Up @@ -36,21 +36,21 @@ const ManifestGeneratorPlugin = require('webpack-extension-manifest-plugin')
* --wk-webview
* --e2e
*/
const calcTarget = argv => ({
const calcTarget = (argv) => ({
/** @type {'nightly' | boolean} */
Firefox: (argv.firefox || argv['firefox-android'] || argv['firefox-gecko']),
Firefox: argv.firefox || argv['firefox-android'] || argv['firefox-gecko'],
/** @type {string | boolean} */
FirefoxDesktop: (argv.firefox),
FirefoxDesktop: argv.firefox,
/** @type {boolean} */
FirefoxForAndroid: (argv['firefox-android']),
FirefoxForAndroid: argv['firefox-android'],
/** @type {boolean} */
StandaloneGeckoView: (argv['firefox-gecko']),
StandaloneGeckoView: argv['firefox-gecko'],
/** @type {boolean} */
Chromium: (argv.chromium),
Chromium: argv.chromium,
/** @type {boolean} */
WKWebview: (argv['wk-webview']),
WKWebview: argv['wk-webview'],
/** @type {boolean} */
E2E: (argv.e2e),
E2E: argv.e2e,
})

/**
Expand All @@ -61,7 +61,7 @@ module.exports = (argvEnv, argv) => {
const target = calcTarget(argv)

if (target.Firefox) {
polyfills = polyfills.filter(name => !name.includes('webextension-polyfill'))
polyfills = polyfills.filter((name) => !name.includes('webextension-polyfill'))
}
if (target.StandaloneGeckoView || target.WKWebview) polyfills.push(require.resolve('./src/polyfill/permissions.js'))

Expand Down Expand Up @@ -294,7 +294,7 @@ module.exports = (argvEnv, argv) => {
if (!fs.existsSync(publicPolyfill)) {
fs.mkdirSync(publicPolyfill)
}
polyfills.map(x => void fs.copyFileSync(x, path.join(publicPolyfill, path.basename(x))))
polyfills.map((x) => void fs.copyFileSync(x, path.join(publicPolyfill, path.basename(x))))

if (env !== 'development') {
config.plugins.push(new SSRPlugin('popup.html', src('./src/extension/popup-page/index.tsx')))
Expand Down

0 comments on commit 2f72848

Please sign in to comment.