1 | "use strict";
|
2 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
3 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
4 | };
|
5 | Object.defineProperty(exports, "__esModule", { value: true });
|
6 | const splitter_1 = __importDefault(require("./splitter"));
|
7 | const bundler_1 = __importDefault(require("./bundler"));
|
8 | const analyzer_1 = __importDefault(require("./analyzer"));
|
9 | const package_1 = __importDefault(require("./package"));
|
10 | const broccoli_debug_1 = require("broccoli-debug");
|
11 | const bundle_config_1 = __importDefault(require("./bundle-config"));
|
12 | const broccoli_append_1 = __importDefault(require("./broccoli-append"));
|
13 | const debugTree = broccoli_debug_1.buildDebugCallback('ember-auto-import');
|
14 | const protocol = '__ember_auto_import_protocol_v1__';
|
15 | class AutoImport {
|
16 | constructor(appOrAddon) {
|
17 | this.packages = new Set();
|
18 | this.analyzers = new Map();
|
19 | this.primaryPackage = appOrAddon;
|
20 |
|
21 | let host = appOrAddon._findHost();
|
22 | this.env = host.env;
|
23 | this.bundles = new bundle_config_1.default(host);
|
24 | if (!this.env) {
|
25 | throw new Error('Bug in ember-auto-import: did not discover environment');
|
26 | }
|
27 | this.consoleWrite = (...args) => appOrAddon.project.ui.write(...args);
|
28 | }
|
29 | static lookup(appOrAddon) {
|
30 | let g = global;
|
31 | if (!g[protocol]) {
|
32 | g[protocol] = new this(appOrAddon);
|
33 | }
|
34 | return g[protocol];
|
35 | }
|
36 | isPrimary(appOrAddon) {
|
37 | return this.primaryPackage === appOrAddon;
|
38 | }
|
39 | analyze(tree, appOrAddon) {
|
40 | let pack = package_1.default.lookup(appOrAddon);
|
41 | this.packages.add(pack);
|
42 | let analyzer = new analyzer_1.default(debugTree(tree, `preprocessor:input-${this.analyzers.size}`), pack);
|
43 | this.analyzers.set(analyzer, pack);
|
44 | return analyzer;
|
45 | }
|
46 | makeBundler(allAppTree) {
|
47 |
|
48 |
|
49 | let splitter = new splitter_1.default({
|
50 | analyzers: this.analyzers,
|
51 | bundles: this.bundles
|
52 | });
|
53 |
|
54 |
|
55 | return new bundler_1.default(allAppTree, {
|
56 | splitter,
|
57 | environment: this.env,
|
58 | packages: this.packages,
|
59 | consoleWrite: this.consoleWrite,
|
60 | bundles: this.bundles
|
61 | });
|
62 | }
|
63 | addTo(allAppTree) {
|
64 | let bundler = debugTree(this.makeBundler(allAppTree), 'output');
|
65 | let mappings = new Map();
|
66 | for (let name of this.bundles.names) {
|
67 | let byType = new Map();
|
68 | mappings.set(`entrypoints/${name}`, byType);
|
69 | for (let type of this.bundles.types) {
|
70 | let target = this.bundles.bundleEntrypoint(name, type);
|
71 | byType.set(type, target);
|
72 | }
|
73 | }
|
74 | let passthrough = new Map();
|
75 | passthrough.set('lazy', this.bundles.lazyChunkPath);
|
76 | return new broccoli_append_1.default(allAppTree, bundler, {
|
77 | mappings, passthrough
|
78 | });
|
79 | }
|
80 | included(addonInstance) {
|
81 | let host = addonInstance._findHost();
|
82 | this.configureFingerprints(host);
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 | let original = host.addonPostprocessTree.bind(host);
|
95 | host.addonPostprocessTree = (which, tree) => {
|
96 | if (which === 'all') {
|
97 | tree = this.addTo(tree);
|
98 | }
|
99 | return original(which, tree);
|
100 | };
|
101 | }
|
102 |
|
103 |
|
104 |
|
105 | configureFingerprints(host) {
|
106 | let pattern = 'assets/chunk.*.js';
|
107 | if (!host.options.fingerprint) {
|
108 | host.options.fingerprint = {};
|
109 | }
|
110 | if (!host.options.fingerprint.hasOwnProperty('exclude')) {
|
111 | host.options.fingerprint.exclude = [pattern];
|
112 | }
|
113 | else {
|
114 | host.options.fingerprint.exclude.push(pattern);
|
115 | }
|
116 | }
|
117 | updateFastBootManifest(manifest) {
|
118 | manifest.vendorFiles.push(`${this.bundles.lazyChunkPath}/auto-import-fastboot.js`);
|
119 | }
|
120 | }
|
121 | exports.default = AutoImport;
|
122 |
|
\ | No newline at end of file |