Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ examples/
**/*.config.js
**/*.config.base.js
.eslintrc.js
constants-generator.js
constants-generator.js
release-stamp-version.js
2 changes: 1 addition & 1 deletion devbox.lock
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@
},
"nodejs@22": {
"last_modified": "2026-03-27T11:17:38Z",
"plugin_version": "0.0.2",
"plugin_version": "0.0.4",
"resolved": "github:NixOS/nixpkgs/832efc09b4caf6b4569fbf9dc01bec3082a00611#nodejs_22",
"source": "devbox-search",
"version": "22.22.2",
Expand Down
13 changes: 6 additions & 7 deletions packages/core/constants-generator.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
const fs = require('fs');
const packageJson = require('./package.json');

// The release passes the computed version here because package.json on master is not bumped (see release-stamp-version.js).
const version = process.env.SEGMENT_LIBRARY_VERSION || packageJson.version;

const body = `
export const libraryInfo = {
name: '${packageJson.name}',
version: '${packageJson.version}',
version: '${version}',
}
`;

fs.writeFile('./src/info.ts', body, function (err) {
if (err) {
return console.log(err);
}
fs.writeFileSync('./src/info.ts', body);

console.log('Configuration file has generated');
});
console.log(`Configuration file has generated (version ${version})`);
33 changes: 33 additions & 0 deletions packages/core/release-stamp-version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const { execFileSync } = require('child_process');
const fs = require('fs');
const path = require('path');

const STAMPED_FILES = [
'src/info.ts',
'lib/commonjs/info.js',
'lib/module/info.js',
];

// Local semantic-release plugin: rebuilds core with the version semantic-release just computed, so the published lib/ reports it.
async function prepare(_pluginConfig, { cwd, nextRelease, logger }) {
const { version } = nextRelease;
logger.log(`Stamping ${version} into libraryInfo and rebuilding`);

execFileSync('yarn', ['build'], {
cwd,
stdio: 'inherit',
env: { ...process.env, SEGMENT_LIBRARY_VERSION: version },
});

const quoted = new RegExp(`['"]${version.replace(/[.+]/g, '\\$&')}['"]`);
for (const file of STAMPED_FILES) {
const contents = fs.readFileSync(path.join(cwd, file), 'utf8');
if (!quoted.test(contents)) {
throw new Error(
`${file} is not stamped with ${version}; refusing to publish`
);
}
}
}

module.exports = { prepare };
8 changes: 8 additions & 0 deletions packages/core/release.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
const { plugins } = require('../../release.config.js');

module.exports = {
extends: ['../../release.config.js'],
// Runs right after @semantic-release/npm's prepare (version bump) and before its publish.
plugins: plugins.flatMap((plugin) =>
[].concat(plugin)[0] === '@semantic-release/npm'
? [plugin, './release-stamp-version.js']
: [plugin]
),
};
Loading