├── schema.json ├── executor.json ├── package.json ├── README.md ├── index.js └── LICENSE /schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/schema", 3 | "type": "object", 4 | "cli": "nx", 5 | "properties": { 6 | "tsConfig": { 7 | "type": "array", 8 | "description": "TypeScript config(s)" 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /executor.json: -------------------------------------------------------------------------------- 1 | { 2 | "executors": { 3 | "tsc": { 4 | "implementation": "./index.js", 5 | "schema": "./schema.json", 6 | "description": "Runs `tsc -p` on the provided TypeScript configurations (tsconfig.json)" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@webpro/nx-tsc", 3 | "version": "0.0.2", 4 | "description": "Nx executor to type-check project source files using tsc --noEmit", 5 | "main": "./index.js", 6 | "executors": "./executor.json", 7 | "keywords": [ 8 | "nx", 9 | "executor", 10 | "tsc" 11 | ], 12 | "author": { 13 | "email": "lars@webpro.nl", 14 | "name": "Lars Kappert" 15 | }, 16 | "license": "MIT", 17 | "publishConfig": { 18 | "access": "public" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # nx-tsc 2 | 3 | Nx executor to type-check project source files using tsc --noEmit 4 | 5 | ## Installation 6 | 7 | ```bash 8 | npm install -D @webpro/nx-tsc 9 | ``` 10 | 11 | ## Configuration 12 | 13 | Add a `tsc` target to each `project.json`: 14 | 15 | ```json 16 | { 17 | "$schema": "../../node_modules/nx/schemas/project-schema.json", 18 | "sourceRoot": "libs/my-lib/src", 19 | "targets": { 20 | "tsc": { 21 | "executor": "@webpro/nx-tsc:tsc", 22 | "options": { 23 | "tsConfig": ["tsconfig.json"] 24 | } 25 | } 26 | } 27 | } 28 | ``` 29 | 30 | ## Run type-checker 31 | 32 | This enables the `tsc` target in the Nx workspace: 33 | 34 | ```bash 35 | nx tsc my-lib 36 | ``` 37 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const { spawn } = require('child_process'); 2 | const { resolve, join } = require('path'); 3 | 4 | const executable = resolve('node_modules', '.bin', 'tsc'); 5 | 6 | async function tscExecutor(options, context) { 7 | const tsConfigs = Array.isArray(options.tsConfig) ? options.tsConfig : [options.tsConfig]; 8 | const libRoot = (context.workspace ?? context.projectsConfigurations).projects[context.projectName].root; 9 | 10 | const executionCodes = await Promise.all( 11 | tsConfigs.map( 12 | tsConfig => 13 | new Promise(resolve => { 14 | const child = spawn(executable, ['--noEmit', '-p', join(libRoot, tsConfig)], { 15 | shell: process.platform == 'win32', 16 | stdio: 'inherit', 17 | }); 18 | child.on('data', console.log); 19 | child.on('error', console.error); 20 | child.on('close', resolve); 21 | }) 22 | ) 23 | ); 24 | 25 | const success = executionCodes.every(executionCode => executionCode === 0); 26 | 27 | return { success }; 28 | } 29 | 30 | exports.default = tscExecutor; 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Lars Kappert 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | --------------------------------------------------------------------------------