Skip to content

Commit 8144d53

Browse files
committed
Add telemetry option
1 parent 60ec499 commit 8144d53

File tree

17 files changed

+454
-355
lines changed

17 files changed

+454
-355
lines changed

.eslintrc.js

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,29 @@
11
module.exports = {
2-
root: true,
3-
parserOptions: {
4-
ecmaVersion: 2017
2+
root: true,
3+
parserOptions: {
4+
ecmaVersion: 2017,
5+
},
6+
env: {
7+
node: true,
8+
es6: true,
9+
},
10+
extends: ['eslint:recommended', 'prettier'],
11+
plugins: ['prettier'],
12+
rules: {
13+
'prettier/prettier': 'error',
14+
},
15+
overrides: [
16+
{
17+
files: ['**/*.ts'],
18+
parser: '@typescript-eslint/parser',
19+
plugins: ['prettier', '@typescript-eslint'],
20+
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'prettier'],
521
},
6-
env: {
7-
node: true,
8-
es6: true
9-
},
10-
extends: ["eslint:recommended", "prettier"],
11-
plugins: ["prettier"],
12-
rules: {
13-
"prettier/prettier": "error"
14-
},
15-
overrides: [
16-
{
17-
files: ['**/*.ts'],
18-
parser: '@typescript-eslint/parser',
19-
plugins: ['prettier', '@typescript-eslint'],
20-
extends: [
21-
'eslint:recommended',
22-
'plugin:@typescript-eslint/recommended',
23-
'prettier',
24-
'prettier/@typescript-eslint',
25-
],
22+
{
23+
files: ['**/*.test.js'],
24+
env: {
25+
jest: true,
2626
},
27-
{
28-
files: ['**/*.test.js'],
29-
env: {
30-
jest: true
31-
}
32-
}
33-
]
27+
},
28+
],
3429
};

TODO.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
```ts
2+
const { Webpack } = require('@embroider/webpack');
3+
return require('@embroider/compat').compatBuild(app, Webpack, {
4+
// staticComponents: true,
5+
// staticModifiers: true,
6+
// staticHelpers: true,
7+
skipBabel: [
8+
{
9+
package: 'qunit',
10+
},
11+
],
12+
});
13+
```
14+
15+
1. Find '@embroider/webpack' entry point
16+
2. Look at second arg to `compatBuild`
17+
3. ...?
18+
19+
20+
# TODO
21+
22+
- [ ] Make telemetry pluggable
23+
- [ ] Maybe Discourse can make their own Telemetry plugin
24+
- [ ] Embroider telemetry plugin[1]
25+
26+
## Problems
27+
28+
[1] Embroider compat tries to link up your modules by emitting the implicit imports.
29+
30+
## Questions for tomorrow
31+
32+
1. How does the angle bracket codemod work?
33+
34+
## Questions for EF4
35+
36+
1. Is this even possible?!?
37+
38+
```ts
39+
{{ambiguous}} ->
40+
1. <Ambiguous>
41+
2. {{(ambiguous)}}
42+
3. {{this.ambiguous}}
43+
4. {{ambiguous}} //modifier
44+
45+
1. leave it alone
46+
2. change to {{this.ambiguous}}
47+
(3. error?)
48+
49+
enum DisambiguateResult {
50+
LeaveIt,
51+
ChangeIt,
52+
CantDoIt,
53+
}
54+
55+
enum Namespace {
56+
Helper,
57+
Component,
58+
ComponentOrHelper,
59+
Modifier,
60+
}
61+
62+
function disambiguate(headName: string, namespace: Namespace, ...?): DisambiguateResult {
63+
// ...
64+
// SOMETHING SOMETHING PLUG IN EMBROIDER
65+
}
66+
67+
68+
69+
```

helpers/types.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
/** Type predicate. Checks if the given value is a `Record<string, unknown>`. */
2-
export function isRecord<R extends Record<string, unknown>>(
3-
value: unknown
4-
): value is R {
2+
export function isRecord<R extends Record<string, unknown>>(value: unknown): value is R {
53
return value !== null && typeof value === 'object';
6-
}
4+
}

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@
6464
"chalk": "^4.1.1",
6565
"common-tags": "^1.8.0",
6666
"coveralls": "^3.1.0",
67-
"eslint": "^6.8.0",
68-
"eslint-config-prettier": "^6.15.0",
67+
"eslint": "^8.41.0",
68+
"eslint-config-prettier": "^8.8.0",
6969
"eslint-plugin-prettier": "^3.4.0",
7070
"execa": "^3.4.0",
7171
"jest": "^29.1.0",
72-
"prettier": "^1.19.1",
72+
"prettier": "^2.8.8",
7373
"release-it": "^14.6.2",
7474
"release-it-lerna-changelog": "^3.1.0",
7575
"ts-jest": "^29.1.0",
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{{not false}}
22

3-
{{#if (not foo)}}
4-
{{foo}}
3+
{{#if (not this.foo)}}
4+
{{this.foo}}
55
{{/if}}
66

77
{{outlet}}

test/helpers/test-runner.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ export class TestRunner {
4343
emberServe.stderr?.pipe(process.stderr);
4444
}
4545

46-
const serverWaiter = new Promise<void>(resolve => {
47-
emberServe.stdout?.on('data', data => {
46+
const serverWaiter = new Promise<void>((resolve) => {
47+
emberServe.stdout?.on('data', (data) => {
4848
if (data.toString().includes('Build successful')) {
4949
resolve();
5050
}
@@ -75,7 +75,7 @@ export class TestRunner {
7575

7676
await execa('diff', ['-rq', actual, expectedApp], { cwd: this.inputDir, stdio: 'inherit' });
7777
} catch (e) {
78-
console.log(isRecord(e) ? e['stdout']: 'codemod did not run successfully');
78+
console.log(isRecord(e) ? e['stdout'] : 'codemod did not run successfully');
7979

8080
throw new Error('codemod did not run successfully');
8181
}

test/helpers/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ export async function kill(subprocess: execa.ExecaChildProcess): Promise<void> {
3333
} catch (e) {
3434
console.log(`PID ${subprocess.pid} has stopped.`);
3535
console.log(`\tKilled: ${subprocess.killed}`);
36-
console.log(`\tCancelled: ${isRecord(e) ? e['isCanceled']: 'unknown'}`);
36+
console.log(`\tCancelled: ${isRecord(e) ? e['isCanceled'] : 'unknown'}`);
3737
}
3838

39-
return new Promise(resolve => {
39+
return new Promise((resolve) => {
4040
setTimeout(() => resolve(), 3000);
4141
});
4242
}

test/run-test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const allVersions = ['3.10', '3.13'];
4444
}
4545

4646
process.exit(didSucceed ? 0 : 1);
47-
})().catch(e => {
47+
})().catch((e) => {
4848
console.error(e);
4949
process.exit(1);
5050
});

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ export type Telemetry = Record<string, Record<string, unknown>>;
22

33
declare const telemetry: Telemetry;
44

5-
export default telemetry;
5+
export default telemetry;

transforms/no-implicit-this/helpers/options.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@ import { getOptions as getCLIOptions } from 'codemod-cli';
22
import fs from 'node:fs';
33
import path from 'node:path';
44
import { ZodError, ZodType, z } from 'zod';
5-
import { Telemetry, getTelemetry } from './telemetry';
5+
import Resolver, { RuntimeResolver } from './resolver';
66

77
export interface Options {
8-
customHelpers: string[],
9-
telemetry: Telemetry
8+
customHelpers: string[];
9+
resolver: Resolver;
1010
}
1111

1212
const CLIOptions = z.object({
1313
config: z.string().optional(),
14+
// FIXME: Defaulting to 'runtime' isn't quite correct
15+
telemetry: z.union([z.literal('runtime'), z.literal('embroider')]).default('runtime'),
16+
// FIXME: Optionally allow angle-bracket conversion for components
17+
// FIXME: Optionally add parens for helpers
1418
});
1519

1620
type CLIOptions = z.infer<typeof CLIOptions>;
@@ -29,7 +33,8 @@ export function getOptions(): Options {
2933
const cliOptions = parse(getCLIOptions(), CLIOptions);
3034
return {
3135
customHelpers: getCustomHelpersFromConfig(cliOptions.config),
32-
telemetry: getTelemetry(),
36+
resolver:
37+
cliOptions.telemetry === 'runtime' ? RuntimeResolver.build() : (null as unknown as Resolver),
3338
};
3439
}
3540

0 commit comments

Comments
 (0)