Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 37 additions & 3 deletions .config/rollup.dist.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ import {
existsSync,
mkdirSync,
rmSync,
writeFileSync
writeFileSync,
readFileSync
} from 'node:fs'
import path from 'node:path'
import { spawnSync } from 'node:child_process'
import { randomUUID } from 'node:crypto'

import { globSync as tinyGlobSync } from 'tinyglobby'

Expand Down Expand Up @@ -122,6 +125,31 @@ function updateDepStatsSync(depStats) {
.saveSync()
}

function versionBanner(_chunk) {
let pkgJsonVersion = 'unknown';
try { pkgJsonVersion = JSON.parse(readFileSync('package.json', 'utf8'))?.version ?? 'unknown' } catch {}

let gitHash = ''
try {
const obj = spawnSync('git', ['rev-parse','--short', 'HEAD']);
if (obj.stdout) {
gitHash = obj.stdout.toString('utf8').trim()
}
} catch {}

// Make each build generate a unique version id, regardless
// Mostly for development: confirms the build refreshed. For prod
// builds the git hash should suffice to identify the build.
const rng = randomUUID().split('-')[0];

return `
var SOCKET_CLI_PKG_JSON_VERSION = "${pkgJsonVersion}"
var SOCKET_CLI_GIT_HASH = "${gitHash}"
var SOCKET_CLI_BUILD_RNG = "${rng}"
var SOCKET_CLI_VERSION = "${pkgJsonVersion}:${gitHash}:${rng}"
`.trim().split('\n').map(s => s.trim()).join('\n')
}

export default () => {
const moduleSyncConfig = baseConfig({
input: {
Expand All @@ -132,12 +160,15 @@ export default () => {
},
output: [
{
intro: versionBanner, // Note: "banner" would defeat "use strict"
dir: path.relative(rootPath, distModuleSyncPath),
entryFileNames: '[name].js',
exports: 'auto',
externalLiveBindings: false,
format: 'cjs',
freeze: false
freeze: false,
sourcemap: true,
sourcemapDebugIds: true,
}
],
external(id_) {
Expand Down Expand Up @@ -182,12 +213,15 @@ export default () => {
},
output: [
{
intro: versionBanner, // Note: "banner" would defeat "use strict"
dir: path.relative(rootPath, distRequirePath),
entryFileNames: '[name].js',
exports: 'auto',
externalLiveBindings: false,
format: 'cjs',
freeze: false
freeze: false,
sourcemap: true,
sourcemapDebugIds: true,
}
],
plugins: [
Expand Down
2 changes: 2 additions & 0 deletions .dep-stats.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"@cyclonedx/cdxgen": "^11.1.8",
"@npmcli/promise-spawn": "^8.0.2",
"@octokit/rest": "^21.1.1",
"@sentry/node": "9.1.0",
"@socketregistry/hyrious__bun.lockb": "^1.0.12",
"@socketregistry/indent-string": "^1.0.9",
"@socketregistry/is-interactive": "^1.0.1",
Expand Down Expand Up @@ -67,6 +68,7 @@
"external": {
"@apideck/better-ajv-errors": "^0.3.6",
"@npmcli/promise-spawn": "^8.0.2",
"@sentry/node": "9.1.0",
"blessed": "^0.1.81",
"blessed-contrib": "^4.11.0",
"browserslist": "4.24.4",
Expand Down
Loading