Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): introduce nx import #26847

Merged
merged 1 commit into from
Aug 12, 2024
Merged

feat(core): introduce nx import #26847

merged 1 commit into from
Aug 12, 2024

Conversation

FrozenPandaz
Copy link
Collaborator

@FrozenPandaz FrozenPandaz commented Jul 5, 2024

Current Behavior

Importing other projects/ repositories into an Nx workspace is a natural part of the Nx adoption story. However, there is no easy built in way of handling this while maintaining git history.

Expected Behavior

nx import is a new command which allows teams to merge code from other repositories into a Nx workspace.

https://asciinema.org/a/oQiA9qOvA2z85AQvVJ5QRVTp1

Related Issue(s)

Fixes #

Copy link

vercel bot commented Jul 5, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Updated (UTC)
nx-dev ⬜️ Ignored (Inspect) Visit Preview Aug 12, 2024 8:53pm

Copy link

🐳 We have a release for that!

This PR has a release associated with it. You can try it out using this command:

npx [email protected] my-workspace

Or just copy this version and use it in your own command:

0.0.0-pr-26847-80c36f5
Release details 📑
Published version 0.0.0-pr-26847-80c36f5
Triggered by @FrozenPandaz
Branch nx-import
Commit 80c36f5
Workflow run 9996161849

To request a new release for this pull request, mention someone from the Nx team or the @nrwl/nx-pipelines-reviewers.

@FrozenPandaz FrozenPandaz self-assigned this Jul 22, 2024
@FrozenPandaz FrozenPandaz force-pushed the nx-import branch 6 times, most recently from 615f0e3 to 6e5743d Compare August 2, 2024 19:45
@FrozenPandaz FrozenPandaz force-pushed the nx-import branch 4 times, most recently from d8d201f to c317fec Compare August 8, 2024 14:35
@FrozenPandaz FrozenPandaz force-pushed the nx-import branch 3 times, most recently from fb3d93f to a2b1a9c Compare August 9, 2024 17:14
type: 'input',
name: 'sourceRemoteUrl',
message:
'What is the Remote URL of the repository you want to import?',
Copy link
Member

Choose a reason for hiding this comment

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

We can rephrase this to also include local directories.

Copy link
Member

Choose a reason for hiding this comment

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

Should test and verify the path passed if it's local

}

if (!source) {
source = (
Copy link
Member

@jaysoo jaysoo Aug 9, 2024

Choose a reason for hiding this comment

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

Validate this exists.

Q: Can we validate the project? Maybe after import we can verify and log out some hints if things didn't work.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Validated

`Fetching ${ref} from ${sourceRemoteUrl}`
);
await gitClient.addFetchRemote('origin', ref);
await gitClient.fetch('origin', { depth: 1, ref });
Copy link
Member

Choose a reason for hiding this comment

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

Check if all the history if depth: 1

Copy link
Collaborator Author

@FrozenPandaz FrozenPandaz Aug 9, 2024

Choose a reason for hiding this comment

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

Yup, that messed it up. I made it the full history...

If it's a local path... it kind of adopts the history depth of the local path... so if people have a shallow clone, then they might be missing some commits 🤔

But if it's a remote path, we get the full history, however long it is

const newPath = join(destinationInSource, file);

await mkdirAsync(dirname(newPath), { recursive: true });
try {
Copy link
Member

@jaysoo jaysoo Aug 9, 2024

Choose a reason for hiding this comment

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

If we're moving to a gitignored directory, what will happen? (Looks like it just works!)

afterAll(() => cleanupProject());

it('should be able to import a vite app', () => {
const remote = 'https://github.com/nrwl/nx.git';
Copy link
Member

Choose a reason for hiding this comment

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

Maybe use a local remote so it's not necessary to have a reference on remote?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

@FrozenPandaz FrozenPandaz force-pushed the nx-import branch 9 times, most recently from 38ae368 to 6c75bf6 Compare August 9, 2024 23:05
@FrozenPandaz FrozenPandaz marked this pull request as ready for review August 12, 2024 14:40
@FrozenPandaz FrozenPandaz requested a review from a team as a code owner August 12, 2024 14:40
@FrozenPandaz FrozenPandaz requested a review from xiongemi August 12, 2024 14:40
} catch {}
await mkdir(tempImportDirectory, { recursive: true });

const sourceGitClient = await cloneFromUpstream(
Copy link
Member

Choose a reason for hiding this comment

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

If this fails, we may want to ask user to check their URL / directory path. If there is a typo, or what they are importing isn't a git repo.

@FrozenPandaz FrozenPandaz merged commit c72ba9b into master Aug 12, 2024
6 checks passed
@FrozenPandaz FrozenPandaz deleted the nx-import branch August 12, 2024 21:52
}
);

checkFilesExist(
Copy link
Member

Choose a reason for hiding this comment

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

Can we make some assertion about the git history of the project files? I trust that it is working, but just to keep it that way.

Comment on lines +60 to +62
execSync(`git commit -am "initial commit"`, {
cwd: tempViteProjectPath,
});
Copy link
Member

Choose a reason for hiding this comment

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

Can we create an extra commit or two? Just want to be safe :)

Copy link

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 28, 2024
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.

3 participants