Skip to content

Commit 170f445

Browse files
authored
Fix FA5 import & add test for FA5 (#236)
* Fix FA5 import & add test * Fix test --------- Co-authored-by: Markus Sanin <m.sanin@hotmail.de>
1 parent 50c5d0f commit 170f445

File tree

6 files changed

+159
-17
lines changed

6 files changed

+159
-17
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ jobs:
5252
try-scenario:
5353
- ember-lts-3.20
5454
- ember-lts-3.24
55+
- ember-lts-3.24-with-fa5
5556
- ember-release
5657
- ember-classic
5758
- ember-default-with-jquery

config/ember-try.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,17 @@ module.exports = async function () {
2222
},
2323
},
2424
},
25+
{
26+
name: 'ember-lts-3.24-with-fa5',
27+
npm: {
28+
devDependencies: {
29+
'ember-source': '~3.24.3',
30+
'@fortawesome/free-brands-svg-icons': '^5.15.4',
31+
'@fortawesome/free-regular-svg-icons': '^5.15.4',
32+
'@fortawesome/free-solid-svg-icons': '^5.15.4',
33+
},
34+
},
35+
},
2536
{
2637
name: 'ember-release',
2738
npm: {

package-lock.json

Lines changed: 124 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
"ember-cli-inject-live-reload": "^2.1.0",
9494
"ember-cli-sri": "^2.1.1",
9595
"ember-cli-terser": "^4.0.2",
96+
"ember-compatibility-helpers": "^1.2.6",
9697
"ember-disable-prototype-extensions": "^1.1.3",
9798
"ember-export-application-global": "^2.0.1",
9899
"ember-load-initializers": "^2.1.2",

tests/integration/components/fa-icon-test.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { setupRenderingTest } from 'ember-qunit';
33
import { render, find } from '@ember/test-helpers';
44
import hbs from 'htmlbars-inline-precompile';
55
import { htmlSafe } from '@ember/template';
6+
import { gte } from 'ember-compatibility-helpers';
67

78
const faCoffee = {
89
prefix: 'fas',
@@ -210,16 +211,21 @@ module('Integration | Component | fa icon', function (hooks) {
210211
test('it renders trash-alt (alias) ', async function (assert) {
211212
await render(hbs`<FaIcon @icon="trash-alt" />`);
212213

214+
let icon = 'trash-can';
215+
let path =
216+
'M135.2 17.7C140.6 6.8 151.7 0 163.8 0H284.2c12.1 0 23.2 6.8 28.6 17.7L320 32h96c17.7 0 32 14.3 32 32s-14.3 32-32 32H32C14.3 96 0 81.7 0 64S14.3 32 32 32h96l7.2-14.3zM32 128H416V448c0 35.3-28.7 64-64 64H96c-35.3 0-64-28.7-64-64V128zm96 64c-8.8 0-16 7.2-16 16V432c0 8.8 7.2 16 16 16s16-7.2 16-16V208c0-8.8-7.2-16-16-16zm96 0c-8.8 0-16 7.2-16 16V432c0 8.8 7.2 16 16 16s16-7.2 16-16V208c0-8.8-7.2-16-16-16zm96 0c-8.8 0-16 7.2-16 16V432c0 8.8 7.2 16 16 16s16-7.2 16-16V208c0-8.8-7.2-16-16-16z';
217+
218+
if (!gte('@fortawesome/free-brands-svg-icons', '6.0.0')) {
219+
icon = 'trash-alt';
220+
path =
221+
'M32 464a48 48 0 0 0 48 48h288a48 48 0 0 0 48-48V128H32zm272-256a16 16 0 0 1 32 0v224a16 16 0 0 1-32 0zm-96 0a16 16 0 0 1 32 0v224a16 16 0 0 1-32 0zm-96 0a16 16 0 0 1 32 0v224a16 16 0 0 1-32 0zM432 32H312l-9.4-18.7A24 24 0 0 0 281.1 0H166.8a23.72 23.72 0 0 0-21.4 13.3L136 32H16A16 16 0 0 0 0 48v32a16 16 0 0 0 16 16h416a16 16 0 0 0 16-16V48a16 16 0 0 0-16-16z';
222+
}
223+
213224
assert.dom('*').hasText('');
214-
assert.dom('svg').hasAttribute('data-icon', 'trash-can');
225+
assert.dom('svg').hasAttribute('data-icon', icon);
215226
assert.ok(
216-
find('svg').getAttribute('class').split(/\s+/).includes('fa-trash-can')
227+
find('svg').getAttribute('class').split(/\s+/).includes(`fa-${icon}`)
217228
);
218-
assert
219-
.dom('svg path')
220-
.hasAttribute(
221-
'd',
222-
'M135.2 17.7C140.6 6.8 151.7 0 163.8 0H284.2c12.1 0 23.2 6.8 28.6 17.7L320 32h96c17.7 0 32 14.3 32 32s-14.3 32-32 32H32C14.3 96 0 81.7 0 64S14.3 32 32 32h96l7.2-14.3zM32 128H416V448c0 35.3-28.7 64-64 64H96c-35.3 0-64-28.7-64-64V128zm96 64c-8.8 0-16 7.2-16 16V432c0 8.8 7.2 16 16 16s16-7.2 16-16V208c0-8.8-7.2-16-16-16zm96 0c-8.8 0-16 7.2-16 16V432c0 8.8 7.2 16 16 16s16-7.2 16-16V208c0-8.8-7.2-16-16-16zm96 0c-8.8 0-16 7.2-16 16V432c0 8.8 7.2 16 16 16s16-7.2 16-16V208c0-8.8-7.2-16-16-16z'
223-
);
229+
assert.dom('svg path').hasAttribute('d', path);
224230
});
225231
});

vendor/broccoli-fontawesome-pack.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,17 @@ class FontAwesomePack extends Plugin {
6262

6363

6464
const packageContents = () => {
65+
const pathToModule = require.resolve(`@fortawesome/${this.options.pack}`)
66+
const moduleDir = path.dirname(pathToModule);
67+
const files = fs.readdirSync(moduleDir);
68+
let entryFile = 'index';
69+
if (files.find((file) => file === 'index.es.js')) {
70+
entryFile = 'index.es.js';
71+
}
6572
return `
6673
export {
6774
${selectedIcons.join(',')}
68-
} from '@fortawesome/${this.options.pack}/index'
75+
} from '@fortawesome/${this.options.pack}/${entryFile}'
6976
`;
7077
}
7178
const _thisPlugin = this

0 commit comments

Comments
 (0)