Skip to content

Instantly share code, notes, and snippets.

View NoriSte's full-sized avatar

Stefano Magni NoriSte

View GitHub Profile
@NoriSte
NoriSte / README.md
Last active October 14, 2021 05:50
TS trap for corrupted *.d.ts files

I had to be creative with TypeScript to prevent a common problem in our codebase, where we can't validate our *.d.ts files through skipLibCheck: false and a type (Action) sometimes become any...

import type { Plugin } from 'vite'
import path from 'path'
const name = 'prevent-server-data-circular-imports'
const defaultOptions = { verbose: false }
// Detect if the module is in server-data
const serverDataFileRegexp = /(.*)?server-data\/src\//
// Extract the imported path

Cypress Protobuf example

I was asked to provide an example of a Cypress test using Protobuf.

@NoriSte
NoriSte / README.md
Last active May 28, 2021 05:50
Migrating a 150K LOC codebase to Vite and ESBuild
// services
const fetchConfig = () => Promise.resolve({ hereId: 'foo', hereCode: 'bar' })
const fetchOrder = () => Promise.resolve({ status: 'done', pods: [1, 2, 3] })
const fetchOrder2 = () => {
if (Math.random() > 0.5) {
return Promise.resolve({ status: 'done', pods: [1, 2, 3] })
} else {
return Promise.reject({ errorMessage: 'foo' })
}
}
@NoriSte
NoriSte / machine.js
Created April 30, 2021 14:53
Generated by XState Viz: https://xstate.js.org/viz
// services
const fetchConfig = () => Promise.resolve({ hereId: 'foo', hereCode: 'bar' })
const fetchOrder = () => Promise.resolve({ status: 'done', pods: [1, 2, 3] })
const fetchOrder2 = () => {
if (Math.random() > 0.5) {
return Promise.resolve({ status: 'done', pods: [1, 2, 3] })
} else {
return Promise.reject({ errorMessage: 'foo' })
}
}
@NoriSte
NoriSte / migrate-to-vite.sh
Created April 30, 2021 06:49
Webpack to Vite Codemods
# AUTOMATIC MIGRATION FROM WEBPACK TO VITE
# chmod +x migrate-to-vite.sh to make this file executable
# installing codemods
# https://docs.python-guide.org/starting/install3/osx/
# https://dev.to/malwarebo/how-to-set-python3-as-a-default-python-version-on-mac-4jjf
# https://pip.pypa.io/en/stable/installing/#installing-with-get-pip-py
# NO NEED; ALREADY ON MASTER - (manual action)
@NoriSte
NoriSte / machine.js
Last active April 30, 2021 14:27
Generated by XState Viz: https://xstate.js.org/viz
// services
const fetchConfig = () => Promise.resolve({ hereId: 'foo', hereCode: 'bar' })
const fetchOrder = () => Promise.resolve({ status: 'done', pods: [1, 2, 3] })
const fetchIntl = () => Promise.resolve({ messages: { foo: 'bar' } })
const fetchMachine = Machine(
{
id: 'tracking-app',
initial: 'loading',
context: {
@NoriSte
NoriSte / machine.js
Last active April 29, 2021 15:31
RM V2' tracking app
const setOnline = assign({
offline: (context, event) => (context.offline = false),
})
const setOffline = assign({
offline: (context, event) => (context.offline = true),
})
const setLastUpdate = assign({
lastUpdate: (context, event) => (context.lastUpdate = Date.now()),
})
const setStatusOk = assign({