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

chore: revert support for nested submodules #1354

Merged
merged 1 commit into from
Nov 14, 2023
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: 4 additions & 0 deletions .projen/deps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions .projen/tasks.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .projenrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const project = new CdklabsConstructLibrary({
'fs-extra',
'got',
'JSONStream',
'jsii-reflect',
'semver',
'spdx-license-list',
'streamx',
Expand Down
1 change: 1 addition & 0 deletions package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions src/__tests__/__snapshots__/construct-hub.test.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

72 changes: 49 additions & 23 deletions src/__tests__/backend/transliterator/transliterator.ecstask.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { MarkdownDocument } from 'jsii-docgen/lib/docgen/render/markdown-doc';
import { MarkdownRenderer } from 'jsii-docgen/lib/docgen/render/markdown-render';
import { Documentation } from 'jsii-docgen/lib/docgen/view/documentation';

import { Submodule } from 'jsii-reflect';
import type { TransliteratorInput } from '../../../backend/payload-schema';
import { reset } from '../../../backend/shared/aws.lambda-shared';
import * as constants from '../../../backend/shared/constants';
Expand Down Expand Up @@ -93,6 +94,10 @@ describe('VPC Endpoints', () => {
};
}
}

public async listSubmodules(): Promise<Submodule[]> {
return [];
}
}

forPackage.mockImplementation(async (_: string) => {
Expand Down Expand Up @@ -229,6 +234,9 @@ test('corrupt assembly marker is uploaded for the necessary languages', async ()
public async toJson() {
throw new CorruptedAssemblyError();
}
public async listSubmodules(): Promise<Submodule[]> {
return [];
}
}

forPackage.mockImplementation(async (_: string) => {
Expand Down Expand Up @@ -286,6 +294,9 @@ test('corrupt assembly and uninstallable markers are deleted', async () => {
public async toJson() {
return new MarkdownDocument();
}
public async listSubmodules(): Promise<Submodule[]> {
return [];
}
}

forPackage.mockImplementation(async (_: string) => {
Expand Down Expand Up @@ -392,14 +403,29 @@ test('uploads a file per language (scoped package)', async () => {
});

test('uploads a file per submodule (unscoped package)', async () => {
// GIVEN
const assembly: spec.Assembly = {
targets: { python: {} },
submodules: {
'@scope/package-name.sub1': {},
'@scope/package-name.sub2': {},
},
} as any;

const submodules: Submodule[] = Object.keys(assembly.submodules ?? {}).map(
(sm) => ({ name: sm.substring(sm.indexOf('.') + 1) } as any)
);

// eslint-disable-next-line @typescript-eslint/no-require-imports
const forPackage = require('jsii-docgen').Documentation
.forPackage as jest.MockedFunction<typeof Documentation.forPackage>;
forPackage.mockImplementation(async (target: string) => {
return new MockDocumentation(target) as unknown as Documentation;
return new MockDocumentation(
target,
submodules
) as unknown as Documentation;
});

// GIVEN
const packageName = 'package-name';
const packageVersion = '1.2.3-dev.4';
const event: TransliteratorInput = {
Expand All @@ -415,15 +441,6 @@ test('uploads a file per submodule (unscoped package)', async () => {
languages: { typescript: true },
};

const assembly: spec.Assembly = {
targets: { python: {} },
submodules: {
'@scope/package-name.sub1': {},
'@scope/package-name.sub2': {},
'@scope/package-name.sub2.nested': {},
},
} as any;

// mock the s3ObjectExists call
mockHeadRequest('package.tgz');

Expand All @@ -435,24 +452,22 @@ test('uploads a file per submodule (unscoped package)', async () => {
'/docs-typescript.md',
'/docs-sub1-typescript.md',
'/docs-sub2-typescript.md',
'/docs-sub2.nested-typescript.md',
'/docs-typescript.json',
'/docs-sub1-typescript.json',
'/docs-sub2-typescript.json',
'/docs-sub2.nested-typescript.json'
'/docs-sub2-typescript.json'
);

// WHEN
const { created } = await handler(event);

// THEN
expect(created).toEqual([
`data/${packageName}/v${packageVersion}/docs-typescript.json`,
`data/${packageName}/v${packageVersion}/docs-typescript.md`,
`data/${packageName}/v${packageVersion}/docs-sub1-typescript.json`,
`data/${packageName}/v${packageVersion}/docs-sub1-typescript.md`,
`data/${packageName}/v${packageVersion}/docs-sub2-typescript.json`,
`data/${packageName}/v${packageVersion}/docs-sub2-typescript.md`,
`data/${packageName}/v${packageVersion}/docs-sub2.nested-typescript.json`,
`data/${packageName}/v${packageVersion}/docs-sub2.nested-typescript.md`,
]);
});

Expand Down Expand Up @@ -517,6 +532,12 @@ test.each([true, false])(

describe('markers for un-supported languages', () => {
test('uploads ".not-supported" markers as relevant', async () => {
// GIVEN
const assembly: spec.Assembly = {
targets: { phony: {} },
submodules: { 'package-name.sub1': {}, 'package-name.sub2': {} },
} as any;

// eslint-disable-next-line @typescript-eslint/no-require-imports
const forPackage = require('jsii-docgen').Documentation
.forPackage as jest.MockedFunction<typeof Documentation.forPackage>;
Expand All @@ -525,13 +546,17 @@ describe('markers for un-supported languages', () => {
public async toJson() {
throw new LanguageNotSupportedError();
}
public async listSubmodules(): Promise<Submodule[]> {
return Object.keys(assembly.submodules ?? {}).map(
(sm) => ({ name: sm.substring(sm.indexOf('.') + 1) } as any)
);
}
}

forPackage.mockImplementation(async (_: string) => {
return new MockDocumentation() as unknown as Documentation;
});

// GIVEN
const packageName = 'package-name';
const packageVersion = '1.2.3-dev.4';

Expand All @@ -549,11 +574,6 @@ describe('markers for un-supported languages', () => {
languages: { python: true },
};

const assembly: spec.Assembly = {
targets: { phony: {} },
submodules: { 'package-name.sub1': {}, 'package-name.sub2': {} },
} as any;

// mock the s3ObjectExists call
mockHeadRequest('package.tgz');

Expand Down Expand Up @@ -584,12 +604,18 @@ describe('markers for un-supported languages', () => {
});

class MockDocumentation {
public constructor(private readonly target: string) {}
public constructor(
private readonly target: string,
private readonly submodules?: Submodule[]
) {}
public async toJson() {
return {
render: () => `{ "content": "docs for ${this.target}" }`,
};
}
public async listSubmodules(): Promise<Submodule[]> {
return this.submodules ?? [];
}
}

function mockFetchRequests(assembly: spec.Assembly, tarball: Buffer) {
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/devapp/__snapshots__/snapshot.test.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions src/backend/transliterator/transliterator.ecstask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ export function handler(
assemblyResponse.Body.toString('utf-8')
) as Assembly;
const submodules = Object.keys(assembly.submodules ?? {}).map(
// Drop the first component, which is the name of the top-level module
(s) => s.split('.').slice(1).join('.')
(s) => s.split('.')[1]
);
console.log(
`Assembly ${assembly.name} has ${submodules.length} submodules.`
Expand Down Expand Up @@ -302,7 +301,10 @@ export function handler(
}
}
await renderAndDispatch();
for (const submodule of submodules) {
const submoduleNames = (await docs.listSubmodules()).map(
(sm) => sm.name
);
for (const submodule of submoduleNames) {
await renderAndDispatch(submodule);
}
}
Expand Down