Skip to content

Commit

Permalink
Switch to async imports for CJS/ESM compat
Browse files Browse the repository at this point in the history
  • Loading branch information
shilman committed May 25, 2024
1 parent 90062ea commit 915a137
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions code/lib/cli/src/automigrate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import prompts from 'prompts';
import chalk from 'chalk';
import boxen from 'boxen';
import { createWriteStream, move, remove } from 'fs-extra';
import { temporaryFile } from 'tempy';
import { join } from 'path';
import invariant from 'tiny-invariant';
import semver from 'semver';
Expand Down Expand Up @@ -40,7 +39,8 @@ let TEMP_LOG_FILE_PATH = '';
const originalStdOutWrite = process.stdout.write.bind(process.stdout);
const originalStdErrWrite = process.stderr.write.bind(process.stdout);

const augmentLogsToFile = () => {
const augmentLogsToFile = async () => {
const { temporaryFile } = await import('tempy');
TEMP_LOG_FILE_PATH = temporaryFile({ name: LOG_FILE_NAME });
const logStream = createWriteStream(TEMP_LOG_FILE_PATH);

Expand Down Expand Up @@ -158,7 +158,7 @@ export const automigrate = async ({
return null;
}

augmentLogsToFile();
await augmentLogsToFile();

logger.info('🔎 checking possible migrations..');

Expand Down
2 changes: 1 addition & 1 deletion code/lib/cli/src/dirs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { dirname, join } from 'path';

import downloadTarball from '@ndelangen/get-tarball';
import getNpmTarballUrl from 'get-npm-tarball-url';
import { temporaryDirectory } from 'tempy';

import invariant from 'tiny-invariant';
import { externalFrameworks } from './project_types';
Expand All @@ -16,6 +15,7 @@ export function getCliDir() {
}

const resolveUsingBranchInstall = async (packageManager: JsPackageManager, request: string) => {
const { temporaryDirectory } = await import('tempy');
const tempDirectory = temporaryDirectory();
const name = request as keyof typeof versions;

Expand Down
6 changes: 3 additions & 3 deletions code/lib/cli/src/doctor/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import chalk from 'chalk';
import boxen from 'boxen';
import { createWriteStream, move, remove } from 'fs-extra';
import { temporaryFile } from 'tempy';
import dedent from 'ts-dedent';
import { join } from 'path';

Expand All @@ -24,7 +23,8 @@ let TEMP_LOG_FILE_PATH = '';
const originalStdOutWrite = process.stdout.write.bind(process.stdout);
const originalStdErrWrite = process.stderr.write.bind(process.stdout);

const augmentLogsToFile = () => {
const augmentLogsToFile = async () => {
const { temporaryFile } = await import('tempy');
TEMP_LOG_FILE_PATH = temporaryFile({ name: LOG_FILE_NAME });
const logStream = createWriteStream(TEMP_LOG_FILE_PATH);

Expand All @@ -51,7 +51,7 @@ export const doctor = async ({
configDir: userSpecifiedConfigDir,
packageManager: pkgMgr,
}: DoctorOptions = {}) => {
augmentLogsToFile();
await augmentLogsToFile();

let foundIssues = false;
const logDiagnostic = (title: string, message: string) => {
Expand Down
2 changes: 1 addition & 1 deletion code/lib/core-common/src/utils/cli.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { WriteStream } from 'fs-extra';
import { move, remove, writeFile, readFile, createWriteStream } from 'fs-extra';
import { join } from 'path';
import { temporaryFile } from 'tempy';
import { rendererPackages } from './get-storybook-info';
import type { JsPackageManager } from '../js-package-manager';
import versions from '../versions';
Expand Down Expand Up @@ -86,6 +85,7 @@ export const createLogStream = async (
logStream: WriteStream;
}> => {
const finalLogPath = join(process.cwd(), logFileName);
const { temporaryFile } = await import('tempy');
const temporaryLogPath = temporaryFile({ name: logFileName });

const logStream = createWriteStream(temporaryLogPath, { encoding: 'utf8' });
Expand Down
2 changes: 1 addition & 1 deletion scripts/combine-compodoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import { join, resolve } from 'path';
import { realpath, readFile, writeFile, lstat } from 'fs-extra';
import { globSync } from 'glob';
import { temporaryDirectory } from 'tempy';
import { execaCommand } from 'execa';
import { esMain } from './utils/esmain';

Expand Down Expand Up @@ -36,6 +35,7 @@ async function run(cwd: string) {

const docsArray: Record<string, any>[] = await Promise.all(
dirs.map(async (dir) => {
const { temporaryDirectory } = await import('tempy');
const outputDir = temporaryDirectory();
const resolvedDir = await realpath(dir);
await execaCommand(
Expand Down

0 comments on commit 915a137

Please sign in to comment.