Skip to content

Revert esm #235

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

Merged
merged 6 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions .changeset/brown-camels-think.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@codeshift/cli': patch
'@hypermod/cli': patch
---

Reverts ESM support.
16 changes: 2 additions & 14 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
transform: {
'\\.[jt]sx?$': [
'^.+\\.ts$': [
'ts-jest',
{
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' },
},
},
],
},
tsconfig: 'tsconfig.json',
},
],
},
Expand All @@ -26,7 +15,6 @@ module.exports = {
'jest-watch-typeahead/testname',
],
moduleNameMapper: {
'(.+)\\.js$': '$1',
'@hypermod/(.*)$': '<rootDir>/packages/$1/src',
'@codeshift/(.*)$': '<rootDir>/packages/$1/src',
},
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
"semver": "^7.3.5",
"tar": "^6.1.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: 3 additions & 1 deletion packages/cli-alias/bin/codeshift-cli.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
#!/usr/bin/env node
export * from '../dist/index.js';
const path = require('path');

require(path.join('..', 'dist', 'index.js'));
1 change: 0 additions & 1 deletion packages/cli-alias/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"name": "@codeshift/cli",
"version": "0.23.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/bin/hypermod-cli.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
#!/usr/bin/env node
export * from '../dist/index.js';
const path = require('path');

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

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';
import main from './main';
import list from './list';
import init from './init';
import validate from './validate';
import { InvalidUserInputError, InvalidConfigError } from './errors';

const packageJson = readFileSync(
path.join(
path.dirname(new URL(import.meta.url).pathname),
'..',
'package.json',
),
path.join(__dirname, '..', '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.js';
import { getHypermodPackageName } from './utils/package-names.js';
import { fetchPackages } from './utils/fetch-package';
import { getHypermodPackageName } from './utils/package-names';

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

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';
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';

const ExperimentalModuleLoader = () => {
const getInfo = (packageName: string) => {
Expand All @@ -37,7 +34,6 @@ 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 @@ -80,11 +76,7 @@ export default async function main(
}

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

// If a registry is provided in the CLI flags, use it for the pluginManagers configuration.
Expand Down Expand Up @@ -164,33 +156,21 @@ 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.js';
import { getHypermodPackageName } from './package-names';

export async function fetchPackages(
packageName: string,
Expand Down
14 changes: 7 additions & 7 deletions packages/fetcher/src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('fetcher', () => {
let mockMatchedPaths: string[] = [];

beforeEach(() => {
mockMatchedPaths = [path.join(mockBasePath, 'hypermod.config.ts')];
mockMatchedPaths = [path.join(mockBasePath, 'hypermod.config.js')];

(globby as unknown as jest.Mock).mockImplementation(() =>
Promise.resolve(mockMatchedPaths),
Expand All @@ -34,10 +34,10 @@ describe('fetcher', () => {

describe('fetchConfig', () => {
it('fetches config with default export', async () => {
const mockFilePath = `${__dirname}/path/to/hypermod.config.ts`;
const mockFilePath = `${__dirname}/path/to/hypermod.config.js`;

jest.mock(
`${__dirname}/path/to/hypermod.config.ts`,
`${__dirname}/path/to/hypermod.config.js`,
() => ({ __esModule: true, default: mockConfig }),
{ virtual: true },
);
Expand All @@ -50,7 +50,7 @@ describe('fetcher', () => {

it('fetches config with named export', async () => {
jest.mock(
path.join(mockBasePath, 'hypermod.config.ts'),
path.join(mockBasePath, 'hypermod.config.js'),
() => mockConfig,
{
virtual: true,
Expand All @@ -61,7 +61,7 @@ describe('fetcher', () => {

expect(configMeta!.config).toEqual(mockConfig);
expect(configMeta!.filePath).toEqual(
path.join(mockBasePath, 'hypermod.config.ts'),
path.join(mockBasePath, 'hypermod.config.js'),
);
});

Expand Down Expand Up @@ -102,7 +102,7 @@ describe('fetcher', () => {

describe('fetchPackage', () => {
it('correctly fetches package and returns a config', async () => {
const mockFilePath = 'path/to/config.hypermod.ts';
const mockFilePath = 'path/to/config.hypermod.js';
const mockPackageManager = {
install: jest.fn(),
getInfo: jest.fn().mockReturnValue({ location: mockFilePath }),
Expand Down Expand Up @@ -155,7 +155,7 @@ describe('fetcher', () => {

expect(configMeta!.config).toEqual(mockConfig);
expect(configMeta!.filePath).toEqual(
mockBasePath + '/hypermod.config.ts',
mockBasePath + '/hypermod.config.js',
);
});

Expand Down
8 changes: 3 additions & 5 deletions scripts/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,17 @@ async function main() {
const directories = communityCodemods.filter(dir => junk.not(dir));

for (const dir of directories) {
const configMeta = await fetchConfig(path.join(COMMUNITY_PATH, dir));
const { config } = await fetchConfig(path.join(COMMUNITY_PATH, dir));

if (!configMeta?.config) {
if (!config) {
throw new Error(`Unable to locate config for path: ${dir}`);
}

const pkgName = `@hypermod/mod-${dir.replace('@', '').replace('/', '__')}`;
const rawPkgName = dir.replace('__', '/');
data.push({
pkgName,
targets:
rawPkgName +
(configMeta.config.targets ? `, ${configMeta.config.targets}` : ''),
targets: rawPkgName + (config.targets ? `, ${config.targets}` : ''),
});
}

Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"compilerOptions": {
"strict": true,
"skipLibCheck": true,
"moduleResolution": "node",
"target": "es6",
"module": "nodenext",
"moduleResolution": "nodenext",
"module": "CommonJS",
"resolveJsonModule": true,
"esModuleInterop": true,
"lib": [
Expand Down
Loading
Loading