diff --git a/.eslintrc.js b/.eslintrc.js index b4b5f6fb1..1d424223b 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -32,8 +32,7 @@ module.exports = { 'test/snapshots', 'test/temporary', 'vendor/', - '.eslintrc.js', - 'new-package/elm-review-package-tests/check-previews-compile.js' + '.eslintrc.js' ], rules: { // Style disagreements with XO. @@ -112,6 +111,8 @@ module.exports = { files: ['./new-package/**/*.js'], rules: { 'n/no-process-exit': 'off', + 'n/no-missing-require': 'off', + '@typescript-eslint/ban-ts-comment': 'off', '@typescript-eslint/unbound-method': 'off' // TODO: Fix this warning. @lishaduck just got confused. } } diff --git a/.prettierignore b/.prettierignore index 0bee5bea6..2f4cba9ef 100644 --- a/.prettierignore +++ b/.prettierignore @@ -9,5 +9,4 @@ test/**/*.json test/temporary/ test/run-snapshots/ -vendor/exit.js .turbo diff --git a/lib/new-package.js b/lib/new-package.js index 8804f14d4..6e752a1ba 100644 --- a/lib/new-package.js +++ b/lib/new-package.js @@ -310,6 +310,14 @@ ElmjutsuDumMyM0DuL3.elm } ); + const checkPreviewsCompile = path.join( + packageTests, + 'check-previews-compile.js' + ); + const data = await FS.readFile(checkPreviewsCompile); + const result = data.replace(/\/\/ @ts-ignore - Generated file.\n/, ''); + await FS.writeFile(checkPreviewsCompile, result, 'utf8'); + Spinner.succeed(); } diff --git a/new-package/elm-review-package-tests/check-previews-compile.js b/new-package/elm-review-package-tests/check-previews-compile.js index 78057dc12..b8ae63e65 100644 --- a/new-package/elm-review-package-tests/check-previews-compile.js +++ b/new-package/elm-review-package-tests/check-previews-compile.js @@ -1,16 +1,18 @@ #!/usr/bin/env node -const path = require('path'); +const path = require('node:path'); const Ansi = require('./helpers/ansi'); -const {execSync} = require('child_process'); +const {execSync} = require('node:child_process'); const {findPreviewConfigurations} = require('./helpers/find-configurations'); +// @ts-ignore - Generated file. const packageDependencies = require('../elm.json').dependencies; const root = path.dirname(__dirname); // Find all elm.json files - -findPreviewConfigurations().forEach(checkThatExampleCompiles); +for (const example of findPreviewConfigurations()) { + checkThatExampleCompiles(example); +} function checkThatExampleCompiles(exampleConfiguration) { const exampleConfigurationElmJson = require(`${exampleConfiguration}/elm.json`); @@ -48,7 +50,6 @@ and make the necessary changes to make it compile.` } success(exampleConfiguration); - return; } catch { console.log( `An error occurred while trying to check whether the ${Ansi.yellow( @@ -66,7 +67,7 @@ function success(config) { } function checkDepsAreCompatible(exampleConfiguration, previewDependencies) { - Object.entries(packageDependencies).forEach(([depName, constraint]) => { + for (const [depName, constraint] of Object.entries(packageDependencies)) { if (!(depName in previewDependencies)) { console.error( `Dependency ${depName} is missing in the ${exampleConfiguration}/ configuration` @@ -81,12 +82,13 @@ function checkDepsAreCompatible(exampleConfiguration, previewDependencies) { previewDependencies[depName] ); delete previewDependencies[depName]; - }); + } const remainingKeys = Object.keys(previewDependencies); - if (remainingKeys.length !== 0) { + if (remainingKeys.length > 0) { console.error( - `There are extraneous dependencies in the ${exampleConfiguration}/ configuration: ${remainingKeys}` + // prettier-ignore + `There are extraneous dependencies in the ${exampleConfiguration}/ configuration: ${remainingKeys.join(', ')}` ); process.exit(1); } diff --git a/test/run-snapshots/elm-review-something-for-new-rule/elm-review-package-tests/check-previews-compile.js b/test/run-snapshots/elm-review-something-for-new-rule/elm-review-package-tests/check-previews-compile.js index 78057dc12..5f55a2c91 100644 --- a/test/run-snapshots/elm-review-something-for-new-rule/elm-review-package-tests/check-previews-compile.js +++ b/test/run-snapshots/elm-review-something-for-new-rule/elm-review-package-tests/check-previews-compile.js @@ -1,16 +1,17 @@ #!/usr/bin/env node -const path = require('path'); +const path = require('node:path'); const Ansi = require('./helpers/ansi'); -const {execSync} = require('child_process'); +const {execSync} = require('node:child_process'); const {findPreviewConfigurations} = require('./helpers/find-configurations'); const packageDependencies = require('../elm.json').dependencies; const root = path.dirname(__dirname); // Find all elm.json files - -findPreviewConfigurations().forEach(checkThatExampleCompiles); +for (const example of findPreviewConfigurations()) { + checkThatExampleCompiles(example); +} function checkThatExampleCompiles(exampleConfiguration) { const exampleConfigurationElmJson = require(`${exampleConfiguration}/elm.json`); @@ -48,7 +49,6 @@ and make the necessary changes to make it compile.` } success(exampleConfiguration); - return; } catch { console.log( `An error occurred while trying to check whether the ${Ansi.yellow( @@ -66,7 +66,7 @@ function success(config) { } function checkDepsAreCompatible(exampleConfiguration, previewDependencies) { - Object.entries(packageDependencies).forEach(([depName, constraint]) => { + for (const [depName, constraint] of Object.entries(packageDependencies)) { if (!(depName in previewDependencies)) { console.error( `Dependency ${depName} is missing in the ${exampleConfiguration}/ configuration` @@ -81,12 +81,13 @@ function checkDepsAreCompatible(exampleConfiguration, previewDependencies) { previewDependencies[depName] ); delete previewDependencies[depName]; - }); + } const remainingKeys = Object.keys(previewDependencies); - if (remainingKeys.length !== 0) { + if (remainingKeys.length > 0) { console.error( - `There are extraneous dependencies in the ${exampleConfiguration}/ configuration: ${remainingKeys}` + // prettier-ignore + `There are extraneous dependencies in the ${exampleConfiguration}/ configuration: ${remainingKeys.join(', ')}` ); process.exit(1); } diff --git a/test/run-snapshots/elm-review-something/elm-review-package-tests/check-previews-compile.js b/test/run-snapshots/elm-review-something/elm-review-package-tests/check-previews-compile.js index 78057dc12..5f55a2c91 100644 --- a/test/run-snapshots/elm-review-something/elm-review-package-tests/check-previews-compile.js +++ b/test/run-snapshots/elm-review-something/elm-review-package-tests/check-previews-compile.js @@ -1,16 +1,17 @@ #!/usr/bin/env node -const path = require('path'); +const path = require('node:path'); const Ansi = require('./helpers/ansi'); -const {execSync} = require('child_process'); +const {execSync} = require('node:child_process'); const {findPreviewConfigurations} = require('./helpers/find-configurations'); const packageDependencies = require('../elm.json').dependencies; const root = path.dirname(__dirname); // Find all elm.json files - -findPreviewConfigurations().forEach(checkThatExampleCompiles); +for (const example of findPreviewConfigurations()) { + checkThatExampleCompiles(example); +} function checkThatExampleCompiles(exampleConfiguration) { const exampleConfigurationElmJson = require(`${exampleConfiguration}/elm.json`); @@ -48,7 +49,6 @@ and make the necessary changes to make it compile.` } success(exampleConfiguration); - return; } catch { console.log( `An error occurred while trying to check whether the ${Ansi.yellow( @@ -66,7 +66,7 @@ function success(config) { } function checkDepsAreCompatible(exampleConfiguration, previewDependencies) { - Object.entries(packageDependencies).forEach(([depName, constraint]) => { + for (const [depName, constraint] of Object.entries(packageDependencies)) { if (!(depName in previewDependencies)) { console.error( `Dependency ${depName} is missing in the ${exampleConfiguration}/ configuration` @@ -81,12 +81,13 @@ function checkDepsAreCompatible(exampleConfiguration, previewDependencies) { previewDependencies[depName] ); delete previewDependencies[depName]; - }); + } const remainingKeys = Object.keys(previewDependencies); - if (remainingKeys.length !== 0) { + if (remainingKeys.length > 0) { console.error( - `There are extraneous dependencies in the ${exampleConfiguration}/ configuration: ${remainingKeys}` + // prettier-ignore + `There are extraneous dependencies in the ${exampleConfiguration}/ configuration: ${remainingKeys.join(', ')}` ); process.exit(1); } diff --git a/tsconfig.json b/tsconfig.json index c06f4be18..8269733bc 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -28,11 +28,5 @@ "test/**/*", "jest.config.js" ], - "exclude": [ - "node_modules", - "**/elm-stuff/", - ".eslintrc.js", - "new-package/elm-review-package-tests/check-previews-compile.js", - "test/temporary" - ] + "exclude": ["node_modules", "**/elm-stuff/", ".eslintrc.js", "test/temporary"] } diff --git a/tsconfig.no-implicit-any.json b/tsconfig.no-implicit-any.json index 404bd5421..39237180f 100644 --- a/tsconfig.no-implicit-any.json +++ b/tsconfig.no-implicit-any.json @@ -32,6 +32,7 @@ "lib/state.js", "lib/styled-message.js", "lib/suppressed-errors.js", + "vendor/exit.js", "jest.config.js" ] } diff --git a/turbo.json b/turbo.json index 92ac8f846..5f173742b 100644 --- a/turbo.json +++ b/turbo.json @@ -23,10 +23,10 @@ ] }, "eslint-check": { - "inputs": ["lib/*", ".eslintrc.js"] + "inputs": ["lib/*", "vendor/*", ".eslintrc.js"] }, "eslint-fix": { - "inputs": ["lib/*", ".eslintrc.js"] + "inputs": ["lib/*", "vendor/*", ".eslintrc.js"] }, "js-check": { "dependsOn": ["eslint-check", "prettier-check"] @@ -35,13 +35,18 @@ "dependsOn": ["eslint-fix", "prettier-fix"] }, "prettier-check": { - "inputs": ["lib/*", ".prettierrc.json", ".prettierignore"] + "inputs": ["lib/*", "vendor/*", ".prettierrc.json", ".prettierignore"] }, "prettier-fix": { - "inputs": ["lib/*", ".prettierrc.json", ".prettierignore"] + "inputs": ["lib/*", "vendor/*", ".prettierrc.json", ".prettierignore"] }, "tsc": { - "inputs": ["lib/*", "tsconfig.json", "tsconfig.*.json"] + "inputs": [ + "lib/*", + "new-package/elm-review-package-tests/**/*.js", + "tsconfig.json", + "tsconfig.*.json" + ] }, "tsc-watch": { "inputs": ["lib/*", "tsconfig.json"], diff --git a/vendor/exit.js b/vendor/exit.js index c4f1abf29..494cea90a 100644 --- a/vendor/exit.js +++ b/vendor/exit.js @@ -1,5 +1,3 @@ -// @ts-nocheck - /* * exit * https://github.com/cowboy/node-exit @@ -12,37 +10,41 @@ /** * @param {number} exitCode - * @param {Array} [streams=undefined] + * @param {Array} [streams] * @returns {never} */ -module.exports = function exit(exitCode, streams) { - if (!streams) { streams = [process.stdout, process.stderr]; } +module.exports = function exit(exitCode, streams = []) { + if (!streams) { + streams = [process.stdout, process.stderr]; + } var drainCount = 0; // Actually exit if all streams are drained. + // @ts-expect-error - This is really `never | void`, but TS isn't smart enough to deal with that later on. + /** @return {never} */ function tryToExit() { if (drainCount === streams.length) { process.exit(exitCode); } } - streams.forEach(function(stream) { + streams.forEach(function (stream) { // Count drained streams now, but monitor non-drained streams. - if (stream.bufferSize === 0) { + if (stream.writableLength === 0) { drainCount++; } else { - stream.write('', 'utf-8', function() { + stream.write('', 'utf-8', function () { drainCount++; tryToExit(); }); } // Prevent further writing. - stream.write = function() {}; + stream.write = () => true; }); // If all streams were already drained, exit now. tryToExit(); // In Windows, when run as a Node.js child process, a script utilizing // this library might just exit with a 0 exit code, regardless. This code, // despite the fact that it looks a bit crazy, appears to fix that. - process.on('exit', function() { + process.on('exit', function () { process.exit(exitCode); }); };