Skip to content

Commit 7ff608d

Browse files
authored
Wider print width (#2012)
* increase formatting print-width to 120; 80 hurts legibility of TS too much * apply formatting * fix
1 parent 460bab2 commit 7ff608d

Some content is hidden

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

72 files changed

+1435
-2966
lines changed

dprint.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"incremental": true,
3-
"lineWidth": 80,
3+
"lineWidth": 120,
44
"prettier": {
55
"associations": [
66
"**/*.{ts,tsx,js,mjs,cjs,jsx,json,md}"

esm.mjs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@ const require = createRequire(fileURLToPath(import.meta.url));
44

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

esm/transpile-only.mjs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ const require = createRequire(fileURLToPath(import.meta.url));
44

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

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@
167167
"v8-compile-cache-lib": "^3.0.1"
168168
},
169169
"prettier": {
170-
"singleQuote": true
170+
"singleQuote": true,
171+
"printWidth": 120
171172
},
172173
"volta": {
173174
"node": "18.14.0",

scripts/build-manifest.mjs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,14 @@ import { resolve } from 'path';
44

55
// NOTE: could be replaced with using https://npm.im/yarpm
66

7-
const manifestPath = resolve(
8-
fileURLToPath(import.meta.url),
9-
'../../package.json'
10-
);
7+
const manifestPath = resolve(fileURLToPath(import.meta.url), '../../package.json');
118
const pkg = JSON.parse(readFileSync(manifestPath, 'utf8'));
129

1310
// Fully splat the "prepack" script so that it does not contain references to a package manager, neither `yarn` nor `npm`
1411
pkg.scripts.prepack = pkg.scripts.__prepack_template__;
1512
while (true) {
1613
let before = pkg.scripts.prepack;
17-
pkg.scripts.prepack = pkg.scripts.prepack.replace(
18-
/yarn (\S+)/g,
19-
($0, $1) => pkg.scripts[$1]
20-
);
14+
pkg.scripts.prepack = pkg.scripts.prepack.replace(/yarn (\S+)/g, ($0, $1) => pkg.scripts[$1]);
2115
if (pkg.scripts.prepack === before) break;
2216
}
2317

scripts/create-merged-schema.ts

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,10 @@ async function main() {
1919
// Apply this prefix to the names of all ts-node-generated definitions
2020
const tsnodeDefinitionPrefix = 'tsNode';
2121
let tsNodeSchema: any = JSON.parse(
22-
JSON.stringify(originalTsNodeSchema).replace(
23-
/#\/definitions\//g,
24-
`#/definitions/${tsnodeDefinitionPrefix}`
25-
)
22+
JSON.stringify(originalTsNodeSchema).replace(/#\/definitions\//g, `#/definitions/${tsnodeDefinitionPrefix}`)
2623
);
2724
tsNodeSchema.definitions = Object.fromEntries(
28-
Object.entries(tsNodeSchema.definitions).map(([key, value]) => [
29-
`${tsnodeDefinitionPrefix}${key}`,
30-
value,
31-
])
25+
Object.entries(tsNodeSchema.definitions).map(([key, value]) => [`${tsnodeDefinitionPrefix}${key}`, value])
3226
);
3327
// console.dir(tsNodeSchema, {
3428
// depth: Infinity
@@ -39,9 +33,7 @@ async function main() {
3933
...schemastoreSchema,
4034
definitions: {
4135
...Object.fromEntries(
42-
Object.entries(schemastoreSchema.definitions).filter(
43-
([key]) => !key.startsWith(tsnodeDefinitionPrefix)
44-
)
36+
Object.entries(schemastoreSchema.definitions).filter(([key]) => !key.startsWith(tsnodeDefinitionPrefix))
4537
),
4638
...tsNodeSchema.definitions,
4739
tsNodeTsConfigOptions: undefined,
@@ -50,15 +42,11 @@ async function main() {
5042
properties: {
5143
'ts-node': {
5244
...tsNodeSchema.definitions.tsNodeTsConfigOptions,
53-
description:
54-
tsNodeSchema.definitions.tsNodeTsConfigSchema.properties[
55-
'ts-node'
56-
].description,
45+
description: tsNodeSchema.definitions.tsNodeTsConfigSchema.properties['ts-node'].description,
5746
properties: {
5847
...tsNodeSchema.definitions.tsNodeTsConfigOptions.properties,
5948
compilerOptions: {
60-
...tsNodeSchema.definitions.tsNodeTsConfigOptions.properties
61-
.compilerOptions,
49+
...tsNodeSchema.definitions.tsNodeTsConfigOptions.properties.compilerOptions,
6250
allOf: [
6351
{
6452
$ref: '#/definitions/compilerOptionsDefinition/properties/compilerOptions',
@@ -73,17 +61,12 @@ async function main() {
7361
};
7462
// Splice into the allOf array at a spot that looks good. Does not affect
7563
// behavior of the schema, but looks nicer if we want to submit as a PR to schemastore.
76-
mergedSchema.allOf = mergedSchema.allOf.filter(
77-
(item: any) => !item.$ref?.includes('tsNode')
78-
);
64+
mergedSchema.allOf = mergedSchema.allOf.filter((item: any) => !item.$ref?.includes('tsNode'));
7965
mergedSchema.allOf.splice(mergedSchema.allOf.length - 1, 0, {
8066
$ref: '#/definitions/tsNodeDefinition',
8167
});
8268

83-
writeFileSync(
84-
resolve(__dirname, '../tsconfig.schemastore-schema.json'),
85-
JSON.stringify(mergedSchema, null, 2)
86-
);
69+
writeFileSync(resolve(__dirname, '../tsconfig.schemastore-schema.json'), JSON.stringify(mergedSchema, null, 2));
8770
}
8871

8972
export async function getSchemastoreSchema() {

scripts/update-schemastore-schema-with-compiler-options.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ import { getSchemastoreSchema } from './create-merged-schema';
3232

3333
async function main() {
3434
const schemastoreSchema = await getSchemastoreSchema();
35-
const compilerOptions =
36-
schemastoreSchema.definitions.compilerOptionsDefinition.properties
37-
.compilerOptions.properties;
35+
const compilerOptions = schemastoreSchema.definitions.compilerOptionsDefinition.properties.compilerOptions.properties;
3836

3937
// These options are only available via CLI flags, not in a tsconfig file.
4038
const excludedOptions = [

src/bin.ts

Lines changed: 22 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,7 @@ import { findAndReadConfig } from './configuration';
4242
*
4343
* @internal
4444
*/
45-
export function main(
46-
argv: string[] = process.argv.slice(2),
47-
entrypointArgs: Record<string, any> = {}
48-
) {
45+
export function main(argv: string[] = process.argv.slice(2), entrypointArgs: Record<string, any> = {}) {
4946
const args = parseArgv(argv, entrypointArgs);
5047
const state: BootstrapState = {
5148
shouldUseChildProcess: false,
@@ -174,8 +171,7 @@ function parseArgv(argv: string[], entrypointArgs: Record<string, any>) {
174171
'--log-error': '--logError',
175172
'--scope-dir': '--scopeDir',
176173
'--no-experimental-repl-await': '--noExperimentalReplAwait',
177-
'--experimental-specifier-resolution':
178-
'--experimentalSpecifierResolution',
174+
'--experimental-specifier-resolution': '--experimentalSpecifierResolution',
179175
},
180176
{
181177
argv,
@@ -379,12 +375,7 @@ function phase3(payload: BootstrapState) {
379375
compilerHost,
380376
ignore,
381377
logError,
382-
projectSearchDir: getProjectSearchDir(
383-
cwd,
384-
scriptMode,
385-
cwdMode,
386-
entryPointPath
387-
),
378+
projectSearchDir: getProjectSearchDir(cwd, scriptMode, cwdMode, entryPointPath),
388379
project,
389380
skipProject,
390381
skipIgnore,
@@ -396,8 +387,7 @@ function phase3(payload: BootstrapState) {
396387
scopeDir,
397388
preferTsExts,
398389
esm,
399-
experimentalSpecifierResolution:
400-
experimentalSpecifierResolution as ExperimentalSpecifierResolution,
390+
experimentalSpecifierResolution: experimentalSpecifierResolution as ExperimentalSpecifierResolution,
401391
});
402392

403393
// If ESM is enabled through the parsed tsconfig, stage4 should be run in a child
@@ -432,20 +422,14 @@ function getEntryPointInfo(state: BootstrapState) {
432422
// `node -e code -i ./script.js` ignores -e
433423
const executeEval = code != null && !(interactive && restArgs.length);
434424
const executeEntrypoint = !executeEval && restArgs.length > 0;
435-
const executeRepl =
436-
!executeEntrypoint &&
437-
(interactive || (process.stdin.isTTY && !executeEval));
425+
const executeRepl = !executeEntrypoint && (interactive || (process.stdin.isTTY && !executeEval));
438426
const executeStdin = !executeEval && !executeRepl && !executeEntrypoint;
439427

440428
/**
441429
* Unresolved. May point to a symlink, not realpath. May be missing file extension
442430
* NOTE: resolution relative to cwd option (not `process.cwd()`) is legacy backwards-compat; should be changed in next major: https://github.com/TypeStrong/ts-node/issues/1834
443431
*/
444-
const entryPointPath = executeEntrypoint
445-
? isCli
446-
? resolve(cwd, restArgs[0])
447-
: resolve(restArgs[0])
448-
: undefined;
432+
const entryPointPath = executeEntrypoint ? (isCli ? resolve(cwd, restArgs[0]) : resolve(restArgs[0])) : undefined;
449433

450434
return {
451435
executeEval,
@@ -458,18 +442,11 @@ function getEntryPointInfo(state: BootstrapState) {
458442

459443
function phase4(payload: BootstrapState) {
460444
const { isInChildProcess, tsNodeScript } = payload;
461-
const { version, showConfig, restArgs, code, print, argv } =
462-
payload.parseArgvResult;
445+
const { version, showConfig, restArgs, code, print, argv } = payload.parseArgvResult;
463446
const { cwd } = payload.phase2Result!;
464447
const { preloadedConfig } = payload.phase3Result!;
465448

466-
const {
467-
entryPointPath,
468-
executeEntrypoint,
469-
executeEval,
470-
executeRepl,
471-
executeStdin,
472-
} = getEntryPointInfo(payload);
449+
const { entryPointPath, executeEntrypoint, executeEval, executeRepl, executeStdin } = getEntryPointInfo(payload);
473450

474451
/**
475452
* <repl>, [stdin], and [eval] are all essentially virtual files that do not exist on disc and are backed by a REPL
@@ -543,13 +520,10 @@ function phase4(payload: BootstrapState) {
543520
});
544521
register(service);
545522

546-
if (replStuff)
547-
replStuff.state.path = join(cwd, REPL_FILENAME(service.ts.version));
523+
if (replStuff) replStuff.state.path = join(cwd, REPL_FILENAME(service.ts.version));
548524

549525
if (isInChildProcess)
550-
(
551-
require('./child/child-loader') as typeof import('./child/child-loader')
552-
).lateBindHooks(createEsmHooks(service));
526+
(require('./child/child-loader') as typeof import('./child/child-loader')).lateBindHooks(createEsmHooks(service));
553527

554528
// Bind REPL service to ts-node compiler service (chicken-and-egg problem)
555529
replStuff?.repl.setService(service);
@@ -566,18 +540,14 @@ function phase4(payload: BootstrapState) {
566540
if (version >= 3) {
567541
console.log(`ts-node v${VERSION} ${dirname(__dirname)}`);
568542
console.log(`node ${process.version}`);
569-
console.log(
570-
`compiler v${service.ts.version} ${service.compilerPath ?? ''}`
571-
);
543+
console.log(`compiler v${service.ts.version} ${service.compilerPath ?? ''}`);
572544
process.exit(0);
573545
}
574546

575547
if (showConfig) {
576548
const ts = service.ts as any as TSInternal;
577549
if (typeof ts.convertToTSConfig !== 'function') {
578-
console.error(
579-
'Error: --showConfig requires a typescript versions >=3.2 that support --showConfig'
580-
);
550+
console.error('Error: --showConfig requires a typescript versions >=3.2 that support --showConfig');
581551
process.exit(1);
582552
}
583553
let moduleTypes = undefined;
@@ -586,20 +556,13 @@ function phase4(payload: BootstrapState) {
586556
const showRelativeTo = dirname(service.configFilePath!);
587557
moduleTypes = {} as Record<string, string>;
588558
for (const [key, value] of Object.entries(service.options.moduleTypes)) {
589-
moduleTypes[
590-
relative(
591-
showRelativeTo,
592-
resolve(service.options.optionBasePaths?.moduleTypes!, key)
593-
)
594-
] = value;
559+
moduleTypes[relative(showRelativeTo, resolve(service.options.optionBasePaths?.moduleTypes!, key))] = value;
595560
}
596561
}
597562
const json = {
598563
['ts-node']: {
599564
...service.options,
600-
require: service.options.require?.length
601-
? service.options.require
602-
: undefined,
565+
require: service.options.require?.length ? service.options.require : undefined,
603566
moduleTypes,
604567
optionBasePaths: undefined,
605568
compilerOptions: undefined,
@@ -621,10 +584,7 @@ function phase4(payload: BootstrapState) {
621584
}
622585

623586
// Prepend `ts-node` arguments to CLI for child processes.
624-
process.execArgv.push(
625-
tsNodeScript,
626-
...argv.slice(2, argv.length - restArgs.length)
627-
);
587+
process.execArgv.push(tsNodeScript, ...argv.slice(2, argv.length - restArgs.length));
628588

629589
// TODO this comes from BootstrapState
630590
process.argv = [process.argv[1]]
@@ -633,10 +593,7 @@ function phase4(payload: BootstrapState) {
633593

634594
// Execute the main contents (either eval, script or piped).
635595
if (executeEntrypoint) {
636-
if (
637-
payload.isInChildProcess &&
638-
versionGteLt(process.versions.node, '18.6.0', '18.7.0')
639-
) {
596+
if (payload.isInChildProcess && versionGteLt(process.versions.node, '18.6.0', '18.7.0')) {
640597
// HACK workaround node regression
641598
require('../dist-raw/runmain-hack.js').run(entryPointPath);
642599
} else {
@@ -647,13 +604,7 @@ function phase4(payload: BootstrapState) {
647604
// If stdin runs, eval and repl will not.
648605
if (executeEval) {
649606
addBuiltinLibsToObject(global);
650-
evalAndExitOnTsError(
651-
evalStuff!.repl,
652-
evalStuff!.module!,
653-
code!,
654-
print,
655-
'eval'
656-
);
607+
evalAndExitOnTsError(evalStuff!.repl, evalStuff!.module!, code!, print, 'eval');
657608
}
658609

659610
if (executeRepl) {
@@ -680,23 +631,15 @@ function phase4(payload: BootstrapState) {
680631
/**
681632
* Get project search path from args.
682633
*/
683-
function getProjectSearchDir(
684-
cwd?: string,
685-
scriptMode?: boolean,
686-
cwdMode?: boolean,
687-
scriptPath?: string
688-
) {
634+
function getProjectSearchDir(cwd?: string, scriptMode?: boolean, cwdMode?: boolean, scriptPath?: string) {
689635
// Validate `--script-mode` / `--cwd-mode` / `--cwd` usage is correct.
690636
if (scriptMode && cwdMode) {
691637
throw new TypeError('--cwd-mode cannot be combined with --script-mode');
692638
}
693639
if (scriptMode && !scriptPath) {
694-
throw new TypeError(
695-
'--script-mode must be used with a script name, e.g. `ts-node --script-mode <script.ts>`'
696-
);
640+
throw new TypeError('--script-mode must be used with a script name, e.g. `ts-node --script-mode <script.ts>`');
697641
}
698-
const doScriptMode =
699-
scriptMode === true ? true : cwdMode === true ? false : !!scriptPath;
642+
const doScriptMode = scriptMode === true ? true : cwdMode === true ? false : !!scriptPath;
700643
if (doScriptMode) {
701644
// Use node's own resolution behavior to ensure we follow symlinks.
702645
// scriptPath may omit file extension or point to a directory with or without package.json.
@@ -739,9 +682,7 @@ function requireResolveNonCached(absoluteModuleSpecifier: string) {
739682
const { dir, base } = parsePath(absoluteModuleSpecifier);
740683
const relativeModuleSpecifier = `./${base}`;
741684

742-
const req = Module.createRequire(
743-
join(dir, 'imaginaryUncacheableRequireResolveScript')
744-
);
685+
const req = Module.createRequire(join(dir, 'imaginaryUncacheableRequireResolveScript'));
745686
return req.resolve(relativeModuleSpecifier, {
746687
paths: [
747688
`${guaranteedNonexistentDirectoryPrefix}${guaranteedNonexistentDirectorySuffix++}`,
@@ -775,11 +716,7 @@ function evalAndExitOnTsError(
775716
}
776717

777718
if (isPrinted) {
778-
console.log(
779-
typeof result === 'string'
780-
? result
781-
: inspect(result, { colors: process.stdout.isTTY })
782-
);
719+
console.log(typeof result === 'string' ? result : inspect(result, { colors: process.stdout.isTTY }));
783720
}
784721
}
785722

src/child/argv-payload.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,5 @@ export function compress(object: any) {
1212

1313
/** @internal */
1414
export function decompress(str: string) {
15-
return JSON.parse(
16-
brotliDecompressSync(Buffer.from(str, 'base64')).toString()
17-
);
15+
return JSON.parse(brotliDecompressSync(Buffer.from(str, 'base64')).toString());
1816
}

0 commit comments

Comments
 (0)