Skip to content

Commit 5275da6

Browse files
chore(deps): Update attrs requirement from ~=21.2 to >=21.2,<23.0 in /packages/@jsii/python-runtime (#3692)
Updates the requirements on [attrs](https://github.com/python-attrs/attrs) to permit the latest version. <details> <summary>Release notes</summary> <p><em>Sourced from <a href="https://github.com/python-attrs/attrs/releases">attrs's releases</a>.</em></p> <blockquote> <h2>22.1.0</h2> <h1>Highlights</h1> <p>The main features of this release are:</p> <ul> <li>The departure of Python 2.7 (enjoy your retirement!),</li> <li>and the arrival of Python 3.11.</li> </ul> <p>We had loftier goals feature-wise, but didn't want to block others embracing Python 3.11.</p> <p>❤️ <strong>Huge</strong> thanks to my <a href="https://github.com/sponsors/hynek">GitHub sponsors</a>, <a href="https://tidelift.com/subscription/pkg/pypi-attrs">Tidelift subscribers</a>, and <a href="https://ko-fi.com/the_hynek">Ko-fi buyers</a>! ❤️</p> <p>None of my projects would exist in their current form without you!</p> <h1>Full Changelog</h1> <h2>Backwards-incompatible Changes</h2> <ul> <li> <p>Python 2.7 is not supported anymore.</p> <p>Dealing with Python 2.7 tooling has become too difficult for a volunteer-run project.</p> <p>We have supported Python 2 more than 2 years after it was officially discontinued and feel that we have paid our dues. All version up to 21.4.0 from December 2021 remain fully functional, of course. <a href="https://github-redirect.dependabot.com/python-attrs/attrs/issues/936">#936</a></p> </li> <li> <p>The deprecated <code>cmp</code> attribute of <code>attrs.Attribute</code> has been removed. This does not affect the <em>cmp</em> argument to <code>attr.s</code> that can be used as a shortcut to set <em>eq</em> and <em>order</em> at the same time. <a href="https://github-redirect.dependabot.com/python-attrs/attrs/issues/939">#939</a></p> </li> </ul> <h2>Changes</h2> <ul> <li>Instantiation of frozen slotted classes is now faster. <a href="https://github-redirect.dependabot.com/python-attrs/attrs/issues/898">#898</a></li> <li>If an <code>eq</code> key is defined, it is also used before hashing the attribute. <a href="https://github-redirect.dependabot.com/python-attrs/attrs/issues/909">#909</a></li> <li>Added <code>attrs.validators.min_len()</code>. <a href="https://github-redirect.dependabot.com/python-attrs/attrs/issues/916">#916</a></li> <li><code>attrs.validators.deep_iterable()</code>'s <em>member_validator</em> argument now also accepts a list of validators and wraps them in an <code>attrs.validators.and_()</code>. <a href="https://github-redirect.dependabot.com/python-attrs/attrs/issues/925">#925</a></li> <li>Added missing type stub re-imports for <code>attrs.converters</code> and <code>attrs.filters</code>. <a href="https://github-redirect.dependabot.com/python-attrs/attrs/issues/931">#931</a></li> <li>Added missing stub for <code>attr(s).cmp_using()</code>. <a href="https://github-redirect.dependabot.com/python-attrs/attrs/issues/949">#949</a></li> <li><code>attrs.validators._in()</code>'s <code>ValueError</code> is not missing the attribute, expected options, and the value it got anymore. <a href="https://github-redirect.dependabot.com/python-attrs/attrs/issues/951">#951</a></li> <li>Python 3.11 is now officially supported. <a href="https://github-redirect.dependabot.com/python-attrs/attrs/issues/969">#969</a></li> </ul> </blockquote> </details> <details> <summary>Changelog</summary> <p><em>Sourced from <a href="https://github.com/python-attrs/attrs/blob/main/CHANGELOG.rst">attrs's changelog</a>.</em></p> <blockquote> <h2>22.1.0 (2022-07-28)</h2> <p>Backwards-incompatible Changes ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^</p> <ul> <li> <p>Python 2.7 is not supported anymore.</p> <p>Dealing with Python 2.7 tooling has become too difficult for a volunteer-run project.</p> <p>We have supported Python 2 more than 2 years after it was officially discontinued and feel that we have paid our dues. All version up to 21.4.0 from December 2021 remain fully functional, of course. <code>[#936](python-attrs/attrs#936) &lt;https://github.com/python-attrs/attrs/issues/936&gt;</code>_</p> </li> <li> <p>The deprecated <code>cmp</code> attribute of <code>attrs.Attribute</code> has been removed. This does not affect the <em>cmp</em> argument to <code>attr.s</code> that can be used as a shortcut to set <em>eq</em> and <em>order</em> at the same time. <code>[#939](python-attrs/attrs#939) &lt;https://github.com/python-attrs/attrs/issues/939&gt;</code>_</p> </li> </ul> <p>Changes ^^^^^^^</p> <ul> <li>Instantiation of frozen slotted classes is now faster. <code>[#898](python-attrs/attrs#898) &lt;https://github.com/python-attrs/attrs/issues/898&gt;</code>_</li> <li>If an <code>eq</code> key is defined, it is also used before hashing the attribute. <code>[#909](python-attrs/attrs#909) &lt;https://github.com/python-attrs/attrs/issues/909&gt;</code>_</li> <li>Added <code>attrs.validators.min_len()</code>. <code>[#916](python-attrs/attrs#916) &lt;https://github.com/python-attrs/attrs/issues/916&gt;</code>_</li> <li><code>attrs.validators.deep_iterable()</code>'s <em>member_validator</em> argument now also accepts a list of validators and wraps them in an <code>attrs.validators.and_()</code>. <code>[#925](python-attrs/attrs#925) &lt;https://github.com/python-attrs/attrs/issues/925&gt;</code>_</li> <li>Added missing type stub re-imports for <code>attrs.converters</code> and <code>attrs.filters</code>. <code>[#931](python-attrs/attrs#931) &lt;https://github.com/python-attrs/attrs/issues/931&gt;</code>_</li> <li>Added missing stub for <code>attr(s).cmp_using()</code>. <code>[#949](python-attrs/attrs#949) &lt;https://github.com/python-attrs/attrs/issues/949&gt;</code>_</li> <li><code>attrs.validators._in()</code>'s <code>ValueError</code> is not missing the attribute, expected options, and the value it got anymore. <code>[#951](python-attrs/attrs#951) &lt;https://github.com/python-attrs/attrs/issues/951&gt;</code>_</li> <li>Python 3.11 is now officially supported. <code>[#969](python-attrs/attrs#969) &lt;https://github.com/python-attrs/attrs/issues/969&gt;</code>_</li> </ul> <hr /> <h2>21.4.0 (2021-12-29)</h2> <p>Changes ^^^^^^^</p> <ul> <li>Fixed the test suite on PyPy3.8 where <code>cloudpickle</code> does not work. <code>[#892](python-attrs/attrs#892) &lt;https://github.com/python-attrs/attrs/issues/892&gt;</code>_</li> </ul> </blockquote> <p>... (truncated)</p> </details> <details> <summary>Commits</summary> <ul> <li><a href="https://github.com/python-attrs/attrs/commit/b3dfebe2e10b44437c4f97d788fb5220d790efd0"><code>b3dfebe</code></a> Prepare 22.1.0</li> <li><a href="https://github.com/python-attrs/attrs/commit/c89abcd6e6a826b00898f93e851c96b78c80891f"><code>c89abcd</code></a> It totally is correct</li> <li><a href="https://github.com/python-attrs/attrs/commit/9f118b7dd5328ee5abd7f3880971ab9554047c3a"><code>9f118b7</code></a> Tune first steps</li> <li><a href="https://github.com/python-attrs/attrs/commit/a3d7f20e54ba29d5ec73563c167d877351228cf2"><code>a3d7f20</code></a> Polish contributing guide</li> <li><a href="https://github.com/python-attrs/attrs/commit/899497f165b3c8291b66c9c3a01b64881b69cf39"><code>899497f</code></a> Clarify (c) ownership</li> <li><a href="https://github.com/python-attrs/attrs/commit/696fd786901a6b82b828dd71e3fd64bfae1014ca"><code>696fd78</code></a> Hyphenate compound adjectives</li> <li><a href="https://github.com/python-attrs/attrs/commit/65c06831c1eee4d9895511c7db5caffba9d93c0e"><code>65c0683</code></a> Use NG APIs in glossary</li> <li><a href="https://github.com/python-attrs/attrs/commit/5d84d9a5686e8210b1616447ac05021b6b211157"><code>5d84d9a</code></a> Move mypy config to pyproject.toml</li> <li><a href="https://github.com/python-attrs/attrs/commit/1590917bf7c49e35bb429d117650f660aa45e0e4"><code>1590917</code></a> Update readme.rst (<a href="https://github-redirect.dependabot.com/python-attrs/attrs/issues/986">#986</a>)</li> <li><a href="https://github.com/python-attrs/attrs/commit/a67c84f51e4e3df875961d287583abaef673eb48"><code>a67c84f</code></a> Add more prominent callout about slots to API docs</li> <li>Additional commits viewable in <a href="https://github.com/python-attrs/attrs/compare/21.2.0...22.1.0">compare view</a></li> </ul> </details> <br /> Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) </details>
1 parent 053004a commit 5275da6

File tree

20 files changed

+114
-94
lines changed

20 files changed

+114
-94
lines changed

.github/workflows/main.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,8 @@ jobs:
362362
name: Run benchmark suite
363363
runs-on: ubuntu-latest
364364
permissions:
365-
contents: write
365+
contents: read
366+
pull-requests: write
366367
needs: build
367368
steps:
368369
# Check out the code
@@ -395,7 +396,7 @@ jobs:
395396
tool: 'customSmallerIsBetter'
396397
output-file-path: ${{ runner.temp }}/bench-output.json
397398
comment-always: true
398-
github-token: ${{ secrets.PROJEN_GITHUB_TOKEN }}
399+
github-token: ${{ secrets.GITHUB_TOKEN }}
399400
fail-on-alert: true
400401
- name: Upload Benchmark Results
401402
if: github.event_name == 'push'

packages/@jsii/python-runtime/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"jsii._embedded.jsii": ["*.js", "*.js.map"],
3131
},
3232
install_requires=[
33-
"attrs~=21.2",
33+
"attrs>=21.2,<23.0",
3434
"cattrs>=1.8,<22.2",
3535
"publication>=0.0.3", # This is used by all generated code.
3636
"typeguard~=2.13.3", # This is used by all generated code.

packages/jsii-rosetta/bin/jsii-rosetta.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import '@jsii/check-node/run';
22

3-
import * as fs from 'fs-extra';
3+
import { promises as fs } from 'fs';
44
import * as path from 'path';
55
import * as yargs from 'yargs';
66

@@ -408,7 +408,7 @@ function main() {
408408
const packageJsonPath = (await fs.stat(args.PACKAGE)).isDirectory()
409409
? path.join(args.PACKAGE, 'package.json')
410410
: args.PACKAGE;
411-
const packageJson = await fs.readJson(packageJsonPath);
411+
const packageJson = JSON.parse(await fs.readFile(packageJsonPath, 'utf-8'));
412412
if (packageJson.jsii == null) {
413413
console.error(
414414
`The package in ${args.PACKAGE} does not have a jsii configuration! You can set it up using jsii-config.`,
@@ -425,7 +425,7 @@ function main() {
425425
const mdRosetta = (mdJsii.rosetta = mdJsii.rosetta ?? {});
426426
mdRosetta.strict = true;
427427

428-
return fs.writeJson(packageJsonPath, packageJson, { spaces: 2 });
428+
return fs.writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2));
429429
}),
430430
)
431431
.demandCommand()

packages/jsii-rosetta/lib/commands/infuse.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as spec from '@jsii/spec';
2-
import * as fs from 'fs-extra';
2+
import * as fs from 'fs';
33
import * as path from 'path';
44

55
import {

packages/jsii-rosetta/lib/commands/transliterate.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Assembly, Docs, SPEC_FILE_NAME, Type, TypeKind, loadAssemblyFromPath } from '@jsii/spec';
2-
import { writeJson } from 'fs-extra';
2+
import { promises as fs } from 'fs';
33
import { resolve } from 'path';
44

55
import { TargetLanguage } from '../languages';
@@ -117,7 +117,10 @@ export async function transliterateAssembly(
117117
transliterateType(type, rosetta, language);
118118
}
119119
// eslint-disable-next-line no-await-in-loop
120-
await writeJson(resolve(options?.outdir ?? location, `${SPEC_FILE_NAME}.${language}`), result, { spaces: 2 });
120+
await fs.writeFile(
121+
resolve(options?.outdir ?? location, `${SPEC_FILE_NAME}.${language}`),
122+
JSON.stringify(result, null, 2),
123+
);
121124
const then = new Date().getTime();
122125
debug(`Done transliterating ${result.name}@${result.version} to ${language} after ${then - now} milliseconds`);
123126
}

packages/jsii-rosetta/lib/find-utils.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
import * as fs from 'fs-extra';
1+
import { promises as fs } from 'fs';
22
import * as path from 'path';
33

4+
import { pathExists } from './util';
5+
46
/**
57
* Find the directory that contains a given dependency, identified by its 'package.json', from a starting search directory
68
*
@@ -34,7 +36,7 @@ export async function findDependencyDirectory(dependencyName: string, searchStar
3436
export async function findPackageJsonUp(packageName: string, directory: string) {
3537
return findUp(directory, async (dir) => {
3638
const pjFile = path.join(dir, 'package.json');
37-
return (await fs.pathExists(pjFile)) && (await fs.readJson(pjFile)).name === packageName;
39+
return (await pathExists(pjFile)) && JSON.parse(await fs.readFile(pjFile, 'utf-8')).name === packageName;
3840
});
3941
}
4042

packages/jsii-rosetta/lib/fixtures.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as fs from 'fs-extra';
1+
import * as fs from 'fs';
22
import * as path from 'path';
33
import { createSourceFile, ScriptKind, ScriptTarget, SyntaxKind } from 'typescript';
44

packages/jsii-rosetta/lib/jsii/assemblies.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import {
77
writeAssembly,
88
} from '@jsii/spec';
99
import * as crypto from 'crypto';
10-
import * as fs from 'fs-extra';
10+
import { promises as fsPromises } from 'fs';
11+
import * as fs from 'fs';
1112
import * as path from 'path';
1213

1314
import { findDependencyDirectory, isBuiltinModule } from '../find-utils';
@@ -78,7 +79,7 @@ export function loadAssemblies(
7879
const pjLocation = path.join(directory, 'package.json');
7980

8081
const assembly = loadAssemblyFromFile(location, validateAssemblies);
81-
const packageJson = fs.pathExistsSync(pjLocation) ? fs.readJSONSync(pjLocation, { encoding: 'utf-8' }) : undefined;
82+
const packageJson = fs.existsSync(pjLocation) ? JSON.parse(fs.readFileSync(pjLocation, 'utf-8')) : undefined;
8283

8384
return { assembly, directory, packageJson };
8485
}
@@ -297,7 +298,7 @@ export function findTypeLookupAssembly(startingDirectory: string): TypeLookupAss
297298

298299
function loadLookupAssembly(directory: string): TypeLookupAssembly | undefined {
299300
try {
300-
const packageJson = fs.readJSONSync(path.join(directory, 'package.json'), { encoding: 'utf-8' });
301+
const packageJson = JSON.parse(fs.readFileSync(path.join(directory, 'package.json'), 'utf-8'));
301302
const assembly: spec.Assembly = loadAssemblyFromPath(directory);
302303
const symbolIdMap = mkDict([
303304
...Object.values(assembly.types ?? {}).map((type) => [type.symbolId ?? '', type.fqn] as const),
@@ -367,7 +368,7 @@ async function withDependencies(asm: LoadedAssembly, snippet: TypeScriptSnippet)
367368

368369
compilationDependencies[asm.assembly.name] = {
369370
type: 'concrete',
370-
resolvedDirectory: await fs.realpath(asm.directory),
371+
resolvedDirectory: await fsPromises.realpath(asm.directory),
371372
};
372373

373374
Object.assign(
@@ -387,7 +388,7 @@ async function withDependencies(asm: LoadedAssembly, snippet: TypeScriptSnippet)
387388
name,
388389
{
389390
type: 'concrete',
390-
resolvedDirectory: await fs.realpath(await findDependencyDirectory(name, asm.directory)),
391+
resolvedDirectory: await fsPromises.realpath(await findDependencyDirectory(name, asm.directory)),
391392
},
392393
] as const,
393394
),

packages/jsii-rosetta/lib/rosetta-reader.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import * as spec from '@jsii/spec';
2-
import * as fs from 'fs-extra';
32
import * as path from 'path';
43

54
import { allTypeScriptSnippets } from './jsii/assemblies';
@@ -19,7 +18,7 @@ import {
1918
import { snippetKey } from './tablets/key';
2019
import { DEFAULT_TABLET_NAME, LanguageTablet, Translation } from './tablets/tablets';
2120
import { Translator } from './translate';
22-
import { commentToken, printDiagnostics } from './util';
21+
import { commentToken, pathExists, printDiagnostics } from './util';
2322

2423
export enum UnknownSnippetMode {
2524
/**
@@ -150,7 +149,7 @@ export class RosettaTabletReader {
150149
*/
151150
public async addAssembly(assembly: spec.Assembly, assemblyDir: string) {
152151
const defaultTablet = path.join(assemblyDir, DEFAULT_TABLET_NAME);
153-
if (await fs.pathExists(defaultTablet)) {
152+
if (await pathExists(defaultTablet)) {
154153
try {
155154
await this.loadTabletFromFile(defaultTablet);
156155
return;

packages/jsii-rosetta/lib/rosetta-translator.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as spec from '@jsii/spec';
2-
import * as fs from 'fs-extra';
2+
import { promises as fs } from 'fs';
33

44
import { TypeFingerprinter } from './jsii/fingerprinting';
55
import { TARGET_LANGUAGES } from './languages';
@@ -190,7 +190,7 @@ export class RosettaTranslator {
190190
} finally {
191191
process.chdir(origDir);
192192
if (cleanCompilationDir) {
193-
await fs.remove(compilationDirectory);
193+
await fs.rm(compilationDirectory, { force: true, recursive: true });
194194
}
195195
}
196196

packages/jsii-rosetta/lib/snippet-dependencies.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as cp from 'child_process';
22
import * as fastGlob from 'fast-glob';
3-
import * as fs from 'fs-extra';
3+
import { promises as fsPromises } from 'fs';
4+
import * as fs from 'fs';
45
import * as os from 'os';
56
import * as path from 'path';
67
import * as semver from 'semver';
@@ -9,7 +10,7 @@ import { intersect } from 'semver-intersect';
910
import { findDependencyDirectory, findUp } from './find-utils';
1011
import * as logging from './logging';
1112
import { TypeScriptSnippet, CompilationDependency } from './snippet';
12-
import { mkDict, formatList } from './util';
13+
import { mkDict, formatList, pathExists } from './util';
1314

1415
/**
1516
* Collect the dependencies of a bunch of snippets together in one declaration
@@ -51,7 +52,9 @@ function resolveConflict(
5152
}
5253

5354
if (a.type === 'concrete' && b.type === 'symbolic') {
54-
const concreteVersion: string = fs.readJsonSync(path.join(a.resolvedDirectory, 'package.json')).version;
55+
const concreteVersion: string = JSON.parse(
56+
fs.readFileSync(path.join(a.resolvedDirectory, 'package.json'), 'utf-8'),
57+
).version;
5558

5659
if (!semver.satisfies(concreteVersion, b.versionRange)) {
5760
throw new Error(
@@ -108,7 +111,7 @@ export async function prepareDependencyDirectory(deps: Record<string, Compilatio
108111
.map((x) => x.resolvedDirectory);
109112
const monorepoPackages = await scanMonoRepos(concreteDirs);
110113

111-
const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'rosetta'));
114+
const tmpDir = await fsPromises.mkdtemp(path.join(os.tmpdir(), 'rosetta'));
112115
logging.info(`Preparing dependency closure at ${tmpDir}`);
113116

114117
// Resolved symbolic packages against monorepo
@@ -148,10 +151,10 @@ export async function prepareDependencyDirectory(deps: Record<string, Compilatio
148151
await Promise.all(
149152
Object.entries(linkedInstalls).map(async ([name, source]) => {
150153
const target = path.join(modDir, name);
151-
if (!(await fs.pathExists(target))) {
154+
if (!(await pathExists(target))) {
152155
// Package could be namespaced, so ensure the namespace dir exists
153-
await fs.mkdirp(path.dirname(target));
154-
await fs.symlink(source, target, 'dir');
156+
await fsPromises.mkdir(path.dirname(target), { recursive: true });
157+
await fsPromises.symlink(source, target, 'dir');
155158
}
156159
}),
157160
);
@@ -182,8 +185,8 @@ async function scanMonoRepos(startingDirs: readonly string[]): Promise<Record<st
182185
await Promise.all(
183186
packageDirectories.map(async (directory) => {
184187
const pjLocation = path.join(directory, 'package.json');
185-
return (await fs.pathExists(pjLocation))
186-
? [[(await fs.readJson(pjLocation)).name as string, directory] as const]
188+
return (await pathExists(pjLocation))
189+
? [[JSON.parse(await fsPromises.readFile(pjLocation, 'utf-8')).name as string, directory] as const]
187190
: [];
188191
}),
189192
)
@@ -198,9 +201,9 @@ async function findMonoRepoGlobs(startingDir: string): Promise<Set<string>> {
198201
const ret = new Set<string>();
199202

200203
// Lerna monorepo
201-
const lernaJsonDir = await findUp(startingDir, async (dir) => fs.pathExists(path.join(dir, 'lerna.json')));
204+
const lernaJsonDir = await findUp(startingDir, async (dir) => pathExists(path.join(dir, 'lerna.json')));
202205
if (lernaJsonDir) {
203-
const lernaJson = await fs.readJson(path.join(lernaJsonDir, 'lerna.json'));
206+
const lernaJson = JSON.parse(await fsPromises.readFile(path.join(lernaJsonDir, 'lerna.json'), 'utf-8'));
204207
for (const glob of lernaJson?.packages ?? []) {
205208
ret.add(path.join(lernaJsonDir, glob));
206209
}
@@ -210,11 +213,11 @@ async function findMonoRepoGlobs(startingDir: string): Promise<Set<string>> {
210213
const yarnWsDir = await findUp(
211214
startingDir,
212215
async (dir) =>
213-
(await fs.pathExists(path.join(dir, 'package.json'))) &&
214-
(await fs.readJson(path.join(dir, 'package.json')))?.workspaces !== undefined,
216+
(await pathExists(path.join(dir, 'package.json'))) &&
217+
JSON.parse(await fsPromises.readFile(path.join(dir, 'package.json'), 'utf-8'))?.workspaces !== undefined,
215218
);
216219
if (yarnWsDir) {
217-
const yarnWs = await fs.readJson(path.join(yarnWsDir, 'package.json'));
220+
const yarnWs = JSON.parse(await fsPromises.readFile(path.join(yarnWsDir, 'package.json'), 'utf-8'));
218221
for (const glob of yarnWs.workspaces?.packages ?? []) {
219222
ret.add(path.join(yarnWsDir, glob));
220223
}

packages/jsii-rosetta/lib/tablets/tablets.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as fs from 'fs-extra';
1+
import { existsSync, promises as fs } from 'fs';
22
import * as path from 'path';
33
import * as zlib from 'zlib';
44

@@ -44,7 +44,7 @@ export class LanguageTablet {
4444
*/
4545
public static async fromOptionalFile(filename: string) {
4646
const ret = new LanguageTablet();
47-
if (fs.existsSync(filename)) {
47+
if (existsSync(filename)) {
4848
try {
4949
await ret.load(filename);
5050
} catch (e: any) {
@@ -179,7 +179,7 @@ export class LanguageTablet {
179179
* the schema will be gzipped before writing to the file.
180180
*/
181181
public async save(filename: string, compress = false) {
182-
await fs.mkdirp(path.dirname(filename));
182+
await fs.mkdir(path.dirname(filename), { recursive: true });
183183

184184
let schema = Buffer.from(JSON.stringify(this.toSchema(), null, 2));
185185
if (compress) {

packages/jsii-rosetta/lib/util.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { promises as fs } from 'fs';
12
import * as ts from 'typescript';
23

34
import { RosettaDiagnostic } from './translate';
@@ -227,3 +228,18 @@ export function commentToken(language: string) {
227228
return '//';
228229
}
229230
}
231+
232+
export async function pathExists(path: string): Promise<boolean> {
233+
try {
234+
await fs.stat(path);
235+
return true;
236+
} catch (err: any) {
237+
if (err.code === 'ENOENT') {
238+
return false;
239+
}
240+
if (!err.stack) {
241+
Error.captureStackTrace(err);
242+
}
243+
throw err;
244+
}
245+
}

packages/jsii-rosetta/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
},
1818
"devDependencies": {
1919
"@types/commonmark": "^0.27.5",
20-
"@types/fs-extra": "^9.0.13",
2120
"@types/mock-fs": "^4.13.1",
2221
"@types/workerpool": "^6.1.0",
2322
"@types/semver": "^7.3.10",
@@ -29,7 +28,6 @@
2928
"@jsii/check-node": "0.0.0",
3029
"@jsii/spec": "0.0.0",
3130
"commonmark": "^0.30.0",
32-
"fs-extra": "^10.1.0",
3331
"typescript": "~3.9.10",
3432
"sort-json": "^2.0.1",
3533
"@xmldom/xmldom": "^0.8.2",

packages/jsii-rosetta/test/commands/extract.test.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { SPEC_FILE_NAME_COMPRESSED } from '@jsii/spec';
2-
import * as fs from 'fs-extra';
2+
import * as fs from 'fs';
33
import { compileJsiiForTest } from 'jsii';
44
import * as path from 'path';
55

@@ -16,6 +16,7 @@ import * as extract from '../../lib/commands/extract';
1616
import { loadAssemblies } from '../../lib/jsii/assemblies';
1717
import { TARGET_LANGUAGES } from '../../lib/languages';
1818
import * as logging from '../../lib/logging';
19+
import { pathExists } from '../../lib/util';
1920
import { TestJsiiModule, DUMMY_JSII_CONFIG, testSnippetLocation } from '../testutil';
2021

2122
jest.setTimeout(30_000);
@@ -159,7 +160,7 @@ describe('with cache file', () => {
159160
});
160161

161162
async function givenThatDefaultTabletDoesNotExist() {
162-
await fs.unlink(path.join(assembly.moduleDirectory, DEFAULT_TABLET_NAME));
163+
await fs.promises.unlink(path.join(assembly.moduleDirectory, DEFAULT_TABLET_NAME));
163164
}
164165

165166
describe('translation does not happen ', () => {
@@ -240,8 +241,8 @@ describe('with cache file', () => {
240241
});
241242

242243
// THEN
243-
expect(await fs.pathExists(path.join(assembly.moduleDirectory, 'dummy.tabl.json'))).toBeTruthy();
244-
expect(await fs.pathExists(path.join(assembly.moduleDirectory, '.jsii.tabl.json'))).toBeTruthy();
244+
expect(await pathExists(path.join(assembly.moduleDirectory, 'dummy.tabl.json'))).toBeTruthy();
245+
expect(await pathExists(path.join(assembly.moduleDirectory, '.jsii.tabl.json'))).toBeTruthy();
245246
});
246247

247248
describe('when the cache output tablet has unrelated snippets', () => {
@@ -644,9 +645,12 @@ test('can use additional dependencies from monorepo', async () => {
644645
),
645646
);
646647
// GIVEN - a lerna.json that would find that package
647-
await fs.writeJson(path.join(asm.workspaceDirectory, 'lerna.json'), {
648-
packages: ['node_modules/*'],
649-
});
648+
await fs.promises.writeFile(
649+
path.join(asm.workspaceDirectory, 'lerna.json'),
650+
JSON.stringify({
651+
packages: ['node_modules/*'],
652+
}),
653+
);
650654

651655
// WHEN
652656
await extract.extractSnippets([asm.moduleDirectory], defaultExtractOptions);

0 commit comments

Comments
 (0)