From 6d61e0b7c702d1bf41f19e3bac8c14a76ebb014c Mon Sep 17 00:00:00 2001 From: Sam Thorogood Date: Mon, 29 Aug 2022 22:15:30 +1000 Subject: [PATCH] stuffs --- build.mjs | 25 +++++++++++++++++++++++++ src/o-decoder.js | 5 +++-- src/polyfill.js | 6 +++--- tsconfig.json | 2 ++ 4 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 build.mjs diff --git a/build.mjs b/build.mjs new file mode 100644 index 0000000..bf7a5ac --- /dev/null +++ b/build.mjs @@ -0,0 +1,25 @@ +import * as esbuild from 'esbuild'; +import * as fs from 'fs'; + +const out = esbuild.buildSync({ + entryPoints: ['src/polyfill.js'], + bundle: true, + format: 'esm', + banner: { + js: `(function(scope) {'use strict';`, + }, + footer: { + js: `}(typeof window !== 'undefined' ? window : (typeof global !== 'undefined' ? global : this)));`, + }, + platform: 'neutral', + sourcemap: 'external', + outfile: 'text.min.js', + target: 'es5', + minify: true, +}); + +// confirm it imports +await import('./text.min.js'); + +const stat = fs.statSync('text.min.js'); +console.info(`text.min.js: ${stat.size}`); diff --git a/src/o-decoder.js b/src/o-decoder.js index 9b8d06b..5256eac 100644 --- a/src/o-decoder.js +++ b/src/o-decoder.js @@ -22,7 +22,8 @@ if (hasBufferFrom) { } -const errorPrefix = `${failedToString} construct 'TextDecoder': the `; +const ctorString = `construct 'TextDecoder'`; +const errorPrefix = `${failedToString} ${ctorString}: the `; /** @@ -31,7 +32,7 @@ const errorPrefix = `${failedToString} construct 'TextDecoder': the `; * @param {{fatal: boolean}=} options */ export function FastTextDecoder(utfLabel = 'utf-8', options) { - maybeThrowFailedToOption(options && options.fatal, `construct 'TextDecoder'`, 'fatal'); + maybeThrowFailedToOption(options && options.fatal, ctorString, 'fatal'); /** @type {boolean} */ let ok; diff --git a/src/polyfill.js b/src/polyfill.js index 241bc71..aeccf68 100644 --- a/src/polyfill.js +++ b/src/polyfill.js @@ -2,10 +2,10 @@ import { FastTextEncoder } from './o-encoder.js'; import { FastTextDecoder } from './o-decoder.js'; -/** @type {object} */ -const scope = typeof window !== 'undefined' ? window : (typeof global !== 'undefined' ? global : this); +// /** @type {object} */ +// const scope = typeof window !== 'undefined' ? window : (typeof global !== 'undefined' ? global : this); scope['TextEncoder'] = scope['TextEncoder'] || FastTextEncoder; scope['TextDecoder'] = scope['TextDecoder'] || FastTextDecoder; -export {}; +// export {}; diff --git a/tsconfig.json b/tsconfig.json index 78d3369..2c0cfb1 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,6 +7,7 @@ // both to e.g., "es2017" "module": "esnext", "target": "esnext", + "moduleResolution": "node", // configure as you like: these are my preferred defaults! "strict": true, @@ -20,5 +21,6 @@ "include": [ // include the JS files you'd like to check here "src/**/*.js", + "*.js", ], } \ No newline at end of file