Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update prettier to 2.5.1 #1573

Merged
merged 2 commits into from
Dec 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions esm.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,5 @@ const require = createRequire(fileURLToPath(import.meta.url));

/** @type {import('./dist/esm')} */
const esm = require('./dist/esm');
export const {
resolve,
load,
getFormat,
transformSource,
} = esm.registerAndCreateEsmHooks();
export const { resolve, load, getFormat, transformSource } =
esm.registerAndCreateEsmHooks();
8 changes: 2 additions & 6 deletions esm/transpile-only.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,5 @@ const require = createRequire(fileURLToPath(import.meta.url));

/** @type {import('../dist/esm')} */
const esm = require('../dist/esm');
export const {
resolve,
load,
getFormat,
transformSource,
} = esm.registerAndCreateEsmHooks({ transpileOnly: true });
export const { resolve, load, getFormat, transformSource } =
esm.registerAndCreateEsmHooks({ transpileOnly: true });
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
"lodash": "^4.17.15",
"ntypescript": "^1.201507091536.1",
"nyc": "^15.0.1",
"prettier": "^2.2.1",
"prettier": "^2.5.1",
"proper-lockfile": "^4.1.2",
"proxyquire": "^2.0.0",
"react": "^16.14.0",
Expand Down
7 changes: 2 additions & 5 deletions scripts/create-merged-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ async function main() {
.compilerOptions,
allOf: [
{
$ref:
'#/definitions/compilerOptionsDefinition/properties/compilerOptions',
$ref: '#/definitions/compilerOptionsDefinition/properties/compilerOptions',
},
],
},
Expand All @@ -62,9 +61,7 @@ async function main() {
}

export async function getSchemastoreSchema() {
const {
data: schemastoreSchema,
} = await axios.get(
const { data: schemastoreSchema } = await axios.get(
'https://schemastore.azurewebsites.net/schemas/json/tsconfig.json',
{ responseType: 'json' }
);
Expand Down
2 changes: 1 addition & 1 deletion src/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ export function main(
}

if (showConfig) {
const ts = (service.ts as any) as TSInternal;
const ts = service.ts as any as TSInternal;
if (typeof ts.convertToTSConfig !== 'function') {
console.error(
'Error: --show-config requires a typescript versions >=3.2 that support --showConfig'
Expand Down
17 changes: 9 additions & 8 deletions src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export function readConfig(
},
bp,
errors,
((ts as unknown) as TSInternal).createCompilerDiagnostic
(ts as unknown as TSInternal).createCompilerDiagnostic
);
if (errors.length) {
return {
Expand All @@ -165,8 +165,9 @@ export function readConfig(
const optionBasePaths: OptionBasePaths = {};
for (let i = configChain.length - 1; i >= 0; i--) {
const { config, basePath, configPath } = configChain[i];
const options = filterRecognizedTsConfigTsNodeOptions(config['ts-node'])
.recognized;
const options = filterRecognizedTsConfigTsNodeOptions(
config['ts-node']
).recognized;

// Some options are relative to the config file, so must be converted to absolute paths here
if (options.require) {
Expand Down Expand Up @@ -250,9 +251,7 @@ export function readConfig(
* Given the raw "ts-node" sub-object from a tsconfig, return an object with only the properties
* recognized by "ts-node"
*/
function filterRecognizedTsConfigTsNodeOptions(
jsonObject: any
): {
function filterRecognizedTsConfigTsNodeOptions(jsonObject: any): {
recognized: TsConfigOptions;
unrecognized: any;
} {
Expand Down Expand Up @@ -303,7 +302,9 @@ function filterRecognizedTsConfigTsNodeOptions(
swc,
};
// Use the typechecker to make sure this implementation has the correct set of properties
const catchExtraneousProps: keyof TsConfigOptions = (null as any) as keyof typeof filteredTsConfigOptions;
const catchMissingProps: keyof typeof filteredTsConfigOptions = (null as any) as keyof TsConfigOptions;
const catchExtraneousProps: keyof TsConfigOptions =
null as any as keyof typeof filteredTsConfigOptions;
const catchMissingProps: keyof typeof filteredTsConfigOptions =
null as any as keyof TsConfigOptions;
return { recognized: filteredTsConfigOptions, unrecognized };
}
25 changes: 11 additions & 14 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -577,12 +577,8 @@ export function create(rawOptions: CreateOptions = {}): Service {
);

// Read config file and merge new options between env and CLI options.
const {
configFilePath,
config,
tsNodeOptionsFromTsconfig,
optionBasePaths,
} = readConfig(cwd, ts, rawOptions);
const { configFilePath, config, tsNodeOptionsFromTsconfig, optionBasePaths } =
readConfig(cwd, ts, rawOptions);
const options = assign<RegisterOptions>(
{},
DEFAULTS,
Expand Down Expand Up @@ -817,9 +813,9 @@ export function create(rawOptions: CreateOptions = {}): Service {
_position: number
) => TypeInfo;

const getCanonicalFileName = ((ts as unknown) as TSInternal).createGetCanonicalFileName(
ts.sys.useCaseSensitiveFileNames
);
const getCanonicalFileName = (
ts as unknown as TSInternal
).createGetCanonicalFileName(ts.sys.useCaseSensitiveFileNames);

const moduleTypeClassifier = createModuleTypeClassifier({
basePath: options.optionBasePaths?.moduleTypes,
Expand Down Expand Up @@ -908,8 +904,10 @@ export function create(rawOptions: CreateOptions = {}): Service {
configFilePath,
});
serviceHost.resolveModuleNames = resolveModuleNames;
serviceHost.getResolvedModuleWithFailedLookupLocationsFromCache = getResolvedModuleWithFailedLookupLocationsFromCache;
serviceHost.resolveTypeReferenceDirectives = resolveTypeReferenceDirectives;
serviceHost.getResolvedModuleWithFailedLookupLocationsFromCache =
getResolvedModuleWithFailedLookupLocationsFromCache;
serviceHost.resolveTypeReferenceDirectives =
resolveTypeReferenceDirectives;

const registry = ts.createDocumentRegistry(
ts.sys.useCaseSensitiveFileNames,
Expand Down Expand Up @@ -1272,9 +1270,8 @@ export function create(rawOptions: CreateOptions = {}): Service {
// Create a simple TypeScript compiler proxy.
function compile(code: string, fileName: string, lineOffset = 0) {
const normalizedFileName = normalizeSlashes(fileName);
const classification = moduleTypeClassifier.classifyModule(
normalizedFileName
);
const classification =
moduleTypeClassifier.classifyModule(normalizedFileName);
// Must always call normal getOutput to throw typechecking errors
let [value, sourceMap] = getOutput(code, normalizedFileName);
// If module classification contradicts the above, call the relevant transpiler
Expand Down
122 changes: 59 additions & 63 deletions src/resolver-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,8 @@ export function createResolverFunctions(kwargs: {
config: _ts.ParsedCommandLine;
configFilePath: string | undefined;
}) {
const {
host,
ts,
config,
cwd,
getCanonicalFileName,
configFilePath,
} = kwargs;
const { host, ts, config, cwd, getCanonicalFileName, configFilePath } =
kwargs;
const moduleResolutionCache = ts.createModuleResolutionCache(
cwd,
getCanonicalFileName,
Expand Down Expand Up @@ -105,69 +99,71 @@ export function createResolverFunctions(kwargs: {
};

// language service never calls this, but TS docs recommend that we implement it
const getResolvedModuleWithFailedLookupLocationsFromCache: _ts.LanguageServiceHost['getResolvedModuleWithFailedLookupLocationsFromCache'] = (
moduleName,
containingFile
): _ts.ResolvedModuleWithFailedLookupLocations | undefined => {
const ret = ts.resolveModuleNameFromCache(
const getResolvedModuleWithFailedLookupLocationsFromCache: _ts.LanguageServiceHost['getResolvedModuleWithFailedLookupLocationsFromCache'] =
(
moduleName,
containingFile,
moduleResolutionCache
);
if (ret && ret.resolvedModule) {
fixupResolvedModule(ret.resolvedModule);
}
return ret;
};

const resolveTypeReferenceDirectives: _ts.LanguageServiceHost['resolveTypeReferenceDirectives'] = (
typeDirectiveNames: string[],
containingFile: string,
redirectedReference: _ts.ResolvedProjectReference | undefined,
options: _ts.CompilerOptions
): (_ts.ResolvedTypeReferenceDirective | undefined)[] => {
// Note: seems to be called with empty typeDirectiveNames array for all files.
return typeDirectiveNames.map((typeDirectiveName) => {
let { resolvedTypeReferenceDirective } = ts.resolveTypeReferenceDirective(
typeDirectiveName,
containingFile
): _ts.ResolvedModuleWithFailedLookupLocations | undefined => {
const ret = ts.resolveModuleNameFromCache(
moduleName,
containingFile,
config.options,
host,
redirectedReference
moduleResolutionCache
);
if (typeDirectiveName === 'node' && !resolvedTypeReferenceDirective) {
// Resolve @types/node relative to project first, then __dirname (copy logic from elsewhere / refactor into reusable function)
let typesNodePackageJsonPath: string | undefined;
try {
typesNodePackageJsonPath = require.resolve(
'@types/node/package.json',
{
paths: [configFilePath ?? cwd, __dirname],
}
);
} catch {} // gracefully do nothing when @types/node is not installed for any reason
if (typesNodePackageJsonPath) {
const typeRoots = [resolve(typesNodePackageJsonPath, '../..')];
({
resolvedTypeReferenceDirective,
} = ts.resolveTypeReferenceDirective(
if (ret && ret.resolvedModule) {
fixupResolvedModule(ret.resolvedModule);
}
return ret;
};

const resolveTypeReferenceDirectives: _ts.LanguageServiceHost['resolveTypeReferenceDirectives'] =
(
typeDirectiveNames: string[],
containingFile: string,
redirectedReference: _ts.ResolvedProjectReference | undefined,
options: _ts.CompilerOptions
): (_ts.ResolvedTypeReferenceDirective | undefined)[] => {
// Note: seems to be called with empty typeDirectiveNames array for all files.
return typeDirectiveNames.map((typeDirectiveName) => {
let { resolvedTypeReferenceDirective } =
ts.resolveTypeReferenceDirective(
typeDirectiveName,
containingFile,
{
...config.options,
typeRoots,
},
config.options,
host,
redirectedReference
));
);
if (typeDirectiveName === 'node' && !resolvedTypeReferenceDirective) {
// Resolve @types/node relative to project first, then __dirname (copy logic from elsewhere / refactor into reusable function)
let typesNodePackageJsonPath: string | undefined;
try {
typesNodePackageJsonPath = require.resolve(
'@types/node/package.json',
{
paths: [configFilePath ?? cwd, __dirname],
}
);
} catch {} // gracefully do nothing when @types/node is not installed for any reason
if (typesNodePackageJsonPath) {
const typeRoots = [resolve(typesNodePackageJsonPath, '../..')];
({ resolvedTypeReferenceDirective } =
ts.resolveTypeReferenceDirective(
typeDirectiveName,
containingFile,
{
...config.options,
typeRoots,
},
host,
redirectedReference
));
}
}
}
if (resolvedTypeReferenceDirective) {
fixupResolvedModule(resolvedTypeReferenceDirective);
}
return resolvedTypeReferenceDirective;
});
};
if (resolvedTypeReferenceDirective) {
fixupResolvedModule(resolvedTypeReferenceDirective);
}
return resolvedTypeReferenceDirective;
});
};

return {
resolveModuleNames,
Expand Down
10 changes: 2 additions & 8 deletions src/test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1086,21 +1086,15 @@ test.suite('ts-node', (test) => {

test.suite('supports experimental-specifier-resolution=node', (test) => {
test('via --experimental-specifier-resolution', async () => {
const {
err,
stdout,
} = await exec(
const { err, stdout } = await exec(
`${CMD_ESM_LOADER_WITHOUT_PROJECT} --experimental-specifier-resolution=node index.ts`,
{ cwd: join(TEST_DIR, './esm-node-resolver') }
);
expect(err).toBe(null);
expect(stdout).toBe('foo bar baz biff libfoo\n');
});
test('via --es-module-specifier-resolution alias', async () => {
const {
err,
stdout,
} = await exec(
const { err, stdout } = await exec(
`${CMD_ESM_LOADER_WITHOUT_PROJECT} ${EXPERIMENTAL_MODULES_FLAG} --es-module-specifier-resolution=node index.ts`,
{ cwd: join(TEST_DIR, './esm-node-resolver') }
);
Expand Down
3 changes: 2 additions & 1 deletion src/test/register.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import * as exp from 'expect';
import { join, resolve } from 'path';
import proxyquire = require('proxyquire');

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

const createOptions: tsNodeTypes.CreateOptions = {
project: PROJECT,
Expand Down
6 changes: 3 additions & 3 deletions src/test/repl/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ export async function contextReplHelpers(
stderr,
...createReplOpts,
});
const service = (registerHooks
? tsNodeUnderTest.register
: tsNodeUnderTest.create)({
const service = (
registerHooks ? tsNodeUnderTest.register : tsNodeUnderTest.create
)({
...replService.evalAwarePartialHost,
project: `${TEST_DIR}/tsconfig.json`,
...createServiceOpts,
Expand Down
8 changes: 5 additions & 3 deletions src/test/repl/node-repl-tla.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ export async function upstreamTopLevelAwaitTests({
},
});
replService.setService(service);
(replService.stdout as NodeJS.WritableStream & {
isTTY: boolean;
}).isTTY = true;
(
replService.stdout as NodeJS.WritableStream & {
isTTY: boolean;
}
).isTTY = true;
const replServer = replService.startInternal({
prompt: PROMPT,
terminal: true,
Expand Down
Loading