Skip to content
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

chore: Upgrade TypeScript to 3.6 #5559

Merged
merged 1 commit into from Mar 31, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/Page.js
Expand Up @@ -26,7 +26,7 @@ const {Keyboard, Mouse, Touchscreen} = require('./Input');
const Tracing = require('./Tracing');
const {helper, debugError, assert} = require('./helper');
const {Coverage} = require('./Coverage');
const {Worker} = require('./Worker');
const {Worker: PuppeteerWorker} = require('./Worker');
Copy link
Contributor

Choose a reason for hiding this comment

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

@mathiasbynens Can the export of Worker be renamed to PuppeteerWorker in Worker.js or does that constitute a breaking change?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think that would be a breaking change if we support people who have done:

const { Worker } = require('puppeteer/lib/Worker')

I'm not sure how common that is - @mathiasbynens WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

It's a potentially breaking change that we can avoid in this case, so let's just stick to the more conservative change for now.

const {createJSHandle} = require('./JSHandle');
const {Accessibility} = require('./Accessibility');
const {TimeoutSettings} = require('./TimeoutSettings');
Expand Down Expand Up @@ -79,7 +79,7 @@ class Page extends EventEmitter {

this._screenshotTaskQueue = screenshotTaskQueue;

/** @type {!Map<string, Worker>} */
/** @type {!Map<string, PuppeteerWorker>} */
this._workers = new Map();
client.on('Target.attachedToTarget', event => {
if (event.targetInfo.type !== 'worker') {
Expand All @@ -90,7 +90,7 @@ class Page extends EventEmitter {
return;
}
const session = Connection.fromSession(client).session(event.sessionId);
const worker = new Worker(session, event.targetInfo.url, this._addConsoleMessage.bind(this), this._handleException.bind(this));
const worker = new PuppeteerWorker(session, event.targetInfo.url, this._addConsoleMessage.bind(this), this._handleException.bind(this));
this._workers.set(event.sessionId, worker);
this.emit(Events.Page.WorkerCreated, worker);
});
Expand Down Expand Up @@ -274,7 +274,7 @@ class Page extends EventEmitter {
}

/**
* @return {!Array<!Worker>}
* @return {!Array<!PuppeteerWorker>}
*/
workers() {
return Array.from(this._workers.values());
Expand Down
8 changes: 4 additions & 4 deletions lib/Target.js
Expand Up @@ -16,7 +16,7 @@

const {Events} = require('./Events');
const {Page} = require('./Page');
const {Worker} = require('./Worker');
const {Worker: PuppeteerWorker} = require('./Worker');

class Target {
/**
Expand All @@ -37,7 +37,7 @@ class Target {
this._screenshotTaskQueue = screenshotTaskQueue;
/** @type {?Promise<!Puppeteer.Page>} */
this._pagePromise = null;
/** @type {?Promise<!Worker>} */
/** @type {?Promise<!PuppeteerWorker>} */
this._workerPromise = null;
this._initializedPromise = new Promise(fulfill => this._initializedCallback = fulfill).then(async success => {
if (!success)
Expand Down Expand Up @@ -77,15 +77,15 @@ class Target {
}

/**
* @return {!Promise<?Worker>}
* @return {!Promise<?PuppeteerWorker>}
*/
async worker() {
if (this._targetInfo.type !== 'service_worker' && this._targetInfo.type !== 'shared_worker')
return null;
if (!this._workerPromise) {
// TODO(einbinder): Make workers send their console logs.
this._workerPromise = this._sessionFactory()
.then(client => new Worker(client, this._targetInfo.url, () => {} /* consoleAPICalled */, () => {} /* exceptionThrown */));
.then(client => new PuppeteerWorker(client, this._targetInfo.url, () => {} /* consoleAPICalled */, () => {} /* exceptionThrown */));
}
return this._workerPromise;
}
Expand Down
11 changes: 8 additions & 3 deletions lib/WebSocketTransport.js
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const WebSocket = require('ws');
const NodeWebSocket = require('ws');

/**
* @implements {!Puppeteer.ConnectionTransport}
Expand All @@ -25,17 +25,22 @@ class WebSocketTransport {
*/
static create(url) {
return new Promise((resolve, reject) => {
const ws = new WebSocket(url, [], {
const ws = new NodeWebSocket(url, [], {
perMessageDeflate: false,
maxPayload: 256 * 1024 * 1024, // 256Mb
});

/* error that WebSocket is not assignable to type WebSocket
* due to a misisng dispatchEvent() method which the ws library
* does not implement and we do not need
mathiasbynens marked this conversation as resolved.
Show resolved Hide resolved
*/
ws.addEventListener('open', () => resolve(new WebSocketTransport(ws)));
ws.addEventListener('error', reject);
});
}

/**
* @param {!WebSocket} ws
* @param {!NodeWebSocket} ws
*/
constructor(ws) {
this._ws = ws;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -61,7 +61,7 @@
"pixelmatch": "^4.0.2",
"pngjs": "^3.3.3",
"text-diff": "^1.0.1",
"typescript": "3.5.3"
"typescript": "3.6.5"
},
"browser": {
"./lib/BrowserFetcher.js": false,
Expand Down