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
28 changes: 28 additions & 0 deletions packages/rstack/THIRD_PARTY_NOTICES.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,34 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

## micromatch

This package includes bundled code from [micromatch](https://github.com/micromatch/micromatch).

License: MIT

The MIT License (MIT)

Copyright (c) 2014-present, Jon Schlinkert.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

## Husky

Portions of the Git hook installer and runtime are derived from [Husky](https://github.com/typicode/husky).
Expand Down
2 changes: 2 additions & 0 deletions packages/rstack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@
"@rstackjs/test-utils": "catalog:",
"@rstest/adapter-rsbuild": "catalog:",
"@rstest/adapter-rslib": "catalog:",
"@types/micromatch": "catalog:",
"@types/node": "catalog:",
"lint-staged": "catalog:",
"micromatch": "catalog:",
Comment thread
chenjiahan marked this conversation as resolved.
"rslog": "catalog:",
"typescript": "catalog:"
},
Expand Down
47 changes: 45 additions & 2 deletions packages/rstack/src/fmt/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { dirname } from 'node:path';
import { dirname, relative } from 'node:path';
import micromatch from 'micromatch';
import type { Options as PrettierOptions } from 'prettier';
import type { FmtConfig, FmtConfigDefinition, ResolvedFmtConfig } from './types.ts';

type ResolveFmtConfigOptions = {
Expand All @@ -19,6 +21,47 @@ const normalizeFmtConfig = (config: FmtConfig | undefined, rootPath: string): Re
};
};

const pathMatchesGlobs = (
filePath: string,
patterns: string | string[],
excludedPatterns?: string | string[],
): boolean => {
const patternList = Array.isArray(patterns) ? patterns : [patterns];
const withSlashes = patternList.filter((pattern) => pattern.includes('/'));
const withoutSlashes = patternList.filter((pattern) => !pattern.includes('/'));

return (
micromatch.isMatch(filePath, withoutSlashes, {
ignore: excludedPatterns,
basename: true,
dot: true,
}) ||
micromatch.isMatch(filePath, withSlashes, {
ignore: excludedPatterns,
basename: false,
dot: true,
})
);
};

/** Applies matching overrides to the shared formatter options. */
const resolveFmtOptions = (filePath: string, config: ResolvedFmtConfig): PrettierOptions => {
if (config.overrides.length === 0) {
return config.baseOptions;
}

const options = { ...config.baseOptions };
const relativeFilePath = relative(config.rootPath, filePath);

for (const override of config.overrides) {
if (pathMatchesGlobs(relativeFilePath, override.files, override.excludeFiles)) {
Object.assign(options, override.options);
}
}

return options;
};

/** Resolves a formatter config definition and its project root. */
const resolveFmtConfig = async ({
definition,
Expand All @@ -31,4 +74,4 @@ const resolveFmtConfig = async ({
return normalizeFmtConfig(config, rootPath);
};

export { normalizeFmtConfig, resolveFmtConfig };
export { normalizeFmtConfig, resolveFmtConfig, resolveFmtOptions };
69 changes: 69 additions & 0 deletions pnpm-lock.yaml

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

2 changes: 2 additions & 0 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ catalog:
'@testing-library/dom': '^10.4.1'
'@testing-library/jest-dom': '^7.0.0'
'@testing-library/react': '^16.3.2'
'@types/micromatch': '^4.0.10'
'@types/node': '^24.13.3'
'@types/react': '^19.2.17'
'@types/react-dom': '^19.2.3'
Expand All @@ -36,6 +37,7 @@ catalog:
'happy-dom': '^20.11.1'
'heading-case': '^1.1.4'
'lint-staged': '^17.2.0'
'micromatch': '4.0.8'
prettier: '3.9.6'
'prettier-plugin-packagejson': '^3.0.2'
'react': '^19.2.8'
Expand Down