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

Sort addon css by package name #1866

Draft
wants to merge 3 commits into
base: stable
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 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
10 changes: 9 additions & 1 deletion packages/compat/src/compat-app-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,15 @@ export class CompatAppBuilder {

private impliedAddonAssets(type: keyof ImplicitAssetPaths, { engine }: AppFiles): string[] {
let result: Array<string> = [];
for (let addon of sortBy(Array.from(engine.addons), this.scriptPriority.bind(this))) {
let addons: Array<AddonPackage> = sortBy(Array.from(engine.addons), this.scriptPriority.bind(this));
if (type === 'implicit-styles') {
const synthesizedVendor = addons.find(pkg => pkg.name === '@embroider/synthesized-vendor');
if (synthesizedVendor) {
addons = sortBy(addons, pkg => pkg.name).filter(pkg => pkg !== synthesizedVendor);
addons.unshift(synthesizedVendor);
}
}
for (let addon of addons) {
let implicitScripts = addon.meta[type];
if (implicitScripts) {
let styles = [];
Expand Down
82 changes: 81 additions & 1 deletion tests/scenarios/compat-addon-styles-test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { ExpectFile } from '@embroider/test-support/file-assertions/qunit';
import { expectFilesAt, expectRewrittenFilesAt } from '@embroider/test-support/file-assertions/qunit';
import type { PreparedApp } from 'scenario-tester';
import type { PreparedApp, Project } from 'scenario-tester';
import { throwOnWarnings } from '@embroider/core';
import { appScenarios, baseAddon } from './scenarios';
import QUnit from 'qunit';
Expand Down Expand Up @@ -132,3 +132,83 @@ appScenarios
});
});
});

function setAddonNameAndCSS(addon: Project, letter: string) {
addon.pkg.name = `addon-${letter}`;
merge(addon.files, {
addon: {
styles: {
'addon.css': `.addon-${letter} {}`,
},
},
});
}

appScenarios
.map('compat-addon-styles', project => {
raycohen marked this conversation as resolved.
Show resolved Hide resolved
const addonA: Project = baseAddon();
setAddonNameAndCSS(addonA, 'a');

const addonB = baseAddon();
setAddonNameAndCSS(addonB, 'b');

const addonC = baseAddon();
setAddonNameAndCSS(addonC, 'c');

const addonD = baseAddon();
setAddonNameAndCSS(addonD, 'd');

project.addDependency(addonA);
project.addDependency(addonB);
addonA.addDependency(addonC);
project.addDependency(addonD);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test without the logic change gave c->a->b->d ordering


project.addDependency('third-party', '1.2.3').files = {
'third-party.css': '.third-party {}',
};

merge(project.files, {
'ember-cli-build.js': `
'use strict';

const EmberApp = require('ember-cli/lib/broccoli/ember-app');
const { maybeEmbroider } = require('@embroider/test-setup');

module.exports = function (defaults) {
let app = new EmberApp(defaults, {});
app.import('node_modules/third-party/third-party.css');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add more of these so we get coverage on the order between app.import calls as well


return maybeEmbroider(app, {
skipBabel: [
{
package: 'qunit',
},
],
});
};`,
});
})
.forEachScenario(scenario => {
Qmodule(scenario.name, function (hooks) {
throwOnWarnings(hooks);

let app: PreparedApp;

let expectFile: ExpectFile;

hooks.before(async assert => {
app = await scenario.prepare();
let result = await app.execute('ember build', { env: { STAGE2_ONLY: 'true' } });
assert.equal(result.exitCode, 0, result.output);
});

hooks.beforeEach(assert => {
expectFile = expectFilesAt(app.dir, { qunit: assert });
});

test('addon styles are in order', function () {
const vendorCssPath = './node_modules/.embroider/rewritten-app/assets/vendor.css';
expectFile(vendorCssPath).matches(/third-party.*addon-a.*addon-b.*addon-c.*addon-d/);
});
});
});
Loading