Skip to content

Commit

Permalink
Add exclude option to publicEntrypoints rollup plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
simonihmig committed Jan 17, 2024
1 parent b1b3814 commit 853f2e7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
2 changes: 2 additions & 0 deletions packages/addon-dev/src/rollup-public-entrypoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ function normalizeFileExt(fileName: string) {
export default function publicEntrypoints(args: {
srcDir: string;
include: string[];
exclude?: string[];
}): Plugin {
return {
name: 'addon-modules',
Expand All @@ -19,6 +20,7 @@ export default function publicEntrypoints(args: {

let matches = walkSync(args.srcDir, {
globs: [...args.include, '**/*.hbs', '**/*.ts', '**/*.gts', '**/*.gjs'],
ignore: args.exclude,
});

for (let name of matches) {
Expand Down
8 changes: 6 additions & 2 deletions packages/addon-dev/src/rollup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,12 @@ export class Addon {
// This configures rollup to emit public entrypoints for each module in your
// srcDir that matches one of the given globs. Typical addons will want to
// match patterns like "components/**/*.js", "index.js", and "test-support.js".
publicEntrypoints(patterns: string[]) {
return publicEntrypoints({ srcDir: this.#srcDir, include: patterns });
publicEntrypoints(patterns: string[], opts: { exclude?: string[] } = {}) {
return publicEntrypoints({
srcDir: this.#srcDir,
include: patterns,
exclude: opts.exclude,
});
}

// This wraps standalone .hbs files as Javascript files using inline
Expand Down
14 changes: 11 additions & 3 deletions tests/scenarios/v2-addon-dev-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ appScenarios
plugins: [
addon.publicEntrypoints([
'components/**/*.js',
]),
], {
exclude: ['**/-excluded/**/*'],
}),
addon.appReexports(['components/**/*.js'], {
mapFilename: (name) => reexportMappings[name] || name,
Expand Down Expand Up @@ -247,11 +249,17 @@ appScenarios
});
});

test('the addon was built successfully', async function () {
test('the addon has expected public entrypoints', async function () {
expectFile('dist/components/demo/index.js').exists();
expectFile('dist/components/demo/out.js').exists();
expectFile('dist/components/demo/namespace-me.js').exists();
expectFile('dist/components/-excluded/never-import-this.js').doesNotExist();
});

test('the addon has expected app-reexports', async function () {
expectFile('dist/_app_/components/demo/index.js').matches(
'export { default } from "v2-addon/components/demo/index"'
);

expectFile('dist/_app_/components/demo/out.js').matches(
'export { default } from "v2-addon/components/demo/out"'
);
Expand Down

0 comments on commit 853f2e7

Please sign in to comment.