Skip to content

Commit

Permalink
feat: improve web package and migrate to vite (#3322)
Browse files Browse the repository at this point in the history
  • Loading branch information
stepan662 committed Apr 5, 2024
1 parent c36fd30 commit a25f7b3
Show file tree
Hide file tree
Showing 156 changed files with 2,374 additions and 2,826 deletions.
1 change: 1 addition & 0 deletions e2e/cypress/e2e/next-internal/tags.cy.ts
Expand Up @@ -44,6 +44,7 @@ context('Tags editing', () => {

cy.wait('@getTags');

cy.wait(100);
getDevUi().findDcy('tag-autocomplete-option').contains('test-tag').click();

getDevUi().contains('Update').click();
Expand Down
2 changes: 1 addition & 1 deletion e2e/package.json
Expand Up @@ -24,6 +24,6 @@
"typescript": "^4.9.5"
},
"dependencies": {
"eslint": "^8.47.0"
"eslint": "^8.57.0"
}
}
8 changes: 4 additions & 4 deletions package.json
Expand Up @@ -51,8 +51,8 @@
"@vue/eslint-config-prettier": "^7.0.0",
"@vue/eslint-config-typescript": "^11.0.0",
"commander": "^9.4.1",
"eslint": "8.22.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint": "8.57.0",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-svelte3": "4.0.0",
"eslint-plugin-vue": "^9.2.0",
"glob": "8.0.3",
Expand All @@ -61,8 +61,8 @@
"lerna": "^5.3.0",
"npm-cli-login": "^1.0.0",
"nunjucks": "3.2.3",
"prettier": "^2.7.1",
"prettier-plugin-svelte": "2.7.0",
"prettier": "^3.2.5",
"prettier-plugin-svelte": "3.2.2",
"semantic-release": "^21.0.6",
"ts-node": "^10.9.1",
"turbo": "1.10.12",
Expand Down
1 change: 1 addition & 0 deletions packages/core/package.json
Expand Up @@ -49,6 +49,7 @@
],
"devDependencies": {
"@rollup/plugin-node-resolve": "13.3.0",
"@rollup/plugin-replace": "^4.0.0",
"@rollup/plugin-typescript": "8.3.4",
"@testing-library/jest-dom": "^5.16.5",
"@types/jest": "^27.0.2",
Expand Down
6 changes: 6 additions & 0 deletions packages/core/rollup.config.js
Expand Up @@ -3,6 +3,7 @@ import { terser } from 'rollup-plugin-terser';
import sizes from 'rollup-plugin-bundle-size';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import { visualizer } from 'rollup-plugin-visualizer';
import replace from '@rollup/plugin-replace';

export default {
input: 'src/index.ts',
Expand Down Expand Up @@ -67,5 +68,10 @@ export default {
nodeResolve(),
sizes(),
visualizer(),
replace({
'process.env.TOLGEE_UI_VERSION':
JSON.stringify(process.env.TOLGEE_UI_VERSION) || 'undefined',
preventAssignment: true,
}),
],
};
1 change: 1 addition & 0 deletions packages/core/src/Controller/Controller.ts
Expand Up @@ -207,6 +207,7 @@ export function Controller({ options }: StateServiceProps) {
changeTranslation: changeTranslation,
getTranslationNs: getTranslationNs,
getDefaultAndFallbackNs: getDefaultAndFallbackNs,
findPositions: pluginService.findPositions,
async changeLanguage(language: string) {
if (
state.getPendingLanguage() === language &&
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/Controller/Plugins/Plugins.ts
Expand Up @@ -57,7 +57,7 @@ export function Plugins(
languageStorage: undefined as LanguageStorageMiddleware | undefined,
};

const onClick: TranslationOnClick = async ({ keysAndDefaults, event }) => {
const onClick: TranslationOnClick = async ({ keysAndDefaults, target }) => {
const withNs: UiKeyOption[] = keysAndDefaults.map(
({ key, ns, defaultValue }) => {
return {
Expand All @@ -72,7 +72,7 @@ export function Plugins(
};
}
);
instances.ui?.handleElementClick(withNs, event);
instances.ui?.handleElementClick(withNs, target);
};

const findPositions: FindPositionsInterface = (key, ns) => {
Expand Down Expand Up @@ -185,7 +185,7 @@ export function Plugins(

const self = Object.freeze({
addPlugin,

findPositions: findPositions,
run() {
const { apiKey, apiUrl, projectId, observerOptions } =
getInitialOptions();
Expand Down
5 changes: 5 additions & 0 deletions packages/core/src/TolgeeCore.ts
Expand Up @@ -171,6 +171,11 @@ function createTolgee(options: TolgeeOptions) {
*/
highlight: controller.highlight,

/**
* Find positions of keys in the DOM.
*/
findPositions: controller.findPositions,

/**
* @return current Tolgee options.
*/
Expand Down
10 changes: 8 additions & 2 deletions packages/core/src/types/errors.ts
Expand Up @@ -22,14 +22,20 @@ export class RecordFetchError extends Error {

export class LanguageDetectorError extends Error {
public name = 'LanguageDetectorError' as const;
constructor(message: string, public cause: any) {
constructor(
message: string,
public cause: any
) {
super(message);
}
}

export class LanguageStorageError extends Error {
public name = 'LanguageStorageError' as const;
constructor(message: string, public cause: any) {
constructor(
message: string,
public cause: any
) {
super(message);
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/types/general.ts
Expand Up @@ -27,7 +27,7 @@ export type TranslateOptions = {

export type TranslateProps<
T = DefaultParamType,
K extends string = TranslationKey
K extends string = TranslationKey,
> = {
key: K;
defaultValue?: string;
Expand All @@ -47,7 +47,7 @@ export type CombinedOptions<T> = TranslateOptions & {
export type TFnType<
T = DefaultParamType,
R = string,
K extends string = TranslationKey
K extends string = TranslationKey,
> = {
(key: K, defaultValue?: string, options?: CombinedOptions<T>): R;
(key: K, options?: CombinedOptions<T>): R;
Expand Down
7 changes: 5 additions & 2 deletions packages/core/src/types/plugin.ts
Expand Up @@ -129,7 +129,7 @@ export type FormatterMiddleware = {

export type TranslationOnClick = (data: {
keysAndDefaults: KeyAndParams[];
event: any;
target: HTMLElement;
}) => void;

export type Highlighter = {
Expand Down Expand Up @@ -172,7 +172,10 @@ export type UiKeyOption = {
export type UiMiddleware = (props: UiProps) => UiInterface;

export interface UiInterface {
handleElementClick(keysAndDefaults: UiKeyOption[], event: any): Promise<void>;
handleElementClick(
keysAndDefaults: UiKeyOption[],
target: HTMLElement
): Promise<void>;
}

export type PluginTools = Readonly<{
Expand Down
6 changes: 3 additions & 3 deletions packages/svelte/package.json
Expand Up @@ -45,15 +45,15 @@
"@types/jest": "^28.1.7",
"@typescript-eslint/eslint-plugin": "^5.34.0",
"@typescript-eslint/parser": "^5.34.0",
"eslint": "^8.22.0",
"eslint": "^8.57.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-svelte3": "^4.0.0",
"jest": "^28.1.3",
"jest-environment-jsdom": "28.1.2",
"jest-fetch-mock": "^3.0.3",
"nodemon": "^2.0.19",
"prettier": "^2.7.1",
"prettier-plugin-svelte": "^2.7.0",
"prettier": "^3.2.5",
"prettier-plugin-svelte": "^3.2.2",
"svelte": "^3.55.1",
"svelte-check": "^3.0.3",
"svelte-jester": "^2.3.2",
Expand Down
24 changes: 0 additions & 24 deletions packages/web/.eslintrc.json

This file was deleted.

30 changes: 16 additions & 14 deletions packages/web/.gitignore
@@ -1,25 +1,27 @@
.DS_Store
node_modules
/dist
/lib
/coverage
stats.html

# local env files
.env.local
.env.*.local

# Log files
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

lib
coverage

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.vscode
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
*.sw?
4 changes: 4 additions & 0 deletions packages/web/index.cjs
@@ -0,0 +1,4 @@
module.exports =
process.env.NODE_ENV === 'production'
? require('./dist/tolgee-web.production.umd.cjs')
: require('./dist/tolgee-web.development.umd.cjs');
13 changes: 13 additions & 0 deletions packages/web/index.html
@@ -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 + React + TS</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/app/main.tsx"></script>
</body>
</html>
4 changes: 0 additions & 4 deletions packages/web/index.js

This file was deleted.

File renamed without changes.

0 comments on commit a25f7b3

Please sign in to comment.