diff --git a/build.js b/build.js index 83817c6..964ad66 100644 --- a/build.js +++ b/build.js @@ -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())) diff --git a/generateMetadataJsonFromScriptResources.js b/generateMetadataJsonFromScriptResources.js index 7dc9e4f..a99aa76 100644 --- a/generateMetadataJsonFromScriptResources.js +++ b/generateMetadataJsonFromScriptResources.js @@ -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"; diff --git a/index.js b/index.js index 417066a..37bd2c2 100644 --- a/index.js +++ b/index.js @@ -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 } diff --git a/package.json b/package.json index 6da3428..4b437be 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/verify.js b/verify.js index d897f3c..68d75ac 100644 --- a/verify.js +++ b/verify.js @@ -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')