Skip to content

Commit

Permalink
fix: preserve stories order
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Jun 6, 2020
1 parent 4f30e77 commit e27f047
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
3 changes: 1 addition & 2 deletions core/loader/src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ import {
parseStories,
} from '@component-controls/instrument';

import { reserveStoriesDoc, addStoriesDoc } from './store';
import { addStoriesDoc } from './store';

module.exports.pitch = async function() {
const options: InstrumentOptions = getOptions(this) || {};
const context = this as loader.LoaderContext;
const filePath = this.resource;
reserveStoriesDoc(filePath);
const source = fs.readFileSync(filePath, 'utf8');
const { transformed, ...store } = await parseStories(
source,
Expand Down
5 changes: 3 additions & 2 deletions core/loader/src/runtimeLoader.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { loadConfiguration, extractStories } from '@component-controls/config';
import { stringifyRequest } from 'loader-utils';
import { replaceSource, StoryPath } from './replaceSource';
import { store } from './store';
import { store, reserveStories } from './store';

module.exports = function(content: string) {
//@ts-ignore
Expand All @@ -11,14 +11,15 @@ module.exports = function(content: string) {
store.config = config?.optionsFilePath
? require(config?.optionsFilePath)
: undefined;

const stories: StoryPath[] = (config ? extractStories(config) || [] : []).map(
fileName => ({
absPath: fileName,
//@ts-ignore
relPath: stringifyRequest(this, fileName),
}),
);

reserveStories(stories.map(story => story.absPath));
content = replaceSource(
stories,
config?.optionsFilePath,
Expand Down
4 changes: 2 additions & 2 deletions core/loader/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ export const store: LoadingStore = {
packages: {},
};

export const reserveStoriesDoc = (filePath: string) => {
store.stores.push({ filePath });
export const reserveStories = (filePaths: string[]) => {
filePaths.forEach(filePath => store.stores.push({ filePath }));
};
export const addStoriesDoc = (filePath: string, added: LoadingDocStore) => {
const { components, packages, stories, doc } = added;
Expand Down

0 comments on commit e27f047

Please sign in to comment.