Skip to content
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
31 changes: 0 additions & 31 deletions .babelrc

This file was deleted.

3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
DEBUG="false"
WATCH="false"
BUILD="production"
23 changes: 23 additions & 0 deletions .github/actions/dependencies/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Install dependencies

runs:
using: "composite"

steps:
- name: Get pnpm store directory
id: pnpm-cache
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT

- name: Setup dependency cache
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
with:
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-

- name: Install dependencies
shell: bash
run: BUILD=production pnpm run setup
22 changes: 22 additions & 0 deletions .github/actions/environment/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Setup environment

inputs:
GITHUB_AUTH_TOKEN:
required: true
description: 'Github Access Token used for Github NPM registry'

runs:
using: "composite"

steps:
- name: Setup pnpm
uses: pnpm/action-setup@e9540b3eafaf84907c087a645d3258bfaa861427 # v3.0.0
with:
version: 8.x
run_install: false

- name: Setup node
uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0
with:
node-version-file: '.nvmrc'
cache: 'pnpm'
25 changes: 20 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
name: CI

on: [push, pull_request]

permissions:
contents: read

jobs:

build:
name: Build & Test
runs-on: ubuntu-latest
Expand All @@ -11,9 +15,20 @@ jobs:
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
persist-credentials: false
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0

- name: Setup environment
uses: ./.github/actions/environment

- name: Create .env file
uses: SpicyPizza/create-envfile@ace6d4f5d7802b600276c23ca417e669f1a06f6f # v2.0
with:
node-version: '18.x'
- run: npm ci
- run: npm run transpile
- run: npm run test
envkey_BUILD: production
envkey_DEBUG: false
envkey_WATCH: false
file_name: .env

- name: Install dependencies
uses: ./.github/actions/dependencies

- name: Run Tests
run: pnpm --filter=@hcaptcha-react/lib run test:unit
30 changes: 23 additions & 7 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
name: Publish NPM

on:
workflow_dispatch:
release:
types: [ created ]

permissions:
contents: read

jobs:
build:
name: Build & Test & Publish
Expand All @@ -14,13 +17,26 @@ jobs:
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
persist-credentials: false
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0

- name: Setup environment
uses: ./.github/actions/environment

- name: Create .env file
uses: SpicyPizza/create-envfile@ace6d4f5d7802b600276c23ca417e669f1a06f6f # v2.0
with:
node-version: '18.x'
registry-url: 'https://registry.npmjs.org'
- run: npm ci
- run: npm run transpile
- run: npm run test
- run: npm publish
envkey_BUILD: production
envkey_DEBUG: false
envkey_WATCH: false
file_name: .env

- name: Install dependencies
uses: ./.github/actions/dependencies

- name: Run Tests
run: pnpm --filter=@hcaptcha-react/lib run test:unit

- name: Publish package
shell: bash
run: pnpm publish --no-git-checks --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
63 changes: 58 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,63 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

*.code-workspace
*.sublime-workspace
.vscode/
.idea/
# TypeScript cache
*.tsbuildinfo

.DS_Store
# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Output of 'npm pack'
*.tgz

# dotenv environment variable files
.env
dist

# MacOS
.DS_Store
**/.DS_Store

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# IDEs
*.code-workspace
*.sublime-workspace
.vscode/
.idea/
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
auto-install-peers=false
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v24.12.0
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ import { default as RenamedCaptcha } from '../utils/captcha';
You can also use the Provider/Hook pattern:

```js
import { HCaptchaProvider, useHCaptcha } from '@hcaptcha/react-hcaptcha/hooks';
import { HCaptchaProvider, useHCaptcha } from '@hcaptcha/react-hcaptcha';

function App() {
return (
Expand Down Expand Up @@ -269,9 +269,13 @@ This will be rare, but could happen in the event you are testing offline, or hav

#### Scripts

* `npm run start` - will start the demo app with hot reload
* `npm run test` - will test the library: unit tests
* `npm run build` - will build the production version
* `pnpm run start` - will start the demo app with hot reload
* `pnpm run test` - will test the library: unit tests
* `pnpm --filter @hcaptcha-react/lib run combile:build` - will build the production version


#### Environment Variables
Create a `.env` in the root directory, see `.env.example` for what variables can be set. If not file is found, variables will fallback to a production configuration.


#### Publishing
Expand Down
13 changes: 13 additions & 0 deletions demo/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"jsc": {
"parser": {
"jsx": true,
"syntax": "ecmascript"
},
"transform": {
"react": {
"runtime": "automatic"
}
}
}
}
1 change: 0 additions & 1 deletion demo/app/components/index.js

This file was deleted.

4 changes: 0 additions & 4 deletions demo/app/examples/index.js

This file was deleted.

10 changes: 0 additions & 10 deletions demo/index.js

This file was deleted.

22 changes: 22 additions & 0 deletions demo/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "@hcaptcha-react/demo",
"version": "1.0.0",
"type": "module",
"main": "src/index.jsx",
"scripts": {
"start": "webpack serve -c ./webpack.config.js"
},
"dependencies": {
"@hcaptcha-react/lib": "workspace:^",
"react": "^19.0.0",
"react-dom": "^19.0.0"
},
"devDependencies": {
"@swc/core": "^1.15.8",
"html-webpack-plugin": "^5.6.5",
"swc-loader": "^0.2.6",
"webpack": "^5.104.1",
"webpack-cli": "^6.0.1",
"webpack-dev-server": "^5.2.2"
}
}
5 changes: 3 additions & 2 deletions demo/app/App.jsx → demo/src/app/App.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@

import React, { useEffect, useState } from 'react';

import { AsyncExample, ClassExample, FrameExample, HookExample } from './examples';
import { CustomFrame } from './components';
import { AsyncExample, ClassExample, FrameExample, HookExample } from './examples/index.js';
import { CustomFrame } from './components/index.js';

export function App() {
const [frame, setFrame] = useState(null);
Expand Down
1 change: 1 addition & 0 deletions demo/src/app/components/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { CustomFrame } from './CustomFrame.jsx';
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useRef, useEffect } from 'react';

import HCaptcha from '../../../src/index.js';
import HCaptcha from '@hcaptcha-react/lib';

export function AsyncExample() {
const captchaRef = useRef();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

import HCaptcha from '../../../src/index.js';
import HCaptcha from '@hcaptcha-react/lib';


export class ClassExample extends React.Component {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useRef } from 'react';

import HCaptcha from '../../../src/index.js';
import HCaptcha from '@hcaptcha-react/lib';

export function FrameExample({ document }) {
const captchaRef = useRef();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState } from 'react';
import { HCaptchaProvider, useHCaptcha } from '../../../src/hooks/index.jsx';
import { HCaptchaProvider, useHCaptcha } from '@hcaptcha-react/lib';

function Form() {
const [email, setEmail] = useState("");
Expand Down
4 changes: 4 additions & 0 deletions demo/src/app/examples/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export { AsyncExample } from './AsyncExample.jsx';
export { ClassExample } from './ClassExample.jsx';
export { FrameExample } from './FrameExample.jsx';
export { HookExample } from './HookExample.jsx';
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions demo/src/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import React from 'react';
import { createRoot } from 'react-dom/client';

import { App } from './app/App.jsx';

const root = createRoot(document.getElementById('app'))
root.render(<App />);
Loading
Loading