Skip to content

Commit

Permalink
codegen: use current package version as default clone version (#208)
Browse files Browse the repository at this point in the history
When running `pnpm run clone` without an argument the latest oxlint
version will be cloned (currently `0.10.3`).
But the project main branch can be differently (currently on `0.10.1`) 

If someone want to contribute they will get new rules from `0.10.3`. 
This PR will prevents it and used the current package.json.
  • Loading branch information
Sysix authored Nov 2, 2024
1 parent b394800 commit ce8acec
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 66 deletions.
38 changes: 0 additions & 38 deletions scripts/oxlint-version.ts

This file was deleted.

12 changes: 1 addition & 11 deletions scripts/rules-generator.test.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
import { vi, test, suite, vitest, beforeEach, afterEach, expect } from 'vitest';
import { test, suite, expect } from 'vitest';
import { RulesGenerator, RulesGrouping } from './rules-generator.js';
import type { Rule } from './traverse-rules.js';

suite('RulesGenerator', () => {
beforeEach(() => {
vi.mock('./oxlint-version.ts', () => ({
getLatestVersionFromClonedRepo: vitest.fn().mockReturnValue('1.0.0'),
}));
});

afterEach(() => {
vi.resetAllMocks();
});

test('RulesGenerator generates rules correctly', async () => {
const successResultArray: Rule[] = [
{
Expand Down
35 changes: 18 additions & 17 deletions scripts/sparse-clone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,18 @@ import {
SPARSE_CLONE_DIRECTORY,
VERSION_PREFIX,
} from './constants.js';
import { getLatestVersionFromClonedRepo } from './oxlint-version.js';
import { version } from '../package.json';

const version = process.argv[2] ?? undefined;
/**
* Run this file in CLI like `pnpm run clone`
* It clones the oxc_linter git project into your local file.
*
* You can run it with a version argument like `pnpm run clone 0.10.0`.
* When no argument is provided, the current package.json version is used.
*
*/

const checkoutVersion = process.argv[2] ?? version;

// Function to initialize or reconfigure sparse-checkout
function configureSparseCheckout(cloneDirectory: string) {
Expand All @@ -28,32 +37,24 @@ function configureSparseCheckout(cloneDirectory: string) {
}
}

function checkoutVersionTag(
targetDirectory: string,
cloneDirectory: string,
version?: string
) {
const tag = version
? `${VERSION_PREFIX}${version}`
: getLatestVersionFromClonedRepo(targetDirectory);
function checkoutVersionTag(version: string) {
const tag = `${VERSION_PREFIX}${version}`;

// Checkout the specified directory
if (shell.exec(`git checkout ${tag}`, { silent: true }).code !== 0) {
shell.echo('Error: Git checkout failed');
shell.exit(1);
}

console.log(
`Successfully cloned ${cloneDirectory} into ${targetDirectory}/${cloneDirectory} at ${tag}`
);
console.log(`Successfully checkout git tag ${tag}`);
}

// Function to clone or update a repository
function cloneOrUpdateRepo(
repositoryUrl: string,
targetDirectory: string,
cloneDirectory: string,
version?: string
version: string
) {
// Check if the target directory exists and is a Git repository
if (
Expand All @@ -65,7 +66,7 @@ function cloneOrUpdateRepo(
shell.cd(targetDirectory);

configureSparseCheckout(cloneDirectory);
checkoutVersionTag(targetDirectory, cloneDirectory, version);
checkoutVersionTag(version);
} else {
console.log(`Cloning new repository into ${targetDirectory}...`);

Expand All @@ -82,13 +83,13 @@ function cloneOrUpdateRepo(
shell.cd(targetDirectory);

configureSparseCheckout(cloneDirectory);
checkoutVersionTag(targetDirectory, cloneDirectory, version);
checkoutVersionTag(version);
}
}

cloneOrUpdateRepo(
'https://github.com/oxc-project/oxc.git',
TARGET_DIRECTORY,
SPARSE_CLONE_DIRECTORY,
version
checkoutVersion
);

0 comments on commit ce8acec

Please sign in to comment.