Skip to content

Commit c7516c8

Browse files
Reid Barberreidbarber
authored andcommitted
fix lint (#199)
* fix lint * add skipLibCheck * remove skipLibCheck --------- Co-authored-by: Reid Barber <[email protected]>
1 parent d0986d8 commit c7516c8

File tree

4 files changed

+2
-101
lines changed

4 files changed

+2
-101
lines changed

packages/@react-spectrum/upgrade-cli/__tests__/imports.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// @ts-ignore
22
import {defineSnapshotTest} from 'jscodeshift/dist/testUtils';
33
import transform from '../src/codemods/codemod';
4-
import {transform as runCodemod} from '../src/transform';
54

65
const test = (name: string, input: string) => {
76
defineSnapshotTest(transform, {}, input, name);

packages/@react-spectrum/upgrade-cli/src/codemods/transforms.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ function removeProp(path: NodePath<t.JSXElement>, options: RemovePropOptions) {
232232
) {
233233
if (t.isIdentifier(path.node.value.expression)) {
234234
// @ts-ignore
235+
// eslint-disable-next-line max-depth
235236
if (path.node.comments && [...path.node.comments].some((comment) => comment.value.includes('could not be automatically'))) {
236237
return;
237238
}
Lines changed: 1 addition & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
const fs = require('fs');
21
const path = require('path');
3-
const jscodeshift = require('jscodeshift');
42
import installPackage from './installPackage';
53
import logger from './logger';
6-
import chalk from 'chalk';
74

85
export async function addMacroSupport() {
96
const packageJson = require(path.join(process.cwd(), 'package.json'));
@@ -15,96 +12,6 @@ export async function addMacroSupport() {
1512

1613
let isMacroPluginInstalled = await installPackage('unplugin-parcel-macros', {dev: true});
1714

18-
return {isMacroPluginInstalled, isMacroSupportEnabled: false};
19-
2015
// TODO: Try to automatically update bundle config
21-
22-
const configFiles = ['webpack', 'next', 'vite', 'rollup'].flatMap(bundler => [
23-
`${bundler}.config.js`,
24-
`${bundler}.config.ts`,
25-
`${bundler}.config.mjs`
26-
]);
27-
28-
// TODO: Detecting esbuild config is harder
29-
30-
const configFile = configFiles.find(file => fs.existsSync(path.join(process.cwd(), file)));
31-
32-
if (!configFile) {
33-
logger.warn(`Bundler config was not detected, so we couldn't update it automatically. Be sure to configure your bundler to support macros: ${chalk.bold('https://react-spectrum.corp.adobe.com/s2/#configuring-your-bundler')}`);
34-
return;
35-
}
36-
37-
const filePath = path.join(process.cwd(), configFile);
38-
const source = fs.readFileSync(filePath, 'utf8');
39-
const j = jscodeshift.withParser(configFile.endsWith('.ts') ? 'ts' : 'babel');
40-
const root = j(source);
41-
42-
const bundler = configFile.split('.')[0];
43-
const pluginName = `macros.${bundler}()`;
44-
45-
let modified = false;
46-
47-
if (bundler === 'webpack' || bundler === 'vite') {
48-
root
49-
.find(j.ArrayExpression)
50-
.filter(path => path.parent.node.key && path.parent.node.key.name === 'plugins')
51-
.forEach(path => {
52-
path.node.elements.push(j.callExpression(j.identifier(pluginName), []));
53-
modified = true;
54-
});
55-
} else if (bundler === 'rollup') {
56-
root
57-
.find(j.ArrayExpression)
58-
.filter(path => path.parent.node.key && path.parent.node.key.name === 'plugins')
59-
.forEach(path => {
60-
// Ensure macro plugin is placed before babel plugin
61-
const babelPluginIndex = path.node.elements.findIndex(node => node.type === 'CallExpression' && node.callee.type === 'Identifier' && node.callee.name === 'babel');
62-
const newPlugin = j.callExpression(j.identifier(pluginName), []);
63-
if (babelPluginIndex !== -1) {
64-
path.node.elements.splice(babelPluginIndex, 0, newPlugin);
65-
} else {
66-
path.node.elements.unshift(newPlugin);
67-
}
68-
modified = true;
69-
});
70-
} else if (bundler === 'next') {
71-
root
72-
.find(j.ObjectExpression)
73-
.filter(path => path.parent.node.type === 'AssignmentExpression' && path.parent.node.left.type === 'MemberExpression' && path.parent.node.left.property.name === 'webpack')
74-
.forEach(path => {
75-
const configParam = j.identifier('config');
76-
const pushCall = j.callExpression(
77-
j.memberExpression(j.memberExpression(configParam, j.identifier('plugins')), j.identifier('push')),
78-
[j.identifier('plugin')]
79-
);
80-
const returnStatement = j.returnStatement(configParam);
81-
path.node.body = j.blockStatement([pushCall, returnStatement]);
82-
modified = true;
83-
});
84-
85-
// Add plugin instantiation
86-
root.get().node.program.body.unshift(
87-
j.variableDeclaration('const', [
88-
j.variableDeclarator(
89-
j.identifier('plugin'),
90-
j.callExpression(j.identifier(pluginName), [])
91-
)
92-
])
93-
);
94-
}
95-
96-
if (modified) {
97-
// Add import statement
98-
root.get().node.program.body.unshift(
99-
j.importDeclaration(
100-
[j.importDefaultSpecifier(j.identifier('macros'))],
101-
j.literal('unplugin-parcel-macros')
102-
)
103-
);
104-
105-
fs.writeFileSync(filePath, root.toSource());
106-
logger.success(`Successfully updated ${chalk.bold(configFile)} with the macros plugin.`);
107-
} else {
108-
console.log(`Could not automatically add the macro plugin to ${chalk.bold(configFile)}. See the docs to try configuring it manually: ${chalk.bold('https://react-spectrum.corp.adobe.com/s2/#configuring-your-bundler')}`);
109-
}
16+
return {isMacroPluginInstalled, isMacroSupportEnabled: false};
11017
}

packages/@react-spectrum/upgrade-cli/src/utils/installPackage.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,6 @@ function detectPackageManager() {
1919
return null;
2020
}
2121

22-
async function isPackageInstalled(packageName: string) {
23-
let packageJsonPath = path.join(process.cwd(), 'package.json');
24-
let packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
25-
return packageJson.dependencies?.[packageName] || packageJson.devDependencies?.[packageName];
26-
}
27-
2822
function hasPackageJson() {
2923
return fs.existsSync(path.join(process.cwd(), 'package.json'));
3024
}

0 commit comments

Comments
 (0)