Skip to content

Commit c640f85

Browse files
committed
feat: 3.0: Add ScriptLoader component and modernize development tooling with tsup, Vitest, pnpm, and gh actions.
1 parent bd56848 commit c640f85

File tree

18 files changed

+3379
-1739
lines changed

18 files changed

+3379
-1739
lines changed

.github/workflows/ci.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [master, main]
6+
pull_request:
7+
branches: [master, main]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- name: Install pnpm
17+
uses: pnpm/action-setup@v3
18+
with:
19+
version: 9
20+
21+
- name: Use Node.js
22+
uses: actions/setup-node@v4
23+
with:
24+
node-version: '20'
25+
cache: 'pnpm'
26+
27+
- name: Install dependencies
28+
run: pnpm install --frozen-lockfile
29+
30+
- name: Lint
31+
run: pnpm lint
32+
33+
- name: Test
34+
run: pnpm test
35+
36+
- name: Build
37+
run: pnpm build

circle.yml

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

dist/index.d.mts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import type { ReactNode } from 'react';
2+
3+
interface Props {
4+
src: string;
5+
onLoad: () => void;
6+
}
7+
declare function ScriptLoader({ src, onLoad }: Props): ReactNode;
8+
9+
export { ScriptLoader as default };

dist/index.d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import type { ReactNode } from 'react';
2+
3+
interface Props {
4+
src: string;
5+
onLoad: () => void;
6+
}
7+
declare function ScriptLoader({ src, onLoad }: Props): ReactNode;
8+
9+
export { ScriptLoader as default };

dist/index.js

Lines changed: 42 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.mjs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// src/index.tsx
2+
import { useEffect } from "react";
3+
import { jsx } from "react/jsx-runtime";
4+
function ScriptLoader({ src, onLoad }) {
5+
useEffect(() => {
6+
const scripts = Array.from(document.querySelectorAll("script"));
7+
if (scripts.find((script2) => script2.src === src)) {
8+
onLoad();
9+
return;
10+
}
11+
const script = document.createElement("script");
12+
script.src = src;
13+
script.onload = () => onLoad();
14+
document.body.appendChild(script);
15+
}, [src, onLoad]);
16+
return /* @__PURE__ */ jsx("span", { style: { display: "none" }, "data-purpose": "Dummy element created by react-isomorphic-scriptloader" });
17+
}
18+
export {
19+
ScriptLoader as default
20+
};
21+
//# sourceMappingURL=index.mjs.map

dist/index.mjs.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

eslint.config.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const js = require('@eslint/js');
2+
const globals = require('globals');
3+
const tseslint = require('typescript-eslint');
4+
5+
module.exports = tseslint.config(
6+
{ ignores: ['dist'] },
7+
{
8+
extends: [js.configs.recommended, ...tseslint.configs.recommended],
9+
files: ['**/*.{ts,tsx}'],
10+
languageOptions: {
11+
ecmaVersion: 2020,
12+
globals: globals.browser,
13+
},
14+
}
15+
);

package.json

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,25 @@
22
"name": "react-isomorphic-scriptloader",
33
"version": "2.0.0",
44
"description": "Load scripts with ease",
5-
"main": "lib/index.js",
6-
"typings": "lib/typings/index.d.ts",
7-
"module": "lib/esm/index.js",
5+
"main": "dist/index.js",
6+
"module": "dist/index.mjs",
7+
"types": "dist/index.d.ts",
8+
"exports": {
9+
".": {
10+
"import": "./dist/index.mjs",
11+
"require": "./dist/index.js",
12+
"types": "./dist/index.d.ts"
13+
}
14+
},
815
"files": [
9-
"lib/*"
16+
"dist"
1017
],
1118
"scripts": {
12-
"lint": "(tsc -p . --noEmit) && (eslint . --ext .ts --ext .tsx) && (prettier -l src/*.tsx)",
13-
"prepare": "yarn build:clean ; yarn build:esm ; yarn build:cjs ; yarn build:typings",
14-
"build:esm": "tsc --module es2015 --target es2018 --outDir lib/esm",
15-
"build:cjs": "tsc --module commonjs --target es5 --outDir lib/cjs",
16-
"build:clean": "rm -rf lib",
17-
"build:typings": "tsc --declaration --outDir lib/typings --emitDeclarationOnly"
19+
"build": "tsup",
20+
"test": "vitest run",
21+
"test:watch": "vitest",
22+
"lint": "eslint .",
23+
"format": "prettier --write ."
1824
},
1925
"repository": {
2026
"type": "git",
@@ -30,28 +36,25 @@
3036
"bugs": {
3137
"url": "https://github.com/archcorsair/react-isomorphic-scriptloader/issues"
3238
},
33-
"dependencies": {},
34-
"devDependencies": {
35-
"@types/react": "^16.9.41",
36-
"@typescript-eslint/eslint-plugin": "^3.5.0",
37-
"@typescript-eslint/parser": "^3.5.0",
38-
"eslint": "7.2.0",
39-
"eslint-config-airbnb": "18.2.0",
40-
"eslint-config-prettier": "^6.11.0",
41-
"eslint-import-resolver-typescript": "^2.0.0",
42-
"eslint-plugin-import": "^2.21.2",
43-
"eslint-plugin-jsx-a11y": "^6.3.0",
44-
"eslint-plugin-prettier": "^3.1.4",
45-
"eslint-plugin-react": "^7.20.0",
46-
"eslint-plugin-react-hooks": "4.0.0",
47-
"jasmine-fix": "^1.3.1",
48-
"prettier": "^2.0.5",
49-
"typescript": "^3.9.6"
50-
},
5139
"peerDependencies": {
52-
"react": "*"
40+
"react": ">=16.8.0"
41+
},
42+
"devDependencies": {
43+
"@testing-library/react": "^16.3.0",
44+
"@types/react": "^19.2.7",
45+
"@types/react-dom": "^19.2.3",
46+
"eslint": "^9.0.0",
47+
"globals": "^15.0.0",
48+
"jsdom": "^24.0.0",
49+
"prettier": "^3.0.0",
50+
"react": "^19.2.1",
51+
"react-dom": "^19.2.1",
52+
"tsup": "^8.0.0",
53+
"typescript": "^5.9.3",
54+
"typescript-eslint": "^7.0.0",
55+
"vitest": "^4.0.15"
5356
},
5457
"engines": {
55-
"node": ">= 8"
58+
"node": ">=18"
5659
}
5760
}

0 commit comments

Comments
 (0)