This repository has been archived by the owner on Mar 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
105 lines (89 loc) · 2.65 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
'use strict';
const path = require('path');
const { stripIndents } = require('common-tags');
const Funnel = require('broccoli-funnel');
const mergeTrees = require('broccoli-merge-trees');
module.exports = {
name: require('./package').name,
options: {
'ember-cli-babel': {
enableTypeScriptTransform: true,
},
babel: {
plugins: [require.resolve('ember-auto-import/babel-plugin')],
},
autoImport: {
webpack: {
node: {
global: false,
__filename: true,
__dirname: true,
},
resolve: {
fallback: {
path: 'path-browserify',
},
},
},
},
},
included() {
this._super.included.apply(this, arguments);
const app = this._findHost(this);
// Adds:
// - ember-template-compiler
// - @glimmer/syntax
app.import('vendor/ember/ember-template-compiler.js');
},
/**
* This technique can't be used because it duplicates the modules
* in traditional builds. Additionally, because this way
* doesn't utilize a service worker, we can't also point all the
* imports within these files to the other files we've copied.
*/
__treeForPublic() {
const publicTree = this._super.treeForPublic.apply(this, arguments);
const app = this._findHost(this);
const root = app.project.root;
const dist = path.join(root, 'node_modules/ember-source/dist/packages');
const trees = [];
if (publicTree) {
trees.push(publicTree);
}
let packages = new Funnel(dist, {
annotation: 'ember-repl adding ember ESM from ember-source/dist/packages',
destDir: '/',
});
trees.push(packages);
return mergeTrees(trees);
},
};
/**
* Builds a file with a single export, COMPONENT_MAP, that
* is a map of the provided paths *to* all exported identifiers
* from each of the provided paths.
*
* This is helpful for building a map of imports to force to be included
* in the build - a requirement for builds that tend to tree shake.
*
* @param {string[]} paths - list of import paths for each module that you want availableb to the REPL
*/
module.exports.buildComponentMap = function buildComponentMap(paths) {
const writeFile = require('broccoli-file-creator');
const fileContent = stripIndents`
${paths
.map((path, i) => {
return `import * as ComponentMapPart${i} from '${path}';`;
})
.join('\n')}
export const COMPONENT_MAP = {
${paths
.map((path, i) => {
return `'${path}': ComponentMapPart${i},`;
})
.join('\n')}
};
`;
const tree = writeFile('/ember-repl/component-map.js', fileContent);
return tree;
};