From 037658cf148c60f977d9d4b4e98754eae12742c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20de=20Metz?= Date: Sun, 16 Jul 2023 20:47:34 +0200 Subject: [PATCH 1/2] Insert the global ember import on production build --- lib/util.js | 2 +- node-tests/__snapshots__/util.test.js.snap | 10 +++++++++ node-tests/fixtures/build-production.html | 25 ++++++++++++++++++++++ node-tests/util.test.js | 8 +++++++ 4 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 node-tests/fixtures/build-production.html diff --git a/lib/util.js b/lib/util.js index b6ff058..4d831bd 100644 --- a/lib/util.js +++ b/lib/util.js @@ -144,7 +144,7 @@ function generatePreviewHead(parsedConfig) { continue; } doc.push(`<${key} ${objectToHTMLAttributes(value)}>`); - if(value.src.indexOf('assets/vendor.js') > -1) { + if(value.src.match(/assets\/vendor[^.]*\.js/)) { // make sure we push this right after vendor to ensure the application does not bind to the window. doc.push(''); } diff --git a/node-tests/__snapshots__/util.test.js.snap b/node-tests/__snapshots__/util.test.js.snap index 2eaa81b..559e97b 100644 --- a/node-tests/__snapshots__/util.test.js.snap +++ b/node-tests/__snapshots__/util.test.js.snap @@ -15,6 +15,16 @@ exports[`util @generatePreviewHead should work with file created with \`ember bu " `; +exports[`util @generatePreviewHead should work with file created with \`ember build\` in production env 1`] = ` +" + + + + + +" +`; + exports[`util @generatePreviewHead should work with file created with \`ember serve\` (should append livereload pointing at serve instance) 1`] = ` " diff --git a/node-tests/fixtures/build-production.html b/node-tests/fixtures/build-production.html new file mode 100644 index 0000000..2d27076 --- /dev/null +++ b/node-tests/fixtures/build-production.html @@ -0,0 +1,25 @@ + + + + + BeforeStorybook + + + + + + + + + + + + + + + + + + + + diff --git a/node-tests/util.test.js b/node-tests/util.test.js index a72d62c..7925876 100644 --- a/node-tests/util.test.js +++ b/node-tests/util.test.js @@ -186,6 +186,14 @@ Object { expect(generatePreviewHead(parse(fileContent))).toMatchSnapshot() }) + it('should work with file created with `ember build` in production env', () => { + expect.assertions(1); + + const fileContent = fs.readFileSync(path.resolve(__dirname, 'fixtures', 'build-production.html'), 'utf8'); + + expect(generatePreviewHead(parse(fileContent))).toMatchSnapshot() + }) + it('should work with file created with `ember serve` (should append livereload pointing at serve instance)', () => { expect.assertions(1); From 57ab78531af85c4ea83572c6f023eea6694e23e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20de=20Metz?= Date: Mon, 31 Jul 2023 23:25:49 +0200 Subject: [PATCH 2/2] Add @ember/string --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e13e499..d5f66e3 100644 --- a/package.json +++ b/package.json @@ -31,8 +31,8 @@ "test:ember-compatibility": "ember try:each" }, "devDependencies": { - "@embroider/test-setup": "^1.8.3", "@ember/optional-features": "^1.3.0", + "@ember/string": "^3.1.1", "@ember/test-helpers": "^2.8.0", "@embroider/test-setup": "^2.0.2", "babel-eslint": "^10.1.0",