mirror of
https://github.com/sern-handler/handler
synced 2026-06-06 09:26:54 +00:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
215aca2f46 | ||
|
|
a7f5ea269f | ||
|
|
52d6368440 | ||
|
|
1e723a4154 | ||
|
|
5fe13f43d2 | ||
|
|
ab9d39306a |
39
.github/workflows/codeql-analysis.yml
vendored
39
.github/workflows/codeql-analysis.yml
vendored
@@ -1,39 +0,0 @@
|
||||
name: "CodeQL"
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ main ]
|
||||
paths: ["src/**/*"]
|
||||
pull_request:
|
||||
branches: [ main ]
|
||||
paths: ["src/**/*"]
|
||||
schedule:
|
||||
- cron: '37 20 * * 4'
|
||||
|
||||
jobs:
|
||||
analyze:
|
||||
name: Analyze
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
actions: read
|
||||
contents: read
|
||||
security-events: write
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
language: [ 'javascript' ]
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v2
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
- name: Autobuild
|
||||
uses: github/codeql-action/autobuild@v2
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@v2
|
||||
4
.github/workflows/npm-publish.yml
vendored
4
.github/workflows/npm-publish.yml
vendored
@@ -2,6 +2,10 @@ name: NPM / Publish
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
# We only publish if the version of sern handler is different. workflow automatically cancels if verson is the same
|
||||
push:
|
||||
branches:
|
||||
- 'main'
|
||||
jobs:
|
||||
test-and-publish:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
29
.github/workflows/test.yml
vendored
Normal file
29
.github/workflows/test.yml
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
|
||||
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
|
||||
|
||||
name: Node.js CI
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches: [ "main" ]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [18.x, 19.x, 20.x]
|
||||
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
cache: 'npm'
|
||||
- run: npm install -g yarn
|
||||
- run: yarn install
|
||||
- run: yarn test
|
||||
4
.gitignore
vendored
4
.gitignore
vendored
@@ -91,3 +91,7 @@ dist
|
||||
# Yarn files
|
||||
.yarn/install-state.gz
|
||||
.yarn/build-state.yml
|
||||
|
||||
.yalc
|
||||
|
||||
yalc.lock
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
# Changelog
|
||||
|
||||
## [3.0.2](https://github.com/sern-handler/handler/compare/v3.0.1...v3.0.2) (2023-08-06)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* invalid id for cts, mts, cjs, mjs files, node paths ([#318](https://github.com/sern-handler/handler/issues/318)) ([a7f5ea2](https://github.com/sern-handler/handler/commit/a7f5ea269fb344e221d10dbdc26a1611ffc8138f))
|
||||
|
||||
## [3.0.1](https://github.com/sern-handler/handler/compare/v3.0.0...v3.0.1) (2023-08-05)
|
||||
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
{
|
||||
"name": "@sern/handler",
|
||||
"packageManager": "yarn@3.5.0",
|
||||
"version": "3.0.1",
|
||||
"version": "3.0.2",
|
||||
"description": "A complete, customizable, typesafe, & reactive framework for discord bots.",
|
||||
"main": "./dist/index.js",
|
||||
"module": "./dist/cjs/index.cjs",
|
||||
"module": "./dist/index.mjs",
|
||||
"types": "./dist/index.d.ts",
|
||||
"exports": {
|
||||
".": {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Result } from 'ts-results-es';
|
||||
import { type Observable, from, mergeMap, ObservableInput } from 'rxjs';
|
||||
import { readdir, stat } from 'fs/promises';
|
||||
import { basename, extname, join, resolve } from 'path';
|
||||
import { basename, extname, join, resolve, parse } from 'path';
|
||||
import assert from 'assert';
|
||||
import { createRequire } from 'node:module';
|
||||
import type { ImportPayload, Wrapper } from '../types/core';
|
||||
@@ -25,27 +25,21 @@ export type ModuleResult<T> = Promise<ImportPayload<T>>;
|
||||
export async function importModule<T>(absPath: string) {
|
||||
let module = await import(absPath).then(esm => esm.default);
|
||||
|
||||
assert(
|
||||
module,
|
||||
'Found no default export for command module at ' +
|
||||
absPath +
|
||||
'Forgot to ignore with "!"? (!filename.ts)?',
|
||||
);
|
||||
assert(module, `Found no export for module at ${absPath}. Forgot to ignore with "!"? (!${basename(absPath)})?`);
|
||||
if ('default' in module) {
|
||||
module = module.default;
|
||||
}
|
||||
return Result.wrap(() => module.getInstance()).unwrapOr(module) as T;
|
||||
return Result
|
||||
.wrap(() => module.getInstance())
|
||||
.unwrapOr(module) as T;
|
||||
}
|
||||
export async function defaultModuleLoader<T extends Module>(absPath: string): ModuleResult<T> {
|
||||
let module = await importModule<T>(absPath);
|
||||
assert.ok(
|
||||
module,
|
||||
"Found an undefined module. Forgot to ignore it with a '!' ie (!filename.ts)?",
|
||||
);
|
||||
assert(module, `Found an undefined module: ${absPath}`);
|
||||
return { module, absPath };
|
||||
}
|
||||
|
||||
export const fmtFileName = (n: string) => n.substring(0, n.length - 3);
|
||||
export const fmtFileName = (fileName: string) => parse(fileName).name;
|
||||
|
||||
/**
|
||||
* a directory string is converted into a stream of modules.
|
||||
|
||||
23
test/core/module-loading.test.ts
Normal file
23
test/core/module-loading.test.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { faker } from '@faker-js/faker'
|
||||
import * as Files from '../../src/core/module-loading'
|
||||
describe('module-loading', () => {
|
||||
it('should properly extract filename from file, nested once', () => {
|
||||
const extension = faker.system.fileExt()
|
||||
const name = faker.system.fileName({ extensionCount: 0 })
|
||||
const filename = Files.fmtFileName(name+'.'+extension);
|
||||
expect(filename).toBe(name)
|
||||
})
|
||||
|
||||
|
||||
// todo: handle commands with multiple extensions
|
||||
// it('should properly extract filename from file, nested multiple', () => {
|
||||
// const extension = faker.system.fileExt()
|
||||
// const extension2 = faker.system.fileExt()
|
||||
// const name = faker.system.fileName({ extensionCount: 0 })
|
||||
// const filename = Files.fmtFileName(name+'.'+extension+'.'+extension2);
|
||||
// console.log(filename, name)
|
||||
// expect(filename).toBe(name)
|
||||
//
|
||||
// })
|
||||
})
|
||||
Reference in New Issue
Block a user