diff --git a/.npmignore b/.npmignore index 7ce25572f8..08aa7c2c78 100644 --- a/.npmignore +++ b/.npmignore @@ -10,8 +10,11 @@ lib/injected/ !lib/**/*.d.ts !index.d.ts -# root for "playwright" package +# used for npm install scripts +!download-browser.js + +# root for "playwright-core" package !index.js -# root for "playwright/web" +# root for "playwright-core/web" !web.js diff --git a/download-browser.js b/download-browser.js new file mode 100644 index 0000000000..5c7d7502fc --- /dev/null +++ b/download-browser.js @@ -0,0 +1,60 @@ +/** + * Copyright (c) Microsoft Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +async function downloadBrowser(browser) { + const playwright = require('.')[browser]; + let progressBar = null; + let lastDownloadedBytes = 0; + function onProgress(downloadedBytes, totalBytes) { + if (!progressBar) { + const ProgressBar = require('progress'); + progressBar = new ProgressBar(`Downloading ${browser} ${playwright._revision} - ${toMegabytes(totalBytes)} [:bar] :percent :etas `, { + complete: '=', + incomplete: ' ', + width: 20, + total: totalBytes, + }); + } + const delta = downloadedBytes - lastDownloadedBytes; + lastDownloadedBytes = downloadedBytes; + progressBar.tick(delta); + } + + const fetcher = playwright._createBrowserFetcher(); + const revisionInfo = fetcher.revisionInfo(); + // Do nothing if the revision is already downloaded. + if (revisionInfo.local) + return revisionInfo; + await fetcher.download(revisionInfo.revision, onProgress); + logPolitely(`${browser} downloaded to ${revisionInfo.folderPath}`); + return revisionInfo; +} + + +function toMegabytes(bytes) { + const mb = bytes / 1024 / 1024; + return `${Math.round(mb * 10) / 10} Mb`; +} + +function logPolitely(toBeLogged) { + const logLevel = process.env.npm_config_loglevel; + const logLevelDisplay = ['silent', 'error', 'warn'].indexOf(logLevel) > -1; + + if (!logLevelDisplay) + console.log(toBeLogged); +} + +module.exports = {downloadBrowser}; diff --git a/install-development.js b/install-development.js index b1c550bad6..fa1cfee176 100644 --- a/install-development.js +++ b/install-development.js @@ -18,78 +18,46 @@ // This file is only run when someone clones the github repo for development try { + console.log('Building playwright...'); require('child_process').execSync('npm run build', { stdio: 'ignore' }); } catch (e) { } +const {downloadBrowser} = require('./download-browser'); (async function() { const protocolGenerator = require('./utils/protocol-types-generator'); try { - const chromeRevision = await downloadBrowser('chromium', require('./index').chromium); + const chromeRevision = await downloadAndCleanup('chromium'); await protocolGenerator.generateChromiunProtocol(chromeRevision); } catch (e) { console.warn(e.message); } try { - const firefoxRevision = await downloadBrowser('firefox', require('./index').firefox); + const firefoxRevision = await downloadAndCleanup('firefox'); await protocolGenerator.generateFirefoxProtocol(firefoxRevision); } catch (e) { console.warn(e.message); } try { - const webkitRevision = await downloadBrowser('webkit', require('./index').webkit); + const webkitRevision = await downloadAndCleanup('webkit'); await protocolGenerator.generateWebKitProtocol(webkitRevision); } catch (e) { console.warn(e.message); } })(); -async function downloadBrowser(browser, playwright) { - let progressBar = null; - let lastDownloadedBytes = 0; - function onProgress(downloadedBytes, totalBytes) { - if (!progressBar) { - const ProgressBar = require('progress'); - progressBar = new ProgressBar(`Downloading ${browser} ${playwright._revision} - ${toMegabytes(totalBytes)} [:bar] :percent :etas `, { - complete: '=', - incomplete: ' ', - width: 20, - total: totalBytes, - }); - } - const delta = downloadedBytes - lastDownloadedBytes; - lastDownloadedBytes = downloadedBytes; - progressBar.tick(delta); - } +async function downloadAndCleanup(browser) { + const revisionInfo = await downloadBrowser(browser); - const fetcher = playwright._createBrowserFetcher(); - const revisionInfo = fetcher.revisionInfo(); - // Do nothing if the revision is already downloaded. - if (revisionInfo.local) - return revisionInfo; - await fetcher.download(revisionInfo.revision, onProgress); - logPolitely(`${browser} downloaded to ${revisionInfo.folderPath}`); - const localRevisions = await fetcher.localRevisions(); // Remove previous revisions. + const playwright = require('.')[browser]; + const fetcher = playwright._createBrowserFetcher(); const cleanupOldVersions = localRevisions.filter(revision => revision !== revisionInfo.revision).map(revision => fetcher.remove(revision)); await Promise.all([...cleanupOldVersions]); + return revisionInfo; } - -function toMegabytes(bytes) { - const mb = bytes / 1024 / 1024; - return `${Math.round(mb * 10) / 10} Mb`; -} - -function logPolitely(toBeLogged) { - const logLevel = process.env.npm_config_loglevel; - const logLevelDisplay = ['silent', 'error', 'warn'].indexOf(logLevel) > -1; - - if (!logLevelDisplay) - console.log(toBeLogged); -} - diff --git a/packages/playwright-chromium/index.js b/packages/playwright-chromium/index.js index 3d5458a3ce..bfdbac7fd0 100644 --- a/packages/playwright-chromium/index.js +++ b/packages/playwright-chromium/index.js @@ -1 +1,16 @@ +/** + * Copyright (c) Microsoft Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ module.exports = require('playwright-core').chromium; diff --git a/packages/playwright-chromium/install.js b/packages/playwright-chromium/install.js index b6c9bac31b..2bf7a0aadc 100644 --- a/packages/playwright-chromium/install.js +++ b/packages/playwright-chromium/install.js @@ -1,39 +1,17 @@ -downloadBrowser('chromium', require('./index').chromium); - -async function downloadBrowser(browser, playwright) { - let progressBar = null; - let lastDownloadedBytes = 0; - function onProgress(downloadedBytes, totalBytes) { - if (!progressBar) { - const ProgressBar = require('progress'); - progressBar = new ProgressBar(`Downloading ${browser} ${playwright._revision} - ${toMegabytes(totalBytes)} [:bar] :percent :etas `, { - complete: '=', - incomplete: ' ', - width: 20, - total: totalBytes, - }); - } - const delta = downloadedBytes - lastDownloadedBytes; - lastDownloadedBytes = downloadedBytes; - progressBar.tick(delta); - } - - const fetcher = playwright._createBrowserFetcher(); - const revisionInfo = fetcher.revisionInfo(); - await fetcher.download(revisionInfo.revision, onProgress); - logPolitely(`${browser} downloaded to ${revisionInfo.folderPath}`); -} - -function toMegabytes(bytes) { - const mb = bytes / 1024 / 1024; - return `${Math.round(mb * 10) / 10} Mb`; -} - -function logPolitely(toBeLogged) { - const logLevel = process.env.npm_config_loglevel; - const logLevelDisplay = ['silent', 'error', 'warn'].indexOf(logLevel) > -1; - - if (!logLevelDisplay) - console.log(toBeLogged); -} - +/** + * Copyright (c) Microsoft Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +const {downloadBrowser} = require('playwright-core/download-browser'); +downloadBrowser('chromium'); diff --git a/packages/playwright-chromium/package.json b/packages/playwright-chromium/package.json index ac8b2111c5..24a449b882 100644 --- a/packages/playwright-chromium/package.json +++ b/packages/playwright-chromium/package.json @@ -1,7 +1,7 @@ { "name": "playwright-chromium", "version": "0.9.17-post", - "description": "A high-level API to automate web browsers", + "description": "A high-level API to automate Chromium", "repository": "github:Microsoft/playwright", "main": "index.js", "scripts": { diff --git a/packages/playwright-firefox/index.js b/packages/playwright-firefox/index.js index 11d23826de..0cf5880f50 100644 --- a/packages/playwright-firefox/index.js +++ b/packages/playwright-firefox/index.js @@ -1 +1,16 @@ +/** + * Copyright (c) Microsoft Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ module.exports = require('playwright-core').firefox; diff --git a/packages/playwright-firefox/install.js b/packages/playwright-firefox/install.js index 0a2b6b13d6..62f901040a 100644 --- a/packages/playwright-firefox/install.js +++ b/packages/playwright-firefox/install.js @@ -1,39 +1,17 @@ -downloadBrowser('firefox', require('./index').firefox); - -async function downloadBrowser(browser, playwright) { - let progressBar = null; - let lastDownloadedBytes = 0; - function onProgress(downloadedBytes, totalBytes) { - if (!progressBar) { - const ProgressBar = require('progress'); - progressBar = new ProgressBar(`Downloading ${browser} ${playwright._revision} - ${toMegabytes(totalBytes)} [:bar] :percent :etas `, { - complete: '=', - incomplete: ' ', - width: 20, - total: totalBytes, - }); - } - const delta = downloadedBytes - lastDownloadedBytes; - lastDownloadedBytes = downloadedBytes; - progressBar.tick(delta); - } - - const fetcher = playwright._createBrowserFetcher(); - const revisionInfo = fetcher.revisionInfo(); - await fetcher.download(revisionInfo.revision, onProgress); - logPolitely(`${browser} downloaded to ${revisionInfo.folderPath}`); -} - -function toMegabytes(bytes) { - const mb = bytes / 1024 / 1024; - return `${Math.round(mb * 10) / 10} Mb`; -} - -function logPolitely(toBeLogged) { - const logLevel = process.env.npm_config_loglevel; - const logLevelDisplay = ['silent', 'error', 'warn'].indexOf(logLevel) > -1; - - if (!logLevelDisplay) - console.log(toBeLogged); -} - +/** + * Copyright (c) Microsoft Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +const {downloadBrowser} = require('playwright-core/download-browser'); +downloadBrowser('firefox'); diff --git a/packages/playwright-firefox/package.json b/packages/playwright-firefox/package.json index 88c9969bc1..0ca99078f7 100644 --- a/packages/playwright-firefox/package.json +++ b/packages/playwright-firefox/package.json @@ -1,7 +1,7 @@ { "name": "playwright-firefox", "version": "0.9.17-post", - "description": "A high-level API to automate web browsers", + "description": "A high-level API to automate Firefox", "repository": "github:Microsoft/playwright", "main": "index.js", "scripts": { diff --git a/packages/playwright-webkit/index.js b/packages/playwright-webkit/index.js index fc57e941a4..03f81e63a6 100644 --- a/packages/playwright-webkit/index.js +++ b/packages/playwright-webkit/index.js @@ -1 +1,16 @@ +/** + * Copyright (c) Microsoft Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ module.exports = require('playwright-core').webkit; diff --git a/packages/playwright-webkit/install.js b/packages/playwright-webkit/install.js index f6a3fbba3c..f289ab867f 100644 --- a/packages/playwright-webkit/install.js +++ b/packages/playwright-webkit/install.js @@ -1,39 +1,17 @@ -downloadBrowser('webkit', require('./index').webkit); - -async function downloadBrowser(browser, playwright) { - let progressBar = null; - let lastDownloadedBytes = 0; - function onProgress(downloadedBytes, totalBytes) { - if (!progressBar) { - const ProgressBar = require('progress'); - progressBar = new ProgressBar(`Downloading ${browser} ${playwright._revision} - ${toMegabytes(totalBytes)} [:bar] :percent :etas `, { - complete: '=', - incomplete: ' ', - width: 20, - total: totalBytes, - }); - } - const delta = downloadedBytes - lastDownloadedBytes; - lastDownloadedBytes = downloadedBytes; - progressBar.tick(delta); - } - - const fetcher = playwright._createBrowserFetcher(); - const revisionInfo = fetcher.revisionInfo(); - await fetcher.download(revisionInfo.revision, onProgress); - logPolitely(`${browser} downloaded to ${revisionInfo.folderPath}`); -} - -function toMegabytes(bytes) { - const mb = bytes / 1024 / 1024; - return `${Math.round(mb * 10) / 10} Mb`; -} - -function logPolitely(toBeLogged) { - const logLevel = process.env.npm_config_loglevel; - const logLevelDisplay = ['silent', 'error', 'warn'].indexOf(logLevel) > -1; - - if (!logLevelDisplay) - console.log(toBeLogged); -} - +/** + * Copyright (c) Microsoft Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +const {downloadBrowser} = require('playwright-core/download-browser'); +downloadBrowser('webkit'); diff --git a/packages/playwright-webkit/package.json b/packages/playwright-webkit/package.json index 2062efee92..932b030ef2 100644 --- a/packages/playwright-webkit/package.json +++ b/packages/playwright-webkit/package.json @@ -1,7 +1,7 @@ { "name": "playwright-webkit", "version": "0.9.17-post", - "description": "A high-level API to automate web browsers", + "description": "A high-level API to automate WebKit", "repository": "github:Microsoft/playwright", "main": "index.js", "scripts": { diff --git a/packages/playwright/install.js b/packages/playwright/install.js index 171ff7e2b3..08e34d9585 100644 --- a/packages/playwright/install.js +++ b/packages/playwright/install.js @@ -1,2 +1,17 @@ +/** + * Copyright (c) Microsoft Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ console.error('This package, "playwright", is a placeholder. Please install "playwright-chromium", "playwright-firefox", or "playwright-webkit" to use playwright.'); -process.exit(1); \ No newline at end of file +process.exit(1);