|
1 | 1 | const childProcess = require('child_process'); |
| 2 | +const fs = require('fs'); |
2 | 3 | const path = require('path'); |
3 | 4 |
|
| 5 | +const SHELL_ERR_CMD_NOT_FOUND = 127; |
| 6 | + |
| 7 | +/** |
| 8 | + * Matches 'deno 2.3.1' or 'Deno 2.7.11-alpha3.24' or even 'some deno and-anything in between 1.43.5' (as long as everything is in the same line) |
| 9 | + * and extracts the correct version string from those ('2.3.1', '2.7.11' and '1.43.5' respectively). |
| 10 | + * |
| 11 | + * Doesn't match 'denoing 2.3.1' or 'deno2.3.1' or 'mydeno 2.7.11alpha3.24' or 'deno\n1.43.5' |
| 12 | + */ |
| 13 | +const extractDenoVersion = (input) => /\bdeno\b.*\b(?<version>\d+\.\d+\.\d+)(?<prerelease>-[\w.-]+)?\b/i.exec(input)?.groups?.version; |
| 14 | + |
4 | 15 | try { |
5 | | - childProcess.execSync('deno info'); |
| 16 | + const toolVersionsPath = path.resolve(__dirname, '..', '..', '..', '.tool-versions'); |
| 17 | + const denoToolVersion = extractDenoVersion(fs.readFileSync(toolVersionsPath).toString()); |
| 18 | + |
| 19 | + if (!denoToolVersion) { |
| 20 | + throw new Error(`Invalid Deno version in ${toolVersionsPath}, aborting...`); |
| 21 | + } |
| 22 | + |
| 23 | + const installedVersion = extractDenoVersion(childProcess.execSync('deno --version').toString()); |
| 24 | + |
| 25 | + if (!installedVersion) { |
| 26 | + throw new Error( |
| 27 | + `Couldn't determine version of installed Deno. Try validating the version with 'deno --version' and make sure it is a valid Deno installation`, |
| 28 | + ); |
| 29 | + } |
| 30 | + |
| 31 | + if (installedVersion !== denoToolVersion) { |
| 32 | + throw new Error(`Incorrect Deno version. Required '${denoToolVersion}', found '${installedVersion}'`); |
| 33 | + } |
6 | 34 | } catch (e) { |
7 | | - console.error( |
8 | | - 'Could not execute "deno" in the system. It is now a requirement for the Apps-Engine framework, and Rocket.Chat apps will not work without it.\n', |
9 | | - 'Make sure to install Deno and run the installation process for the Apps-Engine again. More info on https://docs.deno.com/runtime/manual/getting_started/installation', |
10 | | - ); |
| 35 | + if (e.status === SHELL_ERR_CMD_NOT_FOUND) { |
| 36 | + console.error( |
| 37 | + new Error( |
| 38 | + [ |
| 39 | + 'Could not execute "deno" in the system. It is now a requirement for the Apps-Engine framework, and Rocket.Chat apps will not work without it.', |
| 40 | + 'Make sure to install Deno and run the installation process for the Apps-Engine again. More info on https://docs.deno.com/runtime/manual/getting_started/installation', |
| 41 | + ].join('\n'), |
| 42 | + { cause: e }, |
| 43 | + ), |
| 44 | + ); |
| 45 | + } else { |
| 46 | + console.error(e); |
| 47 | + } |
| 48 | + |
11 | 49 | process.exit(1); |
12 | 50 | } |
13 | 51 |
|
14 | 52 | const rootPath = path.join(__dirname, '..'); |
15 | 53 | const denoRuntimePath = path.join(rootPath, 'deno-runtime'); |
16 | 54 | const DENO_DIR = process.env.DENO_DIR ?? path.join(rootPath, '.deno-cache'); |
17 | 55 |
|
18 | | -childProcess.execSync('deno cache main.ts', { |
| 56 | +childProcess.execSync('deno install --frozen --entrypoint main.ts', { |
19 | 57 | cwd: denoRuntimePath, |
20 | 58 | env: { |
21 | 59 | ...process.env, |
|
0 commit comments