Skip to content

Commit

Permalink
chore: enable noImplicitAny on build.js
Browse files Browse the repository at this point in the history
  • Loading branch information
lishaduck committed Nov 4, 2024
1 parent 3dfb778 commit fd60bd8
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 16 deletions.
45 changes: 35 additions & 10 deletions lib/build.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/**
* @import {AppHash, BuildResult} from './types/build';
* @import {ApplicationElmJson} from './types/content';
* @import {ApplicationElmJson, ElmJson} from './types/content';
* @import {VersionString} from './types/version';
* @import {Options, Template} from './types/options';
* @import {Path} from './types/path';
* @import {CompileOptions} from '../vendor/types/node-elm-compiler';
* @import {CompileOptions, Sources} from '../vendor/types/node-elm-compiler';
*/
const path = require('node:path');
const crypto = require('node:crypto');
Expand Down Expand Up @@ -330,6 +330,11 @@ async function createTemplateProject(
Benchmark.end(options, 'Create template project');
}

/**
* @param {Options} options
* @param {string} userSrc
* @param {ApplicationElmJson} elmJson
*/
function updateSourceDirectories(options, userSrc, elmJson) {
let sourceDirectories = [
...elmJson['source-directories'].map((directory) =>
Expand All @@ -352,13 +357,22 @@ function updateSourceDirectories(options, userSrc, elmJson) {
};
}

/**
* @param {Options} options
* @param {string} dest
* @param {string} elmModulePath
* @param {Sources} compileTargets
* @param {string} elmBinary
* @param {boolean} isReviewApp
* @returns {Promise<string | null>}
*/
async function compileElmProject(
options,
dest,
elmModulePath,
compileTargets,
elmBinary,
isReviewAppApp
isReviewApp
) {
/** @type {CompileOptions} */
const compileOptions = {
Expand All @@ -376,6 +390,7 @@ async function compileElmProject(
}
};

/** @type {string | null} */
const resolvedElmModulePath = await new Promise((resolve) => {
const compileProcess = elmCompiler.compile(compileTargets, compileOptions);

Expand Down Expand Up @@ -434,13 +449,13 @@ async function compileElmProject(
}
});
});
return await OptimizeJs.optimize(
options,
resolvedElmModulePath,
isReviewAppApp
);
return await OptimizeJs.optimize(options, resolvedElmModulePath, isReviewApp);
}

/**
* @param {Options} options
* @param {string} stderr
*/
function compilationError(options, stderr) {
if (stderr.includes('DEBUG REMNANTS')) {
return {
Expand All @@ -454,7 +469,7 @@ function compilationError(options, stderr) {
return {
title: 'MODULE NOT FOUND',
// prettier-ignore
message: `A module is missing in your configuration. Maybe you forgot to add some dependencies that contain the rules you wished to enable? If so, run ${chalk.magenta('elm install')} with the package name from inside ${chalk.yellow(options.userSrc(null))}.`
message: `A module is missing in your configuration. Maybe you forgot to add some dependencies that contain the rules you wished to enable? If so, run ${chalk.magenta('elm install')} with the package name from inside ${chalk.yellow(options.userSrc())}.`
};
}

Expand All @@ -477,6 +492,11 @@ function compilationError(options, stderr) {
};
}

/**
* @param {Options} options
* @param {Path} reviewElmJsonPath
* @param {ElmJson} reviewElmJson
*/
function validateElmReviewVersion(options, reviewElmJsonPath, reviewElmJson) {
if (options.localElmReviewSrc) {
return;
Expand Down Expand Up @@ -530,6 +550,11 @@ of ${chalk.yellow(path.dirname(reviewElmJsonPath))}.`
MinVersion.validate(options, reviewElmJsonPath, elmReviewVersion);
}

/**
* @param {Options} options
* @param {ApplicationElmJson} reviewElmJson
* @returns {Promise<void>}
*/
async function buildElmParser(options, reviewElmJson) {
const elmSyntaxVersion =
reviewElmJson.dependencies.direct['stil4m/elm-syntax'] ||
Expand Down Expand Up @@ -563,7 +588,7 @@ async function buildElmParser(options, reviewElmJson) {
})
]);

return await compileElmProject(
await compileElmProject(
options,
buildFolder,
elmParserPath,
Expand Down
12 changes: 6 additions & 6 deletions lib/optimize-js.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ const FS = require('./fs-wrapper');

/**
* @param {Options} options
* @param {string} elmModulePath
* @param {boolean} isReviewAppApp
* @returns {Promise<string>}
* @param {string | null} elmModulePath
* @param {boolean} isReviewApp
* @returns {Promise<string | null>}
*/
async function optimize(options, elmModulePath, isReviewAppApp) {
async function optimize(options, elmModulePath, isReviewApp) {
if (options.debug || !elmModulePath) {
return elmModulePath;
}

const timerId = isReviewAppApp
const timerId = isReviewApp
? 'optimizing review application'
: 'optimizing parser application';
Benchmark.start(options, timerId);
const originalSource = await FS.readFile(elmModulePath);
const replacements = isReviewAppApp
const replacements = isReviewApp
? [
...performanceReplacements,
...cacheReplacements(options.localElmReviewSrc)
Expand Down
1 change: 1 addition & 0 deletions tsconfig.no-implicit-any.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"lib/app-wrapper.js",
"lib/autofix.js",
"lib/benchmark.js",
"lib/build.js",
"lib/cache.js",
"lib/debug.js",
"lib/dependency-provider.js",
Expand Down
1 change: 1 addition & 0 deletions vendor/node-elm-compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ function compilerErrorToString(err, pathToElm) {
/**
* @param {Sources} sources
* @param {CompileOptions} options
* @returns {ChildProcess}
*/
function compile(sources, options) {
var optionsWithDefaults = prepareOptions(options, options.spawn || spawn);
Expand Down

0 comments on commit fd60bd8

Please sign in to comment.