mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-23 05:57:05 +02:00
refactor: create @docusaurus/bundler
and @docusaurus/babel
packages (#10511)
This commit is contained in:
parent
fd14d6af55
commit
9ecff801ff
65 changed files with 1921 additions and 1588 deletions
|
@ -10,8 +10,11 @@
|
|||
import path from 'path';
|
||||
import Micromatch from 'micromatch'; // Note: Micromatch is used by Globby
|
||||
import {addSuffix} from '@docusaurus/utils-common';
|
||||
import Globby from 'globby';
|
||||
import {posixPath} from './pathUtils';
|
||||
|
||||
/** A re-export of the globby instance. */
|
||||
export {default as Globby} from 'globby';
|
||||
export {Globby};
|
||||
|
||||
/**
|
||||
* The default glob patterns we ignore when sourcing content.
|
||||
|
@ -85,3 +88,40 @@ export function createAbsoluteFilePathMatcher(
|
|||
return (absoluteFilePath: string) =>
|
||||
matcher(getRelativeFilePath(absoluteFilePath));
|
||||
}
|
||||
|
||||
// Globby that fix Windows path patterns
|
||||
// See https://github.com/facebook/docusaurus/pull/4222#issuecomment-795517329
|
||||
export async function safeGlobby(
|
||||
patterns: string[],
|
||||
options?: Globby.GlobbyOptions,
|
||||
): Promise<string[]> {
|
||||
// Required for Windows support, as paths using \ should not be used by globby
|
||||
// (also using the windows hard drive prefix like c: is not a good idea)
|
||||
const globPaths = patterns.map((dirPath) =>
|
||||
posixPath(path.relative(process.cwd(), dirPath)),
|
||||
);
|
||||
|
||||
return Globby(globPaths, options);
|
||||
}
|
||||
|
||||
// A bit weird to put this here, but it's used by core + theme-translations
|
||||
export async function globTranslatableSourceFiles(
|
||||
patterns: string[],
|
||||
): Promise<string[]> {
|
||||
// We only support extracting source code translations from these kind of files
|
||||
const extensionsAllowed = new Set([
|
||||
'.js',
|
||||
'.jsx',
|
||||
'.ts',
|
||||
'.tsx',
|
||||
// TODO support md/mdx too? (may be overkill)
|
||||
// need to compile the MDX to JSX first and remove front matter
|
||||
// '.md',
|
||||
// '.mdx',
|
||||
]);
|
||||
|
||||
const filePaths = await safeGlobby(patterns);
|
||||
return filePaths.filter((filePath) =>
|
||||
extensionsAllowed.has(path.extname(filePath)),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -97,6 +97,8 @@ export {md5Hash, simpleHash, docuHash} from './hashUtils';
|
|||
export {
|
||||
Globby,
|
||||
GlobExcludeDefault,
|
||||
safeGlobby,
|
||||
globTranslatableSourceFiles,
|
||||
createMatcher,
|
||||
createAbsoluteFilePathMatcher,
|
||||
} from './globUtils';
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue