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/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 = { 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/result-cache-json.js b/lib/result-cache-json.js index 7f24a4d8f..01ff6cafd 100644 --- a/lib/result-cache-json.js +++ b/lib/result-cache-json.js @@ -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; }; 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; }; 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 +};