From 384e5c09e4a872d30f50dea06bec793db5f30cc7 Mon Sep 17 00:00:00 2001 From: Douglas Gubert Date: Thu, 25 Jul 2024 18:56:38 -0300 Subject: [PATCH] Improve installation and cache --- .gitignore | 1 + package.json | 7 ++++--- scripts/postinstall.js | 16 ++++++++++++++++ src/server/runtime/deno/AppsEngineDenoRuntime.ts | 3 ++- tsconfig-lint.json | 2 +- 5 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 scripts/postinstall.js diff --git a/.gitignore b/.gitignore index 8a8a5c217..c4568f9c7 100644 --- a/.gitignore +++ b/.gitignore @@ -38,6 +38,7 @@ jspm_packages .npm .deno +.deno-cache # Optional REPL history .node_repl_history diff --git a/package.json b/package.json index a90946038..56f2d5031 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "test:node": "NODE_ENV=test ts-node ./tests/runner.ts", "test:deno": "cd deno-runtime && deno task test", "gen-doc": "typedoc", - "postinstall": "cd deno-runtime && deno cache main.ts && deno test --no-check --no-run" + "postinstall": "node scripts/postinstall.js" }, "repository": { "type": "git", @@ -32,10 +32,11 @@ ], "files": [ "client/**", - "server/**", "definition/**", + "deno-runtime/**", "lib/**", - "deno-runtime/**" + "scripts/**", + "server/**" ], "author": { "name": "Rocket.Chat", diff --git a/scripts/postinstall.js b/scripts/postinstall.js new file mode 100644 index 000000000..5a1f6583c --- /dev/null +++ b/scripts/postinstall.js @@ -0,0 +1,16 @@ +const childProcess = require('child_process'); +const path = require('path'); + +// Find executable installed by deno-bin +const executablePath = path.join(require.resolve('deno-bin'), '..', 'bin', 'deno'); + +const rootPath = path.join(__dirname, '..'); +const DENO_DIR = path.join(rootPath, '.deno-cache'); + +childProcess.spawnSync(executablePath, ['cache', 'main.ts'], { + cwd: path.join(rootPath, 'deno-runtime'), + env: { + DENO_DIR, + }, + stdio: 'inherit', +}); diff --git a/src/server/runtime/deno/AppsEngineDenoRuntime.ts b/src/server/runtime/deno/AppsEngineDenoRuntime.ts index 2355749da..d1de356e1 100644 --- a/src/server/runtime/deno/AppsEngineDenoRuntime.ts +++ b/src/server/runtime/deno/AppsEngineDenoRuntime.ts @@ -128,6 +128,7 @@ export class DenoRuntimeSubprocessController extends EventEmitter { const denoWrapperPath = getDenoWrapperPath(); // During development, the appsEngineDir is enough to run the deno process const appsEngineDir = path.dirname(path.join(denoWrapperPath, '..')); + const DENO_DIR = path.join(appsEngineDir, '.deno-cache'); // When running in production, we're likely inside a node_modules which the Deno // process must be able to read in order to include files that use NPM packages const parentNodeModulesDir = path.dirname(path.join(appsEngineDir, '..')); @@ -150,7 +151,7 @@ export class DenoRuntimeSubprocessController extends EventEmitter { this.appPackage.info.id, ]; - this.deno = child_process.spawn(denoExePath, options, { env: null }); + this.deno = child_process.spawn(denoExePath, options, { env: { DENO_DIR } }); this.messenger.setReceiver(this.deno); this.livenessManager.attach(this.deno); diff --git a/tsconfig-lint.json b/tsconfig-lint.json index bcb9cad61..c63e4a8bb 100644 --- a/tsconfig-lint.json +++ b/tsconfig-lint.json @@ -3,5 +3,5 @@ "compilerOptions": { "allowJs": true }, - "include": ["./src/**/*", "./tests/**/*", "./gulpfile.js"] + "include": ["./scripts/*", "./src/**/*", "./tests/**/*", "./gulpfile.js"] }