Skip to content

Commit 4f2b2fd

Browse files
committed
feat: add support for mise.toml file
1 parent 58a435d commit 4f2b2fd

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
@@ -75721,15 +75721,18 @@ function getNodeVersionFromFile(versionFilePath) {
7572175721
catch {
7572275722
core.info('Node version file is not JSON file');
7572375723
}
75724-
// Try parsing the file as an MISE `mise.toml` file.
75724+
// Try parsing the file as a mise `mise.toml` file.
7572575725
try {
7572675726
const manifest = (0, js_toml_1.load)(contents);
7572775727
if (manifest?.tools?.node) {
7572875728
const node = manifest.tools.node;
7572975729
if (typeof node === 'object' && node?.version) {
7573075730
return node.version;
7573175731
}
75732-
return node;
75732+
if (typeof node === 'string') {
75733+
return node;
75734+
}
75735+
return null;
7573375736
}
7573475737
}
7573575738
catch {

dist/setup/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86259,15 +86259,18 @@ function getNodeVersionFromFile(versionFilePath) {
8625986259
catch {
8626086260
core.info('Node version file is not JSON file');
8626186261
}
86262-
// Try parsing the file as an MISE `mise.toml` file.
86262+
// Try parsing the file as a mise `mise.toml` file.
8626386263
try {
8626486264
const manifest = (0, js_toml_1.load)(contents);
8626586265
if (manifest?.tools?.node) {
8626686266
const node = manifest.tools.node;
8626786267
if (typeof node === 'object' && node?.version) {
8626886268
return node.version;
8626986269
}
86270-
return node;
86270+
if (typeof node === 'string') {
86271+
return node;
86272+
}
86273+
return null;
8627186274
}
8627286275
}
8627386276
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)