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

[fei5815.2.workaround] Add step to tidy up files #1024

Merged
merged 9 commits into from
Aug 30, 2024
12 changes: 12 additions & 0 deletions .changeset/clean-apples-knock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
"@khanacademy/wonder-stuff-ci": patch
"@khanacademy/wonder-stuff-core": patch
"@khanacademy/wonder-stuff-i18n": patch
"@khanacademy/wonder-stuff-render-environment-jsdom": patch
"@khanacademy/wonder-stuff-render-server": patch
"@khanacademy/wonder-stuff-sentry": patch
"@khanacademy/wonder-stuff-server": patch
"@khanacademy/wonder-stuff-testing": patch
---

Stop packaging some files that we don't need to package
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ docs
.DS_Store
yarn-error.log
*.tsbuildinfo
utils/**/*.d.ts
2 changes: 0 additions & 2 deletions .npmignore

This file was deleted.

59 changes: 59 additions & 0 deletions build-settings/check-type-definitions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env -S node -r @swc-node/register
/* eslint-disable no-console */
/**
* Check type definition files for anything that doesn't look right.
*
* If our packages don't export all the types that other packages reference,
* even indirectly, then their type definitions will import them from the source
* files instead. Since we don't want to ship source code in every package,
* we want to guard against this.
*
* This script should be run after `yarn build:types`. It will scan the type
* definitions of each package for any types that are being incorrectly
* imported from other the source code of other packages, and flag them,
* exiting with a non-zero status code if any are found.
*/
import * as fs from "fs";
import * as path from "path";
import * as fglob from "fast-glob";

const rootDir = path.join(__dirname, "..");
const packagesDir = path.join(rootDir, "packages");

// Find all the type definition files in the packages dist directories.
const typeDefinitionFiles = fglob.sync("**/*.d.ts", {
cwd: packagesDir,
onlyFiles: true,
});

let foundErrors = false;
// Scan each one for any imports of types from source.
for (const typeDefinitionFile of typeDefinitionFiles) {
const regexpImportSrc =
/import\(".+\/(wonder-stuff-.+)\/src\/.+"\)\.([a-zA-Z]+)/g;
const content = fs.readFileSync(
path.join(packagesDir, typeDefinitionFile),
"utf-8",
);
const lines = content.split("\n");
let match;
for (let line = 0; line < lines.length; line++) {
while ((match = regexpImportSrc.exec(lines[line]))) {
foundErrors = true;
const position = match.index;
const lineNo = line + 1;
const refPath = path.join("packages", typeDefinitionFile);
console.error(`${refPath}:${lineNo}:${position}`);
console.error(
` Incorrectly imported type ${match[2]} from ${match[1]} source`,
);
console.error(
` Update the package ${match[1]} to export the type ${match[2]}\n`,
);
}
}
}

if (foundErrors) {
process.exit(1);
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-replace": "^5.0.3",
"@rollup/plugin-terser": "^0.4.3",
"@swc-node/register": "^1.6.8",
"@swc-node/register": "^1.10.9",
"@swc/core": "^1.3.93",
"@types/express": "^4.17.20",
"@types/express-winston": "^4.0.0",
Expand Down Expand Up @@ -83,7 +83,7 @@
"rollup": "rollup -c build-settings/rollup.config.mjs",
"build": "yarn rollup",
"build:prodsizecheck": "yarn rollup --configPlatforms='browser' --configFormats='esm' --configEnvironment='production'",
"build:types": "yarn tsc --build --verbose tsconfig-build.json",
"build:types": "yarn tsc --build --verbose tsconfig-build.json && ./build-settings/check-type-definitions.ts",
"build:docs": "typedoc",
"watch": "yarn rollup --watch",
"clean": "rm -rf packages/wonder-stuff-*/dist && rm -rf packages/wonder-stuff-*/node_modules && rm -f packages/*/*.tsbuildinfo",
Expand Down
13 changes: 13 additions & 0 deletions packages/eslint-config-khan/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
*.tsbuildinfo
tsconfig-build.json
dist/**/__tests__
dist/**/*.test.d.ts
src
README.md
demo
docs
node_modules
babel.config.js
.eslintrc.js
.mocharc.js
test
13 changes: 13 additions & 0 deletions packages/eslint-plugin-khan/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
*.tsbuildinfo
tsconfig-build.json
dist/**/__tests__
dist/**/*.test.d.ts
src
README.md
demo
docs
node_modules
babel.config.js
.eslintrc.js
.mocharc.js
test
3 changes: 0 additions & 3 deletions packages/eslint-plugin-khan/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
"publishConfig": {
"access": "public"
},
"files": [
"/dist"
],
"main": "dist/index.js",
"module": "dist/es/index.js",
"author": "Kevin Barabash <[email protected]>",
Expand Down
13 changes: 13 additions & 0 deletions packages/wonder-stuff-ci/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
*.tsbuildinfo
tsconfig-build.json
dist/**/__tests__
dist/**/*.test.d.ts
src
README.md
demo
docs
node_modules
babel.config.js
.eslintrc.js
.mocharc.js
test
13 changes: 13 additions & 0 deletions packages/wonder-stuff-core/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
*.tsbuildinfo
tsconfig-build.json
dist/**/__tests__
dist/**/*.test.d.ts
src
README.md
demo
docs
node_modules
babel.config.js
.eslintrc.js
.mocharc.js
test
13 changes: 13 additions & 0 deletions packages/wonder-stuff-i18n/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
*.tsbuildinfo
tsconfig-build.json
dist/**/__tests__
dist/**/*.test.d.ts
src
README.md
demo
docs
node_modules
babel.config.js
.eslintrc.js
.mocharc.js
test
13 changes: 13 additions & 0 deletions packages/wonder-stuff-render-environment-jsdom/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
*.tsbuildinfo
tsconfig-build.json
dist/**/__tests__
dist/**/*.test.d.ts
src
README.md
demo
docs
node_modules
babel.config.js
.eslintrc.js
.mocharc.js
test
13 changes: 13 additions & 0 deletions packages/wonder-stuff-render-server/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
*.tsbuildinfo
tsconfig-build.json
dist/**/__tests__
dist/**/*.test.d.ts
src
README.md
demo
docs
node_modules
babel.config.js
.eslintrc.js
.mocharc.js
test
13 changes: 13 additions & 0 deletions packages/wonder-stuff-sentry/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
*.tsbuildinfo
tsconfig-build.json
dist/**/__tests__
dist/**/*.test.d.ts
src
README.md
demo
docs
node_modules
babel.config.js
.eslintrc.js
.mocharc.js
test
4 changes: 4 additions & 0 deletions packages/wonder-stuff-sentry/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
"module": "dist/es/index.js",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
"dist",
"CHANGELOG.md"
],
"scripts": {
"test": "bash -c 'yarn --silent --cwd \"../..\" test ${@:0} $($([[ ${@: -1} = -* ]] || [[ ${@: -1} = bash ]]) && echo $PWD)'"
},
Expand Down
13 changes: 13 additions & 0 deletions packages/wonder-stuff-server/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
*.tsbuildinfo
tsconfig-build.json
dist/**/__tests__
dist/**/*.test.d.ts
src
README.md
demo
docs
node_modules
babel.config.js
.eslintrc.js
.mocharc.js
test
13 changes: 13 additions & 0 deletions packages/wonder-stuff-testing/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
*.tsbuildinfo
tsconfig-build.json
dist/**/__tests__
dist/**/*.test.d.ts
src
README.md
demo
docs
node_modules
babel.config.js
.eslintrc.js
.mocharc.js
test
Loading