diff --git a/package-lock.json b/package-lock.json index e584b4ed..9b432e14 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,7 +20,7 @@ "eslint-config-prettier": "^8.8.0", "eslint-plugin-no-only-tests": "^3.1.0", "memfs": "^4.2.0", - "prettier": "^2.8.8", + "prettier": "^3.0.0", "react": "^18.2.0", "react-dom": "^18.2.0", "rimraf": "^5.0.1", @@ -712,9 +712,9 @@ "integrity": "sha512-NuHqBY1PB/D8xU6s/thBgOAiAP7HOYDQ32+BFZILJ8ivkUkAHQnWfn6WhL79Owj1qmUnoN/YPhktdIoucipkAQ==" }, "node_modules/acorn": { - "version": "8.9.0", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.9.0.tgz", - "integrity": "sha512-jaVNAFBHNLXspO543WnNNPZFRtavh3skAkITqD0/2aeMkKZTN+254PyhwxFYrk3vQ1xfY+2wbesJMs/JC8/PwQ==", + "version": "8.10.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.10.0.tgz", + "integrity": "sha512-F0SAmZ8iUtS//m8DmCTA0jlh6TDKkHQyK6xc6V4KDTyZKA9dnvX9/3sRTVQrWm79glUAZbnmmNcdYwUIHWVybw==", "bin": { "acorn": "bin/acorn" }, @@ -1026,9 +1026,9 @@ "dev": true }, "node_modules/electron-to-chromium": { - "version": "1.4.449", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.449.tgz", - "integrity": "sha512-TxLRpRUj/107ATefeP8VIUWNOv90xJxZZbCW/eIbSZQiuiFANCx2b7u+GbVc9X4gU+xnbvypNMYVM/WArE1DNQ==" + "version": "1.4.451", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.451.tgz", + "integrity": "sha512-YYbXHIBxAHe3KWvGOJOuWa6f3tgow44rBW+QAuwVp2DvGqNZeE//K2MowNdWS7XE8li5cgQDrX1LdBr41LufkA==" }, "node_modules/emoji-regex": { "version": "9.2.2", @@ -1506,9 +1506,9 @@ } }, "node_modules/glob/node_modules/minimatch": { - "version": "9.0.2", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.2.tgz", - "integrity": "sha512-PZOT9g5v2ojiTL7r1xF6plNHLtOeTpSlDI007As2NlA2aYBMfVom17yqa6QzhmDP8QOhn7LjHTg7DFCVSSa6yg==", + "version": "9.0.3", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.3.tgz", + "integrity": "sha512-RHiac9mvaRw0x3AYRgDC1CxAP7HTcNrrECeA8YYJeWnpo+2Q5CegtZjaotWTWxDG3UeGA1coE05iH1mPjT/2mg==", "dev": true, "dependencies": { "brace-expansion": "^2.0.1" @@ -2135,15 +2135,15 @@ } }, "node_modules/prettier": { - "version": "2.8.8", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.8.tgz", - "integrity": "sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==", + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.0.0.tgz", + "integrity": "sha512-zBf5eHpwHOGPC47h0zrPyNn+eAEIdEzfywMoYn2XPi0P44Zp0tSq64rq0xAREh4auw2cJZHo9QUob+NqCQky4g==", "dev": true, "bin": { - "prettier": "bin-prettier.js" + "prettier": "bin/prettier.cjs" }, "engines": { - "node": ">=10.13.0" + "node": ">=14" }, "funding": { "url": "https://github.com/prettier/prettier?sponsor=1" diff --git a/package.json b/package.json index e7d0f8d1..acca9706 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "eslint-config-prettier": "^8.8.0", "eslint-plugin-no-only-tests": "^3.1.0", "memfs": "^4.2.0", - "prettier": "^2.8.8", + "prettier": "^3.0.0", "react": "^18.2.0", "react-dom": "^18.2.0", "rimraf": "^5.0.1", diff --git a/packages/esm/src/create-loader.ts b/packages/esm/src/create-loader.ts index 76f6a03e..f65b819c 100644 --- a/packages/esm/src/create-loader.ts +++ b/packages/esm/src/create-loader.ts @@ -16,14 +16,14 @@ export type ModuleFormat = 'builtin' | 'commonjs' | 'json' | 'module' | 'wasm'; export type ResolveHook = ( specifier: string, context: { parentURL?: string; conditions: string[] }, - defaultResolve: ResolveHook + defaultResolve: ResolveHook, ) => { url: string; format?: ModuleFormat }; /** @url https://nodejs.org/docs/latest-v16.x/api/esm.html#loadurl-context-defaultload */ export type LoadHook = ( url: string, context: { format?: ModuleFormat }, - defaultTransformSource: LoadHook + defaultTransformSource: LoadHook, ) => { source: string | SharedArrayBuffer | Uint8Array; format: ModuleFormat; shortCircuit?: boolean }; export interface CreateLoaderOptions { @@ -37,7 +37,7 @@ export function createLoader({ compilerOptions, cwd }: CreateLoaderOptions) { const moduleResolutionCache = ts.createModuleResolutionCache( cwd, ts.sys.useCaseSensitiveFileNames ? (s) => s : (s) => s.toLowerCase(), - compilerOptions + compilerOptions, ); const resolve: ResolveHook = (specifier, context, defaultResolve) => { const { parentURL } = context; @@ -47,7 +47,7 @@ export function createLoader({ compilerOptions, cwd }: CreateLoaderOptions) { fileURLToPath(parentURL), compilerOptions, ts.sys, - moduleResolutionCache + moduleResolutionCache, ); if (resolvedModule && !definitionExtensions.has(resolvedModule.extension)) { diff --git a/packages/esm/src/load-tsconfig.ts b/packages/esm/src/load-tsconfig.ts index 40ca2d29..a75b8374 100644 --- a/packages/esm/src/load-tsconfig.ts +++ b/packages/esm/src/load-tsconfig.ts @@ -10,7 +10,7 @@ export function loadTsconfig(tsconfigPath: string): ts.CompilerOptions { const { options } = ts.parseJsonSourceFileConfigFileContent( ts.readJsonConfigFile(tsconfigPath, ts.sys.readFile), ts.sys, - dirname(tsconfigPath) + dirname(tsconfigPath), ); if (options.module === undefined || options.module < ts.ModuleKind.ES2015) { options.module = ts.ModuleKind.Node16; diff --git a/packages/node/src/node-extension.ts b/packages/node/src/node-extension.ts index be17dd6b..17a7bb22 100644 --- a/packages/node/src/node-extension.ts +++ b/packages/node/src/node-extension.ts @@ -140,7 +140,7 @@ export function createNodeExtension({ // couldn't find a cache directory, so fall back to a non-caching implementation return createTransformerExtension( (filePath) => - ts.transpileModule(readFileSync(filePath, 'utf8'), { fileName: filePath, compilerOptions }).outputText + ts.transpileModule(readFileSync(filePath, 'utf8'), { fileName: filePath, compilerOptions }).outputText, ); } @@ -175,7 +175,7 @@ export function createNodeExtension({ cacheDirectoryPath: optionsScopedCachePath, fileName: filePath, compilerOptions, - }).outputText + }).outputText, ); } diff --git a/packages/robotrix/src/cjs-to-esm-transformer.ts b/packages/robotrix/src/cjs-to-esm-transformer.ts index 4c7ef23b..4abb3e01 100644 --- a/packages/robotrix/src/cjs-to-esm-transformer.ts +++ b/packages/robotrix/src/cjs-to-esm-transformer.ts @@ -29,7 +29,7 @@ export interface ICjsToEsmTransformerOptions { * with a unique identifier. */ export function createCjsToEsmTransformer( - options: ICjsToEsmTransformerOptions = {} + options: ICjsToEsmTransformerOptions = {}, ): ts.TransformerFactory { return (context) => (sourceFile: ts.SourceFile): ts.SourceFile => @@ -39,7 +39,7 @@ export function createCjsToEsmTransformer( function transformSourceFile( sourceFile: ts.SourceFile, context: ts.TransformationContext, - { shouldTransform = () => true }: ICjsToEsmTransformerOptions + { shouldTransform = () => true }: ICjsToEsmTransformerOptions, ): ts.SourceFile { if (sourceFile.statements.some((node) => ts.isImportDeclaration(node) || ts.isExportDeclaration(node))) { // file has esm, so avoid cjs conversion. @@ -88,8 +88,8 @@ function transformSourceFile( factory.createImportDeclaration( undefined /* modifiers */, factory.createImportClause(false, importIdentifier, undefined /* namedBindings */), - node.arguments[0]! - ) + node.arguments[0]!, + ), ); // replace require call with identifier @@ -103,7 +103,7 @@ function transformSourceFile( // export default module.exports function createCjsExportDefault(factory: ts.NodeFactory) { return factory.createExportDefault( - factory.createPropertyAccessExpression(factory.createIdentifier('module'), 'exports') + factory.createPropertyAccessExpression(factory.createIdentifier('module'), 'exports'), ); } @@ -130,17 +130,17 @@ function createCjsModuleDefinition(factory: ts.NodeFactory) { 'exports', undefined /* exclamationToken */, undefined /* type */, - factory.createObjectLiteralExpression() + factory.createObjectLiteralExpression(), ), factory.createVariableDeclaration( 'module', undefined /* exclamationToken */, undefined /* type */, - factory.createObjectLiteralExpression([factory.createShorthandPropertyAssignment('exports')]) + factory.createObjectLiteralExpression([factory.createShorthandPropertyAssignment('exports')]), ), ], - ts.NodeFlags.Let - ) + ts.NodeFlags.Let, + ), ); } diff --git a/packages/robotrix/src/react-dev-transformer.ts b/packages/robotrix/src/react-dev-transformer.ts index 3c8edd61..c1322e8f 100644 --- a/packages/robotrix/src/react-dev-transformer.ts +++ b/packages/robotrix/src/react-dev-transformer.ts @@ -25,7 +25,7 @@ export function reactDevTransformer(context: ts.TransformationContext): ts.Trans // file-wide unique identifier that would point to the fileName string literal const jsxFileNameIdentifier = factory.createUniqueName( JSX_FILENAME, - ts.GeneratedIdentifierFlags.Optimistic | ts.GeneratedIdentifierFlags.FileLevel + ts.GeneratedIdentifierFlags.Optimistic | ts.GeneratedIdentifierFlags.FileLevel, ); // fist run the visitor, so it will mark whether we need to add fileName const declaration @@ -92,7 +92,7 @@ function findUserDefinedAttributes(node: ts.JsxAttributes) { function createSelfAttribute(factory: ts.NodeFactory): ts.JsxAttribute { return factory.createJsxAttribute( factory.createIdentifier(SELF), - factory.createJsxExpression(undefined, factory.createThis()) + factory.createJsxExpression(undefined, factory.createThis()), ); } @@ -100,7 +100,7 @@ function createSelfAttribute(factory: ts.NodeFactory): ts.JsxAttribute { function createSourceAttribute(locationObj: ts.ObjectLiteralExpression, factory: ts.NodeFactory): ts.JsxAttribute { return factory.createJsxAttribute( factory.createIdentifier(SOURCE), - factory.createJsxExpression(undefined, locationObj) + factory.createJsxExpression(undefined, locationObj), ); } @@ -109,7 +109,7 @@ function createLocationObject(jsxFileNameIdentifier: ts.Identifier, line: number return factory.createObjectLiteralExpression([ factory.createPropertyAssignment( 'fileName', - jsxFileNameIdentifier // use the file-wide identifier for fileName value + jsxFileNameIdentifier, // use the file-wide identifier for fileName value ), factory.createPropertyAssignment('lineNumber', factory.createNumericLiteral(String(line + 1))), ]); @@ -120,14 +120,14 @@ function addFileNameConst( sourceFile: ts.SourceFile, jsxFileNameIdentifier: ts.Identifier, fileName: string, - factory: ts.NodeFactory + factory: ts.NodeFactory, ): ts.SourceFile { const variableDecls = [ factory.createVariableDeclaration( jsxFileNameIdentifier, undefined /* exclamationToken */, undefined /* type */, - factory.createStringLiteral(fileName) + factory.createStringLiteral(fileName), ), ]; @@ -135,9 +135,9 @@ function addFileNameConst( sourceFile, factory.createVariableStatement( undefined /* modifiers */, - factory.createVariableDeclarationList(variableDecls, ts.NodeFlags.Const) + factory.createVariableDeclarationList(variableDecls, ts.NodeFlags.Const), ), - factory + factory, ); } @@ -145,7 +145,7 @@ function addFileNameConst( function insertStatementAfterImports( sourceFile: ts.SourceFile, statement: ts.Statement, - factory: ts.NodeFactory + factory: ts.NodeFactory, ): ts.SourceFile { const { statements } = sourceFile; diff --git a/packages/robotrix/src/remap-imports-transformer.ts b/packages/robotrix/src/remap-imports-transformer.ts index 15ea180a..880ef5f9 100644 --- a/packages/robotrix/src/remap-imports-transformer.ts +++ b/packages/robotrix/src/remap-imports-transformer.ts @@ -18,7 +18,7 @@ export function createRemapImportsTransformer({ export function remapSourceFileImports( sourceFile: ts.SourceFile, context: ts.TransformationContext, - remapTarget: IRemapImportsTransformerOptions['remapTarget'] + remapTarget: IRemapImportsTransformerOptions['remapTarget'], ): ts.SourceFile { const { factory } = context; const { fileName } = sourceFile; @@ -43,7 +43,7 @@ export function remapSourceFileImports( ts.getModifiers(node), node.importClause, factory.createStringLiteral(remappedTarget), - node.assertClause + node.assertClause, ); } } else if (ts.isExportDeclaration(node) && node.moduleSpecifier && ts.isStringLiteral(node.moduleSpecifier)) { @@ -56,7 +56,7 @@ export function remapSourceFileImports( node.isTypeOnly, node.exportClause, factory.createStringLiteral(remappedTarget), - node.assertClause + node.assertClause, ); } } diff --git a/packages/robotrix/src/resolved-modules-transformer.ts b/packages/robotrix/src/resolved-modules-transformer.ts index 9d09a2f2..04cc591c 100644 --- a/packages/robotrix/src/resolved-modules-transformer.ts +++ b/packages/robotrix/src/resolved-modules-transformer.ts @@ -22,7 +22,7 @@ export function resolvedModulesTransformer(context: ts.TransformationContext): t function remapImportsToResolvedModules( request: string, _containingFile: string, - { resolvedModules }: ResolvedSourceFile + { resolvedModules }: ResolvedSourceFile, ) { if (!resolvedModules || request.startsWith('./') || request.startsWith('../')) { // relative request or no typescript mapping. diff --git a/packages/robotrix/src/test/cjs-to-esm-transformer.test.ts b/packages/robotrix/src/test/cjs-to-esm-transformer.test.ts index 95c22254..1349f116 100644 --- a/packages/robotrix/src/test/cjs-to-esm-transformer.test.ts +++ b/packages/robotrix/src/test/cjs-to-esm-transformer.test.ts @@ -10,7 +10,7 @@ describe('CjsToEsmTransformer', () => { const compilerOptions: ts.CompilerOptions = { target: ts.ScriptTarget.ES2017 }; describe('wrapping of exports', () => { - it('wraps code using module.exports', () => { + it('wraps code using module.exports', async () => { const transformer = createCjsToEsmTransformer(); const code = `module.exports = 123`; @@ -19,17 +19,17 @@ describe('CjsToEsmTransformer', () => { compilerOptions, }); - codeEqual( + await codeEqual( outputText, ` ${cjsDef} ${code} ${cjsEsmExport} - ` + `, ); }); - it(`wraps code using module['exports']`, () => { + it(`wraps code using module['exports']`, async () => { const transformer = createCjsToEsmTransformer(); const code = `module['exports'] = 123`; @@ -38,17 +38,17 @@ describe('CjsToEsmTransformer', () => { compilerOptions, }); - codeEqual( + await codeEqual( outputText, ` ${cjsDef} ${code} ${cjsEsmExport} - ` + `, ); }); - it('wraps code using exports.', () => { + it('wraps code using exports.', async () => { const transformer = createCjsToEsmTransformer(); const code = `exports.do = 123`; @@ -57,17 +57,17 @@ describe('CjsToEsmTransformer', () => { compilerOptions, }); - codeEqual( + await codeEqual( outputText, ` ${cjsDef} ${code} ${cjsEsmExport} - ` + `, ); }); - it('wraps code using typeof exports', () => { + it('wraps code using typeof exports', async () => { const transformer = createCjsToEsmTransformer(); const code = `typeof exports`; @@ -76,19 +76,19 @@ describe('CjsToEsmTransformer', () => { compilerOptions, }); - codeEqual( + await codeEqual( outputText, ` ${cjsDef} ${code} ${cjsEsmExport} - ` + `, ); }); }); describe('handling require(...) calls', () => { - it('transforms require calls to default imports and wraps code as cjs', () => { + it('transforms require calls to default imports and wraps code as cjs', async () => { const transformer = createCjsToEsmTransformer(); const code = `module.exports = require('some-package')`; @@ -97,18 +97,18 @@ describe('CjsToEsmTransformer', () => { compilerOptions, }); - codeEqual( + await codeEqual( outputText, ` import _imported_1 from 'some-package' ${cjsDef} module.exports = _imported_1 ${cjsEsmExport} - ` + `, ); }); - it('wraps code as cjs even if just require() is used (without exports)', () => { + it('wraps code as cjs even if just require() is used (without exports)', async () => { const transformer = createCjsToEsmTransformer(); const code = `require('some-package')`; @@ -117,18 +117,18 @@ describe('CjsToEsmTransformer', () => { compilerOptions, }); - codeEqual( + await codeEqual( outputText, ` import _imported_1 from 'some-package' ${cjsDef} _imported_1 ${cjsEsmExport} - ` + `, ); }); - it('retains package names when variable declaration is detected', () => { + it('retains package names when variable declaration is detected', async () => { const transformer = createCjsToEsmTransformer(); const code = `const myPackage = require('some-package'), b = require('b')`; @@ -137,7 +137,7 @@ describe('CjsToEsmTransformer', () => { compilerOptions, }); - codeEqual( + await codeEqual( outputText, ` import myPackage_1 from 'some-package' @@ -145,11 +145,11 @@ describe('CjsToEsmTransformer', () => { ${cjsDef} const myPackage = myPackage_1, b = b_1 ${cjsEsmExport} - ` + `, ); }); - it('does not transform if a require function parameter is detected', () => { + it('does not transform if a require function parameter is detected', async () => { const transformer = createCjsToEsmTransformer(); const code = ` function test(require) { @@ -167,10 +167,10 @@ describe('CjsToEsmTransformer', () => { compilerOptions, }); - codeEqual(outputText, code); + await codeEqual(outputText, code); }); - it('does not transform require(...) calls inside a try block', () => { + it('does not transform require(...) calls inside a try block', async () => { const transformer = createCjsToEsmTransformer(); const code = ` try { @@ -183,10 +183,10 @@ describe('CjsToEsmTransformer', () => { compilerOptions, }); - codeEqual(outputText, code); + await codeEqual(outputText, code); }); - it('does not transform require(...) if esm is detected', () => { + it('does not transform require(...) if esm is detected', async () => { const transformer = createCjsToEsmTransformer(); const code = ` import { someSymbol } from 'somewhere' @@ -199,10 +199,10 @@ describe('CjsToEsmTransformer', () => { compilerOptions, }); - codeEqual(outputText, code); + await codeEqual(outputText, code); }); - it('does not transform if shouldTransform returns false', () => { + it('does not transform if shouldTransform returns false', async () => { const transformer = createCjsToEsmTransformer({ shouldTransform: (lib) => lib === 'a', }); @@ -217,7 +217,7 @@ describe('CjsToEsmTransformer', () => { compilerOptions, }); - codeEqual( + await codeEqual( outputText, ` import a_1 from 'a' @@ -225,7 +225,7 @@ describe('CjsToEsmTransformer', () => { const a = a_1 const b = require('b') ${cjsEsmExport} - ` + `, ); }); }); diff --git a/packages/robotrix/src/test/code-equal.ts b/packages/robotrix/src/test/code-equal.ts index d7e3e897..086f9559 100644 --- a/packages/robotrix/src/test/code-equal.ts +++ b/packages/robotrix/src/test/code-equal.ts @@ -3,8 +3,8 @@ import prettier from 'prettier'; const prettierOptions = { parser: 'typescript', endOfLine: 'lf' } as const; -export function codeEqual(actualCode: string, expectedCode: string) { - actualCode = prettier.format(actualCode, prettierOptions); - expectedCode = prettier.format(expectedCode, prettierOptions); +export async function codeEqual(actualCode: string, expectedCode: string) { + actualCode = await prettier.format(actualCode, prettierOptions); + expectedCode = await prettier.format(expectedCode, prettierOptions); equal(actualCode, expectedCode); } diff --git a/packages/robotrix/src/test/dead-ifs-transformer.test.ts b/packages/robotrix/src/test/dead-ifs-transformer.test.ts index 7902b57c..58f3f9fb 100644 --- a/packages/robotrix/src/test/dead-ifs-transformer.test.ts +++ b/packages/robotrix/src/test/dead-ifs-transformer.test.ts @@ -7,7 +7,7 @@ describe('DeadIfsTransformer', () => { const transformers: ts.CustomTransformers = { before: [deadIfsTransformer] }; const compilerOptions: ts.CompilerOptions = { target: ts.ScriptTarget.ES2017 }; - it('detects if (true) and cancels else branch', () => { + it('detects if (true) and cancels else branch', async () => { const code = ` if (true) { shouldBeKept @@ -18,17 +18,17 @@ describe('DeadIfsTransformer', () => { const { outputText } = ts.transpileModule(code, { compilerOptions, transformers }); - codeEqual( + await codeEqual( outputText, ` if (true) { shouldBeKept } - ` + `, ); }); - it('detects if (false) and cancels then branch', () => { + it('detects if (false) and cancels then branch', async () => { const code = ` if (false) { shouldBeRemoved @@ -39,18 +39,18 @@ describe('DeadIfsTransformer', () => { const { outputText } = ts.transpileModule(code, { compilerOptions, transformers }); - codeEqual( + await codeEqual( outputText, ` if (false) { } else { shouldBeKept } - ` + `, ); }); - it('checks `else if` as well', () => { + it('checks `else if` as well', async () => { const code = ` if (false) { shouldBeRemoved @@ -63,19 +63,19 @@ describe('DeadIfsTransformer', () => { const { outputText } = ts.transpileModule(code, { compilerOptions, transformers }); - codeEqual( + await codeEqual( outputText, ` if (false) { } else if (true) { shouldBeKept } - ` + `, ); }); describe('string equality checks', () => { - it('handles === when strings are equal', () => { + it('handles === when strings are equal', async () => { const code = ` if ('same' === 'same') { shouldBeKept @@ -86,17 +86,17 @@ describe('DeadIfsTransformer', () => { const { outputText } = ts.transpileModule(code, { compilerOptions, transformers }); - codeEqual( + await codeEqual( outputText, ` if (true) { shouldBeKept } - ` + `, ); }); - it('handles === when actual strings are not equal', () => { + it('handles === when actual strings are not equal', async () => { const code = ` if ('text' === 'another') { shouldBeRemoved @@ -107,18 +107,18 @@ describe('DeadIfsTransformer', () => { const { outputText } = ts.transpileModule(code, { compilerOptions, transformers }); - codeEqual( + await codeEqual( outputText, ` if (false) { } else { shouldBeKept } - ` + `, ); }); - it('handles !== when actual strings are equal', () => { + it('handles !== when actual strings are equal', async () => { const code = ` if ('same' !== 'same') { shouldBeRemoved @@ -129,18 +129,18 @@ describe('DeadIfsTransformer', () => { const { outputText } = ts.transpileModule(code, { compilerOptions, transformers }); - codeEqual( + await codeEqual( outputText, ` if (false) { } else { shouldBeKept } - ` + `, ); }); - it('handles !== when actual strings are not equal', () => { + it('handles !== when actual strings are not equal', async () => { const code = ` if ('text' !== 'another') { shouldBeKept @@ -151,13 +151,13 @@ describe('DeadIfsTransformer', () => { const { outputText } = ts.transpileModule(code, { compilerOptions, transformers }); - codeEqual( + await codeEqual( outputText, ` if (true) { shouldBeKept } - ` + `, ); }); }); diff --git a/packages/robotrix/src/test/node-env-transformer.test.ts b/packages/robotrix/src/test/node-env-transformer.test.ts index c8f40caf..a2f150fc 100644 --- a/packages/robotrix/src/test/node-env-transformer.test.ts +++ b/packages/robotrix/src/test/node-env-transformer.test.ts @@ -4,44 +4,44 @@ import { createNodeEnvTransformer } from '@ts-tools/robotrix'; import { codeEqual } from './code-equal'; describe('NodeEnvTransformer', () => { - it('replaces process.env.[PARAM] using provided dictionary', () => { + it('replaces process.env.[PARAM] using provided dictionary', async () => { const transformer = createNodeEnvTransformer({ NODE_ENV: 'TEST', PARAM2: 'SOMEVALUE' }); const code = `process.env.NODE_ENV || process.env.PARAM2`; const { outputText } = ts.transpileModule(code, { transformers: { before: [transformer] } }); - codeEqual(outputText, `"TEST" || "SOMEVALUE"`); + await codeEqual(outputText, `"TEST" || "SOMEVALUE"`); }); - it('replaces keys pointing to empty strings', () => { + it('replaces keys pointing to empty strings', async () => { const transformer = createNodeEnvTransformer({ EMPTY: '' }); const code = `process.env.EMPTY`; const { outputText } = ts.transpileModule(code, { transformers: { before: [transformer] } }); - codeEqual(outputText, `""`); + await codeEqual(outputText, `""`); }); - it('does not replace unmapped keys', () => { + it('does not replace unmapped keys', async () => { const transformer = createNodeEnvTransformer({}); const code = `process.env.NOT_MAPPED`; const { outputText } = ts.transpileModule(code, { transformers: { before: [transformer] } }); - codeEqual(outputText, code); + await codeEqual(outputText, code); }); - it('does not replace keys pointing to undefined', () => { + it('does not replace keys pointing to undefined', async () => { const transformer = createNodeEnvTransformer({ NOOP: undefined }); const code = `process.env.NOOP`; const { outputText } = ts.transpileModule(code, { transformers: { before: [transformer] } }); - codeEqual(outputText, code); + await codeEqual(outputText, code); }); - it('does not replace inherited Object attributes', () => { + it('does not replace inherited Object attributes', async () => { const transformer = createNodeEnvTransformer({}); const code = `process.env.toString`; const { outputText } = ts.transpileModule(code, { transformers: { before: [transformer] } }); - codeEqual(outputText, code); + await codeEqual(outputText, code); }); }); diff --git a/packages/robotrix/src/test/react-dev-transformer.test.ts b/packages/robotrix/src/test/react-dev-transformer.test.ts index 88dc962a..fe1e95a4 100644 --- a/packages/robotrix/src/test/react-dev-transformer.test.ts +++ b/packages/robotrix/src/test/react-dev-transformer.test.ts @@ -9,7 +9,7 @@ describe('ReactDevTransformer', () => { const fileName = '/path/to/test-file.tsx'; const jsxFileNameDef = `const __jsxFileName = "${fileName}";`; - it('adds __self and __source attributes to jsx elements', () => { + it('adds __self and __source attributes to jsx elements', async () => { const code = ` (
@@ -18,18 +18,18 @@ describe('ReactDevTransformer', () => { const { outputText } = ts.transpileModule(code, { compilerOptions, transformers, fileName }); - codeEqual( + await codeEqual( outputText, ` ${jsxFileNameDef} (
) - ` + `, ); }); - it('adds attributes to jsx elements inside jsx attributes', () => { + it('adds attributes to jsx elements inside jsx attributes', async () => { const code = ` (
} @@ -38,7 +38,7 @@ describe('ReactDevTransformer', () => { const { outputText } = ts.transpileModule(code, { compilerOptions, transformers, fileName }); - codeEqual( + await codeEqual( outputText, ` ${jsxFileNameDef} @@ -46,29 +46,29 @@ describe('ReactDevTransformer', () => { icon={

} __self={this} __source={{ fileName: __jsxFileName, lineNumber: 2 }} />) - ` + `, ); }); - it('does not override existing __source attribute set by user', () => { + it('does not override existing __source attribute set by user', async () => { const code = `(

) `; const { outputText } = ts.transpileModule(code, { compilerOptions, transformers, fileName }); - codeEqual(outputText, `(
)`); + await codeEqual(outputText, `(
)`); }); - it('does not override existing __self attribute set by user', () => { + it('does not override existing __self attribute set by user', async () => { const code = `(
) `; const { outputText } = ts.transpileModule(code, { compilerOptions, transformers, fileName }); - codeEqual( + await codeEqual( outputText, ` ${jsxFileNameDef} (
) - ` + `, ); }); }); diff --git a/packages/robotrix/src/test/remap-imports-transformer.test.ts b/packages/robotrix/src/test/remap-imports-transformer.test.ts index 30ac94d1..3d267e0d 100644 --- a/packages/robotrix/src/test/remap-imports-transformer.test.ts +++ b/packages/robotrix/src/test/remap-imports-transformer.test.ts @@ -10,7 +10,7 @@ describe('RemapImportsTransformer', () => { remapTarget: (target) => (target === 'A' ? 'B' : target), }); - it('remaps static imports', () => { + it('remaps static imports', async () => { const code = ` import {namedSymbol} from "A" import * as namespaceSymbol from "A" @@ -23,18 +23,18 @@ describe('RemapImportsTransformer', () => { compilerOptions, }); - codeEqual( + await codeEqual( outputText, ` import {namedSymbol} from "B" import * as namespaceSymbol from "B" import "B" console.log(namedSymbol, namespaceSymbol) - ` + `, ); }); - it('remaps re-exports', () => { + it('remaps re-exports', async () => { const code = ` export {someSymbol} from "A" export * from "A" @@ -45,16 +45,16 @@ describe('RemapImportsTransformer', () => { compilerOptions, }); - codeEqual( + await codeEqual( outputText, ` export {someSymbol} from "B" export * from "B" - ` + `, ); }); - it('remaps dynamic imports', () => { + it('remaps dynamic imports', async () => { const code = ` import("A").then(console.log) `; @@ -64,15 +64,15 @@ describe('RemapImportsTransformer', () => { compilerOptions, }); - codeEqual( + await codeEqual( outputText, ` import("B").then(console.log) - ` + `, ); }); - it('remaps common js require calls', () => { + it('remaps common js require calls', async () => { const code = ` require("A") `; @@ -82,11 +82,11 @@ describe('RemapImportsTransformer', () => { compilerOptions, }); - codeEqual( + await codeEqual( outputText, ` require("B") - ` + `, ); }); }); diff --git a/packages/transpile/src/helpers/cache.ts b/packages/transpile/src/helpers/cache.ts index d2989c74..6d88e4b6 100644 --- a/packages/transpile/src/helpers/cache.ts +++ b/packages/transpile/src/helpers/cache.ts @@ -25,7 +25,7 @@ export function calcSha1(data: string): string { // eslint-disable-next-line export function createCachedFn unknown>( fn: FN, - argsToCacheKey: (...args: Parameters) => string + argsToCacheKey: (...args: Parameters) => string, ): [FN, Map>] { const cache = new Map>(); const cachedFn = (...args: Parameters) => { diff --git a/packages/transpile/src/transpile-cached.ts b/packages/transpile/src/transpile-cached.ts index d82b5fb9..302b5fb5 100644 --- a/packages/transpile/src/transpile-cached.ts +++ b/packages/transpile/src/transpile-cached.ts @@ -28,7 +28,7 @@ export function transpileCached(options: ITranspileCachedOptions): ts.TranspileO const transpiledOutput = ts.transpileModule( typeof fileContents === 'string' ? fileContents : readFileSync(filePath, 'utf8'), - options + options, ); writeCacheFileSync(cacheFilePath, { diff --git a/packages/webpack-loader/src/typescript-loader.ts b/packages/webpack-loader/src/typescript-loader.ts index 6418740c..1e62b9fe 100755 --- a/packages/webpack-loader/src/typescript-loader.ts +++ b/packages/webpack-loader/src/typescript-loader.ts @@ -18,7 +18,7 @@ const identity = (value: string) => value; const [cachedFindConfigFile] = createCachedFn( ts.findConfigFile, - (searchPath, _, configName) => searchPath + delimiter + String(configName) + (searchPath, _, configName) => searchPath + delimiter + String(configName), ); const [cachedReadAndParseConfigFile] = createCachedFn(readAndParseConfigFile, identity); const [cachedFindCacheDirectory] = createCachedFn(findCacheDirectory, identity);