Skip to content

Commit 0ad264c

Browse files
authored
Merge pull request #20 from nobkd/refactor
mini refactor
2 parents c6ba837 + 479e55e commit 0ad264c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+834
-654
lines changed

.editorconfig

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
root = true
2+
charset = utf-8
3+
end_of_line = lf
4+
tab_width = 2
5+
indent_size = 2
6+
indent_style = tab
7+
trim_trailing_whitespace = true
8+
insert_final_newline = true

.github/workflows/ci.yml

+1-21
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,9 @@ on:
88
branches:
99
- main
1010

11-
concurrency:
12-
group: ${{ github.ref }}
13-
cancel-in-progress: false
14-
1511
jobs:
16-
lint:
17-
name: Lint
18-
timeout-minutes: 10
19-
runs-on: ubuntu-latest
20-
21-
steps:
22-
- uses: actions/checkout@v4
23-
- uses: oven-sh/setup-bun@v1
24-
25-
- name: Install
26-
run: bun install --frozen-lockfile
27-
28-
- name: Lint
29-
run: bun run lint
30-
3112
test:
3213
name: Test
33-
timeout-minutes: 10
3414
runs-on: ubuntu-latest
3515

3616
steps:
@@ -41,4 +21,4 @@ jobs:
4121
run: bun install --frozen-lockfile
4222

4323
- name: Test
44-
run: bun run test:cov
24+
run: bun test --coverage

.github/workflows/publish.yml

+3-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ concurrency:
1111
jobs:
1212
publish:
1313
name: Publish to Firefox AMO
14-
timeout-minutes: 10
1514
runs-on: ubuntu-latest
1615

1716
steps:
@@ -28,14 +27,14 @@ jobs:
2827
run: bun run bundle
2928

3029
- name: Bundle source
31-
run: git archive --format=zip ${{ github.event.release.tag_name }} --output out/replace_maps_source.zip
30+
run: git archive --format=zip ${{ github.event.release.tag_name }} --output .out/replace_maps_source.zip
3231

3332
- name: Release
3433
uses: browser-actions/release-firefox-addon@latest
3534
with:
3635
37-
addon-path: out/replace_maps.zip
38-
source-path: out/replace_maps_source.zip
36+
addon-path: .out/replace_maps.zip
37+
source-path: .out/replace_maps_source.zip
3938
approval-note: Follow the instructions in AMO-README.md
4039
release-note: ${{ github.event.release.body }} # TODO: convert md to html, h1-6 not allowed... Currently ignoring this problem, as the field is needed for publishing
4140
license: MPL-2.0

.gitignore

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
node_modules/
2-
dist/
3-
out/
4-
coverage/
2+
.dist/
3+
.out/
4+
55
.version-update
66
.env
7-
8-
public/icons/

.prettierignore

-6
This file was deleted.

.prettierrc

-12
This file was deleted.

AMO-README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ This uses the `package-lock.json` file for installation to avoid package changes
1818
bun run build && bun run bundle
1919
```
2020

21-
This transpiles and minifies the TypeScript, copies static resources and bundles the output to `out/replace_maps.zip`.
21+
This minifies the JavaScript, copies static resources and bundles the output to `.out/replace_maps.zip`.

build.sh

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/sh
2+
3+
# clean & create dir
4+
rm -rf '.dist'
5+
mkdir -p '.dist'
6+
7+
# copy static resources
8+
cp -r 'public/.' '.dist'
9+
cp 'node_modules/leaflet/dist/images/marker-icon-2x.png' 'node_modules/leaflet/dist/images/marker-shadow.png' '.dist'
10+
11+
# check if dev / prod, then build
12+
if [[ $1 == 'dev' ]]; then
13+
echo '--watch'
14+
else
15+
echo '--minify'
16+
fi | xargs bun build --experimental-css --experimental-html --outdir '.dist' 'src/bg.html' 'src/map.html' 'src/options.html'

bump.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { writeFileSync } from 'node:fs'
2+
import { version } from './package.json' with { type: 'json' }
3+
import manifest from './public/manifest.json' with { type: 'json' }
4+
5+
manifest.version = version
6+
writeFileSync('./public/manifest.json', JSON.stringify(manifest, null, 2))

bun.lock

+283
Large diffs are not rendered by default.

bun.lockb

-348 KB
Binary file not shown.

package.json

+10-28
Original file line numberDiff line numberDiff line change
@@ -15,38 +15,21 @@
1515
"url": "git+https://github.com/nobkd/replace-maps.git"
1616
},
1717
"scripts": {
18-
"postinstall": "bun build-icons.js",
19-
"lint": "prettier . --check",
20-
"lint:fix": "prettier . --write",
21-
"test": "vitest run",
22-
"test:watch": "vitest",
23-
"test:cov": "vitest run --coverage",
18+
"icons": "bun i --no-save oslllo-svg2 && bun build-icons.js",
2419
"dev": "run-p -rl build:dev serve",
25-
"build": "vite build",
26-
"build:dev": "vite build --watch --mode development --minify false",
27-
"serve": "web-ext run -s dist",
28-
"bundle": "web-ext build -s dist -a out --overwrite-dest -n replace_maps.zip",
29-
"release": "release-it"
20+
"build": "sh build.sh",
21+
"build:dev": "sh build.sh dev",
22+
"serve": "bunx web-ext run -s .dist",
23+
"bundle": "bunx web-ext build -s .dist -a .out --overwrite-dest -n replace_maps.zip",
24+
"release": "bun i --no-save release-it release-it-changelogen && release-it"
3025
},
3126
"devDependencies": {
32-
"@types/leaflet": "^1.9.12",
33-
"@types/leaflet-fullscreen": "^1.0.9",
34-
"@types/webextension-polyfill": "^0.10.7",
35-
"@vitest/coverage-v8": "^1.6.0",
36-
"npm-run-all": "^4.1.5",
37-
"oslllo-svg2": "^2.0.2",
38-
"prettier": "^3.3.2",
39-
"release-it": "^17.4.0",
40-
"release-it-changelogen": "^0.1.0",
41-
"vite": "^5.3.2",
42-
"vite-plugin-static-copy": "^1.0.5",
43-
"vitest": "^1.6.0",
44-
"web-ext": "^8.2.0",
45-
"webextension-polyfill": "^0.12.0"
27+
"npm-run-all": "^4.1.5"
4628
},
4729
"dependencies": {
4830
"leaflet": "^1.9.4",
49-
"leaflet-fullscreen": "^1.0.2"
31+
"leaflet-fullscreen": "^1.0.2",
32+
"webextension-polyfill": "^0.12.0"
5033
},
5134
"release-it": {
5235
"git": {
@@ -70,12 +53,11 @@
7053
},
7154
"hooks": {
7255
"before:init": [
73-
"bun run lint",
7456
"bun run test",
7557
"bun run build"
7658
],
7759
"after:bump": [
78-
"sh scripts/bump.sh"
60+
"bun bump.js"
7961
]
8062
}
8163
}

public/icons/48-icon-grey.png

1.71 KB
Loading

public/icons/48-icon.png

1.72 KB
Loading

public/icons/96-icon-grey.png

2.73 KB
Loading

public/icons/96-icon.png

2.99 KB
Loading

public/manifest.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
"background": {
2626
"page": "bg.html"
2727
},
28-
"web_accessible_resources": ["map.html"],
28+
"web_accessible_resources": [
29+
"map.html"
30+
],
2931
"browser_action": {
3032
"default_icon": {
3133
"48": "icons/48-icon.png",
@@ -37,4 +39,4 @@
3739
"options_ui": {
3840
"page": "options.html"
3941
}
40-
}
42+
}

scripts/bump.sh

-1
This file was deleted.

src/bg.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
<!doctype html>
1+
<!DOCTYPE html>
22
<head>
3-
<meta charset="UTF-8" />
3+
<meta charset="UTF-8">
44
<script src="bg/action.js" type="module"></script>
55
<script src="bg/bg.js" type="module"></script>
66
</head>

src/bg/action.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { browserAction, /*webNavigation,*/ Tabs, tabs } from 'webextension-polyfill'
2-
import { getHostname, invertHostState } from './utils/storage'
1+
import { tabs, browserAction, /*webNavigation*/ } from 'webextension-polyfill'
2+
3+
import { getHostname, invertHostState } from './utils/storage.js'
34
//import { matcher as mapsUrlMatcher, runtimeMapUrl } from './bg';
45

56
//const replacedUrlMatcher = new RegExp(`^${runtimeMapUrl}\?`);
@@ -10,7 +11,7 @@ import { getHostname, invertHostState } from './utils/storage'
1011
*
1112
* Requests all frames from the current tab, filters them for extension Leaflet frames and Maps frames.
1213
* Reloads the full tab on extension Leaflet or Maps frame match.
13-
* @param {Tabs.Tab} tab Currently active tab
14+
* @param {browser.Tabs.Tab} tab Currently active tab
1415
*/
1516
async function actionClick(tab) {
1617
if (!tab.url || !tab.id) return

src/bg/bg.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { runtime, tabs, windows, webRequest, WebRequest } from 'webextension-polyfill'
2-
import { disabledHosts, getHostname } from './utils/storage'
3-
import { updateActiveTabIcon } from './utils/actionIcon'
4-
import { domainEnds } from './utils/domainEnds'
1+
import { runtime, webRequest, tabs, windows } from 'webextension-polyfill'
2+
3+
import { disabledHosts, getHostname } from './utils/storage.js'
4+
import { updateActiveTabIcon } from './utils/actionIcon.js'
5+
import domainEnds from './utils/domainEnds.json' with { type: 'json' }
56

67
const gLocales = domainEnds.join('|') // TODO: collect more locales
78
export const matcher = new RegExp(
@@ -14,8 +15,8 @@ export const runtimeMapUrl = runtime.getURL('map.html')
1415
* Checks if `frames` send a request to Maps.
1516
* If they do and the extension isn't disabled for the current site, then the request is redirected to the extension leaflet map with all URL search params.
1617
* Else the request is'nt blocked.
17-
* @param {WebRequest.OnBeforeRequestDetailsType} req Web Request from frame
18-
* @returns {WebRequest.BlockingResponse} Redirect to extension map or pass through if extension disabled for website
18+
* @param {browser.WebRequest.OnBeforeRequestDetailsType} req Web Request from frame
19+
* @returns {browser.WebRequest.BlockingResponse} Redirect to extension map or pass through if extension disabled for website
1920
*/
2021
function redirect(req) {
2122
// TODO: check if originUrl always matches current tab url -> e.g. in frames with subframes

src/bg/utils/actionIcon.js

+9-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { browserAction, tabs } from 'webextension-polyfill'
2-
import { disabledHosts, getHostname } from './storage'
2+
3+
import { disabledHosts, getHostname } from './storage.js'
34

45
/**
56
* Updates the action icon
@@ -9,15 +10,13 @@ export function updateIcon(hostname) {
910
let disabled = disabledHosts.includes(hostname)
1011

1112
browserAction.setIcon({
12-
path: !disabled
13-
? {
14-
48: '/icons/48-icon.png',
15-
96: '/icons/96-icon.png',
16-
}
17-
: {
18-
48: '/icons/48-icon-grey.png',
19-
96: '/icons/96-icon-grey.png',
20-
},
13+
path: !disabled ? {
14+
48: '/icons/48-icon.png',
15+
96: '/icons/96-icon.png',
16+
} : {
17+
48: '/icons/48-icon-grey.png',
18+
96: '/icons/96-icon-grey.png',
19+
},
2120
})
2221
}
2322

0 commit comments

Comments
 (0)