Skip to content

Submodules :: Hook Should Work Both Inside & Outside Docker Containers #230

@lots0logs

Description

@lots0logs

When the hook is installed in a git submodule the return value of getNodeModulesAbsoluteEntryPoint() is a static path from the time the hook file was generated. This causes problems if you are using containers as part of your dev workflow. Basically the hook fails if you run git from outside the container when the hook was installed from inside the container (and vise-versa).

Doing something like the following should solve the problem:

let _nodeModulesPath = path.resolve(__dirname, '../', '../', 'node_modules')

  if (! fs.existsSync(_nodeModulesPath)) {
    // We might be in a git submodule
    const prefix = __dirname.split(/[/\\]\.git[/\\]/).shift()
    const suffix = __dirname.split(/[/\\]hooks[/\\]/).pop()

    _nodeModulesPath = path.resolve(path.relative(__dirname, `${prefix}${path.sep}${suffix}`), 'node_modules')
  }

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