@mui/internal-docs-infra 0.1.0 → 0.1.1-alpha.1
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/CodeControllerContext/CodeControllerContext.d.ts +22 -0
- package/CodeControllerContext/CodeControllerContext.d.ts.map +1 -0
- package/CodeControllerContext/CodeControllerContext.js +14 -0
- package/CodeControllerContext/index.d.ts +1 -0
- package/CodeControllerContext/index.d.ts.map +1 -0
- package/CodeControllerContext/index.js +1 -0
- package/CodeHighlighter/CodeHighlighter.d.ts +2 -0
- package/CodeHighlighter/CodeHighlighter.d.ts.map +1 -0
- package/CodeHighlighter/CodeHighlighter.js +321 -0
- package/CodeHighlighter/CodeHighlighterClient.d.ts +2 -0
- package/CodeHighlighter/CodeHighlighterClient.d.ts.map +1 -0
- package/CodeHighlighter/CodeHighlighterClient.js +399 -0
- package/CodeHighlighter/CodeHighlighterContext.d.ts +14 -0
- package/CodeHighlighter/CodeHighlighterContext.d.ts.map +1 -0
- package/CodeHighlighter/CodeHighlighterContext.js +14 -0
- package/CodeHighlighter/CodeHighlighterFallbackContext.d.ts +7 -0
- package/CodeHighlighter/CodeHighlighterFallbackContext.d.ts.map +1 -0
- package/CodeHighlighter/CodeHighlighterFallbackContext.js +11 -0
- package/CodeHighlighter/applyTransform.d.ts +19 -0
- package/CodeHighlighter/applyTransform.d.ts.map +1 -0
- package/CodeHighlighter/applyTransform.js +75 -0
- package/CodeHighlighter/codeToFallbackProps.d.ts +2 -0
- package/CodeHighlighter/codeToFallbackProps.d.ts.map +1 -0
- package/CodeHighlighter/codeToFallbackProps.js +70 -0
- package/CodeHighlighter/errors.d.ts +0 -0
- package/CodeHighlighter/errors.d.ts.map +1 -0
- package/CodeHighlighter/errors.js +1 -0
- package/CodeHighlighter/hasAllVariants.d.ts +2 -0
- package/CodeHighlighter/hasAllVariants.d.ts.map +1 -0
- package/CodeHighlighter/hasAllVariants.js +31 -0
- package/CodeHighlighter/index.d.ts +4 -0
- package/CodeHighlighter/index.d.ts.map +1 -0
- package/CodeHighlighter/index.js +4 -0
- package/CodeHighlighter/loadFallbackCode.d.ts +9 -0
- package/CodeHighlighter/loadFallbackCode.d.ts.map +1 -0
- package/CodeHighlighter/loadFallbackCode.js +468 -0
- package/CodeHighlighter/loadVariant.d.ts +11 -0
- package/CodeHighlighter/loadVariant.d.ts.map +1 -0
- package/CodeHighlighter/loadVariant.js +708 -0
- package/CodeHighlighter/maybeInitialData.d.ts +10 -0
- package/CodeHighlighter/maybeInitialData.d.ts.map +1 -0
- package/CodeHighlighter/maybeInitialData.js +94 -0
- package/CodeHighlighter/parseCode.d.ts +6 -0
- package/CodeHighlighter/parseCode.d.ts.map +1 -0
- package/CodeHighlighter/parseCode.js +122 -0
- package/CodeHighlighter/parseControlledCode.d.ts +6 -0
- package/CodeHighlighter/parseControlledCode.d.ts.map +1 -0
- package/CodeHighlighter/parseControlledCode.js +76 -0
- package/CodeHighlighter/transformCode.d.ts +20 -0
- package/CodeHighlighter/transformCode.d.ts.map +1 -0
- package/CodeHighlighter/transformCode.js +223 -0
- package/CodeHighlighter/transformParsedSource.d.ts +3 -0
- package/CodeHighlighter/transformParsedSource.d.ts.map +1 -0
- package/CodeHighlighter/transformParsedSource.js +66 -0
- package/CodeHighlighter/transformSource.d.ts +2 -0
- package/CodeHighlighter/transformSource.d.ts.map +1 -0
- package/CodeHighlighter/transformSource.js +107 -0
- package/CodeHighlighter/types.d.ts +138 -0
- package/CodeHighlighter/types.d.ts.map +1 -0
- package/CodeHighlighter/types.js +1 -0
- package/CodeProvider/CodeContext.d.ts +12 -0
- package/CodeProvider/CodeContext.d.ts.map +1 -0
- package/CodeProvider/CodeContext.js +8 -0
- package/CodeProvider/CodeProvider.d.ts +13 -0
- package/CodeProvider/CodeProvider.d.ts.map +1 -0
- package/CodeProvider/CodeProvider.js +50 -0
- package/CodeProvider/index.d.ts +2 -0
- package/CodeProvider/index.d.ts.map +1 -0
- package/CodeProvider/index.js +2 -0
- package/README.md +3 -1
- package/hast/hast.d.ts +11 -0
- package/hast/hast.d.ts.map +1 -0
- package/hast/hast.js +66 -0
- package/hast/index.d.ts +1 -0
- package/hast/index.d.ts.map +1 -0
- package/hast/index.js +1 -0
- package/loadPrecomputedCodeHighlighter/index.d.ts +2 -0
- package/loadPrecomputedCodeHighlighter/index.d.ts.map +1 -0
- package/loadPrecomputedCodeHighlighter/index.js +4 -0
- package/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.d.ts +57 -0
- package/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.d.ts.map +1 -0
- package/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.js +194 -0
- package/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.d.ts +20 -0
- package/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.d.ts.map +1 -0
- package/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.js +243 -0
- package/loadPrecomputedCodeHighlighter/parseFunctionParameters.d.ts +15 -0
- package/loadPrecomputedCodeHighlighter/parseFunctionParameters.d.ts.map +1 -0
- package/loadPrecomputedCodeHighlighter/parseFunctionParameters.js +168 -0
- package/loadPrecomputedCodeHighlighter/replacePrecomputeValue.d.ts +27 -0
- package/loadPrecomputedCodeHighlighter/replacePrecomputeValue.d.ts.map +1 -0
- package/loadPrecomputedCodeHighlighter/replacePrecomputeValue.js +37 -0
- package/loadServerCodeMeta/index.d.ts +1 -0
- package/loadServerCodeMeta/index.d.ts.map +1 -0
- package/loadServerCodeMeta/index.js +1 -0
- package/loadServerCodeMeta/serverLoadCodeMeta.d.ts +24 -0
- package/loadServerCodeMeta/serverLoadCodeMeta.d.ts.map +1 -0
- package/loadServerCodeMeta/serverLoadCodeMeta.js +77 -0
- package/loadServerSource/index.d.ts +1 -0
- package/loadServerSource/index.d.ts.map +1 -0
- package/loadServerSource/index.js +1 -0
- package/loadServerSource/serverLoadSource.d.ts +25 -0
- package/loadServerSource/serverLoadSource.d.ts.map +1 -0
- package/loadServerSource/serverLoadSource.js +100 -0
- package/loaderUtils/getFileNameFromUrl.d.ts +11 -0
- package/loaderUtils/getFileNameFromUrl.d.ts.map +1 -0
- package/loaderUtils/getFileNameFromUrl.js +32 -0
- package/loaderUtils/index.d.ts +5 -0
- package/loaderUtils/index.d.ts.map +1 -0
- package/loaderUtils/index.js +5 -0
- package/loaderUtils/processImports.d.ts +19 -0
- package/loaderUtils/processImports.d.ts.map +1 -0
- package/loaderUtils/processImports.js +82 -0
- package/loaderUtils/resolveImports.d.ts +4 -0
- package/loaderUtils/resolveImports.d.ts.map +1 -0
- package/loaderUtils/resolveImports.js +71 -0
- package/loaderUtils/resolveModulePath.d.ts +74 -0
- package/loaderUtils/resolveModulePath.d.ts.map +1 -0
- package/loaderUtils/resolveModulePath.js +862 -0
- package/loaderUtils/resolveModulePathWithFs.d.ts +44 -0
- package/loaderUtils/resolveModulePathWithFs.d.ts.map +1 -0
- package/loaderUtils/resolveModulePathWithFs.js +159 -0
- package/loaderUtils/rewriteImports.d.ts +9 -0
- package/loaderUtils/rewriteImports.d.ts.map +1 -0
- package/loaderUtils/rewriteImports.js +57 -0
- package/package.json +20 -7
- package/parseSource/grammars.d.ts +2 -0
- package/parseSource/grammars.d.ts.map +1 -0
- package/parseSource/grammars.js +27 -0
- package/parseSource/index.d.ts +1 -0
- package/parseSource/index.d.ts.map +1 -0
- package/parseSource/index.js +1 -0
- package/parseSource/parseSource.d.ts +3 -0
- package/parseSource/parseSource.d.ts.map +1 -0
- package/parseSource/parseSource.js +37 -0
- package/transformRelativeMarkdownPaths/index.d.ts +2 -0
- package/transformRelativeMarkdownPaths/index.d.ts.map +1 -0
- package/transformRelativeMarkdownPaths/index.js +4 -0
- package/transformRelativeMarkdownPaths/transformRelativeMarkdownPaths.d.ts +12 -0
- package/transformRelativeMarkdownPaths/transformRelativeMarkdownPaths.d.ts.map +1 -0
- package/transformRelativeMarkdownPaths/transformRelativeMarkdownPaths.js +30 -0
- package/transformTsToJs/index.d.ts +1 -0
- package/transformTsToJs/index.d.ts.map +1 -0
- package/transformTsToJs/index.js +1 -0
- package/transformTsToJs/removeTypes.d.ts +13 -0
- package/transformTsToJs/removeTypes.d.ts.map +1 -0
- package/transformTsToJs/removeTypes.js +134 -0
- package/transformTsToJs/transformTsToJs.d.ts +3 -0
- package/transformTsToJs/transformTsToJs.d.ts.map +1 -0
- package/transformTsToJs/transformTsToJs.js +34 -0
- package/useCode/index.d.ts +1 -0
- package/useCode/index.d.ts.map +1 -0
- package/useCode/index.js +1 -0
- package/{esm/useDemo/index.d.ts → useCode/useCode.d.ts} +14 -28
- package/useCode/useCode.d.ts.map +1 -0
- package/useCode/useCode.js +393 -0
- package/useCopier/index.js +10 -18
- package/useDemo/index.d.ts +12 -24
- package/useDemo/index.d.ts.map +1 -0
- package/useDemo/index.js +14 -109
- package/useOnHydrate/index.d.ts +1 -0
- package/useOnHydrate/index.d.ts.map +1 -0
- package/useOnHydrate/index.js +1 -0
- package/useOnHydrate/useOnHydrate.d.ts +1 -0
- package/useOnHydrate/useOnHydrate.d.ts.map +1 -0
- package/useOnHydrate/useOnHydrate.js +18 -0
- package/useOnIdle/index.d.ts +1 -0
- package/useOnIdle/index.d.ts.map +1 -0
- package/useOnIdle/index.js +1 -0
- package/useOnIdle/useOnIdle.d.ts +1 -0
- package/useOnIdle/useOnIdle.d.ts.map +1 -0
- package/useOnIdle/useOnIdle.js +39 -0
- package/esm/package.json +0 -1
- package/esm/useCopier/index.d.ts +0 -15
- package/esm/useCopier/index.js +0 -62
- package/esm/useDemo/index.d.ts.map +0 -1
- package/esm/useDemo/index.js +0 -104
- /package/{esm/useCopier → useCopier}/index.d.ts.map +0 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type DirectoryEntry, type DirectoryReader, type ResolveModulePathOptions } from "./resolveModulePath.js";
|
|
2
|
+
/**
|
|
3
|
+
* Resolves a module path using Node.js filesystem APIs.
|
|
4
|
+
* This is a convenience wrapper around the generic resolveModulePath function.
|
|
5
|
+
*
|
|
6
|
+
* @param modulePath - The module path to resolve (without file extension)
|
|
7
|
+
* @param options - Configuration options
|
|
8
|
+
* @returns Promise<string> - The resolved file path, or throws if not found
|
|
9
|
+
*/
|
|
10
|
+
export declare function resolveModulePathWithFs(modulePath: string, options?: ResolveModulePathOptions): Promise<string>;
|
|
11
|
+
/**
|
|
12
|
+
* Resolves multiple module paths using Node.js filesystem APIs.
|
|
13
|
+
* This is a convenience wrapper around the generic resolveModulePaths function.
|
|
14
|
+
*
|
|
15
|
+
* @param modulePaths - Array of module paths to resolve (without file extensions)
|
|
16
|
+
* @param options - Configuration options
|
|
17
|
+
* @returns Promise<Map<string, string>> - Map from input path to resolved file path
|
|
18
|
+
*/
|
|
19
|
+
export declare function resolveModulePathsWithFs(modulePaths: string[], options?: ResolveModulePathOptions): Promise<Map<string, string>>;
|
|
20
|
+
/**
|
|
21
|
+
* Resolves import result by separating JavaScript modules from static assets,
|
|
22
|
+
* only resolving JavaScript modules and returning a combined map.
|
|
23
|
+
* This is a convenience wrapper around the generic resolveImportResult function
|
|
24
|
+
* that uses Node.js filesystem APIs.
|
|
25
|
+
*
|
|
26
|
+
* @param importResult - The result from resolveImports containing all imports
|
|
27
|
+
* @param options - Configuration options for module resolution
|
|
28
|
+
* @returns Promise<Map<string, string>> - Map from import path to resolved file path
|
|
29
|
+
*/
|
|
30
|
+
export declare function resolveImportResultWithFs(importResult: Record<string, {
|
|
31
|
+
path: string;
|
|
32
|
+
names: string[];
|
|
33
|
+
}>, options?: ResolveModulePathOptions): Promise<Map<string, string>>;
|
|
34
|
+
/**
|
|
35
|
+
* Resolves variant paths from a variants object mapping variant names to their file paths.
|
|
36
|
+
* This is a convenience wrapper around the generic resolveVariantPaths function
|
|
37
|
+
* that uses Node.js filesystem APIs.
|
|
38
|
+
*
|
|
39
|
+
* @param variants - Object mapping variant names to their file paths
|
|
40
|
+
* @param options - Configuration options for module resolution
|
|
41
|
+
* @returns Promise<Map<string, string>> - Map from variant name to resolved file URL
|
|
42
|
+
*/
|
|
43
|
+
export declare function resolveVariantPathsWithFs(variants: Record<string, string>, options?: ResolveModulePathOptions): Promise<Map<string, string>>;
|
|
44
|
+
export type { DirectoryEntry, DirectoryReader, ResolveModulePathOptions };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveModulePathWithFs.d.ts","sourceRoot":"","sources":["../../../src/loaderUtils/resolveModulePathWithFs.ts"],"names":[],"mappings":"AACA,OAAO,EAKL,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,wBAAwB,EAC9B,MAAM,qBAAqB,CAAC;AAe7B;;;;;;;GAOG;AACH,wBAAsB,uBAAuB,CAC3C,UAAU,EAAE,MAAM,EAClB,OAAO,GAAE,wBAA6B,GACrC,OAAO,CAAC,MAAM,CAAC,CAEjB;AAED;;;;;;;GAOG;AACH,wBAAsB,wBAAwB,CAC5C,WAAW,EAAE,MAAM,EAAE,EACrB,OAAO,GAAE,wBAA6B,GACrC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAE9B;AAED;;;;;;;;;GASG;AACH,wBAAsB,yBAAyB,CAC7C,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC,EAC/D,OAAO,GAAE,wBAA6B,GACrC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAE9B;AAED;;;;;;;;GAQG;AACH,wBAAsB,yBAAyB,CAC7C,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAChC,OAAO,GAAE,wBAA6B,GACrC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAE9B;AAGD,YAAY,EAAE,cAAc,EAAE,eAAe,EAAE,wBAAwB,EAAE,CAAC"}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
|
|
2
|
+
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
3
|
+
import { readdir } from 'node:fs/promises';
|
|
4
|
+
import { resolveModulePath, resolveModulePaths, resolveImportResult, resolveVariantPaths } from "./resolveModulePath.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Node.js filesystem-based directory reader that converts Dirent objects
|
|
8
|
+
* to the DirectoryEntry interface expected by the resolver functions.
|
|
9
|
+
*/
|
|
10
|
+
var nodeDirectoryReader = /*#__PURE__*/function () {
|
|
11
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(path) {
|
|
12
|
+
var entries;
|
|
13
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
14
|
+
while (1) switch (_context.prev = _context.next) {
|
|
15
|
+
case 0:
|
|
16
|
+
_context.next = 2;
|
|
17
|
+
return readdir(path, {
|
|
18
|
+
withFileTypes: true
|
|
19
|
+
});
|
|
20
|
+
case 2:
|
|
21
|
+
entries = _context.sent;
|
|
22
|
+
return _context.abrupt("return", entries.map(function (entry) {
|
|
23
|
+
return {
|
|
24
|
+
name: entry.name,
|
|
25
|
+
isFile: entry.isFile(),
|
|
26
|
+
isDirectory: entry.isDirectory()
|
|
27
|
+
};
|
|
28
|
+
}));
|
|
29
|
+
case 4:
|
|
30
|
+
case "end":
|
|
31
|
+
return _context.stop();
|
|
32
|
+
}
|
|
33
|
+
}, _callee);
|
|
34
|
+
}));
|
|
35
|
+
return function nodeDirectoryReader(_x) {
|
|
36
|
+
return _ref.apply(this, arguments);
|
|
37
|
+
};
|
|
38
|
+
}();
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Resolves a module path using Node.js filesystem APIs.
|
|
42
|
+
* This is a convenience wrapper around the generic resolveModulePath function.
|
|
43
|
+
*
|
|
44
|
+
* @param modulePath - The module path to resolve (without file extension)
|
|
45
|
+
* @param options - Configuration options
|
|
46
|
+
* @returns Promise<string> - The resolved file path, or throws if not found
|
|
47
|
+
*/
|
|
48
|
+
export function resolveModulePathWithFs(_x2) {
|
|
49
|
+
return _resolveModulePathWithFs.apply(this, arguments);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Resolves multiple module paths using Node.js filesystem APIs.
|
|
54
|
+
* This is a convenience wrapper around the generic resolveModulePaths function.
|
|
55
|
+
*
|
|
56
|
+
* @param modulePaths - Array of module paths to resolve (without file extensions)
|
|
57
|
+
* @param options - Configuration options
|
|
58
|
+
* @returns Promise<Map<string, string>> - Map from input path to resolved file path
|
|
59
|
+
*/
|
|
60
|
+
function _resolveModulePathWithFs() {
|
|
61
|
+
_resolveModulePathWithFs = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(modulePath) {
|
|
62
|
+
var options,
|
|
63
|
+
_args2 = arguments;
|
|
64
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
65
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
66
|
+
case 0:
|
|
67
|
+
options = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : {};
|
|
68
|
+
return _context2.abrupt("return", resolveModulePath(modulePath, nodeDirectoryReader, options));
|
|
69
|
+
case 2:
|
|
70
|
+
case "end":
|
|
71
|
+
return _context2.stop();
|
|
72
|
+
}
|
|
73
|
+
}, _callee2);
|
|
74
|
+
}));
|
|
75
|
+
return _resolveModulePathWithFs.apply(this, arguments);
|
|
76
|
+
}
|
|
77
|
+
export function resolveModulePathsWithFs(_x3) {
|
|
78
|
+
return _resolveModulePathsWithFs.apply(this, arguments);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Resolves import result by separating JavaScript modules from static assets,
|
|
83
|
+
* only resolving JavaScript modules and returning a combined map.
|
|
84
|
+
* This is a convenience wrapper around the generic resolveImportResult function
|
|
85
|
+
* that uses Node.js filesystem APIs.
|
|
86
|
+
*
|
|
87
|
+
* @param importResult - The result from resolveImports containing all imports
|
|
88
|
+
* @param options - Configuration options for module resolution
|
|
89
|
+
* @returns Promise<Map<string, string>> - Map from import path to resolved file path
|
|
90
|
+
*/
|
|
91
|
+
function _resolveModulePathsWithFs() {
|
|
92
|
+
_resolveModulePathsWithFs = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(modulePaths) {
|
|
93
|
+
var options,
|
|
94
|
+
_args3 = arguments;
|
|
95
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
96
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
97
|
+
case 0:
|
|
98
|
+
options = _args3.length > 1 && _args3[1] !== undefined ? _args3[1] : {};
|
|
99
|
+
return _context3.abrupt("return", resolveModulePaths(modulePaths, nodeDirectoryReader, options));
|
|
100
|
+
case 2:
|
|
101
|
+
case "end":
|
|
102
|
+
return _context3.stop();
|
|
103
|
+
}
|
|
104
|
+
}, _callee3);
|
|
105
|
+
}));
|
|
106
|
+
return _resolveModulePathsWithFs.apply(this, arguments);
|
|
107
|
+
}
|
|
108
|
+
export function resolveImportResultWithFs(_x4) {
|
|
109
|
+
return _resolveImportResultWithFs.apply(this, arguments);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Resolves variant paths from a variants object mapping variant names to their file paths.
|
|
114
|
+
* This is a convenience wrapper around the generic resolveVariantPaths function
|
|
115
|
+
* that uses Node.js filesystem APIs.
|
|
116
|
+
*
|
|
117
|
+
* @param variants - Object mapping variant names to their file paths
|
|
118
|
+
* @param options - Configuration options for module resolution
|
|
119
|
+
* @returns Promise<Map<string, string>> - Map from variant name to resolved file URL
|
|
120
|
+
*/
|
|
121
|
+
function _resolveImportResultWithFs() {
|
|
122
|
+
_resolveImportResultWithFs = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(importResult) {
|
|
123
|
+
var options,
|
|
124
|
+
_args4 = arguments;
|
|
125
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
126
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
127
|
+
case 0:
|
|
128
|
+
options = _args4.length > 1 && _args4[1] !== undefined ? _args4[1] : {};
|
|
129
|
+
return _context4.abrupt("return", resolveImportResult(importResult, nodeDirectoryReader, options));
|
|
130
|
+
case 2:
|
|
131
|
+
case "end":
|
|
132
|
+
return _context4.stop();
|
|
133
|
+
}
|
|
134
|
+
}, _callee4);
|
|
135
|
+
}));
|
|
136
|
+
return _resolveImportResultWithFs.apply(this, arguments);
|
|
137
|
+
}
|
|
138
|
+
export function resolveVariantPathsWithFs(_x5) {
|
|
139
|
+
return _resolveVariantPathsWithFs.apply(this, arguments);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Re-export types for convenience
|
|
143
|
+
function _resolveVariantPathsWithFs() {
|
|
144
|
+
_resolveVariantPathsWithFs = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(variants) {
|
|
145
|
+
var options,
|
|
146
|
+
_args5 = arguments;
|
|
147
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
148
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
149
|
+
case 0:
|
|
150
|
+
options = _args5.length > 1 && _args5[1] !== undefined ? _args5[1] : {};
|
|
151
|
+
return _context5.abrupt("return", resolveVariantPaths(variants, nodeDirectoryReader, options));
|
|
152
|
+
case 2:
|
|
153
|
+
case "end":
|
|
154
|
+
return _context5.stop();
|
|
155
|
+
}
|
|
156
|
+
}, _callee5);
|
|
157
|
+
}));
|
|
158
|
+
return _resolveVariantPathsWithFs.apply(this, arguments);
|
|
159
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rewrites relative imports in source code to assume all files are in the same directory.
|
|
3
|
+
* Converts imports like '../utils/helper' or './components/Button' to './helper' and './Button'
|
|
4
|
+
*
|
|
5
|
+
* @param source - The source code to process
|
|
6
|
+
* @param filePaths - Set of file paths that are available as dependencies
|
|
7
|
+
* @returns The source code with rewritten imports
|
|
8
|
+
*/
|
|
9
|
+
export declare function rewriteImportsToSameDirectory(source: string, filePaths: Set<string>): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rewriteImports.d.ts","sourceRoot":"","sources":["../../../src/loaderUtils/rewriteImports.ts"],"names":[],"mappings":"AAGA;;;;;;;GAOG;AACH,wBAAgB,6BAA6B,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,MAAM,CAmD5F"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { JAVASCRIPT_MODULE_EXTENSIONS, isJavaScriptModule } from "./resolveModulePath.js";
|
|
2
|
+
import { getFileNameFromUrl } from "./getFileNameFromUrl.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Rewrites relative imports in source code to assume all files are in the same directory.
|
|
6
|
+
* Converts imports like '../utils/helper' or './components/Button' to './helper' and './Button'
|
|
7
|
+
*
|
|
8
|
+
* @param source - The source code to process
|
|
9
|
+
* @param filePaths - Set of file paths that are available as dependencies
|
|
10
|
+
* @returns The source code with rewritten imports
|
|
11
|
+
*/
|
|
12
|
+
export function rewriteImportsToSameDirectory(source, filePaths) {
|
|
13
|
+
// Create a map of original file paths to just their basenames
|
|
14
|
+
var fileBasenames = new Map();
|
|
15
|
+
Array.from(filePaths).forEach(function (path) {
|
|
16
|
+
fileBasenames.set(path, getFileNameFromUrl(path).fileName);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
// Regex to match import statements with relative paths
|
|
20
|
+
var importRegex = /import\s+((?:\w+|\*\s+as\s+\w+|{[^}]+})\s+from\s+)['"]([^'"]+)['"]/g;
|
|
21
|
+
return source.replace(importRegex, function (match, importPart, modulePath) {
|
|
22
|
+
// Only process relative imports
|
|
23
|
+
if (modulePath.startsWith('.')) {
|
|
24
|
+
// Extract the filename from the path
|
|
25
|
+
var filename = getFileNameFromUrl(modulePath).fileName;
|
|
26
|
+
|
|
27
|
+
// For static assets (CSS, JSON, etc.), use the filename as-is
|
|
28
|
+
if (!isJavaScriptModule(modulePath)) {
|
|
29
|
+
var matchingPath = Array.from(filePaths).find(function (path) {
|
|
30
|
+
return getFileNameFromUrl(path).fileName === filename;
|
|
31
|
+
});
|
|
32
|
+
if (matchingPath) {
|
|
33
|
+
return "import ".concat(importPart, "'./").concat(filename, "'");
|
|
34
|
+
}
|
|
35
|
+
} else {
|
|
36
|
+
// For JS/TS modules, check against all possible extensions
|
|
37
|
+
var _matchingPath = Array.from(filePaths).find(function (path) {
|
|
38
|
+
var pathBasename = getFileNameFromUrl(path).fileName;
|
|
39
|
+
return pathBasename === filename || JAVASCRIPT_MODULE_EXTENSIONS.some(function (ext) {
|
|
40
|
+
var _getFileNameFromUrl = getFileNameFromUrl(path),
|
|
41
|
+
fileName = _getFileNameFromUrl.fileName;
|
|
42
|
+
return fileName.endsWith(ext) ? fileName.slice(0, -ext.length) === filename : false;
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
if (_matchingPath) {
|
|
46
|
+
// For JS/TS modules, rewrite to same directory without extension
|
|
47
|
+
var pathBasename = getFileNameFromUrl(_matchingPath).fileName;
|
|
48
|
+
var nameWithoutExt = JAVASCRIPT_MODULE_EXTENSIONS.reduce(function (name, ext) {
|
|
49
|
+
return name.replace(new RegExp("\\".concat(ext, "$")), '');
|
|
50
|
+
}, pathBasename);
|
|
51
|
+
return "import ".concat(importPart, "'./").concat(nameWithoutExt, "'");
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return match;
|
|
56
|
+
});
|
|
57
|
+
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mui/internal-docs-infra",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1-alpha.1",
|
|
4
4
|
"author": "MUI Team",
|
|
5
5
|
"description": "MUI Infra - internal documentation creation tools.",
|
|
6
|
+
"type": "module",
|
|
6
7
|
"main": "./index.js",
|
|
7
8
|
"exports": {
|
|
8
9
|
"./package.json": "./package.json",
|
|
9
10
|
".": "./index.js",
|
|
10
|
-
"./*": "./*/index.js"
|
|
11
|
+
"./*": "./*/index.js",
|
|
12
|
+
"./*/types": "./*/types.js",
|
|
13
|
+
"./*/errors": "./*/errors.js"
|
|
11
14
|
},
|
|
12
15
|
"keywords": [
|
|
13
16
|
"react",
|
|
@@ -28,12 +31,23 @@
|
|
|
28
31
|
"homepage": "https://github.com/mui/mui-public/tree/master/packages/docs-infra",
|
|
29
32
|
"dependencies": {
|
|
30
33
|
"@babel/runtime": "^7.27.6",
|
|
31
|
-
"@
|
|
34
|
+
"@babel/standalone": "^7.28.1",
|
|
35
|
+
"@wooorm/starry-night": "^3.8.0",
|
|
32
36
|
"clipboard-copy": "^4.0.1",
|
|
33
|
-
"hast": "^1.0.0",
|
|
34
37
|
"hast-util-to-jsx-runtime": "^2.3.6",
|
|
38
|
+
"hast-util-to-mdast": "^10.1.2",
|
|
35
39
|
"hast-util-to-text": "^4.0.2",
|
|
36
|
-
"
|
|
40
|
+
"js-sha256": "^0.11.1",
|
|
41
|
+
"jsondiffpatch": "^0.7.3",
|
|
42
|
+
"kebab-case": "^2.0.2",
|
|
43
|
+
"prettier": "^3.5.3",
|
|
44
|
+
"rehype-parse": "^9.0.1",
|
|
45
|
+
"rehype-remark": "^10.0.1",
|
|
46
|
+
"rehype-sanitize": "^6.0.0",
|
|
47
|
+
"remark-stringify": "^11.0.0",
|
|
48
|
+
"unified": "^11.0.5",
|
|
49
|
+
"unist-util-visit": "^5.0.0",
|
|
50
|
+
"vscode-oniguruma": "^2.0.1"
|
|
37
51
|
},
|
|
38
52
|
"peerDependencies": {
|
|
39
53
|
"@types/react": "^17.0.0 || ^18.0.0 || ^19.0.0",
|
|
@@ -52,6 +66,5 @@
|
|
|
52
66
|
"engines": {
|
|
53
67
|
"node": ">=14.0.0"
|
|
54
68
|
},
|
|
55
|
-
"private": false
|
|
56
|
-
"module": "./esm/index.js"
|
|
69
|
+
"private": false
|
|
57
70
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grammars.d.ts","sourceRoot":"","sources":["../../../src/parseSource/grammars.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,QAAQ,0CAWpB,CAAC;AAEF,eAAO,MAAM,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAY/C,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import sourceJs from '@wooorm/starry-night/source.js';
|
|
2
|
+
import sourceTs from '@wooorm/starry-night/source.ts';
|
|
3
|
+
import sourceTsx from '@wooorm/starry-night/source.tsx';
|
|
4
|
+
import sourceJson from '@wooorm/starry-night/source.json';
|
|
5
|
+
import textMd from '@wooorm/starry-night/text.md';
|
|
6
|
+
import sourceMdx from '@wooorm/starry-night/source.mdx';
|
|
7
|
+
import textHtmlBasic from '@wooorm/starry-night/text.html.basic';
|
|
8
|
+
import sourceCss from '@wooorm/starry-night/source.css';
|
|
9
|
+
import sourceShell from '@wooorm/starry-night/source.shell';
|
|
10
|
+
import sourceYaml from '@wooorm/starry-night/source.yaml';
|
|
11
|
+
export var grammars = [sourceJs, sourceTs, sourceTsx, sourceJson, textMd, sourceMdx,
|
|
12
|
+
// needs sourceTsx
|
|
13
|
+
textHtmlBasic, sourceCss, sourceShell, sourceYaml];
|
|
14
|
+
export var extensionMap = {
|
|
15
|
+
'.js': 'source.js',
|
|
16
|
+
'.ts': 'source.ts',
|
|
17
|
+
'.jsx': 'source.tsx',
|
|
18
|
+
// TODO: is there a JSX grammar?
|
|
19
|
+
'.tsx': 'source.tsx',
|
|
20
|
+
'.json': 'source.json',
|
|
21
|
+
'.md': 'text.md',
|
|
22
|
+
'.mdx': 'source.mdx',
|
|
23
|
+
'.html': 'text.html.basic',
|
|
24
|
+
'.css': 'source.css',
|
|
25
|
+
'.sh': 'source.shell',
|
|
26
|
+
'.yaml': 'source.yaml'
|
|
27
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./parseSource.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/parseSource/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./parseSource.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parseSource.d.ts","sourceRoot":"","sources":["../../../src/parseSource/parseSource.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAOjD,eAAO,MAAM,WAAW,EAAE,WASzB,CAAC;AAEF,eAAO,MAAM,kBAAkB,QAAa,OAAO,CAAC,WAAW,CAM9D,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
|
|
2
|
+
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
3
|
+
import { createStarryNight } from '@wooorm/starry-night';
|
|
4
|
+
import { grammars, extensionMap } from "./grammars.js";
|
|
5
|
+
var starryNight = null;
|
|
6
|
+
export var parseSource = function parseSource(source, fileName) {
|
|
7
|
+
if (!starryNight) {
|
|
8
|
+
throw new Error('Starry Night not initialized. Use parseSourceFactory to create an initialized parseSource function.');
|
|
9
|
+
}
|
|
10
|
+
var fileType = fileName.slice(fileName.lastIndexOf('.')) || 'plaintext';
|
|
11
|
+
return starryNight.highlight(source, extensionMap[fileType] || 'plaintext');
|
|
12
|
+
};
|
|
13
|
+
export var parseSourceFactory = /*#__PURE__*/function () {
|
|
14
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
15
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
16
|
+
while (1) switch (_context.prev = _context.next) {
|
|
17
|
+
case 0:
|
|
18
|
+
if (starryNight) {
|
|
19
|
+
_context.next = 4;
|
|
20
|
+
break;
|
|
21
|
+
}
|
|
22
|
+
_context.next = 3;
|
|
23
|
+
return createStarryNight(grammars);
|
|
24
|
+
case 3:
|
|
25
|
+
starryNight = _context.sent;
|
|
26
|
+
case 4:
|
|
27
|
+
return _context.abrupt("return", parseSource);
|
|
28
|
+
case 5:
|
|
29
|
+
case "end":
|
|
30
|
+
return _context.stop();
|
|
31
|
+
}
|
|
32
|
+
}, _callee);
|
|
33
|
+
}));
|
|
34
|
+
return function parseSourceFactory() {
|
|
35
|
+
return _ref.apply(this, arguments);
|
|
36
|
+
};
|
|
37
|
+
}();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/transformRelativeMarkdownPaths/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,8BAA8B,EAAE,MAAM,kCAAkC,CAAC;AAElF,eAAe,8BAA8B,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Plugin } from 'unified';
|
|
2
|
+
/**
|
|
3
|
+
* Remark plugin that strips page file extensions from URLs.
|
|
4
|
+
* Removes /page.tsx, /page.jsx, /page.js, /page.mdx, /page.md from both absolute and relative URLs.
|
|
5
|
+
* For relative URLs, converts them to absolute paths based on the current file's location.
|
|
6
|
+
*
|
|
7
|
+
* Examples:
|
|
8
|
+
* - /components/page.tsx -> /components
|
|
9
|
+
* - ./code-highlighter/page.mdx -> /components/code-highlighter (when processed from /components/page.mdx)
|
|
10
|
+
* This allows URLs to resolve when reading in VSCode and Github
|
|
11
|
+
*/
|
|
12
|
+
export declare const transformRelativeMarkdownPaths: Plugin;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transformRelativeMarkdownPaths.d.ts","sourceRoot":"","sources":["../../../src/transformRelativeMarkdownPaths/transformRelativeMarkdownPaths.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAItC;;;;;;;;;GASG;AACH,eAAO,MAAM,8BAA8B,EAAE,MAmB5C,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { visit } from 'unist-util-visit';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Remark plugin that strips page file extensions from URLs.
|
|
6
|
+
* Removes /page.tsx, /page.jsx, /page.js, /page.mdx, /page.md from both absolute and relative URLs.
|
|
7
|
+
* For relative URLs, converts them to absolute paths based on the current file's location.
|
|
8
|
+
*
|
|
9
|
+
* Examples:
|
|
10
|
+
* - /components/page.tsx -> /components
|
|
11
|
+
* - ./code-highlighter/page.mdx -> /components/code-highlighter (when processed from /components/page.mdx)
|
|
12
|
+
* This allows URLs to resolve when reading in VSCode and Github
|
|
13
|
+
*/
|
|
14
|
+
export var transformRelativeMarkdownPaths = function transformRelativeMarkdownPaths() {
|
|
15
|
+
return function (tree, file) {
|
|
16
|
+
visit(tree, 'link', function (node) {
|
|
17
|
+
if (node.url) {
|
|
18
|
+
node.url = node.url.replace(/\/page\.(tsx|jsx|js|mdx|md)$/g, '');
|
|
19
|
+
node.url = node.url.replace(/\/page\.(tsx|jsx|js|mdx|md)(\?[^#]*)?(#.*)?$/g, '$2$3');
|
|
20
|
+
if (node.url.startsWith('./') && file.path) {
|
|
21
|
+
var currentDir = path.dirname(file.path);
|
|
22
|
+
var appIndex = currentDir.indexOf('/app/');
|
|
23
|
+
var baseDir = appIndex !== -1 ? currentDir.substring(appIndex + 4) : '/';
|
|
24
|
+
node.url = path.join('/', baseDir, node.url.replace(/^\.\//, ''));
|
|
25
|
+
}
|
|
26
|
+
node.url = node.url.replace(/\/$/, '');
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./transformTsToJs.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/transformTsToJs/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./transformTsToJs.js";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Options as PrettierOptions } from 'prettier';
|
|
2
|
+
/**
|
|
3
|
+
* Strips TypeScript types and decorators from code (including React in TSX),
|
|
4
|
+
* preserving blank lines and optionally formatting with Prettier.
|
|
5
|
+
*
|
|
6
|
+
* @param code - The source code string to transform.
|
|
7
|
+
* @param filename - The name of the file (e.g. "foo.ts" or "Foo.tsx").
|
|
8
|
+
* Determines whether TSX parsing is enabled.
|
|
9
|
+
* @param prettierConfig - `true` for default formatting, `false` to skip,
|
|
10
|
+
* or a Prettier options object to customize.
|
|
11
|
+
* @returns The transformed (and optionally formatted) code.
|
|
12
|
+
*/
|
|
13
|
+
export declare function removeTypes(code: string, filename?: string, prettierConfig?: PrettierOptions | boolean): Promise<string>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"removeTypes.d.ts","sourceRoot":"","sources":["../../../src/transformTsToJs/removeTypes.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,UAAU,CAAC;AAG3D;;;;;;;;;;GAUG;AACH,wBAAsB,WAAW,CAC/B,IAAI,EAAE,MAAM,EACZ,QAAQ,SAAY,EACpB,cAAc,GAAE,eAAe,GAAG,OAAc,GAC/C,OAAO,CAAC,MAAM,CAAC,CAkGjB"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
|
|
2
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
3
|
+
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
4
|
+
// Based on https://github.com/ember-cli/babel-remove-types/blob/fc3be010e99c4f4926fd70d00242d6777ab1b8d7/src/index.ts
|
|
5
|
+
// Converted to use Babel standalone, with added TSX support
|
|
6
|
+
|
|
7
|
+
import * as Babel from '@babel/standalone';
|
|
8
|
+
import prettier from 'prettier/standalone';
|
|
9
|
+
import prettierPluginEstree from 'prettier/plugins/estree';
|
|
10
|
+
import parserBabel from 'prettier/parser-babel';
|
|
11
|
+
/**
|
|
12
|
+
* Strips TypeScript types and decorators from code (including React in TSX),
|
|
13
|
+
* preserving blank lines and optionally formatting with Prettier.
|
|
14
|
+
*
|
|
15
|
+
* @param code - The source code string to transform.
|
|
16
|
+
* @param filename - The name of the file (e.g. "foo.ts" or "Foo.tsx").
|
|
17
|
+
* Determines whether TSX parsing is enabled.
|
|
18
|
+
* @param prettierConfig - `true` for default formatting, `false` to skip,
|
|
19
|
+
* or a Prettier options object to customize.
|
|
20
|
+
* @returns The transformed (and optionally formatted) code.
|
|
21
|
+
*/
|
|
22
|
+
export function removeTypes(_x) {
|
|
23
|
+
return _removeTypes.apply(this, arguments);
|
|
24
|
+
}
|
|
25
|
+
function _removeTypes() {
|
|
26
|
+
_removeTypes = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(code) {
|
|
27
|
+
var filename,
|
|
28
|
+
prettierConfig,
|
|
29
|
+
removeComments,
|
|
30
|
+
isTSX,
|
|
31
|
+
transformed,
|
|
32
|
+
fixed,
|
|
33
|
+
standardPrettierOptions,
|
|
34
|
+
mergedPrettierOptions,
|
|
35
|
+
_args = arguments;
|
|
36
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
37
|
+
while (1) switch (_context.prev = _context.next) {
|
|
38
|
+
case 0:
|
|
39
|
+
filename = _args.length > 1 && _args[1] !== undefined ? _args[1] : 'file.ts';
|
|
40
|
+
prettierConfig = _args.length > 2 && _args[2] !== undefined ? _args[2] : true;
|
|
41
|
+
// Babel collapses newlines all over the place, which messes with the formatting of almost any
|
|
42
|
+
// code you pass to it. To preserve the formatting, we go through and mark all the empty lines
|
|
43
|
+
// in the code string *before* transforming it. This allows us to go back through after the
|
|
44
|
+
// transformation re-insert the empty lines in the correct place relative to the new code that
|
|
45
|
+
// has been generated.
|
|
46
|
+
code = code.replace(/\n\n+/g, '/* ___NEWLINE___ */\n');
|
|
47
|
+
|
|
48
|
+
// When removing TS-specific constructs (e.g. interfaces), we want to make sure we also remove
|
|
49
|
+
// any comments that are associated with those constructs, since otherwise we'll be left with
|
|
50
|
+
// comments that refer to something that isn't actually there.
|
|
51
|
+
// Credit to https://github.com/cyco130/detype for figuring out this very useful pattern
|
|
52
|
+
removeComments = {
|
|
53
|
+
enter: function enter(nodePath) {
|
|
54
|
+
if (!nodePath.node.leadingComments) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
for (var i = nodePath.node.leadingComments.length - 1; i >= 0; i -= 1) {
|
|
58
|
+
var comment = nodePath.node.leadingComments[i];
|
|
59
|
+
if (code.slice(comment.end).match(/^\s*\n\s*\n/) || comment.value.includes('___NEWLINE___')) {
|
|
60
|
+
// There is at least one empty line between the comment and the TypeScript specific construct
|
|
61
|
+
// We should keep this comment and those before it
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
comment.value = '___REMOVE_ME___';
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
isTSX = /\.tsx$/i.test(filename);
|
|
69
|
+
transformed = Babel.transform(code, {
|
|
70
|
+
filename: filename,
|
|
71
|
+
plugins: [{
|
|
72
|
+
name: 'comment-remover',
|
|
73
|
+
visitor: {
|
|
74
|
+
TSTypeAliasDeclaration: removeComments,
|
|
75
|
+
TSInterfaceDeclaration: removeComments,
|
|
76
|
+
TSDeclareFunction: removeComments,
|
|
77
|
+
TSDeclareMethod: removeComments,
|
|
78
|
+
TSImportType: removeComments,
|
|
79
|
+
TSModuleDeclaration: removeComments
|
|
80
|
+
}
|
|
81
|
+
}, ['transform-typescript', {
|
|
82
|
+
onlyRemoveTypeImports: true,
|
|
83
|
+
isTSX: isTSX,
|
|
84
|
+
allExtensions: true
|
|
85
|
+
}], ['proposal-decorators', {
|
|
86
|
+
legacy: true
|
|
87
|
+
}]],
|
|
88
|
+
generatorOpts: {
|
|
89
|
+
retainLines: true,
|
|
90
|
+
shouldPrintComment: function shouldPrintComment(c) {
|
|
91
|
+
return c !== '___REMOVE_ME___';
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
if (!(!transformed || !transformed.code)) {
|
|
96
|
+
_context.next = 8;
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
throw new Error('There was an issue with the Babel transform.');
|
|
100
|
+
case 8:
|
|
101
|
+
fixed = transformed.code.replace(/\/\* ___NEWLINE___ \*\//g, '\n'); // If the user has *explicitly* passed `false` here, it means they do not want us to run Prettier
|
|
102
|
+
// at all, so we bail here.
|
|
103
|
+
if (!(prettierConfig === false)) {
|
|
104
|
+
_context.next = 11;
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
return _context.abrupt("return", fixed);
|
|
108
|
+
case 11:
|
|
109
|
+
standardPrettierOptions = {
|
|
110
|
+
parser: 'babel',
|
|
111
|
+
singleQuote: true,
|
|
112
|
+
plugins: [prettierPluginEstree, parserBabel]
|
|
113
|
+
}; // If `prettierConfig` is *explicitly* true (as opposed to truthy), it means the user has opted in
|
|
114
|
+
// to default behavior either explicitly or implicitly. Either way, we run basic Prettier on it.
|
|
115
|
+
if (!(prettierConfig === true)) {
|
|
116
|
+
_context.next = 14;
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
return _context.abrupt("return", prettier.format(fixed, standardPrettierOptions));
|
|
120
|
+
case 14:
|
|
121
|
+
// If we've made it here, the user has passed their own Prettier options so we merge it with ours
|
|
122
|
+
// and let theirs overwrite any of the default settings.
|
|
123
|
+
mergedPrettierOptions = _objectSpread(_objectSpread(_objectSpread({}, standardPrettierOptions), prettierConfig), {}, {
|
|
124
|
+
plugins: standardPrettierOptions.plugins
|
|
125
|
+
});
|
|
126
|
+
return _context.abrupt("return", prettier.format(fixed, mergedPrettierOptions));
|
|
127
|
+
case 16:
|
|
128
|
+
case "end":
|
|
129
|
+
return _context.stop();
|
|
130
|
+
}
|
|
131
|
+
}, _callee);
|
|
132
|
+
}));
|
|
133
|
+
return _removeTypes.apply(this, arguments);
|
|
134
|
+
}
|