fixed issue with old node 10
This commit is contained in:
parent
1ed83623e7
commit
61439734af
|
@ -1,9 +1,10 @@
|
|||
import EventEmitter from 'events'
|
||||
import { writeFileSync, existsSync } from 'fs'
|
||||
import { existsSync, readFileSync, writeFileSync } from 'fs'
|
||||
import json5 from 'json5'
|
||||
import { join, resolve } from 'path'
|
||||
import { fileURLToPath } from 'url'
|
||||
|
||||
import { watch as _watch, rollup as _rollup } from 'rollup'
|
||||
import { rollup as _rollup, watch as _watch } from 'rollup'
|
||||
import loadAndParseConfigFile from 'rollup/dist/loadConfigFile.js'
|
||||
|
||||
import Builder from './Builder.js'
|
||||
|
@ -11,11 +12,7 @@ import Builder from './Builder.js'
|
|||
const __dirname = resolve(fileURLToPath(import.meta.url), '../')
|
||||
|
||||
const rootDir = join(__dirname, '../../../../')
|
||||
const pkgJson = (await import(join(rootDir, 'package.json'), {
|
||||
assert: {
|
||||
type: "json",
|
||||
}
|
||||
})).default
|
||||
const pkgJson = json5.parse(readFileSync(join(rootDir, 'package.json')))
|
||||
|
||||
export default class RollupBuilder extends Builder {
|
||||
constructor ({ name = 'rollup', configPath = join(rootDir, 'rollup.config.js'), tempDir = join(rootDir, '.mocha-ts'), watch = false }) {
|
||||
|
|
|
@ -6,19 +6,19 @@ import { fileURLToPath } from 'url'
|
|||
import typescript from 'typescript'
|
||||
import Builder from './Builder.js'
|
||||
|
||||
const { parse } = json5
|
||||
|
||||
const { sys, createSemanticDiagnosticsBuilderProgram, flattenDiagnosticMessageText, createWatchCompilerHost, createWatchProgram } = typescript
|
||||
|
||||
const __dirname = resolve(fileURLToPath(import.meta.url), '../')
|
||||
|
||||
const rootDir = join(__dirname, '../../../../')
|
||||
|
||||
const pkgJson = (await import(join(rootDir, 'package.json'), {
|
||||
assert: {
|
||||
type: "json",
|
||||
}
|
||||
})).default
|
||||
// const pkgJson = (await import(join(rootDir, 'package.json'), {
|
||||
// assert: {
|
||||
// type: "json",
|
||||
// }
|
||||
// })).default
|
||||
|
||||
const pkgJson = json5.parse(readFileSync(join(rootDir, 'package.json')))
|
||||
|
||||
const mochaTsRelativeDir = '.mocha-ts'
|
||||
const mochaTsDir = join(rootDir, mochaTsRelativeDir)
|
||||
|
@ -43,7 +43,7 @@ export default class TestsBuilder extends Builder {
|
|||
|
||||
writeFileSync(this.tempPkgJsonPath, JSON.stringify(pkgJson, undefined, 2))
|
||||
|
||||
const tsConfig = parse(readFileSync(configPath, 'utf8'))
|
||||
const tsConfig = json5.parse(readFileSync(configPath, 'utf8'))
|
||||
|
||||
tsConfig.file = undefined
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
'use strict'
|
||||
|
||||
import { join, relative, resolve, sep } from 'path'
|
||||
import { join, resolve } from 'path'
|
||||
import { readFileSync } from 'fs'
|
||||
import json5 from 'json5'
|
||||
import chai from 'chai'
|
||||
import rimraf from 'rimraf'
|
||||
import { fileURLToPath } from 'url'
|
||||
|
@ -12,17 +14,13 @@ const __dirname = resolve(fileURLToPath(import.meta.url), '../')
|
|||
|
||||
const rootDir = join(__dirname, '../../../')
|
||||
|
||||
const pkgJson = (await import(join(rootDir, 'package.json'), {
|
||||
assert: {
|
||||
type: "json",
|
||||
}
|
||||
})).default
|
||||
const pkgJson = json5.parse(readFileSync(join(rootDir, 'package.json')))
|
||||
|
||||
global.chai = chai
|
||||
|
||||
async function reloadModule () {
|
||||
const _pkg = await import(join(rootDir, pkgJson.exports['.'].node.import + `?update=${Date.now()}`))
|
||||
return _pkg
|
||||
global._pkg = _pkg
|
||||
// if (typeof _pkg === 'function') { // If it is just a default export, load it as named (for compatibility)
|
||||
// global._pkg = {
|
||||
// default: _pkg
|
||||
|
@ -32,7 +30,7 @@ async function reloadModule () {
|
|||
// }
|
||||
}
|
||||
|
||||
global._pkg = await reloadModule()
|
||||
reloadModule()
|
||||
|
||||
global.IS_BROWSER = false
|
||||
|
||||
|
@ -55,7 +53,7 @@ export const mochaHooks = {
|
|||
|
||||
// Just in case our module had been modified. Reload it when the tests are repeated (for mocha watch mode).
|
||||
// delete require.cache[require.resolve(rootDir)]
|
||||
global._pkg = await reloadModule()
|
||||
await reloadModule()
|
||||
|
||||
// And now reset any other transpiled module (just delete the cache so it is fully reloaded)
|
||||
// for (const key in require.cache) {
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
16
docs/API.md
16
docs/API.md
|
@ -155,7 +155,7 @@ A promise that resolves to a boolean that is either true (a probably prime numbe
|
|||
|
||||
#### Defined in
|
||||
|
||||
[src/ts/isProbablyPrime.ts:21](https://github.com/juanelas/bigint-crypto-utils/blob/16c2723/src/ts/isProbablyPrime.ts#L21)
|
||||
[src/ts/isProbablyPrime.ts:21](https://github.com/juanelas/bigint-crypto-utils/blob/1ed8362/src/ts/isProbablyPrime.ts#L21)
|
||||
|
||||
___
|
||||
|
||||
|
@ -322,7 +322,7 @@ A promise that resolves to a bigint probable prime of bitLength bits.
|
|||
|
||||
#### Defined in
|
||||
|
||||
[src/ts/prime.ts:25](https://github.com/juanelas/bigint-crypto-utils/blob/16c2723/src/ts/prime.ts#L25)
|
||||
[src/ts/prime.ts:29](https://github.com/juanelas/bigint-crypto-utils/blob/1ed8362/src/ts/prime.ts#L29)
|
||||
|
||||
___
|
||||
|
||||
|
@ -352,7 +352,7 @@ A bigint probable prime of bitLength bits.
|
|||
|
||||
#### Defined in
|
||||
|
||||
[src/ts/prime.ts:103](https://github.com/juanelas/bigint-crypto-utils/blob/16c2723/src/ts/prime.ts#L103)
|
||||
[src/ts/prime.ts:107](https://github.com/juanelas/bigint-crypto-utils/blob/1ed8362/src/ts/prime.ts#L107)
|
||||
|
||||
___
|
||||
|
||||
|
@ -381,7 +381,7 @@ A cryptographically secure random bigint between [min,max]
|
|||
|
||||
#### Defined in
|
||||
|
||||
[src/ts/randBetween.ts:15](https://github.com/juanelas/bigint-crypto-utils/blob/16c2723/src/ts/randBetween.ts#L15)
|
||||
[src/ts/randBetween.ts:15](https://github.com/juanelas/bigint-crypto-utils/blob/1ed8362/src/ts/randBetween.ts#L15)
|
||||
|
||||
___
|
||||
|
||||
|
@ -410,7 +410,7 @@ A Promise that resolves to a UInt8Array/Buffer (Browser/Node.js) filled with cry
|
|||
|
||||
#### Defined in
|
||||
|
||||
[src/ts/randBits.ts:14](https://github.com/juanelas/bigint-crypto-utils/blob/16c2723/src/ts/randBits.ts#L14)
|
||||
[src/ts/randBits.ts:14](https://github.com/juanelas/bigint-crypto-utils/blob/1ed8362/src/ts/randBits.ts#L14)
|
||||
|
||||
___
|
||||
|
||||
|
@ -439,7 +439,7 @@ A Uint8Array/Buffer (Browser/Node.js) filled with cryptographically secure rando
|
|||
|
||||
#### Defined in
|
||||
|
||||
[src/ts/randBits.ts:45](https://github.com/juanelas/bigint-crypto-utils/blob/16c2723/src/ts/randBits.ts#L45)
|
||||
[src/ts/randBits.ts:45](https://github.com/juanelas/bigint-crypto-utils/blob/1ed8362/src/ts/randBits.ts#L45)
|
||||
|
||||
___
|
||||
|
||||
|
@ -468,7 +468,7 @@ A promise that resolves to a UInt8Array/Buffer (Browser/Node.js) filled with cry
|
|||
|
||||
#### Defined in
|
||||
|
||||
[src/ts/randBytes.ts:14](https://github.com/juanelas/bigint-crypto-utils/blob/16c2723/src/ts/randBytes.ts#L14)
|
||||
[src/ts/randBytes.ts:14](https://github.com/juanelas/bigint-crypto-utils/blob/1ed8362/src/ts/randBytes.ts#L14)
|
||||
|
||||
___
|
||||
|
||||
|
@ -497,7 +497,7 @@ A UInt8Array/Buffer (Browser/Node.js) filled with cryptographically secure rando
|
|||
|
||||
#### Defined in
|
||||
|
||||
[src/ts/randBytes.ts:46](https://github.com/juanelas/bigint-crypto-utils/blob/16c2723/src/ts/randBytes.ts#L46)
|
||||
[src/ts/randBytes.ts:46](https://github.com/juanelas/bigint-crypto-utils/blob/1ed8362/src/ts/randBytes.ts#L46)
|
||||
|
||||
___
|
||||
|
||||
|
|
|
@ -89,8 +89,7 @@
|
|||
"ignore": [
|
||||
"dist/**/*",
|
||||
"examples/**/*",
|
||||
"types/**/*",
|
||||
"build/testing/mocha/**/*"
|
||||
"types/**/*"
|
||||
]
|
||||
},
|
||||
"devDependencies": {
|
||||
|
|
|
@ -396,18 +396,21 @@ export function _isProbablyPrimeWorkerUrl (): string {
|
|||
return _workerUrl(workerCode)
|
||||
}
|
||||
|
||||
try {
|
||||
var workerThreads = await import('worker_threads') // eslint-disable-line no-var
|
||||
if (!IS_BROWSER && _useWorkers) { // node.js with support for workers
|
||||
var workerThreads = await import('worker_threads') // eslint-disable-line
|
||||
const isWorker = !(workerThreads.isMainThread)
|
||||
if (isWorker && workerThreads.parentPort !== null) { // worker
|
||||
workerThreads.parentPort.on('message', function (data: MainToWorkerMsg) { // Let's start once we are called
|
||||
const parentPort = workerThreads.parentPort
|
||||
parentPort.on('message', function (data: MainToWorkerMsg) { // Let's start once we are called
|
||||
const isPrime = _isProbablyPrime(data.rnd, data.iterations)
|
||||
const msg: WorkerToMainMsg = {
|
||||
isPrime: isPrime,
|
||||
value: data.rnd,
|
||||
id: data.id
|
||||
}
|
||||
workerThreads.parentPort?.postMessage(msg)
|
||||
parentPort.postMessage(msg)
|
||||
})
|
||||
}
|
||||
}
|
||||
} catch (error) {}
|
||||
|
|
|
@ -5,7 +5,11 @@ import { _useWorkers, WorkerToMainMsg, MainToWorkerMsg } from './workerUtils'
|
|||
import type { Worker as NodeWorker } from 'worker_threads'
|
||||
|
||||
if (!IS_BROWSER) var os = await import('os') // eslint-disable-line no-var
|
||||
if (!IS_BROWSER) var workerThreads = await import('worker_threads') // eslint-disable-line no-var
|
||||
if (!IS_BROWSER) {
|
||||
try {
|
||||
var workerThreads = await import('worker_threads') // eslint-disable-line no-var
|
||||
} catch {}
|
||||
}
|
||||
|
||||
/**
|
||||
* A probably-prime (Miller-Rabin), cryptographically-secure, random-number generator.
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"prime.d.ts","sourceRoot":"","sources":["../src/ts/prime.ts"],"names":[],"mappings":"AASA;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,KAAK,CAAE,SAAS,EAAE,MAAM,EAAE,UAAU,GAAE,MAAW,GAAG,OAAO,CAAC,MAAM,CAAC,CAgElF;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,SAAS,CAAE,SAAS,EAAE,MAAM,EAAE,UAAU,GAAE,MAAW,GAAG,MAAM,CAO7E"}
|
||||
{"version":3,"file":"prime.d.ts","sourceRoot":"","sources":["../src/ts/prime.ts"],"names":[],"mappings":"AAaA;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,KAAK,CAAE,SAAS,EAAE,MAAM,EAAE,UAAU,GAAE,MAAW,GAAG,OAAO,CAAC,MAAM,CAAC,CAgElF;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,SAAS,CAAE,SAAS,EAAE,MAAM,EAAE,UAAU,GAAE,MAAW,GAAG,MAAM,CAO7E"}
|
Loading…
Reference in New Issue