-
Notifications
You must be signed in to change notification settings - Fork 137
/
rollup-public-entrypoints.ts
56 lines (51 loc) · 1.64 KB
/
rollup-public-entrypoints.ts
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
import walkSync from 'walk-sync';
import { join } from 'path';
import minimatch from 'minimatch';
import type { Plugin } from 'rollup';
import { pathExistsSync } from 'fs-extra';
function normalizeFileExt(fileName: string) {
return fileName.replace(/\.ts|\.hbs|\.gts|\.gjs$/, '.js');
}
const hbsPattern = '**/*.hbs';
export default function publicEntrypoints(args: {
srcDir: string;
include: string[];
}): Plugin {
return {
name: 'addon-modules',
async buildStart() {
let matches = walkSync(args.srcDir, {
globs: [...args.include, hbsPattern],
});
for (let name of matches) {
if (args.include.some((pattern) => minimatch(name, pattern))) {
// anything that matches one of the user's patterns is definitely emitted
this.emitFile({
type: 'chunk',
id: join(args.srcDir, name),
fileName: normalizeFileExt(name),
});
} else {
// this file didn't match one of the user's patterns, so it must match
// our hbsPattern. Infer the possible existence of a synthesized
// template-only component JS file and test whether that file would
// match the user's patterns.
let normalizedName = normalizeFileExt(name);
let id = join(args.srcDir, normalizedName);
if (
args.include.some((pattern) =>
minimatch(normalizedName, pattern)
) &&
!pathExistsSync(id)
) {
this.emitFile({
type: 'chunk',
id,
fileName: normalizedName,
});
}
}
}
},
};
}