diff --git a/.changeset/sixty-teachers-kick.md b/.changeset/sixty-teachers-kick.md new file mode 100644 index 0000000..d0f1fce --- /dev/null +++ b/.changeset/sixty-teachers-kick.md @@ -0,0 +1,5 @@ +--- +'@tokens-studio/sd-transforms': minor +--- + +BREAKING: remove modifier type files, use @tokens-studio/types instead for it. diff --git a/package-lock.json b/package-lock.json index fe399f4..275fca8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,15 +1,15 @@ { "name": "@tokens-studio/sd-transforms", - "version": "0.6.0", + "version": "0.7.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@tokens-studio/sd-transforms", - "version": "0.6.0", + "version": "0.7.0", "license": "MIT", "dependencies": { - "@tokens-studio/types": "^0.1.3", + "@tokens-studio/types": "^0.2.1", "color2k": "^2.0.1", "colorjs.io": "^0.4.3", "expr-eval": "^2.0.2", @@ -1035,9 +1035,9 @@ } }, "node_modules/@tokens-studio/types": { - "version": "0.1.3", - "resolved": "https://registry.npmjs.org/@tokens-studio/types/-/types-0.1.3.tgz", - "integrity": "sha512-m/xNeKA3jgHU4urEI+sVGxSbBOEG3zMEnRiNiKZs+xM5DYK66fPk75Br8dhlz+Pvemxp9qVF00oJOU02uqVONQ==" + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/@tokens-studio/types/-/types-0.2.1.tgz", + "integrity": "sha512-yuSgYbKM7yU/r3Dx5UqG2s/L31ZNA/o232Gk7ayQpcSDHAIrVAoR4rYV3XMKNbuLv9xHjrFa7OnqEjAghFgqWQ==" }, "node_modules/@tsconfig/node10": { "version": "1.0.9", diff --git a/package.json b/package.json index be11159..6e9118b 100644 --- a/package.json +++ b/package.json @@ -11,9 +11,8 @@ "type": "module", "exports": { ".": { - "require": "./dist/index.cjs", - "import": "./dist/src/index.js", - "types": "./dist/index.d.ts" + "require": "./dist/src/index.cjs", + "import": "./dist/src/index.js" } }, "main": "./dist/index.cjs", @@ -43,7 +42,7 @@ }, "types": "./dist/index.d.ts", "dependencies": { - "@tokens-studio/types": "^0.1.3", + "@tokens-studio/types": "^0.2.1", "color2k": "^2.0.1", "colorjs.io": "^0.4.3", "expr-eval": "^2.0.2", diff --git a/rollup/cjs.config.mjs b/rollup/cjs.config.mjs index 84c5206..063f3a7 100644 --- a/rollup/cjs.config.mjs +++ b/rollup/cjs.config.mjs @@ -1,35 +1,28 @@ -import cjs from '@rollup/plugin-commonjs'; import nodeResolve from '@rollup/plugin-node-resolve'; import typescript from '@rollup/plugin-typescript'; import path from 'path'; +import fs from 'fs'; const __dirname = new URL(import.meta.url).pathname; const input = path.join(__dirname, '..', '..', 'src', 'index.ts'); -const file = path.join(__dirname, '..', '..', 'dist', 'index.cjs'); +const pkg = JSON.parse(fs.readFileSync(path.resolve('package.json'), 'utf-8')); + +const externalPackages = [ + ...Object.keys(pkg.dependencies || {}), + ...Object.keys(pkg.peerDependencies || {}), +]; +// Creating regexes of the packages to make sure subpaths of the +// packages are also treated as external +const regexesOfPackages = externalPackages.map(packageName => new RegExp(`^${packageName}(/.*)?`)); export default { + external: regexesOfPackages, input, output: { - file, + dir: 'dist', format: 'cjs', + preserveModules: true, + entryFileNames: '[name].cjs', }, - plugins: [ - cjs(), - nodeResolve(), - typescript({ noEmit: true }), // noEmit doesn't seem to do anything...? - // For some reason I can't get this typescript rollup plugin to stop emitting .D.TS files - // so here's a quick plugin to delete those from the bundle pre- bundle.write(). - // .D.TS files are already emitted by TSC when compiling the lib, this config is only for - // outputting a CJS bundle for users that require CJS... - { - name: 'prevent-type-decl', - generateBundle(_, bundle) { - Object.keys(bundle).forEach(filename => { - if (filename.endsWith('.d.ts')) { - delete bundle[filename]; - } - }); - }, - }, - ], + plugins: [nodeResolve(), typescript({ tsconfig: 'tsconfig.build.json', declaration: false })], }; diff --git a/src/color-modifiers/darken.ts b/src/color-modifiers/darken.ts index 166a9d8..8f631fe 100644 --- a/src/color-modifiers/darken.ts +++ b/src/color-modifiers/darken.ts @@ -1,5 +1,5 @@ import Color from 'colorjs.io'; -import { ColorSpaceTypes } from './types/ColorSpaceTypes.js'; +import { ColorSpaceTypes } from '@tokens-studio/types'; export function darken(color: Color, colorSpace: ColorSpaceTypes, amount: number): Color { switch (colorSpace) { diff --git a/src/color-modifiers/lighten.ts b/src/color-modifiers/lighten.ts index 7331a68..e6de655 100644 --- a/src/color-modifiers/lighten.ts +++ b/src/color-modifiers/lighten.ts @@ -1,5 +1,5 @@ import Color from 'colorjs.io'; -import { ColorSpaceTypes } from './types/ColorSpaceTypes.js'; +import { ColorSpaceTypes } from '@tokens-studio/types'; export function lighten(color: Color, colorSpace: ColorSpaceTypes, amount: number): Color { switch (colorSpace) { diff --git a/src/color-modifiers/modifyColor.ts b/src/color-modifiers/modifyColor.ts index fad8a42..1ece008 100644 --- a/src/color-modifiers/modifyColor.ts +++ b/src/color-modifiers/modifyColor.ts @@ -3,7 +3,7 @@ import { transparentize } from './transparentize.js'; import { mix } from './mix.js'; import { darken } from './darken.js'; import { lighten } from './lighten.js'; -import { ColorModifier } from './types/Modifier.js'; +import { ColorModifier } from '@tokens-studio/types'; export function modifyColor( baseColor: string | undefined, diff --git a/src/color-modifiers/transformColorModifiers.ts b/src/color-modifiers/transformColorModifiers.ts index 506048e..7a4eadf 100644 --- a/src/color-modifiers/transformColorModifiers.ts +++ b/src/color-modifiers/transformColorModifiers.ts @@ -1,10 +1,10 @@ import { DesignToken } from 'style-dictionary'; import { modifyColor } from './modifyColor.js'; +import { ColorModifier } from '@tokens-studio/types'; /** * Helper: Transforms color tokens with tokens studio color modifiers */ export function transformColorModifiers(token: DesignToken): string | undefined { - /** @type {ColorModifier} */ - const modifier = token.$extensions['studio.tokens']?.modify; + const modifier = token.$extensions['studio.tokens']?.modify as ColorModifier; return modifyColor(token.value, modifier); } diff --git a/src/color-modifiers/types/ColorModifierTypes.ts b/src/color-modifiers/types/ColorModifierTypes.ts deleted file mode 100644 index f9d929c..0000000 --- a/src/color-modifiers/types/ColorModifierTypes.ts +++ /dev/null @@ -1,6 +0,0 @@ -export enum ColorModifierTypes { - LIGHTEN = 'lighten', - DARKEN = 'darken', - MIX = 'mix', - ALPHA = 'alpha', -} diff --git a/src/color-modifiers/types/ColorSpaceTypes.ts b/src/color-modifiers/types/ColorSpaceTypes.ts deleted file mode 100644 index 4c3315b..0000000 --- a/src/color-modifiers/types/ColorSpaceTypes.ts +++ /dev/null @@ -1,6 +0,0 @@ -export enum ColorSpaceTypes { - LCH = 'lch', - SRGB = 'srgb', - P3 = 'p3', - HSL = 'hsl', -} diff --git a/src/color-modifiers/types/Modifier.ts b/src/color-modifiers/types/Modifier.ts deleted file mode 100644 index 1fa2a59..0000000 --- a/src/color-modifiers/types/Modifier.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { ColorModifierTypes } from './ColorModifierTypes'; -import { ColorSpaceTypes } from './ColorSpaceTypes'; - -interface Modifier { - type: T; - value: V; -} -interface ColorGenericModifier extends Modifier { - space: ColorSpaceTypes; - format?: ColorSpaceTypes; -} - -export type LightenModifier = ColorGenericModifier; -export type DarkenModifier = ColorGenericModifier; -export interface MixModifier extends ColorGenericModifier { - color: string; -} -export type AlphaModifier = ColorGenericModifier; - -export type ColorModifier = LightenModifier | DarkenModifier | MixModifier | AlphaModifier; diff --git a/test/spec/color-modifiers/transformColorModifiers.spec.ts b/test/spec/color-modifiers/transformColorModifiers.spec.ts index 2dfb398..cf3b66f 100644 --- a/test/spec/color-modifiers/transformColorModifiers.spec.ts +++ b/test/spec/color-modifiers/transformColorModifiers.spec.ts @@ -1,6 +1,6 @@ import { expect } from '@esm-bundle/chai'; +import { ColorSpaceTypes } from '@tokens-studio/types'; import { transformColorModifiers } from '../../../src/color-modifiers/transformColorModifiers.js'; -import { ColorSpaceTypes } from '../../../src/color-modifiers/types/ColorSpaceTypes.js'; import { runTransformSuite } from '../../suites/transform-suite.spec.js'; runTransformSuite(transformColorModifiers as (value: unknown) => unknown, { diff --git a/tsconfig.build.json b/tsconfig.build.json index 816edc0..4117f2d 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.json @@ -1,4 +1,4 @@ { "extends": "./tsconfig.json", - "exclude": ["node_modules", "**/coverage/*", "test/**/*.test.ts"] + "exclude": ["node_modules", "**/coverage/*", "test/**/*"] }