Skip to content

Commit

Permalink
fix(generate): use tsconfig from shared nodecg-io-tsconfig package
Browse files Browse the repository at this point in the history
  • Loading branch information
hlxid authored Dec 29, 2021
1 parent 472d112 commit 298c7cb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 24 deletions.
14 changes: 9 additions & 5 deletions src/generate/packageJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,20 @@ async function genDependencies(opts: GenerationOptions, serviceDeps: Dependency[
* @param nodecgDir the directory in which nodecg is installed. Used to get nodecg version which will be used by nodecg dependency.
*/
async function genTypeScriptDependencies(opts: GenerationOptions): Promise<Dependency[]> {
logger.debug(`Fetching latest ${opts.nodeeCGTypingsPackage}, typescript and @types/node versions...`);
const [nodecgVersion, latestNodeTypes, latestTypeScript] = await Promise.all([
logger.debug(
`Fetching latest ${opts.nodeeCGTypingsPackage}, nodecg-io-tsconfig, typescript and @types/node versions...`,
);
const [nodecgVersion, latestTsConfig, latestTypeScript, latestNodeTypes] = await Promise.all([
getLatestPackageVersion(opts.nodeeCGTypingsPackage),
getLatestPackageVersion("@types/node"),
getLatestPackageVersion("nodecg-io-tsconfig"),
getLatestPackageVersion("typescript"),
getLatestPackageVersion("@types/node"),
]);

return [
[opts.nodeeCGTypingsPackage, `^${nodecgVersion}`],
["@types/node", `^${latestNodeTypes}`],
[opts.nodeeCGTypingsPackage, `^${nodecgVersion}`],
["nodecg-io-tsconfig", `^${latestTsConfig}`],
["typescript", `^${latestTypeScript}`],
];
}
Expand All @@ -90,7 +94,7 @@ async function genTypeScriptDependencies(opts: GenerationOptions): Promise<Depen
*/
function genScripts(opts: GenerationOptions) {
if (opts.language !== "typescript") {
// For JS we don't need any scripts to build anythiing.
// For JS we don't need any scripts to build anything.
return undefined;
}

Expand Down
26 changes: 7 additions & 19 deletions src/generate/tsConfig.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,18 @@
import { GenerationOptions } from "./prompt";
import { writeBundleFile } from "./utils";

const defaultTsConfigJson = {
compilerOptions: {
target: "es2019",
sourceMap: true,
lib: ["es2019"],
alwaysStrict: true,
forceConsistentCasingInFileNames: true,
noFallthroughCasesInSwitch: true,
noImplicitAny: true,
noImplicitReturns: true,
noImplicitThis: true,
strictNullChecks: true,
skipLibCheck: true,
module: "CommonJS",
types: ["node"],
},
};

/**
* Generates a tsconfig.json for a bundle if the language was set to typescript.
*/
export async function genTsConfig(opts: GenerationOptions): Promise<void> {
// Only TS needs its tsconfig.json compiler configuration
if (opts.language === "typescript") {
await writeBundleFile(defaultTsConfigJson, opts.bundlePath, "tsconfig.json");
await writeBundleFile(
{
extends: "nodecg-io-tsconfig",
},
opts.bundlePath,
"tsconfig.json",
);
}
}

0 comments on commit 298c7cb

Please sign in to comment.