yarnScriptParserDirectives top-level property

Map<String, dynamic> yarnScriptParserDirectives
final

Implementation

final Map<String, dynamic> yarnScriptParserDirectives = {
  'alias': (String token, FigExecuteCommandFunction executeShellCommand) async {
    final npmPrefixResult = await executeShellCommand(
      command: 'npm',
      args: ['prefix'],
    );

    if (npmPrefixResult.status != 0) {
      throw Exception('npm prefix command failed');
    }

    final packageJsonResult = await executeShellCommand(
      command: 'cat',
      args: ['${npmPrefixResult.stdout.trim()}/package.json'],
    );

    final packageContent =
        jsonDecode(packageJsonResult.stdout) as Map<String, dynamic>;
    final scripts = packageContent['scripts'] as Map<String, dynamic>?;
    final script = scripts?[token];

    if (script == null) {
      throw Exception('Script not found: \'$token\'');
    }
    return script;
  },
};