From 1e34b4bc80e901aec92fbb5201cdaa8730d48328 Mon Sep 17 00:00:00 2001 From: Robert Hood Chatham Date: Wed, 8 Mar 2023 11:58:45 +0100 Subject: [PATCH 01/23] Allow pyscript package to contain multiple files Followup to #1232. Closes #1226. Use node to make a manifest of the src/python dir and then use terser to inject it into the bundle as a variable called pyscript_package. This means we need to always use the terser plugin even when not minifying. In the non-minify case, we disable terser minification and mangling and enable terser beautification. Note that we bundle mangled versions of many upstream npm dependencies, so even in debug/nonminified builds, these do not include symbol names. --- pyscriptjs/rollup.config.js | 69 +++++++++++++++++++++++++------------ pyscriptjs/src/main.ts | 12 +++++-- 2 files changed, 56 insertions(+), 25 deletions(-) diff --git a/pyscriptjs/rollup.config.js b/pyscriptjs/rollup.config.js index bc6a5c65c5e..a26ad254732 100644 --- a/pyscriptjs/rollup.config.js +++ b/pyscriptjs/rollup.config.js @@ -7,6 +7,31 @@ import css from 'rollup-plugin-css-only'; import serve from 'rollup-plugin-serve'; import { string } from 'rollup-plugin-string'; import copy from 'rollup-plugin-copy'; +import * as fs from 'fs'; +import * as path from 'path'; + +function directoryManifest(root, dir = '.', result = { dirs: [], files: [] }) { + const curdir = path.join(root, dir); + const dirObj = fs.opendirSync(curdir); + try { + let d; + while ((d = dirObj.readSync())) { + const entry = path.join(dir, d.name); + if (d.isDirectory()) { + if (d.name === '__pycache__') { + continue; + } + result.dirs.push(entry); + directoryManifest(root, entry, result); + } else if (d.isFile()) { + result.files.push([entry, fs.readFileSync(path.join(root, entry), { encoding: 'utf-8' })]); + } + } + return result; + } finally { + dirObj.close(); + } +} const production = !process.env.ROLLUP_WATCH || process.env.NODE_ENV === 'production'; @@ -23,29 +48,30 @@ if (!production) { export default { input: 'src/main.ts', - output: [ - { - file: 'build/pyscript.js', - format: 'iife', - sourcemap: true, - inlineDynamicImports: true, - name: 'pyscript', - }, - { - file: 'build/pyscript.min.js', - format: 'iife', - sourcemap: true, - inlineDynamicImports: true, - name: 'pyscript', - plugins: [terser()], - }, - ], + output: [{ minify: true }, { minify: false }].map(({ minify }) => ({ + file: `build/pyscript${minify ? '.min' : ''}.js`, + format: 'iife', + sourcemap: !production, + inlineDynamicImports: true, + name: 'pyscript', + plugins: [ + terser({ + compress: { + defaults: minify, + dead_code: true, + global_defs: { + pyscript_package: directoryManifest('./src/python'), + }, + }, + mangle: minify, + format: { + beautify: !minify, + }, + }), + ], + })), plugins: [ css({ output: 'pyscript.css' }), - // Bundle all the Python files into the output file - string({ - include: './src/**/*.py', - }), legacy({ 'src/toml.js': 'toml' }), resolve({ browser: true, @@ -57,7 +83,6 @@ export default { }), // This will make sure that examples will always get the latest build folder copy(copy_targets), - // production && terser(), !production && serve({ port: 8080, diff --git a/pyscriptjs/src/main.ts b/pyscriptjs/src/main.ts index 760f94043af..5ff8f8ff28f 100644 --- a/pyscriptjs/src/main.ts +++ b/pyscriptjs/src/main.ts @@ -21,6 +21,8 @@ import { StdioDirector as StdioDirector } from './plugins/stdiodirector'; import pyscript from './python/pyscript/__init__.py'; import { robustFetch } from './fetch'; +declare const pyscript_package: { dirs: string[]; files: [string, string] }; + const logger = getLogger('pyscript/main'); /* High-level overview of the lifecycle of a PyScript App: @@ -207,9 +209,13 @@ export class PyScriptApp { // compatible with the old behavior. logger.info('importing pyscript'); - // Save and load pyscript.py from FS - interpreter._remote.interface.FS.mkdirTree('/home/pyodide/pyscript'); - interpreter._remote.interface.FS.writeFile('pyscript/__init__.py', pyscript); + // Write pyscript package into file system + for (let dir of pyscript_package.dirs) { + interpreter._remote.interface.FS.mkdir('/home/pyodide/' + dir); + } + for (let [path, value] of pyscript_package.files) { + interpreter._remote.interface.FS.writeFile('/home/pyodide/' + path, value); + } //Refresh the module cache so Python consistently finds pyscript module interpreter._remote.invalidate_module_path_cache(); From b8d0835497af896c962c8b2d3384e5f5f5057fb0 Mon Sep 17 00:00:00 2001 From: Robert Hood Chatham Date: Wed, 8 Mar 2023 12:26:24 +0100 Subject: [PATCH 02/23] Remove unused import --- pyscriptjs/rollup.config.js | 1 - 1 file changed, 1 deletion(-) diff --git a/pyscriptjs/rollup.config.js b/pyscriptjs/rollup.config.js index a26ad254732..a20dd5c3a8a 100644 --- a/pyscriptjs/rollup.config.js +++ b/pyscriptjs/rollup.config.js @@ -5,7 +5,6 @@ import legacy from '@rollup/plugin-legacy'; import typescript from '@rollup/plugin-typescript'; import css from 'rollup-plugin-css-only'; import serve from 'rollup-plugin-serve'; -import { string } from 'rollup-plugin-string'; import copy from 'rollup-plugin-copy'; import * as fs from 'fs'; import * as path from 'path'; From 564e1e177174ce840709b193d07662fe3eed362f Mon Sep 17 00:00:00 2001 From: Robert Hood Chatham Date: Wed, 8 Mar 2023 12:30:43 +0100 Subject: [PATCH 03/23] Unvendor toml package --- pyscriptjs/package-lock.json | 13 + pyscriptjs/package.json | 1 + pyscriptjs/src/pyconfig.ts | 2 +- pyscriptjs/src/toml.js | 1783 ---------------------------------- 4 files changed, 15 insertions(+), 1784 deletions(-) delete mode 100644 pyscriptjs/src/toml.js diff --git a/pyscriptjs/package-lock.json b/pyscriptjs/package-lock.json index 54ac547e5f6..46c4fe00775 100644 --- a/pyscriptjs/package-lock.json +++ b/pyscriptjs/package-lock.json @@ -40,6 +40,7 @@ "rollup-plugin-serve": "2.0.1", "rollup-plugin-string": "3.0.0", "rollup-plugin-terser": "7.0.2", + "toml": "^3.0.0", "ts-jest": "29.0.3", "tslib": "2.4.0", "typescript": "4.8.4" @@ -5308,6 +5309,12 @@ "node": ">=8.0" } }, + "node_modules/toml": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/toml/-/toml-3.0.0.tgz", + "integrity": "sha512-y/mWCZinnvxjTKYhJ+pYxwD0mRLVvOtdS2Awbgxln6iEnt4rk0yBxeSBHkGJcPucRiG0e55mwWp+g/05rsrd6w==", + "dev": true + }, "node_modules/tough-cookie": { "version": "4.1.2", "dev": true, @@ -9142,6 +9149,12 @@ "is-number": "^7.0.0" } }, + "toml": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/toml/-/toml-3.0.0.tgz", + "integrity": "sha512-y/mWCZinnvxjTKYhJ+pYxwD0mRLVvOtdS2Awbgxln6iEnt4rk0yBxeSBHkGJcPucRiG0e55mwWp+g/05rsrd6w==", + "dev": true + }, "tough-cookie": { "version": "4.1.2", "dev": true, diff --git a/pyscriptjs/package.json b/pyscriptjs/package.json index 43455626daf..e35ab8f59ec 100644 --- a/pyscriptjs/package.json +++ b/pyscriptjs/package.json @@ -38,6 +38,7 @@ "rollup-plugin-serve": "2.0.1", "rollup-plugin-string": "3.0.0", "rollup-plugin-terser": "7.0.2", + "toml": "^3.0.0", "ts-jest": "29.0.3", "tslib": "2.4.0", "typescript": "4.8.4" diff --git a/pyscriptjs/src/pyconfig.ts b/pyscriptjs/src/pyconfig.ts index 9ebfb5ce38e..148d679bbd3 100644 --- a/pyscriptjs/src/pyconfig.ts +++ b/pyscriptjs/src/pyconfig.ts @@ -1,4 +1,4 @@ -import toml from '../src/toml'; +import * as toml from 'toml'; import { getLogger } from './logger'; import { version } from './version'; import { getAttribute, readTextFromPath, htmlDecode, createDeprecationWarning } from './utils'; diff --git a/pyscriptjs/src/toml.js b/pyscriptjs/src/toml.js deleted file mode 100644 index 1bf0a31872a..00000000000 --- a/pyscriptjs/src/toml.js +++ /dev/null @@ -1,1783 +0,0 @@ -/* eslint-disable */ -!(function (r) { - if ('object' == typeof exports && 'undefined' != typeof module) module.exports = r(); - else if ('function' == typeof define && define.amd) define([], r); - else { - ('undefined' != typeof window - ? window - : 'undefined' != typeof global - ? global - : 'undefined' != typeof self - ? self - : this - ).toml = r(); - } -})(function () { - return (function r(t, e, n) { - function u(i, a) { - if (!e[i]) { - if (!t[i]) { - var c = 'function' == typeof require && require; - if (!a && c) return c(i, !0); - if (o) return o(i, !0); - var f = new Error("Cannot find module '" + i + "'"); - throw ((f.code = 'MODULE_NOT_FOUND'), f); - } - var s = (e[i] = { - exports: {}, - }); - t[i][0].call( - s.exports, - function (r) { - var e = t[i][1][r]; - return u(e || r); - }, - s, - s.exports, - r, - t, - e, - n, - ); - } - return e[i].exports; - } - for (var o = 'function' == typeof require && require, i = 0; i < n.length; i++) u(n[i]); - return u; - })( - { - 1: [ - function (r, t, e) { - t.exports = (function () { - 'use strict'; - - function r(t, e, n, u) { - (this.message = t), - (this.expected = e), - (this.found = n), - (this.location = u), - (this.name = 'SyntaxError'), - 'function' == typeof Error.captureStackTrace && Error.captureStackTrace(this, r); - } - return ( - (function (r, t) { - function e() { - this.constructor = r; - } - (e.prototype = t.prototype), (r.prototype = new e()); - })(r, Error), - (r.buildMessage = function (r, t) { - function e(r) { - return r.charCodeAt(0).toString(16).toUpperCase(); - } - - function n(r) { - return r - .replace(/\\/g, '\\\\') - .replace(/"/g, '\\"') - .replace(/\0/g, '\\0') - .replace(/\t/g, '\\t') - .replace(/\n/g, '\\n') - .replace(/\r/g, '\\r') - .replace(/[\x00-\x0F]/g, function (r) { - return '\\x0' + e(r); - }) - .replace(/[\x10-\x1F\x7F-\x9F]/g, function (r) { - return '\\x' + e(r); - }); - } - - function u(r) { - return r - .replace(/\\/g, '\\\\') - .replace(/\]/g, '\\]') - .replace(/\^/g, '\\^') - .replace(/-/g, '\\-') - .replace(/\0/g, '\\0') - .replace(/\t/g, '\\t') - .replace(/\n/g, '\\n') - .replace(/\r/g, '\\r') - .replace(/[\x00-\x0F]/g, function (r) { - return '\\x0' + e(r); - }) - .replace(/[\x10-\x1F\x7F-\x9F]/g, function (r) { - return '\\x' + e(r); - }); - } - - function o(r) { - return i[r.type](r); - } - var i = { - literal: function (r) { - return '"' + n(r.text) + '"'; - }, - class: function (r) { - var t, - e = ''; - for (t = 0; t < r.parts.length; t++) - e += - r.parts[t] instanceof Array - ? u(r.parts[t][0]) + '-' + u(r.parts[t][1]) - : u(r.parts[t]); - return '[' + (r.inverted ? '^' : '') + e + ']'; - }, - any: function (r) { - return 'any character'; - }, - end: function (r) { - return 'end of input'; - }, - other: function (r) { - return r.description; - }, - }; - return ( - 'Expected ' + - (function (r) { - var t, - e, - n = new Array(r.length); - for (t = 0; t < r.length; t++) n[t] = o(r[t]); - if ((n.sort(), n.length > 0)) { - for (t = 1, e = 1; t < n.length; t++) - n[t - 1] !== n[t] && ((n[e] = n[t]), e++); - n.length = e; - } - switch (n.length) { - case 1: - return n[0]; - case 2: - return n[0] + ' or ' + n[1]; - default: - return n.slice(0, -1).join(', ') + ', or ' + n[n.length - 1]; - } - })(r) + - ' but ' + - (function (r) { - return r ? '"' + n(r) + '"' : 'end of input'; - })(t) + - ' found.' - ); - }), - { - SyntaxError: r, - parse: function (t, e) { - function n() { - return t.substring(Me, _e); - } - - function u(r, t) { - throw ((t = void 0 !== t ? t : f(Me, _e)), l(r, t)); - } - - function o(r, t) { - return { - type: 'literal', - text: r, - ignoreCase: t, - }; - } - - function i(r, t, e) { - return { - type: 'class', - parts: r, - inverted: t, - ignoreCase: e, - }; - } - - function a(r) { - return { - type: 'other', - description: r, - }; - } - - function c(r) { - var e, - n = Ne[r]; - if (n) return n; - for (e = r - 1; !Ne[e]; ) e--; - for ( - n = { - line: (n = Ne[e]).line, - column: n.column, - }; - e < r; - - ) - 10 === t.charCodeAt(e) ? (n.line++, (n.column = 1)) : n.column++, e++; - return (Ne[r] = n), n; - } - - function f(r, t) { - var e = c(r), - n = c(t); - return { - start: { - offset: r, - line: e.line, - column: e.column, - }, - end: { - offset: t, - line: n.line, - column: n.column, - }, - }; - } - - function s(r) { - _e < He || (_e > He && ((He = _e), (Ue = [])), Ue.push(r)); - } - - function l(t, e) { - return new r(t, null, null, e); - } - - function h(t, e, n) { - return new r(r.buildMessage(t, e), t, e, n); - } - - function p() { - var r, t, e, n, u, o, i, a; - for ( - r = _e, t = [], (e = g()) === mr && (e = d()) === mr && (e = A()); - e !== mr; - - ) - t.push(e), (e = g()) === mr && (e = d()) === mr && (e = A()); - if (t !== mr) { - if (((e = _e), (n = v()) !== mr)) { - for (u = [], (o = g()) === mr && (o = A()); o !== mr; ) - u.push(o), (o = g()) === mr && (o = A()); - u !== mr - ? ((o = _e), - (i = d()) !== mr && (a = p()) !== mr - ? (o = i = [i, a]) - : ((_e = o), (o = mr)), - o === mr && (o = null), - o !== mr ? (e = n = [n, u, o]) : ((_e = e), (e = mr))) - : ((_e = e), (e = mr)); - } else (_e = e), (e = mr); - e === mr && (e = null), - e !== mr ? ((Me = r), (r = t = wr())) : ((_e = r), (r = mr)); - } else (_e = r), (r = mr); - return r; - } - - function v() { - var r, t; - return ( - (r = _e), - (t = Cr()) !== mr && ((Me = r), (t = Fr(t))), - (r = t) === mr && - ((r = _e), - (t = yr()) !== mr && ((Me = r), (t = Er(t))), - (r = t) === mr && - ((r = _e), (t = C()) !== mr && ((Me = r), (t = Tr(t))), (r = t))), - r - ); - } - - function d() { - var r; - return ( - Ze++, - 10 === t.charCodeAt(_e) ? ((r = Or), _e++) : ((r = mr), 0 === Ze && s(jr)), - r === mr && - (t.substr(_e, 2) === _r - ? ((r = _r), (_e += 2)) - : ((r = mr), 0 === Ze && s(Mr))), - Ze--, - r === mr && 0 === Ze && s(Dr), - r - ); - } - - function g() { - var r; - return ( - Ze++, - Hr.test(t.charAt(_e)) - ? ((r = t.charAt(_e)), _e++) - : ((r = mr), 0 === Ze && s(Ur)), - Ze--, - r === mr && 0 === Ze && s(Nr), - r - ); - } - - function A() { - var r, e, n, u, o, i; - if ( - (Ze++, - (r = _e), - 35 === t.charCodeAt(_e) ? ((e = Ir), _e++) : ((e = mr), 0 === Ze && s(Rr)), - e !== mr) - ) { - for ( - n = [], - u = _e, - o = _e, - Ze++, - i = d(), - Ze--, - i === mr ? (o = void 0) : ((_e = o), (o = mr)), - o !== mr - ? (t.length > _e - ? ((i = t.charAt(_e)), _e++) - : ((i = mr), 0 === Ze && s(qr)), - i !== mr ? (u = o = [o, i]) : ((_e = u), (u = mr))) - : ((_e = u), (u = mr)); - u !== mr; - - ) - n.push(u), - (u = _e), - (o = _e), - Ze++, - (i = d()), - Ze--, - i === mr ? (o = void 0) : ((_e = o), (o = mr)), - o !== mr - ? (t.length > _e - ? ((i = t.charAt(_e)), _e++) - : ((i = mr), 0 === Ze && s(qr)), - i !== mr ? (u = o = [o, i]) : ((_e = u), (u = mr))) - : ((_e = u), (u = mr)); - n !== mr ? (r = e = [e, n]) : ((_e = r), (r = mr)); - } else (_e = r), (r = mr); - return Ze--, r === mr && ((e = mr), 0 === Ze && s(Zr)), r; - } - - function C() { - var r, e, n, u, o, i; - if (((r = _e), (e = y()) !== mr)) { - for (n = [], u = g(); u !== mr; ) n.push(u), (u = g()); - if (n !== mr) - if ( - (61 === t.charCodeAt(_e) - ? ((u = Qr), _e++) - : ((u = mr), 0 === Ze && s(Yr)), - u !== mr) - ) { - for (o = [], i = g(); i !== mr; ) o.push(i), (i = g()); - o !== mr && (i = T()) !== mr - ? ((Me = r), (r = e = kr(e, i))) - : ((_e = r), (r = mr)); - } else (_e = r), (r = mr); - else (_e = r), (r = mr); - } else (_e = r), (r = mr); - return r; - } - - function y() { - var r; - return (r = b()) === mr && (r = x()), r; - } - - function b() { - var r, t, e; - if (((r = _e), (t = []), (e = m()) !== mr)) - for (; e !== mr; ) t.push(e), (e = m()); - else t = mr; - return t !== mr && ((Me = r), (t = zr())), (r = t); - } - - function m() { - var r; - return ( - Ze++, - Jr.test(t.charAt(_e)) - ? ((r = t.charAt(_e)), _e++) - : ((r = mr), 0 === Ze && s(Pr)), - Ze--, - r === mr && 0 === Ze && s(Br), - r - ); - } - - function x() { - var r, t, e; - if (((r = _e), S() !== mr)) { - if (((t = []), (e = j()) !== mr)) for (; e !== mr; ) t.push(e), (e = j()); - else t = mr; - t !== mr && (e = S()) !== mr - ? ((Me = r), (r = Lr(t))) - : ((_e = r), (r = mr)); - } else (_e = r), (r = mr); - return r; - } - - function S() { - var r; - return ( - Ze++, - 34 === t.charCodeAt(_e) ? ((r = Wr), _e++) : ((r = mr), 0 === Ze && s(Gr)), - Ze--, - r === mr && 0 === Ze && s(Vr), - r - ); - } - - function w() { - var r; - return ( - Ze++, - 39 === t.charCodeAt(_e) ? ((r = Xr), _e++) : ((r = mr), 0 === Ze && s($r)), - Ze--, - r === mr && 0 === Ze && s(Kr), - r - ); - } - - function F() { - var r; - return ( - Ze++, - t.substr(_e, 3) === tt - ? ((r = tt), (_e += 3)) - : ((r = mr), 0 === Ze && s(et)), - Ze--, - r === mr && 0 === Ze && s(rt), - r - ); - } - - function E() { - var r; - return ( - Ze++, - t.substr(_e, 3) === ut - ? ((r = ut), (_e += 3)) - : ((r = mr), 0 === Ze && s(ot)), - Ze--, - r === mr && 0 === Ze && s(nt), - r - ); - } - - function T() { - var r; - return ( - (r = D()) === mr && - (r = L()) === mr && - (r = er()) === mr && - (r = V()) === mr && - (r = K()) === mr && - (r = vr()) === mr && - (r = Ar()), - r - ); - } - - function D() { - var r; - return (r = Q()) === mr && (r = O()) === mr && (r = B()) === mr && (r = R()), r; - } - - function O() { - var r, t, e; - if (((r = _e), S() !== mr)) { - for (t = [], e = j(); e !== mr; ) t.push(e), (e = j()); - t !== mr && (e = S()) !== mr - ? ((Me = r), (r = it(t))) - : ((_e = r), (r = mr)); - } else (_e = r), (r = mr); - return r; - } - - function j() { - var r; - return (r = _()) === mr && (r = M()), r; - } - - function _() { - var r, e, n; - return ( - Ze++, - (r = _e), - (e = _e), - Ze++, - (n = d()), - Ze--, - n === mr ? (e = void 0) : ((_e = e), (e = mr)), - e !== mr - ? (ct.test(t.charAt(_e)) - ? ((n = t.charAt(_e)), _e++) - : ((n = mr), 0 === Ze && s(ft)), - n !== mr ? ((Me = r), (r = e = zr())) : ((_e = r), (r = mr))) - : ((_e = r), (r = mr)), - Ze--, - r === mr && ((e = mr), 0 === Ze && s(at)), - r - ); - } - - function M() { - var r, e, n, u; - return ( - (r = _e), - H() !== mr - ? ((e = N()) === mr && - (e = S()) === mr && - (e = H()) === mr && - ((e = _e), - 117 === t.charCodeAt(_e) - ? ((n = st), _e++) - : ((n = mr), 0 === Ze && s(lt)), - n !== mr && (u = U()) !== mr - ? (e = n = [n, u]) - : ((_e = e), (e = mr)), - e === mr && - ((e = _e), - 85 === t.charCodeAt(_e) - ? ((n = ht), _e++) - : ((n = mr), 0 === Ze && s(pt)), - n !== mr && (u = Z()) !== mr - ? (e = n = [n, u]) - : ((_e = e), (e = mr)))), - e !== mr ? ((Me = r), (r = vt())) : ((_e = r), (r = mr))) - : ((_e = r), (r = mr)), - r - ); - } - - function N() { - var r; - return ( - Ze++, - gt.test(t.charAt(_e)) - ? ((r = t.charAt(_e)), _e++) - : ((r = mr), 0 === Ze && s(At)), - Ze--, - r === mr && 0 === Ze && s(dt), - r - ); - } - - function H() { - var r; - return ( - Ze++, - 92 === t.charCodeAt(_e) ? ((r = yt), _e++) : ((r = mr), 0 === Ze && s(bt)), - Ze--, - r === mr && 0 === Ze && s(Ct), - r - ); - } - - function U() { - var r, t, e, n, u; - return ( - Ze++, - (r = _e), - (t = I()) !== mr && (e = I()) !== mr && (n = I()) !== mr && (u = I()) !== mr - ? (r = t = [t, e, n, u]) - : ((_e = r), (r = mr)), - Ze--, - r === mr && ((t = mr), 0 === Ze && s(mt)), - r - ); - } - - function Z() { - var r, t, e, n, u, o, i, a, c; - return ( - Ze++, - (r = _e), - (t = I()) !== mr && - (e = I()) !== mr && - (n = I()) !== mr && - (u = I()) !== mr && - (o = I()) !== mr && - (i = I()) !== mr && - (a = I()) !== mr && - (c = I()) !== mr - ? (r = t = [t, e, n, u, o, i, a, c]) - : ((_e = r), (r = mr)), - Ze--, - r === mr && ((t = mr), 0 === Ze && s(xt)), - r - ); - } - - function I() { - var r; - return ( - St.test(t.charAt(_e)) - ? ((r = t.charAt(_e)), _e++) - : ((r = mr), 0 === Ze && s(wt)), - r - ); - } - - function R() { - var r, t, e; - if (((r = _e), w() !== mr)) { - for (t = [], e = q(); e !== mr; ) t.push(e), (e = q()); - t !== mr && (e = w()) !== mr - ? ((Me = r), (r = Ft())) - : ((_e = r), (r = mr)); - } else (_e = r), (r = mr); - return r; - } - - function q() { - var r, e, n; - return ( - Ze++, - (r = _e), - (e = _e), - Ze++, - (n = d()), - Ze--, - n === mr ? (e = void 0) : ((_e = e), (e = mr)), - e !== mr - ? (Et.test(t.charAt(_e)) - ? ((n = t.charAt(_e)), _e++) - : ((n = mr), 0 === Ze && s(Tt)), - n !== mr ? (r = e = [e, n]) : ((_e = r), (r = mr))) - : ((_e = r), (r = mr)), - Ze--, - r === mr && ((e = mr), 0 === Ze && s(at)), - r - ); - } - - function Q() { - var r, t, e, n; - if (((r = _e), F() !== mr)) - if (((t = d()) === mr && (t = null), t !== mr)) { - for (e = [], n = Y(); n !== mr; ) e.push(n), (n = Y()); - e !== mr && (n = F()) !== mr - ? ((Me = r), (r = Dt(e))) - : ((_e = r), (r = mr)); - } else (_e = r), (r = mr); - else (_e = r), (r = mr); - return r; - } - - function Y() { - var r; - return ( - (r = k()) === mr && - ((r = _e), - H() !== mr && d() !== mr - ? ((Me = r), (r = zr())) - : ((_e = r), (r = mr)), - r === mr && (r = d())), - r - ); - } - - function k() { - var r, t, e; - return ( - (r = _e), - (t = _e), - Ze++, - (e = F()), - Ze--, - e === mr ? (t = void 0) : ((_e = t), (t = mr)), - t !== mr && (e = z()) !== mr - ? ((Me = r), (r = t = zr())) - : ((_e = r), (r = mr)), - r === mr && (r = M()), - r - ); - } - - function z() { - var r, e, n; - return ( - Ze++, - (r = _e), - (e = _e), - Ze++, - (n = d()), - Ze--, - n === mr ? (e = void 0) : ((_e = e), (e = mr)), - e !== mr - ? (Ot.test(t.charAt(_e)) - ? ((n = t.charAt(_e)), _e++) - : ((n = mr), 0 === Ze && s(jt)), - n !== mr ? (r = e = [e, n]) : ((_e = r), (r = mr))) - : ((_e = r), (r = mr)), - Ze--, - r === mr && ((e = mr), 0 === Ze && s(at)), - r - ); - } - - function B() { - var r, t, e, n; - if (((r = _e), E() !== mr)) - if (((t = d()) === mr && (t = null), t !== mr)) { - for (e = [], n = J(); n !== mr; ) e.push(n), (n = J()); - e !== mr && (n = E()) !== mr - ? ((Me = r), (r = it(e))) - : ((_e = r), (r = mr)); - } else (_e = r), (r = mr); - else (_e = r), (r = mr); - return r; - } - - function J() { - var r, e, n; - return ( - (r = _e), - (e = _e), - Ze++, - t.substr(_e, 3) === ut - ? ((n = ut), (_e += 3)) - : ((n = mr), 0 === Ze && s(ot)), - Ze--, - n === mr ? (e = void 0) : ((_e = e), (e = mr)), - e !== mr && (n = P()) !== mr - ? ((Me = r), (r = e = zr())) - : ((_e = r), (r = mr)), - r === mr && (r = d()), - r - ); - } - - function P() { - var r, e, n; - return ( - Ze++, - (r = _e), - (e = _e), - Ze++, - (n = d()), - Ze--, - n === mr ? (e = void 0) : ((_e = e), (e = mr)), - e !== mr - ? (Mt.test(t.charAt(_e)) - ? ((n = t.charAt(_e)), _e++) - : ((n = mr), 0 === Ze && s(Nt)), - n !== mr ? (r = e = [e, n]) : ((_e = r), (r = mr))) - : ((_e = r), (r = mr)), - Ze--, - r === mr && ((e = mr), 0 === Ze && s(_t)), - r - ); - } - - function L() { - var r, e; - return ( - (r = _e), - t.substr(_e, 4) === Ht - ? ((e = Ht), (_e += 4)) - : ((e = mr), 0 === Ze && s(Ut)), - e !== mr && ((Me = r), (e = Zt())), - (r = e) === mr && - ((r = _e), - t.substr(_e, 5) === It - ? ((e = It), (_e += 5)) - : ((e = mr), 0 === Ze && s(Rt)), - e !== mr && ((Me = r), (e = qt())), - (r = e)), - r - ); - } - - function V() { - var r, t, e, n; - return ( - (r = _e), - K() !== mr - ? ((t = _e), - (e = W()) !== mr - ? ((n = G()) === mr && (n = null), - n !== mr ? (t = e = [e, n]) : ((_e = t), (t = mr))) - : ((_e = t), (t = mr)), - t === mr && (t = G()), - t !== mr ? ((Me = r), (r = Qt())) : ((_e = r), (r = mr))) - : ((_e = r), (r = mr)), - r - ); - } - - function W() { - var r, e, n, u, o, i, a; - if ( - ((r = _e), - 46 === t.charCodeAt(_e) ? ((e = Yt), _e++) : ((e = mr), 0 === Ze && s(kt)), - e !== mr) - ) - if ((n = tr()) !== mr) { - for ( - u = [], - o = _e, - 95 === t.charCodeAt(_e) - ? ((i = zt), _e++) - : ((i = mr), 0 === Ze && s(Bt)), - i === mr && (i = null), - i !== mr && (a = tr()) !== mr - ? (o = i = [i, a]) - : ((_e = o), (o = mr)); - o !== mr; - - ) - u.push(o), - (o = _e), - 95 === t.charCodeAt(_e) - ? ((i = zt), _e++) - : ((i = mr), 0 === Ze && s(Bt)), - i === mr && (i = null), - i !== mr && (a = tr()) !== mr - ? (o = i = [i, a]) - : ((_e = o), (o = mr)); - u !== mr ? (r = e = [e, n, u]) : ((_e = r), (r = mr)); - } else (_e = r), (r = mr); - else (_e = r), (r = mr); - return r; - } - - function G() { - var r, e, n; - return ( - (r = _e), - 101 === t.charCodeAt(_e) ? ((e = Jt), _e++) : ((e = mr), 0 === Ze && s(Pt)), - e === mr && - (69 === t.charCodeAt(_e) - ? ((e = Lt), _e++) - : ((e = mr), 0 === Ze && s(Vt))), - e !== mr && (n = K()) !== mr ? (r = e = [e, n]) : ((_e = r), (r = mr)), - r - ); - } - - function K() { - var r, t; - return ( - (r = _e), - (t = X()) === mr && (t = null), - t !== mr && $() !== mr ? ((Me = r), (r = t = Wt())) : ((_e = r), (r = mr)), - r - ); - } - - function X() { - var r; - return ( - 43 === t.charCodeAt(_e) ? ((r = Gt), _e++) : ((r = mr), 0 === Ze && s(Kt)), - r === mr && - (45 === t.charCodeAt(_e) - ? ((r = Xt), _e++) - : ((r = mr), 0 === Ze && s($t))), - r - ); - } - - function $() { - var r, e, n, u, o, i; - if (((r = _e), (e = rr()) !== mr)) { - if ( - ((n = []), - (u = _e), - 95 === t.charCodeAt(_e) - ? ((o = zt), _e++) - : ((o = mr), 0 === Ze && s(Bt)), - o === mr && (o = null), - o !== mr && (i = tr()) !== mr ? (u = o = [o, i]) : ((_e = u), (u = mr)), - u !== mr) - ) - for (; u !== mr; ) - n.push(u), - (u = _e), - 95 === t.charCodeAt(_e) - ? ((o = zt), _e++) - : ((o = mr), 0 === Ze && s(Bt)), - o === mr && (o = null), - o !== mr && (i = tr()) !== mr - ? (u = o = [o, i]) - : ((_e = u), (u = mr)); - else n = mr; - n !== mr ? (r = e = [e, n]) : ((_e = r), (r = mr)); - } else (_e = r), (r = mr); - return r === mr && (r = tr()), r; - } - - function rr() { - var r; - return ( - re.test(t.charAt(_e)) - ? ((r = t.charAt(_e)), _e++) - : ((r = mr), 0 === Ze && s(te)), - r - ); - } - - function tr() { - var r; - return ( - ee.test(t.charAt(_e)) - ? ((r = t.charAt(_e)), _e++) - : ((r = mr), 0 === Ze && s(ne)), - r - ); - } - - function er() { - var r, e; - return ( - (r = _e), - nr() !== mr - ? (84 === t.charCodeAt(_e) - ? ((e = ue), _e++) - : ((e = mr), 0 === Ze && s(oe)), - e !== mr && ar() !== mr - ? ((Me = r), (r = ie())) - : ((_e = r), (r = mr))) - : ((_e = r), (r = mr)), - r - ); - } - - function nr() { - var r, e, n, u, o, i; - return ( - Ze++, - (r = _e), - (e = ur()) !== mr - ? (45 === t.charCodeAt(_e) - ? ((n = Xt), _e++) - : ((n = mr), 0 === Ze && s($t)), - n !== mr && (u = or()) !== mr - ? (45 === t.charCodeAt(_e) - ? ((o = Xt), _e++) - : ((o = mr), 0 === Ze && s($t)), - o !== mr && (i = ir()) !== mr - ? (r = e = [e, n, u, o, i]) - : ((_e = r), (r = mr))) - : ((_e = r), (r = mr))) - : ((_e = r), (r = mr)), - Ze--, - r === mr && ((e = mr), 0 === Ze && s(ae)), - r - ); - } - - function ur() { - var r, t, e, n, u; - return ( - (r = _e), - (t = tr()) !== mr && - (e = tr()) !== mr && - (n = tr()) !== mr && - (u = tr()) !== mr - ? (r = t = [t, e, n, u]) - : ((_e = r), (r = mr)), - r - ); - } - - function or() { - var r, t, e; - return ( - (r = _e), - (t = tr()) !== mr && (e = tr()) !== mr - ? (r = t = [t, e]) - : ((_e = r), (r = mr)), - r - ); - } - - function ir() { - var r, t, e; - return ( - (r = _e), - (t = tr()) !== mr && (e = tr()) !== mr - ? (r = t = [t, e]) - : ((_e = r), (r = mr)), - r - ); - } - - function ar() { - var r, t, e; - return ( - (r = _e), - (t = cr()) !== mr && (e = pr()) !== mr - ? (r = t = [t, e]) - : ((_e = r), (r = mr)), - r - ); - } - - function cr() { - var r, e, n, u, o, i, a; - return ( - (r = _e), - (e = fr()) !== mr - ? (58 === t.charCodeAt(_e) - ? ((n = ce), _e++) - : ((n = mr), 0 === Ze && s(fe)), - n !== mr && (u = sr()) !== mr - ? (58 === t.charCodeAt(_e) - ? ((o = ce), _e++) - : ((o = mr), 0 === Ze && s(fe)), - o !== mr && (i = lr()) !== mr - ? ((a = hr()) === mr && (a = null), - a !== mr - ? (r = e = [e, n, u, o, i, a]) - : ((_e = r), (r = mr))) - : ((_e = r), (r = mr))) - : ((_e = r), (r = mr))) - : ((_e = r), (r = mr)), - r - ); - } - - function fr() { - var r, t, e; - return ( - Ze++, - (r = _e), - (t = tr()) !== mr && (e = tr()) !== mr - ? (r = t = [t, e]) - : ((_e = r), (r = mr)), - Ze--, - r === mr && ((t = mr), 0 === Ze && s(se)), - r - ); - } - - function sr() { - var r, t, e; - return ( - Ze++, - (r = _e), - (t = tr()) !== mr && (e = tr()) !== mr - ? (r = t = [t, e]) - : ((_e = r), (r = mr)), - Ze--, - r === mr && ((t = mr), 0 === Ze && s(le)), - r - ); - } - - function lr() { - var r, t, e; - return ( - Ze++, - (r = _e), - (t = tr()) !== mr && (e = tr()) !== mr - ? (r = t = [t, e]) - : ((_e = r), (r = mr)), - Ze--, - r === mr && ((t = mr), 0 === Ze && s(he)), - r - ); - } - - function hr() { - var r, e, n, u; - if ( - ((r = _e), - 46 === t.charCodeAt(_e) ? ((e = Yt), _e++) : ((e = mr), 0 === Ze && s(kt)), - e !== mr) - ) { - if (((n = []), (u = tr()) !== mr)) for (; u !== mr; ) n.push(u), (u = tr()); - else n = mr; - n !== mr ? (r = e = [e, n]) : ((_e = r), (r = mr)); - } else (_e = r), (r = mr); - return r; - } - - function pr() { - var r, e, n, u, o; - return ( - Ze++, - 90 === t.charCodeAt(_e) ? ((r = ve), _e++) : ((r = mr), 0 === Ze && s(de)), - r === mr && - ((r = _e), - (e = X()) !== mr && (n = fr()) !== mr - ? (58 === t.charCodeAt(_e) - ? ((u = ce), _e++) - : ((u = mr), 0 === Ze && s(fe)), - u !== mr && (o = sr()) !== mr - ? (r = e = [e, n, u, o]) - : ((_e = r), (r = mr))) - : ((_e = r), (r = mr))), - Ze--, - r === mr && ((e = mr), 0 === Ze && s(pe)), - r - ); - } - - function vr() { - var r, e, n, u, o, i, a, c, f, l; - if ( - ((r = _e), - 91 === t.charCodeAt(_e) ? ((e = ge), _e++) : ((e = mr), 0 === Ze && s(Ae)), - e !== mr) - ) { - for (n = [], u = gr(); u !== mr; ) n.push(u), (u = gr()); - if (n !== mr) { - if (((u = _e), (o = dr()) !== mr)) { - for (i = [], a = gr(); a !== mr; ) i.push(a), (a = gr()); - if (i !== mr) { - if ( - ((a = _e), - 44 === t.charCodeAt(_e) - ? ((c = Ce), _e++) - : ((c = mr), 0 === Ze && s(ye)), - c !== mr) - ) { - for (f = [], l = gr(); l !== mr; ) f.push(l), (l = gr()); - f !== mr ? (a = c = [c, f]) : ((_e = a), (a = mr)); - } else (_e = a), (a = mr); - a === mr && (a = null), - a !== mr ? (u = o = [o, i, a]) : ((_e = u), (u = mr)); - } else (_e = u), (u = mr); - } else (_e = u), (u = mr); - u === mr && (u = null), - u !== mr - ? (93 === t.charCodeAt(_e) - ? ((o = be), _e++) - : ((o = mr), 0 === Ze && s(me)), - o !== mr ? ((Me = r), (r = e = xe(u))) : ((_e = r), (r = mr))) - : ((_e = r), (r = mr)); - } else (_e = r), (r = mr); - } else (_e = r), (r = mr); - return r; - } - - function dr() { - var r, e, n, u, o, i, a; - if (((r = _e), (e = T()) !== mr)) { - for (n = _e, u = [], o = gr(); o !== mr; ) u.push(o), (o = gr()); - if (u !== mr) - if ( - (44 === t.charCodeAt(_e) - ? ((o = Ce), _e++) - : ((o = mr), 0 === Ze && s(ye)), - o !== mr) - ) { - for (i = [], a = gr(); a !== mr; ) i.push(a), (a = gr()); - i !== mr && (a = dr()) !== mr - ? (n = u = [u, o, i, a]) - : ((_e = n), (n = mr)); - } else (_e = n), (n = mr); - else (_e = n), (n = mr); - n === mr && (n = null), - n !== mr ? ((Me = r), (r = e = Se(e, n))) : ((_e = r), (r = mr)); - } else (_e = r), (r = mr); - return r; - } - - function gr() { - var r; - return (r = g()) === mr && (r = d()) === mr && (r = A()), r; - } - - function Ar() { - var r, e, n, u, o, i, a, c, f, l, h; - if ( - ((r = _e), - 123 === t.charCodeAt(_e) ? ((e = we), _e++) : ((e = mr), 0 === Ze && s(Fe)), - e !== mr) - ) { - for (n = [], u = g(); u !== mr; ) n.push(u), (u = g()); - if (n !== mr) { - if (((u = _e), (o = C()) !== mr)) { - for (i = [], a = _e, c = [], f = g(); f !== mr; ) - c.push(f), (f = g()); - if (c !== mr) - if ( - (44 === t.charCodeAt(_e) - ? ((f = Ce), _e++) - : ((f = mr), 0 === Ze && s(ye)), - f !== mr) - ) { - for (l = [], h = g(); h !== mr; ) l.push(h), (h = g()); - l !== mr && (h = C()) !== mr - ? (a = c = [c, f, l, h]) - : ((_e = a), (a = mr)); - } else (_e = a), (a = mr); - else (_e = a), (a = mr); - for (; a !== mr; ) { - for (i.push(a), a = _e, c = [], f = g(); f !== mr; ) - c.push(f), (f = g()); - if (c !== mr) - if ( - (44 === t.charCodeAt(_e) - ? ((f = Ce), _e++) - : ((f = mr), 0 === Ze && s(ye)), - f !== mr) - ) { - for (l = [], h = g(); h !== mr; ) l.push(h), (h = g()); - l !== mr && (h = C()) !== mr - ? (a = c = [c, f, l, h]) - : ((_e = a), (a = mr)); - } else (_e = a), (a = mr); - else (_e = a), (a = mr); - } - if (i !== mr) { - for (a = [], c = g(); c !== mr; ) a.push(c), (c = g()); - a !== mr ? (u = o = [o, i, a]) : ((_e = u), (u = mr)); - } else (_e = u), (u = mr); - } else (_e = u), (u = mr); - u === mr && (u = null), - u !== mr - ? (125 === t.charCodeAt(_e) - ? ((o = Ee), _e++) - : ((o = mr), 0 === Ze && s(Te)), - o !== mr ? ((Me = r), (r = e = De(u))) : ((_e = r), (r = mr))) - : ((_e = r), (r = mr)); - } else (_e = r), (r = mr); - } else (_e = r), (r = mr); - return r; - } - - function Cr() { - var r, e, n, u; - return ( - (r = _e), - 91 === t.charCodeAt(_e) ? ((e = ge), _e++) : ((e = mr), 0 === Ze && s(Ae)), - e !== mr && (n = yr()) !== mr - ? (93 === t.charCodeAt(_e) - ? ((u = be), _e++) - : ((u = mr), 0 === Ze && s(me)), - u !== mr ? ((Me = r), (r = e = Oe(n))) : ((_e = r), (r = mr))) - : ((_e = r), (r = mr)), - r - ); - } - - function yr() { - var r, e, n, u, o, i, a, c, f, l; - if ( - ((r = _e), - 91 === t.charCodeAt(_e) ? ((e = ge), _e++) : ((e = mr), 0 === Ze && s(Ae)), - e !== mr) - ) { - for (n = [], u = g(); u !== mr; ) n.push(u), (u = g()); - if (n !== mr) - if ((u = y()) !== mr) { - for (o = [], i = _e, a = [], c = g(); c !== mr; ) - a.push(c), (c = g()); - if (a !== mr) - if ( - (46 === t.charCodeAt(_e) - ? ((c = Yt), _e++) - : ((c = mr), 0 === Ze && s(kt)), - c !== mr) - ) { - for (f = [], l = g(); l !== mr; ) f.push(l), (l = g()); - f !== mr && (l = y()) !== mr - ? (i = a = [a, c, f, l]) - : ((_e = i), (i = mr)); - } else (_e = i), (i = mr); - else (_e = i), (i = mr); - for (; i !== mr; ) { - for (o.push(i), i = _e, a = [], c = g(); c !== mr; ) - a.push(c), (c = g()); - if (a !== mr) - if ( - (46 === t.charCodeAt(_e) - ? ((c = Yt), _e++) - : ((c = mr), 0 === Ze && s(kt)), - c !== mr) - ) { - for (f = [], l = g(); l !== mr; ) f.push(l), (l = g()); - f !== mr && (l = y()) !== mr - ? (i = a = [a, c, f, l]) - : ((_e = i), (i = mr)); - } else (_e = i), (i = mr); - else (_e = i), (i = mr); - } - if (o !== mr) { - for (i = [], a = g(); a !== mr; ) i.push(a), (a = g()); - i !== mr - ? (93 === t.charCodeAt(_e) - ? ((a = be), _e++) - : ((a = mr), 0 === Ze && s(me)), - a !== mr - ? ((Me = r), (r = e = je(u, o))) - : ((_e = r), (r = mr))) - : ((_e = r), (r = mr)); - } else (_e = r), (r = mr); - } else (_e = r), (r = mr); - else (_e = r), (r = mr); - } else (_e = r), (r = mr); - return r; - } - e = void 0 !== e ? e : {}; - var br, - mr = {}, - xr = { - Expressions: p, - }, - Sr = p, - wr = function () { - return Pe; - }, - Fr = function (r) { - Le = Je(Pe, !0, r); - }, - Er = function (r) { - Le = Je(Pe, !1, r); - }, - Tr = function (r) { - Be(Le.table, r[0]), (Le.table[r[0]] = r[1]); - }, - Dr = a('Newline'), - Or = '\n', - jr = o('\n', !1), - _r = '\r\n', - Mr = o('\r\n', !1), - Nr = a('Whitespace'), - Hr = /^[ \t]/, - Ur = i([' ', '\t'], !1, !1), - Zr = a('Comment'), - Ir = '#', - Rr = o('#', !1), - qr = { - type: 'any', - }, - Qr = '=', - Yr = o('=', !1), - kr = function (r, t) { - return [r, t.value]; - }, - zr = function () { - return n(); - }, - Br = a('[a-z], [A-Z], [0-9], "-", "_"'), - Jr = /^[a-zA-Z0-9\-_]/, - Pr = i([['a', 'z'], ['A', 'Z'], ['0', '9'], '-', '_'], !1, !1), - Lr = function (r) { - return r.join(''); - }, - Vr = a('DoubleQuote'), - Wr = '"', - Gr = o('"', !1), - Kr = a('SingleQuote'), - Xr = "'", - $r = o("'", !1), - rt = a('ThreeDoubleQuotes'), - tt = '"""', - et = o('"""', !1), - nt = a('ThreeSingleQuotes'), - ut = "'''", - ot = o("'''", !1), - it = function (r) { - return { - type: 'String', - value: r.join(''), - }; - }, - at = a('NormalCharacter'), - ct = /^[^\0-\x1F"\\]/, - ft = i([['\0', ''], '"', '\\'], !0, !1), - st = 'u', - lt = o('u', !1), - ht = 'U', - pt = o('U', !1), - vt = function () { - var r = n(); - return r.length <= 2 ? ke(r[1]) : ze(parseInt(r.substr(2), 16)); - }, - dt = a('"b", "f", "n", "r", "t"'), - gt = /^[bfnrt]/, - At = i(['b', 'f', 'n', 'r', 't'], !1, !1), - Ct = a('Backslash'), - yt = '\\', - bt = o('\\', !1), - mt = a('FourHexadecimalDigits'), - xt = a('EightHexadecimalDigits'), - St = /^[0-9A-Fa-f]/, - wt = i( - [ - ['0', '9'], - ['A', 'F'], - ['a', 'f'], - ], - !1, - !1, - ), - Ft = function () { - var r = n(); - return { - type: 'String', - value: r.substr(1, r.length - 2), - }; - }, - Et = /^[^\0-\x08\n-\x1F']/, - Tt = i([['\0', '\b'], ['\n', ''], "'"], !0, !1), - Dt = function (r) { - return { - type: 'String', - value: r.join('').replace(/\\\r?\n(?:\r?\n|[ \t])*/g, ''), - }; - }, - Ot = /^[^\0-\x1F\\]/, - jt = i([['\0', ''], '\\'], !0, !1), - _t = a('AnyCharacter'), - Mt = /^[^\0-\x08\n-\x1F]/, - Nt = i( - [ - ['\0', '\b'], - ['\n', ''], - ], - !0, - !1, - ), - Ht = 'true', - Ut = o('true', !1), - Zt = function () { - return { - type: 'Boolean', - value: !0, - }; - }, - It = 'false', - Rt = o('false', !1), - qt = function () { - return { - type: 'Boolean', - value: !1, - }; - }, - Qt = function () { - var r = n(), - t = parseFloat(r.replace(/_/g, '')); - return ( - Re(t) || u(r + 'is not a 64-bit floating-point number.'), - { - type: 'Float', - value: t, - } - ); - }, - Yt = '.', - kt = o('.', !1), - zt = '_', - Bt = o('_', !1), - Jt = 'e', - Pt = o('e', !1), - Lt = 'E', - Vt = o('E', !1), - Wt = function () { - var r = n(), - t = r.replace(/_/g, ''), - e = !1; - if ('-' === t[0]) { - var o = '-9223372036854775808'; - (t.length > o.length || (t.length === o.length && t > o)) && (e = !0); - } else { - '+' === t[0] && (t = t.substr(1)); - var i = '9223372036854775807'; - (t.length > i.length || (t.length === i.length && t > i)) && (e = !0); - } - return ( - e && u(r + ' is not a 64-bit signed integer.'), - (t = parseInt(t, 10)), - Re(t) || u(r + ' is not a 64-bit signed integer.'), - { - type: 'Integer', - value: t, - } - ); - }, - Gt = '+', - Kt = o('+', !1), - Xt = '-', - $t = o('-', !1), - re = /^[1-9]/, - te = i([['1', '9']], !1, !1), - ee = /^[0-9]/, - ne = i([['0', '9']], !1, !1), - ue = 'T', - oe = o('T', !1), - ie = function () { - var r = n(), - t = new Date(r); - return ( - Re(t.getTime()) || - u( - 'Date-time ' + - r + - ' is invalid. It does not conform to RFC 3339 or this is a browser-specific problem.', - ), - { - type: 'DateTime', - value: t, - } - ); - }, - ae = a('FullDate (YYYY-mm-dd)'), - ce = ':', - fe = o(':', !1), - se = a('Hour (HH)'), - le = a('Minute (MM)'), - he = a('Second (SS)'), - pe = a('TimeOffset (Z or +/-HH:MM)'), - ve = 'Z', - de = o('Z', !1), - ge = '[', - Ae = o('[', !1), - Ce = ',', - ye = o(',', !1), - be = ']', - me = o(']', !1), - xe = function (r) { - for ( - var t = { - type: 'Array', - value: r ? r[0] : [], - }, - e = 0, - n = t.value, - u = n.length; - e < u; - e++ - ) - n[e] = n[e].value; - return t; - }, - Se = function (r, t) { - var e = [r]; - if (t) - for (var n = r.type, o = 0, i = t[3], a = i.length; o < a; o++) - n !== i[o].type && - u(Ye(i[o].value) + ' should be of type "' + n + '".'), - e.push(i[o]); - return e; - }, - we = '{', - Fe = o('{', !1), - Ee = '}', - Te = o('}', !1), - De = function (r) { - var t = {}; - if (r) { - t[r[0][0]] = r[0][1]; - for (var e = 0, n = r[1], u = n.length; e < u; e++) { - var o = n[e][3]; - Be(t, o[0]), (t[o[0]] = o[1]); - } - } - return { - type: 'InlineTable', - value: t, - }; - }, - Oe = function (r) { - return r; - }, - je = function (r, t) { - for (var e = [r], n = 0, u = t.length; n < u; n++) e.push(t[n][3]); - return e; - }, - _e = 0, - Me = 0, - Ne = [ - { - line: 1, - column: 1, - }, - ], - He = 0, - Ue = [], - Ze = 0; - if ('startRule' in e) { - if (!(e.startRule in xr)) - throw new Error('Can\'t start parsing from rule "' + e.startRule + '".'); - Sr = xr[e.startRule]; - } - var Ie, Re, qe, Qe, Ye, ke, ze, Be, Je; - (Ie = function (r) { - return 'Value for ' + r + ' should not be redefined in the same table.'; - }), - (Re = - Number.isFinite || - function (r) { - return 'number' == typeof r && isFinite(r); - }), - (qe = - Array.isArray || - function (r) { - return '[object Array]' === Object.prototype.toString.call(r); - }), - (Qe = function (r, t) { - return Object.prototype.hasOwnProperty.call(r, t); - }), - (Ye = - 'object' == typeof JSON && JSON - ? JSON.stringify - : function (r) { - return ( - '"' + - String(r).replace(/[\x00-\x1F"\\]/g, function (r) { - switch (r) { - case '"': - case '\\': - return '\\' + r; - case '\t': - return '\\t'; - case '\n': - return '\\n'; - case '\r': - return '\\r'; - case '\b': - return '\\b'; - case '\f': - return '\\f'; - default: - var t = r.charCodeAt(0).toString(16); - return '\\u' + '0000'.substr(t.length) + t; - } - }) + - '"' - ); - }), - (ke = function (r) { - switch (r) { - case '"': - case '\\': - return r; - case 't': - return '\t'; - case 'n': - return '\n'; - case 'r': - return '\r'; - case 'b': - return '\b'; - case 'f': - return '\f'; - default: - u(Ye(r) + ' cannot be escaped.'); - } - }), - (ze = function (r) { - if ( - ((!Re(r) || r < 0 || r > 1114111) && - u('U+' + r.toString(16) + ' is not a valid Unicode code point.'), - String.fromCodePoint) - ) - return String.fromCodePoint(r); - var t = ''; - return ( - r > 65535 && - ((r -= 65536), - (t += String.fromCharCode(((r >>> 10) & 1023) | 55296)), - (r = 56320 | (1023 & r))), - (t += String.fromCharCode(r)) - ); - }), - (Be = function (r, t) { - Qe(r, t) && u(Ie(Ye(t))); - }), - (Je = function (r, t, e) { - for (var n = '', o = 0, i = e.length; o < i; o++) { - var a = e[o]; - if (((n += (n ? '.' : '') + Ye(a)), Qe(r, a))) - t - ? qe(r[a]) - ? (Ge[n] || u(Ie(n)), - o + 1 === i - ? ((c = {}), r[a].push(c), (r = c)) - : ((n += '.' + Ye(r[a].length - 1)), - (r = r[a][r[a].length - 1]))) - : (Ve[n] || u(Ie(n)), (r = r[a])) - : qe(r[a]) - ? ((Ge[n] && o + 1 !== i) || u(Ie(n)), - (n += '.' + Ye(r[a].length - 1)), - (r = r[a][r[a].length - 1])) - : (Ve[n] || u(Ie(n)), (r = r[a])); - else if (t && o + 1 === i) { - var c = {}; - (r[a] = [c]), (r = c), (Ge[n] = !0); - } else (r = r[a] = {}), (Ve[n] = !0); - } - return ( - t ? Ge[n] || u(Ie(n)) : ((We[n] || Ge[n]) && u(Ie(n)), (We[n] = !0)), - { - table: r, - path: e, - } - ); - }); - var Pe = {}, - Le = { - table: Pe, - path: [], - }, - Ve = {}, - We = {}, - Ge = {}; - if ((br = Sr()) !== mr && _e === t.length) return br; - throw ( - (br !== mr && - _e < t.length && - s({ - type: 'end', - }), - h( - Ue, - He < t.length ? t.charAt(He) : null, - He < t.length ? f(He, He + 1) : f(He, He), - )) - ); - }, - } - ); - })(); - }, - {}, - ], - 2: [ - function (r, t, e) { - 'use strict'; - - function n(r, t, e, n) { - (this.message = r), (this.offset = t), (this.line = e), (this.column = n); - } - !(function (r, t) { - function e() { - this.constructor = r; - } - (e.prototype = t.prototype), (r.prototype = new e()); - })(n, SyntaxError); - var u = r('./lib/parser'), - o = { - parse: function (r) { - try { - return u.parse(r); - } catch (r) { - throw r instanceof u.SyntaxError - ? ((r.line = r.location.start.line), - (r.column = r.location.start.column), - (r.offset = r.location.start.offset), - new n( - r.message, - r.location.start.offset, - r.location.start.line, - r.location.start.column, - )) - : r; - } - }, - SyntaxError: n, - }; - t.exports = o; - }, - { - './lib/parser': 1, - }, - ], - }, - {}, - [2], - )(2); -}); From 19bfa96d91947c1013985d0de5bc362b34f922b9 Mon Sep 17 00:00:00 2001 From: Robert Hood Chatham Date: Wed, 8 Mar 2023 13:11:50 +0100 Subject: [PATCH 04/23] Remove pyscript import --- pyscriptjs/src/main.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/pyscriptjs/src/main.ts b/pyscriptjs/src/main.ts index 5ff8f8ff28f..b36fe0d3876 100644 --- a/pyscriptjs/src/main.ts +++ b/pyscriptjs/src/main.ts @@ -16,9 +16,6 @@ import { PyTerminalPlugin } from './plugins/pyterminal'; import { SplashscreenPlugin } from './plugins/splashscreen'; import { ImportmapPlugin } from './plugins/importmap'; import { StdioDirector as StdioDirector } from './plugins/stdiodirector'; -// eslint-disable-next-line -// @ts-ignore -import pyscript from './python/pyscript/__init__.py'; import { robustFetch } from './fetch'; declare const pyscript_package: { dirs: string[]; files: [string, string] }; From 04ae065f48d0a586ab759a549802062721634be0 Mon Sep 17 00:00:00 2001 From: Robert Hood Chatham Date: Wed, 8 Mar 2023 13:11:18 +0100 Subject: [PATCH 05/23] Fix many ESlint errors For mysterious reasons, these errors appear on my branch #1262 even though they are not related to changes there. The eslint config seems a bit unstable. Anyways this fixes them. --- pyscriptjs/src/interpreter_client.ts | 1 + pyscriptjs/src/logger.ts | 2 +- pyscriptjs/src/main.ts | 6 ++- pyscriptjs/src/pyconfig.ts | 37 +++++++++------- pyscriptjs/src/remote_interpreter.ts | 65 ++++++++++++++++++++-------- 5 files changed, 75 insertions(+), 36 deletions(-) diff --git a/pyscriptjs/src/interpreter_client.ts b/pyscriptjs/src/interpreter_client.ts index 6ade60ff7ce..d25bd41c991 100644 --- a/pyscriptjs/src/interpreter_client.ts +++ b/pyscriptjs/src/interpreter_client.ts @@ -40,6 +40,7 @@ export class InterpreterClient extends Object { * the remote interpreter. * Python exceptions are turned into JS exceptions. * */ + // eslint-disable-next-line @typescript-eslint/no-explicit-any async run(code: string): Promise<{ result: any }> { return await this._remote.run(code); } diff --git a/pyscriptjs/src/logger.ts b/pyscriptjs/src/logger.ts index 84fcdc6d285..e806c6b5100 100644 --- a/pyscriptjs/src/logger.ts +++ b/pyscriptjs/src/logger.ts @@ -27,7 +27,7 @@ interface Logger { debug(message: string, ...args: unknown[]): void; info(message: string, ...args: unknown[]): void; warn(message: string, ...args: unknown[]): void; - error(message: string, ...args: unknown[]): void; + error(message: string | Error, ...args: unknown[]): void; } const _cache = new Map(); diff --git a/pyscriptjs/src/main.ts b/pyscriptjs/src/main.ts index 760f94043af..9032698f62a 100644 --- a/pyscriptjs/src/main.ts +++ b/pyscriptjs/src/main.ts @@ -16,6 +16,7 @@ import { PyTerminalPlugin } from './plugins/pyterminal'; import { SplashscreenPlugin } from './plugins/splashscreen'; import { ImportmapPlugin } from './plugins/importmap'; import { StdioDirector as StdioDirector } from './plugins/stdiodirector'; +import type { PyProxy } from 'pyodide'; // eslint-disable-next-line // @ts-ignore import pyscript from './python/pyscript/__init__.py'; @@ -218,6 +219,7 @@ export class PyScriptApp { const pyscript_module = interpreter._remote.interface.pyimport('pyscript'); pyscript_module.define_custom_element = define_custom_element; pyscript_module.showWarning = showWarning; + // eslint-disable-next-line @typescript-eslint/no-unsafe-call pyscript_module._set_version_info(version); pyscript_module.destroy(); @@ -303,7 +305,7 @@ export class PyScriptApp { const blobFile = new File([pluginBlob], 'plugin.js', { type: 'text/javascript' }); const fileUrl = URL.createObjectURL(blobFile); - const module = await import(fileUrl); + const module = (await import(fileUrl)) as { default: { new (): Plugin } }; // Note: We have to put module.default in a variable // because we have seen weird behaviour when doing // new module.default() directly. @@ -346,7 +348,7 @@ export class PyScriptApp { // interpreter API level and allow each one to implement it in its own way const module = interpreter._remote.interface.pyimport(modulename); if (typeof module.plugin !== 'undefined') { - const py_plugin = module.plugin; + const py_plugin = module.plugin as PyProxy & { init(app: PyScriptApp): void }; py_plugin.init(this); this.plugins.addPythonPlugin(py_plugin); } else { diff --git a/pyscriptjs/src/pyconfig.ts b/pyscriptjs/src/pyconfig.ts index 9ebfb5ce38e..98dcbe0055b 100644 --- a/pyscriptjs/src/pyconfig.ts +++ b/pyscriptjs/src/pyconfig.ts @@ -6,7 +6,7 @@ import { UserError, ErrorCode } from './exceptions'; const logger = getLogger('py-config'); -export interface AppConfig extends Record { +export interface AppConfig { name?: string; description?: string; version?: string; @@ -42,11 +42,11 @@ export type PyScriptMetadata = { time?: string; }; -const allKeys = { +const allKeys = Object.entries({ string: ['name', 'description', 'version', 'type', 'author_name', 'author_email', 'license'], number: ['schema_version'], array: ['runtimes', 'interpreters', 'packages', 'fetch', 'plugins'], -}; +}); export const defaultConfig: AppConfig = { schema_version: 1, @@ -106,6 +106,7 @@ function fillUserData(inputConfig: AppConfig, resultConfig: AppConfig): AppConfi for (const key in inputConfig) { // fill in all extra keys ignored by the validator if (!(key in defaultConfig)) { + // eslint-disable-next-line resultConfig[key] = inputConfig[key]; } } @@ -122,13 +123,14 @@ function mergeConfig(inlineConfig: AppConfig, externalConfig: AppConfig): AppCon } else { let merged: AppConfig = {}; - for (const keyType in allKeys) { - const keys: string[] = allKeys[keyType]; + for (const [keyType, keys] of allKeys) { keys.forEach(function (item: string) { if (keyType === 'boolean') { + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment merged[item] = typeof inlineConfig[item] !== 'undefined' ? inlineConfig[item] : externalConfig[item]; } else { + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment merged[item] = inlineConfig[item] || externalConfig[item]; } }); @@ -143,7 +145,7 @@ function mergeConfig(inlineConfig: AppConfig, externalConfig: AppConfig): AppCon } } -function parseConfig(configText: string, configType = 'toml') { +function parseConfig(configText: string, configType = 'toml'): AppConfig { if (configType === 'toml') { try { // TOML parser is soft and can parse even JSON strings, this additional check prevents it. @@ -153,8 +155,9 @@ function parseConfig(configText: string, configType = 'toml') { `The config supplied: ${configText} is an invalid TOML and cannot be parsed`, ); } - return toml.parse(configText); - } catch (err) { + return toml.parse(configText) as AppConfig; + } catch (e) { + const err = e as Error; const errMessage: string = err.toString(); throw new UserError( ErrorCode.BAD_CONFIG, @@ -163,8 +166,9 @@ function parseConfig(configText: string, configType = 'toml') { } } else if (configType === 'json') { try { - return JSON.parse(configText); - } catch (err) { + return JSON.parse(configText) as AppConfig; + } catch (e) { + const err = e as Error; const errMessage: string = err.toString(); throw new UserError( ErrorCode.BAD_CONFIG, @@ -184,17 +188,17 @@ function validateConfig(configText: string, configType = 'toml') { const finalConfig: AppConfig = {}; - for (const keyType in allKeys) { - const keys: string[] = allKeys[keyType]; + for (const [keyType, keys] of allKeys) { keys.forEach(function (item: string) { if (validateParamInConfig(item, keyType, config)) { if (item === 'interpreters') { finalConfig[item] = []; - const interpreters = config[item] as InterpreterConfig[]; + const interpreters = config[item]; interpreters.forEach(function (eachInterpreter: InterpreterConfig) { const interpreterConfig: InterpreterConfig = {}; for (const eachInterpreterParam in eachInterpreter) { if (validateParamInConfig(eachInterpreterParam, 'string', eachInterpreter)) { + // eslint-disable-next-line interpreterConfig[eachInterpreterParam] = eachInterpreter[eachInterpreterParam]; } } @@ -213,11 +217,12 @@ function validateConfig(configText: string, configType = 'toml') { '', ); finalConfig['interpreters'] = []; - const interpreters = config[item] as InterpreterConfig[]; + const interpreters = config[item]; interpreters.forEach(function (eachInterpreter: InterpreterConfig) { const interpreterConfig: InterpreterConfig = {}; for (const eachInterpreterParam in eachInterpreter) { if (validateParamInConfig(eachInterpreterParam, 'string', eachInterpreter)) { + // eslint-disable-next-line interpreterConfig[eachInterpreterParam] = eachInterpreter[eachInterpreterParam]; } } @@ -225,18 +230,20 @@ function validateConfig(configText: string, configType = 'toml') { }); } else if (item === 'fetch') { finalConfig[item] = []; - const fetchList = config[item] as FetchConfig[]; + const fetchList = config[item]; fetchList.forEach(function (eachFetch: FetchConfig) { const eachFetchConfig: FetchConfig = {}; for (const eachFetchConfigParam in eachFetch) { const targetType = eachFetchConfigParam === 'files' ? 'array' : 'string'; if (validateParamInConfig(eachFetchConfigParam, targetType, eachFetch)) { + // eslint-disable-next-line eachFetchConfig[eachFetchConfigParam] = eachFetch[eachFetchConfigParam]; } } finalConfig[item].push(eachFetchConfig); }); } else { + // eslint-disable-next-line finalConfig[item] = config[item]; } } diff --git a/pyscriptjs/src/remote_interpreter.ts b/pyscriptjs/src/remote_interpreter.ts index 229757b0a95..aee9c79dfd3 100644 --- a/pyscriptjs/src/remote_interpreter.ts +++ b/pyscriptjs/src/remote_interpreter.ts @@ -11,10 +11,23 @@ const logger = getLogger('pyscript/pyodide'); export type InterpreterInterface = PyodideInterface | null; interface Micropip extends PyProxy { - install: (packageName: string | string[]) => Promise; - destroy: () => void; + install(packageName: string | string[]): Promise; } +type FSInterface = { + writeFile(path: string, data: Uint8Array | string, options?: { canOwn: boolean }): void; + mkdirTree(path: string): void; + mkdir(path: string): void; +}; + +type PATHFSInterface = { + resolve(path: string): string; +}; + +type PATHInterface = { + dirname(path: string): string; +}; + /* RemoteInterpreter class is responsible to process requests from the `InterpreterClient` class -- these can be requests for installation of @@ -33,6 +46,10 @@ such as MicroPython. export class RemoteInterpreter extends Object { src: string; interface: InterpreterInterface; + FS: FSInterface; + PATH: PATHInterface; + PATH_FS: PATHFSInterface; + globals: PyProxy; // TODO: Remove this once `runtimes` is removed! interpreter: InterpreterInterface; @@ -74,6 +91,12 @@ export class RemoteInterpreter extends Object { }, fullStdLib: false, }); + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + this.FS = this.interface.FS; + // eslint-disable-next-line + this.PATH = (this.interface as any)._module.PATH; + // eslint-disable-next-line + this.PATH_FS = (this.interface as any)._module.PATH_FS; // TODO: Remove this once `runtimes` is removed! this.interpreter = this.interface; @@ -131,14 +154,14 @@ export class RemoteInterpreter extends Object { // but one of our tests tries to use a locally downloaded older version of pyodide // for which the signature of `loadPackage` accepts the above params as args i.e. // the call uses `logger.info.bind(logger), logger.info.bind(logger)`. - const pyodide_version = (await this.run("import sys; sys.modules['pyodide'].__version__")).result.toString(); - if (pyodide_version.startsWith('0.22')) { + const messageCallback = logger.info.bind(logger) as typeof logger.info; + if (this.interpreter.version.startsWith('0.22')) { await this.interface.loadPackage(names, { - messageCallback: logger.info.bind(logger), - errorCallback: logger.info.bind(logger), + messageCallback, + errorCallback: messageCallback, }); } else { - await this.interface.loadPackage(names, logger.info.bind(logger), logger.info.bind(logger)); + await this.interface.loadPackage(names, messageCallback, messageCallback); } } @@ -157,8 +180,15 @@ export class RemoteInterpreter extends Object { try { await micropip.install(package_name); micropip.destroy(); - } catch (e) { - let exceptionMessage = `Unable to install package(s) '` + package_name + `'.`; + } catch (err) { + const e = err as Error; + let fmt_names: string; + if (Array.isArray(package_name)) { + fmt_names = package_name.join(', '); + } else { + fmt_names = package_name; + } + let exceptionMessage = `Unable to install package(s) '${fmt_names}'.`; // If we can't fetch `package_name` micropip.install throws a huge // Python traceback in `e.message` this logic is to handle the @@ -166,9 +196,8 @@ export class RemoteInterpreter extends Object { // huge traceback. if (e.message.includes("Can't find a pure Python 3 wheel")) { exceptionMessage += - ` Reason: Can't find a pure Python 3 Wheel for package(s) '` + - package_name + - `'. See: https://pyodide.org/en/stable/usage/faq.html#micropip-can-t-find-a-pure-python-wheel ` + + ` Reason: Can't find a pure Python 3 Wheel for package(s) '${fmt_names}'.` + + `See: https://pyodide.org/en/stable/usage/faq.html#micropip-can-t-find-a-pure-python-wheel ` + `for more information.`; } else if (e.message.includes("Can't fetch metadata")) { exceptionMessage += @@ -176,7 +205,7 @@ export class RemoteInterpreter extends Object { 'Please make sure you have entered a correct package name.'; } else { exceptionMessage += - ` Reason: ${e.message as string}. Please open an issue at ` + + ` Reason: ${e.message}. Please open an issue at ` + `https://github.com/pyscript/pyscript/issues/new if you require help or ` + `you think it's a bug.`; } @@ -214,18 +243,18 @@ export class RemoteInterpreter extends Object { async loadFromFile(path: string, fetch_path: string): Promise { // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore - path = this.interface._module.PATH_FS.resolve(path); + path = this.PATH_FS.resolve(path); // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore - const dir = this.interface._module.PATH.dirname(path); - this.interface.FS.mkdirTree(dir); + const dir: string = this.PATH.dirname(path); + this.FS.mkdirTree(dir); // `robustFetch` checks for failures in getting a response const response = await robustFetch(fetch_path); const buffer = await response.arrayBuffer(); const data = new Uint8Array(buffer); - this.interface.FS.writeFile(path, data, { canOwn: true }); + this.FS.writeFile(path, data, { canOwn: true }); } /** @@ -233,7 +262,7 @@ export class RemoteInterpreter extends Object { * caches to the underlying interface */ invalidate_module_path_cache(): void { - const importlib = this.interface.pyimport('importlib'); + const importlib = this.interface.pyimport('importlib') as PyProxy & { invalidate_caches(): void }; importlib.invalidate_caches(); } } From 6ae4d7f63d73943f871545b8f7858da78e5e1aa6 Mon Sep 17 00:00:00 2001 From: Robert Hood Chatham Date: Wed, 8 Mar 2023 16:47:55 +0100 Subject: [PATCH 06/23] Put back Record --- pyscriptjs/src/pyconfig.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyscriptjs/src/pyconfig.ts b/pyscriptjs/src/pyconfig.ts index 98dcbe0055b..4339f3db2bf 100644 --- a/pyscriptjs/src/pyconfig.ts +++ b/pyscriptjs/src/pyconfig.ts @@ -6,7 +6,7 @@ import { UserError, ErrorCode } from './exceptions'; const logger = getLogger('py-config'); -export interface AppConfig { +export interface AppConfig extends Record { name?: string; description?: string; version?: string; From ea45633af7d4e08e77a6c39f460afc7edb9ba1c6 Mon Sep 17 00:00:00 2001 From: Robert Hood Chatham Date: Wed, 8 Mar 2023 18:34:10 +0100 Subject: [PATCH 07/23] Fix typescript compilation --- pyscriptjs/src/main.ts | 2 +- pyscriptjs/src/remote_interpreter.ts | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/pyscriptjs/src/main.ts b/pyscriptjs/src/main.ts index 631ae95d63b..bc2ed835814 100644 --- a/pyscriptjs/src/main.ts +++ b/pyscriptjs/src/main.ts @@ -4,7 +4,7 @@ import { loadConfigFromElement } from './pyconfig'; import type { AppConfig } from './pyconfig'; import { InterpreterClient } from './interpreter_client'; import { version } from './version'; -import { PluginManager, define_custom_element } from './plugin'; +import { PluginManager, define_custom_element, Plugin } from './plugin'; import { make_PyScript, initHandlers, mountElements } from './components/pyscript'; import { getLogger } from './logger'; import { showWarning, globalExport, createLock } from './utils'; diff --git a/pyscriptjs/src/remote_interpreter.ts b/pyscriptjs/src/remote_interpreter.ts index aee9c79dfd3..e802e84b300 100644 --- a/pyscriptjs/src/remote_interpreter.ts +++ b/pyscriptjs/src/remote_interpreter.ts @@ -161,6 +161,7 @@ export class RemoteInterpreter extends Object { errorCallback: messageCallback, }); } else { + // @ts-ignore await this.interface.loadPackage(names, messageCallback, messageCallback); } } From 144efacc858e7a8b754e0de0dff319eb0c90dfd0 Mon Sep 17 00:00:00 2001 From: Robert Hood Chatham Date: Wed, 8 Mar 2023 18:34:10 +0100 Subject: [PATCH 08/23] Fix typescript compilation --- pyscriptjs/src/main.ts | 2 +- pyscriptjs/src/remote_interpreter.ts | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/pyscriptjs/src/main.ts b/pyscriptjs/src/main.ts index 9032698f62a..aa0a5f66a2e 100644 --- a/pyscriptjs/src/main.ts +++ b/pyscriptjs/src/main.ts @@ -4,7 +4,7 @@ import { loadConfigFromElement } from './pyconfig'; import type { AppConfig } from './pyconfig'; import { InterpreterClient } from './interpreter_client'; import { version } from './version'; -import { PluginManager, define_custom_element } from './plugin'; +import { PluginManager, define_custom_element, Plugin } from './plugin'; import { make_PyScript, initHandlers, mountElements } from './components/pyscript'; import { getLogger } from './logger'; import { showWarning, globalExport, createLock } from './utils'; diff --git a/pyscriptjs/src/remote_interpreter.ts b/pyscriptjs/src/remote_interpreter.ts index aee9c79dfd3..e802e84b300 100644 --- a/pyscriptjs/src/remote_interpreter.ts +++ b/pyscriptjs/src/remote_interpreter.ts @@ -161,6 +161,7 @@ export class RemoteInterpreter extends Object { errorCallback: messageCallback, }); } else { + // @ts-ignore await this.interface.loadPackage(names, messageCallback, messageCallback); } } From ad00491420cbb0f8567eb57c7c64ef4a711b02b6 Mon Sep 17 00:00:00 2001 From: Robert Hood Chatham Date: Wed, 8 Mar 2023 20:58:45 +0100 Subject: [PATCH 09/23] Fix lints --- pyscriptjs/.eslintrc.js | 22 ++++++++-------- pyscriptjs/src/components/pyrepl.ts | 9 ++++--- pyscriptjs/src/components/pyscript.ts | 18 ++++++++----- pyscriptjs/src/components/pywidget.ts | 13 +++++---- pyscriptjs/src/interpreter_client.ts | 6 ++--- pyscriptjs/src/logger.ts | 4 +-- pyscriptjs/src/main.ts | 6 ++--- pyscriptjs/src/plugin.ts | 35 +++++++++++++++++++------ pyscriptjs/src/plugins/importmap.ts | 3 ++- pyscriptjs/src/plugins/pyterminal.ts | 6 ++--- pyscriptjs/src/plugins/splashscreen.ts | 12 +++++---- pyscriptjs/src/plugins/stdiodirector.ts | 2 +- pyscriptjs/src/pyconfig.ts | 1 + pyscriptjs/src/pyexec.ts | 33 +++++++++++++++-------- pyscriptjs/src/remote_interpreter.ts | 6 +---- pyscriptjs/src/utils.ts | 2 +- 16 files changed, 106 insertions(+), 72 deletions(-) diff --git a/pyscriptjs/.eslintrc.js b/pyscriptjs/.eslintrc.js index 959539412a1..4eb95de97cf 100644 --- a/pyscriptjs/.eslintrc.js +++ b/pyscriptjs/.eslintrc.js @@ -18,16 +18,16 @@ module.exports = { plugins: ['@typescript-eslint'], ignorePatterns: ['node_modules'], rules: { - 'no-prototype-builtins': 'warn', - '@typescript-eslint/no-unused-vars': 'warn', - '@typescript-eslint/no-explicit-any': 'warn', - '@typescript-eslint/no-unsafe-assignment': 'warn', - '@typescript-eslint/no-unsafe-argument': 'warn', - '@typescript-eslint/no-unsafe-member-access': 'warn', - '@typescript-eslint/no-unsafe-call': 'warn', - '@typescript-eslint/no-unsafe-return': 'warn', - '@typescript-eslint/no-floating-promises': 'warn', - '@typescript-eslint/restrict-plus-operands': 'warn', - '@typescript-eslint/no-empty-function': 'warn', + 'no-prototype-builtins': 'error', + '@typescript-eslint/no-unused-vars': ['error', { args: 'none' }], + '@typescript-eslint/no-explicit-any': 'error', + '@typescript-eslint/no-unsafe-assignment': 'error', + '@typescript-eslint/no-unsafe-argument': 'error', + '@typescript-eslint/no-unsafe-member-access': 'error', + '@typescript-eslint/no-unsafe-call': 'error', + '@typescript-eslint/no-unsafe-return': 'error', + '@typescript-eslint/no-floating-promises': 'error', + '@typescript-eslint/restrict-plus-operands': 'error', + '@typescript-eslint/no-empty-function': 'error', }, }; diff --git a/pyscriptjs/src/components/pyrepl.ts b/pyscriptjs/src/components/pyrepl.ts index 5d5366483c7..48840ed1510 100644 --- a/pyscriptjs/src/components/pyrepl.ts +++ b/pyscriptjs/src/components/pyrepl.ts @@ -2,7 +2,7 @@ import { basicSetup, EditorView } from 'codemirror'; import { python } from '@codemirror/lang-python'; import { indentUnit } from '@codemirror/language'; import { Compartment } from '@codemirror/state'; -import { keymap } from '@codemirror/view'; +import { keymap, Command } from '@codemirror/view'; import { defaultKeymap } from '@codemirror/commands'; import { oneDarkTheme } from '@codemirror/theme-one-dark'; @@ -68,8 +68,8 @@ export function make_PyRepl(interpreter: InterpreterClient) { languageConf.of(python()), keymap.of([ ...defaultKeymap, - { key: 'Ctrl-Enter', run: this.execute.bind(this), preventDefault: true }, - { key: 'Shift-Enter', run: this.execute.bind(this), preventDefault: true }, + { key: 'Ctrl-Enter', run: this.execute.bind(this) as Command, preventDefault: true }, + { key: 'Shift-Enter', run: this.execute.bind(this) as Command, preventDefault: true }, ]), ]; @@ -134,7 +134,7 @@ export function make_PyRepl(interpreter: InterpreterClient) { runButton.id = 'runButton'; runButton.className = 'absolute py-repl-run-button'; runButton.innerHTML = RUNBUTTON; - runButton.addEventListener('click', this.execute.bind(this)); + runButton.addEventListener('click', this.execute.bind(this) as (e: MouseEvent) => void); return runButton; } @@ -166,6 +166,7 @@ export function make_PyRepl(interpreter: InterpreterClient) { outEl.innerHTML = ''; // execute the python code + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment const pyResult = (await pyExec(interpreter, pySrc, outEl)).result; // display the value of the last evaluated expression (REPL-style) diff --git a/pyscriptjs/src/components/pyscript.ts b/pyscriptjs/src/components/pyscript.ts index 3b982775095..1310bd5a1d5 100644 --- a/pyscriptjs/src/components/pyscript.ts +++ b/pyscriptjs/src/components/pyscript.ts @@ -23,7 +23,7 @@ export function make_PyScript(interpreter: InterpreterClient, app: PyScriptApp) * * Concurrent access to the multiple py-script tags is thus avoided. */ - let releaseLock: any; + let releaseLock: () => void; try { releaseLock = await app.tagExecutionLock(); ensureUniqueId(this); @@ -35,6 +35,7 @@ export function make_PyScript(interpreter: InterpreterClient, app: PyScriptApp) this.innerHTML = ''; app.plugins.beforePyScriptExec({ interpreter: interpreter, src: pySrc, pyScriptTag: this }); + /* eslint-disable @typescript-eslint/no-unsafe-assignment */ const result = (await pyExec(interpreter, pySrc, this)).result; app.plugins.afterPyScriptExec({ interpreter: interpreter, @@ -42,6 +43,7 @@ export function make_PyScript(interpreter: InterpreterClient, app: PyScriptApp) pyScriptTag: this, result: result, }); + /* eslint-enable @typescript-eslint/no-unsafe-assignment */ } finally { releaseLock(); } @@ -53,7 +55,8 @@ export function make_PyScript(interpreter: InterpreterClient, app: PyScriptApp) try { const response = await robustFetch(url); return await response.text(); - } catch (e) { + } catch (err) { + const e = err as Error; _createAlertBanner(e.message); this.innerHTML = ''; throw e; @@ -163,15 +166,15 @@ const pyAttributeToEvent: Map = new Map([ ]); /** Initialize all elements with py-* handlers attributes */ -export function initHandlers(interpreter: InterpreterClient) { +export async function initHandlers(interpreter: InterpreterClient) { logger.debug('Initializing py-* event handlers...'); for (const pyAttribute of pyAttributeToEvent.keys()) { - createElementsWithEventListeners(interpreter, pyAttribute); + await createElementsWithEventListeners(interpreter, pyAttribute); } } /** Initializes an element with the given py-on* attribute and its handler */ -function createElementsWithEventListeners(interpreter: InterpreterClient, pyAttribute: string) { +async function createElementsWithEventListeners(interpreter: InterpreterClient, pyAttribute: string) { const matches: NodeListOf = document.querySelectorAll(`[${pyAttribute}]`); for (const el of matches) { // If the element doesn't have an id, let's add one automatically! @@ -195,7 +198,7 @@ function createElementsWithEventListeners(interpreter: InterpreterClient, pyAttr // the source code may contain a syntax error, which will cause // the splashscreen to not be removed. try { - interpreter.run(source); + await interpreter.run(source); } catch (e) { logger.error((e as Error).message); } @@ -204,7 +207,8 @@ function createElementsWithEventListeners(interpreter: InterpreterClient, pyAttr void (async () => { try { await interpreter.run(handlerCode); - } catch (err) { + } catch (e) { + const err = e as Error; displayPyException(err, el.parentElement); } })(); diff --git a/pyscriptjs/src/components/pywidget.ts b/pyscriptjs/src/components/pywidget.ts index 986b82c7810..da0a86ff8d0 100644 --- a/pyscriptjs/src/components/pywidget.ts +++ b/pyscriptjs/src/components/pywidget.ts @@ -1,4 +1,4 @@ -import type { PyProxy } from 'pyodide'; +import type { PyProxy, PyProxyCallable } from 'pyodide'; import { getLogger } from '../logger'; import { robustFetch } from '../fetch'; import { InterpreterClient } from '../interpreter_client'; @@ -13,8 +13,8 @@ function createWidget(interpreter: InterpreterClient, name: string, code: string name: string = name; klass: string = klass; code: string = code; - proxy: PyProxy; - proxyClass: any; + proxy: PyProxy & { connect(): void }; + proxyClass: PyProxyCallable; constructor() { super(); @@ -28,8 +28,8 @@ function createWidget(interpreter: InterpreterClient, name: string, code: string async connectedCallback() { await interpreter.runButDontRaise(this.code); - this.proxyClass = interpreter.globals.get(this.klass); - this.proxy = this.proxyClass(this); + this.proxyClass = interpreter.globals.get(this.klass) as PyProxyCallable; + this.proxy = this.proxyClass(this) as PyProxy & { connect(): void }; this.proxy.connect(); this.registerWidget(); } @@ -39,9 +39,8 @@ function createWidget(interpreter: InterpreterClient, name: string, code: string interpreter.globals.set(this.id, this.proxy); } } - /* eslint-disable @typescript-eslint/no-unused-vars */ + // eslint-disable-next-line @typescript-eslint/no-unused-vars const xPyWidget = customElements.define(name, CustomWidget); - /* eslint-enable @typescript-eslint/no-unused-vars */ } export function make_PyWidget(interpreter: InterpreterClient) { diff --git a/pyscriptjs/src/interpreter_client.ts b/pyscriptjs/src/interpreter_client.ts index d25bd41c991..b6701dde3ab 100644 --- a/pyscriptjs/src/interpreter_client.ts +++ b/pyscriptjs/src/interpreter_client.ts @@ -1,6 +1,6 @@ import type { AppConfig } from './pyconfig'; import { RemoteInterpreter } from './remote_interpreter'; -import type { PyProxy } from 'pyodide'; +import type { PyProxyDict } from 'pyodide'; import { getLogger } from './logger'; import type { Stdio } from './stdio'; @@ -16,7 +16,7 @@ export class InterpreterClient extends Object { /** * global symbols table for the underlying interface. * */ - globals: PyProxy; + globals: PyProxyDict; stdio: Stdio; constructor(config: AppConfig, stdio: Stdio) { @@ -32,7 +32,7 @@ export class InterpreterClient extends Object { * */ async initializeRemote(): Promise { await this._remote.loadInterpreter(this.config, this.stdio); - this.globals = this._remote.globals; + this.globals = this._remote.globals as PyProxyDict; } /** diff --git a/pyscriptjs/src/logger.ts b/pyscriptjs/src/logger.ts index e806c6b5100..a31ecef8d2b 100644 --- a/pyscriptjs/src/logger.ts +++ b/pyscriptjs/src/logger.ts @@ -44,8 +44,8 @@ function getLogger(prefix: string): Logger { function _makeLogger(prefix: string): Logger { prefix = `[${prefix}] `; - function make(level: string) { - const out_fn = console[level].bind(console); + function make(level: 'info' | 'debug' | 'warn' | 'error') { + const out_fn = console[level].bind(console) as typeof console.log; function fn(fmt: string, ...args: unknown[]) { out_fn(prefix + fmt, ...args); } diff --git a/pyscriptjs/src/main.ts b/pyscriptjs/src/main.ts index aa0a5f66a2e..cd442cb9b63 100644 --- a/pyscriptjs/src/main.ts +++ b/pyscriptjs/src/main.ts @@ -191,7 +191,7 @@ export class PyScriptApp { // lifecycle (8) createCustomElements(interpreter); - initHandlers(interpreter); + await initHandlers(interpreter); // NOTE: interpreter message is used by integration tests to know that // pyscript initialization has complete. If you change it, you need to @@ -209,8 +209,8 @@ export class PyScriptApp { logger.info('importing pyscript'); // Save and load pyscript.py from FS - interpreter._remote.interface.FS.mkdirTree('/home/pyodide/pyscript'); - interpreter._remote.interface.FS.writeFile('pyscript/__init__.py', pyscript); + interpreter._remote.FS.mkdirTree('/home/pyodide/pyscript'); + interpreter._remote.FS.writeFile('pyscript/__init__.py', pyscript as string); //Refresh the module cache so Python consistently finds pyscript module interpreter._remote.invalidate_module_path_cache(); diff --git a/pyscriptjs/src/plugin.ts b/pyscriptjs/src/plugin.ts index d68ecc3fde5..e8dc737fc4f 100644 --- a/pyscriptjs/src/plugin.ts +++ b/pyscriptjs/src/plugin.ts @@ -1,3 +1,8 @@ +/* eslint-disable @typescript-eslint/no-unsafe-member-access, + @typescript-eslint/no-unsafe-call, + @typescript-eslint/no-explicit-any, + @typescript-eslint/no-unsafe-assignment */ + import type { AppConfig } from './pyconfig'; import type { UserError } from './exceptions'; import { getLogger } from './logger'; @@ -20,7 +25,9 @@ export class Plugin { * This hook should **NOT** contain expensive operations, else it delays * the download of the python interpreter which is initiated later. */ - configure(config: AppConfig) {} + configure(_config: AppConfig) { + /* empty */ + } /** The preliminary initialization phase is complete and we are about to * download and launch the Python interpreter. @@ -32,14 +39,18 @@ export class Plugin { * This hook should **NOT** contain expensive operations, else it delays * the download of the python interpreter which is initiated later. */ - beforeLaunch(config: AppConfig) {} + beforeLaunch(_config: AppConfig) { + /* empty */ + } /** The Python interpreter has been launched, the virtualenv has been * installed and we are ready to execute user code. * * The tags will be executed after this hook. */ - afterSetup(interpreter: InterpreterClient) {} + afterSetup(_interpreter: InterpreterClient) { + /* empty */ + } /** The source of a > tag has been fetched, and we're about * to evaluate that source using the provided interpreter. @@ -48,7 +59,9 @@ export class Plugin { * @param options.src {string} The Python source code to be evaluated * @param options.pyScriptTag The HTML tag that originated the evaluation */ - beforePyScriptExec(options: { interpreter: InterpreterClient; src: string; pyScriptTag: PyScriptTag }) {} + beforePyScriptExec(_options: { interpreter: InterpreterClient; src: string; pyScriptTag: PyScriptTag }) { + /* empty */ + } /** The Python in a has just been evaluated, but control * has not been ceded back to the JavaScript event loop yet @@ -58,22 +71,28 @@ export class Plugin { * @param options.pyScriptTag The HTML tag that originated the evaluation * @param options.result The returned result of evaluating the Python (if any) */ - afterPyScriptExec(options: { + afterPyScriptExec(_options: { interpreter: InterpreterClient; src: string; pyScriptTag: PyScriptTag; result: any; - }) {} + }) { + /* empty */ + } /** Startup complete. The interpreter is initialized and ready, user * scripts have been executed: the main initialization logic ends here and * the page is ready to accept user interactions. */ - afterStartup(interpreter: InterpreterClient) {} + afterStartup(_interpreter: InterpreterClient) { + /* empty */ + } /** Called when an UserError is raised */ - onUserError(error: UserError) {} + onUserError(_error: UserError) { + /* empty */ + } } export class PluginManager { diff --git a/pyscriptjs/src/plugins/importmap.ts b/pyscriptjs/src/plugins/importmap.ts index 438672fc0f1..03c013c8824 100644 --- a/pyscriptjs/src/plugins/importmap.ts +++ b/pyscriptjs/src/plugins/importmap.ts @@ -25,7 +25,8 @@ export class ImportmapPlugin extends Plugin { const importmap: ImportMapType = (() => { try { return JSON.parse(node.textContent) as ImportMapType; - } catch (error) { + } catch (e) { + const error = e as Error; showWarning('Failed to parse import map: ' + error.message); } })(); diff --git a/pyscriptjs/src/plugins/pyterminal.ts b/pyscriptjs/src/plugins/pyterminal.ts index 45bbc7a5c75..33f9b6857c6 100644 --- a/pyscriptjs/src/plugins/pyterminal.ts +++ b/pyscriptjs/src/plugins/pyterminal.ts @@ -16,7 +16,7 @@ export class PyTerminalPlugin extends Plugin { this.app = app; } - configure(config: AppConfig) { + configure(config: AppConfig & { terminal?: boolean | 'auto' }) { // validate the terminal config and handle default values const t = config.terminal; if (t !== undefined && t !== true && t !== false && t !== 'auto') { @@ -32,7 +32,7 @@ export class PyTerminalPlugin extends Plugin { } } - beforeLaunch(config: AppConfig) { + beforeLaunch(config: AppConfig & { terminal?: boolean | 'auto' }) { // if config.terminal is "yes" or "auto", let's add a to // the document, unless it's already present. const t = config.terminal; @@ -46,7 +46,7 @@ export class PyTerminalPlugin extends Plugin { } } - afterSetup(interpreter: InterpreterClient) { + afterSetup(_interpreter: InterpreterClient) { // the Python interpreter has been initialized and we are ready to // execute user code: // diff --git a/pyscriptjs/src/plugins/splashscreen.ts b/pyscriptjs/src/plugins/splashscreen.ts index 9ad7c9e4d82..e55852c4803 100644 --- a/pyscriptjs/src/plugins/splashscreen.ts +++ b/pyscriptjs/src/plugins/splashscreen.ts @@ -22,7 +22,9 @@ export class SplashscreenPlugin extends Plugin { autoclose: boolean; enabled: boolean; - configure(config: AppConfig) { + configure( + config: AppConfig & { splashscreen?: { autoclose?: boolean; enabled?: boolean }; autoclose_loader?: boolean }, + ) { // the officially supported setting is config.splashscreen.autoclose, // but we still also support the old config.autoclose_loader (with a // deprecation warning) @@ -40,7 +42,7 @@ export class SplashscreenPlugin extends Plugin { } } - beforeLaunch(config: AppConfig) { + beforeLaunch(_config: AppConfig) { if (!this.enabled) { return; } @@ -50,18 +52,18 @@ export class SplashscreenPlugin extends Plugin { this.elem = document.createElement('py-splashscreen'); document.body.append(this.elem); document.addEventListener('py-status-message', (e: CustomEvent) => { - const msg = e.detail; + const msg = e.detail as string; this.elem.log(msg); }); } - afterStartup(interpreter: InterpreterClient) { + afterStartup(_interpreter: InterpreterClient) { if (this.autoclose && this.enabled) { this.elem.close(); } } - onUserError(error: UserError) { + onUserError(_error: UserError) { if (this.elem !== undefined && this.enabled) { // Remove the splashscreen so users can see the banner better this.elem.close(); diff --git a/pyscriptjs/src/plugins/stdiodirector.ts b/pyscriptjs/src/plugins/stdiodirector.ts index fcdea95dc22..2cb379ac419 100644 --- a/pyscriptjs/src/plugins/stdiodirector.ts +++ b/pyscriptjs/src/plugins/stdiodirector.ts @@ -47,7 +47,7 @@ export class StdioDirector extends Plugin { interpreter: InterpreterClient; src: string; pyScriptTag: PyScriptTag; - result: any; + result: any; // eslint-disable-line @typescript-eslint/no-explicit-any }): void { if (options.pyScriptTag.stdout_manager != null) { this._stdioMultiplexer.removeListener(options.pyScriptTag.stdout_manager); diff --git a/pyscriptjs/src/pyconfig.ts b/pyscriptjs/src/pyconfig.ts index e2f1e34e721..b24cdf714e3 100644 --- a/pyscriptjs/src/pyconfig.ts +++ b/pyscriptjs/src/pyconfig.ts @@ -6,6 +6,7 @@ import { UserError, ErrorCode } from './exceptions'; const logger = getLogger('py-config'); +// eslint-disable-next-line @typescript-eslint/no-explicit-any export interface AppConfig extends Record { name?: string; description?: string; diff --git a/pyscriptjs/src/pyexec.ts b/pyscriptjs/src/pyexec.ts index 7cb5fa755a8..e01036b746e 100644 --- a/pyscriptjs/src/pyexec.ts +++ b/pyscriptjs/src/pyexec.ts @@ -2,12 +2,20 @@ import { getLogger } from './logger'; import { ensureUniqueId } from './utils'; import { UserError, ErrorCode } from './exceptions'; import { InterpreterClient } from './interpreter_client'; +import type { PyProxy, PyProxyCallable } from 'pyodide'; const logger = getLogger('pyexec'); -export async function pyExec(interpreter: InterpreterClient, pysrc: string, outElem: HTMLElement) { - //This is pyscript.py - const pyscript_py = interpreter._remote.interface.pyimport('pyscript'); +export async function pyExec( + interpreter: InterpreterClient, + pysrc: string, + outElem: HTMLElement, + // eslint-disable-next-line @typescript-eslint/no-explicit-any +): Promise<{ result: any }> { + const pyscript_py = interpreter._remote.interface.pyimport('pyscript') as PyProxy & { + set_current_display_target(id: string): void; + uses_top_level_await(code: string): boolean; + }; ensureUniqueId(outElem); pyscript_py.set_current_display_target(outElem.id); try { @@ -23,7 +31,8 @@ export async function pyExec(interpreter: InterpreterClient, pysrc: string, outE ); } return await interpreter.run(pysrc); - } catch (err) { + } catch (e) { + const err = e as Error; // XXX: currently we display exceptions in the same position as // the output. But we probably need a better way to do that, // e.g. allowing plugins to intercept exceptions and display them @@ -44,15 +53,17 @@ export async function pyExec(interpreter: InterpreterClient, pysrc: string, outE * pyDisplay(interpreter, obj); * pyDisplay(interpreter, obj, { target: targetID }); */ -export function pyDisplay(interpreter: InterpreterClient, obj: any, kwargs: object) { - const display = interpreter.globals.get('display'); - if (kwargs === undefined) display(obj); - else { +// eslint-disable-next-line @typescript-eslint/no-explicit-any +export function pyDisplay(interpreter: InterpreterClient, obj: any, kwargs: { [k: string]: any } = {}) { + const display = interpreter.globals.get('display') as PyProxyCallable; + try { display.callKwargs(obj, kwargs); + } finally { + display.destroy(); } } -export function displayPyException(err: any, errElem: HTMLElement) { +export function displayPyException(err: Error, errElem: HTMLElement) { //addClasses(errElem, ['py-error']) const pre = document.createElement('pre'); pre.className = 'py-error'; @@ -65,8 +76,8 @@ export function displayPyException(err: any, errElem: HTMLElement) { } else { // this is very likely a normal JS exception. The best we can do is to // display it as is. - logger.error('Non-python exception:\n' + err); - pre.innerText = err; + logger.error('Non-python exception:\n' + err.toString()); + pre.innerText = err.toString(); } errElem.appendChild(pre); } diff --git a/pyscriptjs/src/remote_interpreter.ts b/pyscriptjs/src/remote_interpreter.ts index e802e84b300..3e0fcbab10e 100644 --- a/pyscriptjs/src/remote_interpreter.ts +++ b/pyscriptjs/src/remote_interpreter.ts @@ -161,7 +161,7 @@ export class RemoteInterpreter extends Object { errorCallback: messageCallback, }); } else { - // @ts-ignore + // @ts-expect-error Types don't include this deprecated call signature await this.interface.loadPackage(names, messageCallback, messageCallback); } } @@ -242,11 +242,7 @@ export class RemoteInterpreter extends Object { * and `/a/b.py` will be placed into `/a/b.py`. */ async loadFromFile(path: string, fetch_path: string): Promise { - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore path = this.PATH_FS.resolve(path); - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore const dir: string = this.PATH.dirname(path); this.FS.mkdirTree(dir); diff --git a/pyscriptjs/src/utils.ts b/pyscriptjs/src/utils.ts index 337398a82a8..ac89d1603e1 100644 --- a/pyscriptjs/src/utils.ts +++ b/pyscriptjs/src/utils.ts @@ -117,7 +117,7 @@ export function createSingularWarning(msg: string, sentinelText: string | null = * @returns A new asynchronous lock * @private */ -export function createLock() { +export function createLock(): () => Promise<() => void> { // This is a promise that is resolved when the lock is open, not resolved when lock is held. let _lock = Promise.resolve(); From 2e158d485a59ea89dffca32fedc3346870f94543 Mon Sep 17 00:00:00 2001 From: Robert Hood Chatham Date: Wed, 8 Mar 2023 21:34:02 +0100 Subject: [PATCH 10/23] Try @iarna/toml instead --- pyscriptjs/package-lock.json | 26 +++++++++++++------------- pyscriptjs/package.json | 2 +- pyscriptjs/src/pyconfig.ts | 16 +++++++++------- 3 files changed, 23 insertions(+), 21 deletions(-) diff --git a/pyscriptjs/package-lock.json b/pyscriptjs/package-lock.json index 46c4fe00775..a6e0c4b5979 100644 --- a/pyscriptjs/package-lock.json +++ b/pyscriptjs/package-lock.json @@ -17,6 +17,7 @@ "codemirror": "6.0.1" }, "devDependencies": { + "@iarna/toml": "^2.2.5", "@jest/globals": "29.1.2", "@rollup/plugin-commonjs": "22.0.2", "@rollup/plugin-legacy": "2.2.0", @@ -40,7 +41,6 @@ "rollup-plugin-serve": "2.0.1", "rollup-plugin-string": "3.0.0", "rollup-plugin-terser": "7.0.2", - "toml": "^3.0.0", "ts-jest": "29.0.3", "tslib": "2.4.0", "typescript": "4.8.4" @@ -741,6 +741,12 @@ "dev": true, "license": "BSD-3-Clause" }, + "node_modules/@iarna/toml": { + "version": "2.2.5", + "resolved": "https://registry.npmjs.org/@iarna/toml/-/toml-2.2.5.tgz", + "integrity": "sha512-trnsAYxU3xnS1gPHPyU961coFyLkh4gAD/0zQ5mymY4yOZ+CYvsPqUbOFSw0aDM4y0tV7tiFxL/1XfXPNC6IPg==", + "dev": true + }, "node_modules/@istanbuljs/load-nyc-config": { "version": "1.1.0", "dev": true, @@ -5309,12 +5315,6 @@ "node": ">=8.0" } }, - "node_modules/toml": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/toml/-/toml-3.0.0.tgz", - "integrity": "sha512-y/mWCZinnvxjTKYhJ+pYxwD0mRLVvOtdS2Awbgxln6iEnt4rk0yBxeSBHkGJcPucRiG0e55mwWp+g/05rsrd6w==", - "dev": true - }, "node_modules/tough-cookie": { "version": "4.1.2", "dev": true, @@ -6184,6 +6184,12 @@ "version": "1.2.1", "dev": true }, + "@iarna/toml": { + "version": "2.2.5", + "resolved": "https://registry.npmjs.org/@iarna/toml/-/toml-2.2.5.tgz", + "integrity": "sha512-trnsAYxU3xnS1gPHPyU961coFyLkh4gAD/0zQ5mymY4yOZ+CYvsPqUbOFSw0aDM4y0tV7tiFxL/1XfXPNC6IPg==", + "dev": true + }, "@istanbuljs/load-nyc-config": { "version": "1.1.0", "dev": true, @@ -9149,12 +9155,6 @@ "is-number": "^7.0.0" } }, - "toml": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/toml/-/toml-3.0.0.tgz", - "integrity": "sha512-y/mWCZinnvxjTKYhJ+pYxwD0mRLVvOtdS2Awbgxln6iEnt4rk0yBxeSBHkGJcPucRiG0e55mwWp+g/05rsrd6w==", - "dev": true - }, "tough-cookie": { "version": "4.1.2", "dev": true, diff --git a/pyscriptjs/package.json b/pyscriptjs/package.json index e35ab8f59ec..fa1465ca6ca 100644 --- a/pyscriptjs/package.json +++ b/pyscriptjs/package.json @@ -15,6 +15,7 @@ "test:watch": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --watch" }, "devDependencies": { + "@iarna/toml": "^2.2.5", "@jest/globals": "29.1.2", "@rollup/plugin-commonjs": "22.0.2", "@rollup/plugin-legacy": "2.2.0", @@ -38,7 +39,6 @@ "rollup-plugin-serve": "2.0.1", "rollup-plugin-string": "3.0.0", "rollup-plugin-terser": "7.0.2", - "toml": "^3.0.0", "ts-jest": "29.0.3", "tslib": "2.4.0", "typescript": "4.8.4" diff --git a/pyscriptjs/src/pyconfig.ts b/pyscriptjs/src/pyconfig.ts index 148d679bbd3..285f20796f8 100644 --- a/pyscriptjs/src/pyconfig.ts +++ b/pyscriptjs/src/pyconfig.ts @@ -145,17 +145,19 @@ function mergeConfig(inlineConfig: AppConfig, externalConfig: AppConfig): AppCon function parseConfig(configText: string, configType = 'toml') { if (configType === 'toml') { + // TOML parser is soft and can parse even JSON strings, this additional check prevents it. + if (configText.trim()[0] === '{') { + throw new UserError( + ErrorCode.BAD_CONFIG, + `The config supplied: ${configText} is an invalid TOML and cannot be parsed`, + ); + } try { - // TOML parser is soft and can parse even JSON strings, this additional check prevents it. - if (configText.trim()[0] === '{') { - throw new UserError( - ErrorCode.BAD_CONFIG, - `The config supplied: ${configText} is an invalid TOML and cannot be parsed`, - ); - } return toml.parse(configText); } catch (err) { const errMessage: string = err.toString(); + + throw new UserError( ErrorCode.BAD_CONFIG, `The config supplied: ${configText} is an invalid TOML and cannot be parsed: ${errMessage}`, From ed61b1effc57a40ed6eb7b2ffda1d4d43d56ad31 Mon Sep 17 00:00:00 2001 From: Robert Hood Chatham Date: Wed, 8 Mar 2023 21:45:53 +0100 Subject: [PATCH 11/23] Fix import --- pyscriptjs/src/pyconfig.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pyscriptjs/src/pyconfig.ts b/pyscriptjs/src/pyconfig.ts index 285f20796f8..35bdadab010 100644 --- a/pyscriptjs/src/pyconfig.ts +++ b/pyscriptjs/src/pyconfig.ts @@ -1,4 +1,4 @@ -import * as toml from 'toml'; +import * as toml from '@iarna/toml'; import { getLogger } from './logger'; import { version } from './version'; import { getAttribute, readTextFromPath, htmlDecode, createDeprecationWarning } from './utils'; @@ -156,7 +156,6 @@ function parseConfig(configText: string, configType = 'toml') { return toml.parse(configText); } catch (err) { const errMessage: string = err.toString(); - throw new UserError( ErrorCode.BAD_CONFIG, From 81b4c35e302461ebdf8ae1073c8a8cc02b5ab680 Mon Sep 17 00:00:00 2001 From: Robert Hood Chatham Date: Wed, 8 Mar 2023 22:26:05 +0100 Subject: [PATCH 12/23] Use @ltd/j-toml --- pyscriptjs/package-lock.json | 24 +++++++++++------------- pyscriptjs/package.json | 2 +- pyscriptjs/rollup.config.js | 2 -- pyscriptjs/src/pyconfig.ts | 2 +- 4 files changed, 13 insertions(+), 17 deletions(-) diff --git a/pyscriptjs/package-lock.json b/pyscriptjs/package-lock.json index a6e0c4b5979..78a2e1549a6 100644 --- a/pyscriptjs/package-lock.json +++ b/pyscriptjs/package-lock.json @@ -14,10 +14,10 @@ "@codemirror/state": "6.1.2", "@codemirror/theme-one-dark": "6.1.0", "@codemirror/view": "6.3.0", + "@ltd/j-toml": "^1.38.0", "codemirror": "6.0.1" }, "devDependencies": { - "@iarna/toml": "^2.2.5", "@jest/globals": "29.1.2", "@rollup/plugin-commonjs": "22.0.2", "@rollup/plugin-legacy": "2.2.0", @@ -741,12 +741,6 @@ "dev": true, "license": "BSD-3-Clause" }, - "node_modules/@iarna/toml": { - "version": "2.2.5", - "resolved": "https://registry.npmjs.org/@iarna/toml/-/toml-2.2.5.tgz", - "integrity": "sha512-trnsAYxU3xnS1gPHPyU961coFyLkh4gAD/0zQ5mymY4yOZ+CYvsPqUbOFSw0aDM4y0tV7tiFxL/1XfXPNC6IPg==", - "dev": true - }, "node_modules/@istanbuljs/load-nyc-config": { "version": "1.1.0", "dev": true, @@ -1201,6 +1195,11 @@ "@lezer/lr": "^1.0.0" } }, + "node_modules/@ltd/j-toml": { + "version": "1.38.0", + "resolved": "https://registry.npmjs.org/@ltd/j-toml/-/j-toml-1.38.0.tgz", + "integrity": "sha512-lYtBcmvHustHQtg4X7TXUu1Xa/tbLC3p2wLvgQI+fWVySguVZJF60Snxijw5EiohumxZbR10kWYFFebh1zotiw==" + }, "node_modules/@nodelib/fs.scandir": { "version": "2.1.5", "dev": true, @@ -6184,12 +6183,6 @@ "version": "1.2.1", "dev": true }, - "@iarna/toml": { - "version": "2.2.5", - "resolved": "https://registry.npmjs.org/@iarna/toml/-/toml-2.2.5.tgz", - "integrity": "sha512-trnsAYxU3xnS1gPHPyU961coFyLkh4gAD/0zQ5mymY4yOZ+CYvsPqUbOFSw0aDM4y0tV7tiFxL/1XfXPNC6IPg==", - "dev": true - }, "@istanbuljs/load-nyc-config": { "version": "1.1.0", "dev": true, @@ -6517,6 +6510,11 @@ "@lezer/lr": "^1.0.0" } }, + "@ltd/j-toml": { + "version": "1.38.0", + "resolved": "https://registry.npmjs.org/@ltd/j-toml/-/j-toml-1.38.0.tgz", + "integrity": "sha512-lYtBcmvHustHQtg4X7TXUu1Xa/tbLC3p2wLvgQI+fWVySguVZJF60Snxijw5EiohumxZbR10kWYFFebh1zotiw==" + }, "@nodelib/fs.scandir": { "version": "2.1.5", "dev": true, diff --git a/pyscriptjs/package.json b/pyscriptjs/package.json index fa1465ca6ca..53549620657 100644 --- a/pyscriptjs/package.json +++ b/pyscriptjs/package.json @@ -15,7 +15,6 @@ "test:watch": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --watch" }, "devDependencies": { - "@iarna/toml": "^2.2.5", "@jest/globals": "29.1.2", "@rollup/plugin-commonjs": "22.0.2", "@rollup/plugin-legacy": "2.2.0", @@ -50,6 +49,7 @@ "@codemirror/state": "6.1.2", "@codemirror/theme-one-dark": "6.1.0", "@codemirror/view": "6.3.0", + "@ltd/j-toml": "^1.38.0", "codemirror": "6.0.1" } } diff --git a/pyscriptjs/rollup.config.js b/pyscriptjs/rollup.config.js index bc6a5c65c5e..08cbdbf6f2c 100644 --- a/pyscriptjs/rollup.config.js +++ b/pyscriptjs/rollup.config.js @@ -1,7 +1,6 @@ import commonjs from '@rollup/plugin-commonjs'; import resolve from '@rollup/plugin-node-resolve'; import { terser } from 'rollup-plugin-terser'; -import legacy from '@rollup/plugin-legacy'; import typescript from '@rollup/plugin-typescript'; import css from 'rollup-plugin-css-only'; import serve from 'rollup-plugin-serve'; @@ -46,7 +45,6 @@ export default { string({ include: './src/**/*.py', }), - legacy({ 'src/toml.js': 'toml' }), resolve({ browser: true, }), diff --git a/pyscriptjs/src/pyconfig.ts b/pyscriptjs/src/pyconfig.ts index 35bdadab010..12e008deb35 100644 --- a/pyscriptjs/src/pyconfig.ts +++ b/pyscriptjs/src/pyconfig.ts @@ -1,4 +1,4 @@ -import * as toml from '@iarna/toml'; +import * as toml from '@ltd/j-toml'; import { getLogger } from './logger'; import { version } from './version'; import { getAttribute, readTextFromPath, htmlDecode, createDeprecationWarning } from './utils'; From 81878c8c3fcf11e31bef7c33d02681b39852e98c Mon Sep 17 00:00:00 2001 From: Robert Hood Chatham Date: Wed, 8 Mar 2023 22:31:02 +0100 Subject: [PATCH 13/23] Update test --- pyscriptjs/tests/integration/test_py_config.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pyscriptjs/tests/integration/test_py_config.py b/pyscriptjs/tests/integration/test_py_config.py index a9bfb648450..8a4c6417109 100644 --- a/pyscriptjs/tests/integration/test_py_config.py +++ b/pyscriptjs/tests/integration/test_py_config.py @@ -173,11 +173,10 @@ def test_invalid_toml_config(self): wait_for_pyscript=False, ) banner = self.page.wait_for_selector(".py-error") - assert "SyntaxError: Expected DoubleQuote" in self.console.error.text + assert "SyntaxError: Empty bare key" in self.console.error.text expected = ( "(PY1000): The config supplied: [[ is an invalid TOML and cannot be parsed: " - "SyntaxError: Expected DoubleQuote, Whitespace, or [a-z], [A-Z], " - '[0-9], "-", "_" but "\\n" found.' + "SyntaxError: Empty bare key at line 1: [[" ) assert banner.inner_text() == expected From dcdfc937c89f2d50959a9a299166c8bb2377bd7b Mon Sep 17 00:00:00 2001 From: Robert Hood Chatham Date: Wed, 8 Mar 2023 22:37:51 +0100 Subject: [PATCH 14/23] Use toml-j0.4 --- pyscriptjs/package-lock.json | 24 +++++++++---------- pyscriptjs/package.json | 4 ++-- pyscriptjs/src/pyconfig.ts | 2 +- .../tests/integration/test_py_config.py | 5 ++-- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/pyscriptjs/package-lock.json b/pyscriptjs/package-lock.json index 78a2e1549a6..c68393f6f33 100644 --- a/pyscriptjs/package-lock.json +++ b/pyscriptjs/package-lock.json @@ -14,8 +14,8 @@ "@codemirror/state": "6.1.2", "@codemirror/theme-one-dark": "6.1.0", "@codemirror/view": "6.3.0", - "@ltd/j-toml": "^1.38.0", - "codemirror": "6.0.1" + "codemirror": "6.0.1", + "toml-j0.4": "^1.1.1" }, "devDependencies": { "@jest/globals": "29.1.2", @@ -1195,11 +1195,6 @@ "@lezer/lr": "^1.0.0" } }, - "node_modules/@ltd/j-toml": { - "version": "1.38.0", - "resolved": "https://registry.npmjs.org/@ltd/j-toml/-/j-toml-1.38.0.tgz", - "integrity": "sha512-lYtBcmvHustHQtg4X7TXUu1Xa/tbLC3p2wLvgQI+fWVySguVZJF60Snxijw5EiohumxZbR10kWYFFebh1zotiw==" - }, "node_modules/@nodelib/fs.scandir": { "version": "2.1.5", "dev": true, @@ -5314,6 +5309,11 @@ "node": ">=8.0" } }, + "node_modules/toml-j0.4": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/toml-j0.4/-/toml-j0.4-1.1.1.tgz", + "integrity": "sha512-lYK5otg0+cto8YmsWcPEfeiTiC/VU6P6HA6ooaYI9K/KYT24Jg0BrYtRZK1K3cwakSMyh6nttfJL9RmQH0gyCg==" + }, "node_modules/tough-cookie": { "version": "4.1.2", "dev": true, @@ -6510,11 +6510,6 @@ "@lezer/lr": "^1.0.0" } }, - "@ltd/j-toml": { - "version": "1.38.0", - "resolved": "https://registry.npmjs.org/@ltd/j-toml/-/j-toml-1.38.0.tgz", - "integrity": "sha512-lYtBcmvHustHQtg4X7TXUu1Xa/tbLC3p2wLvgQI+fWVySguVZJF60Snxijw5EiohumxZbR10kWYFFebh1zotiw==" - }, "@nodelib/fs.scandir": { "version": "2.1.5", "dev": true, @@ -9153,6 +9148,11 @@ "is-number": "^7.0.0" } }, + "toml-j0.4": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/toml-j0.4/-/toml-j0.4-1.1.1.tgz", + "integrity": "sha512-lYK5otg0+cto8YmsWcPEfeiTiC/VU6P6HA6ooaYI9K/KYT24Jg0BrYtRZK1K3cwakSMyh6nttfJL9RmQH0gyCg==" + }, "tough-cookie": { "version": "4.1.2", "dev": true, diff --git a/pyscriptjs/package.json b/pyscriptjs/package.json index 53549620657..7273cf85d4b 100644 --- a/pyscriptjs/package.json +++ b/pyscriptjs/package.json @@ -49,7 +49,7 @@ "@codemirror/state": "6.1.2", "@codemirror/theme-one-dark": "6.1.0", "@codemirror/view": "6.3.0", - "@ltd/j-toml": "^1.38.0", - "codemirror": "6.0.1" + "codemirror": "6.0.1", + "toml-j0.4": "^1.1.1" } } diff --git a/pyscriptjs/src/pyconfig.ts b/pyscriptjs/src/pyconfig.ts index 12e008deb35..b5977c0e4fc 100644 --- a/pyscriptjs/src/pyconfig.ts +++ b/pyscriptjs/src/pyconfig.ts @@ -1,4 +1,4 @@ -import * as toml from '@ltd/j-toml'; +import * as toml from 'toml-j0.4'; import { getLogger } from './logger'; import { version } from './version'; import { getAttribute, readTextFromPath, htmlDecode, createDeprecationWarning } from './utils'; diff --git a/pyscriptjs/tests/integration/test_py_config.py b/pyscriptjs/tests/integration/test_py_config.py index 8a4c6417109..a9bfb648450 100644 --- a/pyscriptjs/tests/integration/test_py_config.py +++ b/pyscriptjs/tests/integration/test_py_config.py @@ -173,10 +173,11 @@ def test_invalid_toml_config(self): wait_for_pyscript=False, ) banner = self.page.wait_for_selector(".py-error") - assert "SyntaxError: Empty bare key" in self.console.error.text + assert "SyntaxError: Expected DoubleQuote" in self.console.error.text expected = ( "(PY1000): The config supplied: [[ is an invalid TOML and cannot be parsed: " - "SyntaxError: Empty bare key at line 1: [[" + "SyntaxError: Expected DoubleQuote, Whitespace, or [a-z], [A-Z], " + '[0-9], "-", "_" but "\\n" found.' ) assert banner.inner_text() == expected From 3c6fe2daee2378004196d5e074a2943e1b0c99c0 Mon Sep 17 00:00:00 2001 From: Robert Hood Chatham Date: Wed, 8 Mar 2023 22:47:44 +0100 Subject: [PATCH 15/23] Some changes --- .pre-commit-config.yaml | 1 + pyscriptjs/src/pyconfig.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2ffc4200d85..85847e2500e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -49,6 +49,7 @@ repos: - id: eslint files: pyscriptjs/src/.*\.[jt]sx?$ # *.js, *.jsx, *.ts and *.tsx types: [file] + args: [-c, pyscriptjs/.eslintrc.js] additional_dependencies: - eslint@8.25.0 - typescript@4.8.4 diff --git a/pyscriptjs/src/pyconfig.ts b/pyscriptjs/src/pyconfig.ts index 21b1cacea9d..330bb506bd6 100644 --- a/pyscriptjs/src/pyconfig.ts +++ b/pyscriptjs/src/pyconfig.ts @@ -156,6 +156,7 @@ function parseConfig(configText: string, configType = 'toml'): AppConfig { ); } try { + // eslint-disable-next-line return toml.parse(configText) as AppConfig; } catch (e) { const err = e as Error; From 54ab4b3d690180670ac33fc2022e5b557d0df6db Mon Sep 17 00:00:00 2001 From: Robert Hood Chatham Date: Thu, 9 Mar 2023 09:07:16 +0100 Subject: [PATCH 16/23] Fix toml import --- pyscriptjs/src/pyconfig.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyscriptjs/src/pyconfig.ts b/pyscriptjs/src/pyconfig.ts index b5977c0e4fc..c217a3dd283 100644 --- a/pyscriptjs/src/pyconfig.ts +++ b/pyscriptjs/src/pyconfig.ts @@ -1,4 +1,4 @@ -import * as toml from 'toml-j0.4'; +import toml from 'toml-j0.4'; import { getLogger } from './logger'; import { version } from './version'; import { getAttribute, readTextFromPath, htmlDecode, createDeprecationWarning } from './utils'; From 40324abb74563e93812a90552607c4c970eda0ff Mon Sep 17 00:00:00 2001 From: Robert Hood Chatham Date: Thu, 9 Mar 2023 09:20:48 +0100 Subject: [PATCH 17/23] Try adding eslint gha job --- .github/workflows/build-unstable.yml | 29 ++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/.github/workflows/build-unstable.yml b/.github/workflows/build-unstable.yml index c3b25ab9588..911ba05be05 100644 --- a/.github/workflows/build-unstable.yml +++ b/.github/workflows/build-unstable.yml @@ -81,6 +81,35 @@ jobs: name: test_results path: pyscriptjs/test_results if-no-files-found: error + eslint: + runs-on: ubuntu-latest + defaults: + run: + working-directory: pyscriptjs + steps: + - name: Install node + uses: actions/setup-node@v3 + with: + node-version: 18.x + + - name: Cache node modules + uses: actions/cache@v3 + env: + cache-name: cache-node-modules + with: + # npm cache files are stored in `~/.npm` on Linux/macOS + path: ~/.npm + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-build-${{ env.cache-name }}- + ${{ runner.os }}-build- + ${{ runner.os }}- + + - name: npm install + run: npm install + + - name: Eslint + run: npx eslint src -c .eslintrc.js Deploy: runs-on: ubuntu-latest From d68c6e78a559c98b33894973a5d8fcc5fe024194 Mon Sep 17 00:00:00 2001 From: Robert Hood Chatham Date: Thu, 9 Mar 2023 09:24:15 +0100 Subject: [PATCH 18/23] Add forgotten checkout action --- .github/workflows/build-unstable.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/build-unstable.yml b/.github/workflows/build-unstable.yml index 911ba05be05..1bb9d012061 100644 --- a/.github/workflows/build-unstable.yml +++ b/.github/workflows/build-unstable.yml @@ -87,6 +87,10 @@ jobs: run: working-directory: pyscriptjs steps: + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Install node uses: actions/setup-node@v3 with: From bcb9d927c50dbf02fc606997816dc3411a367cef Mon Sep 17 00:00:00 2001 From: Robert Hood Chatham Date: Thu, 9 Mar 2023 09:25:55 +0100 Subject: [PATCH 19/23] Force CI to run --- pyscriptjs/src/pyconfig.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/pyscriptjs/src/pyconfig.ts b/pyscriptjs/src/pyconfig.ts index 7f9e897904c..937d2b5e24a 100644 --- a/pyscriptjs/src/pyconfig.ts +++ b/pyscriptjs/src/pyconfig.ts @@ -159,6 +159,7 @@ function parseConfig(configText: string, configType = 'toml'): AppConfig { // eslint-disable-next-line return toml.parse(configText) as AppConfig; } catch (e) { + console.log("changed this file"); const err = e as Error; const errMessage: string = err.toString(); From 336782aa6f4026154c1bb49b2391e57a3df44d07 Mon Sep 17 00:00:00 2001 From: Robert Hood Chatham Date: Thu, 9 Mar 2023 09:31:23 +0100 Subject: [PATCH 20/23] Blah --- .github/workflows/build-unstable.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-unstable.yml b/.github/workflows/build-unstable.yml index 1bb9d012061..ac8757f9af7 100644 --- a/.github/workflows/build-unstable.yml +++ b/.github/workflows/build-unstable.yml @@ -7,7 +7,7 @@ on: paths: - pyscriptjs/** - examples/** - - .github/workflows/build-latest.yml # Test that workflow works when changed + - .github/workflows/build-unstable.yml # Test that workflow works when changed pull_request: # Run on any PR that modifies files under pyscriptjs/ and examples/ branches: From 054ada0aae53e0c8e1f86b487b6103b6cd9aab83 Mon Sep 17 00:00:00 2001 From: Robert Hood Chatham Date: Thu, 9 Mar 2023 09:32:07 +0100 Subject: [PATCH 21/23] Fix --- .github/workflows/build-unstable.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/build-unstable.yml b/.github/workflows/build-unstable.yml index ac8757f9af7..a21536cc18a 100644 --- a/.github/workflows/build-unstable.yml +++ b/.github/workflows/build-unstable.yml @@ -86,7 +86,6 @@ jobs: defaults: run: working-directory: pyscriptjs - steps: steps: - name: Checkout uses: actions/checkout@v3 From 859f127d4a396f9f9ef14578accc5186748495f0 Mon Sep 17 00:00:00 2001 From: Robert Hood Chatham Date: Thu, 9 Mar 2023 10:03:10 +0100 Subject: [PATCH 22/23] Revert changes to github workflow --- .github/workflows/build-unstable.yml | 34 +--------------------------- .pre-commit-config.yaml | 1 - 2 files changed, 1 insertion(+), 34 deletions(-) diff --git a/.github/workflows/build-unstable.yml b/.github/workflows/build-unstable.yml index a21536cc18a..c3b25ab9588 100644 --- a/.github/workflows/build-unstable.yml +++ b/.github/workflows/build-unstable.yml @@ -7,7 +7,7 @@ on: paths: - pyscriptjs/** - examples/** - - .github/workflows/build-unstable.yml # Test that workflow works when changed + - .github/workflows/build-latest.yml # Test that workflow works when changed pull_request: # Run on any PR that modifies files under pyscriptjs/ and examples/ branches: @@ -81,38 +81,6 @@ jobs: name: test_results path: pyscriptjs/test_results if-no-files-found: error - eslint: - runs-on: ubuntu-latest - defaults: - run: - working-directory: pyscriptjs - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Install node - uses: actions/setup-node@v3 - with: - node-version: 18.x - - - name: Cache node modules - uses: actions/cache@v3 - env: - cache-name: cache-node-modules - with: - # npm cache files are stored in `~/.npm` on Linux/macOS - path: ~/.npm - key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} - restore-keys: | - ${{ runner.os }}-build-${{ env.cache-name }}- - ${{ runner.os }}-build- - ${{ runner.os }}- - - - name: npm install - run: npm install - - - name: Eslint - run: npx eslint src -c .eslintrc.js Deploy: runs-on: ubuntu-latest diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 85847e2500e..2ffc4200d85 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -49,7 +49,6 @@ repos: - id: eslint files: pyscriptjs/src/.*\.[jt]sx?$ # *.js, *.jsx, *.ts and *.tsx types: [file] - args: [-c, pyscriptjs/.eslintrc.js] additional_dependencies: - eslint@8.25.0 - typescript@4.8.4 From 06ea704b6df86950d59eac8e10735a466d280d54 Mon Sep 17 00:00:00 2001 From: Robert Hood Chatham Date: Thu, 9 Mar 2023 10:45:21 +0100 Subject: [PATCH 23/23] Fix lints --- pyscriptjs/src/pyconfig.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyscriptjs/src/pyconfig.ts b/pyscriptjs/src/pyconfig.ts index 6648eacf76b..7f9e897904c 100644 --- a/pyscriptjs/src/pyconfig.ts +++ b/pyscriptjs/src/pyconfig.ts @@ -158,7 +158,8 @@ function parseConfig(configText: string, configType = 'toml'): AppConfig { try { // eslint-disable-next-line return toml.parse(configText) as AppConfig; - } catch (err) { + } catch (e) { + const err = e as Error; const errMessage: string = err.toString(); throw new UserError(