diff --git a/packages/agtree/CHANGELOG.md b/packages/agtree/CHANGELOG.md index 95d8bbd98..f0f884c8f 100644 --- a/packages/agtree/CHANGELOG.md +++ b/packages/agtree/CHANGELOG.md @@ -8,6 +8,14 @@ The format is based on [Keep a Changelog][keepachangelog], and this project adhe [keepachangelog]: https://keepachangelog.com/en/1.0.0/ [semver]: https://semver.org/spec/v2.0.0.html +## [2.1.1] - 2024-09-19 + +### Fixed + +- Optimized build size. + +[2.1.1]: https://github.com/AdguardTeam/tsurlfilter/releases/tag/agtree-v2.1.1 + ## [2.1.0] - 2024-09-18 ### Added diff --git a/packages/agtree/package.json b/packages/agtree/package.json index 6591de720..4e1765463 100644 --- a/packages/agtree/package.json +++ b/packages/agtree/package.json @@ -1,6 +1,6 @@ { "name": "@adguard/agtree", - "version": "2.1.0", + "version": "2.1.1", "description": "Tool set for working with adblock filter lists", "keywords": [ "adblock", @@ -37,13 +37,16 @@ } }, "files": [ - "dist" + "dist/agtree.d.ts", + "dist/agtree.js", + "dist/agtree.mjs", + "dist/compatibility-table-data.js" ], "engines": { "node": ">=18" }, "scripts": { - "build": "pnpm clean && pnpm build-txt && pnpm build-compatibility-tables && pnpm build-compatibility-tables-wiki && pnpm rollup --config rollup.config.ts --configPlugin typescript && rimraf dist/types", + "build": "pnpm clean && pnpm build-txt && pnpm build-compatibility-tables && pnpm build-compatibility-tables-wiki && pnpm rollup --config rollup.config.ts --configPlugin typescript && rimraf dist/types && rimraf dist/compatibility-table-data.json", "build-txt": "tsx scripts/build-txt.ts", "build-compatibility-tables": "tsx scripts/build-compatibility-tables.ts", "build-compatibility-tables-wiki": "tsx scripts/build-compatibility-tables-wiki.ts", @@ -63,6 +66,7 @@ "@rollup/plugin-commonjs": "^25.0.2", "@rollup/plugin-json": "^6.0.0", "@rollup/plugin-node-resolve": "^15.1.0", + "@rollup/plugin-replace": "^5.0.7", "@rollup/plugin-swc": "^0.4.0", "@rollup/plugin-typescript": "^11.1.2", "@swc/core": "^1.7.24", diff --git a/packages/agtree/rollup.config.ts b/packages/agtree/rollup.config.ts index e42aaf306..9b76d65fe 100644 --- a/packages/agtree/rollup.config.ts +++ b/packages/agtree/rollup.config.ts @@ -10,6 +10,7 @@ import externals from 'rollup-plugin-node-externals'; import dtsPlugin from 'rollup-plugin-dts'; import alias from '@rollup/plugin-alias'; import json from '@rollup/plugin-json'; +import replace from '@rollup/plugin-replace'; import path from 'node:path'; import { readFileSync } from 'node:fs'; @@ -20,6 +21,7 @@ const ROOT_DIR = __dirname; const BASE_FILE_NAME = 'agtree'; const BASE_NAME = 'AGTree'; const PKG_FILE_NAME = 'package.json'; +const COMPATIBILITY_TABLE_FILENAME = 'compatibility-table-data.js'; const distDir = path.join(ROOT_DIR, 'dist'); const pkgFileLocation = path.join(ROOT_DIR, PKG_FILE_NAME); @@ -52,13 +54,12 @@ const banner = `/* // Common plugins for all types of builds export const commonPlugins = [ - json({ preferConst: true }), alias({ entries: [ // Replace dynamic compatibility table data builder with the pre-built data file { find: './compatibility-table-data', - replacement: path.resolve(ROOT_DIR, 'dist/compatibility-tables.json'), + replacement: path.resolve(distDir, COMPATIBILITY_TABLE_FILENAME), }, // Add ".js" extension to all imports of the "semver" package, eg "semver/functions/..." // We need this because we import functions from the "semver" package directly, @@ -73,9 +74,10 @@ export const commonPlugins = [ }, ], }), - commonjs({ sourceMap: false }), - resolve({ preferBuiltins: false }), externals(), + json({ preferConst: true }), + resolve({ preferBuiltins: false }), + commonjs({ sourceMap: false }), typescript({ tsconfig: path.join(ROOT_DIR, 'tsconfig.json'), compilerOptions: { @@ -85,10 +87,41 @@ export const commonPlugins = [ }, include: [path.join(ROOT_DIR, './src/**/*.ts')], exclude: [path.join(ROOT_DIR, './node_modules'), path.join(ROOT_DIR, './test')], - outputToFilesystem: true, + outputToFilesystem: false, + }), + replace({ + preventAssignment: true, + delimiters: ["'", "'"], + values: { + [path.join(distDir, COMPATIBILITY_TABLE_FILENAME)]: `'./${COMPATIBILITY_TABLE_FILENAME}'`, + }, }), ]; +const compatibilityTablesBanner = `/** +* @file Compatibility tables data for AGTree +* +* This file is auto-generated from YAML files in the "compatibility-tables" directory. +* It is optimized for better runtime usage and storage efficiency. +* +* We use "shared" section to share the same values between different map keys +* to reduce the storage usage. +*/`; + +const compatibilityTables = { + input: path.join(distDir, 'compatibility-table-data.json'), + output: [ + { + file: path.join(distDir, COMPATIBILITY_TABLE_FILENAME), + format: 'cjs', + exports: 'named', + sourcemap: false, + banner: compatibilityTablesBanner, + }, + ], + plugins: [json()], +}; + const node = { input: path.join(ROOT_DIR, 'src/index.ts'), output: [ @@ -106,6 +139,9 @@ const node = { banner, }, ], + external: [ + path.resolve(distDir, COMPATIBILITY_TABLE_FILENAME), + ], plugins: commonPlugins, }; @@ -127,4 +163,4 @@ const dts = { }; // Export build configs for Rollup -export default [node, dts]; +export default [compatibilityTables, node, dts]; diff --git a/packages/agtree/scripts/build-compatibility-tables.ts b/packages/agtree/scripts/build-compatibility-tables.ts index 15cd89702..52924cd19 100644 --- a/packages/agtree/scripts/build-compatibility-tables.ts +++ b/packages/agtree/scripts/build-compatibility-tables.ts @@ -11,7 +11,7 @@ import path from 'path'; import * as data from '../src/compatibility-tables/compatibility-table-data'; const DIST_FOLDER_NAME = 'dist'; -const OUTPUT_FILE_NAME = 'compatibility-tables.json'; +const OUTPUT_FILE_NAME = 'compatibility-table-data.json'; /** * Main function. diff --git a/packages/agtree/test/smoke/cjs/index.js b/packages/agtree/test/smoke/cjs/index.js index b143b4ad7..93eb915ec 100644 --- a/packages/agtree/test/smoke/cjs/index.js +++ b/packages/agtree/test/smoke/cjs/index.js @@ -1,8 +1,12 @@ -const { RuleParser } = require('@adguard/agtree'); +const { RuleParser, modifiersCompatibilityTable, SpecificPlatform } = require('@adguard/agtree'); const { ok } = require('assert'); const ruleNode = RuleParser.parse('||example.com^'); ok(ruleNode); +const modifierData = modifiersCompatibilityTable.getSingle('third-party', SpecificPlatform.AdgExtChrome); + +ok(modifierData); + console.log('Smoke test passed'); diff --git a/packages/agtree/test/smoke/esm/index.js b/packages/agtree/test/smoke/esm/index.js index 8b7fb94e1..b22b1b4d7 100644 --- a/packages/agtree/test/smoke/esm/index.js +++ b/packages/agtree/test/smoke/esm/index.js @@ -1,8 +1,12 @@ -import { RuleParser } from '@adguard/agtree'; +import { RuleParser, modifiersCompatibilityTable, SpecificPlatform } from '@adguard/agtree'; import { ok } from 'assert'; const ruleNode = RuleParser.parse('||example.com^'); ok(ruleNode); +const modifierData = modifiersCompatibilityTable.getSingle('third-party', SpecificPlatform.AdgExtChrome); + +ok(modifierData); + console.log('Smoke test passed'); diff --git a/packages/agtree/test/smoke/typescript/index.ts b/packages/agtree/test/smoke/typescript/index.ts index 8b7fb94e1..b22b1b4d7 100644 --- a/packages/agtree/test/smoke/typescript/index.ts +++ b/packages/agtree/test/smoke/typescript/index.ts @@ -1,8 +1,12 @@ -import { RuleParser } from '@adguard/agtree'; +import { RuleParser, modifiersCompatibilityTable, SpecificPlatform } from '@adguard/agtree'; import { ok } from 'assert'; const ruleNode = RuleParser.parse('||example.com^'); ok(ruleNode); +const modifierData = modifiersCompatibilityTable.getSingle('third-party', SpecificPlatform.AdgExtChrome); + +ok(modifierData); + console.log('Smoke test passed'); diff --git a/packages/css-tokenizer/.eslintignore b/packages/css-tokenizer/.eslintignore index f06235c46..2029d9f06 100644 --- a/packages/css-tokenizer/.eslintignore +++ b/packages/css-tokenizer/.eslintignore @@ -1,2 +1,4 @@ node_modules dist +coverage +test/smoke diff --git a/packages/css-tokenizer/CHANGELOG.md b/packages/css-tokenizer/CHANGELOG.md index 697216009..9d20fd81f 100644 --- a/packages/css-tokenizer/CHANGELOG.md +++ b/packages/css-tokenizer/CHANGELOG.md @@ -7,6 +7,14 @@ The format is based on [Keep a Changelog][keepachangelog], and this project adhe [keepachangelog]: https://keepachangelog.com/en/1.0.0/ [semver]: https://semver.org/spec/v2.0.0.html +## [1.1.1] - 2024-09-19 + +### Fixed + +- Optimized build size. + +[1.1.1]: https://github.com/AdguardTeam/tsurlfilter/releases/tag/css-tokenizer-v1.1.1 + ## [1.1.0] - 2024-09-18 ### Removed diff --git a/packages/css-tokenizer/package.json b/packages/css-tokenizer/package.json index d2a6a18c2..9899d1a43 100644 --- a/packages/css-tokenizer/package.json +++ b/packages/css-tokenizer/package.json @@ -1,6 +1,6 @@ { "name": "@adguard/css-tokenizer", - "version": "1.1.0", + "version": "1.1.1", "description": "CSS / Extended CSS tokenizer", "keywords": [ "css", @@ -28,7 +28,9 @@ } }, "files": [ - "dist" + "dist/csstokenizer.d.ts", + "dist/csstokenizer.js", + "dist/csstokenizer.mjs" ], "scripts": { "build": "pnpm clean && pnpm build-txt && pnpm rollup --config rollup.config.ts --configPlugin @rollup/plugin-json --configPlugin @rollup/plugin-typescript && rimraf dist/types", @@ -41,7 +43,8 @@ "lint": "pnpm lint:ts && pnpm lint:md", "lint:md": "markdownlint .", "lint:ts": "eslint . --cache --ext .ts", - "test": "jest --runInBand" + "test": "jest --runInBand", + "test:smoke": "(cd test/smoke/esm && pnpm test) && (cd test/smoke/cjs && pnpm test) && (cd test/smoke/typescript && pnpm test)" }, "devDependencies": { "@csstools/css-tokenizer": "^2.2.1", diff --git a/packages/css-tokenizer/rollup.config.ts b/packages/css-tokenizer/rollup.config.ts index 691f64ea6..e2f1bb38e 100644 --- a/packages/css-tokenizer/rollup.config.ts +++ b/packages/css-tokenizer/rollup.config.ts @@ -61,7 +61,7 @@ const commonPlugins = [ }, include: ['./src/**/*.ts'], exclude: ['./node_modules', './test'], - outputToFilesystem: true, + outputToFilesystem: false, }), ]; diff --git a/packages/css-tokenizer/test/smoke/cjs/index.js b/packages/css-tokenizer/test/smoke/cjs/index.js new file mode 100644 index 000000000..a1d80ca9e --- /dev/null +++ b/packages/css-tokenizer/test/smoke/cjs/index.js @@ -0,0 +1,12 @@ +const { tokenize } = require('@adguard/css-tokenizer'); +const { ok } = require('assert'); + +let tokensCount = 0; + +tokenize('div { color: red; }', () => { + tokensCount += 1; +}); + +ok(tokensCount > 0); + +console.log('Smoke test passed'); diff --git a/packages/css-tokenizer/test/smoke/cjs/package.json b/packages/css-tokenizer/test/smoke/cjs/package.json new file mode 100644 index 000000000..a59623d5c --- /dev/null +++ b/packages/css-tokenizer/test/smoke/cjs/package.json @@ -0,0 +1,11 @@ +{ + "name": "cjs", + "version": "1.0.0", + "main": "index.js", + "license": "MIT", + "author": "Adguard Software Ltd.", + "scripts": { + "start": "node index.js", + "test": "./test.sh" + } +} diff --git a/packages/css-tokenizer/test/smoke/cjs/test.sh b/packages/css-tokenizer/test/smoke/cjs/test.sh new file mode 100755 index 000000000..793b2f370 --- /dev/null +++ b/packages/css-tokenizer/test/smoke/cjs/test.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +set -e # Exit on error + +# pack @adguard/css-tokenizer +curr_path="test/smoke/cjs" +csstokenizer="css-tokenizer.tgz" +nm_path="node_modules" + +# Define cleanup function +cleanup() { + echo "Cleaning up..." + rm -f $csstokenizer && rm -rf $nm_path + echo "Cleanup complete" +} + +# Set trap to execute the cleanup function on script exit +trap cleanup EXIT + +(cd ../../.. && pnpm pack && mv adguard-css-tokenizer-*.tgz "$curr_path/$csstokenizer") + +# unzip to @adguard/tsurlfilter to node_modules +csstokenizer_node_modules=$nm_path"/@adguard/css-tokenizer" +mkdir -p $csstokenizer_node_modules +tar -xzf $csstokenizer --strip-components=1 -C $csstokenizer_node_modules + +pnpm start +echo "Test successfully built." diff --git a/packages/css-tokenizer/test/smoke/esm/index.js b/packages/css-tokenizer/test/smoke/esm/index.js new file mode 100644 index 000000000..948bb6809 --- /dev/null +++ b/packages/css-tokenizer/test/smoke/esm/index.js @@ -0,0 +1,12 @@ +import { tokenize } from '@adguard/css-tokenizer'; +import { ok } from 'assert'; + +let tokensCount = 0; + +tokenize('div { color: red; }', () => { + tokensCount += 1; +}); + +ok(tokensCount > 0); + +console.log('Smoke test passed'); diff --git a/packages/css-tokenizer/test/smoke/esm/package.json b/packages/css-tokenizer/test/smoke/esm/package.json new file mode 100644 index 000000000..b68791870 --- /dev/null +++ b/packages/css-tokenizer/test/smoke/esm/package.json @@ -0,0 +1,12 @@ +{ + "name": "esm", + "version": "1.0.0", + "main": "index.js", + "license": "MIT", + "author": "Adguard Software Ltd.", + "type": "module", + "scripts": { + "start": "node index.js", + "test": "./test.sh" + } +} diff --git a/packages/css-tokenizer/test/smoke/esm/test.sh b/packages/css-tokenizer/test/smoke/esm/test.sh new file mode 100755 index 000000000..35d356d53 --- /dev/null +++ b/packages/css-tokenizer/test/smoke/esm/test.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +set -e # Exit on error + +# pack @adguard/css-tokenizer +curr_path="test/smoke/esm" +csstokenizer="css-tokenizer.tgz" +nm_path="node_modules" + +# Define cleanup function +cleanup() { + echo "Cleaning up..." + rm -f $csstokenizer && rm -rf $nm_path + echo "Cleanup complete" +} + +# Set trap to execute the cleanup function on script exit +trap cleanup EXIT + +(cd ../../.. && pnpm pack && mv adguard-css-tokenizer-*.tgz "$curr_path/$csstokenizer") + +# unzip to @adguard/tsurlfilter to node_modules +csstokenizer_node_modules=$nm_path"/@adguard/css-tokenizer" +mkdir -p $csstokenizer_node_modules +tar -xzf $csstokenizer --strip-components=1 -C $csstokenizer_node_modules + +pnpm start +echo "Test successfully built." diff --git a/packages/css-tokenizer/test/smoke/typescript/index.ts b/packages/css-tokenizer/test/smoke/typescript/index.ts new file mode 100644 index 000000000..948bb6809 --- /dev/null +++ b/packages/css-tokenizer/test/smoke/typescript/index.ts @@ -0,0 +1,12 @@ +import { tokenize } from '@adguard/css-tokenizer'; +import { ok } from 'assert'; + +let tokensCount = 0; + +tokenize('div { color: red; }', () => { + tokensCount += 1; +}); + +ok(tokensCount > 0); + +console.log('Smoke test passed'); diff --git a/packages/css-tokenizer/test/smoke/typescript/package.json b/packages/css-tokenizer/test/smoke/typescript/package.json new file mode 100644 index 000000000..325b1cdff --- /dev/null +++ b/packages/css-tokenizer/test/smoke/typescript/package.json @@ -0,0 +1,11 @@ +{ + "name": "typescript", + "version": "1.0.0", + "main": "index.js", + "license": "MIT", + "author": "Adguard Software Ltd.", + "scripts": { + "start": "tsc --noEmit", + "test": "./test.sh" + } +} diff --git a/packages/css-tokenizer/test/smoke/typescript/test.sh b/packages/css-tokenizer/test/smoke/typescript/test.sh new file mode 100755 index 000000000..a2798ce1c --- /dev/null +++ b/packages/css-tokenizer/test/smoke/typescript/test.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +set -e # Exit on error + +# pack @adguard/css-tokenizer +curr_path="test/smoke/typescript" +csstokenizer="css-tokenizer.tgz" +nm_path="node_modules" + +# Define cleanup function +cleanup() { + echo "Cleaning up..." + rm -f $csstokenizer && rm -rf $nm_path + echo "Cleanup complete" +} + +# Set trap to execute the cleanup function on script exit +trap cleanup EXIT + +(cd ../../.. && pnpm pack && mv adguard-css-tokenizer-*.tgz "$curr_path/$csstokenizer") + +# unzip to @adguard/tsurlfilter to node_modules +csstokenizer_node_modules=$nm_path"/@adguard/css-tokenizer" +mkdir -p $csstokenizer_node_modules +tar -xzf $csstokenizer --strip-components=1 -C $csstokenizer_node_modules + +pnpm start +echo "Test successfully built." diff --git a/packages/css-tokenizer/test/smoke/typescript/tsconfig.json b/packages/css-tokenizer/test/smoke/typescript/tsconfig.json new file mode 100644 index 000000000..18a6bedec --- /dev/null +++ b/packages/css-tokenizer/test/smoke/typescript/tsconfig.json @@ -0,0 +1,10 @@ +{ + "compilerOptions": { + "target": "es2016", + "module": "commonjs", + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true, + "strict": true, + "skipLibCheck": true + } +} diff --git a/packages/css-tokenizer/tsconfig.json b/packages/css-tokenizer/tsconfig.json index 97ea18bd0..c57defd2e 100644 --- a/packages/css-tokenizer/tsconfig.json +++ b/packages/css-tokenizer/tsconfig.json @@ -22,7 +22,8 @@ ], "exclude": [ "./node_modules", - "./dist" + "./dist", + "./test/smoke/typescript" ], "ts-node": { "swc": true, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index dc16901c0..afc157013 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -127,6 +127,9 @@ importers: '@rollup/plugin-node-resolve': specifier: ^15.1.0 version: 15.2.3(rollup@3.29.4) + '@rollup/plugin-replace': + specifier: ^5.0.7 + version: 5.0.7(rollup@3.29.4) '@rollup/plugin-swc': specifier: ^0.4.0 version: 0.4.0(@swc/core@1.7.24)(rollup@3.29.4) @@ -3329,6 +3332,20 @@ packages: rollup: 4.13.0 dev: true + /@rollup/plugin-replace@5.0.7(rollup@3.29.4): + resolution: {integrity: sha512-PqxSfuorkHz/SPpyngLyg5GCEkOcee9M1bkxiVDr41Pd61mqP1PLOoDPbpl44SB2mQGKwV/In74gqQmGITOhEQ==} + engines: {node: '>=14.0.0'} + peerDependencies: + rollup: ^1.20.0||^2.0.0||^3.0.0||^4.0.0 + peerDependenciesMeta: + rollup: + optional: true + dependencies: + '@rollup/pluginutils': 5.1.0(rollup@3.29.4) + magic-string: 0.30.8 + rollup: 3.29.4 + dev: true + /@rollup/plugin-swc@0.1.1(@swc/core@1.4.8)(rollup@3.29.4): resolution: {integrity: sha512-nDbcgC39Y0NWsvSd3O2B7qLB19lVkX5rCqRVDqkS991WL2WVpJyp2vX0pa2W5OviwyG/UFxCypkc6NiC6C6r5Q==} engines: {node: '>=14.0.0'}