From 5275da6585272491628e4b954f4d84a791c40d6b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 1 Aug 2022 14:20:19 +0000 Subject: [PATCH] chore(deps): Update attrs requirement from ~=21.2 to >=21.2,<23.0 in /packages/@jsii/python-runtime (#3692) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updates the requirements on [attrs](https://github.com/python-attrs/attrs) to permit the latest version.
Release notes

Sourced from attrs's releases.

22.1.0

Highlights

The main features of this release are:

We had loftier goals feature-wise, but didn't want to block others embracing Python 3.11.

❤️ Huge thanks to my GitHub sponsors, Tidelift subscribers, and Ko-fi buyers! ❤️

None of my projects would exist in their current form without you!

Full Changelog

Backwards-incompatible Changes

Changes

Changelog

Sourced from attrs's changelog.

22.1.0 (2022-07-28)

Backwards-incompatible Changes ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Changes ^^^^^^^


21.4.0 (2021-12-29)

Changes ^^^^^^^

... (truncated)

Commits

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) ---
Dependabot commands and options
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)
--- .github/workflows/main.yml | 5 +- packages/@jsii/python-runtime/setup.py | 2 +- packages/jsii-rosetta/bin/jsii-rosetta.ts | 6 +- packages/jsii-rosetta/lib/commands/infuse.ts | 2 +- .../lib/commands/transliterate.ts | 7 +- packages/jsii-rosetta/lib/find-utils.ts | 6 +- packages/jsii-rosetta/lib/fixtures.ts | 2 +- packages/jsii-rosetta/lib/jsii/assemblies.ts | 11 ++-- packages/jsii-rosetta/lib/rosetta-reader.ts | 5 +- .../jsii-rosetta/lib/rosetta-translator.ts | 4 +- .../jsii-rosetta/lib/snippet-dependencies.ts | 31 +++++---- packages/jsii-rosetta/lib/tablets/tablets.ts | 6 +- packages/jsii-rosetta/lib/util.ts | 16 +++++ packages/jsii-rosetta/package.json | 2 - .../test/commands/extract.test.ts | 18 +++-- .../jsii-rosetta/test/commands/infuse.test.ts | 10 +-- .../test/commands/transliterate.test.ts | 65 +++++++++---------- .../jsii-rosetta/test/jsii/assemblies.test.ts | 4 +- packages/jsii-rosetta/test/testutil.ts | 4 +- .../jsii-rosetta/test/translations.test.ts | 2 +- 20 files changed, 114 insertions(+), 94 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2fc4606aad..859225ee5e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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 @@ -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' diff --git a/packages/@jsii/python-runtime/setup.py b/packages/@jsii/python-runtime/setup.py index 9b710f78fe..8ad77b0b11 100644 --- a/packages/@jsii/python-runtime/setup.py +++ b/packages/@jsii/python-runtime/setup.py @@ -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. diff --git a/packages/jsii-rosetta/bin/jsii-rosetta.ts b/packages/jsii-rosetta/bin/jsii-rosetta.ts index 396a5b63e8..0a807ce7fb 100644 --- a/packages/jsii-rosetta/bin/jsii-rosetta.ts +++ b/packages/jsii-rosetta/bin/jsii-rosetta.ts @@ -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'; @@ -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.`, @@ -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() diff --git a/packages/jsii-rosetta/lib/commands/infuse.ts b/packages/jsii-rosetta/lib/commands/infuse.ts index 9700537aaa..deaa85b07d 100644 --- a/packages/jsii-rosetta/lib/commands/infuse.ts +++ b/packages/jsii-rosetta/lib/commands/infuse.ts @@ -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 { diff --git a/packages/jsii-rosetta/lib/commands/transliterate.ts b/packages/jsii-rosetta/lib/commands/transliterate.ts index f6538840b1..cba52a96e8 100644 --- a/packages/jsii-rosetta/lib/commands/transliterate.ts +++ b/packages/jsii-rosetta/lib/commands/transliterate.ts @@ -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'; @@ -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`); } diff --git a/packages/jsii-rosetta/lib/find-utils.ts b/packages/jsii-rosetta/lib/find-utils.ts index 77c29907cd..036928d174 100644 --- a/packages/jsii-rosetta/lib/find-utils.ts +++ b/packages/jsii-rosetta/lib/find-utils.ts @@ -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 * @@ -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; }); } diff --git a/packages/jsii-rosetta/lib/fixtures.ts b/packages/jsii-rosetta/lib/fixtures.ts index affa4283b7..5b23c2a292 100644 --- a/packages/jsii-rosetta/lib/fixtures.ts +++ b/packages/jsii-rosetta/lib/fixtures.ts @@ -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'; diff --git a/packages/jsii-rosetta/lib/jsii/assemblies.ts b/packages/jsii-rosetta/lib/jsii/assemblies.ts index 21421610dd..6fc8301433 100644 --- a/packages/jsii-rosetta/lib/jsii/assemblies.ts +++ b/packages/jsii-rosetta/lib/jsii/assemblies.ts @@ -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'; @@ -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 }; } @@ -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), @@ -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( @@ -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, ), diff --git a/packages/jsii-rosetta/lib/rosetta-reader.ts b/packages/jsii-rosetta/lib/rosetta-reader.ts index b2e4457462..29e02a7786 100644 --- a/packages/jsii-rosetta/lib/rosetta-reader.ts +++ b/packages/jsii-rosetta/lib/rosetta-reader.ts @@ -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'; @@ -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 { /** @@ -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; diff --git a/packages/jsii-rosetta/lib/rosetta-translator.ts b/packages/jsii-rosetta/lib/rosetta-translator.ts index 26ba9e33ad..a2fb66f073 100644 --- a/packages/jsii-rosetta/lib/rosetta-translator.ts +++ b/packages/jsii-rosetta/lib/rosetta-translator.ts @@ -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'; @@ -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 }); } } diff --git a/packages/jsii-rosetta/lib/snippet-dependencies.ts b/packages/jsii-rosetta/lib/snippet-dependencies.ts index a21ace6710..86bb0ab4cf 100644 --- a/packages/jsii-rosetta/lib/snippet-dependencies.ts +++ b/packages/jsii-rosetta/lib/snippet-dependencies.ts @@ -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'; @@ -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 @@ -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( @@ -108,7 +111,7 @@ export async function prepareDependencyDirectory(deps: Record 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 @@ -148,10 +151,10 @@ export async function prepareDependencyDirectory(deps: Record { 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'); } }), ); @@ -182,8 +185,8 @@ async function scanMonoRepos(startingDirs: readonly string[]): Promise { 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] : []; }), ) @@ -198,9 +201,9 @@ async function findMonoRepoGlobs(startingDir: string): Promise> { const ret = new Set(); // 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)); } @@ -210,11 +213,11 @@ async function findMonoRepoGlobs(startingDir: string): Promise> { 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)); } diff --git a/packages/jsii-rosetta/lib/tablets/tablets.ts b/packages/jsii-rosetta/lib/tablets/tablets.ts index 54d35563db..d44b071cff 100644 --- a/packages/jsii-rosetta/lib/tablets/tablets.ts +++ b/packages/jsii-rosetta/lib/tablets/tablets.ts @@ -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'; @@ -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) { @@ -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) { diff --git a/packages/jsii-rosetta/lib/util.ts b/packages/jsii-rosetta/lib/util.ts index d35dd1d375..2d526b19e2 100644 --- a/packages/jsii-rosetta/lib/util.ts +++ b/packages/jsii-rosetta/lib/util.ts @@ -1,3 +1,4 @@ +import { promises as fs } from 'fs'; import * as ts from 'typescript'; import { RosettaDiagnostic } from './translate'; @@ -227,3 +228,18 @@ export function commentToken(language: string) { return '//'; } } + +export async function pathExists(path: string): Promise { + try { + await fs.stat(path); + return true; + } catch (err: any) { + if (err.code === 'ENOENT') { + return false; + } + if (!err.stack) { + Error.captureStackTrace(err); + } + throw err; + } +} diff --git a/packages/jsii-rosetta/package.json b/packages/jsii-rosetta/package.json index d9efbd7b2d..48125c69eb 100644 --- a/packages/jsii-rosetta/package.json +++ b/packages/jsii-rosetta/package.json @@ -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", @@ -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", diff --git a/packages/jsii-rosetta/test/commands/extract.test.ts b/packages/jsii-rosetta/test/commands/extract.test.ts index 7cd7615f6c..af0dd92a20 100644 --- a/packages/jsii-rosetta/test/commands/extract.test.ts +++ b/packages/jsii-rosetta/test/commands/extract.test.ts @@ -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'; @@ -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); @@ -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 ', () => { @@ -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', () => { @@ -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); diff --git a/packages/jsii-rosetta/test/commands/infuse.test.ts b/packages/jsii-rosetta/test/commands/infuse.test.ts index 480f2cd0a2..264f558b95 100644 --- a/packages/jsii-rosetta/test/commands/infuse.test.ts +++ b/packages/jsii-rosetta/test/commands/infuse.test.ts @@ -1,5 +1,5 @@ import { loadAssemblyFromPath, SPEC_FILE_NAME, SPEC_FILE_NAME_COMPRESSED } from '@jsii/spec'; -import * as fs from 'fs-extra'; +import * as fs from 'fs'; import * as path from 'path'; import { LanguageTablet, DEFAULT_TABLET_NAME, DEFAULT_TABLET_NAME_COMPRESSED } from '../../lib'; @@ -102,7 +102,7 @@ test('can log to output file', async () => { }); // assert that the output file exists and there is some information in the file. - const stats = await fs.stat(path.join(assembly.moduleDirectory, DEFAULT_INFUSION_RESULTS_NAME)); + const stats = await fs.promises.stat(path.join(assembly.moduleDirectory, DEFAULT_INFUSION_RESULTS_NAME)); expect(stats.isFile()).toBeTruthy(); expect(stats.size).toBeGreaterThan(0); @@ -150,7 +150,7 @@ test('preserves the assembly compression if present', async () => { await infuse([compAssembly.moduleDirectory]); // Expect file at SPEC_FILE_NAME to still be a file redirect (not the actual assembly) - expect(fs.readJSONSync(path.join(compAssembly.moduleDirectory, SPEC_FILE_NAME))).toEqual({ + expect(JSON.parse(fs.readFileSync(path.join(compAssembly.moduleDirectory, SPEC_FILE_NAME), 'utf-8'))).toEqual({ schema: 'jsii/file-redirect', compression: 'gzip', filename: SPEC_FILE_NAME_COMPRESSED, @@ -167,8 +167,8 @@ test('can infuse with compressed default tablets', async () => { // remove any tablets that may currently exist const implicitTablet = path.join(assembly.moduleDirectory, DEFAULT_TABLET_NAME); const compImplicitTablet = path.join(assembly.moduleDirectory, DEFAULT_TABLET_NAME_COMPRESSED); - await fs.remove(implicitTablet); - await fs.remove(compImplicitTablet); + await fs.promises.rm(implicitTablet, { force: true, recursive: true }); + await fs.promises.rm(compImplicitTablet, { force: true, recursive: true }); // create a compressed implicit tablet file via extract await extractSnippets([assembly.moduleDirectory], { diff --git a/packages/jsii-rosetta/test/commands/transliterate.test.ts b/packages/jsii-rosetta/test/commands/transliterate.test.ts index 585fe66c47..f42e018a0d 100644 --- a/packages/jsii-rosetta/test/commands/transliterate.test.ts +++ b/packages/jsii-rosetta/test/commands/transliterate.test.ts @@ -1,5 +1,5 @@ import { Assembly, SPEC_FILE_NAME, writeAssembly } from '@jsii/spec'; -import * as fs from 'fs-extra'; +import * as fs from 'fs'; import * as jsii from 'jsii'; import * as path from 'path'; @@ -96,12 +96,9 @@ export class ClassName implements IInterface { } }`, }); - fs.writeJsonSync( + fs.writeFileSync( path.join(tmpDir, SPEC_FILE_NAME), - { ...compilationResult.assembly, targets }, - { - spaces: 2, - }, + JSON.stringify({ ...compilationResult.assembly, targets }, null, 2), ); for (const [file, content] of Object.entries(compilationResult.files)) { fs.writeFileSync(path.resolve(tmpDir, file), content, 'utf-8'); @@ -121,7 +118,7 @@ export class ClassName implements IInterface { ).resolves.not.toThrow(); // THEN - expect(fs.readJsonSync(path.join(tmpDir, `${SPEC_FILE_NAME}.csharp`))).toMatchInlineSnapshot( + expect(JSON.parse(fs.readFileSync(path.join(tmpDir, `${SPEC_FILE_NAME}.csharp`), 'utf-8'))).toMatchInlineSnapshot( { fingerprint: expect.any(String), jsiiVersion: expect.any(String), @@ -376,7 +373,7 @@ export class ClassName implements IInterface { } `, ); - expect(fs.readJsonSync(path.join(tmpDir, `${SPEC_FILE_NAME}.java`))).toMatchInlineSnapshot( + expect(JSON.parse(fs.readFileSync(path.join(tmpDir, `${SPEC_FILE_NAME}.java`), 'utf-8'))).toMatchInlineSnapshot( { fingerprint: expect.any(String), jsiiVersion: expect.any(String), @@ -631,7 +628,7 @@ export class ClassName implements IInterface { } `, ); - expect(fs.readJsonSync(path.join(tmpDir, `${SPEC_FILE_NAME}.python`))).toMatchInlineSnapshot( + expect(JSON.parse(fs.readFileSync(path.join(tmpDir, `${SPEC_FILE_NAME}.python`), 'utf-8'))).toMatchInlineSnapshot( { fingerprint: expect.any(String), jsiiVersion: expect.any(String), @@ -934,12 +931,9 @@ import { SampleClass } from './index'; new SampleClass('omitted-literate'); `, }); - fs.writeJsonSync( + fs.writeFileSync( path.join(tmpDir, SPEC_FILE_NAME), - { ...compilationResult.assembly, targets }, - { - spaces: 2, - }, + JSON.stringify({ ...compilationResult.assembly, targets }, null, 2), ); for (const [file, content] of Object.entries(compilationResult.files)) { if (file.startsWith('omit-')) { @@ -956,7 +950,7 @@ new SampleClass('omitted-literate'); ).resolves.not.toThrow(); // THEN - expect(fs.readJsonSync(path.join(tmpDir, `${SPEC_FILE_NAME}.csharp`))).toMatchInlineSnapshot( + expect(JSON.parse(fs.readFileSync(path.join(tmpDir, `${SPEC_FILE_NAME}.csharp`), 'utf-8'))).toMatchInlineSnapshot( { fingerprint: expect.any(String), jsiiVersion: expect.any(String), @@ -1051,7 +1045,7 @@ new SampleClass('omitted-literate'); `, ); - expect(fs.readJsonSync(path.join(tmpDir, `${SPEC_FILE_NAME}.java`))).toMatchInlineSnapshot( + expect(JSON.parse(fs.readFileSync(path.join(tmpDir, `${SPEC_FILE_NAME}.java`), 'utf-8'))).toMatchInlineSnapshot( { fingerprint: expect.any(String), jsiiVersion: expect.any(String), @@ -1146,7 +1140,7 @@ new SampleClass('omitted-literate'); `, ); - expect(fs.readJsonSync(path.join(tmpDir, `${SPEC_FILE_NAME}.python`))).toMatchInlineSnapshot( + expect(JSON.parse(fs.readFileSync(path.join(tmpDir, `${SPEC_FILE_NAME}.python`), 'utf-8'))).toMatchInlineSnapshot( { fingerprint: expect.any(String), jsiiVersion: expect.any(String), @@ -1318,12 +1312,9 @@ export class ClassName implements IInterface { } }`, }); - fs.writeJsonSync( + fs.writeFileSync( path.join(tmpDir, SPEC_FILE_NAME), - { ...compilationResult.assembly, targets }, - { - spaces: 2, - }, + JSON.stringify({ ...compilationResult.assembly, targets }, null, 2), ); for (const [file, content] of Object.entries(compilationResult.files)) { fs.writeFileSync(path.resolve(tmpDir, file), content, 'utf-8'); @@ -1373,19 +1364,23 @@ test('will read translations from cache even if they are dirty', async () => { await extractSnippets([infusedAssembly.moduleDirectory]); // Mess up the extracted source file - const schema: TabletSchema = await fs.readJson(path.join(infusedAssembly.moduleDirectory, '.jsii.tabl.json')); + const schema: TabletSchema = JSON.parse( + await fs.promises.readFile(path.join(infusedAssembly.moduleDirectory, '.jsii.tabl.json'), 'utf-8'), + ); for (const snippet of Object.values(schema.snippets)) { snippet.translations[TargetLanguage.PYTHON] = { source: 'oops', version: '999', }; } - await fs.writeJson(path.join(infusedAssembly.moduleDirectory, '.jsii.tabl.json'), schema); + await fs.promises.writeFile(path.join(infusedAssembly.moduleDirectory, '.jsii.tabl.json'), JSON.stringify(schema)); // Run a transliterate, should have used the translation from the cache even though the version is wrong await transliterateAssembly([infusedAssembly.moduleDirectory], [TargetLanguage.PYTHON]); - const translated: Assembly = await fs.readJson(path.join(infusedAssembly.moduleDirectory, '.jsii.python')); + const translated: Assembly = JSON.parse( + await fs.promises.readFile(path.join(infusedAssembly.moduleDirectory, '.jsii.python'), 'utf-8'), + ); expect(translated.types?.['my_assembly.ClassA'].docs?.example).toEqual('oops'); } finally { infusedAssembly.cleanup(); @@ -1472,12 +1467,9 @@ export class ClassName implements IInterface { }`, }); - fs.writeJsonSync( + fs.writeFileSync( path.join(tmpDir, SPEC_FILE_NAME), - { ...compilationResult.assembly, targets }, - { - spaces: 2, - }, + JSON.stringify({ ...compilationResult.assembly, targets }, null, 2), ); for (const [file, content] of Object.entries(compilationResult.files)) { fs.writeFileSync(path.resolve(tmpDir, file), content, 'utf-8'); @@ -1586,12 +1578,13 @@ export class ClassName implements IInterface { }`, }); - fs.writeJsonSync( + fs.writeFileSync( path.join(tmpDir, SPEC_FILE_NAME), - { ...compilationResult.assembly, targets: { ...targets, [targetName(TargetLanguage.GO)]: undefined } }, - { - spaces: 2, - }, + JSON.stringify( + { ...compilationResult.assembly, targets: { ...targets, [targetName(TargetLanguage.GO)]: undefined } }, + null, + 2, + ), ); for (const [file, content] of Object.entries(compilationResult.files)) { fs.writeFileSync(path.resolve(tmpDir, file), content, 'utf-8'); @@ -1617,7 +1610,7 @@ export class ClassName implements IInterface { Object.values(TargetLanguage).forEach((lang) => { if (lang === TargetLanguage.GO) { - expect(fs.pathExistsSync(path.join(outdir, `${SPEC_FILE_NAME}.${lang}`))).toBe(false); + expect(fs.existsSync(path.join(outdir, `${SPEC_FILE_NAME}.${lang}`))).toBe(false); } else { expect(fs.statSync(path.join(outdir, `${SPEC_FILE_NAME}.${lang}`)).isFile()).toBe(true); } diff --git a/packages/jsii-rosetta/test/jsii/assemblies.test.ts b/packages/jsii-rosetta/test/jsii/assemblies.test.ts index 0cc73b8597..212072da7e 100644 --- a/packages/jsii-rosetta/test/jsii/assemblies.test.ts +++ b/packages/jsii-rosetta/test/jsii/assemblies.test.ts @@ -1,5 +1,5 @@ import * as spec from '@jsii/spec'; -import * as fs from 'fs-extra'; +import { promises as fs } from 'fs'; import * as mockfs from 'mock-fs'; import * as path from 'path'; @@ -252,7 +252,7 @@ test('rosetta fixture from submodule is preferred if it exists', async () => { }, ); try { - await fs.mkdirp(path.join(jsiiModule.moduleDirectory, 'rosetta', 'submodule')); + await fs.mkdir(path.join(jsiiModule.moduleDirectory, 'rosetta', 'submodule'), { recursive: true }); await fs.writeFile( path.join(jsiiModule.moduleDirectory, 'rosetta', 'submodule', 'default.ts-fixture'), 'pick me\n/// here', diff --git a/packages/jsii-rosetta/test/testutil.ts b/packages/jsii-rosetta/test/testutil.ts index a54efa47ba..231f396663 100644 --- a/packages/jsii-rosetta/test/testutil.ts +++ b/packages/jsii-rosetta/test/testutil.ts @@ -1,5 +1,5 @@ import { Assembly, writeAssembly } from '@jsii/spec'; -import * as fs from 'fs-extra'; +import * as fs from 'fs'; import { PackageInfo, compileJsiiForTest, TestWorkspace } from 'jsii'; import * as os from 'os'; import * as path from 'path'; @@ -129,5 +129,5 @@ export const DUMMY_JSII_CONFIG = { export async function withTemporaryDirectory(callback: (dir: string) => Promise): Promise { const tmpdir = fs.mkdtempSync(path.join(os.tmpdir(), path.basename(__filename))); - return callback(tmpdir).finally(() => fs.removeSync(tmpdir)); + return callback(tmpdir).finally(() => fs.rmSync(tmpdir, { recursive: true })); } diff --git a/packages/jsii-rosetta/test/translations.test.ts b/packages/jsii-rosetta/test/translations.test.ts index 29ff2ba1c8..86e4ed5a05 100644 --- a/packages/jsii-rosetta/test/translations.test.ts +++ b/packages/jsii-rosetta/test/translations.test.ts @@ -1,4 +1,4 @@ -import * as fs from 'fs-extra'; +import * as fs from 'fs'; import * as path from 'path'; import { SnippetTranslator } from '../lib';