Skip to content

Commit

Permalink
New: Enable compat-api hints by default
Browse files Browse the repository at this point in the history
  • Loading branch information
antross committed Feb 11, 2019
1 parent 9388423 commit 38fd2bc
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 7 deletions.
5 changes: 4 additions & 1 deletion packages/extension-browser/package.json
Expand Up @@ -9,7 +9,8 @@
"description": "webhint browser extension",
"devDependencies": {
"@hint/hint-axe": "^2.1.1",
"@hint/hint-button-type": "^1.0.1",
"@hint/hint-button-type": "^2.0.0",
"@hint/hint-compat-api": "^2.0.1",
"@hint/hint-content-type": "^3.0.0",
"@hint/hint-css-prefix-order": "^1.0.0",
"@hint/hint-disown-opener": "^2.1.1",
Expand Down Expand Up @@ -52,6 +53,7 @@
"html-minifier": "^3.5.21",
"is-ci": "^2.0.0",
"lodash": "^4.17.11",
"mdn-browser-compat-data": "^0.0.66",
"npm-run-all": "^4.1.5",
"nyc": "^13.2.0",
"puppeteer": "^1.12.2",
Expand Down Expand Up @@ -102,6 +104,7 @@
"prebuild:css": "tcm src",
"prebuild:hints": "node ./scripts/import-hints.js",
"prebuild:i18n": "node ./scripts/create-i18n.js",
"prebuild:mdn": "node ./scripts/pack-mdn-data.js",
"test": "npm run lint && npm run build && npm run test-only",
"test-only": "nyc ava",
"watch": "npm run build && npm-run-all --parallel -c watch:*",
Expand Down
12 changes: 10 additions & 2 deletions packages/extension-browser/scripts/import-hints.js
Expand Up @@ -13,10 +13,14 @@ const hints = `// autogenerated by scripts/import-hints.js
import { IHintConstructor } from 'hint/dist/src/lib/types';
const resolve = (module: any): IHintConstructor => {
return module.default || module;
};
const hints = [
${
hintModules.map((name) => {
return ` ...Object.values<IHintConstructor>(require('${name}'))`;
return ` ...Object.values(require('${name}')).map(resolve)`;
}).join(',\n')
}
];
Expand All @@ -39,10 +43,14 @@ const metas = `// autogenerated by scripts/import-hints.js
import { HintMetadata } from 'hint/dist/src/lib/types';
const resolve = (module: any): HintMetadata => {
return module.default || module;
};
const metas = [
${
hintModules.map((name) => {
return ` ...Object.values<HintMetadata>(require('${name}/dist/src/meta'))`;
return ` ...Object.values(require('${name}/dist/src/meta')).map(resolve)`;
}).join(',\n')
}
];
Expand Down
16 changes: 16 additions & 0 deletions packages/extension-browser/scripts/pack-mdn-data.js
@@ -0,0 +1,16 @@
const fs = require('fs');
const mdn = require('mdn-browser-compat-data');
const path = require('path');
const filename = path.resolve(`${__dirname}/../dist/mdn-browser-compat-data.packed.json`);

fs.writeFile(filename, JSON.stringify({
browsers: mdn.browsers,
css: mdn.css,
html: mdn.html
}), (err) => {
if (err) {
throw err;
} else {
console.log(`Created: ${filename}`);
}
});
8 changes: 5 additions & 3 deletions packages/extension-browser/src/content-script/connector.ts
Expand Up @@ -20,6 +20,7 @@ export default class WebExtensionConnector implements IConnector {
private _document = new AsyncHTMLDocument(document);
private _window = new AsyncWindow(this._document); // eslint-disable-line
private _engine: Engine;
private _onComplete: (resource: string) => void = () => { };
private _options: ConnectorOptionsConfig;

public constructor(engine: Engine, options?: ConnectorOptionsConfig) {
Expand Down Expand Up @@ -53,7 +54,7 @@ export default class WebExtensionConnector implements IConnector {
await this._engine.emitAsync('traverse::end', { resource });
}

await this._engine.emitAsync('scan::end', { resource });
this._onComplete(resource);
}, this._options.waitFor);
};

Expand Down Expand Up @@ -159,10 +160,11 @@ export default class WebExtensionConnector implements IConnector {
this.sendMessage({ ready: true });

return new Promise((resolve) => {
this._engine.once('scan::end', () => {
this._onComplete = async (resource: string) => {
await this._engine.emitAsync('scan::end', { resource });
resolve();
this.sendMessage({ done: true });
});
};
});
}

Expand Down
2 changes: 1 addition & 1 deletion packages/extension-browser/src/content-script/webhint.ts
Expand Up @@ -71,7 +71,7 @@ const main = async (userConfig: Config) => {
hints: hintsConfig,
hintsTimeout: 10000,
ignoredUrls: determineIgnoredUrls(userConfig.ignoredUrls),
parsers: ['javascript', 'manifest']
parsers: ['css', 'javascript', 'manifest']
};

const resources: HintResources = {
Expand Down
1 change: 1 addition & 0 deletions packages/extension-browser/tsconfig.json
Expand Up @@ -16,6 +16,7 @@
{ "path": "../hint" },
{ "path": "../hint-axe" },
{ "path": "../hint-button-type" },
{ "path": "../hint-compat-api" },
{ "path": "../hint-content-type" },
{ "path": "../hint-css-prefix-order" },
{ "path": "../hint-disown-opener" },
Expand Down
1 change: 1 addition & 0 deletions packages/extension-browser/webpack.config.js
Expand Up @@ -53,6 +53,7 @@ const baseConfig = {
resolve: {
alias: {
'hint/dist/src/lib/utils/network/request-async$': path.resolve(__dirname, 'dist/src/shims/request-async.js'),
'mdn-browser-compat-data$': path.resolve(__dirname, 'dist/mdn-browser-compat-data.packed.json'),
url$: path.resolve(__dirname, 'dist/src/shims/url.js')
}
}
Expand Down

0 comments on commit 38fd2bc

Please sign in to comment.