Skip to content

Buildtime telemetry #393

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 26 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 25 additions & 30 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,29 @@
module.exports = {
root: true,
parserOptions: {
ecmaVersion: 2017
root: true,
parserOptions: {
ecmaVersion: 2017,
},
env: {
node: true,
es6: true,
},
extends: ['eslint:recommended', 'prettier'],
plugins: ['prettier'],
rules: {
'prettier/prettier': 'error',
},
overrides: [
{
files: ['**/*.ts'],
parser: '@typescript-eslint/parser',
plugins: ['prettier', '@typescript-eslint'],
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'prettier'],
},
env: {
node: true,
es6: true
},
extends: ["eslint:recommended", "prettier"],
plugins: ["prettier"],
rules: {
"prettier/prettier": "error"
},
overrides: [
{
files: ['**/*.ts'],
parser: '@typescript-eslint/parser',
plugins: ['prettier', '@typescript-eslint'],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'prettier',
'prettier/@typescript-eslint',
],
{
files: ['**/*.test.js'],
env: {
jest: true,
},
{
files: ['**/*.test.js'],
env: {
jest: true
}
}
]
},
],
};
12 changes: 6 additions & 6 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ jobs:
timeout-minutes: 15

steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '10.x'
node-version: '16.x'
- name: Install
run: yarn install
- name: Linting
Expand All @@ -30,10 +30,10 @@ jobs:
timeout-minutes: 15

steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '10.x'
node-version: '16.x'
- name: Install
run: yarn install
- name: Test
Expand Down
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,11 @@ node_modules
tmp
*.log
test/**/yarn.lock
test/**/*.js
test/**/*.js.map
!**/fixtures/**/*
transforms/**/*.js
transforms/**/*.js.map
helpers/**/*.js
helpers/**/*.js.map
!**/__testfixtures__/**/*
79 changes: 79 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
```ts
const { Webpack } = require('@embroider/webpack');
return require('@embroider/compat').compatBuild(app, Webpack, {
// staticComponents: true,
// staticModifiers: true,
// staticHelpers: true,
skipBabel: [
{
package: 'qunit',
},
],
});
```

1. Find '@embroider/webpack' entry point
2. Look at second arg to `compatBuild`
3. ...?

FIXME: rename resolver -> telemetry ???

FIXME: Clean up logging shenanigans (e.g. console.log/info, debug)

FIXME: Figure out how to pass no-babel option to jscodeshift via codemod-cli

FIXME: Extract ember codemod buildtime resolver

FIXME: Optional angle-bracketification?


# TODO

- [ ] Make telemetry pluggable
- [ ] Maybe Discourse can make their own Telemetry plugin
- [ ] Embroider telemetry plugin[1]

## Problems

[1] Embroider compat tries to link up your modules by emitting the implicit imports.

## Questions for tomorrow

1. How does the angle bracket codemod work?

## Questions for EF4

1. Is this even possible?!?

```ts
{{ambiguous}} ->
1. <Ambiguous>
2. {{(ambiguous)}}
3. {{this.ambiguous}}
4. {{ambiguous}} //modifier

1. leave it alone
2. change to {{this.ambiguous}}
(3. error?)

enum DisambiguateResult {
LeaveIt,
ChangeIt,
CantDoIt,
}

enum Namespace {
Helper,
Component,
ComponentOrHelper,
Modifier,
}

function disambiguate(headName: string, namespace: Namespace, ...?): DisambiguateResult {
// ...
// SOMETHING SOMETHING PLUG IN EMBROIDER
}



```
24 changes: 8 additions & 16 deletions bin/cli.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
#!/usr/bin/env node
'use strict';

const debug = require('debug')('ember-no-implicit-this-codemod');
const {
gatherTelemetryForUrl,
analyzeEmberObject,
getTelemetry,
} = require('ember-codemods-telemetry-helpers');
const appLocation = process.argv[2];
const args = process.argv.slice(3);
const { Runner } = require('../transforms/no-implicit-this/helpers/options');

(async () => {
debug('Gathering telemetry data from %s ...', appLocation);
await gatherTelemetryForUrl(appLocation, analyzeEmberObject);
const args = process.argv.slice(2);

let telemetry = getTelemetry();
debug('Gathered telemetry on %d modules', Object.keys(telemetry).length);

require('codemod-cli').runTransform(__dirname, 'no-implicit-this', args, 'hbs');
})();
Runner.withArgs(args)
.run(__dirname, args)
.catch((error) => {
console.error(error);
process.exit(1);
});
10 changes: 10 additions & 0 deletions helpers/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/** Type predicate. Checks if the given value is a `Record<string, unknown>`. */
export function isRecord<R extends Record<string, unknown>>(value: unknown): value is R {
return value !== null && typeof value === 'object';
}

export function assert(message: string): never;
export function assert(message: string, cond: unknown): asserts cond;
export function assert(message: string, cond?: unknown): asserts cond {
if (!cond) throw new Error(message);
}
53 changes: 40 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,27 @@
},
"homepage": "https://github.com/ember-codemods/ember-no-implicit-this-codemod#readme",
"author": "",
"files": [
"/bin",
"/helpers/**/*.js",
"/transforms/no-implicit-this/index.js",
"/transforms/no-implicit-this/helpers/**/*.js"
],
"scripts": {
"release": "release-it",
"prepublishOnly": "yarn build",
"build": "tsc",
"clean": "tsc --build --clean",
"pretest": "yarn build",
"test": "jest",
"test:integration": "ts-node ./test/run-test.ts",
"pretest:integration": "yarn build",
"test:integration": "node ./test/run-test.js",
"test:integration:embroider": "yarn test:integration --embroider",
"test:integration:runtime": "yarn test:integration --runtime",
"update-docs": "codemod-cli update-docs",
"coveralls": "cat ./coverage/lcov.info | node node_modules/.bin/coveralls",
"lint:js": "eslint .",
"lint:ts": "tsc --noEmit",
"debug:telemetry": "node --inspect-brk ./bin/telemetry.js",
"debug:codemod:not-working": "node --inspect-brk ./bin/cli",
"codemod": "jscodeshift -t ./transforms/no-implicit-this/index.js --extensions js,ts,hbs --run-in-band",
Expand All @@ -31,33 +45,46 @@
"codemod-cli"
],
"dependencies": {
"codemod-cli": "^2.1.0",
"@babel/core": "^7.21.8",
"@babel/preset-env": "^7.21.5",
"@embroider/core": "^3.0.0",
"codemod-cli": "^3.2.0",
"debug": "^4.1.1",
"ember-codemods-telemetry-helpers": "^2.1.0",
"ember-template-recast": "^3.3.2"
"ember-codemods-telemetry-helpers": "^3.0.0",
"ember-template-recast": "^6.1.4",
"yargs": "^17.7.2",
"zod": "^3.21.4"
},
"devDependencies": {
"@embroider/compat": "^3.0.0",
"@embroider/webpack": "^3.0.0",
"@jest/globals": "^29.5.0",
"@tsconfig/node16": "^1.0.4",
"@tsconfig/strictest": "^2.0.1",
"@types/chalk": "^2.2.0",
"@types/common-tags": "^1.8.0",
"@typescript-eslint/eslint-plugin": "^2.34.0",
"@typescript-eslint/parser": "^2.34.0",
"@types/debug": "^4.1.8",
"@types/jscodeshift": "^0.11.6",
"@types/node": "^20.2.3",
"@typescript-eslint/eslint-plugin": "^5.59.7",
"@typescript-eslint/parser": "^5.59.7",
"babel-plugin-htmlbars-inline-precompile": "^3.0.1",
"chalk": "^4.1.1",
"common-tags": "^1.8.0",
"coveralls": "^3.1.0",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.15.0",
"eslint": "^8.41.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-prettier": "^3.4.0",
"execa": "^3.4.0",
"jest": "^26.6.3",
"prettier": "^1.19.1",
"jest": "^29.1.0",
"prettier": "^2.8.8",
"release-it": "^14.6.2",
"release-it-lerna-changelog": "^3.1.0",
"ts-node": "^8.10.2",
"typescript": "~3.9.7"
"typescript": "~5.0.4",
"webpack": "^5.84.1"
},
"engines": {
"node": "8.* || 10.* || >= 12"
"node": "16.* || 18.* || >= 20"
},
"jest": {
"testEnvironment": "node",
Expand Down
19 changes: 19 additions & 0 deletions test/fixtures/3.28/input/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# editorconfig.org

root = true

[*]
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
indent_style = space
indent_size = 2

[*.hbs]
insert_final_newline = false

[*.{diff,md}]
trim_trailing_whitespace = false
9 changes: 9 additions & 0 deletions test/fixtures/3.28/input/.ember-cli
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
/**
Ember CLI sends analytics information by default. The data is completely
anonymous, but there are times when you might want to disable this behavior.

Setting `disableAnalytics` to true will prevent any data from being sent.
*/
"disableAnalytics": false
}
22 changes: 22 additions & 0 deletions test/fixtures/3.28/input/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# unconventional js
/blueprints/*/files/
/vendor/

# compiled output
/dist/
/tmp/

# dependencies
/bower_components/
/node_modules/

# misc
/coverage/
!.*
.*/
.eslintcache

# ember-try
/.node_modules.ember-try/
/bower.json.ember-try
/package.json.ember-try
Loading