| 1234567891011121314151617181920212223242526272829303132333435 |
- const { toASCII } = require('punycode/');
- const path = require('path');
- const { traceAsync } = require('./trace-runner');
- const publicSuffixPath = path.resolve(__dirname, '../../node_modules/.cache/public_suffix_list_dat.txt');
- const getGorhillPublicSuffix = () => traceAsync('create gorhill public suffix instance', async () => {
- const customFetch = async (url) => {
- return Bun.file(url);
- };
- const publicSuffixFile = Bun.file(publicSuffixPath);
- const [publicSuffixListDat, { default: gorhill }] = await Promise.all([
- await publicSuffixFile.exists()
- ? publicSuffixFile.text()
- : fetch('https://publicsuffix.org/list/public_suffix_list.dat').then(r => {
- console.log('public_suffix_list.dat not found, fetch directly from remote.');
- return r.text();
- }),
- import('gorhill-publicsuffixlist')
- ]);
- gorhill.parse(publicSuffixListDat, toASCII);
- await gorhill.enableWASM({ customFetch });
- return gorhill;
- });
- /** @type {Promise<import('gorhill-publicsuffixlist').default> | null} */
- let gorhillPublicSuffixPromise = null;
- module.exports.getGorhillPublicSuffixPromise = () => {
- gorhillPublicSuffixPromise ||= getGorhillPublicSuffix();
- return gorhillPublicSuffixPromise;
- };
|