Skip to content

Commit

Permalink
chore: [#0] Replaces cp command with Node.js FS
Browse files Browse the repository at this point in the history
  • Loading branch information
btea authored Feb 22, 2025
1 parent 6ced6d8 commit 82efdbc
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions packages/jest-environment/bin/copy-tsdef-for-lit.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/* eslint-disable @typescript-eslint/no-var-requires*/

const Path = require('path');
const ChildProcess = require('child_process');
const fsp = require('fs/promises');

const LIBS = ['@lit/reactive-element', 'lit', 'lit-element', 'lit-html'];

Expand All @@ -16,26 +16,26 @@ function getLibPath(lib) {
return Path.join(split[0], 'node_modules', modulePath);
}

async function copyTsDefFiles(lib) {
const srcDir = getLibPath(lib);
const destDir = Path.resolve(Path.join('lib', 'node_modules', lib));

await fsp.mkdir(destDir, { recursive: true });

const files = await fsp.readdir(srcDir);

const tsDefFiles = files.filter((file) => file.endsWith('.d.ts'));

const copyPromises = tsDefFiles.map((file) => {
const srcFile = Path.join(srcDir, file);
const destFile = Path.join(destDir, file);
return fsp.copyFile(srcFile, destFile);
});
await Promise.all(copyPromises);
}

async function main() {
await Promise.all(
LIBS.map(
(lib) =>
new Promise((resolve, reject) => {
ChildProcess.exec(
`cp ${Path.join(getLibPath(lib), '*.d.ts')} ${Path.resolve(
Path.join('lib', 'node_modules', lib)
)}`,
(error, stdout, stderr) => {
if (error || stderr) {
reject(error || new Error(stderr));
return;
}
resolve(stdout);
}
);
})
)
);
await Promise.all(LIBS.map((lib) => copyTsDefFiles(lib)));
}

process.on('unhandledRejection', (reason) => {
Expand Down

0 comments on commit 82efdbc

Please sign in to comment.