Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
fregante committed Jan 9, 2024
1 parent 9b7ffd6 commit f87ff7b
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 30 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ jobs:
Lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- run: npm install
- run: npx xo

Build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- run: npm install
- run: npm run build

Test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- run: npm install
- run: npm run build
- run: npx ava
32 changes: 18 additions & 14 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,26 @@ function getRawPatternRegex(matchPattern: string): string {
throw new Error(matchPattern + ' is an invalid pattern, it must match ' + String(patternValidationRegex));
}

let [, protocol, host, pathname] = matchPattern.split(/(^[^:]+:[/][/])([^/]+)?/);
// Host undefined for file:///
let [, protocol, host = '', pathname] = matchPattern.split(/(^[^:]+:[/][/])([^/]+)?/);

protocol = protocol
protocol = protocol!
.replace('*', isFirefox ? '(https?|wss?)' : 'https?') // Protocol wildcard
.replace(/[/]/g, '[/]'); // Escape slashes

host = (host ?? '') // Undefined for file:///
.replace(/^[*][.]/, '([^/]+.)*') // Initial wildcard
.replace(/^[*]$/, '[^/]+') // Only wildcard
.replace(/[.]/g, '[.]') // Escape dots
.replace(/[*]$/g, '[^.]+'); // Last wildcard

pathname = pathname
.replace(/[/]/g, '[/]') // Escape slashes
.replace(/[.]/g, '[.]') // Escape dots
.replace(/[*]/g, '.*'); // Any wildcard
.replaceAll(/[/]/g, '[/]'); // Escape slashes

if (host === '*') {
host = '[^/]+';
} else if (host) {
host = host
.replace(/^[*][.]/, '([^/]+.)*') // Initial wildcard
.replaceAll(/[.]/g, '[.]') // Escape dots
.replace(/[*]$/, '[^.]+'); // Last wildcard
}

pathname = pathname!
.replaceAll(/[/]/g, '[/]') // Escape slashes
.replaceAll(/[.]/g, '[.]') // Escape dots
.replaceAll(/[*]/g, '.*'); // Any wildcard

return '^' + protocol + host + '(' + pathname + ')?$';
}
Expand Down
20 changes: 12 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"author": "Federico Brigante <me@fregante.com> (https://fregante.com)",
"type": "module",
"main": "index.js",
"module": "index.js",
"exports": "./index.js",
"types": "./index.d.ts",
"files": [
"index.js",
"index.d.ts"
Expand All @@ -48,13 +49,16 @@
"escape-string-regexp": "^5.0.0"
},
"devDependencies": {
"@sindresorhus/tsconfig": "^3.0.1",
"@types/chrome": "0.0.210",
"ava": "^5.1.1",
"sinon": "^15.0.1",
"type-fest": "^3.5.3",
"typescript": "^4.9.4",
"xo": "^0.53.1"
"@sindresorhus/tsconfig": "^5.0.0",
"@types/chrome": "0.0.256",
"ava": "^6.0.1",
"sinon": "^17.0.1",
"type-fest": "^4.9.0",
"typescript": "^5.3.3",
"xo": "^0.56.0"
},
"engines": {
"node": ">=18"
},
"webExt": {
"sourceDir": "demo-extension",
Expand Down
5 changes: 0 additions & 5 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
{
"extends": "@sindresorhus/tsconfig",
"compilerOptions": {
"target": "es2018",
"module": "es2015",
"noUncheckedIndexedAccess": false
},
"files": [
"index.ts"
]
Expand Down

0 comments on commit f87ff7b

Please sign in to comment.