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

More TS #301

Merged
merged 33 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
cf1ba92
chore: enable `noImplicitAny` on `elm-binary.js`
lishaduck Nov 4, 2024
78f3479
fix: type-level arithmetic!
lishaduck Nov 4, 2024
03479d3
chore: enable `noImplicitAny` on `template-dependencies.js`
lishaduck Nov 4, 2024
70aae3f
chore: add watch-strict script to ease `noImplicitAny` adoption
lishaduck Nov 4, 2024
a5faaca
chore: enable `noImplicitAny` on `result-cache-worker.js`
lishaduck Nov 4, 2024
860a198
refactor: define CacheRequest type
lishaduck Nov 4, 2024
d336723
fix: readAst returns an Ast, not an ElmFile
lishaduck Nov 4, 2024
f02acd1
fix: use unknown over object, which ts now treats as any
lishaduck Nov 4, 2024
834c54a
chore: enable `noImplicitAny` on `result-cache.js`
lishaduck Nov 4, 2024
8b76474
fix: more types
lishaduck Nov 4, 2024
28c23bf
fix: remove redundant annotation
lishaduck Nov 4, 2024
ad4f70a
chore: enable `noImplicitAny` on `review-dependencies.js`
lishaduck Nov 4, 2024
a06b3c7
chore: enable `noImplicitAny` on `project-dependencies.js`
lishaduck Nov 4, 2024
17644f0
chore: enable `noImplicitAny` on `runner.js`
lishaduck Nov 4, 2024
7f6e6a7
chore: enable `noImplicitAny` on `app-wrapper.js`
lishaduck Nov 4, 2024
b2c7e04
chore: enable `noImplicitAny` on `autofix.js`
lishaduck Nov 4, 2024
8acbcea
chore: enable `noImplicitAny` on `remote-template.js`
lishaduck Nov 4, 2024
a6fa97b
chore: enable `noImplicitAny` on `optimize-js.js`
lishaduck Nov 4, 2024
e7c5864
chore: update type imports to use ts extensions
lishaduck Nov 4, 2024
d0f19fc
chore: enable `noImplicitAny` on `build.js`
lishaduck Nov 4, 2024
da322ba
chore: enable `noImplicitAny` on `elm-app-worker.js`
lishaduck Nov 4, 2024
3552ccd
chore: enable `noImplicitAny` on `init.js`
lishaduck Nov 4, 2024
98a0279
chore: enable `noImplicitAny` on `new-package.js`
lishaduck Nov 4, 2024
a64d587
chore: enable `noImplicitAny` on `main.js`
lishaduck Nov 4, 2024
ffe85cc
chore: enable `noImplicitAny` on `module-cache.js`
lishaduck Nov 4, 2024
f68a16d
chore: enable `noImplicitAny` on `run-review.js`
lishaduck Nov 4, 2024
fd34ca9
chore: enable `noImplicitAny` on `watch.js`
lishaduck Nov 4, 2024
505261a
chore: enable `noImplicitAny` on `new-package/`
lishaduck Nov 4, 2024
4e91e56
chore: remove `tsconfig.no-implicit-any.json`
lishaduck Nov 4, 2024
fd4fd3a
chore: enable blanket strict mode
lishaduck Nov 4, 2024
c13b9ff
chore: make eslint depend on tsconfig
lishaduck Nov 4, 2024
d7b4155
chore: add offline testing script
lishaduck Nov 4, 2024
bdaa693
Update maintenance file snapshots
jfmengels Nov 4, 2024
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
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
Comment on lines +362 to +363
Copy link
Owner

@jfmengels jfmengels Nov 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would be more accurate:

 * @param {Path} dest
 * @param {Path} elmModulePath

Same for elmBinary below and other places in this file.

* @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