Skip to content

Adds symlinking of package binaries to the project at install - #194

Merged
lukebatchelor merged 4 commits into
masterfrom
lbatch/linking-package-bins-to-project
Sep 18, 2018
Merged

lukebatchelor merged 4 commits into
masterfrom
lbatch/linking-package-bins-to-project

Conversation

@lukebatchelor

@lukebatchelor lukebatchelor commented Sep 17, 2018 •

Copy link
Copy Markdown
Member

Fixes #187

  • Adds symlinking of package binaries to the project at install time.
  • Removes check that all project bin symlinks must point to project node_modules
  • Fixes some publish tests

@lukebatchelor

Copy link
Copy Markdown
Member Author

@jamiebuilds Just wanted to get your thoughts on this.

We currently have this check in the symlinking step.

if (!pathIsInside(actualBinFile, project.pkg.nodeModules)) {
throw new BoltError(
`${binName} is linked to a location outside of project node_modules: ${actualBinFileRelative}`
);
}

This causes this feature to fail if you run install twice (because there will be a symlink to somewhere outside of node_modules).

In your opinion, should we remove this check (not 100% sure if it's required?) or should we just loosen it to also check if the symlink points to a Package (or even stricter, a Packages binary).

Thoughts

@lukebatchelor
lukebatchelor force-pushed the lbatch/linking-package-bins-to-project branch 2 times, most recently from de67b8d to b71ef8a Compare September 18, 2018 03:19
@lukebatchelor
lukebatchelor force-pushed the lbatch/linking-package-bins-to-project branch from b71ef8a to 731f7c8 Compare September 18, 2018 03:26
]);

expect(publish({ cwd })).rejects.toBeInstanceOf(BoltError);
await expect(publish({ cwd })).rejects.toBeInstanceOf(Error);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@lachlanhunt Just FYI, found why the test below was failing and also found that this test shouldn't have been passing. :S

We weren't awaiting on the expect.

There's another interesting thing here, we can't check for instanceOf(BoltError) because on lower versions of node it just comes through as "Error". Weird.

actualBinFileRelative
);

if (!pathIsInside(actualBinFile, project.pkg.nodeModules)) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Discussed with @jamiebuilds and we're removing this as it was for future plans around linking multiple bolt repos that didn't come to fruition.


symlinksToCreate.push({ src, dest, type: 'exec' });
// Just in case the symlink is already added (it might have already existed in the projects bin/)
if (!symlinksToCreate.find(symlink => symlink.dest === dest)) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Just to explain this check:

I noticed that when running install twice in a row I'd get an error about a symlink already being created. Originally I assumed this must have been from my added code (which hypothetically should be fine, the symlink command rimrafs existing symlinks if they are there).

Upon investigation I found it it was happening in symlinkPackageDependencies because a symlink was being added to symlinksToCreate twice, once because it was in the root dependencies and once because it was an internal dependency.

This check was the least intrusive way to fix the issue.

A couple of other solutions could be:

  • Remove all the code that symlinks binaries between packages and let this be taken care of by symlinkPackagesBinariesToProject. It would copy all binaries from packages into the root .bin and then we'd automatically pick them all up anyway. There's no problem with this imo, the main difference would be that all packages would now have bin's from other internal packages, where as previously they would only get them if they had a dependency (this is not much different to all packages getting a link to all root external bins imo)
  • Run the symlinking code in serial rather than parallel. Not a great solution, it would solve the problem because each time we tried to make a symlink it would always delete first if there was an existing one, this would be fairly slow however.
  • We could rethink how we do all the symlinking of binaries into packages. This currently actually takes a very long time for some reason. We could investigate possibly symlinking the bin directory instead? This would be the most dangerous change imo.

@lukebatchelor
lukebatchelor merged commit d22fd7b into master Sep 18, 2018
@lukebatchelor
lukebatchelor deleted the lbatch/linking-package-bins-to-project branch September 18, 2018 03:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant