|
1 | | -module.exports = function(file, api, options) { |
| 1 | +module.exports = function(file, api) { |
2 | 2 | const j = api.jscodeshift; |
3 | 3 | const root = j(file.source); |
4 | 4 |
|
@@ -28,10 +28,10 @@ module.exports = function(file, api, options) { |
28 | 28 | let anchorImport = root.find(j.ImportDeclaration, { source: { value: anchor } }); |
29 | 29 | let imports = root.find(j.ImportDeclaration); |
30 | 30 | if (anchorImport.size() > 0) { |
31 | | - anchorImport[method](newImport); |
| 31 | + anchorImport.at(anchorImport.size() - 1)[method](newImport); |
32 | 32 | } else if (imports.size() > 0) { |
33 | 33 | // if anchor is not present, always add at the end |
34 | | - imports.insertAfter(newImport); |
| 34 | + imports.at(imports.size() - 1).insertAfter(newImport); |
35 | 35 | } else { |
36 | 36 | // if no imports are present, add as first statement |
37 | 37 | root.get().node.program.body.unshift(newImport); |
@@ -415,20 +415,31 @@ module.exports = function(file, api, options) { |
415 | 415 | ) |
416 | 416 | ); |
417 | 417 | } else if (subjectType === 'model') { |
| 418 | + ensureImportWithSpecifiers({ |
| 419 | + source: '@ember/runloop', |
| 420 | + specifiers: ['run'], |
| 421 | + }); |
| 422 | + |
418 | 423 | p.replace( |
419 | | - j.callExpression( |
420 | | - j.memberExpression( |
| 424 | + j.callExpression(j.identifier('run'), [ |
| 425 | + j.arrowFunctionExpression( |
| 426 | + [], |
421 | 427 | j.callExpression( |
422 | 428 | j.memberExpression( |
423 | | - j.memberExpression(j.thisExpression(), j.identifier('owner')), |
424 | | - j.identifier('lookup') |
| 429 | + j.callExpression( |
| 430 | + j.memberExpression( |
| 431 | + j.memberExpression(j.thisExpression(), j.identifier('owner')), |
| 432 | + j.identifier('lookup') |
| 433 | + ), |
| 434 | + [j.literal('service:store')] |
| 435 | + ), |
| 436 | + j.identifier('createRecord') |
425 | 437 | ), |
426 | | - [j.literal('service:store')] |
| 438 | + [j.literal(subjectName), options].filter(Boolean) |
427 | 439 | ), |
428 | | - j.identifier('createRecord') |
| 440 | + true |
429 | 441 | ), |
430 | | - [j.literal(subjectName), options].filter(Boolean) |
431 | | - ) |
| 442 | + ]) |
432 | 443 | ); |
433 | 444 | } else { |
434 | 445 | p.replace( |
@@ -636,7 +647,7 @@ module.exports = function(file, api, options) { |
636 | 647 | } |
637 | 648 | } |
638 | 649 |
|
639 | | - const printOptions = options.printOptions || { quote: 'single' }; |
| 650 | + const printOptions = { quote: 'single', wrapColumn: 100 }; |
640 | 651 |
|
641 | 652 | moveQUnitImportsFromEmberQUnit(); |
642 | 653 | updateToNewEmberQUnitImports(); |
|
0 commit comments