Skip to content

Commit

Permalink
feat(config): Add custom config for init private flag (yarnpkg#4377)
Browse files Browse the repository at this point in the history
**Summary**

Here is a small custom; I add this because it relates to https://yarnpkg.com/en/docs/cli/init#toc-setting-defaults-for-yarn-init. I discovered this was necessary while writing introduces for this flag.

**Test plan**

New init and config tests.
  • Loading branch information
pierreneter authored and terra-incognita committed Nov 9, 2017
1 parent ee76bc4 commit ce2fd05
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
11 changes: 11 additions & 0 deletions __tests__/commands/__snapshots__/init.js.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`init-config 1`] = `
Object {
"author": "Kittens McKitty <[email protected]> (https://yarnpkg.com)",
"license": "BSD",
"main": "index.js",
"name": "init-config",
"private": true,
"version": "0.0.0-alpha",
}
`;

exports[`init-github 1`] = `
Object {
"license": "MIT",
Expand Down
23 changes: 23 additions & 0 deletions __tests__/commands/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,29 @@ test.concurrent('init --yes --private should create package.json with defaults a
);
});

test.concurrent('init should use init-* configs when defined', (): Promise<void> => {
return buildRun(
ConsoleReporter,
fixturesLoc,
(args, flags, config, reporter, lockfile): Promise<void> => {
return runInit(config, reporter, flags, args);
},
[],
{yes: true},
'init-config',
async (config): Promise<void> => {
const {cwd} = config;
const manifestFile = await fs.readFile(path.join(cwd, 'package.json'));
const manifest = JSON.parse(manifestFile);

// Name is derived from directory name which is dynamic so check
// that separately and then remove from snapshot
expect(manifest.name).toEqual(path.basename(cwd));
expect({...manifest, name: 'init-config'}).toMatchSnapshot('init-config');
},
);
});

test.concurrent('init using Github shorthand should resolve to full repository URL', (): Promise<void> => {
const questionMap = Object.freeze({
name: 'hi-github',
Expand Down
6 changes: 6 additions & 0 deletions __tests__/fixtures/init/init-config/.yarnrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
init-private true
init-license BSD
init-version "0.0.0-alpha"
init-author-name "Kittens McKitty"
init-author-email "[email protected]"
init-author-url "https://yarnpkg.com"
4 changes: 2 additions & 2 deletions src/cli/commands/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export async function run(config: Config, reporter: Reporter, flags: Object, arg
{
key: 'private',
question: 'private',
default: '',
default: config.getOption('init-private') || '',
inputFormatter: yn,
},
];
Expand Down Expand Up @@ -129,7 +129,7 @@ export async function run(config: Config, reporter: Reporter, flags: Object, arg
}

if (def) {
question += ` (${def.toString()})`;
question += ` (${String(def)})`;
}
let answer;
Expand Down

0 comments on commit ce2fd05

Please sign in to comment.