Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
dist/
coverage/
artifacts/
flow-typed/
commitlint.config.js
1 change: 1 addition & 0 deletions .flowconfig
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[include]

[libs]
flow-typed/

[options]
module.system=node
Expand Down
6 changes: 6 additions & 0 deletions flow-typed/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
This directory contains flowtyped declarations for the npm modules that do need
valid flow signatures to be able to flow check the modules part of this project.

The declarations in this directory are not complete definitions of the type defined
in the related modules source code, this declaration files define just as much as
needed for the purpose of flow checking this project source code.
23 changes: 23 additions & 0 deletions flow-typed/chrome-launcher.decl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// flow-typed signatures for 'chrome-launcher' module.

declare module "chrome-launcher" {
declare type LaunchOptions = {
enableExtensions: boolean,
chromePath: ?string,
chromeFlags: Array<string>,
startingUrl: ?string,
userDataDir: ?string,
ignoreDefaultFlags: boolean,
};

declare class Launcher {
static defaultFlags: () => Array<string>,
process: child_process$ChildProcess,
kill(): Promise<void>,
}

declare module.exports: {
Launcher: Class<Launcher>,
launch(options?: LaunchOptions): Promise<Launcher>,
}
}
6 changes: 6 additions & 0 deletions flow-typed/firefox-client.decl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// flow-typed signatures for 'firefox-client' module.

declare module "@cliqz-oss/firefox-client" {
declare class FirefoxClient extends event$EventEmitter {}
declare module.exports: Class<FirefoxClient>;
}
39 changes: 39 additions & 0 deletions flow-typed/firefox-profile.decl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// flow-typed signatures for 'firefox-profile' module.

declare module "firefox-profile" {
declare type ProfileOptions = {
destinationDirectory: string,
}

declare type ProfileCallback =
(err: ?Error, profile: Profile) => void;

declare class Finder {
constructor(baseDir: ?string): Finder,
readProfiles(cb: Function): void,
getPath(name: string, cb: (err: ?Error, profilePath: string) => void): void,

profiles: Array<{ [key:string]: string }>,

static locateUserDirectory(): string,
}

declare class FirefoxProfile {
constructor(opts: ?ProfileOptions): FirefoxProfile,

extensionsDir: string,
profileDir: string,
userPrefs: string,
defaultPreferences: { [key: string]: any },

path(): string,
setPreference(pref: string, value: any): void,
updatePreferences(): void,

static copy({profileDirectory: string}, cb: ProfileCallback): void,
static copyFromUserProfile({name: string}, cb: ProfileCallback): void,
static Finder: Class<Finder>,
}

declare module.exports: Class<FirefoxProfile>;
}
9 changes: 9 additions & 0 deletions flow-typed/watchpack.decl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// flow-typed signatures for 'watchpack' module.

declare module "watchpack" {
declare class Watchpack extends event$EventEmitter {
close(): void,
}

declare module.exports: Class<Watchpack>;
}
36 changes: 36 additions & 0 deletions flow-typed/ws.decl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// flow-typed signatures for 'ws' module.

declare module "ws" {
declare type ServerOptions = {
host: string,
port: number,
}

declare type ServerAddressInfo = {
address: string,
port: number,
}

declare class WebSocket extends events$EventEmitter {
constructor(url: string): WebSocket,
removeEventListener(eventName: string, cb: Function): void,
readyState: "CONNECTING" | "OPEN" | "CLOSING" | "CLOSED",
send(msg: string): void,
close(): void,

static OPEN: "OPEN",
static CLOSED: "CLOSED",
static CONNECTING: "CONNECTING",
static CLOSING: "CLOSING",
static Server: Class<Server>,
}

declare class Server extends net$Server {
constructor(opts?: ServerOptions, listenCb: Function): Server,
address(): ServerAddressInfo,
clients: Set<WebSocket>,
close(closedCb: Function): void,
}

declare module.exports: Class<WebSocket>;
}
8 changes: 6 additions & 2 deletions src/cmd/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,9 @@ export async function defaultPackageCreator(
// Added 'wx' flags to avoid overwriting of existing package.
const stream = createWriteStream(extensionPath, {flags: 'wx'});

stream.write(buffer, () => stream.end());
stream.write(buffer, () => {
stream.end();
});

try {
await eventToPromise(stream, 'close');
Expand All @@ -224,7 +226,9 @@ export async function defaultPackageCreator(
}
log.info(`Destination exists, overwriting: ${extensionPath}`);
const overwriteStream = createWriteStream(extensionPath);
overwriteStream.write(buffer, () => overwriteStream.end());
overwriteStream.write(buffer, () => {
overwriteStream.end();
});
await eventToPromise(overwriteStream, 'close');
}

Expand Down
4 changes: 2 additions & 2 deletions src/cmd/docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export type DocsOptions = {
openUrl?: typeof open,
}

export const url = 'https://developer.mozilla.org/en-US/Add-ons' +
'/WebExtensions/Getting_started_with_web-ext';
// eslint-disable-next-line max-len
export const url = 'https://extensionworkshop.com/documentation/develop/getting-started-with-web-ext/';

export default function docs(
params: DocsParams, {openUrl = open}: DocsOptions = {}
Expand Down
3 changes: 2 additions & 1 deletion src/cmd/sign.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import type {ExtensionManifest} from '../util/manifest';

const log = createLogger(__filename);

const defaultAsyncFsReadFile = fs.readFile.bind(fs);
const defaultAsyncFsReadFile: (string) => Promise<Buffer> =
fs.readFile.bind(fs);

export const extensionIdFile = '.web-extension-id';

Expand Down
16 changes: 9 additions & 7 deletions src/extension-runners/chromium.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const EXCLUDED_CHROME_FLAGS = [
'--mute-audio',
];

export const DEFAULT_CHROME_FLAGS = ChromeLauncher.defaultFlags()
export const DEFAULT_CHROME_FLAGS: Array<string> = ChromeLauncher.defaultFlags()
.filter((flag) => !EXCLUDED_CHROME_FLAGS.includes(flag));

/**
Expand All @@ -52,10 +52,10 @@ export const DEFAULT_CHROME_FLAGS = ChromeLauncher.defaultFlags()
export class ChromiumExtensionRunner {
cleanupCallbacks: Set<Function>;
params: ChromiumExtensionRunnerParams;
chromiumInstance: ChromeLauncher;
chromiumInstance: ?ChromeLauncher;
chromiumLaunch: typeof defaultChromiumLaunch;
reloadManagerExtension: string;
wss: WebSocket.Server;
wss: ?WebSocket.Server;
exiting: boolean;
_promiseSetupDone: ?Promise<void>;

Expand All @@ -73,7 +73,7 @@ export class ChromiumExtensionRunner {
/**
* Returns the runner name.
*/
getName() {
getName(): string {
return 'Chromium';
}

Expand Down Expand Up @@ -241,7 +241,7 @@ export class ChromiumExtensionRunner {
});
}

async wssBroadcast(data: Object) {
async wssBroadcast(data: Object): Promise<void> {
return new Promise((resolve) => {
const clients = this.wss ? new Set(this.wss.clients) : new Set();

Expand Down Expand Up @@ -280,7 +280,7 @@ export class ChromiumExtensionRunner {
});
}

async createReloadManagerExtension() {
async createReloadManagerExtension(): Promise<string> {
const tmpDir = new TempDir();
await tmpDir.create();
this.registerCleanup(() => tmpDir.remove());
Expand All @@ -307,6 +307,7 @@ export class ChromiumExtensionRunner {
})
);

// $FlowIgnore: this method is only called right after creating the server and so wss should be defined.
const wssInfo = this.wss.address();

const bgPage = `(function bgPage() {
Expand Down Expand Up @@ -408,7 +409,8 @@ export class ChromiumExtensionRunner {
}

if (this.wss) {
await new Promise((resolve) => this.wss.close(resolve));
await new Promise((resolve) =>
this.wss ? this.wss.close(resolve) : resolve());
this.wss = null;
}

Expand Down
6 changes: 3 additions & 3 deletions src/extension-runners/firefox-android.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ export type FirefoxAndroidExtensionRunnerParams = {|
*/
export class FirefoxAndroidExtensionRunner {
// Wait 3s before the next unix socket discovery loop.
static unixSocketDiscoveryRetryInterval = 3 * 1000;
static unixSocketDiscoveryRetryInterval: number = 3 * 1000;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is Flow really that dumb to not be able to infer the type from this declaration?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as discussed in the triage meeting: I didn't dig too much, but I got the feeling that flow did enforce explicitly type annotations (instead of just trust what type did flow infer) on what it is being exported explicitly from a module (which to me does make kind of sense: "infer the type used internally as much as possible, enforce explicit type annotation of what is exported outside of a module").

// Wait for at most 3 minutes before giving up.
static unixSocketDiscoveryMaxTime = 3 * 60 * 1000;
static unixSocketDiscoveryMaxTime: number = 3 * 60 * 1000;

params: FirefoxAndroidExtensionRunnerParams;
adbUtils: DefaultADBUtils;
Expand Down Expand Up @@ -168,7 +168,7 @@ export class FirefoxAndroidExtensionRunner {
/**
* Returns the runner name.
*/
getName() {
getName(): string {
return 'Firefox Android';
}

Expand Down
2 changes: 1 addition & 1 deletion src/extension-runners/firefox-desktop.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class FirefoxDesktopExtensionRunner {
/**
* Returns the runner name.
*/
getName() {
getName(): string {
return 'Firefox Desktop';
}

Expand Down
6 changes: 4 additions & 2 deletions src/extension-runners/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ export type MultiExtensionRunnerParams = {|
desktopNotifications: typeof defaultDesktopNotifications,
|};

export async function createExtensionRunner(config: ExtensionRunnerConfig) {
export async function createExtensionRunner(
config: ExtensionRunnerConfig
): Promise<IExtensionRunner> {
switch (config.target) {
case 'firefox-desktop': {
// TODO: use async import instead of require - https://github.com/mozilla/web-ext/issues/1306
Expand Down Expand Up @@ -86,7 +88,7 @@ export class MultiExtensionRunner {
/**
* Returns the runner name.
*/
getName() {
getName(): string {
return 'Multi Extension Runner';
}

Expand Down
7 changes: 4 additions & 3 deletions src/firefox/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import path from 'path';
import {promisify} from 'util';

import {default as defaultFxRunner} from 'fx-runner';
import FirefoxProfile, {copyFromUserProfile as defaultUserProfileCopier}
from 'firefox-profile';
import FirefoxProfile from 'firefox-profile';
import {fs} from 'mz';
import eventToPromise from 'event-to-promise';

Expand All @@ -26,7 +25,9 @@ import type {ExtensionManifest} from '../util/manifest';

const log = createLogger(__filename);

const defaultAsyncFsStat = fs.stat.bind(fs);
const defaultAsyncFsStat: typeof fs.stat = fs.stat.bind(fs);

const defaultUserProfileCopier = FirefoxProfile.copyFromUserProfile;

export const defaultFirefoxEnv = {
XPCOM_DEBUG_BREAK: 'stack',
Expand Down
2 changes: 1 addition & 1 deletion src/util/artifacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {createLogger} from './logger';

const log = createLogger(__filename);

const defaultAsyncFsAccess = fs.access.bind(fs);
const defaultAsyncFsAccess: typeof fs.access = fs.access.bind(fs);

type PrepareArtifactsDirOptions = {
asyncMkdirp?: typeof defaultAsyncMkdirp,
Expand Down
2 changes: 1 addition & 1 deletion src/util/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export class ConsoleStream {
}
}

export const consoleStream = new ConsoleStream();
export const consoleStream: ConsoleStream = new ConsoleStream();


// createLogger types and implementation.
Expand Down
2 changes: 1 addition & 1 deletion src/util/temp-dir.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export class TempDir {
/*
* Remove the temp directory.
*/
remove() {
remove(): Promise<void> | void {
if (!this._removeTempDir) {
return;
}
Expand Down
5 changes: 4 additions & 1 deletion src/util/zip-dir.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ import {promisify} from 'util';

import zipDirModule from 'zip-dir';

export const zipDir = promisify(zipDirModule);
type PromisedZipDir =
(sourceDir: string, { filter(...any): boolean }) => Promise<Buffer>;

export const zipDir: PromisedZipDir = promisify(zipDirModule);
22 changes: 13 additions & 9 deletions tests/functional/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,25 @@ import * as tmpDirUtils from '../../src/util/temp-dir';
export const withTempDir = tmpDirUtils.withTempDir;


export const functionalTestsDir = path.resolve(__dirname);
export const projectDir = path.join(functionalTestsDir, '..', '..');
export const webExt = process.env.TEST_WEB_EXT_BIN ?
export const functionalTestsDir: string = path.resolve(__dirname);
export const projectDir: string = path.join(functionalTestsDir, '..', '..');
export const webExt: string = process.env.TEST_WEB_EXT_BIN ?
path.resolve(process.env.TEST_WEB_EXT_BIN) :
path.join(projectDir, 'bin', 'web-ext');
export const fixturesDir = path.join(functionalTestsDir, '..', 'fixtures');
export const minimalAddonPath = path.join(fixturesDir, 'minimal-web-ext');
export const fixtureEsmImport = path.join(fixturesDir, 'import-as-esm');
export const fixtureCjsRequire = path.join(fixturesDir, 'require-as-cjs');
export const fakeFirefoxPath = path.join(
export const fixturesDir: string =
path.join(functionalTestsDir, '..', 'fixtures');
export const minimalAddonPath: string =
path.join(fixturesDir, 'minimal-web-ext');
export const fixtureEsmImport: string =
path.join(fixturesDir, 'import-as-esm');
export const fixtureCjsRequire: string =
path.join(fixturesDir, 'require-as-cjs');
export const fakeFirefoxPath: string = path.join(
functionalTestsDir,
process.platform === 'win32' ?
'fake-firefox-binary.bat' : 'fake-firefox-binary.js'
);
export const fakeServerPath = path.join(
export const fakeServerPath: string = path.join(
functionalTestsDir, 'fake-amo-server.js'
);

Expand Down
Loading