Skip to content

Commit

Permalink
feat: add support for importing ts-node-maintained
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Aug 31, 2024
1 parent 01322b9 commit 3b97b34
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 36 deletions.
2 changes: 2 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { configPkg } from '@adonisjs/eslint-config'
export default configPkg()
47 changes: 22 additions & 25 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
Expand All @@ -98,9 +98,6 @@
"build",
"ts"
],
"eslintConfig": {
"extends": "@adonisjs/eslint-config/package"
},
"prettier": "@adonisjs/prettier-config",
"commitlint": {
"extends": [
Expand Down
4 changes: 2 additions & 2 deletions src/assets_dev_server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/dev_server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -75,7 +75,7 @@ export class DevServer {
/**
* Reference to the child process
*/
#httpServer?: ExecaChildProcess<string>
#httpServer?: ResultPromise

/**
* Reference to the watcher
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 4 additions & 1 deletion src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
]
Expand Down Expand Up @@ -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: {
Expand Down
6 changes: 3 additions & 3 deletions src/test_runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -87,7 +87,7 @@ export class TestRunner {
/**
* Reference to the test script child process
*/
#testScript?: ExecaChildProcess<string>
#testScript?: ResultPromise

/**
* Reference to the watcher
Expand Down Expand Up @@ -236,7 +236,7 @@ export class TestRunner {
this.#testScript
.then((result) => {
if (mode === 'nonblocking') {
this.#onClose?.(result.exitCode)
this.#onClose?.(result.exitCode!)
this.close()
}
})
Expand Down
6 changes: 6 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

/**
Expand Down
9 changes: 7 additions & 2 deletions tests/run.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 3b97b34

Please sign in to comment.