Skip to content

Commit

Permalink
fix(parse): coerce version prerelease type to string (#184)
Browse files Browse the repository at this point in the history
This PR fixes a type error.

```shell
TypeError: parsedVersion?.prerelease[0]?.endsWith is not a function
 ❯ parse node_modules/nw/src/parse.js:49:39
 ❯ Module.findpath node_modules/nw/src/util.js:51:15
```
  • Loading branch information
ayushmanchhabra authored Jun 22, 2024
1 parent 73da39a commit 992aa86
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default async function parse(options) {
parsedVersion.patch
].join('.');
options.flavor = options.flavor || process.env.npm_config_nwjs_build_type || process.env.NWJS_BUILD_TYPE || 'normal';
if (parsedVersion?.prerelease[0]?.endsWith('sdk')) {
if (String(parsedVersion?.prerelease[0]).endsWith('sdk')) {
options.flavor = 'sdk';
}
options.platform = options.platform || util.PLATFORM_KV[process.env.npm_config_nwjs_platform || process.env.NWJS_PLATFORM || process.platform];
Expand Down
11 changes: 3 additions & 8 deletions test/findpath.test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import fs from 'node:fs';
import { expect, test } from 'vitest';

import util from '../src/util.js';

test('nwjs has downloaded and been extracted', function () {
util.findpath('nwjs', { flavor: 'sdk' }).then(function (path) {
expect(fs.existsSync(path)).toEqual(true);
})
.catch((error) => {
console.log(error);
});
test('nwjs has downloaded and been extracted', async function () {
const path = await util.findpath('nwjs', { flavor: 'sdk' });
expect(util.fileExists(path)).resolves.toEqual(true);
});

0 comments on commit 992aa86

Please sign in to comment.