Skip to content

Update build script to handle bad inputs and update the contributor list. #215

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

Merged
merged 1 commit into from
Jan 22, 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ node_modules
dist
.DS_Store
package-lock.json
.idea
1 change: 1 addition & 0 deletions config/jest/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// noinspection JSUnusedGlobalSymbols
import { dirname, join } from "path";
import { fileURLToPath } from "url";

Expand Down
1 change: 1 addition & 0 deletions config/jest/jest.environment.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// noinspection JSUnusedGlobalSymbols
import Environment from "jest-environment-jsdom-global";
import { TextDecoder, TextEncoder } from "util";

Expand Down
51 changes: 41 additions & 10 deletions config/rollup/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// noinspection JSUnusedGlobalSymbols
import replace from "@rollup/plugin-replace";
import terser from "@rollup/plugin-terser";
import typescript from "@rollup/plugin-typescript";
import { dirname, join } from "path";
Expand All @@ -18,31 +20,60 @@ const plugins = [
typescript: typescriptEngine,
tsconfig: join(fileDirectory, "..", "typescript", "tsconfig.json")
}),
terser({
format: {
comments: false
replace({
preventAssignment: true,
values: {
"process.env.NODE_ENV": JSON.stringify("production")
}
}),
terser({
format: { comments: false }
})
];

/**
* Generate a valid rollup bundle configuration.
*
* @param {string} filename
* @param {string} format
*
* @returns {import("rollup").RollupOptions}
*/
function createBundleConfiguration(filename, format) {
/** @type {import("rollup").RollupOptions} */
const lowercaseFormat = format.toLowerCase();

if (![packageJSON.module, packageJSON.browser].includes(filename)) {
throw new Error(`Invalid filename provided. Received: ${filename}`);
}

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

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

if (lowercaseFormat === "esm" && filename !== packageJSON.module) {
throw new Error("An ESM bundle can only be created for the module bundle.");
}

return {
input,
plugins,
external,
input,
onwarn(warning) {
throw new Error(warning.message);
},
output: {
file: filename,
format,
sourcemap: true
},
onwarn: warning => {
throw new Error(warning.message);
}
plugins
};
}

const ESM = createBundleConfiguration(packageJSON.module, "esm");
const CJS = createBundleConfiguration(packageJSON.main, "cjs");
const CJS = createBundleConfiguration(packageJSON.browser, "cjs");

export default [ESM, CJS];
1 change: 1 addition & 0 deletions config/webpack/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// noinspection JSUnusedGlobalSymbols
import HtmlWebpackPlugin from "html-webpack-plugin";
import { dirname, join } from "path";
import { fileURLToPath } from "url";
Expand Down
21 changes: 16 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"homepage": "https://github.com/P5-wrapper/react",
"license": "MIT",
"type": "module",
"main": "dist/components/index.js",
"browser": "dist/components/index.js",
"module": "dist/components/index.esm.js",
"types": "dist/components/index.d.ts",
"files": [
Expand All @@ -21,7 +21,7 @@
"format:check": "pnpm prettier --check .",
"format": "pnpm prettier --write .",
"lint:fix": "pnpm lint --fix",
"lint": "eslint --config config/eslint/eslint.json src/ --ignore-path .gitignore",
"lint": "eslint --config config/eslint/eslint.json . --ignore-path .gitignore",
"prettier": "prettier --config config/prettier/prettier.json --ignore-path .gitignore",
"release": "pnpm build && gh-pages -d dist/demo && pnpm publish",
"start": "webpack serve --config config/webpack/webpack.config.js --mode development",
Expand All @@ -45,14 +45,23 @@
},
{
"name": "Andreas Wolf",
"email": "info@wolfandreas.com"
"email": "info@wolfandreas.com",
"url": "https://github.com/and-who"
},
{
"name": "Ivan Malyugin"
},
{
"name": "Benjamin Saphier",
"url": "https://github.com/bsaphier"
},
{
"name": "Mark Fuller",
"url": "https://github.com/MarkFuller1"
},
{
"name": "Nathan Manousos",
"url": "https://github.com/trafnar"
}
],
"repository": {
Expand All @@ -63,8 +72,6 @@
"url": "https://github.com/P5-wrapper/react/issues"
},
"dependencies": {
"@rollup/plugin-terser": "^0.3.0",
"@rollup/plugin-typescript": "^11.0.0",
"microdiff": "^1.3.1",
"p5": "^1.5.0"
},
Expand All @@ -77,6 +84,9 @@
"@babel/preset-env": "^7.20.2",
"@babel/preset-react": "^7.18.6",
"@babel/preset-typescript": "^7.18.6",
"@rollup/plugin-replace": "^5.0.2",
"@rollup/plugin-terser": "^0.3.0",
"@rollup/plugin-typescript": "^11.0.0",
"@testing-library/react": "^13.4.0",
"@trivago/prettier-plugin-sort-imports": "^4.0.0",
"@types/jest": "^29.2.3",
Expand All @@ -85,6 +95,7 @@
"@types/react-dom": "^18.0.9",
"@typescript-eslint/eslint-plugin": "^5.44.0",
"@typescript-eslint/parser": "^5.44.0",
"@vue/compiler-sfc": "3",
"babel-loader": "^9.1.0",
"canvas": "^2.10.2",
"css-loader": "^6.7.2",
Expand Down
Loading