Skip to content

Commit

Permalink
Fixes compiler version in postinstall command
Browse files Browse the repository at this point in the history
  • Loading branch information
ManasJayanth committed Feb 6, 2025
1 parent 41b6cdb commit 18c3117
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 9 deletions.
55 changes: 48 additions & 7 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -95238,6 +95238,14 @@ const { isUint8Array, isArrayBuffer } = __nccwpck_require__(84978)
const { File: UndiciFile } = __nccwpck_require__(78511)
const { parseMIMEType, serializeAMimeType } = __nccwpck_require__(685)

let random
try {
const crypto = __nccwpck_require__(6005)
random = (max) => crypto.randomInt(0, max)
} catch {
random = (max) => Math.floor(Math.random(max))
}

let ReadableStream = globalThis.ReadableStream

/** @type {globalThis['File']} */
Expand Down Expand Up @@ -95323,7 +95331,7 @@ function extractBody (object, keepalive = false) {
// Set source to a copy of the bytes held by object.
source = new Uint8Array(object.buffer.slice(object.byteOffset, object.byteOffset + object.byteLength))
} else if (util.isFormDataLike(object)) {
const boundary = `----formdata-undici-0${`${Math.floor(Math.random() * 1e11)}`.padStart(11, '0')}`
const boundary = `----formdata-undici-0${`${random(1e11)}`.padStart(11, '0')}`
const prefix = `--${boundary}\r\nContent-Disposition: form-data`

/*! formdata-polyfill. MIT License. Jimmy Wärting <https://jimmy.warting.se/opensource> */
Expand Down Expand Up @@ -113058,6 +113066,14 @@ ZipStream.prototype.finalize = function() {
*/


/***/ }),

/***/ 41901:
/***/ ((module) => {

module.exports = eval("require")("./esy.lock/index.json");


/***/ }),

/***/ 22877:
Expand Down Expand Up @@ -113212,6 +113228,14 @@ module.exports = require("net");

/***/ }),

/***/ 6005:
/***/ ((module) => {

"use strict";
module.exports = require("node:crypto");

/***/ }),

/***/ 15673:
/***/ ((module) => {

Expand Down Expand Up @@ -137462,8 +137486,8 @@ const create = makeCommand(createFileSync, createFile, createSync, createAsync,
//# sourceMappingURL=create.js.map
;// CONCATENATED MODULE: external "node:assert"
const external_node_assert_namespaceObject = require("node:assert");
;// CONCATENATED MODULE: external "node:crypto"
const external_node_crypto_namespaceObject = require("node:crypto");
// EXTERNAL MODULE: external "node:crypto"
var external_node_crypto_ = __nccwpck_require__(6005);
;// CONCATENATED MODULE: ./node_modules/tar/dist/esm/get-write-flag.js
// Get the appropriate flag to use for creating files
// We use fmap on Windows platforms for files less than
Expand Down Expand Up @@ -138329,7 +138353,7 @@ const unlinkFile = (path, cb) => {
if (!unpack_isWindows) {
return external_node_fs_.unlink(path, cb);
}
const name = path + '.DELETE.' + (0,external_node_crypto_namespaceObject.randomBytes)(16).toString('hex');
const name = path + '.DELETE.' + (0,external_node_crypto_.randomBytes)(16).toString('hex');
external_node_fs_.rename(path, name, er => {
if (er) {
return cb(er);
Expand All @@ -138343,7 +138367,7 @@ const unlinkFileSync = (path) => {
if (!unpack_isWindows) {
return external_node_fs_.unlinkSync(path);
}
const name = path + '.DELETE.' + (0,external_node_crypto_namespaceObject.randomBytes)(16).toString('hex');
const name = path + '.DELETE.' + (0,external_node_crypto_.randomBytes)(16).toString('hex');
external_node_fs_.renameSync(path, name);
external_node_fs_.unlinkSync(name);
};
Expand Down Expand Up @@ -139820,6 +139844,23 @@ function bundleNPMArtifacts() {
return external_child_process_.execSync(cmd).toString().trim();
}
const version = exec("git describe --tags --always");
function getCompilerVersion(sandbox = "esy") {
console.log(`Looking up ${sandbox}.lock/index.json for compiler version`);
const ocamlPackages = Object.keys((__nccwpck_require__(41901).node)).filter(k => k.startsWith("ocaml@"));
if (ocamlPackages.length === 0) {
throw new Error("Couldn't figure ocaml compiler version from lock file because no ocaml-like packages were found");
}
const ocamlPackageID = ocamlPackages[0];
const ocamlPackageIDParts = ocamlPackageID.split("@");
if (ocamlPackageIDParts.length !== 3) {
throw new Error(`Couldn't figure ocaml compiler version from lock file because PackageId wasn't in expected format: ${ocamlPackageID}`);
}
return ocamlPackageIDParts[1];
}
const compilerVersion = getCompilerVersion();
console.log("Found compiler version", compilerVersion);
const staticCompilerVersion = getCompilerVersion("static.esy");
console.log("Found static compiler version", staticCompilerVersion);
const packageJson = JSON.stringify({
name: mainPackageJson.name,
version,
Expand All @@ -139828,8 +139869,8 @@ function bundleNPMArtifacts() {
repository: mainPackageJson.repository,
scripts: {
postinstall: rewritePrefix
? "node -e \"process.env['OCAML_VERSION'] = process.platform == 'linux' ? '4.12.0-musl.static.flambda': '4.12.0'; process.env['OCAML_PKG_NAME'] = 'ocaml'; process.env['ESY_RELEASE_REWRITE_PREFIX']=true; require('./postinstall.js')\""
: "node -e \"process.env['OCAML_VERSION'] = process.platform == 'linux' ? '4.12.0-musl.static.flambda': '4.12.0'; process.env['OCAML_PKG_NAME'] = 'ocaml'; require('./postinstall.js')\"",
? `node -e \"process.env['OCAML_VERSION'] = process.platform == 'linux' ? '${staticCompilerVersion}-musl.static.flambda': '${compilerVersion}'; process.env['OCAML_PKG_NAME'] = 'ocaml'; process.env['ESY_RELEASE_REWRITE_PREFIX']=true; require('./postinstall.js')\"`
: "require('./postinstall.js')\"",
},
bin: bins,
files: [
Expand Down
29 changes: 27 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,31 @@ async function bundleNPMArtifacts() {
return cp.execSync(cmd).toString().trim();
}
const version = exec("git describe --tags --always");


function getCompilerVersion(sandbox = "esy") {
console.log(`Looking up ${sandbox}.lock/index.json for compiler version`);
const ocamlPackages = Object.keys(require("./esy.lock/index.json").node).filter(k => k.startsWith("ocaml@"));

if (ocamlPackages.length === 0) {
throw new Error("Couldn't figure ocaml compiler version from lock file because no ocaml-like packages were found");
}

const ocamlPackageID = ocamlPackages[0];
const ocamlPackageIDParts = ocamlPackageID.split("@");

if (ocamlPackageIDParts.length !== 3) {
throw new Error(`Couldn't figure ocaml compiler version from lock file because PackageId wasn't in expected format: ${ocamlPackageID}`);
}

return ocamlPackageIDParts[1];
}

const compilerVersion = getCompilerVersion();
console.log("Found compiler version", compilerVersion);
const staticCompilerVersion = getCompilerVersion("static.esy");
console.log("Found static compiler version", staticCompilerVersion);

const packageJson = JSON.stringify(
{
name: mainPackageJson.name,
Expand All @@ -419,8 +444,8 @@ async function bundleNPMArtifacts() {
repository: mainPackageJson.repository,
scripts: {
postinstall: rewritePrefix
? "node -e \"process.env['OCAML_VERSION'] = process.platform == 'linux' ? '4.12.0-musl.static.flambda': '4.12.0'; process.env['OCAML_PKG_NAME'] = 'ocaml'; process.env['ESY_RELEASE_REWRITE_PREFIX']=true; require('./postinstall.js')\""
: "node -e \"process.env['OCAML_VERSION'] = process.platform == 'linux' ? '4.12.0-musl.static.flambda': '4.12.0'; process.env['OCAML_PKG_NAME'] = 'ocaml'; require('./postinstall.js')\"",
? `node -e \"process.env['OCAML_VERSION'] = process.platform == 'linux' ? '${staticCompilerVersion}-musl.static.flambda': '${compilerVersion}'; process.env['OCAML_PKG_NAME'] = 'ocaml'; process.env['ESY_RELEASE_REWRITE_PREFIX']=true; require('./postinstall.js')\"`
: "require('./postinstall.js')\"",
},
bin: bins,
files: [
Expand Down

0 comments on commit 18c3117

Please sign in to comment.