Skip to content
This repository was archived by the owner on Apr 13, 2025. It is now read-only.

Commit b6fc493

Browse files
committed
feat: migrate to ES modules
1 parent df5e96b commit b6fc493

34 files changed

+208
-167
lines changed
File renamed without changes.

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
// but the entry-point needs to be executable so we can't have it in src/index.ts directly
66
// because the resulting file won't have the executable flag and you can't properly use it that way.
77

8-
require("./build/src/index");
8+
import "./build/index.js";

jest.config.cjs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/** @type {import("ts-jest").JestConfigWithTsJest} */
2+
module.exports = {
3+
preset: "ts-jest/presets/default-esm",
4+
testEnvironment: "node",
5+
// We don't want to test nodecg, and without including this jest fails because it includes a invalid json
6+
modulePathIgnorePatterns: ["/nodecg/"],
7+
testMatch: ["<rootDir>/test/**/*.ts", "!**/*.util.ts"],
8+
extensionsToTreatAsEsm: [".ts"],
9+
moduleNameMapper: {
10+
"^(\\.{1,2}/.*)\\.js$": "$1"
11+
},
12+
};

jest.config.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"version": "0.3.1",
44
"description": "The CLI to install and manage nodecg-io installations. Also helps you with nodecg-io bundle related development.",
55
"main": "index.js",
6+
"type": "module",
67
"scripts": {
78
"build": "tsc -b",
89
"run": "tsc -b && node build/index.js",

src/generate/extension.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import CodeBlockWriter from "code-block-writer";
2-
import { getServiceClientName } from "../nodecgIOVersions";
3-
import { Installation } from "../utils/installation";
4-
import { CodeLanguage, GenerationOptions } from "./prompt";
5-
import { writeBundleFile } from "./utils";
2+
import { getServiceClientName } from "../nodecgIOVersions.js";
3+
import { Installation } from "../utils/installation.js";
4+
import { CodeLanguage, GenerationOptions } from "./prompt.js";
5+
import { writeBundleFile } from "./utils.js";
66

77
interface ServiceNames {
88
name: string;
@@ -39,7 +39,11 @@ export async function genExtension(opts: GenerationOptions, install: Installatio
3939
// the service names for each version are hardcoded and unknown for a development version.
4040
const services = install.dev === false ? opts.services.map((svc) => getServiceNames(svc, install.version)) : [];
4141

42-
const writer = new CodeBlockWriter();
42+
// FIXME: Types and jest(running via node.js) require "new CodeBlockWriter()", but when running with node.js
43+
// this needs to be "new CodeBlockWriter.default()" to function, wtf?!.
44+
// Needs figuring out why this is happening.
45+
//@ts-ignore
46+
const writer = new CodeBlockWriter.default();
4347

4448
// imports
4549
genImport(writer, "requireService", opts.corePackage.name, opts.language);

src/generate/index.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import { CommandModule } from "yargs";
2-
import * as fs from "fs";
3-
import { logger } from "../utils/log";
4-
import { directoryExists } from "../utils/fs";
5-
import { Installation, readInstallInfo } from "../utils/installation";
6-
import { corePackages } from "../nodecgIOVersions";
7-
import { GenerationOptions, promptGenerationOpts } from "./prompt";
8-
import { runNpmBuild, runNpmInstall } from "../utils/npm";
9-
import { genExtension } from "./extension";
10-
import { findNodeCGDirectory, getNodeCGIODirectory } from "../utils/nodecgInstallation";
11-
import { genDashboard, genGraphic } from "./panel";
12-
import { genTsConfig } from "./tsConfig";
13-
import { writeBundleFile, yellowInstallCommand } from "./utils";
14-
import { genPackageJson } from "./packageJson";
2+
import { promises as fs } from "fs";
3+
import { logger } from "../utils/log.js";
4+
import { directoryExists } from "../utils/fs.js";
5+
import { Installation, readInstallInfo } from "../utils/installation.js";
6+
import { corePackages } from "../nodecgIOVersions.js";
7+
import { GenerationOptions, promptGenerationOpts } from "./prompt.js";
8+
import { runNpmBuild, runNpmInstall } from "../utils/npm.js";
9+
import { genExtension } from "./extension.js";
10+
import { findNodeCGDirectory, getNodeCGIODirectory } from "../utils/nodecgInstallation.js";
11+
import { genDashboard, genGraphic } from "./panel.js";
12+
import { genTsConfig } from "./tsConfig.js";
13+
import { writeBundleFile, yellowInstallCommand } from "./utils.js";
14+
import { genPackageJson } from "./packageJson.js";
1515

1616
export const generateModule: CommandModule = {
1717
command: "generate",
@@ -64,11 +64,11 @@ export function ensureValidInstallation(install: Installation | undefined): inst
6464
export async function generateBundle(opts: GenerationOptions, install: Installation): Promise<void> {
6565
// Create dir if necessary
6666
if (!(await directoryExists(opts.bundlePath))) {
67-
await fs.promises.mkdir(opts.bundlePath);
67+
await fs.mkdir(opts.bundlePath);
6868
}
6969

7070
// In case some re-executes the command in a already used bundle name we should not overwrite their stuff and error instead.
71-
const filesInBundleDir = await fs.promises.readdir(opts.bundlePath);
71+
const filesInBundleDir = await fs.readdir(opts.bundlePath);
7272
if (filesInBundleDir.length > 0) {
7373
throw new Error(
7474
`Directory for bundle at ${opts.bundlePath} already exists and contains files.\n` +

src/generate/packageJson.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { GenerationOptions } from "./prompt";
2-
import { logger } from "../utils/log";
3-
import { getLatestPackageVersion } from "../utils/npm";
4-
import { genNodeCGDashboardConfig, genNodeCGGraphicConfig } from "./panel";
1+
import { GenerationOptions } from "./prompt.js";
2+
import { logger } from "../utils/log.js";
3+
import { getLatestPackageVersion } from "../utils/npm.js";
4+
import { genNodeCGDashboardConfig, genNodeCGGraphicConfig } from "./panel.js";
55
import { SemVer } from "semver";
6-
import { writeBundleFile } from "./utils";
7-
import { Installation } from "../utils/installation";
6+
import { writeBundleFile } from "./utils.js";
7+
import { Installation } from "../utils/installation.js";
88

99
// Loaction where the development tarballs are hosted.
1010
export const developmentPublishRootUrl = "https://codeoverflow-org.github.io/nodecg-io-publish/";

src/generate/panel.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { GenerationOptions } from "./prompt";
2-
import { writeBundleFile } from "./utils";
1+
import { GenerationOptions } from "./prompt.js";
2+
import { writeBundleFile } from "./utils.js";
33

44
type PanelType = "graphic" | "dashboard";
55

src/generate/prompt.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import * as semver from "semver";
2-
import * as inquirer from "inquirer";
1+
import semver from "semver";
2+
import inquirer from "inquirer";
33
import * as path from "path";
4-
import { directoryExists } from "../utils/fs";
5-
import { Installation } from "../utils/installation";
6-
import { getServicesFromInstall } from "../install/prompt";
7-
import { yellowInstallCommand } from "./utils";
8-
import { findNpmPackages, NpmPackage } from "../utils/npm";
9-
import { corePackage } from "../nodecgIOVersions";
10-
import { getNodeCGIODirectory } from "../utils/nodecgInstallation";
4+
import { directoryExists } from "../utils/fs.js";
5+
import { Installation } from "../utils/installation.js";
6+
import { getServicesFromInstall } from "../install/prompt.js";
7+
import { yellowInstallCommand } from "./utils.js";
8+
import { findNpmPackages, NpmPackage } from "../utils/npm.js";
9+
import { corePackage } from "../nodecgIOVersions.js";
10+
import { getNodeCGIODirectory } from "../utils/nodecgInstallation.js";
1111

1212
/**
1313
* Describes all options for bundle generation a user has answered with inside the inquirer prompt

0 commit comments

Comments
 (0)