Skip to content

Commit

Permalink
various and sundry changes
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerbarker committed Dec 7, 2024
1 parent af44c96 commit 7f310b4
Show file tree
Hide file tree
Showing 15 changed files with 120 additions and 62 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
phoenix.d.ts

# Build directory
priv/
assets/

# direnv
.envrc
Expand Down
24 changes: 24 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# MIT License

Copyright (c) 2014 Chris McCord ([phoenix](https://github.com/phoenixframework/phoenix))
Copyright (c) 2018 Chris McCord ([phoenix_live_view](https://github.com/phoenixframework/phoenix_live_view))
Copyright (c) 2024 Tyler Barker - TypeScript ports

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
41 changes: 4 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,43 +1,10 @@
# phoenix_ts
# phx_ts

`phoenix_ts` is, first and foremost, an experiment and a learning exercise. It's an attempt to port the JS library bundled with the Phoenix web framework (as of v1.7.14) to TypeScript. Bundled and tested with [Bun](https://bun.sh).
`phx_ts` is an experiment and a learning exercise. It's an attempt to port the JS libraries bundled with the Phoenix & Phoenix LiveView package to TypeScript such that you can install them via Hex, update your `package.json` and get all the resulting types with no change in functionality. Bundled and tested with [Bun](https://bun.sh).

I'll be doing the same for `phoenix_live_view` in a separate repo at a later date. Great timing actually, as they just announced [a release candidate for v1.0](https://github.com/phoenixframework/phoenix_live_view/commit/d84b19c9761c8a665084a05178dfbd6de8acd6e8)!
I'll be doing the same for `phoenix_live_view` as the 2nd package in this monorepo soon. Both will be published to Hex independently of one another.

This effort isn't officially endorsed by the Phoenix team, just a bit of fun. That being said, I would love it if this or a similar effort was eventually integrated into the Phoenix project. Personally, I think it'd be easier to maintain, extend, and consume the framework if the JS clients were written in TypeScript and shipped types.

## TODO

- [x] Port the Mocha test suite to Bun test (3x speedup!)
- [x] Port util.js to TypeScript
- [x] Port constants.js to TypeScript
- [x] Port index.js to TypeScript
- [x] Port ajax.js to TypeScript
- [x] Port timer.js to TypeScript
- [x] Port serializer.js to TypeScript
- [x] Port push.js to TypeScript
- [x] Port longpoll.js to TypeScript
- [ ] Port presence.js to TypeScript
- [ ] Port channel.js to TypeScript
- [ ] Port socket.js to TypeScript
- [ ] Circle back to `any` types after everything is ported
- [ ] Circle back to `as` type assertions after everything is ported
- [ ] Reassess bundling targets e.g what do we need to support?
- [ ] Configure as Hex package (minimal Elixir scaffolding)
- [ ] Write installation documentation

## Staying Up to Date

Current Version: v1.7.14

I intend to release a corresponding version of this library for each Phoenix release from v1.7.12 onwards, even if the bundled JS does not change to assure compatibility.

I've written a script - to be run every day by a GH Action - which:

1. Checks the Phoenix repo for releases newer than our current version.
2. If a new release is found, it raises an issue on this repo with details of any changes to the Phoenix `assets/` repo if they are present.

See `phx-changes-check.ts`.
This isn't officially endorsed by the Phoenix team. I'm doing it because it's fun, and I think it'd be easier to maintain, extend, and consume the framework if the JS clients were written in TypeScript and shipped types.

## Development

Expand Down
2 changes: 1 addition & 1 deletion build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Bun from "bun";

const phoenixTsResult = await Bun.build({
entrypoints: ["./packages/phoenix_ts/src/index.ts"],
outdir: "./packages/phoenix_ts/priv/assets/js/phoenix",
outdir: "./packages/phoenix_ts/assets/js/phoenix",
minify: true,
target: "browser",
});
Expand Down
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
{
"name": "phx_ts",
"version": "0.0.0",
"workspaces": ["packages/*"],
"workspaces": [
"packages/*"
],
"devDependencies": {
"@microsoft/api-extractor": "^7.43.2",
"bun-types": "^1.1.38"
},
"scripts": {
"build:lib": "bun build.mjs",
"build:types": "cd ./packages/phoenix_ts && bunx tsc && bunx api-extractor run --local",
"build": "bun run build:lib && bun run build:types"
"build:phoenix_ts:types": "cd ./packages/phoenix_ts && bunx tsc && bunx api-extractor run --local",
"build": "bun run build:lib && bun run build:phoenix_ts:types"
}
}
23 changes: 23 additions & 0 deletions packages/phoenix_ts/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# MIT License

Copyright (c) 2014 Chris McCord ([phoenix](https://github.com/phoenixframework/phoenix))
Copyright (c) 2024 Tyler Barker - TypeScript port

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 changes: 23 additions & 0 deletions packages/phoenix_ts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# phoenix_ts

Current Version: v1.7.17

## TODO

- [x] Port the Mocha test suite to Bun test (3x speedup!)
- [x] Port util.js to TypeScript
- [x] Port constants.js to TypeScript
- [x] Port index.js to TypeScript
- [x] Port ajax.js to TypeScript
- [x] Port timer.js to TypeScript
- [x] Port serializer.js to TypeScript
- [x] Port push.js to TypeScript
- [x] Port longpoll.js to TypeScript
- [ ] Port presence.js to TypeScript
- [ ] Port channel.js to TypeScript
- [ ] Port socket.js to TypeScript
- [x] Configure as Hex package (minimal Elixir scaffolding)
- [ ] Circle back to `any` types after everything is ported
- [ ] Circle back to `as` type assertions after everything is ported
- [ ] Reassess bundling targets e.g what do we need to support?
- [ ] Write installation documentation
4 changes: 2 additions & 2 deletions packages/phoenix_ts/api-extractor.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": "../../api-extractor.base.json",
"projectFolder": ".",
"mainEntryPointFilePath": "<projectFolder>/priv/assets/js/phoenix/index.d.ts",
"mainEntryPointFilePath": "<projectFolder>/assets/js/phoenix/index.d.ts",
"dtsRollup": {
/**
* (REQUIRED) Whether to generate the .d.ts rollup file.
Expand All @@ -20,7 +20,7 @@
* SUPPORTED TOKENS: <projectFolder>, <packageName>, <unscopedPackageName>
* DEFAULT VALUE: "<projectFolder>/dist/<unscopedPackageName>.d.ts"
*/
"untrimmedFilePath": "<projectFolder>/priv/assets/js/phoenix/index.d.ts"
"untrimmedFilePath": "<projectFolder>/assets/js/phoenix/index.d.ts"

/**
* Specifies the output path for a .d.ts rollup file to be generated with trimming for an "alpha" release.
Expand Down
37 changes: 28 additions & 9 deletions packages/phoenix_ts/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,40 @@ defmodule PhoenixTS.MixProject do
use Mix.Project

@app :phoenix_ts
@version "1.7.14"
@version "1.7.17"

def project do
[
app: @app,
version: @version,
elixir: "~> 1.15",
description: "The unofficial TypeScript client for the Phoenix web framework.",
elixir: "~> 1.13",
deps: [],
package: [
name: "phoenix_ts",
files: ~w(mix.exs README.md priv),
licenses: ["MIT"],
links: %{"GitHub" => "https://github.com/tylerbarker/phx_ts"}
]
docs: docs(),
package: packages(),
description: """
The unofficial TypeScript client for the Phoenix web framework.
"""
]
end

defp docs() do
[
main: "readme",
name: "PhoenixTS",
source_ref: "v#{@version}",
canonical: "http://hexdocs.pm/phoenix_ts",
source_url: "https://github.com/tylerbarker/phx_ts",
extras: ["README.md"]
]
end

def package do
[
name: "phoenix_ts",
maintainers: ["Tyler Barker"],
licenses: ["MIT"],
links: %{"GitHub" => "https://github.com/tylerbarker/phx_ts"},
files: ~w(mix.exs lib assets README.md LICENSE.md)
]
end
end
8 changes: 4 additions & 4 deletions packages/phoenix_ts/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "phoenix_ts",
"version": "1.7.14",
"version": "1.7.17",
"description": "The unofficial TypeScript client for the Phoenix web framework.",
"license": "MIT",
"main": "./priv/assets/js/phoenix/index.js",
"module": "./priv/assets/js/phoenix/index.js",
"typings": "./priv/assets/js/phoenix/index.d.ts",
"main": "./assets/js/phoenix/index.js",
"module": "./assets/js/phoenix/index.js",
"typings": "./assets/js/phoenix/index.d.ts",
"type": "module",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/phoenix_ts/test/channel.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { afterEach, beforeAll, beforeEach, describe, expect, it } from "bun:test";

import sinon from "sinon";
import { Channel, Socket } from "../priv/assets/js/phoenix";
import { Channel, Socket } from "../assets/js/phoenix";

let channel, socket;

Expand Down
2 changes: 1 addition & 1 deletion packages/phoenix_ts/test/presence.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from "bun:test";

import { Presence } from "../priv/assets/js/phoenix";
import { Presence } from "../assets/js/phoenix";

const clone = (obj) => {
const cloned = JSON.parse(JSON.stringify(obj));
Expand Down
2 changes: 1 addition & 1 deletion packages/phoenix_ts/test/serializer.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from "bun:test";

import { Serializer } from "../priv/assets/js/phoenix";
import { Serializer } from "../assets/js/phoenix";

const exampleMsg = {
join_ref: "0",
Expand Down
2 changes: 1 addition & 1 deletion packages/phoenix_ts/test/socket.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import sinon from "sinon";
import { WebSocket, Server as WebSocketServer } from "mock-socket";
import { encode } from "./serializer";
import { Socket, LongPoll } from "../priv/assets/js/phoenix";
import { Socket, LongPoll } from "../assets/js/phoenix";

let socket;

Expand Down
2 changes: 1 addition & 1 deletion packages/phoenix_ts/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"extends": "../../base.jsonc",
"include": ["./src/**/*"],
"compilerOptions": {
"outDir": "priv/assets/js/phoenix"
"outDir": "assets/js/phoenix"
}
}

0 comments on commit 7f310b4

Please sign in to comment.