-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
70 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,35 @@ | ||
import { readDefaultTsConfig } from '@swc-node/register/read-default-tsconfig'; | ||
import { register } from '@swc-node/register/register'; | ||
import { join } from 'path'; | ||
|
||
/** | ||
* Optionally, if swc-node and tsconfig-paths are available in the current workspace, apply the require | ||
* register hooks so that .ts files can be used for writing custom workspace projects. | ||
* | ||
* If ts-node and tsconfig-paths are not available, the user can still provide an index.js file in | ||
* the root of their project 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); | ||
|
||
/** | ||
* Load the ts config from the source project | ||
*/ | ||
const tsconfigPaths = require('tsconfig-paths'); | ||
const tsConfigResult = tsconfigPaths.loadConfig(path); | ||
/** | ||
* Register the custom workspace path mappings with node so that workspace libraries | ||
* can be imported and used within project | ||
*/ | ||
return tsconfigPaths.register({ | ||
baseUrl: tsConfigResult.absoluteBaseUrl, | ||
paths: tsConfigResult.paths, | ||
}); | ||
} catch (err) {} | ||
}; |