@mui/internal-code-infra 0.0.4-canary.4 → 0.0.4-canary.40

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.
Files changed (101) hide show
  1. package/README.md +19 -8
  2. package/build/babel-config.d.mts +11 -3
  3. package/build/brokenLinksChecker/crawlWorker.d.mts +1 -0
  4. package/build/brokenLinksChecker/index.d.mts +44 -2
  5. package/build/changelog/types.d.ts +1 -1
  6. package/build/cli/cmdArgosPush.d.mts +2 -2
  7. package/build/cli/cmdBuild.d.mts +2 -2
  8. package/build/cli/cmdCopyFiles.d.mts +2 -2
  9. package/build/cli/cmdExtractErrorCodes.d.mts +2 -2
  10. package/build/cli/cmdGenerateChangelog.d.mts +2 -2
  11. package/build/cli/cmdGithubAuth.d.mts +2 -2
  12. package/build/cli/cmdListWorkspaces.d.mts +4 -2
  13. package/build/cli/cmdNetlifyIgnore.d.mts +2 -2
  14. package/build/cli/cmdPublish.d.mts +4 -2
  15. package/build/cli/cmdPublishCanary.d.mts +3 -2
  16. package/build/cli/cmdPublishNewPackage.d.mts +4 -2
  17. package/build/cli/cmdSetVersionOverrides.d.mts +2 -2
  18. package/build/cli/cmdVale.d.mts +46 -0
  19. package/build/cli/cmdValidateBuiltTypes.d.mts +2 -2
  20. package/build/eslint/baseConfig.d.mts +3 -1
  21. package/build/eslint/mui/rules/disallow-react-api-in-server-components.d.mts +2 -2
  22. package/build/eslint/mui/rules/docgen-ignore-before-comment.d.mts +2 -2
  23. package/build/eslint/mui/rules/no-guarded-throw.d.mts +31 -0
  24. package/build/eslint/mui/rules/no-restricted-resolved-imports.d.mts +2 -2
  25. package/build/eslint/mui/rules/nodeEnvUtils.d.mts +18 -0
  26. package/build/markdownlint/duplicate-h1.d.mts +1 -1
  27. package/build/markdownlint/git-diff.d.mts +1 -1
  28. package/build/markdownlint/index.d.mts +1 -1
  29. package/build/markdownlint/straight-quotes.d.mts +1 -1
  30. package/build/markdownlint/table-alignment.d.mts +1 -1
  31. package/build/markdownlint/terminal-language.d.mts +1 -1
  32. package/build/remark/config.d.mts +43 -0
  33. package/build/remark/createLintTester.d.mts +10 -0
  34. package/build/remark/firstBlockHeading.d.mts +4 -0
  35. package/build/remark/gitDiff.d.mts +2 -0
  36. package/build/remark/noSpaceInLinks.d.mts +2 -0
  37. package/build/remark/straightQuotes.d.mts +2 -0
  38. package/build/remark/tableAlignment.d.mts +2 -0
  39. package/build/remark/terminalLanguage.d.mts +2 -0
  40. package/build/utils/build.d.mts +3 -3
  41. package/build/utils/github.d.mts +1 -1
  42. package/build/utils/pnpm.d.mts +68 -2
  43. package/build/utils/testUtils.d.mts +7 -0
  44. package/package.json +59 -32
  45. package/src/babel-config.mjs +9 -3
  46. package/src/brokenLinksChecker/__fixtures__/static-site/index.html +1 -0
  47. package/src/brokenLinksChecker/__fixtures__/static-site/invalid-html.html +15 -0
  48. package/src/brokenLinksChecker/crawlWorker.mjs +200 -0
  49. package/src/brokenLinksChecker/index.mjs +213 -164
  50. package/src/brokenLinksChecker/index.test.ts +63 -13
  51. package/src/changelog/categorizeCommits.test.ts +5 -5
  52. package/src/changelog/fetchChangelogs.mjs +6 -2
  53. package/src/changelog/parseCommitLabels.test.ts +5 -5
  54. package/src/changelog/renderChangelog.mjs +1 -1
  55. package/src/changelog/types.ts +1 -1
  56. package/src/cli/cmdListWorkspaces.mjs +9 -2
  57. package/src/cli/cmdNetlifyIgnore.mjs +4 -88
  58. package/src/cli/cmdPublish.mjs +51 -14
  59. package/src/cli/cmdPublishCanary.mjs +139 -107
  60. package/src/cli/cmdPublishNewPackage.mjs +27 -6
  61. package/src/cli/cmdVale.mjs +513 -0
  62. package/src/cli/cmdVale.test.mjs +644 -0
  63. package/src/cli/index.mjs +2 -0
  64. package/src/eslint/baseConfig.mjs +45 -20
  65. package/src/eslint/docsConfig.mjs +2 -1
  66. package/src/eslint/jsonConfig.mjs +2 -1
  67. package/src/eslint/mui/config.mjs +20 -1
  68. package/src/eslint/mui/index.mjs +2 -0
  69. package/src/eslint/mui/rules/no-guarded-throw.mjs +115 -0
  70. package/src/eslint/mui/rules/no-guarded-throw.test.mjs +206 -0
  71. package/src/eslint/mui/rules/nodeEnvUtils.mjs +52 -0
  72. package/src/eslint/mui/rules/require-dev-wrapper.mjs +25 -40
  73. package/src/eslint/testConfig.mjs +2 -1
  74. package/src/estree-typescript.d.ts +1 -1
  75. package/src/remark/config.mjs +157 -0
  76. package/src/remark/createLintTester.mjs +19 -0
  77. package/src/remark/firstBlockHeading.mjs +87 -0
  78. package/src/remark/firstBlockHeading.test.mjs +107 -0
  79. package/src/remark/gitDiff.mjs +43 -0
  80. package/src/remark/gitDiff.test.mjs +45 -0
  81. package/src/remark/noSpaceInLinks.mjs +42 -0
  82. package/src/remark/noSpaceInLinks.test.mjs +22 -0
  83. package/src/remark/straightQuotes.mjs +31 -0
  84. package/src/remark/straightQuotes.test.mjs +25 -0
  85. package/src/remark/tableAlignment.mjs +23 -0
  86. package/src/remark/tableAlignment.test.mjs +28 -0
  87. package/src/remark/terminalLanguage.mjs +19 -0
  88. package/src/remark/terminalLanguage.test.mjs +17 -0
  89. package/src/untyped-plugins.d.ts +11 -11
  90. package/src/utils/build.test.mjs +546 -575
  91. package/src/utils/pnpm.mjs +192 -3
  92. package/src/utils/pnpm.test.mjs +580 -0
  93. package/src/utils/testUtils.mjs +18 -0
  94. package/src/utils/typescript.test.mjs +249 -272
  95. package/vale/.vale.ini +1 -0
  96. package/vale/styles/MUI/CorrectReferenceAllCases.yml +43 -0
  97. package/vale/styles/MUI/CorrectRererenceCased.yml +14 -0
  98. package/vale/styles/MUI/GoogleLatin.yml +11 -0
  99. package/vale/styles/MUI/MuiBrandName.yml +22 -0
  100. package/vale/styles/MUI/NoBritish.yml +112 -0
  101. package/vale/styles/MUI/NoCompanyName.yml +17 -0
@@ -31,6 +31,7 @@ export type GetWorkspacePackagesOptions = {
31
31
  publicOnly?: boolean;
32
32
  nonPublishedOnly?: boolean;
33
33
  cwd?: string;
34
+ filter?: string[];
34
35
  };
35
36
  export declare function getWorkspacePackages(options?: {
36
37
  publicOnly: true;
@@ -49,13 +50,78 @@ export declare function getWorkspacePackages(options?: GetWorkspacePackagesOptio
49
50
  * @returns {Promise<VersionInfo>} Version information
50
51
  */
51
52
  export declare function getPackageVersionInfo(packageName: string, baseVersion: string): Promise<VersionInfo>;
53
+ export type PublishSummaryEntry = {
54
+ name: string;
55
+ version: string;
56
+ };
57
+ /**
58
+ * @typedef {Object} PublishSummaryEntry
59
+ * @property {string} name
60
+ * @property {string} version
61
+ */
52
62
  /**
53
63
  * Publish packages with the given options
54
64
  * @param {PublicPackage[]} packages - Packages to publish
55
65
  * @param {PublishOptions} [options={}] - Publishing options
56
- * @returns {Promise<void>}
66
+ * @returns {Promise<PublishSummaryEntry[]>}
67
+ */
68
+ export declare function publishPackages(packages: PublicPackage[], options?: PublishOptions): Promise<PublishSummaryEntry[]>;
69
+ export type GetTransitiveDependenciesOptions = {
70
+ workspacePathByName?: Map<string, string>;
71
+ includeDev?: boolean;
72
+ };
73
+ /**
74
+ * @typedef {Object} GetTransitiveDependenciesOptions
75
+ * @property {Map<string, string>} [workspacePathByName] - Map of workspace package name to directory path
76
+ * @property {boolean} [includeDev=true] - Whether to include devDependencies in the traversal
77
+ */
78
+ /**
79
+ * Get all transitive workspace dependencies for a set of packages.
80
+ *
81
+ * Only follows deps whose version spec starts with `workspace:` (e.g. `workspace:*`
82
+ * or `workspace:^`), meaning they are sourced directly from the monorepo. Pinned
83
+ * external versions (e.g. `^1.0.0`) are ignored even when the package name exists
84
+ * in the workspace. Traverses `dependencies` and optionally `devDependencies`.
85
+ * Results are cached per package so each package is read from disk at most once
86
+ * regardless of how many roots depend on it.
87
+ *
88
+ * @param {string[]} packageNames - Package names to start the traversal from
89
+ * @param {GetTransitiveDependenciesOptions} [options]
90
+ * @returns {Promise<Set<string>>} All reachable workspace package names, including the input packages themselves
91
+ */
92
+ export declare function getTransitiveDependencies(packageNames: string[], options?: GetTransitiveDependenciesOptions): Promise<Set<string>>;
93
+ /**
94
+ * Pure validation logic: given a publish set and workspace maps, checks that all
95
+ * transitive hard workspace dependencies are covered and none are private.
96
+ *
97
+ * A hard dependency is one listed in `dependencies` (not `peerDependencies` or
98
+ * `devDependencies`) using a `workspace:` version specifier (e.g. `workspace:*` or
99
+ * `workspace:^`). Peer dependencies are never bundled and dev dependencies are not installed
100
+ * on consumer devices - both are excluded regardless of version specifier. Pinned-version
101
+ * references in `dependencies` are also excluded - they resolve from the registry and do
102
+ * not need to be co-published.
103
+ *
104
+ * @param {PublicPackage[]} packages - The packages intended for publishing
105
+ * @param {Map<string, PublicPackage | PrivatePackage>} workspacePackageByName - All workspace packages by name
106
+ * @param {Map<string, string>} workspacePathByName - Map of workspace package name to directory path
107
+ * @returns {Promise<{issues: string[]}>}
108
+ * List of human-readable issue strings. Empty when the dependency set is valid.
109
+ * @internal
110
+ */
111
+ export declare function checkPublishDependencies(packages: PublicPackage[], workspacePackageByName: Map<string, PublicPackage | PrivatePackage>, workspacePathByName: Map<string, string>): Promise<{
112
+ issues: string[];
113
+ }>;
114
+ /**
115
+ * Validate that a set of packages covers all of their transitive hard workspace dependencies,
116
+ * and that none of those dependencies are private (which would make them unpublishable).
117
+ *
118
+ * @param {PublicPackage[]} packages - The packages intended for publishing
119
+ * @returns {Promise<{issues: string[]}>}
120
+ * List of human-readable issue strings. Empty when the dependency set is valid.
57
121
  */
58
- export declare function publishPackages(packages: PublicPackage[], options?: PublishOptions): Promise<void>;
122
+ export declare function validatePublishDependencies(packages: PublicPackage[]): Promise<{
123
+ issues: string[];
124
+ }>;
59
125
  /**
60
126
  * Read package.json from a directory
61
127
  * @param {string} packagePath - Path to package directory
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Creates a temporary directory and registers an `onTestFinished` hook to
3
+ * remove it automatically when the current test ends — even if the test throws.
4
+ *
5
+ * @returns {Promise<string>} The path of the created temporary directory.
6
+ */
7
+ export declare function makeTempDir(): Promise<string>;
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "@mui/internal-code-infra",
3
- "version": "0.0.4-canary.4",
3
+ "version": "0.0.4-canary.40",
4
+ "author": "MUI Team",
4
5
  "description": "Infra scripts and configs to be used across MUI repos.",
5
- "type": "module",
6
6
  "license": "MIT",
7
+ "type": "module",
7
8
  "repository": {
8
9
  "type": "git",
9
10
  "url": "git+https://github.com/mui/mui-public.git",
@@ -32,6 +33,10 @@
32
33
  "types": "./build/markdownlint/index.d.mts",
33
34
  "default": "./src/markdownlint/index.mjs"
34
35
  },
36
+ "./remark": {
37
+ "types": "./build/remark/config.d.mts",
38
+ "default": "./src/remark/config.mjs"
39
+ },
35
40
  "./prettier": {
36
41
  "types": "./build/prettier.d.mts",
37
42
  "default": "./src/prettier.mjs"
@@ -52,28 +57,29 @@
52
57
  "code-infra": "./bin/code-infra.mjs"
53
58
  },
54
59
  "dependencies": {
55
- "@argos-ci/core": "^4.5.0",
60
+ "@argos-ci/core": "^5.2.0",
56
61
  "@babel/cli": "^7.28.6",
57
62
  "@babel/core": "^7.29.0",
58
63
  "@babel/plugin-syntax-jsx": "^7.28.6",
59
64
  "@babel/plugin-syntax-typescript": "^7.28.6",
60
65
  "@babel/plugin-transform-runtime": "^7.29.0",
61
- "@babel/preset-env": "^7.29.0",
66
+ "@babel/preset-env": "^7.29.2",
62
67
  "@babel/preset-react": "^7.28.5",
63
68
  "@babel/preset-typescript": "^7.28.5",
64
- "@eslint/compat": "^2.0.2",
69
+ "@eslint/compat": "^2.0.3",
70
+ "@eslint/config-helpers": "^0.5.4",
65
71
  "@eslint/js": "^10.0.1",
66
- "@eslint/json": "^1.0.1",
67
- "@inquirer/confirm": "^6.0.4",
68
- "@inquirer/select": "^5.0.4",
72
+ "@eslint/json": "^1.1.0",
73
+ "@inquirer/confirm": "^6.0.11",
74
+ "@inquirer/select": "^5.1.3",
69
75
  "@napi-rs/keyring": "^1.2.0",
70
76
  "@octokit/auth-action": "^6.0.2",
71
77
  "@octokit/oauth-methods": "^6.0.2",
72
78
  "@octokit/rest": "^22.0.1",
73
- "@pnpm/find-workspace-dir": "^1000.1.4",
74
- "@typescript-eslint/types": "^8.56.1",
75
- "@typescript-eslint/utils": "^8.56.1",
76
- "@vitest/eslint-plugin": "^1.6.9",
79
+ "@pnpm/find-workspace-dir": "^1000.1.5",
80
+ "@typescript-eslint/types": "^8.57.1",
81
+ "@typescript-eslint/utils": "^8.57.1",
82
+ "@vitest/eslint-plugin": "^1.6.11",
77
83
  "babel-plugin-optimize-clsx": "^2.6.2",
78
84
  "babel-plugin-react-compiler": "^1.0.0",
79
85
  "babel-plugin-transform-import-meta": "^2.3.3",
@@ -81,44 +87,61 @@
81
87
  "babel-plugin-transform-react-remove-prop-types": "^0.4.24",
82
88
  "babel-plugin-transform-remove-imports": "^1.8.1",
83
89
  "chalk": "^5.6.2",
84
- "clipboardy": "^5.3.0",
90
+ "clipboardy": "^5.3.1",
85
91
  "content-type": "^1.0.5",
86
92
  "env-ci": "^11.2.0",
93
+ "es-toolkit": "^1.45.1",
87
94
  "eslint-config-prettier": "^10.1.8",
88
95
  "eslint-import-resolver-typescript": "^4.4.4",
89
96
  "eslint-module-utils": "^2.12.1",
90
- "eslint-plugin-compat": "^6.2.0",
97
+ "eslint-plugin-compat": "^7.0.1",
91
98
  "eslint-plugin-import": "^2.32.0",
92
99
  "eslint-plugin-jsx-a11y": "^6.10.2",
100
+ "eslint-plugin-mdx": "^3.7.0",
93
101
  "eslint-plugin-mocha": "^11.2.0",
94
102
  "eslint-plugin-react": "^7.37.5",
95
103
  "eslint-plugin-react-compiler": "^19.1.0-rc.2",
96
104
  "eslint-plugin-react-hooks": "^7.0.1",
97
105
  "eslint-plugin-testing-library": "^7.16.0",
98
- "es-toolkit": "^1.44.0",
99
106
  "execa": "^9.6.1",
100
107
  "git-url-parse": "^16.1.0",
101
- "globals": "^16.5.0",
102
- "globby": "^16.1.1",
103
- "minimatch": "^10.2.2",
104
- "node-html-parser": "^7.0.2",
105
- "open": "^10.2.0",
108
+ "globals": "^17.5.0",
109
+ "globby": "^16.2.0",
110
+ "html-validate": "^10.13.0",
111
+ "minimatch": "^10.2.5",
112
+ "node-html-parser": "^7.1.0",
113
+ "open": "^11.0.0",
106
114
  "postcss-styled-syntax": "^0.7.1",
107
115
  "regexp.escape": "^2.0.1",
108
116
  "rehype-slug": "^6.0.0",
109
117
  "rehype-stringify": "^10.0.1",
118
+ "remark-frontmatter": "^5.0.0",
110
119
  "remark-gfm": "^4.0.1",
120
+ "remark-lint": "^10.0.1",
121
+ "remark-lint-code-block-style": "^4.0.1",
122
+ "remark-lint-fenced-code-flag": "^4.2.0",
123
+ "remark-lint-heading-increment": "^4.0.1",
124
+ "remark-lint-heading-style": "^4.0.1",
125
+ "remark-lint-no-duplicate-headings": "^4.0.1",
126
+ "remark-lint-no-empty-url": "^4.0.1",
127
+ "remark-lint-no-heading-punctuation": "^4.0.1",
128
+ "remark-lint-no-multiple-toplevel-headings": "^4.0.1",
129
+ "remark-lint-no-undefined-references": "^5.0.2",
130
+ "remark-lint-no-unused-definitions": "^4.0.2",
131
+ "remark-lint-table-pipes": "^5.0.1",
111
132
  "remark-parse": "^11.0.0",
112
133
  "remark-rehype": "^11.1.2",
113
134
  "resolve-pkg-maps": "^1.0.0",
114
135
  "semver": "^7.7.4",
115
136
  "stylelint-config-standard": "^40.0.0",
116
- "typescript-eslint": "^8.56.1",
137
+ "typescript-eslint": "^8.57.1",
117
138
  "unified": "^11.0.5",
139
+ "unified-lint-rule": "^3.0.1",
140
+ "unist-util-visit": "^5.1.0",
118
141
  "yargs": "^18.0.0",
119
- "@mui/internal-babel-plugin-display-name": "1.0.4-canary.14",
120
- "@mui/internal-babel-plugin-minify-errors": "2.0.8-canary.24",
121
- "@mui/internal-babel-plugin-resolve-imports": "2.0.7-canary.33"
142
+ "@mui/internal-babel-plugin-resolve-imports": "2.0.7-canary.36",
143
+ "@mui/internal-babel-plugin-display-name": "1.0.4-canary.19",
144
+ "@mui/internal-babel-plugin-minify-errors": "2.0.8-canary.27"
122
145
  },
123
146
  "peerDependencies": {
124
147
  "@next/eslint-plugin-next": "*",
@@ -144,27 +167,31 @@
144
167
  "@types/eslint-plugin-jsx-a11y": "6.10.1",
145
168
  "@types/estree": "1.0.8",
146
169
  "@types/estree-jsx": "1.0.5",
170
+ "@types/mdast": "4.0.4",
147
171
  "@types/regexp.escape": "2.0.0",
148
172
  "@types/yargs": "17.0.35",
149
- "@typescript-eslint/parser": "8.56.1",
150
- "@typescript-eslint/rule-tester": "8.56.1",
151
- "eslint": "10.0.2",
152
- "get-port": "7.1.0",
153
- "prettier": "3.8.1",
154
- "serve": "14.2.5",
155
- "typescript-eslint": "8.56.1"
173
+ "@typescript-eslint/parser": "8.57.1",
174
+ "@typescript-eslint/rule-tester": "8.57.1",
175
+ "eslint": "10.0.3",
176
+ "get-port": "7.2.0",
177
+ "prettier": "3.8.3",
178
+ "remark": "^15.0.1",
179
+ "remark-mdx": "^3.1.1",
180
+ "serve": "14.2.6",
181
+ "typescript-eslint": "8.57.1"
156
182
  },
157
183
  "files": [
158
184
  "bin",
159
185
  "build",
160
186
  "src",
187
+ "vale",
161
188
  "README.md",
162
189
  "LICENSE"
163
190
  ],
164
191
  "publishConfig": {
165
192
  "access": "public"
166
193
  },
167
- "gitSha": "96a7c608aa3603924622f70e8fe30cf084d59909",
194
+ "gitSha": "38a586faaccee1b655da0047f227fe82038494e8",
168
195
  "scripts": {
169
196
  "build": "tsgo -p tsconfig.build.json",
170
197
  "typescript": "tsgo -noEmit",
@@ -10,6 +10,10 @@ import pluginTransformImportMeta from 'babel-plugin-transform-import-meta';
10
10
  import pluginTransformInlineEnvVars from 'babel-plugin-transform-inline-environment-variables';
11
11
  import pluginRemovePropTypes from 'babel-plugin-transform-react-remove-prop-types';
12
12
 
13
+ /**
14
+ * @typedef {'annotation' | 'syntax' | 'infer' | 'all'} ReactCompilationMode
15
+ */
16
+
13
17
  /**
14
18
  * @param {Object} param0
15
19
  * @param {boolean} [param0.debug]
@@ -20,7 +24,8 @@ import pluginRemovePropTypes from 'babel-plugin-transform-react-remove-prop-type
20
24
  * @param {string | null} param0.outExtension - Specify the output file extension.
21
25
  * @param {string} param0.runtimeVersion
22
26
  * @param {string} [param0.reactCompilerReactVersion]
23
- * @param {string} [param0.reactCompilerMode]
27
+ * @param {ReactCompilationMode} [param0.reactCompilerMode]
28
+ * @param {{ allowedCallees?: Record<string, string[]> }} [param0.displayName] - Options for the display name plugin.
24
29
  * @returns {import('@babel/core').TransformOptions} The base Babel configuration.
25
30
  */
26
31
  export function getBaseConfig({
@@ -33,6 +38,7 @@ export function getBaseConfig({
33
38
  outExtension,
34
39
  reactCompilerReactVersion,
35
40
  reactCompilerMode,
41
+ displayName,
36
42
  }) {
37
43
  /**
38
44
  * @type {import('@babel/preset-env').Options}
@@ -57,7 +63,7 @@ export function getBaseConfig({
57
63
  },
58
64
  '@babel/plugin-transform-runtime',
59
65
  ],
60
- [pluginDisplayName, {}, '@mui/internal-babel-plugin-display-name'],
66
+ [pluginDisplayName, { ...displayName }, '@mui/internal-babel-plugin-display-name'],
61
67
  [
62
68
  pluginTransformInlineEnvVars,
63
69
  {
@@ -183,6 +189,6 @@ export default function getBabelConfig(api) {
183
189
  removePropTypes: process.env.MUI_REMOVE_PROP_TYPES === 'true',
184
190
  noResolveImports,
185
191
  reactCompilerReactVersion: process.env.MUI_REACT_COMPILER_REACT_VERSION,
186
- reactCompilerMode: process.env.MUI_REACT_COMPILER_MODE,
192
+ reactCompilerMode: /** @type {ReactCompilationMode} */ (process.env.MUI_REACT_COMPILER_MODE),
187
193
  });
188
194
  }
@@ -22,6 +22,7 @@
22
22
  <li><a href="/page-with-api-links.html">Page with API Links</a></li>
23
23
  <li><a href="/example.md">Example Markdown</a></li>
24
24
  <li><a href="/unclosed-tags.html">Page with Unclosed Tags</a></li>
25
+ <li><a href="/invalid-html.html">Invalid HTML Page</a></li>
25
26
  </ul>
26
27
  </nav>
27
28
  </body>
@@ -0,0 +1,15 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <title>Invalid HTML Page</title>
6
+ </head>
7
+ <body>
8
+ <h1>Invalid HTML</h1>
9
+ <!-- Duplicate ID (violates no-duplicate-id rule) -->
10
+ <div id="dup">First</div>
11
+ <div id="dup">Second</div>
12
+ <!-- Raw ampersand (violates no-raw-characters rule) -->
13
+ <p>Tom & Jerry</p>
14
+ </body>
15
+ </html>
@@ -0,0 +1,200 @@
1
+ import { workerData, parentPort } from 'node:worker_threads';
2
+ import { parse } from 'node-html-parser';
3
+ import contentType from 'content-type';
4
+ import { HtmlValidate, StaticConfigLoader, staticResolver } from 'html-validate';
5
+ import { unified } from 'unified';
6
+ import remarkParse from 'remark-parse';
7
+ import remarkGfm from 'remark-gfm';
8
+ import remarkRehype from 'remark-rehype';
9
+ import rehypeSlug from 'rehype-slug';
10
+ import rehypeStringify from 'rehype-stringify';
11
+
12
+ /** @type {import('./index.mjs').CrawlWorkerInput} */
13
+ const { pageUrl, options } = workerData;
14
+
15
+ /**
16
+ * Tests if a value matches any of the patterns in the array.
17
+ * Returns true if patterns is undefined/empty (wildcard behavior).
18
+ * Strings use exact match, RegExp uses .test().
19
+ * @param {string} value
20
+ * @param {(string | RegExp)[] | undefined} patterns
21
+ * @returns {boolean}
22
+ */
23
+ function matchesAnyPattern(value, patterns) {
24
+ if (!patterns || patterns.length === 0) {
25
+ return true;
26
+ }
27
+ return patterns.some((pattern) =>
28
+ typeof pattern === 'string' ? value === pattern : pattern.test(value),
29
+ );
30
+ }
31
+
32
+ /**
33
+ * Posts the crawl result back to the parent thread.
34
+ * @param {import('./index.mjs').CrawlWorkerOutput} output
35
+ */
36
+ function postResult(output) {
37
+ if (!parentPort) {
38
+ throw new Error('crawlWorker must be run as a worker thread');
39
+ }
40
+ parentPort.postMessage(output);
41
+ }
42
+
43
+ /**
44
+ * Computes the accessible name of an element according to ARIA rules.
45
+ * @param {import('node-html-parser').HTMLElement | null} elm
46
+ * @param {import('node-html-parser').HTMLElement} ownerDocument
47
+ * @returns {string}
48
+ */
49
+ function getAccessibleName(elm, ownerDocument) {
50
+ if (!elm) {
51
+ return '';
52
+ }
53
+
54
+ const ariaLabel = elm.getAttribute('aria-label')?.trim();
55
+ if (ariaLabel) {
56
+ return ariaLabel;
57
+ }
58
+
59
+ const labelledby = elm.getAttribute('aria-labelledby');
60
+ if (labelledby) {
61
+ const labels = [];
62
+ for (const id of labelledby.split(/\s+/)) {
63
+ const label = getAccessibleName(ownerDocument.getElementById(id), ownerDocument);
64
+ if (label) {
65
+ labels.push(label);
66
+ }
67
+ }
68
+ const label = labels.join(' ').trim();
69
+ if (label) {
70
+ return label;
71
+ }
72
+ }
73
+
74
+ if (elm.id) {
75
+ const label = ownerDocument.querySelector(`label[for="${elm.id}"]`);
76
+ if (label) {
77
+ return getAccessibleName(label, ownerDocument);
78
+ }
79
+ }
80
+
81
+ if (elm.tagName === 'IMG') {
82
+ const alt = elm.getAttribute('alt')?.trim();
83
+ if (alt) {
84
+ return alt;
85
+ }
86
+ }
87
+
88
+ return elm.innerText.trim();
89
+ }
90
+
91
+ /**
92
+ * Converts markdown content to HTML using unified pipeline.
93
+ * @param {string} markdown
94
+ * @returns {Promise<string>}
95
+ */
96
+ async function markdownToHtml(markdown) {
97
+ const result = await unified()
98
+ .use(remarkParse)
99
+ .use(remarkGfm)
100
+ .use(remarkRehype)
101
+ .use(rehypeSlug)
102
+ .use(rehypeStringify)
103
+ .process(markdown);
104
+ return String(result);
105
+ }
106
+
107
+ const res = await fetch(new URL(pageUrl, options.host));
108
+
109
+ const contentTypeHeader = res.headers.get('content-type');
110
+ let type = 'text/html';
111
+
112
+ if (contentTypeHeader) {
113
+ try {
114
+ const parsed = contentType.parse(contentTypeHeader);
115
+ type = parsed.type;
116
+ } catch {
117
+ // invalid content-type, default to text/html
118
+ }
119
+ }
120
+
121
+ /** @type {import('./index.mjs').CrawlWorkerPageData} */
122
+ const pageData = {
123
+ url: pageUrl,
124
+ status: res.status,
125
+ targets: [],
126
+ contentType: type,
127
+ };
128
+
129
+ if (pageData.status < 200 || pageData.status >= 400) {
130
+ postResult({ pageData, links: [], htmlValidateResults: null });
131
+ } else if (type.startsWith('image/') || (type !== 'text/html' && type !== 'text/markdown')) {
132
+ postResult({ pageData, links: [], htmlValidateResults: null });
133
+ } else {
134
+ const rawContent = await res.text();
135
+
136
+ const content = type === 'text/markdown' ? await markdownToHtml(rawContent) : rawContent;
137
+
138
+ const dom = parse(content, { parseNoneClosedTags: true });
139
+
140
+ // Extract targets
141
+ for (const target of dom.querySelectorAll('*[id]')) {
142
+ if (!options.ignoredTargets.has(target.id)) {
143
+ pageData.targets.push(`#${target.id}`);
144
+ }
145
+ }
146
+
147
+ // Extract links
148
+ let ignoredSelector = ':not(*)';
149
+ if (options.ignoredContent.length > 0) {
150
+ ignoredSelector = Array.from(options.ignoredContent)
151
+ .flatMap((selector) => [selector, `${selector} *`])
152
+ .join(',');
153
+ }
154
+ const linksSelector = `a[href]:not(${ignoredSelector})`;
155
+
156
+ const links = dom.querySelectorAll(linksSelector).map((a) => ({
157
+ src: pageUrl,
158
+ text: getAccessibleName(a, dom),
159
+ href: a.getAttribute('href') ?? '',
160
+ contentType: type,
161
+ }));
162
+
163
+ // HTML validation. Walk every entry and remember the last one whose path
164
+ // matches the current page — last match wins, so callers can layer
165
+ // specific overrides after a default entry.
166
+ /** @type {{ pageUrl: string, results: import('html-validate').Result[] } | null} */
167
+ let htmlValidateResults = null;
168
+ if (type === 'text/html' && options.htmlValidate.length > 0) {
169
+ /** @type {import('./index.mjs').ResolvedHtmlValidateEntry | null} */
170
+ let matchedEntry = null;
171
+ for (const entry of options.htmlValidate) {
172
+ if (matchesAnyPattern(pageUrl, entry.path)) {
173
+ matchedEntry = entry;
174
+ }
175
+ }
176
+
177
+ if (matchedEntry) {
178
+ const muiHtmlValidateResolver = staticResolver({
179
+ configs: {
180
+ 'mui:recommended': {
181
+ extends: ['html-validate:standard', 'html-validate:document', 'html-validate:browser'],
182
+ rules: {
183
+ // TODO: Enable when subresource integrity is adopted across projects
184
+ 'require-sri': 'off',
185
+ },
186
+ },
187
+ },
188
+ });
189
+
190
+ const htmlValidator = new HtmlValidate(
191
+ new StaticConfigLoader([muiHtmlValidateResolver], matchedEntry.config),
192
+ );
193
+
194
+ const report = await htmlValidator.validateString(rawContent, pageUrl);
195
+ htmlValidateResults = { pageUrl, results: report.results };
196
+ }
197
+ }
198
+
199
+ postResult({ pageData, links, htmlValidateResults });
200
+ }