Skip to content

Commit 753f061

Browse files
author
Kelly Selden
committed
require local blueprints start with .
Previously we had logic to detect the difference between a subdir with the name "foo" and an npm package "foo". This prevented a self referencings blueprints "." because it would be considered a subdir. Now we avoid this problem by requiring local blueprints start with ".". So "foo" => "./foo".
1 parent 09439d3 commit 753f061

File tree

2 files changed

+27
-21
lines changed

2 files changed

+27
-21
lines changed

src/parse-blueprint-package.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,22 @@ function toPosixAbsolutePath(path) {
1414
return posixPath;
1515
}
1616

17-
// https://stackoverflow.com/a/45242825/1703845
18-
function isSubDir(base, test) {
19-
let relative = path.relative(base, test);
20-
return !relative.startsWith('..') && !path.isAbsolute(relative);
21-
}
22-
2317
async function parseBlueprintPackage({
2418
cwd = '.',
2519
blueprint
2620
}) {
2721
let name;
2822
let location;
2923
let url;
30-
let blueprintPath = path.resolve(cwd, blueprint);
31-
if (await fs.pathExists(blueprintPath) && !isSubDir(cwd, blueprintPath)) {
24+
let blueprintPath;
25+
26+
if (blueprint.startsWith('.')) {
27+
blueprintPath = path.resolve(cwd, blueprint);
28+
} else if (path.isAbsolute(blueprint) && await fs.pathExists(blueprint)) {
29+
blueprintPath = blueprint;
30+
}
31+
32+
if (blueprintPath) {
3233
let posixBlueprintPath = toPosixAbsolutePath(blueprintPath);
3334
url = `git+file://${posixBlueprintPath}`;
3435
location = blueprint;
@@ -42,6 +43,7 @@ async function parseBlueprintPackage({
4243
name = blueprint;
4344
}
4445
}
46+
4547
return {
4648
name,
4749
location,

test/integration/parse-blueprint-package-test.js

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,39 +23,43 @@ describe(parseBlueprintPackage, function() {
2323
});
2424
});
2525

26-
it('ignores subdirs that collide with blueprint names', async function() {
27-
let blueprint = 'config';
26+
it('detects urls', async function() {
27+
let blueprint = 'http://test-blueprint.com';
2828

2929
let parsedPackage = await parseBlueprintPackage({
30-
cwd: path.resolve(__dirname, '../fixtures/blueprint/app/local-app/local/my-app'),
3130
blueprint
3231
});
3332

3433
expect(parsedPackage).to.deep.equal({
35-
name: blueprint,
36-
location: undefined,
37-
url: undefined
34+
name: undefined,
35+
location: blueprint,
36+
url: blueprint
3837
});
3938
});
4039

41-
it('detects urls', async function() {
42-
let blueprint = 'http://test-blueprint.com';
40+
it('detects npm packages', async function() {
41+
let blueprint = 'test-blueprint';
4342

4443
let parsedPackage = await parseBlueprintPackage({
4544
blueprint
4645
});
4746

4847
expect(parsedPackage).to.deep.equal({
49-
name: undefined,
50-
location: blueprint,
51-
url: blueprint
48+
name: blueprint,
49+
location: undefined,
50+
url: undefined
5251
});
5352
});
5453

55-
it('detects npm packages', async function() {
56-
let blueprint = 'test-blueprint';
54+
it('uses npm even if subdir match', async function() {
55+
let blueprint = 'config';
56+
57+
let cwd = path.resolve(__dirname, '../fixtures/blueprint/app/local-app/local/my-app');
58+
59+
expect(cwd).to.be.a.directory().and.include.subDirs([blueprint]);
5760

5861
let parsedPackage = await parseBlueprintPackage({
62+
cwd,
5963
blueprint
6064
});
6165

0 commit comments

Comments
 (0)