Commit 50831d53 authored by Alejandro Celaya's avatar Alejandro Celaya Committed by Alejandro Celaya

Add support for TS in boot script

parent 26a12c9f
...@@ -109,7 +109,7 @@ gulp.task('watch-boot-script', () => { ...@@ -109,7 +109,7 @@ gulp.task('watch-boot-script', () => {
// //
// We could alternatively use `watchJS` to rebuild the bundle, but we'd // We could alternatively use `watchJS` to rebuild the bundle, but we'd
// need to make its logging less noisy first. // need to make its logging less noisy first.
'src/boot/**/*.js', 'src/boot/**/*.{js,ts,tsx}',
], ],
{ delay: 500 }, { delay: 500 },
gulp.task('build-boot-script') gulp.task('build-boot-script')
......
...@@ -64,11 +64,11 @@ export default { ...@@ -64,11 +64,11 @@ export default {
// Rollup docs recommend against "inline", but for this tiny bundle it // Rollup docs recommend against "inline", but for this tiny bundle it
// produces a prod bundle of the same size and dev bundle that has less cruft in it. // produces a prod bundle of the same size and dev bundle that has less cruft in it.
babelHelpers: 'inline', babelHelpers: 'inline',
exclude: 'node_modules/**', exclude: 'node_modules/**',
extensions: ['.js', '.ts', '.tsx']
}), }),
json(), json(),
nodeResolve(), nodeResolve({ extensions: ['.js', '.ts', '.tsx'] }),
...prodPlugins, ...prodPlugins,
], ],
}; };
{ {
"presets": [ "presets": [
"@babel/preset-typescript",
["@babel/preset-env", { ["@babel/preset-env", {
"targets": { "targets": {
"chrome": "40", "chrome": "40",
......
/** /**
* Returns the extension ID which is running this script, or undefined if this * Returns the extension ID which is running this script, or undefined if this
* script is not being run by the browser extension. * script is not being run by the browser extension.
*
* @param {Window} window_
* @return {string | undefined}
*/ */
export function getExtensionId(window_ = window) { export function getExtensionId(window_: Window = window): string | undefined {
return /** @type {any} */ (window_).chrome?.runtime?.id; return (window_ as any).chrome?.runtime?.id;
} }
/** /**
* Verifies if there's a config script in the document that was generated by a * Verifies if there's a config script in the document that was generated by a
* specific browser extension. * specific browser extension.
*
* @param {string} extensionId
* @param {Document} document_
* @return {boolean}
*/ */
export function hasExtensionConfig(extensionId, document_ = document) { export function hasExtensionConfig(
extensionId: string,
document_: Document = document
): boolean {
return !!document_.querySelector( return !!document_.querySelector(
`script.js-hypothesis-config[data-extension-id=${extensionId}]` `script.js-hypothesis-config[data-extension-id=${extensionId}]`
); );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment