Skip to content

Commit 5fe4ca8

Browse files
Merge pull request #235 from hypermod-io/revert-esm
Revert esm
2 parents ef96f53 + e69f221 commit 5fe4ca8

15 files changed

+53
-89
lines changed

.changeset/brown-camels-think.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@codeshift/cli': patch
3+
'@hypermod/cli': patch
4+
---
5+
6+
Reverts ESM support.

jest.config.js

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,9 @@
1-
/** @type {import('ts-jest').JestConfigWithTsJest} */
21
module.exports = {
32
transform: {
4-
'\\.[jt]sx?$': [
3+
'^.+\\.ts$': [
54
'ts-jest',
65
{
7-
diagnostics: { ignoreCodes: [1343] },
8-
astTransformers: {
9-
before: [
10-
{
11-
path: 'node_modules/ts-jest-mock-import-meta', // or, alternatively, 'ts-jest-mock-import-meta' directly, without node_modules.
12-
options: {
13-
metaObjectReplacement: { url: 'https://www.url.com' },
14-
},
15-
},
16-
],
17-
},
6+
tsconfig: 'tsconfig.json',
187
},
198
],
209
},
@@ -26,7 +15,6 @@ module.exports = {
2615
'jest-watch-typeahead/testname',
2716
],
2817
moduleNameMapper: {
29-
'(.+)\\.js$': '$1',
3018
'@hypermod/(.*)$': '<rootDir>/packages/$1/src',
3119
'@codeshift/(.*)$': '<rootDir>/packages/$1/src',
3220
},

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@
6969
"semver": "^7.3.5",
7070
"tar": "^6.1.0",
7171
"ts-jest": "^29.2.5",
72-
"ts-jest-mock-import-meta": "^1.2.0",
7372
"ts-loader": "^6.2.1",
7473
"ts-node": "^10.9.1",
7574
"tslib": "^2.2.0",
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
#!/usr/bin/env node
2-
export * from '../dist/index.js';
2+
const path = require('path');
3+
4+
require(path.join('..', 'dist', 'index.js'));

packages/cli-alias/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"name": "@codeshift/cli",
33
"version": "0.23.0",
4-
"type": "module",
54
"source": "src/index.ts",
65
"main": "dist/index.js",
76
"types": "dist/index.d.ts",

packages/cli/bin/hypermod-cli.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
#!/usr/bin/env node
2-
export * from '../dist/index.js';
2+
const path = require('path');
3+
4+
require(path.join('..', 'dist', 'index.js'));

packages/cli/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"name": "@hypermod/cli",
33
"version": "0.23.0",
4-
"type": "module",
54
"source": "src/index.ts",
65
"main": "dist/index.js",
76
"types": "dist/index.d.ts",

packages/cli/src/index.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,14 @@ import { readFileSync } from 'fs';
33
import chalk from 'chalk';
44
import { Command, Option, CommanderError } from 'commander';
55

6-
import main from './main.js';
7-
import list from './list.js';
8-
import init from './init.js';
9-
import validate from './validate.js';
10-
import { InvalidUserInputError, InvalidConfigError } from './errors.js';
6+
import main from './main';
7+
import list from './list';
8+
import init from './init';
9+
import validate from './validate';
10+
import { InvalidUserInputError, InvalidConfigError } from './errors';
1111

1212
const packageJson = readFileSync(
13-
path.join(
14-
path.dirname(new URL(import.meta.url).pathname),
15-
'..',
16-
'package.json',
17-
),
13+
path.join(__dirname, '..', 'package.json'),
1814
'utf-8',
1915
);
2016

packages/cli/src/list.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import chalk from 'chalk';
22
import { PluginManager } from 'live-plugin-manager';
33

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

77
export default async function list(packages: string[]) {
88
const packageManager = new PluginManager();

packages/cli/src/main.ts

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,11 @@ import { installPackage } from '@antfu/install-pkg';
1010
import * as core from '@hypermod/core';
1111
import { fetchConfigAtPath } from '@hypermod/fetcher';
1212

13-
import { InvalidUserInputError } from './errors.js';
14-
import { fetchPackages } from './utils/fetch-package.js';
15-
import { mergeConfigs } from './utils/merge-configs.js';
16-
import {
17-
fetchConfigsForWorkspaces,
18-
getPackageJson,
19-
} from './utils/file-system.js';
20-
import { getConfigPrompt, getMultiConfigPrompt } from './prompt.js';
13+
import { InvalidUserInputError } from './errors';
14+
import { fetchPackages } from './utils/fetch-package';
15+
import { mergeConfigs } from './utils/merge-configs';
16+
import { fetchConfigsForWorkspaces, getPackageJson } from './utils/file-system';
17+
import { getConfigPrompt, getMultiConfigPrompt } from './prompt';
2118

2219
const ExperimentalModuleLoader = () => {
2320
const getInfo = (packageName: string) => {
@@ -37,7 +34,6 @@ const ExperimentalModuleLoader = () => {
3734
};
3835

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

8278
const pluginManagerConfig: Partial<PluginManagerOptions> = {
83-
pluginsPath: path.join(
84-
path.dirname(new URL(import.meta.url).pathname),
85-
'..',
86-
'node_modules',
87-
),
79+
pluginsPath: path.join(__dirname, '..', 'node_modules'),
8880
};
8981

9082
// If a registry is provided in the CLI flags, use it for the pluginManagers configuration.
@@ -164,33 +156,21 @@ export default async function main(
164156
*/
165157
const configFilePath = await findUp([
166158
'hypermod.config.js',
167-
'hypermod.config.cjs',
168-
'hypermod.config.mjs',
169159
'hypermod.config.ts',
170160
'hypermod.config.tsx',
171161
'src/hypermod.config.js',
172-
'src/hypermod.config.cjs',
173-
'src/hypermod.config.mjs',
174162
'src/hypermod.config.ts',
175163
'src/hypermod.config.tsx',
176164
'codemods/hypermod.config.js',
177-
'codemods/hypermod.config.cjs',
178-
'codemods/hypermod.config.mjs',
179165
'codemods/hypermod.config.ts',
180166
'codemods/hypermod.config.tsx',
181167
'codeshift.config.js',
182-
'codeshift.config.cjs',
183-
'codeshift.config.mjs',
184168
'codeshift.config.ts',
185169
'codeshift.config.tsx',
186170
'src/codeshift.config.js',
187-
'src/codeshift.config.cjs',
188-
'src/codeshift.config.mjs',
189171
'src/codeshift.config.ts',
190172
'src/codeshift.config.tsx',
191173
'codemods/codeshift.config.js',
192-
'codemods/codeshift.config.cjs',
193-
'codemods/codeshift.config.mjs',
194174
'codemods/codeshift.config.ts',
195175
'codemods/codeshift.config.tsx',
196176
]);

packages/cli/src/utils/fetch-package.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
} from '@hypermod/fetcher';
1010
import { isValidConfig } from '@hypermod/validator';
1111

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

1414
export async function fetchPackages(
1515
packageName: string,

packages/fetcher/src/index.spec.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ describe('fetcher', () => {
1919
let mockMatchedPaths: string[] = [];
2020

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

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

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

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

5151
it('fetches config with named export', async () => {
5252
jest.mock(
53-
path.join(mockBasePath, 'hypermod.config.ts'),
53+
path.join(mockBasePath, 'hypermod.config.js'),
5454
() => mockConfig,
5555
{
5656
virtual: true,
@@ -61,7 +61,7 @@ describe('fetcher', () => {
6161

6262
expect(configMeta!.config).toEqual(mockConfig);
6363
expect(configMeta!.filePath).toEqual(
64-
path.join(mockBasePath, 'hypermod.config.ts'),
64+
path.join(mockBasePath, 'hypermod.config.js'),
6565
);
6666
});
6767

@@ -102,7 +102,7 @@ describe('fetcher', () => {
102102

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

156156
expect(configMeta!.config).toEqual(mockConfig);
157157
expect(configMeta!.filePath).toEqual(
158-
mockBasePath + '/hypermod.config.ts',
158+
mockBasePath + '/hypermod.config.js',
159159
);
160160
});
161161

scripts/sync.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,17 @@ async function main() {
2121
const directories = communityCodemods.filter(dir => junk.not(dir));
2222

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

26-
if (!configMeta?.config) {
26+
if (!config) {
2727
throw new Error(`Unable to locate config for path: ${dir}`);
2828
}
2929

3030
const pkgName = `@hypermod/mod-${dir.replace('@', '').replace('/', '__')}`;
3131
const rawPkgName = dir.replace('__', '/');
3232
data.push({
3333
pkgName,
34-
targets:
35-
rawPkgName +
36-
(configMeta.config.targets ? `, ${configMeta.config.targets}` : ''),
34+
targets: rawPkgName + (config.targets ? `, ${config.targets}` : ''),
3735
});
3836
}
3937

tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
"compilerOptions": {
33
"strict": true,
44
"skipLibCheck": true,
5+
"moduleResolution": "node",
56
"target": "es6",
6-
"module": "nodenext",
7-
"moduleResolution": "nodenext",
7+
"module": "CommonJS",
88
"resolveJsonModule": true,
99
"esModuleInterop": true,
1010
"lib": [

0 commit comments

Comments
 (0)