-
Notifications
You must be signed in to change notification settings - Fork 110
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 monorepo bootstrap #377
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
58d2343
adds monorepo bootstrap
delambo 59d69c7
remove timer from bootstrap command
delambo 6ad99c0
Merge branch 'master' into better-bootstrap
delambo 9daf2fd
removes starter-kyts dir
delambo a963d78
Merge branch 'master' into better-bootstrap
delambo a53234b
addresses code review feedback
delambo 6ab55b8
adds starter-kyt build gitignore paths
delambo defb3ed
fixes starter kyt paths in config
delambo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* eslint-disable import/no-dynamic-require,global-require */ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const spawn = require('child_process').spawnSync; | ||
|
||
const type = process.env.type || 'upgrade'; // yarn update types | ||
const logTask = msg => console.log(`👍 ${msg}`); | ||
|
||
const installPackage = (at) => { | ||
const result = spawn('yarn', [type], { stdio: 'inherit', cwd: at }); | ||
if (result.error) { | ||
console.log(result.error); | ||
process.exit(1); | ||
} | ||
logTask(`installed ${at}\n`); | ||
}; | ||
|
||
const packages = fs.readdirSync('packages').reduce((pkgs, pkg) => { | ||
const packagePath = path.join(process.cwd(), 'packages', pkg); | ||
const packageJSON = path.join(packagePath, 'package.json'); | ||
try { | ||
if (fs.statSync(packagePath).isDirectory() && fs.statSync(packageJSON).isFile()) { | ||
pkgs.push({ path: packagePath, name: require(packageJSON).name }); | ||
} | ||
} catch (e) { return pkgs; } | ||
return pkgs; | ||
}, []); | ||
|
||
console.log(`\n🔥 Bootstrapping\n`); | ||
|
||
// Install the root package.json first so that we can use shelljs. | ||
installPackage(process.cwd()); | ||
const shell = require('shelljs'); | ||
|
||
// Install all of the monorepo packages. | ||
packages.forEach(pkg => installPackage(pkg.path)); | ||
|
||
// Symlink monorepo package dependencies to local packages. | ||
packages.forEach((pkg) => { | ||
const packageJSON = require(path.join(pkg.path, 'package.json')); | ||
const dependencies = Object.assign({}, packageJSON.dependencies, packageJSON.devDependencies); | ||
packages.forEach((spkg) => { | ||
if (dependencies.hasOwnProperty(spkg.name)) { // eslint-disable-line no-prototype-builtins | ||
const to = path.join(spkg.path, 'node_modules', spkg.name); | ||
shell.rm('-rf', to); | ||
shell.ln('-sf', spkg.path, to); | ||
logTask(`symlinked:\n${to} -> ${spkg.path}\n`); | ||
} | ||
}); | ||
}); | ||
|
||
// npm link kyt-cli and kyt | ||
shell.exec('npm link', { cwd: path.join(process.cwd(), 'packages', 'kyt-cli') }); | ||
logTask('npm-linked kyt-cli\n'); | ||
shell.exec('npm link', { cwd: path.join(process.cwd(), 'packages', 'kyt-core') }); | ||
logTask('npm-linked kyt'); | ||
|
||
console.log(`\n✅ strapped\n`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how does this system resolve dependency clashes when you flatten here? for example: if one of your monorepo packages depends on [given module]@2.2.0 and a sibling package depends on version [given module]@1.9.0. Do you assume that your project will include both versions of dependency?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of the kyt-specific dependencies in the monorepo should be in sync with the latest published versions. Symlinking makes it easy to do local development on a specific kyt package and its respective kyt dependencies (eg changes to kyt-core and kyt-utils). It's true that this makes the assumption that things will stay in sync, but the symlinks are also easy to override after bootstrap if there is an issue or you want to test against a specific version. Let me know if I can clarify more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so the assumption is that the last package which contains dependency of said version will be the chosen version as it was the last symlinked? Wondering if this has caused or might cause interdependency related errors in the past/future? Do you have a recommended approach to ensuring the dependencies as you say as "latest published versions"? do you suggest to use
@latest
for example? Or how do you sanity check this in terms of upgrading workflow?Should this code be improved by emitting warnings in this event of version conflicts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This tool is just for local development so you can make changes without having to constantly reinstall node_modules. All published packages will have pinned dependencies.
For example:
I want to add a new utility to kyt-utils to use in a command in kyt-core. When I bootstrap for local development kyt-utils is symlinked in my node_modules for kyt-core and I can make changes directly in my files and see those changes as I run and test kyt-core locally. When I'm ready to commit changes I would update and publish a new version of kyt-utils and then use that pinned version as the dependency of kyt-core.
Dependencies that we don't manage (eg. jest, shelljs) will always use versions from npm even in local development.