Compare commits

..

7 Commits

Author SHA1 Message Date
Jacob Nguyen
395f75bcda fix: tsresults 2023-08-21 21:39:30 -05:00
github-actions[bot]
215aca2f46 chore(main): release 3.0.2 (#319)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2023-08-06 10:45:17 -05:00
Jacob Nguyen
a7f5ea269f fix: invalid id for cts, mts, cjs, mjs files, node paths (#318)
* better error messages

* fix: invalid id for cts, mts, cjs, mjs files
2023-08-06 10:43:34 -05:00
Jacob Nguyen
52d6368440 Delete codeql-analysis.yml 2023-08-06 00:36:50 -05:00
Jacob Nguyen
1e723a4154 Update npm-publish.yml 2023-08-06 00:34:43 -05:00
Jacob Nguyen
5fe13f43d2 better npm-publish.yml 2023-08-06 00:33:40 -05:00
Jacob Nguyen
ab9d39306a Create test.yml (#317)
* Create test.yml

* Update test.yml

* Update test.yml
2023-08-06 00:29:43 -05:00
9 changed files with 79 additions and 57 deletions

View File

@@ -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

View File

@@ -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
View 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
View File

@@ -91,3 +91,7 @@ dist
# Yarn files
.yarn/install-state.gz
.yarn/build-state.yml
.yalc
yalc.lock

View File

@@ -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)

View File

@@ -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": {
".": {
@@ -40,7 +40,7 @@
"dependencies": {
"iti": "^0.6.0",
"rxjs": "^7.8.0",
"ts-results-es": "latest"
"ts-results-es": "^3.6.1"
},
"devDependencies": {
"@faker-js/faker": "^8.0.1",

View File

@@ -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.

View 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)
//
// })
})

View File

@@ -619,7 +619,7 @@ __metadata:
iti: ^0.6.0
prettier: 2.8.8
rxjs: ^7.8.0
ts-results-es: latest
ts-results-es: ^3.6.1
tsup: ^6.7.0
typescript: 5.0.2
vitest: latest
@@ -3844,7 +3844,7 @@ __metadata:
languageName: node
linkType: hard
"ts-results-es@npm:latest":
"ts-results-es@npm:^3.6.1":
version: 3.6.1
resolution: "ts-results-es@npm:3.6.1"
checksum: af0d93ee4d3bd9e99a5fd4ac4b0ad090aef0a61e1f38ee596cfebe8d47090b34a2557d3778e00b4aae7c74962133805275ffffe56716e4d747fa559a926d9ced