feat(@schematics/angular): support controlling addDependency utilit… · angular/angular-cli@707911d (original) (raw)

`@@ -15,7 +15,7 @@ import {

`

15

15

`callRule,

`

16

16

`chain,

`

17

17

`} from '@angular-devkit/schematics';

`

18

``

`-

import { DependencyType, addDependency } from './dependency';

`

``

18

`+

import { DependencyType, InstallBehavior, addDependency } from './dependency';

`

19

19

``

20

20

`async function testRule(rule: Rule, tree: Tree): Promise<TaskConfigurationGenerator[]> {

`

21

21

`const tasks: TaskConfigurationGenerator[] = [];

`

`@@ -192,6 +192,58 @@ describe('addDependency', () => {

`

192

192

`]);

`

193

193

`});

`

194

194

``

``

195

`+

it('schedules a package install task when install behavior is auto', async () => {

`

``

196

`+

const tree = new EmptyTree();

`

``

197

`+

tree.create('/abc/package.json', JSON.stringify({}));

`

``

198

+

``

199

`+

const rule = addDependency('@angular/core', '^14.0.0', {

`

``

200

`+

packageJsonPath: '/abc/package.json',

`

``

201

`+

install: InstallBehavior.Auto,

`

``

202

`+

});

`

``

203

+

``

204

`+

const tasks = await testRule(rule, tree);

`

``

205

+

``

206

`+

expect(tasks.map((task) => task.toConfiguration())).toEqual([

`

``

207

`+

{

`

``

208

`+

name: 'node-package',

`

``

209

`+

options: jasmine.objectContaining({ command: 'install', workingDirectory: '/abc' }),

`

``

210

`+

},

`

``

211

`+

]);

`

``

212

`+

});

`

``

213

+

``

214

`+

it('schedules a package install task when install behavior is always', async () => {

`

``

215

`+

const tree = new EmptyTree();

`

``

216

`+

tree.create('/abc/package.json', JSON.stringify({}));

`

``

217

+

``

218

`+

const rule = addDependency('@angular/core', '^14.0.0', {

`

``

219

`+

packageJsonPath: '/abc/package.json',

`

``

220

`+

install: InstallBehavior.Always,

`

``

221

`+

});

`

``

222

+

``

223

`+

const tasks = await testRule(rule, tree);

`

``

224

+

``

225

`+

expect(tasks.map((task) => task.toConfiguration())).toEqual([

`

``

226

`+

{

`

``

227

`+

name: 'node-package',

`

``

228

`+

options: jasmine.objectContaining({ command: 'install', workingDirectory: '/abc' }),

`

``

229

`+

},

`

``

230

`+

]);

`

``

231

`+

});

`

``

232

+

``

233

`+

it('does not schedule a package install task when install behavior is none', async () => {

`

``

234

`+

const tree = new EmptyTree();

`

``

235

`+

tree.create('/abc/package.json', JSON.stringify({}));

`

``

236

+

``

237

`+

const rule = addDependency('@angular/core', '^14.0.0', {

`

``

238

`+

packageJsonPath: '/abc/package.json',

`

``

239

`+

install: InstallBehavior.None,

`

``

240

`+

});

`

``

241

+

``

242

`+

const tasks = await testRule(rule, tree);

`

``

243

+

``

244

`+

expect(tasks).toEqual([]);

`

``

245

`+

});

`

``

246

+

195

247

`it('does not schedule a package install task if version is the same', async () => {

`

196

248

`const tree = new EmptyTree();

`

197

249

`tree.create(

`

`@@ -208,7 +260,7 @@ describe('addDependency', () => {

`

208

260

`expect(tasks).toEqual([]);

`

209

261

`});

`

210

262

``

211

``

`-

it('only schedules one package install task for the same manifest path', async () => {

`

``

263

`+

it('only schedules one package install task for the same manifest path by default', async () => {

`

212

264

`const tree = new EmptyTree();

`

213

265

`tree.create('/package.json', JSON.stringify({}));

`

214

266

``

`@@ -227,6 +279,86 @@ describe('addDependency', () => {

`

227

279

`]);

`

228

280

`});

`

229

281

``

``

282

`+

it('only schedules one package install task for the same manifest path with auto install behavior', async () => {

`

``

283

`+

const tree = new EmptyTree();

`

``

284

`+

tree.create('/package.json', JSON.stringify({}));

`

``

285

+

``

286

`+

const rule = chain([

`

``

287

`+

addDependency('@angular/core', '^14.0.0', { install: InstallBehavior.Auto }),

`

``

288

`+

addDependency('@angular/common', '^14.0.0', { install: InstallBehavior.Auto }),

`

``

289

`+

]);

`

``

290

+

``

291

`+

const tasks = await testRule(rule, tree);

`

``

292

+

``

293

`+

expect(tasks.map((task) => task.toConfiguration())).toEqual([

`

``

294

`+

{

`

``

295

`+

name: 'node-package',

`

``

296

`+

options: jasmine.objectContaining({ command: 'install', workingDirectory: '/' }),

`

``

297

`+

},

`

``

298

`+

]);

`

``

299

`+

});

`

``

300

+

``

301

`+

it('only schedules one package install task for the same manifest path with mixed auto/none install behavior', async () => {

`

``

302

`+

const tree = new EmptyTree();

`

``

303

`+

tree.create('/package.json', JSON.stringify({}));

`

``

304

+

``

305

`+

const rule = chain([

`

``

306

`+

addDependency('@angular/core', '^14.0.0', { install: InstallBehavior.Auto }),

`

``

307

`+

addDependency('@angular/common', '^14.0.0', { install: InstallBehavior.None }),

`

``

308

`+

]);

`

``

309

+

``

310

`+

const tasks = await testRule(rule, tree);

`

``

311

+

``

312

`+

expect(tasks.map((task) => task.toConfiguration())).toEqual([

`

``

313

`+

{

`

``

314

`+

name: 'node-package',

`

``

315

`+

options: jasmine.objectContaining({ command: 'install', workingDirectory: '/' }),

`

``

316

`+

},

`

``

317

`+

]);

`

``

318

`+

});

`

``

319

+

``

320

`+

it('only schedules one package install task for the same manifest path with mixed always then auto install behavior', async () => {

`

``

321

`+

const tree = new EmptyTree();

`

``

322

`+

tree.create('/package.json', JSON.stringify({}));

`

``

323

+

``

324

`+

const rule = chain([

`

``

325

`+

addDependency('@angular/core', '^14.0.0', { install: InstallBehavior.Always }),

`

``

326

`+

addDependency('@angular/common', '^14.0.0', { install: InstallBehavior.Auto }),

`

``

327

`+

]);

`

``

328

+

``

329

`+

const tasks = await testRule(rule, tree);

`

``

330

+

``

331

`+

expect(tasks.map((task) => task.toConfiguration())).toEqual([

`

``

332

`+

{

`

``

333

`+

name: 'node-package',

`

``

334

`+

options: jasmine.objectContaining({ command: 'install', workingDirectory: '/' }),

`

``

335

`+

},

`

``

336

`+

]);

`

``

337

`+

});

`

``

338

+

``

339

`+

it('schedules multiple package install tasks for the same manifest path with mixed auto then always install behavior', async () => {

`

``

340

`+

const tree = new EmptyTree();

`

``

341

`+

tree.create('/package.json', JSON.stringify({}));

`

``

342

+

``

343

`+

const rule = chain([

`

``

344

`+

addDependency('@angular/core', '^14.0.0', { install: InstallBehavior.Auto }),

`

``

345

`+

addDependency('@angular/common', '^14.0.0', { install: InstallBehavior.Always }),

`

``

346

`+

]);

`

``

347

+

``

348

`+

const tasks = await testRule(rule, tree);

`

``

349

+

``

350

`+

expect(tasks.map((task) => task.toConfiguration())).toEqual([

`

``

351

`+

{

`

``

352

`+

name: 'node-package',

`

``

353

`+

options: jasmine.objectContaining({ command: 'install', workingDirectory: '/' }),

`

``

354

`+

},

`

``

355

`+

{

`

``

356

`+

name: 'node-package',

`

``

357

`+

options: jasmine.objectContaining({ command: 'install', workingDirectory: '/' }),

`

``

358

`+

},

`

``

359

`+

]);

`

``

360

`+

});

`

``

361

+

230

362

`it('schedules a package install task for each manifest path present', async () => {

`

231

363

`const tree = new EmptyTree();

`

232

364

`tree.create('/package.json', JSON.stringify({}));

`