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

fix(pacmak): fails on bundled dependency without entry point #3277

Merged
merged 5 commits into from
Dec 22, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 7 additions & 1 deletion packages/jsii-pacmak/lib/dependency-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export interface TraverseDependencyGraphHost {
export interface PackageJson {
readonly dependencies?: { readonly [name: string]: string };
readonly peerDependencies?: { readonly [name: string]: string };
readonly bundledDependencies?: string[];
rix0rrr marked this conversation as resolved.
Show resolved Hide resolved

readonly [key: string]: unknown;
}
Expand Down Expand Up @@ -88,7 +89,12 @@ async function real$traverseDependencyGraph(
]);
return Promise.all(
Array.from(deps)
.filter((m) => !util.isBuiltinModule(m))
// No need to pacmak the dependency if it's built-in, or if it's bundled
.filter(
(m) =>
!util.isBuiltinModule(m) &&
!(meta.bundledDependencies ?? []).includes(m),
rix0rrr marked this conversation as resolved.
Show resolved Hide resolved
)
.map(async (dep) => {
const dependencyDir = await host.findDependencyDirectory(
dep,
Expand Down
38 changes: 38 additions & 0 deletions packages/jsii-pacmak/test/dependency-graph.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,41 @@ test('stops traversing when callback returns false', async () => {
expect(mockHost.readJson).toHaveBeenCalledTimes(2);
expect(mockHost.findDependencyDirectory).toHaveBeenCalledTimes(1);
});

test('dont call findDependencyDirectory for bundledDependencies', async () => {
rix0rrr marked this conversation as resolved.
Show resolved Hide resolved
// GIVEN the following package dependency graph:
// A -> B -> C
const packages: Record<string, { root: string; meta: any }> = {
A: {
root: join(tmpdir(), 'A'),
meta: { dependencies: { B: '*' }, bundledDependencies: ['B'] },
},
};

const cb: Callback = jest.fn().mockName('callback').mockReturnValue(true);

mockHost.readJson.mockImplementation((file) => {
const result = Object.values(packages).find(
({ root }) => file === join(root, 'package.json'),
)?.meta;
return result != null
? Promise.resolve(result)
: Promise.reject(new Error(`Unexpected file access: ${file}`));
});

mockHost.findDependencyDirectory.mockImplementation(async (dep, _dir) => {
const result = packages[dep]?.root;
if (result == null) {
throw new Error(`Unknown dependency: ${dep}`);
}
return result;
});

// WHEN
await expect(
traverseDependencyGraph(packages.A.root, cb, mockHost),
).resolves.not.toThrow();

// THEN
expect(mockHost.findDependencyDirectory).not.toHaveBeenCalled();
});