Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add exclude option to appReexports and publicEntrypoints rollup plugins #1760

Merged
merged 2 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/addon-dev/src/rollup-app-reexports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default function appReexports(opts: {
from: string;
to: string;
include: string[];
exclude?: string[];
mapFilename?: (filename: string) => string;
exports?: (filename: string) => string[] | string | undefined;
}): Plugin {
Expand All @@ -26,7 +27,8 @@ export default function appReexports(opts: {

if (
opts.include.some((glob) => minimatch(addonFilename, glob)) &&
!minimatch(addonFilename, '**/*.d.ts')
!minimatch(addonFilename, '**/*.d.ts') &&
opts.exclude?.some((glob) => minimatch(addonFilename, glob)) !== true
) {
appJS[`./${appFilename}`] = `./dist/_app_/${appFilename}`;
this.emitFile({
Expand Down
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
10 changes: 8 additions & 2 deletions packages/addon-dev/src/rollup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export class Addon {
opts: {
mapFilename?: (fileName: string) => string;
exports?: (filename: string) => string[] | string | undefined;
exclude?: string[];
} = {}
): Plugin {
return appReexports({
Expand All @@ -34,14 +35,19 @@ export class Addon {
include: patterns,
mapFilename: opts.mapFilename,
exports: opts.exports,
exclude: opts.exclude,
});
}

// 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
20 changes: 17 additions & 3 deletions tests/scenarios/v2-addon-dev-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,13 @@ appScenarios
plugins: [
addon.publicEntrypoints([
'components/**/*.js',
]),
], {
exclude: ['**/-excluded/**/*'],
}),

addon.appReexports(['components/**/*.js'], {
mapFilename: (name) => reexportMappings[name] || name,
exclude: ['**/-excluded/**/*'],
}),

addon.hbs(),
Expand Down Expand Up @@ -141,6 +144,11 @@ appScenarios
<div data-test="should-transform">{{transformMe}}</div>
`,
},
'-excluded': {
'never-import-this.js': `
throw new Exception('This should never have been imported!');
`,
},
},
},
});
Expand Down Expand Up @@ -241,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
Loading