Skip to content

Commit e915977

Browse files
committed
style: Fix formatting (prettier)
1 parent bb97f01 commit e915977

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+625
-569
lines changed

src/compatibility/node-register.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import type TSNode from "ts-node";
2-
import type { REGISTER_INSTANCE } from "ts-node";
3-
import type TS from "typescript";
4-
import { transformer } from "../transform";
1+
import type TSNode from 'ts-node';
2+
import type { REGISTER_INSTANCE } from 'ts-node';
3+
import type TS from 'typescript';
4+
import { transformer } from '../transform';
55

66
/* ****************************************************************************************************************** */
77
// region: Helpers
@@ -16,7 +16,7 @@ const checkModuleIsTsTp = (m: string) => {
1616
if (!transformerModule) return m === 'typescript-transform-paths';
1717

1818
return transformerModule.isTsTp;
19-
}
19+
};
2020

2121
function getProjectTransformerConfig(pcl: TS.ParsedCommandLine) {
2222
const plugins = pcl.options.plugins as Record<string, string>[] | undefined;
@@ -25,7 +25,7 @@ function getProjectTransformerConfig(pcl: TS.ParsedCommandLine) {
2525
const res: { afterDeclarations?: Record<string, string>; before?: Record<string, string> } = {};
2626
for (const plugin of plugins) {
2727
if (plugin.transform && checkModuleIsTsTp(plugin.transform) && !plugin.after)
28-
res[plugin.afterDeclarations ? "afterDeclarations" : "before"] = plugin;
28+
res[plugin.afterDeclarations ? 'afterDeclarations' : 'before'] = plugin;
2929
}
3030

3131
return res;
@@ -78,7 +78,7 @@ export function nodeRegister(): TSNode.RegisterOptions | undefined {
7878

7979
const registerOptions: TSNode.RegisterOptions = Object.assign({}, tsNodeInstance.options);
8080
if (registerOptions.transformers) {
81-
if (typeof registerOptions.transformers === "function") {
81+
if (typeof registerOptions.transformers === 'function') {
8282
let oldTransformersFactory = registerOptions.transformers;
8383
registerOptions.transformers = (program) => {
8484
const transformers = getTransformers(program, beforeConfig, afterDeclarationsConfig);
@@ -108,14 +108,14 @@ export namespace nodeRegister {
108108
} {
109109
let tsNode: typeof TSNode;
110110
try {
111-
tsNode = require("ts-node");
111+
tsNode = require('ts-node');
112112
} catch {
113113
throw new Error(
114114
`Cannot resolve ts-node. Make sure ts-node is installed before using typescript-transform-paths/register`
115115
);
116116
}
117117

118-
const instanceSymbol: typeof REGISTER_INSTANCE = tsNode["REGISTER_INSTANCE"];
118+
const instanceSymbol: typeof REGISTER_INSTANCE = tsNode['REGISTER_INSTANCE'];
119119

120120
let tsNodeInstance = global.process[instanceSymbol];
121121
if (!tsNodeInstance) {

src/index.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
/* ****************************************************************************************************************** *
32
* Transformer
43
* ****************************************************************************************************************** */
@@ -10,14 +9,14 @@ export default transformer;
109
* Types
1110
* ****************************************************************************************************************** */
1211

13-
export * from "./types";
12+
export * from './types';
1413

1514
/* ****************************************************************************************************************** *
1615
* Compatibility
1716
* ****************************************************************************************************************** */
1817

1918
/** @internal */
20-
export { nodeRegister } from "./compatibility/node-register";
19+
export { nodeRegister } from './compatibility/node-register';
2120

2221
/* ****************************************************************************************************************** *
2322
* Internal

src/resolve/extensions.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { extName } from "../utils";
1+
import { extName } from '../utils';
22

33
/* ****************************************************************************************************************** *
44
* Locals
55
* ****************************************************************************************************************** */
66

7-
const implicitExtensions = [ '.js', '.d.ts', '.ts' ];
7+
const implicitExtensions = ['.js', '.d.ts', '.ts'];
88

99
/* ****************************************************************************************************************** */
1010
// region: Utils
@@ -20,4 +20,3 @@ export function stripImplicitExtension(fileName: string) {
2020
}
2121

2222
// endregion
23-

src/resolve/index-checker.ts

+15-13
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,28 @@
1-
import type TS from "typescript";
2-
import fs from "fs";
3-
import { isImplicitExtension, stripImplicitExtension } from "./extensions";
4-
import { dirName, normalizePath, relativePath, resolvePath } from "../utils";
1+
import type TS from 'typescript';
2+
import fs from 'fs';
3+
import { isImplicitExtension, stripImplicitExtension } from './extensions';
4+
import { dirName, normalizePath, relativePath, resolvePath } from '../utils';
55

66
/* ****************************************************************************************************************** */
77
// region: Types
88
/* ****************************************************************************************************************** */
99

1010
export interface IndexDetail {
11-
flags: IndexFlags
12-
indexPath?: string
11+
flags: IndexFlags;
12+
indexPath?: string;
1313
}
1414

1515
export enum IndexFlags {
1616
None,
1717
Implicit = 1 << 0,
1818
Package = 1 << 1,
19-
Node = 1 << 2
19+
Node = 1 << 2,
2020
}
2121

22-
type PackageIndexInfo = { packageIndex: string, packageDir: string }
22+
type PackageIndexInfo = { packageIndex: string; packageDir: string };
2323

2424
// endregion
2525

26-
2726
/* ****************************************************************************************************************** *
2827
* IndexChecker (class)
2928
* ****************************************************************************************************************** */
@@ -40,8 +39,8 @@ export class IndexChecker {
4039
if (suppliedBaseNameNoExt !== baseNameNoExt) flags |= IndexFlags.Implicit;
4140
return {
4241
indexPath: baseNameNoExt + (ext ?? ''),
43-
flags
44-
}
42+
flags,
43+
};
4544
}
4645

4746
return { flags: IndexFlags.None };
@@ -67,7 +66,10 @@ export class IndexChecker {
6766
if (fileNameStrippedExt.slice(-matchedStar.length) !== matchedStar) flags |= IndexFlags.Implicit;
6867
} else {
6968
if (suppliedPackageName)
70-
if (!suppliedPathStrippedExt || fileNameStrippedExt.slice(-suppliedPathStrippedExt.length) !== suppliedPathStrippedExt)
69+
if (
70+
!suppliedPathStrippedExt ||
71+
fileNameStrippedExt.slice(-suppliedPathStrippedExt.length) !== suppliedPathStrippedExt
72+
)
7173
flags |= IndexFlags.Implicit;
7274
}
7375

@@ -103,7 +105,7 @@ export class IndexChecker {
103105
packageIndex = resolvePath(dir, packageIndex);
104106

105107
const res = { packageDir: dir, packageIndex };
106-
pathStack.forEach(p => this.packageMap.set(p, res));
108+
pathStack.forEach((p) => this.packageMap.set(p, res));
107109

108110
return res;
109111
}

src/resolve/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export { resolvePathAndUpdateNode } from './resolve-path-update-node'
1+
export { resolvePathAndUpdateNode } from './resolve-path-update-node';

src/resolve/output-path-detail.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { Pattern, ResolvedModuleFull } from "typescript";
2-
import { baseName, extName, joinPaths, normalizeSlashes, removeSuffix } from "../utils";
3-
import { VisitorContext } from "../types";
4-
import { IndexDetail } from "./index-checker";
1+
import { Pattern, ResolvedModuleFull } from 'typescript';
2+
import { baseName, extName, joinPaths, normalizeSlashes, removeSuffix } from '../utils';
3+
import { VisitorContext } from '../types';
4+
import { IndexDetail } from './index-checker';
55

66
/* ****************************************************************************************************************** */
77
// region: Types
@@ -21,7 +21,7 @@ export interface OutputPathDetail {
2121
packageRoot?: string;
2222
packageFileName?: string;
2323
tsPathsKey?: string;
24-
indexDetail: IndexDetail
24+
indexDetail: IndexDetail;
2525
}
2626

2727
// endregion
@@ -116,7 +116,7 @@ export function getOutputPathDetail(
116116
suppliedPackagePath,
117117
suppliedPackageName,
118118
packageFileName,
119-
indexDetail
119+
indexDetail,
120120
};
121121
}
122122

src/resolve/resolve-module-name.ts

+21-12
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
1-
import { ResolutionContext, VisitorContext } from "../types";
1+
import { ResolutionContext, VisitorContext } from '../types';
22
import {
3-
baseName, dirName, isBaseDir, isURL, joinPaths, maybeAddRelativeLocalPrefix, normalizeSlashes, relativePath,
4-
removeSuffix
5-
} from "../utils";
6-
import { Node, Pattern, removeFileExtension, ResolvedModuleFull, SourceFile } from "typescript";
7-
import { getOutputPathForSourceFile, getOutputExtension } from "../ts";
8-
import { getOutputPathDetail, OutputPathDetail } from "./output-path-detail";
9-
import { IndexFlags } from "./index-checker";
3+
baseName,
4+
dirName,
5+
isBaseDir,
6+
isURL,
7+
joinPaths,
8+
maybeAddRelativeLocalPrefix,
9+
normalizeSlashes,
10+
relativePath,
11+
removeSuffix,
12+
} from '../utils';
13+
import { Node, Pattern, removeFileExtension, ResolvedModuleFull, SourceFile } from 'typescript';
14+
import { getOutputPathForSourceFile, getOutputExtension } from '../ts';
15+
import { getOutputPathDetail, OutputPathDetail } from './output-path-detail';
16+
import { IndexFlags } from './index-checker';
1017

1118
/* ****************************************************************************************************************** */
1219
// region: Types
@@ -64,7 +71,7 @@ function getReturnPath(ctx: GetReturnPathContext) {
6471
config: { outputExtensions, outputIndexes },
6572
compilerOptions,
6673
tsInstance,
67-
isDeclarationFile
74+
isDeclarationFile,
6875
} = ctx.visitorContext;
6976
const { suppliedExt, resolvedPath, isImplicitExtension, indexDetail, isExternalLibraryImport } = ctx.pathDetail ?? {};
7077

@@ -98,7 +105,8 @@ function getReturnPath(ctx: GetReturnPathContext) {
98105
if (resolver) {
99106
const { moduleName, node, visitorContext, isURL, resolvedModule } = ctx;
100107
const { resolvedFileName, originalPath } = resolvedModule ?? {};
101-
const { packageName, suppliedPackageName, tsPathsKey, packageFileName, isExternalLibraryImport } = ctx.pathDetail ?? {};
108+
const { packageName, suppliedPackageName, tsPathsKey, packageFileName, isExternalLibraryImport } =
109+
ctx.pathDetail ?? {};
102110

103111
const resolutionContext: ResolutionContext = {
104112
moduleExtName: suppliedExt,
@@ -186,7 +194,8 @@ export function resolveModuleName(
186194
const { suppliedPackageName, suppliedPackagePath, indexDetail } = pathDetail;
187195

188196
let outputPath = joinPaths(suppliedPackageName, suppliedPackagePath && removeFileExtension(suppliedPackagePath));
189-
if (indexDetail.flags & IndexFlags.Implicit) outputPath = joinPaths(outputPath, removeFileExtension(indexDetail.indexPath!));
197+
if (indexDetail.flags & IndexFlags.Implicit)
198+
outputPath = joinPaths(outputPath, removeFileExtension(indexDetail.indexPath!));
190199

191200
return getReturnPath({
192201
moduleName,
@@ -195,7 +204,7 @@ export function resolveModuleName(
195204
resolvedModule,
196205
resolvedSourceFile,
197206
pathDetail,
198-
outputPath
207+
outputPath,
199208
});
200209
}
201210

src/resolve/resolve-path-update-node.ts

+16-12
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import type TS from "typescript";
2-
import { VisitorContext } from "../types";
3-
import { isURL, maybeAddRelativeLocalPrefix, normalizePath } from "../utils";
4-
import { resolveModuleName } from "./resolve-module-name";
5-
import { getTsPathsMatch } from "../ts";
6-
1+
import type TS from 'typescript';
2+
import { VisitorContext } from '../types';
3+
import { isURL, maybeAddRelativeLocalPrefix, normalizePath } from '../utils';
4+
import { resolveModuleName } from './resolve-module-name';
5+
import { getTsPathsMatch } from '../ts';
76

87
/* ****************************************************************************************************************** *
98
* Node Updater Util
@@ -18,7 +17,12 @@ export function resolvePathAndUpdateNode(
1817
moduleName: string,
1918
updaterFn: (newPath: TS.StringLiteral) => TS.Node | undefined
2019
): TS.Node | undefined {
21-
const { sourceFile, tsInstance, factory, config: { outputExtensions, outputIndexes, usePaths } } = context;
20+
const {
21+
sourceFile,
22+
tsInstance,
23+
factory,
24+
config: { outputExtensions, outputIndexes, usePaths },
25+
} = context;
2226

2327
/* Handle JSDoc statement tags */
2428
const tags = getStatementTags();
@@ -39,7 +43,7 @@ export function resolvePathAndUpdateNode(
3943
const pathsMatch = usePaths ? getTsPathsMatch(context, moduleName) : undefined;
4044

4145
// Skip if possible
42-
const canSkip = !pathsMatch && !context.resolver && outputIndexes !== "always" && outputExtensions !== "always";
46+
const canSkip = !pathsMatch && !context.resolver && outputIndexes !== 'always' && outputExtensions !== 'always';
4347
if (canSkip) return node;
4448

4549
// Resolve
@@ -78,11 +82,11 @@ export function resolvePathAndUpdateNode(
7882
for (let match = regex.exec(trivia); match; match = regex.exec(trivia)) commentTags.set(match[1], match[2]);
7983
} catch {}
8084

81-
const overridePath = findTag("transform-path");
82-
const shouldSkip = findTag("no-transform-path");
85+
const overridePath = findTag('transform-path');
86+
const shouldSkip = findTag('no-transform-path');
8387

8488
return {
85-
overridePath: typeof overridePath === "string" ? overridePath : void 0,
89+
overridePath: typeof overridePath === 'string' ? overridePath : void 0,
8690
shouldSkip: !!shouldSkip,
8791
};
8892

@@ -92,7 +96,7 @@ export function resolvePathAndUpdateNode(
9296

9397
for (const tag of jsDocTags) {
9498
const tagName = tag.tagName.text.toLowerCase();
95-
if (tagName === expected) return typeof tag.comment === "string" ? tag.comment : true;
99+
if (tagName === expected) return typeof tag.comment === 'string' ? tag.comment : true;
96100
}
97101
}
98102
}

src/transform/elide-import-export.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
* import { A, B } from './b'
2929
* export { A } from './b'
3030
*/
31-
import { ImportOrExportClause, ImportOrExportDeclaration, VisitorContext } from "../types";
31+
import { ImportOrExportClause, ImportOrExportDeclaration, VisitorContext } from '../types';
3232
import type {
3333
ExportDeclaration,
3434
ExportSpecifier,
@@ -39,7 +39,7 @@ import type {
3939
NamedImportBindings,
4040
Visitor,
4141
VisitResult,
42-
} from "typescript";
42+
} from 'typescript';
4343

4444
/* ****************************************************************************************************************** */
4545
// region: Utilities
@@ -55,7 +55,7 @@ import type {
5555
export function elideImportOrExportClause<T extends ImportOrExportDeclaration>(
5656
context: VisitorContext,
5757
node: T
58-
): (T extends ImportDeclaration ? ImportDeclaration["importClause"] : ExportDeclaration["exportClause"]) | undefined;
58+
): (T extends ImportDeclaration ? ImportDeclaration['importClause'] : ExportDeclaration['exportClause']) | undefined;
5959

6060
export function elideImportOrExportClause(
6161
context: VisitorContext,

src/transform/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export { transformer } from './transformer'
1+
export { transformer } from './transformer';

0 commit comments

Comments
 (0)