Skip to content

Commit

Permalink
fix(nx-plugin): allow some customization when running nx-plugins (#15438
Browse files Browse the repository at this point in the history
)
  • Loading branch information
AgentEnder authored Mar 21, 2023
1 parent 2cc949e commit 6834b65
Show file tree
Hide file tree
Showing 24 changed files with 68 additions and 32 deletions.
2 changes: 1 addition & 1 deletion packages/cypress/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"Cypress",
"CLI"
],
"main": "./index.js",
"main": "./index",
"typings": "./index.d.ts",
"author": "Victor Savkin",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/detox/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},
"license": "MIT",
"author": "Victor Savkin",
"main": "index.js",
"main": "./index",
"types": "index.d.ts",
"dependencies": {
"@nrwl/devkit": "file:../devkit",
Expand Down
2 changes: 1 addition & 1 deletion packages/devkit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"Cypress",
"CLI"
],
"main": "./index.js",
"main": "./index",
"typings": "./index.d.ts",
"author": "Victor Savkin",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/esbuild/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"Web",
"CLI"
],
"main": "./index.js",
"main": "./index",
"typings": "./index.d.ts",
"author": "Victor Savkin",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/expo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
},
"license": "MIT",
"author": "Victor Savkin",
"main": "index.js",
"main": "./index",
"types": "index.d.ts",
"dependencies": {
"@nrwl/detox": "file:../detox",
Expand Down
2 changes: 1 addition & 1 deletion packages/express/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"Cypress",
"CLI"
],
"main": "./index.js",
"main": "./index",
"typings": "./index.d.ts",
"author": "Victor Savkin",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/jest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"Unit Testing",
"CLI"
],
"main": "./index.js",
"main": "./index",
"typings": "./index.d.ts",
"author": "Victor Savkin",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/linter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"ESLint",
"CLI"
],
"main": "./index.js",
"main": "./index",
"typings": "./index.d.ts",
"author": "Victor Savkin",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/nest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"Cypress",
"CLI"
],
"main": "./index.js",
"main": "./index",
"typings": "./index.d.ts",
"author": "Victor Savkin",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"Cypress",
"CLI"
],
"main": "./index.js",
"main": "./index",
"typings": "./index.d.ts",
"author": "Victor Savkin",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"Cypress",
"CLI"
],
"main": "./index.js",
"main": "./index",
"typings": "./index.d.ts",
"author": "Victor Savkin",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/nx-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"Nx",
"CLI"
],
"main": "./index.js",
"main": "./index",
"types": "./index.d.ts",
"author": "Nrwl",
"license": "MIT",
Expand Down
18 changes: 16 additions & 2 deletions packages/nx/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
17 changes: 14 additions & 3 deletions packages/nx/src/utils/nx-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<ts.ParsedCommandLine> = 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;
Expand Down
21 changes: 16 additions & 5 deletions packages/nx/src/utils/register.ts
Original file line number Diff line number Diff line change
@@ -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');
Expand Down Expand Up @@ -178,9 +178,9 @@ export function getTsNodeCompilerOptions(compilerOptions: CompilerOptions) {
ts = require('typescript');
}

const flagMap: Partial<
Record<keyof RemoveIndex<CompilerOptions>, keyof typeof ts>
> = {
const flagMap: Partial<{
[key in keyof RemoveIndex<CompilerOptions>]: keyof typeof ts;
}> = {
module: 'ModuleKind',
target: 'ScriptTarget',
moduleDetection: 'ModuleDetectionKind',
Expand All @@ -189,14 +189,25 @@ 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]) {
result[flag] = ts[flagMap[flag]][compilerOptions[flag]];
}
}

delete result.pathsBasePath;
delete result.configFilePath;
if (result.moduleResolution) {
result.moduleResolution =
result.moduleResolution === 'NodeJs'
? 'node'
: result.moduleResolution.toLowerCase();
}

return result;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/react-native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},
"license": "MIT",
"author": "Victor Savkin",
"main": "index.js",
"main": "./index",
"types": "index.d.ts",
"dependencies": {
"@nrwl/detox": "file:../detox",
Expand Down
2 changes: 1 addition & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"Cypress",
"CLI"
],
"main": "./index.js",
"main": "./index",
"typings": "./index.d.ts",
"author": "Victor Savkin",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/rollup/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"Web",
"CLI"
],
"main": "./index.js",
"main": "./index",
"typings": "./index.d.ts",
"author": "Victor Savkin",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/storybook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"Storybook",
"Cypress"
],
"main": "./index.js",
"main": "./index",
"typings": "./index.d.ts",
"author": "Isaac Mann",
"license": "MIT",
Expand Down
4 changes: 2 additions & 2 deletions packages/tao/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
"Cypress",
"CLI"
],
"main": "./index.js",
"main": "./index",
"typings": "./index.d.ts",
"author": "Victor Savkin",
"license": "MIT",
"bugs": {
"url": "https://github.com/nrwl/nx/issues"
},
"bin": {
"tao": "./index.js"
"tao": "./index"
},
"homepage": "https://nx.dev",
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"Web",
"CLI"
],
"main": "./index.js",
"main": "./index",
"typings": "./index.d.ts",
"author": "Victor Savkin",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"Cypress",
"CLI"
],
"main": "./index.js",
"main": "./index",
"typings": "./index.d.ts",
"author": "Victor Savkin",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/webpack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"Web",
"CLI"
],
"main": "./index.js",
"main": "./index",
"typings": "./index.d.ts",
"author": "Victor Savkin",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/workspace/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"Cypress",
"CLI"
],
"main": "./index.js",
"main": "./index",
"typings": "./index.d.ts",
"author": "Victor Savkin",
"license": "MIT",
Expand Down

1 comment on commit 6834b65

@vercel
Copy link

@vercel vercel bot commented on 6834b65 Mar 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-dev-nrwl.vercel.app
nx-five.vercel.app
nx-dev-git-master-nrwl.vercel.app
nx.dev

Please sign in to comment.