diff --git a/package.json b/package.json index 3f3b0515d..141aec741 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "node": ">=12.20" }, "scripts": { - "test": "xo && tsd && tsc" + "test": "xo && tsd && tsc && node script/test/source-files-extension.js" }, "files": [ "index.d.ts", diff --git a/script/test/source-files-extension.js b/script/test/source-files-extension.js new file mode 100755 index 000000000..b29664be6 --- /dev/null +++ b/script/test/source-files-extension.js @@ -0,0 +1,26 @@ +/* eslint-disable unicorn/prefer-module */ +const fs = require('fs'); +const process = require('process'); + +const checkSourceFilesExtension = async () => { + try { + const files = await fs.promises.readdir('source'); + + let hasIncorrectFileExtension = false; + for (const file of files) { + if (!file.endsWith('.d.ts')) { + hasIncorrectFileExtension = true; + console.error(`source/${file} extension should be \`.d.ts\`.`); + } + } + + if (hasIncorrectFileExtension) { + process.exitCode = 1; + } + } catch (error) { + console.error(error); + process.exitCode = 1; + } +}; + +checkSourceFilesExtension();