Skip to content

Commit

Permalink
chore: enable noImplicitAny on new-package/
Browse files Browse the repository at this point in the history
  • Loading branch information
lishaduck committed Nov 4, 2024
1 parent fd34ca9 commit 6e1c367
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 5 deletions.
23 changes: 22 additions & 1 deletion new-package/elm-review-package-tests/check-previews-compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ for (const example of findPreviewConfigurations()) {
checkThatExampleCompiles(example);
}

/**
* @param {string} exampleConfiguration
*/
function checkThatExampleCompiles(exampleConfiguration) {
const exampleConfigurationElmJson = require(`${exampleConfiguration}/elm.json`);

Expand Down Expand Up @@ -62,10 +65,17 @@ and make the necessary changes to make it compile.`
}
}

/**
* @param {string} config
*/
function success(config) {
console.log(`${Ansi.green('✔')} ${path.relative(root, config)}/ compiles`);
}

/**
* @param {string} exampleConfiguration
* @param {Record<string, string>} previewDependencies
*/
function checkDepsAreCompatible(exampleConfiguration, previewDependencies) {
for (const [depName, constraint] of Object.entries(packageDependencies)) {
if (!(depName in previewDependencies)) {
Expand Down Expand Up @@ -94,6 +104,12 @@ function checkDepsAreCompatible(exampleConfiguration, previewDependencies) {
}
}

/**
* @param {string} exampleConfiguration
* @param {string} depName
* @param {string} constraint
* @param {string} version
*/
function checkConstraint(exampleConfiguration, depName, constraint, version) {
const [minVersion] = constraint.split(' <= v < ').map(splitVersion);
const previewVersion = splitVersion(version);
Expand All @@ -110,6 +126,11 @@ function checkConstraint(exampleConfiguration, depName, constraint, version) {
}
}

/**
* @param {string} version
*/
function splitVersion(version) {
return version.split('.').map((n) => Number.parseInt(n, 10));
return version
.split('.')
.map((/** @type {string} */ n) => Number.parseInt(n, 10));
}
15 changes: 12 additions & 3 deletions new-package/elm-review-package-tests/helpers/ansi.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
/**
* @param {string} text
*/
function red(text) {
return '\u001B[31m' + text + '\u001B[39m';
return `\u001B[31m${text}\u001B[39m`;
}

/**
* @param {string} text
*/
function green(text) {
return '\u001B[32m' + text + '\u001B[39m';
return `\u001B[32m${text}\u001B[39m`;
}

/**
* @param {string} text
*/
function yellow(text) {
return '\u001B[33m' + text + '\u001B[39m';
return `\u001B[33m${text}\u001B[39m`;
}

module.exports = {
Expand Down
20 changes: 19 additions & 1 deletion new-package/maintenance/update-examples-from-preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,28 @@ if (require.main === module) {

// Find all elm.json files

/**
* @typedef {object} ApplicationElmJson
* @property {string[]} source-directories
* @property {DependencyList} dependencies
*/

/**
* @typedef {object} DependencyList
* @property {Record<string, string>} direct
* @property {Record<string, string>} indirect
*/

function copyPreviewsToExamples() {
const previewFolders = findPreviewConfigurations();
for (const folder of previewFolders) {
copyPreviewToExample(folder);
}
}

/**
* @param {string} pathToPreviewFolder
*/
function copyPreviewToExample(pathToPreviewFolder) {
const pathToExampleFolder = `${pathToPreviewFolder}/`.replace(
/preview/g,
Expand All @@ -32,7 +47,10 @@ function copyPreviewToExample(pathToPreviewFolder) {
fs.copySync(pathToPreviewFolder, pathToExampleFolder, {overwrite: true});

const pathToElmJson = path.resolve(pathToExampleFolder, 'elm.json');
const elmJson = fs.readJsonSync(pathToElmJson);
const elmJson =
/** @type {{ ['source-directories']: string[], dependencies: {direct: Record<string, string>} }} */ (
fs.readJsonSync(pathToElmJson)
);

// Remove the source directory pointing to the package's src/
elmJson['source-directories'] = elmJson['source-directories'].filter(
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 @@ -58,6 +58,7 @@
"lib/template-dependencies.js",
"lib/utils.js",
"lib/watch.js",
"new-package/elm-review-package-tests/*.js",
"test/jest-helpers/cli.js",
"test/jest-helpers/types/cli.ts",
"test/flags.test.js",
Expand Down

0 comments on commit 6e1c367

Please sign in to comment.