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: ESM error when using SST #1279

Closed
wants to merge 1 commit into from
Closed
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
4 changes: 3 additions & 1 deletion packages/manager/src/lib/format.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import prettier from "prettier";
import type prettier from "prettier";
import { stripIndent } from "common-tags";

type FormatOptions = {
Expand All @@ -16,6 +16,8 @@ export const format = async (
filePath: string,
options?: FormatOptions,
): Promise<string> => {
const prettier = await import("prettier");

Copy link
Collaborator

@bapmrl bapmrl Jan 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❓ Can dynamically loading the prettier module impact the performance of the format function? I'm thinking of what could happen with a large amount of consecutive calls.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dynamic imports shouldn't significantly impact performance unless the module contains a lot of code. Prettier is large, so it's possible it could cause slow-downs, but I don't think it would be significant enough to worry about it.

Typically only the first load takes longer. I think Node.js's import cache speeds up subsequent imports.

let formatted = stripIndent(source);

const prettierOptions = await prettier.resolveConfig(filePath);
Expand Down
4 changes: 3 additions & 1 deletion packages/plugin-kit/src/createSliceMachineHelpers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as path from "node:path";
import * as fs from "node:fs/promises";

import prettier from "prettier";
import type prettier from "prettier";
import { stripIndent } from "common-tags";

import { decodeSliceMachineConfig } from "./lib/decodeSliceMachineConfig";
Expand Down Expand Up @@ -105,6 +105,8 @@ export class SliceMachineHelpers {
filePath?: string,
options?: FormatOptions,
): Promise<string> => {
const prettier = await import("prettier");

let formatted = stripIndent(source);

const prettierOptions = await prettier.resolveConfig(
Expand Down
Loading