Skip to content

refactor: modernize node imports #1198

Closed
@jkowalleck

Description

@jkowalleck

currently all node-modules are imported like import { dirname, join } from 'path'

for maintainability, this could be optimized:

  • group built-in modules and 3rd part modules
  • prefix built-in modules

example result

from

import * as CDX from '@cyclonedx/cyclonedx-library'
import { readdirSync, readFileSync } from 'fs'
import * as normalizePackageJson from 'normalize-package-data'
import { dirname, join } from 'path'

to

import { readdirSync, readFileSync } from 'node:fs'
import { dirname, join } from 'node:path'

import * as CDX from '@cyclonedx/cyclonedx-library'
import * as normalizePackageJson from 'normalize-package-data'

enforcement

maybe there is a eslint rule for this? import-js/eslint-plugin-import#2717

risks and problems:

the following section became obsolete due to #1209

the lib supports node versions that do not know the node-colon(node:) prefix.
this can be "fixed" on compile time. (untested):

{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "node:*": ["*"]
    }
  }
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions