Skip to content

Commit

Permalink
feat(scripts): Rewrite genVersions to CommonJS
Browse files Browse the repository at this point in the history
This is required to run it with `node` in `postinstall`.

Otherwise, we have either to install all the dependencies or add
`ts-node` as a dependency (not dev depenendency).
  • Loading branch information
jubnzv committed Nov 20, 2024
1 parent e1fe023 commit 33fe99d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"clean": "rm -fr dist docs/*",
"build": "tsc && cp -R src/detectors/templates dist/detectors/",
"postinstall": "yarn gen",
"gen": "ts-node scripts/genVersions.ts",
"gen": "node scripts/genVersions.cjs",
"test": "jest",
"benchmark": "ts-node benchmarks/detectors.ts",
"lint": "eslint src",
Expand Down
32 changes: 14 additions & 18 deletions scripts/genVersions.ts → scripts/genVersions.cjs
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
/**
* Generates Misti and Tact versions in `src/version-info.ts`.
*
* This is needed to avoid reading them from `package.json` at runtime to simplify
* building the distribution package.
* This is needed to avoid reading them from `package.json` at runtime to
* simplify building the distribution package.
*
* **Note:** If the `MISTI_RELEASE` environment variable is set to `'1'`, the Git
* revision will not be included in the version string.
*
* @packageDocumentation
* **Note:** If the `MISTI_RELEASE` environment variable is set to `'1'`, the
* Git revision will not be included in the version string.
*/

import * as fs from "fs";
import * as path from "path";
import { execSync } from "child_process";
const fs = require("fs");
const path = require("path");
const { execSync } = require("child_process");

const packageJsonPath = path.join(__dirname, "..", "package.json");
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
const packageVersion: string = packageJson.version;
const packageVersion = packageJson.version;

// Initialize MISTI_VERSION with packageVersion
let MISTI_VERSION: string = packageVersion;
let MISTI_VERSION = packageVersion;

if (process.env.MISTI_RELEASE !== '1') {
if (process.env.MISTI_RELEASE !== "1") {
// Retrieve the Git revision number
let gitRevision = "unknown";
try {
Expand All @@ -34,13 +32,11 @@ if (process.env.MISTI_RELEASE !== '1') {
MISTI_VERSION = `${packageVersion}-${gitRevision}`;
}

const TACT_COMPILER_VERSION: string =
packageJson.dependencies["@tact-lang/compiler"];
const TACT_COMPILER_VERSION = packageJson.dependencies["@tact-lang/compiler"];

const normalizeVersion = (version: string): string =>
version.startsWith("^") || version.startsWith("~")
? version.slice(1)
: version;
const normalizeVersion = (version) =>
version.startsWith("^") || version.startsWith("~") ? version.slice(1)
: version;

const content = `
export const MISTI_VERSION = '${MISTI_VERSION}';
Expand Down

0 comments on commit 33fe99d

Please sign in to comment.