UNPKG

1.57 kBPlain TextView Raw
1/*
2 This module is the only place where we make assumptions about Ember's default
3 "app" vs "test" bundles.
4*/
5
6import { dirname } from 'path';
7const testsPattern = new RegExp(`^/?[^/]+/(tests|test-support)/`);
8
9export default class BundleConfig {
10 constructor(private emberApp: any) {}
11
12 // This list of valid bundles, in priority order. The first one in the list that
13 // needs a given import will end up with that import.
14 get names() : ReadonlyArray<string> {
15 return Object.freeze(['app', 'tests']);
16 }
17
18 get types(): ReadonlyArray<string> {
19 return Object.freeze(['js', 'css']);
20 }
21
22 // Which final JS file the given bundle's dependencies should go into.
23 bundleEntrypoint(name: string, type: string): string | undefined {
24 switch (name) {
25 case 'tests':
26 switch (type) {
27 case 'js':
28 return 'assets/test-support.js';
29 case 'css':
30 return 'assets/test-support.css';
31 }
32 case 'app':
33 switch (type) {
34 case 'js':
35 return this.emberApp.options.outputPaths.vendor.js.replace(/^\//, '');
36 case 'css':
37 return this.emberApp.options.outputPaths.vendor.css.replace(/^\//, '');
38 }
39 }
40 }
41
42 // For any relative path to a module in our application, return which bundle its
43 // imports go into.
44 bundleForPath(path: string): string {
45 if (testsPattern.test(path)) {
46 return 'tests';
47 } else {
48 return 'app';
49 }
50 }
51
52 get lazyChunkPath() {
53 return dirname(this.bundleEntrypoint(this.names[0], 'js')!);
54 }
55}