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

Adds bolt add and bolt workspace add commands #35

Closed
wants to merge 18 commits into from

Conversation

lukebatchelor
Copy link
Member

This is encompasses all the work from #27

  • adds yarn.add helper
  • adds symlinking helper
  • refactors install to use symlinking
  • adds tests for install

Its still a bit messy and theres some dupliacted code I'd like to clean up, but I wanna try to get this in and do any more refactors in the next drop (which would also add bolt workspaces add).

As an aside, the testing patterns I've been using have changed a fair bit over the course of all this, so I definitely want to refactor and align all that at some point.

The mock yarn.add command for instance is in three different forms in three different places. A single one that everything uses would be awesome.

@lukebatchelor
Copy link
Member Author

[] refactor nested-workspaces-with-root-dependencies-installed tests to use package-with-external-deps-installed

@@ -6,6 +6,6 @@
},
"dependencies": {
"react": "^15.6.1",
"bar": "^1.0.0"
"@scoped/bar": "^1.0.0"
Copy link
Member Author

@lukebatchelor lukebatchelor Oct 6, 2017

Choose a reason for hiding this comment

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

Hmm... I'm going to double check all these fixures. I dont recall changing all these, so I'm thinking my tests may have modified them at some point.

  • find out if I modified all these fixtures or not...

Copy link
Member Author

Choose a reason for hiding this comment

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

Yup, all good.

}

// a mock yarn add function to update the pakcages's config and also node_modules dir
async function fakeYarnAdd(pkg: Package, dependencies, type = 'dependencies') {
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the yarn.add mock I'll be using in the rest of the tests later. Just a much cleaner way of handling than what I was doing before.

type: configDependencyType
};

const depTypeFlags = {
Copy link
Member Author

Choose a reason for hiding this comment

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

This and the toWorkspaceAddOptions are almost identical to the ones in add() bar the workspace arg. I'd love to dedupe if possible...

@lukebatchelor
Copy link
Member Author

Okay, had another look through and this seems pretty fine. I'm going to start work on the addDependenciesToPackage s function now.

devDependencies: '--dev',
peerDependencies: '--peer',
optionalDependencies: '--optional'
};
Copy link
Member

Choose a reason for hiding this comment

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

Might as well hoist this as a constant

);

await yarn.run(pkg, 'postinstall');
await yarn.run(pkg, 'prepublish');
Copy link
Member

Choose a reason for hiding this comment

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

pkg.config.getName(),
dep.name,
installed,
String(dep.version)
Copy link
Member

Choose a reason for hiding this comment

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

If you store the version in a variable, you won't need to check this again.

const installed = project.pkg.getDependencyVersionRange(dep.name);
const version = dep.version;
if (version && version !== installed) {
  logger.warn(
    messages.depMustMatchProject(
    pkg.config.getName(),
    dep.name,
    installed,
    version
  )
);

String(dep.version)
)
);
throw new Error();
Copy link
Member

Choose a reason for hiding this comment

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

I'd rather throw the warning as an error instead of logging it and throwing an error.

String(dep.version)
)
);
throw new Error();
Copy link
Member

Choose a reason for hiding this comment

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

@jamiebuilds
Copy link
Member

I think we should enforce at the project level that you cannot add a workspace as a dependency.

path/to/project/ $ bolt add workspace-name # error
path/to/project/other-workspace/ $ bolt add workspace-name # success

})
);
expect(yarn.add).toHaveBeenCalledTimes(0);
expect(await depIsInstalled(fooWorkspaceDir, 'project-only-dep')).toEqual(
Copy link
Member

Choose a reason for hiding this comment

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

btw .toEqual is meant for deep object comparison where .toBe is meant for reference equality. I generally use it for .toBe(true)-etc

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, no worries. I'll go replace all of these in the next PR if you like

@jamiebuilds
Copy link
Member

Can you rebase?

@lukebatchelor
Copy link
Member Author

I cant seem to push here after rebasing, so pushed to #36

@jamiebuilds jamiebuilds deleted the lbatch/bolt-add-its-happening branch October 9, 2017 06:09
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.

2 participants