Skip to content

Commit 6451715

Browse files
authored
Merge pull request #54 from SMAKSS/security/secure-randomness
fix(security): use unbiased cryptographic randomness
2 parents f42d8db + 5a980eb commit 6451715

42 files changed

Lines changed: 5597 additions & 2659 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.eslintignore‎

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

‎.eslintrc.json‎

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

‎.github/copilot-instructions.md‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Copilot Instructions
2+
3+
Follow AGENTS.md and the repository's existing patterns.
4+
5+
- Use pnpm 12.17.0 and the scripts declared in package.json.
6+
- Keep library source in src/ and regression tests with the existing test files.
7+
- Preserve ESM and CommonJS runtime exports and their matching TypeScript declarations.
8+
- Preserve the documented security defaults and Node.js runtime requirement.
9+
- Keep the Vite playground importing the workspace package, not private source files.
10+
- Update Readme.md when changing the public API or user-facing behavior.
11+
- Keep generated output in dist/; do not commit build artifacts or publish a release.
12+
13+
Helpful commands:
14+
- pnpm test
15+
- pnpm typecheck
16+
- pnpm lint
17+
- pnpm format:check
18+
- pnpm audit
19+
- pnpm run dev:playground
20+

‎.github/workflows/ci.yml‎

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
runs-on: ubuntu-latest
1010

1111
steps:
12-
- uses: actions/checkout@v3
12+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
1313
with:
1414
fetch-depth: 1
1515

@@ -18,45 +18,34 @@ jobs:
1818
echo "Head ref: ${{ github.head_ref }}"
1919
echo "Base ref: ${{ github.base_ref }}"
2020
21-
- name: Setup Node.js
22-
uses: actions/setup-node@v3
21+
- name: Setup pnpm, Node.js, and dependencies
22+
uses: pnpm/setup@fbda4c85fc2e1e08721cd8763afea8f48d60f024 # v3.0.0
2323
with:
24-
node-version: "18"
24+
runtime: node
25+
node-version-file: .nvmrc
26+
cache: true
27+
require-lockfile: true
2528

26-
- name: Cache dependencies
27-
uses: actions/cache@v3
28-
with:
29-
path: |
30-
**/node_modules
31-
key: ${{ runner.os }}-node-18-yarn-${{ hashFiles('**/yarn.lock') }}
32-
restore-keys: |
33-
${{ runner.os }}-node-18-yarn-
34-
35-
- name: Install dependencies
36-
run: yarn install
29+
- name: Run Tests
30+
run: pnpm run test
3731

3832
- name: Type check
39-
run: yarn typecheck
33+
run: pnpm run typecheck
4034

4135
- name: Check code quality
4236
run: |
43-
yarn lint
44-
yarn format:check
45-
yarn run --if-present generate
46-
47-
- name: Security Audit
48-
run: yarn audit --level moderate || true
49-
continue-on-error: true
37+
pnpm run lint
38+
pnpm run format:check
39+
pnpm run --if-present generate
5040
51-
- name: Security Audit Summary
52-
if: success() || failure()
53-
run: yarn audit --summary
41+
- name: Security audit
42+
run: pnpm audit
5443

5544
- name: Archive production artifacts
56-
uses: actions/upload-artifact@v3
45+
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
5746
with:
5847
name: build-artifacts
59-
path: ./build/
48+
path: ./dist/
6049

6150
- name: Error handling
6251
if: failure()

‎.github/workflows/npm-publish.yml‎

Lines changed: 23 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,34 @@
1-
name: "@smakss/react-scroll-direction"
1+
name: Release @smakss/random-string
22

33
on:
4-
release:
5-
types: [created]
4+
push:
5+
branches: [master]
66

77
jobs:
8-
build:
8+
release:
99
runs-on: ubuntu-latest
10-
steps:
11-
- uses: actions/checkout@v3
12-
- uses: actions/setup-node@v3
13-
with:
14-
node-version: 18
15-
- run: yarn
16-
- run: yarn generate
17-
- uses: actions/upload-artifact@v3
18-
with:
19-
name: built-package
20-
path: |
21-
./path-to-your-build-folder
22-
package.json
10+
permissions:
11+
contents: write
12+
issues: write
13+
pull-requests: write
2314

24-
publish-npm:
25-
needs: build
26-
runs-on: ubuntu-latest
2715
steps:
28-
- uses: actions/checkout@v3
29-
- uses: actions/download-artifact@v3
30-
with:
31-
name: built-package
32-
- uses: actions/setup-node@v3
16+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
3317
with:
34-
node-version: 18
35-
registry-url: https://registry.npmjs.org/
36-
scope: "@smakss"
37-
- run: yarn install
38-
- run: yarn generate
39-
- run: |
40-
if grep -q "beta" package.json; then
41-
echo "Publishing Beta to npm"
42-
npm publish --tag beta
43-
else
44-
echo "Publishing Release to npm"
45-
npm publish
46-
fi
47-
env:
48-
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
18+
fetch-depth: 0
4919

50-
publish-gpr:
51-
needs: build
52-
runs-on: ubuntu-latest
53-
steps:
54-
- uses: actions/checkout@v3
55-
- uses: actions/download-artifact@v3
20+
- uses: pnpm/setup@fbda4c85fc2e1e08721cd8763afea8f48d60f024 # v3.0.0
5621
with:
57-
name: built-package
58-
- uses: actions/setup-node@v3
59-
with:
60-
node-version: 18
61-
registry-url: https://npm.pkg.github.com/
62-
scope: "@smakss"
63-
- run: yarn install
64-
- run: yarn generate
65-
- run: |
66-
if grep -q "beta" package.json; then
67-
echo "Publishing Beta to GitHub Package Registry"
68-
npm publish --tag beta
69-
else
70-
echo "Publishing Release to GitHub Package Registry"
71-
npm publish
72-
fi
22+
runtime: node
23+
node-version-file: .nvmrc
24+
cache: true
25+
require-lockfile: true
26+
27+
- name: Build package
28+
run: pnpm run generate
29+
30+
- name: Run semantic release
31+
run: pnpm run release
7332
env:
74-
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
33+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
34+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
name: Publish @smakss/random-string to GitHub Packages
2+
3+
on:
4+
workflow_run:
5+
workflows: ['Release @smakss/random-string']
6+
types: [completed]
7+
branches: [master]
8+
9+
concurrency:
10+
group: github-packages-${{ github.event.workflow_run.head_sha }}
11+
cancel-in-progress: false
12+
13+
jobs:
14+
publish:
15+
if: github.event.workflow_run.conclusion == 'success'
16+
runs-on: ubuntu-latest
17+
permissions:
18+
contents: read
19+
packages: write
20+
21+
steps:
22+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
23+
with:
24+
ref: ${{ github.event.workflow_run.head_sha }}
25+
fetch-depth: 0
26+
27+
- name: Find semantic-release tag
28+
id: release
29+
env:
30+
RELEASE_SHA: ${{ github.event.workflow_run.head_sha }}
31+
run: |
32+
tag="$(git describe --tags --exact-match "$RELEASE_SHA" 2>/dev/null || true)"
33+
case "$tag" in
34+
v[0-9]*)
35+
echo "version=${tag#v}" >> "$GITHUB_OUTPUT"
36+
;;
37+
*)
38+
echo "version=" >> "$GITHUB_OUTPUT"
39+
;;
40+
esac
41+
42+
- name: Configure GitHub Packages registry
43+
if: steps.release.outputs.version != ''
44+
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
45+
with:
46+
node-version-file: .nvmrc
47+
registry-url: https://npm.pkg.github.com/
48+
scope: "@smakss"
49+
50+
- name: Setup pnpm and dependencies
51+
if: steps.release.outputs.version != ''
52+
uses: pnpm/setup@fbda4c85fc2e1e08721cd8763afea8f48d60f024 # v3.0.0
53+
with:
54+
node-version-file: false
55+
cache: true
56+
require-lockfile: true
57+
58+
- name: Set package version from release tag
59+
if: steps.release.outputs.version != ''
60+
env:
61+
RELEASE_VERSION: ${{ steps.release.outputs.version }}
62+
run: |
63+
node -e '
64+
const fs = require("node:fs");
65+
const packageJson = JSON.parse(fs.readFileSync("package.json", "utf8"));
66+
packageJson.version = process.env.RELEASE_VERSION;
67+
fs.writeFileSync("package.json", `${JSON.stringify(packageJson, null, 2)}\n`);
68+
'
69+
70+
- name: Build package
71+
if: steps.release.outputs.version != ''
72+
run: pnpm run generate
73+
74+
- name: Check if version is already published
75+
id: registry
76+
if: steps.release.outputs.version != ''
77+
env:
78+
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
79+
PACKAGE_NAME: "@smakss/random-string"
80+
RELEASE_VERSION: ${{ steps.release.outputs.version }}
81+
run: |
82+
if npm view "${PACKAGE_NAME}@${RELEASE_VERSION}" version --registry=https://npm.pkg.github.com/ >"$RUNNER_TEMP/npm-view.log" 2>&1; then
83+
echo "published=true" >> "$GITHUB_OUTPUT"
84+
elif grep -Eq 'E404|404 Not Found' "$RUNNER_TEMP/npm-view.log"; then
85+
echo "published=false" >> "$GITHUB_OUTPUT"
86+
else
87+
cat "$RUNNER_TEMP/npm-view.log" >&2
88+
exit 1
89+
fi
90+
91+
- name: Publish to GitHub Packages
92+
if: steps.release.outputs.version != '' && steps.registry.outputs.published != 'true'
93+
run: pnpm publish --no-git-checks --registry=https://npm.pkg.github.com/
94+
env:
95+
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

‎.husky/commit-msg‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/usr/bin/env sh
22
. "$(dirname -- "$0")/_/husky.sh"
33

4-
yarn commitlint --edit ${1}
4+
pnpm exec commitlint --edit "${1}"

‎.husky/pre-commit‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/usr/bin/env sh
22
. "$(dirname -- "$0")/_/husky.sh"
33

4-
yarn lint-staged
4+
pnpm exec lint-staged

‎.nvmrc‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
26

‎.oxfmtrc.json‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"$schema": "./node_modules/oxfmt/configuration_schema.json",
3+
"ignorePatterns": [
4+
".cache",
5+
".shadowenv.d",
6+
".vscode",
7+
"build",
8+
"dist",
9+
"coverage",
10+
"node_modules",
11+
"public",
12+
".github",
13+
"tmp",
14+
"*.yml",
15+
"pnpm-lock.yaml"
16+
],
17+
"singleQuote": true,
18+
"printWidth": 80,
19+
"tabWidth": 2,
20+
"trailingComma": "none",
21+
"semi": true
22+
}

0 commit comments

Comments
 (0)