mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-25 15:07:17 +02:00
fix(v2): fix Webpack persistent caching (evict on swizzle/alias/config change) (#5047)
* webpack upgrade * refactor docusaurus-utils hash fns * Fix webpack cache eviction problems on config/aliases/swizzle changes * Move/Rename InitPlugin type * fix TS typos * Add tests for webpack aliases * fix windows tests
This commit is contained in:
parent
9916a0b4a4
commit
99270dbab2
38 changed files with 274 additions and 169 deletions
37
packages/docusaurus-utils/src/hashUtils.ts
Normal file
37
packages/docusaurus-utils/src/hashUtils.ts
Normal file
|
@ -0,0 +1,37 @@
|
|||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import {createHash} from 'crypto';
|
||||
import {kebabCase} from 'lodash';
|
||||
import {shortName, isNameTooLong} from './pathUtils';
|
||||
|
||||
export function md5Hash(str: string): string {
|
||||
return createHash('md5').update(str).digest('hex');
|
||||
}
|
||||
|
||||
export function simpleHash(str: string, length: number): string {
|
||||
return md5Hash(str).substr(0, length);
|
||||
}
|
||||
|
||||
// Based on https://github.com/gatsbyjs/gatsby/pull/21518/files
|
||||
/**
|
||||
* Given an input string, convert to kebab-case and append a hash.
|
||||
* Avoid str collision.
|
||||
* Also removes part of the string if its larger than the allowed
|
||||
* filename per OS. Avoids ERRNAMETOOLONG error.
|
||||
*/
|
||||
export function docuHash(str: string): string {
|
||||
if (str === '/') {
|
||||
return 'index';
|
||||
}
|
||||
const shortHash = simpleHash(str, 3);
|
||||
const parsedPath = `${kebabCase(str)}-${shortHash}`;
|
||||
if (isNameTooLong(parsedPath)) {
|
||||
return `${shortName(kebabCase(str))}-${shortHash}`;
|
||||
}
|
||||
return parsedPath;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue