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

fix bookmarklet, replace zod with valibot #319

Merged
merged 14 commits into from
Dec 31, 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
1 change: 0 additions & 1 deletion .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ jobs:

- uses: ncipollo/release-action@v1
with:
# artifacts: "dist/wyzant-looker.zip,dist/changelog.md,CHANGELOG.md"
allowUpdates: true
artifacts: "build/jiffyReader*"
token: ${{ secrets.GITHUB_TOKEN }}
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines.

## [1.5.0](https://github.com/ansh/jiffyreader.com/compare/v1.4.0...v1.5.0) (2024-12-31)


### Features

* ability to enable and disable elements on a page like buttons, links, ... etc ([30b889a](https://github.com/ansh/jiffyreader.com/commit/30b889a27906786c2220b4ec3d389d5790e697e2))

## [1.4.0](https://github.com/ansh/jiffyreader.com/compare/v1.3.5...v1.4.0) (2024-12-30)


Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"name": "jiffy-reader",
"displayName": "Jiffy reader",
"version": "1.4.0",
"version": "1.5.0",
"description": "jiffy reader",
"packageManager": "yarn@1.22.19",
"scripts": {
"dev": "PLASMO_PUBLIC_VERSION=\"$(npm pkg get version | tr -d '\"')\" PLASMO_PUBLIC_TARGET=${PLASMO_PUBLIC_TARGET:-chrome} PLASMO_PUBLIC_NAME=${PLASMO_PUBLIC_NAME:-\"jiffy-reader-chrome\"} PLASMO_PUBLIC_TAG=${PLASMO_PUBLIC_TAG:-dev} PLASMO_TAG=$PLASMO_PUBLIC_TAG PLASMO_PUBLIC_VERSION_NAME=$PLASMO_PUBLIC_VERSION-$PLASMO_PUBLIC_TARGET-$PLASMO_PUBLIC_TAG PLASMO_PUBLIC_DEBUG=${PLASMO_PUBLIC_DEBUG:-TRUE} PLASMO_PUBLIC_SHORTCUT=${PLASMO_PUBLIC_SHORTCUT:-\"Alt+B\"} plasmo dev --target=${PLASMO_PUBLIC_MANIFEST_VERSION:-chrome-mv3}",
"dev:bookmarklet": "nodemon -x 'pnpm gh:build:bookmarklet' -w src/Bookmarklet",
"buildx": "PLASMO_PUBLIC_VERSION=\"$(npm pkg get version | tr -d '\"')\" PLASMO_PUBLIC_TARGET=${PLASMO_PUBLIC_TARGET:-chrome} PLASMO_PUBLIC_NAME=${PLASMO_PUBLIC_NAME:-\"Jiffy Reader\"} PLASMO_PUBLIC_TAG=${PLASMO_PUBLIC_TAG:-prod} PLASMO_TAG=$PLASMO_PUBLIC_TAG PLASMO_PUBLIC_VERSION_NAME=$PLASMO_PUBLIC_VERSION-$PLASMO_PUBLIC_TARGET-$PLASMO_PUBLIC_TAG PLASMO_PUBLIC_DEBUG=${PLASMO_PUBLIC_DEBUG:-FALSE} PLASMO_PUBLIC_SHORTCUT=${PLASMO_PUBLIC_SHORTCUT:-\"Alt+B\"} plasmo build --target=${PLASMO_PUBLIC_MANIFEST_VERSION:-chrome-mv3}",
"build": "npm run build:opera && npm run build:chrome & npm run build:firefox & npm run build:safari",
"dev:chrome": "npm run dev",
Expand All @@ -19,7 +20,7 @@
"gh:build:opera": "PLASMO_PUBLIC_TARGET=opera PLASMO_PUBLIC_SHORTCUT=\"Alt+B\" PLASMO_PUBLIC_MANIFEST_VERSION=opera-mv3 npm run buildx && npm run bundle:opera",
"gh:build:firefox": "PLASMO_PUBLIC_TARGET=firefox PLASMO_PUBLIC_SHORTCUT=\"Alt+W\" PLASMO_PUBLIC_MANIFEST_VERSION=firefox-mv2 npm run buildx && npm run bundle:firefox",
"gh:build:safari": "PLASMO_PUBLIC_TARGET=safari PLASMO_PUBLIC_SHORTCUT=\"Alt+W\" PLASMO_PUBLIC_MANIFEST_VERSION=safari-mv2 npm run buildx && npm run bundle:safari",
"gh:build": "echo 'PLASMO_PUBLIC_TAG=prod NODE_ENV=production npm run gh:build:' | xargs -I{} bash -c '{}opera && {}chrome & {}firefox & {}safari && wait'",
"gh:build": "echo 'PLASMO_PUBLIC_TAG=prod NODE_ENV=production npm run gh:build:' | xargs -I{} bash -c '{}opera && {}chrome & {}firefox & {}safari && wait && pnpm gh:build:bookmarklet'",
"gh:build:development": "echo 'PLASMO_PUBLIC_TAG=dev NODE_ENV=development PLASMO_PUBLIC_NAME=Jiffy-Reader-Dev npm run gh:build:' | xargs -I{} bash -c '{}opera && {}chrome & {}firefox & {}safari && wait'",
"gh:build:bookmarklet": "PLASMO_PUBLIC_VERSION=\"$(npm pkg get version | tr -d '\"')\" node src/Bookmarklet/esbuild.mjs",
"bundle": "npm run bundle:chrome & npm run bundle:firefix & npm run bundle:safari",
Expand Down Expand Up @@ -49,8 +50,8 @@
"postcss": "^8.4.49",
"react": "18.2.0",
"react-dom": "18.2.0",
"webpack": "^4.47.0",
"zod": "^3.24.1"
"valibot": "1.0.0-beta.9",
"webpack": "^4.47.0"
},
"devDependencies": {
"@parcel/transformer-sass": "2.6.2",
Expand Down
22 changes: 14 additions & 8 deletions pnpm-lock.yaml

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

15 changes: 13 additions & 2 deletions src/Bookmarklet/esbuild.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,16 @@ const /** @type {import('esbuild').BuildOptions} */ defaultConfigs = {
minify: true,
write: false,
plugins: [sassPlugin({ type: 'css-text' })],
define: { 'process.env.PLASMO_PUBLIC_DEBUG': '"false"' },
define: {
'process.env.PLASMO_PUBLIC_SHORTCUT': `'${process.env.PLASMO_PUBLIC_SHORTCUT}'`,
'process.env.PLASMO_PUBLIC_VERSION': `'${process.env.PLASMO_PUBLIC_VERSION}'`,
'process.env.PLASMO_PUBLIC_VERSION_NAME': `'${process.env.PLASMO_PUBLIC_VERSION_NAME}'`,
'process.env.PLASMO_PUBLIC_TARGET': `'${process.env.PLASMO_PUBLIC_TARGET}'`,
'process.env.NODE_ENV': `'${process.env.NODE_ENV}'`,
'process.env.PLASMO_PUBLIC_DEBUG': `'${process.env.PLASMO_PUBLIC_DEBUG ?? 'FALSE'}'`,
'process.env.PLASMO_PUBLIC_ENABLE_TRACKING': `'${process.env.PLASMO_PUBLIC_ENABLE_TRACKING ?? 'FALSE'}'`,
'process.env.PLASMO_PUBLIC_HOME_URL': `'${process.env.PLASMO_PUBLIC_HOME_URL}'`,
},
tsconfig: './tsconfig.json',
};

Expand All @@ -23,7 +32,7 @@ build({
})
.then(({ outputFiles: [res] }) => {
const outputScript = res.text.replace(/\n/g, '');
const output = [
const buttons = [
...[
['JiffyReader Toggle', 'fireReadingToggle'],
['FixationStrength Toggle', 'fireFixationStrengthTransition'],
Expand All @@ -35,6 +44,8 @@ build({
`<p>Drag any of the links above onto your bookmark bar to save it as a bookmarklet which works on any site just like the full extension <br/>Version: ${process.env.PLASMO_PUBLIC_VERSION}</p>`,
].join(' ');

const output = `<div style='display: block grid; grid-template-columns: repeat(5,1fr);grid-template-rows: repeat(2,40px);'>${buttons}<div></div>`;

fs.writeFileSync(outputFile, output);
})
.catch((error) => {
Expand Down
8 changes: 0 additions & 8 deletions src/services/Logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@

import { envService } from './envService';

/**
* @description stateMachine of debug to cantDebug states
*/
const debugStates = new Map([
['true', false],
['false', true],
]);

const cantDebug = (shouldDebug: boolean = false) => !shouldDebug;

const nullCallback = () => null;
Expand Down
67 changes: 24 additions & 43 deletions src/services/envService.ts
Original file line number Diff line number Diff line change
@@ -1,70 +1,51 @@
import { z } from 'zod';

const booleanMap = new Map<'true' | 'false' | undefined, boolean>([
['true', true],
['false', false],
[undefined, false],
]);
import { boolean, object, optional, parse, picklist, pipe, string, transform, ValiError, type InferOutput } from 'valibot';

const env = {
PLASMO_PUBLIC_SHORTCUT: { value: process.env.PLASMO_PUBLIC_SHORTCUT, validator: z.string() },
PLASMO_PUBLIC_VERSION: { value: process.env.PLASMO_PUBLIC_VERSION, validator: z.string().optional() },
PLASMO_PUBLIC_VERSION_NAME: { value: process.env.PLASMO_PUBLIC_VERSION_NAME, validator: z.string().optional() },
PLASMO_PUBLIC_SHORTCUT: { value: process.env.PLASMO_PUBLIC_SHORTCUT, validator: string() },
PLASMO_PUBLIC_VERSION: { value: process.env.PLASMO_PUBLIC_VERSION, validator: string() },
PLASMO_PUBLIC_VERSION_NAME: { value: process.env.PLASMO_PUBLIC_VERSION_NAME, validator: string() },
PLASMO_PUBLIC_TARGET: {
value: process.env.PLASMO_PUBLIC_TARGET,
validator: z
.string()
.default('')
.transform((x) => x as typeof process.env.PLASMO_PUBLIC_TARGET),
validator: string(),
},
NODE_ENV: {
value: process.env.NODE_ENV,
validator: z
.string()
.optional()
.transform((x) => x as typeof process.env.NODE_ENV),
validator: pipe(
string(),
transform((input) => input as typeof process.env.NODE_ENV),
),
},
PLASMO_PUBLIC_DEBUG: {
value: process.env.PLASMO_PUBLIC_DEBUG,
validator: z
.boolean()
.or(
z
.enum(['TRUE', 'FALSE'])
// .optional()
// .default('true')
.transform((x) => booleanMap.get(x as keyof typeof booleanMap.keys)),
)
.default(false),
validator: pipe(
optional(picklist(['TRUE', 'FALSE'] as const), 'FALSE'),
transform((input) => ({ TRUE: true, FALSE: false, '': false })[input]),
boolean(),
),
},
PLASMO_PUBLIC_ENABLE_TRACKING: {
value: process.env.PLASMO_PUBLIC_ENABLE_TRACKING,
validator: z
.boolean()
.or(
z
.enum(['true', 'false'])
.optional()
.default('false')
.transform((x) => booleanMap.get(x as keyof typeof booleanMap.keys)),
)
.default(false),
validator: pipe(
optional(picklist(['TRUE', 'FALSE'] as const), 'FALSE'),
transform((input) => ({ TRUE: true, FALSE: false })[input] ?? false),
boolean(),
),
},
PLASMO_PUBLIC_HOME_URL: { value: process.env.PLASMO_PUBLIC_HOME_URL, validator: z.string().optional() },
PLASMO_PUBLIC_HOME_URL: { value: process.env.PLASMO_PUBLIC_HOME_URL, validator: optional(string(), '') },
};

type Env = typeof env;

console.log({ env });

let envSchema = z.object(Object.fromEntries(Object.entries(env).map(([key, { validator }]) => [key, validator])) as { [K in keyof Env]: Env[K]['validator'] });
let envSchema = object(Object.fromEntries(Object.entries(env).map(([key, { validator }]) => [key, validator])) as { [K in keyof Env]: Env[K]['validator'] });
let envSelection = Object.fromEntries(Object.entries(env).map(([key, { value }]) => [key, value])) as (typeof process)['env'];
let sourceEnv: z.infer<typeof envSchema>;
let sourceEnv: InferOutput<typeof envSchema>;

try {
sourceEnv = envSchema.parse(envSelection);
sourceEnv = parse(envSchema, envSelection);
} catch (error) {
const zerr = JSON.stringify((error as z.ZodError).flatten(), null, 2);
const zerr = JSON.stringify(error as typeof ValiError, null, 2);
console.error(zerr);
throw new Error(zerr);
}
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
"exclude": ["node_modules"],
"include": [".plasmo/index.d.ts", ".plasmo/**/*", "./**/*.ts", "./**/*.tsx"],
"compilerOptions": {
"target": "ES2023",
"target": "ES2018",
"strict": true,
"noUnusedLocals": true,
"alwaysStrict": true,
"removeComments": true,
"baseUrl": ".",
"paths": {
"~*": ["./src/*"]
Expand Down
Loading