Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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

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

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

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

Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,18 @@ function stableCreatedFiles(
}

describe('eject', () => {
async function testEject(action: SwizzleAction, componentName: string) {
async function testEject(
action: SwizzleAction,
componentName: string,
{typescript}: {typescript: boolean} = {typescript: true},
) {
const siteDir = await createTempSiteDir();
const siteThemePath = path.join(siteDir, 'src/theme');
const result = await eject({
siteDir,
componentName,
themePath: ThemePath,
typescript,
});
return {
siteDir,
Expand All @@ -53,6 +58,22 @@ describe('eject', () => {
`);
});

it(`eject ${Components.JsComponent} JS`, async () => {
const result = await testEject('eject', Components.JsComponent, {
typescript: false,
});
expect(result.createdFiles).toEqual([
'JsComponent/index.css',
'JsComponent/index.js',
]);
expect(result.tree).toMatchInlineSnapshot(`
"theme
└── JsComponent
├── index.css
└── index.js"
`);
});

it(`eject ${Components.ComponentInSubFolder}`, async () => {
const result = await testEject('eject', Components.ComponentInSubFolder);
expect(result.createdFiles).toEqual([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const Components = {
Sibling: 'ComponentInFolder/Sibling',
ComponentInFolder: 'ComponentInFolder',
FirstLevelComponent: 'FirstLevelComponent',
JsComponent: 'JsComponent',
NoIndex: 'NoIndex',
NoIndexComp1: 'NoIndex/NoIndexComp1',
NoIndexComp2: 'NoIndex/NoIndexComp2',
Expand Down
10 changes: 8 additions & 2 deletions packages/docusaurus/src/commands/swizzle/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export type ActionParams = {
siteDir: string;
themePath: string;
componentName: string;
typescript: boolean;
};

export type ActionResult = {
Expand All @@ -49,6 +50,7 @@ export async function eject({
siteDir,
themePath,
componentName,
typescript,
}: ActionParams): Promise<ActionResult> {
const fromPath = path.join(themePath, componentName);
const isDirectory = await isDir(fromPath);
Expand All @@ -60,7 +62,12 @@ export async function eject({
const globPatternPosix = posixPath(globPattern);

const filesToCopy = await Globby(globPatternPosix, {
ignore: ['**/*.{story,stories,test,tests}.{js,jsx,ts,tsx}'],
ignore: _.compact([
'**/*.{story,stories,test,tests}.{js,jsx,ts,tsx}',
// When ejecting JS components, we want to avoid emitting TS files
// In particular the .d.ts files that theme build output contains
typescript ? null : '**/*.{d.ts,ts,tsx}',
]),
});

if (filesToCopy.length === 0) {
Expand Down Expand Up @@ -103,7 +110,6 @@ export async function wrap({
typescript,
importType = 'original',
}: ActionParams & {
typescript: boolean;
importType?: 'original' | 'init';
}): Promise<ActionResult> {
const isDirectory = await isDir(path.join(themePath, themeComponentName));
Expand Down
1 change: 1 addition & 0 deletions packages/docusaurus/src/commands/swizzle/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ Created wrapper of name=${componentName} from name=${themeName} in path=${result
siteDir,
themePath,
componentName,
typescript,
});
logger.success`
Ejected name=${componentName} from name=${themeName} to path=${result.createdFiles}
Expand Down