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

FEI-4957.7: Generate .js.flow files from .d.ts files #529

Merged
merged 2 commits into from
Feb 16, 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
10 changes: 10 additions & 0 deletions .changeset/modern-turtles-invent.md
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
26 changes: 0 additions & 26 deletions .flowconfig

This file was deleted.

9 changes: 4 additions & 5 deletions .github/workflows/node-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,10 @@ jobs:
run: yarn build

- name: Build Types
# There isn't an easy way for us to type check our tests without
# also including them in dist folder when we build the .d.ts files
# so we have to manually remove them.
# TODO(kevin): Figure out how to have the `build:types` script do this.
run: yarn build:types && rm -rf packages/*/dist/**/__tests__
run: yarn build:types

- name: Build Flow Types
run: yarn build:flowtypes

# Linting / type checking
- name: Eslint
Expand Down
18 changes: 18 additions & 0 deletions build-scripts/gen-flow-types.ts
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});

Check warning

Code scanning / CodeQL

Shell command built from environment values

This shell command depends on an uncontrolled [file name](1).
console.log(`✅ wrote: ${outFile}`);
} catch (e) {
console.log(`❌ error processing: ${inFile}: ${e}`);
}
}
21 changes: 21 additions & 0 deletions build-scripts/remove-test-types-from-dist.ts
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));
}
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
"@rollup/plugin-babel": "^6.0.3",
"@rollup/plugin-node-resolve": "^15.0.1",
"@rollup/plugin-replace": "^5.0.2",
"@swc-node/register": "^1.6.2",
"@swc/core": "^1.3.35",
"@types/express": "^4.17.17",
"@types/express-winston": "^4.0.0",
"@types/jest": "^29.4.0",
Expand All @@ -53,6 +55,7 @@
"fast-glob": "^3.2.12",
"flow-bin": "^0.199.1",
"flow-enums-runtime": "^0.0.6",
"flowgen": "^1.21.0",
"heapdump": "^0.3.15",
"jest": "^29.4.3",
"jest-extended": "^3.2.3",
Expand All @@ -73,14 +76,15 @@
"scripts": {
"build": "rollup -c build-settings/rollup.config.js",
"build:prodsizecheck": "rollup -c build-settings/rollup.config.js --configPlatforms='browser' --configFormats='esm' --configEnvironment='production'",
"build:types": "yarn tsc --build --verbose tsconfig-build.json",
"build:types": "yarn tsc --build --verbose tsconfig-build.json && node -r @swc-node/register build-scripts/remove-test-types-from-dist.ts",
"build:flowtypes": "node -r @swc-node/register build-scripts/gen-flow-types.ts",
"watch": "rollup -c build-settings/rollup.config.js --watch",
"clean": "rm -rf packages/wonder-stuff-*/dist && rm -rf packages/wonder-stuff-*/node_modules && rm -f packages/*/tsconfig.tsbuildinfo",
"coverage": "yarn run jest --coverage",
"format": "prettier --write .",
"lint": "eslint --config .eslintrc.js packages",
"lint:ci": "eslint --config .eslintrc.js",
"publish:ci": "node utils/pre-publish-check-ci.js && git diff --stat --exit-code HEAD && yarn build && changeset publish",
"publish:ci": "node utils/pre-publish-check-ci.js && git diff --stat --exit-code HEAD && yarn build && yarn build:types && yarn build:flowtypes && changeset publish",
"test": "yarn jest",
"typecheck": "tsc --project tsconfig-check.json",
"nochangeset": "yarn changeset add --empty"
Expand Down
Loading