Skip to content

Commit f681e5f

Browse files
committed
run lint-fix
1 parent e8a80cf commit f681e5f

15 files changed

+146
-170
lines changed

esm.mjs

+2-6
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,5 @@ const require = createRequire(fileURLToPath(import.meta.url));
44

55
/** @type {import('./dist/esm')} */
66
const esm = require('./dist/esm');
7-
export const {
8-
resolve,
9-
load,
10-
getFormat,
11-
transformSource,
12-
} = esm.registerAndCreateEsmHooks();
7+
export const { resolve, load, getFormat, transformSource } =
8+
esm.registerAndCreateEsmHooks();

esm/transpile-only.mjs

+2-6
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,5 @@ const require = createRequire(fileURLToPath(import.meta.url));
44

55
/** @type {import('../dist/esm')} */
66
const esm = require('../dist/esm');
7-
export const {
8-
resolve,
9-
load,
10-
getFormat,
11-
transformSource,
12-
} = esm.registerAndCreateEsmHooks({ transpileOnly: true });
7+
export const { resolve, load, getFormat, transformSource } =
8+
esm.registerAndCreateEsmHooks({ transpileOnly: true });

scripts/create-merged-schema.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ async function main() {
3737
.compilerOptions,
3838
allOf: [
3939
{
40-
$ref:
41-
'#/definitions/compilerOptionsDefinition/properties/compilerOptions',
40+
$ref: '#/definitions/compilerOptionsDefinition/properties/compilerOptions',
4241
},
4342
],
4443
},
@@ -62,9 +61,7 @@ async function main() {
6261
}
6362

6463
export async function getSchemastoreSchema() {
65-
const {
66-
data: schemastoreSchema,
67-
} = await axios.get(
64+
const { data: schemastoreSchema } = await axios.get(
6865
'https://schemastore.azurewebsites.net/schemas/json/tsconfig.json',
6966
{ responseType: 'json' }
7067
);

src/bin.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ export function main(
292292
}
293293

294294
if (showConfig) {
295-
const ts = (service.ts as any) as TSInternal;
295+
const ts = service.ts as any as TSInternal;
296296
if (typeof ts.convertToTSConfig !== 'function') {
297297
console.error(
298298
'Error: --show-config requires a typescript versions >=3.2 that support --showConfig'

src/configuration.ts

+9-8
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ export function readConfig(
142142
},
143143
bp,
144144
errors,
145-
((ts as unknown) as TSInternal).createCompilerDiagnostic
145+
(ts as unknown as TSInternal).createCompilerDiagnostic
146146
);
147147
if (errors.length) {
148148
return {
@@ -165,8 +165,9 @@ export function readConfig(
165165
const optionBasePaths: OptionBasePaths = {};
166166
for (let i = configChain.length - 1; i >= 0; i--) {
167167
const { config, basePath, configPath } = configChain[i];
168-
const options = filterRecognizedTsConfigTsNodeOptions(config['ts-node'])
169-
.recognized;
168+
const options = filterRecognizedTsConfigTsNodeOptions(
169+
config['ts-node']
170+
).recognized;
170171

171172
// Some options are relative to the config file, so must be converted to absolute paths here
172173
if (options.require) {
@@ -250,9 +251,7 @@ export function readConfig(
250251
* Given the raw "ts-node" sub-object from a tsconfig, return an object with only the properties
251252
* recognized by "ts-node"
252253
*/
253-
function filterRecognizedTsConfigTsNodeOptions(
254-
jsonObject: any
255-
): {
254+
function filterRecognizedTsConfigTsNodeOptions(jsonObject: any): {
256255
recognized: TsConfigOptions;
257256
unrecognized: any;
258257
} {
@@ -303,7 +302,9 @@ function filterRecognizedTsConfigTsNodeOptions(
303302
swc,
304303
};
305304
// Use the typechecker to make sure this implementation has the correct set of properties
306-
const catchExtraneousProps: keyof TsConfigOptions = (null as any) as keyof typeof filteredTsConfigOptions;
307-
const catchMissingProps: keyof typeof filteredTsConfigOptions = (null as any) as keyof TsConfigOptions;
305+
const catchExtraneousProps: keyof TsConfigOptions =
306+
null as any as keyof typeof filteredTsConfigOptions;
307+
const catchMissingProps: keyof typeof filteredTsConfigOptions =
308+
null as any as keyof TsConfigOptions;
308309
return { recognized: filteredTsConfigOptions, unrecognized };
309310
}

src/index.ts

+11-14
Original file line numberDiff line numberDiff line change
@@ -577,12 +577,8 @@ export function create(rawOptions: CreateOptions = {}): Service {
577577
);
578578

579579
// Read config file and merge new options between env and CLI options.
580-
const {
581-
configFilePath,
582-
config,
583-
tsNodeOptionsFromTsconfig,
584-
optionBasePaths,
585-
} = readConfig(cwd, ts, rawOptions);
580+
const { configFilePath, config, tsNodeOptionsFromTsconfig, optionBasePaths } =
581+
readConfig(cwd, ts, rawOptions);
586582
const options = assign<RegisterOptions>(
587583
{},
588584
DEFAULTS,
@@ -817,9 +813,9 @@ export function create(rawOptions: CreateOptions = {}): Service {
817813
_position: number
818814
) => TypeInfo;
819815

820-
const getCanonicalFileName = ((ts as unknown) as TSInternal).createGetCanonicalFileName(
821-
ts.sys.useCaseSensitiveFileNames
822-
);
816+
const getCanonicalFileName = (
817+
ts as unknown as TSInternal
818+
).createGetCanonicalFileName(ts.sys.useCaseSensitiveFileNames);
823819

824820
const moduleTypeClassifier = createModuleTypeClassifier({
825821
basePath: options.optionBasePaths?.moduleTypes,
@@ -908,8 +904,10 @@ export function create(rawOptions: CreateOptions = {}): Service {
908904
configFilePath,
909905
});
910906
serviceHost.resolveModuleNames = resolveModuleNames;
911-
serviceHost.getResolvedModuleWithFailedLookupLocationsFromCache = getResolvedModuleWithFailedLookupLocationsFromCache;
912-
serviceHost.resolveTypeReferenceDirectives = resolveTypeReferenceDirectives;
907+
serviceHost.getResolvedModuleWithFailedLookupLocationsFromCache =
908+
getResolvedModuleWithFailedLookupLocationsFromCache;
909+
serviceHost.resolveTypeReferenceDirectives =
910+
resolveTypeReferenceDirectives;
913911

914912
const registry = ts.createDocumentRegistry(
915913
ts.sys.useCaseSensitiveFileNames,
@@ -1272,9 +1270,8 @@ export function create(rawOptions: CreateOptions = {}): Service {
12721270
// Create a simple TypeScript compiler proxy.
12731271
function compile(code: string, fileName: string, lineOffset = 0) {
12741272
const normalizedFileName = normalizeSlashes(fileName);
1275-
const classification = moduleTypeClassifier.classifyModule(
1276-
normalizedFileName
1277-
);
1273+
const classification =
1274+
moduleTypeClassifier.classifyModule(normalizedFileName);
12781275
// Must always call normal getOutput to throw typechecking errors
12791276
let [value, sourceMap] = getOutput(code, normalizedFileName);
12801277
// If module classification contradicts the above, call the relevant transpiler

src/resolver-functions.ts

+59-63
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,8 @@ export function createResolverFunctions(kwargs: {
1313
config: _ts.ParsedCommandLine;
1414
configFilePath: string | undefined;
1515
}) {
16-
const {
17-
host,
18-
ts,
19-
config,
20-
cwd,
21-
getCanonicalFileName,
22-
configFilePath,
23-
} = kwargs;
16+
const { host, ts, config, cwd, getCanonicalFileName, configFilePath } =
17+
kwargs;
2418
const moduleResolutionCache = ts.createModuleResolutionCache(
2519
cwd,
2620
getCanonicalFileName,
@@ -105,69 +99,71 @@ export function createResolverFunctions(kwargs: {
10599
};
106100

107101
// language service never calls this, but TS docs recommend that we implement it
108-
const getResolvedModuleWithFailedLookupLocationsFromCache: _ts.LanguageServiceHost['getResolvedModuleWithFailedLookupLocationsFromCache'] = (
109-
moduleName,
110-
containingFile
111-
): _ts.ResolvedModuleWithFailedLookupLocations | undefined => {
112-
const ret = ts.resolveModuleNameFromCache(
102+
const getResolvedModuleWithFailedLookupLocationsFromCache: _ts.LanguageServiceHost['getResolvedModuleWithFailedLookupLocationsFromCache'] =
103+
(
113104
moduleName,
114-
containingFile,
115-
moduleResolutionCache
116-
);
117-
if (ret && ret.resolvedModule) {
118-
fixupResolvedModule(ret.resolvedModule);
119-
}
120-
return ret;
121-
};
122-
123-
const resolveTypeReferenceDirectives: _ts.LanguageServiceHost['resolveTypeReferenceDirectives'] = (
124-
typeDirectiveNames: string[],
125-
containingFile: string,
126-
redirectedReference: _ts.ResolvedProjectReference | undefined,
127-
options: _ts.CompilerOptions
128-
): (_ts.ResolvedTypeReferenceDirective | undefined)[] => {
129-
// Note: seems to be called with empty typeDirectiveNames array for all files.
130-
return typeDirectiveNames.map((typeDirectiveName) => {
131-
let { resolvedTypeReferenceDirective } = ts.resolveTypeReferenceDirective(
132-
typeDirectiveName,
105+
containingFile
106+
): _ts.ResolvedModuleWithFailedLookupLocations | undefined => {
107+
const ret = ts.resolveModuleNameFromCache(
108+
moduleName,
133109
containingFile,
134-
config.options,
135-
host,
136-
redirectedReference
110+
moduleResolutionCache
137111
);
138-
if (typeDirectiveName === 'node' && !resolvedTypeReferenceDirective) {
139-
// Resolve @types/node relative to project first, then __dirname (copy logic from elsewhere / refactor into reusable function)
140-
let typesNodePackageJsonPath: string | undefined;
141-
try {
142-
typesNodePackageJsonPath = require.resolve(
143-
'@types/node/package.json',
144-
{
145-
paths: [configFilePath ?? cwd, __dirname],
146-
}
147-
);
148-
} catch {} // gracefully do nothing when @types/node is not installed for any reason
149-
if (typesNodePackageJsonPath) {
150-
const typeRoots = [resolve(typesNodePackageJsonPath, '../..')];
151-
({
152-
resolvedTypeReferenceDirective,
153-
} = ts.resolveTypeReferenceDirective(
112+
if (ret && ret.resolvedModule) {
113+
fixupResolvedModule(ret.resolvedModule);
114+
}
115+
return ret;
116+
};
117+
118+
const resolveTypeReferenceDirectives: _ts.LanguageServiceHost['resolveTypeReferenceDirectives'] =
119+
(
120+
typeDirectiveNames: string[],
121+
containingFile: string,
122+
redirectedReference: _ts.ResolvedProjectReference | undefined,
123+
options: _ts.CompilerOptions
124+
): (_ts.ResolvedTypeReferenceDirective | undefined)[] => {
125+
// Note: seems to be called with empty typeDirectiveNames array for all files.
126+
return typeDirectiveNames.map((typeDirectiveName) => {
127+
let { resolvedTypeReferenceDirective } =
128+
ts.resolveTypeReferenceDirective(
154129
typeDirectiveName,
155130
containingFile,
156-
{
157-
...config.options,
158-
typeRoots,
159-
},
131+
config.options,
160132
host,
161133
redirectedReference
162-
));
134+
);
135+
if (typeDirectiveName === 'node' && !resolvedTypeReferenceDirective) {
136+
// Resolve @types/node relative to project first, then __dirname (copy logic from elsewhere / refactor into reusable function)
137+
let typesNodePackageJsonPath: string | undefined;
138+
try {
139+
typesNodePackageJsonPath = require.resolve(
140+
'@types/node/package.json',
141+
{
142+
paths: [configFilePath ?? cwd, __dirname],
143+
}
144+
);
145+
} catch {} // gracefully do nothing when @types/node is not installed for any reason
146+
if (typesNodePackageJsonPath) {
147+
const typeRoots = [resolve(typesNodePackageJsonPath, '../..')];
148+
({ resolvedTypeReferenceDirective } =
149+
ts.resolveTypeReferenceDirective(
150+
typeDirectiveName,
151+
containingFile,
152+
{
153+
...config.options,
154+
typeRoots,
155+
},
156+
host,
157+
redirectedReference
158+
));
159+
}
163160
}
164-
}
165-
if (resolvedTypeReferenceDirective) {
166-
fixupResolvedModule(resolvedTypeReferenceDirective);
167-
}
168-
return resolvedTypeReferenceDirective;
169-
});
170-
};
161+
if (resolvedTypeReferenceDirective) {
162+
fixupResolvedModule(resolvedTypeReferenceDirective);
163+
}
164+
return resolvedTypeReferenceDirective;
165+
});
166+
};
171167

172168
return {
173169
resolveModuleNames,

src/test/index.spec.ts

+2-8
Original file line numberDiff line numberDiff line change
@@ -1086,21 +1086,15 @@ test.suite('ts-node', (test) => {
10861086

10871087
test.suite('supports experimental-specifier-resolution=node', (test) => {
10881088
test('via --experimental-specifier-resolution', async () => {
1089-
const {
1090-
err,
1091-
stdout,
1092-
} = await exec(
1089+
const { err, stdout } = await exec(
10931090
`${CMD_ESM_LOADER_WITHOUT_PROJECT} --experimental-specifier-resolution=node index.ts`,
10941091
{ cwd: join(TEST_DIR, './esm-node-resolver') }
10951092
);
10961093
expect(err).toBe(null);
10971094
expect(stdout).toBe('foo bar baz biff libfoo\n');
10981095
});
10991096
test('via --es-module-specifier-resolution alias', async () => {
1100-
const {
1101-
err,
1102-
stdout,
1103-
} = await exec(
1097+
const { err, stdout } = await exec(
11041098
`${CMD_ESM_LOADER_WITHOUT_PROJECT} ${EXPERIMENTAL_MODULES_FLAG} --es-module-specifier-resolution=node index.ts`,
11051099
{ cwd: join(TEST_DIR, './esm-node-resolver') }
11061100
);

src/test/register.spec.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import * as exp from 'expect';
1212
import { join, resolve } from 'path';
1313
import proxyquire = require('proxyquire');
1414

15-
const SOURCE_MAP_REGEXP = /\/\/# sourceMappingURL=data:application\/json;charset=utf\-8;base64,[\w\+]+=*$/;
15+
const SOURCE_MAP_REGEXP =
16+
/\/\/# sourceMappingURL=data:application\/json;charset=utf\-8;base64,[\w\+]+=*$/;
1617

1718
const createOptions: tsNodeTypes.CreateOptions = {
1819
project: PROJECT,

src/test/repl/helpers.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ export async function contextReplHelpers(
3939
stderr,
4040
...createReplOpts,
4141
});
42-
const service = (registerHooks
43-
? tsNodeUnderTest.register
44-
: tsNodeUnderTest.create)({
42+
const service = (
43+
registerHooks ? tsNodeUnderTest.register : tsNodeUnderTest.create
44+
)({
4545
...replService.evalAwarePartialHost,
4646
project: `${TEST_DIR}/tsconfig.json`,
4747
...createServiceOpts,

src/test/repl/node-repl-tla.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,11 @@ export async function upstreamTopLevelAwaitTests({
3939
},
4040
});
4141
replService.setService(service);
42-
(replService.stdout as NodeJS.WritableStream & {
43-
isTTY: boolean;
44-
}).isTTY = true;
42+
(
43+
replService.stdout as NodeJS.WritableStream & {
44+
isTTY: boolean;
45+
}
46+
).isTTY = true;
4547
const replServer = replService.startInternal({
4648
prompt: PROMPT,
4749
terminal: true,

0 commit comments

Comments
 (0)