Skip to content

Commit 96c905c

Browse files
committed
Ensure deno is installed
1 parent d9350d1 commit 96c905c

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

packages/deno/package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,23 @@
2424
"rollup-plugin-dts": "^6.1.0"
2525
},
2626
"scripts": {
27-
"prebuild": "deno types > lib.deno.d.ts",
27+
"install:deno": "run-s install:deno:binary install:deno:types",
28+
"install:deno:binary": "node ./scripts/install-deno.mjs",
29+
"install:deno:types": "deno types > lib.deno.d.ts",
30+
"prebuild": "yarn install:deno",
2831
"build": "rollup -c rollup.config.js",
2932
"postbuild": "deno check build/index.js",
3033
"build:dev": "yarn build",
34+
"build:transpile": "yarn build",
3135
"build:watch": "run-p build:transpile:watch build:types:watch",
3236
"build:dev:watch": "yarn build:watch",
3337
"circularDepCheck": "madge --circular src/index.ts",
3438
"clean": "rimraf build coverage",
39+
"prefix": "yarn install:deno",
3540
"fix": "run-s fix:eslint fix:prettier",
3641
"fix:eslint": "eslint . --format stylish --fix",
3742
"fix:prettier": "prettier --write \"{src,test,scripts}/**/**.ts\"",
43+
"prelint": "yarn install:deno",
3844
"lint": "run-s lint:prettier lint:eslint",
3945
"lint:eslint": "eslint . --format stylish",
4046
"lint:prettier": "prettier --check \"{src,test,scripts}/**/**.ts\""
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { execSync } from 'child_process';
2+
3+
async function download(url) {
4+
try {
5+
return await fetch(url).then(res => res.text());
6+
} catch (e) {
7+
console.error('Failed to download', url, e);
8+
process.exit(1);
9+
}
10+
}
11+
12+
try {
13+
// Ensure we're using the latest Deno version
14+
execSync('deno upgrade', { stdio: 'inherit' });
15+
} catch (_) {
16+
console.error('Deno is not installed. Installing...');
17+
if (process.platform === 'win32') {
18+
// TODO
19+
console.error('Please install Deno manually: https://docs.deno.com/runtime/manual/getting_started/installation');
20+
process.exit(1);
21+
} else {
22+
const script = await download('https://deno.land/x/install/install.sh');
23+
24+
try {
25+
execSync(script, { stdio: 'inherit' });
26+
} catch (e) {
27+
console.error('Failed to install Deno', e);
28+
process.exit(1);
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)