Skip to content

Commit

Permalink
Merge branch 'main' into renovate/pnpm-9.x
Browse files Browse the repository at this point in the history
  • Loading branch information
raducristianpopa authored Aug 21, 2024
2 parents 71980e2 + 4edb518 commit 6b73ad3
Show file tree
Hide file tree
Showing 16 changed files with 714 additions and 1,084 deletions.
15 changes: 15 additions & 0 deletions .github/actions/get-built-version.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// @ts-check
/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-var-requires */
const fs = require('node:fs/promises')

/**
* Retrieves the manifest version from the built extension.
* @param {import('github-script').AsyncFunctionArguments} AsyncFunctionArguments
*/
module.exports = async ({ core }) => {
const manifest = await fs
.readFile('./dist/chrome/manifest.json', 'utf8')
.then(JSON.parse)

core.setOutput('version', manifest.version)
}
1 change: 1 addition & 0 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: Environment setup
description: Sets up Node and pnpm

runs:
using: 'composite'
Expand Down
54 changes: 54 additions & 0 deletions .github/workflows/nightly-build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Nightly build

on:
schedule:
- cron: '0 0 * * 1-6'
workflow_dispatch:
inputs: {}

permissions:
contents: write

defaults:
run:
shell: bash

jobs:
build-nightly:
name: Create Release
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Environment setup
uses: ./.github/actions/setup

- name: Build
run: pnpm build --channel=nightly

- name: Get built version
uses: actions/github-script@v7
id: version
with:
script: |
const script = require('./.github/actions/get-built-version.cjs')
await script({ github, context, core })
- name: Delete existing release
run: gh release delete nightly --cleanup-tag --yes
continue-on-error: true
env:
GH_TOKEN: ${{ github.token }}

- name: Create GH Release
uses: softprops/action-gh-release@v2
with:
files: |
dist/*.zip
tag_name: 'nightly'
name: Nightly ${{ steps.version.outputs.version }}
body: |
> [!warning]
> The Nightly build is for adventurous folks. It's updated daily with less-tested features and improvements.
prerelease: true
6 changes: 3 additions & 3 deletions .github/workflows/pr-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ jobs:

- name: Build
shell: bash
run: pnpm build ${{ matrix.browser }} nightly
run: pnpm build ${{ matrix.browser }} --channel=nightly

- name: Upload artifacts
uses: actions/upload-artifact@v3.1.3
uses: actions/upload-artifact@v4
with:
name: ${{ github.event.pull_request.number }}-${{ matrix.browser }}
path: dist/${{ matrix.browser }}.zip
path: dist/${{ matrix.browser }}/
if-no-files-found: error

lint:
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/pr-title-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ name: Check PR title
on:
pull_request:
branches: ['**']
types:
- edited
- opened
- synchronize

jobs:
check-pr-title:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/sanity.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:

- name: Build
shell: bash
run: pnpm build ${{ matrix.browser}} nightly
run: pnpm build ${{ matrix.browser}} --channel=nightly

test:
name: Test
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ pnpm i

All commands are run from the root of the project, from a terminal:

| Command | Action |
| :------------------------------ | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `pnpm dev [target]` | Builds the extension for development, rebuilding on source code changes, for a specified target (`chrome` or `firefox`). If the target is not specified the script will build the extension for a Chromium based browser. Output folder: `dev`. |
| `pnpm build [TARGET] [CHANNEL]` | Builds the extension for production usage, for a specified target (`chrome` or `firefox`) and channel (`nightly`, `preview` or `stable`). If the target is not specified the script will build the extension for all available targets. If the channel is not specified the script will build the extension for the `nightly` channel. Output folder: `dist`. |
| `pnpm test` | Runs all test files using Jest. |
| Command | Action |
| :-------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `pnpm dev [target]` | Builds the extension for development, rebuilding on source code changes, for a specified target (`chrome` or `firefox`). If the target is not specified the script will build the extension for a Chromium based browser. Output folder: `dev`. |
| `pnpm build [TARGET] --channel=CHANNEL` | Builds the extension for production usage, for a specified target (`chrome` or `firefox`) and channel (`nightly`, `preview` or `stable`). If the target is not specified the script will build the extension for all available targets. If the channel is not specified the script will build the extension for the `nightly` channel. Output folder: `dist`. |
| `pnpm test` | Runs all test files using Jest. |

### Installing the extension from source, in Chromium based browsers (Chrome, Opera, Edge, Brave, Arc, Vivaldi)

Expand Down
4 changes: 3 additions & 1 deletion cspell-dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ data-testid
nums

# scripts and 3rd party terms
nvmrc
typecheck
prettiercache
corepack
linkcode
endregion
metafile
iife
softprops

# packages and 3rd party tools/libraries
awilix
Expand All @@ -38,3 +38,5 @@ raducristianpopa
sidvishnoi
dianafulga
jgoz
amannn
softprops
3 changes: 2 additions & 1 deletion esbuild/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ function processManifestPlugin({
scripts: [json.background.service_worker]
}
json.content_scripts?.forEach((contentScript) => {
// @ts-expect-error firefox doesn't support execution context yet
// TODO: Remove this when Firefox supports `world` - at least last 10
// versions
contentScript.world = undefined
})
delete json.minimum_chrome_version
Expand Down
28 changes: 23 additions & 5 deletions esbuild/prod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { createWriteStream } from 'node:fs'
import path from 'node:path'
import type { BuildOptions, Plugin as ESBuildPlugin } from 'esbuild'
import archiver from 'archiver'
import type { BuildArgs } from './config'
import type { BuildArgs, Channel, Target, WebExtensionManifest } from './config'
import { getPlugins } from './plugins'
import { typecheckPlugin } from '@jgoz/esbuild-plugin-typecheck'

Expand All @@ -22,7 +22,7 @@ export const getProdOptions = ({
plugins: getPlugins({ outDir, dev: false, target, channel }).concat([
typecheckPlugin({ buildMode: 'readonly' }),
preservePolyfillClassNamesPlugin({ outDir }),
zipPlugin({ outDir })
zipPlugin({ outDir, target, channel })
]),
define: {
NODE_ENV: JSON.stringify('production'),
Expand All @@ -36,16 +36,34 @@ export const getProdOptions = ({
}
}

function zipPlugin({ outDir }: { outDir: string }): ESBuildPlugin {
function zipPlugin({
outDir,
target,
channel
}: {
channel: Channel
target: Target
outDir: string
}): ESBuildPlugin {
return {
name: 'zip',
setup(build) {
build.onEnd(async () => {
const output = createWriteStream(`${outDir}.zip`)
const manifest = JSON.parse(
await fs.readFile(path.join(outDir, 'manifest.json'), 'utf8')
) as WebExtensionManifest

let zipName = `${target}-${manifest.version}.zip`
if (channel !== 'stable') {
zipName = `${channel}-${zipName}`
}

const dest = path.join(outDir, '..', zipName)
const output = createWriteStream(dest)
const archive = archiver('zip')
archive.on('end', function () {
const archiveSize = archive.pointer()
const fileName = path.relative(process.cwd(), `${outDir}.zip`)
const fileName = path.relative(process.cwd(), dest)
console.log(` Archived ${fileName}: ${formatBytes(archiveSize)}`)
})
archive.pipe(output)
Expand Down
33 changes: 17 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,42 +27,43 @@
"class-variance-authority": "^0.7.0",
"crypto-browserify": "^3.12.0",
"date-fns": "^3.6.0",
"framer-motion": "^11.2.10",
"framer-motion": "^11.3.28",
"http-message-signatures": "^1.0.4",
"httpbis-digest-headers": "^1.0.0",
"iso8601-duration": "^2.1.2",
"loglevel": "^1.9.1",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-hook-form": "^7.52.1",
"react-router-dom": "^6.25.1",
"react-hook-form": "^7.52.2",
"react-router-dom": "^6.26.1",
"safe-buffer": "5.2.1",
"tailwind-merge": "^2.4.0",
"tailwind-merge": "^2.5.2",
"webextension-polyfill": "^0.12.0"
},
"devDependencies": {
"@jgoz/esbuild-plugin-typecheck": "^4.0.1",
"@tailwindcss/forms": "^0.5.7",
"@testing-library/jest-dom": "^6.4.6",
"@testing-library/jest-dom": "^6.4.8",
"@testing-library/react": "^16.0.0",
"@types/archiver": "^6.0.2",
"@types/github-script": "github:actions/github-script",
"@types/jest": "^29.5.12",
"@types/node": "^20.14.10",
"@types/react": "^18.3.3",
"@types/react": "^18.3.4",
"@types/react-dom": "^18.3.0",
"@types/react-router-dom": "^5.3.3",
"@types/webextension-polyfill": "^0.10.7",
"@types/webextension-polyfill": "^0.12.0",
"@typescript-eslint/eslint-plugin": "^7.16.0",
"@typescript-eslint/parser": "^7.16.0",
"archiver": "^7.0.1",
"autoprefixer": "^10.4.19",
"esbuild": "^0.23.0",
"autoprefixer": "^10.4.20",
"esbuild": "^0.23.1",
"esbuild-node-builtin": "^0.1.1",
"esbuild-plugin-copy": "^2.1.1",
"esbuild-style-plugin": "^1.6.3",
"eslint": "^8.57.0",
"eslint-plugin-html": "^8.1.1",
"eslint-plugin-jest": "^28.5.0",
"eslint-plugin-jest": "^28.8.0",
"eslint-plugin-jsx-a11y": "^6.9.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-react": "^7.35.0",
Expand All @@ -71,14 +72,14 @@
"jest-chrome": "^0.8.0",
"jest-environment-jsdom": "^29.7.0",
"jest-transform-stub": "^2.0.0",
"postcss": "^8.4.39",
"postcss": "^8.4.41",
"prettier": "^3.3.3",
"prettier-plugin-tailwindcss": "^0.6.5",
"prettier-plugin-tailwindcss": "^0.6.6",
"sade": "^1.8.1",
"tailwindcss": "^3.4.4",
"ts-jest": "^29.2.3",
"tsx": "^4.16.2",
"typescript": "^5.5.3"
"tailwindcss": "^3.4.10",
"ts-jest": "^29.2.4",
"tsx": "^4.17.0",
"typescript": "^5.5.4"
},
"engines": {
"pnpm": "^9.7.1",
Expand Down
Loading

0 comments on commit 6b73ad3

Please sign in to comment.