Skip to content

Commit 27aad4e

Browse files
add minimal docs + collect telemetry while running the codemod (#8)
* add minimal docs * Update bin/cli.js Co-Authored-By: Robert Jackson <[email protected]> * update, lint, etc * re-add the logger * add more builtins * add all helpers * remove console warn * fixed everything * Linting
1 parent 5b86872 commit 27aad4e

11 files changed

Lines changed: 802 additions & 679 deletions

File tree

README.md

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,13 @@
55
[![npm](https://img.shields.io/npm/v/ember-no-implicit-this-codemod.svg?label=npm)](https://www.npmjs.com/package/ember-no-implicit-this-codemod)
66

77

8-
A collection of codemod's for ember-no-implicit-this-codemod.
9-
108
## Usage
119

12-
To run a specific codemod from this project, you would run the following:
13-
14-
```
15-
npx ember-no-implicit-this-codemod http://localhost:4200 path/of/files/ or/some**/*glob.hbs
16-
17-
# or
18-
19-
yarn global add ember-no-implicit-this-codemod
20-
ember-no-implicit-this-codemod http://url/of/local/dev-server path/of/files/ or/some**/*glob.js
21-
```
22-
23-
The codemod accepts the following options:
24-
25-
| Option | Value | Default | Details |
26-
| --- | --- | ---| --- |
27-
| --dont-assume-this | boolean | false | The codemod won't prepend `this.` to `PathExpressions` names which don't appear in a component's telemetry data |
28-
29-
## Transforms
30-
31-
<!--TRANSFORMS_START-->
32-
* [no-implicit-this](transforms/no-implicit-this/README.md)
33-
<!--TRANSFORMS_END-->
10+
1. Start your ember development server
11+
2. Run Codemod, pointing it at the address of the development server
12+
```
13+
npx ember-no-implicit-this-codemod http://localhost:4200 path/of/files/ or/some**/*glob.hbs
14+
```
3415
3516
## Contributing
3617
@@ -44,6 +25,6 @@ The codemod accepts the following options:
4425
4526
* `yarn test`
4627
47-
### Update Documentation
28+
#### Running a single test
4829
49-
* `yarn update-docs`
30+
* `yarn test --runInBand --testNamePattern=void-elements`

bin/cli.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22
'use strict';
33

44
const { gatherTelemetryForUrl } = require('ember-codemods-telemetry-helpers');
5+
const appLocation = process.argv[2];
6+
const args = process.argv.slice(3);
57

68
(async () => {
7-
await gatherTelemetryForUrl(process.argv[2]);
9+
await gatherTelemetryForUrl(appLocation);
810

9-
require('codemod-cli').runTransform(
10-
__dirname,
11-
'no-implicit-this',
12-
process.argv.slice(2) /* paths or globs */
13-
);
11+
require('codemod-cli').runTransform(__dirname, 'no-implicit-this', args, 'hbs');
1412
})();

bin/telemetry.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env node
22
'use strict';
33

4-
const { gatherTelemetry } = require('ember-codemods-telemetry-helpers');
4+
const { gatherTelemetryForUrl } = require('ember-codemods-telemetry-helpers');
55

6-
gatherTelemetry(process.argv[2]);
6+
gatherTelemetryForUrl(process.argv[2]);

package.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,27 +31,27 @@
3131
"codemod-cli"
3232
],
3333
"dependencies": {
34-
"codemod-cli": "^1.1.0",
35-
"ember-codemods-telemetry-helpers": "^0.4.0",
36-
"ember-template-recast": "^3.1.3",
34+
"codemod-cli": "^2.1.0",
35+
"ember-codemods-telemetry-helpers": "^0.5.0",
36+
"ember-template-recast": "^3.2.0",
3737
"fs-extra": "^8.1.0",
3838
"git-repo-info": "^2.1.0",
3939
"minimatch": "^3.0.4",
40-
"puppeteer": "^1.19.0",
40+
"puppeteer": "^1.20.0",
4141
"sync-disk-cache": "^1.3.3",
4242
"walk-sync": "^2.0.2",
4343
"winston": "^3.2.1"
4444
},
4545
"devDependencies": {
46-
"babel-plugin-htmlbars-inline-precompile": "^1.0.0",
46+
"babel-plugin-htmlbars-inline-precompile": "^3.0.0",
4747
"coveralls": "^3.0.6",
48-
"eslint": "^6.1.0",
49-
"eslint-config-prettier": "^6.0.0",
50-
"eslint-plugin-prettier": "^3.1.0",
51-
"execa": "^2.0.4",
52-
"jest": "^24.8.0",
48+
"eslint": "^6.5.1",
49+
"eslint-config-prettier": "^6.3.0",
50+
"eslint-plugin-prettier": "^3.1.1",
51+
"execa": "^2.0.5",
52+
"jest": "^24.9.0",
5353
"prettier": "^1.18.2",
54-
"release-it": "^12.3.5",
54+
"release-it": "^12.4.2",
5555
"release-it-lerna-changelog": "^1.0.3"
5656
},
5757
"engines": {

transforms/no-implicit-this/__testfixtures__/-mock-telemetry.json

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,60 +4,52 @@
44
"block-component": { "type": "Component" },
55
"foo": { "type": "Component" },
66
"namespace/foo": { "type": "Component" },
7-
"built-in-helpers.input": {
7+
"built-in-helpers": {
88
"type": "Component",
99
"computedProperties": ["foo", "records"],
1010
"ownActions": ["myAction"]
1111
},
12-
"angle-brackets-with-block-params.input": {
12+
"angle-brackets-with-block-params": {
1313
"type": "Component",
1414
"computedProperties": ["foo", "property", "bar"],
1515
"ownActions": ["myAction"]
1616
},
17-
"angle-brackets-with-hash-params.input": {
17+
"angle-brackets-with-hash-params": {
1818
"type": "Component",
1919
"computedProperties": ["foo", "property"],
2020
"ownActions": ["myAction"]
2121
},
22-
"angle-brackets-without-params.input": {
22+
"angle-brackets-without-params": {
2323
"type": "Component",
2424
"computedProperties": ["foo"]
2525
},
26-
"dont-assume-this.input": {
26+
"dont-assume-this": {
2727
"type": "Component",
2828
"computedProperties": ["foo"]
2929
},
30-
"handlebars-with-positional-params.input": {
30+
"handlebars-with-positional-params": {
3131
"type": "Component",
3232
"computedProperties": ["foo", "property"],
3333
"ownActions": ["myAction"]
3434
},
35-
"handlebars-with-hash-params.input": {
35+
"handlebars-with-hash-params": {
3636
"type": "Component",
3737
"computedProperties": ["foo", "property"],
3838
"ownActions": ["myAction"]
3939
},
40-
"handlebars-with-block-params.input": {
40+
"handlebars-with-block-params": {
4141
"type": "Component",
4242
"computedProperties": ["foo", "property"]
4343
},
44-
"handlebars-without-params.input": {
44+
"handlebars-without-params": {
4545
"type": "Component",
4646
"computedProperties": ["foo", "property"],
4747
"getters": ["someGetter"]
4848
},
49-
"void-elements.input": {
49+
"void-elements": {
5050
"type": "Component",
5151
"computedProperties": ["previewImageUrl"]
5252
},
5353
"my-helper": { "type": "Helper" },
54-
"a-helper": { "type": "Helper" },
55-
"link-to": { "type": "Helper" },
56-
"action": { "type": "Helper" },
57-
"concat": { "type": "Helper" },
58-
"each": { "type": "Helper" },
59-
"mut": { "type": "Helper" },
60-
"let": { "type": "Helper" },
61-
"if": { "type": "Helper" },
62-
"fn": { "type": "Helper" }
54+
"a-helper": { "type": "Helper" }
6355
}

transforms/no-implicit-this/helpers/determine-this-usage.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ function determineThisUsage(ast, file, options) {
1515
let runtimeData = getTelemetryFor(path.resolve(filePath));
1616

1717
if (!runtimeData) {
18-
logger.warn(`[${filePath}]: SKIPPED Could not find runtime data NO_RUNTIME_DATA`);
18+
let msg = `[${filePath}]: SKIPPED Could not find runtime data NO_RUNTIME_DATA`;
19+
logger.warn(msg);
1920
return;
2021
}
2122

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
const KNOWN_HELPERS = [
2+
// Ember.js
3+
'action',
4+
'array',
5+
'component',
6+
'concat',
7+
'debugger',
8+
'each',
9+
'each-in',
10+
'else',
11+
'fn',
12+
'get',
13+
'hash',
14+
'has-block',
15+
'hasBlock',
16+
'if',
17+
'if-unless',
18+
'in-element',
19+
'-in-element',
20+
'input',
21+
'textarea',
22+
'let',
23+
'link-to',
24+
'loc',
25+
'log',
26+
'mut',
27+
'on',
28+
'outlet',
29+
'partial',
30+
'query-params',
31+
'readonly',
32+
'unbound',
33+
'unless',
34+
'with',
35+
'yield',
36+
37+
// Glimmer VM
38+
'identity', // glimmer blocks
39+
'render-inverse', // glimmer blocks
40+
'-get-dynamic-var', // glimmer internal helper
41+
42+
// ember-route-helpers
43+
'transition-to',
44+
'replace-with',
45+
'transition-to-external',
46+
'replace-with-external',
47+
48+
// ember-intl
49+
'format-date',
50+
'format-message',
51+
'format-relative',
52+
'format-time',
53+
'format-money',
54+
'format-number',
55+
't',
56+
57+
// ember-moment
58+
'is-after',
59+
'is-before',
60+
'is-between',
61+
'is-same',
62+
'is-same-or-after',
63+
'is-same-or-before',
64+
'moment',
65+
'moment-calendar',
66+
'moment-diff',
67+
'moment-duration',
68+
'moment-format',
69+
'moment-from',
70+
'moment-from-now',
71+
'moment-to',
72+
'moment-to-now',
73+
'now',
74+
'unix',
75+
76+
// ember-cp-validations
77+
'v-get',
78+
79+
// ember-route-action-helper
80+
'route-action',
81+
82+
// ember-composable-helpers
83+
'map-by',
84+
'sort-by',
85+
'filter-by',
86+
'reject-by',
87+
'find-by',
88+
'object-at',
89+
'has-block',
90+
'has-next',
91+
'has-previous',
92+
'group-by',
93+
'not-eq',
94+
'is-array',
95+
'is-empty',
96+
'is-equal',
97+
98+
// liquid-fire
99+
'liquid-unless',
100+
'liquid-container',
101+
'liquid-outlet',
102+
'liquid-versions',
103+
'liquid-bind',
104+
'liquid-spacer',
105+
'liquid-sync',
106+
'liquid-measured',
107+
'liquid-child',
108+
'liquid-if',
109+
110+
// ember-animated
111+
'animated-beacon',
112+
'animated-each',
113+
'animated-if',
114+
'animated-orphans',
115+
'animated-value',
116+
117+
// ember-app-version
118+
'app-version',
119+
120+
// ember-font-awesome
121+
'fa-icon',
122+
'fa-list',
123+
'fa-stack',
124+
125+
// ember-svg-jar
126+
'svg-jar',
127+
128+
// ember-concurrency
129+
'perform',
130+
131+
// ember-maybe-in-element
132+
'maybe-in-element',
133+
];
134+
135+
module.exports = KNOWN_HELPERS;

transforms/no-implicit-this/helpers/plugin.js

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,12 @@ const { getTelemetry } = require('ember-codemods-telemetry-helpers');
22
// everything is copy-pasteable to astexplorer.net.
33
// sorta. telemetry needs to be defined.
44
// telemtry can be populated with -mock-telemetry.json
5-
const ARGLESS_BUILTINS = [
6-
'debugger',
7-
'has-block',
8-
'hasBlock',
9-
'input',
10-
'outlet',
11-
'textarea',
12-
'yield',
13-
];
5+
const KNOWN_HELPERS = require('./known-helpers');
146

157
/**
168
* plugin entrypoint
179
*/
18-
function transformPlugin(env, runtimeData, options) {
10+
function transformPlugin(env, runtimeData, options = {}) {
1911
let { builders: b } = env.syntax;
2012

2113
let scopedParams = [];
@@ -70,7 +62,7 @@ function doesTokenNeedThis(
7062
runtimeData,
7163
{ dontAssumeThis }
7264
) {
73-
if (ARGLESS_BUILTINS.includes(token)) {
65+
if (KNOWN_HELPERS.includes(token)) {
7466
return false;
7567
}
7668

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const path = require('path');
2+
const { setTelemetry } = require('ember-codemods-telemetry-helpers');
3+
const mockTelemetryData = require('./__testfixtures__/-mock-telemetry.json');
4+
5+
function setupTelemetry() {
6+
let mockTelemetry = {};
7+
8+
Object.keys(mockTelemetryData).forEach(key => {
9+
let value = mockTelemetryData[key] || {};
10+
let mockPath = path.resolve(__dirname, `./__testfixtures__/${key}`);
11+
12+
mockTelemetry[mockPath] = value;
13+
});
14+
15+
setTelemetry(mockTelemetry);
16+
}
17+
18+
module.exports = { setupTelemetry };

0 commit comments

Comments
 (0)