mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-09 00:19:13 +08:00
Support dot folders and adjust regex to support sub-paths
This commit is contained in:
parent
2213e7f121
commit
0519e6083e
@ -180,6 +180,23 @@ describe('transformImportFiles', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('should transform import declarations with sub-paths', async () => {
|
||||
const sourceContents = dedent`
|
||||
import { other } from '@storybook/theming/create';
|
||||
`;
|
||||
const sourceFiles = [join('src', 'test.ts')];
|
||||
|
||||
vi.mocked(readFile).mockResolvedValueOnce(sourceContents);
|
||||
|
||||
const errors = await transformImportFiles(sourceFiles, false);
|
||||
|
||||
expect(errors).toHaveLength(0);
|
||||
expect(writeFile).toHaveBeenCalledWith(
|
||||
sourceFiles[0],
|
||||
expect.stringContaining(`from 'storybook/internal/theming/create'`)
|
||||
);
|
||||
});
|
||||
|
||||
it('should transform require calls', async () => {
|
||||
const sourceContents = dedent`
|
||||
const something = require('@storybook/components');
|
||||
|
@ -45,9 +45,9 @@ function transformImports(source: string) {
|
||||
|
||||
for (const [from, to] of Object.entries(consolidatedPackages)) {
|
||||
// Match the package name when it's inside either single or double quotes
|
||||
const regex = new RegExp(`(['"])${from}\\1`, 'g');
|
||||
const regex = new RegExp(`(['"])${from}(.*)\\1`, 'g');
|
||||
if (regex.test(transformed)) {
|
||||
transformed = transformed.replace(regex, `$1${to}$1`);
|
||||
transformed = transformed.replace(regex, `$1${to}$2$1`);
|
||||
hasChanges = true;
|
||||
}
|
||||
}
|
||||
@ -180,6 +180,7 @@ export const consolidatedImports: Fix<ConsolidatedOptions> = {
|
||||
const sourceFiles = await globby([glob], {
|
||||
...commonGlobOptions(''),
|
||||
ignore: ['**/node_modules/**'],
|
||||
dot: true,
|
||||
cwd: projectRoot,
|
||||
});
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user