Skip to content

Commit 6c776d8

Browse files
author
Daniel Del Core
committed
package val+fetcher esm setup
1 parent d3162ae commit 6c776d8

File tree

4 files changed

+8
-4
lines changed

4 files changed

+8
-4
lines changed

packages/fetcher/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"name": "@hypermod/fetcher",
33
"version": "0.9.0",
4+
"type": "module",
45
"source": "src/index.ts",
56
"main": "dist/index.js",
67
"types": "dist/index.d.ts",

packages/fetcher/src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ function resolveConfigExport(pkg: any): Config {
4848
return pkg.default ? pkg.default : pkg;
4949
}
5050

51-
function requireConfig(filePath: string, resolvedPath: string) {
51+
async function requireConfig(filePath: string, resolvedPath: string) {
5252
try {
5353
// eslint-disable-next-line @typescript-eslint/no-var-requires
54-
const pkg = require(resolvedPath);
54+
const pkg = await import(resolvedPath);
5555
return resolveConfigExport(pkg);
5656
} catch (e) {
5757
console.log(resolvedPath, e);
@@ -89,7 +89,7 @@ export async function fetchConfigs(filePath: string): Promise<ConfigMeta[]> {
8989

9090
configs.push({
9191
filePath: matchedPath,
92-
config: requireConfig(matchedPath, resolvedMatchedPath),
92+
config: await requireConfig(matchedPath, resolvedMatchedPath),
9393
});
9494
}
9595

packages/validator/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"name": "@hypermod/validator",
33
"version": "0.6.9",
4+
"type": "module",
45
"source": "src/index.ts",
56
"main": "dist/index.js",
67
"types": "dist/index.d.ts",

scripts/validate.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import fs, { lstatSync, existsSync } from 'fs-extra';
22
import junk from 'junk';
33
import path from 'path';
44
import chalk from 'chalk';
5-
import { isValidPackageName, isValidConfigAtPath } from '@hypermod/validator';
65

76
const validPackageNameFormat =
87
/^@hypermod\/mod(-[a-zA-Z0-9]+)*(-(?!__)[a-zA-Z0-9]+)*(__([a-zA-Z0-9]+(-[a-zA-Z0-9]+)*)?)?$/;
@@ -29,6 +28,9 @@ For example: @hypermod/mod-foo__bar`);
2928
}
3029

3130
async function main(targetPath: string) {
31+
const { isValidPackageName, isValidConfigAtPath } = await import(
32+
'@hypermod/validator'
33+
);
3234
const directories = await fs.readdir(targetPath);
3335

3436
directories

0 commit comments

Comments
 (0)