Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: modernize node imports #1251

Open
jkowalleck opened this issue Dec 28, 2024 · 0 comments
Open

refactor: modernize node imports #1251

jkowalleck opened this issue Dec 28, 2024 · 0 comments

Comments

@jkowalleck
Copy link
Member

jkowalleck commented Dec 28, 2024

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 tool supports node versions that do not know the node-colon(node:) prefix.
this can be "fixed" on compile time. (untested):

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant