Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,12 @@
"cleave.js": "^1.6.0",
"concurrently": "^8.2.2",
"core-js": "^3.21.1",
"fast-glob": "^3.3.2",
"foundation-emails": "^2.3.1",
"intl-tel-input": "^24.5.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"source-map-loader": "^4.0.0",
"webpack": "^5.94.0",
"webpack": "^5.97.1",
"webpack-assets-manifest": "^5.2.1",
"webpack-cli": "^5.1.4"
},
Expand All @@ -58,7 +57,7 @@
"@types/dirty-chai": "^2.0.2",
"@types/grecaptcha": "^3.0.4",
"@types/mocha": "^10.0.0",
"@types/node": "^22.10.1",
"@types/node": "^22.10.2",
"@types/react": "^17.0.39",
"@types/react-dom": "^17.0.11",
"@types/sinon": "^10.0.13",
Expand All @@ -68,7 +67,7 @@
"@typescript-eslint/parser": "^6.7.5",
"chai": "^4.3.10",
"chai-as-promised": "^7.1.1",
"clipboard-polyfill": "^3.0.3",
"clipboard-polyfill": "^4.1.1",
"dirty-chai": "^2.0.1",
"dom-accessibility-api": "^0.5.14",
"eslint": "^8.43.0",
Expand All @@ -91,7 +90,7 @@
"stylelint": "^16.2.1",
"svgo": "^3.2.0",
"swr": "^2.0.0",
"typescript": "^5.2.2",
"typescript": "^5.7.2",
"yarn-deduplicate": "^6.0.2"
},
"resolutions": {
Expand Down
24 changes: 17 additions & 7 deletions scripts/enforce-typescript-files.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#!/usr/bin/env node

import assert from 'node:assert';
import { readFile } from 'node:fs/promises';
import { dirname, join } from 'node:path';
import glob from 'fast-glob';
import { readFile, glob } from 'node:fs/promises';
import { dirname, relative, join } from 'node:path';

// Do not add to this list! All new scripts should be written in TypeScript, so this list should
// only ever shrink over time. Scripts which are loaded directly by Node.js should exist within
Expand Down Expand Up @@ -70,15 +69,26 @@ const LEGACY_FILE_EXCEPTIONS = [
'spec/javascript/packages/document-capture/services/upload-spec.js',
];

const packagesWithEntrypoints = await glob('app/javascript/packages/*/package.json')
const packagesWithEntrypoints = await Array.fromAsync(
glob('app/javascript/packages/*/package.json'),
)
.then((files) => Promise.all(files.map(async (file) => [file, await readFile(file, 'utf-8')])))
.then((contents) => contents.map(([file, content]) => [file, JSON.parse(content)]))
.then((manifests) => manifests.filter(([_file, manifest]) => manifest.exports || manifest.main))
.then((manifests) => manifests.map(([file]) => dirname(file)));

const jsFiles = await glob(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just curious, did we find all these by searching for await glob( or did they turn up as type errors?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had searched fast-glob and updated references. TypeScript did come in handy when it came to converting to using Array.fromAsync, since the return type of Node.js's built-in glob is neither an array nor a promise, but instead an AsyncIterable.

['app/{javascript/packages,components}/**/*.{js,jsx}', 'spec/javascript/*/**/*.{js,jsx}'],
{ ignore: packagesWithEntrypoints.map((path) => join(path, '**')) },
const jsFileEntries = await Array.fromAsync(
glob(['app/{javascript/packages,components}/**/*.{js,jsx}', 'spec/javascript/*/**/*.{js,jsx}'], {
exclude: (fileName) =>
packagesWithEntrypoints.some((path) =>
relative(process.cwd(), fileName.parentPath).startsWith(path),
),
withFileTypes: true,
}),
);

const jsFiles = jsFileEntries.map(({ parentPath, name }) =>
relative(process.cwd(), join(parentPath, name)),
);

const invalidExceptions = LEGACY_FILE_EXCEPTIONS.filter((file) => !jsFiles.includes(file));
Expand Down
9 changes: 5 additions & 4 deletions scripts/validate-workspaces.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#!/usr/bin/env node

import { readFile, stat } from 'node:fs/promises';
import { readFile, stat, glob } from 'node:fs/promises';
import { dirname, basename, join, resolve, relative } from 'node:path';
import glob from 'fast-glob';

/** @typedef {[path: string, manifest: Record<string, any>]} ManifestPair */
/** @typedef {ManifestPair[]} ManifestPairs */
Expand Down Expand Up @@ -129,7 +128,9 @@ function checkPackageSideEffectsIncludesCustomElements(manifests) {
return Promise.all(
manifests.map(async ([manifestPath, manifest]) => {
const manifestDirectory = dirname(manifestPath);
const customElementPaths = await glob(join(manifestDirectory, '*-element.ts'));
const customElementPaths = await Array.fromAsync(
glob(join(manifestDirectory, '*-element.ts')),
);
const expectedPaths = customElementPaths.map((path) => resolve(path));
const actualPaths = Array.from(manifest.sideEffects).map((path) =>
resolve(join(manifestDirectory, path)),
Expand Down Expand Up @@ -170,7 +171,7 @@ const EXCEPTIONS = {
checkHaveCorrectPackageName: ['app/javascript/packages/eslint-plugin/package.json'],
};

const manifestPaths = await glob('app/javascript/packages/*/package.json');
const manifestPaths = await Array.fromAsync(glob('app/javascript/packages/*/package.json'));
Promise.all(manifestPaths.map(async (path) => [path, await readFile(path, 'utf-8')]))
.then((contents) =>
contents.map(([path, content]) => /** @type {ManifestPair} */ ([path, JSON.parse(content)])),
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"exclude": [
"**/fixtures",
"spec/**/*.spec.js",
"app/javascript/packs/digital-analytics-program.ts",
"app/javascript/packages/analytics/digital-analytics-program*.js"
]
}
1 change: 0 additions & 1 deletion typings/clipboard-polyfill/overwrite-globals.d.ts

This file was deleted.

2 changes: 1 addition & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { parse, resolve } = require('path');
const url = require('url');
const { sync: glob } = require('fast-glob');
const { globSync: glob } = require('fs');
const WebpackAssetsManifest = require('webpack-assets-manifest');
const RailsI18nWebpackPlugin = require('@18f/identity-rails-i18n-webpack-plugin');
const RailsAssetsWebpackPlugin = require('@18f/identity-assets/webpack-plugin');
Expand Down
Loading