From ecdf25c9addafc87f21aae59438ca7e87343d6e0 Mon Sep 17 00:00:00 2001 From: Federico Brigante Date: Thu, 16 Mar 2023 20:48:23 +0800 Subject: [PATCH] Prepare for Safari release --- .github/workflows/is-dist-up-to-date.yml | 20 ++++++++ contributing.md | 2 +- package-lock.json | 48 +++++++++++++++++++ package.json | 13 +++-- pre-build.mjs | 29 +++++++++++ safari/prepare-release.sh | 13 +++-- ...enger.js => advanced-editors-messenger.js} | 0 source/ghost-text.js | 4 +- source/manifest.json | 9 +++- source/options.css | 7 +++ source/options.html | 8 ++-- 11 files changed, 132 insertions(+), 21 deletions(-) create mode 100644 .github/workflows/is-dist-up-to-date.yml create mode 100644 pre-build.mjs rename source/{unsafe-messenger.js => advanced-editors-messenger.js} (100%) diff --git a/.github/workflows/is-dist-up-to-date.yml b/.github/workflows/is-dist-up-to-date.yml new file mode 100644 index 0000000..a2f63bf --- /dev/null +++ b/.github/workflows/is-dist-up-to-date.yml @@ -0,0 +1,20 @@ +env: + SCRIPT_NAME: build + +# FILE GENERATED WITH: npx ghat fregante/ghatemplates/is-dist-up-to-date +# SOURCE: https://github.com/fregante/ghatemplates + +name: Verify Built Files +on: + - pull_request + - push +jobs: + Verify: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: install + run: npm ci || npm install + - run: npm run ${{ env.SCRIPT_NAME }} + - name: verify that built files are up to date + run: git diff --exit-code diff --git a/contributing.md b/contributing.md index 2b106ea..e7827b3 100644 --- a/contributing.md +++ b/contributing.md @@ -61,7 +61,7 @@ If the value an be set via DOM, like for a standard `contentEditable`, the secon https://github.com/fregante/GhostText/blob/febe6a66146cd3e620ad4458e50954e213bbb629/source/ghost-text.js#L14-L30 -In the more likely case where you have to access the website’s own script data, you'd have to go through the `AdvancedTextWrapper`, which communicates with the [`unsafe-messenger` script](https://github.com/fregante/GhostText/blob/main/source/unsafe-messenger.js) to get and set the text: +In the more likely case where you have to access the website’s own script data, you'd have to go through the `AdvancedTextWrapper`, which communicates with the [`advanced-editors-messenger` script](https://github.com/fregante/GhostText/blob/main/source/advanced-editors-messenger.js) to get and set the text: https://github.com/fregante/GhostText/blob/febe6a66146cd3e620ad4458e50954e213bbb629/source/unsafe-messenger.js#L35-L51 diff --git a/package-lock.json b/package-lock.json index ffdf4cb..137ca0b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,6 +13,7 @@ "devDependencies": { "@codemirror/view": "^6.9.2", "@parcel/config-webextension": "^2.8.3", + "dot-json": "^1.2.2", "parcel": "^2.8.3", "xo": "^0.53.1" }, @@ -2591,6 +2592,15 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/detect-indent": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/detect-indent/-/detect-indent-6.0.0.tgz", + "integrity": "sha512-oSyFlqaTHCItVRGK5RmrmjB+CmaMOW7IaNA/kdxqhoa6d17j/5ce9O9eWXmV/KEdRwqpQA+Vqe8a8Bsybu4YnA==", + "dev": true, + "engines": { + "node": ">=8" + } + }, "node_modules/detect-libc": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-1.0.3.tgz", @@ -2615,6 +2625,15 @@ "node": ">=8" } }, + "node_modules/docopt": { + "version": "0.6.2", + "resolved": "https://registry.npmjs.org/docopt/-/docopt-0.6.2.tgz", + "integrity": "sha512-NqTbaYeE4gA/wU1hdKFdU+AFahpDOpgGLzHP42k6H6DKExJd0A55KEVWYhL9FEmHmgeLvEU2vuKXDuU+4yToOw==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/doctrine": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-3.0.0.tgz", @@ -2696,6 +2715,20 @@ "url": "https://github.com/fb55/domutils?sponsor=1" } }, + "node_modules/dot-json": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/dot-json/-/dot-json-1.2.2.tgz", + "integrity": "sha512-AKL+GsO4wSEU4LU+fAk/PqN4nQ6PB1vT3HpMiZous9xCzK5S0kh4DzfUY0EfU67jsIXLlu0ty71659N9Nmg+Tw==", + "dev": true, + "dependencies": { + "detect-indent": "~6.0.0", + "docopt": "~0.6.2", + "underscore-keypath": "~0.0.22" + }, + "bin": { + "dot-json": "bin/dot-json.js" + } + }, "node_modules/dotenv": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-7.0.0.tgz", @@ -7201,6 +7234,21 @@ "node": ">=0.10.0" } }, + "node_modules/underscore": { + "version": "1.13.6", + "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.13.6.tgz", + "integrity": "sha512-+A5Sja4HP1M08MaXya7p5LvjuM7K6q/2EaC0+iovj/wOcMsTzMvDFbasi/oSapiwOlt252IqsKqPjCl7huKS0A==", + "dev": true + }, + "node_modules/underscore-keypath": { + "version": "0.0.22", + "resolved": "https://registry.npmjs.org/underscore-keypath/-/underscore-keypath-0.0.22.tgz", + "integrity": "sha512-fU7aYj1J2LQd+jqdQ67AlCOZKK3Pl+VErS8fGYcgZG75XB9/bY+RLM+F2xEcKHhHNtLvqqFyXAoZQlLYfec3Xg==", + "dev": true, + "dependencies": { + "underscore": "*" + } + }, "node_modules/update-browserslist-db": { "version": "1.0.10", "resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.0.10.tgz", diff --git a/package.json b/package.json index ade4f2c..7343941 100644 --- a/package.json +++ b/package.json @@ -1,17 +1,19 @@ { "private": true, "scripts": { - "build": "parcel build source/manifest.json --dist-dir distribution --no-cache", + "pre:build": "rm -rf distribution && node pre-build.mjs", + "build": "parcel build source/manifest.json --dist-dir distribution --no-cache --no-source-maps", "lint": "xo", "pack:safari": "xcodebuild -project 'safari/GhostText.xcodeproj'", "prepare:safari": "bash safari/prepare-release.sh", "start:safari": "open 'safari/build/Release/GhostText.app'", "test": "xo && npm run build", + "pre:watch": "npm run pre:build", "watch": "parcel watch source/manifest.json --dist-dir distribution --no-cache --no-hmr" }, "browserslist": [ - "Chrome >= 86", - "Firefox >= 83", + "Chrome >= 100", + "Firefox >= 100", "Safari >= 14" ], "xo": { @@ -35,6 +37,7 @@ "devDependencies": { "@codemirror/view": "^6.9.2", "@parcel/config-webextension": "^2.8.3", + "dot-json": "^1.2.2", "parcel": "^2.8.3", "xo": "^0.53.1" }, @@ -49,9 +52,5 @@ "https://ghosttext.fregante.com/test/" ] } - }, - "@parcel/bundler-default-bug": "https://github.com/parcel-bundler/parcel/issues/8071", - "@parcel/bundler-default": { - "minBundles": 10000000 } } diff --git a/pre-build.mjs b/pre-build.mjs new file mode 100644 index 0000000..5900d43 --- /dev/null +++ b/pre-build.mjs @@ -0,0 +1,29 @@ +// Parcel changes names unless they're in web_accessible_resources +// `npm run build` creates additional files with hashed names +// Xcode can't handle dynamically-created filenames, so we need to keep this list here + +import {readdir} from 'node:fs/promises'; +import DotJson from 'dot-json'; + +const list = await readdir('./source', {withFileTypes: true}); +const excludes = new Set([ + 'options.css', // Inlined, but only if excluded + 'advanced-editors-messenger.js', // Inlined + 'manifest.json', // Not necessary +]); +const resources = []; +for (const item of list) { + if (excludes.has(item.name)) { + continue; + } + + if (item.isDirectory()) { + resources.push(item.name + '/*'); + } else { + resources.push(item.name); + } +} + +const manifest = new DotJson('source/manifest.json'); +manifest.set('web_accessible_resources', resources); +manifest.save(); diff --git a/safari/prepare-release.sh b/safari/prepare-release.sh index f8cfafb..dc23118 100644 --- a/safari/prepare-release.sh +++ b/safari/prepare-release.sh @@ -8,9 +8,12 @@ CONFIG_FILE=./safari/LocalOverrides.xcconfig TAG=$(git describe --tags --abbrev=0) if [[ $(git describe --tags) != "$TAG" ]]; then - echo You’re ahead of the latest tag. Run: - echo git checkout "$TAG" - exit 1 + if [[ -z "$SKIP_TAG_CHECK" ]]; then + echo You’re ahead of the latest tag. Run: + echo git checkout "$TAG" + exit 1 + fi + echo You’re ahead of the latest tag. Watch out! fi PROJECT_VERSION=$(sed -n 's/^CURRENT_PROJECT_VERSION = \(.*\)/\1/p' < $CONFIG_FILE) @@ -18,8 +21,8 @@ NEXT_PROJECT_VERSION=$((PROJECT_VERSION + 1)) echo "Will bump the project version" "$PROJECT_VERSION" -trash distribution -npm run build +echo "Run \`npm run watch\` in another shell, close it, then press any key." +read -r npx dot-json distribution/manifest.json version "$TAG" sed -i '' '/MARKETING_VERSION/d' $CONFIG_FILE diff --git a/source/unsafe-messenger.js b/source/advanced-editors-messenger.js similarity index 100% rename from source/unsafe-messenger.js rename to source/advanced-editors-messenger.js diff --git a/source/ghost-text.js b/source/ghost-text.js index adaf2d4..fd8f296 100644 --- a/source/ghost-text.js +++ b/source/ghost-text.js @@ -1,5 +1,5 @@ import GThumane from './humane-ghosttext.js'; -import unsafeMessenger from './unsafe-messenger.js'; +import advancedEditors from './advanced-editors-messenger.js'; import optionsStorage from './options-storage.js'; const knownElements = new Map(); @@ -334,7 +334,7 @@ function stopGT() { function init() { const script = document.createElement('script'); - script.textContent = '(' + unsafeMessenger.toString() + ')()'; + script.textContent = '(' + advancedEditors.toString() + ')()'; document.head.append(script); } diff --git a/source/manifest.json b/source/manifest.json index 4a83e0f..a80ac44 100644 --- a/source/manifest.json +++ b/source/manifest.json @@ -72,7 +72,14 @@ ] }, "web_accessible_resources": [ + "background.js", + "ghost-text.css", "ghost-text.js", - "ghost-text.css" + "humane-ghosttext.css", + "humane-ghosttext.js", + "icons/*", + "options-storage.js", + "options.html", + "options.js" ] } diff --git a/source/options.css b/source/options.css index d62ee22..0c67ba8 100644 --- a/source/options.css +++ b/source/options.css @@ -1,3 +1,10 @@ +/* Keep this here to avoid creating a new bundle that breaks Safari */ +@import "npm:webext-base-css"; + +:root { + max-width: 30em; +} + .field { display: flex; align-items: baseline; diff --git a/source/options.html b/source/options.html index 4458b4f..9f746d7 100644 --- a/source/options.html +++ b/source/options.html @@ -1,10 +1,8 @@ GhostText options - + +