Skip to content

Commit

Permalink
initial esm cli migration
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Del Core committed Sep 2, 2024
1 parent 5248c0e commit 417bcfc
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 18 deletions.
1 change: 1 addition & 0 deletions packages/cli-alias/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "@codeshift/cli",
"version": "0.22.0",
"type": "module",
"source": "src/index.ts",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
4 changes: 3 additions & 1 deletion packages/cli-alias/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"compilerOptions": {
"rootDir": "src",
"outDir": "dist",
"baseUrl": "."
"baseUrl": ".",
"module": "NodeNext",
"moduleResolution": "NodeNext"
},
"include": ["src"],
"references": [
Expand Down
4 changes: 1 addition & 3 deletions packages/cli/bin/hypermod-cli.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
#!/usr/bin/env node
const path = require('path');

require(path.join('..', 'dist', 'index.js'));
export * from '../dist/index.js';
1 change: 1 addition & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "@hypermod/cli",
"version": "0.22.0",
"type": "module",
"source": "src/index.ts",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
12 changes: 7 additions & 5 deletions packages/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import { readFileSync } from 'fs';
import chalk from 'chalk';
import { Command, Option, CommanderError } from 'commander';

import main from './main';
import list from './list';
import init from './init';
import validate from './validate';
import { InvalidUserInputError, InvalidConfigError } from './errors';
import main from './main.js';
import list from './list.js';
import init from './init.js';
import validate from './validate.js';
import { InvalidUserInputError, InvalidConfigError } from './errors.js';

const __dirname = path.dirname(new URL(import.meta.url).pathname);

const packageJson = readFileSync(
path.join(__dirname, '..', 'package.json'),
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/list.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import chalk from 'chalk';
import { PluginManager } from 'live-plugin-manager';

import { fetchPackages } from './utils/fetch-package';
import { getHypermodPackageName } from './utils/package-names';
import { fetchPackages } from './utils/fetch-package.js';
import { getHypermodPackageName } from './utils/package-names.js';

export default async function list(packages: string[]) {
const packageManager = new PluginManager();
Expand Down
27 changes: 22 additions & 5 deletions packages/cli/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@ import { installPackage } from '@antfu/install-pkg';
import * as core from '@hypermod/core';
import { fetchConfigAtPath } from '@hypermod/fetcher';

import { InvalidUserInputError } from './errors';
import { fetchPackages } from './utils/fetch-package';
import { mergeConfigs } from './utils/merge-configs';
import { fetchConfigsForWorkspaces, getPackageJson } from './utils/file-system';
import { getConfigPrompt, getMultiConfigPrompt } from './prompt';
import { InvalidUserInputError } from './errors.js';
import { fetchPackages } from './utils/fetch-package.js';
import { mergeConfigs } from './utils/merge-configs.js';
import {
fetchConfigsForWorkspaces,
getPackageJson,
} from './utils/file-system.js';
import { getConfigPrompt, getMultiConfigPrompt } from './prompt.js';

const __dirname = path.dirname(new URL(import.meta.url).pathname);

const ExperimentalModuleLoader = () => {
const getInfo = (packageName: string) => {
Expand Down Expand Up @@ -156,21 +161,33 @@ export default async function main(
*/
const configFilePath = await findUp([
'hypermod.config.js',
'hypermod.config.cjs',
'hypermod.config.mjs',
'hypermod.config.ts',
'hypermod.config.tsx',
'src/hypermod.config.js',
'src/hypermod.config.cjs',
'src/hypermod.config.mjs',
'src/hypermod.config.ts',
'src/hypermod.config.tsx',
'codemods/hypermod.config.js',
'codemods/hypermod.config.cjs',
'codemods/hypermod.config.mjs',
'codemods/hypermod.config.ts',
'codemods/hypermod.config.tsx',
'codeshift.config.js',
'codeshift.config.cjs',
'codeshift.config.mjs',
'codeshift.config.ts',
'codeshift.config.tsx',
'src/codeshift.config.js',
'src/codeshift.config.cjs',
'src/codeshift.config.mjs',
'src/codeshift.config.ts',
'src/codeshift.config.tsx',
'codemods/codeshift.config.js',
'codemods/codeshift.config.cjs',
'codemods/codeshift.config.mjs',
'codemods/codeshift.config.ts',
'codemods/codeshift.config.tsx',
]);
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/utils/fetch-package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from '@hypermod/fetcher';
import { isValidConfig } from '@hypermod/validator';

import { getHypermodPackageName } from './package-names';
import { getHypermodPackageName } from './package-names.js';

export async function fetchPackages(
packageName: string,
Expand Down
4 changes: 3 additions & 1 deletion packages/cli/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"compilerOptions": {
"rootDir": "src",
"outDir": "dist",
"baseUrl": "."
"baseUrl": ".",
"module": "NodeNext",
"moduleResolution": "NodeNext"
},
"include": ["src"],
"references": [
Expand Down

0 comments on commit 417bcfc

Please sign in to comment.