Skip to content

Commit

Permalink
Small fixes (#1090)
Browse files Browse the repository at this point in the history
* chore(utils,radio): remove unused merged ref and add truthy check for useReadyRef

* chore(tools): combine update-dependabot-config and productionize scripts
  • Loading branch information
Mike Wolf authored Oct 20, 2023
1 parent dcc54db commit aa44577
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 51 deletions.
6 changes: 6 additions & 0 deletions .changeset/khaki-carpets-develop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@real-system/utils-library': patch
'@real-system/radio-group': patch
---

remove unused useMergeRefs and add truthy check to useReadyRef
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ $ git add .
$ git commit -m "<your_commit_message>"

# or to be prompted by commitizen :)
$ yarn commit
$ git commit
$ git push origin <branch_name>

# then raise a PR
Expand Down
7 changes: 2 additions & 5 deletions packages/components/radio-group/src/Radio.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import React, { useRef } from 'react';
import React from 'react';
import { forwardRef } from 'react';

import { useInteractions } from '@real-system/a11y-library';
import type { AriakitRadioProps } from '@real-system/ariakit-library';
import { AriakitRadio } from '@real-system/ariakit-library';
import { Text } from '@real-system/typography';
import { useMergeRefs } from '@real-system/utils-library';
import { VisuallyHidden } from '@real-system/visually-hidden';

import { RadioControl, RadioLabel } from './components';
Expand All @@ -28,8 +27,6 @@ const Radio = forwardRef<HTMLInputElement, RadioProps>(function Radio(

const { hoverProps, pressProps, focusWithinProps, ...restInteractions } =
useInteractions({ disabled });
const internalRef = useRef<HTMLInputElement>(null);
const mergedRef = useMergeRefs(internalRef, ref);

return (
<Text.Label
Expand All @@ -40,7 +37,7 @@ const Radio = forwardRef<HTMLInputElement, RadioProps>(function Radio(
{...focusWithinProps}>
<VisuallyHidden>
<AriakitRadio
ref={mergedRef}
ref={ref}
value={value}
disabled={disabled}
name={store.name}
Expand Down
6 changes: 4 additions & 2 deletions packages/libraries/utils-library/src/hooks/useReadyRef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ const useReadyRef = <T>(

const setRef = useCallback(
(node: T) => {
mergeRefs(node);
setReady(!!node);
if (node) {
mergeRefs(node);
setReady(!!node);
}
},
[mergeRefs, refs]
);
Expand Down
8 changes: 6 additions & 2 deletions tools/productionize-package.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const {
getWorkspacesInfo,
logger,
writeToFile,
updateDependabotConfig,
PRODUCTION,
} = require('./utils');

Expand Down Expand Up @@ -37,8 +38,10 @@ const getPackagesToProductionize = async () => {
if (!packagesToProductionize) {
return logger.info('All packages are productionized already.');
}

/** update each original package.json */
packagesToProductionize.forEach(({ name, location }) => {
for (const pkg of packagesToProductionize) {
const { name, location } = pkg;
const pathToPkgJson = `${resolve(location)}/package.json`;
const pkgJson = fs.readFileSync(pathToPkgJson, 'utf-8');

Expand All @@ -51,5 +54,6 @@ const getPackagesToProductionize = async () => {
successMessage: `Productionized ${name}.`,
errorMessage: `Failed to productionize ${name}.`,
});
});
}
updateDependabotConfig();
})();
43 changes: 2 additions & 41 deletions tools/update-dependabot-config.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,3 @@
const fs = require('fs');
const yaml = require('js-yaml');
const { getWorkspacesInfo, logger, writeToFile } = require('./utils');
const { updateDependabotConfig } = require('./utils');

const DEPENDABOT_CONFIG_PATH = `${__dirname}/../.github/dependabot.yml`;
const applyUpdate = (directory, restOptions = {}) => ({
'package-ecosystem': 'npm',
directory,
schedule: { interval: 'weekly' },
labels: ['area: infra', 'area: security', 'area: repo'],
...restOptions,
});

const staticUpdates = [
applyUpdate('/', { 'package-ecosystem': 'github-actions' }),
applyUpdate('/', { 'package-ecosystem': 'npm' }),
];

const makeTemplate = (packages) => {
const updates = staticUpdates;

packages.forEach((pkg) => {
updates.push(applyUpdate(`/${pkg.location}`));
});

return updates;
};

(async function updateDependabotConfig() {
logger.info('Updating dependabot config');

const { pkgList } = await getWorkspacesInfo({ withCore: true });

let dependabot = yaml.load(fs.readFileSync(DEPENDABOT_CONFIG_PATH, 'utf-8'));
const updates = makeTemplate(pkgList);

dependabot.updates = updates;

await writeToFile(DEPENDABOT_CONFIG_PATH, yaml.dump(dependabot), {
successMessage: 'Updated dependabot config',
});
})();
updateDependabotConfig();
2 changes: 2 additions & 0 deletions tools/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const {
getPurePkgName,
} = require('./workspaceUtils');
const { updatePackageCache } = require('./updatePackageCache');
const { updateDependabotConfig } = require('./update-dependabot-config');

module.exports = {
writeToFile,
Expand All @@ -29,6 +30,7 @@ module.exports = {
getFullPkgName,
getPurePkgName,
updatePackageCache,
updateDependabotConfig,
CORE_PATH,
ROOT_PATH,
PACKAGE_STATUS_CONFIG,
Expand Down
46 changes: 46 additions & 0 deletions tools/utils/update-dependabot-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const fs = require('fs');
const yaml = require('js-yaml');
const { getWorkspacesInfo } = require('./workspaceUtils');
const { writeToFile } = require('./writeToFile');
const { logger } = require('./logger');

const DEPENDABOT_CONFIG_PATH = `${__dirname}/../../.github/dependabot.yml`;
const applyUpdate = (directory, restOptions = {}) => ({
'package-ecosystem': 'npm',
directory,
schedule: { interval: 'weekly' },
labels: ['area: infra', 'area: security', 'area: repo'],
...restOptions,
});

const staticUpdates = [
applyUpdate('/', { 'package-ecosystem': 'github-actions' }),
applyUpdate('/', { 'package-ecosystem': 'npm' }),
];

const makeTemplate = (packages) => {
const updates = staticUpdates;

packages.forEach((pkg) => {
updates.push(applyUpdate(`/${pkg.location}`));
});

return updates;
};

async function updateDependabotConfig() {
logger.info('Updating dependabot config');

const { pkgList } = await getWorkspacesInfo({ withCore: true });

let dependabot = yaml.load(fs.readFileSync(DEPENDABOT_CONFIG_PATH, 'utf-8'));
const updates = makeTemplate(pkgList);

dependabot.updates = updates;

await writeToFile(DEPENDABOT_CONFIG_PATH, yaml.dump(dependabot), {
successMessage: 'Updated dependabot config',
});
}

module.exports = { updateDependabotConfig };

0 comments on commit aa44577

Please sign in to comment.