Skip to content

Commit

Permalink
Update dependency manipulation
Browse files Browse the repository at this point in the history
  • Loading branch information
NullVoxPopuli committed Sep 23, 2024
1 parent c905078 commit 6e25ccc
Show file tree
Hide file tree
Showing 6 changed files with 297 additions and 27 deletions.
98 changes: 98 additions & 0 deletions files-override/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
'use strict';

module.exports = {
overrides: [
{
files: ['*.{js,ts,mjs,cjs}'],
plugins: ['ember'],
parser: '@typescript-eslint/parser',
extends: ['eslint:recommended', 'plugin:ember/recommended'],
},
{
files: ['*.gts'],
parser: 'ember-eslint-parser',
plugins: ['ember'],
extends: [
'eslint:recommended',
'plugin:ember/recommended',
'plugin:ember/recommended-gts',
],
},
{
files: ['*.gjs'],
parser: 'ember-eslint-parser',
plugins: ['ember'],
extends: [
'eslint:recommended',
'plugin:ember/recommended',
'plugin:ember/recommended-gjs',
],
},
// test files
{
files: ['tests/**/*-test.{js,ts}'],
plugins: ['ember'],
parser: '@typescript-eslint/parser',
extends: ['eslint:recommended', 'plugin:qunit/recommended'],
},
{
files: ['tests/**/*-test.{gjs,gts}'],
parser: 'ember-eslint-parser',
plugins: ['ember'],
extends: [
'eslint:recommended',
'plugin:ember/recommended',
'plugin:ember/recommended-gts',
],
},
{
files: ['*.gts', '*.ts'],
plugins: ['no-relative-import-paths'],
settings: {
node: {
tryExtensions: ['.gts', '.ts', '.js', '.module.css', '.css'],
},
},
rules: {
'no-relative-import-paths/no-relative-import-paths': [
'warn',
{ allowSameFolder: true, rootDir: 'app', prefix: 'discord-clone' },
],
'n/file-extension-in-import': [
'error',
'always',
{
'.css': 'always',
'.module.css': 'always',
'.gts': 'never',
'.ts': 'never',
'.js': 'never',
},
],
},
},

// node files
{
files: [
'./.eslintrc.{js,cjs}',
'./.prettierrc.{js,cjs}',
'./.stylelintrc.{js,cjs}',
'./.template-lintrc.{js,cjs}',
'./ember-cli-build.js',
'./testem.js',
'./blueprints/*/index.js',
'./config/**/*.js',
'./lib/*/index.js',
'./server/**/*.js',
'*.mjs',
'*.cjs',
],
env: {
browser: false,
node: true,
},
extends: ['plugin:n/recommended'],
},
],
};
34 changes: 34 additions & 0 deletions files-override/.prettierrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'use strict';

module.exports = {
plugins: ['prettier-plugin-ember-template-tag'],
overrides: [
{
files: ['*.js', '*.ts', '*.cjs', '.mjs', '.cts', '.mts', '.cts'],
options: {
singleQuote: true,
trailingComma: 'es5',
},
},
{
files: ['*.json'],
options: {
singleQuote: false,
},
},
{
files: ['*.hbs'],
options: {
singleQuote: false,
},
},
{
files: ['*.gjs', '*.gts'],
options: {
singleQuote: true,
templateSingleQuote: false,
trailingComma: 'es5',
},
},
],
};
File renamed without changes.
46 changes: 46 additions & 0 deletions files-override/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"extends": "@tsconfig/ember/tsconfig.json",
"include": [
"app/**/*",
"tests/**/*",
],
"glint": {
"environment": [
"ember-loose",
"ember-template-imports"
]
},
"compilerOptions": {
"allowJs": true,
/**
https://www.typescriptlang.org/tsconfig#noEmitOnError
Do not block emit on TS errors.
*/
"noEmitOnError": false,

"declaration": false,
"declarationMap": false,

/**
https://www.typescriptlang.org/tsconfig#allowImportingTsExtensions
We want our tooling to know how to resolve our custom files so the appropriate plugins
can do the proper transformations on those files.
*/
"allowImportingTsExtensions": true,
"paths": {
"<%= name %./tests/*": [
"./tests/*"
],
"<%= naem %./*": [
"./app/*"
],
"*": [
"./types/*"
]
},
"types": [
"ember-source/types"
]
},
}
8 changes: 8 additions & 0 deletions files/babel.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ const {

module.exports = {
plugins: [
[
'@babel/plugin-transform-typescript',
{
allExtensions: true,
onlyRemoveTypeImports: true,
allowDeclareFields: true,
},
],
[
'babel-plugin-ember-template-compilation',
{
Expand Down
138 changes: 111 additions & 27 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const fs = require('fs');
const { join } = require('path');
const emberCliUpdate = require('./lib/ember-cli-update');
const copyWithTemplate = require('./lib/copy-with-template');
const { rm } = require('fs/promises');
const { rm, readFile } = require('fs/promises');

const appBlueprint = Blueprint.lookup('app');

Expand All @@ -23,6 +23,84 @@ module.exports = {
},

async updateDeps(options) {
let manifestPath = join(options.target, 'package.json');
let manifestBuffer = await readFile(manifestPath);
let manifest = JSON.parse(manifestBuffer.toString());

let existingDeps = [
...Object.keys(manifest.dependencies || {}),
...Object.keys(manifest.devDependencies || {}),
];

let uninstallTask = this.taskFor('npm-uninstall');
const packages = [
'ember-fetch',
'broccoli-asset-rev',
'ember-cli-app-version',
'ember-cli-clean-css',
'ember-cli-dependency-checker',
'ember-cli-sri',
'ember-cli-terser',

// Upstream TypeScript blueprint is too conservative
// at the same time, ember-data has been what's holding it back
'@types/ember',
'@types/ember-data',
'@types/ember-data__adapter',
'@types/ember-data__model',
'@types/ember-data__serializer',
'@types/ember-data__store',
'@types/ember__application',
'@types/ember__array',
'@types/ember__component',
'@types/ember__controller',
'@types/ember__debug',
'@types/ember__destroyable',
'@types/ember__engine',
'@types/ember__error',
'@types/ember__helper',
'@types/ember__modifier',
'@types/ember__object',
'@types/ember__owner',
'@types/ember__polyfills',
'@types/ember__routing',
'@types/ember__runloop',
'@types/ember__service',
'@types/ember__string',
'@types/ember__template',
'@types/ember__test',
'@types/ember__utils',

// These dependencies in the blueprint we want to keep (if they exist)
// but they are generally too out of date
'@ember/string',
'@ember/test-helpers',
'ember-resolver',
'eslint-plugin-ember',
'ember-template-lint',
'qunit-dom',
'qunit',
'stylelint',
'stylelint-prettier',
'stylelint-config-standard',
'concurrently',
'typescript',

'@glint/core',
'@glint/environment-ember-loose', // currently required :(
'@glint/environment-ember-template-imports',
'@glint/template',
'@typescript-eslint/eslint-plugin',
'@typescript-eslint/parser',
].filter((depToRemove) => existingDeps.includes(depToRemove));

await uninstallTask.run({
'save-dev': true,
verbose: false,
packages,
packageManager: options.packageManager,
});

// this.addPackagesToProject doesn't respect the packageManager that the blueprint specified 🙈 so we're skipping a level here
let installTask = this.taskFor('npm-install');
await installTask.run({
Expand All @@ -37,40 +115,46 @@ module.exports = {
'vite',
'@rollup/plugin-babel',
'decorator-transforms',

// Dependencies out of date from upstream
'@ember/string',
'@ember/test-helpers',
'ember-resolver',
'eslint-plugin-ember',
'ember-template-lint',
'qunit-dom',
'qunit',
'stylelint',
'stylelint-prettier',
'stylelint-config-standard',
'concurrently',
'prettier-plugin-ember-template-tag',

// TypeScript
// Note that Vite supports TypeScript with 0 configuration on the user's part
'@babel/plugin-transform-typescript',
'typescript',
'@glint/core',
'@glint/environment-ember-loose', // currently required :(
'@glint/environment-ember-template-imports',
'@glint/template',
'@typescript-eslint/eslint-plugin',
'@typescript-eslint/parser',
],
packageManager: options.packageManager,
});

let uninstallTask = this.taskFor('npm-uninstall');
const packages = [
'ember-fetch',
'broccoli-asset-rev',
'ember-cli-app-version',
'ember-cli-clean-css',
'ember-cli-dependency-checker',
'ember-cli-sri',
'ember-cli-terser',
];

for (const package of packages) {
try {
await uninstallTask.run({
'save-dev': true,
verbose: false,
packages: [package],
packageManager: options.packageManager,
});
} catch {
console.log(`Could not uninstall ${package}`);
}
}
},

async afterInstall(options) {
const filesToDelete = ['app/index.html'];
const filesToDelete = [
'app/index.html',
'.eslintrc.js',
'.prettierrc.js',
'types',
];

for (let file of filesToDelete) {
await rm(join(options.target, file));
await rm(join(options.target, file), { recursive: true });
}

// there doesn't seem to be a way to tell ember-cli to not prompt to override files that were added in the beforeInstall
Expand Down

0 comments on commit 6e25ccc

Please sign in to comment.