-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
## Summary: We want to generate .js.flow files from our .d.ts files so that wonder-stuff packages can be used in codebases that are still using Flow. This PR adds a build script to run flowgen on each .d.ts file in the dist folder of each package. It also adds a script for removing .d.ts files that were generated from .test.ts files. Both scripts are written in TypeScript and use swc-node/register to run. I've added package.json scripts to make this easier. I'll research this further to see if there's a nice shebang approach we can use in the future, but this should suffice for now. Issue: FEI-4957 ## Test plan: - yarn clean - yarn build:types - yarn build:flowtypes - See that .d.ts and .js.flow files have been added to each packages' dist folder - See that there are no __tests__ folders in the dist folder - Copy the dist folders for wonder-stuff-core and wonder-stuff-testing into the node_modules folder of wonder-blocks - Restart flow in wonder-blocks, see that there are two Flow errors in wonder-blocks-icon (this is expected since the Flow types generated from the .d.ts files are different from the Flow types in the original code) Author: kevinbarabash Reviewers: jeresig, github-code-scanning[bot] Required Reviewers: Approved By: jeresig Checks: ✅ CodeQL, ⌛ Lint, typecheck, and coverage check (ubuntu-latest, 16.x), ✅ Prime node_modules cache for primary configuration (ubuntu-latest, 16.x), ✅ gerald, ⏭ dependabot, ✅ Analyze (javascript) Pull Request URL: #529
- Loading branch information
1 parent
da34455
commit 035e345
Showing
7 changed files
with
217 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
"@khanacademy/wonder-stuff-server-google": patch | ||
"@khanacademy/wonder-stuff-testing": patch | ||
"@khanacademy/wonder-stuff-sentry": patch | ||
"@khanacademy/wonder-stuff-server": patch | ||
"@khanacademy/wonder-stuff-core": patch | ||
"@khanacademy/wonder-stuff-i18n": patch | ||
--- | ||
|
||
Generate Flow types from TypeScript types |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import {execSync} from "child_process"; | ||
import * as fg from "fast-glob"; | ||
import * as path from "path"; | ||
|
||
const rootDir = path.join(__dirname, ".."); | ||
const files = fg.sync("packages/wonder-stuff-*/dist/**/*.d.ts", {cwd: rootDir}); | ||
|
||
for (const inFile of files) { | ||
const outFile = inFile.replace(".d.ts", ".js.flow"); | ||
const command = `yarn flowgen ${inFile} -o ${outFile} --add-flow-header`; | ||
|
||
try { | ||
execSync(command, {cwd: rootDir}); | ||
console.log(`✅ wrote: ${outFile}`); | ||
} catch (e) { | ||
console.log(`❌ error processing: ${inFile}: ${e}`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import * as fs from "fs"; | ||
import * as fg from "fast-glob"; | ||
import * as path from "path"; | ||
|
||
const rootDir = path.join(__dirname, ".."); | ||
const files = fg.sync("packages/wonder-stuff-*/dist/**/__tests__/*.d.ts", { | ||
cwd: rootDir, | ||
}); | ||
|
||
for (const file of files) { | ||
fs.unlinkSync(path.join(rootDir, file)); | ||
} | ||
|
||
const dirs = fg.sync("packages/wonder-stuff-*/dist/**/__tests__", { | ||
cwd: rootDir, | ||
onlyFiles: false, | ||
}); | ||
|
||
for (const dir of dirs) { | ||
fs.rmdirSync(path.join(rootDir, dir)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.