Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions .npmpackagejsonlintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"requireEndingPeriod": true
}
],
"prefer-no-devDependencies": "error",
"require-publishConfig": "error",
"require-repository-directory": "error",
"valid-values-author": [ "error", [ "The WordPress Contributors" ] ],
Expand All @@ -26,16 +25,14 @@
"patterns": [ "./package.json" ],
"rules": {
"require-publishConfig": "off",
"require-repository-directory": "off",
"prefer-no-devDependencies": "off"
"require-repository-directory": "off"
}
},
{
"patterns": [ "./platform-docs/package.json" ],
"rules": {
"require-publishConfig": "off",
"require-repository-directory": "off",
"prefer-no-devDependencies": "off"
"require-repository-directory": "off"
}
}
]
Expand Down
27 changes: 8 additions & 19 deletions bin/validate-tsconfig.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
/**
* External dependencies
*/
// @ts-ignore
import glob from 'glob';
import { dirname, basename } from 'path';
import stripJsonComments from 'strip-json-comments';
import JSONC from 'jsonc-parser';
Copy link
Member Author

Choose a reason for hiding this comment

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

tsconfig files are JSONC files, so we may as well use a JSONC parser than trying to transform the string into something we can shove into JSON.parse. This is the library that TypeScript itself maintains and uses internally.

import { readFileSync } from 'fs';

let hasErrors = false;
Expand Down Expand Up @@ -40,22 +39,12 @@ for ( const packageName of packagesWithTypes ) {
);
throw e;
}
let tsconfigJson;
try {
tsconfigJson = JSON.parse(
stripJsonComments(
readFileSync(
`packages/${ packageName }/tsconfig.json`,
'utf8'
)
)
);
} catch ( e ) {
console.error(
`Error parsing tsconfig.json for package ${ packageName }`
);
throw e;
}

const tsconfigs = glob.sync( `packages/${ packageName }/tsconfig*.json` );
const references = tsconfigs.flatMap(
( path ) => JSONC.parse( readFileSync( path, 'utf8' ) ).references ?? []
);

if ( packageJson.dependencies ) {
for ( const dependency of Object.keys( packageJson.dependencies ) ) {
if ( dependency.startsWith( '@wordpress/' ) ) {
Expand All @@ -64,7 +53,7 @@ for ( const packageName of packagesWithTypes ) {
);
if (
packagesWithTypes.includes( dependencyPackageName ) &&
! tsconfigJson.references?.some(
! references.some(
( reference ) =>
reference.path === `../${ dependencyPackageName }`
)
Expand Down
70 changes: 41 additions & 29 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@
"jest-message-util": "29.6.2",
"jest-watch-typeahead": "2.2.2",
"json2md": "2.0.1",
"jsonc-parser": "3.3.1",
"lerna": "8.1.9",
"lint-staged": "10.0.2",
"make-dir": "3.0.0",
Expand Down Expand Up @@ -168,7 +169,6 @@
"sprintf-js": "1.1.1",
"storybook": "8.4.7",
"storybook-source-link": "2.0.9",
"strip-json-comments": "5.0.0",
"style-loader": "3.2.1",
"stylelint-plugin-logical-css": "^1.2.3",
"terser": "5.32.0",
Expand Down
83 changes: 0 additions & 83 deletions packages/theme/bin/build-tokens.js

This file was deleted.

46 changes: 46 additions & 0 deletions packages/theme/bin/generate-default-ramps/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* External dependencies
*/
import { writeFile } from 'node:fs/promises';
import { join } from 'node:path';

/**
* Internal dependencies
*/
import {
DEFAULT_SEED_COLORS,
buildBgRamp,
buildAccentRamp,
} from '../../src/color-ramps/index.ts';

const bgRamp = buildBgRamp( DEFAULT_SEED_COLORS.bg );
const accentRamps = Object.fromEntries(
[ ...Object.entries( DEFAULT_SEED_COLORS ) ]
.filter( ( [ scaleName ] ) => scaleName !== 'bg' )
.map( ( [ scaleName, seed ] ) => [
scaleName,
buildAccentRamp( seed, bgRamp ),
] )
);

const ramps = { bg: bgRamp, ...accentRamps };

const outputPath = join(
import.meta.dirname,
'../../src/color-ramps/lib/default-ramps.ts'
);

const content = `
/**
* Internal dependencies
*/
import type { RampResult } from './types';
import type { DEFAULT_SEED_COLORS } from './constants';

export const DEFAULT_RAMPS: Record<
keyof typeof DEFAULT_SEED_COLORS,
RampResult
> = ${ JSON.stringify( ramps ) };
`;

await writeFile( outputPath, content );
8 changes: 7 additions & 1 deletion packages/theme/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
"colorjs.io": "^0.5.2",
"memize": "^2.1.0"
},
"devDependencies": {
"esbuild-esm-loader": "0.3.3"
},
"peerDependencies": {
"react": "^18.0.0",
"react-dom": "^18.0.0"
Expand All @@ -52,6 +55,9 @@
"access": "public"
},
"scripts": {
"build": "rimraf src/prebuilt docs && node bin/build-tokens.js && prettier --write tokens/color.json src/prebuilt docs"
"build:default-ramps": "node --import=esbuild-esm-loader/register bin/generate-default-ramps/index.ts",
"build:tokens": "node --import=esbuild-esm-loader/register bin/generate-primitive-tokens/index.ts && NODE_OPTIONS=--import=esbuild-esm-loader/register tz build --config terrazzo.config.ts",
"build": "npm run build:tokens && npm run build:default-ramps",
"postbuild": "prettier --write tokens/color.json src/prebuilt src/color-ramps/lib/default-ramps.ts docs"
}
}
Loading
Loading