Skip to content

Commit

Permalink
Merge pull request #99 from tokens-studio/types
Browse files Browse the repository at this point in the history
feat: remove types, use @tokens-studio/types instead
  • Loading branch information
jorenbroekema authored Apr 14, 2023
2 parents 837aeb3 + 3728d90 commit fccffa1
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 71 deletions.
5 changes: 5 additions & 0 deletions .changeset/sixty-teachers-kick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@tokens-studio/sd-transforms': minor
---

BREAKING: remove modifier type files, use @tokens-studio/types instead for it.
12 changes: 6 additions & 6 deletions package-lock.json

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

7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
37 changes: 15 additions & 22 deletions rollup/cjs.config.mjs
Original file line number Diff line number Diff line change
@@ -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 })],
};
2 changes: 1 addition & 1 deletion src/color-modifiers/darken.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/color-modifiers/lighten.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/color-modifiers/modifyColor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/color-modifiers/transformColorModifiers.ts
Original file line number Diff line number Diff line change
@@ -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);
}
6 changes: 0 additions & 6 deletions src/color-modifiers/types/ColorModifierTypes.ts

This file was deleted.

6 changes: 0 additions & 6 deletions src/color-modifiers/types/ColorSpaceTypes.ts

This file was deleted.

20 changes: 0 additions & 20 deletions src/color-modifiers/types/Modifier.ts

This file was deleted.

2 changes: 1 addition & 1 deletion test/spec/color-modifiers/transformColorModifiers.spec.ts
Original file line number Diff line number Diff line change
@@ -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, {
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"extends": "./tsconfig.json",
"exclude": ["node_modules", "**/coverage/*", "test/**/*.test.ts"]
"exclude": ["node_modules", "**/coverage/*", "test/**/*"]
}

0 comments on commit fccffa1

Please sign in to comment.