Skip to content

Commit

Permalink
support esm and test in bun
Browse files Browse the repository at this point in the history
  • Loading branch information
ayonli committed Sep 18, 2023
1 parent d76c647 commit a68b3a3
Show file tree
Hide file tree
Showing 11 changed files with 635 additions and 330 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/bun.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Bun CI

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: oven-sh/setup-bun@v1
- run: bun install
- run: bun run test:bun
14 changes: 7 additions & 7 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@ name: Node.js CI

on:
push:
branches: [ master ]
branches: [ main ]
pull_request:
branches: [ master ]
branches: [ main ]

jobs:
build:

runs-on: ${{ matrix.os }}
runs-on: ubuntu-latest

strategy:
matrix:
os: [ubuntu-latest]
node-version: [8.x, 20.x]
node-version: [12.x, 20.x]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm i
- run: npm test
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.vscode/settings.json
.vscode/
node_modules/
index.js*
index.d.ts
cjs
*.tgz
3 changes: 1 addition & 2 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.*
node_modules/
package-locak.json
test.ts
index.ts
*.tgz
100 changes: 100 additions & 0 deletions esm/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions esm/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions esm/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "module"
}
7 changes: 5 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ export function applyMagic<T extends new (...args: any[]) => any>(ctor: T, ctx?:
export function applyMagic<T extends (...args: any[]) => any>(fn: T, proxyOnly: boolean): T;
export function applyMagic<T extends object>(obj: T): T;
export function applyMagic(target: any, ctx: boolean | object = false) {
if (typeof target == "function") {
if (typeof target === "function") {
if (ctx === true) {
return proxify(target);
}

const PseudoClass = function PseudoClass(this: any, ...args: any[]) {
if (typeof this == "undefined") { // function call
// Must use `new.target` instead of `this`, because in ES Module
// system, `this` will reference to the `globalThis` if not provided
// by `Function.call()`.
if (typeof new.target === "undefined") { // function call
let invoke = target[__invoke] || target["__invoke"];

if (invoke) { // use static __invoke
Expand Down
Loading

0 comments on commit a68b3a3

Please sign in to comment.