Skip to content

Commit

Permalink
Merge pull request #1016 from chromaui/reuben/ap-4736-ts-when-file-na…
Browse files Browse the repository at this point in the history
…mes-have-special-characters-eg-ts-is-unable

Added logic to account for parentheses at the beginning
  • Loading branch information
ethriel3695 authored Jul 31, 2024
2 parents c91d301 + 8079d57 commit 295aaf5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
12 changes: 10 additions & 2 deletions node-src/tasks/upload.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,13 @@ describe('traceChangedFiles', () => {

it('escapes special characters on context', async () => {
const deps = {
'./$example-new.stories.js': ['./$example-new.stories.js'],
'./+example-new.stories.js': ['./+example-new.stories.js'],
'./example-(new).stories.js': ['./example-(new).stories.js'],
'./example[[lang=language]].stories.js': ['./example[[lang=language]].stories.js'],
'[./example/[account]/[id]/[unit]/language/example.stories.tsx]': [
'[./example/[account]/[id]/[unit]/language/example.stories.tsx]',
],
};
findChangedDependencies.mockResolvedValue([]);
findChangedPackageFiles.mockResolvedValue([]);
Expand All @@ -186,8 +191,11 @@ describe('traceChangedFiles', () => {
await traceChangedFiles(ctx, {} as any);

expect(ctx.onlyStoryFiles).toStrictEqual([
'./example-\\(\\new\\)\\.stories.js',
'./example\\[\\[\\lang=language\\]\\]\\.stories.js',
'./\\$example-new.stories.js',
'./\\+example-new.stories.js',
'./example-\\(new\\).stories.js',
'./example\\[\\[lang=language\\]\\].stories.js',
'\\[./example/\\[account\\]/\\[id\\]/\\[unit\\]/language/example.stories.tsx\\]',
]);
});

Expand Down
12 changes: 6 additions & 6 deletions node-src/tasks/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ interface PathSpec {
pathname: string;
contentLength: number;
}

const SPECIAL_CHARS_REGEXP = new RegExp(`([${'`$^*+?()[]'.split('').join('\\')}])`);
// These are the special characters that need to be escaped in the filename
// because they are used as special characters in picomatch
const SPECIAL_CHARS_REGEXP = /([$^*+?()[\]])/g;

// Get all paths in rootDir, starting at dirname.
// We don't want the paths to include rootDir -- so if rootDir = storybook-static,
Expand Down Expand Up @@ -162,10 +163,9 @@ export const traceChangedFiles = async (ctx: Context, task: Task) => {
);
if (onlyStoryFiles) {
// Escape special characters in the filename so it does not conflict with picomatch
ctx.onlyStoryFiles = Object.keys(onlyStoryFiles).map((key) => {
const filteredArray = key.split(SPECIAL_CHARS_REGEXP).filter((item) => item !== '');
return filteredArray.join('\\');
});
ctx.onlyStoryFiles = Object.keys(onlyStoryFiles).map((key) =>
key.replace(SPECIAL_CHARS_REGEXP, '\\$1')
);

if (!ctx.options.interactive) {
if (!ctx.options.traceChanged) {
Expand Down

0 comments on commit 295aaf5

Please sign in to comment.