@docusaurus/utils 2.0.0-beta.15d451942 → 2.0.0-beta.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/lib/constants.d.ts +20 -0
- package/lib/constants.d.ts.map +1 -0
- package/lib/constants.js +27 -0
- package/lib/constants.js.map +1 -0
- package/lib/dataFileUtils.d.ts +24 -0
- package/lib/dataFileUtils.d.ts.map +1 -0
- package/lib/dataFileUtils.js +65 -0
- package/lib/dataFileUtils.js.map +1 -0
- package/lib/gitUtils.d.ts +17 -0
- package/lib/gitUtils.d.ts.map +1 -0
- package/lib/gitUtils.js +63 -0
- package/lib/gitUtils.js.map +1 -0
- package/lib/globUtils.d.ts +12 -0
- package/lib/globUtils.d.ts.map +1 -0
- package/lib/globUtils.js +48 -0
- package/lib/globUtils.js.map +1 -0
- package/lib/hashUtils.d.ts +16 -0
- package/lib/hashUtils.d.ts.map +1 -0
- package/lib/hashUtils.js +41 -0
- package/lib/hashUtils.js.map +1 -0
- package/lib/index.d.ts +30 -52
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +126 -247
- package/lib/index.js.map +1 -0
- package/lib/markdownLinks.d.ts +1 -0
- package/lib/markdownLinks.d.ts.map +1 -0
- package/lib/markdownLinks.js +36 -11
- package/lib/markdownLinks.js.map +1 -0
- package/lib/markdownParser.d.ts +7 -3
- package/lib/markdownParser.d.ts.map +1 -0
- package/lib/markdownParser.js +77 -48
- package/lib/markdownParser.js.map +1 -0
- package/lib/pathUtils.d.ts +51 -0
- package/lib/pathUtils.d.ts.map +1 -0
- package/lib/pathUtils.js +106 -0
- package/lib/pathUtils.js.map +1 -0
- package/lib/slugger.d.ts +14 -0
- package/lib/slugger.d.ts.map +1 -0
- package/lib/slugger.js +19 -0
- package/lib/slugger.js.map +1 -0
- package/lib/tags.d.ts +27 -0
- package/lib/tags.d.ts.map +1 -0
- package/lib/tags.js +77 -0
- package/lib/tags.js.map +1 -0
- package/lib/urlUtils.d.ts +9 -0
- package/lib/urlUtils.d.ts.map +1 -0
- package/lib/urlUtils.js +81 -0
- package/lib/urlUtils.js.map +1 -0
- package/lib/webpackUtils.d.ts +30 -0
- package/lib/webpackUtils.d.ts.map +1 -0
- package/lib/webpackUtils.js +112 -0
- package/lib/webpackUtils.js.map +1 -0
- package/package.json +20 -10
- package/src/constants.ts +38 -0
- package/src/dataFileUtils.ts +90 -0
- package/src/deps.d.ts +10 -0
- package/src/gitUtils.ts +93 -0
- package/src/globUtils.ts +64 -0
- package/src/hashUtils.ts +37 -0
- package/src/index.ts +135 -294
- package/src/markdownLinks.ts +35 -13
- package/src/markdownParser.ts +86 -62
- package/src/pathUtils.ts +115 -0
- package/src/slugger.ts +24 -0
- package/src/tags.ts +105 -0
- package/src/urlUtils.ts +96 -0
- package/src/webpackUtils.ts +146 -0
- package/lib/.tsbuildinfo +0 -3972
- package/lib/codeTranslationsUtils.d.ts +0 -11
- package/lib/codeTranslationsUtils.js +0 -50
- package/lib/escapePath.d.ts +0 -17
- package/lib/escapePath.js +0 -25
- package/lib/posixPath.d.ts +0 -14
- package/lib/posixPath.js +0 -28
- package/src/__tests__/__fixtures__/defaultCodeTranslations/en.json +0 -4
- package/src/__tests__/__fixtures__/defaultCodeTranslations/fr-FR.json +0 -5
- package/src/__tests__/__fixtures__/defaultCodeTranslations/fr.json +0 -4
- package/src/__tests__/__snapshots__/index.test.ts.snap +0 -8
- package/src/__tests__/codeTranslationsUtils.test.ts +0 -112
- package/src/__tests__/escapePath.test.ts +0 -25
- package/src/__tests__/index.test.ts +0 -681
- package/src/__tests__/markdownParser.test.ts +0 -772
- package/src/__tests__/posixPath.test.ts +0 -25
- package/src/codeTranslationsUtils.ts +0 -56
- package/src/escapePath.ts +0 -23
- package/src/posixPath.ts +0 -27
- package/tsconfig.json +0 -9
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type {RuleSetRule} from 'webpack';
|
|
9
|
+
import path from 'path';
|
|
10
|
+
import {escapePath} from './pathUtils';
|
|
11
|
+
import {
|
|
12
|
+
WEBPACK_URL_LOADER_LIMIT,
|
|
13
|
+
OUTPUT_STATIC_ASSETS_DIR_NAME,
|
|
14
|
+
} from './constants';
|
|
15
|
+
|
|
16
|
+
type AssetFolder = 'images' | 'files' | 'fonts' | 'medias';
|
|
17
|
+
|
|
18
|
+
type FileLoaderUtils = {
|
|
19
|
+
loaders: {
|
|
20
|
+
file: (options: {folder: AssetFolder}) => RuleSetRule;
|
|
21
|
+
url: (options: {folder: AssetFolder}) => RuleSetRule;
|
|
22
|
+
inlineMarkdownImageFileLoader: string;
|
|
23
|
+
inlineMarkdownLinkFileLoader: string;
|
|
24
|
+
};
|
|
25
|
+
rules: {
|
|
26
|
+
images: () => RuleSetRule;
|
|
27
|
+
fonts: () => RuleSetRule;
|
|
28
|
+
media: () => RuleSetRule;
|
|
29
|
+
svg: () => RuleSetRule;
|
|
30
|
+
otherAssets: () => RuleSetRule;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
// Inspired by https://github.com/gatsbyjs/gatsby/blob/8e6e021014da310b9cc7d02e58c9b3efe938c665/packages/gatsby/src/utils/webpack-utils.ts#L447
|
|
35
|
+
export function getFileLoaderUtils(): FileLoaderUtils {
|
|
36
|
+
// files/images < urlLoaderLimit will be inlined as base64 strings directly in
|
|
37
|
+
// the html
|
|
38
|
+
const urlLoaderLimit = WEBPACK_URL_LOADER_LIMIT;
|
|
39
|
+
|
|
40
|
+
// defines the path/pattern of the assets handled by webpack
|
|
41
|
+
const fileLoaderFileName = (folder: AssetFolder) =>
|
|
42
|
+
`${OUTPUT_STATIC_ASSETS_DIR_NAME}/${folder}/[name]-[contenthash].[ext]`;
|
|
43
|
+
|
|
44
|
+
const loaders: FileLoaderUtils['loaders'] = {
|
|
45
|
+
file: (options: {folder: AssetFolder}) => ({
|
|
46
|
+
loader: require.resolve(`file-loader`),
|
|
47
|
+
options: {
|
|
48
|
+
name: fileLoaderFileName(options.folder),
|
|
49
|
+
},
|
|
50
|
+
}),
|
|
51
|
+
url: (options: {folder: AssetFolder}) => ({
|
|
52
|
+
loader: require.resolve('url-loader'),
|
|
53
|
+
options: {
|
|
54
|
+
limit: urlLoaderLimit,
|
|
55
|
+
name: fileLoaderFileName(options.folder),
|
|
56
|
+
fallback: require.resolve('file-loader'),
|
|
57
|
+
},
|
|
58
|
+
}),
|
|
59
|
+
|
|
60
|
+
// TODO avoid conflicts with the ideal-image plugin
|
|
61
|
+
// TODO this may require a little breaking change for ideal-image users?
|
|
62
|
+
// Maybe with the ideal image plugin, all md images should be "ideal"?
|
|
63
|
+
// This is used to force url-loader+file-loader on markdown images
|
|
64
|
+
// https://webpack.js.org/concepts/loaders/#inline
|
|
65
|
+
inlineMarkdownImageFileLoader: `!${escapePath(
|
|
66
|
+
require.resolve('url-loader'),
|
|
67
|
+
)}?limit=${urlLoaderLimit}&name=${fileLoaderFileName(
|
|
68
|
+
'images',
|
|
69
|
+
)}&fallback=${escapePath(require.resolve('file-loader'))}!`,
|
|
70
|
+
inlineMarkdownLinkFileLoader: `!${escapePath(
|
|
71
|
+
require.resolve('file-loader'),
|
|
72
|
+
)}?name=${fileLoaderFileName('files')}!`,
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const rules: FileLoaderUtils['rules'] = {
|
|
76
|
+
/**
|
|
77
|
+
* Loads image assets, inlines images via a data URI if they are below
|
|
78
|
+
* the size threshold
|
|
79
|
+
*/
|
|
80
|
+
images: () => ({
|
|
81
|
+
use: [loaders.url({folder: 'images'})],
|
|
82
|
+
test: /\.(?:ico|jpe?g|png|gif|webp)(?:\?.*)?$/i,
|
|
83
|
+
}),
|
|
84
|
+
|
|
85
|
+
fonts: () => ({
|
|
86
|
+
use: [loaders.url({folder: 'fonts'})],
|
|
87
|
+
test: /\.(?:woff2?|eot|ttf|otf)$/i,
|
|
88
|
+
}),
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Loads audio and video and inlines them via a data URI if they are below
|
|
92
|
+
* the size threshold
|
|
93
|
+
*/
|
|
94
|
+
media: () => ({
|
|
95
|
+
use: [loaders.url({folder: 'medias'})],
|
|
96
|
+
test: /\.(?:mp4|webm|ogv|wav|mp3|m4a|aac|oga|flac)$/i,
|
|
97
|
+
}),
|
|
98
|
+
|
|
99
|
+
svg: () => ({
|
|
100
|
+
test: /\.svg$/i,
|
|
101
|
+
oneOf: [
|
|
102
|
+
{
|
|
103
|
+
use: [
|
|
104
|
+
{
|
|
105
|
+
loader: require.resolve('@svgr/webpack'),
|
|
106
|
+
options: {
|
|
107
|
+
prettier: false,
|
|
108
|
+
svgo: true,
|
|
109
|
+
svgoConfig: {
|
|
110
|
+
plugins: [
|
|
111
|
+
{
|
|
112
|
+
name: 'preset-default',
|
|
113
|
+
params: {
|
|
114
|
+
overrides: {
|
|
115
|
+
removeTitle: false,
|
|
116
|
+
removeViewBox: false,
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
],
|
|
121
|
+
},
|
|
122
|
+
titleProp: true,
|
|
123
|
+
ref: ![path],
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
],
|
|
127
|
+
// We don't want to use SVGR loader for non-React source code
|
|
128
|
+
// ie we don't want to use SVGR for CSS files...
|
|
129
|
+
issuer: {
|
|
130
|
+
and: [/\.(?:tsx?|jsx?|mdx?)$/i],
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
use: [loaders.url({folder: 'images'})],
|
|
135
|
+
},
|
|
136
|
+
],
|
|
137
|
+
}),
|
|
138
|
+
|
|
139
|
+
otherAssets: () => ({
|
|
140
|
+
use: [loaders.file({folder: 'files'})],
|
|
141
|
+
test: /\.(?:pdf|docx?|xlsx?|zip|rar)$/i,
|
|
142
|
+
}),
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
return {loaders, rules};
|
|
146
|
+
}
|