Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix the workflow os matrix #265

Merged
merged 3 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .eslintignore

This file was deleted.

20 changes: 0 additions & 20 deletions .eslintrc

This file was deleted.

1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
68 changes: 34 additions & 34 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
name: Release and Publish

on:
push:
branches:
- main
- alpha
- beta
- next
push:
branches:
- main
- alpha
- beta
- next

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20.x

- name: npm install
run: npm install

- name: npm lint
run: npm run lint

- name: npm types
run: npm run types

- name: npm test
run: npm test

- name: npx semantic-release
run: npx semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20

- name: npm install
run: npm install

- name: npm lint
run: npm run lint

- name: npm types
run: npm run types

- name: npm test
run: npm test

- name: npx semantic-release
run: npx semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
17 changes: 9 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
name: Run Lint and Tests

on:
pull_request:
branches:
- main
- alpha
- beta
- next
push:
branches-ignore:
- main
- alpha
- beta
- next

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [lts/-1, lts/*]
os: [ubuntu-latest, macOS-latest, windows-latest]
node-version: [18, 20]
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v4
Expand Down
5 changes: 0 additions & 5 deletions .prettierrc

This file was deleted.

13 changes: 13 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"singleQuote": true,
"trailingComma": "all",
"tabWidth": 4,
"overrides": [
{
"files": ["*.json", "*.yml"],
"options": {
"tabWidth": 2
}
}
]
}
22 changes: 22 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import prettierConfig from 'eslint-config-prettier';
import prettierPlugin from 'eslint-plugin-prettier/recommended';
import globals from 'globals';
import js from '@eslint/js';

export default [
js.configs.recommended,
prettierConfig,
prettierPlugin,
{
languageOptions: {
globals: {
...globals.node,
...globals.browser,
global: true,
},
},
},
{
ignores: ['coverage/*', 'dist/*'],
},
];
9 changes: 3 additions & 6 deletions example/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,18 @@ const layout = new Layout({
pathname: '/',
logger: console,
name: 'layout',

});

const podlet = layout.client.register({
name: 'myPodlet',
uri: 'http://localhost:7100/manifest.json'
uri: 'http://localhost:7100/manifest.json',
});

app.register(FastifyLayout, layout);

app.get('/', async (request, reply) => {
const incoming = reply.app.podium;
const result = await Promise.all([
podlet.fetch(incoming),
]);
const result = await Promise.all([podlet.fetch(incoming)]);
reply.podiumSend(result[0].content);
});

Expand All @@ -37,5 +34,5 @@ const start = async () => {
app.log.error(err);
process.exit(1);
}
}
};
start();
12 changes: 12 additions & 0 deletions fixup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import fs from 'node:fs';
import path from 'node:path';

let podium = path.join(process.cwd(), 'types', 'podium.d.ts');
let module = path.join(process.cwd(), 'types', 'layout-plugin.d.ts');

fs.writeFileSync(
module,
`${fs.readFileSync(podium, 'utf-8')}
${fs.readFileSync(module, 'utf-8')}`,
'utf-8',
);
2 changes: 0 additions & 2 deletions fixup.sh

This file was deleted.

139 changes: 72 additions & 67 deletions lib/layout-plugin.js
Original file line number Diff line number Diff line change
@@ -1,81 +1,86 @@
/* eslint-disable no-param-reassign */
/* eslint-disable consistent-return */

import { HttpIncoming, pathnameBuilder } from '@podium/utils';
import fp from 'fastify-plugin';

export default fp(
(fastify, options, done) => {
const layout = /** @type {import('@podium/layout').default} */ (options);

// Decorate reply with .app.podium we can write to throughout the request
fastify.decorateReply('app', null);
fastify.addHook('onRequest', async (request, reply) => {
// namespace
// @ts-ignore We type this for our consumers with fixup.sh
reply.app = reply.app || {};
// used to pass additional values to HttpIncoming
// @ts-ignore We type this for our consumers with fixup.sh
reply.app.params = reply.app.params || {};
// used to hold the HttpIncoming object
// @ts-ignore We type this for our consumers with fixup.sh
reply.app.podium = new HttpIncoming(
request.raw,
reply.raw,
// @ts-ignore We type this for our consumers with fixup.sh
reply.app.params,
const layout = /** @type {import('@podium/layout').default} */ (
options
);
// @ts-ignore We type this for our consumers with fixup.sh
reply.app.podium = await layout.process(reply.app.podium, {
proxy: false,
});
});

// Decorate response with .podiumSend() method
fastify.decorateReply('podiumSend',
/**
* @see https://podium-lib.io/docs/api/layout#respodiumsendfragment
* @param {unknown} payload
* @param {unknown[]} args
*/
function podiumSend(payload, ...args) {
this.type('text/html; charset=utf-8'); // "this" here is the fastify 'Reply' object
// @ts-ignore We type this for our consumers with fixup.sh
this.send(layout.render(this.app.podium, payload, ...args));
});
// Decorate reply with .app.podium we can write to throughout the request
fastify.decorateReply('app', null);
fastify.addHook('onRequest', async (request, reply) => {
// namespace
// @ts-ignore We type this for our consumers with fixup.sh
reply.app = reply.app || {};
// used to pass additional values to HttpIncoming
// @ts-ignore We type this for our consumers with fixup.sh
reply.app.params = reply.app.params || {};
// used to hold the HttpIncoming object
// @ts-ignore We type this for our consumers with fixup.sh
reply.app.podium = new HttpIncoming(
request.raw,
reply.raw,
// @ts-ignore We type this for our consumers with fixup.sh
reply.app.params,
);
// @ts-ignore We type this for our consumers with fixup.sh
reply.app.podium = await layout.process(reply.app.podium, {
proxy: false,
});
});

// Mount proxy route as an instance so its executed only on
// the registered path. Iow: the proxy check is not run on
// any other routes
fastify.register((instance, opts, next) => {
const pathname = pathnameBuilder(
layout.httpProxy.pathname,
layout.httpProxy.prefix,
'/*',
// Decorate response with .podiumSend() method
fastify.decorateReply(
'podiumSend',
/**
* @see https://podium-lib.io/docs/api/layout#respodiumsendfragment
* @param {unknown} payload
* @param {unknown[]} args
*/
function podiumSend(payload, ...args) {
this.type('text/html; charset=utf-8'); // "this" here is the fastify 'Reply' object
// @ts-ignore We type this for our consumers with fixup.sh
this.send(layout.render(this.app.podium, payload, ...args));
},
);

// Allow all content types for proxy requests
// https://github.com/fastify/fastify/blob/master/docs/ContentTypeParser.md#catch-all
instance.addContentTypeParser('*', (req, payload, cb) => {
// @ts-ignore
cb();
});
// Mount proxy route as an instance so its executed only on
// the registered path. Iow: the proxy check is not run on
// any other routes
fastify.register((instance, opts, next) => {
const pathname = pathnameBuilder(
layout.httpProxy.pathname,
layout.httpProxy.prefix,
'/*',
);

instance.addHook('preHandler', async (req, reply) => {
// @ts-ignore We type this for our consumers with fixup.sh
const incoming = await layout.httpProxy.process(reply.app.podium);
if (incoming.proxy) return;
return incoming;
});
// Allow all content types for proxy requests
// https://github.com/fastify/fastify/blob/master/docs/ContentTypeParser.md#catch-all
instance.addContentTypeParser('*', (req, payload, cb) => {
// @ts-ignore
cb();
});

instance.all(pathname, (req, reply) => {
reply.code(404).send('Not found');
});
instance.addHook('preHandler', async (req, reply) => {
const incoming = await layout.httpProxy.process(
// @ts-ignore We type this for our consumers with fixup.sh
reply.app.podium,
);
if (incoming.proxy) return;
return incoming;
});

instance.all(pathname, (req, reply) => {
reply.code(404).send('Not found');
});

next();
});
next();
});

done();
}, {
name: 'podium-layout',
});
done();
},
{
name: 'podium-layout',
},
);
Loading