Skip to content

Commit b40f415

Browse files
authored
CJS interop + TS types (#15)
* CJS interop + TS types * Improve linter
1 parent 24c118a commit b40f415

File tree

15 files changed

+1401
-295
lines changed

15 files changed

+1401
-295
lines changed

.editorconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,10 @@ root = true
77
[*]
88
end_of_line = lf
99
insert_final_newline = true
10+
indent_style = space
11+
indent_size = 2
12+
charset = utf-8
13+
trim_trailing_whitespace = true
14+
block_comment_start = /**
15+
block_comment = *
16+
block_comment_end = */

.eslintrc

Lines changed: 0 additions & 13 deletions
This file was deleted.

.eslintrc.cjs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/* eslint-env node */
2+
module.exports = {
3+
root: true,
4+
extends: [
5+
'eslint:recommended',
6+
'plugin:@typescript-eslint/recommended',
7+
'prettier',
8+
],
9+
parser: '@typescript-eslint/parser',
10+
plugins: ['@typescript-eslint', 'prettier'],
11+
rules: {
12+
'prettier/prettier': 2, // Means error
13+
},
14+
overrides: [
15+
{
16+
files: ['lint.js', 'cli.js', 'scripts/**/*'],
17+
env: {
18+
node: true,
19+
},
20+
},
21+
],
22+
};

.github/workflows/release.yml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,8 @@ jobs:
3838
env:
3939
AWS_DEFAULT_REGION: us-east-1
4040

41-
- name: Export SQL
42-
run: npm run export-sql
43-
44-
- name: Export JSON
45-
run: npm run export-json
46-
47-
- name: Export Adblocker Engine
48-
run: npm run export-engine
41+
- name: Build
42+
run: npm run build
4943

5044
- name: NPM package version bump
5145
run: npm version patch --no-git-tag-version

.github/workflows/tests.yml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,5 @@ jobs:
3939
- name: Test
4040
run: npm test
4141

42-
- name: Export SQL
43-
run: npm run export-sql
44-
45-
- name: Export JSON
46-
run: npm run export-json
47-
48-
- name: Export Adblocker Engine
49-
run: npm run export-engine
42+
- name: Build
43+
run: npm run build

cli.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
#!/usr/bin/env node
22

33
import { readFileSync } from 'node:fs';
4+
import path from 'node:path';
5+
import * as url from 'url';
46
import { FiltersEngine, Request } from '@cliqz/adblocker';
5-
import { generateEngine } from './src/prepare.js';
67

8+
const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
9+
10+
// eslint-disable-next-line @typescript-eslint/no-empty-function
711
const debug = process.env.DEBUG === 'true' ? console.log : () => {};
812

913
(async () => {
@@ -15,10 +19,10 @@ const debug = process.env.DEBUG === 'true' ? console.log : () => {};
1519
process.exit(1);
1620
}
1721

18-
const trackerEnginePath = await generateEngine();
19-
2022
const loadingStart = Date.now();
21-
const engine = FiltersEngine.deserialize(readFileSync(trackerEnginePath));
23+
const engine = FiltersEngine.deserialize(
24+
readFileSync(path.join(__dirname, 'dist', 'trackerdb.engine')),
25+
);
2226
const loadingEnd = Date.now();
2327

2428
const matches = url.startsWith('http')

fixup

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
cat >dist/cjs/package.json <<!EOF
2+
{
3+
"type": "commonjs"
4+
}
5+
!EOF

lint.js

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -126,22 +126,6 @@ function extractSection(source, tag) {
126126
}
127127
}
128128

129-
function removeSection(source, section) {
130-
return (
131-
source.slice(0, source.lastIndexOf('\n\n---', section[0])) +
132-
source.slice(source.indexOf('\n', section[1] + 1))
133-
);
134-
}
135-
136-
function replaceSection(source, section, replacement) {
137-
replacement.sort();
138-
return (
139-
source.slice(0, section[0]) +
140-
replacement.join('\n') +
141-
source.slice(section[1])
142-
);
143-
}
144-
145129
function* iterPatternFiles() {
146130
const baseDir = path.join(
147131
path.dirname(fileURLToPath(import.meta.url)),

0 commit comments

Comments
 (0)