Skip to content

Commit 2e7fe45

Browse files
committed
fix(react-md): fix additional exports from @react-md/core
1 parent c64bc41 commit 2e7fe45

16 files changed

Lines changed: 198 additions & 34 deletions

File tree

.changeset/fifty-trams-sing.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
"react-md": patch
3+
---
4+
5+
Fixed a few additional exports from @react-md/core -> react-md.
6+
7+
- `react-md/configureMaterialSymbols`
8+
- `react-md/test-utils`
9+
- `react-md/test-utils/jest-globals/setup`
10+
- `react-md/test-utils/jest-globals`
11+
- `react-md/test-utils/vitest/setup`
12+
- `react-md/test-utils/vitest`
13+
- `react-md/test-utils/polyfills`
14+
- `react-md/test-utils/data-testid`

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"clean-root": "rm -rf .turbo coverage node_modules",
3838
"clean-examples": "rm -rf examples/*/node_modules",
3939
"core-export-map": "pnpm --filter core export-map",
40-
"core-index-file": "pnpm --filter core create-index-file",
40+
"create-react-md": "pnpm --filter core create-react-md",
4141
"validate": "pnpm lint && pnpm typecheck",
4242
"changeset": "changeset",
4343
"turbo-release": "pnpm turbo-s --filter=react-md --filter=@react-md/codemod --filter=@react-md/material-icons --filter @react-md/vite-material-symbols-plugin",

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
"build-scss-watch": "pnpm build-scss --watch",
8787
"build": "concurrently 'pnpm build-esm' 'pnpm build-scss' 'pnpm build-types'",
8888
"export-map": "tsx scripts/getExportMap.ts",
89-
"create-index-file": "tsx scripts/createIndexFile.ts",
89+
"create-react-md": "tsx scripts/create-react-md.ts",
9090
"prepare-release": "pnpm clean-dist && pnpm build",
9191
"dev": "concurrently 'pnpm build-esm-watch' 'pnpm build-scss-watch' 'pnpm build-types-watch'"
9292
},

packages/core/scripts/constants.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,16 @@ export const PRIVATE_FILES = [
2525
"**/transition/utils*",
2626
"**/tree/useTreeMovement*",
2727
];
28+
29+
export const GENERATED_FILE_BANNER =
30+
"// THIS FILE WAS GENERATED BY A SCRIPT AND SHOULD NOT BE UPDATED MANUALLY";
31+
32+
export const SYNCED_EXPORTS = [
33+
"test-utils",
34+
"test-utils/data-testid",
35+
"test-utils/jest-globals",
36+
"test-utils/jest-globals/setup",
37+
"test-utils/vitest",
38+
"test-utils/vitest/setup",
39+
"test-utils/polyfills",
40+
];
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import { glob } from "glob";
2+
import { writeFile } from "node:fs/promises";
3+
import { join, resolve } from "node:path";
4+
import { format } from "prettier";
5+
6+
import { alphaNumericSort } from "../src/utils/alphaNumericSort.js";
7+
import {
8+
GENERATED_FILE_BANNER,
9+
PRIVATE_FILES,
10+
SYNCED_EXPORTS,
11+
} from "./constants.js";
12+
13+
const write = async (filePath: string, contents: string): Promise<void> => {
14+
await writeFile(
15+
filePath,
16+
await format(
17+
`${GENERATED_FILE_BANNER}
18+
19+
${contents}
20+
`,
21+
{ filepath: filePath }
22+
)
23+
);
24+
console.log(
25+
`Wrote ${filePath.replace(resolve("../react-md"), "packages/react-md")}`
26+
);
27+
};
28+
29+
const coreSrc = join(process.cwd(), "src");
30+
const filesForBarrelFile = await glob("**/*.{ts,tsx}", {
31+
cwd: coreSrc,
32+
ignore: ["**/__tests__/**", "**/test-utils/**", ...PRIVATE_FILES],
33+
});
34+
35+
const barrelFileContents = alphaNumericSort(filesForBarrelFile)
36+
.map(
37+
(name) => `export * from "@react-md/core/${name.replace(/\.tsx?$/, "")}"`
38+
)
39+
.join(";\n");
40+
const indexFileName = resolve("../react-md/src/index.ts");
41+
const configureMaterialSymbols = resolve(
42+
"../react-md/src/configureMaterialSymbols.ts"
43+
);
44+
await Promise.all([
45+
write(indexFileName, barrelFileContents),
46+
...SYNCED_EXPORTS.map((exportName) => {
47+
let prefix = "export * from";
48+
if (exportName === "test-utils/data-testid") {
49+
prefix = "import";
50+
}
51+
52+
write(
53+
resolve(`../react-md/src/${exportName}.ts`),
54+
`${prefix} "@react-md/core/${exportName}"`
55+
);
56+
}),
57+
write(
58+
configureMaterialSymbols,
59+
'import "@react-md/core/icon/configureMaterialSymbols"'
60+
),
61+
]);
62+
63+
const packageJsonPath = resolve("../react-md/package.json");
64+
const { default: packageJson } = await import(packageJsonPath, {
65+
with: { type: "json" },
66+
});
67+
68+
packageJson.exports = {
69+
"./a11y": {
70+
sass: "./dist/_a11y.scss",
71+
},
72+
"./colors": {
73+
sass: "./dist/_colors.scss",
74+
},
75+
"./configureMaterialSymbols": "./dist/configureMaterialSymbols.js",
76+
"./test-utils": "./dist/test-utils.js",
77+
"./test-utils/*": "./dist/test-utils/*.js",
78+
".": {
79+
sass: "./dist/_react-md.scss",
80+
types: "./dist/index.d.ts",
81+
default: "./dist/index.js",
82+
},
83+
"./package.json": "./package.json",
84+
};
85+
86+
await writeFile(
87+
packageJsonPath,
88+
await format(JSON.stringify(packageJson), { filepath: packageJsonPath })
89+
);

packages/core/scripts/createIndexFile.ts

Lines changed: 0 additions & 24 deletions
This file was deleted.

packages/react-md/README.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,65 @@ convenience. Some more information can be found
2929
- Left-to-right and right-to-left language support
3030
- Written and maintained in [Typescript]
3131

32+
## Additional Exports
33+
34+
There are a few exports from `@react-md/core` which must be imported separately
35+
since they have side effects or are for testing only:
36+
37+
### `configureMaterialSymbols`
38+
39+
This is the shortcut for configuring the default icons to use material symbols
40+
instead of font icons.
41+
42+
```diff
43+
-import "@react-md/core/icon/configureMaterialSymbols";
44+
+import "react-md/configureMaterialSymbols";
45+
```
46+
47+
### `test-utils`
48+
49+
```diff
50+
-export * from "@react-md/core/test-utils";
51+
+export * from "react-md/test-utils";
52+
```
53+
54+
### `test-utils/data-testid`
55+
56+
```diff
57+
-import "@react-md/core/test-utils/data-testid";
58+
+import "react-md/test-utils/data-testid";
59+
```
60+
61+
### `test-utils/polyfills`
62+
63+
```diff
64+
-import "@react-md/core/test-utils/polyfills";
65+
+import "react-md/test-utils/polyfills";
66+
```
67+
68+
> NOTE: You cannot pick and choose which polyfills to use unlike in
69+
> `@react-md/core`. It is all or nothing.
70+
71+
### `test-utils/jest-globals`
72+
73+
```diff
74+
-import "@react-md/core/test-utils/jest-globals/setup";
75+
+import "react-md/test-utils/jest-globals/setup";
76+
77+
-export * from "@react-md/core/test-utils/jest-globals";
78+
+export * from "react-md/test-utils/jest-globals";
79+
```
80+
81+
### `test-utils/vitest`
82+
83+
```diff
84+
-import "@react-md/core/test-utils/vitest";
85+
+import "react-md/test-utils/vitest/setup";
86+
87+
-export * from "@react-md/core/test-utils/vitest/setup";
88+
+export * from "react-md/test-utils/vitest";
89+
```
90+
3291
[typescript]: https://www.typescriptlang.org/
3392
[www.w3.org]: https://www.w3.org/TR/wai-aria-practices
3493
[installation]: https://react-md.dev/getting-started/installation

packages/react-md/package.json

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,9 @@
1111
"./colors": {
1212
"sass": "./dist/_colors.scss"
1313
},
14-
"./test-utils/polyfills": {
15-
"require": "./dist/test-utils/polyfills",
16-
"default": "./dist/test-utils/polyfills/index.js"
17-
},
18-
"./test-utils/jest-globals": "./dist/test-utils/jest-globals/index.js",
19-
"./test-utils/vitest": "./dist/test-utils/vitest/index.js",
20-
"./test-utils": "./dist/test-utils/index.js",
2114
"./configureMaterialSymbols": "./dist/configureMaterialSymbols.js",
15+
"./test-utils": "./dist/test-utils.js",
16+
"./test-utils/*": "./dist/test-utils/*.js",
2217
".": {
2318
"sass": "./dist/_react-md.scss",
2419
"types": "./dist/index.d.ts",
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
export * from "@react-md/core/icon/configureMaterialSymbols";
1+
// THIS FILE WAS GENERATED BY A SCRIPT AND SHOULD NOT BE UPDATED MANUALLY
2+
import "@react-md/core/icon/configureMaterialSymbols";
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// THIS FILE WAS GENERATED BY A SCRIPT AND SHOULD NOT BE UPDATED MANUALLY
2+
3+
export * from "@react-md/core/test-utils";

0 commit comments

Comments
 (0)