Skip to content

Commit

Permalink
fix: pin all internal dependencies
Browse files Browse the repository at this point in the history
Related: #2040
  • Loading branch information
B4nan committed Aug 21, 2023
1 parent 3741578 commit bf3fbdf
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,9 @@ jobs:
GIT_USER: "noreply@apify.com:${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }}"
GH_TOKEN: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }}

- name: Update lockfile
- name: Pin versions in internal dependencies and update lockfile
run: |
yarn release:tilde
yarn install --no-immutable
git add .
git diff-index --quiet HEAD || git commit -m 'chore(release): update internal dependencies [skip ci]'
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"release:next": "yarn build && yarn publish:next",
"publish:prod": "lerna publish from-package --contents dist --force-publish",
"release:prod": "yarn build && yarn publish:prod",
"release:pin-versions": "turbo run copy -- -- --pin-versions",
"lint": "eslint \"packages/**/*.ts\" \"test/**/*.ts\"",
"lint:fix": "eslint \"packages/**/*.ts\" \"test/**/*.ts\" --fix"
},
Expand Down
32 changes: 25 additions & 7 deletions scripts/copy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { copyFileSync, readFileSync, writeFileSync } from 'fs';
import { resolve } from 'path';
/* eslint-disable @typescript-eslint/no-var-requires,import/no-dynamic-require,global-require */
import { execSync } from 'node:child_process';
import { copyFileSync, readFileSync, writeFileSync } from 'node:fs';
import { resolve } from 'node:path';

const options = process.argv.slice(2).reduce((args, arg) => {
const [key, value] = arg.split('=');
Expand All @@ -25,17 +26,19 @@ function rewrite(path: string, replacer: (from: string) => string): void {

let rootVersion: string;

function getRootVersion(): string {
function getRootVersion(bump = true): string {
if (rootVersion) {
return rootVersion;
}

// eslint-disable-next-line @typescript-eslint/no-var-requires,import/no-dynamic-require,global-require
rootVersion = require(resolve(root, './lerna.json')).version.replace(/^(\d+\.\d+\.\d+)-?.*$/, '$1');

const parts = rootVersion.split('.');
parts[2] = `${+parts[2] + 1}`;
rootVersion = parts.join('.');
if (bump) {
const parts = rootVersion.split('.');
parts[2] = `${+parts[2] + 1}`;
rootVersion = parts.join('.');
}

return rootVersion;
}
Expand Down Expand Up @@ -79,7 +82,6 @@ const target = resolve(process.cwd(), 'dist');
const pkgPath = resolve(process.cwd(), 'package.json');

if (options.canary) {
// eslint-disable-next-line @typescript-eslint/no-var-requires,import/no-dynamic-require,global-require
const pkgJson = require(pkgPath);
const nextVersion = getNextVersion();
pkgJson.version = nextVersion;
Expand All @@ -97,6 +99,22 @@ if (options.canary) {
writeFileSync(pkgPath, `${JSON.stringify(pkgJson, null, 4)}\n`);
}

if (options['pin-versions']) {
const pkgJson = require(pkgPath);
const version = getRootVersion(false);

for (const dep of Object.keys(pkgJson.dependencies ?? {})) {
if (dep.startsWith('@crawlee/') || dep === 'crawlee') {
pkgJson.dependencies[dep] = version;
}
}

// eslint-disable-next-line no-console
console.info(`pin-versions: version ${version}`, pkgJson.dependencies);

writeFileSync(pkgPath, `${JSON.stringify(pkgJson, null, 4)}\n`);
}

copy('README.md', root, target);
copy('LICENSE.md', root, target);
copy('package.json', process.cwd(), target);
Expand Down

0 comments on commit bf3fbdf

Please sign in to comment.