Skip to content
This repository has been archived by the owner on Dec 4, 2024. It is now read-only.

Commit

Permalink
fix: support node v16 and later
Browse files Browse the repository at this point in the history
  • Loading branch information
ErrorErrorError committed Dec 13, 2023
1 parent 8b226c1 commit 0f64500
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

Powered by <a href="https://github.com/evanw/esbuild"><img style="height: 1rem; vertical-align: text-bottom;" src="https://esbuild.github.io/favicon.svg" alt="esbuild logo"/></a>

## Requirements
You must have [Node](https://nodejs.org) installed on your computer and the minimum version supported is `v16.x`.

## Installation

For pnpm:
Expand Down
51 changes: 24 additions & 27 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,45 @@ import * as path from 'path';

import vm from 'vm';
import consola from 'consola';
import { Dirent } from 'fs';
import { rm, readFile, writeFile, mkdir, readdir, stat } from 'fs/promises';
import ejs from 'ejs';
import ts from 'typescript';
import esbuild from 'esbuild';

const MOCHI_JS_NAME = '@mochiapp/js';

const getModulesDirectories = async (basedir: string, log: boolean = true) => {
type ModulePath = {
name: string;
path: string;
};

const getModulesDirectories = async (basedir: string, log: boolean = true): Promise<ModulePath[]> => {
consola.log('');
consola.info(`Verifying ${basedir}`);
const directories = await readdir(path.join(basedir, 'src'), { withFileTypes: true });
const directories = await readdir(path.join(basedir, 'src'));

const allModules = await Promise.all(
directories.map((f) =>
stat(path.join(f.path, f.name, 'index.ts'))
const allModules: ModulePath[] = await Promise.all(
directories.map((item) => {
const itemPath = path.join(basedir, 'src', item);
const itemIndexPath = path.join(itemPath, 'index.ts');
return stat(itemIndexPath)
.then((s) => {
if (s.isFile()) {
if (log)
consola.log(
` \x1b[32m\u21B3\x1b[0m ${path.relative(
basedir,
path.join(f.path, f.name),
)}/index.ts - module found!`,
);
return f;
if (log) consola.log(` \x1b[32m\u21B3\x1b[0m ${itemIndexPath} - module found!`);
return {
name: item,
path: itemPath,
} as ModulePath;
} else {
throw new Error(''); // stub
}
throw new Error(''); // stub
})
.then(() => f)
.catch(() => {
if (log)
consola.log(
` \x1b[33m\u26A0\x1b[0m ${path.relative(
basedir,
path.join(f.path, f.name),
)} - does not contain an index.ts file, skipping..`,
);
if (log) consola.log(` \x1b[33m\u26A0\x1b[0m ${itemPath} - does not contain an index.ts file, skipping..`);
return undefined;
}),
),
).then((l) => l.filter((d): d is Dirent => !!d));
});
}),
).then((l) => l.filter((i): i is ModulePath => !!i));

consola.log('');
consola.info(`Found ${allModules.length} module${allModules.length == 1 ? '' : 's'}.`);
Expand Down Expand Up @@ -98,7 +95,7 @@ export const buildOptions = async (basedir: string, outOptions?: BundleOption, t

const entryPoints = modulesDirs.map((d) => {
return {
in: path.resolve(d.path, d.name, 'index.ts'),
in: path.resolve(d.path, 'index.ts'),
out: d.name,
};
});
Expand Down

0 comments on commit 0f64500

Please sign in to comment.