Skip to content

Commit

Permalink
Introduce typescript to scriptlets, migrate helpers
Browse files Browse the repository at this point in the history
Merge in ADGUARD-FILTERS/scriptlets from feature/typescript to master

Squashed commit of the following:

commit f931a21
Merge: 0acaf28 7f8dd98
Author: Stanislav A <s.atroschenko@adguard.com>
Date:   Mon Jun 19 15:58:57 2023 +0300

    Merge branch 'master' into feature/typescript

commit 0acaf28
Merge: 1339ca3 0512bd1
Author: stanislav-atr <s.atroschenko@adguard.com>
Date:   Sat Jun 17 01:15:09 2023 +0300

    Merge branch 'master' into feature/typescript

commit 1339ca3
Author: stanislav-atr <s.atroschenko@adguard.com>
Date:   Thu Jun 15 01:12:57 2023 +0300

    fix jsdocplugin and lint

commit e39c4ed
Author: stanislav-atr <s.atroschenko@adguard.com>
Date:   Tue Jun 13 22:52:47 2023 +0300

    improve observer naming in observeDocumentWithTimeout

commit 7ea0547
Author: stanislav-atr <s.atroschenko@adguard.com>
Date:   Sun Jun 11 00:30:13 2023 +0300

    add missing typings

commit d646852
Author: stanislav-atr <s.atroschenko@adguard.com>
Date:   Sat Jun 10 23:52:59 2023 +0300

    resolve linting and misc typings

commit 48fd2b1
Author: stanislav-atr <s.atroschenko@adguard.com>
Date:   Sat Jun 10 23:22:39 2023 +0300

    fix abort-on-stack-trace testcase

commit 95beeb9
Author: stanislav-atr <s.atroschenko@adguard.com>
Date:   Sat Jun 10 21:38:53 2023 +0300

    update yarn.lock

commit 363eab9
Author: stanislav-atr <s.atroschenko@adguard.com>
Date:   Sat Jun 10 21:22:25 2023 +0300

    convert response-utils

commit 754e817
Author: stanislav-atr <s.atroschenko@adguard.com>
Date:   Sat Jun 10 21:09:57 2023 +0300

    resolve fixmes

commit d192e9c
Author: stanislav-atr <s.atroschenko@adguard.com>
Date:   Sat Jun 10 20:54:45 2023 +0300

    fix prune-utils

commit 9c36493
Merge: ac2782b a55b61f
Author: stanislav-atr <s.atroschenko@adguard.com>
Date:   Thu Jun 8 02:30:26 2023 +0300

    merge master

commit ac2782b
Author: stanislav-atr <s.atroschenko@adguard.com>
Date:   Wed Jun 7 23:08:07 2023 +0300

    tweak getAbpSnippetArguments

commit 23dd9f6
Author: stanislav-atr <s.atroschenko@adguard.com>
Date:   Sun May 14 20:46:57 2023 +0300

    improve convertScriptletToAdg, fix createOnErrorHandler calls linting

commit 5ac964d
Author: stanislav-atr <s.atroschenko@adguard.com>
Date:   Sun May 14 19:20:54 2023 +0300

    rename RedirectCompatibilityObject, fix createOnErrorHandler calls

commit 6cc6597
Author: stanislav-atr <s.atroschenko@adguard.com>
Date:   Wed May 10 23:04:13 2023 +0300

    improve createOnErrorHandler typings

commit 198448c
Author: stanislav-atr <s.atroschenko@adguard.com>
Date:   Sun May 7 23:01:08 2023 +0300

    return index in imports paths

commit 27765da
Author: stanislav-atr <s.atroschenko@adguard.com>
Date:   Sun May 7 22:42:10 2023 +0300

    fix LegalRequestProp, improve :any typings, tweak hit() and remove 'hit' prop from Source

commit 7ef8e59
Merge: 16c3d3e e60fdd1
Author: stanislav-atr <s.atroschenko@adguard.com>
Date:   Sun May 7 21:40:06 2023 +0300

    merge master

commit 16c3d3e
Author: stanislav-atr <s.atroschenko@adguard.com>
Date:   Fri Apr 28 01:22:50 2023 +0300

    improve number-utils typings, fix validator comments

... and 31 more commits
  • Loading branch information
stanislav-atr committed Jun 19, 2023
1 parent 7f8dd98 commit 6c3693f
Show file tree
Hide file tree
Showing 84 changed files with 4,249 additions and 3,588 deletions.
94 changes: 71 additions & 23 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
const path = require('path');

module.exports = {
extends: [
'airbnb-base',
'plugin:jsdoc/recommended',
],
parser: '@babel/eslint-parser',
parserOptions: {
babelOptions: {
Expand All @@ -14,23 +12,39 @@ module.exports = {
qunit: true,
jest: true,
},
rules: {
'max-len': [
'error',
{
code: 120,
ignoreUrls: true,
extends: [
'airbnb-base',
'plugin:jsdoc/recommended',
],
plugins: [
'import',
'import-newlines',
],
settings: {
'import/resolver': {
typescript: {
alwaysTryTypes: true,
project: 'tsconfig.eslint.json',
},
],
indent: ['error', 4, { SwitchCase: 1 }],
},
},
rules: {
indent: ['error', 4, {
SwitchCase: 1,
}],
'import/extensions': ['error', 'never', { json: 'always' }],
'no-param-reassign': 0,
'no-shadow': 0,
'no-bitwise': 0,
'no-new': 0,
'import/prefer-default-export': 0,
'arrow-body-style': 0,
'import/no-extraneous-dependencies': 0,
'no-continue': 'off',
'no-continue': 0,
'no-await-in-loop': 0,
'no-restricted-syntax': 0,
'max-len': ['error', { code: 120, ignoreUrls: true }],
'arrow-body-style': 0,
'import/no-extraneous-dependencies': ['error', { devDependencies: true }],
'no-restricted-syntax': ['error', 'LabeledStatement', 'WithStatement'],
'no-constant-condition': ['error', { checkLoops: false }],
// jsdoc rules
'jsdoc/check-tag-names': ['error', {
definedTags: [
Expand All @@ -44,16 +58,50 @@ module.exports = {
'jsdoc/tag-lines': 'off',
'jsdoc/require-jsdoc': 0,
'jsdoc/require-param': 0,
'jsdoc/valid-types': 0,
'jsdoc/no-undefined-types': 0,
'jsdoc/require-param-description': 0,
'jsdoc/require-returns-description': 0,
},
settings: {
jsdoc: {
preferredTypes: {
object: 'Object',
overrides: [
{
files: ['**/*.ts'],
parser: '@typescript-eslint/parser',
parserOptions: {
tsconfigRootDir: path.join(__dirname),
project: 'tsconfig.eslint.json',
},
extends: [
'airbnb-typescript/base',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
],
rules: {
'jsdoc/require-param-type': 0,
'jsdoc/require-returns-type': 0,
'@typescript-eslint/ban-ts-comment': 0,
'@typescript-eslint/member-delimiter-style': [
'error',
{
multiline: {
delimiter: 'semi',
requireLast: true,
},
singleline: {
delimiter: 'semi',
requireLast: false,
},
},
],
'@typescript-eslint/no-explicit-any': 0,
'@typescript-eslint/indent': ['error', 4],
'@typescript-eslint/interface-name-prefix': 0,
'@typescript-eslint/no-non-null-assertion': 0,
'@typescript-eslint/type-annotation-spacing': [
'error',
{
after: true,
},
],
},
},
},
],
};
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ where:

```javascript
/**
* @typedef {Object} Source — Scriptlet properties.
* @typedef {object} Source — Scriptlet properties.
* @property {string} name — Scriptlet name.
* @property {Array<string>} args — Arguments for scriptlet function.
* @property {'extension'|'corelibs'} engine — Defines the final form of scriptlet string presentation.
Expand Down
7 changes: 7 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,17 @@ module.exports = (api) => {
],
},
],
[
'@babel/preset-typescript',
{
optimizeConstEnums: true,
},
],
],
plugins: [
'@babel/plugin-transform-runtime',
'@babel/plugin-transform-arrow-functions',
'@babel/plugin-transform-function-name',
],
};

Expand Down
42 changes: 27 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"version": "1.9.39",
"description": "AdGuard's JavaScript library of Scriptlets and Redirect resources",
"scripts": {
"build": "babel-node scripts/build.js",
"build": "babel-node -x .js,.ts scripts/build.js",
"test": "yarn test:jest && yarn test:qunit",
"browserstack": "yarn test --build && node browserstack.js",
"test:qunit": "babel-node scripts/test.js",
"test:qunit": "babel-node -x .js,.ts scripts/test.js",
"test:jest": "jest",
"lint": "eslint --cache . && yarn lint:md",
"lint:md": "markdownlint .",
Expand Down Expand Up @@ -41,21 +41,27 @@
}
},
"dependencies": {
"@babel/runtime": "^7.7.2",
"@babel/runtime": "^7.20.13",
"js-yaml": "^3.13.1"
},
"devDependencies": {
"@babel/cli": "^7.20.7",
"@babel/core": "^7.20.12",
"@babel/eslint-parser": "^7.19.1",
"@babel/node": "^7.20.7",
"@babel/plugin-transform-runtime": "^7.6.2",
"@babel/eslint-parser": "^7.16.5",
"@babel/node": "^7.8.7",
"@babel/plugin-proposal-class-properties": "^7.18.6",
"@babel/plugin-proposal-private-methods": "^7.18.6",
"@babel/plugin-transform-regenerator": "^7.20.5",
"@babel/plugin-transform-runtime": "^7.19.6",
"@babel/preset-env": "^7.20.2",
"@rollup/plugin-babel": "^5.0.4",
"@rollup/plugin-commonjs": "^17.0.0",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^8.1.0",
"@rollup/plugin-replace": "^4.0.0",
"@babel/preset-typescript": "^7.21.4",
"@rollup/plugin-babel": "^6.0.3",
"@rollup/plugin-commonjs": "^24.0.1",
"@rollup/plugin-json": "^6.0.0",
"@rollup/plugin-node-resolve": "^15.0.1",
"@rollup/plugin-replace": "^5.0.2",
"@typescript-eslint/eslint-plugin": "^5.52.0",
"@typescript-eslint/parser": "^5.52.0",
"axios": "^1.2.0",
"browserstack-local": "^1.4.9",
"chalk": "^4.1.2",
Expand All @@ -64,10 +70,14 @@
"crypto-js": "^4.1.1",
"dotenv": "^8.2.0",
"dox": "^0.9.0",
"eslint": "^7.25.0",
"eslint": "^8.34.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-config-airbnb-typescript": "^17.0.0",
"eslint-import-resolver-typescript": "^3.5.5",
"eslint-plugin-compat": "^3.9.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jsdoc": "^39.6.4",
"eslint-plugin-import-newlines": "^1.3.1",
"eslint-plugin-jsdoc": "^41.1.1",
"fs-extra": "^10.0.1",
"husky": "^8.0.3",
"jest": "^29.5.0",
Expand All @@ -80,13 +90,15 @@
"node-qunit-puppeteer": "2.1.1",
"openurl": "^1.1.1",
"qunit": "^2.9.3",
"rollup": "^2.70.2",
"rollup": "^3.15.0",
"rollup-plugin-cleanup": "^3.1.1",
"rollup-plugin-copy": "^3.1.0",
"rollup-plugin-generate-html": "^0.2.0",
"selenium-webdriver": "^4.1.1",
"sinon": "^7.5.0",
"terser": "^5.16.1"
"terser": "^5.16.1",
"ts-node": "^10.9.1",
"typescript": "^4.9.5"
},
"files": [
"dist"
Expand Down
166 changes: 166 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
import resolve from '@rollup/plugin-node-resolve';
import babel from '@rollup/plugin-babel';
import commonjs from '@rollup/plugin-commonjs';
import copy from 'rollup-plugin-copy';
import cleanup from 'rollup-plugin-cleanup';
import generateHtml from 'rollup-plugin-generate-html';
import path from 'path';
import project from './package.json';

const BUILD_DIST = 'dist';
const DIST_REDIRECT_FILES = 'dist/redirect-files';
const BANNER = `
/**
* AdGuard Scriptlets
* Version ${project.version}
*/
`;
const FOOTER = `
/**
* -------------------------------------------
* | |
* | If you want to add your own scriptlet |
* | please put your code below |
* | |
* -------------------------------------------
*/
`;

const commonPlugins = [
resolve({ extensions: ['.js', '.ts'] }),
commonjs({
include: path.resolve(__dirname, './node_modules/**'),
}),
babel({
extensions: ['.js', '.ts'],
babelHelpers: 'runtime',
}),
];

const scriptletsIIFEConfig = {
input: {
scriptlets: 'src/scriptlets/scriptlets-wrapper.js',
},
output: {
dir: BUILD_DIST,
entryFileNames: '[name].js',
format: 'iife',
strict: false,
banner: BANNER,
footer: FOOTER,
},
plugins: [
...commonPlugins,
],
};

const scriptletsUMDConfig = {
input: {
'scriptlets.umd': 'src/scriptlets/scriptlets-umd-wrapper.js',
},
output: {
dir: 'dist/umd',
entryFileNames: '[name].js',
// umd is preferred over cjs to avoid variables renaming in tsurlfilter
format: 'umd',
exports: 'named',
strict: false,
banner: BANNER,
footer: FOOTER,
},
plugins: [
...commonPlugins,
copy({
targets: [
{ src: 'types/scriptlets.d.ts', dest: 'dist/umd/' },
],
}),
],
};

const scriptletsListConfig = {
input: {
'scriptlets-list': 'src/scriptlets/scriptlets-list.js',
},
output: {
dir: 'tmp',
entryFileNames: '[name].js',
format: 'es',
},
plugins: [
...commonPlugins,
],
};

const redirectsListConfig = {
input: {
'redirects-list': 'src/redirects/redirects-list.js',
},
output: {
dir: 'tmp',
entryFileNames: '[name].js',
format: 'es',
},
plugins: [
...commonPlugins,
],
};

const redirectsPrebuildConfig = {
input: {
redirects: 'src/redirects/index.js',
},
output: {
dir: 'tmp',
entryFileNames: '[name].js',
format: 'es',
},
plugins: [
...commonPlugins,
],
};

const click2LoadConfig = {
script: {
input: {
click2load: 'src/redirects/blocking-redirects/click2load.js',
},
output: {
dir: 'tmp',
entryFileNames: '[name].js',
name: 'click2load',
format: 'iife',
},
plugins: [
...commonPlugins,
cleanup(),
],
},
html: {
input: 'src/redirects/blocking-redirects/click2load.js',
output: {
dir: DIST_REDIRECT_FILES,
name: 'click2load',
format: 'iife',
},
plugins: [
...commonPlugins,
cleanup(),
generateHtml({
filename: `${DIST_REDIRECT_FILES}/click2load.html`,
template: 'src/redirects/blocking-redirects/click2load.html',
selector: 'body',
inline: true,
}),
],
},
};

export {
scriptletsIIFEConfig,
scriptletsUMDConfig,
scriptletsListConfig,
redirectsListConfig,
click2LoadConfig,
redirectsPrebuildConfig,
};
Loading

0 comments on commit 6c3693f

Please sign in to comment.