Skip to content

Running dev:prepare in the root of a module behaves differently than preparing in the playground #704

Description

@cernymatej

@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

  1. run pnpm dev:prepare in the root of the project
  2. 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",

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions