-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create preversion script to check exports
It would be easy to forget to add or remove a class from package.json, index.js, or README.md. Check that all classes are present before changing the package version. Signed-off-by: Kevin Locke <[email protected]>
- Loading branch information
Showing
3 changed files
with
59 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#!/usr/bin/env node | ||
/** | ||
* @copyright Copyright 2024 Kevin Locke <[email protected]> | ||
* @license MIT | ||
*/ | ||
|
||
/* eslint-disable no-console */ | ||
|
||
import { readdir, readFile } from 'node:fs/promises'; | ||
import path from 'node:path'; | ||
import { fileURLToPath } from 'node:url'; | ||
import { debuglog } from 'node:util'; | ||
|
||
const debug = debuglog('openapi-transformers-preversion'); | ||
|
||
const packagePath = path.dirname(path.dirname(fileURLToPath(import.meta.url))); | ||
|
||
const indexJsPath = path.join(packagePath, 'index.js'); | ||
const indexJs = await readFile(indexJsPath, { encoding: 'utf8' }); | ||
|
||
const packageJsonPath = path.join(packagePath, 'package.json'); | ||
const packageJsonStr = await readFile(packageJsonPath, { encoding: 'utf8' }); | ||
const packageJson = JSON.parse(packageJsonStr); | ||
|
||
const readmePath = path.join(packagePath, 'README.md'); | ||
const readme = await readFile(readmePath, { encoding: 'utf8' }); | ||
|
||
let errors = 0; | ||
const packageFiles = await readdir(packagePath); | ||
for (const packageFile of packageFiles) { | ||
if (packageFile.slice(-3) === '.js' | ||
&& packageFile !== 'index.js') { | ||
debug('Checking %s...', packageFile); | ||
|
||
const dotPackageFile = `./${packageFile}`; | ||
|
||
if (!indexJs.includes(dotPackageFile)) { | ||
console.error('Error: %s not exported from index.js', dotPackageFile); | ||
errors += 1; | ||
} | ||
|
||
if (packageJson.exports[dotPackageFile] !== dotPackageFile) { | ||
console.error('Error: %s not in package.json#exports', dotPackageFile); | ||
errors += 1; | ||
} | ||
|
||
if (!readme.includes(dotPackageFile)) { | ||
console.error('Error: %s not in README.md', dotPackageFile); | ||
errors += 1; | ||
} | ||
} | ||
} | ||
|
||
debug('preversion checks completed with %d errors', errors); | ||
|
||
process.exitCode = errors > 0 ? 1 : 0; |