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

Add repositoryResolver option to mgit.json #30

Closed
Reinmar opened this issue Jan 23, 2017 · 7 comments
Closed

Add repositoryResolver option to mgit.json #30

Reinmar opened this issue Jan 23, 2017 · 7 comments

Comments

@Reinmar
Copy link
Member

Reinmar commented Jan 23, 2017

In some configurations you may want to use a different resolver by default. It shouldn't be necessary to always pass it through CLI args.

@Reinmar
Copy link
Member Author

Reinmar commented Jan 23, 2017

Actually, let's make it a bit differently. This will be the default values:

  "resolver": {
    "path": "@mgit2/lib/default-repository-resolver.js",
    "urlTemplate": "git@github.com:${ path }.git",
    "include": "*",
    "useLongPaths": false,
    "defaultBranch": "master"
  }

And each of these options will have a CLI alternative:

--resolver-path
--resolver-urlTemplate
--resolver-include
--resolver-useLongPaths
--resolver-defaultBranch

@Reinmar Reinmar self-assigned this Jan 23, 2017
@Reinmar
Copy link
Member Author

Reinmar commented Jan 23, 2017

I proposed two more options – include which will be needed for recursive cloning (currently, we handle this by a custom resolver (https://github.com/ckeditor/ckeditor5-dev/blob/c7fc65cd9f795255dee0bccc83a0b8cf3915af86/packages/ckeditor5-dev-tests/lib/git-https-resolver.js#L25) and defaultBranch which may be needed in the future.

@Reinmar
Copy link
Member Author

Reinmar commented Jan 23, 2017

The proposed options:

    Options:
        --fetch                     Whether to fetch changes from remote repositories.
                                    Default: true.

        --recursive                 Whether to install dependencies recursively.
                                    Needs to be used together with --repository-include. Only packages
                                    matching these patterns will be cloned recursively.
                                    Default: false.

        --resolver-path             Path to a custom repository resolver function.
                                    Default: '@mgit2/lib/default-repository-resolver.js'.

        --resolver-urlTemplate      Template used to generate repository URL out of a
                                    simplified 'organization/repository' format of the dependencies option.
                                    Default: 'git@github.com:${ path }.git'.

        --resolver-include          Comma separate minimatch patterns of packages which can be cloned recursively.
                                    Needs to be used together with '--recursive'.
                                    mgit gets dependencies and devDependencies of cloned package from its
                                    'package.json' and clones those which match the specified patterns.

        --resolver-useLongPaths     Applies to scoped npm packages.
                                    If true, the package will be cloned to: 'packages/@scope/pkgname'.
                                    If false, to 'packages/pkgname'.
                                    Default: false

        --resolver-defaultBranch    The branch name to use if not specified in mgit.json dependencies.
                                    Default: 'master'

@pomek
Copy link
Member

pomek commented Jan 23, 2017

To be consistent with CLI standard:

--resolver-urlTemplate => --resolver-url-template

Etc.

@pomek
Copy link
Member

pomek commented Jan 23, 2017

And remember about update the README file.

@Reinmar
Copy link
Member Author

Reinmar commented Jan 23, 2017

Turns out that --resolver-include can't be implemented this way. It's not about which packages to include, but how to generate their URL. A simple pattern matching won't do that.

@Reinmar
Copy link
Member Author

Reinmar commented Jan 23, 2017

OK, so if I haven't missed anything, the default resolver will look like this:

'use strict';

const parseRepositoryUrl = require( './utils/parserepositoryurl' );

/**
 * Resolves repository URL for a given package name.
 *
 * @param {String} name Package name.
 * @param {Object} options TODO
 * @returns {Repository|null}
 */
module.exports = function repositoryResolver( name, options ) {
	let repositoryUrl = options.dependencies[ name ];

	if ( !repositoryUrl ) {
		return null;
	}

	return parseRepositoryUrl( repositoryUrl, options );
};

The options object is, for simplicty, exactly the same as the options passed to CLI. This way the function is maximally short and hence, can be easilly extended by anyone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants