Skip to content

Commit 3679703

Browse files
committed
feat: add support for mise.toml file
1 parent d721415 commit 3679703

File tree

4 files changed

+35
-23
lines changed

4 files changed

+35
-23
lines changed

__tests__/main.test.ts

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -94,23 +94,25 @@ describe('main tests', () => {
9494

9595
describe('getNodeVersionFromFile', () => {
9696
each`
97-
contents | expected
98-
${'12'} | ${'12'}
99-
${'12.3'} | ${'12.3'}
100-
${'12.3.4'} | ${'12.3.4'}
101-
${'v12.3.4'} | ${'12.3.4'}
102-
${'lts/erbium'} | ${'lts/erbium'}
103-
${'lts/*'} | ${'lts/*'}
104-
${'nodejs 12.3.4'} | ${'12.3.4'}
105-
${'ruby 2.3.4\nnodejs 12.3.4\npython 3.4.5'} | ${'12.3.4'}
106-
${''} | ${''}
107-
${'unknown format'} | ${'unknown format'}
108-
${' 14.1.0 '} | ${'14.1.0'}
109-
${'{"volta": {"node": ">=14.0.0 <=17.0.0"}}'}| ${'>=14.0.0 <=17.0.0'}
110-
${'{"volta": {"extends": "./package.json"}}'}| ${'18.0.0'}
111-
${'{"engines": {"node": "17.0.0"}}'} | ${'17.0.0'}
112-
${'[tools]\ngo="latest"\nnode = "24.10"'} | ${'24.10'}
113-
${'{}'} | ${null}
97+
contents | expected
98+
${'12'} | ${'12'}
99+
${'12.3'} | ${'12.3'}
100+
${'12.3.4'} | ${'12.3.4'}
101+
${'v12.3.4'} | ${'12.3.4'}
102+
${'lts/erbium'} | ${'lts/erbium'}
103+
${'lts/*'} | ${'lts/*'}
104+
${'nodejs 12.3.4'} | ${'12.3.4'}
105+
${'ruby 2.3.4\nnodejs 12.3.4\npython 3.4.5'} | ${'12.3.4'}
106+
${''} | ${''}
107+
${'unknown format'} | ${'unknown format'}
108+
${' 14.1.0 '} | ${'14.1.0'}
109+
${'{"volta": {"node": ">=14.0.0 <=17.0.0"}}'} | ${'>=14.0.0 <=17.0.0'}
110+
${'{"volta": {"extends": "./package.json"}}'} | ${'18.0.0'}
111+
${'{"engines": {"node": "17.0.0"}}'} | ${'17.0.0'}
112+
${'[tools]\ngo="latest"\nnode = "24.10"'} | ${'24.10'}
113+
${'[tools]\nnode = { version = "22.20" }'} | ${'22.20'}
114+
${'[tools]\nnode = { postinstall = "corepack enable" }'} | ${null}
115+
${'{}'} | ${null}
114116
`.it('parses "$contents"', ({contents, expected}) => {
115117
const existsSpy = jest.spyOn(fs, 'existsSync');
116118
existsSpy.mockImplementation(() => true);

dist/cache-save/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93333,15 +93333,18 @@ function getNodeVersionFromFile(versionFilePath) {
9333393333
catch (_g) {
9333493334
core.info('Node version file is not JSON file');
9333593335
}
93336-
// Try parsing the file as an MISE `mise.toml` file.
93336+
// Try parsing the file as a mise `mise.toml` file.
9333793337
try {
9333893338
const manifest = (0, js_toml_1.load)(contents);
9333993339
if ((_d = manifest === null || manifest === void 0 ? void 0 : manifest.tools) === null || _d === void 0 ? void 0 : _d.node) {
9334093340
const node = manifest.tools.node;
9334193341
if (typeof node === 'object' && (node === null || node === void 0 ? void 0 : node.version)) {
9334293342
return node.version;
9334393343
}
93344-
return node;
93344+
if (typeof node === 'string') {
93345+
return node;
93346+
}
93347+
return null;
9334593348
}
9334693349
}
9334793350
catch (_h) {

dist/setup/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103848,15 +103848,18 @@ function getNodeVersionFromFile(versionFilePath) {
103848103848
catch (_g) {
103849103849
core.info('Node version file is not JSON file');
103850103850
}
103851-
// Try parsing the file as an MISE `mise.toml` file.
103851+
// Try parsing the file as a mise `mise.toml` file.
103852103852
try {
103853103853
const manifest = (0, js_toml_1.load)(contents);
103854103854
if ((_d = manifest === null || manifest === void 0 ? void 0 : manifest.tools) === null || _d === void 0 ? void 0 : _d.node) {
103855103855
const node = manifest.tools.node;
103856103856
if (typeof node === 'object' && (node === null || node === void 0 ? void 0 : node.version)) {
103857103857
return node.version;
103858103858
}
103859-
return node;
103859+
if (typeof node === 'string') {
103860+
return node;
103861+
}
103862+
return null;
103860103863
}
103861103864
}
103862103865
catch (_h) {

src/util.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export function getNodeVersionFromFile(versionFilePath: string): string | null {
5757
core.info('Node version file is not JSON file');
5858
}
5959

60-
// Try parsing the file as an MISE `mise.toml` file.
60+
// Try parsing the file as a mise `mise.toml` file.
6161
try {
6262
const manifest: Record<string, any> = load(contents);
6363
if (manifest?.tools?.node) {
@@ -67,7 +67,11 @@ export function getNodeVersionFromFile(versionFilePath: string): string | null {
6767
return node.version;
6868
}
6969

70-
return node;
70+
if (typeof node === 'string') {
71+
return node;
72+
}
73+
74+
return null;
7175
}
7276
} catch {
7377
core.info('Node version file is not TOML file');

0 commit comments

Comments
 (0)