From eb48e6d1a0d8152721a943cfa8469dc382ea2a49 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 10 Jul 2023 00:07:41 +0000 Subject: [PATCH 1/8] deps: prettier ~3.0.0 --- package.json | 2 +- yarn.lock | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 4f269d5b6..046e8c741 100644 --- a/package.json +++ b/package.json @@ -102,7 +102,7 @@ "npm-run-path": "^4.0.1", "npm-which": "^3.0.1", "picomatch": "^2.2.2", - "prettier": "~2.8.5", + "prettier": "~3.0.0", "read-pkg-up": "^7.0.1", "runtypes": "^6.0.0", "semantic-release": "^19.0.0", diff --git a/yarn.lock b/yarn.lock index 95e3c07f5..d96ca0264 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7908,11 +7908,16 @@ prelude-ls@^1.2.1: resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.2.1.tgz#debc6489d7a6e6b0e7611888cec880337d316396" integrity sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g== -prettier@^2.7.1, prettier@~2.8.5: +prettier@^2.7.1: version "2.8.8" resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.8.8.tgz#e8c5d7e98a4305ffe3de2e1fc4aca1a71c28b1da" integrity sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q== +prettier@~3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-3.0.0.tgz#e7b19f691245a21d618c68bc54dc06122f6105ae" + integrity sha512-zBf5eHpwHOGPC47h0zrPyNn+eAEIdEzfywMoYn2XPi0P44Zp0tSq64rq0xAREh4auw2cJZHo9QUob+NqCQky4g== + pretty-format@^29.0.0, pretty-format@^29.6.0: version "29.6.0" resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-29.6.0.tgz#c90c8f145187fe73240662527a513599c16f3b97" From 98b49eed2a059d69c1b5f5b6317d05facd0d8a37 Mon Sep 17 00:00:00 2001 From: samchungy Date: Thu, 13 Jul 2023 15:43:46 +1000 Subject: [PATCH 2/8] Make everything async --- src/cli/adapter/prettier.ts | 23 ++++++++++--------- src/cli/configure/addEmptyExports.ts | 2 +- src/cli/configure/analyseDependencies.ts | 2 +- src/cli/configure/analysis/project.ts | 10 ++++---- src/cli/configure/ensureTemplateCompletion.ts | 2 +- src/cli/configure/modules/jest.ts | 4 ++-- src/cli/configure/patchRenovateConfig.ts | 4 ++-- src/cli/configure/patchServerListener.ts | 2 +- .../configure/processing/typescript.test.ts | 4 ++-- src/cli/configure/processing/typescript.ts | 8 +++---- src/cli/configure/testing/module.ts | 6 ++--- src/cli/configure/types.ts | 2 +- src/cli/init/writePackageJson.ts | 2 +- 13 files changed, 36 insertions(+), 35 deletions(-) diff --git a/src/cli/adapter/prettier.ts b/src/cli/adapter/prettier.ts index 817aa185f..1448b478b 100644 --- a/src/cli/adapter/prettier.ts +++ b/src/cli/adapter/prettier.ts @@ -32,10 +32,11 @@ let languages: SupportLanguage[] | undefined; * - https://github.com/prettier/prettier/blob/2.4.1/src/main/options.js#L167 * - seek-oss/skuba#659 */ -export const inferParser = (filepath: string): string | undefined => { +export const inferParser = async (filepath: string): Promise => { const filename = path.basename(filepath).toLowerCase(); - languages ??= getSupportInfo().languages.filter((language) => language.since); + const supportInfo = await getSupportInfo() + languages ??= supportInfo.languages.filter((language) => language.since); const firstLanguage = languages.find( (language) => @@ -46,13 +47,13 @@ export const inferParser = (filepath: string): string | undefined => { return firstLanguage?.parsers[0]; }; -const isPackageJsonOk = ({ +const isPackageJsonOk = async ({ data, filepath, }: { data: string; filepath: string; -}): boolean => { +}): Promise => { if (path.basename(filepath) !== 'package.json') { return true; } @@ -60,7 +61,7 @@ const isPackageJsonOk = ({ try { const packageJson = parsePackage(data); - return !packageJson || formatPackage(packageJson) === data; + return !packageJson || await formatPackage(packageJson) === data; } catch { // Be more lenient about our custom formatting and don't throw if it errors. } @@ -81,15 +82,15 @@ interface Result { unparsed: string[]; } -const formatOrLintFile = ( +const formatOrLintFile = async ( { data, filepath, options }: File, mode: 'format' | 'lint', result: Result, -): string | undefined => { +): Promise => { if (mode === 'lint') { let ok: boolean; try { - ok = check(data, options) && isPackageJsonOk({ data, filepath }); + ok = (await check(data, options)) && (await isPackageJsonOk({ data, filepath })); } catch (err) { result.errored.push({ err, filepath }); return; @@ -104,7 +105,7 @@ const formatOrLintFile = ( let formatted: string; try { - formatted = format(data, options); + formatted = await format(data, options); } catch (err) { result.errored.push({ err, filepath }); return; @@ -115,7 +116,7 @@ const formatOrLintFile = ( if (path.basename(filepath) === 'package.json') { const packageJson = parsePackage(formatted); if (packageJson) { - formatted = formatPackage(packageJson); + formatted = await formatPackage(packageJson); } } } catch { @@ -183,7 +184,7 @@ export const runPrettier = async ( for (const filepath of filepaths) { // Infer parser upfront so we can skip unsupported files. - const parser = inferParser(filepath); + const parser = await inferParser(filepath); logger.debug(filepath); logger.debug(' parser:', parser ?? '-'); diff --git a/src/cli/configure/addEmptyExports.ts b/src/cli/configure/addEmptyExports.ts index f850415a5..5845f05bc 100644 --- a/src/cli/configure/addEmptyExports.ts +++ b/src/cli/configure/addEmptyExports.ts @@ -33,7 +33,7 @@ const addEmptyExports = async () => { return; } - const data = formatPrettier([inputFile, 'export {}'].join('\n\n'), { + const data = await formatPrettier([inputFile, 'export {}'].join('\n\n'), { parser: 'typescript', }); diff --git a/src/cli/configure/analyseDependencies.ts b/src/cli/configure/analyseDependencies.ts index 1d6822ba3..97d49b37c 100644 --- a/src/cli/configure/analyseDependencies.ts +++ b/src/cli/configure/analyseDependencies.ts @@ -124,7 +124,7 @@ export const analyseDependencies = async ({ } return async () => { - const updatedPackageJson = formatPackage({ + const updatedPackageJson = await formatPackage({ ...packageJson, dependencies: output.dependencies, devDependencies: output.devDependencies, diff --git a/src/cli/configure/analysis/project.ts b/src/cli/configure/analysis/project.ts index cd183036d..4064df42d 100644 --- a/src/cli/configure/analysis/project.ts +++ b/src/cli/configure/analysis/project.ts @@ -49,7 +49,7 @@ const loadModuleFiles = async (modules: Module[], destinationRoot: string) => { }; }; -const processTextFiles = ( +const processTextFiles = async ( modules: Module[], inputFiles: Readonly, patternToFilepaths: Record, @@ -68,13 +68,13 @@ const processTextFiles = ( }), ); - for (const [filepath, processText] of textProcessorEntries) { - outputFiles[filepath] = processText( + await Promise.all(textProcessorEntries.map(async ([filepath, processText]) => { + outputFiles[filepath] = await processText( outputFiles[filepath], outputFiles, inputFiles, ); - } + })) return outputFiles; }; @@ -86,7 +86,7 @@ export const diffFiles = async (opts: Options): Promise => { await loadModuleFiles(modules, opts.destinationRoot), ); - const outputFiles = processTextFiles(modules, inputFiles, patternToFilepaths); + const outputFiles = await processTextFiles(modules, inputFiles, patternToFilepaths); const diffEntries = Object.entries(outputFiles) .filter(([filepath, data]) => inputFiles[filepath] !== data) diff --git a/src/cli/configure/ensureTemplateCompletion.ts b/src/cli/configure/ensureTemplateCompletion.ts index 6a1ba6101..ebdf29716 100644 --- a/src/cli/configure/ensureTemplateCompletion.ts +++ b/src/cli/configure/ensureTemplateCompletion.ts @@ -41,7 +41,7 @@ export const ensureTemplateCompletion = async ({ name: 'customAnswers', }); - const updatedPackageJson = formatPackage(manifest.packageJson); + const updatedPackageJson = await formatPackage(manifest.packageJson); const packageJsonFilepath = path.join(destinationRoot, 'package.json'); await fs.promises.writeFile(packageJsonFilepath, updatedPackageJson); diff --git a/src/cli/configure/modules/jest.ts b/src/cli/configure/modules/jest.ts index 6aa7c430b..5a3ba7d10 100644 --- a/src/cli/configure/modules/jest.ts +++ b/src/cli/configure/modules/jest.ts @@ -44,7 +44,7 @@ export const jestModule = async (): Promise => { return { ...deleteFiles('jest.config.js', 'jest.setup.js'), - 'jest.config.ts': (tsFile, currentFiles, initialFiles) => { + 'jest.config.ts': async (tsFile, currentFiles, initialFiles) => { // Allow customised TS Jest config that extends skuba if (tsFile?.includes('skuba')) { return OUTDATED_ISOLATED_MODULES_CONFIG_SNIPPETS.reduce( @@ -66,7 +66,7 @@ export const jestModule = async (): Promise => { const inputFile = tsFile ?? jsFile; const props = - inputFile === undefined ? undefined : readModuleExports(inputFile); + inputFile === undefined ? undefined : await readModuleExports(inputFile); if (props === undefined) { return configFile; diff --git a/src/cli/configure/patchRenovateConfig.ts b/src/cli/configure/patchRenovateConfig.ts index 99d6da4db..7654023ea 100644 --- a/src/cli/configure/patchRenovateConfig.ts +++ b/src/cli/configure/patchRenovateConfig.ts @@ -60,7 +60,7 @@ const patchJson: PatchFile = async ({ filepath, input, presetToAdd }) => { await fs.promises.writeFile( filepath, - formatPrettier(JSON.stringify(config), { parser: 'json' }), + await formatPrettier(JSON.stringify(config), { parser: 'json' }), ); return; @@ -77,7 +77,7 @@ const patchJson5: PatchFile = async ({ filepath, input, presetToAdd }) => { await fs.promises.writeFile( filepath, - formatPrettier(fleece.patch(input, config), { parser: 'json5' }), + await formatPrettier(fleece.patch(input, config), { parser: 'json5' }), ); return; diff --git a/src/cli/configure/patchServerListener.ts b/src/cli/configure/patchServerListener.ts index dde520753..b2e0a45a7 100644 --- a/src/cli/configure/patchServerListener.ts +++ b/src/cli/configure/patchServerListener.ts @@ -42,7 +42,7 @@ const patchServerListener = async (dir: string) => { await fs.promises.writeFile( SERVER_LISTENER_FILENAME, - formatPrettier(listener, { + await formatPrettier(listener, { parser: 'typescript', }), ); diff --git a/src/cli/configure/processing/typescript.test.ts b/src/cli/configure/processing/typescript.test.ts index f466e09f2..d7f9a6590 100644 --- a/src/cli/configure/processing/typescript.test.ts +++ b/src/cli/configure/processing/typescript.test.ts @@ -236,8 +236,8 @@ describe('transformModuleImportsAndExports', () => { }); describe('readModuleExports', () => { - it('extracts props from a module.exports expression', () => { - const result = readModuleExports(JEST_CONFIG); + it('extracts props from a module.exports expression', async () => { + const result = await readModuleExports(JEST_CONFIG); assertDefined(result); expect(result).toHaveLength(5); diff --git a/src/cli/configure/processing/typescript.ts b/src/cli/configure/processing/typescript.ts index 5ea528046..29a327e17 100644 --- a/src/cli/configure/processing/typescript.ts +++ b/src/cli/configure/processing/typescript.ts @@ -286,10 +286,10 @@ export const createPropAppender = * * The props can then be used when transforming another source file. */ -export const readModuleExports = (inputFile: string): Props | undefined => { +export const readModuleExports = async (inputFile: string): Promise => { let result: Props | undefined; - transformModuleImportsAndExports(inputFile, (_, props) => (result = props)); + await transformModuleImportsAndExports(inputFile, (_, props) => (result = props)); return result; }; @@ -301,10 +301,10 @@ export const readModuleExports = (inputFile: string): Props | undefined => { * - Convert `module.exports =` into `export default` * - Run a transformer over the exported props */ -export const transformModuleImportsAndExports = ( +export const transformModuleImportsAndExports = async ( inputFile: string, transformProps: Transformer, -): string => { +): Promise => { const sourceFile = ts.createSourceFile('', inputFile, ts.ScriptTarget.Latest); const moduleExportsTransformer = diff --git a/src/cli/configure/testing/module.ts b/src/cli/configure/testing/module.ts index c2e3b99c4..4fdefbb74 100644 --- a/src/cli/configure/testing/module.ts +++ b/src/cli/configure/testing/module.ts @@ -38,13 +38,13 @@ export const executeModule = async ( // Some modules create a new file at the specified pattern. const filepaths = [pattern, ...allFilepaths.filter((p) => isMatch(p))]; - for (const filepath of [...new Set(filepaths)]) { - outputFiles[filepath] = processText( + await Promise.all([...new Set(filepaths)].map(async (filepath) => { + outputFiles[filepath] = await processText( outputFiles[filepath], outputFiles, inputFiles, ); - } + })) } return outputFiles; diff --git a/src/cli/configure/types.ts b/src/cli/configure/types.ts index 7e10c3f08..3f443174d 100644 --- a/src/cli/configure/types.ts +++ b/src/cli/configure/types.ts @@ -21,7 +21,7 @@ type FileProcessor = ( file: string | undefined, files: Files, initialFiles: Readonly, -) => string | undefined; +) => Promise | string | undefined; export type FileDiff = Record< string, diff --git a/src/cli/init/writePackageJson.ts b/src/cli/init/writePackageJson.ts index eef87de82..2ac4a391c 100644 --- a/src/cli/init/writePackageJson.ts +++ b/src/cli/init/writePackageJson.ts @@ -31,7 +31,7 @@ export const writePackageJson = async ({ version, }; - const updatedPackageJson = formatPackage(manifest.packageJson); + const updatedPackageJson = await formatPackage(manifest.packageJson); await fs.promises.writeFile(manifest.path, updatedPackageJson); }; From e74e4c945f6d17ba595a95cfe59b9a59e107701f Mon Sep 17 00:00:00 2001 From: Ryan Ling Date: Fri, 14 Jul 2023 12:01:56 +1000 Subject: [PATCH 3/8] See what happens with experimental-vm-modules --- .github/workflows/validate.yml | 4 ++++ CONTRIBUTING.md | 2 ++ 2 files changed, 6 insertions(+) diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 2c4e5a904..ee849b853 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -54,6 +54,8 @@ jobs: - name: Test run: yarn test:ci + env: + NODE_OPTIONS: --experimental-vm-modules - name: Lint run: yarn lint @@ -91,3 +93,5 @@ jobs: - if: github.head_ref != 'beta' && github.head_ref != 'changeset-release/master' && github.ref_name != 'beta' && github.ref_name != 'changeset-release/master' name: Test template run: yarn test:template ${{ matrix.template }} + env: + NODE_OPTIONS: --experimental-vm-modules diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4d4d17412..b995ca933 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -100,6 +100,8 @@ If all is well, they will merge your pull request into master. You may find it easier to develop alongside unit tests: ```shell +export NODE_OPTIONS=--experimental-vm-modules + yarn test --watch ``` From 8b7cbf4af13148b69e55e1e43b816edff06529ad Mon Sep 17 00:00:00 2001 From: Ryan Ling Date: Fri, 14 Jul 2023 12:33:36 +1000 Subject: [PATCH 4/8] Get format formatting --- src/cli/adapter/prettier.ts | 15 ++++++++----- src/cli/configure/analysis/project.ts | 22 ++++++++++++------- src/cli/configure/modules/jest.ts | 4 +++- src/cli/configure/processing/typescript.ts | 9 ++++++-- src/cli/configure/testing/module.ts | 16 ++++++++------ src/cli/lint/annotate/buildkite/prettier.ts | 4 +++- .../lambda-sqs-worker/src/testing/handler.ts | 4 ++-- 7 files changed, 47 insertions(+), 27 deletions(-) diff --git a/src/cli/adapter/prettier.ts b/src/cli/adapter/prettier.ts index 1448b478b..2a383a764 100644 --- a/src/cli/adapter/prettier.ts +++ b/src/cli/adapter/prettier.ts @@ -32,11 +32,12 @@ let languages: SupportLanguage[] | undefined; * - https://github.com/prettier/prettier/blob/2.4.1/src/main/options.js#L167 * - seek-oss/skuba#659 */ -export const inferParser = async (filepath: string): Promise => { +export const inferParser = async ( + filepath: string, +): Promise => { const filename = path.basename(filepath).toLowerCase(); - const supportInfo = await getSupportInfo() - languages ??= supportInfo.languages.filter((language) => language.since); + languages ??= (await getSupportInfo()).languages; const firstLanguage = languages.find( (language) => @@ -61,7 +62,7 @@ const isPackageJsonOk = async ({ try { const packageJson = parsePackage(data); - return !packageJson || await formatPackage(packageJson) === data; + return !packageJson || (await formatPackage(packageJson)) === data; } catch { // Be more lenient about our custom formatting and don't throw if it errors. } @@ -90,7 +91,9 @@ const formatOrLintFile = async ( if (mode === 'lint') { let ok: boolean; try { - ok = (await check(data, options)) && (await isPackageJsonOk({ data, filepath })); + ok = + (await check(data, options)) && + (await isPackageJsonOk({ data, filepath })); } catch (err) { result.errored.push({ err, filepath }); return; @@ -205,7 +208,7 @@ export const runPrettier = async ( options: { ...config, filepath }, }; - const formatted = formatOrLintFile(file, mode, result); + const formatted = await formatOrLintFile(file, mode, result); if (typeof formatted === 'string') { await fs.promises.writeFile(filepath, formatted); diff --git a/src/cli/configure/analysis/project.ts b/src/cli/configure/analysis/project.ts index 4064df42d..252c31948 100644 --- a/src/cli/configure/analysis/project.ts +++ b/src/cli/configure/analysis/project.ts @@ -68,13 +68,15 @@ const processTextFiles = async ( }), ); - await Promise.all(textProcessorEntries.map(async ([filepath, processText]) => { - outputFiles[filepath] = await processText( - outputFiles[filepath], - outputFiles, - inputFiles, - ); - })) + await Promise.all( + textProcessorEntries.map(async ([filepath, processText]) => { + outputFiles[filepath] = await processText( + outputFiles[filepath], + outputFiles, + inputFiles, + ); + }), + ); return outputFiles; }; @@ -86,7 +88,11 @@ export const diffFiles = async (opts: Options): Promise => { await loadModuleFiles(modules, opts.destinationRoot), ); - const outputFiles = await processTextFiles(modules, inputFiles, patternToFilepaths); + const outputFiles = await processTextFiles( + modules, + inputFiles, + patternToFilepaths, + ); const diffEntries = Object.entries(outputFiles) .filter(([filepath, data]) => inputFiles[filepath] !== data) diff --git a/src/cli/configure/modules/jest.ts b/src/cli/configure/modules/jest.ts index 5a3ba7d10..aaa656d54 100644 --- a/src/cli/configure/modules/jest.ts +++ b/src/cli/configure/modules/jest.ts @@ -66,7 +66,9 @@ export const jestModule = async (): Promise => { const inputFile = tsFile ?? jsFile; const props = - inputFile === undefined ? undefined : await readModuleExports(inputFile); + inputFile === undefined + ? undefined + : await readModuleExports(inputFile); if (props === undefined) { return configFile; diff --git a/src/cli/configure/processing/typescript.ts b/src/cli/configure/processing/typescript.ts index 29a327e17..6c1944e27 100644 --- a/src/cli/configure/processing/typescript.ts +++ b/src/cli/configure/processing/typescript.ts @@ -286,10 +286,15 @@ export const createPropAppender = * * The props can then be used when transforming another source file. */ -export const readModuleExports = async (inputFile: string): Promise => { +export const readModuleExports = async ( + inputFile: string, +): Promise => { let result: Props | undefined; - await transformModuleImportsAndExports(inputFile, (_, props) => (result = props)); + await transformModuleImportsAndExports( + inputFile, + (_, props) => (result = props), + ); return result; }; diff --git a/src/cli/configure/testing/module.ts b/src/cli/configure/testing/module.ts index 4fdefbb74..c6ca13cdc 100644 --- a/src/cli/configure/testing/module.ts +++ b/src/cli/configure/testing/module.ts @@ -38,13 +38,15 @@ export const executeModule = async ( // Some modules create a new file at the specified pattern. const filepaths = [pattern, ...allFilepaths.filter((p) => isMatch(p))]; - await Promise.all([...new Set(filepaths)].map(async (filepath) => { - outputFiles[filepath] = await processText( - outputFiles[filepath], - outputFiles, - inputFiles, - ); - })) + await Promise.all( + [...new Set(filepaths)].map(async (filepath) => { + outputFiles[filepath] = await processText( + outputFiles[filepath], + outputFiles, + inputFiles, + ); + }), + ); } return outputFiles; diff --git a/src/cli/lint/annotate/buildkite/prettier.ts b/src/cli/lint/annotate/buildkite/prettier.ts index cdd84792a..afae7e150 100644 --- a/src/cli/lint/annotate/buildkite/prettier.ts +++ b/src/cli/lint/annotate/buildkite/prettier.ts @@ -1,7 +1,9 @@ import * as Buildkite from '../../../../api/buildkite'; import type { PrettierOutput } from '../../../adapter/prettier'; -export const createPrettierAnnotations = (prettier: PrettierOutput): string[] => +export const createPrettierAnnotations = ( + prettier: PrettierOutput, +): string[] => !prettier.ok ? [ '**Prettier**', diff --git a/template/lambda-sqs-worker/src/testing/handler.ts b/template/lambda-sqs-worker/src/testing/handler.ts index 232d8714f..a7dd9c99d 100644 --- a/template/lambda-sqs-worker/src/testing/handler.ts +++ b/template/lambda-sqs-worker/src/testing/handler.ts @@ -5,9 +5,9 @@ import { chance } from './types'; export const createCtx = () => ({ awsRequestId: chance.guid({ version: 4 }), - } as Context); + }) as Context; export const createSqsEvent = (bodies: string[]) => ({ Records: bodies.map((body) => ({ body })), - } as SQSEvent); + }) as SQSEvent; From b2a99611832d3749f9366f8e08adcc6bedb1ccb1 Mon Sep 17 00:00:00 2001 From: samchungy Date: Fri, 14 Jul 2023 12:54:01 +1000 Subject: [PATCH 5/8] make tests async --- src/cli/adapter/prettier.test.ts | 6 +- src/cli/configure/processing/json.test.ts | 17 +++-- src/cli/configure/processing/package.test.ts | 24 +++--- .../configure/processing/typescript.test.ts | 76 +++++++++---------- 4 files changed, 63 insertions(+), 60 deletions(-) diff --git a/src/cli/adapter/prettier.test.ts b/src/cli/adapter/prettier.test.ts index 2885f937d..5c429a710 100644 --- a/src/cli/adapter/prettier.test.ts +++ b/src/cli/adapter/prettier.test.ts @@ -9,7 +9,9 @@ describe('inferParser', () => { ${'client.tsx'} | ${'typescript'} ${'server.ts'} | ${'typescript'} ${'vanilla.js'} | ${'babel'} - `('inferParser($filepath) === $parser', ({ filepath, parser }) => - expect(inferParser(filepath)).toBe(parser), + `( + 'inferParser($filepath) === $parser', + async ({ filepath, parser }) => + await expect(inferParser(filepath)).resolves.toBe(parser), ); }); diff --git a/src/cli/configure/processing/json.test.ts b/src/cli/configure/processing/json.test.ts index 4a5fc22ce..ebb61163e 100644 --- a/src/cli/configure/processing/json.test.ts +++ b/src/cli/configure/processing/json.test.ts @@ -1,14 +1,14 @@ import { formatObject, parseObject } from './json'; describe('formatObject', () => { - it('sorts and formats', () => - expect( + it('sorts and formats', async () => + await expect( formatObject({ b: 1, a: null, c: [], }), - ).toMatchInlineSnapshot(` + ).resolves.toMatchInlineSnapshot(` "{ "a": null, "b": 1, @@ -17,17 +17,18 @@ describe('formatObject', () => { " `)); - it('handles ordinary JSON array formatting', () => - expect(formatObject({ files: ['1', '2', '3'] })).toMatchInlineSnapshot(` + it('handles ordinary JSON array formatting', async () => + await expect(formatObject({ files: ['1', '2', '3'] })).resolves + .toMatchInlineSnapshot(` "{ "files": ["1", "2", "3"] } " `)); - it('handles special-cased package.json array formatting', () => - expect(formatObject({ files: ['1', '2', '3'] }, 'package.json')) - .toMatchInlineSnapshot(` + it('handles special-cased package.json array formatting', async () => + await expect(formatObject({ files: ['1', '2', '3'] }, 'package.json')) + .resolves.toMatchInlineSnapshot(` "{ "files": [ "1", diff --git a/src/cli/configure/processing/package.test.ts b/src/cli/configure/processing/package.test.ts index a93f34efd..4e902a9bd 100644 --- a/src/cli/configure/processing/package.test.ts +++ b/src/cli/configure/processing/package.test.ts @@ -66,22 +66,22 @@ describe('createDependencyFilter', () => { }); describe('withPackage', () => { - it('applies function', () => - expect( + it('applies function', async () => + await expect( withPackage((data) => { data.$name = 'unit-test'; return data; })('{}'), - ).toMatchInlineSnapshot(` + ).resolves.toMatchInlineSnapshot(` "{ "$name": "unit-test" } " `)); - it('preserves legitimate fields', () => - expect( + it('preserves legitimate fields', async () => + await expect( withPackage((data) => { data.$name = 'unit-test'; @@ -94,7 +94,7 @@ describe('withPackage', () => { name: 'my-package', }), ), - ).toMatchInlineSnapshot(` + ).resolves.toMatchInlineSnapshot(` "{ "name": "my-package", "version": "0.1.0", @@ -105,8 +105,8 @@ describe('withPackage', () => { " `)); - it('sorts fields', () => - expect( + it('sorts fields', async () => + await expect( withPackage((data) => data)( JSON.stringify({ devDependencies: { @@ -138,7 +138,7 @@ describe('withPackage', () => { files: ['b', 'a'], }), ), - ).toMatchInlineSnapshot(` + ).resolves.toMatchInlineSnapshot(` "{ "files": [ "b", @@ -170,14 +170,14 @@ describe('withPackage', () => { " `)); - it('handles bad JSON gracefully', () => - expect( + it('handles bad JSON gracefully', async () => + await expect( withPackage((data) => { data.$name = 'unit-test'; return data; })('}'), - ).toMatchInlineSnapshot(` + ).resolves.toMatchInlineSnapshot(` "{ "$name": "unit-test" } diff --git a/src/cli/configure/processing/typescript.test.ts b/src/cli/configure/processing/typescript.test.ts index d7f9a6590..f97e47196 100644 --- a/src/cli/configure/processing/typescript.test.ts +++ b/src/cli/configure/processing/typescript.test.ts @@ -27,146 +27,146 @@ const JEST_CONFIG = `export default { describe('transformModuleImportsAndExports', () => { const factory = ts.factory; - it('converts imports', () => { - expect( + it('converts imports', async () => { + await expect( transformModuleImportsAndExports("const abc = require('abc');\n", () => factory.createNodeArray(), ), - ).toMatchInlineSnapshot(` + ).resolves.toMatchInlineSnapshot(` "import abc from 'abc'; " `); - expect( + await expect( transformModuleImportsAndExports("const { a } = require('abc');\n", () => factory.createNodeArray(), ), - ).toMatchInlineSnapshot(` + ).resolves.toMatchInlineSnapshot(` "import { a } from 'abc'; " `); - expect( + await expect( transformModuleImportsAndExports( "const { a, b, c } = require('abc');\n", () => factory.createNodeArray(), ), - ).toMatchInlineSnapshot(` + ).resolves.toMatchInlineSnapshot(` "import { a, b, c } from 'abc'; " `); - expect( + await expect( transformModuleImportsAndExports("import abc from 'abc';\n", () => factory.createNodeArray(), ), - ).toMatchInlineSnapshot(` + ).resolves.toMatchInlineSnapshot(` "import abc from 'abc'; " `); }); - it('detects an object literal export', () => { - expect( + it('detects an object literal export', async () => { + await expect( transformModuleImportsAndExports( "module.exports = { key: 'value' };\n", () => factory.createNodeArray(), ), - ).toMatchInlineSnapshot(` + ).resolves.toMatchInlineSnapshot(` "export default {}; " `); - expect( + await expect( transformModuleImportsAndExports( "export default { key: 'value' };\n", () => factory.createNodeArray(), ), - ).toMatchInlineSnapshot(` + ).resolves.toMatchInlineSnapshot(` "export default {}; " `); }); - it('detects a single-arg call expression export', () => { - expect( + it('detects a single-arg call expression export', async () => { + await expect( transformModuleImportsAndExports( "export default Jest.mergePreset({ key: 'value' });\n", () => factory.createNodeArray(), ), - ).toMatchInlineSnapshot(` + ).resolves.toMatchInlineSnapshot(` "export default Jest.mergePreset({}); " `); - expect( + await expect( transformModuleImportsAndExports( "module.exports = Jest.mergePreset({ key: 'value' });\n", () => factory.createNodeArray(), ), - ).toMatchInlineSnapshot(` + ).resolves.toMatchInlineSnapshot(` "export default Jest.mergePreset({}); " `); }); - it('does not transform props of a multi-arg call expression export', () => { - expect( + it('does not transform props of a multi-arg call expression export', async () => { + await expect( transformModuleImportsAndExports( "export default Jest.mergePreset({ key: 'value' }, null, 2);\n", () => factory.createNodeArray(), ), - ).toMatchInlineSnapshot(` + ).resolves.toMatchInlineSnapshot(` "export default Jest.mergePreset({ key: 'value' }, null, 2); " `); - expect( + await expect( transformModuleImportsAndExports( "module.exports = Jest.mergePreset({ key: 'value' }, null, 2);\n", () => factory.createNodeArray(), ), - ).toMatchInlineSnapshot(` + ).resolves.toMatchInlineSnapshot(` "export default Jest.mergePreset({ key: 'value' }, null, 2); " `); }); - it('does not transform props of a function export', () => { - expect( + it('does not transform props of a function export', async () => { + await expect( transformModuleImportsAndExports( 'export default () => undefined;\n', () => factory.createNodeArray(), ), - ).toMatchInlineSnapshot(` + ).resolves.toMatchInlineSnapshot(` "export default () => undefined; " `); - expect( + await expect( transformModuleImportsAndExports( 'module.exports = () => undefined;\n', () => factory.createNodeArray(), ), - ).toMatchInlineSnapshot(` + ).resolves.toMatchInlineSnapshot(` "export default () => undefined; " `); }); - it('ignores a named export', () => - expect( + it('ignores a named export', async () => + await expect( transformModuleImportsAndExports( 'export const fn = () => undefined;\n', () => factory.createNodeArray(), ), - ).toMatchInlineSnapshot(` + ).resolves.toMatchInlineSnapshot(` "export const fn = () => undefined; " `)); - it('works with a no-op transformer', () => { - const result = transformModuleImportsAndExports( + it('works with a no-op transformer', async () => { + const result = await transformModuleImportsAndExports( JEST_CONFIG, (_, props) => props, ); @@ -174,7 +174,7 @@ describe('transformModuleImportsAndExports', () => { expect(result).toBe(JEST_CONFIG); }); - it('works with a prop appender', () => { + it('works with a prop appender', async () => { const append = createPropAppender( factory.createNodeArray([ factory.createPropertyAssignment( @@ -188,7 +188,7 @@ describe('transformModuleImportsAndExports', () => { ]), ); - const result = transformModuleImportsAndExports(JEST_CONFIG, append); + const result = await transformModuleImportsAndExports(JEST_CONFIG, append); expect(result).toMatchInlineSnapshot(` "export default { @@ -209,14 +209,14 @@ describe('transformModuleImportsAndExports', () => { `); }); - it('works with a prop filter', () => { + it('works with a prop filter', async () => { const filter = createPropFilter([ 'coverageThreshold', 'setupFilesAfterEnv', 'globalSetup', ]); - const result = transformModuleImportsAndExports(JEST_CONFIG, filter); + const result = await transformModuleImportsAndExports(JEST_CONFIG, filter); expect(result).toMatchInlineSnapshot(` "export default { From ea4d119c15d8880bf55a9c17826f42eaed29ac9d Mon Sep 17 00:00:00 2001 From: samchungy Date: Fri, 14 Jul 2023 13:10:11 +1000 Subject: [PATCH 6/8] test replacing promise map --- src/cli/configure/analysis/project.ts | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/cli/configure/analysis/project.ts b/src/cli/configure/analysis/project.ts index 252c31948..4de592ed6 100644 --- a/src/cli/configure/analysis/project.ts +++ b/src/cli/configure/analysis/project.ts @@ -68,15 +68,13 @@ const processTextFiles = async ( }), ); - await Promise.all( - textProcessorEntries.map(async ([filepath, processText]) => { - outputFiles[filepath] = await processText( - outputFiles[filepath], - outputFiles, - inputFiles, - ); - }), - ); + for (const [filepath, processText] of textProcessorEntries) { + outputFiles[filepath] = await processText( + outputFiles[filepath], + outputFiles, + inputFiles, + ); + } return outputFiles; }; From 19052bb17ffdd112f9ea7228ba4ca355714974de Mon Sep 17 00:00:00 2001 From: samchungy Date: Fri, 14 Jul 2023 13:13:51 +1000 Subject: [PATCH 7/8] remove promise map --- src/cli/configure/testing/module.ts | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/cli/configure/testing/module.ts b/src/cli/configure/testing/module.ts index c6ca13cdc..0013e6d6f 100644 --- a/src/cli/configure/testing/module.ts +++ b/src/cli/configure/testing/module.ts @@ -38,15 +38,13 @@ export const executeModule = async ( // Some modules create a new file at the specified pattern. const filepaths = [pattern, ...allFilepaths.filter((p) => isMatch(p))]; - await Promise.all( - [...new Set(filepaths)].map(async (filepath) => { - outputFiles[filepath] = await processText( - outputFiles[filepath], - outputFiles, - inputFiles, - ); - }), - ); + for (const filepath of [...new Set(filepaths)]) { + outputFiles[filepath] = await processText( + outputFiles[filepath], + outputFiles, + inputFiles, + ); + } } return outputFiles; From 6c8a2d9ffc7391bacf900f6aff060ebde4a58b5d Mon Sep 17 00:00:00 2001 From: Ryan Ling Date: Fri, 14 Jul 2023 13:41:16 +1000 Subject: [PATCH 8/8] Add changeset --- .changeset/lazy-foxes-clap.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .changeset/lazy-foxes-clap.md diff --git a/.changeset/lazy-foxes-clap.md b/.changeset/lazy-foxes-clap.md new file mode 100644 index 000000000..638e59188 --- /dev/null +++ b/.changeset/lazy-foxes-clap.md @@ -0,0 +1,7 @@ +--- +'skuba': minor +--- + +deps: Prettier 3.0 + +See the [release notes](https://prettier.io/blog/2023/07/05/3.0.0.html) for more information.