Skip to content

Commit

Permalink
chore(npm): upgrade project for Node.js v20.x
Browse files Browse the repository at this point in the history
  • Loading branch information
jlenon7 committed Oct 3, 2023
1 parent 4fcf154 commit 9fab55a
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 108 deletions.
22 changes: 0 additions & 22 deletions node

This file was deleted.

31 changes: 22 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@athenna/common",
"version": "4.15.5",
"version": "4.16.0",
"description": "The Athenna common helpers to use in any Node.js ESM project.",
"license": "MIT",
"author": "João Lenon <[email protected]>",
Expand All @@ -19,8 +19,8 @@
"scripts": {
"build": "rimraf build && tsc --project bin/tsconfig.build.json",
"lint:fix": "eslint \"{bin,src,tests}/**/*.ts\" --fix",
"test": "npm run --silent lint:fix && sh node bin/test.ts",
"test:debug": "cross-env NODE_DEBUG=athenna:* sh node --inspect bin/test.ts",
"test": "npm run --silent lint:fix && node --import=@athenna/tsconfig bin/test.ts",
"test:debug": "cross-env NODE_DEBUG=athenna:* node --inspect bin/test.js",
"test:coverage": "c8 npm run --silent test"
},
"files": [
Expand Down Expand Up @@ -75,7 +75,8 @@
"youch-terminal": "^2.2.2"
},
"devDependencies": {
"@athenna/test": "^4.7.0",
"@athenna/test": "^4.9.1",
"@athenna/tsconfig": "^4.5.0",
"@types/bytes": "^3.1.1",
"@types/callsite": "^1.0.31",
"@types/debug": "^4.1.7",
Expand Down
20 changes: 0 additions & 20 deletions src/exceptions/NotFoundResolveException.ts

This file was deleted.

16 changes: 5 additions & 11 deletions src/helpers/Module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { Path, File, Folder } from '#src'
import { createRequire } from 'node:module'
import { fileURLToPath, pathToFileURL } from 'node:url'
import { extname, dirname, resolve, isAbsolute } from 'node:path'
import { NotFoundResolveException } from '#src/exceptions/NotFoundResolveException'

export class Module {
/**
Expand Down Expand Up @@ -188,14 +187,10 @@ export class Module {
* Resolve the module path by meta url and import it.
*/
public static async resolve(path: string, meta: string): Promise<any> {
if (!import.meta.resolve || process.env.RESOLVE_TESTING) {
throw new NotFoundResolveException()
}

const splited = path.split('?')
const queries = splited[1] || ''
const splitted = path.split('?')
const queries = splitted[1] || ''

path = splited[0]
path = splitted[0]

if (!path.startsWith('#') && extname(path)) {
path = resolve(path)
Expand All @@ -212,9 +207,8 @@ export class Module {
queries
)

return import.meta
.resolve(path, meta)
.then(resolved => Module.get(import(`${resolved}?${queries}`)))
// `await` is not needed for `import.meta.resolve` method, but TypeScript complains on it.
return Module.get(import(await import.meta.resolve(path, meta)))
}

/**
Expand Down
6 changes: 5 additions & 1 deletion tests/unit/ExecTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,11 @@ export default class ExecTest {

@Test()
public async shouldBeAbleToExecuteANodeScriptInTheVMAndGetTheStdout({ assert }: Context) {
const { stdout, stderr, exitCode } = await Exec.node(Path.fixtures('node-script.ts'))
const { stdout, stderr, exitCode } = await Exec.node(Path.fixtures('node-script.ts'), [
'node',
'--loader=ts-node/esm',
Path.fixtures('node-script.ts')
])

assert.equal(exitCode, 0)
assert.equal(stdout, 'hello')
Expand Down
10 changes: 0 additions & 10 deletions tests/unit/ModuleTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import { Module, Path } from '#src'
import { Test, type Context } from '@athenna/test'
import { NotFoundResolveException } from '#src/exceptions/NotFoundResolveException'

export default class ModuleTest {
@Test()
Expand Down Expand Up @@ -150,13 +149,4 @@ export default class ModuleTest {

assert.deepEqual(chalk, (await import('chalk')).default)
}

@Test()
public async shouldThrownAnExceptionWhenTheImportMetaResolveFunctionIsNotDefined({ assert }: Context) {
process.env.RESOLVE_TESTING = 'true'

await assert.rejects(() => Module.resolve('chalk', import.meta.url), NotFoundResolveException)

delete process.env.RESOLVE_TESTING
}
}
33 changes: 2 additions & 31 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,33 +1,4 @@
{
"ts-node": {
"esm": true,
"transpileOnly": true,
"ignoreDiagnostics": [5104]
},
"compilerOptions": {
"strict": false,
"rootDir": ".",
"baseUrl": ".",
"outDir": "build",
"module": "NodeNext",
"target": "ESNext",
"moduleResolution": "NodeNext",
"declaration": true,
"skipLibCheck": true,
"esModuleInterop": true,
"removeComments": false,
"resolveJsonModule": true,
"experimentalDecorators": true,
"useDefineForClassFields": false,
"verbatimModuleSyntax": true,
"forceConsistentCasingInFileNames": true,
"paths": {
"#bin/*": ["./bin/*.ts"],
"#src/*": ["./src/*.ts"],
"#tests/*": ["./tests/*.ts"],
"#src/types": ["./src/types/index.ts"]
}
},
"include": ["./**/*"],
"exclude": ["build", "node_modules"]
"extends": "@athenna/tsconfig/tsconfig.lib.json",
"compilerOptions": {}
}

0 comments on commit 9fab55a

Please sign in to comment.