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

feat: added types for react-hyper-js #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
29 changes: 27 additions & 2 deletions build.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const esbuild = require("esbuild");
const fs = require("fs");
const path = require("path");

const sharedConfig = {
entryPoints: ["./src/Index.bs.js"], // Input source file
Expand All @@ -9,23 +11,43 @@ const sharedConfig = {
},
external: ["react", "react-dom"], // External dependencies
plugins: [],
sourcemap: true,
};

const copyTypeDefinitions = () => {
const typeDefSource = path.join(__dirname, "src/index.d.ts");
const typeDefDest = path.join(__dirname, "dist/index.d.ts");

if (fs.existsSync(typeDefSource)) {
fs.copyFileSync(typeDefSource, typeDefDest);
console.log("✓ Type definitions copied to dist");
} else {
console.warn(
"⚠ Warning: Type definitions file not found at src/index.d.ts"
);
}
};

const build = async (options) => {
try {
console.log(`Building for format: ${options.format.toUpperCase()}`);
await esbuild.build(options);
console.log(`Build successful: ${options.outfile}`);
console.log(`Build successful: ${options.outfile}`);
} catch (error) {
console.error(
`Build failed for format: ${options.format.toUpperCase()}`,
`Build failed for format: ${options.format.toUpperCase()}`,
error
);
process.exit(1);
}
};

const runBuilds = async () => {
// Ensure the dist folder exists
if (!fs.existsSync("dist")) {
fs.mkdirSync("dist", { recursive: true });
}

// Build for ESM with desired .mjs output
await build({
...sharedConfig,
Expand All @@ -39,6 +61,9 @@ const runBuilds = async () => {
outfile: "dist/index.js", // Explicitly set output filename
format: "cjs",
});

// Copy type definitions to dist
copyTypeDefinitions();
};

runBuilds();
Empty file added dist/index.d.ts
Empty file.
27 changes: 2 additions & 25 deletions dist/index.js

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions dist/index.js.map

Large diffs are not rendered by default.

27 changes: 2 additions & 25 deletions dist/index.mjs

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions dist/index.mjs.map

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
"exports": {
".": {
"import": "./dist/index.mjs",
"require": "./dist/index.js"
"require": "./dist/index.js",
"types": "./dist/index.d.ts"
}
},
"types": "dist/index.d.ts",
"files": [
"dist/",
"README.md",
Expand All @@ -32,9 +34,7 @@
},
"scripts": {
"start": "esbuild src/Index.bs.js --bundle --outfile=dist/index.js --servedir=dist",
"build": "npm run build:js && npm run build:es",
"build:js": "esbuild src/Index.bs.js --bundle --outfile=dist/index.js --minify",
"build:es": "esbuild src/Index.bs.js --bundle --format=esm --outfile=dist/index.mjs --minify",
"build": "node build.js",
"re:build": "rescript",
"re:start": "rescript build -w",
"re:format": "rescript format -all",
Expand Down
4 changes: 2 additions & 2 deletions src/components/Elements.res
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
@react.component
let make = (~children, ~stripe: Promise.t<OrcaJs.switchInstance>, ~options: JSON.t) => {
let make = (~children, ~hyper: Promise.t<OrcaJs.switchInstance>, ~options: JSON.t) => {
let elementOptions = options->Context.elementsOptionObjMapper
let (switchState, setSwitchState) = React.useState(() => Context.defaultSwitchContext)
let (elementsState, setElementsState) = React.useState(() => Context.defaultElementsContext)

React.useEffect0(() => {
stripe
hyper
->(Js.Promise.then_((switchInstance: OrcaJs.switchInstance) => {
let orcaElementsConfig = switchInstance.elements(options)
let newElemValues: Context.elementsType = {
Expand Down
Loading
Loading