Skip to content

Commit

Permalink
fix: throw an error if running with an unsupported version of nodejs (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith authored Apr 27, 2020
1 parent 8eef5cb commit 94fdf1e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
> Google TypeScript Style
[![NPM Version][npm-image]][npm-url]
[![CircleCI][circle-image]][circle-url]
[![GitHub Actions][github-image]][github-url]
[![Dependency Status][david-image]][david-url]
[![Known Vulnerabilities][snyk-image]][snyk-url]
[![codecov][codecov-image]][codecov-url]
Expand Down Expand Up @@ -74,6 +74,9 @@ Show your love for `gts` and include a badge!
[![Code Style: Google](https://img.shields.io/badge/code%20style-google-blueviolet.svg)](https://github.com/google/gts)
```

## Supported Node.js Versions
Our client libraries follow the [Node.js release schedule](https://nodejs.org/en/about/releases/). Libraries are compatible with all current _active_ and _maintenance_ versions of Node.js.

## License
[Apache-2.0](LICENSE)

Expand All @@ -82,8 +85,8 @@ Made with ❤️ by the Google Node.js team.

> ***NOTE: This is not an official Google product.***
[circle-image]: https://circleci.com/gh/google/gts.svg?style=shield
[circle-url]: https://circleci.com/gh/google/gts
[github-image]: https://github.com/google/gts/workflows/ci/badge.svg
[github-url]: https://github.com/google/gts/actions
[prettier-url]: https://prettier.io/
[codecov-image]: https://codecov.io/gh/google/gts/branch/master/graph/badge.svg
[codecov-url]: https://codecov.io/gh/google/gts
Expand Down
22 changes: 21 additions & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,34 @@ const cli = meow({
},
});

/**
* Get the current version of node.js being run.
* Exported purely for stubbing purposes.
* @private
*/
export function getNodeVersion() {
return process.version;
}

function usage(msg?: string): void {
if (msg) {
logger.error(msg);
}
cli.showHelp(1);
}

async function run(verb: string, files: string[]): Promise<boolean> {
export async function run(verb: string, files: string[]): Promise<boolean> {
// throw if running on an old version of nodejs
const nodeMajorVersion = Number(getNodeVersion().slice(1).split('.')[0]);
console.log(`version: ${nodeMajorVersion}`);
if (nodeMajorVersion < 10) {
throw new Error(
`gts requires node.js 10.x or up. You are currently running
${process.version}, which is not supported. Please upgrade to
a safe, secure version of nodejs!`
);
}

const options = {
dryRun: cli.flags.dryRun || false,
// Paths are relative to the transpiled output files.
Expand Down
2 changes: 0 additions & 2 deletions test/test-clean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ describe('clean', () => {
};

it('should gracefully error if tsconfig is missing', () => {
// eslint-disable-next-line node/no-unsupported-features/node-builtins
return assert.rejects(() =>
withFixtures({}, async () => {
await clean(OPTIONS);
Expand All @@ -61,7 +60,6 @@ describe('clean', () => {
});

it('should ensure that outDir is local to targetRoot', () => {
// eslint-disable-next-line node/no-unsupported-features/node-builtins
return assert.rejects(() =>
withFixtures(
{
Expand Down

0 comments on commit 94fdf1e

Please sign in to comment.