Skip to content

Commit

Permalink
feat: tsc compiling (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
deblanco authored Apr 19, 2023
1 parent 3d31c65 commit af268be
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 802 deletions.
37 changes: 9 additions & 28 deletions __tests__/EventEmitterP2P.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { jest } from '@jest/globals'
import { EventEmitterP2P } from '../src/EventEmitterP2P.js'
import { pEvent } from 'p-event'
import type { Message, SubscriptionChangeData } from '@libp2p/interface-pubsub'

enum TestTopic {
TEST = 'TEST',
Expand Down Expand Up @@ -65,20 +64,14 @@ describe('EventEmitterP2P', () => {

// await subscription change
await Promise.all([
pEvent<'subscription-change', CustomEvent<SubscriptionChangeData>>(
ev0.p2pnode.pubsub,
'subscription-change'
),
pEvent<'subscription-change', CustomEvent<SubscriptionChangeData>>(
ev1.p2pnode.pubsub,
'subscription-change'
)
pEvent(ev0.p2pnode.pubsub, 'subscription-change'),
pEvent(ev1.p2pnode.pubsub, 'subscription-change')
])

expect(ev1.listeners[TestTopic.TEST]).toBeDefined()

// we have to wait for this event to be emitted
const promise = pEvent<'message', CustomEvent<Message>>(ev1.p2pnode.pubsub, 'message')
const promise = pEvent<'message', any>(ev1.p2pnode.pubsub, 'message')
await ev0.emit(TestTopic.TEST, 'test')
await promise

Expand All @@ -91,20 +84,14 @@ describe('EventEmitterP2P', () => {

// await subscription change
await Promise.all([
pEvent<'subscription-change', CustomEvent<SubscriptionChangeData>>(
ev0.p2pnode.pubsub,
'subscription-change'
),
pEvent<'subscription-change', CustomEvent<SubscriptionChangeData>>(
ev1.p2pnode.pubsub,
'subscription-change'
)
pEvent(ev0.p2pnode.pubsub, 'subscription-change'),
pEvent(ev1.p2pnode.pubsub, 'subscription-change')
])

expect(ev1.listenersOncer[TestTopic.TEST]).toBeDefined()

// we have to wait for this event to be emitted
const promise = pEvent<'message', CustomEvent<Message>>(ev1.p2pnode.pubsub, 'message')
const promise = pEvent<'message', any>(ev1.p2pnode.pubsub, 'message')
await ev0.emit(TestTopic.TEST, 'test')
await promise

Expand All @@ -118,20 +105,14 @@ describe('EventEmitterP2P', () => {

// await subscription change
await Promise.all([
pEvent<'subscription-change', CustomEvent<SubscriptionChangeData>>(
ev0.p2pnode.pubsub,
'subscription-change'
),
pEvent<'subscription-change', CustomEvent<SubscriptionChangeData>>(
ev1.p2pnode.pubsub,
'subscription-change'
)
pEvent(ev0.p2pnode.pubsub, 'subscription-change'),
pEvent(ev1.p2pnode.pubsub, 'subscription-change')
])

expect(ev0.listenersOncer[TestTopic.TEST]).toBeDefined()

// we have to wait for this event to be emitted
const promise = pEvent<'message', CustomEvent<Message>>(ev0.p2pnode.pubsub, 'message')
const promise = pEvent<'message', any>(ev0.p2pnode.pubsub, 'message')
await ev1.emit(TestTopic.TEST, 'test')
await promise

Expand Down
15 changes: 4 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,28 @@
"name": "@stabilityprotocol/p2p",
"version": "1.0.5",
"source": "src/index.ts",
"main": "dist/p2p.js",
"types": "dist/index.d.ts",
"main": "dist/src/index.js",
"types": "dist/src/index.d.ts",
"repository": "[email protected]:stabilityprotocol/p2p.git",
"author": "[email protected]",
"license": "MIT",
"type": "module",
"scripts": {
"build": "vite build",
"build": "rm -rf dist/ && tsc",
"test": "node --experimental-vm-modules ./node_modules/.bin/jest --detectOpenHandles --forceExit",
"test:dev": "node --experimental-vm-modules ./node_modules/.bin/jest --detectOpenHandles --forceExit --watch"
},
"devDependencies": {
"@commitlint/cli": "^17.5.1",
"@commitlint/config-conventional": "^17.4.4",
"@esbuild-plugins/node-globals-polyfill": "^0.2.3",
"@esbuild-plugins/node-modules-polyfill": "^0.2.2",
"@types/debug": "^4.1.7",
"@types/events": "^3.0.0",
"@types/jest": "^29.5.0",
"@types/node": "^18.15.11",
"events": "^3.3.0",
"jest": "^29.5.0",
"p-event": "^5.0.1",
"rollup-plugin-node-polyfills": "^0.2.1",
"ts-jest": "^29.1.0",
"tslib": "^2.5.0",
"typescript": "^5.0.4",
"vite": "^4.2.2",
"vite-plugin-dts": "^2.3.0"
"typescript": "^5.0.4"
},
"dependencies": {
"@chainsafe/libp2p-gossipsub": "^6.2.0",
Expand Down
6 changes: 3 additions & 3 deletions src/EventEmitterP2P.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import LibP2P, { Libp2p } from 'libp2p'
import { Disposable, IEventEmitter, Listener } from './IEventEmitter'
import { getNode } from './node'
import { Disposable, IEventEmitter, Listener } from './IEventEmitter.js'
import { getNode } from './node.js'
import { fromString as uint8ArrayFromString } from 'uint8arrays'
import { error, info } from './logger'
import { error, info } from './logger.js'

type P2POptions = { overridedOptions: LibP2P.Libp2pOptions; bootstrapList?: string[] }

Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from './EventEmitterP2P'
export * from './node'
export * from './IEventEmitter'
export * from './EventEmitterP2P.js'
export * from './node.js'
export * from './IEventEmitter.js'
105 changes: 40 additions & 65 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,72 +1,47 @@
{
"compilerOptions": {
"baseUrl": "./src",
"paths": {
"*": [
"src/types/*"
]
},
/* Basic Options */
"target": "es2020" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */,
"module": "es2020" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
// "lib": [], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
// "declaration": true, /* Generates corresponding '.d.ts' file. */
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
"sourceMap": true /* Generates corresponding '.map' file. */,
// "outFile": "./", /* Concatenate and emit output to single file. */
"outDir": "./build" /* Redirect output structure to the directory. */,
// "rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "composite": true, /* Enable project compilation */
// "removeComments": true, /* Do not emit comments to output. */
// "noEmit": true, /* Do not emit outputs. */
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
/* Strict Type-Checking Options */
"strict": true /* Enable all strict type-checking options. */,
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
"strictNullChecks": true /* Enable strict null checks. */,
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
/* Additional Checks */
// "noUnusedLocals": true, /* Report errors on unused locals. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
/* Module Resolution Options */
"moduleResolution": "node" /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */,
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */
"allowSyntheticDefaultImports": true /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */,
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
/* Source Map Options */
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
/* Experimental Options */
"experimentalDecorators": true /* Enables experimental support for ES7 decorators. */,
"emitDecoratorMetadata": true /* Enables experimental support for emitting type metadata for decorators. */,
"resolveJsonModule": true,
"skipLibCheck": true
"strict": true,
// project options
"outDir": "dist",
"allowJs": true,
"checkJs": true,
"target": "ES2020",
"module": "ES2020",
"lib": [
"ES2021",
"ES2021.Promise",
"ES2021.String",
"ES2020.BigInt",
],
"noEmit": false,
"noEmitOnError": true,
"emitDeclarationOnly": false,
"declaration": true,
"declarationMap": true,
"incremental": true,
"composite": true,
"isolatedModules": true,
"removeComments": false,
"sourceMap": true,
// module resolution
"esModuleInterop": true,
"moduleResolution": "node",
// linter checks
"noImplicitReturns": false,
"noFallthroughCasesInSwitch": true,
"noUnusedLocals": true,
"noUnusedParameters": false,
// advanced
"forceConsistentCasingInFileNames": true,
"skipLibCheck": true,
"stripInternal": true,
"resolveJsonModule": true
},
"include": [
"src/**/*",
"types/"
],
"exclude": [
"node_modules",
"**/*.spec.ts"
"src",
],
"ts-node": {
"esm": true
},
"esm": true,
"experimentalSpecifierResolution": "node"
}
}
75 changes: 0 additions & 75 deletions vite.config.js

This file was deleted.

Loading

0 comments on commit af268be

Please sign in to comment.