-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Setup mono repository #3300
Setup mono repository #3300
Conversation
@@ -14,7 +14,7 @@ var debug = require( 'debug' )( 'calypso:i18n' ), | |||
var config = require( 'config' ), | |||
numberFormatPHPJS = require( './number-format' ), | |||
emitter = require( 'lib/mixins/emitter' ), | |||
interpolateComponents = require( 'lib/interpolate-components' ); | |||
interpolateComponents = require( 'lib/interpolate-components/src/' ); |
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.
Couldn't we use your new package.json
"main" attribute to define the main entry point for this lib thus keeping this require clean?
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.
Agreed
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.
After investigating this would require the module to be built on its own. The package.json already has a main property that is set to lib/index.js which is created once it is compiled. By providing th full path the component will be compiled as part of the parent projects build process. Do you you see an alternative?
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.
Probably we can leave it for now like this and change it once we figure out how to deal with build steps.
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.
By providing th full path the component will be compiled as part of the parent projects build process.
I'm not sure I follow that. By requiring directly into the component's inner-files, we're just requiring the pre-compiled /src/index.js
file. Couldn't we just build the module as part of calypso's build process and then require it by name and then allow it to bring in the specified main file?
Or if we just want to require the original source file, could we change the location of interpolate-components
inside the main package.json file to:
"interpolate-components": "client/lib/interpolate-components/src",
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.
Requiring from a sub-directory in a published module will not find the package.json, the main reason to require it to install dependencies. I did not explain correctly how this PR works. Please see the main description which I have updated.
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.
The package.json already has a main property that is set to lib/index.js which is created once it is compiled.
The package.json
for interpolate-components
in this PR has "main" set to src/index.js
. Though I agree that we would want it set to the generated lib/index.js
so the module works correctly for people requiring it through npm.
./bin/list-publishable-modules.js | ||
|
||
publish-module: | ||
( cd $(path) && make publish ) |
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.
Would this work in all shells?
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.
Changing that line to make -C $(path) publish
should do the trick.
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 we should probably also add a |
process.exitCode = 0; | ||
} | ||
|
||
exec( 'npm view ' + packageJsonPath.name + ' version', function( error, stdout ) { |
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.
Can the name contain spaces or other shell special characters?
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.
Good, call. I'll put in a patch.
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.
Resolved in: 152aa0f
I really like the approach. The rest is in code comments, but one high-level question – how do you think we should deal with keeping module dependencies up to date with the global ones? For example, if we decide to upgrade to React 15, we will need to update all of the |
} | ||
|
||
function publishModule( modulePath ) { | ||
return exec( 'make -C ' + modulePath.slice( 0, -12 ) + ' publish' ) |
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.
We could use the more standard npm publish
command and run our tests with hooks such as prepublish
. What do you think?
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.
Unfortunately prepublish runs when you npm install a package from a local path: npm/npm#3059 That makes it difficult to use. To have that work all sub packages would have to have their dependencies installed.
Nice work so far, this is a tricky problem :) With this approach, where do our existing separate libraries fit in? For example, I had to fix a problem in https://github.com/Automattic/xgettext-js, and it was pretty painful. You have to fix the module, hack the fix into calypso for testing, then go and commit and publish the fix in the module, then come back to calypso to pull in the latest version and make sure you haven't accidentally broken anything. I'd love to be able to take advantage of our monorepo to pull in a module like this and smooth out that workflow. How do you see that fitting in with this approach? |
Option number two is basically the same as if the module was part of the mono-repo. Also any script that you put into prepublish will run when a module is installed locally |
@nb When you update a dependency in the main package.json the pre-commit hook can check sub-module package.json files to see if those packages have been updated. This could either be a check or a requirement. The next step would be to automatically update the submodule dependency versions. UPDATE: Looks like this functionality is already built in: bin/update-dependency I will test this script to ensure that it works and update here. UPDATE: bin/update-dependency correctly updates dependencies in modules. |
For without support for build step, but worked out versions and dependencies. Branch 'belcherj-try/mono-repo-1'
This commit breaks the build because the Docker file copies over the package.json and installs without the rest of the repository so that the npm install process doesn't have to run on every build because of the docker cache: http://www.clock.co.uk/blog/a-guide-on-how-to-cache-npm-install-with-docker To merge this PR caching in Docker for npm installed would have to be invalidated each time. UPDATE: This has been resolved by not installing submodules. Instead list all dependencies in Calypso package.json. |
This PR was a failed approach to independently publishing NPM modules from within the main repository. |
This implementation assumes that all submodule dependencies are specified in the main package.json. When
make run
is run all submodules dependencies will be installed globally. Submodules will look up the directory tree to find the modules it requires and find them in the Calypso node_modules folder.Steps to Make a Package Publishable: