diff --git a/packages/cypress/package.json b/packages/cypress/package.json index 6b741d688286c..12dbd48290af0 100644 --- a/packages/cypress/package.json +++ b/packages/cypress/package.json @@ -19,7 +19,7 @@ "Cypress", "CLI" ], - "main": "./index.js", + "main": "./index", "typings": "./index.d.ts", "author": "Victor Savkin", "license": "MIT", diff --git a/packages/detox/package.json b/packages/detox/package.json index c81fe76c19f62..6ad96ed1d7974 100644 --- a/packages/detox/package.json +++ b/packages/detox/package.json @@ -22,7 +22,7 @@ }, "license": "MIT", "author": "Victor Savkin", - "main": "index.js", + "main": "./index", "types": "index.d.ts", "dependencies": { "@nrwl/devkit": "file:../devkit", diff --git a/packages/devkit/package.json b/packages/devkit/package.json index 2059ea2bffaa0..1582771901d89 100644 --- a/packages/devkit/package.json +++ b/packages/devkit/package.json @@ -19,7 +19,7 @@ "Cypress", "CLI" ], - "main": "./index.js", + "main": "./index", "typings": "./index.d.ts", "author": "Victor Savkin", "license": "MIT", diff --git a/packages/esbuild/package.json b/packages/esbuild/package.json index d42066efe56ee..13649571cbb7d 100644 --- a/packages/esbuild/package.json +++ b/packages/esbuild/package.json @@ -14,7 +14,7 @@ "Web", "CLI" ], - "main": "./index.js", + "main": "./index", "typings": "./index.d.ts", "author": "Victor Savkin", "license": "MIT", diff --git a/packages/expo/package.json b/packages/expo/package.json index 1a1e59e07a725..62fab978e4eea 100644 --- a/packages/expo/package.json +++ b/packages/expo/package.json @@ -23,7 +23,7 @@ }, "license": "MIT", "author": "Victor Savkin", - "main": "index.js", + "main": "./index", "types": "index.d.ts", "dependencies": { "@nrwl/detox": "file:../detox", diff --git a/packages/express/package.json b/packages/express/package.json index 6b10225d8c46b..7b4bc15b456f0 100644 --- a/packages/express/package.json +++ b/packages/express/package.json @@ -16,7 +16,7 @@ "Cypress", "CLI" ], - "main": "./index.js", + "main": "./index", "typings": "./index.d.ts", "author": "Victor Savkin", "license": "MIT", diff --git a/packages/jest/package.json b/packages/jest/package.json index 1a907a464337a..fe17321aa70ae 100644 --- a/packages/jest/package.json +++ b/packages/jest/package.json @@ -19,7 +19,7 @@ "Unit Testing", "CLI" ], - "main": "./index.js", + "main": "./index", "typings": "./index.d.ts", "author": "Victor Savkin", "license": "MIT", diff --git a/packages/linter/package.json b/packages/linter/package.json index 6ee91db1058ec..531c044354a9c 100644 --- a/packages/linter/package.json +++ b/packages/linter/package.json @@ -15,7 +15,7 @@ "ESLint", "CLI" ], - "main": "./index.js", + "main": "./index", "typings": "./index.d.ts", "author": "Victor Savkin", "license": "MIT", diff --git a/packages/nest/package.json b/packages/nest/package.json index d3fbfdb2d98e9..b8648052c5643 100644 --- a/packages/nest/package.json +++ b/packages/nest/package.json @@ -16,7 +16,7 @@ "Cypress", "CLI" ], - "main": "./index.js", + "main": "./index", "typings": "./index.d.ts", "author": "Victor Savkin", "license": "MIT", diff --git a/packages/next/package.json b/packages/next/package.json index af5cb5c0fde2a..6e37247e68c9d 100644 --- a/packages/next/package.json +++ b/packages/next/package.json @@ -16,7 +16,7 @@ "Cypress", "CLI" ], - "main": "./index.js", + "main": "./index", "typings": "./index.d.ts", "author": "Victor Savkin", "license": "MIT", diff --git a/packages/node/package.json b/packages/node/package.json index 445db110b3648..65cd661b4fde0 100644 --- a/packages/node/package.json +++ b/packages/node/package.json @@ -16,7 +16,7 @@ "Cypress", "CLI" ], - "main": "./index.js", + "main": "./index", "typings": "./index.d.ts", "author": "Victor Savkin", "license": "MIT", diff --git a/packages/nx-plugin/package.json b/packages/nx-plugin/package.json index 1a08a70d93fcd..2a1e202b59132 100644 --- a/packages/nx-plugin/package.json +++ b/packages/nx-plugin/package.json @@ -13,7 +13,7 @@ "Nx", "CLI" ], - "main": "./index.js", + "main": "./index", "types": "./index.d.ts", "author": "Nrwl", "license": "MIT", diff --git a/packages/nx/.eslintrc.json b/packages/nx/.eslintrc.json index 634134c1f3b32..2160aa7bb5821 100644 --- a/packages/nx/.eslintrc.json +++ b/packages/nx/.eslintrc.json @@ -8,8 +8,22 @@ "rules": {} }, { - "files": ["*.ts", "*.tsx"], - "rules": {} + "files": ["*.ts"], + "excludedFiles": ["*.spec.ts"], + "rules": { + "@typescript-eslint/no-restricted-imports": [ + "error", + { + "paths": [ + { + "name": "typescript", + "message": "TypeScript is an optional dependency for Nx. If you need to use it, make sure its installed first with ensureTypescript.", + "allowTypeImports": true + } + ] + } + ] + } }, { "files": ["*.js", "*.jsx"], diff --git a/packages/nx/src/utils/nx-plugin.ts b/packages/nx/src/utils/nx-plugin.ts index 44c0c3334d4cf..bb933097aa320 100644 --- a/packages/nx/src/utils/nx-plugin.ts +++ b/packages/nx/src/utils/nx-plugin.ts @@ -24,6 +24,9 @@ import { import { normalizePath } from './path'; import { join } from 'path'; import { getNxRequirePaths } from './installation-directory'; +import { readTsConfig } from './typescript'; + +import type * as ts from 'typescript'; export type ProjectTargetConfigurator = ( file: string @@ -253,17 +256,25 @@ export function registerPluginTSTranspiler() { if (!tsNodeAndPathsRegistered) { // nx-ignore-next-line const ts: typeof import('typescript') = require('typescript'); + const tsConfigName = existsSync('tsconfig.base.json') + ? 'tsconfig.base.json' + : existsSync('tsconfig.json') + ? 'tsconfig.json' + : null; + const tsConfig: Partial = tsConfigName + ? readTsConfig(tsConfigName) + : {}; registerTsConfigPaths(join(workspaceRoot, 'tsconfig.base.json')); registerTranspiler({ + experimentalDecorators: true, + emitDecoratorMetadata: true, + ...tsConfig.options, lib: ['es2021'], module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2021, inlineSourceMap: true, - esModuleInterop: true, skipLibCheck: true, - experimentalDecorators: true, - emitDecoratorMetadata: true, }); } tsNodeAndPathsRegistered = true; diff --git a/packages/nx/src/utils/register.ts b/packages/nx/src/utils/register.ts index 5739d3a9dd6c8..de87ed3f8ce3b 100644 --- a/packages/nx/src/utils/register.ts +++ b/packages/nx/src/utils/register.ts @@ -1,5 +1,5 @@ import { dirname, join } from 'path'; -import type { CompilerOptions } from 'typescript'; +import type { CompilerOptions, ModuleResolutionKind } from 'typescript'; import { logger, NX_PREFIX, stripIndent } from './logger'; const swcNodeInstalled = packageIsInstalled('@swc-node/register'); @@ -178,9 +178,9 @@ export function getTsNodeCompilerOptions(compilerOptions: CompilerOptions) { ts = require('typescript'); } - const flagMap: Partial< - Record, keyof typeof ts> - > = { + const flagMap: Partial<{ + [key in keyof RemoveIndex]: keyof typeof ts; + }> = { module: 'ModuleKind', target: 'ScriptTarget', moduleDetection: 'ModuleDetectionKind', @@ -189,7 +189,9 @@ export function getTsNodeCompilerOptions(compilerOptions: CompilerOptions) { importsNotUsedAsValues: 'ImportsNotUsedAsValues', }; - const result = { ...compilerOptions }; + const result: { [key in keyof CompilerOptions]: any } = { + ...compilerOptions, + }; for (const flag in flagMap) { if (compilerOptions[flag]) { @@ -197,6 +199,15 @@ export function getTsNodeCompilerOptions(compilerOptions: CompilerOptions) { } } + delete result.pathsBasePath; + delete result.configFilePath; + if (result.moduleResolution) { + result.moduleResolution = + result.moduleResolution === 'NodeJs' + ? 'node' + : result.moduleResolution.toLowerCase(); + } + return result; } diff --git a/packages/react-native/package.json b/packages/react-native/package.json index 915988c3088e3..8ca6b41ad6238 100644 --- a/packages/react-native/package.json +++ b/packages/react-native/package.json @@ -22,7 +22,7 @@ }, "license": "MIT", "author": "Victor Savkin", - "main": "index.js", + "main": "./index", "types": "index.d.ts", "dependencies": { "@nrwl/detox": "file:../detox", diff --git a/packages/react/package.json b/packages/react/package.json index ce4e0237ccffa..617bd64a410c5 100644 --- a/packages/react/package.json +++ b/packages/react/package.json @@ -16,7 +16,7 @@ "Cypress", "CLI" ], - "main": "./index.js", + "main": "./index", "typings": "./index.d.ts", "author": "Victor Savkin", "license": "MIT", diff --git a/packages/rollup/package.json b/packages/rollup/package.json index eea7331434da0..1271e2d369951 100644 --- a/packages/rollup/package.json +++ b/packages/rollup/package.json @@ -14,7 +14,7 @@ "Web", "CLI" ], - "main": "./index.js", + "main": "./index", "typings": "./index.d.ts", "author": "Victor Savkin", "license": "MIT", diff --git a/packages/storybook/package.json b/packages/storybook/package.json index d3d93510415a2..48a44cdb6f893 100644 --- a/packages/storybook/package.json +++ b/packages/storybook/package.json @@ -15,7 +15,7 @@ "Storybook", "Cypress" ], - "main": "./index.js", + "main": "./index", "typings": "./index.d.ts", "author": "Isaac Mann", "license": "MIT", diff --git a/packages/tao/package.json b/packages/tao/package.json index 195e17c5b22e8..f8a9bb31acd69 100644 --- a/packages/tao/package.json +++ b/packages/tao/package.json @@ -19,7 +19,7 @@ "Cypress", "CLI" ], - "main": "./index.js", + "main": "./index", "typings": "./index.d.ts", "author": "Victor Savkin", "license": "MIT", @@ -27,7 +27,7 @@ "url": "https://github.com/nrwl/nx/issues" }, "bin": { - "tao": "./index.js" + "tao": "./index" }, "homepage": "https://nx.dev", "dependencies": { diff --git a/packages/vite/package.json b/packages/vite/package.json index a0d1649f2a1d2..47819969d03a0 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -14,7 +14,7 @@ "Web", "CLI" ], - "main": "./index.js", + "main": "./index", "typings": "./index.d.ts", "author": "Victor Savkin", "license": "MIT", diff --git a/packages/web/package.json b/packages/web/package.json index 6bc4547ed6a9e..685eb14ff613d 100644 --- a/packages/web/package.json +++ b/packages/web/package.json @@ -15,7 +15,7 @@ "Cypress", "CLI" ], - "main": "./index.js", + "main": "./index", "typings": "./index.d.ts", "author": "Victor Savkin", "license": "MIT", diff --git a/packages/webpack/package.json b/packages/webpack/package.json index d5cc148e4970f..942a505f142ba 100644 --- a/packages/webpack/package.json +++ b/packages/webpack/package.json @@ -14,7 +14,7 @@ "Web", "CLI" ], - "main": "./index.js", + "main": "./index", "typings": "./index.d.ts", "author": "Victor Savkin", "license": "MIT", diff --git a/packages/workspace/package.json b/packages/workspace/package.json index a6944ba69caae..218c5e324a1c3 100644 --- a/packages/workspace/package.json +++ b/packages/workspace/package.json @@ -19,7 +19,7 @@ "Cypress", "CLI" ], - "main": "./index.js", + "main": "./index", "typings": "./index.d.ts", "author": "Victor Savkin", "license": "MIT",