Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

skuba migrate node 22 #1735

Open
wants to merge 38 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
72c0a9f
Initial `skuba migrate` modifications
zbrydon Nov 13, 2024
c7be1a5
Use latest node 22 types
zbrydon Nov 13, 2024
ca66785
Replace fetch with npm show
zbrydon Nov 13, 2024
14dc05c
Mock execSync
zbrydon Nov 13, 2024
2176a05
Generalise and add back node20 migrate
zbrydon Nov 14, 2024
575eaea
Merge branch 'main' of github.com:seek-oss/skuba into node-22
zbrydon Nov 18, 2024
ec85772
Add checkServerlessVersion
zbrydon Nov 19, 2024
178c02f
WIP dependent file checks
zbrydon Nov 19, 2024
8d2a75b
This isn't suspicious at all
zbrydon Nov 19, 2024
99be3a9
Refactor
zbrydon Nov 20, 2024
b165e28
WIP
zbrydon Nov 26, 2024
c80bb24
Merge branch 'main' of github.com:seek-oss/skuba into node-22
zbrydon Jan 8, 2025
bf26aa1
Fix
zbrydon Jan 10, 2025
9c55f4d
Fix
zbrydon Jan 10, 2025
659fe97
Init changeset
zbrydon Jan 10, 2025
1eb0494
changeset scope
zbrydon Jan 10, 2025
3e8d957
Fixes
zbrydon Jan 14, 2025
4c5da8d
Merge branch 'main' of github.com:seek-oss/skuba into node-22
zbrydon Jan 15, 2025
c66aa14
Fixes
zbrydon Jan 15, 2025
88e54f7
Remove " from node types version
zbrydon Jan 15, 2025
6f543cf
Snapshots and mock
zbrydon Jan 15, 2025
805ec17
Merge branch 'main' of github.com:seek-oss/skuba into node-22
zbrydon Jan 15, 2025
0efdaf0
Sanitize queried node types version
zbrydon Jan 15, 2025
c771121
Well... I don't like this
zbrydon Jan 15, 2025
45f800a
.trim() & it.each
zbrydon Jan 15, 2025
a0e2a27
Support nested files
zbrydon Jan 15, 2025
4ebea5b
Missed one
zbrydon Jan 15, 2025
9928479
Fix lint
zbrydon Jan 15, 2025
c930683
Stop self upgrading...
zbrydon Jan 15, 2025
ae6e164
Update workflow node
zbrydon Jan 15, 2025
4b16e12
Conditionally update based on serverless version
zbrydon Jan 15, 2025
421b193
This would probably help
zbrydon Jan 15, 2025
a2305b8
Don't error on intended functionality
zbrydon Jan 15, 2025
ebc6bc3
Merge branch 'main' into node-22
zbrydon Jan 15, 2025
4aeabb1
Shamelessly yoink changeset
zbrydon Jan 15, 2025
3ae3e5e
Merge branch 'node-22' of github.com:seek-oss/skuba into node-22
zbrydon Jan 15, 2025
32a852e
Words
zbrydon Jan 15, 2025
ed14a1b
Not bumping the minimum node version
zbrydon Jan 16, 2025
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
4 changes: 4 additions & 0 deletions src/cli/migrate/nodeVersion/getNode22TypesVersion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { execSync } from 'child_process';

export const getNode22TypesVersion = () =>
execSync("npm show @types/node@^22 version --json | jq '.[-1]'").toString();
zbrydon marked this conversation as resolved.
Show resolved Hide resolved
34 changes: 26 additions & 8 deletions src/cli/migrate/nodeVersion/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import memfs, { vol } from 'memfs';

import { getLatestNode22Types, nodeVersionMigration } from '.';
import * as getNode22TypesVersionModule from './getNode22TypesVersion';

import { getNode22TypeVersion, nodeVersionMigration } from '.';

jest
.spyOn(getNode22TypesVersionModule, 'getNode22TypesVersion')
.mockReturnValue('22.9.0');

jest.mock('fs-extra', () => memfs);
jest.mock('fast-glob', () => ({
Expand All @@ -13,6 +19,8 @@ const volToJson = () => vol.toJSON(process.cwd(), undefined, true);

beforeEach(() => vol.reset());

afterEach(() => jest.clearAllMocks());

describe('nodeVersionMigration', () => {
const scenarios: Array<{
filesBefore: Record<string, string>;
Expand Down Expand Up @@ -193,19 +201,29 @@ describe('nodeVersionMigration', () => {
);
});

describe('getLatestNode22Types', () => {
describe('getNodeTypesVersion', () => {
it('finds the latest node22 types version', () => {
const { version, err } = getLatestNode22Types();
const { version, err } = getNode22TypeVersion();
expect(version).toBe('22.9.0');
expect(err).toBeUndefined();
});

it('defaults to 22.9.0 if the exec returns an invalid version', () => {
jest
.spyOn(getNode22TypesVersionModule, 'getNode22TypesVersion')
.mockReturnValue('This is not a version');
const { version, err } = getNode22TypeVersion();
expect(version).toBe('22.9.0');
expect(err).toBe('Failed to fetch latest version, using fallback version');
});

it('defaults to 22.9.0 if the exec fails', () => {
// Mock JSON.parse to throw an error
jest.spyOn(JSON, 'parse').mockImplementationOnce(() => {
throw new Error('Failed to fetch latest version');
});
const { version, err } = getLatestNode22Types();
jest
.spyOn(getNode22TypesVersionModule, 'getNode22TypesVersion')
.mockReturnValue(
new Error('Failed to fetch latest version') as unknown as string,
);
const { version, err } = getNode22TypeVersion();
expect(version).toBe('22.9.0');
expect(err).toBe('Failed to fetch latest version, using fallback version');
});
Expand Down
17 changes: 6 additions & 11 deletions src/cli/migrate/nodeVersion/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { execSync } from 'child_process';
import { inspect } from 'util';

import { glob } from 'fast-glob';
Expand All @@ -7,6 +6,8 @@ import fs from 'fs-extra';
import { log } from '../../../utils/logging';
import { createDestinationFileReader } from '../../configure/analysis/project';

import { getNode22TypesVersion } from './getNode22TypesVersion';

type SubPatch = (
| { files: string; file?: never }
| { file: string; files?: never }
Expand All @@ -20,17 +21,11 @@ type VersionResult = {
err: string | undefined;
};

export const getLatestNode22Types = (): VersionResult => {
export const getNode22TypeVersion = (): VersionResult => {
const FALLBACK_VERSION = '22.9.0';
try {
const version = (
JSON.parse(
execSync('npm show @types/node@^22 version --json', {
encoding: 'utf8',
}),
) as string[]
).pop();
if (!version) {
const version = getNode22TypesVersion();
if (!version || !/^22.\d+\.\d+$/.test(version)) {
throw new Error('No version found');
}
return {
Expand Down Expand Up @@ -177,7 +172,7 @@ export const nodeVersionMigration = async (
) => {
log.ok(`Upgrading to Node.js ${version}`);
try {
const { version: nodeTypesVersion, err } = getLatestNode22Types();
const { version: nodeTypesVersion, err } = getNode22TypeVersion();
if (err) {
log.warn(err);
}
Expand Down