fix: added incremental typing to piston

This commit is contained in:
Endercheif 2023-02-27 18:08:05 -08:00
parent 593f59a184
commit 2962e0cf99
No known key found for this signature in database
GPG key ID: 7767459A0C8BEE00
14 changed files with 1039 additions and 1318 deletions

View file

@ -1,10 +1,13 @@
const logger = require('logplease').create('runtime');
const semver = require('semver');
const config = require('./config');
const globals = require('./globals');
const fss = require('fs');
const path = require('path');
import { create } from 'logplease';
import { parse, satisfies, rcompare } from 'semver';
import config from './config';
import { platform } from './globals';
import { readFileSync, existsSync } from 'fs';
import { join } from 'path';
const logger = create('runtime', {});
/** @type {Array<Runtime>} */
const runtimes = [];
class Runtime {
@ -99,7 +102,8 @@ class Runtime {
static load_package(package_dir) {
let info = JSON.parse(
fss.read_file_sync(path.join(package_dir, 'pkg-info.json'))
// @ts-ignore
readFileSync(join(package_dir, 'pkg-info.json'))
);
let {
@ -110,12 +114,12 @@ class Runtime {
provides,
limit_overrides,
} = info;
version = semver.parse(version);
version = parse(version);
if (build_platform !== globals.platform) {
if (build_platform !== platform) {
logger.warn(
`Package ${language}-${version} was built for platform ${build_platform}, ` +
`but our platform is ${globals.platform}`
`but our platform is ${platform}`
);
}
@ -138,6 +142,7 @@ class Runtime {
});
} else {
runtimes.push(
// @ts-ignore
new Runtime({
language,
version,
@ -153,7 +158,7 @@ class Runtime {
get compiled() {
if (this._compiled === undefined) {
this._compiled = fss.exists_sync(path.join(this.pkgdir, 'compile'));
this._compiled = existsSync(join(this.pkgdir, 'compile'));
}
return this._compiled;
@ -161,8 +166,8 @@ class Runtime {
get env_vars() {
if (!this._env_vars) {
const env_file = path.join(this.pkgdir, '.env');
const env_content = fss.read_file_sync(env_file).toString();
const env_file = join(this.pkgdir, '.env');
const env_content = readFileSync(env_file).toString();
this._env_vars = {};
@ -188,31 +193,32 @@ class Runtime {
}
}
module.exports = runtimes;
module.exports.Runtime = Runtime;
module.exports.get_runtimes_matching_language_version = function (lang, ver) {
const _runtimes = runtimes;
export { _runtimes as runtimes };
const _Runtime = Runtime;
export { _Runtime as Runtime };
export function get_runtimes_matching_language_version(lang, ver) {
return runtimes.filter(
rt =>
(rt.language == lang || rt.aliases.includes(lang)) &&
semver.satisfies(rt.version, ver)
satisfies(rt.version, ver)
);
};
module.exports.get_latest_runtime_matching_language_version = function (
}
export function get_latest_runtime_matching_language_version(
lang,
ver
) {
return module.exports
.get_runtimes_matching_language_version(lang, ver)
.sort((a, b) => semver.rcompare(a.version, b.version))[0];
};
return get_runtimes_matching_language_version(lang, ver)
.sort((a, b) => rcompare(a.version, b.version))[0];
}
module.exports.get_runtime_by_name_and_version = function (runtime, ver) {
export function get_runtime_by_name_and_version(runtime, ver) {
return runtimes.find(
rt =>
(rt.runtime == runtime ||
(rt.runtime === undefined && rt.language == runtime)) &&
semver.satisfies(rt.version, ver)
satisfies(rt.version, ver)
);
};
}
module.exports.load_package = Runtime.load_package;
export const load_package = Runtime.load_package;