( updater: (currentConfig: ProjectConfig) => ProjectConfig, )
| 1691 | } |
| 1692 | |
| 1693 | export function saveCurrentProjectConfig( |
| 1694 | updater: (currentConfig: ProjectConfig) => ProjectConfig, |
| 1695 | ): void { |
| 1696 | if (process.env.NODE_ENV === 'test') { |
| 1697 | const config = updater(TEST_PROJECT_CONFIG_FOR_TESTING) |
| 1698 | // Skip if no changes (same reference returned) |
| 1699 | if (config === TEST_PROJECT_CONFIG_FOR_TESTING) { |
| 1700 | return |
| 1701 | } |
| 1702 | Object.assign(TEST_PROJECT_CONFIG_FOR_TESTING, config) |
| 1703 | return |
| 1704 | } |
| 1705 | const absolutePath = getProjectPathForConfig() |
| 1706 | const globalConfigFile = getGlobalNcodeFile() |
| 1707 | |
| 1708 | if (blockedConfigWrites.has(globalConfigFile)) { |
| 1709 | const config = |
| 1710 | globalConfigCache.config ?? getConfig(globalConfigFile, createDefaultGlobalConfig) |
| 1711 | const currentProjectConfig = |
| 1712 | config.projects?.[absolutePath] ?? DEFAULT_PROJECT_CONFIG |
| 1713 | const newProjectConfig = updater(currentProjectConfig) |
| 1714 | if (newProjectConfig === currentProjectConfig) { |
| 1715 | return |
| 1716 | } |
| 1717 | writeThroughGlobalConfigCache({ |
| 1718 | ...config, |
| 1719 | projects: { |
| 1720 | ...config.projects, |
| 1721 | [absolutePath]: newProjectConfig, |
| 1722 | }, |
| 1723 | }) |
| 1724 | return |
| 1725 | } |
| 1726 | |
| 1727 | let written: GlobalConfig | null = null |
| 1728 | try { |
| 1729 | const didWrite = saveConfigWithLock( |
| 1730 | globalConfigFile, |
| 1731 | createDefaultGlobalConfig, |
| 1732 | current => { |
| 1733 | const currentProjectConfig = |
| 1734 | current.projects?.[absolutePath] ?? DEFAULT_PROJECT_CONFIG |
| 1735 | const newProjectConfig = updater(currentProjectConfig) |
| 1736 | // Skip if no changes (same reference returned) |
| 1737 | if (newProjectConfig === currentProjectConfig) { |
| 1738 | return current |
| 1739 | } |
| 1740 | written = { |
| 1741 | ...current, |
| 1742 | projects: { |
| 1743 | ...current.projects, |
| 1744 | [absolutePath]: newProjectConfig, |
| 1745 | }, |
| 1746 | } |
| 1747 | return written |
| 1748 | }, |
| 1749 | ) |
| 1750 | if (didWrite && written) { |
no test coverage detected