Skip to content

Commit

Permalink
upgrades some old packages in project that were causing build issues
Browse files Browse the repository at this point in the history
  • Loading branch information
williamstein committed Oct 14, 2024
1 parent e37682f commit 8840a18
Show file tree
Hide file tree
Showing 8 changed files with 3,172 additions and 2,752 deletions.
5,857 changes: 3,114 additions & 2,743 deletions src/packages/pnpm-lock.yaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export async function browser_symmetric_channel(
return name;
}

class SymmetricChannel extends EventEmitter {
export class SymmetricChannel extends EventEmitter {
channel: any;

constructor(channel?: any) {
Expand Down
16 changes: 16 additions & 0 deletions src/packages/project/daemonize-process/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// BSD 2-clause

import { SpawnOptions } from 'node:child_process';

type DaemonizeProcessOpts = {
/** The path to the script to be executed. Default: The current script. */
script?: string;
/** The command line arguments to be used. Default: The current arguments. */
arguments?: string[];
/** The path to the Node.js binary to be used. Default: The current Node.js binary. */
node?: string;
/** The exit code to be used when exiting the parent process. Default: `0`. */
exitCode?: number;
} & SpawnOptions;
export declare function daemonizeProcess(opts?: DaemonizeProcessOpts): void;
export {};
36 changes: 36 additions & 0 deletions src/packages/project/daemonize-process/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// BSD 2-clause

// This is just https://www.npmjs.com/package/daemonize-process
// but they stopped supporting commonjs, and we need commonjs or
// to build via typescript, and I don't have the time to stress
// for hours about a 20 line function!

import { spawn } from 'node:child_process';
import { env, cwd, execPath, argv, exit } from 'node:process';

const id = "_DAEMONIZE_PROCESS";
function daemonizeProcess(opts = {}) {
if (id in env) {
delete env[id];
} else {
const o = {
// spawn options
env: Object.assign(env, opts.env, { [id]: "1" }),
cwd: cwd(),
stdio: "ignore",
detached: true,
// custom options
node: execPath,
script: argv[1],
arguments: argv.slice(2),
exitCode: 0,
...opts
};
const args = [o.script, ...o.arguments];
const proc = spawn(o.node, args, o);
proc?.unref?.();
exit(o.exitCode);
}
}

export { daemonizeProcess };
3 changes: 1 addition & 2 deletions src/packages/project/named-servers/control.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
* License: MS-RSL – see LICENSE.md for details
*/

import getPort from "get-port";
import { exec } from "node:child_process";
import { mkdir, readFile, writeFile } from "node:fs/promises";
import { join } from "node:path";

import basePath from "@cocalc/backend/base-path";
import { data } from "@cocalc/backend/data";
import { project_id } from "@cocalc/project/data";
Expand All @@ -26,6 +24,7 @@ export async function start(name: NamedServerName): Promise<number> {
winston.debug(`${name} is already running`);
return s.port;
}
const getPort = (await import("get-port")).default; // since esm only
const port = await getPort({ port: preferredPort(name) });
// For servers that need a basePath, they will use this one.
// Other servers (e.g., Pluto, code-server) that don't need
Expand Down
3 changes: 1 addition & 2 deletions src/packages/project/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@
"body-parser": "^1.20.3",
"commander": "^7.2.0",
"compression": "^1.7.4",
"daemonize-process": "^3.0.0",
"debug": "^4.3.2",
"diskusage": "^1.1.3",
"diskusage": "^1.2.0",
"expect": "^26.6.2",
"express": "^4.20.0",
"express-rate-limit": "^7.4.0",
Expand Down
3 changes: 1 addition & 2 deletions src/packages/project/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
* License: MS-RSL – see LICENSE.md for details
*/

import daemonizeProcess from "daemonize-process";

import { init as initBugCounter } from "./bug-counter";
import { init as initClient } from "./client";
import initInfoJson from "./info-json";
Expand All @@ -13,6 +11,7 @@ import { getOptions } from "./init-program";
import { cleanup as cleanupEnvironmentVariables } from "./project-setup";
import initPublicPaths from "./public-paths";
import initServers from "./servers/init";
import { daemonizeProcess } from "./daemonize-process";

import { getLogger } from "./logger";
const logger = getLogger("project-main");
Expand Down
4 changes: 2 additions & 2 deletions src/packages/project/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ export default function init(): Router {

const router = Router();

router.get("/.smc/upload", function (_, res) {
router.get("/.smc/upload", (_, res) => {
logger.http("upload GET");
return res.send("hello");
res.send("hello");
});

router.post("/.smc/upload", async function (req, res): Promise<void> {
Expand Down

0 comments on commit 8840a18

Please sign in to comment.