Skip to content

Commit e0d9fdc

Browse files
committed
chore: remove await imports
1 parent da47cd1 commit e0d9fdc

File tree

8 files changed

+56
-90
lines changed

8 files changed

+56
-90
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
},
3131
"lint-staged": {
3232
"*.{ts,tsx,js,jsx}": [
33-
"eslint --fix --cache"
33+
"oxlint --format stylish --fix",
34+
"prettier --write"
3435
],
3536
"**/(package|tsconfig(.*)?).json": [
3637
"prettier --write"

packages/jsx-email/src/components/code.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Suspense } from 'react';
2-
// @ts-ignore
3-
import { type BuiltinLanguage } from 'shiki';
2+
import { codeToHtml, type BuiltinLanguage } from 'shiki';
43

54
import { debug } from '../debug.js';
65
import { useData } from '../renderer/suspense.js';
@@ -20,9 +19,6 @@ const Renderer = (props: React.PropsWithChildren<CodeProps>) => {
2019
const { children, language, style, theme = 'nord', ...rest } = props;
2120
const code = children as string;
2221
const highlight = async () => {
23-
// Note: When building CJS with thsy, tsc thinks that this isn't already dynamic
24-
// @ts-ignore
25-
const { codeToHtml } = await import('shiki');
2622
const html = await codeToHtml(code, { lang: language, theme });
2723
return html;
2824
};

packages/jsx-email/src/components/tailwind/tailwind.tsx

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
// eslint-disable-next-line import/no-extraneous-dependencies
2-
// @ts-ignore
31
import type { ConfigBase } from '@unocss/core';
2+
import { createGenerator } from '@unocss/core';
3+
import { presetTypography } from '@unocss/preset-typography';
4+
import { presetWind } from '@unocss/preset-wind';
5+
import { presetUno } from '@unocss/preset-uno';
6+
import { presetRemToPx } from '@unocss/preset-rem-to-px';
7+
import transformerCompileClass from '@unocss/transformer-compile-class';
8+
import transformerVariantGroup from '@unocss/transformer-variant-group';
49
import MagicString from 'magic-string';
510
import postcss from 'postcss';
611
// @ts-ignore
@@ -26,21 +31,6 @@ export interface TailwindProps {
2631
const debugProps = debug.elements.enabled ? { dataType: 'jsx-email/tailwind' } : {};
2732

2833
const getUno = async (config: ConfigBase, production: boolean) => {
29-
// @ts-ignore
30-
const { createGenerator } = await import('@unocss/core');
31-
// @ts-ignore
32-
const { presetTypography } = await import('@unocss/preset-typography');
33-
// @ts-ignore
34-
const { presetWind } = await import('@unocss/preset-wind');
35-
// @ts-ignore
36-
const { presetUno } = await import('@unocss/preset-uno');
37-
// @ts-ignore
38-
const { presetRemToPx } = await import('@unocss/preset-rem-to-px');
39-
// @ts-ignore
40-
const { default: transformerCompileClass } = await import('@unocss/transformer-compile-class');
41-
// @ts-ignore
42-
const { default: transformerVariantGroup } = await import('@unocss/transformer-variant-group');
43-
4434
const transformers = [transformerVariantGroup()];
4535

4636
if (production)

packages/jsx-email/src/config.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,6 @@ const handleImportError = (error: any, name: string) => {
9595
// their names without additional config, and we don't want that burden on users
9696
const importInlinePlugin = async () => {
9797
try {
98-
// Note: tshy up to bullshit again with compile errors where there are none
99-
// @ts-ignore
10098
const { plugin } = (await import('@jsx-email/plugin-inline')) as unknown as PluginImport;
10199
return plugin;
102100
} catch (error) {
@@ -108,7 +106,6 @@ const importInlinePlugin = async () => {
108106

109107
const importMinifyPlugin = async () => {
110108
try {
111-
// @ts-ignore
112109
const { plugin } = (await import('@jsx-email/plugin-minify')) as unknown as PluginImport;
113110
return plugin;
114111
} catch (error) {
@@ -120,7 +117,6 @@ const importMinifyPlugin = async () => {
120117

121118
const importPrettyPlugin = async () => {
122119
try {
123-
// @ts-ignore
124120
const { plugin } = (await import('@jsx-email/plugin-pretty')) as unknown as PluginImport;
125121
return plugin;
126122
} catch (error) {

packages/jsx-email/src/renderer/move-style.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import type { Element, Parents, Root } from 'hast';
2+
import { visit } from 'unist-util-visit';
23

34
interface ElementWithParent extends Element {
45
index: number;
56
parent: Parents;
67
}
78

89
export const getMovePlugin = async () => {
9-
const { visit } = await import('unist-util-visit');
10-
1110
return function moveStylePlugin() {
1211
return function move(tree: Root) {
1312
const matches: ElementWithParent[] = [];

packages/jsx-email/src/renderer/render.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { htmlToText } from 'html-to-text';
2+
import { rehype } from 'rehype';
3+
import stringify from 'rehype-stringify';
24

35
import { defineConfig, loadConfig, mergeConfig, type JsxEmailConfig } from '../config.js';
46
import { callHook, callProcessHook } from '../plugins.js';
@@ -69,8 +71,6 @@ export const render = async (component: React.ReactElement, options?: RenderOpti
6971
};
7072

7173
const processHtml = async (config: JsxEmailConfig, html: string) => {
72-
const { rehype } = await import('rehype');
73-
const { default: stringify } = await import('rehype-stringify');
7474
const docType =
7575
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
7676
const movePlugin = await getMovePlugin();

packages/plugin-inline/src/index.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
1-
// Note: tshy has some bugs with dual-mode package importing in the cjs build https://github.com/isaacs/tshy/issues/50
2-
// @ts-ignore
31
import { parse } from '@adobe/css-tools';
4-
// @ts-ignore
52
import type { Root } from 'hast';
3+
import { selectAll } from 'hast-util-select';
4+
import { toString } from 'hast-util-to-string';
5+
import { remove } from 'unist-util-remove';
6+
import { visit } from 'unist-util-visit';
67
import { pluginSymbol, type JsxEmailPlugin } from 'jsx-email';
7-
// @ts-ignore
88
import type { Plugin } from 'unified';
99

1010
export const plugin: JsxEmailPlugin = {
1111
name: 'root/inline',
1212
process: async () => {
13-
const { selectAll } = await import('hast-util-select');
14-
const { toString } = await import('hast-util-to-string');
15-
const { remove } = await import('unist-util-remove');
16-
const { visit } = await import('unist-util-visit');
17-
1813
return function inlineCssPlugin() {
1914
return function inline(tree: Root) {
2015
if (!tree) return null;

packages/plugin-minify/src/index.ts

Lines changed: 39 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,22 @@
11
import { pluginSymbol, type JsxEmailPlugin } from 'jsx-email';
2-
// Note: tshy has some bugs with dual-mode package importing in the cjs build https://github.com/isaacs/tshy/issues/50
3-
// @ts-ignore
4-
import type { Pluggable, Preset, Settings } from 'unified';
5-
6-
// Note: rehype is all ESM-only, so for CJS compat we're dynamically importing
7-
// No, we're not going to force ESM on users
8-
const importPlugins = async () => {
9-
const rehypeMinifyAttributeWhitespace = await import('rehype-minify-attribute-whitespace');
10-
const rehypeMinifyCssStyle = await import('rehype-minify-css-style');
11-
const rehypeMinifyEnumeratedAttribute = await import('rehype-minify-enumerated-attribute');
12-
const rehypeMinifyMediaAttribute = await import('rehype-minify-media-attribute');
13-
const rehypeMinifyMetaColor = await import('rehype-minify-meta-color');
14-
const rehypeMinifyMetaContent = await import('rehype-minify-meta-content');
15-
const rehypeMinifyStyleAttribute = await import('rehype-minify-style-attribute');
16-
const rehypeMinifyWhitespace = await import('rehype-minify-whitespace');
17-
const rehypeNormalizeAttributeValueCase = await import('rehype-normalize-attribute-value-case');
18-
const rehypeRemoveComments = await import('rehype-remove-comments');
19-
const rehypeRemoveDuplicateAttributeValues = await import(
20-
'rehype-remove-duplicate-attribute-values'
21-
);
22-
const rehypeRemoveEmptyAttribute = await import('rehype-remove-empty-attribute');
23-
const rehypeRemoveExternalScriptContent = await import('rehype-remove-external-script-content');
24-
const rehypeRemoveMetaHttpEquiv = await import('rehype-remove-meta-http-equiv');
25-
const rehypeRemoveStyleTypeCss = await import('rehype-remove-style-type-css');
26-
const rehypeSortAttributeValues = await import('rehype-sort-attribute-values');
27-
const rehypeSortAttributes = await import('rehype-sort-attributes');
28-
29-
return [
30-
rehypeMinifyAttributeWhitespace,
31-
rehypeMinifyCssStyle,
32-
// Note: `rehypeRemoveMetaHttpEquiv` goes before
33-
// `rehypeMinifyEnumeratedAttribute`, as the latter might minify things further.
34-
rehypeRemoveMetaHttpEquiv,
35-
rehypeMinifyEnumeratedAttribute,
36-
rehypeMinifyMediaAttribute,
37-
rehypeMinifyMetaColor,
38-
rehypeMinifyMetaContent,
39-
rehypeMinifyStyleAttribute,
40-
rehypeMinifyWhitespace,
41-
rehypeNormalizeAttributeValueCase,
42-
rehypeRemoveComments,
43-
rehypeRemoveDuplicateAttributeValues,
44-
rehypeRemoveEmptyAttribute,
45-
rehypeRemoveExternalScriptContent,
46-
rehypeRemoveStyleTypeCss,
47-
rehypeSortAttributeValues,
48-
rehypeSortAttributes
49-
].map((mod) => mod.default) as Pluggable[];
50-
};
2+
import rehypeMinifyAttributeWhitespace from 'rehype-minify-attribute-whitespace';
3+
import rehypeMinifyCssStyle from 'rehype-minify-css-style';
4+
import rehypeMinifyEnumeratedAttribute from 'rehype-minify-enumerated-attribute';
5+
import rehypeMinifyMediaAttribute from 'rehype-minify-media-attribute';
6+
import rehypeMinifyMetaColor from 'rehype-minify-meta-color';
7+
import rehypeMinifyMetaContent from 'rehype-minify-meta-content';
8+
import rehypeMinifyStyleAttribute from 'rehype-minify-style-attribute';
9+
import rehypeMinifyWhitespace from 'rehype-minify-whitespace';
10+
import rehypeNormalizeAttributeValueCase from 'rehype-normalize-attribute-value-case';
11+
import rehypeRemoveComments from 'rehype-remove-comments';
12+
import rehypeRemoveDuplicateAttributeValues from 'rehype-remove-duplicate-attribute-values';
13+
import rehypeRemoveEmptyAttribute from 'rehype-remove-empty-attribute';
14+
import rehypeRemoveExternalScriptContent from 'rehype-remove-external-script-content';
15+
import rehypeRemoveMetaHttpEquiv from 'rehype-remove-meta-http-equiv';
16+
import rehypeRemoveStyleTypeCss from 'rehype-remove-style-type-css';
17+
import rehypeSortAttributeValues from 'rehype-sort-attribute-values';
18+
import rehypeSortAttributes from 'rehype-sort-attributes';
19+
import type { Preset, Settings } from 'unified';
5120

5221
const settings = {
5322
allowParseErrors: true,
@@ -69,7 +38,27 @@ const settings = {
6938
export const plugin: JsxEmailPlugin = {
7039
name: 'root/minify',
7140
process: async (): Promise<Preset> => {
72-
const plugins = await importPlugins();
41+
const plugins = [
42+
rehypeMinifyAttributeWhitespace,
43+
rehypeMinifyCssStyle,
44+
// Note: `rehypeRemoveMetaHttpEquiv` goes before
45+
// `rehypeMinifyEnumeratedAttribute`, as the latter might minify things further.
46+
rehypeRemoveMetaHttpEquiv,
47+
rehypeMinifyEnumeratedAttribute,
48+
rehypeMinifyMediaAttribute,
49+
rehypeMinifyMetaColor,
50+
rehypeMinifyMetaContent,
51+
rehypeMinifyStyleAttribute,
52+
rehypeMinifyWhitespace,
53+
rehypeNormalizeAttributeValueCase,
54+
rehypeRemoveComments,
55+
rehypeRemoveDuplicateAttributeValues,
56+
rehypeRemoveEmptyAttribute,
57+
rehypeRemoveExternalScriptContent,
58+
rehypeRemoveStyleTypeCss,
59+
rehypeSortAttributeValues,
60+
rehypeSortAttributes
61+
];
7362

7463
return { plugins, settings };
7564
},

0 commit comments

Comments
 (0)