Skip to content

Commit

Permalink
Run examples in both commonjs and esm (#4103)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrmod authored Jul 16, 2024
1 parent 91eb4c3 commit f8aa010
Show file tree
Hide file tree
Showing 14 changed files with 141 additions and 28 deletions.
13 changes: 12 additions & 1 deletion packages/adblocker-electron-example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,19 @@

Blocking ads in Electron using [@cliqz/adblocker-electron](https://github.com/ghostery/adblocker/tree/master/packages/adblocker-electron).

Build code
```sh
$ yarn start
$ yarn build
```

Start example as commonjs module
```sh
$ yarn start:commonjs
```

Or, start example as esm module
```sh
$ yarn start:esm
```

Checkout [index.ts](./index.ts) for more details!
2 changes: 0 additions & 2 deletions packages/adblocker-electron-example/index.js

This file was deleted.

37 changes: 31 additions & 6 deletions packages/adblocker-electron-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,43 @@
"homepage": "https://github.com/ghostery/adblocker#readme",
"license": "MPL-2.0",
"type": "module",
"tshy": {
"exports": {
"./package.json": "./package.json",
".": "./src/index.ts"
}
},
"exports": {
"./package.json": "./package.json",
".": {
"import": {
"types": "./dist/esm/index.d.ts",
"default": "./dist/esm/index.js"
},
"require": {
"types": "./dist/commonjs/index.d.ts",
"default": "./dist/commonjs/index.js"
}
}
},
"main": "./dist/commonjs/index.js",
"types": "./dist/commonjs/index.d.ts",
"module": "./dist/esm/index.js",
"files": [
"LICENSE",
"index.ts",
"index.js"
"dist"
],
"repository": {
"type": "git",
"url": "git+ssh://git@github.com/ghostery/adblocker.git",
"directory": "packages/adblocker-electron-example"
},
"scripts": {
"start": "electron index.js",
"lint": "eslint index.ts"
"clean": "rimraf dist .tshy .tshy-build",
"start:commonjs": "electron dist/commonjs/index.js",
"start:esm": "electron dist/commonjs/index.js",
"build": "tshy",
"lint": "eslint src/index.ts"
},
"bugs": {
"url": "https://github.com/ghostery/adblocker/issues"
Expand Down Expand Up @@ -63,12 +87,13 @@
"dependencies": {
"@cliqz/adblocker-electron": "^1.28.2",
"cross-fetch": "^4.0.0",
"electron": "^31.0.0",
"tsx": "^4.16.2"
"electron": "^31.0.0"
},
"devDependencies": {
"@types/node": "^20.12.12",
"eslint": "^9.3.0",
"rimraf": "^6.0.1",
"tshy": "^3.0.2",
"typescript": "^5.5.2"
}
}
2 changes: 1 addition & 1 deletion packages/adblocker-electron-example/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
{ "path": "../adblocker-electron/tsconfig.json" }
],
"files": [
"./index.ts"
"./src/index.ts"
]
}
13 changes: 12 additions & 1 deletion packages/adblocker-playwright-example/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
Blocking ads in Playwright using [@cliqz/adblocker-playwright](https://github.com/ghostery/adblocker/tree/master/packages/adblocker-playwright).

Build code
```sh
$ yarn start
$ yarn build
```

Start as commonjs
```sh
$ yarn start:commonjs
```

Or, start as esm
```
$ yarn start:esm
```

Checkout [index.ts](https://github.com/ghostery/adblocker/blob/master/packages/adblocker-playwright-example/index.ts) for more details!
37 changes: 32 additions & 5 deletions packages/adblocker-playwright-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,58 @@
},
"homepage": "https://github.com/ghostery/adblocker#readme",
"license": "MPL-2.0",
"type": "module",
"tshy": {
"exports": {
"./package.json": "./package.json",
".": "./src/index.ts"
}
},
"exports": {
"./package.json": "./package.json",
".": {
"import": {
"types": "./dist/esm/index.d.ts",
"default": "./dist/esm/index.js"
},
"require": {
"types": "./dist/commonjs/index.d.ts",
"default": "./dist/commonjs/index.js"
}
}
},
"main": "./dist/commonjs/index.js",
"types": "./dist/commonjs/index.d.ts",
"module": "./dist/esm/index.js",
"files": [
"LICENSE",
"index.ts"
"dist"
],
"repository": {
"type": "git",
"url": "git+ssh://git@github.com/ghostery/adblocker.git",
"directory": "packages/adblocker-playwright-example"
},
"scripts": {
"start": "tsx index.ts",
"lint": "eslint index.ts"
"clean": "rimraf dist .tshy .tshy-build",
"start:commonjs": "node dist/commonjs/index.js",
"start:esm": "node dist/esm/index.js",
"build": "tshy",
"lint": "eslint src/index.ts"
},
"bugs": {
"url": "https://github.com/ghostery/adblocker/issues"
},
"dependencies": {
"@cliqz/adblocker-playwright": "^1.28.2",
"cross-fetch": "^4.0.0",
"playwright": "^1.38.0",
"tsx": "^4.16.2"
"playwright": "^1.38.0"
},
"devDependencies": {
"@types/node": "^20.12.12",
"eslint": "^9.3.0",
"rimraf": "^6.0.1",
"tshy": "^3.0.2",
"typescript": "^5.5.2"
},
"contributors": [
Expand Down
2 changes: 1 addition & 1 deletion packages/adblocker-playwright-example/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
{ "path": "../adblocker-playwright/tsconfig.json" }
],
"files": [
"./index.ts"
"./src/index.ts"
]
}
13 changes: 12 additions & 1 deletion packages/adblocker-puppeteer-example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,19 @@

Blocking ads in Puppeteer using [@cliqz/adblocker-puppeteer](https://github.com/ghostery/adblocker/tree/master/packages/adblocker-puppeteer).

Build code
```sh
$ yarn start
$ yarn build
```

Start example as commonjs module
```sh
$ yarn start:commonjs
```

Or, start example as esm module
```sh
$ yarn start:esm
```

Checkout [index.ts](./index.ts) for more details!
37 changes: 32 additions & 5 deletions packages/adblocker-puppeteer-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,58 @@
},
"homepage": "https://github.com/ghostery/adblocker#readme",
"license": "MPL-2.0",
"type": "module",
"tshy": {
"exports": {
"./package.json": "./package.json",
".": "./src/index.ts"
}
},
"exports": {
"./package.json": "./package.json",
".": {
"import": {
"types": "./dist/esm/index.d.ts",
"default": "./dist/esm/index.js"
},
"require": {
"types": "./dist/commonjs/index.d.ts",
"default": "./dist/commonjs/index.js"
}
}
},
"main": "./dist/commonjs/index.js",
"types": "./dist/commonjs/index.d.ts",
"module": "./dist/esm/index.js",
"files": [
"LICENSE",
"index.ts"
"dist"
],
"repository": {
"type": "git",
"url": "git+ssh://git@github.com/ghostery/adblocker.git",
"directory": "packages/adblocker-puppeteer-example"
},
"scripts": {
"start": "tsx index.ts",
"lint": "eslint index.ts"
"clean": "rimraf dist .tshy .tshy-build",
"start:commonjs": "node dist/commonjs/index.js",
"start:esm": "node dist/esm/index.js",
"build": "tshy",
"lint": "eslint src/index.ts"
},
"bugs": {
"url": "https://github.com/ghostery/adblocker/issues"
},
"dependencies": {
"@cliqz/adblocker-puppeteer": "^1.28.2",
"cross-fetch": "^4.0.0",
"puppeteer": "22.13.0",
"tsx": "^4.16.2"
"puppeteer": "22.13.0"
},
"devDependencies": {
"@types/node": "^20.12.12",
"eslint": "^9.3.0",
"rimraf": "^6.0.1",
"tshy": "^3.0.2",
"typescript": "^5.5.2"
},
"contributors": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { promises as fs } from 'fs';

function getUrlToLoad(): string {
let url = 'https://www.mangareader.to/';
if (process.argv[process.argv.length - 1].endsWith('.ts') === false) {
if (process.argv[process.argv.length - 1].endsWith('.js') === false) {
url = process.argv[process.argv.length - 1];
}

Expand Down
2 changes: 1 addition & 1 deletion packages/adblocker-puppeteer-example/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
{ "path": "../adblocker-puppeteer/tsconfig.json" }
],
"files": [
"./index.ts"
"./src/index.ts"
]
}
9 changes: 6 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,8 @@ __metadata:
cross-fetch: "npm:^4.0.0"
electron: "npm:^31.0.0"
eslint: "npm:^9.3.0"
tsx: "npm:^4.16.2"
rimraf: "npm:^6.0.1"
tshy: "npm:^3.0.2"
typescript: "npm:^5.5.2"
languageName: unknown
linkType: soft
Expand Down Expand Up @@ -475,7 +476,8 @@ __metadata:
cross-fetch: "npm:^4.0.0"
eslint: "npm:^9.3.0"
playwright: "npm:^1.38.0"
tsx: "npm:^4.16.2"
rimraf: "npm:^6.0.1"
tshy: "npm:^3.0.2"
typescript: "npm:^5.5.2"
languageName: unknown
linkType: soft
Expand Down Expand Up @@ -513,7 +515,8 @@ __metadata:
cross-fetch: "npm:^4.0.0"
eslint: "npm:^9.3.0"
puppeteer: "npm:22.13.0"
tsx: "npm:^4.16.2"
rimraf: "npm:^6.0.1"
tshy: "npm:^3.0.2"
typescript: "npm:^5.5.2"
languageName: unknown
linkType: soft
Expand Down

0 comments on commit f8aa010

Please sign in to comment.