Skip to content

Lerna import#173

Merged
hzoo merged 14 commits intolerna:masterfrom
gigabo:lerna-import
Jun 23, 2016
Merged

Lerna import#173
hzoo merged 14 commits intolerna:masterfrom
gigabo:lerna-import

Conversation

@gigabo
Copy link
Copy Markdown
Contributor

@gigabo gigabo commented Jun 2, 2016

The problem: I have a package in a stand-alone repository that I want to pull into a lerna repo.

The solution: lerna import.

Imports a package from a foreign repository with commit history.

@gigabo
Copy link
Copy Markdown
Contributor Author

gigabo commented Jun 3, 2016

Pretty sweet progress bar experience with enough git history to import:

tty

@jamiebuilds
Copy link
Copy Markdown
Contributor

I really really like this. Thanks for doing this.

Can you use the name "external" instead of "foreign"?


this.commits.forEach(sha => {
progressBar.tick(sha);
const patch = this.foreignExecSync(`git format-patch -1 ${sha} --stdout`)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment explaining what is happening here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added.

@gigabo
Copy link
Copy Markdown
Contributor Author

gigabo commented Jun 6, 2016

Can you use the name "external" instead of "foreign"?

Yes, that's a better name. Done.

README.md Outdated
$ lerna import <path-to-external-repository>
```

Import the package at `<path-to-external-repository>`, with commit history.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to be more verbose here, you can mention that the package x is imported into packages/x and maybe an example. You can even use lerna-changelog as the example?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some more detail here. I worry that using lerna-changelog as an example might be confusing, since it has "lerna" in the name, so I continued to use placeholders.

I also lower-cased the section heading to match the changes from @kaicataldo over the weekend (which I've picked up via rebase).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah you're right - maybe babel would of been a better example but all good

README.md Outdated
into `packages/<package-name>`. Original commit authors, dates and messages
are preserved. Commits are applied to the current branch.

This is useful for gathering pre-exising standalone packages into a Lerna
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exising -> existing

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops! Thanks.

if (!packageName) {
throw new Error(`No package name specified in "${packageJson}"`);
}
this.targetDir = "packages/"+packageName;
Copy link
Copy Markdown
Contributor

@hzoo hzoo Jun 7, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can do packages/${packageName} here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, though I've tended not to when concatenating a single string constant with a single variable, since a template string is actually longer in that case. How about I add some space around the operator? That's the same length, but involves less punctuation. Seems to fit with context, too.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah the style has been to usually have whitespace between operators (we should add space-infix-ops)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should add space-infix-ops

#188

@hzoo
Copy link
Copy Markdown
Contributor

hzoo commented Jun 7, 2016

👍

@jamiebuilds
Copy link
Copy Markdown
Contributor

Can you add a test that --yes works?

@gigabo
Copy link
Copy Markdown
Contributor Author

gigabo commented Jun 9, 2016

--yes was not supported. Added support and a test.

@gigabo
Copy link
Copy Markdown
Contributor Author

gigabo commented Jun 9, 2016

Looks like the latest build may have had a spurious failure in one environment. I'm not able to retry.

@jamiebuilds
Copy link
Copy Markdown
Contributor

--yes was not supported.

Weird, I thought PromptUtilities.confirm supported that all the time

@hzoo
Copy link
Copy Markdown
Contributor

hzoo commented Jun 9, 2016

There's a merge conflict b/c of the last PR

@gigabo
Copy link
Copy Markdown
Contributor Author

gigabo commented Jun 9, 2016

Rebased.

@jamiebuilds
Copy link
Copy Markdown
Contributor

Oh fucking hell, merged another one of your PRs and it needs another rebase. 🃏

@hzoo
Copy link
Copy Markdown
Contributor

hzoo commented Jun 9, 2016

blah I hope it's not because of the readme

@gigabo
Copy link
Copy Markdown
Contributor Author

gigabo commented Jun 9, 2016

Rebased again.

blah I hope it's not because of the readme

Nope, lerna.js and index.js this time. 😛

@hzoo
Copy link
Copy Markdown
Contributor

hzoo commented Jun 10, 2016

Would be nice to use lerna here and do a canary release - can try a publish manually

throw new Error(`Input path "${inputPath}" is not a directory`);
}
const packageJson = path.join(externalRepoPath, "package.json");
const packageName = require(packageJson).name;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to make a specific error message here or no? (if the package path doesn't have a package.json)

Errored while running ImportCommand.initialize
Error: Cannot find module '/module/package.json'

@hzoo
Copy link
Copy Markdown
Contributor

hzoo commented Jun 11, 2016

Testing it out locally - do we want have an option to add a prefix or no? Like in babel everything is called babel-, and I assume when you import the packages are in like babel/generator and when you import you might want it to be called babel-generator (or for scoped modules)

maybe like lerna import ../generator --prefix generator or just the next be the new folder/package name like lerna import ../generator babel-generator ``lerna import ../generator --name babel-generator`

Not a blocker and can be a further improvement

@hzoo
Copy link
Copy Markdown
Contributor

hzoo commented Jun 11, 2016

Another simple error we can add in is if you have already imported that repo in before (either by name or git log, package.json, etc)

@gigabo gigabo force-pushed the lerna-import branch 2 times, most recently from 7a0afd2 to 7f0ebd9 Compare June 18, 2016 00:10
@gigabo
Copy link
Copy Markdown
Contributor Author

gigabo commented Jun 18, 2016

Rebased, added some tests, did these two things and got it running in node 0.10.


this.targetDir = "packages/" + externalRepoBase;

let targetDirExists;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this block could be

try {
  fs.statSync(this.targetDir);
} catch (e) { 
  return callback(new Error(`Target directory already exists "${this.targetDir}"`));
}

right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I spent some time trying to come up with a simpler check here. What you posted above is nicer looking, but it is actually the inverse of what we want: It returns an error when the target directory does not exist.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right my bad, read the code again now.
How about

try {
  if (fs.statSync(this.targetDir)) {
    return callback(new Error(`Target directory already exists "${this.targetDir}"`));
  }
} catch (e) { /* Pass */ }

This is a nit anyway :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it! Always glad to be rid of a variable. 👹

@hzoo
Copy link
Copy Markdown
Contributor

hzoo commented Jun 22, 2016

There's a docs fix to add, but other than that I'm good with landing this and we can improve as it's tested/used?

@gigabo
Copy link
Copy Markdown
Contributor Author

gigabo commented Jun 23, 2016

Need to rebase again and back out the changes to support node 0.10.

@gigabo
Copy link
Copy Markdown
Contributor Author

gigabo commented Jun 23, 2016

Rebased and updated docs.

@hzoo hzoo merged commit 599aae4 into lerna:master Jun 23, 2016
gigabo added a commit to gigabo/lerna that referenced this pull request Jun 23, 2016
That last commit in lerna#173 updated _one_ reference to package name, but missed another.
hzoo pushed a commit that referenced this pull request Jun 23, 2016
That last commit in #173 updated _one_ reference to package name, but missed another.
LoicMahieu added a commit to LoicMahieu/lerna that referenced this pull request Jun 28, 2016
* feature/pkg-main:
  Bootstrap: copy `main` property from package.json
  2.0.0-beta.23
  fix execSync use
  Add `onlyExplicitUpdates` flag so that only packages that have changed have version bumps rather than all packages that depend on the updated packages (lerna#241)
  Re-introduce node 0.10 support (lerna#248)
  2.0.0-beta.22
  Consistent naming in README `import` section (lerna#243) [skip ci]
  Lerna import (lerna#173)
  Revert "Use sync-exec for node 0.10" (lerna#242)
  Revert "Fix bootstrap install to use quotes around versions (lerna#235)"
  2.0.0-beta.21
  Fix bootstrap install to use quotes around versions (lerna#235)
  typo [skip ci]

# Conflicts:
#	src/commands/BootstrapCommand.js
@lock
Copy link
Copy Markdown

lock bot commented Dec 28, 2018

This thread has been automatically locked because there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Dec 28, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants