Skip to content

Commit

Permalink
feat: workspaces support
Browse files Browse the repository at this point in the history
  • Loading branch information
wesleytodd committed Dec 11, 2023
1 parent 6e1df67 commit 1afb1de
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
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

0 comments on commit 1afb1de

Please sign in to comment.