Skip to content

Commit

Permalink
ESM modules (#3924)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrmod committed May 24, 2024
1 parent 52acfb2 commit 3e0ff50
Show file tree
Hide file tree
Showing 58 changed files with 637 additions and 586 deletions.
File renamed without changes.
3 changes: 0 additions & 3 deletions .github/workflows/assets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ jobs:
- name: Build
run: yarn build

- name: Bundle
run: yarn bundle

- name: Fetch latest assets
id: fetch
working-directory: ./packages/adblocker/assets
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ jobs:
- name: Build
run: yarn build

- name: Bundle
run: yarn bundle

- name: Lint
run: yarn lint

Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,3 @@ jobs:

- name: Test
run: yarn test

- name: Bundle
run: yarn bundle
9 changes: 0 additions & 9 deletions .mocharc.js

This file was deleted.

13 changes: 13 additions & 0 deletions .mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"timeout": 10000,
"reporter": "spec",
"require": "ts-node/register",
"retries": 0,
"color": false,
"extension": ["ts"],
"recursive": true,
"node-option": [
"experimental-specifier-resolution=node",
"loader=ts-node/esm"
]
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"author": {
"name": "Ghostery"
},
"type": "module",
"description": "Cliqz adblocker",
"contributors": [
{
Expand Down Expand Up @@ -61,7 +62,6 @@
"lint": "lerna run --parallel lint",
"watch": "tsc --build ./tsconfig.project.json --watch",
"build": "tsc --build ./tsconfig.project.json && lerna run build",
"bundle": "lerna run --concurrency 4 bundle",
"test": "lerna run --concurrency 4 test",
"clean": "lerna run --parallel clean && lerna clean --yes",
"release": "auto shipit -v",
Expand All @@ -83,7 +83,7 @@
"lerna": "^8.0.0",
"patch-package": "^8.0.0",
"prettier": "^3.0.3",
"typescript": "^5.2.2"
"typescript": "^5.4.5"
},
"auto": {
"extends": "@remusao/auto-config",
Expand Down
16 changes: 10 additions & 6 deletions packages/adblocker-content/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@
},
"homepage": "https://github.com/cliqz-oss/adblocker#readme",
"license": "MPL-2.0",
"main": "dist/cjs/adblocker.js",
"module": "dist/es6/adblocker.js",
"type": "module",
"exports": {
"require": "./dist/cjs/adblocker.cjs",
"import": "./dist/esm/adblocker.js",
"types": "./dist/types/adblocker.d.ts"
},
"main": "dist/cjs/adblocker.cjs",
"module": "dist/esm/adblocker.js",
"types": "dist/types/adblocker.d.ts",
"files": [
"LICENSE",
Expand All @@ -25,9 +31,7 @@
"scripts": {
"clean": "rimraf dist coverage",
"lint": "eslint adblocker.ts",
"build": "tsc --build ./tsconfig.json",
"bundle": "tsc --build ./tsconfig.bundle.json && rollup --config ./rollup.config.ts --configPlugin typescript",
"prepack": "yarn run bundle"
"build": "tsc --build ./tsconfig.json && rollup --config ./rollup.config.ts --configPlugin typescript"
},
"bugs": {
"url": "https://github.com/cliqz-oss/adblocker/issues"
Expand All @@ -44,7 +48,7 @@
"rollup": "^4.0.2",
"rollup-plugin-sourcemaps": "^0.6.3",
"rollup-plugin-terser": "^7.0.2",
"typescript": "^5.2.2"
"typescript": "^5.4.5"
},
"contributors": [
{
Expand Down
51 changes: 35 additions & 16 deletions packages/adblocker-content/rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,40 @@ import resolve from '@rollup/plugin-node-resolve';
import sourcemaps from 'rollup-plugin-sourcemaps';
import { terser } from 'rollup-plugin-terser';

export default {
input: './dist/es6/adblocker.js',
output: {
file: './dist/adblocker.umd.min.js',
format: 'umd',
name: 'adblocker',
sourcemap: true,
export default [
{
input: './dist/src/adblocker.js',
output: {
file: './dist/adblocker.umd.min.js',
format: 'umd',
name: 'adblocker',
sourcemap: true,
},
plugins: [
resolve(),
sourcemaps(),
terser({
output: {
comments: false,
},
}),
],
},
plugins: [
resolve(),
sourcemaps(),
terser({
output: {
comments: false,
{
input: './dist/src/adblocker.js',
output: [
{
dir: './dist/esm',
format: 'esm',
preserveModules: true,
entryFileNames: '[name].js',
},
}),
],
};
{
dir: './dist/cjs',
format: 'cjs',
preserveModules: true,
entryFileNames: '[name].cjs',
},
],
},
];
12 changes: 0 additions & 12 deletions packages/adblocker-content/tsconfig.bundle.json

This file was deleted.

5 changes: 2 additions & 3 deletions packages/adblocker-content/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{
"extends": "../../tsconfig",
"compilerOptions": {
"composite": true,
"outDir": "dist/cjs",
"declarationDir": "dist/types"
"outDir": "./dist/src",
"declarationDir": "./dist/types",
},
"references": [
{ "path": "../adblocker-extended-selectors/tsconfig.json" },
Expand Down
5 changes: 2 additions & 3 deletions packages/adblocker-electron-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,12 @@
],
"dependencies": {
"@cliqz/adblocker-electron": "^1.27.3",
"cross-fetch": "^4.0.0",
"electron": "^30.0.0",
"node-fetch": "^3.3.2",
"ts-node": "^10.9.1"
},
"devDependencies": {
"@types/node-fetch": "^3.0.3",
"eslint": "^8.49.0",
"typescript": "^5.2.2"
"typescript": "^5.4.5"
}
}
13 changes: 9 additions & 4 deletions packages/adblocker-electron-preload/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@
},
"homepage": "https://github.com/cliqz-oss/adblocker#readme",
"license": "MPL-2.0",
"main": "dist/preload.cjs.js",
"module": "dist/preload.es6.js",
"type": "module",
"exports": {
"require": "./dist/cjs/preload.cjs",
"import": "./dist/esm/preload.js",
"types": "./dist/types/preload.d.ts"
},
"main": "dist/preload.cjs",
"module": "dist/esm/preload.js",
"types": "dist/types/preload.d.ts",
"files": [
"LICENSE",
Expand All @@ -29,7 +35,6 @@
"clean": "rimraf dist coverage",
"lint": "eslint preload.ts",
"build": "tsc --build ./tsconfig.json && rollup --config ./rollup.config.ts --configPlugin typescript",
"bundle": "yarn build",
"prepack": "yarn run bundle"
},
"peerDependencies": {
Expand All @@ -48,7 +53,7 @@
"rimraf": "^5.0.1",
"rollup": "^4.0.2",
"rollup-plugin-sourcemaps": "^0.6.3",
"typescript": "^5.2.2"
"typescript": "^5.4.5"
},
"contributors": [
{
Expand Down
10 changes: 5 additions & 5 deletions packages/adblocker-electron-preload/rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ import sourcemaps from 'rollup-plugin-sourcemaps';
import commonjs from '@rollup/plugin-commonjs';

export default {
input: './dist/es6/preload.js',
input: './dist/src/preload.js',
external: ['electron'],
output: [
{
file: './dist/preload.es6.js',
format: 'esm',
file: './dist/cjs/preload.cjs',
format: 'commonjs',
sourcemap: true,
},
{
file: './dist/preload.cjs.js',
format: 'commonjs',
file: './dist/esm/preload.cjs',
format: 'esm',
sourcemap: true,
},
],
Expand Down
6 changes: 2 additions & 4 deletions packages/adblocker-electron-preload/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
{
"extends": "../../tsconfig",
"compilerOptions": {
"composite": true,
"outDir": "dist/es6",
"module": "es6",
"declarationDir": "dist/types"
"outDir": "./dist/src",
"declarationDir": "./dist/types",
},
"references": [
{ "path": "../adblocker-content/tsconfig.json" }
Expand Down
8 changes: 5 additions & 3 deletions packages/adblocker-electron/adblocker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

import { resolve } from 'path';
import { ipcMain } from 'electron';
import * as electron from 'electron';
import { parse } from 'tldts-experimental';
import { createRequire } from 'node:module';

import { ElectronRequestType, FiltersEngine, Request } from '@cliqz/adblocker';
import type {
IBackgroundCallback,
IMessageFromBackground,
} from '@cliqz/adblocker-electron-preload';

const PRELOAD_PATH = resolve(require.resolve('@cliqz/adblocker-electron-preload'));
const { ipcMain } = electron;

const PRELOAD_PATH = createRequire(import.meta.url).resolve('@cliqz/adblocker-electron-preload');

// https://stackoverflow.com/questions/48854265/why-do-i-see-an-electron-security-warning-after-updating-my-electron-project-t
process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true';
Expand Down
23 changes: 16 additions & 7 deletions packages/adblocker-electron/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@
},
"homepage": "https://github.com/cliqz-oss/adblocker#readme",
"license": "MPL-2.0",
"main": "dist/cjs/adblocker.js",
"module": "dist/es6/adblocker.js",
"type": "module",
"exports": {
"require": "./dist/cjs/adblocker.cjs",
"import": "./dist/esm/adblocker.js",
"types": "./dist/types/adblocker.d.ts"
},
"main": "dist/cjs/adblocker.cjs",
"module": "dist/esm/adblocker.js",
"types": "dist/types/adblocker.d.ts",
"files": [
"LICENSE",
Expand All @@ -28,10 +34,9 @@
"scripts": {
"clean": "rimraf dist coverage",
"lint": "eslint adblocker.ts",
"build": "tsc --build ./tsconfig.json",
"bundle": "tsc --build ./tsconfig.bundle.json",
"build": "tsc --build ./tsconfig.json && rollup --config ./rollup.config.ts --configPlugin typescript",
"prepack": "yarn run bundle",
"test": "nyc mocha --config ../../.mocharc.js"
"test": "nyc mocha --config ../../.mocharc.json"
},
"peerDependencies": {
"electron": ">11"
Expand All @@ -42,16 +47,20 @@
"tldts-experimental": "^6.0.14"
},
"devDependencies": {
"@rollup/plugin-node-resolve": "^15.2.3",
"@types/chai": "^4.3.6",
"@types/mocha": "^10.0.1",
"chai": "^4.3.8",
"chai": "^5.1.0",
"electron": "^30.0.0",
"eslint": "^8.49.0",
"mocha": "^10.2.0",
"nyc": "^15.1.0",
"rimraf": "^5.0.1",
"rollup": "^4.17.2",
"rollup-plugin-sourcemaps": "^0.6.3",
"rollup-plugin-terser": "^7.0.2",
"ts-node": "^10.9.1",
"typescript": "^5.2.2"
"typescript": "^5.4.5"
},
"contributors": [
{
Expand Down

0 comments on commit 3e0ff50

Please sign in to comment.