Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

chore: npm packages (#525)

Joel Einbinderfa1d286d56d2
diff --git a/.npmignore b/.npmignore
index 6b7ce811a4..08aa7c2c78 100644
--- a/.npmignore
+++ b/.npmignore
@@ -10,11 +10,11 @@ lib/injected/
!lib/**/*.d.ts
!index.d.ts
-# Install
-!install.js
+# used for npm install scripts
+!download-browser.js
-# root for "playwright" package
+# root for "playwright-core" package
!index.js
-# root for "playwright/web"
+# root for "playwright-core/web"
!web.js
diff --git a/install.js b/download-browser.js
similarity index 53%
rename from install.js
rename to download-browser.js
index d35baf03a7..5c7d7502fc 100644
--- a/install.js
+++ b/download-browser.js
@@ -1,12 +1,11 @@
/**
- * Copyright 2017 Google Inc. All rights reserved.
- * Modifications copyright (c) Microsoft Corporation.
+ * 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
+ * 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,
@@ -15,47 +14,8 @@
* limitations under the License.
*/
- // This file is only run when someone clones the github repo for development
-
-try {
- require('child_process').execSync('npm run build', {
- stdio: 'ignore'
- });
-} catch (e) {
-}
-
-(async function() {
- let protocolGenerator;
- try {
- protocolGenerator = require('./utils/protocol-types-generator');
- } catch (e) {
- // Release mode
- }
- try {
- const chromeRevision = await downloadBrowser('chromium', require('./index').chromium);
- if (protocolGenerator)
- await protocolGenerator.generateChromiunProtocol(chromeRevision);
- } catch (e) {
- console.warn(e.message);
- }
-
- try {
- const firefoxRevision = await downloadBrowser('firefox', require('./index').firefox);
- if (protocolGenerator)
- await protocolGenerator.generateFirefoxProtocol(firefoxRevision);
- } catch (e) {
- console.warn(e.message);
- }
- try {
- const webkitRevision = await downloadBrowser('webkit', require('./index').webkit);
- if (protocolGenerator)
- await protocolGenerator.generateWebKitProtocol(webkitRevision);
- } catch (e) {
- console.warn(e.message);
- }
-})();
-
-async function downloadBrowser(browser, playwright) {
+async function downloadBrowser(browser) {
+ const playwright = require('.')[browser];
let progressBar = null;
let lastDownloadedBytes = 0;
function onProgress(downloadedBytes, totalBytes) {
@@ -80,13 +40,10 @@ async function downloadBrowser(browser, playwright) {
return revisionInfo;
await fetcher.download(revisionInfo.revision, onProgress);
logPolitely(`${browser} downloaded to ${revisionInfo.folderPath}`);
- const localRevisions = await fetcher.localRevisions();
- // Remove previous revisions.
- 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`;
@@ -100,3 +57,4 @@ function logPolitely(toBeLogged) {
console.log(toBeLogged);
}
+module.exports = {downloadBrowser};
diff --git a/package.json b/package.json
index 1fa454169a..072b1a5cfd 100644
--- a/package.json
+++ b/package.json
@@ -1,5 +1,5 @@
{
- "name": "playwright",
+ "name": "playwright-core",
"version": "0.9.17-post",
"description": "A high-level API to automate web browsers",
"repository": "github:Microsoft/playwright",
@@ -19,7 +19,7 @@
"debug-unit": "node --inspect-brk test/test.js",
"test-doclint": "node utils/doclint/check_public_api/test/test.js && node utils/doclint/preprocessor/test.js",
"test": "npm run lint --silent && npm run coverage && npm run test-doclint && node utils/testrunner/test/test.js",
- "install": "node install.js",
+ "prepare": "node prepare.js",
"lint": "([ \"$CI\" = true ] && eslint --quiet -f codeframe --ext js,ts ./src || eslint --ext js,ts ./src) && npm run tsc && npm run doc",
"doc": "node utils/doclint/cli.js",
"coverage": "cross-env COVERAGE=true npm run unit",
@@ -28,7 +28,8 @@
"tsc": "tsc -p .",
"build": "node utils/runWebpack.js --mode='development' && tsc -p .",
"watch": "node utils/runWebpack.js --mode='development' --watch --silent | tsc -w -p .",
- "apply-next-version": "node utils/apply_next_version.js"
+ "apply-next-version": "node utils/apply_next_version.js",
+ "version": "node utils/sync_package_versions.js"
},
"author": {
"name": "Microsoft Corporation"
diff --git a/packages/playwright-chromium/README.md b/packages/playwright-chromium/README.md
new file mode 100644
index 0000000000..8c10a95d5f
--- /dev/null
+++ b/packages/playwright-chromium/README.md
@@ -0,0 +1,2 @@
+# playwright-chromium
+This packagage contains the [Chromium](https://www.chromium.org/) flavor of [Playwright](http://github.com/microsoft/playwright).
diff --git a/packages/playwright-chromium/index.js b/packages/playwright-chromium/index.js
new file mode 100644
index 0000000000..bfdbac7fd0
--- /dev/null
+++ b/packages/playwright-chromium/index.js
@@ -0,0 +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
new file mode 100644
index 0000000000..2bf7a0aadc
--- /dev/null
+++ b/packages/playwright-chromium/install.js
@@ -0,0 +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.
+ */
+const {downloadBrowser} = require('playwright-core/download-browser');
+downloadBrowser('chromium');
diff --git a/packages/playwright-chromium/package.json b/packages/playwright-chromium/package.json
new file mode 100644
index 0000000000..24a449b882
--- /dev/null
+++ b/packages/playwright-chromium/package.json
@@ -0,0 +1,17 @@
+{
+ "name": "playwright-chromium",
+ "version": "0.9.17-post",
+ "description": "A high-level API to automate Chromium",
+ "repository": "github:Microsoft/playwright",
+ "main": "index.js",
+ "scripts": {
+ "install": "node install.js"
+ },
+ "author": {
+ "name": "Microsoft Corporation"
+ },
+ "license": "Apache-2.0",
+ "dependencies": {
+ "playwright-core": "=0.9.17-post"
+ }
+}
diff --git a/packages/playwright-firefox/README.md b/packages/playwright-firefox/README.md
new file mode 100644
index 0000000000..975e53f5db
--- /dev/null
+++ b/packages/playwright-firefox/README.md
@@ -0,0 +1,2 @@
+# playwright-firefox
+This packagage contains the [Firefox](https://www.mozilla.org/firefox/) flavor of [Playwright](http://github.com/microsoft/playwright).
diff --git a/packages/playwright-firefox/index.js b/packages/playwright-firefox/index.js
new file mode 100644
index 0000000000..0cf5880f50
--- /dev/null
+++ b/packages/playwright-firefox/index.js
@@ -0,0 +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
new file mode 100644
index 0000000000..62f901040a
--- /dev/null
+++ b/packages/playwright-firefox/install.js
@@ -0,0 +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.
+ */
+const {downloadBrowser} = require('playwright-core/download-browser');
+downloadBrowser('firefox');
diff --git a/packages/playwright-firefox/package.json b/packages/playwright-firefox/package.json
new file mode 100644
index 0000000000..0ca99078f7
--- /dev/null
+++ b/packages/playwright-firefox/package.json
@@ -0,0 +1,17 @@
+{
+ "name": "playwright-firefox",
+ "version": "0.9.17-post",
+ "description": "A high-level API to automate Firefox",
+ "repository": "github:Microsoft/playwright",
+ "main": "index.js",
+ "scripts": {
+ "install": "node install.js"
+ },
+ "author": {
+ "name": "Microsoft Corporation"
+ },
+ "license": "Apache-2.0",
+ "dependencies": {
+ "playwright-core": "=0.9.17-post"
+ }
+}
diff --git a/packages/playwright-webkit/README.md b/packages/playwright-webkit/README.md
new file mode 100644
index 0000000000..e4a5808f9b
--- /dev/null
+++ b/packages/playwright-webkit/README.md
@@ -0,0 +1,2 @@
+# playwright-webkit
+This packagage contains the [WebKit](https://www.webkit.org/) flavor of [Playwright](http://github.com/microsoft/playwright).
diff --git a/packages/playwright-webkit/index.js b/packages/playwright-webkit/index.js
new file mode 100644
index 0000000000..03f81e63a6
--- /dev/null
+++ b/packages/playwright-webkit/index.js
@@ -0,0 +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
new file mode 100644
index 0000000000..f289ab867f
--- /dev/null
+++ b/packages/playwright-webkit/install.js
@@ -0,0 +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.
+ */
+const {downloadBrowser} = require('playwright-core/download-browser');
+downloadBrowser('webkit');
diff --git a/packages/playwright-webkit/package.json b/packages/playwright-webkit/package.json
new file mode 100644
index 0000000000..932b030ef2
--- /dev/null
+++ b/packages/playwright-webkit/package.json
@@ -0,0 +1,17 @@
+{
+ "name": "playwright-webkit",
+ "version": "0.9.17-post",
+ "description": "A high-level API to automate WebKit",
+ "repository": "github:Microsoft/playwright",
+ "main": "index.js",
+ "scripts": {
+ "install": "node install.js"
+ },
+ "author": {
+ "name": "Microsoft Corporation"
+ },
+ "license": "Apache-2.0",
+ "dependencies": {
+ "playwright-core": "=0.9.17-post"
+ }
+}
diff --git a/packages/playwright/README.md b/packages/playwright/README.md
new file mode 100644
index 0000000000..b662a736d4
--- /dev/null
+++ b/packages/playwright/README.md
@@ -0,0 +1,2 @@
+# playwright
+This packagage contains the [Chromium](https://www.chromium.org/), [Firefox](https://www.mozilla.org/firefox/) and [WebKit](https://www.webkit.org/) flavors of [Playwright](http://github.com/microsoft/playwright).
diff --git a/packages/playwright/index.js b/packages/playwright/index.js
new file mode 100644
index 0000000000..a85e0cb7f7
--- /dev/null
+++ b/packages/playwright/index.js
@@ -0,0 +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');
diff --git a/packages/playwright/install.js b/packages/playwright/install.js
new file mode 100644
index 0000000000..17e5976528
--- /dev/null
+++ b/packages/playwright/install.js
@@ -0,0 +1,21 @@
+/**
+ * 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');
+(async function() {
+ await downloadBrowser('chromium');
+ await downloadBrowser('firefox');
+ await downloadBrowser('webkit');
+})();
diff --git a/packages/playwright/package.json b/packages/playwright/package.json
new file mode 100644
index 0000000000..fca9b1695e
--- /dev/null
+++ b/packages/playwright/package.json
@@ -0,0 +1,17 @@
+{
+ "name": "playwright",
+ "version": "0.9.17-post",
+ "description": "A high-level API to automate web browsers",
+ "repository": "github:Microsoft/playwright",
+ "main": "index.js",
+ "scripts": {
+ "install": "node install.js"
+ },
+ "author": {
+ "name": "Microsoft Corporation"
+ },
+ "license": "Apache-2.0",
+ "dependencies": {
+ "playwright-core": "=0.9.13-post"
+ }
+}
diff --git a/prepare.js b/prepare.js
new file mode 100644
index 0000000000..2ada94891e
--- /dev/null
+++ b/prepare.js
@@ -0,0 +1,64 @@
+/**
+ * Copyright 2017 Google Inc. All rights reserved.
+ * Modifications 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.
+ */
+
+ // This file is only run when someone installs via the github repo
+
+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 downloadAndCleanup('chromium');
+ await protocolGenerator.generateChromiunProtocol(chromeRevision);
+ } catch (e) {
+ console.warn(e.message);
+ }
+
+ try {
+ const firefoxRevision = await downloadAndCleanup('firefox');
+ await protocolGenerator.generateFirefoxProtocol(firefoxRevision);
+ } catch (e) {
+ console.warn(e.message);
+ }
+
+ try {
+ const webkitRevision = await downloadAndCleanup('webkit');
+ await protocolGenerator.generateWebKitProtocol(webkitRevision);
+ } catch (e) {
+ console.warn(e.message);
+ }
+})();
+
+async function downloadAndCleanup(browser) {
+ const revisionInfo = await downloadBrowser(browser);
+
+ // Remove previous revisions.
+ const playwright = require('.')[browser];
+ const fetcher = playwright._createBrowserFetcher();
+ const localRevisions = await fetcher.localRevisions();
+ const cleanupOldVersions = localRevisions.filter(revision => revision !== revisionInfo.revision).map(revision => fetcher.remove(revision));
+ await Promise.all([...cleanupOldVersions]);
+
+ return revisionInfo;
+}
diff --git a/utils/sync_package_versions.js b/utils/sync_package_versions.js
new file mode 100644
index 0000000000..54954b2d69
--- /dev/null
+++ b/utils/sync_package_versions.js
@@ -0,0 +1,33 @@
+/**
+ * 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 fs = require('fs');
+const path = require('path');
+const {version} = require('../package.json');
+
+for (const packageName of ['playwright-chromium', 'playwright-firefox', 'playwright-webkit', 'playwright']) {
+ updatePackage(packageName, packageJSON => {
+ packageJSON.version = version;
+ packageJSON.dependencies['playwright-core'] = `=${version}`;
+ });
+}
+
+function updatePackage(packageName, transform) {
+ const packageJSONPath = path.join(__dirname, '..', 'packages', packageName, 'package.json');
+ console.log(`Updating ${packageJSONPath} to ${version}.`);
+ const packageJSON = JSON.parse(fs.readFileSync(packageJSONPath));
+ transform(packageJSON);
+ fs.writeFileSync(packageJSONPath, JSON.stringify(packageJSON, undefined, 2) + '\n');
+}
\ No newline at end of file