Skip to content

Commit 2b0eb8a

Browse files
author
Kelly Selden
committed
only pre-download blueprint when it's not on npm
1 parent f8c2dee commit 2b0eb8a

File tree

7 files changed

+124
-57
lines changed

7 files changed

+124
-57
lines changed

src/ember-install-addon.js

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,47 @@ async function getEmberCliVersion({
3636

3737
async function emberInstallAddon({
3838
cwd,
39-
addonName,
40-
blueprintPackageName,
39+
addonNameOverride,
40+
packageName,
41+
version,
42+
blueprintPath,
4143
stdin
4244
}) {
43-
let emberCliVersion = await getEmberCliVersion({ cwd });
45+
let addon;
4446

45-
let install = ember(['i', addonName], { cwd, stdin });
47+
if (addonNameOverride) {
48+
addon = addonNameOverride;
49+
if (version && !blueprintPath) {
50+
addon += `@${version}`;
51+
}
52+
}
4653

47-
let generate;
54+
if (!addon) {
55+
addon = blueprintPath;
56+
}
57+
58+
if (!addon) {
59+
addon = `${packageName}@${version}`;
60+
}
4861

49-
let isBuggyEmberCliVersion = semver.satisfies(emberCliVersion, buggyEmberCliRange);
62+
let install = ember(['i', addon], { cwd, stdin });
5063

51-
if (!isBuggyEmberCliVersion) {
64+
let generate;
65+
66+
if (!blueprintPath) {
5267
generate = install;
5368
} else {
54-
await install;
69+
let emberCliVersion = await getEmberCliVersion({ cwd });
70+
71+
let isBuggyEmberCliVersion = semver.satisfies(emberCliVersion, buggyEmberCliRange);
72+
73+
if (!isBuggyEmberCliVersion) {
74+
generate = install;
75+
} else {
76+
await install;
5577

56-
generate = ember(['g', blueprintPackageName], { cwd, stdin });
78+
generate = ember(['g', packageName], { cwd, stdin });
79+
}
5780
}
5881

5982
return {

src/get-base-blueprint.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,18 @@ async function getBaseBlueprint({
2222
baseBlueprint = loadSafeBlueprint(baseBlueprint);
2323
let isCustomBlueprint = !isDefaultBlueprint(baseBlueprint);
2424
if (isCustomBlueprint) {
25-
let url;
2625
if (baseBlueprint.location) {
2726
let parsedPackage = await parseBlueprintPackage({
2827
cwd,
2928
blueprint: baseBlueprint
3029
});
31-
url = parsedPackage.url;
30+
let downloadedPackage = await downloadPackage(
31+
baseBlueprint.packageName,
32+
parsedPackage.url,
33+
baseBlueprint.version
34+
);
35+
baseBlueprint.path = downloadedPackage.path;
3236
}
33-
let downloadedPackage = await downloadPackage(baseBlueprint.packageName, url, baseBlueprint.version);
34-
baseBlueprint.path = downloadedPackage.path;
3537
}
3638
} else {
3739
defaultBlueprint = await loadDefaultBlueprintFromDisk(cwd);

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

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const isDefaultBlueprint = require('./is-default-blueprint');
99
const emberInstallAddon = require('./ember-install-addon');
1010
const overwriteBlueprintFiles = require('./overwrite-blueprint-files');
1111
const debug = require('debug')('ember-cli-update');
12+
const npm = require('boilerplate-update/src/npm');
1213

1314
const nodeModulesIgnore = `
1415
@@ -37,7 +38,10 @@ module.exports = function getStartAndEndCommands({
3738
} else if (!endBlueprint.isBaseBlueprint && isDefaultBlueprint(baseBlueprint)) {
3839
startRange = endRange = baseBlueprint.version;
3940
} else {
40-
startRange = endRange = '';
41+
// first version that supports blueprints with versions
42+
43+
// https://github.com/ember-cli/ember-cli/pull/8571
44+
startRange = endRange = '>=3.11.0-beta.1';
4145
}
4246

4347
return {
@@ -63,13 +67,18 @@ module.exports = function getStartAndEndCommands({
6367
};
6468
};
6569

66-
function isDefaultAddonBlueprint(blueprint) {
70+
async function isDefaultAddonBlueprint(blueprint) {
6771
let isCustomBlueprint = !isDefaultBlueprint(blueprint);
6872

6973
let isDefaultAddonBlueprint;
7074

7175
if (isCustomBlueprint) {
72-
let { keywords } = utils.require(path.join(blueprint.path, 'package'));
76+
let keywords;
77+
if (blueprint.path) {
78+
keywords = utils.require(path.join(blueprint.path, 'package')).keywords;
79+
} else {
80+
keywords = await npm.json(`v ${blueprint.packageName} keywords`);
81+
}
7382

7483
isDefaultAddonBlueprint = !(keywords && keywords.includes('ember-blueprint'));
7584
}
@@ -88,14 +97,16 @@ function getArgs(projectName, blueprint) {
8897
args.push('init');
8998
}
9099

91-
let isCustomBlueprint = !isDefaultBlueprint(blueprint);
92-
93100
let _blueprint;
94-
if (isCustomBlueprint) {
101+
if (blueprint.path) {
102+
// Only use path when necessary, because `npm install <folder>`
103+
// symlinks instead of actually installing, so any peerDeps won't
104+
// work. Example https://github.com/salsify/ember-cli-dependency-lint/blob/v1.0.3/lib/commands/dependency-lint.js#L5
95105
_blueprint = blueprint.path;
96-
} else {
97-
// Can we use the above path all the time, even if it is default?
106+
} else if (isDefaultBlueprint(blueprint)) {
98107
_blueprint = blueprint.name;
108+
} else {
109+
_blueprint = `${blueprint.packageName}@${blueprint.version}`;
99110
}
100111

101112
return [
@@ -186,7 +197,7 @@ function createProject(runEmber) {
186197
}
187198

188199
if (options.blueprint) {
189-
if (isDefaultAddonBlueprint(options.blueprint)) {
200+
if (await isDefaultAddonBlueprint(options.blueprint)) {
190201
await module.exports.installAddonBlueprint({
191202
cwd,
192203
projectName: options.projectName,
@@ -227,8 +238,9 @@ module.exports.installAddonBlueprint = async function installAddonBlueprint({
227238

228239
let { ps } = await emberInstallAddon({
229240
cwd: projectRoot,
230-
addonName: blueprint.path,
231-
blueprintPackageName: blueprint.packageName,
241+
packageName: blueprint.packageName,
242+
version: blueprint.version,
243+
blueprintPath: blueprint.path,
232244
stdin: 'pipe'
233245
});
234246

src/index.js

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -172,21 +172,27 @@ All blueprints are up-to-date!`;
172172
endBlueprint = { ...blueprint };
173173

174174
if (isCustomBlueprint) {
175-
let [
176-
startDownloadedPackage,
177-
endDownloadedPackage
178-
] = await Promise.all([
179-
startBlueprint ? downloadPackage(startBlueprint.packageName, packageUrl, startBlueprint.version) : null,
180-
downloadPackage(endBlueprint.packageName, packageUrl, to)
181-
]);
182-
183-
if (startBlueprint) {
184-
startBlueprint.path = startDownloadedPackage.path;
185-
startBlueprint.version = startDownloadedPackage.version;
175+
if (packageUrl) {
176+
let [
177+
startDownloadedPackage,
178+
endDownloadedPackage
179+
] = await Promise.all([
180+
startBlueprint ? downloadPackage(startBlueprint.packageName, packageUrl, startBlueprint.version) : null,
181+
downloadPackage(endBlueprint.packageName, packageUrl, to)
182+
]);
183+
184+
if (startBlueprint) {
185+
startBlueprint.path = startDownloadedPackage.path;
186+
startBlueprint.version = startDownloadedPackage.version;
187+
}
188+
189+
endBlueprint.path = endDownloadedPackage.path;
190+
endBlueprint.version = endDownloadedPackage.version;
191+
} else {
192+
let versions = await getVersions(endBlueprint.packageName);
193+
let getTagVersion = _getTagVersion(versions, endBlueprint.packageName);
194+
endBlueprint.version = await getTagVersion(to);
186195
}
187-
188-
endBlueprint.path = endDownloadedPackage.path;
189-
endBlueprint.version = endDownloadedPackage.version;
190196
} else {
191197
let packageName = getPackageName(projectOptions);
192198
let packageVersion = getPackageVersion(packageJson, packageName);

src/init.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ const loadBlueprintFile = require('./load-blueprint-file');
1414
const bootstrap = require('./bootstrap');
1515
const findBlueprint = require('./find-blueprint');
1616
const getBaseBlueprint = require('./get-base-blueprint');
17+
const getVersions = require('boilerplate-update/src/get-versions');
18+
const _getTagVersion = require('./get-tag-version');
1719

1820
module.exports = async function init({
1921
blueprint: _blueprint,
@@ -35,6 +37,7 @@ module.exports = async function init({
3537
blueprint: _blueprint
3638
});
3739
packageName = parsedPackage.name;
40+
name = parsedPackage.name;
3841
location = parsedPackage.location;
3942
url = parsedPackage.url;
4043
} else {
@@ -43,13 +46,18 @@ module.exports = async function init({
4346
name = defaultBlueprint.name;
4447
}
4548

46-
let downloadedPackage = await downloadPackage(packageName, url, to);
47-
packageName = downloadedPackage.name;
48-
49-
// could be "app" or "addon" already
50-
// don't want to overwrite with "ember-cli"
51-
if (!name) {
49+
let version;
50+
let path;
51+
if (url) {
52+
let downloadedPackage = await downloadPackage(packageName, url, to);
53+
packageName = downloadedPackage.name;
5254
name = downloadedPackage.name;
55+
version = downloadedPackage.version;
56+
path = downloadedPackage.path;
57+
} else {
58+
let versions = await getVersions(packageName);
59+
let getTagVersion = _getTagVersion(versions, packageName);
60+
version = await getTagVersion(to);
5361
}
5462

5563
let emberCliUpdateJson = await loadSafeBlueprintFile(cwd);
@@ -70,8 +78,8 @@ module.exports = async function init({
7078

7179
blueprint = loadSafeBlueprint(blueprint);
7280

73-
blueprint.version = downloadedPackage.version;
74-
blueprint.path = downloadedPackage.path;
81+
blueprint.version = version;
82+
blueprint.path = path;
7583

7684
let {
7785
baseBlueprint

src/install.js

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ const saveBlueprint = require('./save-blueprint');
77
const loadBlueprintFile = require('./load-blueprint-file');
88
const bootstrap = require('./bootstrap');
99
const emberInstallAddon = require('./ember-install-addon');
10+
const getVersions = require('boilerplate-update/src/get-versions');
11+
const _getTagVersion = require('./get-tag-version');
1012

1113
const toDefault = require('./args').to.default;
1214

@@ -20,26 +22,40 @@ module.exports = async function install({
2022
blueprint: addon
2123
});
2224

23-
let downloadedPackage = await downloadPackage(parsedPackage.name, parsedPackage.url, toDefault);
25+
let packageName;
26+
let version;
27+
let path;
28+
if (parsedPackage.location) {
29+
let downloadedPackage = await downloadPackage(null, parsedPackage.url, toDefault);
30+
packageName = downloadedPackage.name;
31+
version = downloadedPackage.version;
32+
path = downloadedPackage.path;
33+
} else {
34+
packageName = addon;
35+
let versions = await getVersions(packageName);
36+
let getTagVersion = _getTagVersion(versions, packageName);
37+
version = await getTagVersion(toDefault);
38+
}
2439

2540
// We are double installing it, via the above and the below.
26-
// The above is needed to resolve the real package name,
27-
// and the below is needed to allow NPM/yarn to resolve the
28-
// package.json version for us.
41+
// The above is needed to resolve the real package name
42+
// if location is specified, and the below is needed to allow
43+
// NPM/yarn to resolve the package.json version for us.
2944
// This may be able to be combined somehow...
3045
let { ps } = await emberInstallAddon({
3146
cwd,
32-
addonName: addon,
33-
blueprintPackageName: downloadedPackage.name
47+
addonNameOverride: addon,
48+
packageName,
49+
blueprintPath: path
3450
});
3551

3652
await ps;
3753

3854
let blueprint = loadSafeBlueprint({
39-
packageName: downloadedPackage.name,
40-
name: downloadedPackage.name,
55+
packageName,
56+
name: packageName,
4157
location: parsedPackage.location,
42-
version: downloadedPackage.version
58+
version
4359
});
4460

4561
if (!await loadBlueprintFile(cwd)) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ describe(_getStartAndEndCommands, function() {
351351
name: blueprint,
352352
version: startVersion
353353
},
354-
packageRange: ''
354+
packageRange: '>=3.11.0-beta.1'
355355
},
356356
endOptions: {
357357
baseBlueprint: {
@@ -362,7 +362,7 @@ describe(_getStartAndEndCommands, function() {
362362
name: blueprint,
363363
version: endVersion
364364
},
365-
packageRange: ''
365+
packageRange: '>=3.11.0-beta.1'
366366
}
367367
});
368368
});

0 commit comments

Comments
 (0)