Skip to content

Commit 3918916

Browse files
authored
Rename export files and folders (#223)
* Rename export files and folders To support all possible export bundle types we should export the main, module and browser fields from the package.json. * 4.1.0
1 parent 711b1bd commit 3918916

File tree

3 files changed

+25
-14
lines changed

3 files changed

+25
-14
lines changed

config/rollup/rollup.config.js

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,29 @@ const plugins = [
4242
function createBundleConfiguration(filename, format) {
4343
const lowercaseFormat = format.toLowerCase();
4444

45-
if (![packageJSON.module, packageJSON.browser].includes(filename)) {
45+
if (
46+
![packageJSON.module, packageJSON.main, packageJSON.browser].includes(
47+
filename
48+
)
49+
) {
4650
throw new Error(`Invalid filename provided. Received: ${filename}`);
4751
}
4852

4953
if (!["esm", "cjs"].includes(lowercaseFormat)) {
5054
throw new Error(`Unrecognised output format provided. Received: ${format}`);
5155
}
5256

53-
if (lowercaseFormat === "cjs" && filename !== packageJSON.browser) {
57+
if (lowercaseFormat === "cjs" && filename !== packageJSON.main) {
5458
throw new Error("A CJS bundle can only be created for the main bundle.");
5559
}
5660

57-
if (lowercaseFormat === "esm" && filename !== packageJSON.module) {
58-
throw new Error("An ESM bundle can only be created for the module bundle.");
61+
if (
62+
lowercaseFormat === "esm" &&
63+
![packageJSON.module, packageJSON.browser].includes(filename)
64+
) {
65+
throw new Error(
66+
"An ES module bundle can only be created for the module or browser bundle."
67+
);
5968
}
6069

6170
return {
@@ -73,7 +82,8 @@ function createBundleConfiguration(filename, format) {
7382
};
7483
}
7584

76-
const ESM = createBundleConfiguration(packageJSON.module, "esm");
77-
const CJS = createBundleConfiguration(packageJSON.browser, "cjs");
78-
79-
export default [ESM, CJS];
85+
export default [
86+
createBundleConfiguration(packageJSON.module, "esm"),
87+
createBundleConfiguration(packageJSON.browser, "esm"),
88+
createBundleConfiguration(packageJSON.main, "cjs")
89+
];

config/typescript/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"compilerOptions": {
3-
"outDir": "../../dist/components",
3+
"outDir": "../../dist/react-p5-wrapper",
44
"declaration": true,
55
"esModuleInterop": true,
66
"forceConsistentCasingInFileNames": true,

package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
{
22
"name": "react-p5-wrapper",
3-
"version": "4.0.1",
3+
"version": "4.1.0",
44
"description": "A wrapper component that allows you to utilise P5 sketches within React apps.",
55
"homepage": "https://github.com/P5-wrapper/react",
66
"license": "MIT",
77
"type": "module",
8-
"browser": "dist/components/index.js",
9-
"module": "dist/components/index.esm.js",
10-
"types": "dist/components/index.d.ts",
8+
"main": "dist/react-p5-wrapper/index.js",
9+
"browser": "dist/react-p5-wrapper/index.browser.js",
10+
"module": "dist/react-p5-wrapper/index.module.js",
11+
"types": "dist/react-p5-wrapper/index.d.ts",
1112
"files": [
12-
"dist/components/*"
13+
"dist/react-p5-wrapper/*"
1314
],
1415
"scripts": {
1516
"aui": "pnpm audit && pnpm update && pnpm install",

0 commit comments

Comments
 (0)