Skip to content

Commit 42d6a3c

Browse files
author
Kelly Selden
committed
fix for project with dot in name
1 parent 27c2e14 commit 42d6a3c

2 files changed

Lines changed: 84 additions & 16 deletions

File tree

src/get-start-and-end-commands.js

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -184,26 +184,39 @@ function createProject(runEmber) {
184184
return cwd;
185185
}
186186

187-
// remove scope
188-
let directoryName = projectName.replace(/^@.+\//, '');
187+
let projectRoot;
189188

190189
async function _runEmber(blueprint) {
191-
let args = getArgs({
192-
projectName,
193-
directoryName,
194-
blueprint
195-
});
196-
197-
await runEmber({
198-
packageRoot,
199-
cwd,
200-
blueprint,
201-
args
202-
});
190+
async function __runEmber() {
191+
// remove scope
192+
let directoryName = projectName.replace(/^@.+\//, '');
193+
194+
let args = getArgs({
195+
projectName,
196+
directoryName,
197+
blueprint
198+
});
199+
200+
await runEmber({
201+
packageRoot,
202+
cwd,
203+
blueprint,
204+
args
205+
});
206+
207+
projectRoot = path.join(cwd, directoryName);
208+
}
209+
210+
try {
211+
await __runEmber();
212+
} catch (err) {
213+
// We currently do not support a name of `...`.
214+
projectName = 'my-project';
215+
216+
await __runEmber();
217+
}
203218
}
204219

205-
let projectRoot = path.join(cwd, directoryName);
206-
207220
if (await isDefaultAddonBlueprint(blueprint)) {
208221
await _runEmber(baseBlueprint);
209222

test/unit/get-start-and-end-commands-test.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,61 @@ describe(_getStartAndEndCommands, function() {
465465
projectRoot
466466
}]]);
467467
});
468+
469+
it('falls back to safe project name if invalid', async function() {
470+
let { createProjectFromRemote } = getStartAndEndCommands();
471+
472+
readdirStub.resolves([]);
473+
474+
let createProject = createProjectFromRemote({
475+
options: {
476+
baseBlueprint,
477+
projectName,
478+
blueprint: loadSafeBlueprint({
479+
path: blueprintPath
480+
})
481+
}
482+
});
483+
484+
sinon.stub(utils, 'require')
485+
.withArgs(path.join(blueprintPath, 'package'))
486+
.returns({ keywords: ['ember-addon'] });
487+
488+
npxStub.onCall(0).rejects();
489+
490+
expect(await createProject(cwd)).to.equal(path.join(cwd, 'my-project'));
491+
492+
expect(npxStub.getCall(1).args).to.deep.equal([
493+
[
494+
'-p',
495+
`${baseBlueprint.packageName}@${baseBlueprint.version}`,
496+
commandName,
497+
'new',
498+
'my-project',
499+
'-sg',
500+
'-sn',
501+
'-sb',
502+
'-b',
503+
baseBlueprint.name,
504+
...baseBlueprint.options
505+
],
506+
{
507+
cwd
508+
}
509+
]);
510+
511+
expect(installAddonBlueprintStub.args).to.deep.equal([[{
512+
projectRoot: path.join(cwd, 'my-project'),
513+
blueprint: {
514+
path: blueprintPath,
515+
options: []
516+
}
517+
}]]);
518+
519+
expect(appendNodeModulesIgnoreStub.args).to.deep.equal([[{
520+
projectRoot: path.join(cwd, 'my-project')
521+
}]]);
522+
});
468523
});
469524

470525
describe('init blueprint', function() {

0 commit comments

Comments
 (0)