Skip to content

Commit

Permalink
feat(virtual test-support.css): implement the generation of the virtu…
Browse files Browse the repository at this point in the history
…al content
  • Loading branch information
BlueCutOfficial committed Apr 10, 2024
1 parent 1d57e06 commit cabe100
Showing 1 changed file with 52 additions and 3 deletions.
55 changes: 52 additions & 3 deletions packages/core/src/virtual-test-support-styles.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import type { Package } from '@embroider/shared-internals';
import type { V2AddonPackage } from '@embroider/shared-internals/src/package';
import { readFileSync } from 'fs';
import { sortBy } from 'lodash';
import resolve from 'resolve';
import type { Engine } from './app-files';
import type { Resolver } from './module-resolver';
import type { VirtualContentResult } from './virtual-content';

Expand All @@ -15,7 +20,51 @@ export function renderTestSupportStyles(filename: string, resolver: Resolver): V
}

function getTestSupportStyles(owner: Package, resolver: Resolver): string {
console.log(owner);
console.log(resolver);
return `h1 { color: white; }`;
let engineConfig = resolver.owningEngine(owner);
let engine: Engine = {
package: owner,
addons: new Map(
engineConfig.activeAddons.map(addon => [
resolver.packageCache.get(addon.root) as V2AddonPackage,
addon.canResolveFromFile,
])
),
isApp: true,
modulePrefix: resolver.options.modulePrefix,
appRelativePath: 'NOT_USED_DELETE_ME',
};

return generateTestSupportStyles(engine);
}

function generateTestSupportStyles(engine: Engine): string {
let result: string[] = impliedAddonTestSupportStyles(engine).map((sourcePath: string): string => {
let source = readFileSync(sourcePath);
return `${source}`;
});

return result.join('') as string;
}

function impliedAddonTestSupportStyles(engine: Engine): string[] {
let result: Array<string> = [];
for (let addon of sortBy(Array.from(engine.addons.keys()), pkg => {
switch (pkg.name) {
case 'loader.js':
return 0;
case 'ember-source':
return 10;
default:
return 1000;
}
})) {
let implicitStyles = addon.meta['implicit-test-styles'];
if (implicitStyles) {
let options = { basedir: addon.root };
for (let mod of implicitStyles) {
result.push(resolve.sync(mod, options));
}
}
}
return result;
}

0 comments on commit cabe100

Please sign in to comment.