@mui/internal-code-infra 0.0.4-canary.9 → 0.0.4-canary.90
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/LICENSE +1 -1
- package/README.md +19 -8
- package/build/babel-config.d.mts +5 -1
- package/build/brokenLinksChecker/crawlWorker.d.mts +1 -0
- package/build/brokenLinksChecker/index.d.mts +45 -2
- package/build/changelog/types.d.ts +3 -1
- package/build/cli/cmdArgosPush.d.mts +2 -2
- package/build/cli/cmdBuild.d.mts +3 -2
- package/build/cli/cmdCopyFiles.d.mts +2 -2
- package/build/cli/cmdExtractErrorCodes.d.mts +2 -2
- package/build/cli/cmdGenerateChangelog.d.mts +2 -2
- package/build/cli/cmdGithubAuth.d.mts +2 -2
- package/build/cli/cmdListWorkspaces.d.mts +6 -4
- package/build/cli/cmdNetlifyIgnore.d.mts +3 -2
- package/build/cli/cmdPublish.d.mts +4 -2
- package/build/cli/cmdPublishCanary.d.mts +3 -3
- package/build/cli/cmdPublishNewPackage.d.mts +4 -2
- package/build/cli/cmdSetVersionOverrides.d.mts +2 -2
- package/build/cli/cmdVale.d.mts +46 -0
- package/build/cli/cmdValidateBuiltTypes.d.mts +2 -2
- package/build/eslint/baseConfig.d.mts +3 -1
- package/build/eslint/mui/rules/disallow-react-api-in-server-components.d.mts +2 -2
- package/build/eslint/mui/rules/docgen-ignore-before-comment.d.mts +2 -2
- package/build/eslint/mui/rules/no-floating-cleanup.d.mts +5 -0
- package/build/eslint/mui/rules/no-guarded-throw.d.mts +31 -0
- package/build/eslint/mui/rules/no-presentation-role.d.mts +5 -0
- package/build/eslint/mui/rules/no-restricted-resolved-imports.d.mts +2 -2
- package/build/eslint/mui/rules/nodeEnvUtils.d.mts +18 -0
- package/build/remark/config.d.mts +43 -0
- package/build/remark/createLintTester.d.mts +10 -0
- package/build/remark/firstBlockHeading.d.mts +4 -0
- package/build/remark/gitDiff.d.mts +2 -0
- package/build/remark/noSpaceInLinks.d.mts +2 -0
- package/build/remark/straightQuotes.d.mts +2 -0
- package/build/remark/tableAlignment.d.mts +2 -0
- package/build/remark/terminalLanguage.d.mts +2 -0
- package/build/utils/babel.d.mts +1 -1
- package/build/utils/build.d.mts +56 -37
- package/build/utils/git.d.mts +7 -0
- package/build/utils/github.d.mts +1 -1
- package/build/utils/pnpm.d.mts +81 -2
- package/build/utils/testUtils.d.mts +7 -0
- package/build/utils/typescript.d.mts +6 -16
- package/package.json +74 -50
- package/src/babel-config.mjs +3 -1
- package/src/brokenLinksChecker/crawlWorker.mjs +240 -0
- package/src/brokenLinksChecker/index.mjs +263 -188
- package/src/changelog/fetchChangelogs.mjs +8 -2
- package/src/changelog/renderChangelog.mjs +1 -1
- package/src/changelog/types.ts +3 -1
- package/src/cli/cmdBuild.mjs +51 -85
- package/src/cli/cmdListWorkspaces.mjs +12 -27
- package/src/cli/cmdNetlifyIgnore.mjs +34 -93
- package/src/cli/cmdPublish.mjs +95 -20
- package/src/cli/cmdPublishCanary.mjs +128 -132
- package/src/cli/cmdPublishNewPackage.mjs +27 -6
- package/src/cli/cmdSetVersionOverrides.mjs +8 -9
- package/src/cli/cmdVale.mjs +513 -0
- package/src/cli/index.mjs +2 -0
- package/src/cli/packageJson.d.ts +1 -1
- package/src/eslint/baseConfig.mjs +51 -19
- package/src/eslint/docsConfig.mjs +2 -1
- package/src/eslint/mui/config.mjs +24 -4
- package/src/eslint/mui/index.mjs +6 -0
- package/src/eslint/mui/rules/no-floating-cleanup.mjs +187 -0
- package/src/eslint/mui/rules/no-guarded-throw.mjs +115 -0
- package/src/eslint/mui/rules/no-presentation-role.mjs +60 -0
- package/src/eslint/mui/rules/nodeEnvUtils.mjs +52 -0
- package/src/eslint/mui/rules/require-dev-wrapper.mjs +25 -40
- package/src/estree-typescript.d.ts +1 -1
- package/src/remark/config.mjs +157 -0
- package/src/remark/createLintTester.mjs +19 -0
- package/src/remark/firstBlockHeading.mjs +87 -0
- package/src/remark/gitDiff.mjs +43 -0
- package/src/remark/noSpaceInLinks.mjs +42 -0
- package/src/remark/straightQuotes.mjs +31 -0
- package/src/remark/tableAlignment.mjs +23 -0
- package/src/remark/terminalLanguage.mjs +19 -0
- package/src/untyped-plugins.d.ts +11 -11
- package/src/utils/build.mjs +604 -270
- package/src/utils/git.mjs +27 -7
- package/src/utils/pnpm.mjs +277 -10
- package/src/utils/testUtils.mjs +18 -0
- package/src/utils/typescript.mjs +23 -42
- package/vale/.vale.ini +1 -0
- package/vale/styles/MUI/CorrectReferenceAllCases.yml +42 -0
- package/vale/styles/MUI/CorrectRererenceCased.yml +14 -0
- package/vale/styles/MUI/GoogleLatin.yml +11 -0
- package/vale/styles/MUI/MuiBrandName.yml +22 -0
- package/vale/styles/MUI/NoBritish.yml +112 -0
- package/vale/styles/MUI/NoCompanyName.yml +17 -0
- package/build/markdownlint/duplicate-h1.d.mts +0 -56
- package/build/markdownlint/git-diff.d.mts +0 -11
- package/build/markdownlint/index.d.mts +0 -52
- package/build/markdownlint/straight-quotes.d.mts +0 -11
- package/build/markdownlint/table-alignment.d.mts +0 -11
- package/build/markdownlint/terminal-language.d.mts +0 -11
- package/src/brokenLinksChecker/__fixtures__/static-site/broken-links.html +0 -20
- package/src/brokenLinksChecker/__fixtures__/static-site/broken-targets.html +0 -22
- package/src/brokenLinksChecker/__fixtures__/static-site/example.md +0 -20
- package/src/brokenLinksChecker/__fixtures__/static-site/external-links.html +0 -21
- package/src/brokenLinksChecker/__fixtures__/static-site/ignored-page.html +0 -17
- package/src/brokenLinksChecker/__fixtures__/static-site/index.html +0 -28
- package/src/brokenLinksChecker/__fixtures__/static-site/known-targets.json +0 -5
- package/src/brokenLinksChecker/__fixtures__/static-site/nested/page.html +0 -21
- package/src/brokenLinksChecker/__fixtures__/static-site/orphaned-page.html +0 -20
- package/src/brokenLinksChecker/__fixtures__/static-site/page-with-api-links.html +0 -20
- package/src/brokenLinksChecker/__fixtures__/static-site/page-with-custom-targets.html +0 -24
- package/src/brokenLinksChecker/__fixtures__/static-site/page-with-ignored-content.html +0 -28
- package/src/brokenLinksChecker/__fixtures__/static-site/page-with-known-target-links.html +0 -19
- package/src/brokenLinksChecker/__fixtures__/static-site/unclosed-tags.html +0 -1
- package/src/brokenLinksChecker/__fixtures__/static-site/valid.html +0 -20
- package/src/brokenLinksChecker/__fixtures__/static-site/with-anchors.html +0 -31
- package/src/brokenLinksChecker/index.test.ts +0 -261
- package/src/changelog/categorizeCommits.test.ts +0 -319
- package/src/changelog/filterCommits.test.ts +0 -363
- package/src/changelog/parseCommitLabels.test.ts +0 -509
- package/src/changelog/renderChangelog.test.ts +0 -378
- package/src/changelog/sortSections.test.ts +0 -199
- package/src/eslint/mui/rules/add-undef-to-optional.test.mjs +0 -361
- package/src/eslint/mui/rules/consistent-production-guard.test.mjs +0 -162
- package/src/eslint/mui/rules/disallow-active-elements-as-key-event-target.test.mjs +0 -66
- package/src/eslint/mui/rules/disallow-react-api-in-server-components.test.mjs +0 -305
- package/src/eslint/mui/rules/docgen-ignore-before-comment.test.mjs +0 -52
- package/src/eslint/mui/rules/flatten-parentheses.test.mjs +0 -245
- package/src/eslint/mui/rules/mui-name-matches-component-name.test.mjs +0 -247
- package/src/eslint/mui/rules/no-empty-box.test.mjs +0 -40
- package/src/eslint/mui/rules/no-styled-box.test.mjs +0 -73
- package/src/eslint/mui/rules/require-dev-wrapper.test.mjs +0 -265
- package/src/eslint/mui/rules/rules-of-use-theme-variants.test.mjs +0 -149
- package/src/eslint/mui/rules/straight-quotes.test.mjs +0 -67
- package/src/markdownlint/duplicate-h1.mjs +0 -69
- package/src/markdownlint/git-diff.mjs +0 -31
- package/src/markdownlint/index.mjs +0 -62
- package/src/markdownlint/straight-quotes.mjs +0 -26
- package/src/markdownlint/table-alignment.mjs +0 -42
- package/src/markdownlint/terminal-language.mjs +0 -19
- package/src/utils/build.test.mjs +0 -705
- package/src/utils/template.test.mjs +0 -133
- package/src/utils/typescript.test.mjs +0 -380
package/src/utils/git.mjs
CHANGED
|
@@ -24,6 +24,10 @@ export async function getRepositoryInfo(cwd = process.cwd()) {
|
|
|
24
24
|
* @type {Set<string>}
|
|
25
25
|
*/
|
|
26
26
|
const repoRemotes = new Set();
|
|
27
|
+
/**
|
|
28
|
+
* @type {Map<string, { owner: string, repo: string }>}
|
|
29
|
+
*/
|
|
30
|
+
const validRemotes = new Map();
|
|
27
31
|
|
|
28
32
|
for (const line of lines) {
|
|
29
33
|
// Match pattern: "remoteName url (fetch|push)"
|
|
@@ -36,20 +40,25 @@ export async function getRepositoryInfo(cwd = process.cwd()) {
|
|
|
36
40
|
cause[remoteName] = `Remote is not a GitHub repository under 'mui' organization: ${url}`;
|
|
37
41
|
continue;
|
|
38
42
|
}
|
|
39
|
-
|
|
40
|
-
owner: parsed.owner,
|
|
41
|
-
|
|
42
|
-
remoteName,
|
|
43
|
-
};
|
|
43
|
+
if (!validRemotes.has(remoteName)) {
|
|
44
|
+
validRemotes.set(remoteName, { owner: parsed.owner, repo: parsed.name });
|
|
45
|
+
}
|
|
44
46
|
} catch (error) {
|
|
45
47
|
cause[remoteName] = `Failed to parse URL for remote ${remoteName}: ${url}`;
|
|
46
48
|
}
|
|
47
|
-
}
|
|
48
|
-
if (type !== '(push)') {
|
|
49
|
+
} else if (type !== '(push)') {
|
|
49
50
|
throw new Error(`Unexpected line format for "git remote -v": "${line}"`);
|
|
50
51
|
}
|
|
51
52
|
}
|
|
52
53
|
|
|
54
|
+
const preferredOrder = ['upstream', 'origin', ...validRemotes.keys()];
|
|
55
|
+
for (const name of preferredOrder) {
|
|
56
|
+
const match = validRemotes.get(name);
|
|
57
|
+
if (match) {
|
|
58
|
+
return { ...match, remoteName: name };
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
53
62
|
throw new Error(
|
|
54
63
|
`Failed to find correct remote(s) in : ${Array.from(repoRemotes.keys()).join(', ')}`,
|
|
55
64
|
{ cause },
|
|
@@ -64,3 +73,14 @@ export async function getCurrentGitSha() {
|
|
|
64
73
|
const result = await $`git rev-parse HEAD`;
|
|
65
74
|
return result.stdout.trim();
|
|
66
75
|
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Check whether a tag already exists on the origin remote
|
|
79
|
+
* @param {string} tagName - Tag name to check (e.g. `v1.2.3`)
|
|
80
|
+
* @param {string} [cwd=process.cwd()]
|
|
81
|
+
* @returns {Promise<boolean>} True if the tag exists on origin
|
|
82
|
+
*/
|
|
83
|
+
export async function remoteGitTagExists(tagName, cwd = process.cwd()) {
|
|
84
|
+
const { stdout } = await $({ cwd })`git ls-remote --tags origin refs/tags/${tagName}`;
|
|
85
|
+
return stdout.trim().length > 0;
|
|
86
|
+
}
|
package/src/utils/pnpm.mjs
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
+
import { findWorkspaceDir } from '@pnpm/find-workspace-dir';
|
|
3
4
|
import { $ } from 'execa';
|
|
4
5
|
import * as fs from 'node:fs/promises';
|
|
5
6
|
import * as path from 'node:path';
|
|
6
7
|
import * as semver from 'semver';
|
|
8
|
+
import { parseDocument, isMap } from 'yaml';
|
|
7
9
|
|
|
8
10
|
/**
|
|
9
11
|
* @typedef {Object} PrivatePackage
|
|
@@ -48,6 +50,7 @@ import * as semver from 'semver';
|
|
|
48
50
|
* @property {boolean} [publicOnly=false] - Whether to filter to only public packages
|
|
49
51
|
* @property {boolean} [nonPublishedOnly=false] - Whether to filter to only non-published packages. It by default means public packages yet to be published.
|
|
50
52
|
* @property {string} [cwd] - Current working directory to run pnpm command in
|
|
53
|
+
* @property {string[]} [filter] - Same as filtering packages with --filter in pnpm. Only include packages matching the filter. See https://pnpm.io/filtering.
|
|
51
54
|
*/
|
|
52
55
|
|
|
53
56
|
/**
|
|
@@ -73,15 +76,35 @@ import * as semver from 'semver';
|
|
|
73
76
|
* @returns {Promise<(PrivatePackage | PublicPackage)[]>} Array of packages
|
|
74
77
|
*/
|
|
75
78
|
export async function getWorkspacePackages(options = {}) {
|
|
76
|
-
const { sinceRef = null, publicOnly = false, nonPublishedOnly = false } = options;
|
|
79
|
+
const { sinceRef = null, publicOnly = false, nonPublishedOnly = false, filter = [] } = options;
|
|
77
80
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
81
|
+
/**
|
|
82
|
+
* Run `pnpm ls` with the given --filter args and return the parsed list.
|
|
83
|
+
* @param {string[]} filterArg
|
|
84
|
+
* @returns {Promise<PnpmListResultItem[]>}
|
|
85
|
+
*/
|
|
86
|
+
const listPackages = async (filterArg) => {
|
|
87
|
+
const result = await $({ cwd: options.cwd })`pnpm ls -r --json --depth -1 ${filterArg}`;
|
|
88
|
+
return JSON.parse(result.stdout);
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
// pnpm ORs --filter args, so intersect "matches filter" with "changed since ref"
|
|
92
|
+
// in JS. The `[ref]` selector (no `...`) excludes dependents of changed packages.
|
|
93
|
+
const patternFilterArg = filter.flatMap((f) => ['--filter', f]);
|
|
94
|
+
const [candidatePackages, changedPackages] = await Promise.all([
|
|
95
|
+
listPackages(patternFilterArg),
|
|
96
|
+
// null when no sinceRef (skip the constraint); [] when nothing changed.
|
|
97
|
+
sinceRef ? listPackages(['--filter', `[${sinceRef}]`]) : Promise.resolve(null),
|
|
98
|
+
]);
|
|
99
|
+
let packageData = candidatePackages;
|
|
100
|
+
if (changedPackages) {
|
|
101
|
+
// sinceRef given but nothing changed → no packages, regardless of filter.
|
|
102
|
+
if (changedPackages.length === 0) {
|
|
103
|
+
return [];
|
|
104
|
+
}
|
|
105
|
+
const changedPaths = new Set(changedPackages.map((pkg) => pkg.path));
|
|
106
|
+
packageData = packageData.filter((pkg) => changedPaths.has(pkg.path));
|
|
107
|
+
}
|
|
85
108
|
|
|
86
109
|
// Filter packages based on options
|
|
87
110
|
const filteredPackages = packageData.flatMap((pkg) => {
|
|
@@ -148,11 +171,17 @@ export async function getPackageVersionInfo(packageName, baseVersion) {
|
|
|
148
171
|
}
|
|
149
172
|
}
|
|
150
173
|
|
|
174
|
+
/**
|
|
175
|
+
* @typedef {Object} PublishSummaryEntry
|
|
176
|
+
* @property {string} name
|
|
177
|
+
* @property {string} version
|
|
178
|
+
*/
|
|
179
|
+
|
|
151
180
|
/**
|
|
152
181
|
* Publish packages with the given options
|
|
153
182
|
* @param {PublicPackage[]} packages - Packages to publish
|
|
154
183
|
* @param {PublishOptions} [options={}] - Publishing options
|
|
155
|
-
* @returns {Promise<
|
|
184
|
+
* @returns {Promise<PublishSummaryEntry[]>}
|
|
156
185
|
*/
|
|
157
186
|
export async function publishPackages(packages, options = {}) {
|
|
158
187
|
const args = [];
|
|
@@ -172,7 +201,183 @@ export async function publishPackages(packages, options = {}) {
|
|
|
172
201
|
args.push('--no-git-checks');
|
|
173
202
|
}
|
|
174
203
|
|
|
175
|
-
|
|
204
|
+
const workspaceDir = await findWorkspaceDir(process.cwd());
|
|
205
|
+
if (!workspaceDir) {
|
|
206
|
+
throw new Error('Could not find pnpm workspace root');
|
|
207
|
+
}
|
|
208
|
+
const summaryPath = path.join(workspaceDir, 'pnpm-publish-summary.json');
|
|
209
|
+
|
|
210
|
+
// Clean up any leftover summary file from a previous run
|
|
211
|
+
await fs.rm(summaryPath, { force: true });
|
|
212
|
+
|
|
213
|
+
await $({
|
|
214
|
+
stdio: 'inherit',
|
|
215
|
+
env: { npm_config_loglevel: 'warn' },
|
|
216
|
+
})`pnpm -r publish --access public --tag=${tag} --report-summary ${args}`;
|
|
217
|
+
|
|
218
|
+
const summary = JSON.parse(await fs.readFile(summaryPath, 'utf-8'));
|
|
219
|
+
await fs.rm(summaryPath, { force: true });
|
|
220
|
+
return /** @type {PublishSummaryEntry[]} */ (summary.publishedPackages);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* @typedef {Object} GetTransitiveDependenciesOptions
|
|
225
|
+
* @property {Map<string, string>} [workspacePathByName] - Map of workspace package name to directory path
|
|
226
|
+
* @property {boolean} [includeDev=true] - Whether to include devDependencies in the traversal
|
|
227
|
+
*/
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Get all transitive workspace dependencies for a set of packages.
|
|
231
|
+
*
|
|
232
|
+
* Only follows deps whose version spec starts with `workspace:` (e.g. `workspace:*`
|
|
233
|
+
* or `workspace:^`), meaning they are sourced directly from the monorepo. Pinned
|
|
234
|
+
* external versions (e.g. `^1.0.0`) are ignored even when the package name exists
|
|
235
|
+
* in the workspace. Traverses `dependencies` and optionally `devDependencies`.
|
|
236
|
+
* Results are cached per package so each package is read from disk at most once
|
|
237
|
+
* regardless of how many roots depend on it.
|
|
238
|
+
*
|
|
239
|
+
* @param {string[]} packageNames - Package names to start the traversal from
|
|
240
|
+
* @param {GetTransitiveDependenciesOptions} [options]
|
|
241
|
+
* @returns {Promise<Set<string>>} All reachable workspace package names, including the input packages themselves
|
|
242
|
+
*/
|
|
243
|
+
export async function getTransitiveDependencies(packageNames, options = {}) {
|
|
244
|
+
const { includeDev = true, workspacePathByName = new Map() } = options;
|
|
245
|
+
|
|
246
|
+
/** @type {Map<string, Promise<Set<string>>>} */
|
|
247
|
+
const cache = new Map();
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* @param {string} packageName
|
|
251
|
+
* @returns {Promise<Set<string>>}
|
|
252
|
+
*/
|
|
253
|
+
function collectDeps(packageName) {
|
|
254
|
+
const cached = cache.get(packageName);
|
|
255
|
+
if (cached) {
|
|
256
|
+
return cached;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
const promise = (async () => {
|
|
260
|
+
const packagePath = workspacePathByName.get(packageName);
|
|
261
|
+
if (!packagePath) {
|
|
262
|
+
throw new Error(`Workspace "${packageName}" not found`);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
const pkgJson = await readPackageJson(packagePath);
|
|
266
|
+
const allDepEntries = [
|
|
267
|
+
...Object.entries(pkgJson.dependencies ?? {}),
|
|
268
|
+
...(includeDev ? Object.entries(pkgJson.devDependencies ?? {}) : []),
|
|
269
|
+
];
|
|
270
|
+
const workspaceDeps = allDepEntries
|
|
271
|
+
.filter(
|
|
272
|
+
([dep, spec]) =>
|
|
273
|
+
workspacePathByName.has(dep) &&
|
|
274
|
+
typeof spec === 'string' &&
|
|
275
|
+
spec.startsWith('workspace:'),
|
|
276
|
+
)
|
|
277
|
+
.map(([dep]) => dep);
|
|
278
|
+
|
|
279
|
+
const recursiveResults = await Promise.all(workspaceDeps.map(collectDeps));
|
|
280
|
+
return new Set([...workspaceDeps, ...recursiveResults.flatMap((s) => [...s])]);
|
|
281
|
+
})();
|
|
282
|
+
|
|
283
|
+
cache.set(packageName, promise);
|
|
284
|
+
return promise;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
for (const name of packageNames) {
|
|
288
|
+
if (!workspacePathByName.has(name)) {
|
|
289
|
+
throw new Error(`Workspace "${name}" not found`);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
const results = await Promise.all(packageNames.map(collectDeps));
|
|
294
|
+
return new Set([...packageNames, ...results.flatMap((s) => [...s])]);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Pure validation logic: given a publish set and workspace maps, checks that all
|
|
299
|
+
* transitive hard workspace dependencies are covered and none are private.
|
|
300
|
+
*
|
|
301
|
+
* A hard dependency is one listed in `dependencies` (not `peerDependencies` or
|
|
302
|
+
* `devDependencies`) using a `workspace:` version specifier (e.g. `workspace:*` or
|
|
303
|
+
* `workspace:^`). Peer dependencies are never bundled and dev dependencies are not installed
|
|
304
|
+
* on consumer devices - both are excluded regardless of version specifier. Pinned-version
|
|
305
|
+
* references in `dependencies` are also excluded - they resolve from the registry and do
|
|
306
|
+
* not need to be co-published.
|
|
307
|
+
*
|
|
308
|
+
* @param {PublicPackage[]} packages - The packages intended for publishing
|
|
309
|
+
* @param {Map<string, PublicPackage | PrivatePackage>} workspacePackageByName - All workspace packages by name
|
|
310
|
+
* @param {Map<string, string>} workspacePathByName - Map of workspace package name to directory path
|
|
311
|
+
* @returns {Promise<{issues: string[]}>}
|
|
312
|
+
* List of human-readable issue strings. Empty when the dependency set is valid.
|
|
313
|
+
* @internal
|
|
314
|
+
*/
|
|
315
|
+
export async function checkPublishDependencies(
|
|
316
|
+
packages,
|
|
317
|
+
workspacePackageByName,
|
|
318
|
+
workspacePathByName,
|
|
319
|
+
) {
|
|
320
|
+
const publishedNames = new Set(packages.map((pkg) => pkg.name));
|
|
321
|
+
|
|
322
|
+
const transitiveDeps = await getTransitiveDependencies(
|
|
323
|
+
packages.map((pkg) => pkg.name),
|
|
324
|
+
{ includeDev: false, workspacePathByName },
|
|
325
|
+
);
|
|
326
|
+
|
|
327
|
+
/** @type {Set<string>} */
|
|
328
|
+
const privateButRequired = new Set();
|
|
329
|
+
/** @type {Set<string>} */
|
|
330
|
+
const missingFromPublish = new Set();
|
|
331
|
+
|
|
332
|
+
for (const depName of transitiveDeps) {
|
|
333
|
+
if (publishedNames.has(depName)) {
|
|
334
|
+
continue;
|
|
335
|
+
}
|
|
336
|
+
const workspacePkg = workspacePackageByName.get(depName);
|
|
337
|
+
if (workspacePkg?.isPrivate) {
|
|
338
|
+
privateButRequired.add(depName);
|
|
339
|
+
} else {
|
|
340
|
+
missingFromPublish.add(depName);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/** @type {string[]} */
|
|
345
|
+
const issues = [];
|
|
346
|
+
|
|
347
|
+
if (privateButRequired.size > 0) {
|
|
348
|
+
issues.push(
|
|
349
|
+
`The following private workspace packages are required as dependencies but cannot be published: ${[...privateButRequired].join(', ')}`,
|
|
350
|
+
);
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
if (missingFromPublish.size > 0) {
|
|
354
|
+
issues.push(
|
|
355
|
+
`The following workspace packages are required as dependencies but are not included in the publish set: ${[...missingFromPublish].join(', ')}. Add them to the --filter list.`,
|
|
356
|
+
);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
return { issues };
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* Validate that a set of packages covers all of their transitive hard workspace dependencies,
|
|
364
|
+
* and that none of those dependencies are private (which would make them unpublishable).
|
|
365
|
+
*
|
|
366
|
+
* @param {PublicPackage[]} packages - The packages intended for publishing
|
|
367
|
+
* @returns {Promise<{issues: string[]}>}
|
|
368
|
+
* List of human-readable issue strings. Empty when the dependency set is valid.
|
|
369
|
+
*/
|
|
370
|
+
export async function validatePublishDependencies(packages) {
|
|
371
|
+
const allWorkspacePackages = await getWorkspacePackages();
|
|
372
|
+
|
|
373
|
+
const workspacePackageByName = /** @type {Map<string, PublicPackage | PrivatePackage>} */ (
|
|
374
|
+
new Map(allWorkspacePackages.flatMap((pkg) => (pkg.name ? [[pkg.name, pkg]] : [])))
|
|
375
|
+
);
|
|
376
|
+
const workspacePathByName = new Map(
|
|
377
|
+
allWorkspacePackages.flatMap((pkg) => (pkg.name ? [[pkg.name, pkg.path]] : [])),
|
|
378
|
+
);
|
|
379
|
+
|
|
380
|
+
return checkPublishDependencies(packages, workspacePackageByName, workspacePathByName);
|
|
176
381
|
}
|
|
177
382
|
|
|
178
383
|
/**
|
|
@@ -196,6 +401,68 @@ export async function writePackageJson(packagePath, packageJson) {
|
|
|
196
401
|
await fs.writeFile(path.join(packagePath, 'package.json'), content);
|
|
197
402
|
}
|
|
198
403
|
|
|
404
|
+
/**
|
|
405
|
+
* Write the computed overrides into whichever manifest already defines
|
|
406
|
+
* overrides — preferring pnpm-workspace.yaml, falling back to package.json
|
|
407
|
+
* `pnpm.overrides`, defaulting to pnpm-workspace.yaml — and persist the result.
|
|
408
|
+
* A missing pnpm-workspace.yaml is treated as empty, so a fresh file is created
|
|
409
|
+
* with just the `overrides:` block. Rejects a `resolutions` field in
|
|
410
|
+
* package.json because pnpm 11 silently ignores it.
|
|
411
|
+
*
|
|
412
|
+
* @param {string} workspaceDir - Workspace root directory
|
|
413
|
+
* @param {Record<string, string>} overrides - Overrides to apply
|
|
414
|
+
* @returns {Promise<void>}
|
|
415
|
+
*/
|
|
416
|
+
export async function writeOverridesToWorkspace(workspaceDir, overrides) {
|
|
417
|
+
const workspaceYamlPath = path.join(workspaceDir, 'pnpm-workspace.yaml');
|
|
418
|
+
const yamlPromise = fs.readFile(workspaceYamlPath, { encoding: 'utf8' }).catch((error) => {
|
|
419
|
+
if (/** @type {NodeJS.ErrnoException} */ (error).code !== 'ENOENT') {
|
|
420
|
+
throw error;
|
|
421
|
+
}
|
|
422
|
+
return '';
|
|
423
|
+
});
|
|
424
|
+
const [rootPackageJson, yamlSource] = await Promise.all([
|
|
425
|
+
readPackageJson(workspaceDir),
|
|
426
|
+
yamlPromise,
|
|
427
|
+
]);
|
|
428
|
+
|
|
429
|
+
const { resolutions } = rootPackageJson;
|
|
430
|
+
if (resolutions && Object.keys(resolutions).length > 0) {
|
|
431
|
+
throw new Error(
|
|
432
|
+
'Found a "resolutions" field in package.json. pnpm 11 ignores it silently. ' +
|
|
433
|
+
'Move those entries into the "overrides:" key of pnpm-workspace.yaml.',
|
|
434
|
+
);
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
// Parsed once, reused for both the read (does it have overrides?) and the write.
|
|
438
|
+
const doc = parseDocument(yamlSource);
|
|
439
|
+
const existing = doc.get('overrides');
|
|
440
|
+
const workspaceHasOverrides = isMap(existing) && existing.items.length > 0;
|
|
441
|
+
|
|
442
|
+
const pnpm = /** @type {{ overrides?: Record<string, string> } | undefined} */ (
|
|
443
|
+
rootPackageJson.pnpm
|
|
444
|
+
);
|
|
445
|
+
const packageJsonOverrides = pnpm?.overrides;
|
|
446
|
+
|
|
447
|
+
// Write where overrides already live; default to the workspace file.
|
|
448
|
+
if (
|
|
449
|
+
!workspaceHasOverrides &&
|
|
450
|
+
packageJsonOverrides &&
|
|
451
|
+
Object.keys(packageJsonOverrides).length > 0
|
|
452
|
+
) {
|
|
453
|
+
await writePackageJson(workspaceDir, {
|
|
454
|
+
...rootPackageJson,
|
|
455
|
+
pnpm: { ...pnpm, overrides: { ...packageJsonOverrides, ...overrides } },
|
|
456
|
+
});
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
for (const [name, version] of Object.entries(overrides)) {
|
|
461
|
+
doc.setIn(['overrides', name], version);
|
|
462
|
+
}
|
|
463
|
+
await fs.writeFile(workspaceYamlPath, doc.toString());
|
|
464
|
+
}
|
|
465
|
+
|
|
199
466
|
/**
|
|
200
467
|
* Resolve a package@version specifier to an exact version
|
|
201
468
|
* @param {string} packageSpec - Package specifier in format "package@version"
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as fs from 'node:fs/promises';
|
|
2
|
+
import * as os from 'node:os';
|
|
3
|
+
import * as path from 'node:path';
|
|
4
|
+
import { onTestFinished } from 'vitest';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Creates a temporary directory and registers an `onTestFinished` hook to
|
|
8
|
+
* remove it automatically when the current test ends — even if the test throws.
|
|
9
|
+
*
|
|
10
|
+
* @returns {Promise<string>} The path of the created temporary directory.
|
|
11
|
+
*/
|
|
12
|
+
export async function makeTempDir() {
|
|
13
|
+
const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'code-infra-test-'));
|
|
14
|
+
onTestFinished(async () => {
|
|
15
|
+
await fs.rm(tmpDir, { recursive: true, force: true });
|
|
16
|
+
});
|
|
17
|
+
return tmpDir;
|
|
18
|
+
}
|
package/src/utils/typescript.mjs
CHANGED
|
@@ -111,30 +111,21 @@ export async function copyDeclarations(sourceDirectory, destinationDirectory, op
|
|
|
111
111
|
* @param {Object} param0
|
|
112
112
|
* @param {string} param0.inputDir
|
|
113
113
|
* @param {string} param0.buildDir
|
|
114
|
-
* @param {
|
|
115
|
-
* @param {boolean} [param0.isFlat]
|
|
114
|
+
* @param {import('../utils/build.mjs').BundleType[]} param0.bundles
|
|
116
115
|
* @param {'module' | 'commonjs'} [param0.packageType]
|
|
117
116
|
* @returns
|
|
118
117
|
*/
|
|
119
|
-
export async function moveAndTransformDeclarations({
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
isFlat,
|
|
124
|
-
packageType,
|
|
125
|
-
}) {
|
|
126
|
-
// Directly copy to the bundle directory if there's only one bundle, mainly for esm, since
|
|
127
|
-
// the js files are inside 'esm' folder. resolve-imports plugin needs d.ts to be alongside js files to
|
|
128
|
-
// resolve paths correctly.
|
|
129
|
-
const toCopyDir = bundles.length === 1 ? path.join(buildDir, bundles[0].dir) : buildDir;
|
|
130
|
-
await fs.cp(inputDir, toCopyDir, {
|
|
118
|
+
export async function moveAndTransformDeclarations({ inputDir, buildDir, bundles, packageType }) {
|
|
119
|
+
// d.ts files sit alongside the js files in the build root so the resolve-imports
|
|
120
|
+
// plugin can resolve paths correctly.
|
|
121
|
+
await fs.cp(inputDir, buildDir, {
|
|
131
122
|
recursive: true,
|
|
132
123
|
force: false,
|
|
133
124
|
});
|
|
134
125
|
|
|
135
|
-
const dtsFiles = await globby('**/*.d.ts', { absolute: true, cwd:
|
|
126
|
+
const dtsFiles = await globby('**/*.d.ts', { absolute: true, cwd: buildDir });
|
|
136
127
|
if (dtsFiles.length === 0) {
|
|
137
|
-
console.log(`No d.ts files found in ${
|
|
128
|
+
console.log(`No d.ts files found in ${buildDir}. Skipping transformation.`);
|
|
138
129
|
return;
|
|
139
130
|
}
|
|
140
131
|
|
|
@@ -144,37 +135,30 @@ export async function moveAndTransformDeclarations({
|
|
|
144
135
|
// Normalize to native separators to make path comparisons reliable on Windows
|
|
145
136
|
const nativeDtsFile = path.normalize(dtsFile);
|
|
146
137
|
const content = await fs.readFile(nativeDtsFile, 'utf8');
|
|
147
|
-
const relativePath = path.relative(
|
|
138
|
+
const relativePath = path.relative(buildDir, nativeDtsFile);
|
|
148
139
|
|
|
149
|
-
const writesToOriginalPath =
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
isFlat,
|
|
154
|
-
isType: true,
|
|
155
|
-
packageType,
|
|
156
|
-
});
|
|
157
|
-
const outFileRelative = relativePath.replace(/\.d\.ts$/, newFileExtension);
|
|
158
|
-
const outFilePath = path.join(buildDir, bundle.dir, outFileRelative);
|
|
159
|
-
// Ensure both paths are normalized before comparison (fixes Windows posix vs win32 separators)
|
|
160
|
-
return path.resolve(outFilePath) === path.resolve(nativeDtsFile);
|
|
140
|
+
const writesToOriginalPath = bundles.some((bundle) => {
|
|
141
|
+
const newFileExtension = getOutExtension(bundle, {
|
|
142
|
+
isType: true,
|
|
143
|
+
packageType,
|
|
161
144
|
});
|
|
145
|
+
const outFileRelative = relativePath.replace(/\.d\.ts$/, newFileExtension);
|
|
146
|
+
const outFilePath = path.join(buildDir, outFileRelative);
|
|
147
|
+
// Ensure both paths are normalized before comparison (fixes Windows posix vs win32 separators)
|
|
148
|
+
return path.resolve(outFilePath) === path.resolve(nativeDtsFile);
|
|
149
|
+
});
|
|
162
150
|
|
|
163
151
|
await Promise.all(
|
|
164
152
|
bundles.map(async (bundle) => {
|
|
165
|
-
const importExtension = getOutExtension(bundle
|
|
166
|
-
isFlat,
|
|
153
|
+
const importExtension = getOutExtension(bundle, {
|
|
167
154
|
packageType,
|
|
168
155
|
});
|
|
169
|
-
const newFileExtension = getOutExtension(bundle
|
|
170
|
-
isFlat,
|
|
156
|
+
const newFileExtension = getOutExtension(bundle, {
|
|
171
157
|
isType: true,
|
|
172
158
|
packageType,
|
|
173
159
|
});
|
|
174
|
-
const outFileRelative =
|
|
175
|
-
|
|
176
|
-
: relativePath;
|
|
177
|
-
const outFilePath = path.join(buildDir, bundle.dir, outFileRelative);
|
|
160
|
+
const outFileRelative = relativePath.replace(/\.d\.ts$/, newFileExtension);
|
|
161
|
+
const outFilePath = path.join(buildDir, outFileRelative);
|
|
178
162
|
|
|
179
163
|
const babelPlugins = [
|
|
180
164
|
[pluginTypescriptSyntax, { dts: true }],
|
|
@@ -194,7 +178,7 @@ export async function moveAndTransformDeclarations({
|
|
|
194
178
|
}
|
|
195
179
|
}),
|
|
196
180
|
);
|
|
197
|
-
if (
|
|
181
|
+
if (!writesToOriginalPath) {
|
|
198
182
|
await fs.unlink(nativeDtsFile);
|
|
199
183
|
}
|
|
200
184
|
},
|
|
@@ -208,9 +192,8 @@ export async function moveAndTransformDeclarations({
|
|
|
208
192
|
* After copying, babel transformations are applied to the copied files because they need to be alongside the actual js files for proper resolution.
|
|
209
193
|
*
|
|
210
194
|
* @param {Object} param0
|
|
211
|
-
* @param {boolean} [param0.isFlat = false] - Whether to place generated declaration files in a flattened directory.
|
|
212
195
|
* @param {boolean} [param0.verbose = false] - Whether to log additional information while generating and moving declaration files.
|
|
213
|
-
* @param {
|
|
196
|
+
* @param {import('../utils/build.mjs').BundleType[]} param0.bundles - The bundles to create declarations for.
|
|
214
197
|
* @param {string} param0.srcDir - The source directory.
|
|
215
198
|
* @param {string} param0.buildDir - The build directory.
|
|
216
199
|
* @param {string} param0.cwd - The current working directory.
|
|
@@ -225,7 +208,6 @@ export async function createTypes({
|
|
|
225
208
|
cwd,
|
|
226
209
|
skipTsc,
|
|
227
210
|
useTsgo = false,
|
|
228
|
-
isFlat = false,
|
|
229
211
|
packageType,
|
|
230
212
|
verbose,
|
|
231
213
|
}) {
|
|
@@ -253,7 +235,6 @@ export async function createTypes({
|
|
|
253
235
|
inputDir: tmpDir,
|
|
254
236
|
buildDir,
|
|
255
237
|
bundles,
|
|
256
|
-
isFlat,
|
|
257
238
|
packageType,
|
|
258
239
|
});
|
|
259
240
|
} finally {
|
package/vale/.vale.ini
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
StylesPath = styles
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# Enforce a single way to write specific terms or phrases.
|
|
2
|
+
extends: substitution
|
|
3
|
+
message: Use '%s' instead of '%s'
|
|
4
|
+
level: error
|
|
5
|
+
ignorecase: true # There is only one correct way to spell those, so we want to match inputs regardless of case.
|
|
6
|
+
# swap maps tokens in form of bad: good
|
|
7
|
+
# for more information: https://vale.sh/docs/topics/styles/#substitution
|
|
8
|
+
swap:
|
|
9
|
+
' api': ' API'
|
|
10
|
+
'typescript ': 'TypeScript '
|
|
11
|
+
' ts': ' TypeScript'
|
|
12
|
+
javascript: JavaScript
|
|
13
|
+
' js': ' JavaScript'
|
|
14
|
+
' css ': ' CSS '
|
|
15
|
+
' html ': ' HTML '
|
|
16
|
+
NPM: npm # https://css-tricks.com/start-sentence-npm/
|
|
17
|
+
Github: GitHub
|
|
18
|
+
StackOverflow: Stack Overflow
|
|
19
|
+
Stack Overflow: Stack Overflow
|
|
20
|
+
CSS modules: CSS Modules
|
|
21
|
+
Tailwind CSS: Tailwind CSS
|
|
22
|
+
Heat map: Heatmap
|
|
23
|
+
Tree map: Treemap
|
|
24
|
+
Sparkline Chart: Sparkline chart
|
|
25
|
+
Gauge Chart: Gauge chart
|
|
26
|
+
Treemap Chart: Treemap chart
|
|
27
|
+
sub-component: subcomponent
|
|
28
|
+
sub-components: subcomponents
|
|
29
|
+
use-case: use case
|
|
30
|
+
usecase: use case
|
|
31
|
+
Material 3: Material Design 3
|
|
32
|
+
VSCode: VS Code
|
|
33
|
+
VS Code: VS Code
|
|
34
|
+
'Codesandbox ': 'CodeSandbox '
|
|
35
|
+
code sandbox: CodeSandbox
|
|
36
|
+
Stackblitz: StackBlitz
|
|
37
|
+
Webpack: webpack # https://x.com/wSokra/status/855800490713649152
|
|
38
|
+
app router: App Router # Next.js
|
|
39
|
+
pages router: Pages Router # Next.js
|
|
40
|
+
page router: Pages Router # Next.js
|
|
41
|
+
eslint: ESLint
|
|
42
|
+
ES modules: ES modules
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Write things correctly, please no wrong references.
|
|
2
|
+
extends: substitution
|
|
3
|
+
message: Use '%s' instead of '%s'
|
|
4
|
+
level: error
|
|
5
|
+
ignorecase: false
|
|
6
|
+
# swap maps tokens in form of bad: good
|
|
7
|
+
# for more information: https://vale.sh/docs/topics/styles/#substitution
|
|
8
|
+
swap:
|
|
9
|
+
eg: e.g.
|
|
10
|
+
eg\.: e.g.
|
|
11
|
+
e\.g: e.g.
|
|
12
|
+
ie: i.e.
|
|
13
|
+
ie\.: i.e.
|
|
14
|
+
i\.e: i.e.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
extends: substitution
|
|
2
|
+
message: Use '%s' instead of '%s'
|
|
3
|
+
link: https://developers.google.com/style/abbreviations
|
|
4
|
+
ignorecase: false
|
|
5
|
+
level: error
|
|
6
|
+
nonword: true
|
|
7
|
+
action:
|
|
8
|
+
name: replace
|
|
9
|
+
swap:
|
|
10
|
+
'\b(?:eg|e\.g\.)(?=[\s,;])': for example
|
|
11
|
+
'\b(?:ie|i\.e\.)(?=[\s,;])': that is
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Without a non-breaking space, brand names can be split in the middle
|
|
2
|
+
# with the start and end on two different lines.
|
|
3
|
+
# For example, Apple does this meticulously with their brand name: https://www.apple.com/macbook-air/.
|
|
4
|
+
# Also read https://www.chrisdpeters.com/blog/using-non-breaking-spaces-to-help-with-branding/ for why.
|
|
5
|
+
extends: substitution
|
|
6
|
+
message: Use a non-breaking space (option+space on Mac, Alt+0160 on Windows or AltGr+Space on Linux, instead of space) for brand name ('%s' instead of '%s')
|
|
7
|
+
level: error
|
|
8
|
+
ignorecase: true
|
|
9
|
+
# swap maps tokens in form of bad: good
|
|
10
|
+
# for more information: https://vale.sh/docs/topics/styles/#substitution
|
|
11
|
+
swap:
|
|
12
|
+
Material UI: Material UI
|
|
13
|
+
MUI X: MUI X
|
|
14
|
+
Base UI: Base UI
|
|
15
|
+
MUI Base: MUI Base
|
|
16
|
+
MUI System: MUI System
|
|
17
|
+
MUI Store: MUI Store
|
|
18
|
+
MUI Core: MUI Core
|
|
19
|
+
MUI Toolpad: Toolpad
|
|
20
|
+
MUI Toolpad: Toolpad
|
|
21
|
+
MUI Connect: MUI Connect
|
|
22
|
+
Pigment CSS: Pigment CSS
|