@oclif/core 4.0.0-beta.14 → 4.0.0-beta.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -78,6 +78,24 @@ async function loadTSConfig(root) {
78
78
  (0, warn_1.memoizedWarn)(`Could not parse tsconfig.json for ${root}. Falling back to compiled source.`);
79
79
  }
80
80
  }
81
+ async function registerTsx(root, moduleType) {
82
+ if (REGISTERED.has(root))
83
+ return;
84
+ try {
85
+ const apiPath = moduleType === 'module' ? 'tsx/esm/api' : 'tsx/cjs/api';
86
+ const tsxPath = require.resolve(apiPath, { paths: [root] });
87
+ if (!tsxPath)
88
+ return;
89
+ debug('registering tsx at', root);
90
+ debug('tsx path:', tsxPath);
91
+ const { register } = await import(tsxPath);
92
+ register();
93
+ REGISTERED.add(root);
94
+ }
95
+ catch {
96
+ debug(`Could not find tsx. Skipping tsx registration for ${root}.`);
97
+ }
98
+ }
81
99
  async function registerTSNode(root, tsconfig) {
82
100
  if (REGISTERED.has(root))
83
101
  return;
@@ -135,18 +153,20 @@ async function registerTSNode(root, tsconfig) {
135
153
  }
136
154
  /**
137
155
  * Skip ts-node registration for ESM plugins in production.
138
- * The node ecosystem is not mature enough to support auto-transpiling ESM modules at this time.
156
+ * The node/ts-node ecosystem is not mature enough to support auto-transpiling ESM modules at this time.
139
157
  * See the following:
140
158
  * - https://github.com/TypeStrong/ts-node/issues/1791#issuecomment-1149754228
141
159
  * - https://github.com/nodejs/node/issues/49432
142
160
  * - https://github.com/nodejs/node/pull/49407
143
161
  * - https://github.com/nodejs/node/issues/34049
144
162
  *
145
- * We still register ts-node for ESM plugins when NODE_ENV is "test" or "development" and root plugin is also ESM
163
+ * We still register tsx/ts-node for ESM plugins when NODE_ENV is "test" or "development" and root plugin is also ESM
146
164
  * since that allows plugins to be auto-transpiled when developing locally using `bin/dev.js`.
147
165
  */
148
166
  function cannotTranspileEsm(rootPlugin, plugin, isProduction) {
149
- return (isProduction || rootPlugin?.moduleType === 'commonjs') && plugin?.moduleType === 'module';
167
+ return ((isProduction || rootPlugin?.moduleType === 'commonjs') &&
168
+ plugin?.moduleType === 'module' &&
169
+ !plugin?.pjson.devDependencies?.tsx);
150
170
  }
151
171
  /**
152
172
  * If the dev script is run with ts-node for an ESM plugin, skip ts-node registration
@@ -166,15 +186,18 @@ function cannotUseTsNode(root, plugin, isProduction) {
166
186
  /**
167
187
  * Determine the path to the source file from the compiled ./lib files
168
188
  */
169
- async function determinePath(root, orig) {
189
+ async function determinePath(root, orig, plugin) {
170
190
  const tsconfig = await loadTSConfig(root);
171
191
  if (!tsconfig)
172
192
  return orig;
173
193
  debug(`Determining path for ${orig}`);
174
- if (RUN_TIME === 'tsx' || RUN_TIME === 'bun') {
194
+ if (RUN_TIME === 'bun') {
175
195
  debug(`Skipping ts-node registration for ${root} because the runtime is: ${RUN_TIME}`);
176
196
  }
177
197
  else {
198
+ // attempt to register tsx first. If it fails to register, we will fall back to ts-node
199
+ await registerTsx(root, plugin?.moduleType);
200
+ // if tsx registration succeeded, then this will exit early since the path will be in REGISTERED already
178
201
  await registerTSNode(root, tsconfig);
179
202
  }
180
203
  const { baseUrl, outDir, rootDir, rootDirs } = tsconfig.compilerOptions;
@@ -251,7 +274,7 @@ async function tsPath(root, orig, plugin) {
251
274
  return orig;
252
275
  }
253
276
  try {
254
- return await determinePath(root, orig);
277
+ return await determinePath(root, orig, plugin);
255
278
  }
256
279
  catch (error) {
257
280
  debug(error);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@oclif/core",
3
3
  "description": "base library for oclif CLIs",
4
- "version": "4.0.0-beta.14",
4
+ "version": "4.0.0-beta.15",
5
5
  "author": "Salesforce",
6
6
  "bugs": "https://github.com/oclif/core/issues",
7
7
  "dependencies": {