@mui/internal-docs-infra 0.11.1-canary.5 → 0.11.1-canary.6
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.
|
@@ -34,20 +34,20 @@ type AbstractCreateDemoOptions<T extends {}> = {
|
|
|
34
34
|
sourceParser?: Promise<ParseSource>;
|
|
35
35
|
sourceEnhancers?: SourceEnhancers;
|
|
36
36
|
/**
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
37
|
+
* `file://` URL of the project root used to resolve `url`s gathered from
|
|
38
|
+
* `import.meta.url`. Combined with `projectUrl` to rewrite local `file://`
|
|
39
|
+
* URLs into hosted Git URLs (e.g.
|
|
40
40
|
* `https://github.com/owner/repo/tree/<branch>/`) before they reach the
|
|
41
41
|
* `CodeHighlighter`.
|
|
42
42
|
*
|
|
43
43
|
* Typically read from an environment variable populated by the build
|
|
44
|
-
* pipeline (e.g.
|
|
45
|
-
* `
|
|
46
|
-
*
|
|
44
|
+
* pipeline (e.g. `process.env.SOURCE_CODE_ROOT_DIR` from
|
|
45
|
+
* `withDeploymentConfig`). When either `projectDir` or `projectUrl` is
|
|
46
|
+
* missing, URLs are left untouched.
|
|
47
47
|
*/
|
|
48
|
-
|
|
48
|
+
projectDir?: string;
|
|
49
49
|
/**
|
|
50
|
-
* Public URL prefix that maps to `
|
|
50
|
+
* Public URL prefix that maps to `projectDir`. See `projectDir` for
|
|
51
51
|
* details.
|
|
52
52
|
*/
|
|
53
53
|
projectUrl?: string;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { pathToFileURL } from 'node:url';
|
|
3
2
|
import { CodeHighlighter } from "../CodeHighlighter/index.mjs";
|
|
4
3
|
import { applyUrlPrefixToCode, applyUrlPrefixToGlobalsCode, replaceUrlPrefix } from "../pipeline/loaderUtils/applyUrlPrefix.mjs";
|
|
5
4
|
import { createDemoDataWithVariants } from "../createDemoData/index.mjs";
|
|
@@ -26,7 +25,7 @@ export function abstractCreateDemo(options, url, variants, meta) {
|
|
|
26
25
|
// the `urlPrefix` prop on `<CodeHighlighter>` (forwarded into
|
|
27
26
|
// `loadIsomorphicCodeVariant`) takes care of rewriting the loaded variant after the
|
|
28
27
|
// file is read.
|
|
29
|
-
const urlPrefix = resolveUrlPrefix(options.
|
|
28
|
+
const urlPrefix = resolveUrlPrefix(options.projectDir, options.projectUrl);
|
|
30
29
|
const resolvedUrl = urlPrefix && demoData.precompute ? replaceUrlPrefix(demoData.url, urlPrefix) ?? demoData.url : demoData.url;
|
|
31
30
|
const resolvedPrecompute = urlPrefix && demoData.precompute ? applyUrlPrefixToCode(demoData.precompute, urlPrefix) : demoData.precompute;
|
|
32
31
|
const resolvedGlobalCode = urlPrefix && globalCode.length > 0 ? applyUrlPrefixToGlobalsCode(globalCode, urlPrefix) : globalCode;
|
|
@@ -87,11 +86,11 @@ export function abstractCreateDemo(options, url, variants, meta) {
|
|
|
87
86
|
}
|
|
88
87
|
return DemoComponent;
|
|
89
88
|
}
|
|
90
|
-
function resolveUrlPrefix(
|
|
91
|
-
if (!
|
|
89
|
+
function resolveUrlPrefix(projectDir, projectUrl) {
|
|
90
|
+
if (!projectDir || !projectUrl) {
|
|
92
91
|
return undefined;
|
|
93
92
|
}
|
|
94
|
-
const from = `${
|
|
93
|
+
const from = projectDir.endsWith('/') ? projectDir : `${projectDir}/`;
|
|
95
94
|
const to = projectUrl.endsWith('/') ? projectUrl : `${projectUrl}/`;
|
|
96
95
|
return {
|
|
97
96
|
from,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mui/internal-docs-infra",
|
|
3
|
-
"version": "0.11.1-canary.
|
|
3
|
+
"version": "0.11.1-canary.6",
|
|
4
4
|
"author": "MUI Team",
|
|
5
5
|
"description": "MUI Infra - internal documentation creation tools.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -686,5 +686,5 @@
|
|
|
686
686
|
"bin": {
|
|
687
687
|
"docs-infra": "./cli/index.mjs"
|
|
688
688
|
},
|
|
689
|
-
"gitSha": "
|
|
689
|
+
"gitSha": "dc47acc4c60d02db487df3900491752cf51fe989"
|
|
690
690
|
}
|
|
@@ -3,6 +3,7 @@ import { execSync } from 'node:child_process';
|
|
|
3
3
|
import { readFileSync } from 'node:fs';
|
|
4
4
|
import * as os from 'node:os';
|
|
5
5
|
import { dirname, join } from 'node:path';
|
|
6
|
+
import { pathToFileURL } from 'node:url';
|
|
6
7
|
|
|
7
8
|
// Read Next.js version to handle version-specific config
|
|
8
9
|
const nextMajorVersion = parseInt(pkgJson.version.split('.')[0], 10);
|
|
@@ -59,10 +60,22 @@ process.env.SHOW_PRIVATE_PAGES = SHOW_PRIVATE_PAGES;
|
|
|
59
60
|
* Resolves to an empty string when neither source yields a value.
|
|
60
61
|
*/
|
|
61
62
|
const repoRootDir = findRepoRootDir();
|
|
62
|
-
|
|
63
|
+
// Stored as a `file://` URL (with exactly one trailing slash) so consumers
|
|
64
|
+
// can use it in isomorphic code without depending on Node's `url` module to
|
|
65
|
+
// convert from a filesystem path. We normalize via the `URL` object so a repo
|
|
66
|
+
// root that already ends in a separator (e.g. `/` or `C:\` at a drive root)
|
|
67
|
+
// doesn't produce a double-slash suffix.
|
|
68
|
+
const SOURCE_CODE_ROOT_DIR = repoRootDir ? toDirFileUrl(repoRootDir) : '';
|
|
63
69
|
const SOURCE_CODE_ROOT_URL = resolveSourceCodeRootUrl(repoRootDir);
|
|
64
|
-
process.env.
|
|
70
|
+
process.env.SOURCE_CODE_ROOT_DIR = SOURCE_CODE_ROOT_DIR;
|
|
65
71
|
process.env.SOURCE_CODE_ROOT_URL = SOURCE_CODE_ROOT_URL;
|
|
72
|
+
function toDirFileUrl(dir) {
|
|
73
|
+
const url = pathToFileURL(dir);
|
|
74
|
+
if (!url.pathname.endsWith('/')) {
|
|
75
|
+
url.pathname = `${url.pathname}/`;
|
|
76
|
+
}
|
|
77
|
+
return url.href;
|
|
78
|
+
}
|
|
66
79
|
function resolveSourceCodeRootUrl(rootDir) {
|
|
67
80
|
const repositoryUrl = process.env.REPOSITORY_URL ?? (rootDir ? readRepositoryUrlFromPackageJson(rootDir) : undefined);
|
|
68
81
|
const headEnv = process.env.HEAD;
|
|
@@ -189,10 +202,10 @@ export function withDeploymentConfig(nextConfig) {
|
|
|
189
202
|
// commit (e.g. `https://github.com/owner/repo/tree/<branch>/`). Derived
|
|
190
203
|
// from REPOSITORY_URL/BRANCH with package.json/git fallbacks.
|
|
191
204
|
SOURCE_CODE_ROOT_URL,
|
|
192
|
-
//
|
|
193
|
-
// `import.meta.url` file URLs into paths relative to the repo
|
|
194
|
-
// before applying SOURCE_CODE_ROOT_URL.
|
|
195
|
-
|
|
205
|
+
// `file://` URL (with trailing slash) of the repository root, used to
|
|
206
|
+
// translate `import.meta.url` file URLs into paths relative to the repo
|
|
207
|
+
// root before applying SOURCE_CODE_ROOT_URL.
|
|
208
|
+
SOURCE_CODE_ROOT_DIR,
|
|
196
209
|
// For template images
|
|
197
210
|
TEMPLATE_IMAGE_URL: ''
|
|
198
211
|
},
|