Skip to content

Commit

Permalink
Merge pull request #330 from rwjblue/fix-bundle-name-for-bundleForTre…
Browse files Browse the repository at this point in the history
…eType

Ensure `bundleForTreeType` returns the proper values.
  • Loading branch information
ef4 authored Dec 15, 2020
2 parents d748424 + 4778225 commit ebad14b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/ember-auto-import/ts/analyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ makeDebug.formatters.m = (modules: Import[]) => {

const debug = makeDebug('ember-auto-import:analyzer');

export type TreeType = 'app' | 'addon' | 'addon-test-support' | 'test';
export type TreeType = 'app' | 'addon' | 'addon-templates' | 'addon-test-support' | 'styles' | 'templates' | 'test';

export interface Import {
path: string;
Expand Down
30 changes: 21 additions & 9 deletions packages/ember-auto-import/ts/bundle-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,61 +9,73 @@ const testsPattern = new RegExp(`^/?[^/]+/(tests|test-support)/`);

import type { TreeType } from './analyzer';

function exhausted(value: never): never {
throw new Error(`Unknown tree type specified: ${value}`);
function exhausted(label: string, value: never): never {
throw new Error(`Unknown ${label} specified: ${value}`);
}

export type BundleName = 'app' | 'tests';
export type BundleType = 'js' | 'css';

export default class BundleConfig {
constructor(private emberApp: AppInstance) {}

// This list of valid bundles, in priority order. The first one in the list that
// needs a given import will end up with that import.
get names() : ReadonlyArray<string> {
get names() : ReadonlyArray<BundleName> {
return Object.freeze(['app', 'tests']);
}

get types(): ReadonlyArray<string> {
get types(): ReadonlyArray<BundleType> {
return Object.freeze(['js', 'css']);
}

// Which final JS file the given bundle's dependencies should go into.
bundleEntrypoint(name: string, type: string): string | undefined {
bundleEntrypoint(name: BundleName, type: BundleType): string | undefined {
switch (name) {
case 'tests':
switch (type) {
case 'js':
return 'assets/test-support.js';
case 'css':
return 'assets/test-support.css';
default:
exhausted('test bundle type', type);
}
case 'app':
switch (type) {
case 'js':
return this.emberApp.options.outputPaths.vendor.js.replace(/^\//, '');
case 'css':
return this.emberApp.options.outputPaths.vendor.css.replace(/^\//, '');
default:
exhausted('app bundle type', type);
}
default:
exhausted('bundle name', name);
}
}

bundleForTreeType(treeType: TreeType) {
bundleForTreeType(treeType: TreeType): BundleName {
switch (treeType) {
case 'app':
case 'addon':
case 'addon-templates':
case 'styles':
case 'templates':
return 'app';

case 'addon-test-support':
case 'test':
return 'test';
return 'tests';

default:
exhausted(treeType);
exhausted('bundle name', treeType);
}
}

// For any relative path to a module in our application, return which bundle its
// imports go into.
bundleForPath(path: string): string {
bundleForPath(path: string): BundleName {
if (testsPattern.test(path)) {
return 'tests';
} else {
Expand Down

0 comments on commit ebad14b

Please sign in to comment.