From 99c2d74753b6216594fb80b234788e1c8b45ab3b Mon Sep 17 00:00:00 2001 From: Patrick Pircher Date: Tue, 1 Aug 2023 19:14:43 +0200 Subject: [PATCH] update inline strategy (#254) * update inline strategy fixes issue #253 --- packages/ember-svg-jar/addon/helpers/svg-jar.js | 13 ++++++++++--- packages/ember-svg-jar/lib/inline-packer.js | 13 ------------- .../node-tests/acceptance/inline-packer-test.js | 2 -- 3 files changed, 10 insertions(+), 18 deletions(-) diff --git a/packages/ember-svg-jar/addon/helpers/svg-jar.js b/packages/ember-svg-jar/addon/helpers/svg-jar.js index 9dfdc7c..0ed5b75 100644 --- a/packages/ember-svg-jar/addon/helpers/svg-jar.js +++ b/packages/ember-svg-jar/addon/helpers/svg-jar.js @@ -1,13 +1,20 @@ import { helper } from '@ember/component/helper'; import makeSVG from 'ember-svg-jar/utils/make-svg'; -import assets from '../inlined'; +import { importSync } from '@embroider/macros'; function getInlineAsset(assetId) { + let result = null; try { - return assets[assetId]().default; + result = require(`ember-svg-jar/inlined/${assetId}`).default; } catch (err) { - return null; + // skip } + try { + result = importSync(`../inlined/${assetId}`).default; + } catch (err) { + // skip + } + return result; } export function svgJar(assetId, svgAttrs) { diff --git a/packages/ember-svg-jar/lib/inline-packer.js b/packages/ember-svg-jar/lib/inline-packer.js index 780d5c2..c82bb7f 100644 --- a/packages/ember-svg-jar/lib/inline-packer.js +++ b/packages/ember-svg-jar/lib/inline-packer.js @@ -55,19 +55,6 @@ class InlinePacker extends CachingWriter { assets.push(jsName); }); - - // Generate index.js that contains methods to import each asset - const contents = `import { importSync } from '@embroider/macros'; - const obj = { - ${assets - .map(asset => { - const assetName = asset.replace(/'/g, "\\'"); - return `['${assetName}']: function() { return importSync('./${assetName}'); }`; - }) - .join(',\n')} - }; export default obj;`; - - saveToFile(path.join(outputPath, `index.js`), contents); } } diff --git a/packages/ember-svg-jar/node-tests/acceptance/inline-packer-test.js b/packages/ember-svg-jar/node-tests/acceptance/inline-packer-test.js index 1fbbf66..8d02ffc 100644 --- a/packages/ember-svg-jar/node-tests/acceptance/inline-packer-test.js +++ b/packages/ember-svg-jar/node-tests/acceptance/inline-packer-test.js @@ -40,8 +40,6 @@ describe('InlinePacker', function () { 'export default {"content":"","attrs":{"viewBox":"0 0 1 1"}}', 'bar.js': 'export default {"content":"","attrs":{"height":"10px","viewBox":"0 0 2 2"}}', - 'index.js': - "import { importSync } from '@embroider/macros';\n const obj = {\n ['apost\\'rophe']: function() { return importSync('./apost\\'rophe'); },\n['bar']: function() { return importSync('./bar'); },\n['foo']: function() { return importSync('./foo'); }\n }; export default obj;", }, };