Skip to content
This repository has been archived by the owner on Mar 15, 2024. It is now read-only.

Commit

Permalink
fix: run eslint and prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
lachrist committed Apr 9, 2021
1 parent fc573fd commit 266fe27
Show file tree
Hide file tree
Showing 14 changed files with 70 additions and 66 deletions.
1 change: 1 addition & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ rules:
- error
- properties: never
no-param-reassign: off
valid-typeof: off
spaced-comment: off
max-classes-per-file: off
no-unused-vars:
Expand Down
2 changes: 1 addition & 1 deletion bin/bin.mjs → bin/bin-inline.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node

import minimist from 'minimist';
import main from '../lib/server/inline-main.mjs';
import main from '../lib/server/inline/main.mjs';

main(minimist(process.argv.slice(2)), 'inherit');
3 changes: 2 additions & 1 deletion lib/client/es2015/node/request/curl-sync.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const ChildProcess = require("child_process");

const global_Reflect_apply = Reflect.apply;
const global_String_prototype_split = String.prototype.split;
const global_Error = Error;
const global_JSON_parse = JSON.parse;
const global_JSON_stringify = JSON.stringify;
Expand Down
12 changes: 6 additions & 6 deletions lib/client/es2015/node/request/fork-async.mjs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@

const ChildProcess = require("child_process");

// process is an event emitter and send is directly added to it and not to its prototype
// cf: https://github.com/nodejs/node/blob/master/lib/internal/child_process.js

const global_Reflect_apply = Reflect.apply;
const global_process = process;
const global_Error = Error;
const global_undefined = undefined;
const global_process_send = process.send;
const global_Reflect_getOwnPropertyDescriptor = Reflect.getOwnPropertyDescriptor;

const getFreeIndex = (array) => {
for (let index = 0; index < array.length; index++) {
for (let index = 0; index < array.length; index += 1) {
if (array[index] === null) {
return index;
}
Expand All @@ -31,7 +31,7 @@ const checkNotNull = (value) => {
}

const checkHas = (object, key) => {
if (global_Reflect_getOwnPropertyDescriptor(object, key) === void 0) {
if (global_Reflect_getOwnPropertyDescriptor(object, key) === global_undefined) {
throw new global_Error(`Missing property ${key}`);
}
};
Expand All @@ -46,7 +46,7 @@ module.exports = () => {
checkHas(json, "failure");
checkTypeof(json.index, "number");
checkHas(pendings, json.index);
const pending = pending[json.index];
const pending = pendings[json.index];
pendings[json.index] = null;
if (json.failure === null) {
pending.resolve(json.success);
Expand All @@ -66,4 +66,4 @@ module.exports = () => {
data: json
}]);
};
}:
};
2 changes: 1 addition & 1 deletion lib/server/appmap/git.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as ChildProcess from 'child_process';
import logger from './logger.mjs';
import logger from '../logger.mjs';

const trim = (string) => string.trim();

Expand Down
File renamed without changes.
1 change: 0 additions & 1 deletion lib/server/dispatcher.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import logger from './logger.mjs';
import Appmap from './appmap/index.mjs';

const checkHas = (object, key) => {
Expand Down
4 changes: 2 additions & 2 deletions lib/server/inline/channel.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getDefaultConfig } from '../config.mjs';
import { makeDispatch } from '../dispatch.mjs';
import Dispatcher from '../dispatcher.mjs';
import { makeChannel } from './response.mjs';

export default () => makeChannel(makeDispatch(getDefaultConfig()));
export default () => makeChannel(new Dispatcher(getDefaultConfig()));
4 changes: 2 additions & 2 deletions lib/server/inline/main.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as ChildProcess from 'child_process';
import logger from './logger.mjs';
import { home } from '../../home.js';
import logger from '../logger.mjs';
import { home } from '../../../home.js';

const mapping = {
__proto__: null,
Expand Down
33 changes: 17 additions & 16 deletions lib/server/inline/response.mjs
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
import logger from '../../logger.mjs';
import logger from '../logger.mjs';

export const makeChannel = (dispatcher) => ({
requestSync: (json1) => {
logger.info();
logger.info('inline sync request: %j', json1);
const json2 = dispatcher.dispatch(json1);
logger.info();
logger.info('inline sync response success: %j', json2);
return json2;
},
requestAsync: (json1, pending) => {
logger.info();
if (pending === null) {
const json2 = dispatcher.dispatch(json1);
if (json1 !== null) {
throw new Error(``);
}
} else {
let json2;
try {
json2 = dispatcher.dispatch(json1);
} catch (error) {
logger.info('inline async request: %j', json1);
let json2;
try {
json2 = dispatcher.dispatch(json1);
} catch (error) {
logger.info('inline async request failure: %s', error.stack);
if (pending !== null) {
pending.reject(error);
}
logger.info(json2);
pending.resolve(json2);
}
if (json2 !== undefined) {
logger.info('inline sync response success: %j', json2);
if (pending !== null) {
pending.resolve(json2);
}
}
},
});
41 changes: 20 additions & 21 deletions lib/server/main.mjs
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import { fork } from 'child_process';
import { makeServer as createHttp1Server } from './response/http1.mjs';
import { makeServer as createHttp2Server } from './response/http2.mjs';
import { registerChild } from './response/fork.mjs';
import home from '../../../home.js';
import ChildProcess from 'child_process';
import Path from 'path';
import home from '../../home.js';
import logger from './logger.mjs';
import Dispatcher from './dispatcher.mjs';
import { getDefaultConfig } from './config.mjs';
import {
makeHttp1Server,
makeHttp2Server,
registerChild,
} from './response/index.mjs';

const mapping = {
1: createHttp1Server,
'1.0': createHttp1Server,
1.1: createHttp1Server,
2: createHttp2Server,
'2.0': createHttp2Server,
1: makeHttp1Server,
'1.0': makeHttp1Server,
1.1: makeHttp1Server,
2: makeHttp2Server,
'2.0': makeHttp2Server,
};

export default (env) => {
Expand All @@ -31,7 +37,7 @@ export default (env) => {
return {
server,
fork: (path, argv, options) => {
const options = {
options = {
__proto__: null,
...options,
};
Expand Down Expand Up @@ -78,19 +84,12 @@ export default (env) => {
APPMAP_PORT: String(env.APPMAP_PORT),
APPMAP_HTTP_VERSION: env.APPMAP_HTTP_VERSION,
};
for (let key in env1) {
Reflect.ownKeys(env1).forEach((key) => {
// avoid propagating redundant APPMAP environment variable
if (!key.startsWith('APPMAP_') || env1[key] !== env[key]) {
env2[key] = env1[key];
}
}
const env1 = { __proto__: null };
if ('env' in options) {
env = {
__proto__: null,
...options,
};
} else {
}
});
const child = ChildProcess.fork(path, argv, {
...options,
execArgv,
Expand Down
10 changes: 5 additions & 5 deletions lib/server/response/http1.mjs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { createServer } from 'http';
import logger from './logger.mjs';
import logger from '../logger.mjs';

const onServerListen = function (error) {
const onServerListening = function onServerListening(error) {
logger.info('http1 server listening on %j', this.address());
};

const onServerError = function (error) {
const onServerError = (error) => {
logger.error('http1 server error %s', error.stack);
};

const onRequestError = function (error) {
const onRequestError = (error) => {
logger.error('http1 request error %s', error.stack);
};

const onResponseError = function (error) {
const onResponseError = (error) => {
logger.error('http1 response error %s', error.stack);
};

Expand Down
20 changes: 10 additions & 10 deletions lib/server/response/http2.mjs
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import { createServer } from 'http2';
import logger from './logger.mjs';
import logger from '../logger.mjs';

const onServerListening = function (error) {
const onServerListening = function onServerListening(error) {
logger.info('http2 Server listening on %j', this.address());
};

const onServerError = function (error) {
const onServerError = (error) => {
logger.error('http2 server error %s', error.stack);
};

const onStreamError = function (error) {
const onStreamError = (error) => {
logger.error('http2 stream error %s', error.stack);
};

export const makeServer = (dispatcher) => {
const server = createServer();
server.on('error', onServerError);
server.on('listening', onServerListening);
server.on('stream', (stream, headers) => {
logger.info('http2 request head: %j', headers);
server.on('stream', (stream, headers1) => {
logger.info('http2 request head: %j', headers1);
stream.setEncoding('utf8');
stream.on('error', onStreamError);
let body1 = '';
Expand All @@ -28,19 +28,19 @@ export const makeServer = (dispatcher) => {
stream.on('end', () => {
logger.info('http2 request body: %s', body1);
let body2;
const headers = {
const headers2 = {
':status': 200,
'content-type': 'application/json; charset=utf-8',
};
try {
body2 = JSON.stringify(dispatcher.dispatch(JSON.parse(body1)));
} catch (error) {
logger.error('Error while processing %s\n%s', body1, error.stack);
headers[':status'] = 400;
headers2[':status'] = 400;
body2 = error.message;
}
logger.info('http2 response %j %s', headers, body2);
stream.respond(headers);
logger.info('http2 response %j %s', headers2, body2);
stream.respond(headers2);
stream.end(body2, 'utf8');
});
});
Expand Down
3 changes: 3 additions & 0 deletions lib/server/response/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { makeServer as makeHttp1Server } from './http1.mjs';
export { makeServer as makeHttp2Server } from './http2.mjs';
export { registerChild } from './fork.mjs';

0 comments on commit 266fe27

Please sign in to comment.