Skip to content

Commit

Permalink
Merge pull request #232 from hypermod-io/esm-support
Browse files Browse the repository at this point in the history
ESM codemod package support via CLI
  • Loading branch information
danieldelcore authored Sep 17, 2024
2 parents 5248c0e + d3162ae commit a1885c2
Show file tree
Hide file tree
Showing 38 changed files with 176 additions and 79 deletions.
6 changes: 6 additions & 0 deletions .changeset/yellow-shrimps-arrive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@codeshift/cli': minor
'@hypermod/cli': minor
---

CLI packages now support hypermod packages using ESM syntax
2 changes: 1 addition & 1 deletion community/@atlaskit__avatar/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@types/node": "^16.11.0",
"jest": "^29.0.0",
"prettier": "^2.0.0",
"ts-jest": "^29.0.0",
"ts-jest": "^29.2.5",
"typescript": "^5.2.2"
},
"repository": "https://github.com/hypermod-io/hypermod-community/tree/main/community/@atlaskit__avatar"
Expand Down
2 changes: 1 addition & 1 deletion community/@atlaskit__breadcrumbs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@types/node": "^16.11.0",
"jest": "^29.0.0",
"prettier": "^2.0.0",
"ts-jest": "^29.0.0",
"ts-jest": "^29.2.5",
"typescript": "^5.2.2"
},
"repository": "https://github.com/hypermod-io/hypermod-community/tree/main/community/@atlaskit__breadcrumbs"
Expand Down
2 changes: 1 addition & 1 deletion community/@atlaskit__button/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@types/node": "^16.11.0",
"jest": "^29.0.0",
"prettier": "^2.0.0",
"ts-jest": "^29.0.0",
"ts-jest": "^29.2.5",
"typescript": "^5.2.2"
},
"repository": "https://github.com/hypermod-io/hypermod-community/tree/main/community/@atlaskit__button"
Expand Down
2 changes: 1 addition & 1 deletion community/@atlaskit__calendar/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@types/node": "^16.11.0",
"jest": "^29.0.0",
"prettier": "^2.0.0",
"ts-jest": "^29.0.0",
"ts-jest": "^29.2.5",
"typescript": "^5.2.2"
},
"repository": "https://github.com/hypermod-io/hypermod-community/tree/main/community/@atlaskit__calendar"
Expand Down
2 changes: 1 addition & 1 deletion community/@atlaskit__checkbox/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@types/node": "^16.11.0",
"jest": "^29.0.0",
"prettier": "^2.0.0",
"ts-jest": "^29.0.0",
"ts-jest": "^29.2.5",
"typescript": "^5.2.2"
},
"repository": "https://github.com/hypermod-io/hypermod-community/tree/main/community/@atlaskit__checkbox"
Expand Down
2 changes: 1 addition & 1 deletion community/@atlaskit__icon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@types/node": "^16.11.0",
"jest": "^29.0.0",
"prettier": "^2.0.0",
"ts-jest": "^29.0.0",
"ts-jest": "^29.2.5",
"typescript": "^5.2.2"
},
"repository": "https://github.com/hypermod-io/hypermod-community/tree/main/community/@atlaskit__icon"
Expand Down
2 changes: 1 addition & 1 deletion community/@atlaskit__menu/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@types/node": "^16.11.0",
"jest": "^29.0.0",
"prettier": "^2.0.0",
"ts-jest": "^29.0.0",
"ts-jest": "^29.2.5",
"typescript": "^5.2.2"
},
"repository": "https://github.com/hypermod-io/hypermod-community/tree/main/community/@atlaskit__menu"
Expand Down
2 changes: 1 addition & 1 deletion community/@atlaskit__popper/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@types/node": "^16.11.0",
"jest": "^29.0.0",
"prettier": "^2.0.0",
"ts-jest": "^29.0.0",
"ts-jest": "^29.2.5",
"typescript": "^5.2.2"
},
"repository": "https://github.com/hypermod-io/hypermod-community/tree/main/community/@atlaskit__popper"
Expand Down
2 changes: 1 addition & 1 deletion community/@atlaskit__popup/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@types/node": "^16.11.0",
"jest": "^29.0.0",
"prettier": "^2.0.0",
"ts-jest": "^29.0.0",
"ts-jest": "^29.2.5",
"typescript": "^5.2.2"
},
"repository": "https://github.com/hypermod-io/hypermod-community/tree/main/community/@atlaskit__popup"
Expand Down
2 changes: 1 addition & 1 deletion community/@atlaskit__progress-indicator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@types/node": "^16.11.0",
"jest": "^29.0.0",
"prettier": "^2.0.0",
"ts-jest": "^29.0.0",
"ts-jest": "^29.2.5",
"typescript": "^5.2.2"
},
"repository": "https://github.com/hypermod-io/hypermod-community/tree/main/community/@atlaskit__progress-indicator"
Expand Down
2 changes: 1 addition & 1 deletion community/@atlaskit__range/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@types/node": "^16.11.0",
"jest": "^29.0.0",
"prettier": "^2.0.0",
"ts-jest": "^29.0.0",
"ts-jest": "^29.2.5",
"typescript": "^5.2.2"
},
"repository": "https://github.com/hypermod-io/hypermod-community/tree/main/community/@atlaskit__range"
Expand Down
2 changes: 1 addition & 1 deletion community/@atlaskit__section-message/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@types/node": "^16.11.0",
"jest": "^29.0.0",
"prettier": "^2.0.0",
"ts-jest": "^29.0.0",
"ts-jest": "^29.2.5",
"typescript": "^5.2.2"
},
"repository": "https://github.com/hypermod-io/hypermod-community/tree/main/community/@atlaskit__section-message"
Expand Down
2 changes: 1 addition & 1 deletion community/@atlaskit__side-navigation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@types/node": "^16.11.0",
"jest": "^29.0.0",
"prettier": "^2.0.0",
"ts-jest": "^29.0.0",
"ts-jest": "^29.2.5",
"typescript": "^5.2.2"
},
"repository": "https://github.com/hypermod-io/hypermod-community/tree/main/community/@atlaskit__side-navigation"
Expand Down
2 changes: 1 addition & 1 deletion community/@atlaskit__spinner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@types/node": "^16.11.0",
"jest": "^29.0.0",
"prettier": "^2.0.0",
"ts-jest": "^29.0.0",
"ts-jest": "^29.2.5",
"typescript": "^5.2.2"
},
"repository": "https://github.com/hypermod-io/hypermod-community/tree/main/community/@atlaskit__spinner"
Expand Down
2 changes: 1 addition & 1 deletion community/@atlaskit__tag/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@types/node": "^16.11.0",
"jest": "^29.0.0",
"prettier": "^2.0.0",
"ts-jest": "^29.0.0",
"ts-jest": "^29.2.5",
"typescript": "^5.2.2"
},
"repository": "https://github.com/hypermod-io/hypermod-community/tree/main/community/@atlaskit__tag"
Expand Down
2 changes: 1 addition & 1 deletion community/@atlaskit__textarea/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@types/node": "^16.11.0",
"jest": "^29.0.0",
"prettier": "^2.0.0",
"ts-jest": "^29.0.0",
"ts-jest": "^29.2.5",
"typescript": "^5.2.2"
},
"repository": "https://github.com/hypermod-io/hypermod-community/tree/main/community/@atlaskit__textarea"
Expand Down
2 changes: 1 addition & 1 deletion community/@atlaskit__textfield/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@types/node": "^16.11.0",
"jest": "^29.0.0",
"prettier": "^2.0.0",
"ts-jest": "^29.0.0",
"ts-jest": "^29.2.5",
"typescript": "^5.2.2"
},
"repository": "https://github.com/hypermod-io/hypermod-community/tree/main/community/@atlaskit__textfield"
Expand Down
2 changes: 1 addition & 1 deletion community/@atlaskit__toggle/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@types/node": "^16.11.0",
"jest": "^29.0.0",
"prettier": "^2.0.0",
"ts-jest": "^29.0.0",
"ts-jest": "^29.2.5",
"typescript": "^5.2.2"
},
"repository": "https://github.com/hypermod-io/hypermod-community/tree/main/community/@atlaskit__toggle"
Expand Down
2 changes: 1 addition & 1 deletion community/@emotion__monorepo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@types/node": "^16.11.0",
"jest": "^29.0.0",
"prettier": "^2.0.0",
"ts-jest": "^29.0.0",
"ts-jest": "^29.2.5",
"typescript": "^5.2.2"
},
"repository": "https://github.com/hypermod-io/hypermod-community/tree/main/community/@emotion__monorepo"
Expand Down
2 changes: 1 addition & 1 deletion community/hypermod/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"jest": "^29.0.0",
"parcel": "^2.8.3",
"prettier": "^2.0.0",
"ts-jest": "^29.0.0",
"ts-jest": "^29.2.5",
"typescript": "^5.2.2"
},
"repository": "https://github.com/hypermod-io/hypermod-community/tree/main/community/hypermod"
Expand Down
2 changes: 1 addition & 1 deletion community/javascript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@types/node": "^16.11.0",
"jest": "^29.0.0",
"prettier": "^2.0.0",
"ts-jest": "^29.0.0",
"ts-jest": "^29.2.5",
"typescript": "^5.2.2"
},
"repository": "https://github.com/hypermod-io/hypermod-community/tree/main/community/javascript"
Expand Down
2 changes: 1 addition & 1 deletion community/memoize-one/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@types/node": "^16.11.0",
"jest": "^29.0.0",
"prettier": "^2.0.0",
"ts-jest": "^29.0.0",
"ts-jest": "^29.2.5",
"typescript": "^5.2.2"
},
"repository": "https://github.com/hypermod-io/hypermod-community/tree/main/community/memoize-one"
Expand Down
2 changes: 1 addition & 1 deletion community/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@types/node": "^16.11.0",
"jest": "^29.0.0",
"prettier": "^2.0.0",
"ts-jest": "^29.0.0",
"ts-jest": "^29.2.5",
"typescript": "^5.2.2"
},
"repository": "https://github.com/hypermod-io/hypermod-community/tree/main/community/react"
Expand Down
16 changes: 14 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
transform: {
'^.+\\.ts$': [
'\\.[jt]sx?$': [
'ts-jest',
{
tsconfig: 'tsconfig.json',
diagnostics: { ignoreCodes: [1343] },
astTransformers: {
before: [
{
path: 'node_modules/ts-jest-mock-import-meta', // or, alternatively, 'ts-jest-mock-import-meta' directly, without node_modules.
options: {
metaObjectReplacement: { url: 'https://www.url.com' },
},
},
],
},
},
],
},
Expand All @@ -15,6 +26,7 @@ module.exports = {
'jest-watch-typeahead/testname',
],
moduleNameMapper: {
'(.+)\\.js$': '$1',
'@hypermod/(.*)$': '<rootDir>/packages/$1/src',
'@codeshift/(.*)$': '<rootDir>/packages/$1/src',
},
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@
"rimraf": "^2.6.3",
"semver": "^7.3.5",
"tar": "^6.1.0",
"ts-jest": "^29.0.0",
"ts-jest": "^29.2.5",
"ts-jest-mock-import-meta": "^1.2.0",
"ts-loader": "^6.2.1",
"ts-node": "^10.9.1",
"tslib": "^2.2.0",
Expand Down
4 changes: 1 addition & 3 deletions packages/cli-alias/bin/codeshift-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-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: 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
16 changes: 10 additions & 6 deletions packages/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ 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 packageJson = readFileSync(
path.join(__dirname, '..', 'package.json'),
path.join(
path.dirname(new URL(import.meta.url).pathname),
'..',
'package.json',
),
'utf-8',
);

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
32 changes: 26 additions & 6 deletions packages/cli/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ 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 ExperimentalModuleLoader = () => {
const getInfo = (packageName: string) => {
Expand All @@ -34,6 +37,7 @@ const ExperimentalModuleLoader = () => {
};

const install = async (packageName: string) => {
const __dirname = path.dirname(new URL(import.meta.url).pathname);
await installPackage(packageName, {
cwd: __dirname,
packageManager: 'npm',
Expand Down Expand Up @@ -76,7 +80,11 @@ export default async function main(
}

const pluginManagerConfig: Partial<PluginManagerOptions> = {
pluginsPath: path.join(__dirname, '..', 'node_modules'),
pluginsPath: path.join(
path.dirname(new URL(import.meta.url).pathname),
'..',
'node_modules',
),
};

// If a registry is provided in the CLI flags, use it for the pluginManagers configuration.
Expand Down Expand Up @@ -156,21 +164,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
Loading

0 comments on commit a1885c2

Please sign in to comment.