Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use esbuild instead of webpacker #1957

Merged
merged 24 commits into from
Apr 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
73c7049
first commit to migrate to esbuild. jquery does not work right
johrstrom Apr 13, 2022
9dc8c01
sprockets can navigate that far away for images?
johrstrom Apr 14, 2022
4d9d0c4
dont commit build dir
johrstrom Apr 15, 2022
d189f03
and be sure to ignore it too
johrstrom Apr 15, 2022
b806053
this actually works
johrstrom Apr 15, 2022
4e23daf
get datatables to work
johrstrom Apr 19, 2022
8d92797
tests will now precompile assets
johrstrom Apr 19, 2022
b5ee106
fix this test
johrstrom Apr 19, 2022
46c72a1
maybe fix e2e tests
johrstrom Apr 19, 2022
d75f3f8
window works now
johrstrom Apr 22, 2022
f8a0a5a
fix data_table.js and rm unused render function
johrstrom Apr 22, 2022
2ec3565
add lodash to fileops
johrstrom Apr 22, 2022
86c2846
fix delete test
johrstrom Apr 22, 2022
8d693c1
fixup bin/setup
johrstrom Apr 22, 2022
e675373
fixup test rake
johrstrom Apr 22, 2022
c23884f
editor needs csrf token
johrstrom Apr 22, 2022
ac7a8ba
add helper for recomiling assets
johrstrom Apr 22, 2022
96e08c5
Merge branch 'dev/esbuild' of github.com:OSC/ondemand into dev/esbuild
johrstrom Apr 22, 2022
920f2c1
tests should clobber just to be safe
johrstrom Apr 22, 2022
450a5e1
this stopped working so move it to test envrionment where it does
johrstrom Apr 25, 2022
1f26784
maybe more wait time works
johrstrom Apr 25, 2022
961e953
add comment to jquery plugins
johrstrom Apr 25, 2022
bb5ac51
xdmod widgets need lodash
johrstrom Apr 25, 2022
cb2fb4a
Merge branch 'dev/esbuild' of github.com:OSC/ondemand into dev/esbuild
johrstrom Apr 25, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
/apps/*/public/packs
/apps/*/public/packs-test
/apps/*/vendor/bundle/
/apps/*/app/assets/builds/
!/apps/*/app/assets/builds/.keep
/*/.bundle

# files used for deployment should not be versioned
Expand Down
6 changes: 4 additions & 2 deletions apps/dashboard/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ gem 'mocha', '~> 1.1', group: :test
gem 'autoprefixer-rails', '~> 10.2.5'
gem 'dotiw'
gem 'local_time', '~> 1.0.3'
gem 'zip_tricks', '~> 5.5'

gem 'jsbundling-rails', '~> 1.0'
gem 'cssbundling-rails', '~> 1.1'

# OOD specific gems
gem 'ood_support', '~> 0.0.2'
Expand All @@ -58,5 +62,3 @@ gem "sinatra-contrib", require: false
gem "erubi", require: false
gem "dalli", require: false

gem 'webpacker', '~> 5.4'
gem 'zip_tricks', '~> 5.5'
15 changes: 6 additions & 9 deletions apps/dashboard/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ GEM
coffee-script-source (1.12.2)
concurrent-ruby (1.1.10)
crass (1.0.6)
cssbundling-rails (1.1.0)
railties (>= 6.0.0)
dalli (3.2.1)
dotenv (2.7.6)
dotenv-rails (2.7.6)
Expand All @@ -108,6 +110,8 @@ GEM
jbuilder (2.11.5)
actionview (>= 5.0.0)
activesupport (>= 5.0.0)
jsbundling-rails (1.0.2)
railties (>= 6.0.0)
local_time (1.0.3)
coffee-rails
lograge (0.12.0)
Expand Down Expand Up @@ -151,8 +155,6 @@ GEM
rack (2.2.3)
rack-protection (2.2.0)
rack
rack-proxy (0.7.2)
rack
rack-test (1.1.0)
rack (>= 1.0, < 3)
rails (6.1.4.7)
Expand Down Expand Up @@ -196,7 +198,6 @@ GEM
childprocess (>= 0.5, < 5.0)
rexml (~> 3.2, >= 3.2.5)
rubyzip (>= 1.2.2)
semantic_range (3.0.0)
sinatra (2.2.0)
mustermann (~> 1.0)
rack (~> 2.2)
Expand All @@ -220,11 +221,6 @@ GEM
timecop (0.9.5)
tzinfo (2.0.4)
concurrent-ruby (~> 1.0)
webpacker (5.4.3)
activesupport (>= 5.2)
rack-proxy (>= 0.6.1)
railties (>= 5.2)
semantic_range (>= 2.3.0)
websocket-driver (0.7.5)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
Expand All @@ -244,11 +240,13 @@ DEPENDENCIES
byebug
capybara
climate_control (~> 0.2)
cssbundling-rails (~> 1.1)
dalli
dotenv-rails (~> 2.1)
dotiw
erubi
jbuilder (~> 2.0)
jsbundling-rails (~> 1.0)
local_time (~> 1.0.3)
mocha (~> 1.1)
ood_appkit (~> 2.1.0)
Expand All @@ -262,7 +260,6 @@ DEPENDENCIES
sinatra
sinatra-contrib
timecop (~> 0.9)
webpacker (~> 5.4)
zip_tricks (~> 5.5)

BUNDLED WITH
Expand Down
4 changes: 4 additions & 0 deletions apps/dashboard/app/assets/config/manifest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@


//= link_tree ../images
//= link_tree ../builds
Empty file.
2 changes: 1 addition & 1 deletion apps/dashboard/app/helpers/dashboard_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def logo_image_tag(url)
uri.query_values = (uri.query_values || {}).merge({timestamp: Time.now.to_i})
tag.img(src: uri, alt: "logo", height: Configuration.logo_height, class: 'py-2')
else # default logo image
image_pack_tag("OpenOnDemand_stack_RGB.svg", alt: "logo", height: "85", class: 'py-2')
image_tag("OpenOnDemand_stack_RGB.svg", alt: "logo", height: "85", class: 'py-2')
end
end

Expand Down
37 changes: 20 additions & 17 deletions apps/dashboard/app/javascript/packs/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// a relevant structure within app/javascript and only use these pack files to reference
// that code so it'll be compiled.
//
// To reference this file, add <%= javascript_pack_tag 'application' %> to the appropriate
// To reference this file, add <%= javascript_include_tag 'application' %> to the appropriate
// layout file, like app/views/layouts/application.html.erb
//
// Uncomment to copy all static images under ../images to the output folder and reference
Expand All @@ -14,32 +14,35 @@
// const images = require.context('../images', true)
// const imagePath = (name) => images(name, true)

import 'jquery';
import 'jquery-ujs'

// lot's of inline scripts and stuff rely on jquery just being available
window.jQuery = jQuery;
window.$ = $;
import jQuery from 'jquery';
import 'jquery-ujs';
import datatables from 'datatables.net';
Copy link
Contributor

Choose a reason for hiding this comment

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

We're trying to decouple. Why move the datatables here? if there is a piece of functionality that needs datatable access, shouldn't we do the same as we did in the files app?

Copy link
Contributor

Choose a reason for hiding this comment

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

Another thought, by adding datatables import here, we're loading datatables even on pages that do not use datatables.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's true, but jquery plugins don't play nice when jquery has a conflict (i.e., some other definition of jquery). #1846 is an example of this. Indeed - tooltip is a global jquery plugin. Along with poppers that we have installed everywhere.

I figure if we buy in on jquery, we buy in on it's plugins too.

I can try to fix this but it didn't work easily so i'll bet we have to use jquery's noConflict.

Copy link
Contributor

Choose a reason for hiding this comment

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

No need to fix. I was just asking the question.

import datatablesBs4 from 'datatables.net-bs4/js/dataTables.bootstrap4';
import datatablesSelect from 'datatables.net-select';

import Rails from '@rails/ujs';
Rails.start();

// Import popper.js for Bootstrap 4
import 'popper.js'
import 'popper.js';

// Import Bootstrap 4
import 'bootstrap/dist/js/bootstrap'
import 'bootstrap/dist/js/bootstrap';

// FIXME: confim modals don't work in esbuild.
// import 'data-confirm-modal';
Comment on lines +31 to +32
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This may actually be OK because it's buggy: #665.


// confim modals
import 'data-confirm-modal';
import { setNavbarColor } from './config';

// Import application stylesheets
import '../stylesheets/application'
// lot's of inline scripts and stuff rely on jquery just being available
window.jQuery = jQuery;
window.$ = jQuery;

import '../images/OpenOnDemand_powered_by_RGB.svg';
import '../images/OpenOnDemand_stack_RGB.svg';
// these plugins don't automatically load, so this loads them.
datatables(window, jQuery);
Copy link
Contributor

Choose a reason for hiding this comment

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

more coupling? Now, we're having to pass window and jQuery to the datatable. Seems counter-productive to the goal of decoupling?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This deserves a comment which I'll give it, but this is here to initialize these plugins. They don't directly initialize just by being imported (because of javascript toolchain compilations and how old it is and how it's being invoked).

So I had to initialize them to tie them to this jquery otherwise they never invoke.

datatablesBs4(window, jQuery);
datatablesSelect(window, jQuery);

import { setNavbarColor } from './config';
Rails.start();

jQuery(function(){

Expand Down
3 changes: 0 additions & 3 deletions apps/dashboard/app/javascript/packs/apps.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
'use strict';

import 'datatables.net'
import 'datatables.net-bs4/js/dataTables.bootstrap4'

jQuery(function() {
$('#all-apps-table').DataTable({
stateSave: true
Expand Down
1 change: 1 addition & 0 deletions apps/dashboard/app/javascript/packs/dashboard.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

import _ from 'lodash';
window._ = _;

function promiseLoginToXDMoD(xdmodUrl){
return new Promise(function(resolve, reject){
Expand Down
5 changes: 4 additions & 1 deletion apps/dashboard/app/javascript/packs/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,10 @@ jQuery(function () {
url: apiUrl,
type: 'PUT',
data: editor.getValue(),
contentType: 'text/plain',
headers: {
'Content-Type': 'text/plain',
'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content')
},
success: function (data) {
toggleSaveSpinner();
toggleSaveConfirmed();
Expand Down
9 changes: 0 additions & 9 deletions apps/dashboard/app/javascript/packs/files/data_table.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import 'datatables.net';
import 'datatables.net-bs4/js/dataTables.bootstrap4';
import 'datatables.net-select';
import 'datatables.net-select-bs4';
import Handlebars from 'handlebars';
import {EVENTNAME as SWAL_EVENTNAME} from './sweet_alert.js';

Expand Down Expand Up @@ -198,11 +194,6 @@ class DataTable {
data: null,
orderable: false,
defaultContent: '<input type="checkbox">',
render: function (data, type, row, meta) {
var api = new $.fn.dataTable.Api(meta.settings);
let selected = api.rows(meta.row, { selected: true }).count() > 0;
return `<input type="checkbox" ${selected ? 'checked' : ''}> ${selected ? 'checked' : ''}`;
}
Comment on lines -201 to -205
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't believe this is ever used or is useful. plus it adds the text checked to the innerHtml?

Copy link
Contributor

Choose a reason for hiding this comment

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

files app test fine with this removed, so we should be good.

},
{ data: 'type', render: (data, type, row, meta) => data == 'd' ? '<span title="directory" class="fa fa-folder" style="color: gold"><span class="sr-only"> dir</span></span>' : '<span title="file" class="fa fa-file" style="color: lightgrey"><span class="sr-only"> file</span></span>' }, // type
{ name: 'name', data: 'name', className: 'text-break', render: (data, type, row, meta) => `<a class="${row.type} name ${row.type == 'd' ? '' : 'view-file'}" href="${row.url}">${Handlebars.escapeExpression(data)}</a>` }, // name
Expand Down
1 change: 1 addition & 0 deletions apps/dashboard/app/javascript/packs/files/file_ops.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Handlebars from 'handlebars';
import {CONTENTID, EVENTNAME as DATATABLE_EVENTNAME} from './data_table.js';
import {EVENTNAME as CLIPBOARD_EVENTNAME} from './clip_board.js';
import {EVENTNAME as SWAL_EVENTNAME} from './sweet_alert.js';
import _ from 'lodash';

export {EVENTNAME};

Expand Down
4 changes: 2 additions & 2 deletions apps/dashboard/app/javascript/packs/files/uppy_ops.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@ jQuery(function() {
});

// https://stackoverflow.com/questions/6756583/prevent-browser-from-loading-a-drag-and-dropped-file
global.addEventListener("dragover",function(e){
window.addEventListener("dragover",function(e){
e = e || event;
e.preventDefault();
},false);

global.addEventListener("drop",function(e){
window.addEventListener("drop",function(e){
e = e || event;
e.preventDefault();
},false);
Expand Down
2 changes: 1 addition & 1 deletion apps/dashboard/app/javascript/packs/icon_picker.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

import ALL_ICONS from 'icons';
import ALL_ICONS from './icons';

const ICON_SHOW_ID = "product_icon"
const ICON_SELECT_ID = "product_icon_select"
Expand Down
4 changes: 2 additions & 2 deletions apps/dashboard/app/javascript/stylesheets/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,5 @@ $navbar-nav-link-padding-x: 0.75rem;
// breadcrumbs are purely visual for accessibility
$breadcrumb-divider: '';

// needs to be set by webpack
// $fa-font-path:
// files get copied during 'yarn build' in esbuild.config.js
$fa-font-path: "../builds";
2 changes: 1 addition & 1 deletion apps/dashboard/app/views/active_jobs/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= javascript_pack_tag 'active_jobs', nonce: true %>
<%= javascript_include_tag 'active_jobs', nonce: true %>

<div class="row">
<div class="col-md-12">
Expand Down
2 changes: 1 addition & 1 deletion apps/dashboard/app/views/apps/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= javascript_pack_tag 'apps', nonce: true %>
<%= javascript_include_tag 'apps', nonce: true %>

<%= render partial: 'batch_connect/shared/breadcrumb',
locals: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<%= f.submit t('dashboard.batch_connect_form_launch'), class: "btn btn-primary btn-block" %>
<% end %>

<%= javascript_pack_tag 'batch_connect', nonce: true if Configuration.bc_dynamic_js? %>
<%= javascript_include_tag 'batch_connect', nonce: true if Configuration.bc_dynamic_js? %>

<% @app.custom_javascript_files.each do |jsfile| %>
<%= javascript_tag "(function(){\n" + jsfile.read + "\n}());" %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
any_apps = (@sys_app_groups + @usr_app_groups + @dev_app_groups).any?
-%>

<%= javascript_pack_tag 'batch_connect_sessions', nonce: true %>
<%= javascript_include_tag 'batch_connect_sessions', nonce: true %>

<%= render partial: 'batch_connect/shared/breadcrumb',
locals: {
Expand Down
2 changes: 1 addition & 1 deletion apps/dashboard/app/views/dashboard/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= javascript_pack_tag 'dashboard', nonce: true %>
<%= javascript_include_tag 'dashboard', nonce: true %>
<%= render partial: 'shared/welcome' %>

<%- dashboard_layout.fetch(:rows, []).each do |row| -%>
Expand Down
2 changes: 1 addition & 1 deletion apps/dashboard/app/views/layouts/_footer.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="mr-2">
<%= link_to "https://openondemand.org" do %>
<%=
image_pack_tag(
image_tag(
"OpenOnDemand_powered_by_RGB.svg",
class: "footer-logo",
alt: "Powered by Open OnDemand",
Expand Down
4 changes: 2 additions & 2 deletions apps/dashboard/app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<title><%= content_for?(:title) ? yield(:title) : "Dashboard - #{OodAppkit.dashboard.title}" %></title>
<%= favicon_link_tag 'favicon.ico', href: OodAppkit.public.url.join('favicon.ico'), skip_pipeline: true %>

<%= javascript_pack_tag 'application', nonce: true %>
<%= stylesheet_pack_tag 'application', nonce: true, media: 'all' %>
<%= javascript_include_tag 'application', nonce: true %>
<%= stylesheet_link_tag 'application', nonce: true, media: 'all' %>

<%= csrf_meta_tags %>

Expand Down
8 changes: 4 additions & 4 deletions apps/dashboard/app/views/layouts/editor.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
<meta charset="UTF-8">

<title><%= "File Editor - #{OodAppkit.dashboard.title}" %><%= @path.nil? ? "" : " - #{@path.basename.to_s}" %></title>
<%= favicon_link_tag 'favicon.ico', href: OodAppkit.public.url.join('favicon.ico') %>
<%= favicon_link_tag 'favicon.ico', href: OodAppkit.public.url.join('favicon.ico'), skip_pipeline: true %>

<%= javascript_pack_tag 'application', nonce: true %>
<%= javascript_pack_tag 'editor', nonce: true %>
<%= stylesheet_pack_tag 'application', nonce: true, media: 'all' %>
<%= javascript_include_tag 'application', nonce: true %>
<%= javascript_include_tag 'editor', nonce: true %>
<%= stylesheet_link_tag 'application', nonce: true, media: 'all' %>

<%= csrf_meta_tags %>

Expand Down
2 changes: 1 addition & 1 deletion apps/dashboard/app/views/layouts/files.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<%
content_for :head do
javascript_pack_tag 'files/index', nonce: true
javascript_include_tag 'files/index', nonce: true
end
%>

Expand Down
2 changes: 1 addition & 1 deletion apps/dashboard/app/views/products/_form_icon.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= javascript_pack_tag 'icon_picker', nonce: true %>
<%= javascript_include_tag 'icon_picker', nonce: true %>

<% if product.app.image_icon? %>
<p class="text-center">
Expand Down
2 changes: 1 addition & 1 deletion apps/dashboard/app/views/products/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= javascript_pack_tag 'products_index', nonce: true %>
<%= javascript_include_tag 'products_index', nonce: true %>

<% product_class = Product.product_types[@type] %>

Expand Down
2 changes: 1 addition & 1 deletion apps/dashboard/app/views/products/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= javascript_pack_tag 'products_show', nonce: true %>
<%= javascript_include_tag 'products_show', nonce: true %>

<%= render layout: 'products/breadcrumbs' do %>
<li class="breadcrumb-item"><%= @product.title %></li>
Expand Down
Loading