Skip to content

Commit

Permalink
fix commonJs format (#1043)
Browse files Browse the repository at this point in the history
* fix commonJs format

* added changeset
  • Loading branch information
lukasoppermann authored Sep 3, 2024
1 parent 306907f commit faead48
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/bright-lions-push.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/primitives': patch
---

Update exports.default to module.exports in commonJs
2 changes: 1 addition & 1 deletion integration/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ describe('PrimerStyleDictionary', () => {

it('runs commonJs format', () => {
const output = fs.readFileSync(`${basePath}/build/js/common.js`, 'utf8')
const expectedOutput = `exports.default = {
const expectedOutput = `module.exports = {
PREFIX: {
base: {
color: {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
"prepack": "npm run build",
"release": "changeset publish",
"start:storybook": "npm run build && cd docs/storybook && npm run storybook",
"test": "vitest run --coverage",
"test": "npm run test:unit && npm run test:integration",
"test:unit": "vitest run --coverage",
"test:integration": "vitest run -r integration"
},
"prettier": "@github/prettier-config",
Expand Down
4 changes: 2 additions & 2 deletions src/formats/javascriptCommonJs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('Format: CommonJs', () => {
})

const expectedOutput = syncPrettier.format(
`exports.default = {
`module.exports = {
test: {
tokens: {
subgroup: {
Expand All @@ -29,7 +29,7 @@ describe('Format: CommonJs', () => {
it('Formats tokens without prefix', () => {
const input = getMockFormatterArguments()
const expectedOutput = syncPrettier.format(
`exports.default = {
`module.exports = {
tokens: {
subgroup: {
red: "transformedValue",
Expand Down
2 changes: 1 addition & 1 deletion src/formats/javascriptCommonJs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const javascriptCommonJs: StyleDictionary.Formatter = ({dictionary, file,
// add prefix if defined
const tokens = prefixTokens(dictionary.tokens, platform)
// add file header and convert output
const output = `${fileHeader({file})}exports.default = ${JSON.stringify(jsonToNestedValue(tokens), null, 2)}\n`
const output = `${fileHeader({file})}module.exports = ${JSON.stringify(jsonToNestedValue(tokens), null, 2)}\n`
// return prettified
return syncPrettier.format(output, {parser: 'typescript', printWidth: 500})
}

0 comments on commit faead48

Please sign in to comment.