From b0fbea249d81ac134a781fd06596a18fdeea43eb Mon Sep 17 00:00:00 2001 From: Daniel Perez Alvarez Date: Tue, 6 Aug 2024 17:06:57 -0400 Subject: [PATCH] chore: format code with prettier --- .all-contributorsrc | 79 ++++++------------------- README.md | 38 ++++++------ register.js | 2 +- src/harmony/utils.ts | 5 +- src/harmony/versions/four-seven.ts | 16 ++--- src/harmony/versions/three-eight.ts | 18 +++--- src/register.ts | 8 +-- src/transformer.ts | 6 +- src/utils/elide-import-export.ts | 12 ++-- src/utils/get-relative-path.ts | 2 +- src/utils/resolve-module-name.ts | 4 +- src/utils/resolve-path-update-node.ts | 4 +- src/utils/ts-helpers.ts | 8 +-- src/visitor.ts | 12 ++-- test/tests/extras.test.ts | 2 +- test/tests/register.test.ts | 8 +-- test/tests/transformer/general.test.ts | 2 +- test/tests/transformer/specific.test.ts | 28 ++++----- test/utils/helpers.ts | 21 ++++--- types/index.d.ts | 4 +- 20 files changed, 118 insertions(+), 161 deletions(-) diff --git a/.all-contributorsrc b/.all-contributorsrc index 2a75158..283340c 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -3,9 +3,7 @@ "projectOwner": "LeDDGroup", "repoType": "github", "repoHost": "https://github.com", - "files": [ - "README.md" - ], + "files": ["README.md"], "imageSize": 100, "commit": true, "commitConvention": "angular", @@ -15,155 +13,112 @@ "name": "Daniel Perez Alvarez", "avatar_url": "https://avatars2.githubusercontent.com/u/17787042?v=4", "profile": "https://github.com/danielpza", - "contributions": [ - "code", - "maintenance", - "test" - ] + "contributions": ["code", "maintenance", "test"] }, { "login": "anion155", "name": "Михайлов Антон", "avatar_url": "https://avatars1.githubusercontent.com/u/4786672?v=4", "profile": "https://github.com/anion155", - "contributions": [ - "code", - "bug", - "test" - ] + "contributions": ["code", "bug", "test"] }, { "login": "joshuaavalon", "name": "Joshua Avalon", "avatar_url": "https://avatars0.githubusercontent.com/u/7152420?v=4", "profile": "https://joshuaavalon.io", - "contributions": [ - "bug", - "platform" - ] + "contributions": ["bug", "platform"] }, { "login": "roblav96", "name": "Robert Laverty", "avatar_url": "https://avatars1.githubusercontent.com/u/1457327?v=4", "profile": "https://roblav96.github.io/resume", - "contributions": [ - "bug", - "test" - ] + "contributions": ["bug", "test"] }, { "login": "oleersoy", "name": "Ole Ersoy", "avatar_url": "https://avatars3.githubusercontent.com/u/1163873?v=4", "profile": "https://github.com/oleersoy", - "contributions": [ - "bug", - "blog" - ] + "contributions": ["bug", "blog"] }, { "login": "sbmw", "name": "sbmw", "avatar_url": "https://avatars0.githubusercontent.com/u/30099628?v=4", "profile": "https://github.com/sbmw", - "contributions": [ - "bug" - ] + "contributions": ["bug"] }, { "login": "richardspence", "name": "richardspence", "avatar_url": "https://avatars2.githubusercontent.com/u/9914123?v=4", "profile": "https://github.com/richardspence", - "contributions": [ - "bug" - ] + "contributions": ["bug"] }, { "login": "viT-1", "name": "Vitaly Pinchuk", "avatar_url": "https://avatars1.githubusercontent.com/u/19496430?v=4", "profile": "http://codepen.io/viT-1/", - "contributions": [ - "bug" - ] + "contributions": ["bug"] }, { "login": "laij84", "name": "laij84", "avatar_url": "https://avatars0.githubusercontent.com/u/18145822?v=4", "profile": "https://github.com/laij84", - "contributions": [ - "bug" - ] + "contributions": ["bug"] }, { "login": "dko-slapdash", "name": "dko-slapdash", "avatar_url": "https://avatars0.githubusercontent.com/u/46383452?v=4", "profile": "https://github.com/dko-slapdash", - "contributions": [ - "bug" - ] + "contributions": ["bug"] }, { "login": "hedwiggggg", "name": "hedwiggggg", "avatar_url": "https://avatars1.githubusercontent.com/u/42947316?v=4", "profile": "https://github.com/hedwiggggg", - "contributions": [ - "bug", - "test", - "code" - ] + "contributions": ["bug", "test", "code"] }, { "login": "kuskoman", "name": "kuskoman", "avatar_url": "https://avatars3.githubusercontent.com/u/15456923?v=4", "profile": "https://github.com/kuskoman", - "contributions": [ - "doc" - ] + "contributions": ["doc"] }, { "login": "booninite", "name": "alex weidner", "avatar_url": "https://avatars3.githubusercontent.com/u/13647495?v=4", "profile": "https://github.com/booninite", - "contributions": [ - "bug" - ] + "contributions": ["bug"] }, { "login": "nonara", "name": "Ron S.", "avatar_url": "https://avatars0.githubusercontent.com/u/1427565?v=4", "profile": "https://github.com/nonara", - "contributions": [ - "bug", - "test", - "code" - ] + "contributions": ["bug", "test", "code"] }, { "login": "vladimiry", "name": "Vladimir Yakovlev", "avatar_url": "https://avatars2.githubusercontent.com/u/1560781?v=4", "profile": "https://github.com/vladimiry", - "contributions": [ - "bug" - ] + "contributions": ["bug"] }, { "login": "vwpo", "name": "vwpo", "avatar_url": "https://avatars3.githubusercontent.com/u/57674261?v=4", "profile": "https://github.com/vwpo", - "contributions": [ - "bug" - ] + "contributions": ["bug"] } ], "contributorsPerLine": 7, diff --git a/README.md b/README.md index 60a7af6..078c6db 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ Add it to _plugins_ in your _tsconfig.json_ "baseUrl": "./", // Configure your path mapping here "paths": { - "@utils/*": ["utils/*"] + "@utils/*": ["utils/*"], }, // Note: To transform paths for both the output .js and .d.ts files, you need both of the below entries "plugins": [ @@ -36,9 +36,9 @@ Add it to _plugins_ in your _tsconfig.json_ { "transform": "typescript-transform-paths" }, // Transform paths in output .d.ts files (Include this line if you output declarations files) - { "transform": "typescript-transform-paths", "afterDeclarations": true } - ] - } + { "transform": "typescript-transform-paths", "afterDeclarations": true }, + ], + }, } ``` @@ -86,12 +86,12 @@ import { sum } from "@utils/sum"; "transformers": [ { "name": "typescript-transform-paths/nx-transformer", - "options": { "afterDeclarations": true } - } - ] - } - } - } + "options": { "afterDeclarations": true }, + }, + ], + }, + }, + }, } ``` @@ -108,13 +108,13 @@ To enable virtual directory mapping, use the `useRootDirs` plugin option. "rootDirs": ["src", "generated"], "baseUrl": ".", "paths": { - "#root/*": ["./src/*", "./generated/*"] + "#root/*": ["./src/*", "./generated/*"], }, "plugins": [ { "transform": "typescript-transform-paths", "useRootDirs": true }, - { "transform": "typescript-transform-paths", "useRootDirs": true, "afterDeclarations": true } - ] - } + { "transform": "typescript-transform-paths", "useRootDirs": true, "afterDeclarations": true }, + ], + }, } ``` @@ -158,15 +158,15 @@ Example: "compilerOptions": { "paths": { "sub-module1/*": ["../../node_modules/sub-module1/*"], - "sub-module2/*": ["../../node_modules/sub-module2/*"] + "sub-module2/*": ["../../node_modules/sub-module2/*"], }, "plugins": [ { "transform": "typescript-transform-paths", - "exclude": ["**/node_modules/**"] - } - ] - } + "exclude": ["**/node_modules/**"], + }, + ], + }, } ``` diff --git a/register.js b/register.js index 172f7ff..6e9b581 100755 --- a/register.js +++ b/register.js @@ -3,7 +3,7 @@ try { tsNode = require("ts-node"); } catch { throw new Error( - `Cannot resolve ts-node. Make sure ts-node is installed before using typescript-transform-paths/register` + `Cannot resolve ts-node. Make sure ts-node is installed before using typescript-transform-paths/register`, ); } diff --git a/src/harmony/utils.ts b/src/harmony/utils.ts index 6eb8beb..48c15a4 100644 --- a/src/harmony/utils.ts +++ b/src/harmony/utils.ts @@ -13,9 +13,8 @@ export type DownSampleTsTypes = T extends Exclude - ? Extract[1] - : T; +type DownSampleTsType = + T extends Exclude ? Extract[1] : T; // @formatter:on // endregion diff --git a/src/harmony/versions/four-seven.ts b/src/harmony/versions/four-seven.ts index 34c11d1..6d0d9f6 100644 --- a/src/harmony/versions/four-seven.ts +++ b/src/harmony/versions/four-seven.ts @@ -32,7 +32,7 @@ export namespace TsFourSeven { [TsCurrentModule.NamedExportBindings, TsFourSevenModule.NamedExportBindings], [TsCurrentModule.ModuleDeclaration, TsFourSevenModule.ModuleDeclaration], [TsCurrentModule.ModuleName, TsFourSevenModule.ModuleName], - [TsCurrentModule.ModuleBody, TsFourSevenModule.ModuleBody] + [TsCurrentModule.ModuleBody, TsFourSevenModule.ModuleBody], ]; } @@ -56,13 +56,13 @@ export namespace TsFourSeven { modifiers: readonly Modifier[] | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression, - assertClause: AssertClause | undefined + assertClause: AssertClause | undefined, ) { const [dsNode, dsImportClause, dsModuleSpecifier, dsAssertClause] = downSample( node, importClause, moduleSpecifier, - assertClause + assertClause, ); return factory.updateImportDeclaration( @@ -71,7 +71,7 @@ export namespace TsFourSeven { dsNode.modifiers, dsImportClause, dsModuleSpecifier, - dsAssertClause + dsAssertClause, ); }; case "updateExportDeclaration": @@ -81,13 +81,13 @@ export namespace TsFourSeven { isTypeOnly: boolean, exportClause: NamedExportBindings | undefined, moduleSpecifier: Expression | undefined, - assertClause: AssertClause | undefined + assertClause: AssertClause | undefined, ) { const [dsNode, dsExportClause, dsModuleSpecifier, dsAssertClause] = downSample( node, exportClause, moduleSpecifier, - assertClause + assertClause, ); return factory.updateExportDeclaration( @@ -97,7 +97,7 @@ export namespace TsFourSeven { isTypeOnly, dsExportClause, dsModuleSpecifier, - dsAssertClause + dsAssertClause, ); }; case "updateModuleDeclaration": @@ -105,7 +105,7 @@ export namespace TsFourSeven { node: ModuleDeclaration, modifiers: readonly Modifier[] | undefined, name: ModuleName, - body: ModuleBody | undefined + body: ModuleBody | undefined, ) { const [dsNode, dsName, dsBody] = downSample(node, name, body); diff --git a/src/harmony/versions/three-eight.ts b/src/harmony/versions/three-eight.ts index 219932a..9a99ae3 100644 --- a/src/harmony/versions/three-eight.ts +++ b/src/harmony/versions/three-eight.ts @@ -51,7 +51,7 @@ export namespace TsThreeEight { [TsCurrentModule.Expression, TsThreeEightModule.Expression], [TsCurrentModule.ModuleBody, TsThreeEightModule.ModuleBody], [TsCurrentModule.ModuleName, TsThreeEightModule.ModuleName], - [TsCurrentModule.ExportDeclaration["exportClause"], TsThreeEightModule.ExportDeclaration["exportClause"]] + [TsCurrentModule.ExportDeclaration["exportClause"], TsThreeEightModule.ExportDeclaration["exportClause"]], ]; } @@ -75,7 +75,7 @@ export namespace TsThreeEight { node: ImportClause, isTypeOnly: boolean, name: Identifier | undefined, - namedBindings: NamedImportBindings | undefined + namedBindings: NamedImportBindings | undefined, ) { return ts.updateImportClause.apply(void 0, downSample(node, name, namedBindings)); }; @@ -84,7 +84,7 @@ export namespace TsThreeEight { node: ImportDeclaration, modifiers: readonly Modifier[] | undefined, importClause: ImportClause | undefined, - moduleSpecifier: Expression + moduleSpecifier: Expression, ) { const [dsNode, dsImportClause, dsModuleSpecifier] = downSample(node, importClause, moduleSpecifier); @@ -93,7 +93,7 @@ export namespace TsThreeEight { dsNode.decorators, dsNode.modifiers, dsImportClause, - dsModuleSpecifier + dsModuleSpecifier, ); }; case "updateExportDeclaration": @@ -102,7 +102,7 @@ export namespace TsThreeEight { modifiers: readonly Modifier[] | undefined, isTypeOnly: boolean, exportClause: NamedExportBindings | undefined, - moduleSpecifier: Expression | undefined + moduleSpecifier: Expression | undefined, ) { const [dsNode, dsModuleSpecifier, dsExportClause] = downSample(node, moduleSpecifier, exportClause); return ts.updateExportDeclaration( @@ -112,7 +112,7 @@ export namespace TsThreeEight { dsExportClause, dsModuleSpecifier, // @ts-ignore - This was added in later versions of 3.x - dsNode.isTypeOnly + dsNode.isTypeOnly, ); }; case "updateModuleDeclaration": @@ -120,7 +120,7 @@ export namespace TsThreeEight { node: ModuleDeclaration, modifiers: readonly Modifier[] | undefined, name: ModuleName, - body: ModuleBody | undefined + body: ModuleBody | undefined, ) { const [dsNode, dsName, dsBody] = downSample(node, name, body); @@ -133,13 +133,13 @@ export namespace TsThreeEight { assertions: ImportTypeAssertionContainer | undefined, qualifier: EntityName | undefined, typeArguments: readonly TypeNode[] | undefined, - isTypeOf?: boolean + isTypeOf?: boolean, ) { const [dsNode, dsArgument, dsQualifier, dsTypeArguments] = downSample( node, argument, qualifier, - typeArguments + typeArguments, ); return ts.updateImportTypeNode(dsNode, dsArgument, dsQualifier, dsTypeArguments, isTypeOf); diff --git a/src/register.ts b/src/register.ts index 3ac76fd..683d62c 100755 --- a/src/register.ts +++ b/src/register.ts @@ -23,7 +23,7 @@ function getProjectTransformerConfig(pcl: ts.ParsedCommandLine) { function getTransformers( program?: ts.Program, beforeConfig?: Record, - afterDeclarationsConfig?: Record + afterDeclarationsConfig?: Record, ): ts.CustomTransformers { return { ...(beforeConfig && { before: [transformer(program, beforeConfig)] }), @@ -33,7 +33,7 @@ function getTransformers( export function mergeTransformers( baseTransformers: ts.CustomTransformers, - transformers: ts.CustomTransformers + transformers: ts.CustomTransformers, ): ts.CustomTransformers { const res = { ...((baseTransformers.before || transformers.before) && { @@ -77,7 +77,7 @@ export function register(): TSNode.RegisterOptions | undefined { } else { registerOptions.transformers = mergeTransformers( registerOptions.transformers, - getTransformers(undefined, beforeConfig, afterDeclarationsConfig) + getTransformers(undefined, beforeConfig, afterDeclarationsConfig), ); } } else { @@ -100,7 +100,7 @@ export namespace register { tsNode = require("ts-node"); } catch { throw new Error( - `Cannot resolve ts-node. Make sure ts-node is installed before using typescript-transform-paths/register` + `Cannot resolve ts-node. Make sure ts-node is installed before using typescript-transform-paths/register`, ); } diff --git a/src/transformer.ts b/src/transformer.ts index c6e5f94..03fc611 100755 --- a/src/transformer.ts +++ b/src/transformer.ts @@ -62,7 +62,7 @@ function getTsProperties(args: Parameters) { } else { throw new Error( `Cannot transform without a Program, ts-node instance, or manual parameters supplied. ` + - `Make sure you're using ts-patch or ts-node with transpileOnly.` + `Make sure you're using ts-patch or ts-node with transpileOnly.`, ); } @@ -85,7 +85,7 @@ export default function transformer( manualTransformOptions?: { compilerOptions?: ts.CompilerOptions; fileNames?: string[]; - } + }, ) { return (transformationContext: ts.TransformationContext) => { // prettier-ignore @@ -106,7 +106,7 @@ export default function transformer( if (!emitHost || tsNodeState === TsNodeState.Stripped) { if (!fileNames) throw new Error( - `No EmitHost found and could not determine files to be processed. Please file an issue with a reproduction!` + `No EmitHost found and could not determine files to be processed. Please file an issue with a reproduction!`, ); emitHost = createSyntheticEmitHost(compilerOptions, tsInstance, getCanonicalFileName, fileNames as string[]); } diff --git a/src/utils/elide-import-export.ts b/src/utils/elide-import-export.ts index 85f84b6..9c2c742 100755 --- a/src/utils/elide-import-export.ts +++ b/src/utils/elide-import-export.ts @@ -69,14 +69,14 @@ export function elideImportOrExportDeclaration((bindings: NamedExportBindings) => visitNamedExportBindings(bindings, allowEmpty)), - isNamedExportBindings + isNamedExportBindings, ); return exportClause @@ -151,7 +151,7 @@ export function elideImportOrExportDeclaration( exportClause, newModuleSpecifier, // This will be changed in the next release of TypeScript, but by that point we can drop elision entirely - (node as any).attributes || node.assertClause + (node as any).attributes || node.assertClause, ) : undefined; } @@ -220,7 +220,7 @@ export function elideImportOrExportDeclaration( function visitNamedExportBindings( node: NamedExportBindings, - allowEmpty: boolean + allowEmpty: boolean, ): VisitResult | undefined { return isNamespaceExport(node) ? visitNamespaceExports(node) : visitNamedExports(node, allowEmpty); } diff --git a/src/utils/get-relative-path.ts b/src/utils/get-relative-path.ts index 1c70576..2a2f140 100644 --- a/src/utils/get-relative-path.ts +++ b/src/utils/get-relative-path.ts @@ -39,7 +39,7 @@ function getIsFsCaseSensitive() { } console.warn( - `Could not determine filesystem's case sensitivity. Please file a bug report with your system's details` + `Could not determine filesystem's case sensitivity. Please file a bug report with your system's details`, ); isCaseSensitiveFilesystem = false; diff --git a/src/utils/resolve-module-name.ts b/src/utils/resolve-module-name.ts index 5ef0e24..ba0e3b5 100755 --- a/src/utils/resolve-module-name.ts +++ b/src/utils/resolve-module-name.ts @@ -99,7 +99,7 @@ function getResolvedSourceFile(context: VisitorContext, fileName: string): Sourc /* Attempt to find without extension */ res = (program.getSourceFiles() as SourceFile[]).find( - (s) => removeFileExtension(s.fileName) === removeFileExtension(fileName) + (s) => removeFileExtension(s.fileName) === removeFileExtension(fileName), ); if (res) return res; } @@ -128,7 +128,7 @@ export function resolveModuleName(context: VisitorContext, moduleName: string): moduleName, sourceFile.fileName, compilerOptions, - tsInstance.sys + tsInstance.sys, ); // Handle non-resolvable module diff --git a/src/utils/resolve-path-update-node.ts b/src/utils/resolve-path-update-node.ts index 803104c..d16d2ca 100755 --- a/src/utils/resolve-path-update-node.ts +++ b/src/utils/resolve-path-update-node.ts @@ -15,7 +15,7 @@ export function resolvePathAndUpdateNode( context: VisitorContext, node: ts.Node, moduleName: string, - updaterFn: (newPath: ts.StringLiteral) => ts.Node | undefined + updaterFn: (newPath: ts.StringLiteral) => ts.Node | undefined, ): ts.Node | undefined { const { sourceFile, tsInstance, factory } = context; const { normalizePath } = tsInstance; @@ -57,7 +57,7 @@ export function resolvePathAndUpdateNode( function getStatementTags() { let targetNode = tsInstance.isStatement(node) ? node - : tsInstance.findAncestor(node, tsInstance.isStatement) ?? node; + : (tsInstance.findAncestor(node, tsInstance.isStatement) ?? node); targetNode = tsInstance.getOriginalNode(targetNode); let jsDocTags: readonly ts.JSDocTag[] | undefined; diff --git a/src/utils/ts-helpers.ts b/src/utils/ts-helpers.ts index 736dfba..fd895b8 100755 --- a/src/utils/ts-helpers.ts +++ b/src/utils/ts-helpers.ts @@ -29,13 +29,13 @@ export function getOutputDirForSourceFile(context: VisitorContext, sourceFile: S : getOwnEmitOutputFilePath( sourceFile.fileName, emitHost, - getOutputExtension(sourceFile.fileName, compilerOptions) + getOutputExtension(sourceFile.fileName, compilerOptions), ); if (!outputPath) throw new Error( `Could not resolve output path for ${sourceFile.fileName}. Please report a GH issue at: ` + - `https://github.com/LeDDGroup/typescript-transform-paths/issues` + `https://github.com/LeDDGroup/typescript-transform-paths/issues`, ); const res = path.dirname(outputPath); @@ -63,7 +63,7 @@ export function createSyntheticEmitHost( compilerOptions: ts.CompilerOptions, tsInstance: typeof ts, getCanonicalFileName: GetCanonicalFileName, - fileNames: string[] + fileNames: string[], ) { return { getCompilerOptions: () => compilerOptions, @@ -71,7 +71,7 @@ export function createSyntheticEmitHost( getCommonSourceDirectory: () => tsInstance.getCommonSourceDirectoryOfConfig( { options: compilerOptions, fileNames: fileNames } as ts.ParsedCommandLine, - !tsInstance.sys.useCaseSensitiveFileNames + !tsInstance.sys.useCaseSensitiveFileNames, ), getCanonicalFileName, } as unknown as ts.EmitHost; diff --git a/src/visitor.ts b/src/visitor.ts index 00f9a68..1c334cd 100755 --- a/src/visitor.ts +++ b/src/visitor.ts @@ -56,7 +56,7 @@ export function nodeVisitor(this: VisitorContext, node: ts.Node): ts.Node | unde // selector in capture group and dismiss anything after the final comment close tag /^\/\*(.+)\*\/.*/s : /^\/\/(.+)/s, - /* replaceValue */ "$1" + /* replaceValue */ "$1", ); tsInstance.addSyntheticLeadingComment(p, kind, caption, hasTrailingNewLine); } @@ -71,7 +71,7 @@ export function nodeVisitor(this: VisitorContext, node: ts.Node): ts.Node | unde */ if (tsInstance.isExternalModuleReference(node) && tsInstance.isStringLiteral(node.expression)) return resolvePathAndUpdateNode(this, node, node.expression.text, (p) => - factory.updateExternalModuleReference(node, p) + factory.updateExternalModuleReference(node, p), ); /** @@ -94,8 +94,8 @@ export function nodeVisitor(this: VisitorContext, node: ts.Node): ts.Node | unde node.assertions, node.qualifier, node.typeArguments, - node.isTypeOf - ) + node.isTypeOf, + ), ); return tsInstance.visitEachChild(res, this.getVisitor(), transformationContext); @@ -142,7 +142,7 @@ export function nodeVisitor(this: VisitorContext, node: ts.Node): ts.Node | unde node.isTypeOnly, node.exportClause, p, - node.assertClause + node.assertClause, ); }); @@ -151,7 +151,7 @@ export function nodeVisitor(this: VisitorContext, node: ts.Node): ts.Node | unde */ if (tsInstance.isModuleDeclaration(node) && tsInstance.isStringLiteral(node.name)) return resolvePathAndUpdateNode(this, node, node.name.text, (p) => - factory.updateModuleDeclaration(node, node.modifiers, p, node.body) + factory.updateModuleDeclaration(node, node.modifiers, p, node.body), ); return tsInstance.visitEachChild(node, this.getVisitor(), transformationContext); diff --git a/test/tests/extras.test.ts b/test/tests/extras.test.ts index 0db5bca..545931e 100755 --- a/test/tests/extras.test.ts +++ b/test/tests/extras.test.ts @@ -23,7 +23,7 @@ describe(`Extra Tests`, () => { () => { require("sdf0s39rf3333d@fake-module"); }, - { virtual: true } + { virtual: true }, ); try { const program = createTsProgram({ tsInstance: ts, tsConfigFile }, config.builtTransformerPath); diff --git a/test/tests/register.test.ts b/test/tests/register.test.ts index 717ef4e..4b5a47e 100755 --- a/test/tests/register.test.ts +++ b/test/tests/register.test.ts @@ -93,7 +93,7 @@ describe(`Register script`, () => { () => { require("sdf0s39rf3333d@fake-module"); }, - { virtual: true } + { virtual: true }, ); expect(() => register()).toThrow(`Cannot resolve ts-node`); jest.dontMock("ts-node"); @@ -224,10 +224,10 @@ describe(`Register script`, () => { expect(mockTransformer).toBeCalledTimes(callTimes); const afterDeclarationsConfig = transformers.find( - (t) => t.transform === "typescript-transform-paths" && t.afterDeclarations + (t) => t.transform === "typescript-transform-paths" && t.afterDeclarations, ); const beforeConfig = transformers.find( - (t) => t.transform === "typescript-transform-paths" && !t.afterDeclarations + (t) => t.transform === "typescript-transform-paths" && !t.afterDeclarations, ); if (hasBefore) expect(beforeConfig).not.toBeUndefined(); @@ -236,7 +236,7 @@ describe(`Register script`, () => { const expectedCfg = [beforeConfig, afterDeclarationsConfig].filter((c) => !!c); for (let i = 0; i < callTimes; i++) { expect(mockTransformer.mock.calls[i][0]).toBe( - existingTransformers === transformerFactoryFn ? fakeProgram : void 0 + existingTransformers === transformerFactoryFn ? fakeProgram : void 0, ); expect(mockTransformer.mock.calls[i][1]).toBe(expectedCfg[i]); } diff --git a/test/tests/transformer/general.test.ts b/test/tests/transformer/general.test.ts index 98c63b9..7d7bab5 100755 --- a/test/tests/transformer/general.test.ts +++ b/test/tests/transformer/general.test.ts @@ -18,7 +18,7 @@ const getExpected = (tsInstance: typeof ts, fileName: string, original: string, original .replace(/"@(.*)"/g, (_, p) => makeRelative(tsInstance, fileName, p, rootDir)) .replace(/"#utils\/(.*)"/g, (_, p) => - makeRelative(tsInstance, fileName, path.join(p === "hello" ? "secondary" : "utils", p), rootDir) + makeRelative(tsInstance, fileName, path.join(p === "hello" ? "secondary" : "utils", p), rootDir), ) .replace('"path"', '"https://external.url/path.js"') .replace('"circular/a"', '"../circular/a"'); diff --git a/test/tests/transformer/specific.test.ts b/test/tests/transformer/specific.test.ts index 368d0fd..1769998 100755 --- a/test/tests/transformer/specific.test.ts +++ b/test/tests/transformer/specific.test.ts @@ -86,7 +86,7 @@ describe(`Specific Tests`, () => { const pcl = tsInstance.getParsedCommandLineOfConfigFile( tsConfigFile, {}, - tsInstance.sys + tsInstance.sys, )! as TS.ParsedCommandLine; normalEmit = getManualEmitResult({ ...baseConfig, useRootDirs: false }, tsInstance, pcl); rootDirsEmit = getManualEmitResult({ ...baseConfig, useRootDirs: true }, tsInstance, pcl); @@ -96,7 +96,7 @@ describe(`Specific Tests`, () => { const pcl = tsInstance.getParsedCommandLineOfConfigFile( tsConfigFile, {}, - tsInstance.sys + tsInstance.sys, )! as TS.ParsedCommandLine; skipDts = true; normalEmit = getTsNodeEmitResult({ ...baseConfig, useRootDirs: false }, pcl, tsSpecifier); @@ -108,7 +108,7 @@ describe(`Specific Tests`, () => { transformedMatches( fileName: string, expected: RegExp | string, - opt?: { base?: EmittedFiles[]; kind?: ("dts" | "js")[] } + opt?: { base?: EmittedFiles[]; kind?: ("dts" | "js")[] }, ) { const bases = opt?.base ?? [normalEmit, rootDirsEmit]; const kinds = (opt?.kind ?? ["dts", "js"]).filter((k) => !skipDts || k !== "dts"); @@ -123,7 +123,7 @@ describe(`Specific Tests`, () => { failed = true; messages.push( `File: ${fileName}\nKind: ${kind}\nrootDirs: ${base === normalEmit}\n\n` + - `Expected: \`${expected}\`\nReceived:\n\t${content.replace(/(\r?\n)+/g, "$1\t")}` + `Expected: \`${expected}\`\nReceived:\n\t${content.replace(/(\r?\n)+/g, "$1\t")}`, ); } } @@ -151,7 +151,7 @@ describe(`Specific Tests`, () => { test(`(exclude) Doesn't transform for exclusion patterns`, () => { expect(indexFile).transformedMatches( - /export { bb } from "#exclusion\/ex";\s*export { dd } from "#root\/excluded-file"/ + /export { bb } from "#exclusion\/ex";\s*export { dd } from "#root\/excluded-file"/, ); }); }); @@ -176,7 +176,7 @@ describe(`Specific Tests`, () => { }); expect(typeElisionIndex).transformedMatches( /import { ConstB, TypeA } from "\.\/a";\s*import { TypeA as TypeA2 } from "\.\/a";\s*export { ConstB, TypeA };\s*export { TypeA2 };/, - { kind: ["dts"] } + { kind: ["dts"] }, ); if (tsVersion >= 50) { @@ -187,24 +187,24 @@ describe(`Specific Tests`, () => { expect(typeElisionIndex).transformedMatches( /import { type TypeAndConst, ConstB as __ } from "\.\/a";\s*export { TypeAndConst, __ };/, - { kind: ["dts"] } + { kind: ["dts"] }, ); /* Export Import type-only keyword on import specifier */ expect(typeElisionIndex).transformedMatches( /import { TypeAndConst as TypeAndConst2, ConstB as ___ } from "\.\/a";\s*export { type TypeAndConst2, ___ };/, - { kind: ["dts"] } + { kind: ["dts"] }, ); expect(typeElisionIndex).transformedMatches( /import { TypeAndConst as TypeAndConst2, ConstB as ___ } from "\.\/a";\s*export { ___ };/, - { kind: ["js"] } + { kind: ["js"] }, ); /* Unreferenced w/ type-only keyword on import specifier */ expect(typeElisionIndex).not.transformedMatches( /import { ConstB as ____, type TypeAndConst as TypeAndConst3 } from "\.\/a";\s/, - { kind: ["dts"] } + { kind: ["dts"] }, ); expect(typeElisionIndex).not.transformedMatches(/import { ConstB as ____ } from "\.\/a";\s/, { kind: ["js"] }); @@ -221,7 +221,7 @@ describe(`Specific Tests`, () => { }); expect(indexFile).transformedMatches( /\/\/ comment 1\r?\n\s*\/\*\r?\n\s*comment 2\r?\n\s*\*\/\r?\n\s*"\.\/dir\/src-file"/, - { kind: ["js"] } + { kind: ["js"] }, ); }); @@ -261,10 +261,10 @@ describe(`Specific Tests`, () => { expect(subPackagesFile).transformedMatches(`export { packageCConst as C2 } from "./packages/pkg-c/main"`); expect(subPackagesFile).transformedMatches(`export { packageCConst as C3 } from "./packages/pkg-c/main.js"`); expect(subPackagesFile).transformedMatches( - `export { subPackageConst as C4 } from "./packages/pkg-a/sub-pkg/main"` + `export { subPackageConst as C4 } from "./packages/pkg-a/sub-pkg/main"`, ); expect(subPackagesFile).transformedMatches( - `export { subPackageConst as C5 } from "./packages/pkg-a/sub-pkg/main.js"` + `export { subPackageConst as C5 } from "./packages/pkg-a/sub-pkg/main.js"`, ); }); @@ -273,7 +273,7 @@ describe(`Specific Tests`, () => { `export ${ tsVersion < 49 ? `declare ` : "" }type ImportWithChildren = import("./packages/pkg-a").PassThru`, - { kind: ["dts"] } + { kind: ["dts"] }, ); }); diff --git a/test/utils/helpers.ts b/test/utils/helpers.ts index 8153da0..8ba1cbe 100755 --- a/test/utils/helpers.ts +++ b/test/utils/helpers.ts @@ -65,7 +65,7 @@ function createReadFile(outputFiles: EmittedFiles, originalReadFile: Function) { */ export function createTsProgram( opt: CreateTsProgramOptions, - transformerPath: string = config.transformerPath + transformerPath: string = config.transformerPath, ): ts.Program { const { disablePlugin, additionalOptions, pluginOptions } = opt; const tsInstance: typeof ts = opt.tsInstance; @@ -97,10 +97,13 @@ export function createTsProgram( compilerOptions = pcl.options; fileNames = pcl.fileNames; } else { - const files = Object.entries(compilerOptions.files!).reduce((p, [fileName, data]) => { - p[tsInstance.normalizePath(fileName)] = data; - return p; - }, {}); + const files = Object.entries(compilerOptions.files!).reduce( + (p, [fileName, data]) => { + p[tsInstance.normalizePath(fileName)] = data; + return p; + }, + {}, + ); fileNames = Object.keys(files); host = tsInstance.createCompilerHost(compilerOptions); @@ -119,7 +122,7 @@ export function createTsProgram( } export function createTsSolutionBuilder( - opt: CreateTsSolutionBuilderOptions + opt: CreateTsSolutionBuilderOptions, ): ts.SolutionBuilder & { getEmitFiles(): EmittedFiles } { const { tsInstance, projectDir } = opt; @@ -157,10 +160,10 @@ export function getManualEmitResult(pluginConfig: TsTransformPathsConfig, tsInst const { transformed } = tsInstance.transform( fileNames.map((f) => - tsInstance.createSourceFile(f, fs.readFileSync(f, "utf8"), tsInstance.ScriptTarget.ESNext, true) + tsInstance.createSourceFile(f, fs.readFileSync(f, "utf8"), tsInstance.ScriptTarget.ESNext, true), ), [transformer], - compilerOptions + compilerOptions, ); const printer = tsInstance.createPrinter(); @@ -174,7 +177,7 @@ export function getManualEmitResult(pluginConfig: TsTransformPathsConfig, tsInst export function getTsNodeEmitResult( pluginConfig: TsTransformPathsConfig, pcl: ts.ParsedCommandLine, - tsSpecifier: string + tsSpecifier: string, ) { const compiler = tsNode.create({ transpileOnly: true, diff --git a/types/index.d.ts b/types/index.d.ts index 86d8e78..a8b0da0 100755 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -32,7 +32,7 @@ export default function transformer( manualTransformOptions?: { compilerOptions?: ts.CompilerOptions; fileNames?: string[]; - } + }, ): ts.CustomTransformerFactory; /* ****************************************************************************************************************** * @@ -41,7 +41,7 @@ export default function transformer( export type NxTransformerFactory = ( config?: Omit, - program?: ts.Program + program?: ts.Program, ) => ts.TransformerFactory; export interface NxTransformerPlugin {