From 74de8aa4b1407adbf122157b6fedb24d0b9f205a Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Fri, 8 Feb 2019 17:33:07 -0600 Subject: [PATCH] Port to TypeScript --- .blade.yml | 18 - .gitignore | 5 +- .npmignore | 1 + .ruby-version | 1 - .travis.yml | 6 +- {test/.vscode => .vscode}/launch.json | 5 +- .vscode/tasks.json | 36 + Gemfile | 11 - Gemfile.lock | 101 -- LICENSE | 20 - README.md | 21 +- bin/blade | 16 - bin/ci | 7 - bin/rackup | 16 - config.ru | 8 - dist/turbolinks.js | 6 - test/intern.json => intern.json | 6 +- package.json | 26 +- rollup.config.js | 46 + src/adapter.ts | 17 + src/browser_adapter.ts | 99 ++ src/controller.ts | 340 +++++ src/error_renderer.ts | 53 + src/globals.d.ts | 8 + src/head_details.ts | 113 ++ src/history.ts | 77 ++ src/http_request.ts | 141 +++ src/index.ts | 21 + src/location.ts | 97 ++ src/namespace.ts | 28 + src/progress_bar.ts | 115 ++ src/renderer.ts | 42 + src/script_warning.ts | 22 + src/scroll_manager.ts | 47 + src/snapshot.ts | 98 ++ src/snapshot_cache.ts | 54 + src/snapshot_renderer.ts | 177 +++ .../tests}/fixtures/additional_assets.html | 0 {test => src/tests}/fixtures/body_script.html | 0 .../tests}/fixtures/eval_false_script.html | 0 {test => src/tests}/fixtures/head_script.html | 0 {test => src/tests}/fixtures/navigation.html | 0 {test => src/tests}/fixtures/one.html | 0 .../tests}/fixtures/permanent_element.html | 0 {test => src/tests}/fixtures/rendering.html | 0 {test => src/tests}/fixtures/test.js | 0 .../tests}/fixtures/tracked_asset_change.html | 0 src/tests/fixtures/turbolinks.js | 1 + src/tests/fixtures/turbolinks.js.map | 1 + {test => src/tests}/fixtures/visit.html | 0 .../tests}/fixtures/visit_control_reload.html | 0 .../tests/helpers}/browser_test_case.ts | 0 .../tests/helpers}/intern_test_case.ts | 0 .../tests/helpers}/remote_channel.ts | 4 +- .../tests/helpers}/turbolinks_test_case.ts | 6 - src/tests/index.ts | 3 + .../suites => src/tests}/navigation_tests.ts | 4 +- {test/suites => src/tests}/rendering_tests.ts | 6 +- {test/suites => src/tests}/visit_tests.ts | 5 +- src/turbolinks/BANNER.js.erb | 4 - src/turbolinks/VERSION | 1 - src/turbolinks/browser_adapter.coffee | 60 - src/turbolinks/compatibility.coffee | 30 - src/turbolinks/controller.coffee | 244 ---- src/turbolinks/error_renderer.coffee | 27 - src/turbolinks/head_details.coffee | 68 - src/turbolinks/helpers.coffee | 74 -- src/turbolinks/history.coffee | 48 - src/turbolinks/http_request.coffee | 88 -- src/turbolinks/index.coffee | 22 - src/turbolinks/location.coffee | 70 -- src/turbolinks/progress_bar.coffee | 83 -- src/turbolinks/renderer.coffee | 28 - src/turbolinks/script_warning.coffee | 16 - src/turbolinks/scroll_manager.coffee | 28 - src/turbolinks/snapshot.coffee | 65 - src/turbolinks/snapshot_cache.coffee | 43 - src/turbolinks/snapshot_renderer.coffee | 104 -- src/turbolinks/start.coffee | 18 - src/turbolinks/view.coffee | 37 - src/turbolinks/visit.coffee | 162 --- src/types.ts | 7 + src/util.ts | 95 ++ src/view.ts | 54 + src/visit.ts | 270 ++++ test/.gitignore | 1 - test/environment.js | 1 - test/fixtures/turbolinks.js | 1 - test/package.json | 16 - test/tsconfig.json | 7 - tsconfig.json | 17 + test/yarn.lock => yarn.lock | 1117 +++++++++++------ 92 files changed, 2855 insertions(+), 1986 deletions(-) delete mode 100644 .blade.yml create mode 100644 .npmignore delete mode 100644 .ruby-version rename {test/.vscode => .vscode}/launch.json (56%) create mode 100644 .vscode/tasks.json delete mode 100644 Gemfile delete mode 100644 Gemfile.lock delete mode 100644 LICENSE delete mode 100755 bin/blade delete mode 100755 bin/ci delete mode 100755 bin/rackup delete mode 100644 config.ru delete mode 100644 dist/turbolinks.js rename test/intern.json => intern.json (73%) create mode 100644 rollup.config.js create mode 100644 src/adapter.ts create mode 100644 src/browser_adapter.ts create mode 100644 src/controller.ts create mode 100644 src/error_renderer.ts create mode 100644 src/globals.d.ts create mode 100644 src/head_details.ts create mode 100644 src/history.ts create mode 100644 src/http_request.ts create mode 100644 src/index.ts create mode 100644 src/location.ts create mode 100644 src/namespace.ts create mode 100644 src/progress_bar.ts create mode 100644 src/renderer.ts create mode 100644 src/script_warning.ts create mode 100644 src/scroll_manager.ts create mode 100644 src/snapshot.ts create mode 100644 src/snapshot_cache.ts create mode 100644 src/snapshot_renderer.ts rename {test => src/tests}/fixtures/additional_assets.html (100%) rename {test => src/tests}/fixtures/body_script.html (100%) rename {test => src/tests}/fixtures/eval_false_script.html (100%) rename {test => src/tests}/fixtures/head_script.html (100%) rename {test => src/tests}/fixtures/navigation.html (100%) rename {test => src/tests}/fixtures/one.html (100%) rename {test => src/tests}/fixtures/permanent_element.html (100%) rename {test => src/tests}/fixtures/rendering.html (100%) rename {test => src/tests}/fixtures/test.js (100%) rename {test => src/tests}/fixtures/tracked_asset_change.html (100%) create mode 120000 src/tests/fixtures/turbolinks.js create mode 120000 src/tests/fixtures/turbolinks.js.map rename {test => src/tests}/fixtures/visit.html (100%) rename {test => src/tests}/fixtures/visit_control_reload.html (100%) rename {test/lib => src/tests/helpers}/browser_test_case.ts (100%) rename {test/lib => src/tests/helpers}/intern_test_case.ts (100%) rename {test/lib => src/tests/helpers}/remote_channel.ts (89%) rename {test/lib => src/tests/helpers}/turbolinks_test_case.ts (96%) create mode 100644 src/tests/index.ts rename {test/suites => src/tests}/navigation_tests.ts (97%) rename {test/suites => src/tests}/rendering_tests.ts (97%) rename {test/suites => src/tests}/visit_tests.ts (92%) delete mode 100644 src/turbolinks/BANNER.js.erb delete mode 100644 src/turbolinks/VERSION delete mode 100644 src/turbolinks/browser_adapter.coffee delete mode 100644 src/turbolinks/compatibility.coffee delete mode 100644 src/turbolinks/controller.coffee delete mode 100644 src/turbolinks/error_renderer.coffee delete mode 100644 src/turbolinks/head_details.coffee delete mode 100644 src/turbolinks/helpers.coffee delete mode 100644 src/turbolinks/history.coffee delete mode 100644 src/turbolinks/http_request.coffee delete mode 100644 src/turbolinks/index.coffee delete mode 100644 src/turbolinks/location.coffee delete mode 100644 src/turbolinks/progress_bar.coffee delete mode 100644 src/turbolinks/renderer.coffee delete mode 100644 src/turbolinks/script_warning.coffee delete mode 100644 src/turbolinks/scroll_manager.coffee delete mode 100644 src/turbolinks/snapshot.coffee delete mode 100644 src/turbolinks/snapshot_cache.coffee delete mode 100644 src/turbolinks/snapshot_renderer.coffee delete mode 100644 src/turbolinks/start.coffee delete mode 100644 src/turbolinks/view.coffee delete mode 100644 src/turbolinks/visit.coffee create mode 100644 src/types.ts create mode 100644 src/util.ts create mode 100644 src/view.ts create mode 100644 src/visit.ts delete mode 100644 test/.gitignore delete mode 100644 test/environment.js delete mode 120000 test/fixtures/turbolinks.js delete mode 100644 test/package.json delete mode 100644 test/tsconfig.json create mode 100644 tsconfig.json rename test/yarn.lock => yarn.lock (54%) diff --git a/.blade.yml b/.blade.yml deleted file mode 100644 index 653cf2f0c..000000000 --- a/.blade.yml +++ /dev/null @@ -1,18 +0,0 @@ -load_paths: - - src - - test/src - - test/vendor - -logical_paths: - - replicant.js - - test.js - - test.css - -build: - logical_paths: - - turbolinks.js - path: dist - js_compressor: uglifier - -require: - - sprockets/export diff --git a/.gitignore b/.gitignore index ab9822168..e6a926968 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ -/tmp - +/dist +/node_modules +*.log diff --git a/.npmignore b/.npmignore new file mode 100644 index 000000000..16e470097 --- /dev/null +++ b/.npmignore @@ -0,0 +1 @@ +dist/tests/ diff --git a/.ruby-version b/.ruby-version deleted file mode 100644 index 3f684d2d9..000000000 --- a/.ruby-version +++ /dev/null @@ -1 +0,0 @@ -2.3.4 diff --git a/.travis.yml b/.travis.yml index 9a3b2359a..e45a2b266 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,11 @@ dist: trusty sudo: false cache: -- bundler - yarn -script: bin/ci +before_script: +- yarn install +- yarn build +script: yarn test addons: apt: sources: diff --git a/test/.vscode/launch.json b/.vscode/launch.json similarity index 56% rename from test/.vscode/launch.json rename to .vscode/launch.json index e2a986968..e710bda63 100644 --- a/test/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,10 +1,13 @@ { + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "type": "node", "request": "launch", - "name": "Run All Tests", + "name": "Turbolinks: Debug browser tests", "cwd": "${workspaceFolder}", "port": 9229, "outputCapture": "std", diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 000000000..75e1c77c9 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,36 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + { + "label": "Turbolinks: Build dist directory", + "type": "shell", + "command": "yarn build", + "group": { + "kind": "build", + "isDefault": true + }, + "problemMatcher": [ + "$tsc" + ] + }, + { + "label": "Turbolinks: Run tests", + "type": "shell", + "dependsOn": "Turbolinks: Build dist directory", + "command": "yarn test", + "group": { + "kind": "test", + "isDefault": true + } + }, + { + "label": "Turbolinks: Start dev server", + "type": "shell", + "dependsOn": "Turbolinks: Build dist directory", + "command": "yarn start", + "problemMatcher": [] + } + ] +} diff --git a/Gemfile b/Gemfile deleted file mode 100644 index bd26dacac..000000000 --- a/Gemfile +++ /dev/null @@ -1,11 +0,0 @@ -source 'https://rubygems.org' - -gem 'rake' -gem 'sprockets' -gem 'sprockets-export' -gem 'coffee-script' -gem 'coffee-script-source', '~> 1.9.1' -gem 'eco' -gem 'uglifier' - -gem 'blade', '~> 0.7.1' diff --git a/Gemfile.lock b/Gemfile.lock deleted file mode 100644 index 26e3b0594..000000000 --- a/Gemfile.lock +++ /dev/null @@ -1,101 +0,0 @@ -GEM - remote: https://rubygems.org/ - specs: - activesupport (5.1.4) - concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (~> 0.7) - minitest (~> 5.1) - tzinfo (~> 1.1) - addressable (2.5.2) - public_suffix (>= 2.0.2, < 4.0) - blade (0.7.1) - activesupport (>= 3.0.0) - blade-qunit_adapter (~> 2.0.1) - coffee-script - coffee-script-source - curses (~> 1.0.0) - eventmachine - faye - sprockets (>= 3.0) - thin (>= 1.6.0) - thor (>= 0.19.1) - useragent (~> 0.16.7) - blade-qunit_adapter (2.0.1) - coffee-script (2.4.1) - coffee-script-source - execjs - coffee-script-source (1.9.3) - concurrent-ruby (1.0.2) - cookiejar (0.3.3) - curses (1.0.2) - daemons (1.2.6) - eco (1.0.0) - coffee-script - eco-source - execjs - eco-source (1.1.0.rc.1) - em-http-request (1.1.5) - addressable (>= 2.3.4) - cookiejar (!= 0.3.1) - em-socksify (>= 0.3) - eventmachine (>= 1.0.3) - http_parser.rb (>= 0.6.0) - em-socksify (0.3.2) - eventmachine (>= 1.0.0.beta.4) - eventmachine (1.2.5) - execjs (2.6.0) - faye (1.2.4) - cookiejar (>= 0.3.0) - em-http-request (>= 0.3.0) - eventmachine (>= 0.12.0) - faye-websocket (>= 0.9.1) - multi_json (>= 1.0.0) - rack (>= 1.0.0) - websocket-driver (>= 0.5.1) - faye-websocket (0.10.7) - eventmachine (>= 0.12.0) - websocket-driver (>= 0.5.1) - http_parser.rb (0.6.0) - i18n (0.9.1) - concurrent-ruby (~> 1.0) - json (1.8.3) - minitest (5.11.1) - multi_json (1.12.2) - public_suffix (3.0.1) - rack (1.6.4) - rake (10.4.2) - sprockets (3.6.0) - concurrent-ruby (~> 1.0) - rack (> 1, < 3) - sprockets-export (1.0.0) - thin (1.7.2) - daemons (~> 1.0, >= 1.0.9) - eventmachine (~> 1.0, >= 1.0.4) - rack (>= 1, < 3) - thor (0.20.0) - thread_safe (0.3.6) - tzinfo (1.2.4) - thread_safe (~> 0.1) - uglifier (2.7.2) - execjs (>= 0.3.0) - json (>= 1.8.0) - useragent (0.16.8) - websocket-driver (0.7.0) - websocket-extensions (>= 0.1.0) - websocket-extensions (0.1.3) - -PLATFORMS - ruby - -DEPENDENCIES - blade (~> 0.7.1) - coffee-script - coffee-script-source (~> 1.9.1) - eco - rake - sprockets - sprockets-export - uglifier - -BUNDLED WITH - 1.16.1 diff --git a/LICENSE b/LICENSE deleted file mode 100644 index aa3fd084f..000000000 --- a/LICENSE +++ /dev/null @@ -1,20 +0,0 @@ -Copyright 2018 Basecamp, LLC - -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. diff --git a/README.md b/README.md index 8df598ed7..57456cc4e 100644 --- a/README.md +++ b/README.md @@ -17,8 +17,6 @@ Turbolinks works in all modern desktop and mobile browsers. It depends on the [H ## Installation -Include [`dist/turbolinks.js`](dist/turbolinks.js) in your application’s JavaScript bundle. - Turbolinks automatically initializes itself when loaded via a standalone `