Skill update round trip / roundtrip (false, macos-latest, copy, 1.5.17) (push) Canceled after 0s
Skill update round trip / roundtrip (false, macos-latest, symlink, 1.5.17) (push) Canceled after 0s
Skill update round trip / roundtrip (false, ubuntu-latest, copy, 1.5.17) (push) Canceled after 0s
Skill update round trip / roundtrip (false, ubuntu-latest, symlink, 1.5.17) (push) Canceled after 0s
Skill update round trip / roundtrip (false, ubuntu-latest, symlink, latest) (push) Canceled after 0s
Skill update round trip / roundtrip (false, windows-latest, copy, 1.5.17) (push) Canceled after 0s
Skill update round trip / roundtrip (false, windows-latest, symlink, 1.5.17) (push) Canceled after 0s
Skill update round trip / roundtrip (true, macos-latest, copy, 1.5.17) (push) Canceled after 0s
Skill update round trip / roundtrip (true, macos-latest, symlink, 1.5.17) (push) Canceled after 0s
Skill update round trip / roundtrip (true, ubuntu-latest, copy, 1.5.17) (push) Canceled after 0s
Skill update round trip / roundtrip (true, ubuntu-latest, symlink, 1.5.17) (push) Canceled after 0s
Skill update round trip / roundtrip (true, windows-latest, copy, 1.5.17) (push) Canceled after 0s
Skill update round trip / roundtrip (true, windows-latest, symlink, 1.5.17) (push) Canceled after 0s
27 lines
1.0 KiB
JavaScript
27 lines
1.0 KiB
JavaScript
import { copyFileSync, mkdirSync, readFileSync } from 'node:fs'
|
|
import { basename, dirname, join } from 'node:path'
|
|
|
|
/**
|
|
* Copy a script and every co-located module it imports into a fixture's `config/scripts`.
|
|
*
|
|
* Walked rather than listed: a module the script needs but the fixture never copied fails every
|
|
* test in the suite with a module-resolution error that looks nothing like the defect it hides.
|
|
*/
|
|
export function copyScriptWithLocalModules(sourceScriptPath, destinationScriptsDir) {
|
|
mkdirSync(destinationScriptsDir, { recursive: true })
|
|
for (const modulePath of collectScriptModules(sourceScriptPath)) {
|
|
copyFileSync(modulePath, join(destinationScriptsDir, basename(modulePath)))
|
|
}
|
|
}
|
|
|
|
function collectScriptModules(scriptPath, seen = new Set()) {
|
|
if (seen.has(scriptPath)) {
|
|
return seen
|
|
}
|
|
seen.add(scriptPath)
|
|
for (const [, specifier] of readFileSync(scriptPath, 'utf8').matchAll(/from '(\.\/[^']+)'/g)) {
|
|
collectScriptModules(join(dirname(scriptPath), specifier), seen)
|
|
}
|
|
return seen
|
|
}
|