Skip to content

chore(NODE-5277): add definition clean up script #576

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 18, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
35 changes: 35 additions & 0 deletions etc/clean_definition_files.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#! /usr/bin/env node
Copy link
Contributor

Choose a reason for hiding this comment

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

just curious - any reason we're using a cjs module if we're not using top level await?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A few non binding reasons:

  • aligning with the choice made in the driver
  • esm and await is slower for scripting tasks like this
  • cjs has greater compatibility, it can be a nice-to-have that little scripts like this run fine on node 8 (still a common version on linux package managers) despite the package src having a higher node requirement.

/* eslint-disable @typescript-eslint/no-var-requires */
const fs = require('fs');
const path = require('path');

function* walk(root) {
const directoryContents = fs.readdirSync(root);
for (const filepath of directoryContents) {
const fullPath = path.join(root, filepath);
const stat = fs.statSync(fullPath);
if (stat.isDirectory()) {
yield fullPath;
yield* walk(fullPath);
} else if (stat.isFile()) {
yield fullPath;
}
}
}

const libPath = path.resolve(__dirname, '..', 'lib');
if (fs.existsSync(libPath)) {
const definitionFiles = Array.from(walk(libPath))
.filter(filePath => filePath.endsWith('.d.ts') || filePath.endsWith('.d.ts.map'));

for (const definitionFile of definitionFiles) {
fs.unlinkSync(definitionFile);
}

const emptyDirectories = Array.from(walk(libPath))
.filter(filePath => fs.statSync(filePath).isDirectory() && fs.readdirSync(filePath).length === 0);
Comment on lines +29 to +30
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unlike the driver, BSON has only the top-level bundles in lib/ so the lib/parser/ and lib/utils/ directories can be cleaned up.


for (const emptyDirectory of emptyDirectories) {
fs.rmdirSync(emptyDirectory);
}
}
Loading