Skip to content

Commit

Permalink
Merge pull request #50 from lukasoppermann/v4.15
Browse files Browse the repository at this point in the history
V4.15
  • Loading branch information
lukasoppermann committed Mar 11, 2024
2 parents 628ff18 + 01a9759 commit e904ceb
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 36 deletions.
2 changes: 1 addition & 1 deletion __tests__/build.test.md → __tests__/build.test.js
@@ -1,5 +1,5 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
const StyleDictionary = require("../dist");
import StyleDictionary from "../dist-cjs/index.js";

describe('index.js', () => {
it("all formats are attached", () => {
Expand Down
24 changes: 12 additions & 12 deletions __tests__/format/javascript-commonJs.test.ts
Expand Up @@ -23,7 +23,7 @@ describe('Format: CommonJs', () => {
}
}

it('Formats tokens adding prefix', () => {
it('Formats tokens adding prefix', async () => {
const output = `exports.default = {
test: {
colors: {
Expand All @@ -32,24 +32,24 @@ describe('Format: CommonJs', () => {
},
};
`
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore: fake values to test formatter
expect(javascriptCommonJs({dictionary, file, options: undefined, platform})).toStrictEqual(output)
// @ts-expect-error: fake values to test formatter
const result = await javascriptCommonJs({ dictionary, file, options: undefined, platform })
expect(result).toStrictEqual(output)
})

it('Formats tokens without prefix', () => {
it('Formats tokens without prefix', async () => {
const output = `exports.default = {
colors: {
red: "#FF0000",
},
};
`
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore: fake values to test formatter
expect(javascriptCommonJs({dictionary, file, options: undefined, undefined})).toStrictEqual(output)
// @ts-expect-error: fake values to test formatter
const result = await javascriptCommonJs({ dictionary, file, options: undefined, undefined })
expect(result).toStrictEqual(output)
})

it('Formats tokens accepting a custom prettier configuration', () => {
it('Formats tokens accepting a custom prettier configuration', async () => {
const output = `exports.default = {
colors: {
red: '#FF0000',
Expand All @@ -60,9 +60,9 @@ describe('Format: CommonJs', () => {
singleQuote: true
}

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore: fake values to test formatter
expect(javascriptCommonJs({dictionary, file, options: {prettier}, undefined})).toStrictEqual(output)
// @ts-expect-error: fake values to test formatter
const result = await javascriptCommonJs({ dictionary, file, options: { prettier }, undefined })
expect(result).toStrictEqual(output)
})

})
25 changes: 12 additions & 13 deletions __tests__/format/javascript-esm.test.ts
Expand Up @@ -23,7 +23,7 @@ describe('Format: ESM', () => {
}
}

it('Formats tokens adding prefix', () => {
it('Formats tokens adding prefix', async () => {
const output = `export default {
test: {
colors: {
Expand All @@ -32,24 +32,24 @@ describe('Format: ESM', () => {
},
};
`
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore: fake values to test formatter
expect(javascriptEsm({dictionary, file, options: undefined, platform})).toStrictEqual(output)
// @ts-expect-error: fake values to test formatter
const result = await javascriptEsm({ dictionary, file, options: undefined, platform })
expect(result).toStrictEqual(output)
})

it('Formats tokens without prefix', () => {
it('Formats tokens without prefix', async () => {
const output = `export default {
colors: {
red: "#FF0000",
},
};
`
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore: fake values to test formatter
expect(javascriptEsm({dictionary, file, options: undefined, undefined})).toStrictEqual(output)
// @ts-expect-error: fake values to test formatter
const result = await javascriptEsm({ dictionary, file, options: undefined, undefined })
expect(result).toStrictEqual(output)
})

it('Formats tokens accepting a custom prettier configuration', () => {
it('Formats tokens accepting a custom prettier configuration', async () => {
const output = `export default {
colors: {
red: '#FF0000',
Expand All @@ -59,10 +59,9 @@ describe('Format: ESM', () => {
const prettier = {
singleQuote: true
}

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore: fake values to test formatter
expect(javascriptEsm({dictionary, file, options: {prettier}, undefined})).toStrictEqual(output)
// @ts-expect-error: fake values to test formatter
const result = await javascriptEsm({ dictionary, file, options: { prettier }, undefined })
expect(result).toStrictEqual(output)
})

})
8 changes: 4 additions & 4 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -33,7 +33,7 @@
"test": "NODE_OPTIONS=--experimental-vm-modules npx jest && npm run lint && tsc --noEmit",
"lint": "npx eslint . --ext .ts",
"fix": "npx eslint . --ext .ts --fix",
"clean:dist": "rm -rf dist/",
"clean:dist": "rm -rf dist/ && rm -rf dist-cjs/",
"prebuild": "npm run clean:dist",
"build": "tsc && tsc -p tsconfig-esm.json",
"preversion": "npm run build && npm run test",
Expand Down Expand Up @@ -65,6 +65,6 @@
"typescript": "^5.1.6"
},
"peerDependencies": {
"style-dictionary": "4.0.0-prerelease.14"
"style-dictionary": "4.0.0-prerelease.15"
}
}
4 changes: 2 additions & 2 deletions src/format/javascript-commonJs.ts
Expand Up @@ -6,11 +6,11 @@ import { jsonToNestedValue } from '../utilities/jsonToNestedValue.js'

const { fileHeader } = StyleDictionary.formatHelpers

export const javascriptCommonJs: Format['formatter'] = ({ dictionary, file, options, platform = {} }) => {
export const javascriptCommonJs: Format['formatter'] = async ({ dictionary, file, options, platform = {} }) => {
const { prefix } = platform
const tokens = prefix ? { [prefix]: dictionary.tokens } : dictionary.tokens
//
const output = fileHeader({ file }) +
const output = await fileHeader({ file }) +
`exports.default = ${JSON.stringify(jsonToNestedValue(tokens), null, 2)}\n`
// return prettified
return syncPrettier.format(output, { parser: 'typescript', printWidth: 500, ...options?.prettier })
Expand Down
4 changes: 2 additions & 2 deletions src/format/javascript-esm.ts
Expand Up @@ -6,11 +6,11 @@ import { jsonToNestedValue } from '../utilities/jsonToNestedValue.js'

const { fileHeader } = StyleDictionary.formatHelpers

export const javascriptEsm: Format['formatter'] = ({ dictionary, file, options, platform = {} }) => {
export const javascriptEsm: Format['formatter'] = async ({ dictionary, file, options, platform = {} }) => {
const { prefix } = platform
const tokens = prefix ? { [prefix]: dictionary.tokens } : dictionary.tokens
//
const output = fileHeader({ file }) +
const output = await fileHeader({ file }) +
`export default \n${JSON.stringify(jsonToNestedValue(tokens), null, 2)}\n`
// return prettified
return syncPrettier.format(output, { parser: 'typescript', printWidth: 500, ...options?.prettier })
Expand Down

0 comments on commit e904ceb

Please sign in to comment.