mirror of
https://github.com/actions/setup-node.git
synced 2026-08-14 23:12:08 +08:00
feat: add support for mise.toml file (#1421)
* feat: add support for mise.toml file feat: add support for mise.toml file feat: update licensed cache feat: switch from js-toml to smol-toml to reduce deps and bundle size * feat: added docs and improved tests * feat: added docs and improved tests * ci: fix ci * ci: fix ci
This commit is contained in:
+21
@@ -1,6 +1,7 @@
|
||||
import * as core from '@actions/core';
|
||||
import * as exec from '@actions/exec';
|
||||
import * as io from '@actions/io';
|
||||
import {parse} from 'smol-toml';
|
||||
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
@@ -68,6 +69,26 @@ export function getNodeVersionFromFile(versionFilePath: string): string | null {
|
||||
core.info('Node version file is not JSON file');
|
||||
}
|
||||
|
||||
// Try parsing the file as a mise `mise.toml` file.
|
||||
try {
|
||||
const manifest: Record<string, any> = parse(contents);
|
||||
if (manifest?.tools?.node) {
|
||||
const node = manifest.tools.node;
|
||||
|
||||
if (typeof node === 'object' && node?.version) {
|
||||
return node.version;
|
||||
}
|
||||
|
||||
if (typeof node === 'string') {
|
||||
return node;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
} catch {
|
||||
core.info('Node version file is not TOML file');
|
||||
}
|
||||
|
||||
const found = contents.match(/^(?:node(js)?\s+)?v?(?<version>[^\s]+)$/m);
|
||||
return found?.groups?.version ?? contents.trim();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user