Skip to content
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

fix(jsx-email): use upstream lilconfig, upstream next fix #231

Merged
merged 2 commits into from
Oct 26, 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
2 changes: 1 addition & 1 deletion packages/jsx-email/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
"@jsx-email/doiuse-email": "^1.0.1",
"@parcel/watcher": "^2.4.1",
"@radix-ui/react-slot": "1.0.2",
"@shellscape/lilconfig": "^3.2.1",
"@unocss/core": "^0.60.0",
"@unocss/preset-rem-to-px": "^0.59.3",
"@unocss/preset-typography": "^0.60.0",
Expand All @@ -82,6 +81,7 @@
"globby": "11.0.4",
"hash-it": "^6.0.0",
"html-to-text": "9.0.5",
"lilconfig": "^3.1.2",
"magic-string": "^0.30.5",
"md-to-react-email": "5.0.2",
"micromatch": "^4.0.5",
Expand Down
32 changes: 28 additions & 4 deletions packages/jsx-email/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AssertionError } from 'assert';

import chalk from 'chalk';
import { lilconfig } from '@shellscape/lilconfig';
import { lilconfig } from 'lilconfig';
import type { MethodFactoryLevels } from '@dot/log';

import { getPluginLog, log } from './log.js';
Expand Down Expand Up @@ -191,11 +191,36 @@
return result;
};

const moduleImport = async (id: string) => {
try {
const mod = await import(id);
return mod;
} catch (e) {
try {
return require(id);

Check warning on line 200 in packages/jsx-email/src/config.ts

View workflow job for this annotation

GitHub Actions / Validate

Unexpected require()

Check warning on line 200 in packages/jsx-email/src/config.ts

View workflow job for this annotation

GitHub Actions / Validate

Calls to require() should use string literals
} catch (error) {
if (
(error as any).code === 'ERR_REQUIRE_ESM' ||
(error instanceof SyntaxError &&
error.toString().includes('Cannot use import statement outside a module'))
) {
throw e;
}
throw error;
}
}
};

export const loadConfig = async (startDir?: string): Promise<JsxEmailConfig> => {
if ((globalThis as any)[globalConfigSymbol]) return (globalThis as any)[globalConfigSymbol];

const name = 'jsx-email';
const searchResult = await lilconfig(name, {
loaders: {
'.cjs': moduleImport,
'.js': moduleImport,
'.mjs': moduleImport
},
searchPlaces: [
`.config/${name}rc.js`,
`.config/${name}rc.cjs`,
Expand All @@ -209,9 +234,8 @@
`${name}.config.js`,
`${name}.config.cjs`,
`${name}.config.mjs`
],
...(startDir ? { startDir } : {})
}).search();
]
}).search(startDir);

log.debug('loadConfig →', { cwd: process.cwd(), searchResult, startDir });

Expand Down
38 changes: 19 additions & 19 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading