Skip to content

Commit

Permalink
chore(deps): Update attrs requirement from ~=21.2 to >=21.2,<23.0 in …
Browse files Browse the repository at this point in the history
…/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>
  • Loading branch information
dependabot[bot] authored Aug 1, 2022
1 parent 053004a commit 5275da6
Show file tree
Hide file tree
Showing 20 changed files with 114 additions and 94 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,8 @@ jobs:
name: Run benchmark suite
runs-on: ubuntu-latest
permissions:
contents: write
contents: read
pull-requests: write
needs: build
steps:
# Check out the code
Expand Down Expand Up @@ -395,7 +396,7 @@ jobs:
tool: 'customSmallerIsBetter'
output-file-path: ${{ runner.temp }}/bench-output.json
comment-always: true
github-token: ${{ secrets.PROJEN_GITHUB_TOKEN }}
github-token: ${{ secrets.GITHUB_TOKEN }}
fail-on-alert: true
- name: Upload Benchmark Results
if: github.event_name == 'push'
Expand Down
2 changes: 1 addition & 1 deletion packages/@jsii/python-runtime/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"jsii._embedded.jsii": ["*.js", "*.js.map"],
},
install_requires=[
"attrs~=21.2",
"attrs>=21.2,<23.0",
"cattrs>=1.8,<22.2",
"publication>=0.0.3", # This is used by all generated code.
"typeguard~=2.13.3", # This is used by all generated code.
Expand Down
6 changes: 3 additions & 3 deletions packages/jsii-rosetta/bin/jsii-rosetta.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import '@jsii/check-node/run';

import * as fs from 'fs-extra';
import { promises as fs } from 'fs';
import * as path from 'path';
import * as yargs from 'yargs';

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

return fs.writeJson(packageJsonPath, packageJson, { spaces: 2 });
return fs.writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2));
}),
)
.demandCommand()
Expand Down
2 changes: 1 addition & 1 deletion packages/jsii-rosetta/lib/commands/infuse.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as spec from '@jsii/spec';
import * as fs from 'fs-extra';
import * as fs from 'fs';
import * as path from 'path';

import {
Expand Down
7 changes: 5 additions & 2 deletions packages/jsii-rosetta/lib/commands/transliterate.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Assembly, Docs, SPEC_FILE_NAME, Type, TypeKind, loadAssemblyFromPath } from '@jsii/spec';
import { writeJson } from 'fs-extra';
import { promises as fs } from 'fs';
import { resolve } from 'path';

import { TargetLanguage } from '../languages';
Expand Down Expand Up @@ -117,7 +117,10 @@ export async function transliterateAssembly(
transliterateType(type, rosetta, language);
}
// eslint-disable-next-line no-await-in-loop
await writeJson(resolve(options?.outdir ?? location, `${SPEC_FILE_NAME}.${language}`), result, { spaces: 2 });
await fs.writeFile(
resolve(options?.outdir ?? location, `${SPEC_FILE_NAME}.${language}`),
JSON.stringify(result, null, 2),
);
const then = new Date().getTime();
debug(`Done transliterating ${result.name}@${result.version} to ${language} after ${then - now} milliseconds`);
}
Expand Down
6 changes: 4 additions & 2 deletions packages/jsii-rosetta/lib/find-utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import * as fs from 'fs-extra';
import { promises as fs } from 'fs';
import * as path from 'path';

import { pathExists } from './util';

/**
* Find the directory that contains a given dependency, identified by its 'package.json', from a starting search directory
*
Expand Down Expand Up @@ -34,7 +36,7 @@ export async function findDependencyDirectory(dependencyName: string, searchStar
export async function findPackageJsonUp(packageName: string, directory: string) {
return findUp(directory, async (dir) => {
const pjFile = path.join(dir, 'package.json');
return (await fs.pathExists(pjFile)) && (await fs.readJson(pjFile)).name === packageName;
return (await pathExists(pjFile)) && JSON.parse(await fs.readFile(pjFile, 'utf-8')).name === packageName;
});
}

Expand Down
2 changes: 1 addition & 1 deletion packages/jsii-rosetta/lib/fixtures.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as fs from 'fs-extra';
import * as fs from 'fs';
import * as path from 'path';
import { createSourceFile, ScriptKind, ScriptTarget, SyntaxKind } from 'typescript';

Expand Down
11 changes: 6 additions & 5 deletions packages/jsii-rosetta/lib/jsii/assemblies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
writeAssembly,
} from '@jsii/spec';
import * as crypto from 'crypto';
import * as fs from 'fs-extra';
import { promises as fsPromises } from 'fs';
import * as fs from 'fs';
import * as path from 'path';

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

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

return { assembly, directory, packageJson };
}
Expand Down Expand Up @@ -297,7 +298,7 @@ export function findTypeLookupAssembly(startingDirectory: string): TypeLookupAss

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

compilationDependencies[asm.assembly.name] = {
type: 'concrete',
resolvedDirectory: await fs.realpath(asm.directory),
resolvedDirectory: await fsPromises.realpath(asm.directory),
};

Object.assign(
Expand All @@ -387,7 +388,7 @@ async function withDependencies(asm: LoadedAssembly, snippet: TypeScriptSnippet)
name,
{
type: 'concrete',
resolvedDirectory: await fs.realpath(await findDependencyDirectory(name, asm.directory)),
resolvedDirectory: await fsPromises.realpath(await findDependencyDirectory(name, asm.directory)),
},
] as const,
),
Expand Down
5 changes: 2 additions & 3 deletions packages/jsii-rosetta/lib/rosetta-reader.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as spec from '@jsii/spec';
import * as fs from 'fs-extra';
import * as path from 'path';

import { allTypeScriptSnippets } from './jsii/assemblies';
Expand All @@ -19,7 +18,7 @@ import {
import { snippetKey } from './tablets/key';
import { DEFAULT_TABLET_NAME, LanguageTablet, Translation } from './tablets/tablets';
import { Translator } from './translate';
import { commentToken, printDiagnostics } from './util';
import { commentToken, pathExists, printDiagnostics } from './util';

export enum UnknownSnippetMode {
/**
Expand Down Expand Up @@ -150,7 +149,7 @@ export class RosettaTabletReader {
*/
public async addAssembly(assembly: spec.Assembly, assemblyDir: string) {
const defaultTablet = path.join(assemblyDir, DEFAULT_TABLET_NAME);
if (await fs.pathExists(defaultTablet)) {
if (await pathExists(defaultTablet)) {
try {
await this.loadTabletFromFile(defaultTablet);
return;
Expand Down
4 changes: 2 additions & 2 deletions packages/jsii-rosetta/lib/rosetta-translator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as spec from '@jsii/spec';
import * as fs from 'fs-extra';
import { promises as fs } from 'fs';

import { TypeFingerprinter } from './jsii/fingerprinting';
import { TARGET_LANGUAGES } from './languages';
Expand Down Expand Up @@ -190,7 +190,7 @@ export class RosettaTranslator {
} finally {
process.chdir(origDir);
if (cleanCompilationDir) {
await fs.remove(compilationDirectory);
await fs.rm(compilationDirectory, { force: true, recursive: true });
}
}

Expand Down
31 changes: 17 additions & 14 deletions packages/jsii-rosetta/lib/snippet-dependencies.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as cp from 'child_process';
import * as fastGlob from 'fast-glob';
import * as fs from 'fs-extra';
import { promises as fsPromises } from 'fs';
import * as fs from 'fs';
import * as os from 'os';
import * as path from 'path';
import * as semver from 'semver';
Expand All @@ -9,7 +10,7 @@ import { intersect } from 'semver-intersect';
import { findDependencyDirectory, findUp } from './find-utils';
import * as logging from './logging';
import { TypeScriptSnippet, CompilationDependency } from './snippet';
import { mkDict, formatList } from './util';
import { mkDict, formatList, pathExists } from './util';

/**
* Collect the dependencies of a bunch of snippets together in one declaration
Expand Down Expand Up @@ -51,7 +52,9 @@ function resolveConflict(
}

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

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

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

// Resolved symbolic packages against monorepo
Expand Down Expand Up @@ -148,10 +151,10 @@ export async function prepareDependencyDirectory(deps: Record<string, Compilatio
await Promise.all(
Object.entries(linkedInstalls).map(async ([name, source]) => {
const target = path.join(modDir, name);
if (!(await fs.pathExists(target))) {
if (!(await pathExists(target))) {
// Package could be namespaced, so ensure the namespace dir exists
await fs.mkdirp(path.dirname(target));
await fs.symlink(source, target, 'dir');
await fsPromises.mkdir(path.dirname(target), { recursive: true });
await fsPromises.symlink(source, target, 'dir');
}
}),
);
Expand Down Expand Up @@ -182,8 +185,8 @@ async function scanMonoRepos(startingDirs: readonly string[]): Promise<Record<st
await Promise.all(
packageDirectories.map(async (directory) => {
const pjLocation = path.join(directory, 'package.json');
return (await fs.pathExists(pjLocation))
? [[(await fs.readJson(pjLocation)).name as string, directory] as const]
return (await pathExists(pjLocation))
? [[JSON.parse(await fsPromises.readFile(pjLocation, 'utf-8')).name as string, directory] as const]
: [];
}),
)
Expand All @@ -198,9 +201,9 @@ async function findMonoRepoGlobs(startingDir: string): Promise<Set<string>> {
const ret = new Set<string>();

// Lerna monorepo
const lernaJsonDir = await findUp(startingDir, async (dir) => fs.pathExists(path.join(dir, 'lerna.json')));
const lernaJsonDir = await findUp(startingDir, async (dir) => pathExists(path.join(dir, 'lerna.json')));
if (lernaJsonDir) {
const lernaJson = await fs.readJson(path.join(lernaJsonDir, 'lerna.json'));
const lernaJson = JSON.parse(await fsPromises.readFile(path.join(lernaJsonDir, 'lerna.json'), 'utf-8'));
for (const glob of lernaJson?.packages ?? []) {
ret.add(path.join(lernaJsonDir, glob));
}
Expand All @@ -210,11 +213,11 @@ async function findMonoRepoGlobs(startingDir: string): Promise<Set<string>> {
const yarnWsDir = await findUp(
startingDir,
async (dir) =>
(await fs.pathExists(path.join(dir, 'package.json'))) &&
(await fs.readJson(path.join(dir, 'package.json')))?.workspaces !== undefined,
(await pathExists(path.join(dir, 'package.json'))) &&
JSON.parse(await fsPromises.readFile(path.join(dir, 'package.json'), 'utf-8'))?.workspaces !== undefined,
);
if (yarnWsDir) {
const yarnWs = await fs.readJson(path.join(yarnWsDir, 'package.json'));
const yarnWs = JSON.parse(await fsPromises.readFile(path.join(yarnWsDir, 'package.json'), 'utf-8'));
for (const glob of yarnWs.workspaces?.packages ?? []) {
ret.add(path.join(yarnWsDir, glob));
}
Expand Down
6 changes: 3 additions & 3 deletions packages/jsii-rosetta/lib/tablets/tablets.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as fs from 'fs-extra';
import { existsSync, promises as fs } from 'fs';
import * as path from 'path';
import * as zlib from 'zlib';

Expand Down Expand Up @@ -44,7 +44,7 @@ export class LanguageTablet {
*/
public static async fromOptionalFile(filename: string) {
const ret = new LanguageTablet();
if (fs.existsSync(filename)) {
if (existsSync(filename)) {
try {
await ret.load(filename);
} catch (e: any) {
Expand Down Expand Up @@ -179,7 +179,7 @@ export class LanguageTablet {
* the schema will be gzipped before writing to the file.
*/
public async save(filename: string, compress = false) {
await fs.mkdirp(path.dirname(filename));
await fs.mkdir(path.dirname(filename), { recursive: true });

let schema = Buffer.from(JSON.stringify(this.toSchema(), null, 2));
if (compress) {
Expand Down
16 changes: 16 additions & 0 deletions packages/jsii-rosetta/lib/util.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { promises as fs } from 'fs';
import * as ts from 'typescript';

import { RosettaDiagnostic } from './translate';
Expand Down Expand Up @@ -227,3 +228,18 @@ export function commentToken(language: string) {
return '//';
}
}

export async function pathExists(path: string): Promise<boolean> {
try {
await fs.stat(path);
return true;
} catch (err: any) {
if (err.code === 'ENOENT') {
return false;
}
if (!err.stack) {
Error.captureStackTrace(err);
}
throw err;
}
}
2 changes: 0 additions & 2 deletions packages/jsii-rosetta/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
},
"devDependencies": {
"@types/commonmark": "^0.27.5",
"@types/fs-extra": "^9.0.13",
"@types/mock-fs": "^4.13.1",
"@types/workerpool": "^6.1.0",
"@types/semver": "^7.3.10",
Expand All @@ -29,7 +28,6 @@
"@jsii/check-node": "0.0.0",
"@jsii/spec": "0.0.0",
"commonmark": "^0.30.0",
"fs-extra": "^10.1.0",
"typescript": "~3.9.10",
"sort-json": "^2.0.1",
"@xmldom/xmldom": "^0.8.2",
Expand Down
18 changes: 11 additions & 7 deletions packages/jsii-rosetta/test/commands/extract.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SPEC_FILE_NAME_COMPRESSED } from '@jsii/spec';
import * as fs from 'fs-extra';
import * as fs from 'fs';
import { compileJsiiForTest } from 'jsii';
import * as path from 'path';

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

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

async function givenThatDefaultTabletDoesNotExist() {
await fs.unlink(path.join(assembly.moduleDirectory, DEFAULT_TABLET_NAME));
await fs.promises.unlink(path.join(assembly.moduleDirectory, DEFAULT_TABLET_NAME));
}

describe('translation does not happen ', () => {
Expand Down Expand Up @@ -240,8 +241,8 @@ describe('with cache file', () => {
});

// THEN
expect(await fs.pathExists(path.join(assembly.moduleDirectory, 'dummy.tabl.json'))).toBeTruthy();
expect(await fs.pathExists(path.join(assembly.moduleDirectory, '.jsii.tabl.json'))).toBeTruthy();
expect(await pathExists(path.join(assembly.moduleDirectory, 'dummy.tabl.json'))).toBeTruthy();
expect(await pathExists(path.join(assembly.moduleDirectory, '.jsii.tabl.json'))).toBeTruthy();
});

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

// WHEN
await extract.extractSnippets([asm.moduleDirectory], defaultExtractOptions);
Expand Down
Loading

0 comments on commit 5275da6

Please sign in to comment.