Skip to content

Commit

Permalink
🚧 fixes circleci
Browse files Browse the repository at this point in the history
  • Loading branch information
josemigallas committed Jul 17, 2024
1 parent d274bea commit e3706e1
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 15 deletions.
6 changes: 0 additions & 6 deletions .browserslistrc

This file was deleted.

5 changes: 2 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ save-assets-cache: &save-assets-cache
key: *assets-cache-key
paths:
- public/assets
- public/packs-test
- public/packs
- tmp/cache/assets

restore-assets-cache: &restore-assets-cache
Expand Down Expand Up @@ -509,15 +509,14 @@ jobs:
- *use-example-config-files
- run:
name: Precompile assets
command: bundle exec rake assets:precompile:test
command: bundle exec rake assets:precompile
environment:
RAILS_GROUPS: assets
- *save-assets-cache
- persist_to_workspace:
root: .
paths:
- ./public/packs
- ./public/packs-test
- ./public/assets
- ./config/*.yml
- notify_failure
Expand Down
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ config/*.sphinx.conf
public/assets
public/system
public/packs
public/packs-tests
openshift/system/*file
openshift/system/Dockerfile*
openshift/system/*.yml
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ package-lock.json

# Webpack
/public/packs
/public/packs-test
/node_modules
/yarn-error.log
yarn-debug.log*
Expand Down
10 changes: 7 additions & 3 deletions app/helpers/webpack_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# rubocop:disable Rails/HelperInstanceVariable
# frozen_string_literal: true
# frozen_string_literal: false

module WebpackHelper
def load_webpack_manifest
Expand All @@ -17,13 +17,16 @@ def webpack_manifest

##
# Returns a string of HTML script and style tags, containing all chunks of one or more +packs+.
# Chunks generated from ".ts" packs are located under the entrypoint with extension.
# Chunks generated from ".scss" packs are located under the entrypoint without extension.
#
# +packs+ is a list of pack names, without extension (.ts, .js).
#
# FIXME: the entrypoints in manifest should not have extension .ts
#
# A RuntimeError is raised if one pack is not found in the manifest, possibly pointing out a typo.
def javascript_packs_with_chunks_tag(*packs) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity
raise RuntimeError
@packs ||= []
tags = ''

Expand All @@ -41,13 +44,13 @@ def javascript_packs_with_chunks_tag(*packs) # rubocop:disable Metrics/AbcSize,
if (js = assets['js'])
new_js_assets = js - @packs
@packs.concat(new_js_assets)
tags += javascript_include_tag(*new_js_assets, defer: false)
tags.concat(javascript_include_tag(*new_js_assets, defer: false), "\n")
end

if (css = assets['css']) # rubocop:disable Style/Next
new_css_assets = css - @packs
@packs.concat(new_css_assets)
tags += stylesheet_link_tag(*new_css_assets, defer: false)
tags.concat(stylesheet_link_tag(*new_css_assets, defer: false))
end
end

Expand All @@ -56,6 +59,7 @@ def javascript_packs_with_chunks_tag(*packs) # rubocop:disable Metrics/AbcSize,

##
# Returns a string of HTML style tags, containing all CSS chunks of one or more +packs+.
# Chunks generated from ".scss" packs are located under the entrypoint without extension.
#
# +packs+ is a list of pack names, without extension.
#
Expand Down
1 change: 1 addition & 0 deletions lib/developer_portal/lib/liquid/filters/rails_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def javascript_include_tag(name, options = {})
js = RailsHelpers.replace_googleapis(name)
case
when THREESCALE_WEBPACK_PACKS.include?(name) # TODO: This is an intermediate step in order to tackle webpack assets in dev portal. A final solution might be needed easing the update of templates/assets.
binding.pry
active_docs_proxy(name) + view.javascript_packs_with_chunks_tag(name.chomp('.js'))
when js != name || THREESCALE_JAVASCRIPTS.include?(js)
active_docs_proxy(js) + view.javascript_include_tag(js)
Expand Down
60 changes: 60 additions & 0 deletions test/unit/helpers/webpack_helper_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# frozen_string_literal: true

require 'test_helper'

class WebpackHelperTest < ActionView::TestCase
include WebpackHelper

test 'unknown pack raise an error' do
assert_raise(RuntimeError) do
javascript_packs_with_chunks_tag('unknown')
end

assert_raise(RuntimeError) do
stylesheet_packs_chunks_tag('unknown')
end
end

test 'javascript_packs_with_chunks_tag' do
tags = javascript_packs_with_chunks_tag('application')

assert_equal 6, tags.lines.size
end

test 'stylesheet_packs_chunks_tag' do
tags = stylesheet_packs_chunks_tag('application')

assert_equal 1, tags.lines.size
end

private

def webpack_manifest # rubocop:disable Metrics/MethodLength
JSON.parse({
entrypoints: {
application: {
assets: {
js: [
'packs/js/application-1.js',
'packs/js/application-2.js',
],
css: [
'packs/css/application-1.css',
]
}
},
'application.ts': {
assets: {
js: [
'packs/js/application.ts-1.js',
],
css: [
'packs/css/application.ts-1.css',
'packs/css/application.ts-2.css',
]
}
}
}
}.to_json)
end
end
2 changes: 1 addition & 1 deletion test/unit/liquid/filters/rails_helpers_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def setup

test 'javascript_include_tag' do
@context.registers[:controller] = ApplicationController.new
WebpackHelper.stubs(:javascript_packs_with_chunks_tag).with('stats', type: :javascript).returns('/packs/stats.js') # TODO: FIXME
WebpackHelper.expects(:javascript_packs_with_chunks_tag).returns('/packs/stats.js') # TODO: FIXME!!!
assert_equal "<script src=\"/packs/stats.js\"></script>", javascript_include_tag('stats.js')
end

Expand Down

0 comments on commit e3706e1

Please sign in to comment.