Skip to content

Commit a026cee

Browse files
[fei5815.2.workaround] Add step to tidy up files (#1024)
## Summary: It seems that `changesets publish` isn't honoring our root `.npmignore` even though `npm pack` would. This works around that by borrowing some code from Wonder Blocks where we tidy up any ignored files that aren't source-controlled, reducing what we package. We also explicitly include things in each package.json. This combination means we can easily exclude files and folders in the `dist` location, without having really explicit `files` definitions that might be hard to maintain. Issue: FEI-5815 ## Test plan: `yarn build:types` and see the files being removed. Author: somewhatabstract Reviewers: jeresig Required Reviewers: Approved By: jeresig Checks: ✅ Test (macos-latest, 20.x), ✅ codecov/project, ✅ CodeQL, ✅ Lint, typecheck, and coverage check (ubuntu-latest, 20.x), ✅ Prime node_modules cache for primary configuration (ubuntu-latest, 20.x), ✅ Analyze (javascript), ✅ gerald, ⏭️ dependabot Pull Request URL: #1024
1 parent fd1083e commit a026cee

File tree

18 files changed

+368
-7
lines changed

18 files changed

+368
-7
lines changed

.changeset/clean-apples-knock.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
"@khanacademy/wonder-stuff-ci": patch
3+
"@khanacademy/wonder-stuff-core": patch
4+
"@khanacademy/wonder-stuff-i18n": patch
5+
"@khanacademy/wonder-stuff-render-environment-jsdom": patch
6+
"@khanacademy/wonder-stuff-render-server": patch
7+
"@khanacademy/wonder-stuff-sentry": patch
8+
"@khanacademy/wonder-stuff-server": patch
9+
"@khanacademy/wonder-stuff-testing": patch
10+
---
11+
12+
Stop packaging some files that we don't need to package

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ docs
77
.DS_Store
88
yarn-error.log
99
*.tsbuildinfo
10+
utils/**/*.d.ts

.npmignore

-2
This file was deleted.
+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/usr/bin/env -S node -r @swc-node/register
2+
/* eslint-disable no-console */
3+
/**
4+
* Check type definition files for anything that doesn't look right.
5+
*
6+
* If our packages don't export all the types that other packages reference,
7+
* even indirectly, then their type definitions will import them from the source
8+
* files instead. Since we don't want to ship source code in every package,
9+
* we want to guard against this.
10+
*
11+
* This script should be run after `yarn build:types`. It will scan the type
12+
* definitions of each package for any types that are being incorrectly
13+
* imported from other the source code of other packages, and flag them,
14+
* exiting with a non-zero status code if any are found.
15+
*/
16+
import * as fs from "fs";
17+
import * as path from "path";
18+
import * as fglob from "fast-glob";
19+
20+
const rootDir = path.join(__dirname, "..");
21+
const packagesDir = path.join(rootDir, "packages");
22+
23+
// Find all the type definition files in the packages dist directories.
24+
const typeDefinitionFiles = fglob.sync("**/*.d.ts", {
25+
cwd: packagesDir,
26+
onlyFiles: true,
27+
});
28+
29+
let foundErrors = false;
30+
// Scan each one for any imports of types from source.
31+
for (const typeDefinitionFile of typeDefinitionFiles) {
32+
const regexpImportSrc =
33+
/import\(".+\/(wonder-stuff-.+)\/src\/.+"\)\.([a-zA-Z]+)/g;
34+
const content = fs.readFileSync(
35+
path.join(packagesDir, typeDefinitionFile),
36+
"utf-8",
37+
);
38+
const lines = content.split("\n");
39+
let match;
40+
for (let line = 0; line < lines.length; line++) {
41+
while ((match = regexpImportSrc.exec(lines[line]))) {
42+
foundErrors = true;
43+
const position = match.index;
44+
const lineNo = line + 1;
45+
const refPath = path.join("packages", typeDefinitionFile);
46+
console.error(`${refPath}:${lineNo}:${position}`);
47+
console.error(
48+
` Incorrectly imported type ${match[2]} from ${match[1]} source`,
49+
);
50+
console.error(
51+
` Update the package ${match[1]} to export the type ${match[2]}\n`,
52+
);
53+
}
54+
}
55+
}
56+
57+
if (foundErrors) {
58+
process.exit(1);
59+
}

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"@rollup/plugin-node-resolve": "^15.2.3",
2929
"@rollup/plugin-replace": "^5.0.3",
3030
"@rollup/plugin-terser": "^0.4.3",
31-
"@swc-node/register": "^1.6.8",
31+
"@swc-node/register": "^1.10.9",
3232
"@swc/core": "^1.3.93",
3333
"@types/express": "^4.17.20",
3434
"@types/express-winston": "^4.0.0",
@@ -83,7 +83,7 @@
8383
"rollup": "rollup -c build-settings/rollup.config.mjs",
8484
"build": "yarn rollup",
8585
"build:prodsizecheck": "yarn rollup --configPlatforms='browser' --configFormats='esm' --configEnvironment='production'",
86-
"build:types": "yarn tsc --build --verbose tsconfig-build.json",
86+
"build:types": "yarn tsc --build --verbose tsconfig-build.json && ./build-settings/check-type-definitions.ts",
8787
"build:docs": "typedoc",
8888
"watch": "yarn rollup --watch",
8989
"clean": "rm -rf packages/wonder-stuff-*/dist && rm -rf packages/wonder-stuff-*/node_modules && rm -f packages/*/*.tsbuildinfo",
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
*.tsbuildinfo
2+
tsconfig-build.json
3+
dist/**/__tests__
4+
dist/**/*.test.d.ts
5+
src
6+
README.md
7+
demo
8+
docs
9+
node_modules
10+
babel.config.js
11+
.eslintrc.js
12+
.mocharc.js
13+
test
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
*.tsbuildinfo
2+
tsconfig-build.json
3+
dist/**/__tests__
4+
dist/**/*.test.d.ts
5+
src
6+
README.md
7+
demo
8+
docs
9+
node_modules
10+
babel.config.js
11+
.eslintrc.js
12+
.mocharc.js
13+
test

packages/eslint-plugin-khan/package.json

-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
"publishConfig": {
1111
"access": "public"
1212
},
13-
"files": [
14-
"/dist"
15-
],
1613
"main": "dist/index.js",
1714
"module": "dist/es/index.js",
1815
"author": "Kevin Barabash <[email protected]>",

packages/wonder-stuff-ci/.npmignore

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
*.tsbuildinfo
2+
tsconfig-build.json
3+
dist/**/__tests__
4+
dist/**/*.test.d.ts
5+
src
6+
README.md
7+
demo
8+
docs
9+
node_modules
10+
babel.config.js
11+
.eslintrc.js
12+
.mocharc.js
13+
test

packages/wonder-stuff-core/.npmignore

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
*.tsbuildinfo
2+
tsconfig-build.json
3+
dist/**/__tests__
4+
dist/**/*.test.d.ts
5+
src
6+
README.md
7+
demo
8+
docs
9+
node_modules
10+
babel.config.js
11+
.eslintrc.js
12+
.mocharc.js
13+
test

packages/wonder-stuff-i18n/.npmignore

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
*.tsbuildinfo
2+
tsconfig-build.json
3+
dist/**/__tests__
4+
dist/**/*.test.d.ts
5+
src
6+
README.md
7+
demo
8+
docs
9+
node_modules
10+
babel.config.js
11+
.eslintrc.js
12+
.mocharc.js
13+
test
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
*.tsbuildinfo
2+
tsconfig-build.json
3+
dist/**/__tests__
4+
dist/**/*.test.d.ts
5+
src
6+
README.md
7+
demo
8+
docs
9+
node_modules
10+
babel.config.js
11+
.eslintrc.js
12+
.mocharc.js
13+
test
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
*.tsbuildinfo
2+
tsconfig-build.json
3+
dist/**/__tests__
4+
dist/**/*.test.d.ts
5+
src
6+
README.md
7+
demo
8+
docs
9+
node_modules
10+
babel.config.js
11+
.eslintrc.js
12+
.mocharc.js
13+
test
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
*.tsbuildinfo
2+
tsconfig-build.json
3+
dist/**/__tests__
4+
dist/**/*.test.d.ts
5+
src
6+
README.md
7+
demo
8+
docs
9+
node_modules
10+
babel.config.js
11+
.eslintrc.js
12+
.mocharc.js
13+
test

packages/wonder-stuff-sentry/package.json

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
"module": "dist/es/index.js",
1717
"main": "dist/index.js",
1818
"types": "dist/index.d.ts",
19+
"files": [
20+
"dist",
21+
"CHANGELOG.md"
22+
],
1923
"scripts": {
2024
"test": "bash -c 'yarn --silent --cwd \"../..\" test ${@:0} $($([[ ${@: -1} = -* ]] || [[ ${@: -1} = bash ]]) && echo $PWD)'"
2125
},
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
*.tsbuildinfo
2+
tsconfig-build.json
3+
dist/**/__tests__
4+
dist/**/*.test.d.ts
5+
src
6+
README.md
7+
demo
8+
docs
9+
node_modules
10+
babel.config.js
11+
.eslintrc.js
12+
.mocharc.js
13+
test
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
*.tsbuildinfo
2+
tsconfig-build.json
3+
dist/**/__tests__
4+
dist/**/*.test.d.ts
5+
src
6+
README.md
7+
demo
8+
docs
9+
node_modules
10+
babel.config.js
11+
.eslintrc.js
12+
.mocharc.js
13+
test

0 commit comments

Comments
 (0)