Skip to content

Commit

Permalink
feat: typecheck on linting (#303)
Browse files Browse the repository at this point in the history
  • Loading branch information
patzick authored Jul 6, 2023
1 parent 61f5599 commit aeb639a
Show file tree
Hide file tree
Showing 44 changed files with 405 additions and 562 deletions.
16 changes: 16 additions & 0 deletions .changeset/brown-beers-camp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
"@shopware/api-client": patch
"vue-demo-store": patch
"@shopware-pwa/nuxt3-module": patch
"@shopware-pwa/composables-next": patch
"@shopware-pwa/vue3-plugin": patch
"@shopware-pwa/api-client": patch
"vue-blank": patch
"@shopware-pwa/cms-base": patch
"@shopware/api-gen": patch
"@shopware-pwa/helpers-next": patch
"@shopware-pwa/typer": patch
"@shopware-pwa/types": patch
---

Improved linting in packages. Types should be more reliable
6 changes: 6 additions & 0 deletions .changeset/tall-brooms-reflect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@shopware-pwa/vue3-plugin": patch
"@shopware-pwa/typer": patch
---

unified build process with `unbuild`
3 changes: 2 additions & 1 deletion packages/api-client-next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"build:types": "tsc ./src/*.ts --declaration --allowJs --emitDeclarationOnly --outDir ./temp --skipLibCheck",
"dev": "export NODE_ENV=development && unbuild --stub",
"generate": "esno ../api-gen/src/cli.ts generate",
"lint": "eslint src/**/*.ts* --fix --max-warnings=0",
"lint": "eslint src/**/*.ts* --fix --max-warnings=0 && pnpm run typecheck",
"typecheck": "tsc --noEmit",
"test": "vitest run && pnpm run test:types",
"test:types": "vitest typecheck --run",
"test:bench": "vitest bench",
Expand Down
3 changes: 2 additions & 1 deletion packages/api-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"build": "export NODE_ENV=production && unbuild && pnpm build:types",
"build:types": "tsc ./src/*.ts --declaration --allowJs --emitDeclarationOnly --outDir ./temp --skipLibCheck",
"dev": "export NODE_ENV=development && unbuild --stub",
"lint": "eslint src/**/*.ts* --fix --max-warnings=0",
"lint": "eslint src/**/*.ts* --fix --max-warnings=0 && pnpm run typecheck",
"typecheck": "tsc --noEmit",
"test": "vitest run --segfault-retry=3"
},
"devDependencies": {
Expand Down
12 changes: 9 additions & 3 deletions packages/api-client/src/interceptors/apiInterceptors.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,9 @@ describe("apiInterceptors", () => {
code: "",
detail: "timeout of 5ms",
meta: {},
source: {},
source: {
pointer: "",
},
status: "",
title: "",
},
Expand All @@ -217,7 +219,9 @@ describe("apiInterceptors", () => {
code: "",
detail: "Network Error",
meta: {},
source: {},
source: {
pointer: "",
},
status: "",
title: "",
},
Expand Down Expand Up @@ -255,7 +259,9 @@ describe("apiInterceptors", () => {
code: "",
title: "",
meta: {},
source: {},
source: {
pointer: "",
},
},
],
statusCode: 408,
Expand Down
4 changes: 3 additions & 1 deletion packages/api-client/src/interceptors/errorInterceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ const extractNotApiErrorMessage = (error: AxiosError): ShopwareError[] => [
code: "",
title: "",
meta: {},
source: {},
source: {
pointer: "",
},
},
];

Expand Down
2 changes: 1 addition & 1 deletion packages/api-gen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"build": "unbuild",
"cli": "esno ./src/cli.ts",
"dev": "export NODE_ENV=development && unbuild --stub",
"lint": "eslint src/**/*.ts* --fix --max-warnings=0",
"lint": "eslint src/**/*.ts* --fix --max-warnings=0 && pnpm run typecheck",
"typecheck": "tsc --noEmit",
"test": "vitest run",
"test:bench": "vitest bench",
Expand Down
4 changes: 2 additions & 2 deletions packages/api-gen/src/commands/generate.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { readFileSync, writeFileSync, existsSync } from "node:fs";
import { resolve } from "node:path";
import openapiTS from "openapi-typescript";
import openapiTS, { OpenAPI3 } from "openapi-typescript";
import * as dotenv from "dotenv";
import * as c from "picocolors";
import { format } from "prettier";
Expand Down Expand Up @@ -72,7 +72,7 @@ export async function generate() {
const schemaFile = readFileSync(SCHEMA_FILENAME(version), {
encoding: "utf-8",
});
let schemaForPatching = JSON.parse(schemaFile);
let schemaForPatching = JSON.parse(schemaFile) as OpenAPI3;
const allPatches = Object.keys(patches) as Array<keyof typeof patches>;
const semverVersion = version.slice(2);
const patchesToApply = allPatches.filter((patch) => {
Expand Down
74 changes: 46 additions & 28 deletions packages/api-gen/src/patches.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { OpenAPI3 } from "openapi-typescript";

/**
* To add new patch define version (using semver) and patch function which modifies JSON schema and saves it back to file.
*/
Expand All @@ -7,7 +9,11 @@ export const patches = {
* Fixes the problem with schema >=5.0 where ContextTokenResponse is not defined
*/
name: "ContextTokenResponse",
patch: (schema: Object) => {
patch: (schema: OpenAPI3) => {
schema.components ??= {};
schema.components.schemas ??= {};
schema.paths ??= {};

schema.components.schemas["ContextTokenResponse"] ??= {
type: "object",
properties: {
Expand All @@ -18,41 +24,53 @@ export const patches = {
},
};

schema.paths["/context"].patch.responses["200"] = {
description:
"Returns the context token. Use that as your `sw-context-token` header for subsequent requests. Redirect if getRedirectUrl is set.",
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/ContextTokenResponse",
schema.paths["/context"].patch ??= {};
if ("responses" in schema.paths["/context"].patch) {
schema.paths["/context"].patch.responses ??= {};
schema.paths["/context"].patch.responses["200"] = {
description:
"Returns the context token. Use that as your `sw-context-token` header for subsequent requests. Redirect if getRedirectUrl is set.",
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/ContextTokenResponse",
},
},
},
},
};
};
}

schema.paths["/account/login"].post.responses["200"] = {
description:
"A successful login returns a context token which is associated with the logged in user. Use that as your `sw-context-token` header for subsequent requests.",
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/ContextTokenResponse",
schema.paths["/account/login"].post ??= {};
if ("responses" in schema.paths["/account/login"].post) {
schema.paths["/account/login"].post.responses ??= {};
schema.paths["/account/login"].post.responses["200"] = {
description:
"A successful login returns a context token which is associated with the logged in user. Use that as your `sw-context-token` header for subsequent requests.",
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/ContextTokenResponse",
},
},
},
},
};
};
}

schema.paths["/account/logout"].post.responses["200"] = {
description:
"A successful logout returns a context token for the anonymous user. Use that as your `sw-context-token` header for subsequent requests.",
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/ContextTokenResponse",
schema.paths["/account/logout"].post ??= {};
if ("responses" in schema.paths["/account/logout"].post) {
schema.paths["/account/logout"].post.responses ??= {};
schema.paths["/account/logout"].post.responses["200"] = {
description:
"A successful logout returns a context token for the anonymous user. Use that as your `sw-context-token` header for subsequent requests.",
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/ContextTokenResponse",
},
},
},
},
};
};
}

return schema;
},
Expand Down
8 changes: 7 additions & 1 deletion packages/cms-base/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
module.exports = {
root: true,
extends: ["shopware", "plugin:vue/vue3-recommended"],
extends: [
"shopware",
"plugin:vue/vue3-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended",
"prettier",
],
parser: "vue-eslint-parser",
parserOptions: {
parser: "@typescript-eslint/parser",
Expand Down
4 changes: 2 additions & 2 deletions packages/cms-base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
"scripts": {
"build": "unbuild",
"dev": "unbuild --stub",
"check-types": "vue-tsc --noemit",
"eslint": "eslint components/**/*.vue* --fix --max-warnings=0",
"lint": "pnpm run eslint && pnpm run check-types",
"lint": "pnpm run eslint && pnpm run typecheck",
"typecheck": "tsc --noEmit",
"test": "echo \"Warn: no test specified yet\""
},
"dependencies": {
Expand Down
3 changes: 2 additions & 1 deletion packages/composables/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"build": "unbuild && pnpm build:types",
"build:types": "npx -p typescript tsc --project tsconfig.build.json",
"dev": "unbuild --stub",
"lint": "eslint src/**/*.ts* --fix --max-warnings=0",
"lint": "eslint src/**/*.ts* --fix --max-warnings=0 && pnpm run typecheck",
"typecheck": "tsc --noEmit",
"test": "vitest run",
"coverage": "vitest run --coverage"
},
Expand Down
8 changes: 4 additions & 4 deletions packages/composables/src/useAddress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
ClientApiError,
CustomerAddress,
ShopwareSearchParams,
Error,
ShopwareError,
} from "@shopware-pwa/types";
import { useUser } from "./useUser";

Expand Down Expand Up @@ -54,9 +54,9 @@ export type UseAddressReturn = {
/**
* Returns formatted error message
*
* @param {Error} error
* @param {ShopwareError} error
*/
errorMessageBuilder(error: Error): string | null;
errorMessageBuilder(error: ShopwareError): string | null;
};

/**
Expand Down Expand Up @@ -148,7 +148,7 @@ export function useAddress(): UseAddressReturn {
* @param {error} error
* @returns {string | null}
*/
function errorMessageBuilder(error: Error): string | null {
function errorMessageBuilder(error: ShopwareError): string | null {
switch (error.code) {
case "VIOLATION::IS_BLANK_ERROR":
return `${error?.source?.pointer.slice(1)} - ${error.detail}`;
Expand Down
2 changes: 1 addition & 1 deletion packages/composables/src/useCustomerOrders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export type UseCustomerOrdersReturn = {
/**
* Fetches the orders list and assigns the result to the `orders` property
*/
loadOrders(parameters: ShopwareSearchParams): Promise<void>;
loadOrders(parameters?: ShopwareSearchParams): Promise<void>;
};

/**
Expand Down
3 changes: 2 additions & 1 deletion packages/helpers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"build": "unbuild && pnpm build:types",
"build:types": "tsc ./src/*.ts --declaration --allowJs --emitDeclarationOnly --outDir ./temp --skipLibCheck",
"dev": "unbuild --stub",
"lint": "eslint src/**/*.ts* --fix --max-warnings=0",
"lint": "eslint src/**/*.ts* --fix --max-warnings=0 && pnpm run typecheck",
"typecheck": "tsc --noEmit",
"test": "vitest run"
},
"devDependencies": {
Expand Down
3 changes: 2 additions & 1 deletion packages/nuxt3-module/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"scripts": {
"build": "unbuild",
"dev": "unbuild --stub",
"lint": "eslint plugin.ts src/**/*.ts* --fix --max-warnings=0",
"lint": "eslint plugin.ts src/**/*.ts* --fix --max-warnings=0 && pnpm run typecheck",
"typecheck": "tsc --noEmit",
"test": "echo \"Warn: no test specified yet\""
},
"dependencies": {
Expand Down
4 changes: 4 additions & 0 deletions packages/typer/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
root: true,
extends: ["shopware"],
};
11 changes: 11 additions & 0 deletions packages/typer/build.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { defineBuildConfig } from "unbuild";

export default defineBuildConfig({
entries: ["src/index"],
declaration: true,
rollup: {
emitCJS: true,
cjsBridge: true,
},
externals: ["typedoc", "fs-extra", "find-in-files", "ts-dox", "vite"],
});
42 changes: 23 additions & 19 deletions packages/typer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,41 @@
"bugs": {
"url": "https://github.com/shopware/frontends/issues"
},
"type": "module",
"license": "MIT",
"types": "./dist/main.d.ts",
"module": "./dist/typer.js",
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"files": [
"dist"
],
"exports": {
".": {
"types": "./dist/main.d.ts",
"import": "./dist/typer.js",
"require": "./dist/typer.cjs"
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
"require": "./dist/index.cjs"
}
},
"files": [
"dist"
],
"scripts": {
"build": "vite build",
"dev": "vite"
"build": "unbuild",
"dev": "unbuild --stub",
"lint": "eslint src/**/*.ts* --fix --max-warnings=0 && pnpm run typecheck",
"typecheck": "tsc --noEmit"
},
"dependencies": {
"find-in-files": "^0.5.0",
"fs-extra": "^11.1.0",
"ts-dox": "^0.1.0",
"typedoc": "^0.24.8",
"vinyl": "^3.0.0",
"vite": "^4.3.9"
},
"devDependencies": {
"@shopware-pwa/types": "workspace:*",
"@stackblitz/sdk": "^1.9.0",
"@types/find-in-files": "^0.5.1",
"@types/fs-extra": "^11.0.1",
"find-in-files": "^0.5.0",
"fishery": "^2.2.2",
"intermock": "^0.2.5",
"ts-dox": "^0.1.0",
"typedoc": "^0.24.8",
"eslint-config-shopware": "workspace:*",
"tsconfig": "workspace:*",
"typescript": "^5.1.6",
"vinyl": "^3.0.0",
"vite-plugin-dts": "^2.3.0",
"vitest": "^0.32.2"
}
}
2 changes: 1 addition & 1 deletion packages/typer/src/extractor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { Metadata, Property, PropertyMdTableRow } from "./types";
import type { TsDoxFile, TsDoxFunction, TsDoxDict } from "ts-dox";
import { normalizeString } from "./string";

let tableHeader = `
const tableHeader = `
<table>
<tr>
<th>Name</th>
Expand Down
File renamed without changes.
Loading

2 comments on commit aeb639a

@vercel
Copy link

@vercel vercel bot commented on aeb639a Jul 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on aeb639a Jul 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

frontends-demo – ./templates/vue-demo-store

frontends-demo-shopware-frontends.vercel.app
frontends-demo.vercel.app
frontends-demo-git-main-shopware-frontends.vercel.app

Please sign in to comment.