-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1963 from h3poteto/try/dual-package
ESM and CJS dual package support
- Loading branch information
Showing
26 changed files
with
649 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
name: Example | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
|
||
tags: | ||
|
||
pull_request: | ||
|
||
jobs: | ||
typescript: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
node-version: [16.x, 18.x, 19.x] | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- name: Install dependencies | ||
run: | | ||
yarn install | ||
- name: Build | ||
run: | | ||
yarn workspace megalodon run build | ||
- name: Typescript example | ||
env: | ||
MASTODON_URL: https://fedibird.com | ||
PLEROMA_URL: https://pleroma.io | ||
FIREFISH_URL: https://cybre.club | ||
FRIENDICA_URL: https://squeet.me | ||
run: | | ||
yarn workspace example run build | ||
node example/typescript/dist/mastodon/instance.js | ||
node example/typescript/dist/pleroma/instance.js | ||
node example/typescript/dist/firefish/instance.js | ||
node example/typescript/dist/friendica/instance.js | ||
webpack: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
node-version: [16.x, 18.x, 19.x] | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- name: Install dependencies | ||
run: | | ||
yarn install | ||
- name: Build | ||
run: | | ||
yarn workspace megalodon run build | ||
- name: Webpack example | ||
run: | | ||
yarn workspace webpack run build | ||
vite: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
node-version: [16.x, 18.x, 19.x] | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- name: Install dependencies | ||
run: | | ||
yarn install | ||
- name: Build | ||
run: | | ||
yarn workspace megalodon run build | ||
- name: Vite example | ||
run: | | ||
yarn workspace vite build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
node_modules | ||
lib | ||
example/typescript/dist | ||
example/javascript/dist | ||
example/browser/dist | ||
docs/ | ||
example/webpack/dist | ||
example/vite/dist | ||
docs/ | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
pnpm-debug.log* | ||
lerna-debug.log* | ||
|
||
node_modules | ||
dist | ||
dist-ssr | ||
*.local | ||
|
||
# Editor directories and files | ||
.vscode/* | ||
!.vscode/extensions.json | ||
.idea | ||
.DS_Store | ||
*.suo | ||
*.ntvs* | ||
*.njsproj | ||
*.sln | ||
*.sw? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<link rel="icon" type="image/svg+xml" href="/vite.svg" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Vite + TS</title> | ||
</head> | ||
<body> | ||
<div id="app"></div> | ||
|
||
<script type="module" src="/src/main.ts"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"name": "vite", | ||
"private": true, | ||
"version": "0.0.0", | ||
"type": "module", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "tsc && vite build", | ||
"preview": "vite preview" | ||
}, | ||
"dependencies": { | ||
"megalodon": "*" | ||
}, | ||
"devDependencies": { | ||
"typescript": "^5.0.2", | ||
"vite": "^4.4.5", | ||
"node-stdlib-browser": "^1.2.0", | ||
"vite-plugin-node-stdlib-browser": "^0.2.1", | ||
"process": "^0.11.10" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import generator, { Entity } from 'megalodon' | ||
|
||
const BASE_URL: string = import.meta.env.VITE_MASTODON_URL | ||
const ACCESS_TOKEN: string = import.meta.env.VITE_MASTODON_ACCESS_TOKEN | ||
console.log(BASE_URL) | ||
console.log('start') | ||
|
||
const client = generator('mastodon', BASE_URL, ACCESS_TOKEN) | ||
|
||
const stream = client.publicSocket() | ||
stream.on('connect', () => { | ||
console.log('connect') | ||
}) | ||
|
||
stream.on('pong', () => { | ||
console.log('pong') | ||
}) | ||
|
||
stream.on('update', (status: Entity.Status) => { | ||
console.log(status) | ||
}) | ||
|
||
stream.on('notification', (notification: Entity.Notification) => { | ||
console.log(notification) | ||
}) | ||
|
||
stream.on('delete', (id: number) => { | ||
console.log(id) | ||
}) | ||
|
||
stream.on('error', (err: Error) => { | ||
console.error(err) | ||
}) | ||
|
||
stream.on('status_update', (status: Entity.Status) => { | ||
console.log('updated: ', status.url) | ||
}) | ||
|
||
stream.on('heartbeat', () => { | ||
console.log('thump.') | ||
}) | ||
|
||
stream.on('close', () => { | ||
console.log('close') | ||
}) | ||
|
||
stream.on('parser-error', (err: Error) => { | ||
console.error(err) | ||
}) | ||
// | ||
// setTimeout(() => { | ||
// stream.removeAllListeners() | ||
// stream.stop() | ||
// console.log('closed') | ||
// }, 10000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/// <reference types="vite/client" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ES2020", | ||
"useDefineForClassFields": true, | ||
"module": "ESNext", | ||
"lib": ["ES2020", "DOM", "DOM.Iterable"], | ||
"skipLibCheck": true, | ||
|
||
/* Bundler mode */ | ||
"moduleResolution": "bundler", | ||
"allowImportingTsExtensions": true, | ||
"resolveJsonModule": true, | ||
"isolatedModules": true, | ||
"noEmit": true, | ||
|
||
/* Linting */ | ||
"strict": true, | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": true, | ||
"noFallthroughCasesInSwitch": true | ||
}, | ||
"include": ["src"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { defineConfig } from 'vite' | ||
import nodePolyfills from 'vite-plugin-node-stdlib-browser' | ||
|
||
// https://vitejs.dev/config/ | ||
export default defineConfig({ | ||
resolve: { | ||
alias: { | ||
process: 'process/browser' | ||
} | ||
}, | ||
define: { | ||
'process.browser': true, | ||
'process.env.NODE_DEBUG': false | ||
}, | ||
plugins: [ | ||
nodePolyfills({ | ||
include: ['buffer'] | ||
}) | ||
] | ||
}) |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"name": "browser", | ||
"name": "webpack", | ||
"version": "4.0.0", | ||
"private": true, | ||
"scripts": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
example/browser/tsconfig.json → example/webpack/tsconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.