Skip to content

Commit

Permalink
Don't use ember-cli project instance outside of ember-cli commands
Browse files Browse the repository at this point in the history
  • Loading branch information
bertdeblock committed Dec 18, 2024
1 parent d3b56f1 commit f747ca7
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 29 deletions.
2 changes: 1 addition & 1 deletion lib/commands/reset.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ module.exports = {
let ResetTask = require('../tasks/reset');

let resetTask = new ResetTask({
project: this.project,
config,
cwd: this.project.root,
});

return await resetTask.run();
Expand Down
2 changes: 1 addition & 1 deletion lib/commands/try-each.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ module.exports = {
debug('Config: %s', JSON.stringify(config));

let tryEachTask = new this._TryEachTask({
project: this.project,
config,
cwd: this.project.root,
});

return await tryEachTask.run(config.scenarios, { skipCleanup: commandOptions.skipCleanup });
Expand Down
2 changes: 1 addition & 1 deletion lib/commands/try-ember.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ module.exports = {
debug('Config: %s', JSON.stringify(config));

let tryEachTask = new this._TryEachTask({
project: this.project,
config,
cwd: this.project.root,
});

return await tryEachTask.run(config.scenarios, { skipCleanup: commandOptions.skipCleanup });
Expand Down
4 changes: 2 additions & 2 deletions lib/commands/try-one.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ module.exports = {
}

let tryEachTask = new this._TryEachTask({
project: this.project,
config,
commandArgs,
config,
cwd: this.project.root,
});

return await tryEachTask.run([scenario], { skipCleanup: commandOptions.skipCleanup });
Expand Down
4 changes: 2 additions & 2 deletions lib/tasks/reset.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ const DependencyManagerAdapterFactory = require('./../utils/dependency-manager-a
module.exports = class ResetTask {
constructor(options) {
this.config = options.config;
this.project = options.project;
this.cwd = options.cwd;
}

run() {
let dependencyAdapters = DependencyManagerAdapterFactory.generateFromConfig(
this.config,
this.project.root,
this.cwd,
);
debug(
'DependencyManagerAdapters: %s',
Expand Down
6 changes: 3 additions & 3 deletions lib/tasks/try-each.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ module.exports = class TryEachTask {
this.commandArgs = options.commandArgs;
this.commandOptions = options.commandOptions;
this.config = options.config;
this.cwd = options.cwd;
this.dependencyManagerAdapters = options.dependencyManagerAdapters;
this.project = options.project;
}

async run(scenarios, options) {
Expand All @@ -21,7 +21,7 @@ module.exports = class TryEachTask {

let dependencyManagerAdapters =
this.dependencyManagerAdapters ||
DependencyManagerAdapterFactory.generateFromConfig(this.config, this.project.root);
DependencyManagerAdapterFactory.generateFromConfig(this.config, this.cwd);
debug(
'DependencyManagerAdapters: %s',
dependencyManagerAdapters.map((item) => {
Expand Down Expand Up @@ -134,7 +134,7 @@ module.exports = class TryEachTask {
}

_runCommand(options) {
return runCommand(this.project.root, options.commandArgs, options.commandOptions);
return runCommand(this.cwd, options.commandArgs, options.commandOptions);
}

_commandOptions(env) {
Expand Down
10 changes: 5 additions & 5 deletions lib/utils/dependency-manager-adapter-factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const WorkspaceAdapter = require('../dependency-manager-adapters/workspace');
const YarnAdapter = require('../dependency-manager-adapters/yarn');

module.exports = {
generateFromConfig(config, root) {
generateFromConfig(config, cwd) {
let hasNpm = false;
let adapters = [];
if (!config || !config.scenarios) {
Expand All @@ -22,7 +22,7 @@ module.exports = {
if (config.useWorkspaces) {
adapters.push(
new WorkspaceAdapter({
cwd: root,
cwd,
managerOptions: config.npmOptions,
packageManager: config.packageManager,
buildManagerOptions: config.buildManagerOptions,
Expand All @@ -31,23 +31,23 @@ module.exports = {
} else if (config.packageManager === 'pnpm') {
adapters.push(
new PnpmAdapter({
cwd: root,
cwd,
managerOptions: config.npmOptions,
buildManagerOptions: config.buildManagerOptions,
}),
);
} else if (config.packageManager === 'yarn') {
adapters.push(
new YarnAdapter({
cwd: root,
cwd,
managerOptions: config.npmOptions,
buildManagerOptions: config.buildManagerOptions,
}),
);
} else if (hasNpm) {
adapters.push(
new NpmAdapter({
cwd: root,
cwd,
managerOptions: config.npmOptions,
buildManagerOptions: config.buildManagerOptions,
}),
Expand Down
4 changes: 4 additions & 0 deletions test/commands/try-one-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ describe('commands/try-one', () => {
MockTryEachTask.prototype.run = function () {};

beforeEach(() => {
TryOneCommand.project = { root: '' };

TryOneCommand._getConfig = function () {
return Promise.resolve(mockConfig || { scenarios: [] });
};
Expand All @@ -45,6 +47,8 @@ describe('commands/try-one', () => {
});

afterEach(() => {
delete TryOneCommand.project;

TryOneCommand._TryEachTask = origTryEachTask;
TryOneCommand._getConfig = origGetConfig;
mockConfig = null;
Expand Down
2 changes: 1 addition & 1 deletion test/tasks/reset-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ describe('reset', () => {
};

let resetTask = new ResetTask({
project: { root: tmpdir },
config,
cwd: tmpdir,
});

writeJSONFile('package.json', fixturePackageJson);
Expand Down
26 changes: 13 additions & 13 deletions test/tasks/try-each-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ describe('tryEach', () => {
_mockLog(outputFn);

let tryEachTask = new TryEachTask({
project: { root: tmpdir },
config,
cwd: tmpdir,
});

tryEachTask._on = () => {};
Expand Down Expand Up @@ -138,8 +138,8 @@ describe('tryEach', () => {
_mockLog(outputFn);

let tryEachTask = new TryEachTask({
project: { root: tmpdir },
config,
cwd: tmpdir,
});

tryEachTask._on = () => {};
Expand Down Expand Up @@ -203,8 +203,8 @@ describe('tryEach', () => {
_mockLog(outputFn);

let tryEachTask = new TryEachTask({
project: { root: tmpdir },
config,
cwd: tmpdir,
dependencyManagerAdapters: [],
});

Expand Down Expand Up @@ -251,8 +251,8 @@ describe('tryEach', () => {
_mockLog(outputFn);

let tryEachTask = new TryEachTask({
project: { root: tmpdir },
config,
cwd: tmpdir,
commandArgs: ['ember', 'serve'],
commandOptions: { timeout: { length: 20000, isSuccess: true } },
dependencyManagerAdapters: [new StubDependencyAdapter()],
Expand Down Expand Up @@ -305,8 +305,8 @@ describe('tryEach', () => {
_mockLog(outputFn);

let tryEachTask = new TryEachTask({
project: { root: tmpdir },
config,
cwd: tmpdir,
dependencyManagerAdapters: [new StubDependencyAdapter()],
});

Expand Down Expand Up @@ -356,8 +356,8 @@ describe('tryEach', () => {
_mockLog(outputFn);

let tryEachTask = new TryEachTask({
project: { root: tmpdir },
config,
cwd: tmpdir,
dependencyManagerAdapters: [new StubDependencyAdapter()],
});

Expand Down Expand Up @@ -408,8 +408,8 @@ describe('tryEach', () => {
_mockLog(outputFn);

let tryEachTask = new TryEachTask({
project: { root: tmpdir },
config,
cwd: tmpdir,
dependencyManagerAdapters: [new StubDependencyAdapter()],
});

Expand Down Expand Up @@ -463,8 +463,8 @@ describe('tryEach', () => {
_mockLog(outputFn);

let tryEachTask = new TryEachTask({
project: { root: tmpdir },
config,
cwd: tmpdir,
commandArgs: [],
dependencyManagerAdapters: [new StubDependencyAdapter()],
});
Expand Down Expand Up @@ -511,8 +511,8 @@ describe('tryEach', () => {
_mockLog(outputFn);

let tryEachTask = new TryEachTask({
project: { root: tmpdir },
config,
cwd: tmpdir,
commandArgs: ['ember', 'serve'],
dependencyManagerAdapters: [new StubDependencyAdapter()],
});
Expand Down Expand Up @@ -584,8 +584,8 @@ describe('tryEach', () => {
_mockLog(outputFn);

let tryEachTask = new TryEachTask({
project: { root: tmpdir },
config,
cwd: tmpdir,
dependencyManagerAdapters: [new StubDependencyAdapter()],
});

Expand Down Expand Up @@ -632,8 +632,8 @@ describe('tryEach', () => {
_mockLog(outputFn);

let tryEachTask = new TryEachTask({
project: { root: tmpdir },
config,
cwd: tmpdir,
commandArgs: ['ember', 'version', '--verbose', 'true'],
dependencyManagerAdapters: [new StubDependencyAdapter()],
});
Expand Down Expand Up @@ -688,8 +688,8 @@ describe('tryEach', () => {
_mockLog(outputFn);

let tryEachTask = new TryEachTask({
project: { root: tmpdir },
config,
cwd: tmpdir,
dependencyManagerAdapters: [new StubDependencyAdapter()],
});

Expand Down Expand Up @@ -742,8 +742,8 @@ describe('tryEach', () => {
};

let tryEachTask = new TryEachTask({
project: { root: tmpdir },
config,
cwd: tmpdir,
dependencyManagerAdapters: [new StubDependencyAdapter()],
});

Expand Down

0 comments on commit f747ca7

Please sign in to comment.