Skip to content

Commit

Permalink
fix: remove unnecessary dependencies (#583)
Browse files Browse the repository at this point in the history
* fix: remove unnecessary dependencies

Remove some unnecessary dependencies and/or moves them to dev dependencies.

Also updates some other packages that where left behind.

* node18
  • Loading branch information
mrgrain authored Apr 26, 2024
1 parent 3622c77 commit edd03e2
Show file tree
Hide file tree
Showing 14 changed files with 691 additions and 970 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml

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

6 changes: 3 additions & 3 deletions .github/workflows/release.yml

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

2 changes: 1 addition & 1 deletion .github/workflows/upgrade-dev-deps-main.yml

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

2 changes: 1 addition & 1 deletion .github/workflows/upgrade-main.yml

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

18 changes: 5 additions & 13 deletions .projen/deps.json

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

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

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

9 changes: 3 additions & 6 deletions .projenrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,19 @@ const project = new CdklabsTypeScriptProject({
'@jsii/spec',
'jsii-reflect',
'jsii-rosetta',
'jsii',
'fs-extra',
'yargs',
],
devDeps: [
'cdklabs-projen-project-types',
'@types/jest',
'@types/yargs',
'cdklabs-projen-project-types',
'jest',
'@types/fs-extra',
'jsii',
'typescript',
],
releaseToNpm: true,
gitignore: ['*.js', '*.d.ts'],
workflowNodeVersion: '16.x',
minNodeVersion: '16.0.0',
workflowNodeVersion: '18.x',
enablePRAutoMerge: true,
setNodeEngineVersion: false,
});
Expand Down
17 changes: 8 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## CDK Generate Synthetic Examples
# CDK Generate Synthetic Examples

This tool will find all classes in the JSII assembly that don't yet have
any example code associated with them, and will generate a synthetic
Expand All @@ -8,16 +8,15 @@ all classes get something usable (which otherwise would not have any
examples at all). It is designed to run during the build of a CDK Construct
Library.

### Install
## Install

This tool is published as an npm module, so it can be either installed
locally or globally via:
This tool is published as an npm module, install locally:

```bash
npm i -g cdk-generate-synthetic-examples
npm install cdk-generate-synthetic-examples
```

### Usage
## Usage

Suppose you are in the base directory of your CDK construct, `aws-construct`.
After a successful build, you have a `.jsii` file.
Expand All @@ -36,11 +35,11 @@ npx cdk-generate-synthetic-examples .jsii

A common workflow is to run `cdk-generate-synthetic-examples` sandwiched
between calls to [`rosetta:extract`](https://www.npmjs.com/package/jsii-rosetta).
The first `rosetta:extract` will extract any possible hand-written examples
into your assembly. The second `rosetta:extract` will then compile and
The first `rosetta:extract` will extract any possible hand-written examples
into your assembly. The second `rosetta:extract` will then compile and
translate the new synthetic examples.

The `--extract` flag is simply a helper that does the second `rosetta:extract`
The `--extract` flag is simply a helper that does the second `rosetta:extract`
call for you.

```bash
Expand Down
26 changes: 13 additions & 13 deletions package.json

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

2 changes: 1 addition & 1 deletion src/assemblies.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as fs from 'fs';
import * as path from 'path';
import { Type } from '@jsii/spec';
import * as fs from 'fs-extra';
import { FIXTURE_NAME } from './generate-missing-examples';

export function addFixtureToRosetta(directory: string, fileName: string, fixture: string) {
Expand Down
4 changes: 2 additions & 2 deletions src/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export function generateAssignmentStatement(type: reflect.ClassType | reflect.In
context.rendered.add(type.fqn);

if (type.isClassType()) {
const expression = exampleValueForClass(context, type, 0);
const expression = exampleValueForClass(context, type as reflect.ClassType, 0);
if (!expression) { return undefined; }
return Code.concatAll(
`const ${escapeIdentifier(lowercaseFirstLetter(type.name))} = `,
Expand All @@ -85,7 +85,7 @@ export function generateAssignmentStatement(type: reflect.ClassType | reflect.In
}

if (type.isInterfaceType()) {
const expression = exampleValueForStruct(context, type, 0);
const expression = exampleValueForStruct(context, type as reflect.InterfaceType, 0);
if (!expression) { return undefined; }

return Code.concatAll(
Expand Down
10 changes: 5 additions & 5 deletions test/generate-missing-examples.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as fs from 'fs';
import * as path from 'path';
import { SPEC_FILE_NAME, SPEC_FILE_NAME_COMPRESSED } from '@jsii/spec';
import * as fs from 'fs-extra';

import { LanguageTablet, TargetLanguage } from 'jsii-rosetta';
import { DUMMY_ASSEMBLY_TARGETS, AssemblyFixture } from './testutil';
import { generateMissingExamples } from '../lib/generate-missing-examples';
import { generateMissingExamples } from '../src/generate-missing-examples';

test('@aws-cdk/core special case', async () => {
const assembly = await AssemblyFixture.fromSource(
Expand Down Expand Up @@ -33,7 +33,7 @@ test('@aws-cdk/core special case', async () => {

const generatedFixture = path.join(assembly.directory, 'rosetta', '_generated.ts-fixture');

const file = await fs.readFile(generatedFixture, 'utf-8');
const file = fs.readFileSync(generatedFixture, { encoding: 'utf-8' });
expect(file.startsWith('import { Construct } from "@aws-cdk/core";')).toBeTruthy();
} finally {
await assembly.cleanup();
Expand Down Expand Up @@ -121,7 +121,7 @@ test('test end-to-end and translation to Python with compressed assembly', async
try {
// ensure the compressed assembly exists and the file at SPEC_FILE_NAME is a redirect schema
expect(fs.existsSync(path.join(assembly.directory, SPEC_FILE_NAME_COMPRESSED))).toBeTruthy();
const schema = await fs.readJson(path.join(assembly.directory, SPEC_FILE_NAME), { encoding: 'utf-8' });
const schema = JSON.parse(fs.readFileSync(path.join(assembly.directory, SPEC_FILE_NAME), { encoding: 'utf-8' }));
expect(schema).toEqual({
schema: 'jsii/file-redirect',
compression: 'gzip',
Expand All @@ -137,7 +137,7 @@ test('test end-to-end and translation to Python with compressed assembly', async
});

// ensure the file at SPEC_FILE_NAME is still a redirect schema
expect(await fs.readJson(path.join(assembly.directory, SPEC_FILE_NAME), { encoding: 'utf-8' })).toEqual({
expect(JSON.parse(fs.readFileSync(path.join(assembly.directory, SPEC_FILE_NAME), { encoding: 'utf-8' }))).toEqual({
schema: 'jsii/file-redirect',
compression: 'gzip',
filename: SPEC_FILE_NAME_COMPRESSED,
Expand Down
18 changes: 10 additions & 8 deletions test/testutil.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as fs from 'fs';
import * as os from 'os';
import * as path from 'path';
import { writeAssembly } from '@jsii/spec';
import * as fs from 'fs-extra';
import { PackageInfo, compileJsiiForTest } from 'jsii';

export type MultipleSources = { [key: string]: string; 'index.ts': string };
Expand Down Expand Up @@ -31,27 +31,29 @@ export class AssemblyFixture {
//
// In fact we will drop them in 'node_modules/<name>' so they can be imported
// as if they were installed.
const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'jsii-rosetta'));
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'jsii-rosetta'));
const modDir = path.join(tmpDir, 'node_modules', packageInfo.name);
await fs.ensureDir(modDir);
if (!fs.existsSync(modDir)) {
fs.mkdirSync(modDir, { recursive: true });
}

writeAssembly(modDir, assembly, { compress: options.compressAssembly });
await fs.writeJSON(path.join(modDir, 'package.json'), {
fs.writeFileSync(path.join(modDir, 'package.json'), JSON.stringify({
name: packageInfo.name,
jsii: packageInfo.jsii,
});
}, null, 2));
for (const [fileName, fileContents] of Object.entries(files)) {
// eslint-disable-next-line no-await-in-loop
await fs.writeFile(path.join(modDir, fileName), fileContents);
fs.writeFileSync(path.join(modDir, fileName), fileContents);
}

return new AssemblyFixture(modDir);
}

private constructor(public readonly directory: string) {}

public async cleanup() {
await fs.remove(this.directory);
public cleanup() {
fs.rmSync(this.directory, { recursive: true });
}
}

Expand Down
Loading

0 comments on commit edd03e2

Please sign in to comment.