From 4366192010008db5dc7efe2cebf34eba416b0ad6 Mon Sep 17 00:00:00 2001 From: Eli <88557639+lishaduck@users.noreply.github.com> Date: Sat, 31 Aug 2024 21:49:28 -0500 Subject: [PATCH 1/5] refactor: deduplicate the uniq function --- lib/build.js | 10 +--------- lib/extra-files.js | 13 ++----------- lib/utils.js | 12 ++++++++++++ 3 files changed, 15 insertions(+), 20 deletions(-) create mode 100644 lib/utils.js diff --git a/lib/build.js b/lib/build.js index 062a4824e..80141af98 100644 --- a/lib/build.js +++ b/lib/build.js @@ -25,6 +25,7 @@ const OptimizeJs = require('./optimize-js'); const RemoteTemplate = require('./remote-template'); const Spinner = require('./spinner'); const TemplateDependencies = require('./template-dependencies'); +const {unique} = require('./utils'); const templateSrc = path.join(__dirname, '../template/src'); const parseElmFolder = path.join(__dirname, '../parseElm'); @@ -354,15 +355,6 @@ function updateSourceDirectories(options, userSrc, elmJson) { }; } -/** - * @template T - * @param {T[]} array - * @returns {T[]} - */ -function unique(array) { - return [...new Set(array)]; -} - async function compileElmProject( options, dest, diff --git a/lib/extra-files.js b/lib/extra-files.js index e18aa74e6..283bc4f05 100644 --- a/lib/extra-files.js +++ b/lib/extra-files.js @@ -4,6 +4,7 @@ const {glob} = require('tinyglobby'); const FS = require('./fs-wrapper'); const OsHelpers = require('./os-helpers'); +const {unique} = require('./utils'); /** * Collect the extra files requested by the rules. @@ -15,8 +16,7 @@ async function collect(requests) { const files2D = await Promise.all( requests.map(async (request) => await getFiles(request)) ); - const flatFiles = files2D.flat(); - const files = unique(flatFiles); + const files = unique(files2D.flat()); const filesAndContents = await Promise.all( files.map(async (filePath) => { @@ -56,15 +56,6 @@ async function getFiles(request) { ); } -/** - * @template T - * @param {T[]} array - * @returns {T[]} - */ -function unique(array) { - return [...new Set(array)]; -} - module.exports = { collect }; diff --git a/lib/utils.js b/lib/utils.js new file mode 100644 index 000000000..c1966d1d9 --- /dev/null +++ b/lib/utils.js @@ -0,0 +1,12 @@ +/** + * @template T + * @param {T[]} array + * @returns {T[]} + */ +function unique(array) { + return [...new Set(array)]; +} + +module.exports = { + unique +}; From 5b39238a26ca8df1f97675b0fd62ef5462a8e944 Mon Sep 17 00:00:00 2001 From: Eli <88557639+lishaduck@users.noreply.github.com> Date: Thu, 29 Aug 2024 22:15:31 -0500 Subject: [PATCH 2/5] refactor: update ValueStruct I think it's supposed to be treated as immutable. I also removed some type assertions. --- lib/result-cache-json.js | 6 +++--- lib/types/elm-internals.ts | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/result-cache-json.js b/lib/result-cache-json.js index 7f24a4d8f..90fc3a5c5 100644 --- a/lib/result-cache-json.js +++ b/lib/result-cache-json.js @@ -12,7 +12,7 @@ function replacer(_key, value_) { } if (typeof value === 'object') { - // TODO(@jfmengels): Also support serializing `Dict`s. + // // TODO(@jfmengels): Also support serializing `Dict`s. // if (value.$ === -1) { // return { // $: '$D', @@ -109,13 +109,13 @@ function reviver(_, value_) { } } -const _ListNilPROD = /** @type {const} */ ({$: 0}); +/** @type {ValueStruct} */ +const _ListNilPROD = {$: 0}; /** * @param {string | string[]} array */ function _ListFromArrayPROD(array) { - /** @type {ValueStruct} */ let out = _ListNilPROD; for (let i = array.length; i--; ) { out = {$: 1, a: array[i], b: out}; diff --git a/lib/types/elm-internals.ts b/lib/types/elm-internals.ts index 2a54ffd55..b503d55fe 100644 --- a/lib/types/elm-internals.ts +++ b/lib/types/elm-internals.ts @@ -1,7 +1,7 @@ export type Value = null | ValueStruct | number | string; export type ValueStruct = { - $: 1 | -1 | 0 | `$L`; - a?: string[] | string; - b?: ValueStruct; - c?: unknown; + readonly $: 1 | -1 | 0 | `$L`; + readonly a?: string[] | string; + readonly b?: ValueStruct; + readonly c?: unknown; }; From 416304f957ac204f12c61164ee00438eceec2ea9 Mon Sep 17 00:00:00 2001 From: Eli <88557639+lishaduck@users.noreply.github.com> Date: Thu, 29 Aug 2024 22:16:58 -0500 Subject: [PATCH 3/5] fix: `ParserPort` output type --- lib/parse-elm-worker.js | 1 - lib/types/parse-elm.ts | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/parse-elm-worker.js b/lib/parse-elm-worker.js index fa30039d0..4293dbb4b 100644 --- a/lib/parse-elm-worker.js +++ b/lib/parse-elm-worker.js @@ -46,7 +46,6 @@ function workerParseElm({source, elmParserPath}) { return promisifyPort({ subscribeTo: app.ports.parseResult, sendThrough: app.ports.requestParsing, - // @ts-expect-error(TS2322): TS wants an `ElmJson`, but we're giving a string. data: source }); } diff --git a/lib/types/parse-elm.ts b/lib/types/parse-elm.ts index cd8cb9fb1..24269c9f3 100644 --- a/lib/types/parse-elm.ts +++ b/lib/types/parse-elm.ts @@ -1,4 +1,4 @@ -import {ElmFile, Source, type ElmJson} from './content.js'; +import {ElmFile, Source} from './content.js'; import {Path} from './path.js'; import type {SendPort, SubscribePort} from './promisify-port.js'; @@ -18,6 +18,6 @@ export type ParserApp = { }; type ParserPorts = { - requestParsing: SendPort; + requestParsing: SendPort; parseResult: SubscribePort; }; From e8e2b94cdaa4892691fa8ac3285d533cbbb878e6 Mon Sep 17 00:00:00 2001 From: Eli <88557639+lishaduck@users.noreply.github.com> Date: Thu, 29 Aug 2024 22:21:48 -0500 Subject: [PATCH 4/5] style: remove trailing underscore --- lib/os-helpers.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/os-helpers.js b/lib/os-helpers.js index 53d79af01..fefcab9f7 100644 --- a/lib/os-helpers.js +++ b/lib/os-helpers.js @@ -3,11 +3,11 @@ /** @import {Path} from './types/path'; */ /** - * @param {Path} path_ + * @param {Path} path * @returns {Path} */ -function makePathOsAgnostic(path_) { - return path_.replace(/.:/, '').replace(/\\/g, '/'); +function makePathOsAgnostic(path) { + return path.replace(/.:/, '').replace(/\\/g, '/'); } module.exports = { From 6ba03f398b054495bd6d0e796441a3c86b75a6ff Mon Sep 17 00:00:00 2001 From: Eli <88557639+lishaduck@users.noreply.github.com> Date: Sun, 3 Nov 2024 19:36:36 -0600 Subject: [PATCH 5/5] Update lib/result-cache-json.js --- lib/result-cache-json.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/result-cache-json.js b/lib/result-cache-json.js index 90fc3a5c5..01ff6cafd 100644 --- a/lib/result-cache-json.js +++ b/lib/result-cache-json.js @@ -12,7 +12,7 @@ function replacer(_key, value_) { } if (typeof value === 'object') { - // // TODO(@jfmengels): Also support serializing `Dict`s. + // TODO(@jfmengels): Also support serializing `Dict`s. // if (value.$ === -1) { // return { // $: '$D',