|
9 | 9 | * will parse them and register them so that modules can be resolved correctly.
|
10 | 10 | */
|
11 | 11 |
|
12 |
| -const { existsSync, readFileSync } = require('fs') |
13 |
| -const { loadConfig, register } = require('tsconfig-paths') |
14 |
| -const { parse } = require('comment-json') |
| 12 | +import('fs').then(({ existsSync, readFileSync }) => { |
| 13 | + import('tsconfig-paths').then(({ loadConfig, register }) => { |
| 14 | + import('comment-json').then(({ parse }) => { |
| 15 | + import('path').then(({ dirname }) => { |
| 16 | + import('url').then(({ fileURLToPath }) => { |
| 17 | + if ( |
| 18 | + process.env.TARGET_ACTION_PATH && |
| 19 | + process.env.TARGET_ACTION_PATH !== '' |
| 20 | + ) { |
| 21 | + // Check if the action has a `tsconfig.json` file. |
| 22 | + if (existsSync(`${process.env.TARGET_ACTION_PATH}/tsconfig.json`)) { |
| 23 | + const __dirname = dirname(fileURLToPath(import.meta.url)) |
15 | 24 |
|
16 |
| -if (process.env.TARGET_ACTION_PATH && process.env.TARGET_ACTION_PATH !== '') { |
17 |
| - // Check if the action has a `tsconfig.json` file. |
18 |
| - if (existsSync(`${process.env.TARGET_ACTION_PATH}/tsconfig.json`)) { |
19 |
| - // Load the `tsconfig.json` from the action directory. |
20 |
| - const actionTsConfig = parse( |
21 |
| - readFileSync(`${process.env.TARGET_ACTION_PATH}/tsconfig.json`, 'utf-8') |
22 |
| - ) |
| 25 | + // Load the `tsconfig.json` from the action directory. |
| 26 | + const actionTsConfig = parse( |
| 27 | + readFileSync( |
| 28 | + `${process.env.TARGET_ACTION_PATH}/tsconfig.json`, |
| 29 | + 'utf-8' |
| 30 | + ) |
| 31 | + ) |
23 | 32 |
|
24 |
| - // Load the current `tsconfig.json` from the root of this directory. |
25 |
| - loadConfig(__dirname) |
| 33 | + // Load the current `tsconfig.json` from the root of this directory. |
| 34 | + loadConfig(__dirname) |
26 | 35 |
|
27 |
| - // Get the paths from the action's `tsconfig.json`, if any. |
28 |
| - const paths = actionTsConfig.compilerOptions?.paths ?? {} |
| 36 | + // Get the paths from the action's `tsconfig.json`, if any. |
| 37 | + // @ts-expect-error comment-json type mismatch |
| 38 | + const paths = actionTsConfig?.compilerOptions?.paths ?? {} |
29 | 39 |
|
30 |
| - // Add any path mappings from the imported action. Replace the base URL with |
31 |
| - // the target action path. |
32 |
| - // @todo Should this take into account the previous `baseUrl` value? |
33 |
| - register({ |
34 |
| - baseUrl: process.env.TARGET_ACTION_PATH, |
35 |
| - paths, |
36 |
| - addMatchAll: true |
| 40 | + // Add any path mappings from the imported action. Replace the base URL with |
| 41 | + // the target action path. |
| 42 | + // @todo Should this take into account the previous `baseUrl` value? |
| 43 | + register({ |
| 44 | + baseUrl: process.env.TARGET_ACTION_PATH, |
| 45 | + paths, |
| 46 | + addMatchAll: true |
| 47 | + }) |
| 48 | + } |
| 49 | + } |
| 50 | + }) |
| 51 | + }) |
37 | 52 | })
|
38 |
| - } |
39 |
| -} |
| 53 | + }) |
| 54 | +}) |
0 commit comments