Skip to content

Commit fd028e1

Browse files
committed
feat: add support for mise.toml file
1 parent 50a9caa commit fd028e1

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
@@ -48307,15 +48307,18 @@ function getNodeVersionFromFile(versionFilePath) {
4830748307
catch {
4830848308
core.info('Node version file is not JSON file');
4830948309
}
48310-
// Try parsing the file as an MISE `mise.toml` file.
48310+
// Try parsing the file as a mise `mise.toml` file.
4831148311
try {
4831248312
const manifest = (0, js_toml_1.load)(contents);
4831348313
if (manifest?.tools?.node) {
4831448314
const node = manifest.tools.node;
4831548315
if (typeof node === 'object' && node?.version) {
4831648316
return node.version;
4831748317
}
48318-
return node;
48318+
if (typeof node === 'string') {
48319+
return node;
48320+
}
48321+
return null;
4831948322
}
4832048323
}
4832148324
catch {

dist/setup/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58845,15 +58845,18 @@ function getNodeVersionFromFile(versionFilePath) {
5884558845
catch {
5884658846
core.info('Node version file is not JSON file');
5884758847
}
58848-
// Try parsing the file as an MISE `mise.toml` file.
58848+
// Try parsing the file as a mise `mise.toml` file.
5884958849
try {
5885058850
const manifest = (0, js_toml_1.load)(contents);
5885158851
if (manifest?.tools?.node) {
5885258852
const node = manifest.tools.node;
5885358853
if (typeof node === 'object' && node?.version) {
5885458854
return node.version;
5885558855
}
58856-
return node;
58856+
if (typeof node === 'string') {
58857+
return node;
58858+
}
58859+
return null;
5885758860
}
5885858861
}
5885958862
catch {

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)