diff --git a/package.json b/package.json index 238977d..9afaac4 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/TestCompiler.mts b/scripts/TestCompiler.mts similarity index 87% rename from test/TestCompiler.mts rename to scripts/TestCompiler.mts index 8b4f886..b5804b3 100644 --- a/test/TestCompiler.mts +++ b/scripts/TestCompiler.mts @@ -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); @@ -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); } @@ -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); }, @@ -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); diff --git a/build.mts b/scripts/build.mts similarity index 97% rename from build.mts rename to scripts/build.mts index 94a6bf8..2f43cc4 100644 --- a/build.mts +++ b/scripts/build.mts @@ -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"; @@ -24,6 +23,7 @@ import { Logger, transports } from "winston"; +import {mode} from "./mode.mjs"; class Build { @@ -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" @@ -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); diff --git a/scripts/mode.mts b/scripts/mode.mts new file mode 100644 index 0000000..0785d70 --- /dev/null +++ b/scripts/mode.mts @@ -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}; \ No newline at end of file diff --git a/test/BooleanTest.mts b/test/BooleanTest.mts index dff019f..9250fc7 100644 --- a/test/BooleanTest.mts +++ b/test/BooleanTest.mts @@ -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; diff --git a/test/ObjectTest.mts b/test/ObjectTest.mts index 044e81f..e131d36 100644 --- a/test/ObjectTest.mts +++ b/test/ObjectTest.mts @@ -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; diff --git a/tsconfig.json b/tsconfig.json index e5e55d8..bf2aee6 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -20,14 +20,13 @@ "sourceMap": true }, "include": [ - "build.mts", "src/**/*.mts", "test/**/*.mts" ], "exclude": [ + "scripts", "node_modules", "target", - "scripts", "./.eslintrc.mjs", "test/TestGlobalConfiguration.mts" ],