Skip to content

Commit 7346596

Browse files
committed
resolve script path relative to caller so that it can be imported in the unified runner
1 parent d677a5d commit 7346596

3 files changed

Lines changed: 22 additions & 5 deletions

File tree

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { Codemod } from '../codemods/types.js';
2+
import { resolveScriptPath } from '../utils/utils.codemod.js';
23

34
export default [
45
{
56
name: 'example-addition',
67
description: 'Example addition demonstrating Valibot schema with type inference',
7-
scriptPath: './scripts/example-addition.ts',
8+
scriptPath: resolveScriptPath(import.meta.url, './scripts/example-addition.js'),
89
},
910
] satisfies Codemod[];

packages/create-plugin/src/migrations/migrations.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { LEGACY_UPDATE_CUTOFF_VERSION } from '../constants.js';
22
import { Codemod } from '../codemods/types.js';
3+
import { resolveScriptPath } from '../utils/utils.codemod.js';
34

45
export interface Migration extends Codemod {
56
version: string;
@@ -10,26 +11,26 @@ export default [
1011
name: '001-update-grafana-compose-extend',
1112
version: LEGACY_UPDATE_CUTOFF_VERSION,
1213
description: 'Update ./docker-compose.yaml to extend from ./.config/docker-compose-base.yaml.',
13-
scriptPath: './scripts/001-update-grafana-compose-extend.js',
14+
scriptPath: resolveScriptPath(import.meta.url, './scripts/001-update-grafana-compose-extend.js'),
1415
},
1516
{
1617
name: '002-update-is-compatible-workflow',
1718
version: LEGACY_UPDATE_CUTOFF_VERSION,
1819
description:
1920
'Update ./.github/workflows/is-compatible.yml to use is-compatible github action instead of calling levitate directly',
20-
scriptPath: './scripts/002-update-is-compatible-workflow.js',
21+
scriptPath: resolveScriptPath(import.meta.url, './scripts/002-update-is-compatible-workflow.js'),
2122
},
2223
{
2324
name: '003-update-eslint-deprecation-rule',
2425
version: LEGACY_UPDATE_CUTOFF_VERSION,
2526
description: 'Replace deprecated eslint-plugin-deprecation with @typescript-eslint/no-deprecated rule.',
26-
scriptPath: './scripts/003-update-eslint-deprecation-rule.js',
27+
scriptPath: resolveScriptPath(import.meta.url, './scripts/003-update-eslint-deprecation-rule.js'),
2728
},
2829
{
2930
name: '004-eslint9-flat-config',
3031
version: LEGACY_UPDATE_CUTOFF_VERSION,
3132
description: 'Migrate eslint config to flat config format and update devDependencies to latest versions.',
32-
scriptPath: './scripts/004-eslint9-flat-config.js',
33+
scriptPath: resolveScriptPath(import.meta.url, './scripts/004-eslint9-flat-config.js'),
3334
},
3435
// Do not use LEGACY_UPDATE_CUTOFF_VERSION for new migrations. It is only used above to force migrations to run
3536
// for those written before the switch to updates as migrations.

packages/create-plugin/src/utils/utils.codemod.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import minimist from 'minimist';
2+
import { fileURLToPath } from 'node:url';
3+
import { dirname, resolve } from 'node:path';
24
import { isGitDirectory, isGitDirectoryClean } from './utils.git.js';
35
import { isPluginDirectory } from './utils.plugin.js';
46
import { output } from './utils.console.js';
@@ -45,3 +47,16 @@ export async function performPreCodemodChecks(argv: minimist.ParsedArgs): Promis
4547
process.exit(1);
4648
}
4749
}
50+
51+
/**
52+
* Resolves a script path relative to the caller's file location.
53+
*
54+
* @param callerUrl - The import.meta.url from the calling file
55+
* @param relativePath - The relative path to resolve (e.g., './scripts/example.js')
56+
* @returns The absolute resolved path
57+
*/
58+
export function resolveScriptPath(callerUrl: string, relativePath: string): string {
59+
const __filename = fileURLToPath(callerUrl);
60+
const __dirname = dirname(__filename);
61+
return resolve(__dirname, relativePath);
62+
}

0 commit comments

Comments
 (0)