With HMR, installing, enabling, disabling and removing bundles take effect live. Each profile recomposition compares the loaded modules below the profile directory and its linked targets with disk, stops the plugins whose files changed, and recomposes the profile through app-boot's recomposeProfile(): the rows the next generation drops are removed first, the latest runtime resolution is published once, and the generation is applied and judged. Afterwards HMR evicts the modules below the mappings the recomposition dropped. - app-boot: recomposeProfile(); PluginPackages.resolution; ResolutionRestartRequired; the resolver accepts in-place version changes and relinks, and relocates Node's cached link real paths. - plugin-manager: with HMR, installBundle refuses an installed package (already-installed), so an upgrade is a removal and an installation; every restart-required result carries a restartReason; removal uses the registry the package was installed from. - ui-plugin-manager: the Official Update removes and then installs; restart prompts name their reason.
25 lines
959 B
TypeScript
25 lines
959 B
TypeScript
/** The file clock ModuleFiles compares module files with. */
|
|
import * as fs from 'node:fs'
|
|
import { expect, it, vi } from 'vitest'
|
|
import { ModuleFiles } from '../src/module-files.ts'
|
|
|
|
vi.mock('node:fs', async original => ({ ...await original<typeof import('node:fs')>() }))
|
|
|
|
it('reads the time from a new marker file and removes it', () => {
|
|
const created = vi.spyOn(fs, 'mkdtempSync')
|
|
try {
|
|
const time = new ModuleFiles().now()
|
|
expect(time).toBeGreaterThan(0)
|
|
const directory = created.mock.results[0]?.value as string
|
|
expect(fs.existsSync(directory)).toBe(false)
|
|
} finally { created.mockRestore() }
|
|
})
|
|
|
|
it('falls back to the system clock when no marker can be created', () => {
|
|
const created = vi.spyOn(fs, 'mkdtempSync').mockImplementationOnce(() => { throw new Error('read-only') })
|
|
try {
|
|
const before = Date.now()
|
|
expect(new ModuleFiles().now()).toBeGreaterThanOrEqual(before)
|
|
} finally { created.mockRestore() }
|
|
})
|