diff --git a/.changeset/brown-camels-think.md b/.changeset/brown-camels-think.md new file mode 100644 index 000000000..5569a07f5 --- /dev/null +++ b/.changeset/brown-camels-think.md @@ -0,0 +1,6 @@ +--- +'@codeshift/cli': patch +'@hypermod/cli': patch +--- + +Reverts ESM support. diff --git a/jest.config.js b/jest.config.js index 92fd8ac0f..239ff437c 100644 --- a/jest.config.js +++ b/jest.config.js @@ -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', }, ], }, @@ -26,7 +15,6 @@ module.exports = { 'jest-watch-typeahead/testname', ], moduleNameMapper: { - '(.+)\\.js$': '$1', '@hypermod/(.*)$': '/packages/$1/src', '@codeshift/(.*)$': '/packages/$1/src', }, diff --git a/package.json b/package.json index c54fe1fc3..6a81d8c02 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/packages/cli-alias/bin/codeshift-cli.js b/packages/cli-alias/bin/codeshift-cli.js index 9ff5293bd..af523d395 100755 --- a/packages/cli-alias/bin/codeshift-cli.js +++ b/packages/cli-alias/bin/codeshift-cli.js @@ -1,2 +1,4 @@ #!/usr/bin/env node -export * from '../dist/index.js'; +const path = require('path'); + +require(path.join('..', 'dist', 'index.js')); diff --git a/packages/cli-alias/package.json b/packages/cli-alias/package.json index f402d4185..47811fef1 100644 --- a/packages/cli-alias/package.json +++ b/packages/cli-alias/package.json @@ -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", diff --git a/packages/cli/bin/hypermod-cli.js b/packages/cli/bin/hypermod-cli.js index 9ff5293bd..af523d395 100755 --- a/packages/cli/bin/hypermod-cli.js +++ b/packages/cli/bin/hypermod-cli.js @@ -1,2 +1,4 @@ #!/usr/bin/env node -export * from '../dist/index.js'; +const path = require('path'); + +require(path.join('..', 'dist', 'index.js')); diff --git a/packages/cli/package.json b/packages/cli/package.json index b2142145a..6ff614661 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -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", diff --git a/packages/cli/src/index.ts b/packages/cli/src/index.ts index ed1c513b0..869a3ad87 100644 --- a/packages/cli/src/index.ts +++ b/packages/cli/src/index.ts @@ -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', ); diff --git a/packages/cli/src/list.ts b/packages/cli/src/list.ts index aab66bafa..2b677dd8c 100644 --- a/packages/cli/src/list.ts +++ b/packages/cli/src/list.ts @@ -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(); diff --git a/packages/cli/src/main.ts b/packages/cli/src/main.ts index a263d1796..1f7efc04d 100644 --- a/packages/cli/src/main.ts +++ b/packages/cli/src/main.ts @@ -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) => { @@ -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', @@ -80,11 +76,7 @@ export default async function main( } const pluginManagerConfig: Partial = { - 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. @@ -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', ]); diff --git a/packages/cli/src/utils/fetch-package.ts b/packages/cli/src/utils/fetch-package.ts index abbd426f5..83ffd2ef4 100644 --- a/packages/cli/src/utils/fetch-package.ts +++ b/packages/cli/src/utils/fetch-package.ts @@ -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, diff --git a/packages/fetcher/src/index.spec.ts b/packages/fetcher/src/index.spec.ts index eaaf38e8f..9fd72464b 100644 --- a/packages/fetcher/src/index.spec.ts +++ b/packages/fetcher/src/index.spec.ts @@ -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), @@ -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 }, ); @@ -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, @@ -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'), ); }); @@ -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 }), @@ -155,7 +155,7 @@ describe('fetcher', () => { expect(configMeta!.config).toEqual(mockConfig); expect(configMeta!.filePath).toEqual( - mockBasePath + '/hypermod.config.ts', + mockBasePath + '/hypermod.config.js', ); }); diff --git a/scripts/sync.ts b/scripts/sync.ts index 4a84480b7..c333e7250 100644 --- a/scripts/sync.ts +++ b/scripts/sync.ts @@ -21,9 +21,9 @@ 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}`); } @@ -31,9 +31,7 @@ async function main() { const rawPkgName = dir.replace('__', '/'); data.push({ pkgName, - targets: - rawPkgName + - (configMeta.config.targets ? `, ${configMeta.config.targets}` : ''), + targets: rawPkgName + (config.targets ? `, ${config.targets}` : ''), }); } diff --git a/tsconfig.json b/tsconfig.json index 8d593c628..f31e7316d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,9 +2,9 @@ "compilerOptions": { "strict": true, "skipLibCheck": true, + "moduleResolution": "node", "target": "es6", - "module": "nodenext", - "moduleResolution": "nodenext", + "module": "CommonJS", "resolveJsonModule": true, "esModuleInterop": true, "lib": [ diff --git a/yarn.lock b/yarn.lock index bde1586c2..8ae2faee7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3142,7 +3142,7 @@ astral-regex@^2.0.0: async@^3.2.3: version "3.2.6" - resolved "https://packages.atlassian.com/api/npm/npm-remote/async/-/async-3.2.6.tgz#1b0728e14929d51b85b449b7f06e27c1145e38ce" + resolved "https://registry.yarnpkg.com/async/-/async-3.2.6.tgz#1b0728e14929d51b85b449b7f06e27c1145e38ce" integrity sha512-htCUDlxyyCLMgaM3xXg0C0LW2xqfuQ6p05pCEIsXuyQ+a1koYKTuBMzRNwmybfLgvJDMd0r1LTn4+E0Ti6C2AA== asynckit@^0.4.0: @@ -3338,7 +3338,7 @@ brace-expansion@^1.1.7: brace-expansion@^2.0.1: version "2.0.1" - resolved "https://packages.atlassian.com/api/npm/npm-remote/brace-expansion/-/brace-expansion-2.0.1.tgz#1edc459e0f0c548486ecf9fc99f2221364b9a0ae" + resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-2.0.1.tgz#1edc459e0f0c548486ecf9fc99f2221364b9a0ae" integrity sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA== dependencies: balanced-match "^1.0.0" @@ -3385,7 +3385,7 @@ browserslist@^4.22.2, browserslist@^4.6.6: bs-logger@^0.2.6: version "0.2.6" - resolved "https://packages.atlassian.com/api/npm/npm-remote/bs-logger/-/bs-logger-0.2.6.tgz#eb7d365307a72cf974cc6cda76b68354ad336bd8" + resolved "https://registry.yarnpkg.com/bs-logger/-/bs-logger-0.2.6.tgz#eb7d365307a72cf974cc6cda76b68354ad336bd8" integrity sha512-pd8DCoxmbgc7hyPKOvxtqNcjYoOsABPQdcCUjGp3d42VR2CX1ORhk2A87oqqu5R1kk+76nsxZupkmyd+MVtCog== dependencies: fast-json-stable-stringify "2.x" @@ -3754,7 +3754,7 @@ cross-spawn@^5.1.0: cross-spawn@^7.0.2, cross-spawn@^7.0.3: version "7.0.3" - resolved "https://packages.atlassian.com/api/npm/npm-remote/cross-spawn/-/cross-spawn-7.0.3.tgz#f73a85b9d5d41d045551c177e2882d4ac85728a6" + resolved "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz" integrity sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w== dependencies: path-key "^3.1.0" @@ -4024,7 +4024,7 @@ duplexer3@^0.1.4: ejs@^3.1.10: version "3.1.10" - resolved "https://packages.atlassian.com/api/npm/npm-remote/ejs/-/ejs-3.1.10.tgz#69ab8358b14e896f80cc39e62087b88500c3ac3b" + resolved "https://registry.yarnpkg.com/ejs/-/ejs-3.1.10.tgz#69ab8358b14e896f80cc39e62087b88500c3ac3b" integrity sha512-UeJmFfOrAQS8OJWPZ4qtgHyWExa088/MtK5UEyoJGFH67cDEXkZSviOiKRCZ4Xij0zxI3JECgYs3oKx+AizQBA== dependencies: jake "^10.8.5" @@ -4466,7 +4466,7 @@ file-entry-cache@^6.0.1: filelist@^1.0.4: version "1.0.4" - resolved "https://packages.atlassian.com/api/npm/npm-remote/filelist/-/filelist-1.0.4.tgz#f78978a1e944775ff9e62e744424f215e58352b5" + resolved "https://registry.yarnpkg.com/filelist/-/filelist-1.0.4.tgz#f78978a1e944775ff9e62e744424f215e58352b5" integrity sha512-w1cEuf3S+DrLCQL7ET6kz+gmlJdbq9J7yXCSjK/OZCPA+qEN1WyF4ZAf0YYJa4/shHJra2t/d/r8SV4Ji+x+8Q== dependencies: minimatch "^5.0.1" @@ -5377,7 +5377,7 @@ istanbul-reports@^3.1.3: jake@^10.8.5: version "10.9.2" - resolved "https://packages.atlassian.com/api/npm/npm-remote/jake/-/jake-10.9.2.tgz#6ae487e6a69afec3a5e167628996b59f35ae2b7f" + resolved "https://registry.yarnpkg.com/jake/-/jake-10.9.2.tgz#6ae487e6a69afec3a5e167628996b59f35ae2b7f" integrity sha512-2P4SQ0HrLQ+fw6llpLnOaGAvN2Zu6778SJMrCUwns4fOoG9ayrTiZk3VV8sCPkVZF8ab0zksVpS8FDY5pRCNBA== dependencies: async "^3.2.3" @@ -6169,7 +6169,7 @@ lodash.debounce@^4.0.8: lodash.memoize@^4.1.2: version "4.1.2" - resolved "https://packages.atlassian.com/api/npm/npm-remote/lodash.memoize/-/lodash.memoize-4.1.2.tgz#bcc6c49a42a2840ed997f323eada5ecd182e0bfe" + resolved "https://registry.yarnpkg.com/lodash.memoize/-/lodash.memoize-4.1.2.tgz#bcc6c49a42a2840ed997f323eada5ecd182e0bfe" integrity sha512-t7j+NzmgnQzTAYXcsHYLgimltOV1MXHtlOWf6GjL9Kj8GK5FInw5JotxvbOs+IvV1/Dzo04/fCGfLVs7aXb4Ag== lodash.merge@^4.6.2: @@ -6256,7 +6256,7 @@ make-dir@^4.0.0: make-error@^1.1.1, make-error@^1.3.6: version "1.3.6" - resolved "https://packages.atlassian.com/api/npm/npm-remote/make-error/-/make-error-1.3.6.tgz#2eb2e37ea9b67c4891f684a1394799af484cf7a2" + resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.6.tgz#2eb2e37ea9b67c4891f684a1394799af484cf7a2" integrity sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw== makeerror@1.0.12: @@ -6391,7 +6391,7 @@ minimatch@^3.0.2, minimatch@^3.0.4, minimatch@^3.1.1, minimatch@^3.1.2: minimatch@^5.0.1: version "5.1.6" - resolved "https://packages.atlassian.com/api/npm/npm-remote/minimatch/-/minimatch-5.1.6.tgz#1cfcb8cf5522ea69952cd2af95ae09477f122a96" + resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-5.1.6.tgz#1cfcb8cf5522ea69952cd2af95ae09477f122a96" integrity sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g== dependencies: brace-expansion "^2.0.1" @@ -7412,7 +7412,7 @@ semver@^7.2.1, semver@^7.3.5, semver@^7.3.7, semver@^7.5.2, semver@^7.5.3, semve semver@^7.6.3: version "7.6.3" - resolved "https://packages.atlassian.com/api/npm/npm-remote/semver/-/semver-7.6.3.tgz#980f7b5550bc175fb4dc09403085627f9eb33143" + resolved "https://registry.yarnpkg.com/semver/-/semver-7.6.3.tgz#980f7b5550bc175fb4dc09403085627f9eb33143" integrity sha512-oVekP1cKtI+CTDvHWYFUcMtsK/00wmAEfyqKfNdARm8u1wNVhSgaX7A8d4UuIlUI5e84iEwOhs7ZPYRmzU9U6A== set-blocking@^2.0.0: @@ -7981,14 +7981,9 @@ trim-newlines@^3.0.0: resolved "https://registry.npmjs.org/trim-newlines/-/trim-newlines-3.0.1.tgz" integrity sha512-c1PTsA3tYrIsLGkJkzHF+w9F2EyxfXGo4UyJc4pFL++FMjnq0HJS69T3M7d//gKrFKwy429bouPescbjecU+Zw== -ts-jest-mock-import-meta@^1.2.0: - version "1.2.0" - resolved "https://packages.atlassian.com/api/npm/npm-remote/ts-jest-mock-import-meta/-/ts-jest-mock-import-meta-1.2.0.tgz#6fb12a1fa47f70f9335a288e888cbacf592c4dc1" - integrity sha512-r2+TH6d8LHBXqLTXjJh1KfTZoMvGV0hdn9gwickNVcwS2Co2/mewGjj0XDVEPLg5MVfZVHUFQ9O09anURA3KCw== - ts-jest@^29.2.5: version "29.2.5" - resolved "https://packages.atlassian.com/api/npm/npm-remote/ts-jest/-/ts-jest-29.2.5.tgz#591a3c108e1f5ebd013d3152142cb5472b399d63" + resolved "https://registry.yarnpkg.com/ts-jest/-/ts-jest-29.2.5.tgz#591a3c108e1f5ebd013d3152142cb5472b399d63" integrity sha512-KD8zB2aAZrcKIdGk4OwpJggeLcH1FgrICqDSROWqlnJXGCXK4Mn6FcdK2B6670Xr73lHMG1kHw8R87A0ecZ+vA== dependencies: bs-logger "^0.2.6"