Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc #298

Merged
merged 5 commits into from
Nov 4, 2024
Merged

Misc #298

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions lib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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,
Expand Down
13 changes: 2 additions & 11 deletions lib/extra-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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) => {
Expand Down Expand Up @@ -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
};
6 changes: 3 additions & 3 deletions lib/os-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
1 change: 0 additions & 1 deletion lib/parse-elm-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
}
4 changes: 2 additions & 2 deletions lib/result-cache-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
8 changes: 4 additions & 4 deletions lib/types/elm-internals.ts
Original file line number Diff line number Diff line change
@@ -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;
};
4 changes: 2 additions & 2 deletions lib/types/parse-elm.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -18,6 +18,6 @@ export type ParserApp = {
};

type ParserPorts = {
requestParsing: SendPort<ElmJson>;
requestParsing: SendPort<string>;
parseResult: SubscribePort<ElmFile>;
};
12 changes: 12 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* @template T
* @param {T[]} array
* @returns {T[]}
*/
function unique(array) {
return [...new Set(array)];
}

module.exports = {
unique
};