Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into esm-child-process
Browse files Browse the repository at this point in the history
  • Loading branch information
cspotcode committed Feb 22, 2022
2 parents 1e5e666 + f8b572c commit a28a3be
Show file tree
Hide file tree
Showing 29 changed files with 1,026 additions and 507 deletions.
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ tests/throw error.ts
tests/throw error react tsx.tsx
tests/esm/throw error.ts
tests/legacy-source-map-support-interop/index.ts
tests/main-realpath/symlink/symlink.tsx
122 changes: 84 additions & 38 deletions README.md

Large diffs are not rendered by default.

22 changes: 19 additions & 3 deletions api-extractor/ts-node.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export interface CreateOptions {
ignore?: string[];
ignoreDiagnostics?: Array<number | string>;
logError?: boolean;
moduleTypes?: Record<string, 'cjs' | 'esm' | 'package'>;
moduleTypes?: ModuleTypes;
pretty?: boolean;
project?: string;
projectSearchDir?: string;
Expand All @@ -43,10 +43,12 @@ export interface CreateOptions {
scopeDir?: string;
skipIgnore?: boolean;
skipProject?: boolean;
swc?: boolean;
// (undocumented)
transformers?: _ts.CustomTransformers | ((p: _ts.Program) => _ts.CustomTransformers);
transpileOnly?: boolean;
transpiler?: string | [string, object];
tsTrace?: (str: string) => void;
typeCheck?: boolean;
}

Expand All @@ -72,12 +74,15 @@ export interface CreateReplOptions {
// @public (undocumented)
export interface CreateTranspilerOptions {
// (undocumented)
service: Pick<Service, 'config' | 'options'>;
service: Pick<Service, Extract<'config' | 'options' | 'projectLocalResolveHelper', keyof Service>>;
}

// @public
export type EvalAwarePartialHost = Pick<CreateOptions, 'readFile' | 'fileExists'>;

// @public (undocumented)
export type ModuleTypes = Record<string, 'cjs' | 'esm' | 'package'>;

// @public (undocumented)
export interface NodeLoaderHooksAPI1 {
// (undocumented)
Expand Down Expand Up @@ -118,12 +123,22 @@ export namespace NodeLoaderHooksAPI2 {
// (undocumented)
export type LoadHook = (url: string, context: {
format: NodeLoaderHooksFormat | null | undefined;
importAssertions?: NodeImportAssertions;
}, defaultLoad: NodeLoaderHooksAPI2['load']) => Promise<{
format: NodeLoaderHooksFormat;
source: string | Buffer | undefined;
}>;
// (undocumented)
export interface NodeImportAssertions {
// (undocumented)
type?: 'json';
}
// (undocumented)
export type NodeImportConditions = unknown;
// (undocumented)
export type ResolveHook = (specifier: string, context: {
conditions?: NodeImportConditions;
importAssertions?: NodeImportAssertions;
parentURL: string;
}, defaultResolve: ResolveHook) => Promise<{
url: string;
Expand All @@ -147,6 +162,7 @@ export const REGISTER_INSTANCE: unique symbol;

// @public
export interface RegisterOptions extends CreateOptions {
experimentalResolverFeatures?: boolean;
preferTsExts?: boolean;
}

Expand Down Expand Up @@ -276,7 +292,7 @@ export interface TSCommon {
}

// @public
export interface TsConfigOptions extends Omit<RegisterOptions, 'transformers' | 'readFile' | 'fileExists' | 'skipProject' | 'project' | 'dir' | 'cwd' | 'projectSearchDir' | 'optionBasePaths'> {
export interface TsConfigOptions extends Omit<RegisterOptions, 'transformers' | 'readFile' | 'fileExists' | 'skipProject' | 'project' | 'dir' | 'cwd' | 'projectSearchDir' | 'optionBasePaths' | 'tsTrace'> {
}

// @public
Expand Down
87 changes: 31 additions & 56 deletions package-lock.json

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

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ts-node",
"version": "10.4.0",
"version": "10.5.0",
"description": "TypeScript execution environment and REPL for node.js, with source map support",
"main": "dist/index.js",
"exports": {
Expand Down Expand Up @@ -138,8 +138,8 @@
"semver": "^7.1.3",
"throat": "^6.0.1",
"typedoc": "^0.22.10",
"typescript": "4.5.2",
"typescript-json-schema": "^0.51.0",
"typescript": "4.5.5",
"typescript-json-schema": "^0.53.0",
"util.promisify": "^1.0.1"
},
"peerDependencies": {
Expand Down
33 changes: 29 additions & 4 deletions src/bin.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env node

import { join, resolve, dirname, parse as parsePath } from 'path';
import { spawnSync } from 'child_process';
import { join, resolve, dirname, parse as parsePath, relative } from 'path';
import { inspect } from 'util';
import Module = require('module');
let arg: typeof import('arg');
Expand Down Expand Up @@ -403,24 +402,50 @@ function phase4(payload: BootstrapState) {
stdinStuff?.repl.setService(service);

// Output project information.
if (version >= 2) {
if (version === 2) {
console.log(`ts-node v${VERSION}`);
console.log(`node ${process.version}`);
console.log(`compiler v${service.ts.version}`);
process.exit(0);
}
if (version >= 3) {
console.log(`ts-node v${VERSION} ${dirname(__dirname)}`);
console.log(`node ${process.version}`);
console.log(
`compiler v${service.ts.version} ${service.compilerPath ?? ''}`
);
process.exit(0);
}

if (showConfig) {
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'
'Error: --showConfig requires a typescript versions >=3.2 that support --showConfig'
);
process.exit(1);
}
let moduleTypes = undefined;
if (service.options.moduleTypes) {
// Assumption: this codepath requires CLI invocation, so moduleTypes must have come from a tsconfig, not API.
const showRelativeTo = dirname(service.configFilePath!);
moduleTypes = {} as Record<string, string>;
for (const [key, value] of Object.entries(service.options.moduleTypes)) {
moduleTypes[
relative(
showRelativeTo,
resolve(service.options.optionBasePaths?.moduleTypes!, key)
)
] = value;
}
}
const json = {
['ts-node']: {
...service.options,
require: service.options.require?.length
? service.options.require
: undefined,
moduleTypes,
optionBasePaths: undefined,
compilerOptions: undefined,
project: service.configFilePath ?? service.options.project,
Expand Down
14 changes: 11 additions & 3 deletions src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import type { TSInternal } from './ts-compiler-types';
import { createTsInternals } from './ts-internals';
import { getDefaultTsconfigJsonForNodeVersion } from './tsconfigs';
import { assign, createRequire } from './util';
import { assign, createProjectLocalResolveHelper } from './util';

/**
* TypeScript compiler option values required by `ts-node` which cannot be overridden.
Expand Down Expand Up @@ -172,9 +172,11 @@ export function readConfig(
// Some options are relative to the config file, so must be converted to absolute paths here
if (options.require) {
// Modules are found relative to the tsconfig file, not the `dir` option
const tsconfigRelativeRequire = createRequire(configPath);
const tsconfigRelativeResolver = createProjectLocalResolveHelper(
dirname(configPath)
);
options.require = options.require.map((path: string) =>
tsconfigRelativeRequire.resolve(path)
tsconfigRelativeResolver(path, false)
);
}
if (options.scopeDir) {
Expand All @@ -185,6 +187,12 @@ export function readConfig(
if (options.moduleTypes) {
optionBasePaths.moduleTypes = basePath;
}
if (options.transpiler != null) {
optionBasePaths.transpiler = basePath;
}
if (options.compiler != null) {
optionBasePaths.compiler = basePath;
}

assign(tsNodeOptionsFromTsconfig, options);
}
Expand Down

0 comments on commit a28a3be

Please sign in to comment.