-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathindex.js
More file actions
47 lines (37 loc) · 1.2 KB
/
index.js
File metadata and controls
47 lines (37 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const { getParser } = require('codemod-cli').jscodeshift;
const { addImportStatement, writeImportStatements } = require('../utils');
module.exports = function transformer(file, api) {
const j = getParser(api);
const root = j(file.source);
/**
* Transform imports from ember-test-helpers to @ember/test-helpers
*/
function transform() {
let deprecatedEmberTestHelperStatements = root.find(j.ImportDeclaration, {
source: { value: 'ember-test-helpers' },
});
if (deprecatedEmberTestHelperStatements.length === 0) {
return root.toSource({
quote: 'single',
trailingComma: true,
});
}
let newImports = [];
deprecatedEmberTestHelperStatements.forEach((importStatement) => {
let oldSpecifiers = importStatement.get('specifiers');
oldSpecifiers.each(({ node: specifier }) => {
let importedName = specifier.imported.name;
newImports.push(importedName);
});
// Remove "ember-test-helper" import statement
j(importStatement).remove();
});
addImportStatement(newImports);
writeImportStatements(j, root);
}
transform();
return root.toSource({
quote: 'single',
trailingComma: true,
});
};