From 3b97b34db43de6d76184f35fb80e48f628a624fb Mon Sep 17 00:00:00 2001
From: Harminder Virk <virk.officials@gmail.com>
Date: Sat, 31 Aug 2024 23:59:28 +0530
Subject: [PATCH] feat: add support for importing ts-node-maintained

---
 eslint.config.js         |  2 ++
 package.json             | 47 +++++++++++++++++++---------------------
 src/assets_dev_server.ts |  4 ++--
 src/dev_server.ts        |  6 ++---
 src/helpers.ts           |  5 ++++-
 src/test_runner.ts       |  6 ++---
 src/types.ts             |  6 +++++
 tests/run.spec.ts        |  9 ++++++--
 8 files changed, 49 insertions(+), 36 deletions(-)
 create mode 100644 eslint.config.js

diff --git a/eslint.config.js b/eslint.config.js
new file mode 100644
index 0000000..e4cad4b
--- /dev/null
+++ b/eslint.config.js
@@ -0,0 +1,2 @@
+import { configPkg } from '@adonisjs/eslint-config'
+export default configPkg()
diff --git a/package.json b/package.json
index 896cbef..9be7266 100644
--- a/package.json
+++ b/package.json
@@ -20,7 +20,7 @@
   "scripts": {
     "pretest": "npm run lint",
     "test": "c8 npm run quick:test",
-    "lint": "eslint . --ext=.ts",
+    "lint": "eslint .",
     "clean": "del-cli build",
     "typecheck": "tsc --noEmit",
     "precompile": "npm run lint && npm run clean",
@@ -31,54 +31,54 @@
     "sync-labels": "github-label-sync --labels .github/labels.json adonisjs/assembler",
     "format": "prettier --write .",
     "prepublishOnly": "npm run build",
-    "quick:test": "cross-env NODE_DEBUG=adonisjs:assembler node --enable-source-maps --loader=ts-node/esm bin/test.ts"
+    "quick:test": "cross-env NODE_DEBUG=adonisjs:assembler node --enable-source-maps --import=ts-node-maintained/register/esm bin/test.ts"
   },
   "devDependencies": {
     "@adonisjs/application": "^8.3.1",
-    "@adonisjs/eslint-config": "^1.3.0",
-    "@adonisjs/prettier-config": "^1.3.0",
-    "@adonisjs/tsconfig": "^1.3.0",
-    "@commitlint/cli": "^19.3.0",
-    "@commitlint/config-conventional": "^19.2.2",
+    "@adonisjs/eslint-config": "^2.0.0-beta.6",
+    "@adonisjs/prettier-config": "^1.4.0",
+    "@adonisjs/tsconfig": "^1.4.0",
+    "@commitlint/cli": "^19.4.1",
+    "@commitlint/config-conventional": "^19.4.1",
     "@japa/assert": "^3.0.0",
     "@japa/file-system": "^2.3.0",
     "@japa/runner": "^3.1.4",
     "@japa/snapshot": "^2.0.5",
-    "@swc/core": "^1.5.24",
-    "@types/node": "^20.13.0",
-    "@types/picomatch": "^2.3.3",
+    "@swc/core": "^1.7.22",
+    "@types/node": "^22.5.1",
+    "@types/picomatch": "^3.0.1",
     "@types/pretty-hrtime": "^1.0.3",
-    "c8": "^9.1.0",
+    "c8": "^10.1.2",
     "cross-env": "^7.0.3",
     "del-cli": "^5.1.0",
-    "eslint": "^8.57.0",
+    "eslint": "^9.9.1",
+    "execa": "^9.3.1",
     "github-label-sync": "^2.3.1",
     "hot-hook": "^0.2.6",
-    "husky": "^9.0.11",
+    "husky": "^9.1.5",
     "p-event": "^6.0.1",
-    "prettier": "^3.3.0",
-    "release-it": "^17.3.0",
-    "ts-node": "^10.9.2",
-    "tsup": "^8.0.2",
-    "typescript": "^5.4.5"
+    "prettier": "^3.3.3",
+    "release-it": "^17.6.0",
+    "ts-node-maintained": "^10.9.4",
+    "tsup": "^8.2.4",
+    "typescript": "^5.5.4"
   },
   "dependencies": {
     "@adonisjs/env": "^6.1.0",
-    "@antfu/install-pkg": "^0.3.3",
+    "@antfu/install-pkg": "^0.4.1",
     "@poppinss/chokidar-ts": "^4.1.4",
     "@poppinss/cliui": "^6.4.1",
     "@poppinss/hooks": "^7.2.3",
     "@poppinss/utils": "^6.7.3",
-    "cpy": "^11.0.1",
+    "cpy": "^11.1.0",
     "dedent": "^1.5.3",
-    "execa": "^8.0.1",
     "fast-glob": "^3.3.2",
     "get-port": "^7.1.0",
     "junk": "^4.0.1",
     "picomatch": "^4.0.2",
     "pretty-hrtime": "^1.0.3",
     "slash": "^5.1.0",
-    "ts-morph": "^22.0.0"
+    "ts-morph": "^23.0.0"
   },
   "peerDependencies": {
     "typescript": "^4.0.0 || ^5.0.0"
@@ -98,9 +98,6 @@
     "build",
     "ts"
   ],
-  "eslintConfig": {
-    "extends": "@adonisjs/eslint-config/package"
-  },
   "prettier": "@adonisjs/prettier-config",
   "commitlint": {
     "extends": [
diff --git a/src/assets_dev_server.ts b/src/assets_dev_server.ts
index 5721c8d..342eaf5 100644
--- a/src/assets_dev_server.ts
+++ b/src/assets_dev_server.ts
@@ -7,7 +7,7 @@
  * file that was distributed with this source code.
  */
 
-import type { ExecaChildProcess } from 'execa'
+import type { ResultPromise } from 'execa'
 import { type Logger, cliui } from '@poppinss/cliui'
 
 import { run } from './helpers.js'
@@ -33,7 +33,7 @@ export class AssetsDevServer {
   #cwd: URL
   #logger = ui.logger
   #options?: AssetsBundlerOptions
-  #devServer?: ExecaChildProcess<string>
+  #devServer?: ResultPromise
 
   /**
    * Getting reference to colors library from logger
diff --git a/src/dev_server.ts b/src/dev_server.ts
index fa37e49..39034fa 100644
--- a/src/dev_server.ts
+++ b/src/dev_server.ts
@@ -12,7 +12,7 @@ import { relative } from 'node:path'
 import type tsStatic from 'typescript'
 import prettyHrtime from 'pretty-hrtime'
 import { fileURLToPath } from 'node:url'
-import { type ExecaChildProcess } from 'execa'
+import { type ResultPromise } from 'execa'
 import { cliui, type Logger } from '@poppinss/cliui'
 import type { Watcher } from '@poppinss/chokidar-ts'
 
@@ -75,7 +75,7 @@ export class DevServer {
   /**
    * Reference to the child process
    */
-  #httpServer?: ExecaChildProcess<string>
+  #httpServer?: ResultPromise
 
   /**
    * Reference to the watcher
@@ -223,7 +223,7 @@ export class DevServer {
     this.#httpServer
       .then((result) => {
         if (mode === 'nonblocking') {
-          this.#onClose?.(result.exitCode)
+          this.#onClose?.(result.exitCode!)
           this.#watcher?.close()
           this.#assetsServer?.stop()
         } else {
diff --git a/src/helpers.ts b/src/helpers.ts
index ef8d31c..9e5c310 100644
--- a/src/helpers.ts
+++ b/src/helpers.ts
@@ -28,7 +28,9 @@ import debug from './debug.js'
  */
 const DEFAULT_NODE_ARGS = [
   // Use ts-node/esm loader. The project must install it
-  '--loader=ts-node/esm',
+  process.versions.tsNodeMaintained
+    ? '--import=ts-node-maintained/register/esm'
+    : '--loader=ts-node/esm',
   // Enable source maps, since TSNode source maps are broken
   '--enable-source-maps',
 ]
@@ -77,6 +79,7 @@ export function runNode(cwd: string | URL, options: RunOptions) {
     windowsHide: false,
     localDir: cwd,
     cwd,
+    reject: options.reject ?? false,
     buffer: false,
     stdio: options.stdio || 'inherit',
     env: {
diff --git a/src/test_runner.ts b/src/test_runner.ts
index 2a68536..0842597 100644
--- a/src/test_runner.ts
+++ b/src/test_runner.ts
@@ -9,7 +9,7 @@
 
 import picomatch from 'picomatch'
 import type tsStatic from 'typescript'
-import { type ExecaChildProcess } from 'execa'
+import { type ResultPromise } from 'execa'
 import { cliui, type Logger } from '@poppinss/cliui'
 import type { Watcher } from '@poppinss/chokidar-ts'
 
@@ -87,7 +87,7 @@ export class TestRunner {
   /**
    * Reference to the test script child process
    */
-  #testScript?: ExecaChildProcess<string>
+  #testScript?: ResultPromise
 
   /**
    * Reference to the watcher
@@ -236,7 +236,7 @@ export class TestRunner {
     this.#testScript
       .then((result) => {
         if (mode === 'nonblocking') {
-          this.#onClose?.(result.exitCode)
+          this.#onClose?.(result.exitCode!)
           this.close()
         }
       })
diff --git a/src/types.ts b/src/types.ts
index 3a807b3..b4b4664 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -37,6 +37,12 @@ export type RunOptions = {
    * Environment variables to pass to the child process
    */
   env?: NodeJS.ProcessEnv
+
+  /**
+   * Whether or not to reject the promise. Defaults
+   * false
+   */
+  reject?: boolean
 }
 
 /**
diff --git a/tests/run.spec.ts b/tests/run.spec.ts
index e396310..c28d50a 100644
--- a/tests/run.spec.ts
+++ b/tests/run.spec.ts
@@ -69,7 +69,7 @@ test.group('Child process', () => {
     assert.equal(childProcess.exitCode, 0)
     assert.deepEqual(payload, {
       args: [
-        '--loader=ts-node/esm',
+        '--import=ts-node-maintained/register/esm',
         '--enable-source-maps',
         process.allowedNodeEnvironmentFlags.has('--disable-warning')
           ? '--disable-warning=ExperimentalWarning'
@@ -116,7 +116,12 @@ test.group('Child process', () => {
     `
     )
 
-    const childProcess = runNode(fs.basePath, { script: 'foo.ts', scriptArgs: [], nodeArgs: [] })
+    const childProcess = runNode(fs.basePath, {
+      script: 'foo.ts',
+      scriptArgs: [],
+      nodeArgs: [],
+      reject: true,
+    })
     try {
       await childProcess
     } catch {