Skip to content

Commit 82efdbc

Browse files
authored
chore: [#0] Replaces cp command with Node.js FS
1 parent 6ced6d8 commit 82efdbc

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

packages/jest-environment/bin/copy-tsdef-for-lit.cjs

+20-20
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/* eslint-disable @typescript-eslint/no-var-requires*/
33

44
const Path = require('path');
5-
const ChildProcess = require('child_process');
5+
const fsp = require('fs/promises');
66

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

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

19+
async function copyTsDefFiles(lib) {
20+
const srcDir = getLibPath(lib);
21+
const destDir = Path.resolve(Path.join('lib', 'node_modules', lib));
22+
23+
await fsp.mkdir(destDir, { recursive: true });
24+
25+
const files = await fsp.readdir(srcDir);
26+
27+
const tsDefFiles = files.filter((file) => file.endsWith('.d.ts'));
28+
29+
const copyPromises = tsDefFiles.map((file) => {
30+
const srcFile = Path.join(srcDir, file);
31+
const destFile = Path.join(destDir, file);
32+
return fsp.copyFile(srcFile, destFile);
33+
});
34+
await Promise.all(copyPromises);
35+
}
36+
1937
async function main() {
20-
await Promise.all(
21-
LIBS.map(
22-
(lib) =>
23-
new Promise((resolve, reject) => {
24-
ChildProcess.exec(
25-
`cp ${Path.join(getLibPath(lib), '*.d.ts')} ${Path.resolve(
26-
Path.join('lib', 'node_modules', lib)
27-
)}`,
28-
(error, stdout, stderr) => {
29-
if (error || stderr) {
30-
reject(error || new Error(stderr));
31-
return;
32-
}
33-
resolve(stdout);
34-
}
35-
);
36-
})
37-
)
38-
);
38+
await Promise.all(LIBS.map((lib) => copyTsDefFiles(lib)));
3939
}
4040

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

0 commit comments

Comments
 (0)