Skip to content

Commit 19831ac

Browse files
authored
Merge pull request #1025 from bertdeblock/support-a-packageManager-option
Support a `packageManager` option (instead of `usePnpm` and `useYarn`)
2 parents ccebacb + 2272b5a commit 19831ac

10 files changed

Lines changed: 62 additions & 22 deletions

File tree

README.md

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,10 @@ module.exports = async function() {
116116
*/
117117
useVersionCompatibility: true,
118118
/*
119-
If set to true, all npm scenarios will use `yarn` for install with the `--no-lockfile` option. At cleanup, your
120-
dependencies will be restored to their prior state.
119+
The package manager to use for all scenarios. By default, lockfiles will be ignored when installing dependencies.
120+
At cleanup, all dependencies will be restored to their prior state.
121121
*/
122-
useYarn: true,
123-
/*
124-
If set to true, all npm scenarios will use `pnpm` for install with the `--no-lockfile` options. At cleanup, your
125-
dependencies will be restored to their prior state.
126-
*/
127-
usePnpm: true,
122+
packageManager: 'npm' | 'pnpm' | 'yarn',
128123

129124
/*
130125
buildManagerOptions allows you to opt-out of the default options such as `--ignore-engines --no-lockfile`.
@@ -149,15 +144,15 @@ module.exports = async function() {
149144
'ember-source': '2.11.0'
150145
},
151146
/*
152-
You can optionally define npm or pnpm overrides to enforce a specific dependency version
147+
You can optionally define npm or pnpm overrides to enforce a specific dependency version
153148
to be installed. This is useful if other libraries you depend on include different
154-
versions of a package. This does nothing if `useYarn` is true;
149+
versions of a package. This does nothing if `packageManager` is `yarn`;
155150
*/
156151
overrides: {
157152
'lodash': '5.0.0'
158153
}
159154
/*
160-
When `useYarn` is true, you can optionally define yarn resolutions to enforce a
155+
When `packageManager` is `yarn`, you can optionally define yarn resolutions to enforce a
161156
specific dependency version to be installed. This is useful if other libraries
162157
you depend on include different versions of a package.
163158
*/
@@ -209,11 +204,11 @@ The `name` can be used to try just one scenario using the `ember try:one` comman
209204

210205
##### Yarn
211206

212-
If you include `useYarn: true` in your `ember-try` config, all npm scenarios will use `yarn` for install with the `--no-lockfile` option. At cleanup, your dependencies will be restored to their prior state.
207+
If you include `packageManager: 'yarn'` in your `ember-try` config, all npm scenarios will use `yarn` for install with the `--no-lockfile` option. At cleanup, your dependencies will be restored to their prior state.
213208

214209
##### Pnpm
215210

216-
If you include `usePnpm: true` in your `ember-try` config, all npm scenarios will use `pnpm` for install with the `--no-lockfile` options. At cleanup, your dependencies will be restored to their prior state.
211+
If you include `packageManager: 'pnpm'` in your `ember-try` config, all npm scenarios will use `pnpm` for install with the `--no-lockfile` options. At cleanup, your dependencies will be restored to their prior state.
217212

218213
> ⚠ pnpm versions from 8.0.0 to 8.6.x have the default value of [resolution-mode](https://pnpm.io/npmrc#resolution-mode) setting changed to `lowest-direct`. This violates `ember-try` expectations as `resolution-mode` is expected to be `highest`, like in `npm` and `pnpm` versions < 8.0.0 and >= 8.7.0.
219214
>

lib/dependency-manager-adapters/npm.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ module.exports = class {
6868
if (fs.statSync(path.join(this.cwd, this.yarnLock)).isFile()) {
6969
ui.writeLine(
7070
chalk.yellow(
71-
'Detected a yarn.lock file. Add `useYarn: true` to your `config/ember-try.js` configuration file if you want to use Yarn to install npm dependencies.',
71+
"Detected a yarn.lock file. Add `packageManager: 'yarn'` to your `config/ember-try.js` configuration file if you want to use Yarn to install npm dependencies.",
7272
),
7373
);
7474
}

lib/dependency-manager-adapters/workspace.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module.exports = class {
1919

2020
if (!this.useYarnCommand) {
2121
throw new Error(
22-
'workspaces are currently only supported by Yarn, you must set `useYarn` to true',
22+
'workspaces are currently only supported by Yarn, you must set `packageManager` to `yarn`',
2323
);
2424
}
2525
let packageJSON = JSON.parse(fs.readFileSync(this.packageJSON));

lib/utils/config.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22

3+
const chalk = require('chalk');
34
const path = require('path');
45
const fs = require('fs');
56
const findByName = require('./find-by-name');
@@ -62,6 +63,24 @@ async function getBaseConfig(options) {
6263
async function config(options) {
6364
const configData = await getBaseConfig(options);
6465

66+
for (const packageManager of [
67+
['pnpm', 'usePnpm'],
68+
['yarn', 'useYarn'],
69+
]) {
70+
const [name, oldOption] = packageManager;
71+
72+
if (typeof configData[oldOption] === 'boolean') {
73+
console.warn(
74+
chalk.yellow(
75+
`${chalk.inverse(' ember-try DEPRECATION ')} The \`${oldOption}\` config option is deprecated. Please use \`packageManager: '${name}'\` instead.`,
76+
),
77+
);
78+
79+
delete configData[oldOption];
80+
configData.packageManager = name;
81+
}
82+
}
83+
6584
return configData;
6685
}
6786

lib/utils/dependency-manager-adapter-factory.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ module.exports = {
2323
new WorkspaceAdapter({
2424
cwd: root,
2525
managerOptions: config.npmOptions,
26-
useYarnCommand: config.useYarn,
26+
useYarnCommand: config.packageManager === 'yarn',
2727
buildManagerOptions: config.buildManagerOptions,
2828
}),
2929
);
30-
} else if (config.usePnpm) {
30+
} else if (config.packageManager === 'pnpm') {
3131
adapters.push(
3232
new PnpmAdapter({
3333
cwd: root,
@@ -40,7 +40,7 @@ module.exports = {
4040
new NpmAdapter({
4141
cwd: root,
4242
managerOptions: config.npmOptions,
43-
useYarnCommand: config.useYarn,
43+
useYarnCommand: config.packageManager === 'yarn',
4444
buildManagerOptions: config.buildManagerOptions,
4545
}),
4646
);

test/dependency-manager-adapters/workspace-adapter-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ describe('workspaceAdapter', () => {
124124
cwd: tmpdir,
125125
});
126126
}).to.throw(
127-
/workspaces are currently only supported by Yarn, you must set `useYarn` to true/,
127+
/workspaces are currently only supported by Yarn, you must set `packageManager` to `yarn`/,
128128
);
129129
});
130130
});

test/fixtures/dummy-ember-try-config-with-yarn-scenarios.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module.exports = {
2-
useYarn: true,
2+
packageManager: 'yarn',
33
scenarios: [
44
{
55
name: 'test2',

test/tasks/try-each-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ describe('tryEach', () => {
9797
return tryEachTask.run(config.scenarios, {}).then((exitCode) => {
9898
expect(exitCode).to.equal(0, 'exits 0 when all scenarios succeed');
9999
expect(output).to.include(
100-
'Detected a yarn.lock file. Add `useYarn: true` to your `config/ember-try.js` configuration file if you want to use Yarn to install npm dependencies.',
100+
"Detected a yarn.lock file. Add `packageManager: 'yarn'` to your `config/ember-try.js` configuration file if you want to use Yarn to install npm dependencies.",
101101
);
102102
expect(output).to.include('Scenario first: SUCCESS');
103103
expect(output).to.include('Scenario second: SUCCESS');

test/utils/config-test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,32 @@ describe('utils/config', () => {
240240
});
241241
});
242242
});
243+
244+
describe('old package-manager options', () => {
245+
it("replaces `usePnpm` with `packageManager: 'pnpm'`", () => {
246+
generateConfigFile(
247+
'module.exports = { usePnpm: true, scenarios: [] };',
248+
'config/use-pnpm.js',
249+
);
250+
251+
return getConfig({ configPath: 'config/use-pnpm.js', project }).then((config) => {
252+
expect(config.usePnpm).to.be.undefined;
253+
expect(config.packageManager).to.be.equal('pnpm');
254+
});
255+
});
256+
257+
it("replaces `useYarn` with `packageManager: 'yarn'`", () => {
258+
generateConfigFile(
259+
'module.exports = { useYarn: true, scenarios: [] };',
260+
'config/use-yarn.js',
261+
);
262+
263+
return getConfig({ configPath: 'config/use-yarn.js', project }).then((config) => {
264+
expect(config.useYarn).to.be.undefined;
265+
expect(config.packageManager).to.be.equal('yarn');
266+
});
267+
});
268+
});
243269
});
244270

245271
function writePackageJSONWithVersionCompatibility() {

test/utils/dependency-manager-adapter-factory-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ describe('DependencyManagerAdapterFactory', () => {
4343

4444
let adapters = DependencyManagerAdapterFactory.generateFromConfig(
4545
{
46-
useYarn: true,
46+
packageManager: 'yarn',
4747
useWorkspaces: true,
4848
scenarios: [{ npm: {} }],
4949
},

0 commit comments

Comments
 (0)