mirror of
https://github.com/gristlabs/grist-core.git
synced 2024-10-27 20:44:07 +00:00
51ff72c15e
Summary: Building: - Builds no longer wait for tsc for either client, server, or test targets. All use esbuild which is very fast. - Build still runs tsc, but only to report errors. This may be turned off with `SKIP_TSC=1` env var. - Grist-core continues to build using tsc. - Esbuild requires ES6 module semantics. Typescript's esModuleInterop is turned on, so that tsc accepts and enforces correct usage. - Client-side code is watched and bundled by webpack as before (using esbuild-loader) Code changes: - Imports must now follow ES6 semantics: `import * as X from ...` produces a module object; to import functions or class instances, use `import X from ...`. - Everything is now built with isolatedModules flag. Some exports were updated for it. Packages: - Upgraded browserify dependency, and related packages (used for the distribution-building step). - Building the distribution now uses esbuild's minification. babel-minify is no longer used. Test Plan: Should have no behavior changes, existing tests should pass, and docker image should build too. Reviewers: georgegevoian Reviewed By: georgegevoian Subscribers: alexmojaki Differential Revision: https://phab.getgrist.com/D3506
50 lines
1.7 KiB
TypeScript
50 lines
1.7 KiB
TypeScript
/**
|
|
* Various utilities and constants for communicating with the python sandbox.
|
|
*/
|
|
import * as MemBuffer from 'app/common/MemBuffer';
|
|
import log from 'app/server/lib/log';
|
|
|
|
|
|
/**
|
|
* SandboxError is an error type for reporting errors forwarded from the sandbox.
|
|
*/
|
|
export class SandboxError extends Error {
|
|
constructor(message: string) {
|
|
super("[Sandbox] " + (message || 'Python reported an error'));
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* Special msgCode values that precede msgBody to indicate what kind of message it is.
|
|
* These all cost one byte. If we needed more, we should probably switch to a number (5 bytes)
|
|
* CALL = call to the other side. The data must be an array of [func_name, arguments...]
|
|
* DATA = data must be a value to return to a call from the other side
|
|
* EXC = data must be an exception to return to a call from the other side
|
|
*/
|
|
export const CALL = null;
|
|
export const DATA = true;
|
|
export const EXC = false;
|
|
|
|
|
|
/**
|
|
* Returns a function that takes data buffers and logs them to log.info() with the given prefix.
|
|
* The logged output is line-oriented, so that the prefix is only inserted at the start of a line.
|
|
* Binary data is encoded as with JSON.stringify.
|
|
*/
|
|
export function makeLinePrefixer(prefix: string, logMeta: object) {
|
|
let partial = '';
|
|
return (data: Uint8Array) => {
|
|
partial += MemBuffer.arrayToString(data);
|
|
let newline;
|
|
while ((newline = partial.indexOf("\n")) !== -1) {
|
|
const line = partial.slice(0, newline);
|
|
partial = partial.slice(newline + 1);
|
|
// Escape some parts of the string by serializing it to JSON (without the quotes).
|
|
log.origLog('info', "%s%s", prefix,
|
|
JSON.stringify(line).slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\'),
|
|
logMeta);
|
|
}
|
|
};
|
|
}
|