Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add basic browser support #26

Merged
merged 13 commits into from
Nov 16, 2022
4 changes: 2 additions & 2 deletions package-lock.json

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

8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@
"engines": {
"node": ">=14.0.0"
},
"browser": {
"os": "./src/shims/os.js",
"./src/runtime/env": "./src/shims/runtime/env.js",
"./src/runtime/logger": "./src/shims/runtime/logger.js"
},
"aegir": {
"test": {
"target": [
Expand All @@ -66,6 +71,7 @@
},
"contributors": [
"Henrique Dias <[email protected]>",
"Laurent Senta <[email protected]>"
"Laurent Senta <[email protected]>",
"Glen De Cauwsemaecker <[email protected]>"
]
}
15 changes: 15 additions & 0 deletions src/runtime/env.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict'

/**
* Gets the environment that can be used by the environment
* to create the runtime.
*
* @returns {Record<string, string|undefined>}
*/
function getCurrentEnv () {
return process.env
}

module.exports = {
getCurrentEnv
}
4 changes: 0 additions & 4 deletions src/runtime/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ function newEvents (runParams, logger, getSignalEmitter) {

logger.info('', { event })
return emitEvent(event)
// TODO(metrics): re.metrics.recordEvent(&evt)
},
recordSuccess: () => {
const event = {
Expand All @@ -58,7 +57,6 @@ function newEvents (runParams, logger, getSignalEmitter) {

logger.info('', { event })
return emitEvent(event)
// TODO(metrics): re.metrics.recordEvent(&evt)
},
recordFailure: (err) => {
const event = {
Expand All @@ -70,7 +68,6 @@ function newEvents (runParams, logger, getSignalEmitter) {

logger.info('', { event })
return emitEvent(event)
// TODO(metrics): re.metrics.recordEvent(&evt)
},
recordCrash: (err) => {
const event = {
Expand All @@ -83,7 +80,6 @@ function newEvents (runParams, logger, getSignalEmitter) {

logger.info('', { event })
return emitEvent(event)
// TODO(metrics): re.metrics.recordEvent(&evt)
GlenDC marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/runtime/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const { getLogger } = require('./logger')
const { newEvents } = require('./events')
const { parseRunParams } = require('./params')
const { getCurrentEnv } = require('./env')

/** @typedef {import('./types').RunParams} RunParams */
/** @typedef {import('./types').SignalEmitter} SignalEmitter */
Expand All @@ -14,7 +15,8 @@ const { parseRunParams } = require('./params')
* @returns {RunEnv}
*/
function currentRunEnv () {
return parseRunEnv(process.env)
const env = getCurrentEnv()
return parseRunEnv(env)
}

/**
Expand Down
20 changes: 20 additions & 0 deletions src/shims/os.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict'

/**
* @returns {any[]}
*/
function networkInterfaces () {
return []
}

/**
* @returns {string}
*/
function hostname () {
return 'browser'
}

module.exports = {
networkInterfaces,
hostname
}
16 changes: 16 additions & 0 deletions src/shims/runtime/env.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict'

/**
* Gets the environment that can be used by the environment
* to create the runtime.
*
* @returns {Record<string, string|undefined>}
*/
function getCurrentEnv () {
// @ts-ignore
return window.testground.env
}

module.exports = {
getCurrentEnv
}
9 changes: 9 additions & 0 deletions src/shims/runtime/logger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict'

function getLogger () {
return console
}
GlenDC marked this conversation as resolved.
Show resolved Hide resolved

module.exports = {
getLogger
}
GlenDC marked this conversation as resolved.
Show resolved Hide resolved