Skip to content

Commit

Permalink
Add support for nodejs flavors
Browse files Browse the repository at this point in the history
The main nodejs flavor is "npm", which is to be used to
lint/test and the publication of an official npm
package -- and by design it has dependencies on mocha,
eslint, etc.

A new flavor "dig" has been created with minimal
dependencies and which purpose is to easily allow to
write specialized code to investigate local code changes
in uBO -- and it's not meant for publication.

Consequently, "make nodejs" has been replaced with
"make npm", and a new "dig" target has been added to the
makefile, to be used for instrumenting local code changes
for investigation purpose.
  • Loading branch information
gorhill committed Aug 15, 2021
1 parent 0a11999 commit 087da64
Show file tree
Hide file tree
Showing 13 changed files with 152 additions and 226 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
tools/make-chromium.sh ${{ steps.release_info.outputs.VERSION }}
tools/make-firefox.sh ${{ steps.release_info.outputs.VERSION }}
tools/make-thunderbird.sh ${{ steps.release_info.outputs.VERSION }}
tools/make-nodejs.sh ${{ steps.release_info.outputs.VERSION }}
tools/make-npm.sh ${{ steps.release_info.outputs.VERSION }}
- name: Upload Chromium package
uses: actions/upload-release-asset@v1
env:
Expand Down Expand Up @@ -73,6 +73,6 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: dist/build/uBlock0_${{ steps.release_info.outputs.VERSION }}.nodejs.tgz
asset_name: uBlock0_${{ steps.release_info.outputs.VERSION }}.nodejs.tgz
asset_path: dist/build/uBlock0_${{ steps.release_info.outputs.VERSION }}.npm.tgz
asset_name: uBlock0_${{ steps.release_info.outputs.VERSION }}.npm.tgz
asset_content_type: application/octet-stream
24 changes: 15 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: all clean test lint chromium firefox nodejs
.PHONY: all clean test lint chromium firefox npm

sources := $(wildcard src/* src/*/* src/*/*/* src/*/*/*/*)
platform := $(wildcard platform/* platform/*/*)
Expand All @@ -7,7 +7,7 @@ assets := $(wildcard submodules/uAssets/* \
submodules/uAssets/*/*/* \
submodules/uAssets/*/*/*/*)

all: chromium firefox nodejs
all: chromium firefox npm

dist/build/uBlock0.chromium: tools/make-chromium.sh $(sources) $(platform) $(assets)
tools/make-chromium.sh
Expand All @@ -21,17 +21,23 @@ dist/build/uBlock0.firefox: tools/make-firefox.sh $(sources) $(platform) $(asset
# Build the extension for Firefox.
firefox: dist/build/uBlock0.firefox

dist/build/uBlock0.nodejs: tools/make-nodejs.sh $(sources) $(platform) $(assets)
tools/make-nodejs.sh
dist/build/uBlock0.npm: tools/make-nodejs.sh $(sources) $(platform) $(assets)
tools/make-npm.sh

# Build the Node.js package.
nodejs: dist/build/uBlock0.nodejs
npm: dist/build/uBlock0.npm

lint: nodejs
cd dist/build/uBlock0.nodejs && npm install && npm run lint
lint: npm
cd dist/build/uBlock0.npm && npm install && npm run lint

test: nodejs
cd dist/build/uBlock0.nodejs && npm install && npm run test
test: npm
cd dist/build/uBlock0.npm && npm install && npm run test

dist/build/uBlock0.dig: tools/make-nodejs.sh $(sources) $(platform) $(assets)
tools/make-dig.sh

dig: dist/build/uBlock0.dig
cd dist/build/uBlock0.dig && npm install && npm run test

# Update submodules.
update-submodules:
Expand Down
2 changes: 1 addition & 1 deletion platform/nodejs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ and use this capability now if you figure out the details.
You can directly use specific APIs exposed by this package, here are some of
them, which are used internally by uBO's SNFE.

### `HNTrieContainer`
### HNTrieContainer

A well optimised [compressed trie](https://en.wikipedia.org/wiki/Trie#Compressing_tries)
container specialized to specifically store and lookup hostnames.
Expand Down
14 changes: 9 additions & 5 deletions platform/nodejs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ function pslInit(raw) {
return globals.publicSuffixList;
}

const require = createRequire(import.meta.url); // jshint ignore:line
raw = require('./data/effective_tld_names.json');
raw = readFileSync(resolve(__dirname, './assets/thirdparties/publicsuffix.org/list/effective_tld_names.dat'), 'utf8')
if ( typeof raw !== 'string' || raw.trim() === '' ) {
console.error('Unable to populate public suffix list');
return;
Expand Down Expand Up @@ -203,14 +202,14 @@ class MockStorage {
}

const fctx = new FilteringContext();
let snfeInstance = null;
let snfeProxyInstance = null;

class StaticNetFilteringEngine {
constructor() {
if ( snfeInstance !== null ) {
if ( snfeProxyInstance !== null ) {
throw new Error('Only a single instance is supported.');
}
snfeInstance = this;
snfeProxyInstance = this;
}

async useLists(lists) {
Expand Down Expand Up @@ -253,6 +252,11 @@ class StaticNetFilteringEngine {

return instance;
}

static release() {
useLists([]);
snfeProxyInstance = null;
}
}

/******************************************************************************/
Expand Down
160 changes: 0 additions & 160 deletions platform/nodejs/test.js

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
46 changes: 46 additions & 0 deletions platform/npm/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*******************************************************************************
uBlock Origin - a browser extension to block requests.
Copyright (C) 2014-present Raymond Hill
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see {http://www.gnu.org/licenses/}.
Home: https://github.com/gorhill/uBlock
*/

/* eslint-disable-next-line no-redeclare */
/* globals process */

'use strict';

/******************************************************************************/

import { spawn } from "child_process";
import { promisify } from 'util';

/******************************************************************************/

async function spawnMocha() {
await promisify(spawn)('mocha', [ '--experimental-vm-modules', '--no-warnings', 'tests' ], { stdio: [ 'inherit', 'inherit', 'inherit' ] });
}

async function main() {
if ( process.argv[2] === '--mocha' ) {
await spawnMocha();
}
}

main();

/******************************************************************************/
File renamed without changes.
17 changes: 17 additions & 0 deletions tools/make-dig.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash
#
# This script assumes a linux environment

set -e

DES="dist/build/uBlock0.dig"

./tools/make-nodejs.sh $DES
./tools/make-assets.sh $DES

cp -R platform/dig/* $DES/

cd $DES
npm run build

echo "*** uBlock0.dig: Package done."
Loading

0 comments on commit 087da64

Please sign in to comment.