question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Lerna import does not correctly import the file tree

See original GitHub issue

Expected Behavior

I imported another repo with lerna import ../other-repo --preserve-commit --dest=packages. I’d expect that there now is a directory packages/other-repo with all the files from ../other-repo

Current Behavior

Files are missing, and the file tree is different. Unfortunately, I can’t figure out any pattern in how it’s different. Maybe some changes from commits weren’t correctly applied?

lerna.json

{
  "packages": [
    "admin",
    "lib",
    "packages/*",
    "web"
  ],
  "version": "0.0.0"
}

Your Environment

Executable Version
lerna --version 4.0.0
npm --version 7.9.0
node --version 15.11.0
OS macOS Catalina 10.15.7 19H524 x86_64

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:6
  • Comments:10

github_iconTop GitHub Comments

1reaction
jasonbekolaycommented, Mar 16, 2022

FYI I ended up not using lerna import at all. The script we ended up with was something like:

# current directory is the monorepo
# $1 is the repo to import and is a sibling to the current directory
# $2 is the destination path, eg "packages"

function import_git_history {
  REPO_NAME="$1"
  REPO_PATH="../$REPO_NAME"
  DEST_DIR="$2"
  
  pushd "$REPO_PATH"

  git fetch

  if git rev-parse --verify main ; then
    BRANCH_NAME=main
  else
    BRANCH_NAME=master
  fi

  git checkout origin/$BRANCH_NAME
  git checkout -b tmp/monorepo-import

  # move the files to the subdir they will be located at in the
  # monorepo so that git history isn't borked
  git ls-files | xargs bash -e -x -c '
  for file in "$@"; do
    mkdir -p "$0"/`dirname "$file"`
    git mv "$file" "$0"/`dirname "$file"`/
  done' "$DEST_DIR"

  git commit -a -m "Relocating all files from $REPO_NAME to $DEST_DIR before monorepo import"

  popd

  git remote remove import-repo || true
  git remote add -f import-repo "$REPO_PATH"
  git merge --allow-unrelated-histories import-repo/tmp/monorepo-import -m "import $REPO_NAME"

  pushd "$REPO_PATH"
  git checkout $BRANCH_NAME
  git branch -D tmp/monorepo-import
  popd
}
1reaction
JGJPcommented, Mar 16, 2022

Any verdict on this? Sounds like a pretty serious issue

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshooting | Lerna
Run lerna import with the --flatten flag to import the history in "flat" mode, i.e. with each merge commit as a single change...
Read more >
Is there a way to "refresh" an imported repository with Lerna?
The lerna import command takes all the commits from your original repository, reverses and replays them. However there's no way to replay these ......
Read more >
@lerna/import - npm Package Health Analysis | Snyk
This is useful for gathering pre-existing standalone packages into a Lerna repo. Each commit is modified to make changes relative to the package...
Read more >
eslint-plugin-import - npm
Ensure imports point to a file/module that can be resolved. ... your project's working tree npm install eslint-plugin-import --save-dev.
Read more >
Configuring TypeScript for multiple packages in a Lerna + ...
The aim of this article will be so you can import TypeScript code from ... serves as a base directory to resolve non-relative...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found