Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ function initOpts () {
}
},

workspaces: {
type: 'string',
prompt: {
message: 'Workspaces:',
filter: parseList
}
},

type: {
type: 'string',
prompt: {
Expand Down Expand Up @@ -300,6 +308,11 @@ async function format (opts, packageInstance) {
pkg.scripts = { ...(pkg.scripts || {}), ...opts.scripts };
}

// Workspaces
if (Array.isArray(opts.workspaces) && opts.workspaces.length) {
pkg.workspaces = opts.workspaces;
}

// TODO: to test the empty string, we need to stub git.author()
pkg.author = opts.author || '';
pkg.license = opts.license;
Expand Down
41 changes: 41 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,47 @@ suite('create-package-json', () => {
});
});

suite.only('scaffold workspaces', () => {
test('workspaces input', async () => {
await fix.setup();
// Empty array is invalid according to npm
const pkg1 = await createPackageJson({
workspaces: []
});
assert.deepStrictEqual(pkg1.workspaces, undefined);

await fix.setup();
const pkg2 = await createPackageJson({
workspaces: ['./lib']
});
assert.deepStrictEqual(pkg2.workspaces, ['./lib']);

await fix.setup();
const pkg3 = await createPackageJson({
workspaces: ['./lib/a', './lib/b']
});
assert.deepStrictEqual(pkg3.workspaces, ['./lib/a', './lib/b']);
});

test('workspaces prompts', async () => {
await fix.setup();
const pkg1 = await createPackageJson();
assert.deepStrictEqual(pkg1.workspaces, undefined);

const pkg2 = await createPackageJson({}, {
promptor: () => {
return async (prompts) => {
console.log(prompts);
return {
workspaces: ['./lib/a', './lib/b']
};
};
}
});
assert.deepStrictEqual(pkg2.workspaces, ['./lib/a', './lib/b']);
});
});

suite('npm init', () => {
test('parity', async () => {
await fix.setup();
Expand Down