Skip to content

Commit 11c3d34

Browse files
authored
Downstreamed changes from @embroider/[email protected] (#68)
* feature: Downstreamed changes from @embroider/[email protected] * chore: Updated fixtures * feature: Replaced ember-cli-typescript with typescript (addon) * chore: Updated fixtures * feature: Extended tsconfig.json from @tsconfig/ember (addon) * chore: Updated fixtures * refactor: Removed unused code --------- Co-authored-by: ijlee2 <[email protected]>
1 parent 32e7537 commit 11c3d34

File tree

76 files changed

+748
-424
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+748
-424
lines changed
Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
1-
<% if (options.packages.addon.hasTypeScript) { %>{
2-
"presets": [["@babel/preset-typescript"]],
1+
{
32
"plugins": [
4-
"@embroider/addon-dev/template-colocation-plugin",
5-
["@babel/plugin-transform-typescript", { "allowDeclareFields": true }],
3+
<% if (options.packages.addon.hasTypeScript) { %> [
4+
"@babel/plugin-transform-typescript",
5+
{
6+
"allExtensions": true,
7+
"allowDeclareFields": true,
8+
"onlyRemoveTypeImports": true
9+
}
10+
],
11+
<% } %> "@embroider/addon-dev/template-colocation-plugin",
12+
"@babel/plugin-transform-class-static-block",
13+
[
14+
"babel-plugin-ember-template-compilation",
15+
{
16+
"targetFormat": "hbs",
17+
"transforms": []
18+
}
19+
],
620
["@babel/plugin-proposal-decorators", { "version": "legacy" }],
721
"@babel/plugin-transform-class-properties"
822
]
9-
}<% } else { %>{
10-
"plugins": [
11-
"@embroider/addon-dev/template-colocation-plugin",
12-
["@babel/plugin-proposal-decorators", { "version": "legacy" }],
13-
"@babel/plugin-transform-class-properties"
14-
]
15-
}<% } %>
23+
}

src/blueprints/ember-addon/__addonLocation__/rollup.config.mjs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,22 @@ export default {
1515
plugins: [
1616
// These are the modules that users should be able to import from your
1717
// addon. Anything not listed here may get optimized away.
18-
addon.publicEntrypoints([<%= context.addon.publicEntrypoints.map((filePath) => `'${filePath}'`).join(', ') %>]),
18+
// By default all your JavaScript modules (**/*.js) will be importable.
19+
// But you are encouraged to tweak this to only cover the modules that make
20+
// up your addon's public API. Also make sure your package.json#exports
21+
// is aligned to the config here.
22+
// See https://github.com/embroider-build/embroider/blob/main/docs/v2-faq.md#how-can-i-define-the-public-exports-of-my-addon
23+
addon.publicEntrypoints(['**/*.js', 'index.js'<% if (options.packages.addon.hasGlint) {%>, 'template-registry.js'<% } %>]),
1924

2025
// These are the modules that should get reexported into the traditional
2126
// "app" tree. Things in here should also be in publicEntrypoints above, but
2227
// not everything in publicEntrypoints necessarily needs to go here.
23-
addon.appReexports([<%= context.addon.appReexports.map((filePath) => `'${filePath}'`).join(', ') %>]),
28+
addon.appReexports([
29+
'components/**/*.js',
30+
'helpers/**/*.js',
31+
'modifiers/**/*.js',
32+
'services/**/*.js',
33+
]),
2434

2535
// Follow the V2 Addon rules about dependencies. Your code can import from
2636
// `dependencies` and `peerDependencies` as well as standard Ember-provided
@@ -35,12 +45,15 @@ export default {
3545
// babel.config.json.
3646
babel({
3747
babelHelpers: 'bundled',
38-
extensions: ['.js'<% if (options.packages.addon.hasTypeScript) { %>, '.ts'<% } %>],
48+
extensions: ['.js', '.gjs'<% if (options.packages.addon.hasTypeScript) { %>, '.ts', '.gts'<% } %>],
3949
}),
4050

4151
// Ensure that standalone .hbs files are properly integrated as Javascript.
4252
addon.hbs(),
4353

54+
// Ensure that .gjs files are properly integrated as Javascript
55+
addon.gjs(),
56+
4457
// addons are allowed to contain imports of .css files, which we want rollup
4558
// to leave alone and keep in the published output.
4659
addon.keepAssets(['**/*.css']),

src/steps/analyze-addon.ts

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,6 @@ import { findFiles, renamePathByDirectory } from '@codemod-utils/files';
33
import type { Context, Options } from '../types/index.js';
44
import { getVersion } from '../utils/blueprints.js';
55

6-
function getAppReexports(options: Options): string[] {
7-
const { projectRoot } = options;
8-
9-
const filePaths = findFiles('app/**/*.js', {
10-
projectRoot,
11-
});
12-
13-
return filePaths
14-
.map((filePath) => {
15-
return renamePathByDirectory(filePath, {
16-
from: 'app',
17-
to: '',
18-
});
19-
})
20-
.sort();
21-
}
22-
236
function getProjectRootDevDependencies(
247
options: Options,
258
): Record<string, string> {
@@ -45,38 +28,10 @@ function getPublicAssets(options: Options): string[] {
4528
.sort();
4629
}
4730

48-
function getPublicEntrypoints(options: Options): string[] {
49-
const { projectRoot } = options;
50-
51-
const filePaths = findFiles('{addon,addon-test-support}/**/*.{js,ts}', {
52-
projectRoot,
53-
});
54-
55-
return filePaths
56-
.map((filePath) => {
57-
return renamePathByDirectory(filePath, {
58-
from: 'addon',
59-
to: '',
60-
});
61-
})
62-
.map((filePath) => {
63-
return renamePathByDirectory(filePath, {
64-
from: 'addon-test-support',
65-
to: 'test-support',
66-
});
67-
})
68-
.map((filePath) => {
69-
return filePath.replace(/(?<!\.d)\.ts$/, '.js');
70-
})
71-
.sort();
72-
}
73-
7431
export function analyzeAddon(options: Options): Context {
7532
return {
7633
addon: {
77-
appReexports: getAppReexports(options),
7834
publicAssets: getPublicAssets(options),
79-
publicEntrypoints: getPublicEntrypoints(options),
8035
},
8136
projectRoot: {
8237
devDependencies: getProjectRootDevDependencies(options),

src/steps/update-addon-package-json/update-dependencies.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,18 @@ export function updateDependencies(
99
): void {
1010
const dependencies = convertToMap(packageJson['dependencies']);
1111

12-
const packagesToDelete = [
12+
const packagesToDelete = new Set([
1313
'@embroider/macros',
1414
'ember-auto-import',
1515
'ember-cli-babel',
1616
'ember-cli-htmlbars',
17-
];
17+
]);
1818

19-
packagesToDelete.forEach((packageName) => {
19+
if (options.packages.addon.hasTypeScript) {
20+
packagesToDelete.add('ember-cli-typescript');
21+
}
22+
23+
Array.from(packagesToDelete).forEach((packageName) => {
2024
dependencies.delete(packageName);
2125
});
2226

src/steps/update-addon-package-json/update-dev-dependencies.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,20 @@ export function updateDevDependencies(
2727
'@babel/core',
2828
'@babel/plugin-proposal-decorators',
2929
'@babel/plugin-transform-class-properties',
30+
'@babel/plugin-transform-class-static-block',
3031
'@babel/runtime',
3132
'@embroider/addon-dev',
3233
'@rollup/plugin-babel',
34+
'babel-plugin-ember-template-compilation',
3335
'concurrently',
3436
'rollup',
3537
'rollup-plugin-copy',
3638
]);
3739

3840
if (packages.addon.hasTypeScript) {
39-
packagesToInstall.add('@babel/preset-typescript');
41+
packagesToInstall.add('@babel/plugin-transform-typescript');
42+
packagesToInstall.add('@tsconfig/ember');
43+
packagesToInstall.add('typescript');
4044
}
4145

4246
Array.from(packagesToInstall).forEach((packageName) => {

src/steps/update-addon-package-json/update-scripts.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ export function updateScripts(
2525
: 'tsc --emitDeclarationOnly false --noEmit',
2626
);
2727

28+
if (scripts.get('postpack') === 'ember ts:clean') {
29+
scripts.delete('postpack');
30+
}
31+
2832
scripts.set('prepack', 'rollup --config');
2933

3034
scripts.set('start', 'concurrently "npm:start:*" --names "start:"');

src/steps/update-addon-tsconfig-json.ts

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,32 @@ import { convertToMap, convertToObject } from '@codemod-utils/json';
66
import type { Options, TsConfigJson } from '../types/index.js';
77
import { sanitizeJson } from '../utils/json.js';
88

9-
function updateCompilerOptions(
9+
function setExtends(tsConfigJson: TsConfigJson): void {
10+
tsConfigJson['extends'] = '@tsconfig/ember/tsconfig.json';
11+
}
12+
13+
function setCompilerOptions(
1014
tsConfigJson: TsConfigJson,
1115
options: Options,
1216
): void {
1317
const { packages } = options;
1418

15-
const compilerOptions = convertToMap(tsConfigJson['compilerOptions']);
19+
const compilerOptions = convertToMap();
1620

17-
compilerOptions.delete('baseUrl');
18-
compilerOptions.delete('paths');
21+
compilerOptions.set('allowImportingTsExtensions', true);
22+
compilerOptions.set('allowJs', true);
23+
compilerOptions.set('declarationDir', 'declarations');
1924

20-
if (packages.addon.hasGlint) {
21-
compilerOptions.set('allowImportingTsExtensions', true);
22-
compilerOptions.set('allowJs', true);
23-
compilerOptions.set('declarationDir', 'declarations');
24-
} else {
25-
compilerOptions.set('allowImportingTsExtensions', true);
26-
compilerOptions.set('allowJs', true);
25+
if (!packages.addon.hasGlint) {
2726
compilerOptions.set('declaration', true);
28-
compilerOptions.set('declarationDir', 'declarations');
2927
compilerOptions.set('emitDeclarationOnly', true);
3028
compilerOptions.set('noEmit', false);
3129
}
3230

3331
tsConfigJson['compilerOptions'] = convertToObject(compilerOptions);
3432
}
3533

36-
function updateInclude(tsConfigJson: TsConfigJson): void {
34+
function setInclude(tsConfigJson: TsConfigJson): void {
3735
tsConfigJson['include'] = ['src/**/*', 'unpublished-development-types/**/*'];
3836
}
3937

@@ -48,8 +46,9 @@ export function updateAddonTsConfigJson(options: Options): void {
4846
const oldFile = readFileSync(oldPath, 'utf8');
4947
const tsConfigJson = JSON.parse(sanitizeJson(oldFile));
5048

51-
updateCompilerOptions(tsConfigJson, options);
52-
updateInclude(tsConfigJson);
49+
setExtends(tsConfigJson);
50+
setCompilerOptions(tsConfigJson, options);
51+
setInclude(tsConfigJson);
5352

5453
const newFile = JSON.stringify(tsConfigJson, null, 2) + '\n';
5554

src/types/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ type CodemodOptions = {
99

1010
type Context = {
1111
addon: {
12-
appReexports: string[];
1312
publicAssets: string[];
14-
publicEntrypoints: string[];
1513
};
1614
projectRoot: {
1715
devDependencies: Record<string, string>;

src/utils/blueprints/get-version.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,25 @@ import { decideVersion } from '@codemod-utils/blueprints';
33
import type { Options } from '../../types/index.js';
44

55
const latestVersions = new Map([
6-
['@babel/core', '7.22.17'],
6+
['@babel/core', '7.23.2'],
77
['@babel/plugin-proposal-decorators', '7.22.15'],
88
['@babel/plugin-transform-class-properties', '7.22.5'],
9-
['@babel/preset-typescript', '7.22.15'],
10-
['@babel/runtime', '7.22.15'],
11-
['@embroider/addon-dev', '4.1.0'],
9+
['@babel/plugin-transform-class-static-block', '7.22.11'],
10+
['@babel/plugin-transform-typescript', '7.22.15'],
11+
['@babel/runtime', '7.23.2'],
12+
['@embroider/addon-dev', '4.1.1'],
1213
['@embroider/addon-shim', '1.8.6'],
13-
['@embroider/test-setup', '3.0.1'],
14-
['@rollup/plugin-babel', '6.0.3'],
15-
['concurrently', '8.2.1'],
14+
['@embroider/test-setup', '3.0.2'],
15+
['@rollup/plugin-babel', '6.0.4'],
16+
['@tsconfig/ember', '3.0.2'],
17+
['babel-plugin-ember-template-compilation', '2.2.1'],
18+
['concurrently', '8.2.2'],
1619
['ember-auto-import', '2.6.3'],
17-
['ember-cli-babel', '8.0.0'],
20+
['ember-cli-babel', '8.1.0'],
1821
['ember-cli-htmlbars', '6.3.0'],
19-
['rollup', '3.29.1'],
22+
['rollup', '4.3.0'],
2023
['rollup-plugin-copy', '3.5.0'],
24+
['typescript', '5.2.2'],
2125
]);
2226

2327
export function getVersion(packageName: string, options: Options): string {

tests/fixtures/ember-container-query-customizations/output/packages/ember-container-query/babel.config.json

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
11
{
2-
"presets": [["@babel/preset-typescript"]],
32
"plugins": [
3+
[
4+
"@babel/plugin-transform-typescript",
5+
{
6+
"allExtensions": true,
7+
"allowDeclareFields": true,
8+
"onlyRemoveTypeImports": true
9+
}
10+
],
411
"@embroider/addon-dev/template-colocation-plugin",
5-
["@babel/plugin-transform-typescript", { "allowDeclareFields": true }],
12+
"@babel/plugin-transform-class-static-block",
13+
[
14+
"babel-plugin-ember-template-compilation",
15+
{
16+
"targetFormat": "hbs",
17+
"transforms": []
18+
}
19+
],
620
["@babel/plugin-proposal-decorators", { "version": "legacy" }],
721
"@babel/plugin-transform-class-properties"
822
]

0 commit comments

Comments
 (0)