-
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
Changes from 4 commits
58d2343
59d69c7
6ad99c0
9daf2fd
a963d78
a53234b
6ab55b8
defb3ed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: Dependencies that we don't manage (eg. jest, shelljs) will always use versions from npm even in local development. |
||
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`); |
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.
I think you need to move the `