Skip to content

Commit e137f7f

Browse files
committed
chore(scripts): use mjs for downlevel-dts scripts
1 parent 3bc2986 commit e137f7f

File tree

4 files changed

+18
-18
lines changed

4 files changed

+18
-18
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"main": "index.js",
77
"scripts": {
88
"copy-models": "node ./scripts/copy-models",
9-
"downlevel-dts": "node ./scripts/downlevel-dts",
9+
"downlevel-dts": "node --es-module-specifier-resolution=node ./scripts/downlevel-dts",
1010
"generate-clients": "node ./scripts/generate-clients",
1111
"bootstrap": "yarn",
1212
"clean": "yarn clear-build-cache && yarn clear-build-info && lerna clean",

scripts/downlevel-dts/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
Runs downlevel-dts npm script (if present) in each workspace of monorepo, and
1111
strips comments from *.d.ts files.
1212
13-
Usage: index.js
13+
Usage: index.mjs
1414
1515
Options:
1616
--version Show version number [boolean]

scripts/downlevel-dts/downlevelWorkspace.js renamed to scripts/downlevel-dts/downlevelWorkspace.mjs

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
const { access, readFile, writeFile } = require("fs/promises");
2-
const { join } = require("path");
3-
const { promisify } = require("util");
4-
const exec = promisify(require("child_process").exec);
5-
const stripComments = require("strip-comments");
1+
import { exec } from "child_process";
2+
import { access, readFile, writeFile } from "fs/promises";
3+
import { join } from "path";
4+
import stripComments from "strip-comments";
5+
import { promisify } from "util";
66

7-
const downlevelWorkspace = async (workspacesDir, workspaceName) => {
7+
const execPromise = promisify(exec);
8+
9+
export const downlevelWorkspace = async (workspacesDir, workspaceName) => {
810
const workspaceDir = join(workspacesDir, workspaceName);
911

1012
const packageJsonPath = join(workspaceDir, "package.json");
@@ -38,7 +40,7 @@ const downlevelWorkspace = async (workspacesDir, workspaceName) => {
3840
try {
3941
await access(downlevelDir);
4042
} catch (error) {
41-
await exec(["yarn", "downlevel-dts"].join(" "), { cwd: workspaceDir });
43+
await execPromise(["yarn", "downlevel-dts"].join(" "), { cwd: workspaceDir });
4244
}
4345

4446
// Strip comments from downlevel-dts files
@@ -55,5 +57,3 @@ const downlevelWorkspace = async (workspacesDir, workspaceName) => {
5557
});
5658
} catch (error) {}
5759
};
58-
59-
module.exports = { downlevelWorkspace };

scripts/downlevel-dts/index.js renamed to scripts/downlevel-dts/index.mjs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
// @ts-check
2-
const yargs = require("yargs");
2+
import parallelLimit from "async/parallelLimit";
3+
import { readdirSync, readFileSync, statSync } from "fs";
4+
import { cpus } from "os";
5+
import { join } from "path";
6+
import yargs from "yargs";
37

4-
const { readFileSync, readdirSync, statSync } = require("fs");
5-
const { join } = require("path");
6-
const { cpus } = require("os");
7-
const { downlevelWorkspace } = require("./downlevelWorkspace");
8-
const parallelLimit = require("async/parallelLimit");
8+
import { downlevelWorkspace } from "./downlevelWorkspace.mjs";
99

1010
// ToDo: Write downlevel-dts as a yargs command, and import yargs in scripts instead.
1111
yargs
1212
.usage(
1313
"Runs downlevel-dts npm script (if present) in each workspace of monorepo," +
1414
" and strips comments from *.d.ts files.\n\n" +
15-
"Usage: index.js"
15+
"Usage: index.mjs"
1616
)
1717
.help()
1818
.alias("h", "help").argv;

0 commit comments

Comments
 (0)