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

Fix the path to the on-disk styles file for in-repo engines #709

Merged
merged 5 commits into from
Mar 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions packages/compat/tests/stage2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ describe('stage2 build', function () {
test('lazy engine css is imported', function () {
expectFile('assets/_engine_/lazy-engine.js')
.matches(` if (macroCondition(!getGlobalConfig().fastboot?.isRunning)) {
i(\"../../../lazy-engine/lazy-engine.css\");
i(\"../../node_modules/lazy-engine/lazy-engine.css\");
}`);
});

Expand Down Expand Up @@ -760,7 +760,7 @@ i(\"../../../lazy-engine/lazy-engine.css\");
test('lazy engine css is not imported', function () {
expectFile('assets/_engine_/lazy-engine.js')
.doesNotMatch(` if (macroCondition(!getGlobalConfig().fastboot?.isRunning)) {
i(\"../../../lazy-engine/lazy-engine.css\");
i(\"../../node_modules/lazy-engine/lazy-engine.css\");
}`);
});
});
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1081,7 +1081,7 @@ export class AppBuilder<TreeNames> {
if (engineMeta && engineMeta['implicit-styles']) {
for (let style of engineMeta['implicit-styles']) {
styles.push({
path: explicitRelative(relativePath, join(engine.package.name, style)),
path: explicitRelative(dirname(relativePath), join(engine.appRelativePath, style)),
});
}
}
Expand Down
1 change: 1 addition & 0 deletions test-packages/engines-host-app/app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Router.map(function() {
this.route('use-eager-engine');
this.mount('lazy-engine', { path: '/use-lazy-engine', as: 'use-lazy-engine' });
this.route('style-check');
this.mount('lazy-in-repo-engine', { path: '/use-lazy-in-repo-engine', as: 'use-lazy-in-repo-engine' });
});

export default Router;
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Engine from 'ember-engines/engine';
import loadInitializers from 'ember-load-initializers';
import Resolver from './resolver';
import config from './config/environment';

const { modulePrefix } = config;

const Eng = Engine.extend({
modulePrefix,
Resolver
});

loadInitializers(Eng, modulePrefix);

export default Eng;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { helper } from '@ember/component/helper';

export function duplicatedHelper() {
return 'from-lazy-in-repo-engine';
}

export default helper(duplicatedHelper);
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Resolver from 'ember-resolver';

export default Resolver;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import buildRoutes from 'ember-engines/routes';

export default buildRoutes(function () {});
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.shared-style-target {
border-bottom-width: 2px;
border-bottom-style: solid;
border-bottom-color: blue;
content: 'lazy-in-repo-engine/addon/styles/addon.css';
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<div data-test-lazy-in-repo-engine-main>
<h1>Lazy In-Repo Engine</h1>
<div data-test-duplicated-helper>
{{duplicated-helper needAnArgumentHere="to force ember to consider this a helper"}}
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* eslint-env node */
'use strict';

module.exports = function(environment) {
let ENV = {
modulePrefix: 'lazy-in-repo-engine',
environment
};

return ENV;
};
12 changes: 12 additions & 0 deletions test-packages/engines-host-app/lib/lazy-in-repo-engine/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* eslint-env node */
'use strict';

const EngineAddon = require('ember-engines/lib/engine-addon');

module.exports = EngineAddon.extend({
name: 'lazy-in-repo-engine',

lazyLoading: Object.freeze({
enabled: true,
}),
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "lazy-in-repo-engine",
"keywords": [
"ember-addon",
"ember-engine"
],
"dependencies": {
"ember-cli-htmlbars": "*",
"ember-cli-babel": "*"
},
"devDependencies": {
"ember-engines": "*"
},
"volta": {
"extends": "../../package.json"
}
}
5 changes: 5 additions & 0 deletions test-packages/engines-host-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,10 @@
},
"volta": {
"extends": "../../package.json"
},
"ember-addon": {
"paths": [
"lib/lazy-in-repo-engine"
]
}
}
52 changes: 52 additions & 0 deletions test-packages/engines-host-app/tests/acceptance/basics-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,58 @@ module('Acceptance | basics', function (hooks) {
// See TODO comment in above test
skip('lazy engines own app tree is lazy', function () {});

// this test must be the first test that loads the lazy-in-repo-engine as after it has loaded
// it will not "unload" and we are checkign that these modules are entering require.entries
// for the first time.
test('lazy-in-repo-engine', async function (assert) {
await visit('/');
const entriesBefore = Object.entries(window.require.entries).length;
let rules = arrayOfCSSRules(document.styleSheets, '.shared-style-target', 'content');

assert.notOk(rules.includes('lazy-in-repo-engine/addon/styles/addon.css'));

await visit('/style-check');
assert.dom('.shared-style-target').exists();

assert.equal(
getComputedStyle(document.querySelector('.shared-style-target'))['border-left-width'],
'2px',
'eager-engine styles are present'
);

assert.equal(
getComputedStyle(document.querySelector('.shared-style-target'))['border-bottom-width'],
'0px',
'lazy-in-repo-engine addon styles are not present'
);

await visit('/use-lazy-in-repo-engine');
const entriesAfter = Object.entries(window.require.entries).length;
assert.ok(!!window.require.entries['lazy-in-repo-engine/helpers/duplicated-helper']);
assert.ok(entriesAfter > entriesBefore);
assert.equal(currentURL(), '/use-lazy-in-repo-engine');
assert.dom('[data-test-lazy-in-repo-engine-main] > h1').containsText('Lazy In-Repo Engine');
assert.dom('[data-test-duplicated-helper]').containsText('from-lazy-in-repo-engine');

rules = arrayOfCSSRules(document.styleSheets, '.shared-style-target', 'content');

assert.ok(rules.includes('lazy-in-repo-engine/addon/styles/addon.css'));

await visit('/style-check');

assert.equal(
getComputedStyle(document.querySelector('.shared-style-target'))['border-left-width'],
'2px',
'eager-engine styles are still present'
);

assert.equal(
getComputedStyle(document.querySelector('.shared-style-target'))['border-bottom-width'],
'2px',
'lazy-in-repo-engine addon styles are present'
);
});

test('eager-engine', async function (assert) {
await visit('/use-eager-engine');
assert.equal(currentURL(), '/use-eager-engine');
Expand Down