Skip to content

Commit

Permalink
Update package.json (#91)
Browse files Browse the repository at this point in the history
* Update package.json

I copied part of redux's tsup.config.ts, package.json, and also copied the scripts
from https://github.com/thoughtbot/belt. After reading https://blog.isquaredsoftware.com/2023/08/esm-modernization-lessons/
the last thing I want to do is do this myself.

* Prettier fix

* Lint fix
  • Loading branch information
jho406 authored Jul 14, 2024
1 parent f5bc910 commit fa3175a
Show file tree
Hide file tree
Showing 18 changed files with 748 additions and 699 deletions.
18 changes: 7 additions & 11 deletions superglue/.babelrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,14 @@ module.exports = {
plugins: [],
presets: [
[
"@babel/preset-env",
'@babel/preset-env',
{
useBuiltIns: "entry",
corejs: "2",
useBuiltIns: 'entry',
corejs: '2',
loose: true,
}
],
[
"@babel/preset-react"
],
[
"@babel/preset-typescript"
},
],
['@babel/preset-react'],
['@babel/preset-typescript'],
],
};
}
3 changes: 3 additions & 0 deletions superglue/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,6 @@ typings/
dist/

package-lock.json

coverage/
todo.txt
6 changes: 6 additions & 0 deletions superglue/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Ignore artifacts:
dist
coverage

# Ignore all HTML files:
**/*.html
39 changes: 18 additions & 21 deletions superglue/lib/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ function pageToInitialState(key: string, page: VisitResponse) {
const nextPage: Page = {
...page,
pageKey: key, //TODO remove this
savedAt: Date.now()
savedAt: Date.now(),
}

return {
pages: { [key]: nextPage},
pages: { [key]: nextPage },
...slices,
}
}
Expand All @@ -70,7 +70,12 @@ function start({
baseUrl = config.baseUrl,
maxPages = config.maxPages,
path,
}: {initialPage: VisitResponse, baseUrl: string, maxPages?: number, path: string}) {
}: {
initialPage: VisitResponse
baseUrl: string
maxPages?: number
path: string
}) {
const initialPageKey = urlToPageKey(parse(path).href)
const { csrfToken } = initialPage
const location = parse(path)
Expand All @@ -97,32 +102,25 @@ function start({
}
}

class NotImplementedError extends Error {
constructor(message: string) {
super(message)
this.name = this.constructor.name
}
}

interface Props {
initialPage: VisitResponse
baseUrl: string
path: string
appEl: HTMLElement
}

type ConnectedMapping = Record<
string,
ConnectedComponent<React.ComponentType, PageOwnProps>
>
string,
ConnectedComponent<React.ComponentType, PageOwnProps>
>

export abstract class ApplicationBase extends React.Component<Props> {
public hasWindow: boolean
public navigatorRef: React.RefObject<Nav>
public initialPageKey: string
public store: SuperglueStore
public history: History
public connectedMapping: ConnectedMapping
public connectedMapping: ConnectedMapping
public ujsHandlers: Handlers
public visit: Visit
public remote: Remote
Expand Down Expand Up @@ -176,12 +174,11 @@ export abstract class ApplicationBase extends React.Component<Props> {
this.remote = remote
}

visitAndRemote(
abstract visitAndRemote(
// eslint-disable-next-line
navigatorRef: React.RefObject<Nav>, store: SuperglueStore
): { visit: Visit; remote: Remote } {
throw new NotImplementedError('Implement this')
}
navigatorRef: React.RefObject<Nav>,
store: SuperglueStore
): { visit: Visit; remote: Remote }

componentDidMount(): void {
const { appEl } = this.props
Expand All @@ -207,7 +204,7 @@ export abstract class ApplicationBase extends React.Component<Props> {
}

abstract buildStore(
initialState: {pages: AllPages, [key: string]: JSONValue},
initialState: { pages: AllPages; [key: string]: JSONValue },
reducer: typeof rootReducer
): SuperglueStore

Expand Down
52 changes: 34 additions & 18 deletions superglue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,55 @@
"version": "0.53.4",
"description": "Use a vanilla Rails with React and Redux",
"scripts": {
"test": "vitest --config ./vitest.config.ts",
"lint": "eslint 'lib/**/*.{js,ts,tsx}'",
"clean": "rm -rf ./dist",
"copy:package": "cat ./package.json | jq 'del(.scripts)' > dist/package.json",
"copy:readme": "cp ../README.md dist/",
"build": "npm run clean && npm run build:js && npm run copy:package && npm run copy:readme",
"build:js": "babel lib --out-dir dist --extensions \".ts,.tsx\"",
"type-check": "tsc --noEmit",
"type-check:watch": "npm run type-check -- --watch",
"prepublishOnly": "npm run build"
"build": "tsup",
"dev": "tsup --watch",
"clean": "rm -rf dist",
"lint": "run-p lint:eslint lint:types lint:prettier",
"lint:eslint": "eslint --max-warnings=0 --ext js,jsx,ts,tsx ./lib",
"lint:prettier": "prettier --check '**/*' --ignore-unknown",
"lint:types": "tsc",
"fix:prettier": "prettier --write '**/*' --ignore-unknown",
"test": "vitest",
"test:run": "vitest run",
"test:cov": "vitest --coverage",
"test:all": "npm lint && npm test:run",
"pub:beta": "npm build && npm publish --tag beta",
"pub:release": "npm build && npm publish"
},
"repository": {
"type": "git",
"url": "git+https://github.com/thoughtbot/superglue.git"
},
"author": "Johny Ho",
"main": "dist/cjs/superglue.cjs",
"module": "dist/superglue.mjs",
"types": "dist/superglue.d.mts",
"exports": {
"./package.json": "./package.json",
".": {
"types": "./dist/superglue.d.mts",
"import": "./dist/superglue.mjs",
"default": "./dist/cjs/superglue.cjs"
},
"./action_creators": {
"types": "./dist/action_creators.d.mts",
"import": "./dist/action_creators.mjs",
"default": "./dist/cjs/action_creators.cjs"
}
},
"license": "MIT",
"bugs": {
"url": "https://github.com/thoughtbot/superglue/issues"
},
"homepage": "https://github.com/thoughtbot/superglue#readme",
"devDependencies": {
"@babel/cli": "^7.14.3",
"@babel/core": "^7.14.3",
"@babel/preset-env": "^7.14.4",
"@babel/preset-react": "^7.13.13",
"@babel/preset-typescript": "^7.24.6",
"@reduxjs/toolkit": "^2.2.5",
"@types/url-parse": "^1.4.11",
"@typescript-eslint/eslint-plugin": "^7.15.0",
"@typescript-eslint/parser": "^7.15.0",
"@vitejs/plugin-react": "^4.3.1",
"core-js": "^2.6.12",
"@vitest/coverage-v8": "^2.0.2",
"abortcontroller-polyfill": "^1.7.3",
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.6",
"eslint": "^8.57.0",
Expand All @@ -44,15 +60,16 @@
"fetch-mock": "^9.11.0",
"jsdom": "^24.1.0",
"node-fetch": "^2.6.1",
"npm-run-all": "^4.1.5",
"prettier": "^2.3.1",
"prettier-eslint": "^16.3.0",
"prop-types": "^15.7.2",
"react": "^16.4.0",
"react-dom": "^16.4.0",
"react-redux": "^7.2.4",
"redux": "^5.0.1",
"redux-mock-store": "^1.5.4",
"redux-thunk": "^3.1.0",
"tsup": "^8.1.0",
"typescript": "^5.5.3",
"vitest": "^2.0.2"
},
Expand All @@ -63,7 +80,6 @@
"redux-thunk": ">=2.3"
},
"dependencies": {
"abortcontroller-polyfill": "^1.7.3",
"history": "^5.3.0",
"url-parse": "^1.5.1"
}
Expand Down
Loading

0 comments on commit fa3175a

Please sign in to comment.