Skip to content

Commit

Permalink
Remove TypeScript (#971)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alberto Fernández-Capel authored Sep 6, 2023
1 parent 0826b81 commit 9f3aad7
Show file tree
Hide file tree
Showing 101 changed files with 1,620 additions and 2,472 deletions.
23 changes: 0 additions & 23 deletions .eslintrc

This file was deleted.

42 changes: 42 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
module.exports = {
env: {
browser: true,
es2021: true
},
extends: ["eslint:recommended"],
overrides: [
{
env: {
node: true
},
files: [".eslintrc.{js,cjs}"],
parserOptions: {
sourceType: "script"
}
}
],
parserOptions: {
ecmaVersion: "latest",
sourceType: "module"
},
rules: {
"comma-dangle": "error",
"curly": ["error", "multi-line"],
"getter-return": "off",
"no-console": "off",
"no-duplicate-imports": ["error"],
"no-multi-spaces": ["error", { "exceptions": { "VariableDeclarator": true }}],
"no-multiple-empty-lines": ["error", { "max": 2 }],
"no-self-assign": ["error", { "props": false }],
"no-trailing-spaces": ["error"],
"no-unused-vars": ["error", { argsIgnorePattern: "_*" }],
"no-useless-escape": "off",
"no-var": ["error"],
"prefer-const": ["error"],
"semi": ["error", "never"]
},
globals: {
test: true,
setup: true
}
}
18 changes: 5 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,39 +39,31 @@
"@playwright/test": "^1.28.0",
"@rollup/plugin-node-resolve": "13.1.3",
"@rollup/plugin-typescript": "^11.0.0",
"@types/multer": "^1.4.5",
"@typescript-eslint/eslint-plugin": "^5.50.0",
"@typescript-eslint/parser": "^5.50.0",
"@web/dev-server-esbuild": "^0.3.3",
"@web/test-runner": "^0.15.0",
"@web/test-runner-playwright": "^0.9.0",
"arg": "^5.0.1",
"body-parser": "^1.20.1",
"chai": "~4.3.4",
"eslint": "^8.13.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.0.0",
"express": "^4.18.2",
"multer": "^1.4.2",
"prettier": "2.6.2",
"rollup": "^2.35.1",
"ts-node": "^10.9.1",
"tslib": "^2.5.0",
"typescript": "^4.9.5"
"rollup": "^2.35.1"
},
"scripts": {
"clean": "rm -fr dist",
"clean:win": "rmdir /s /q dist",
"build": "tsc --noEmit false --declaration true --emitDeclarationOnly true --outDir dist/types && rollup -c",
"build:win": "tsc --noEmit false --declaration true --emitDeclarationOnly true --outDir dist/types & rollup -c",
"build": "rollup -c",
"build:win": "rollup -c",
"watch": "rollup -wc",
"start": "ts-node -O '{\"module\":\"commonjs\"}' src/tests/server.ts",
"start": "node src/tests/server.mjs",
"test": "yarn test:unit && yarn test:browser",
"test:browser": "playwright test",
"test:unit": "NODE_OPTIONS=--inspect web-test-runner",
"test:unit:win": "SET NODE_OPTIONS=--inspect & web-test-runner",
"release": "yarn build && npm publish",
"lint": "eslint . --ext .ts"
"lint": "eslint . --ext .js"
},
"engines": {
"node": ">= 14"
Expand Down
29 changes: 29 additions & 0 deletions playwright.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { devices } from "@playwright/test"

const config = {
projects: [
{
name: "chrome",
use: { ...devices["Desktop Chrome"] }
},
{
name: "firefox",
use: { ...devices["Desktop Firefox"] }
}
],
retries: 2,
testDir: "./src/tests/",
testMatch: /(functional|integration)\/.*_tests\.js/,
webServer: {
command: "yarn start",
url: "http://localhost:9000/src/tests/fixtures/test.js",
timeout: 120 * 1000,
// eslint-disable-next-line no-undef
reuseExistingServer: !process.env.CI
},
use: {
baseURL: "http://localhost:9000/"
}
}

export default config
28 changes: 0 additions & 28 deletions playwright.config.ts

This file was deleted.

8 changes: 2 additions & 6 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import resolve from "@rollup/plugin-node-resolve"
import typescript from "@rollup/plugin-typescript"

import { version } from "./package.json"
const year = new Date().getFullYear()
const banner = `/*!\nTurbo ${version}\nCopyright © ${year} 37signals LLC\n */`

export default [
{
input: "src/index.ts",
input: "src/index.js",
output: [
{
name: "Turbo",
Expand All @@ -21,10 +20,7 @@ export default [
banner
}
],
plugins: [
resolve(),
typescript()
],
plugins: [resolve()],
watch: {
include: "src/**"
}
Expand Down
32 changes: 9 additions & 23 deletions src/core/bardo.ts → src/core/bardo.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,12 @@
import { PermanentElementMap } from "./snapshot"

export interface BardoDelegate {
enteringBardo(currentPermanentElement: Element, newPermanentElement: Element): void
leavingBardo(currentPermanentElement: Element): void
}

export class Bardo {
readonly permanentElementMap: PermanentElementMap
readonly delegate: BardoDelegate

static async preservingPermanentElements(
delegate: BardoDelegate,
permanentElementMap: PermanentElementMap,
callback: () => void
) {
static async preservingPermanentElements(delegate, permanentElementMap, callback) {
const bardo = new this(delegate, permanentElementMap)
bardo.enter()
await callback()
bardo.leave()
}

constructor(delegate: BardoDelegate, permanentElementMap: PermanentElementMap) {
constructor(delegate, permanentElementMap) {
this.delegate = delegate
this.permanentElementMap = permanentElementMap
}
Expand All @@ -42,31 +28,31 @@ export class Bardo {
}
}

replaceNewPermanentElementWithPlaceholder(permanentElement: Element) {
replaceNewPermanentElementWithPlaceholder(permanentElement) {
const placeholder = createPlaceholderForPermanentElement(permanentElement)
permanentElement.replaceWith(placeholder)
}

replaceCurrentPermanentElementWithClone(permanentElement: Element) {
replaceCurrentPermanentElementWithClone(permanentElement) {
const clone = permanentElement.cloneNode(true)
permanentElement.replaceWith(clone)
}

replacePlaceholderWithPermanentElement(permanentElement: Element) {
replacePlaceholderWithPermanentElement(permanentElement) {
const placeholder = this.getPlaceholderById(permanentElement.id)
placeholder?.replaceWith(permanentElement)
}

getPlaceholderById(id: string) {
getPlaceholderById(id) {
return this.placeholders.find((element) => element.content == id)
}

get placeholders(): HTMLMetaElement[] {
return [...document.querySelectorAll<HTMLMetaElement>("meta[name=turbo-permanent-placeholder][content]")]
get placeholders() {
return [...document.querySelectorAll("meta[name=turbo-permanent-placeholder][content]")]
}
}

function createPlaceholderForPermanentElement(permanentElement: Element) {
function createPlaceholderForPermanentElement(permanentElement) {
const element = document.createElement("meta")
element.setAttribute("name", "turbo-permanent-placeholder")
element.setAttribute("content", permanentElement.id)
Expand Down
13 changes: 5 additions & 8 deletions src/core/cache.ts → src/core/cache.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { Session } from "./session"
import { setMetaContent } from "../util"

export class Cache {
readonly session: Session

constructor(session: Session) {
constructor(session) {
this.session = session
}

Expand All @@ -13,18 +10,18 @@ export class Cache {
}

resetCacheControl() {
this.setCacheControl("")
this.#setCacheControl("")
}

exemptPageFromCache() {
this.setCacheControl("no-cache")
this.#setCacheControl("no-cache")
}

exemptPageFromPreview() {
this.setCacheControl("no-preview")
this.#setCacheControl("no-preview")
}

private setCacheControl(value: string) {
#setCacheControl(value) {
setMetaContent("turbo-cache-control", value)
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { PageSnapshot } from "./page_snapshot"
import { Renderer } from "../renderer"
import { activateScriptElement } from "../../util"
import { Renderer } from "../renderer"

export class ErrorRenderer extends Renderer<HTMLBodyElement, PageSnapshot> {
static renderElement(currentElement: HTMLBodyElement, newElement: HTMLBodyElement) {
export class ErrorRenderer extends Renderer {
static renderElement(currentElement, newElement) {
const { documentElement, body } = document

documentElement.replaceChild(newElement, body)
Expand Down
Loading

4 comments on commit 9f3aad7

@ntsd
Copy link

@ntsd ntsd commented on 9f3aad7 Sep 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't wait for this tag and release.

@alii
Copy link

@alii alii commented on 9f3aad7 Sep 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

goodbye our beloved types, thank you for sharing your short but happy life with us

@altfoxie
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤡🤡🤡

@mybearworld
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea what Turbo is about but I know full well now what not to use

Please sign in to comment.