Skip to content

Commit 1f84bfe

Browse files
authored
Remove rollup-plugin-ts (#51)
* refactor: Used Array.from to convert a Set to an array * feature: Updated the codemod so that v2 addons do not rely on rollup-plugin-ts * chore: Updated test fixtures --------- Co-authored-by: ijlee2 <[email protected]>
1 parent ae2a4d7 commit 1f84bfe

File tree

108 files changed

+869
-773
lines changed

Some content is hidden

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

108 files changed

+869
-773
lines changed

src/blueprints/ember-addon/__addonLocation__/.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/blueprints/*/files/
33

44
# compiled output
5+
/declarations/
56
/dist/
67

78
# misc
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# The authoritative copies of these live in the monorepo root (because they're
2+
# more useful on github that way), but the build copies them into here so they
3+
# will also appear in published NPM packages.
4+
/LICENSE.md
5+
/README.md
6+
7+
# compiled output
8+
/declarations/
9+
/dist/
10+
11+
# dependencies
12+
/node_modules/

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

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
<% if (options.packages.addon.hasTypeScript) { %>import typescript from 'rollup-plugin-ts';<% } else { %>import { babel } from '@rollup/plugin-babel';<% } %>
2-
import copy from 'rollup-plugin-copy';
31
import { Addon } from '@embroider/addon-dev/rollup';
2+
import { babel } from '@rollup/plugin-babel';
3+
import { nodeResolve } from '@rollup/plugin-node-resolve';
4+
import copy from 'rollup-plugin-copy';
45

56
const addon = new Addon({
67
srcDir: 'src',
78
destDir: 'dist',
89
});
910

11+
// Add extensions here, such as ts, gjs, etc that you may import
12+
const extensions = ['.js'<% if (options.packages.addon.hasTypeScript) { %>, '.ts'<% } %>];
13+
1014
export default {
1115
// This provides defaults that work well alongside `publicEntrypoints` below.
1216
// You can augment this if you need to.
@@ -27,22 +31,22 @@ export default {
2731
// package names.
2832
addon.dependencies(),
2933

30-
<% if (options.packages.addon.hasTypeScript) { %> // compile TypeScript to latest JavaScript, including Babel transpilation
31-
typescript({
32-
transpiler: 'babel',
33-
browserslist: false,
34-
transpileOnly: false,
35-
}),
36-
<% } else { %> // This babel config should *not* apply presets or compile away ES modules.
34+
// This babel config should *not* apply presets or compile away ES modules.
3735
// It exists only to provide development niceties for you, like automatic
3836
// template colocation.
3937
//
4038
// By default, this will load the actual babel config from the file
4139
// babel.config.json.
4240
babel({
4341
babelHelpers: 'bundled',
42+
extensions,
4443
}),
45-
<% } %>
44+
45+
// Allows rollup to resolve imports of files with the specified extensions
46+
nodeResolve({
47+
extensions,
48+
}),
49+
4650
// Ensure that standalone .hbs files are properly integrated as Javascript.
4751
addon.hbs(),
4852

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,11 @@
11
# compiled output
2-
/dist/
2+
dist/
33

44
# dependencies
5-
/node_modules/
5+
node_modules/
66

77
# misc
88
/.env*
9-
/.pnp*
10-
/.eslintcache
11-
/coverage/
9+
/.pnpm-debug.log
1210
/npm-debug.log*
13-
/testem.log
1411
/yarn-error.log
15-
16-
# ember-try
17-
/.node_modules.ember-try/
18-
/npm-shrinkwrap.json.ember-try
19-
/package.json.ember-try
20-
/package-lock.json.ember-try
21-
/yarn.lock.ember-try
22-
23-
# broccoli-debug
24-
/DEBUG/

src/migration/ember-addon/steps/create-files-from-blueprints.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { blueprintsRoot } from '../../../utils/blueprints.js';
1010
function getFilesToSkip(options: Options): string[] {
1111
const { packageManager, packages } = options;
1212

13-
const files = new Set();
13+
const files = new Set<string>();
1414

1515
if (!packages.addon.hasTypeScript) {
1616
files.add('__addonLocation__/unpublished-development-types/index.d.ts');
@@ -21,7 +21,7 @@ function getFilesToSkip(options: Options): string[] {
2121
files.add('pnpm-workspace.yaml');
2222
}
2323

24-
return [...files] as string[];
24+
return Array.from(files);
2525
}
2626

2727
function resolveBlueprintFilePath(

src/migration/ember-addon/steps/create-options.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function analyzePackageManager(codemodOptions: CodemodOptions): PackageManager {
4545
['yarn.lock', 'yarn'],
4646
]);
4747

48-
const lockFiles = [...mapping.keys()];
48+
const lockFiles = Array.from(mapping.keys());
4949

5050
const filePaths = findFiles(unionize(lockFiles), {
5151
projectRoot,

src/migration/ember-addon/steps/move-project-root-files.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function moveToAddonAndTestApp(options: Options): void {
4949
files.add('tsconfig.json');
5050
}
5151

52-
const filePaths = findFiles(unionize([...files]), {
52+
const filePaths = findFiles(unionize(Array.from(files)), {
5353
projectRoot,
5454
});
5555

src/migration/ember-addon/steps/update-addon-package-json.ts

Lines changed: 64 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -62,21 +62,23 @@ function updateDevDependencies(
6262
'@babel/runtime',
6363
'@embroider/addon-dev',
6464
'@rollup/plugin-babel',
65+
'@rollup/plugin-node-resolve',
66+
'concurrently',
6567
'rollup',
6668
'rollup-plugin-copy',
6769
]);
6870

6971
if (packages.addon.hasTypeScript) {
7072
packagesToInstall.add('@babel/preset-typescript');
71-
packagesToInstall.add('rollup-plugin-ts');
72-
packagesToInstall.delete('@rollup/plugin-babel');
7373
}
7474

75-
[...packagesToInstall].sort().forEach((packageName) => {
76-
const version = getVersion(packageName, options);
75+
Array.from(packagesToInstall)
76+
.sort()
77+
.forEach((packageName) => {
78+
const version = getVersion(packageName, options);
7779

78-
devDependencies.set(packageName, version);
79-
});
80+
devDependencies.set(packageName, version);
81+
});
8082

8183
packageJson['devDependencies'] = convertToObject(devDependencies);
8284
}
@@ -120,12 +122,15 @@ function updateOtherFields(
120122

121123
if (packages.addon.hasTypeScript) {
122124
packageJson['exports'] = {
123-
'.': './dist/index.js',
125+
'.': {
126+
types: './declarations/index.d.ts',
127+
default: './dist/index.js',
128+
},
124129
'./*': {
125130
/*
126131
This object has an order dependency. The `default` key must appear last.
127132
*/
128-
types: './dist/*.d.ts',
133+
types: './declarations/*.d.ts',
129134
default: './dist/*.js',
130135
},
131136
'./addon-main.js': './addon-main.cjs',
@@ -138,31 +143,69 @@ function updateOtherFields(
138143
};
139144
}
140145

146+
const files = new Set(['addon-main.cjs', 'dist']);
147+
141148
if (hasPublicAssets) {
142-
packageJson['files'] = ['addon-main.cjs', 'dist', 'public'];
143-
} else {
144-
packageJson['files'] = ['addon-main.cjs', 'dist'];
149+
files.add('public');
145150
}
146151

152+
if (packages.addon.hasTypeScript) {
153+
files.add('declarations');
154+
}
155+
156+
packageJson['files'] = Array.from(files).sort();
157+
147158
if (packages.addon.hasTypeScript) {
148159
packageJson['typesVersions'] = {
149160
'*': {
150-
'*': ['dist/*'],
161+
'*': ['declarations/*'],
151162
},
152163
};
153164
}
154165
}
155166

156-
function updateScripts(packageJson: PackageJson): void {
167+
function updateScripts(packageJson: PackageJson, options: Options): void {
168+
const { packages } = options;
169+
157170
const scripts = convertToMap(packageJson['scripts']);
158171

159-
scripts.set('build', 'rollup --config');
160-
scripts.set('prepack', 'rollup --config');
161-
scripts.set('start', 'rollup --config --watch');
162-
scripts.set(
163-
'test',
164-
"echo 'A v2 addon does not have tests, run tests in test-app'",
165-
);
172+
if (packages.addon.hasTypeScript) {
173+
scripts.set('build', 'concurrently "npm:build:*" --names "build:"');
174+
scripts.set('build:js', 'rollup --config');
175+
scripts.set(
176+
'build:types',
177+
packages.addon.hasGlint ? 'glint --declaration' : 'tsc',
178+
);
179+
180+
scripts.set(
181+
'lint:types',
182+
packages.addon.hasGlint
183+
? 'glint'
184+
: 'tsc --emitDeclarationOnly false --noEmit',
185+
);
186+
187+
scripts.set('prepack', 'rollup --config');
188+
189+
scripts.set('start', 'concurrently "npm:start:*" --names "start:"');
190+
scripts.set('start:js', 'rollup --config --watch --no-watch.clearScreen');
191+
scripts.set(
192+
'start:types',
193+
packages.addon.hasGlint ? 'glint --declaration --watch' : 'tsc --watch',
194+
);
195+
196+
scripts.set(
197+
'test',
198+
"echo 'A v2 addon does not have tests, run tests in test-app'",
199+
);
200+
} else {
201+
scripts.set('build', 'rollup --config');
202+
scripts.set('prepack', 'rollup --config');
203+
scripts.set('start', 'rollup --config --watch');
204+
scripts.set(
205+
'test',
206+
"echo 'A v2 addon does not have tests, run tests in test-app'",
207+
);
208+
}
166209

167210
packageJson['scripts'] = convertToObject(scripts);
168211
}
@@ -179,7 +222,7 @@ export function updateAddonPackageJson(
179222

180223
updateDependencies(packageJson, options);
181224
updateDevDependencies(packageJson, options);
182-
updateScripts(packageJson);
225+
updateScripts(packageJson, options);
183226
updateOtherFields(packageJson, context, options);
184227

185228
const destination = join(projectRoot, locations.addon, 'package.json');

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,26 @@ 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(tsConfigJson: TsConfigJson): void {
9+
function updateCompilerOptions(
10+
tsConfigJson: TsConfigJson,
11+
options: Options,
12+
): void {
13+
const { packages } = options;
14+
1015
const compilerOptions = convertToMap(tsConfigJson['compilerOptions']);
1116

1217
compilerOptions.delete('baseUrl');
1318
compilerOptions.delete('paths');
1419

20+
if (packages.addon.hasGlint) {
21+
compilerOptions.set('declarationDir', 'declarations');
22+
} else {
23+
compilerOptions.set('declaration', true);
24+
compilerOptions.set('declarationDir', 'declarations');
25+
compilerOptions.set('emitDeclarationOnly', true);
26+
compilerOptions.set('noEmit', false);
27+
}
28+
1529
tsConfigJson['compilerOptions'] = convertToObject(compilerOptions);
1630
}
1731

@@ -30,7 +44,7 @@ export function updateAddonTsConfigJson(options: Options): void {
3044
const oldFile = readFileSync(oldPath, 'utf8');
3145
const tsConfigJson = JSON.parse(sanitizeJson(oldFile));
3246

33-
updateCompilerOptions(tsConfigJson);
47+
updateCompilerOptions(tsConfigJson, options);
3448
updateInclude(tsConfigJson);
3549

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

src/migration/ember-addon/steps/update-test-app-package-json.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function moveDependenciesToDevDependencies(
2929
packagesToMove.add('ember-cli-typescript');
3030
}
3131

32-
[...packagesToMove]
32+
Array.from(packagesToMove)
3333
.filter((packageName) => dependencies.has(packageName))
3434
.sort()
3535
.forEach((packageName) => {

0 commit comments

Comments
 (0)