Skip to content
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

Downstreamed changes from @embroider/[email protected] #68

Merged
merged 7 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
30 changes: 19 additions & 11 deletions src/blueprints/ember-addon/__addonLocation__/babel.config.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
<% if (options.packages.addon.hasTypeScript) { %>{
"presets": [["@babel/preset-typescript"]],
{
"plugins": [
"@embroider/addon-dev/template-colocation-plugin",
["@babel/plugin-transform-typescript", { "allowDeclareFields": true }],
<% if (options.packages.addon.hasTypeScript) { %> [
"@babel/plugin-transform-typescript",
{
"allExtensions": true,
"allowDeclareFields": true,
"onlyRemoveTypeImports": true
}
],
<% } %> "@embroider/addon-dev/template-colocation-plugin",
"@babel/plugin-transform-class-static-block",
[
"babel-plugin-ember-template-compilation",
{
"targetFormat": "hbs",
"transforms": []
}
],
["@babel/plugin-proposal-decorators", { "version": "legacy" }],
"@babel/plugin-transform-class-properties"
]
}<% } else { %>{
"plugins": [
"@embroider/addon-dev/template-colocation-plugin",
["@babel/plugin-proposal-decorators", { "version": "legacy" }],
"@babel/plugin-transform-class-properties"
]
}<% } %>
}
19 changes: 16 additions & 3 deletions src/blueprints/ember-addon/__addonLocation__/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,22 @@ export default {
plugins: [
// These are the modules that users should be able to import from your
// addon. Anything not listed here may get optimized away.
addon.publicEntrypoints([<%= context.addon.publicEntrypoints.map((filePath) => `'${filePath}'`).join(', ') %>]),
// By default all your JavaScript modules (**/*.js) will be importable.
// But you are encouraged to tweak this to only cover the modules that make
// up your addon's public API. Also make sure your package.json#exports
// is aligned to the config here.
// See https://github.com/embroider-build/embroider/blob/main/docs/v2-faq.md#how-can-i-define-the-public-exports-of-my-addon
addon.publicEntrypoints(['**/*.js', 'index.js'<% if (options.packages.addon.hasGlint) {%>, 'template-registry.js'<% } %>]),

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

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

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

// Ensure that .gjs files are properly integrated as Javascript
addon.gjs(),

// addons are allowed to contain imports of .css files, which we want rollup
// to leave alone and keep in the published output.
addon.keepAssets(['**/*.css']),
Expand Down
45 changes: 0 additions & 45 deletions src/steps/analyze-addon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,6 @@ import { findFiles, renamePathByDirectory } from '@codemod-utils/files';
import type { Context, Options } from '../types/index.js';
import { getVersion } from '../utils/blueprints.js';

function getAppReexports(options: Options): string[] {
const { projectRoot } = options;

const filePaths = findFiles('app/**/*.js', {
projectRoot,
});

return filePaths
.map((filePath) => {
return renamePathByDirectory(filePath, {
from: 'app',
to: '',
});
})
.sort();
}

function getProjectRootDevDependencies(
options: Options,
): Record<string, string> {
Expand All @@ -45,38 +28,10 @@ function getPublicAssets(options: Options): string[] {
.sort();
}

function getPublicEntrypoints(options: Options): string[] {
const { projectRoot } = options;

const filePaths = findFiles('{addon,addon-test-support}/**/*.{js,ts}', {
projectRoot,
});

return filePaths
.map((filePath) => {
return renamePathByDirectory(filePath, {
from: 'addon',
to: '',
});
})
.map((filePath) => {
return renamePathByDirectory(filePath, {
from: 'addon-test-support',
to: 'test-support',
});
})
.map((filePath) => {
return filePath.replace(/(?<!\.d)\.ts$/, '.js');
})
.sort();
}

export function analyzeAddon(options: Options): Context {
return {
addon: {
appReexports: getAppReexports(options),
publicAssets: getPublicAssets(options),
publicEntrypoints: getPublicEntrypoints(options),
},
projectRoot: {
devDependencies: getProjectRootDevDependencies(options),
Expand Down
10 changes: 7 additions & 3 deletions src/steps/update-addon-package-json/update-dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@ export function updateDependencies(
): void {
const dependencies = convertToMap(packageJson['dependencies']);

const packagesToDelete = [
const packagesToDelete = new Set([
'@embroider/macros',
'ember-auto-import',
'ember-cli-babel',
'ember-cli-htmlbars',
];
]);

packagesToDelete.forEach((packageName) => {
if (options.packages.addon.hasTypeScript) {
packagesToDelete.add('ember-cli-typescript');
}

Array.from(packagesToDelete).forEach((packageName) => {
dependencies.delete(packageName);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,20 @@ export function updateDevDependencies(
'@babel/core',
'@babel/plugin-proposal-decorators',
'@babel/plugin-transform-class-properties',
'@babel/plugin-transform-class-static-block',
'@babel/runtime',
'@embroider/addon-dev',
'@rollup/plugin-babel',
'babel-plugin-ember-template-compilation',
'concurrently',
'rollup',
'rollup-plugin-copy',
]);

if (packages.addon.hasTypeScript) {
packagesToInstall.add('@babel/preset-typescript');
packagesToInstall.add('@babel/plugin-transform-typescript');
packagesToInstall.add('@tsconfig/ember');
packagesToInstall.add('typescript');
}

Array.from(packagesToInstall).forEach((packageName) => {
Expand Down
4 changes: 4 additions & 0 deletions src/steps/update-addon-package-json/update-scripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ export function updateScripts(
: 'tsc --emitDeclarationOnly false --noEmit',
);

if (scripts.get('postpack') === 'ember ts:clean') {
scripts.delete('postpack');
}

scripts.set('prepack', 'rollup --config');

scripts.set('start', 'concurrently "npm:start:*" --names "start:"');
Expand Down
29 changes: 14 additions & 15 deletions src/steps/update-addon-tsconfig-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,32 @@ import { convertToMap, convertToObject } from '@codemod-utils/json';
import type { Options, TsConfigJson } from '../types/index.js';
import { sanitizeJson } from '../utils/json.js';

function updateCompilerOptions(
function setExtends(tsConfigJson: TsConfigJson): void {
tsConfigJson['extends'] = '@tsconfig/ember/tsconfig.json';
}

function setCompilerOptions(
tsConfigJson: TsConfigJson,
options: Options,
): void {
const { packages } = options;

const compilerOptions = convertToMap(tsConfigJson['compilerOptions']);
const compilerOptions = convertToMap();

compilerOptions.delete('baseUrl');
compilerOptions.delete('paths');
compilerOptions.set('allowImportingTsExtensions', true);
compilerOptions.set('allowJs', true);
compilerOptions.set('declarationDir', 'declarations');

if (packages.addon.hasGlint) {
compilerOptions.set('allowImportingTsExtensions', true);
compilerOptions.set('allowJs', true);
compilerOptions.set('declarationDir', 'declarations');
} else {
compilerOptions.set('allowImportingTsExtensions', true);
compilerOptions.set('allowJs', true);
if (!packages.addon.hasGlint) {
compilerOptions.set('declaration', true);
compilerOptions.set('declarationDir', 'declarations');
compilerOptions.set('emitDeclarationOnly', true);
compilerOptions.set('noEmit', false);
}

tsConfigJson['compilerOptions'] = convertToObject(compilerOptions);
}

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

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

updateCompilerOptions(tsConfigJson, options);
updateInclude(tsConfigJson);
setExtends(tsConfigJson);
setCompilerOptions(tsConfigJson, options);
setInclude(tsConfigJson);

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

Expand Down
2 changes: 0 additions & 2 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ type CodemodOptions = {

type Context = {
addon: {
appReexports: string[];
publicAssets: string[];
publicEntrypoints: string[];
};
projectRoot: {
devDependencies: Record<string, string>;
Expand Down
22 changes: 13 additions & 9 deletions src/utils/blueprints/get-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,25 @@ import { decideVersion } from '@codemod-utils/blueprints';
import type { Options } from '../../types/index.js';

const latestVersions = new Map([
['@babel/core', '7.22.17'],
['@babel/core', '7.23.2'],
['@babel/plugin-proposal-decorators', '7.22.15'],
['@babel/plugin-transform-class-properties', '7.22.5'],
['@babel/preset-typescript', '7.22.15'],
['@babel/runtime', '7.22.15'],
['@embroider/addon-dev', '4.1.0'],
['@babel/plugin-transform-class-static-block', '7.22.11'],
['@babel/plugin-transform-typescript', '7.22.15'],
['@babel/runtime', '7.23.2'],
['@embroider/addon-dev', '4.1.1'],
['@embroider/addon-shim', '1.8.6'],
['@embroider/test-setup', '3.0.1'],
['@rollup/plugin-babel', '6.0.3'],
['concurrently', '8.2.1'],
['@embroider/test-setup', '3.0.2'],
['@rollup/plugin-babel', '6.0.4'],
['@tsconfig/ember', '3.0.2'],
['babel-plugin-ember-template-compilation', '2.2.1'],
['concurrently', '8.2.2'],
['ember-auto-import', '2.6.3'],
['ember-cli-babel', '8.0.0'],
['ember-cli-babel', '8.1.0'],
['ember-cli-htmlbars', '6.3.0'],
['rollup', '3.29.1'],
['rollup', '4.3.0'],
['rollup-plugin-copy', '3.5.0'],
['typescript', '5.2.2'],
]);

export function getVersion(packageName: string, options: Options): string {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
{
"presets": [["@babel/preset-typescript"]],
"plugins": [
[
"@babel/plugin-transform-typescript",
{
"allExtensions": true,
"allowDeclareFields": true,
"onlyRemoveTypeImports": true
}
],
"@embroider/addon-dev/template-colocation-plugin",
["@babel/plugin-transform-typescript", { "allowDeclareFields": true }],
"@babel/plugin-transform-class-static-block",
[
"babel-plugin-ember-template-compilation",
{
"targetFormat": "hbs",
"transforms": []
}
],
["@babel/plugin-proposal-decorators", { "version": "legacy" }],
"@babel/plugin-transform-class-properties"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
"lint:js": "eslint . --cache --ext=.js,.ts",
"lint:js:fix": "eslint . --fix",
"lint:types": "glint",
"postpack": "ember ts:clean",
"prepack": "rollup --config",
"start": "concurrently \"npm:start:*\" --names \"start:\"",
"start:js": "rollup --config --watch --no-watch.clearScreen",
Expand All @@ -60,23 +59,26 @@
},
"dependencies": {
"@embroider/addon-shim": "^1.8.6",
"ember-cli-typescript": "^5.2.1",
"ember-element-helper": "^0.6.1",
"ember-modifier": "^3.2.7",
"ember-resize-observer-service": "^1.1.0",
"ember-test-selectors": "^6.0.0"
},
"devDependencies": {
"@babel/core": "^7.22.17",
"@babel/core": "^7.23.2",
"@babel/plugin-proposal-decorators": "^7.22.15",
"@babel/plugin-transform-class-properties": "^7.22.5",
"@babel/preset-typescript": "^7.22.15",
"@babel/runtime": "^7.22.15",
"@embroider/addon-dev": "^4.1.0",
"@rollup/plugin-babel": "^6.0.3",
"@babel/plugin-transform-class-static-block": "^7.22.11",
"@babel/plugin-transform-typescript": "^7.22.15",
"@babel/runtime": "^7.23.2",
"@embroider/addon-dev": "^4.1.1",
"@rollup/plugin-babel": "^6.0.4",
"@tsconfig/ember": "^2.0.0",
"babel-plugin-ember-template-compilation": "^2.2.1",
"concurrently": "^7.6.0",
"rollup": "^3.29.1",
"rollup-plugin-copy": "^3.5.0"
"rollup": "^4.3.0",
"rollup-plugin-copy": "^3.5.0",
"typescript": "^4.9.4"
},
"engines": {
"node": "14.* || 16.* || >= 18"
Expand Down
Loading