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

Sort imports #1960

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
47 changes: 47 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"ignorePatterns": [
"/dist-raw/**",
"/esm/**",
"/esm-usage-example/**",
"/raw/**",
"/register/**",
"/scripts/**",
"/tests/**",
"/transpilers/**",
"/website/**",
"/*.js",
"/*.cjs",
"/*.mjs",
"*.json"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
// "project": ["./tsconfig.json"],
"sourceType": "module"
},
"plugins": ["import"],
"rules": {
"sort-imports": ["error", {
"ignoreDeclarationSort": true
}],
"import/first": "error",
"import/newline-after-import": "error",
"import/no-duplicates": "error",
"import/order": [
"error",
{
"groups": [
"builtin",
"external",
"parent",
"sibling",
"index"
],
"newlines-between": "always",
"alphabetize": {
"order": "asc"
}
}
]
}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ npm-debug.log
/.yarn/install-state.gz
/tests/.yarn/install-state.gz
/tests/.yarn/cache
/.eslintcache
2 changes: 2 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ lint *ARGS:
dprint check "$@"
fmt *ARGS:
dprint fmt "$@"
fmt-eslint *ARGS:
eslint --fix --ext ts,mts,cts,js,mjs,cjs --cache . "$@"
clean *ARGS:
rimraf temp dist tsconfig.schema.json tsconfig.schemastore-schema.json tsconfig.tsbuildinfo tests/ts-node-packed.tgz tests/node_modules tests/tmp "$@"
rebuild *ARGS:
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"scripts": {
"lint": "dprint check",
"fmt": "dprint fmt",
"fmt-eslint": "eslint --fix --ext ts,mts,cts,js,mjs,cjs --cache .",
"clean": "rimraf temp dist tsconfig.schema.json tsconfig.schemastore-schema.json tsconfig.tsbuildinfo tests/ts-node-packed.tgz tests/node_modules tests/tmp",
"rebuild": "yarn clean && yarn build",
"build": "yarn build-nopack && yarn build-pack && yarn build-manifest",
Expand Down Expand Up @@ -122,9 +123,12 @@
"@types/react": "^16.14.19",
"@types/rimraf": "^3.0.0",
"@types/semver": "^7.1.0",
"@typescript-eslint/parser": "^5.52.0",
"ava": "^5.1.1",
"axios": "^0.21.1",
"dprint": "^0.25.0",
"eslint": "^8.34.0",
"eslint-plugin-import": "^2.27.5",
"expect": "27.0.2",
"lodash": "^4.17.15",
"nyc": "^15.0.1",
Expand Down
41 changes: 24 additions & 17 deletions src/bin.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,42 @@
#!/usr/bin/env node

import { join, resolve, dirname, parse as parsePath, relative } from 'path';
import { inspect } from 'util';
import Module = require('module');
let arg: typeof import('arg');
import { parse, createRequire, hasOwnProperty, versionGteLt } from './util';
import { dirname, join, parse as parsePath, relative, resolve } from 'path';
import { inspect } from 'util';




import { addBuiltinLibsToObject } from '../dist-raw/node-internal-modules-cjs-helpers';

import { callInChild } from './child/spawn-child';
import { findAndReadConfig } from './configuration';
import {
EVAL_FILENAME,
EVAL_NAME,
EvalAwarePartialHost,
EvalState,
createRepl,
REPL_FILENAME,
ReplService,
setupContext,
STDIN_FILENAME,
EvalAwarePartialHost,
EVAL_NAME,
STDIN_NAME,
REPL_FILENAME,
createRepl,
setupContext,
} from './repl';
import type { TSInternal } from './ts-compiler-types';
import { createRequire, hasOwnProperty, parse, versionGteLt } from './util';

import {
VERSION,
DEFAULTS,
ExperimentalSpecifierResolution,
TSError,
register,
VERSION,
createEsmHooks,
createFromPreloadedConfig,
DEFAULTS,
ExperimentalSpecifierResolution,
register,
} from './index';
import type { TSInternal } from './ts-compiler-types';
import { addBuiltinLibsToObject } from '../dist-raw/node-internal-modules-cjs-helpers';
import { callInChild } from './child/spawn-child';
import { findAndReadConfig } from './configuration';

let arg: typeof import('arg');

/**
* Main `bin` functionality.
Expand Down
1 change: 1 addition & 0 deletions src/child/child-entrypoint.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { BootstrapState, bootstrap } from '../bin';

import { argPrefix, compress, decompress } from './argv-payload';

const base64ConfigArg = process.argv[2];
Expand Down
4 changes: 3 additions & 1 deletion src/child/spawn-child.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { BootstrapState } from '../bin';
import { spawn } from 'child_process';
import { pathToFileURL } from 'url';

import type { BootstrapState } from '../bin';

import { argPrefix, compress } from './argv-payload';

/**
Expand Down
1 change: 1 addition & 0 deletions src/cjs-resolve-hooks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type Module = require('module');

import type { Service } from '.';

/** @internal */
Expand Down
21 changes: 12 additions & 9 deletions src/configuration.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import { resolve, dirname, join } from 'path';
import { dirname, join, resolve } from 'path';

import type * as _ts from 'typescript';
import {
CreateOptions,
DEFAULTS,
OptionBasePaths,
RegisterOptions,
TSCommon,
TsConfigOptions,
} from './index';

import type { TSInternal } from './ts-compiler-types';
import { createTsInternals } from './ts-internals';
import { getDefaultTsconfigJsonForNodeVersion } from './tsconfigs';
Expand All @@ -18,6 +12,15 @@ import {
getBasePathForProjectLocalDependencyResolution,
} from './util';

import {
CreateOptions,
DEFAULTS,
OptionBasePaths,
RegisterOptions,
TSCommon,
TsConfigOptions,
} from './index';

/**
* TypeScript compiler option values required by `ts-node` which cannot be overridden.
*/
Expand Down
15 changes: 9 additions & 6 deletions src/esm.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import { register, RegisterOptions, Service } from './index';
import * as assert from 'assert';
import { createRequire } from 'module';
import { extname, resolve as pathResolve } from 'path';
import {
parse as parseUrl,
format as formatUrl,
UrlWithStringQuery,
fileURLToPath,
format as formatUrl,
parse as parseUrl,
pathToFileURL,
} from 'url';
import { extname, resolve as pathResolve } from 'path';
import * as assert from 'assert';

import { normalizeSlashes, versionGteLt } from './util';
import { createRequire } from 'module';


import { RegisterOptions, Service, register } from './index';

// Note: On Windows, URLs look like this: file:///D:/dev/@TypeStrong/ts-node-examples/foo.ts

Expand Down
4 changes: 3 additions & 1 deletion src/file-extensions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import type * as _ts from 'typescript';
import type { RegisterOptions } from '.';

import { versionGteLt } from './util';

import type { RegisterOptions } from '.';

/**
* Centralized specification of how we deal with file extensions based on
* project options:
Expand Down
46 changes: 24 additions & 22 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,46 @@
import { relative, basename, extname, dirname, join } from 'path';
import { Module } from 'module';
import * as util from 'util';
import { basename, dirname, extname, join, relative } from 'path';
import { fileURLToPath } from 'url';
import * as util from 'util';

import type * as _sourceMapSupport from '@cspotcode/source-map-support';
import { BaseError } from 'make-error';
import type * as _ts from 'typescript';

import type * as _nodeInternalModulesCjsLoader from '../dist-raw/node-internal-modules-cjs-loader';
import { assertScriptCanLoadAsCJS } from '../dist-raw/node-internal-modules-cjs-loader';
import type * as _nodeInternalModulesEsmGetFormat from '../dist-raw/node-internal-modules-esm-get_format';
import type * as _nodeInternalModulesEsmResolve from '../dist-raw/node-internal-modules-esm-resolve';

import {
ModuleConstructorWithInternals,
installCommonjsResolveHooksIfNecessary,
} from './cjs-resolve-hooks';
import { findAndReadConfig, loadCompiler } from './configuration';
import type { createEsmHooks as createEsmHooksFn } from './esm';
import { Extensions, getExtensions } from './file-extensions';
import {
ModuleTypeClassifier,
createModuleTypeClassifier,
} from './module-type-classifier';
import { classifyModule } from './node-module-type-classifier';
import { createResolverFunctions } from './resolver-functions';
import type { Transpiler, TranspilerFactory } from './transpilers/types';
import type { TSCommon, TSInternal } from './ts-compiler-types';
import { createTsTranspileModule } from './ts-transpile-module';
import {
ProjectLocalResolveHelper,
cachedLookup,
createProjectLocalResolveHelper,
hasOwnProperty,
normalizeSlashes,
once,
parse,
ProjectLocalResolveHelper,
split,
versionGteLt,
yn,
} from './util';
import { findAndReadConfig, loadCompiler } from './configuration';
import type { TSCommon, TSInternal } from './ts-compiler-types';
import {
createModuleTypeClassifier,
ModuleTypeClassifier,
} from './module-type-classifier';
import { createResolverFunctions } from './resolver-functions';
import type { createEsmHooks as createEsmHooksFn } from './esm';
import {
installCommonjsResolveHooksIfNecessary,
ModuleConstructorWithInternals,
} from './cjs-resolve-hooks';
import { classifyModule } from './node-module-type-classifier';
import type * as _nodeInternalModulesEsmResolve from '../dist-raw/node-internal-modules-esm-resolve';
import type * as _nodeInternalModulesEsmGetFormat from '../dist-raw/node-internal-modules-esm-get_format';
import type * as _nodeInternalModulesCjsLoader from '../dist-raw/node-internal-modules-cjs-loader';
import { Extensions, getExtensions } from './file-extensions';
import { createTsTranspileModule } from './ts-transpile-module';
import { assertScriptCanLoadAsCJS } from '../dist-raw/node-internal-modules-cjs-loader';


export { TSCommon };
export {
Expand Down
3 changes: 2 additions & 1 deletion src/module-type-classifier.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type { ModuleTypeOverride, ModuleTypes } from '.';
import { getPatternFromSpec } from './ts-internals';
import { cachedLookup, normalizeSlashes } from './util';

import type { ModuleTypeOverride, ModuleTypes } from '.';

// Logic to support our `moduleTypes` option, which allows overriding node's default ESM / CJS
// classification of `.js` files based on package.json `type` field.

Expand Down
21 changes: 12 additions & 9 deletions src/repl.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
import type * as _diff from 'diff';
import * as assert from 'assert';
import { Console } from 'console';
import { readFileSync, statSync } from 'fs';
import type * as Module from 'module';
import { builtinModules } from 'module';
import { homedir } from 'os';
import { join } from 'path';
import {
REPLServer,
Recoverable,
ReplOptions,
REPLServer,
start as nodeReplStart,
} from 'repl';
import { Context, createContext, Script } from 'vm';
import { Service, CreateOptions, TSError, env } from './index';
import { readFileSync, statSync } from 'fs';
import { Console } from 'console';
import * as assert from 'assert';
import type * as tty from 'tty';
import type * as Module from 'module';
import { builtinModules } from 'module';
import { Context, Script, createContext } from 'vm';

import type * as _diff from 'diff';

import { CreateOptions, Service, TSError, env } from './index';


// Lazy-loaded.
let _processTopLevelAwait: (src: string) => string | null;
Expand Down
4 changes: 3 additions & 1 deletion src/resolver-functions.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { resolve } from 'path';
import type { CreateOptions } from '.';

import type { Extensions } from './file-extensions';
import type { TSCommon, TSInternal } from './ts-compiler-types';
import type { ProjectLocalResolveHelper } from './util';

import type { CreateOptions } from '.';

/**
* @internal
* In a factory because these are shared across both CompilerHost and LanguageService codepaths
Expand Down
2 changes: 2 additions & 0 deletions src/test/ci-node-and-ts-versions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
// and typescript in the test matrix.

import { execSync } from 'child_process';

import semver = require('semver');

import { ctxTsNode, ts } from './helpers';
import { context, expect } from './testlib';

Expand Down
10 changes: 5 additions & 5 deletions src/test/configuration/tsnode-opts-from-tsconfig.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { BIN_PATH } from '../helpers/paths';
import { createExec } from '../exec-helpers';
import { TEST_DIR } from '../helpers/paths';
import { context, expect } from '../testlib';
import { join, resolve } from 'path';
import { tsSupportsExtendsArray } from '../helpers/version-checks';

import { createExec } from '../exec-helpers';
import { ctxTsNode } from '../helpers';
import { BIN_PATH , TEST_DIR } from '../helpers/paths';
import { tsSupportsExtendsArray } from '../helpers/version-checks';
import { context, expect } from '../testlib';

const test = context(ctxTsNode);

Expand Down
7 changes: 5 additions & 2 deletions src/test/diagnostics.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { once } from 'lodash';
import * as semver from 'semver';

import type { TSError } from '..';

import { ctxTsNode, ts } from './helpers';
import { context, expect } from './testlib';
import * as semver from 'semver';
import { once } from 'lodash';

const test = context(ctxTsNode);

test.suite('TSError diagnostics', ({ context }) => {
Expand Down
Loading