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

Make config/paths.json exportable for ESM import #2857

Merged
merged 1 commit into from
Sep 16, 2022

Conversation

colinrotherham
Copy link
Contributor

@colinrotherham colinrotherham commented Sep 16, 2022

This PR renames ./config/paths.json./config/paths.js as it's easier to import in ESM

Before

Parses import.meta.url due to no __dirname in ESM

import { dirname, resolve } from 'path'
import { fileURLToPath } from 'url'
import { readFile } from 'fs/promises'

const basePath = dirname(fileURLToPath(import.meta.url))
const configPaths = JSON.parse(await readFile(resolve(basePath, '../../paths.json')))

After (via import)

Plain CommonJS import

import configPaths from '../../paths.js'

Future (via import assertion from JSON)

Plain JSON import but needs --experimental-json-modules flag in Node.js 16

import configPaths from '../../paths.json' assert { type: 'json' }

Avoids the `--experimental-json-modules` flag in Node.js 16
Copy link
Member

@36degrees 36degrees left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

@colinrotherham colinrotherham merged commit bdd019b into main Sep 16, 2022
Design System Sprint Board automation moved this from Needs review 🔍 to Done 🏁 Sep 16, 2022
@colinrotherham colinrotherham deleted the remove-deprecated-request branch September 16, 2022 08:16
@colinrotherham colinrotherham removed their assignment Nov 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

None yet

3 participants