Skip to content

Commit 37537d5

Browse files
chore: adds React17 reset script (#3115)
* Component compat * .ts compat * PolymorphicRenderFunctionReturnType * sync spec files * update Link & BackLink specs * Update useEchart.spec.ts * Update index.ts * Update FormField.spec.tsx * restore Popover.spec.tsx ts expect error * Update PasswordInput.spec.tsx * select spec * packages/table/src/utils/stories.testutils.tsx * sync ts files * @ts-ignore React18 * packages/popover/src/Popover/Popover.spec.tsx * Refresh RTLOverrides * packages/toast/src/InternalToast/InternalToast.stories.tsx * fix render hook * Update ExpandedContent.spec.tsx * charts/core/src/ChartContext/ChartContext.spec.tsx * changesets * renderDescendantsTestContext * cleanup tooltip tests * bump popover-polyfill * fix ToggleEvent type import * test(date-picker): wrap timer advancement in waitFor * test(getAllPackages): ensure temporary directories * Creates R17 init script * Delete install-react17.ts * Update react17.yml * Update init.ts * cleanup tsconfigs * Update package.json * install lodash. rm gh-pages * init defaults deep * rm clean from init script * lint * feat: add lib exists type * lint exports * storyoobk addon typoe * chore: update react17 files * Delete init.ts * lint * add separate R17 build & test jobs * Squashed commit of the following: commit 87dc0b6 Author: Adam Thompson <[email protected]> Date: Wed Sep 10 13:22:33 2025 -0400 [LG-5490] chore: React17 compatibility (#3101) * Component compat * .ts compat * PolymorphicRenderFunctionReturnType * sync spec files * update Link & BackLink specs * Update useEchart.spec.ts * Update index.ts * Update FormField.spec.tsx * restore Popover.spec.tsx ts expect error * Update PasswordInput.spec.tsx * select spec * packages/table/src/utils/stories.testutils.tsx * sync ts files * @ts-ignore React18 * packages/popover/src/Popover/Popover.spec.tsx * Refresh RTLOverrides * packages/toast/src/InternalToast/InternalToast.stories.tsx * fix render hook * Update ExpandedContent.spec.tsx * charts/core/src/ChartContext/ChartContext.spec.tsx * changesets * renderDescendantsTestContext * cleanup tooltip tests * bump popover-polyfill * fix ToggleEvent type import * test(date-picker): wrap timer advancement in waitFor * test(getAllPackages): ensure temporary directories * chore(testing-lib): RTL overrides re-organization (#3114) * Updates internal structure of RTL overrides * Update rtl-overrides.md * fix git mv * Update hooks.spec.tsx * fix act * Squashed commit of the following: commit 87dc0b6 Author: Adam Thompson <[email protected]> Date: Wed Sep 10 13:22:33 2025 -0400 [LG-5490] chore: React17 compatibility (#3101) * Component compat * .ts compat * PolymorphicRenderFunctionReturnType * sync spec files * update Link & BackLink specs * Update useEchart.spec.ts * Update index.ts * Update FormField.spec.tsx * restore Popover.spec.tsx ts expect error * Update PasswordInput.spec.tsx * select spec * packages/table/src/utils/stories.testutils.tsx * sync ts files * @ts-ignore React18 * packages/popover/src/Popover/Popover.spec.tsx * Refresh RTLOverrides * packages/toast/src/InternalToast/InternalToast.stories.tsx * fix render hook * Update ExpandedContent.spec.tsx * charts/core/src/ChartContext/ChartContext.spec.tsx * changesets * renderDescendantsTestContext * cleanup tooltip tests * bump popover-polyfill * fix ToggleEvent type import * test(date-picker): wrap timer advancement in waitFor * test(getAllPackages): ensure temporary directories * no --frozen-lockfile * [LG-5354, LG-5461] fix(Polymorphic) Updates Polymorphic return types (#3111) * PolymorphicRenderFunctionReturnType * propTypes * tsdoc * Create poly-types.md * Update poly-types.md * Create poly-types.md * pkg json scripts * rename PolymorphicReturnType * Update Polymorphic.hooks.tsx * Update Polymorphic.hooks.tsx * rm pre-install step * Adds polymorphic tests to assert event type * fix: Fixes tests failing in React 17 (#3112) * Update r17-packages.json * Update transformToNestedData.spec.ts * Update DrawerToolbarContext.spec.tsx * Update Message.spec.tsx * WIP resizable * Update setup.js * useResizable * Update useScreenReaderAnnouncer.tsx * Update ProgressBar.spec.tsx * changeset * Update .changeset/progress-bar-strict.md * Update react17.yml * Update react17.yml * Update react17.yml * export isReact17 * Update transformToNestedData.spec.ts * Update transformToNestedData.spec.ts * rm cache: false * useDrawerToolbarContext tests * consistent queryByRole * Update Polymorphic.hooks.tsx * Update Polymorphic.hooks.tsx * WIP resizable * useResizable * Update react17.yml * Update react17.yml * Update react17.yml * Update transformToNestedData.spec.ts * rm cache: false * useDrawerToolbarContext tests * Create reset.mjs * Update package.json * reset yaml * Update reset.mjs
1 parent 5a0d672 commit 37537d5

File tree

2 files changed

+210
-0
lines changed

2 files changed

+210
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"lint": "lg lint",
3030
"prepublishOnly": "pnpm run build && pnpm build:ts-downlevel && pnpm build:docs",
3131
"publish": "pnpm changeset publish --public",
32+
"reset:react17": "npx node ./scripts/react17/reset.mjs; pnpm run init",
3233
"slackbot": "lg slackbot",
3334
"start": "npx storybook dev -p 9001 --no-version-updates --no-open",
3435
"serve": "npx http-server storybook-static -c5",

scripts/react17/reset.mjs

Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
/* eslint-disable no-console */
2+
3+
/**
4+
* This file resets all changes made by the init.mjs script
5+
* to restore the repository to its original React 18 state
6+
*/
7+
import { execSync } from 'child_process';
8+
import fs from 'fs';
9+
import path from 'path';
10+
import { fileURLToPath } from 'url';
11+
12+
const __filename = fileURLToPath(import.meta.url);
13+
const __dirname = path.dirname(__filename);
14+
15+
const ROOT_DIR = path.resolve(__dirname, '../..');
16+
17+
// Check for verbose flag
18+
const isVerbose =
19+
process.argv.includes('--verbose') || process.argv.includes('-v');
20+
21+
async function main() {
22+
console.log('🔄 Resetting React 17 environment changes');
23+
24+
if (isVerbose) {
25+
console.log('📝 Verbose mode enabled - showing detailed output');
26+
}
27+
28+
// Step 1: Reset root package.json
29+
console.log('1️⃣ Resetting package.json...');
30+
await resetFile('package.json');
31+
32+
// Step 2: Reset pnpm-lock.yaml if it exists
33+
console.log('2️⃣ Resetting pnpm-lock.yaml...');
34+
await resetFile('pnpm-lock.yaml');
35+
36+
// Step 3: Reset all tsconfig.json files in package directories
37+
console.log('3️⃣ Resetting TypeScript configurations...');
38+
await resetTsConfigFiles();
39+
40+
console.log('✅ React 17 environment reset complete!');
41+
}
42+
43+
/**
44+
* Reset a specific file using git checkout
45+
* @param {string} fileName - The file name to reset
46+
*/
47+
async function resetFile(fileName) {
48+
// Check if file is actually modified
49+
if (!isFileModified(fileName)) {
50+
if (isVerbose) {
51+
console.log(`\t ✓ ${fileName} (no changes)`);
52+
}
53+
return;
54+
}
55+
56+
try {
57+
const cmd = `git checkout HEAD -- ${fileName}`;
58+
if (isVerbose) {
59+
console.log(`\t \x1b[90m${cmd}\x1b[0m`);
60+
}
61+
62+
execSync(cmd, {
63+
cwd: ROOT_DIR,
64+
stdio: isVerbose ? 'inherit' : 'pipe',
65+
});
66+
67+
if (isVerbose) {
68+
console.log(`\t ✓ Reset ${fileName}`);
69+
}
70+
} catch (error) {
71+
// File might not be tracked or might not exist, which is fine
72+
console.log(
73+
`\t ⚠️ Could not reset ${fileName} (might not be tracked or might not exist)`,
74+
);
75+
if (isVerbose) {
76+
console.log(`\t Error: ${error.message}`);
77+
}
78+
}
79+
}
80+
81+
/**
82+
* Check if a file is modified in git
83+
* @param {string} filePath - The relative path to check
84+
* @returns {boolean} True if the file is modified
85+
*/
86+
function isFileModified(filePath) {
87+
try {
88+
const output = execSync(`git status --porcelain -- "${filePath}"`, {
89+
cwd: ROOT_DIR,
90+
stdio: 'pipe',
91+
encoding: 'utf8',
92+
});
93+
return output.trim().length > 0;
94+
} catch (error) {
95+
return false;
96+
}
97+
}
98+
99+
/**
100+
* Get all modified tsconfig.json files
101+
* @returns {Array<string>} Array of modified tsconfig.json file paths
102+
*/
103+
function getModifiedTsConfigFiles() {
104+
try {
105+
const output = execSync('git status --porcelain', {
106+
cwd: ROOT_DIR,
107+
stdio: 'pipe',
108+
encoding: 'utf8',
109+
});
110+
111+
return output
112+
.split('\n')
113+
.filter(line => line.trim().length > 0)
114+
.filter(line => line.includes('tsconfig.json'))
115+
.map(line => line.slice(3).trim()); // Remove git status prefix (e.g., " M ")
116+
} catch (error) {
117+
return [];
118+
}
119+
}
120+
121+
/**
122+
* Find and reset all tsconfig.json files in package directories
123+
*/
124+
async function resetTsConfigFiles() {
125+
const modifiedTsConfigFiles = getModifiedTsConfigFiles();
126+
127+
console.log(
128+
`\t Found ${modifiedTsConfigFiles.length} modified tsconfig.json files`,
129+
);
130+
131+
if (modifiedTsConfigFiles.length === 0) {
132+
console.log('\t ✓ No tsconfig.json files need to be reset');
133+
return;
134+
}
135+
136+
console.log('\t Resetting modified files...');
137+
138+
let processed = 0;
139+
let errors = 0;
140+
141+
for (const modifiedFile of modifiedTsConfigFiles) {
142+
try {
143+
resetFile(modifiedFile);
144+
processed++;
145+
} catch (error) {
146+
console.log(`\t ⚠️ Could not reset ${modifiedFile}`);
147+
if (isVerbose) {
148+
console.log(`\t Error: ${error.message}`);
149+
}
150+
errors++;
151+
processed++;
152+
}
153+
}
154+
155+
if (errors > 0) {
156+
console.log(
157+
`\t ✓ Reset ${processed - errors} tsconfig.json files (${errors} errors)`,
158+
);
159+
} else {
160+
console.log(`\t ✓ Reset ${processed} tsconfig.json files`);
161+
}
162+
}
163+
164+
/**
165+
* Find tsconfig.json files only in root package directories (packages, charts, chat, tools)
166+
* Skip nested directories like scripts, src, etc. to avoid modifying non-package configs
167+
* @param {string} dir - The directory to search in
168+
* @returns {Array<string>} Array of tsconfig.json file paths
169+
*/
170+
function findTsConfigFiles(dir) {
171+
/** @type {Array<string>} */
172+
const results = [];
173+
const packageDirs = ['packages', 'charts', 'chat', 'tools'];
174+
175+
for (const packageDir of packageDirs) {
176+
const packagePath = path.join(dir, packageDir);
177+
178+
if (!fs.existsSync(packagePath)) {
179+
continue;
180+
}
181+
182+
try {
183+
const packages = fs.readdirSync(packagePath);
184+
185+
for (const pkg of packages) {
186+
const pkgPath = path.join(packagePath, pkg);
187+
const stat = fs.statSync(pkgPath);
188+
189+
if (stat.isDirectory()) {
190+
const tsConfigPath = path.join(pkgPath, 'tsconfig.json');
191+
192+
if (fs.existsSync(tsConfigPath)) {
193+
results.push(tsConfigPath);
194+
}
195+
}
196+
}
197+
} catch (error) {
198+
console.warn(`⚠️ Failed to read directory ${packagePath}:`, error);
199+
}
200+
}
201+
202+
return results;
203+
}
204+
205+
// Run the script
206+
main().catch(error => {
207+
console.error('❌ Reset script failed:', error);
208+
process.exit(1);
209+
});

0 commit comments

Comments
 (0)