Skip to content

Commit

Permalink
FI-1506 fix: bin command e2ed-install-browsers
Browse files Browse the repository at this point in the history
  • Loading branch information
uid11 committed Nov 13, 2024
1 parent aa1658a commit 5b1c35b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
4 changes: 4 additions & 0 deletions bin/installBrowsers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
set -eu

npm install --global @playwright/browser-chromium@latest
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
"author": "uid11",
"license": "MIT",
"bin": {
"e2ed": "bin/runE2edInLocalEnvironment.js",
"e2ed-init": "bin/init.js"
"e2ed": "./bin/runE2edInLocalEnvironment.js",
"e2ed-init": "./bin/init.js",
"e2ed-install-browsers": "./bin/installBrowsers.sh"
},
"bugs": "https://github.com/joomcode/e2ed/issues",
"engines": {
Expand Down Expand Up @@ -91,11 +92,11 @@
"build:remove:types-js": "find ./build/node_modules/e2ed/types/ -name *.js -exec rm {} \\;",
"postbuild:remove": "touch ./build/node_modules/e2ed/types/index.js",
"build:copy": "npm run build:copy:bin && npm run build:copy:scripts && npm run build:copy:meta && npm run build:copy:example && npm run build:copy:tsconfig",
"build:copy:bin": "cp ./bin/dockerEntrypoint.sh ./build/node_modules/e2ed/bin",
"build:copy:bin": "cp ./bin/dockerEntrypoint.sh ./bin/installBrowsers.sh ./build/node_modules/e2ed/bin",
"postbuild:copy:bin": "npm run make:executable build/node_modules/e2ed/bin/init.js build/node_modules/e2ed/bin/runE2edInLocalEnvironment.js build/node_modules/e2ed/bin/runE2edInDockerEnvironment.js",
"build:copy:scripts": "cp ./build/scripts/*.js ./build",
"build:copy:meta": "cp -R ./LICENSE ./logo.svg ./README.md ./styles ./build/node_modules/e2ed",
"postbuild:copy:meta": "node ./build/writePrunedPackageJson.js",
"postbuild:copy:meta": "node ./build/writeInstallBrowsers.js && node ./build/writePrunedPackageJson.js",
"prebuild:copy:example": "rm -r ./build/autotests",
"build:copy:example": "cp -R ./autotests ./build/node_modules/e2ed/",
"postbuild:copy:example": "(cd ./build/node_modules/e2ed/autotests && rm -r ./node_modules ./tests/internalTypeTests && mv ./.gitignore ./gitignore && mv ./packs/local.example.ts ./packs/local.ts)",
Expand Down
18 changes: 18 additions & 0 deletions scripts/writeInstallBrowsers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* @file Writes actual Playwright version to `installBrowsers.sh` script.
*/

import {readFileSync, writeFileSync} from 'node:fs';
import {join} from 'node:path';

import packageJson from '../package.json';

const playwrightVersion = packageJson.dependencies['@playwright/test'];

const installBrowsersPath = join(__dirname, 'node_modules', 'e2ed', 'bin', 'installBrowsers.sh');

const installBrowsersText = readFileSync(installBrowsersPath, 'utf8');

const newInstallBrowsersText = installBrowsersText.replace('@latest', `@${playwrightVersion}`);

writeFileSync(installBrowsersPath, newInstallBrowsersText);
9 changes: 1 addition & 8 deletions scripts/writePrunedPackageJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,15 @@ import originalPackageJson from '../package.json';

type OriginalPackageJson = typeof originalPackageJson;

type PrunedPackageJson = Omit<OriginalPackageJson, 'bin' | 'devDependencies' | 'scripts'> & {
bin: OriginalPackageJson['bin'] & {['e2ed-install-browsers']: string};
type PrunedPackageJson = Omit<OriginalPackageJson, 'devDependencies' | 'scripts'> & {
devDependencies: undefined;
scripts: undefined;
};

const prunedPackageJsonPath = join(__dirname, 'node_modules', 'e2ed', 'package.json');

const playwrightVersion = originalPackageJson.dependencies['@playwright/test'];

const prunedPackageJson: PrunedPackageJson = {
...originalPackageJson,
bin: {
...originalPackageJson.bin,
'e2ed-install-browsers': `npm install --global @playwright/browser-chromium@${playwrightVersion}`,
},
devDependencies: undefined,
scripts: undefined,
};
Expand Down

0 comments on commit 5b1c35b

Please sign in to comment.