From a4cb2cbd790cbe69313545f1c334cc2f1557a353 Mon Sep 17 00:00:00 2001 From: Mike Donnalley Date: Mon, 25 Sep 2023 14:50:01 -0700 Subject: [PATCH] feat: remove ts-node (#794) * feat: drop ts-node dependency * test: use --json for config unset --- package.json | 4 ++-- src/config/ts-node.ts | 16 ++++++++++++++-- test/integration/sf.e2e.ts | 2 +- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 4841001c1..71f798bed 100644 --- a/package.json +++ b/package.json @@ -28,8 +28,6 @@ "strip-ansi": "^6.0.1", "supports-color": "^8.1.1", "supports-hyperlinks": "^2.2.0", - "ts-node": "^10.9.1", - "tslib": "^2.5.0", "widest-line": "^3.1.0", "wordwrap": "^1.0.0", "wrap-ansi": "^7.0.0" @@ -72,6 +70,8 @@ "shx": "^0.3.4", "sinon": "^11.1.2", "tsd": "^0.29.0", + "ts-node": "^10.9.1", + "tslib": "^2.5.0", "typescript": "^5" }, "engines": { diff --git a/src/config/ts-node.ts b/src/config/ts-node.ts index 67093f80e..2addcf5a9 100644 --- a/src/config/ts-node.ts +++ b/src/config/ts-node.ts @@ -23,7 +23,11 @@ function loadTSConfig(root: string): TSConfig | undefined { } catch { try { typescript = require(join(root, 'node_modules', 'typescript')) - } catch {} + } catch { + debug(`Could not find typescript dependency. Skipping ts-node registration for ${root}.`) + memoizedWarn('Could not find typescript. Please ensure that typescript is a devDependency. Falling back to compiled source.') + return + } } if (existsSync(tsconfigPath) && typescript) { @@ -49,7 +53,15 @@ function registerTSNode(root: string): TSConfig | undefined { debug('registering ts-node at', root) const tsNodePath = require.resolve('ts-node', {paths: [root, __dirname]}) debug('ts-node path:', tsNodePath) - const tsNode: typeof TSNode = require(tsNodePath) + let tsNode: typeof TSNode + + try { + tsNode = require(tsNodePath) + } catch { + debug(`Could not find ts-node at ${tsNodePath}. Skipping ts-node registration for ${root}.`) + memoizedWarn(`Could not find ts-node at ${tsNodePath}. Please ensure that ts-node is a devDependency. Falling back to compiled source.`) + return + } const typeRoots = [ join(root, 'node_modules', '@types'), diff --git a/test/integration/sf.e2e.ts b/test/integration/sf.e2e.ts index 7e423d206..bd2786122 100644 --- a/test/integration/sf.e2e.ts +++ b/test/integration/sf.e2e.ts @@ -115,7 +115,7 @@ describe('Salesforce CLI (sf)', () => { expect(results.failures).to.be.empty - const unset = await executor.executeCommand('config unset disable-telemetry org-api-version --global') + const unset = await executor.executeCommand('config unset disable-telemetry org-api-version --global --json') const unsetParsed = parseJson(unset.stdout!) expect(unsetParsed.status).to.equal(0) })