Skip to content

Commit

Permalink
chore: drop dependency on playwright-core in all our packages
Browse files Browse the repository at this point in the history
This patch:
- drops dependency on playwright-core in all our packages. Instead of
  the dependency, packages are now built with `//packages/build_package.sh`
  script.
- unifies `browsers.json` - now there's a single `//browsers.json` file
  that is used to manage browser revisions.

This patch temporary switches canary publishing to `--dryn-run` from CI/CD so that we
can verify that it does sane things.

We'll unify all our package management scripts under `//packages/` in a
follow-up.

Fixes #2268
  • Loading branch information
aslushnikov committed May 20, 2020
1 parent e658a3e commit f1baa0c
Show file tree
Hide file tree
Showing 26 changed files with 255 additions and 139 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,4 @@ yarn.lock
/src/firefox/protocol.ts
/src/webkit/protocol.ts
lib/
playwright-*.tgz
/types/*
File renamed without changes.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "playwright-core",
"name": "playwright-internal",
"private": true,
"version": "1.0.0-post",
"description": "A high-level API to automate web browsers",
"repository": "github:Microsoft/playwright",
Expand Down
40 changes: 40 additions & 0 deletions packages/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Managing and Publishing Playwright Packages

## Overview

- Playwright ships multiple packages to NPM. All packges that are published to NPM are listed as folders under [`//packages/`](../packages).
- Playwright's [root package.json](../package.json) is **never published to NPM**. It is only used for devmode, e.g. when running `npm install` with no arguments or installing from github.
- Playwright dependencies for all packages are the same and are managed with the [`root package.json`](../package.json).
- Playwright browser versions for all packages are the same and are managed with the [`browsers.json`](../browsers.json).

> **NOTE** As of May 20, 2020, the only exception is the `playwright-electron` package that
> doesn't follow the pack and is published manually. This is due to it's pre-1.0 status.

## Building NPM package

To build a package that will be shipped to NPM, use [`//packages/build_package.sh`](./build_package.sh) script.
The script populates package folder with contents, and then uses `npm pack` to archive the folder.

For example, to build `playwright` package and save result as `./playwright.tgz` file:

```sh
$ ./packages/build_package.sh playwright ./playwright.tgz
```

To debug what files are put into the folder, use `--no-cleanup` flag and inspect the package folder:

```sh
$ ./packages/build_package.sh playwright ./playwright.tgz --no-cleanup
$ ls ./packages/playwright # inspecting the folder..
```


## Testing packages

To test packages, use [`//tests/installation-tests/installation-tests.sh`](../tests/installation-tests/installation-tests.sh).


## Publishing packages

All package publishing happens **exclusively** over CI/CD using the [`//utils/publish_all_packages.sh`](../utils/publish_all_packages.sh) script.
154 changes: 154 additions & 0 deletions packages/build_package.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
#!/bin/bash
set -e
set +x

if [[ "$(uname)" != "Darwin" && "$(uname)" != "Linux" ]]; then
echo "ERROR: can't run on $(uname). This script is designed to work on Mac or Linux only"
exit 1
fi


# 1. Read arguments

if [[ $1 == "--help" ]]; then
echo "usage: $(basename $0) <package-name> <output-path> [--no-cleanup] [--no-build]"
echo
echo "Creates a .tgz of the package and saves it at the given output path"
echo
echo " --no-cleanup skip cleaning up generated files from package directory"
echo " --no-build skip building root package. DANGER: make sure to build root package before running this script."
echo
echo "Example:"
echo " $(basename $0) playwright $(pwd -P)/playwright.tgz"
exit 1
fi

if [[ $# < 1 ]]; then
echo "Please specify package name, e.g. 'playwright' or 'playwright-chromium'."
echo "Try running $(basename $0) --help"
exit 1
fi
PACKAGE_NAME="$1"

if [[ $# < 2 ]]; then
echo "Please specify output path"
echo "Try running $(basename $0) --help"
exit 1
fi
OUTPUT_PATH=$(node -e "console.log(require('path').resolve('$2'))")

NO_CLEANUP=""
if [[ "$3" == "--no-cleanup" || "$4" == "--no-cleanup" ]]; then
NO_CLEANUP="true"
fi

NO_BUILD=""
if [[ "$3" == "--no-build" || "$4" == "--no-build" ]]; then
NO_BUILD="true"
fi


# 2. Change directory to the script directory and setup cleanup hooks.

CLEANUP_PATHS=()
function do_cleanup {
if [[ ! -z "${NO_CLEANUP}" ]]; then
return
fi
for CLEANUP_PATH in "${CLEANUP_PATHS[@]}"; do
rm -rf "${CLEANUP_PATH}"
done
}
trap "do_cleanup; cd $(pwd -P)" EXIT
cd "$(dirname $0)"


# 3. Figure out package parameters.
PACKAGE_PATH="$(pwd -P)/${PACKAGE_NAME}"
PACKAGE_DESCRIPTION=""
PACKAGE_BROWSERS="[]"
if [[ "${PACKAGE_NAME}" == "playwright" ]]; then
PACKAGE_DESCRIPTION="A high-level API to automate web browsers"
PACKAGE_BROWSERS="['chromium', 'firefox', 'webkit']"

# For Playwright, we need to copy README.md
README_PATH="${PACKAGE_PATH}/README.md"
CLEANUP_PATHS+=("${README_PATH}")
cp ../README.md "${README_PATH}"
elif [[ "${PACKAGE_NAME}" == "playwright-core" ]]; then
PACKAGE_DESCRIPTION="A high-level API to automate web browsers"
PACKAGE_BROWSERS="[]"
elif [[ "${PACKAGE_NAME}" == "playwright-webkit" ]]; then
PACKAGE_DESCRIPTION="A high-level API to automate Webkit"
PACKAGE_BROWSERS="['webkit']"
elif [[ "${PACKAGE_NAME}" == "playwright-firefox" ]]; then
PACKAGE_DESCRIPTION="A high-level API to automate Firefox"
PACKAGE_BROWSERS="['firefox']"
elif [[ "${PACKAGE_NAME}" == "playwright-chromium" ]]; then
PACKAGE_DESCRIPTION="A high-level API to automate Chromium"
PACKAGE_BROWSERS="['chromium']"
else
echo "ERROR: unknown package '${PACKAGE_NAME}'"
exit 1
fi


# 4. Build root package unless --no-build was provided.

if [[ -z "${NO_BUILD}" ]]; then
npm run build
else
echo "Skippping BUILD because --no-build is provided" >/dev/stderr
fi


# 5. Copy library sources in the package.

LIB_PATH="${PACKAGE_PATH}/lib"
CLEANUP_PATHS+=("${LIB_PATH}")
cp -r ../lib "${LIB_PATH}"


# 6. Generate package.json for the package.

PACKAGE_JSON_PATH="${PACKAGE_PATH}/package.json"
CLEANUP_PATHS+=("${PACKAGE_JSON_PATH}")
node -e "$(cat <<EOF
const sourceJSON = require('../package.json');
const packageJSON = {
"name": "${PACKAGE_NAME}",
"version": sourceJSON.version,
"description": "${PACKAGE_DESCRIPTION}",
"repository": "github:Microsoft/playwright",
"engines": sourceJSON.engines,
"homepage": "https://playwright.dev",
"main": "index.js",
"scripts": {
"install": "node install.js"
},
"author": {
"name": "Microsoft Corporation"
},
"license": "Apache-2.0",
"dependencies": sourceJSON.dependencies
};
console.log(JSON.stringify(packageJSON, null, 2));
EOF
)" > "${PACKAGE_JSON_PATH}"


# 7. Generate browsers.json for the package.
BROWSERS_JSON_PATH="${PACKAGE_PATH}/browsers.json"
CLEANUP_PATHS+=("${BROWSERS_JSON_PATH}")
node -e "$(cat <<EOF
const browsersJSON = require('../browsers.json');
browsersJSON.browsers = browsersJSON.browsers.filter(browser => ${PACKAGE_BROWSERS}.includes(browser.name));
console.log(JSON.stringify(browsersJSON, null, 2));
EOF
)" > "${BROWSERS_JSON_PATH}"


# 8. Pack package and move to output directory.
TAR_NAME=$(npm pack "${PACKAGE_PATH}")
mv "${TAR_NAME}" "${OUTPUT_PATH}"
echo "${OUTPUT_PATH}"
8 changes: 0 additions & 8 deletions packages/playwright-chromium/browsers.json

This file was deleted.

2 changes: 1 addition & 1 deletion packages/playwright-chromium/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
* limitations under the License.
*/

const { Playwright } = require('playwright-core/lib/server/playwright');
const { Playwright } = require('./lib/server/playwright');

module.exports = new Playwright(__dirname, require('./browsers.json')['browsers']);
2 changes: 1 addition & 1 deletion packages/playwright-chromium/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
* limitations under the License.
*/

const { installBrowsersWithProgressBar } = require('playwright-core/lib/install/installer');
const { installBrowsersWithProgressBar } = require('./lib/install/installer');

installBrowsersWithProgressBar(__dirname);
18 changes: 0 additions & 18 deletions packages/playwright-chromium/package.json

This file was deleted.

3 changes: 3 additions & 0 deletions packages/playwright-core/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# playwright-core

This package contains the no-browser flavor of [Playwright](http://github.com/microsoft/playwright).
17 changes: 17 additions & 0 deletions packages/playwright-core/install.js
Original file line number Diff line number Diff line change
@@ -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.
*/

/* NOTE: playwright-core does not install browsers by design. */
8 changes: 0 additions & 8 deletions packages/playwright-firefox/browsers.json

This file was deleted.

2 changes: 1 addition & 1 deletion packages/playwright-firefox/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
* limitations under the License.
*/

const { Playwright } = require('playwright-core/lib/server/playwright');
const { Playwright } = require('./lib/server/playwright');

module.exports = new Playwright(__dirname, require('./browsers.json')['browsers']);
2 changes: 1 addition & 1 deletion packages/playwright-firefox/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
* limitations under the License.
*/

const { installBrowsersWithProgressBar } = require('playwright-core/lib/install/installer');
const { installBrowsersWithProgressBar } = require('./lib/install/installer');

installBrowsersWithProgressBar(__dirname);
18 changes: 0 additions & 18 deletions packages/playwright-firefox/package.json

This file was deleted.

8 changes: 0 additions & 8 deletions packages/playwright-webkit/browsers.json

This file was deleted.

2 changes: 1 addition & 1 deletion packages/playwright-webkit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
* limitations under the License.
*/

const { Playwright } = require('playwright-core/lib/server/playwright');
const { Playwright } = require('./lib/server/playwright');

module.exports = new Playwright(__dirname, require('./browsers.json')['browsers']);
2 changes: 1 addition & 1 deletion packages/playwright-webkit/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
* limitations under the License.
*/

const { installBrowsersWithProgressBar } = require('playwright-core/lib/install/installer');
const { installBrowsersWithProgressBar } = require('./lib/install/installer');

installBrowsersWithProgressBar(__dirname);
18 changes: 0 additions & 18 deletions packages/playwright-webkit/package.json

This file was deleted.

2 changes: 0 additions & 2 deletions packages/playwright/.gitignore

This file was deleted.

2 changes: 1 addition & 1 deletion packages/playwright/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
* limitations under the License.
*/

const { Playwright } = require('playwright-core/lib/server/playwright');
const { Playwright } = require('./lib/server/playwright');

module.exports = new Playwright(__dirname, require('./browsers.json')['browsers']);
2 changes: 1 addition & 1 deletion packages/playwright/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
* limitations under the License.
*/

const { installBrowsersWithProgressBar } = require('playwright-core/lib/install/installer');
const { installBrowsersWithProgressBar } = require('./lib/install/installer');

installBrowsersWithProgressBar(__dirname);
Loading

0 comments on commit f1baa0c

Please sign in to comment.