Skip to content
This repository has been archived by the owner on Jul 17, 2023. It is now read-only.

Commit

Permalink
feat(ui): move socket/port creation to a bundled dependency 🎨
Browse files Browse the repository at this point in the history
This prepares us for making the socket/port location generation code to be shared between the UI and the reporter, thus allowing end users to omit the socket address from the config in most circumstances. 😍
  • Loading branch information
robertrossmann committed Mar 5, 2019
1 parent 7346f8c commit 4144c3c
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 38 deletions.
29 changes: 8 additions & 21 deletions packages/atom-ide-mocha-core/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion packages/atom-ide-mocha-core/package.json
Expand Up @@ -9,11 +9,14 @@
"bugs": "https://github.com/Dreamscapes/atom-ide-mocha-core/issues",
"contributors": [],
"dependencies": {
"@atom-ide/utils": "^1.0.0",
"atom-package-deps": "^5.0.0",
"hash-to-port": "^1.0.0",
"remote-event-emitter": "^1.1.0",
"stack-utils": "^1.0.1"
},
"bundledDependencies": [
"@atom-ide/utils"
],
"engines": {
"atom": "^1.32.0",
"node": "^10.0.0"
Expand Down
17 changes: 1 addition & 16 deletions packages/atom-ide-mocha-core/src/util.mjs
@@ -1,22 +1,7 @@
import * as os from 'os'
import * as path from 'path'
import * as hashToPort from 'hash-to-port'
import { mkaddress } from '@atom-ide/utils'

const CONSOLE_VIEW_URI = 'atom://nuclide/console'

function mkaddress({ root, type = 'unix' }) {
const name = path.basename(root)

switch (type) {
case 'unix':
return path.resolve(os.tmpdir(), `ide-mocha-${name}.sock`)
case 'IP':
return hashToPort(name)
default:
throw new Error(`Unknown address interface type: ${type}`)
}
}

function mkcommandinfo({ address }) {
return [
'npx mocha',
Expand Down
21 changes: 21 additions & 0 deletions packages/utils/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions packages/utils/package.json
@@ -0,0 +1,19 @@
{
"name": "@atom-ide/utils",
"description": "Code shared across multiple core packages in this monorepo",
"version": "1.0.0",
"author": "Robert Rossmann <rr.rossmann@me.com>",
"bugs": "https://github.com/Dreamscapes/atom-ide-mocha-core/issues",
"contributors": [],
"dependencies": {
"hash-to-port": "^1.0.0"
},
"homepage": "https://github.com/Dreamscapes/atom-ide-mocha-core/tree/master/packages/utils",
"keywords": [],
"license": "BSD-3-Clause",
"main": "src",
"repository": {
"type": "git",
"url": "git://github.com/Dreamscapes/atom-ide-mocha-core.git"
}
}
29 changes: 29 additions & 0 deletions packages/utils/src/index.mjs
@@ -0,0 +1,29 @@
import * as os from 'os'
import * as path from 'path'
import * as hashToPort from 'hash-to-port'

/**
* Create a socket address or port in a deterministic way for a given absolute directory path
*
* @param {Object} options Function options
* @param {String} options.root Absolute path to the directory
* @param {String} options.mode Interface mode. Either `unix` or `ip`.
* @return {String} A full path to the socket
*/
function mkaddress({ root, mode = 'unix' }) {
const name = path.basename(root)

switch (mode) {
case 'unix':
return path.resolve(os.tmpdir(), `ide-mocha-${name}.sock`)
case 'IP':
case 'ip':
return hashToPort(name)
default:
throw new Error(`Unknown address interface mode: ${mode}`)
}
}

export {
mkaddress,
}

0 comments on commit 4144c3c

Please sign in to comment.