├── LICENSE ├── README.md ├── index.js ├── manifest.yml └── package.json /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Hung Viet Nguyen 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 🤖 Netlify Plugin Playwright Cache 2 | 3 | [![npm version](https://img.shields.io/npm/v/netlify-plugin-playwright-cache)](https://www.npmjs.com/package/netlify-plugin-playwright-cache) 4 | ![PRs Welcome](https://img.shields.io/badge/PRs-welcome-green.svg) 5 | 6 | Persist the Playwright executables between Netlify builds. 7 | 8 | ## Why `netlify-plugin-playwright-cache` 9 | 10 | When you install `playwright-chromium`, it downloads Chromium executables to a cache folder (not `node_modules`). Netlify does not cache this folder between builds, but caches `node_modules`. This leads to unsuccessful builds with the following error like this: 11 | 12 | ``` 13 | 11:33:48 PM: [: Executable doesn't exist at /opt/buildhome/.cache/ms-playwright/chromium-1019/chrome-linux/chrome 14 | ╔═════════════════════════════════════════════════════════════════════════╗ 15 | 11:33:48 PM: ║ Looks like Playwright Test or Playwright was just installed or updated. ║ 16 | 11:33:48 PM: ║ Please run the following command to download new browsers: ║ 17 | 11:33:48 PM: ║ ║ 18 | 11:33:48 PM: ║ npx playwright install ║ 19 | 11:33:48 PM: ║ ║ 20 | 11:33:48 PM: ║ <3 Playwright Team ║ 21 | 11:33:48 PM: ╚═════════════════════════════════════════════════════════════════════════╝ 22 | ``` 23 | 24 | This plugins fixes the above issue by caching the Playwright executables (Chromium, ffmpeg...) between builds. 25 | 26 | ## Installation 27 | 28 | You can install `netlify-plugin-playwright-cache` by one of the following ways: 29 | 30 | 1. Install directly from Netlify Dashboard: 31 | 32 | 33 | 34 | 2. Install as a dependency of your project: 35 | 36 | ```bash 37 | npm install --save-dev netlify-plugin-playwright-cache 38 | # Or 39 | yarn add -D netlify-plugin-playwright-cache 40 | # Or 41 | pnpm add -D netlify-plugin-playwright-cache 42 | ``` 43 | 44 | Then update `netlify.toml` to include the plugin: 45 | 46 | ```toml 47 | [[plugins]] 48 | package = "netlify-plugin-playwright-cache" 49 | ``` 50 | 51 | ## Usage 52 | 53 | Remember to **Clear cache and retry deploy** after adding the plugin. 54 | 55 | 56 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | import path from "path"; 2 | import os from "os"; 3 | 4 | // https://github.com/microsoft/playwright/blob/b6bc8b654d4bee7460256b65b1cf4eb3f1b889ad/packages/playwright-core/src/server/registry/index.ts#L229-L230 5 | const CACHE_LOCATION = path.join( 6 | process.env.XDG_CACHE_HOME || path.join(os.homedir(), ".cache"), 7 | "ms-playwright" 8 | ); 9 | 10 | console.log("Cache Location", CACHE_LOCATION); 11 | 12 | export const onPreBuild = async function ({ utils }) { 13 | await utils.cache.restore(CACHE_LOCATION); 14 | }; 15 | 16 | export const onPostBuild = async function ({ utils }) { 17 | await utils.cache.save(CACHE_LOCATION); 18 | }; 19 | -------------------------------------------------------------------------------- /manifest.yml: -------------------------------------------------------------------------------- 1 | name: playwright-cache 2 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "netlify-plugin-playwright-cache", 3 | "version": "0.0.1", 4 | "description": "Persist the Playwright executables between Netlify builds.", 5 | "keywords": [ 6 | "netlify", 7 | "netlify-plugin", 8 | "playwright", 9 | "custom cache" 10 | ], 11 | "homepage": "https://github.com/nvh95/netlify-plugin-playwright-cache", 12 | "repository": { 13 | "type": "git", 14 | "url": "git+https://github.com/nvh95/netlify-plugin-playwright-cache.git" 15 | }, 16 | "license": "MIT", 17 | "author": { 18 | "name": "Hung Viet Nguyen", 19 | "url": "https://github.com/nvh95" 20 | }, 21 | "type": "module", 22 | "main": "index.js", 23 | "scripts": { 24 | "publish:alpha": "npm publish --tag alpha", 25 | "publish:latest": "npm publish", 26 | "sort": "npx sort-package-json" 27 | }, 28 | "bug": { 29 | "url": "https://github.com/nvh95/netlify-plugin-playwright-cache/issues" 30 | } 31 | } 32 | --------------------------------------------------------------------------------