Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Indexer: Rename index to createIndex #24075

Merged
merged 8 commits into from
Sep 12, 2023
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
2 changes: 1 addition & 1 deletion code/addons/docs/src/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ async function webpack(

export const createStoriesMdxIndexer = (legacyMdx1?: boolean): Indexer => ({
test: /(stories|story)\.mdx$/,
index: async (fileName, opts) => {
createIndex: async (fileName, opts) => {
let code = (await fs.readFile(fileName, 'utf-8')).toString();
const { compile } = legacyMdx1
? await import('@storybook/mdx1-csf')
Expand Down
2 changes: 1 addition & 1 deletion code/lib/core-server/src/presets/common-preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export const features = async (

export const csfIndexer: Indexer = {
test: /(stories|story)\.(m?js|ts)x?$/,
index: async (fileName, options) => (await readCsf(fileName, options)).parse().indexInputs,
createIndex: async (fileName, options) => (await readCsf(fileName, options)).parse().indexInputs,
};

// eslint-disable-next-line @typescript-eslint/naming-convention
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1166,7 +1166,7 @@ describe('StoryIndexGenerator with deprecated indexer API', () => {
indexers: [
{
test: /\.stories\.(m?js|ts)x?$/,
index: async (fileName, options) => {
createIndex: async (fileName, options) => {
const code = (await fs.readFile(fileName, 'utf-8')).toString();
const csf = loadCsf(code, { ...options, fileName }).parse();

Expand Down
2 changes: 1 addition & 1 deletion code/lib/core-server/src/utils/StoryIndexGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ export class StoryIndexGenerator {
});
}

const indexInputs = await indexer.index(absolutePath, { makeTitle: defaultMakeTitle });
const indexInputs = await indexer.createIndex(absolutePath, { makeTitle: defaultMakeTitle });

const entries: ((StoryIndexEntryWithMetaId | DocsCacheEntry) & { tags: Tag[] })[] =
indexInputs.map((input) => {
Expand Down
22 changes: 11 additions & 11 deletions code/lib/core-server/src/utils/__tests__/index-extraction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('story extraction', () => {
indexers: [
{
test: /\.stories\.(m?js|ts)x?$/,
index: async (fileName) => [
createIndex: async (fileName) => [
// properties identical to the auto-generated ones, eg. 'StoryOne' -> 'Story One'
{
type: 'story',
Expand Down Expand Up @@ -107,7 +107,7 @@ describe('story extraction', () => {
indexers: [
{
test: /\.stories\.(m?js|ts)x?$/,
index: async (fileName) => [
createIndex: async (fileName) => [
{
exportName: 'StoryOne',
importPath: fileName,
Expand Down Expand Up @@ -150,7 +150,7 @@ describe('story extraction', () => {
indexers: [
{
test: /\.stories\.(m?js|ts)x?$/,
index: async (fileName) => [
createIndex: async (fileName) => [
{
exportName: 'StoryOne',
__id: 'a--story-one',
Expand Down Expand Up @@ -198,7 +198,7 @@ describe('story extraction', () => {
indexers: [
{
test: /\.stories\.(m?js|ts)x?$/,
index: async (fileName) => [
createIndex: async (fileName) => [
{
exportName: 'StoryOne',
__id: 'a--story-one',
Expand Down Expand Up @@ -246,7 +246,7 @@ describe('story extraction', () => {
indexers: [
{
test: /\.stories\.(m?js|ts)x?$/,
index: async (fileName) => [
createIndex: async (fileName) => [
// exportName + title -> id
{
exportName: 'StoryOne',
Expand Down Expand Up @@ -336,7 +336,7 @@ describe('story extraction', () => {
indexers: [
{
test: /\.stories\.(m?js|ts)x?$/,
index: async (fileName) => [
createIndex: async (fileName) => [
{
exportName: 'StoryOne',
tags: ['story-tag-from-indexer'],
Expand Down Expand Up @@ -383,7 +383,7 @@ describe('docs entries from story extraction', () => {
indexers: [
{
test: /\.stories\.(m?js|ts)x?$/,
index: async (fileName) => [
createIndex: async (fileName) => [
{
exportName: 'StoryOne',
__id: 'a--story-one',
Expand Down Expand Up @@ -444,7 +444,7 @@ describe('docs entries from story extraction', () => {
indexers: [
{
test: /\.stories\.(m?js|ts)x?$/,
index: async (fileName) => [
createIndex: async (fileName) => [
{
exportName: 'StoryOne',
__id: 'a--story-one',
Expand Down Expand Up @@ -506,7 +506,7 @@ describe('docs entries from story extraction', () => {
indexers: [
{
test: /\.stories\.(m?js|ts)x?$/,
index: async (fileName) => [
createIndex: async (fileName) => [
{
exportName: 'StoryOne',
__id: 'a--story-one',
Expand Down Expand Up @@ -555,7 +555,7 @@ describe('docs entries from story extraction', () => {
indexers: [
{
test: /\.stories\.(m?js|ts)x?$/,
index: async (fileName) => [
createIndex: async (fileName) => [
{
exportName: 'StoryOne',
__id: 'a--story-one',
Expand Down Expand Up @@ -617,7 +617,7 @@ describe('docs entries from story extraction', () => {
indexers: [
{
test: /\.stories\.mdx?$/,
index: async (fileName) => [
createIndex: async (fileName) => [
{
exportName: '__page',
__id: 'page--page',
Expand Down
4 changes: 2 additions & 2 deletions code/lib/types/src/modules/indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export type Indexer = BaseIndexer & {
* @param options {@link IndexerOptions} for indexing the file.
* @returns A promise that resolves to an array of {@link IndexInput} objects.
*/
index: (fileName: string, options: IndexerOptions) => Promise<IndexInput[]>;
createIndex: (fileName: string, options: IndexerOptions) => Promise<IndexInput[]>;
/**
* @soonDeprecated Use {@link index} instead
*/
Expand All @@ -75,7 +75,7 @@ export type Indexer = BaseIndexer & {

export type DeprecatedIndexer = BaseIndexer & {
indexer: (fileName: string, options: IndexerOptions) => Promise<IndexedCSFFile>;
index?: never;
createIndex?: never;
};

/**
Expand Down
2 changes: 1 addition & 1 deletion code/renderers/server/src/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const experimental_indexers: StorybookConfig['experimental_indexers'] = (
) => [
{
test: /(stories|story)\.(json|ya?ml)$/,
index: async (fileName) => {
createIndex: async (fileName) => {
const content: FileContent = fileName.endsWith('.json')
? await fs.readJson(fileName, 'utf-8')
: yaml.parse((await fs.readFile(fileName, 'utf-8')).toString());
Expand Down