Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): move swc register to tao
- Loading branch information
Showing
6 changed files
with
66 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { readDefaultTsConfig } from '@swc-node/register/read-default-tsconfig'; | ||
import { register } from '@swc-node/register/register'; | ||
import { join } from 'path'; | ||
|
||
/** | ||
* Optionally, if ts-node and tsconfig-paths are available in the current workspace, apply the require | ||
* register hooks so that .ts files can be used for writing workspace lint rules. | ||
* | ||
* If ts-node and tsconfig-paths are not available, the user can still provide an index.js file in | ||
* tools/eslint-rules and write their rules in JavaScript and the fundamentals will still work (but | ||
* workspace path mapping will not, for example). | ||
*/ | ||
export const registerTsProject = ( | ||
path: string, | ||
configFilename = 'tsconfig.json' | ||
) => { | ||
try { | ||
const tsConfig = readDefaultTsConfig(join(path, configFilename)); | ||
register(tsConfig); | ||
|
||
/** | ||
* Register the custom workspace path mappings with node so that workspace libraries | ||
* can be imported and used within custom workspace lint rules. | ||
*/ | ||
const tsconfigPaths = require('tsconfig-paths'); | ||
return tsconfigPaths.register({ | ||
baseUrl: tsConfig.absoluteBaseUrl, | ||
paths: tsConfig.paths, | ||
}); | ||
} catch (err) {} | ||
}; |