Skip to content

Commit

Permalink
feat: improve package installation and deno caching (#786)
Browse files Browse the repository at this point in the history
  • Loading branch information
d-gubert committed Jul 29, 2024
1 parent c442564 commit c4df1f1
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ jspm_packages
.npm

.deno
.deno-cache

# Optional REPL history
.node_repl_history
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -32,10 +32,11 @@
],
"files": [
"client/**",
"server/**",
"definition/**",
"deno-runtime/**",
"lib/**",
"deno-runtime/**"
"scripts/**",
"server/**"
],
"author": {
"name": "Rocket.Chat",
Expand Down
16 changes: 16 additions & 0 deletions scripts/postinstall.js
Original file line number Diff line number Diff line change
@@ -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',
});
3 changes: 2 additions & 1 deletion src/server/runtime/deno/AppsEngineDenoRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, '..'));
Expand All @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion tsconfig-lint.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"compilerOptions": {
"allowJs": true
},
"include": ["./src/**/*", "./tests/**/*", "./gulpfile.js"]
"include": ["./scripts/*", "./src/**/*", "./tests/**/*", "./gulpfile.js"]
}

0 comments on commit c4df1f1

Please sign in to comment.