From 52de7a09d4cef007ac566bea0390266bf74ca464 Mon Sep 17 00:00:00 2001 From: Henrique Buss Date: Fri, 5 May 2023 16:29:28 -0300 Subject: [PATCH 01/12] Add options.js to no-implicit-any config --- lib/options.js | 74 ++++++++++++++++++++++++++++++++--- lib/types/options.d.ts | 4 +- tsconfig.no-implicit-any.json | 1 + 3 files changed, 72 insertions(+), 7 deletions(-) diff --git a/lib/options.js b/lib/options.js index b426dcda8..24d7e6912 100644 --- a/lib/options.js +++ b/lib/options.js @@ -45,9 +45,12 @@ function compute(processArgv) { alias: Flags.flags .filter((flag) => flag.alias) .reduce((object, flag) => { - object[flag.name] = flag.alias; + if (flag.alias) { + object[flag.name] = flag.alias; + } + return object; - }, {}), + }, /** @type {Record} */ ({})), boolean: Flags.flags .filter((flag) => flag.boolean) .map((flag) => flag.name), @@ -201,7 +204,7 @@ try re-running it with ${chalk.cyan('--elmjson ')}.`, forceBuild: args['force-build'], report: args.report === 'json' || args.report === 'ndjson' ? 'json' : null, reportOnOneLine: args.report === 'ndjson', - rulesFilter: listOfStrings(args.rules), + rulesFilter: listOfStrings(args.rules) || [], ignoredDirs: listOfStrings(args['ignore-dirs']) || [], ignoredFiles: listOfStrings(args['ignore-files']) || [], @@ -289,14 +292,24 @@ try re-running it with ${chalk.cyan('--elmjson ')}.`, }; } +/** + * + * @param {minimist.ParsedArgs} args + * @returns {boolean} + */ function parseUnsuppress(args) { if (args.unsuppress) { return true; } - return listOfStrings(args['unsuppress-rules']) || false; + return Boolean(listOfStrings(args['unsuppress-rules'])); } +/** + * + * @param {string | string[]} input + * @returns {string[] | null} + */ function listOfStrings(input) { if (typeof input === 'string') { return input.split(','); @@ -305,13 +318,19 @@ function listOfStrings(input) { if (Array.isArray(input)) { return input.reduce( (acc, subArray) => [...acc, ...subArray.split(',')], - [] + /** @type {string[]} */ ([]) ); } return null; } +/** + * + * @param {Subcommand | null} subcommand + * @param {string} string + * @returns {{ repoName: string, pathToFolder: string, reference: string }} + */ function parseTemplate(subcommand, string) { const match = /([^/]+\/[^#/]+)(\/[^#]+)?(#(.+))?/.exec(string); if (!match) { @@ -338,6 +357,12 @@ ${Flags.buildFlag(subcommand, Flags.templateFlag)}` }; } +/** + * + * @param {minimist.ParsedArgs} args + * @param {Subcommand | null} subcommand + * @returns {string | null} + */ function findElmJsonPath(args, subcommand) { if (args.elmjson) return args.elmjson; // Shortcutting the search for elm.json when `--help` since we won't need it @@ -355,6 +380,10 @@ function findElmJsonPath(args, subcommand) { return findUp.sync('elm.json') || null; } +/** + * + * @returns {(flag: string) => true} + */ function unknownCheck() { const allFlagNames = new Set(Flags.flags.map((flag) => flag.name)); @@ -376,6 +405,11 @@ function unknownCheck() { }; } +/** + * + * @param {string} name + * @returns {string} + */ function unknownFlagMessage(name) { if (name === 'suppress') { const orange = chalk.keyword('orange'); @@ -403,6 +437,11 @@ function unknownFlagMessage(name) { ].join('\n'); } +/** + * + * @param {string} flag + * @returns {true} + */ function unknownShortHandFlagCheck(flag) { const flagRegex = /^-(?\w+)/; const match = flagRegex.exec(flag); @@ -442,6 +481,11 @@ function unknownShortHandFlagCheck(flag) { return true; } +/** + * + * @param {string} flag + * @returns {string[]} + */ function suggestions(flag) { return Flags.flags .map((f) => ({ @@ -463,6 +507,11 @@ function suggestions(flag) { .map((f) => chalk.greenBright(` --${f.name}${Flags.buildFlagsArgs(f)}`)); } +/** + * + * @param {Subcommand | null} subcommand + * @param {minimist.ParsedArgs} args + */ function checkForMissingArgs(subcommand, args) { Flags.flags .filter((flag) => flag.boolean === false) @@ -502,6 +551,11 @@ ${Flags.buildFlag(subcommand, flag)}` }); } +/** + * + * @param {Subcommand | null} subcommand + * @param {minimist.ParsedArgs} args + */ function checkForInvalidArgs(subcommand, args) { if (args.report && !['json', 'ndjson', 'human'].includes(args.report)) { reportErrorAndExit( @@ -519,6 +573,12 @@ ${Flags.buildFlag(subcommand, Flags.reportFlag)}` } } +/** + * + * @param {Subcommand | null} subcommand + * @param {string} gitHubAuth + * @returns {{ gitHubUser: string, gitHubPassword: string }} + */ function parseGitHubAuth(subcommand, gitHubAuth) { const split = gitHubAuth.split(':'); if (split.length !== 2) { @@ -540,6 +600,10 @@ ${Flags.buildFlag(subcommand, Flags.gitHubAuthFlag)}` return {gitHubUser, gitHubPassword}; } +/** + * + * @param {ErrorMessage.CustomError} errorToReport + */ function reportErrorAndExit(errorToReport) { // @ts-expect-error - Handle this later console.log(ErrorMessage.report({}, errorToReport)); diff --git a/lib/types/options.d.ts b/lib/types/options.d.ts index 301350612..2e4d92439 100644 --- a/lib/types/options.d.ts +++ b/lib/types/options.d.ts @@ -48,9 +48,9 @@ export type Options = { templateElmModulePath: (string) => Path; pathToTemplateElmJson: (string) => Path; dependenciesCachePath: () => Path; - elmJsonPath: Path; + elmJsonPath: Path | null; elmJsonPathWasSpecified: boolean; - readmePath: Path; + readmePath: Path | null; projectToReview: () => Path; directoriesToAnalyze: Path[]; fileCachePath: () => Path; diff --git a/tsconfig.no-implicit-any.json b/tsconfig.no-implicit-any.json index 0eeb93360..7792e7795 100644 --- a/tsconfig.no-implicit-any.json +++ b/tsconfig.no-implicit-any.json @@ -11,6 +11,7 @@ "lib/hash.js", "lib/help.js", "lib/os-helpers.js", + "lib/options.js", "jest.config.js" ] } From 596bde19ea227dd27b4ddc73531e05da0224f61b Mon Sep 17 00:00:00 2001 From: Henrique Buss Date: Fri, 5 May 2023 16:34:42 -0300 Subject: [PATCH 02/12] Fix tsExpectError in reportErrorAndExit --- lib/anonymize.js | 4 ++-- lib/error-message.js | 9 ++++++--- lib/options.js | 3 +-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/anonymize.js b/lib/anonymize.js index e6a07b96b..41ece688c 100644 --- a/lib/anonymize.js +++ b/lib/anonymize.js @@ -20,12 +20,12 @@ module.exports = { /** * Strip the version and paths out of the given string. * This is only used for tests to make them pass even when the version/paths change. - * @param {Options} options + * @param {Options | null} options * @param {string} string * @returns {string} */ function pathsAndVersions(options, string) { - if (options.forTests) { + if (options && options.forTests) { const root = path.dirname(__dirname); return replaceVersion(string.split(root).join('')); } diff --git a/lib/error-message.js b/lib/error-message.js index 01cb8ea96..a78b6ba30 100644 --- a/lib/error-message.js +++ b/lib/error-message.js @@ -22,13 +22,13 @@ class CustomError extends Error { } /** - * @param {Options} options + * @param {Options | null} options * @param {CustomError} err * @param {Path} [defaultPath] * @returns {string} */ function report(options, err, defaultPath) { - if (options.report === 'json') { + if (options && options.report === 'json') { return Anonymize.pathsAndVersions( options, Anonymize.pathsAndVersions( @@ -42,7 +42,10 @@ function report(options, err, defaultPath) { ); } - return Anonymize.pathsAndVersions(options, formatHuman(options.debug, err)); + return Anonymize.pathsAndVersions( + options, + formatHuman(options?.debug ?? false, err) + ); } /** diff --git a/lib/options.js b/lib/options.js index 24d7e6912..c8b1824bd 100644 --- a/lib/options.js +++ b/lib/options.js @@ -605,8 +605,7 @@ ${Flags.buildFlag(subcommand, Flags.gitHubAuthFlag)}` * @param {ErrorMessage.CustomError} errorToReport */ function reportErrorAndExit(errorToReport) { - // @ts-expect-error - Handle this later - console.log(ErrorMessage.report({}, errorToReport)); + console.log(ErrorMessage.report(null, errorToReport)); process.exit(1); } From a4c306eb2e14368310d4f8211077eb816c23b55d Mon Sep 17 00:00:00 2001 From: Henrique Buss Date: Sat, 6 May 2023 13:31:46 -0300 Subject: [PATCH 03/12] Remove optional chaining --- lib/error-message.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/error-message.js b/lib/error-message.js index a78b6ba30..aa6d407e0 100644 --- a/lib/error-message.js +++ b/lib/error-message.js @@ -44,7 +44,7 @@ function report(options, err, defaultPath) { return Anonymize.pathsAndVersions( options, - formatHuman(options?.debug ?? false, err) + formatHuman((options && options.debug) || false, err) ); } From 3333c8de9e188d6f6d4a32af11d8a53062673577 Mon Sep 17 00:00:00 2001 From: Henrique Buss Date: Sat, 6 May 2023 13:36:55 -0300 Subject: [PATCH 04/12] Remove `returns {true}` --- lib/options.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/options.js b/lib/options.js index c8b1824bd..cffbfcea2 100644 --- a/lib/options.js +++ b/lib/options.js @@ -58,7 +58,12 @@ function compute(processArgv) { color: true, details: true }, - unknown: containsHelp ? () => true : unknownCheck() + unknown: containsHelp + ? () => true + : () => { + unknownCheck(); + return true; + } }); /** @@ -382,7 +387,7 @@ function findElmJsonPath(args, subcommand) { /** * - * @returns {(flag: string) => true} + * @returns {(flag: string) => void} */ function unknownCheck() { const allFlagNames = new Set(Flags.flags.map((flag) => flag.name)); @@ -391,7 +396,8 @@ function unknownCheck() { const flagRegex = /^--(?[^=]*)/; const match = flagRegex.exec(flag); if (containsHelp || !match || !match.groups) { - return unknownShortHandFlagCheck(flag); + unknownShortHandFlagCheck(flag); + return; } const {name} = match.groups; @@ -400,8 +406,6 @@ function unknownCheck() { new ErrorMessage.CustomError('UNKNOWN FLAG', unknownFlagMessage(name)) ); } - - return true; }; } @@ -440,20 +444,20 @@ function unknownFlagMessage(name) { /** * * @param {string} flag - * @returns {true} + * @returns {void} */ function unknownShortHandFlagCheck(flag) { const flagRegex = /^-(?\w+)/; const match = flagRegex.exec(flag); if (!match || !match.groups) { - return true; + return; } const flags = match.groups.name.split(''); if (containsHelp || flags.includes('h')) { containsHelp = true; - return true; + return; } const aliases = Flags.flags.map((flag) => flag.alias).filter(Boolean); @@ -477,8 +481,6 @@ function unknownShortHandFlagCheck(flag) { ); } }); - - return true; } /** From 96dbdd9b314960bd07f3be19feb1a3731e1d4847 Mon Sep 17 00:00:00 2001 From: Henrique Buss Date: Sat, 6 May 2023 13:39:49 -0300 Subject: [PATCH 05/12] Allow rulesFilter to be null --- lib/options.js | 2 +- lib/types/options.d.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/options.js b/lib/options.js index cffbfcea2..34032dc88 100644 --- a/lib/options.js +++ b/lib/options.js @@ -209,7 +209,7 @@ try re-running it with ${chalk.cyan('--elmjson ')}.`, forceBuild: args['force-build'], report: args.report === 'json' || args.report === 'ndjson' ? 'json' : null, reportOnOneLine: args.report === 'ndjson', - rulesFilter: listOfStrings(args.rules) || [], + rulesFilter: listOfStrings(args.rules), ignoredDirs: listOfStrings(args['ignore-dirs']) || [], ignoredFiles: listOfStrings(args['ignore-files']) || [], diff --git a/lib/types/options.d.ts b/lib/types/options.d.ts index 2e4d92439..686a74d79 100644 --- a/lib/types/options.d.ts +++ b/lib/types/options.d.ts @@ -26,7 +26,7 @@ export type Options = { forceBuild: boolean; report: ReportMode; reportOnOneLine: boolean; - rulesFilter: string[]; + rulesFilter: string[] | null; ignoredDirs: string[]; ignoredFiles: string[]; ignoreProblematicDependencies: boolean; From 945d9da0df6fa92d3f7b28c7c2da7160d079073f Mon Sep 17 00:00:00 2001 From: Henrique Buss Date: Mon, 8 May 2023 11:34:40 -0300 Subject: [PATCH 06/12] Use template instead of inline record --- lib/options.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/options.js b/lib/options.js index 34032dc88..974bc2cd8 100644 --- a/lib/options.js +++ b/lib/options.js @@ -334,7 +334,7 @@ function listOfStrings(input) { * * @param {Subcommand | null} subcommand * @param {string} string - * @returns {{ repoName: string, pathToFolder: string, reference: string }} + * @returns {Template} */ function parseTemplate(subcommand, string) { const match = /([^/]+\/[^#/]+)(\/[^#]+)?(#(.+))?/.exec(string); From 8d203434b32ff4ba9d9c5fae9c81d7c8c526850f Mon Sep 17 00:00:00 2001 From: Henrique Buss Date: Mon, 8 May 2023 11:48:42 -0300 Subject: [PATCH 07/12] Handle nullable readmeWatcher --- lib/watch.js | 68 +++++++++++++++++++++++++++------------------------- 1 file changed, 36 insertions(+), 32 deletions(-) diff --git a/lib/watch.js b/lib/watch.js index e86949e5c..911a43e33 100644 --- a/lib/watch.js +++ b/lib/watch.js @@ -74,7 +74,7 @@ function watchFiles( clearTimeout(suppressedErrorsTimeout); await Promise.all([ elmJsonWatcher.close(), - readmeWatcher.close(), + readmeWatcher && readmeWatcher.close(), fileWatcher.close(), suppressedErrorsWatcher.close(), configurationWatcher && configurationWatcher.close() @@ -108,36 +108,40 @@ function watchFiles( } }); - const readmeWatcher = chokidar - .watch(OsHelpers.makePathOsAgnostic(options.readmePath), { - ignoreInitial: true - }) - .on('add', async () => { - Debug.log('README.md has been added'); - - const readme = { - path: options.readmePath, - content: await FS.readFile(options.readmePath) - }; - - AppState.readmeChanged(readme); - app.ports.collectReadme.send(readme); - runReview(); - }) - .on('change', async () => { - const readme = { - path: options.readmePath, - content: await FS.readFile(options.readmePath) - }; - const readmeHasChanged = AppState.readmeChanged(readme); - if (readmeHasChanged) { - Debug.log('README.md has been changed'); - - app.ports.collectReadme.send(readme); - runReview(); - } - }) - .on('error', onError); + const readmeWatcher = + options.readmePath === null + ? null + : ((readmePath) => + chokidar + .watch(OsHelpers.makePathOsAgnostic(readmePath), { + ignoreInitial: true + }) + .on('add', async () => { + Debug.log('README.md has been added'); + + const readme = { + path: readmePath, + content: await FS.readFile(readmePath) + }; + + AppState.readmeChanged(readme); + app.ports.collectReadme.send(readme); + runReview(); + }) + .on('change', async () => { + const readme = { + path: readmePath, + content: await FS.readFile(readmePath) + }; + const readmeHasChanged = AppState.readmeChanged(readme); + if (readmeHasChanged) { + Debug.log('README.md has been changed'); + + app.ports.collectReadme.send(readme); + runReview(); + } + }) + .on('error', onError))(options.readmePath); const fileWatcher = chokidar .watch( @@ -274,7 +278,7 @@ function watchFiles( clearTimeout(suppressedErrorsTimeout); await Promise.all([ elmJsonWatcher.close(), - readmeWatcher.close(), + readmeWatcher && readmeWatcher.close(), fileWatcher.close(), suppressedErrorsWatcher.close() ]); From 96867787fe65f096a9a0d82d23c5c50c952377a4 Mon Sep 17 00:00:00 2001 From: Henrique Buss Date: Mon, 8 May 2023 11:53:07 -0300 Subject: [PATCH 08/12] Remove IIFE --- lib/watch.js | 65 ++++++++++++++++++++++++++-------------------------- 1 file changed, 32 insertions(+), 33 deletions(-) diff --git a/lib/watch.js b/lib/watch.js index 911a43e33..dc582273c 100644 --- a/lib/watch.js +++ b/lib/watch.js @@ -108,40 +108,39 @@ function watchFiles( } }); + const {readmePath} = options; const readmeWatcher = - options.readmePath === null - ? null - : ((readmePath) => - chokidar - .watch(OsHelpers.makePathOsAgnostic(readmePath), { - ignoreInitial: true - }) - .on('add', async () => { - Debug.log('README.md has been added'); - - const readme = { - path: readmePath, - content: await FS.readFile(readmePath) - }; - - AppState.readmeChanged(readme); - app.ports.collectReadme.send(readme); - runReview(); - }) - .on('change', async () => { - const readme = { - path: readmePath, - content: await FS.readFile(readmePath) - }; - const readmeHasChanged = AppState.readmeChanged(readme); - if (readmeHasChanged) { - Debug.log('README.md has been changed'); - - app.ports.collectReadme.send(readme); - runReview(); - } - }) - .on('error', onError))(options.readmePath); + readmePath && + chokidar + .watch(OsHelpers.makePathOsAgnostic(readmePath), { + ignoreInitial: true + }) + .on('add', async () => { + Debug.log('README.md has been added'); + + const readme = { + path: readmePath, + content: await FS.readFile(readmePath) + }; + + AppState.readmeChanged(readme); + app.ports.collectReadme.send(readme); + runReview(); + }) + .on('change', async () => { + const readme = { + path: readmePath, + content: await FS.readFile(readmePath) + }; + const readmeHasChanged = AppState.readmeChanged(readme); + if (readmeHasChanged) { + Debug.log('README.md has been changed'); + + app.ports.collectReadme.send(readme); + runReview(); + } + }) + .on('error', onError); const fileWatcher = chokidar .watch( From 9d5a442f9f7f312b57f49922672fde18700e89f0 Mon Sep 17 00:00:00 2001 From: Henrique Buss Date: Fri, 12 May 2023 09:40:12 -0300 Subject: [PATCH 09/12] Make sure elmJsonPath is not null when we need it --- lib/elm-files.js | 3 +- lib/types/options.d.ts | 4 ++ lib/watch.js | 91 ++++++++++++++++++++++-------------------- 3 files changed, 53 insertions(+), 45 deletions(-) diff --git a/lib/elm-files.js b/lib/elm-files.js index 9c0cf1400..b25389cec 100644 --- a/lib/elm-files.js +++ b/lib/elm-files.js @@ -16,6 +16,7 @@ const Cache = require('./cache'); /** * @typedef { import("./types/options").Options } Options + * @typedef { import("./types/options").OptionsForRunningElmReview } OptionsForRunningElmReview * @typedef { import("./types/path").Path } Path * @typedef { import("./types/content").ElmFile } ElmFile * @typedef { import("./types/content").Readme } Readme @@ -41,7 +42,7 @@ function flatMap(array, fn) { /** * Get all files from the project. - * @param {Options} options + * @param {OptionsForRunningElmReview} options * @param {string} elmSyntaxVersion * @returns {Promise} */ diff --git a/lib/types/options.d.ts b/lib/types/options.d.ts index 686a74d79..6e5b45a65 100644 --- a/lib/types/options.d.ts +++ b/lib/types/options.d.ts @@ -60,6 +60,10 @@ export type Options = { gitHubPassword: string | undefined; }; +export type OptionsForRunningElmReview = Omit & { + elmJsonPath: Path; +}; + export type DetailsMode = 'without-details' | 'with-details'; export type ReportMode = 'json' | null; diff --git a/lib/watch.js b/lib/watch.js index dc582273c..16871d579 100644 --- a/lib/watch.js +++ b/lib/watch.js @@ -62,53 +62,56 @@ function watchFiles( isFlushingStdio = true; } - const elmJsonWatcher = chokidar - .watch(OsHelpers.makePathOsAgnostic(options.elmJsonPath), { - ignoreInitial: true - }) - .on('change', async () => { - const newValue = await FS.readJsonFile(options.elmJsonPath); - if (JSON.stringify(newValue) !== JSON.stringify(elmJsonContent)) { - elmJsonContent = newValue; - runReview = () => {}; - clearTimeout(suppressedErrorsTimeout); - await Promise.all([ - elmJsonWatcher.close(), - readmeWatcher && readmeWatcher.close(), - fileWatcher.close(), - suppressedErrorsWatcher.close(), - configurationWatcher && configurationWatcher.close() - ]); - - if (options.report !== 'json') { - if (!options.debug) { - clearConsole(); + const {elmJsonPath, readmePath} = options; + + const elmJsonWatcher = + elmJsonPath && + chokidar + .watch(OsHelpers.makePathOsAgnostic(elmJsonPath), { + ignoreInitial: true + }) + .on('change', async () => { + const newValue = await FS.readJsonFile(elmJsonPath); + if (JSON.stringify(newValue) !== JSON.stringify(elmJsonContent)) { + elmJsonContent = newValue; + runReview = () => {}; + clearTimeout(suppressedErrorsTimeout); + await Promise.all([ + elmJsonWatcher && elmJsonWatcher.close(), + readmeWatcher && readmeWatcher.close(), + fileWatcher.close(), + suppressedErrorsWatcher.close(), + configurationWatcher && configurationWatcher.close() + ]); + + if (options.report !== 'json') { + if (!options.debug) { + clearConsole(); + } + + // TODO Detect what has changed and only re-load the necessary parts. + // We do some of this work in `autofix.js` already. + Debug.log('Your `elm.json` has changed. Restarting elm-review.'); } - // TODO Detect what has changed and only re-load the necessary parts. - // We do some of this work in `autofix.js` already. - Debug.log('Your `elm.json` has changed. Restarting elm-review.'); + rebuildAndRewatch(); + + // At the moment, since a lot of things can change (elm.json properties, source-directories, dependencies, ...), + // it is simpler to re-run the whole process like when the configuration changes. + // + // We could try and handle each possible change separately to make this more efficient. + // + // app.ports.collectElmJson.send(newValue); + // const projectDeps = await projectDependencies.collect( + // options, + // newValue, + // elmVersion + // ); + // app.ports.collectDependencies.send(projectDeps); + // runReview(); } + }); - rebuildAndRewatch(); - - // At the moment, since a lot of things can change (elm.json properties, source-directories, dependencies, ...), - // it is simpler to re-run the whole process like when the configuration changes. - // - // We could try and handle each possible change separately to make this more efficient. - // - // app.ports.collectElmJson.send(newValue); - // const projectDeps = await projectDependencies.collect( - // options, - // newValue, - // elmVersion - // ); - // app.ports.collectDependencies.send(projectDeps); - // runReview(); - } - }); - - const {readmePath} = options; const readmeWatcher = readmePath && chokidar @@ -276,7 +279,7 @@ function watchFiles( clearTimeout(suppressedErrorsTimeout); await Promise.all([ - elmJsonWatcher.close(), + elmJsonWatcher && elmJsonWatcher.close(), readmeWatcher && readmeWatcher.close(), fileWatcher.close(), suppressedErrorsWatcher.close() From 956fef8ab90b2b95885b5eac41564556d2bf8857 Mon Sep 17 00:00:00 2001 From: Henrique Buss Date: Fri, 12 May 2023 09:58:38 -0300 Subject: [PATCH 10/12] Parse options into optionsWithElmJsonPath --- lib/main.js | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/lib/main.js b/lib/main.js index c5b96349f..44c287925 100644 --- a/lib/main.js +++ b/lib/main.js @@ -49,20 +49,27 @@ function errorHandler(err) { async function runElmReview() { const {elmModulePath, reviewElmJson, appHash} = await Builder.build(options); - if (!elmModulePath) { + if (!elmModulePath || !options.elmJsonPath) { AppState.exitRequested(1); return; } + const optionsWithElmJsonPath = {...options, elmJsonPath: options.elmJsonPath}; + const [{app}] = await Promise.all([ - Builder.buildElmParser(options, reviewElmJson).then(() => - Runner.initializeApp(options, elmModulePath, reviewElmJson, appHash) + Builder.buildElmParser(optionsWithElmJsonPath, reviewElmJson).then(() => + Runner.initializeApp( + optionsWithElmJsonPath, + elmModulePath, + reviewElmJson, + appHash + ) ), - ResultCache.load(options, appHash) + ResultCache.load(optionsWithElmJsonPath, appHash) ]); - const success = await Runner.runReview(options, app); + const success = await Runner.runReview(optionsWithElmJsonPath, app); AppState.exitRequested(success ? 0 : 1); } @@ -72,7 +79,7 @@ async function runElmReviewInWatchMode() { await Builder.build(options); await Builder.buildElmParser(options, reviewElmJson); - if (!elmModulePath) { + if (!elmModulePath || !options.elmJsonPath) { Watch.watchConfiguration(options, reviewElmJson, reviewElmJsonPath, () => { AppState.buildRestarted(); runElmReviewInWatchMode(); @@ -80,8 +87,10 @@ async function runElmReviewInWatchMode() { return; } + const optionsWithElmJsonPath = {...options, elmJsonPath: options.elmJsonPath}; + const initialization = await Runner.initializeApp( - options, + optionsWithElmJsonPath, elmModulePath, reviewElmJson, appHash From 70ab2069c9460b83a7f6eda636a5fdc4bc0954ac Mon Sep 17 00:00:00 2001 From: Henrique Buss Date: Wed, 24 May 2023 19:08:07 -0300 Subject: [PATCH 11/12] import CustomError --- lib/options.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/options.js b/lib/options.js index 974bc2cd8..145557918 100644 --- a/lib/options.js +++ b/lib/options.js @@ -12,6 +12,7 @@ const ErrorMessage = require('./error-message'); * @typedef { import("./types/options").Options } Options * @typedef { import("./types/options").Subcommand } Subcommand * @typedef { import("./types/options").Template } Template + * @typedef { import("./error-message").CustomError } CustomError */ /* @@ -604,7 +605,7 @@ ${Flags.buildFlag(subcommand, Flags.gitHubAuthFlag)}` /** * - * @param {ErrorMessage.CustomError} errorToReport + * @param {CustomError} errorToReport */ function reportErrorAndExit(errorToReport) { console.log(ErrorMessage.report(null, errorToReport)); From 66ea252b70b022a362ecbe35b5746de839850f88 Mon Sep 17 00:00:00 2001 From: Henrique Buss Date: Wed, 24 May 2023 19:22:35 -0300 Subject: [PATCH 12/12] Adjust function types inside of Options --- lib/options.js | 10 +++++----- lib/types/options.d.ts | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/options.js b/lib/options.js index 145557918..ab2394a17 100644 --- a/lib/options.js +++ b/lib/options.js @@ -236,9 +236,9 @@ try re-running it with ${chalk.cyan('--elmjson ')}.`, buildFolder: () => path.join(elmStuffFolder(), 'build-project'), buildFolderForParserApp: () => path.join(elmStuffFolder(), 'parser-app-build-project'), - elmModulePath: (appHash /* : string */) => + elmModulePath: (appHash) => path.join(elmStuffFolder(), 'review-applications', `${appHash}.js`), - elmParserPath: (elmSyntaxVersion /* : string */) => + elmParserPath: (elmSyntaxVersion) => path.resolve( process.cwd(), elmStuffFolder(), @@ -246,7 +246,7 @@ try re-running it with ${chalk.cyan('--elmjson ')}.`, `elm-syntax-v${elmSyntaxVersion}${args.debug ? '-debug' : ''}.js` ), generatedCodePackageJson: elmStuffFolder, - templateElmModulePath: (commit /* : string */) => { + templateElmModulePath: (commit) => { if (!template) { // Should not happen, but makes Flow happy return 'MISSING-TEMPLATE'; @@ -264,7 +264,7 @@ try re-running it with ${chalk.cyan('--elmjson ')}.`, ].join('') + '.js' ); }, - pathToTemplateElmJson: (commit /* : string */) => { + pathToTemplateElmJson: (commit) => { if (!template) { // Should not happen, but makes Flow happy return 'MISSING-TEMPLATE'; @@ -289,7 +289,7 @@ try re-running it with ${chalk.cyan('--elmjson ')}.`, projectToReview, directoriesToAnalyze, fileCachePath: () => path.join(elmStuffFolder(), 'file-cache'), - resultCachePath: (appHash /* : string */) => + resultCachePath: (appHash) => path.join(elmStuffFolder(), 'result-cache', appHash), // GitHub tokens diff --git a/lib/types/options.d.ts b/lib/types/options.d.ts index 6e5b45a65..3a65616ff 100644 --- a/lib/types/options.d.ts +++ b/lib/types/options.d.ts @@ -42,11 +42,11 @@ export type Options = { suppressedErrorsFolder: () => Path; buildFolder: () => Path; buildFolderForParserApp: () => Path; - elmModulePath: (string) => Path; - elmParserPath: (string) => Path; + elmModulePath: (appHash: string) => Path; + elmParserPath: (elmSyntaxVersion: string) => Path; generatedCodePackageJson: () => Path; - templateElmModulePath: (string) => Path; - pathToTemplateElmJson: (string) => Path; + templateElmModulePath: (commit: string) => Path; + pathToTemplateElmJson: (commit: string) => Path; dependenciesCachePath: () => Path; elmJsonPath: Path | null; elmJsonPathWasSpecified: boolean; @@ -54,7 +54,7 @@ export type Options = { projectToReview: () => Path; directoriesToAnalyze: Path[]; fileCachePath: () => Path; - resultCachePath: (string) => Path; + resultCachePath: (appHash: string) => Path; gitHubUser: string | undefined; gitHubPassword: string | undefined;