mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-11 08:07:26 +02:00
perf/fix(v2): more efficient hot reload & consistent filegen (#1950)
* perf(v2): efficient hot reload, consistent generated file * changelog * more
This commit is contained in:
parent
87f864e5ba
commit
e04c8f140f
7 changed files with 60 additions and 6 deletions
|
@ -15,6 +15,7 @@ import {
|
|||
getSubFolder,
|
||||
normalizeUrl,
|
||||
posixPath,
|
||||
objectWithKeySorted,
|
||||
} from '../index';
|
||||
|
||||
describe('load utils', () => {
|
||||
|
@ -82,6 +83,41 @@ describe('load utils', () => {
|
|||
});
|
||||
});
|
||||
|
||||
test('objectWithKeySorted', () => {
|
||||
const obj = {
|
||||
'/docs/adding-blog': '4',
|
||||
'/docs/versioning': '5',
|
||||
'/': '1',
|
||||
'/blog/2018': '3',
|
||||
'/youtube': '7',
|
||||
'/users/en/': '6',
|
||||
'/blog': '2',
|
||||
};
|
||||
expect(objectWithKeySorted(obj)).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"/": "1",
|
||||
"/blog": "2",
|
||||
"/blog/2018": "3",
|
||||
"/docs/adding-blog": "4",
|
||||
"/docs/versioning": "5",
|
||||
"/users/en/": "6",
|
||||
"/youtube": "7",
|
||||
}
|
||||
`);
|
||||
const obj2 = {
|
||||
b: 'foo',
|
||||
c: 'bar',
|
||||
a: 'baz',
|
||||
};
|
||||
expect(objectWithKeySorted(obj2)).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"a": "baz",
|
||||
"b": "foo",
|
||||
"c": "bar",
|
||||
}
|
||||
`);
|
||||
});
|
||||
|
||||
test('genChunkName', () => {
|
||||
const firstAssert = {
|
||||
'/docs/adding-blog': 'docs-adding-blog-062',
|
||||
|
|
|
@ -31,6 +31,15 @@ export async function generate(
|
|||
}
|
||||
}
|
||||
|
||||
export function objectWithKeySorted(obj: Object) {
|
||||
// https://github.com/lodash/lodash/issues/1459#issuecomment-253969771
|
||||
return _(obj)
|
||||
.toPairs()
|
||||
.sortBy(0)
|
||||
.fromPairs()
|
||||
.value();
|
||||
}
|
||||
|
||||
const indexRE = /(^|.*\/)index\.(md|js)$/i;
|
||||
const extRE = /\.(md|js)$/;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue