Skip to content

Various improvemnts pre esm #240

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 2 commits into from
Sep 21, 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/hungry-spies-build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@hypermod/validator': patch
'@hypermod/cli': patch
---

Various configuration changes in support of ESM.
16 changes: 15 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
testEnvironment: 'node',
transform: {
'^.+\\.ts$': [
'\\.[jt]sx?$': [
'ts-jest',
{
tsconfig: 'tsconfig.json',
diagnostics: { ignoreCodes: [1343] },
astTransformers: {
before: [
{
path: 'node_modules/ts-jest-mock-import-meta',
options: {
metaObjectReplacement: { url: 'https://www.url.com' },
},
},
],
},
},
],
},
Expand All @@ -15,6 +28,7 @@ module.exports = {
'jest-watch-typeahead/testname',
],
moduleNameMapper: {
'(.+)\\.js$': '$1',
'@hypermod/(.*)$': '<rootDir>/packages/$1/src',
'@codeshift/(.*)$': '<rootDir>/packages/$1/src',
},
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"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
12 changes: 12 additions & 0 deletions packages/cli/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,21 +112,33 @@ export default async function main(
*/
const configFilePath = await findUp([
'hypermod.config.js',
'hypermod.config.mjs',
'hypermod.config.cjs',
'hypermod.config.ts',
'hypermod.config.tsx',
'src/hypermod.config.js',
'src/hypermod.config.mjs',
'src/hypermod.config.cjs',
'src/hypermod.config.ts',
'src/hypermod.config.tsx',
'codemods/hypermod.config.js',
'codemods/hypermod.config.mjs',
'codemods/hypermod.config.cjs',
'codemods/hypermod.config.ts',
'codemods/hypermod.config.tsx',
'codeshift.config.js',
'codeshift.config.mjs',
'codeshift.config.cjs',
'codeshift.config.ts',
'codeshift.config.tsx',
'src/codeshift.config.js',
'src/codeshift.config.mjs',
'src/codeshift.config.cjs',
'src/codeshift.config.ts',
'src/codeshift.config.tsx',
'codemods/codeshift.config.js',
'codemods/codeshift.config.mjs',
'codemods/codeshift.config.cjs',
'codemods/codeshift.config.ts',
'codemods/codeshift.config.tsx',
]);
Expand Down
22 changes: 11 additions & 11 deletions packages/fetcher/src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ const mockBasePath = path.join(__dirname, 'path', 'to');

const mockConfig = {
transforms: {
'10.0.0': 'path/to/transform.js',
'10.0.0': 'path/to/transform.ts',
},
};

describe('fetcher', () => {
let mockMatchedPaths: string[] = [];

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

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

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

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

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

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

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

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

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

Expand All @@ -177,7 +177,7 @@ describe('fetcher', () => {
install: jest.fn(),
require: jest.fn().mockReturnValueOnce(mockConfig),
getInfo: jest.fn().mockReturnValue({
location: mockBasePath + '/index.js',
location: mockBasePath + '/index.ts',
}),
};

Expand All @@ -187,15 +187,15 @@ describe('fetcher', () => {
);

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

it('throws if entrypoint-based config does not contain a valid config (and there are no config files available elsewhere)', async () => {
const mockPackageManager = {
install: jest.fn(),
require: jest.fn().mockReturnValueOnce({}),
getInfo: jest.fn().mockReturnValue({
location: mockBasePath + '/index.js',
location: mockBasePath + '/index.ts',
}),
};

Expand Down
2 changes: 1 addition & 1 deletion packages/validator/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function hasValidPresets(config: Config): boolean {
if (!config.presets) return true;

return Object.entries(config.presets).every(([key]) =>
key.match(/^[0-9a-zA-Z\-]+$/),
key.match(/^[0-9a-zA-Z\-\.]+$/),
);
}

Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7981,6 +7981,11 @@ 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://registry.yarnpkg.com/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://registry.yarnpkg.com/ts-jest/-/ts-jest-29.2.5.tgz#591a3c108e1f5ebd013d3152142cb5472b399d63"
Expand Down
Loading