@lewebsimple pointed out an edge case where, if a module checks for the existence of a certain file, running the dev:prepare script will fail when executed from the root of the module (via @nuxt/module-builder).
Reproduction
https://github.com/lewebsimple/nuxt-module-layers-repro
const rootDirs = getLayerDirectories().map(({ root }) => root)
let discoverMePath
for (const rootDir of rootDirs) {
if (existsSync(`${rootDir}/discover-me.txt`)) {
discoverMePath = `${rootDir}/discover-me.txt`
logger.info(`Found discover-me.txt in layer: ${rootDir}`)
break
}
}
if (!discoverMePath) {
throw new Error('Required file discover-me.txt not found in any layer directories.')
}
Steps to reproduce
- run
pnpm dev:prepare in the root of the project
- see that it fails
Additional context
This happens because the module's setup function runs initially without taking the playground directory into account, and only afterward does it run separately for the playground.
"dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",