diff --git a/packages/docs/package.json b/packages/docs/package.json index 52c0b3bb6..b29b6ce15 100644 --- a/packages/docs/package.json +++ b/packages/docs/package.json @@ -16,8 +16,9 @@ "scripts": { "build": "tsx --tsconfig ./scripts/tsconfig.json ./build.mts", "clear": "docusaurus clear", - "deploy": "docusaurus deploy", + "deploy": "tsx --tsconfig ./scripts/tsconfig.json ./deploy.mts", "docusaurus": "docusaurus", + "lint": "tsx --tsconfig ./scripts/tsconfig.json ./lint.mts", "serve": "docusaurus serve", "start": "docusaurus start", "swizzle": "docusaurus swizzle", diff --git a/packages/docs/scripts/build.mts b/packages/docs/scripts/build.mts index f3d58a638..269ab11f8 100644 --- a/packages/docs/scripts/build.mts +++ b/packages/docs/scripts/build.mts @@ -11,11 +11,7 @@ const GENERATED_DOC_DIRECTORY_NAMES = [ "eslint-config-isaacscript", ] as const; -await buildScript(async ({ packageRoot, outDir }) => { - if (outDir === undefined) { - outDir = "dist"; // eslint-disable-line no-param-reassign - } - +await buildScript(async ({ packageRoot }) => { const generatedDocPaths = GENERATED_DOC_DIRECTORY_NAMES.map((directoryName) => path.join(packageRoot, "docs", directoryName), ); diff --git a/packages/eslint-plugin-isaacscript/scripts/build.mts b/packages/eslint-plugin-isaacscript/scripts/build.mts index 1fc0620f1..ef69b762a 100644 --- a/packages/eslint-plugin-isaacscript/scripts/build.mts +++ b/packages/eslint-plugin-isaacscript/scripts/build.mts @@ -14,7 +14,6 @@ await buildScript(async ({ outDir, packageRoot }) => { outDir, 'Failed to get the "outDir" from the "tsconfig.json" file.', ); - rm(outDir); await buildTypeScript(packageRoot); copyToMonorepoNodeModules(packageRoot, outDir); diff --git a/packages/isaac-lua-polyfill/scripts/build.ts b/packages/isaac-lua-polyfill/scripts/build.ts index 73ca44298..e2b88c09e 100644 --- a/packages/isaac-lua-polyfill/scripts/build.ts +++ b/packages/isaac-lua-polyfill/scripts/build.ts @@ -1,12 +1,5 @@ -import { buildScript, buildTypeScript, rm } from "isaacscript-common-node"; -import { assertDefined } from "isaacscript-common-ts"; - -await buildScript(async ({ outDir, packageRoot }) => { - assertDefined( - outDir, - 'Failed to get the "outDir" from the "tsconfig.json" file.', - ); - rm(outDir); +import { buildScript, buildTypeScript } from "isaacscript-common-node"; +await buildScript(async ({ packageRoot }) => { await buildTypeScript(packageRoot); }); diff --git a/packages/isaac-typescript-definitions/package.json b/packages/isaac-typescript-definitions/package.json index 0c82663f6..e84cfb0c3 100644 --- a/packages/isaac-typescript-definitions/package.json +++ b/packages/isaac-typescript-definitions/package.json @@ -29,9 +29,9 @@ "README.md" ], "scripts": { - "build": "tsx scripts/build.ts", + "build": "tsx --tsconfig ./scripts/tsconfig.json ./scripts/build.ts", "docs": "typedoc", - "lint": "tsx scripts/lint.ts" + "lint": "tsx --tsconfig ./scripts/tsconfig.json ./scripts/lint.ts" }, "dependencies": { "lua-types": "^2.13.1" diff --git a/packages/isaac-typescript-definitions/scripts/build.ts b/packages/isaac-typescript-definitions/scripts/build.ts index ec1005cf1..b73cfe32d 100644 --- a/packages/isaac-typescript-definitions/scripts/build.ts +++ b/packages/isaac-typescript-definitions/scripts/build.ts @@ -1,13 +1,6 @@ -import { $, buildScript, buildTypeScript, rm } from "isaacscript-common-node"; -import { assertDefined } from "isaacscript-common-ts"; - -await buildScript(async ({ outDir, packageRoot }) => { - assertDefined( - outDir, - 'Failed to get the "outDir" from the "tsconfig.json" file.', - ); - rm(outDir); +import { $, buildScript, buildTypeScript } from "isaacscript-common-node"; +await buildScript(async ({ packageRoot }) => { const promises: Array> = []; promises.push( diff --git a/packages/isaac-typescript-definitions/tsconfig.json b/packages/isaac-typescript-definitions/tsconfig.json index 5b306d9da..286a3bdd6 100644 --- a/packages/isaac-typescript-definitions/tsconfig.json +++ b/packages/isaac-typescript-definitions/tsconfig.json @@ -1,8 +1,6 @@ { - "extends": [ - "../isaacscript-tsconfig/tsconfig.base.json", - "../../tsconfig.monorepo.json", - ], + // We cannot extend from the monorepo TSConfig since TSTL will complain about "paths". + "extends": "../isaacscript-tsconfig/tsconfig.base.json", // https://www.typescriptlang.org/docs/handbook/compiler-options.html "compilerOptions": { diff --git a/packages/isaacscript-cli/scripts/build.ts b/packages/isaacscript-cli/scripts/build.ts index cf39209d2..fc5d204f8 100644 --- a/packages/isaacscript-cli/scripts/build.ts +++ b/packages/isaacscript-cli/scripts/build.ts @@ -1,22 +1,9 @@ -import { - $, - $s, - buildScript, - buildTypeScript, - rm, -} from "isaacscript-common-node"; -import { assertDefined } from "isaacscript-common-ts"; +import { $, $s, buildScript, buildTypeScript } from "isaacscript-common-node"; const TSCONFIG_SCHEMA_PATH = "schemas/tsconfig-isaacscript-section-schema.json"; const ISAACSCRIPT_SCHEMA_PATH = "schemas/isaacscript-schema.json"; -await buildScript(async ({ outDir, packageRoot }) => { - assertDefined( - outDir, - 'Failed to get the "outDir" from the "tsconfig.json" file.', - ); - rm(outDir); - +await buildScript(async ({ packageRoot }) => { const promises: Array> = []; promises.push( diff --git a/packages/isaacscript-cli/src/commands/publish/validate.ts b/packages/isaacscript-cli/src/commands/publish/validate.ts index 031781272..bd4326ef9 100644 --- a/packages/isaacscript-cli/src/commands/publish/validate.ts +++ b/packages/isaacscript-cli/src/commands/publish/validate.ts @@ -3,8 +3,8 @@ import { PACKAGE_JSON, fatalError, isFile, - isGitClean, isGitRepository, + isGitRepositoryClean, isLoggedInToNPM, } from "isaacscript-common-node"; import { PROJECT_NAME } from "../../constants.js"; @@ -21,7 +21,7 @@ export function validate( ); } - if (!isGitClean()) { + if (!isGitRepositoryClean()) { fatalError( "Failed to publish since the Git repository was dirty. Before publishing, you must push any current changes to git. (Version commits should not contain any code changes.)", ); diff --git a/packages/isaacscript-common-node/package.json b/packages/isaacscript-common-node/package.json index ed2a9bbed..289355569 100644 --- a/packages/isaacscript-common-node/package.json +++ b/packages/isaacscript-common-node/package.json @@ -16,6 +16,17 @@ "type": "module", "main": "./dist/index.js", "types": "./dist/index.d.ts", + "files": [ + "dist", + "src", + "LICENSE", + "package.json", + "README.md" + ], + "scripts": { + "build": "tsx ./scripts/build.ts", + "lint": "tsx ./scripts/lint.ts" + }, "dependencies": { "@arktype/fs": "^0.0.1", "chalk": "^5.3.0", diff --git a/packages/isaacscript-common-node/scripts/build.sh b/packages/isaacscript-common-node/scripts/build.sh deleted file mode 100644 index a7baf6045..000000000 --- a/packages/isaacscript-common-node/scripts/build.sh +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/bash - -set -euo pipefail # Exit on errors and undefined variables. - -# Get the directory of this script: -# https://stackoverflow.com/questions/59895/getting-the-source-directory-of-a-bash-script-from-within -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" - -# Get the name of the package: -# https://stackoverflow.com/questions/23162299/how-to-get-the-last-part-of-dirname-in-bash/23162553 -PACKAGE_NAME="$(basename "$DIR")" - -echo "Building: $PACKAGE_NAME" - -SECONDS=0 - -cd "$DIR" - -REPO_ROOT="$DIR/../.." -OUT_DIR="$REPO_ROOT/dist/packages/$PACKAGE_NAME" - -rm -rf "$OUT_DIR" - -# Compile the project. -npx tsc -mv "$OUT_DIR/src" "$OUT_DIR/dist" - -# The source maps and declaration maps will be bugged due to the consolidated "dist" directory, so -# we use a script to manually rewrite them. -npx tsx "$REPO_ROOT/scripts/rewriteSourceMapDeclarationMapPaths.ts" "isaacscript-common-ts" - -# Copy the rest of the files needed for npm. -cp "$DIR/LICENSE" "$OUT_DIR/" -cp "$DIR/package.json" "$OUT_DIR/" -cp "$DIR/README.md" "$OUT_DIR/" -cp "$DIR/src" "$OUT_DIR/" --recursive - -echo "Successfully built $PACKAGE_NAME in $SECONDS seconds." diff --git a/packages/isaacscript-common-node/scripts/build.ts b/packages/isaacscript-common-node/scripts/build.ts new file mode 100644 index 000000000..e2b88c09e --- /dev/null +++ b/packages/isaacscript-common-node/scripts/build.ts @@ -0,0 +1,5 @@ +import { buildScript, buildTypeScript } from "isaacscript-common-node"; + +await buildScript(async ({ packageRoot }) => { + await buildTypeScript(packageRoot); +}); diff --git a/packages/isaacscript-common-node/scripts/lint.sh b/packages/isaacscript-common-node/scripts/lint.sh deleted file mode 100644 index 9a8c59648..000000000 --- a/packages/isaacscript-common-node/scripts/lint.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/bash - -set -euo pipefail # Exit on errors and undefined variables. - -# Get the directory of this script: -# https://stackoverflow.com/questions/59895/getting-the-source-directory-of-a-bash-script-from-within -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" - -# Get the name of the package: -# https://stackoverflow.com/questions/23162299/how-to-get-the-last-part-of-dirname-in-bash/23162553 -PACKAGE_NAME="$(basename "$DIR")" - -SECONDS=0 - -cd "$DIR" - -# Use Prettier to check formatting. -# "--log-level=warn" makes it only output errors. -npx prettier --log-level=warn --ignore-path="$DIR/../../.prettierignore" --check . - -# Use ESLint to lint the TypeScript. -# "--max-warnings 0" makes warnings fail in CI, since we set all ESLint errors to warnings. -npx eslint --max-warnings 0 . - -# Check for unused files, dependencies, and exports. -npx knip - -# Spell check every file using CSpell. -# "--no-progress" and "--no-summary" make it only output errors. -npx cspell --no-progress --no-summary . - -echo "Successfully linted $PACKAGE_NAME in $SECONDS seconds." diff --git a/packages/isaacscript-common-node/scripts/lint.ts b/packages/isaacscript-common-node/scripts/lint.ts new file mode 100644 index 000000000..b29e81b73 --- /dev/null +++ b/packages/isaacscript-common-node/scripts/lint.ts @@ -0,0 +1,9 @@ +import { $, lintScript } from "isaacscript-common-node"; + +await lintScript(async () => { + const promises: Array> = []; + + promises.push($`tsc --noEmit`, $`eslint --max-warnings 0 .`); + + await Promise.all(promises); +}); diff --git a/packages/isaacscript-common-node/src/functions/scriptHelpers.ts b/packages/isaacscript-common-node/src/functions/scriptHelpers.ts index dc4c70e00..40c3cbfe9 100644 --- a/packages/isaacscript-common-node/src/functions/scriptHelpers.ts +++ b/packages/isaacscript-common-node/src/functions/scriptHelpers.ts @@ -2,6 +2,7 @@ import path from "node:path"; import { dirOfCaller, findPackageRoot } from "./arkType.js"; +import { rm } from "./file.js"; import { getElapsedSeconds } from "./time.js"; import { getTSConfigJSONOutDir } from "./tsconfigJSON.js"; import { getArgs } from "./utils.js"; @@ -15,9 +16,28 @@ interface ScriptCallbackData { outDir?: string; } -/** See the documentation for the `script` helper function. */ +/** + * Removes the "outdir" directory specified in the "tsconfig.json" file (if it exists), then runs + * the provided logic. + * + * For more information, see the documentation for the `script` helper function. + */ export async function buildScript(func: ScriptCallback): Promise { - await script(func, "built", 2); + await script( + async (data) => { + const { outDir } = data; + if (outDir !== undefined) { + rm(outDir); + } + + // We do not want to execute the `buildTypeScript` helper function automatically because the + // end-user might want to do that in parallel with other tasks. + + await func(data); + }, + "built", + 2, + ); } /** See the documentation for the `script` helper function. */ diff --git a/packages/isaacscript-common-ts/package.json b/packages/isaacscript-common-ts/package.json index fb0bcfc59..ad4bdf78e 100644 --- a/packages/isaacscript-common-ts/package.json +++ b/packages/isaacscript-common-ts/package.json @@ -15,5 +15,17 @@ "author": "Zamiell", "type": "module", "main": "./dist/index.js", - "types": "./dist/index.d.ts" + "types": "./dist/index.d.ts", + "files": [ + "dist", + "src", + "LICENSE", + "package.json", + "README.md" + ], + "scripts": { + "build": "tsx ./scripts/build.ts", + "lint": "tsx ./scripts/lint.ts", + "test": "jest" + } } diff --git a/packages/isaacscript-common-ts/scripts/build.sh b/packages/isaacscript-common-ts/scripts/build.sh deleted file mode 100644 index a7baf6045..000000000 --- a/packages/isaacscript-common-ts/scripts/build.sh +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/bash - -set -euo pipefail # Exit on errors and undefined variables. - -# Get the directory of this script: -# https://stackoverflow.com/questions/59895/getting-the-source-directory-of-a-bash-script-from-within -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" - -# Get the name of the package: -# https://stackoverflow.com/questions/23162299/how-to-get-the-last-part-of-dirname-in-bash/23162553 -PACKAGE_NAME="$(basename "$DIR")" - -echo "Building: $PACKAGE_NAME" - -SECONDS=0 - -cd "$DIR" - -REPO_ROOT="$DIR/../.." -OUT_DIR="$REPO_ROOT/dist/packages/$PACKAGE_NAME" - -rm -rf "$OUT_DIR" - -# Compile the project. -npx tsc -mv "$OUT_DIR/src" "$OUT_DIR/dist" - -# The source maps and declaration maps will be bugged due to the consolidated "dist" directory, so -# we use a script to manually rewrite them. -npx tsx "$REPO_ROOT/scripts/rewriteSourceMapDeclarationMapPaths.ts" "isaacscript-common-ts" - -# Copy the rest of the files needed for npm. -cp "$DIR/LICENSE" "$OUT_DIR/" -cp "$DIR/package.json" "$OUT_DIR/" -cp "$DIR/README.md" "$OUT_DIR/" -cp "$DIR/src" "$OUT_DIR/" --recursive - -echo "Successfully built $PACKAGE_NAME in $SECONDS seconds." diff --git a/packages/isaacscript-common-ts/scripts/build.ts b/packages/isaacscript-common-ts/scripts/build.ts new file mode 100644 index 000000000..e2b88c09e --- /dev/null +++ b/packages/isaacscript-common-ts/scripts/build.ts @@ -0,0 +1,5 @@ +import { buildScript, buildTypeScript } from "isaacscript-common-node"; + +await buildScript(async ({ packageRoot }) => { + await buildTypeScript(packageRoot); +}); diff --git a/packages/isaacscript-common-ts/scripts/lint.sh b/packages/isaacscript-common-ts/scripts/lint.sh deleted file mode 100644 index 9a8c59648..000000000 --- a/packages/isaacscript-common-ts/scripts/lint.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/bash - -set -euo pipefail # Exit on errors and undefined variables. - -# Get the directory of this script: -# https://stackoverflow.com/questions/59895/getting-the-source-directory-of-a-bash-script-from-within -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" - -# Get the name of the package: -# https://stackoverflow.com/questions/23162299/how-to-get-the-last-part-of-dirname-in-bash/23162553 -PACKAGE_NAME="$(basename "$DIR")" - -SECONDS=0 - -cd "$DIR" - -# Use Prettier to check formatting. -# "--log-level=warn" makes it only output errors. -npx prettier --log-level=warn --ignore-path="$DIR/../../.prettierignore" --check . - -# Use ESLint to lint the TypeScript. -# "--max-warnings 0" makes warnings fail in CI, since we set all ESLint errors to warnings. -npx eslint --max-warnings 0 . - -# Check for unused files, dependencies, and exports. -npx knip - -# Spell check every file using CSpell. -# "--no-progress" and "--no-summary" make it only output errors. -npx cspell --no-progress --no-summary . - -echo "Successfully linted $PACKAGE_NAME in $SECONDS seconds." diff --git a/packages/isaacscript-common-ts/scripts/lint.ts b/packages/isaacscript-common-ts/scripts/lint.ts new file mode 100644 index 000000000..b29e81b73 --- /dev/null +++ b/packages/isaacscript-common-ts/scripts/lint.ts @@ -0,0 +1,9 @@ +import { $, lintScript } from "isaacscript-common-node"; + +await lintScript(async () => { + const promises: Array> = []; + + promises.push($`tsc --noEmit`, $`eslint --max-warnings 0 .`); + + await Promise.all(promises); +}); diff --git a/packages/isaacscript-common-ts/scripts/test.sh b/packages/isaacscript-common-ts/scripts/test.sh deleted file mode 100644 index d8211215d..000000000 --- a/packages/isaacscript-common-ts/scripts/test.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash - -set -euo pipefail # Exit on errors and undefined variables. - -# Get the directory of this script: -# https://stackoverflow.com/questions/59895/getting-the-source-directory-of-a-bash-script-from-within -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" - -cd "$DIR" - -npx jest diff --git a/packages/isaacscript-common-ts/scripts/tsconfig.json b/packages/isaacscript-common-ts/scripts/tsconfig.json new file mode 100644 index 000000000..06ff8b0a0 --- /dev/null +++ b/packages/isaacscript-common-ts/scripts/tsconfig.json @@ -0,0 +1,26 @@ +// This is a tsconfig.json intended to be used by scripts in the IsaacScript monorepo. +{ + "extends": [ + "../../isaacscript-tsconfig/tsconfig.node.json", + "../../../tsconfig.monorepo.json", + ], + + "include": [ + "./**/*.js", + "./**/.*.js", + "./**/*.cjs", + "./**/.*.cjs", + "./**/*.mjs", + "./**/.*.mjs", + "./**/*.jsx", + "./**/.*.jsx", + "./**/*.ts", + "./**/.*.ts", + "./**/*.cts", + "./**/.*.cts", + "./**/*.mts", + "./**/.*.mts", + "./**/*.tsx", + "./**/.*.tsx", + ], +} diff --git a/packages/isaacscript-common-ts/tsconfig.json b/packages/isaacscript-common-ts/tsconfig.json index 36dd3bd76..dc594a0db 100644 --- a/packages/isaacscript-common-ts/tsconfig.json +++ b/packages/isaacscript-common-ts/tsconfig.json @@ -35,5 +35,5 @@ "./**/.*.tsx", ], - "exclude": ["dist"], + "exclude": ["dist", "scripts"], } diff --git a/packages/isaacscript-common/package.json b/packages/isaacscript-common/package.json index 12d00f285..b104e738b 100644 --- a/packages/isaacscript-common/package.json +++ b/packages/isaacscript-common/package.json @@ -21,13 +21,20 @@ }, "license": "GPL-3.0", "author": "Zamiell", - "type": "commonjs", + "type": "module", "main": "./dist/src/index", "types": "./dist/index.rollup.d.ts", + "files": [ + "dist", + "src", + "LICENSE", + "package.json", + "README.md" + ], "scripts": { - "build": "tsx scripts/build.ts", + "build": "tsx ./scripts/build.ts", "docs": "typedoc", - "lint": "tsx scripts/lint.ts" + "lint": "tsx ./scripts/lint.ts" }, "dependencies": { "isaac-typescript-definitions": "^37.0.1" diff --git a/packages/isaacscript-common/scripts/build.sh b/packages/isaacscript-common/scripts/build.sh deleted file mode 100644 index 5d6ca18fe..000000000 --- a/packages/isaacscript-common/scripts/build.sh +++ /dev/null @@ -1,68 +0,0 @@ -#!/bin/bash - -set -euo pipefail # Exit on errors and undefined variables. - -# Get the directory of this script: -# https://stackoverflow.com/questions/59895/getting-the-source-directory-of-a-bash-script-from-within -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" - -# Get the name of the package: -# https://stackoverflow.com/questions/23162299/how-to-get-the-last-part-of-dirname-in-bash/23162553 -PACKAGE_NAME="$(basename "$DIR")" - -echo "Building: $PACKAGE_NAME" - -SECONDS=0 - -cd "$DIR" - -REPO_ROOT="$DIR/../.." -OUT_DIR="$REPO_ROOT/dist/packages/$PACKAGE_NAME" - -rm -rf "$OUT_DIR" - -# Compile the project using TSTL, which will generate ".lua" files and ".d.ts" files. -npx tstl - -# The declaration maps will be bugged due to the consolidated "dist" directory, so we use a script -# to manually rewrite them. -npx tsx "$REPO_ROOT/scripts/rewriteSourceMapDeclarationMapPaths.ts" "isaacscript-common" - -# Scrub internal exports from the declaration file using the ".d.ts rollup" feature of API -# Extractor: https://api-extractor.com/ -# If we did not use API Extractor, we would instead have to manually append "@internal" JSDoc tags -# to every single private function in order for the TypeScript compiler to remove it from the -# generated ".d.ts" file. API Extractor automatically knows which functions are public or private by -# parsing the "index.ts" file, and generates a new ".d.ts" file with private exports removed. Note -# that end-users can still manually import internal functions with e.g. -# `import { RunInNFrames } from "isaacscript-common/dist/src/classes/features/other/RunInNFrames"; -# but by removing them from the ".d.ts" file, they will not appear as part of auto-complete, which -# is good enough for our case. However, a downside of this method is that the declaration maps will -# not work: -# https://github.com/microsoft/rushstack/issues/1886 -# https://github.com/timocov/dts-bundle-generator/issues/218 -npx api-extractor run - -# API Extractor will make a "dist/tsdoc-metadata.json" file, which we don't need. -rm -rf "$DIR/dist" - -# Copy the rest of the files needed for npm. -cp "$DIR/LICENSE" "$OUT_DIR/" -cp "$DIR/package.json" "$OUT_DIR/" -cp "$DIR/README.md" "$OUT_DIR/" -cp "$DIR/src" "$OUT_DIR/" --recursive - -# Bundle the entire library into one file specifically for Lua consumers. We also include -# `isaac-typescript-definitions` in the bundled exports so that Lua users do not have to consume two -# separate libraries. -if [[ "${1-}" == "fast" ]]; then - echo "Skipping the Lua build due to the \"fast\" option being present." -else - INDEX_LUA="$DIR/src/indexLua.ts" - cp "$DIR/src/index.ts" "$INDEX_LUA" - echo "export * from \"isaac-typescript-definitions\";" >> "$INDEX_LUA" - npx tstl --project "$DIR/tsconfig.bundle.json" - rm -f "$INDEX_LUA" -fi - -echo "Successfully built $PACKAGE_NAME in $SECONDS seconds." diff --git a/packages/isaacscript-common/scripts/build.ts b/packages/isaacscript-common/scripts/build.ts new file mode 100644 index 000000000..0fa69fdde --- /dev/null +++ b/packages/isaacscript-common/scripts/build.ts @@ -0,0 +1,63 @@ +import { + $, + $s, + appendFile, + buildScript, + buildTypeScript, + cp, + rm, +} from "isaacscript-common-node"; +import { assertDefined } from "isaacscript-common-ts"; +import path from "node:path"; + +await buildScript(async ({ packageRoot, outDir }) => { + assertDefined( + outDir, + 'Failed to get the "outDir" from the "tsconfig.json" file.', + ); + + // In addition to the normal compilation, we want to bundle the entire library into one file + // specifically for Lua consumers. We also include `isaac-typescript-definitions` in the bundled + // exports so that Lua users do not have to consume two separate libraries. + const indexTSPath = path.join(packageRoot, "src", "index.ts"); + const indexLuaTSPath = path.join(packageRoot, "src", "indexLua.ts"); + cp(indexTSPath, indexLuaTSPath); + appendFile(indexLuaTSPath, 'export * from "isaac-typescript-definitions";'); + + const promises: Array> = []; + + promises.push( + // We need to create JavaScript files in addition to Lua files because we want this package to + // be usable in Jest tests. + buildTypeScript(packageRoot), + $`tstl`, + $`tstl --project tsconfig.bundle.json`, + ); + + await Promise.all(promises); + + rm(indexLuaTSPath); + + // Scrub internal exports from the declaration file using the ".d.ts rollup" feature of API + // Extractor: https://api-extractor.com/ + // If we did not use API Extractor, we would instead have to manually append "@internal" JSDoc + // tags to every single private function in order for the TypeScript compiler to remove it from + // the generated ".d.ts" file. API Extractor automatically knows which functions are public or + // private by parsing the "index.ts" file, and generates a new ".d.ts" file with private exports + // removed. Note that end-users can still manually import internal functions with e.g. `import { + // RunInNFrames } from "isaacscript-common/dist/src/classes/features/other/RunInNFrames"; but by + // removing them from the ".d.ts" file, they will not appear as part of auto-complete, which is + // good enough for our case. However, a downside of this method is that the declaration maps will + // not work: + // https://github.com/microsoft/rushstack/issues/1886 + // https://github.com/timocov/dts-bundle-generator/issues/218 + $s`npx api-extractor run`; + + // API Extractor will make a "dist/tsdoc-metadata.json" file, which we don't need. + const metadataJSONPath = path.join( + packageRoot, + outDir, + "tsdoc-metadata.json", + ); + rm(metadataJSONPath); +}); diff --git a/packages/isaacscript-common/scripts/lint.sh b/packages/isaacscript-common/scripts/lint.sh deleted file mode 100644 index 9a8c59648..000000000 --- a/packages/isaacscript-common/scripts/lint.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/bash - -set -euo pipefail # Exit on errors and undefined variables. - -# Get the directory of this script: -# https://stackoverflow.com/questions/59895/getting-the-source-directory-of-a-bash-script-from-within -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" - -# Get the name of the package: -# https://stackoverflow.com/questions/23162299/how-to-get-the-last-part-of-dirname-in-bash/23162553 -PACKAGE_NAME="$(basename "$DIR")" - -SECONDS=0 - -cd "$DIR" - -# Use Prettier to check formatting. -# "--log-level=warn" makes it only output errors. -npx prettier --log-level=warn --ignore-path="$DIR/../../.prettierignore" --check . - -# Use ESLint to lint the TypeScript. -# "--max-warnings 0" makes warnings fail in CI, since we set all ESLint errors to warnings. -npx eslint --max-warnings 0 . - -# Check for unused files, dependencies, and exports. -npx knip - -# Spell check every file using CSpell. -# "--no-progress" and "--no-summary" make it only output errors. -npx cspell --no-progress --no-summary . - -echo "Successfully linted $PACKAGE_NAME in $SECONDS seconds." diff --git a/packages/isaacscript-common/scripts/lint.ts b/packages/isaacscript-common/scripts/lint.ts new file mode 100644 index 000000000..b29e81b73 --- /dev/null +++ b/packages/isaacscript-common/scripts/lint.ts @@ -0,0 +1,9 @@ +import { $, lintScript } from "isaacscript-common-node"; + +await lintScript(async () => { + const promises: Array> = []; + + promises.push($`tsc --noEmit`, $`eslint --max-warnings 0 .`); + + await Promise.all(promises); +}); diff --git a/packages/isaacscript-common/scripts/tsconfig.json b/packages/isaacscript-common/scripts/tsconfig.json new file mode 100644 index 000000000..06ff8b0a0 --- /dev/null +++ b/packages/isaacscript-common/scripts/tsconfig.json @@ -0,0 +1,26 @@ +// This is a tsconfig.json intended to be used by scripts in the IsaacScript monorepo. +{ + "extends": [ + "../../isaacscript-tsconfig/tsconfig.node.json", + "../../../tsconfig.monorepo.json", + ], + + "include": [ + "./**/*.js", + "./**/.*.js", + "./**/*.cjs", + "./**/.*.cjs", + "./**/*.mjs", + "./**/.*.mjs", + "./**/*.jsx", + "./**/.*.jsx", + "./**/*.ts", + "./**/.*.ts", + "./**/*.cts", + "./**/.*.cts", + "./**/*.mts", + "./**/.*.mts", + "./**/*.tsx", + "./**/.*.tsx", + ], +} diff --git a/packages/isaacscript-common/src/indexLua.ts b/packages/isaacscript-common/src/indexLua.ts new file mode 100644 index 000000000..e7951e810 --- /dev/null +++ b/packages/isaacscript-common/src/indexLua.ts @@ -0,0 +1,202 @@ +export * from "./classes/DefaultMap"; +export * from "./classes/ModFeature"; +export * from "./classes/ModUpgraded"; +export * from "./core/cachedClasses"; +export * from "./core/constants"; +export * from "./core/constantsFirstLast"; +export * from "./core/constantsVanilla"; +export * from "./core/upgradeMod"; +export * from "./enums/AmbushType"; +export * from "./enums/CornerType"; +export * from "./enums/HealthType"; +export * from "./enums/ISCFeature"; +export * from "./enums/LadderSubTypeCustom"; +export * from "./enums/ModCallbackCustom"; +export * from "./enums/MysteriousPaperEffect"; +export * from "./enums/PlayerStat"; +export * from "./enums/PocketItemType"; +export * from "./enums/RockAltType"; +export * from "./enums/SaveDataKey"; +export * from "./enums/SerializationType"; +export * from "./enums/SlotDestructionType"; +export * from "./functions/ambush"; +export * from "./functions/array"; +export * from "./functions/arrayLua"; +export * from "./functions/benchmark"; +export * from "./functions/bitSet128"; +export * from "./functions/bitwise"; +export * from "./functions/bombs"; +export * from "./functions/bosses"; +export * from "./functions/cards"; +export * from "./functions/challenges"; +export * from "./functions/characters"; +export * from "./functions/charge"; +export * from "./functions/chargeBar"; +export * from "./functions/collectibleTag"; +export * from "./functions/collectibles"; +export * from "./functions/color"; +export * from "./functions/console"; +export * from "./functions/curses"; +export * from "./functions/debugFunctions"; +export * from "./functions/decorators"; +export * from "./functions/deepCopy"; +export * from "./functions/deepCopyTests"; +export * from "./functions/dimensions"; +export * from "./functions/direction"; +export * from "./functions/doors"; +export * from "./functions/easing"; +export * from "./functions/effects"; +export * from "./functions/emptyRoom"; +export * from "./functions/entities"; +export * from "./functions/entitiesSpecific"; +export * from "./functions/entityTypes"; +export * from "./functions/enums"; +export * from "./functions/external"; +export * from "./functions/familiars"; +export * from "./functions/flag"; +export * from "./functions/frames"; +export * from "./functions/globals"; +export * from "./functions/gridEntities"; +export * from "./functions/gridEntitiesSpecific"; +export * from "./functions/gridIndex"; +export * from "./functions/hash"; +export * from "./functions/hex"; +export * from "./functions/input"; +export * from "./functions/isaacAPIClass"; +export * from "./functions/itemPool"; +export * from "./functions/jsonHelpers"; +export * from "./functions/jsonRoom"; +export * from "./functions/kColor"; +export * from "./functions/language"; +export * from "./functions/level"; +export * from "./functions/levelGrid"; +export * from "./functions/log"; +export * from "./functions/logEntities"; +export * from "./functions/logMisc"; +export * from "./functions/map"; +export * from "./functions/math"; +export * from "./functions/merge"; +export * from "./functions/mergeTests"; +export * from "./functions/minimap"; +export * from "./functions/modFeatures"; +export * from "./functions/newArray"; +export * from "./functions/nextStage"; +export * from "./functions/npcDataStructures"; +export * from "./functions/npcs"; +export * from "./functions/pickupVariants"; +export * from "./functions/pickups"; +export * from "./functions/pickupsSpecific"; +export * from "./functions/pills"; +export * from "./functions/playerCenter"; +export * from "./functions/playerCollectibles"; +export * from "./functions/playerDataStructures"; +export * from "./functions/playerHealth"; +export * from "./functions/playerIndex"; +export * from "./functions/playerTrinkets"; +export * from "./functions/players"; +export * from "./functions/pocketItems"; +export * from "./functions/positionVelocity"; +export * from "./functions/pressurePlate"; +export * from "./functions/projectiles"; +export * from "./functions/random"; +export * from "./functions/readOnly"; +export * from "./functions/render"; +export * from "./functions/revive"; +export * from "./functions/rng"; +export * from "./functions/rockAlt"; +export * from "./functions/roomData"; +export * from "./functions/roomGrid"; +export * from "./functions/roomShape"; +export * from "./functions/roomShapeWalls"; +export * from "./functions/roomTransition"; +export * from "./functions/rooms"; +export * from "./functions/run"; +export * from "./functions/seeds"; +export * from "./functions/serialization"; +export * from "./functions/set"; +export * from "./functions/slots"; +export * from "./functions/sort"; +export * from "./functions/sound"; +export * from "./functions/spawnCollectible"; +export * from "./functions/sprites"; +export * from "./functions/stage"; +export * from "./functions/stats"; +export * from "./functions/string"; +export * from "./functions/table"; +export * from "./functions/tears"; +export * from "./functions/transformations"; +export * from "./functions/trinketGive"; +export * from "./functions/trinkets"; +export * from "./functions/tstlClass"; +export * from "./functions/types"; +export * from "./functions/ui"; +export * from "./functions/utils"; +export * from "./functions/vector"; +export * from "./functions/versusScreen"; +export * from "./functions/weighted"; +export * from "./interfaces/ChargeBarSprites"; +export * from "./interfaces/Corner"; +export * from "./interfaces/CustomStageTSConfig"; +export * from "./interfaces/GridEntityCustomData"; +export * from "./interfaces/JSONRoomsFile"; +export * from "./interfaces/PlayerHealth"; +export * from "./interfaces/PlayerStats"; +export * from "./interfaces/PocketItemDescription"; +export * from "./interfaces/RoomDescription"; +export * from "./interfaces/SaveData"; +export * from "./interfaces/StageHistoryEntry"; +export * from "./interfaces/TSTLClassMetatable"; +export * from "./interfaces/TrinketSituation"; +export * from "./maps/cardNameToTypeMap"; +export * from "./maps/characterNameToTypeMap"; +export * from "./maps/collectibleNameToTypeMap"; +export * from "./maps/pillNameToEffectMap"; +export * from "./maps/roomNameToTypeMap"; +export * from "./maps/transformationNameToPlayerFormMap"; +export * from "./maps/trinketNameToTypeMap"; +export * from "./objects/colors"; +export * from "./objects/kColors"; +export * from "./types/AddSubtract"; +export * from "./types/AllButFirst"; +export * from "./types/AllButLast"; +export * from "./types/AnyClass"; +export * from "./types/AnyEntity"; +export * from "./types/AnyFunction"; +export * from "./types/AnyGridEntity"; +export * from "./types/CompositionTypeSatisfiesEnum"; +export * from "./types/ConversionHeartSubType"; +export * from "./types/Decrement"; +export * from "./types/ERange"; +export * from "./types/EntityID"; +export * from "./types/Expand"; +export * from "./types/FunctionTuple"; +export * from "./types/GridEntityID"; +export * from "./types/HasFunction"; +export * from "./types/IRange"; +export * from "./types/Immutable"; +export * from "./types/Increment"; +export * from "./types/LowercaseKeys"; +export * from "./types/NaturalNumbersLessThan"; +export * from "./types/NaturalNumbersLessThanOrEqualTo"; +export * from "./types/PickingUpItem"; +export * from "./types/PickupIndex"; +export * from "./types/PlayerIndex"; +export * from "./types/PossibleStatType"; +export * from "./types/PublicInterface"; +export * from "./types/ReadonlyMap"; +export * from "./types/ReadonlySet"; +export * from "./types/StartsWithLowercase"; +export * from "./types/StartsWithUppercase"; +export * from "./types/TSTLClass"; +export * from "./types/Tuple"; +export * from "./types/TupleKeys"; +export * from "./types/TupleToIntersection"; +export * from "./types/TupleToUnion"; +export * from "./types/TupleWithLengthBetween"; +export * from "./types/TupleWithMaxLength"; +export * from "./types/UnionToIntersection"; +export * from "./types/UppercaseKeys"; +export * from "./types/WeightedArray"; +export * from "./types/WidenLiteral"; +export * from "./types/Writable"; +export * from "isaac-typescript-definitions"; \ No newline at end of file diff --git a/packages/isaacscript-common/tsconfig.bundle.json b/packages/isaacscript-common/tsconfig.bundle.json index cac0ac0f4..c0f907b73 100644 --- a/packages/isaacscript-common/tsconfig.bundle.json +++ b/packages/isaacscript-common/tsconfig.bundle.json @@ -6,9 +6,6 @@ // We want the only output to be the bundled Lua file. "declaration": false, "declarationMap": false, - - // We want to slightly reduce the file size of the output. - "removeComments": true, }, // TypeScriptToLua settings @@ -22,12 +19,12 @@ // A plugin to add an explanatory comment at the top of the compiled "main.lua" file (for // `isaacscript-common` specifically). { - "name": "../../dist/packages/isaacscript-cli/src/plugins/addIsaacScriptCommentHeaderCommon.js", + "name": "../isaacscript-cli/dist/plugins/addIsaacScriptCommentHeaderCommon.js", }, // A plugin to make enums safe from global variables. { - "name": "../../dist/packages/isaacscript-cli/src/plugins/noExtendedEnums.js", + "name": "../isaacscript-cli/dist/plugins/noExtendedEnums.js", }, ], "noHeader": true, diff --git a/packages/isaacscript-common/tsconfig.json b/packages/isaacscript-common/tsconfig.json index 0afe655fb..6455e90f7 100644 --- a/packages/isaacscript-common/tsconfig.json +++ b/packages/isaacscript-common/tsconfig.json @@ -1,8 +1,6 @@ { - "extends": [ - "../isaacscript-tsconfig/tsconfig.base.json", - "../../tsconfig.monorepo.json", - ], + // We cannot extend from the monorepo TSConfig since TSTL will complain about "paths". + "extends": "../isaacscript-tsconfig/tsconfig.base.json", // https://www.typescriptlang.org/docs/handbook/compiler-options.html "compilerOptions": { @@ -51,7 +49,7 @@ "./**/.*.tsx", ], - "exclude": ["dist"], + "exclude": ["dist", "scripts"], // TypeScriptToLua settings "tstl": { @@ -60,7 +58,7 @@ "luaPlugins": [ // A plugin to make enums safe from global variables. { - "name": "../../dist/packages/isaacscript-cli/src/plugins/noExtendedEnums.js", + "name": "../isaacscript-cli/dist/plugins/noExtendedEnums.js", }, ], "noHeader": true, diff --git a/todo.txt b/todo.txt index 8fb4c0da8..c5f6242c4 100644 --- a/todo.txt +++ b/todo.txt @@ -23,7 +23,6 @@ isaacscript-common --> isaac-typescript-definitions - remove all knip.jsonc - look through prePublish.ts -- search for all "console.log" in scripts --> echo