Skip to content

Commit

Permalink
Merge pull request #63 from axiomhq/use-rollup-to-build
Browse files Browse the repository at this point in the history
convert packages to esm
  • Loading branch information
dasfmi authored Sep 28, 2023
2 parents b2ad739 + 8e16b3f commit afded7f
Show file tree
Hide file tree
Showing 82 changed files with 1,961 additions and 2,751 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
node-version: ${{ matrix.node }}
cache: 'pnpm'
- run: pnpm install --frozen-lockfile
- run: pnpm build && pnpm build:esm
- run: pnpm build && pnpm build:cjs
- run: pnpm lint
- run: pnpm test

Expand All @@ -58,7 +58,7 @@ jobs:
node-version: ${{ matrix.node }}
cache: 'pnpm'
- run: pnpm install --frozen-lockfile
- run: pnpm build && pnpm build:esm
- run: pnpm build && pnpm build:cjs
- run: cd examples/winston && pnpm example

test-integration:
Expand All @@ -83,7 +83,7 @@ jobs:
node-version: ${{ matrix.node }}
cache: 'pnpm'
- run: pnpm install --frozen-lockfile
- run: pnpm build && pnpm build:esm
- run: pnpm build && pnpm build:cjs
- env:
AXIOM_TOKEN: ${{ secrets.TESTING_STAGING_TOKEN }}
AXIOM_URL: ${{ secrets.TESTING_STAGING_API_URL }}
Expand Down Expand Up @@ -133,7 +133,7 @@ jobs:
node-version: ${{ matrix.node }}
cache: 'pnpm'
- run: pnpm install --frozen-lockfile
- run: pnpm build && pnpm build:esm # cjs build needed to run jest tests
- run: pnpm build && pnpm build:cjs # cjs build needed to run tests
- env:
TESTING_TARGET_URL: ${{ needs.deploy-e2e-apps.outputs.preview-url }}
run: pnpm run e2e
3 changes: 1 addition & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ jobs:
registry-url: 'https://registry.npmjs.org'
cache: 'pnpm'
- run: pnpm install --frozen-lockfile
- run: pnpm build && pnpm build:esm
- run: ./scripts/resolveVersion.sh # replace the constant VERSION with correct value
- run: pnpm build && pnpm build:cjs
- run: pnpm publish --access public --filter "./packages/**"
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTOMATION_TOKEN }}
10 changes: 0 additions & 10 deletions e2e/nextjs-app/jest.config.ts

This file was deleted.

2 changes: 1 addition & 1 deletion e2e/nextjs-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"dev": "next dev",
"format": "eslint 'src/**/*.{js,ts}' --quiet --fix",
"lint": "eslint 'src/**/*.{js,ts}'",
"e2e": "jest test"
"e2e": "vitest run test/*"
},
"dependencies": {
"@axiomhq/js": "workspace:*",
Expand Down
30 changes: 20 additions & 10 deletions e2e/nextjs-app/src/app/api/edge/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,27 @@ export const runtime = 'edge';
export const dynamic = 'force-dynamic'; // disable prerendering

export async function GET() {
const axiom = new AxiomWithoutBatching();
const axiom = new AxiomWithoutBatching({
token: process.env.AXIOM_TOKEN || '',
orgId: process.env.AXIOM_ORG_ID,
url: process.env.AXIOM_URL,
});

const resp = await axiom.ingestRaw(
'axiom-js-e2e-test',
`[{"foo":"bar", "test": "ingest_on_edge"},{"bar":"baz", "test": "ingest_on_edge"}]`,
ContentType.JSON,
ContentEncoding.Identity,
);
if (resp.ingested !== 2) {
return NextResponse.json({ test: 'ingest_on_edge', error: 'ingest failed' }, { status: 500 });
try {
const resp = await axiom.ingestRaw(
'axiom-js-e2e-test',
`[{"foo":"bar", "test": "ingest_on_edge"},{"bar":"baz", "test": "ingest_on_edge"}]`,
ContentType.JSON,
ContentEncoding.Identity,
);
if (resp.ingested !== 2) {
return NextResponse.json({ test: 'ingest_on_edge', error: 'ingest failed' }, { status: 500 });
}

return NextResponse.json({ test: 'ingest_on_edge', ...resp });
} catch(err) {
return NextResponse.json({ test: 'ingest_on_edge', error: err.message }, { status: 500 });
}

return NextResponse.json({ test: 'ingest_on_edge', ...resp });

}
30 changes: 19 additions & 11 deletions e2e/nextjs-app/src/app/api/lambda/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,25 @@ import { NextResponse } from 'next/server';
export const dynamic = 'force-dynamic'; // disable prerendering

export async function GET() {
const axiom = new AxiomWithoutBatching();
const axiom = new AxiomWithoutBatching({
token: process.env.AXIOM_TOKEN || '',
orgId: process.env.AXIOM_ORG_ID,
url: process.env.AXIOM_URL,
});

const resp = await axiom.ingestRaw(
'axiom-js-e2e-test',
`[{"foo":"bar", "test": "ingest_on_lambda"},{"bar":"baz", "test": "ingest_on_lambda"}]`,
ContentType.JSON,
ContentEncoding.Identity,
);
if (resp.ingested !== 2) {
return NextResponse.json({ test: 'ingest_on_lambda', error: 'ingest failed' }, { status: 500 });
}
try {
const resp = await axiom.ingestRaw(
'axiom-js-e2e-test',
`[{"foo":"bar", "test": "ingest_on_lambda"},{"bar":"baz", "test": "ingest_on_lambda"}]`,
ContentType.JSON,
ContentEncoding.Identity,
);
if (resp.ingested !== 2) {
return NextResponse.json({ test: 'ingest_on_lambda', error: 'ingest failed' }, { status: 500 });
}

return NextResponse.json({ test: 'ingest_on_lambda', ...resp });
return NextResponse.json({ test: 'ingest_on_lambda', ...resp });
} catch (err) {
return NextResponse.json({ test: 'ingest_on_lambda', error: err.message }, { status: 500 });
}
}
15 changes: 15 additions & 0 deletions e2e/nextjs-app/src/app/page.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
'use client';
import { Axiom } from '@axiomhq/js'
import { useEffect } from 'react';

export default function Home() {
const axiom = new Axiom({ token: '' })

axiom.ingest({
name: 'test',
})

useEffect(() => {
return async () => {
await axiom.flush();
}
})

return (
<div>Test</div>
)
Expand Down
6 changes: 3 additions & 3 deletions e2e/nextjs-app/test/ingest.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Axiom } from '@axiomhq/js';
import { describe, it, expect, beforeAll, afterAll, jest } from '@jest/globals';
import { describe, it, expect, beforeAll, afterAll, vi } from 'vitest';

jest.useRealTimers()

describe('Ingestion & query on different runtime', () => {
const axiom = new Axiom();
vi.useRealTimers()

const axiom = new Axiom();
const datasetName = 'axiom-js-e2e-test';

beforeAll(async () => {
Expand Down
2 changes: 1 addition & 1 deletion examples/js/src/ingest-events.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AxiomWithoutBatching } from '@axiomhq/js';

const axiom = new AxiomWithoutBatching();
const axiom = new AxiomWithoutBatching({ token: process.env.AXIOM_TOKEN || ''});

async function ingest() {
const events = [
Expand Down
2 changes: 1 addition & 1 deletion examples/js/src/ingest-file.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs';
import { Axiom, ContentType, ContentEncoding } from '@axiomhq/js';

const axiom = new Axiom();
const axiom = new Axiom({ token: process.env.AXIOM_TOKEN || ''});

async function ingestFile() {
const buff = fs.readFileSync('logs.json');
Expand Down
2 changes: 1 addition & 1 deletion examples/js/src/ingest-string.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Axiom, ContentType, ContentEncoding } from '@axiomhq/js';

const axiom = new Axiom();
const axiom = new Axiom({ token: process.env.AXIOM_TOKEN || ''});

async function ingestString() {
const data = JSON.stringify([{ foo: 'bar' }, { foo: 'bar' }, { bar: 'baz' }]);
Expand Down
2 changes: 1 addition & 1 deletion examples/js/src/list-datasets.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Axiom } from '@axiomhq/js';

const axiom = new Axiom();
const axiom = new Axiom({ token: process.env.AXIOM_TOKEN || ''});

async function listDatasets() {
const res = await axiom.datasets.list();
Expand Down
2 changes: 1 addition & 1 deletion examples/js/src/query-legacy.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// The purpose of this example is to show how to query a dataset.
import { Axiom } from '@axiomhq/js';

const axiom = new Axiom();
const axiom = new Axiom({ token: process.env.AXIOM_TOKEN || ''});

async function query() {
const endTime = new Date(Date.now()).toISOString();
Expand Down
2 changes: 1 addition & 1 deletion examples/js/src/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Processing Language (APL).
import { Axiom } from '@axiomhq/js';

const axiom = new Axiom();
const axiom = new Axiom({ token: process.env.AXIOM_TOKEN || ''});

async function query() {
const aplQuery = "['my-dataset']";
Expand Down
15 changes: 15 additions & 0 deletions examples/node/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
env: {
browser: true,
commonjs: true,
es2021: true,
},
extends: 'airbnb-base',
overrides: [
],
parserOptions: {
ecmaVersion: 'latest',
},
rules: {
},
};
16 changes: 16 additions & 0 deletions examples/node/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "examples-node",
"main": "main.cjs",
"scripts": {
"build": "rollup src/main.cjs --dir dist",
"dev": "node src/main.cjs",
"lint": "eslint src/main.cjs"
},
"dependencies": {
"@axiomhq/js": "workspace:*"
},
"devDependencies": {
"eslint-config-airbnb-base": "^15.0.0",
"eslint-plugin-import": "^2.25.2"
}
}
9 changes: 9 additions & 0 deletions examples/node/src/main.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const { Axiom } = require('@axiomhq/js');

const main = async () => {
const axiom = new Axiom({});

await axiom.ingest(process.env.AXIOM_DATASET, [{ foo: 'bar' }]);
};

main();
24 changes: 24 additions & 0 deletions examples/vue-app/.gitignore
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?
18 changes: 18 additions & 0 deletions examples/vue-app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Vue 3 + TypeScript + Vite

This template should help get you started developing with Vue 3 and TypeScript in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.

## Recommended IDE Setup

- [VS Code](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur) + [TypeScript Vue Plugin (Volar)](https://marketplace.visualstudio.com/items?itemName=Vue.vscode-typescript-vue-plugin).

## Type Support For `.vue` Imports in TS

TypeScript cannot handle type information for `.vue` imports by default, so we replace the `tsc` CLI with `vue-tsc` for type checking. In editors, we need [TypeScript Vue Plugin (Volar)](https://marketplace.visualstudio.com/items?itemName=Vue.vscode-typescript-vue-plugin) to make the TypeScript language service aware of `.vue` types.

If the standalone TypeScript plugin doesn't feel fast enough to you, Volar has also implemented a [Take Over Mode](https://github.com/johnsoncodehk/volar/discussions/471#discussioncomment-1361669) that is more performant. You can enable it by the following steps:

1. Disable the built-in TypeScript Extension
1. Run `Extensions: Show Built-in Extensions` from VSCode's command palette
2. Find `TypeScript and JavaScript Language Features`, right click and select `Disable (Workspace)`
2. Reload the VSCode window by running `Developer: Reload Window` from the command palette.
13 changes: 13 additions & 0 deletions examples/vue-app/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!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 + Vue + TS</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
21 changes: 21 additions & 0 deletions examples/vue-app/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "vue-app",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vue-tsc && vite build",
"preview": "vite preview"
},
"dependencies": {
"vue": "^3.3.4",
"@axiomhq/js": "workspace:*"
},
"devDependencies": {
"@vitejs/plugin-vue": "^4.2.3",
"typescript": "^5.0.2",
"vite": "^4.4.5",
"vue-tsc": "^1.8.5"
}
}
1 change: 1 addition & 0 deletions examples/vue-app/public/vite.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 39 additions & 0 deletions examples/vue-app/src/App.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<script setup lang="ts">
import { Axiom } from '@axiomhq/js'
import HelloWorld from './components/HelloWorld.vue'
const axiom = new Axiom({ token: import.meta.env.VITE_AXIOM_TOKEN})
axiom.ingest('dataset', {
message: 'Hello from Vite + Vue!',
level: 'info',
tags: ['vue', 'vite'],
})
</script>

<template>
<div>
<a href="https://vitejs.dev" target="_blank">
<img src="/vite.svg" class="logo" alt="Vite logo" />
</a>
<a href="https://vuejs.org/" target="_blank">
<img src="./assets/vue.svg" class="logo vue" alt="Vue logo" />
</a>
</div>
<HelloWorld msg="Vite + Vue" />
</template>

<style scoped>
.logo {
height: 6em;
padding: 1.5em;
will-change: filter;
transition: filter 300ms;
}
.logo:hover {
filter: drop-shadow(0 0 2em #646cffaa);
}
.logo.vue:hover {
filter: drop-shadow(0 0 2em #42b883aa);
}
</style>
1 change: 1 addition & 0 deletions examples/vue-app/src/assets/vue.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit afded7f

Please sign in to comment.