@mui/internal-code-infra 0.1.1-canary.12 → 0.1.1-canary.14
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/build/remark/config.d.mts +5 -14
- package/build/utils/build.d.mts +14 -0
- package/package.json +3 -2
- package/src/cli/cmdBuild.mjs +2 -0
- package/src/remark/config.mjs +41 -4
- package/src/utils/build.mjs +34 -0
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import remarkGfm from 'remark-gfm';
|
|
2
|
-
import remarkLint from 'remark-lint';
|
|
3
1
|
/**
|
|
4
2
|
* Returns a remark preset wiring the MUI-authored remark-lint plugins together
|
|
5
3
|
* with a curated set of community plugins. Drop this into `.remarkrc.mjs`:
|
|
@@ -23,21 +21,14 @@ import remarkLint from 'remark-lint';
|
|
|
23
21
|
* ```
|
|
24
22
|
*
|
|
25
23
|
* @param {Object} [options]
|
|
24
|
+
* @param {boolean} [options.allowDefinitionComments=false] Allow titled `[//]` link-reference comments.
|
|
26
25
|
* @param {Array<{ files: string | string[], rules: Record<string, false | unknown[]> }>} [options.overrides]
|
|
26
|
+
* @returns {import('unified').Preset}
|
|
27
27
|
*/
|
|
28
|
-
export declare function createRemarkConfig({ overrides }?: {
|
|
28
|
+
export declare function createRemarkConfig({ overrides, allowDefinitionComments }?: {
|
|
29
|
+
allowDefinitionComments?: boolean;
|
|
29
30
|
overrides?: Array<{
|
|
30
31
|
files: string | string[];
|
|
31
32
|
rules: Record<string, false | unknown[]>;
|
|
32
33
|
}>;
|
|
33
|
-
}):
|
|
34
|
-
settings: {
|
|
35
|
-
bullet: string;
|
|
36
|
-
emphasis: string;
|
|
37
|
-
fence: string;
|
|
38
|
-
listItemIndent: string;
|
|
39
|
-
resourceLink: boolean;
|
|
40
|
-
rule: string;
|
|
41
|
-
};
|
|
42
|
-
plugins: (any[] | typeof remarkGfm | typeof remarkLint)[];
|
|
43
|
-
};
|
|
34
|
+
}): import('unified').Preset;
|
package/build/utils/build.d.mts
CHANGED
|
@@ -93,6 +93,20 @@ export declare function validatePkgJson(packageJson: Record<string, any>, option
|
|
|
93
93
|
skipMainCheck?: boolean;
|
|
94
94
|
enableReactCompiler?: boolean;
|
|
95
95
|
}): void;
|
|
96
|
+
/**
|
|
97
|
+
* Validates that "engines.node" in package.json doesn't allow Node.js versions older than the
|
|
98
|
+
* "node" browserslist environment, which the CommonJS bundle is compiled for. Otherwise the
|
|
99
|
+
* build can emit syntax that the oldest supported Node.js version can't run.
|
|
100
|
+
* Targets are resolved the same way `@babel/preset-env` resolves them during the build.
|
|
101
|
+
* @param {{ name?: string; engines?: { node?: string } }} packageJson
|
|
102
|
+
* @param {string} cwd - The package directory, used to find the browserslist config.
|
|
103
|
+
*/
|
|
104
|
+
export declare function validateEnginesNode(packageJson: {
|
|
105
|
+
name?: string;
|
|
106
|
+
engines?: {
|
|
107
|
+
node?: string;
|
|
108
|
+
};
|
|
109
|
+
}, cwd: string): void;
|
|
96
110
|
/**
|
|
97
111
|
* Marks the start and end of a function execution for performance measurement.
|
|
98
112
|
* Uses the Performance API to create marks and measure the duration.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mui/internal-code-infra",
|
|
3
|
-
"version": "0.1.1-canary.
|
|
3
|
+
"version": "0.1.1-canary.14",
|
|
4
4
|
"author": "MUI Team",
|
|
5
5
|
"description": "Infra scripts and configs to be used across MUI repos.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -56,6 +56,7 @@
|
|
|
56
56
|
"@argos-ci/core": "6.8.7",
|
|
57
57
|
"@babel/cli": "^8.0.6",
|
|
58
58
|
"@babel/core": "^8.0.7",
|
|
59
|
+
"@babel/helper-compilation-targets": "^8.0.7",
|
|
59
60
|
"@babel/plugin-syntax-jsx": "^8.0.1",
|
|
60
61
|
"@babel/plugin-syntax-typescript": "^8.0.3",
|
|
61
62
|
"@babel/plugin-transform-react-pure-annotations": "^8.0.1",
|
|
@@ -189,7 +190,7 @@
|
|
|
189
190
|
"publishConfig": {
|
|
190
191
|
"access": "public"
|
|
191
192
|
},
|
|
192
|
-
"gitSha": "
|
|
193
|
+
"gitSha": "a8db5a1b050cfffe37636173e3d1e18537baaca1",
|
|
193
194
|
"scripts": {
|
|
194
195
|
"build": "tsc -p tsconfig.build.json",
|
|
195
196
|
"typescript": "tsc -noEmit",
|
package/src/cli/cmdBuild.mjs
CHANGED
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
createPackageExports,
|
|
13
13
|
createPackageImports,
|
|
14
14
|
getOutExtension,
|
|
15
|
+
validateEnginesNode,
|
|
15
16
|
validatePkgJson,
|
|
16
17
|
} from '../utils/build.mjs';
|
|
17
18
|
import { readPnpmConfig } from '../utils/pnpm.mjs';
|
|
@@ -266,6 +267,7 @@ export default /** @type {import('yargs').CommandModule<{}, Args>} */ ({
|
|
|
266
267
|
const pkgJsonPath = path.join(cwd, 'package.json');
|
|
267
268
|
const packageJson = JSON.parse(await fs.readFile(pkgJsonPath, { encoding: 'utf8' }));
|
|
268
269
|
validatePkgJson(packageJson, { skipMainCheck: args.skipMainCheck, enableReactCompiler });
|
|
270
|
+
validateEnginesNode(packageJson, cwd);
|
|
269
271
|
|
|
270
272
|
const buildDirBase = /** @type {string} */ (packageJson.publishConfig?.directory);
|
|
271
273
|
const buildDir = path.join(cwd, buildDirBase);
|
package/src/remark/config.mjs
CHANGED
|
@@ -97,6 +97,37 @@ function withOverrides(name, plugin, baseSettings, overrideEntries) {
|
|
|
97
97
|
return wrapper;
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
+
/**
|
|
101
|
+
* Allows link-reference comments while retaining diagnostics for real links and definitions.
|
|
102
|
+
* Existing docs generators use these markers in both Markdown and MDX and parse them as metadata.
|
|
103
|
+
* Authored MDX can use JSX comments without this compatibility option.
|
|
104
|
+
*
|
|
105
|
+
* @param {import('unified').Plugin<any[], any, any>} plugin
|
|
106
|
+
*/
|
|
107
|
+
function withDefinitionComments(plugin) {
|
|
108
|
+
/** @param {any[]} settings */
|
|
109
|
+
return function wrapper(...settings) {
|
|
110
|
+
const processor = unified().use(plugin, ...settings);
|
|
111
|
+
/** @type {import('unified').Transformer} */
|
|
112
|
+
return async function transformer(tree, file) {
|
|
113
|
+
const previousMessages = file.messages.length;
|
|
114
|
+
await processor.run(tree, file);
|
|
115
|
+
file.messages = file.messages.filter((message, index) => {
|
|
116
|
+
const node = message.ancestors?.at(-1);
|
|
117
|
+
return !(
|
|
118
|
+
index >= previousMessages &&
|
|
119
|
+
node?.type === 'definition' &&
|
|
120
|
+
'identifier' in node &&
|
|
121
|
+
node.identifier === '//' &&
|
|
122
|
+
'title' in node &&
|
|
123
|
+
typeof node.title === 'string' &&
|
|
124
|
+
node.title.length > 0
|
|
125
|
+
);
|
|
126
|
+
});
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
|
|
100
131
|
/**
|
|
101
132
|
* Returns a remark preset wiring the MUI-authored remark-lint plugins together
|
|
102
133
|
* with a curated set of community plugins. Drop this into `.remarkrc.mjs`:
|
|
@@ -120,9 +151,11 @@ function withOverrides(name, plugin, baseSettings, overrideEntries) {
|
|
|
120
151
|
* ```
|
|
121
152
|
*
|
|
122
153
|
* @param {Object} [options]
|
|
154
|
+
* @param {boolean} [options.allowDefinitionComments=false] Allow titled `[//]` link-reference comments.
|
|
123
155
|
* @param {Array<{ files: string | string[], rules: Record<string, false | unknown[]> }>} [options.overrides]
|
|
156
|
+
* @returns {import('unified').Preset}
|
|
124
157
|
*/
|
|
125
|
-
export function createRemarkConfig({ overrides = [] } = {}) {
|
|
158
|
+
export function createRemarkConfig({ overrides = [], allowDefinitionComments = false } = {}) {
|
|
126
159
|
for (const override of overrides) {
|
|
127
160
|
const unknown = Object.keys(override.rules).filter((ruleName) => !(ruleName in RULES));
|
|
128
161
|
if (unknown.length > 0) {
|
|
@@ -130,10 +163,14 @@ export function createRemarkConfig({ overrides = [] } = {}) {
|
|
|
130
163
|
}
|
|
131
164
|
}
|
|
132
165
|
|
|
166
|
+
/** @type {import('unified').PluggableList} */
|
|
133
167
|
const entries = Object.entries(RULES).map(([name, entry]) => {
|
|
134
|
-
const [
|
|
135
|
-
entry
|
|
136
|
-
|
|
168
|
+
const [rulePlugin, baseSettings] =
|
|
169
|
+
/** @type {[import('unified').Plugin<any[], any, any>, any]} */ (entry);
|
|
170
|
+
const plugin =
|
|
171
|
+
allowDefinitionComments && (name === 'no-empty-url' || name === 'no-unused-definitions')
|
|
172
|
+
? withDefinitionComments(rulePlugin)
|
|
173
|
+
: rulePlugin;
|
|
137
174
|
const overrideEntries = overrides
|
|
138
175
|
.filter((override) => name in override.rules)
|
|
139
176
|
.map((override) => ({ files: override.files, settings: override.rules[name] }));
|
package/src/utils/build.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as fs from 'node:fs/promises';
|
|
2
2
|
import * as path from 'node:path';
|
|
3
|
+
import getTargets from '@babel/helper-compilation-targets';
|
|
3
4
|
import { globby } from 'globby';
|
|
4
5
|
import * as semver from 'semver';
|
|
5
6
|
|
|
@@ -867,6 +868,39 @@ export function validatePkgJson(packageJson, options = {}) {
|
|
|
867
868
|
}
|
|
868
869
|
}
|
|
869
870
|
|
|
871
|
+
/**
|
|
872
|
+
* Validates that "engines.node" in package.json doesn't allow Node.js versions older than the
|
|
873
|
+
* "node" browserslist environment, which the CommonJS bundle is compiled for. Otherwise the
|
|
874
|
+
* build can emit syntax that the oldest supported Node.js version can't run.
|
|
875
|
+
* Targets are resolved the same way `@babel/preset-env` resolves them during the build.
|
|
876
|
+
* @param {{ name?: string; engines?: { node?: string } }} packageJson
|
|
877
|
+
* @param {string} cwd - The package directory, used to find the browserslist config.
|
|
878
|
+
*/
|
|
879
|
+
export function validateEnginesNode(packageJson, cwd) {
|
|
880
|
+
const enginesNode = packageJson.engines?.node;
|
|
881
|
+
if (!enginesNode) {
|
|
882
|
+
return;
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
const minEnginesVersion = semver.minVersion(enginesNode);
|
|
886
|
+
if (!minEnginesVersion) {
|
|
887
|
+
throw new Error(
|
|
888
|
+
`Unable to determine the minimum Node.js version from "engines.node" in "${packageJson.name}" package.json: "${enginesNode}".`,
|
|
889
|
+
);
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
const targetNode = getTargets(undefined, { configPath: cwd, browserslistEnv: 'node' }).node;
|
|
893
|
+
if (!targetNode) {
|
|
894
|
+
return;
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
if (semver.gt(targetNode, minEnginesVersion)) {
|
|
898
|
+
throw new Error(
|
|
899
|
+
`"engines.node" in "${packageJson.name}" package.json allows Node.js ${minEnginesVersion.version}, but the "node" browserslist environment compiles for Node.js ${targetNode} and up. Raise "engines.node" to at least ${targetNode}, or lower the "node" browserslist target.`,
|
|
900
|
+
);
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
|
|
870
904
|
/**
|
|
871
905
|
* Marks the start and end of a function execution for performance measurement.
|
|
872
906
|
* Uses the Performance API to create marks and measure the duration.
|