@oclif/core
Advanced tools
Comparing version 4.0.0-beta.14 to 4.0.0-beta.15
@@ -81,2 +81,20 @@ "use strict"; | ||
} | ||
async function registerTsx(root, moduleType) { | ||
if (REGISTERED.has(root)) | ||
return; | ||
try { | ||
const apiPath = moduleType === 'module' ? 'tsx/esm/api' : 'tsx/cjs/api'; | ||
const tsxPath = require.resolve(apiPath, { paths: [root] }); | ||
if (!tsxPath) | ||
return; | ||
debug('registering tsx at', root); | ||
debug('tsx path:', tsxPath); | ||
const { register } = await import(tsxPath); | ||
register(); | ||
REGISTERED.add(root); | ||
} | ||
catch { | ||
debug(`Could not find tsx. Skipping tsx registration for ${root}.`); | ||
} | ||
} | ||
async function registerTSNode(root, tsconfig) { | ||
@@ -139,3 +157,3 @@ if (REGISTERED.has(root)) | ||
* Skip ts-node registration for ESM plugins in production. | ||
* The node ecosystem is not mature enough to support auto-transpiling ESM modules at this time. | ||
* The node/ts-node ecosystem is not mature enough to support auto-transpiling ESM modules at this time. | ||
* See the following: | ||
@@ -147,7 +165,9 @@ * - https://github.com/TypeStrong/ts-node/issues/1791#issuecomment-1149754228 | ||
* | ||
* We still register ts-node for ESM plugins when NODE_ENV is "test" or "development" and root plugin is also ESM | ||
* We still register tsx/ts-node for ESM plugins when NODE_ENV is "test" or "development" and root plugin is also ESM | ||
* since that allows plugins to be auto-transpiled when developing locally using `bin/dev.js`. | ||
*/ | ||
function cannotTranspileEsm(rootPlugin, plugin, isProduction) { | ||
return (isProduction || rootPlugin?.moduleType === 'commonjs') && plugin?.moduleType === 'module'; | ||
return ((isProduction || rootPlugin?.moduleType === 'commonjs') && | ||
plugin?.moduleType === 'module' && | ||
!plugin?.pjson.devDependencies?.tsx); | ||
} | ||
@@ -172,3 +192,3 @@ /** | ||
*/ | ||
async function determinePath(root, orig) { | ||
async function determinePath(root, orig, plugin) { | ||
const tsconfig = await loadTSConfig(root); | ||
@@ -178,6 +198,9 @@ if (!tsconfig) | ||
debug(`Determining path for ${orig}`); | ||
if (RUN_TIME === 'tsx' || RUN_TIME === 'bun') { | ||
if (RUN_TIME === 'bun') { | ||
debug(`Skipping ts-node registration for ${root} because the runtime is: ${RUN_TIME}`); | ||
} | ||
else { | ||
// attempt to register tsx first. If it fails to register, we will fall back to ts-node | ||
await registerTsx(root, plugin?.moduleType); | ||
// if tsx registration succeeded, then this will exit early since the path will be in REGISTERED already | ||
await registerTSNode(root, tsconfig); | ||
@@ -259,3 +282,3 @@ } | ||
try { | ||
return await determinePath(root, orig); | ||
return await determinePath(root, orig, plugin); | ||
} | ||
@@ -262,0 +285,0 @@ catch (error) { |
{ | ||
"name": "@oclif/core", | ||
"description": "base library for oclif CLIs", | ||
"version": "4.0.0-beta.14", | ||
"version": "4.0.0-beta.15", | ||
"author": "Salesforce", | ||
@@ -6,0 +6,0 @@ "bugs": "https://github.com/oclif/core/issues", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
398264
10034
35