/ concept-collection / fastandaccurate
Sign in
concept-collection / fastandaccurate
fastandaccurate / scripts / cli-launcher.cjs
33 lines · 1.2 KBBlameHistoryRaw
1#!/usr/bin/env node
2/**
3 * The published command's entry point, whose only job is to be parseable
4 * by whatever node it lands on. main.js is a modern bundle: on an old node
5 * its first `import {` is a syntax error pointing at a brace, before any
6 * check inside it could run. This file is therefore deliberately ES5, and
7 * the dynamic import is built at run time, which older node cannot parse
8 * as written syntax either.
9 */
10"use strict";
12var MIN_MAJOR = 20;
13var have = process.versions.node;
14var major = parseInt(have.split(".")[0], 10);
16if (!(major >= MIN_MAJOR)) {
17 process.stderr.write(
18 "fastandaccurate: this is node " + have + ", and the harness needs node " +
19 MIN_MAJOR + " or newer (WebCrypto as a global, among other things).\n" +
20 " nodejs.org has current builds; nvm, fnm and asdf install one per user\n" +
21 " without touching what the system depends on.\n"
22 );
23 process.exit(1);
26var path = require("path");
27var url = require("url");
28var target = url.pathToFileURL(path.join(__dirname, "main.js")).href;
30new Function("specifier", "return import(specifier);")(target).catch(function (e) {
31 process.stderr.write(String((e && e.stack) || e) + "\n");
32 process.exit(1);
33});
moveopenescclose