aboutsummaryrefslogtreecommitdiffstats
path: root/playwright-cli/playwright-cli.SlackBuild
blob: 407b5e15615bb8a6093ca64f9972efc6374fe2da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/bin/bash

# Slackware build script for playwright-cli

# Copyright 2026 Danilo M. <danix@danix.xyz>
# All rights reserved.
#
# Redistribution and use of this script, with or without modification, is
# permitted provided that the following conditions are met:
#
# 1. Redistributions of this script must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
# OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

cd $(dirname $0) ; CWD=$(pwd)

PRGNAM=playwright-cli
VERSION=${VERSION:-0.1.14}
BUILD=${BUILD:-1}
TAG=${TAG:-_SBo}
PKGTYPE=${PKGTYPE:-tgz}

# playwright-cli and its dependencies (playwright, playwright-core) are pure
# JavaScript: no compiled objects, no native node addons, no per-arch
# prebuilds. The package is therefore noarch. Playwright's only native parts
# are the browser binaries, which are NOT packaged here (see below).
ARCH=noarch

# Functionality lives in the "playwright" / "playwright-core" dependencies,
# pulled from the npm registry at build time. This is the accepted convention
# for npm command-line tools: the network is used at build time only, never
# at run time.

# The Playwright browser binaries (Chromium, Firefox, WebKit) are NOT packaged.
# They are runtime data the user downloads on first use into
# ~/.cache/ms-playwright via "playwright-cli install". The environment variable
# below makes sure the npm postinstall step does not download them into the
# package.
export PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1

if [ ! -z "${PRINT_PACKAGE_NAME}" ]; then
  echo "$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.$PKGTYPE"
  exit 0
fi

TMP=${TMP:-/tmp/SBo}
PKG=$TMP/package-$PRGNAM
OUTPUT=${OUTPUT:-/tmp}

set -e

rm -rf $PKG
mkdir -p $TMP $PKG $OUTPUT

# The npm registry tarball is named cli-$VERSION.tgz; accept that as well as
# the SBo-conventional $PRGNAM-$VERSION.tgz name.
SRCTGZ=$CWD/$PRGNAM-$VERSION.tgz
[ -f "$SRCTGZ" ] || SRCTGZ=$CWD/cli-$VERSION.tgz

# Install the npm tarball and its dependencies into the package, globally,
# under /usr. npm reads the source tarball directly; no extraction needed.
DESTDIR=$PKG npm install \
  --user root \
  --location=global \
  --prefix $PKG/usr \
  --omit=dev \
  --no-audit \
  --no-fund \
  $SRCTGZ

# noarch: pure-JS modules must live in /usr/lib, never the arch-specific
# /usr/lib64. node's default prefix may land them in lib64, so normalise.
if [ -d "$PKG/usr/lib64/node_modules" ]; then
  mkdir -p $PKG/usr/lib
  mv $PKG/usr/lib64/node_modules $PKG/usr/lib/node_modules
  rmdir $PKG/usr/lib64 2>/dev/null || true
fi

NODE_MODULES=$PKG/usr/lib/node_modules

# Remove the stray "root" module npm sometimes creates from --user root
rm -rf $NODE_MODULES/root

# Create the launcher symlink. npm's --prefix/global bin-linking is
# unreliable under DESTDIR staging, so make it explicitly. The bin name and
# target come from the package's own "bin" field (playwright-cli.js).
mkdir -p $PKG/usr/bin
ln -sf ../lib/node_modules/@playwright/cli/playwright-cli.js \
  $PKG/usr/bin/playwright-cli
chmod 0755 $NODE_MODULES/@playwright/cli/playwright-cli.js

# Remove VCS / CI leftovers
find $PKG/usr \( -name '.git*' -o -name '.travis.yml' \) -exec rm -f {} \;

# Scrub absolute build-time paths from package.json files
find $PKG -name "package.json" \
  -exec sed -e "s|$CWD||g" -e "s|$TMP||g" -i '{}' \; 2>/dev/null || true

chown -R root:root $PKG
find -L $PKG \
  \( -perm 777 -o -perm 775 -o -perm 750 -o -perm 711 -o -perm 555 \
   -o -perm 511 \) -exec chmod 755 {} \+ -o \
  \( -perm 666 -o -perm 664 -o -perm 640 -o -perm 600 -o -perm 444 \
   -o -perm 440 -o -perm 400 \) -exec chmod 644 {} \+

# Make sure the launcher and any bin shims are executable
[ -d "$PKG/usr/bin" ] && chmod 0755 $PKG/usr/bin/* 2>/dev/null || true

mkdir -p $PKG/usr/doc/$PRGNAM-$VERSION
DOCDIR=$NODE_MODULES/@playwright/cli
cp -a \
  $DOCDIR/LICENSE $DOCDIR/README.md \
  $PKG/usr/doc/$PRGNAM-$VERSION 2>/dev/null || true
cat $CWD/$PRGNAM.SlackBuild > $PKG/usr/doc/$PRGNAM-$VERSION/$PRGNAM.SlackBuild

mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

cd $PKG
/sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.$PKGTYPE