Skip to content

Commit

Permalink
Cleanup of build files
Browse files Browse the repository at this point in the history
  • Loading branch information
cowwoc committed Nov 30, 2023
1 parent 37b2154 commit ed67fe0
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 30 deletions.
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@
"url": "https://github.com/cowwoc/requirements.js/"
},
"scripts": {
"build.debug": "tsx build.mts --mode=DEBUG",
"build.release": "tsx build.mts --mode=RELEASE"
"build.debug": "node node_modules/tsx/dist/cli.mjs scripts/build.mts --mode=DEBUG",
"build.release": "node node_modules/tsx/dist/cli.mjs scripts/build.mts --mode=RELEASE"
},
"browser": "browser/index.js",
"module": "node/index.mjs",
"types": "node/index.d.mts",
"sideEffects": false,
"prepublishOnly": "tsx build.mts --mode=DEBUG",
"dependencies": {
"chalk": "^5.3.0",
"diff": "^5.1.0",
Expand Down
13 changes: 7 additions & 6 deletions test/TestCompiler.mts → scripts/TestCompiler.mts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ class TestCompiler
{
// The root directory relative to which external files will be interpreted
private static readonly rootDir: string = path.resolve(".");
private static readonly fileToExclude = "build.mts";
// We have to include at least one existing file to avoid CompilerHost complaining that it couldn't find any
// input files
private static readonly existingFileToSuppressError = "scripts/build.mts";
private static readonly snippetFilename = "test.mts";
private static readonly config = TestCompiler.createParsedCommandLine();
private static readonly defaultCompilerHost = ts.createCompilerHost(TestCompiler.config.options);
Expand All @@ -21,9 +23,8 @@ class TestCompiler
throw Error("tsconfig.json not found");
const {config} = ts.readConfigFile(configFile, ts.sys.readFile);

// We have to include at least one existing file to avoid CompilerHost throwing an exception
config.include = [TestCompiler.snippetFilename, TestCompiler.fileToExclude];
config.exclude.concat(["src/**", "test/**"]);
config.include = [TestCompiler.snippetFilename, TestCompiler.existingFileToSuppressError];
config.exclude = [];

return ts.parseJsonConfigFileContent(config, ts.sys, TestCompiler.rootDir);
}
Expand All @@ -42,7 +43,7 @@ class TestCompiler
{
if (fileName === TestCompiler.snippetFilename)
return snippet;
if (fileName === TestCompiler.fileToExclude)
if (fileName === TestCompiler.existingFileToSuppressError)
return undefined;
return TestCompiler.defaultCompilerHost.readFile(fileName);
},
Expand All @@ -54,7 +55,7 @@ class TestCompiler
{
if (fileName === TestCompiler.snippetFilename)
return ts.createSourceFile(fileName, snippet, languageVersion);
if (fileName === TestCompiler.fileToExclude)
if (fileName === TestCompiler.existingFileToSuppressError)
return undefined;
return TestCompiler.defaultCompilerHost.getSourceFile(fileName, languageVersion, onError,
shouldCreateNewSourceFile);
Expand Down
10 changes: 3 additions & 7 deletions build.mts → scripts/build.mts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import parseArgs from "minimist";
import * as url from "url";
import path from "path";
import {ESLint} from "eslint";
// @ts-ignore
import eslintConfig from "./.eslintrc.mjs";
import eslintConfig from "../.eslintrc.mjs";
import TypeDoc from "typedoc";
import fs from "fs";
import rollupCommonjs from "@rollup/plugin-commonjs";
Expand All @@ -24,6 +23,7 @@ import {
Logger,
transports
} from "winston";
import {mode} from "./mode.mjs";

class Build
{
Expand Down Expand Up @@ -274,7 +274,7 @@ class Build
return new Promise(function(resolve, reject)
{
// https://stackoverflow.com/a/14231570/14731
const process = spawn(c8Path, [mochaPath, "./test/**/*.mts"],
const process = spawn(c8Path, [mochaPath, "./test/**/*.mts", "--mode=" + mode],
{
shell: true,
stdio: "inherit"
Expand Down Expand Up @@ -345,10 +345,6 @@ class LogFactory
}

console.time("Time elapsed");
const env = parseArgs(process.argv.slice(2));
let mode = env.mode;
if (typeof (mode) === "undefined")
mode = "DEBUG";

const __filename = path.basename(url.fileURLToPath(import.meta.url));
const log = LogFactory.getLogger(__filename, mode);
Expand Down
8 changes: 8 additions & 0 deletions scripts/mode.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import parseArgs from "minimist";

const env = parseArgs(process.argv.slice(2));
let mode = env.mode;
if (typeof (mode) === "undefined")
mode = "DEBUG";

export {mode};
8 changes: 2 additions & 6 deletions test/BooleanTest.mts
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,14 @@ import {
requireThat
} from "../src/index.mjs";
import {TestGlobalConfiguration} from "./TestGlobalConfiguration.mjs";
import {TestCompiler} from "./TestCompiler.mjs";
import {TestCompiler} from "../scripts/TestCompiler.mjs";
import os from "os";
import parseArgs from "minimist";
import {mode} from "../scripts/mode.mjs";

const globalConfiguration = new TestGlobalConfiguration(TerminalEncoding.NONE);
const configuration = new Configuration(globalConfiguration);
const requirements = new Requirements(configuration);

const env = parseArgs(process.argv.slice(2));
let mode = env.mode;
if (typeof (mode) === "undefined")
mode = "DEBUG";
let compiler: TestCompiler | undefined;
if (mode === "DEBUG")
compiler = undefined;
Expand Down
8 changes: 2 additions & 6 deletions test/ObjectTest.mts
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,16 @@ import {
TerminalEncoding
} from "../src/internal/internal.mjs";
import {Requirements} from "../src/index.mjs";
import {TestCompiler} from "./TestCompiler.mjs";
import {TestCompiler} from "../scripts/TestCompiler.mjs";
import {TestGlobalConfiguration} from "./TestGlobalConfiguration.mjs";
import * as os from "os";
import parseArgs from "minimist";
import {mode} from "../scripts/mode.mjs";


const globalConfiguration = new TestGlobalConfiguration(TerminalEncoding.NONE);
const configuration = new Configuration(globalConfiguration);
const requirements = new Requirements(configuration);

const env = parseArgs(process.argv.slice(2));
let mode = env.mode;
if (typeof (mode) === "undefined")
mode = "DEBUG";
let compiler: TestCompiler | undefined;
if (mode === "DEBUG")
compiler = undefined;
Expand Down
3 changes: 1 addition & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@
"sourceMap": true
},
"include": [
"build.mts",
"src/**/*.mts",
"test/**/*.mts"
],
"exclude": [
"scripts",
"node_modules",
"target",
"scripts",
"./.eslintrc.mjs",
"test/TestGlobalConfiguration.mts"
],
Expand Down

0 comments on commit ed67fe0

Please sign in to comment.