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
26 changes: 23 additions & 3 deletions utils/publish_all_packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,31 @@ else
exit 1
fi

# A successful `npm publish` only means the registry accepted the package: it is processed
# asynchronously and may show up minutes later, or never (playwright-core@1.65.0 never did,
# leaving playwright@1.65.0 on @latest pointing to a missing dependency).
function wait_until_available {
local name="$1"
local attempt
for attempt in $(seq 60); do
if [[ "$(npm view "${name}@${VERSION}" version --prefer-online 2>/dev/null)" == "${VERSION}" ]]; then
return 0
fi
sleep 15
done
echo "ERROR: ${name}@${VERSION} was accepted by npm but did not become available within 15 minutes"
return 1
}

echo "==================== Publishing version ${VERSION} ================"
node ./utils/workspace.js --ensure-consistent
node ./utils/workspace.js --list-public-package-paths | while read package
do
npm publish --access=public ${package} --tag="${NPM_PUBLISH_TAG}"
# Packages are listed in dependency order. Wait for each one to go live before publishing the next,
# so nothing is published (and tagged) while a package it depends on is missing.
PACKAGE_PATHS=$(node ./utils/workspace.js --list-public-package-paths)
for package in ${PACKAGE_PATHS}; do
name=$(node -p "require('${package}/package.json').name")
npm publish --access=public "${package}" --tag="${NPM_PUBLISH_TAG}"
wait_until_available "${name}"
done

echo "Done."
22 changes: 18 additions & 4 deletions utils/workspace.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,21 @@ class Workspace {
return this._packages;
}

/**
* Public packages, each listed after the workspace packages it depends on.
* @returns {PWPackage[]}
*/
publicPackagesInDependencyOrder() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think this could be done in ~5 lines 😄

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done 🙂

const ordered = new Set();
const visit = pkg => {
for (const dep of Object.keys(pkg.packageJSON.dependencies || {}))
this._packages.filter(p => p.name === dep).forEach(visit);
ordered.add(pkg);
};
this._packages.forEach(visit);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is just for me to understand (hope it's not annoying), but why not filter out private packages before visiting them all? I'm sure I'm missing something here :)

Anyway love Playwright -- Thank you

return [...ordered].filter(pkg => !pkg.isPrivate);
}

async version() {
const workspacePackageJSON = await readJSON(path.join(this._rootDir, 'package.json'));
return workspacePackageJSON.version;
Expand Down Expand Up @@ -219,10 +234,9 @@ async function parseCLI() {
die(`\n ERROR: package-lock.json lockfileVersion must be 3`);
},
'--list-public-package-paths': () => {
for (const pkg of workspace.packages()) {
if (!pkg.isPrivate)
console.log(pkg.path);
}
// Dependency order: publishing relies on it to never publish a package before its dependencies.
for (const pkg of workspace.publicPackagesInDependencyOrder())
console.log(pkg.path);
},
'--get-version': async (version) => {
console.log(await workspace.version());
Expand Down
Loading