An open source design system that's fully customizable and agent ready
TypeScript
Remove internal identifier from published source (#6873)
Cindy Zhang61defd1fc79a
diff --git a/.changeset/public-package-identifiers.md b/.changeset/public-package-identifiers.mdnew file mode 100644index 0000000000..e51a166f88--- /dev/null+++ b/.changeset/public-package-identifiers.md@@ -0,0 +1,7 @@+---+'@astryxdesign/core': patch+---++[fix] Replace an environment-specific example token in published Markdown audit source with a neutral fixed-width token.++@cixzhangdiff --git a/package.json b/package.jsonindex 114d97c8b7..5bdd54c735 100644--- a/package.json+++ b/package.json@@ -13,7 +13,8 @@"test:a11y-contract": "playwright test --config playwright.config.ts --project chromium","test:docsite-browser": "playwright test --config apps/docsite/playwright.config.ts","check:package-boundaries": "node scripts/check-package-boundaries.js",- "check:repo": "pnpm check:visual-owner && pnpm check:sync && pnpm check:knowledge && pnpm check:package-boundaries && pnpm check:changesets && pnpm check:demo-media && pnpm check:executable-bits && pnpm check:cli-structure && pnpm check:use-client && pnpm check:portable-scripts && pnpm check:i18n-runtime && pnpm check:i18n-catalog && pnpm check:cldr-weekdays && pnpm check:fixtures && pnpm check:setup-contract",+ "check:public-package-identifiers": "vitest run --project node scripts/check-public-package-identifiers.test.mjs && node scripts/check-public-package-identifiers.mjs",+ "check:repo": "pnpm check:visual-owner && pnpm check:sync && pnpm check:knowledge && pnpm check:package-boundaries && pnpm check:changesets && pnpm check:public-package-identifiers && pnpm check:demo-media && pnpm check:executable-bits && pnpm check:cli-structure && pnpm check:use-client && pnpm check:portable-scripts && pnpm check:i18n-runtime && pnpm check:i18n-catalog && pnpm check:cldr-weekdays && pnpm check:fixtures && pnpm check:setup-contract","check:visual-owner": "node scripts/check-visual-workflow-owner.mjs","check:fixtures": "node internal/vibe-tests/scripts/fixture-suite.mjs verify","generate:cldr-weekdays": "node scripts/generate-cldr-weekdays.mjs",diff --git a/packages/core/src/Markdown/MarkdownTable.a11y.chromium.spec.ts b/packages/core/src/Markdown/MarkdownTable.a11y.chromium.spec.tsindex 9ae4a8026b..52b7f5bcd0 100644--- a/packages/core/src/Markdown/MarkdownTable.a11y.chromium.spec.ts+++ b/packages/core/src/Markdown/MarkdownTable.a11y.chromium.spec.ts@@ -703,7 +703,7 @@ test('a column floor survives the cell padding it sits behind', async ({const longLabel = wide.headers.find(header =>header.text.startsWith('Accessibility status'),);- // `D116586407` is ten characters and cannot break: the column carries it.+ // `REFERENCE1` is ten characters and cannot break: the column carries it.expect(identifier?.contentWidth).toBeGreaterThanOrEqual(10 * wide.chPx - 1);// A 42-character label floors the column at 21ch (its body floor) and wraps.expect(longLabel?.contentWidth).toBeGreaterThanOrEqual(20 * wide.chPx - 1);diff --git a/scripts/check-public-package-identifiers.mjs b/scripts/check-public-package-identifiers.mjsnew file mode 100644index 0000000000..2a5e27a71a--- /dev/null+++ b/scripts/check-public-package-identifiers.mjs@@ -0,0 +1,113 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++import {execFileSync} from 'node:child_process';+import fs from 'node:fs';+import path from 'node:path';+import {fileURLToPath} from 'node:url';++const INTERNAL_HOST =+ /(?:internalfb\.com|internalmeta\.com|fburl\.com|registry\.facebook\.net)/iu;+const INTERNAL_DIFF = /(^|[^A-Za-z0-9_])D[0-9]{6,}(?![A-Za-z0-9_])/u;++function publishedPackageDirectories(root) {+ const directories = [];+ for (const parent of ['packages', path.join('packages', 'themes')]) {+ const absoluteParent = path.join(root, parent);+ for (const entry of fs.readdirSync(absoluteParent, {withFileTypes: true})) {+ if (!entry.isDirectory()) continue;+ const packageDirectory = path.join(absoluteParent, entry.name);+ const packageFile = path.join(packageDirectory, 'package.json');+ if (!fs.existsSync(packageFile)) continue;+ const manifest = JSON.parse(fs.readFileSync(packageFile, 'utf8'));+ if (manifest.private || manifest.astryx?.canaryOnly) continue;+ directories.push(packageDirectory);+ }+ }+ return directories.sort();+}++function packedFiles(root, packageDirectory) {+ const output = execFileSync(+ 'npm',+ [+ 'pack',+ `./${path.relative(root, packageDirectory)}`,+ '--dry-run',+ '--json',+ '--ignore-scripts',+ ],+ {cwd: root, encoding: 'utf8'},+ );+ const result = JSON.parse(output);+ if (+ !Array.isArray(result) ||+ result.length !== 1 ||+ !Array.isArray(result[0].files)+ ) {+ throw new Error(+ `npm pack returned an unexpected manifest for ${path.relative(root, packageDirectory)}`,+ );+ }+ return result[0].files.map(file => file.path);+}++function findingInLine(line) {+ if (INTERNAL_HOST.test(line)) return 'internal host reference';+ if (INTERNAL_DIFF.test(line)) return 'internal diff identifier';+ return null;+}++export function scanPackage(root, packageDirectory) {+ const findings = [];+ for (const relativeFile of packedFiles(root, packageDirectory)) {+ const file = path.resolve(packageDirectory, relativeFile);+ if (!file.startsWith(`${path.resolve(packageDirectory)}${path.sep}`)) {+ throw new Error(+ `npm pack listed a file outside ${path.relative(root, packageDirectory)}`,+ );+ }+ const contents = fs.readFileSync(file);+ if (contents.includes(0)) continue;+ const lines = contents.toString('utf8').split(/\r?\n/u);+ for (const [index, line] of lines.entries()) {+ const kind = findingInLine(line);+ if (kind) {+ findings.push({+ file: path.relative(root, file).split(path.sep).join('/'),+ line: index + 1,+ kind,+ });+ }+ }+ }+ return findings;+}++export function scanPublishedPackages(root) {+ return publishedPackageDirectories(root).flatMap(packageDirectory =>+ scanPackage(root, packageDirectory),+ );+}++function main() {+ const root = path.resolve(process.cwd());+ const findings = scanPublishedPackages(root);+ if (findings.length > 0) {+ for (const finding of findings) {+ console.error(`${finding.file}:${finding.line}: ${finding.kind}`);+ }+ console.error(+ `Published-package identifier check failed with ${findings.length} finding(s).`,+ );+ process.exitCode = 1;+ return;+ }+ console.log('Published-package identifier check passed.');+}++if (+ process.argv[1] &&+ fileURLToPath(import.meta.url) === path.resolve(process.argv[1])+) {+ main();+}diff --git a/scripts/check-public-package-identifiers.test.mjs b/scripts/check-public-package-identifiers.test.mjsnew file mode 100644index 0000000000..d11aa44507--- /dev/null+++ b/scripts/check-public-package-identifiers.test.mjs@@ -0,0 +1,52 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++import fs from 'node:fs';+import os from 'node:os';+import path from 'node:path';+import {expect, it} from 'vitest';+import {scanPackage} from './check-public-package-identifiers.mjs';++function fixture() {+ const root = fs.mkdtempSync(+ path.join(os.tmpdir(), 'astryx-package-identifiers-'),+ );+ const packageDirectory = path.join(root, 'packages', 'fixture');+ fs.mkdirSync(packageDirectory, {recursive: true});+ fs.writeFileSync(+ path.join(packageDirectory, 'package.json'),+ JSON.stringify({+ name: '@astryxdesign/fixture',+ version: '1.0.0',+ files: ['published.txt'],+ }),+ );+ return {root, packageDirectory};+}++it('scans files npm includes and redacts the matched identifier', () => {+ const {root, packageDirectory} = fixture();+ const identifier = ['D', '123456'].join('');+ fs.writeFileSync(+ path.join(packageDirectory, 'published.txt'),+ `before\n${identifier}\nafter\n`,+ );+ fs.writeFileSync(path.join(packageDirectory, 'ignored.txt'), identifier);++ expect(scanPackage(root, packageDirectory)).toEqual([+ {+ file: 'packages/fixture/published.txt',+ line: 2,+ kind: 'internal diff identifier',+ },+ ]);+});++it('accepts public fixed-width example tokens', () => {+ const {root, packageDirectory} = fixture();+ fs.writeFileSync(+ path.join(packageDirectory, 'published.txt'),+ 'REFERENCE1\n',+ );++ expect(scanPackage(root, packageDirectory)).toEqual([]);+});