Skip to content

Commit

Permalink
migrate to module scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
antonok-edm committed Aug 10, 2024
1 parent 60ca496 commit 482b072
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 17 deletions.
8 changes: 4 additions & 4 deletions build.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const fs = require('fs')
const path = require('path')
import fs from 'fs'
import path from 'path'

const { readResources } = require('.')
import { readResources } from './index.js'

fs.writeFileSync(path.join(__dirname, 'dist', 'resources.json'), JSON.stringify(readResources()))
fs.writeFileSync(path.join(import.meta.dirname, 'dist', 'resources.json'), JSON.stringify(readResources()))
4 changes: 2 additions & 2 deletions generateMetadataJsonFromScriptResources.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* For instance - brave-fix script needs the "bf" alias
*/

const fs = require("fs");
const path = require("path");
import fs from "fs";
import path from "path";

const metadataJsonFile = "metadata.json";
const resourcesDir = "resources";
Expand Down
12 changes: 6 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
const fs = require('fs')
const path = require('path')
import fs from 'fs'
import path from 'path'

const metadata = require('./metadata.json')
import metadata from './metadata.json' with { type: "json" }

const readResources = (() => {
return metadata.map(item => ({
name: item.name,
aliases: item.aliases,
kind: item.kind,
content: fs.readFileSync(path.join(__dirname, 'resources', item.resourcePath)).toString('base64')
content: fs.readFileSync(path.join(import.meta.dirname, 'resources', item.resourcePath)).toString('base64')
}))
})

const listCatalog = require('./filter_lists/list_catalog.json')
import listCatalog from './filter_lists/list_catalog.json' with { type: "json" }

module.exports = { listCatalog, readResources }
export { listCatalog, readResources }
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "1.0.0",
"description": "Custom resources and scriptlets used for Brave's adblocker",
"main": "index.js",
"type": "module",
"scripts": {
"build": "node build",
"test": "node verify",
Expand Down
10 changes: 5 additions & 5 deletions verify.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const { readResources, listCatalog } = require('.')
import { readResources, listCatalog } from './index.js'

const assert = require('node:assert')
const crypto = require('crypto')
const test = require('node:test')
const { Engine, FilterFormat, FilterSet } = require('adblock-rs')
import assert from 'node:assert'
import crypto from 'crypto'
import test from 'node:test'
import { Engine, FilterFormat, FilterSet } from 'adblock-rs'

const getIDFromBase64PublicKey = (key) => {
const hash = crypto.createHash('sha256')
Expand Down

0 comments on commit 482b072

Please sign in to comment.