Skip to content

Commit

Permalink
chore: upgrade eslint and typescript-eslint
Browse files Browse the repository at this point in the history
+ fix type issues
  • Loading branch information
knjshimi committed Dec 6, 2024
1 parent 3d33a95 commit efde5b0
Show file tree
Hide file tree
Showing 11 changed files with 323 additions and 251 deletions.
23 changes: 22 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1 +1,22 @@
{}
{
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.codeActionsOnSave": {
"source.fixAll": "explicit"
},
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true
},
"[markdown]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.unicodeHighlight.ambiguousCharacters": false,
"editor.unicodeHighlight.invisibleCharacters": false,
"editor.wordWrap": "on",
"editor.rulers": [82]
},
"typescript.validate.enable": true,
"javascript.validate.enable": false,
"eslint.validate": ["javascript", "typescript"],
"eslint.useFlatConfig": true
}
5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,10 @@
},
"devDependencies": {
"@types/node": "22.0.0",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"prettier": "^3.4.2",
"tsup": "^8.3.5",
"turbo": "^2.3.3",
"typescript": "^5.4.3",
"typescript-eslint": "^7.7.0"
"typescript": "^5.7.2"
},
"packageManager": "pnpm@9.14.4"
}
2 changes: 0 additions & 2 deletions packages/vite-plugin-shopify-assets/.eslintignore

This file was deleted.

22 changes: 0 additions & 22 deletions packages/vite-plugin-shopify-assets/.eslintrc.json

This file was deleted.

33 changes: 33 additions & 0 deletions packages/vite-plugin-shopify-assets/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// @ts-check

import globals from 'globals';
import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';

export default tseslint.config(
eslint.configs.recommended,
tseslint.configs.recommendedTypeChecked,
{
ignores: ['**/dist/**', '**/node_modules/**'],
},
{
plugins: {
'@typescript-eslint': tseslint.plugin,
},
languageOptions: {
parser: tseslint.parser,
parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname,
},
globals: {
...globals.node,
},
},
},
{
// disable type-aware linting on JS files
files: ['**/*.js'],
extends: [tseslint.configs.disableTypeChecked],
},
);
10 changes: 6 additions & 4 deletions packages/vite-plugin-shopify-assets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"scripts": {
"dev": "tsup --watch",
"build": "tsup",
"lint": "eslint .",
"lint": "eslint . && tsc --noEmit",
"format": "prettier --write .",
"type-check": "tsc --noEmit"
},
Expand All @@ -46,15 +46,17 @@
"picomatch": "^3.0.1"
},
"devDependencies": {
"@eslint/js": "^9.16.0",
"@types/node": "22.0.0",
"@types/picomatch": "^2.3.3",
"eslint": "^8.57.0",
"eslint": "^9.16.0",
"eslint-config-prettier": "^9.1.0",
"globals": "^15.13.0",
"prettier": "^3.4.2",
"rollup": "^4.13.0",
"tsup": "^8.0.2",
"typescript": "^5.4.3",
"typescript-eslint": "^7.7.0"
"typescript": "^5.7.2",
"typescript-eslint": "^8.17.0"
},
"peerDependencies": {
"vite": ">=5.0.0"
Expand Down
18 changes: 11 additions & 7 deletions packages/vite-plugin-shopify-assets/src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { normalizePath } from 'vite';
import { copyAllAssetMap, getBundleFiles, isChildDir, logEvent, logWarn, logWarnConsole, renameFile } from './utils.js';

import type { Logger, Plugin, ResolvedConfig, UserConfig } from 'vite';
import type { RenderedChunk } from 'rollup';
import type { OutputAsset, OutputChunk } from 'rollup';
import type { ResolvedTarget, ResolvedPluginShopifyAssetsOptions } from './options.js';

export type AssetMap = Map<string, ResolvedTarget>;
Expand Down Expand Up @@ -154,7 +154,7 @@ export const buildPlugin = ({
}
},

async writeBundle(_, bundle: { [fileName: string]: RenderedChunk }): Promise<void> {
async writeBundle(_, bundle: { [fileName: string]: OutputAsset | OutputChunk }): Promise<void> {
if (!clean) return;

const themeAssetFiles = readdirSync(themeAssetsDir);
Expand All @@ -174,7 +174,7 @@ export const buildPlugin = ({
const matchToDelete = matchFiles.filter((file) => !assetDestSet.has(file));
if (!matchToDelete.length) continue;

filesToDelete.add(...matchToDelete);
matchToDelete.forEach((file) => filesToDelete.add(file));
}

if (!filesToDelete.size) return;
Expand All @@ -183,8 +183,10 @@ export const buildPlugin = ({
Array.from(filesToDelete).map(async (file) => {
return existsSync(file) ? unlink(file).then(() => Promise.resolve(file)) : Promise.resolve(file);
}),
).catch((error: Error) => {
if (!silent) logger.error(error);
).catch((error: unknown) => {
if (silent) return;
const message = error instanceof Error ? error.message : 'An unknown error occurred while deleting files';
logger.error(message);
});
},

Expand Down Expand Up @@ -219,8 +221,10 @@ export const buildPlugin = ({
const relativeDeleted = relative(themeRoot, asset.dest);
logEvent(event, relativeDeleted, logger);
})
.catch((error: Error) => {
if (!silent) logger.error(error);
.catch((error: unknown) => {
if (silent) return;
const message = error instanceof Error ? error.message : 'An unknown error occurred while deleting files';
logger.error(message);
});
}

Expand Down
22 changes: 13 additions & 9 deletions packages/vite-plugin-shopify-assets/src/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,10 @@ export const servePlugin = ({
logEvent('delete', relativePath, logger, true);
}
})
.catch((error: Error) => {
if (!silent) logger.error(error);
.catch((error: unknown) => {
if (silent) return;
const message = error instanceof Error ? error.message : 'An unknown error occurred while deleting files';
logger.error(message);
});
}

Expand All @@ -104,7 +106,7 @@ export const servePlugin = ({
}
},

watchChange(fileChanged: string, { event }): Promise<void> {
async watchChange(fileChanged: string, { event }): Promise<void> {
if (!onServe) return;

const target = targets.find((_target) => picomatch(_target.src)(fileChanged));
Expand All @@ -119,16 +121,18 @@ export const servePlugin = ({
switch (event) {
case 'create':
case 'update':
copyAsset(target, fileChanged, event, logger, silent).catch((error: Error) => {
if (!silent) logger.error(error);
return copyAsset(target, fileChanged, event, logger, silent).catch((error: unknown) => {
if (silent) return;
const message = error instanceof Error ? error.message : 'An unknown error occurred while copying files';
logger.error(message);
});
break;

case 'delete':
deleteAsset(target, fileChanged, event, logger, silent).catch((error: Error) => {
if (!silent) logger.error(error);
return deleteAsset(target, fileChanged, event, logger, silent).catch((error: unknown) => {
if (silent) return;
const message = error instanceof Error ? error.message : 'An unknown error occurred while deleting files';
logger.error(message);
});
break;
}
},
};
Expand Down
24 changes: 13 additions & 11 deletions packages/vite-plugin-shopify-assets/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import fg from 'fast-glob';
import { normalizePath } from 'vite';

import type { Logger } from 'vite';
import type { RenderedChunk } from 'rollup';
import type { OutputAsset, OutputChunk } from 'rollup';
// import type { RenderedChunk } from 'rollup';
import type { AssetMap } from './build.js';
import type { ResolvedTarget, RenameFunc } from './options.js';

Expand Down Expand Up @@ -140,9 +141,9 @@ export const copyAsset = async (
preserveTimestamps: target.preserveTimestamps,
})
.then(() => logEvent(event, relativePath, logger, true))
.catch((error: Error) => {
.catch((error: unknown) => {
logError(`could not create ${relativePath}`, logger, true);
if (!silent) logger.error(error);
if (!silent && error instanceof Error) logger.error(error.message);
});
};

Expand All @@ -163,9 +164,9 @@ export const deleteAsset = async (

unlink(destPath)
.then(() => logEvent(event, relativePath, logger, true))
.catch((error: Error) => {
.catch((error: unknown) => {
logError(`Could not delete ${relativePath}`, logger, true);
if (!silent) logger.error(error);
if (!silent && error instanceof Error) logger.error(error.message);
});
};

Expand Down Expand Up @@ -203,9 +204,9 @@ export const copyAllAssets = async (
.then(() => {
if (!fileExists) logCopySuccess(dest, src, logger, timestamp);
})
.catch((error: Error) => {
.catch((error: unknown) => {
logCopyError(dest, src, logger, timestamp);
if (!silent) logger.error(error);
if (!silent && error instanceof Error) logger.error(error.message);
});
}
};
Expand Down Expand Up @@ -238,16 +239,16 @@ export const copyAllAssetMap = async (
.then(() => {
if (!fileExists) logCopySuccess(target.dest, src, logger, timestamp);
})
.catch((error: Error) => {
.catch((error: unknown) => {
logCopyError(target.dest, src, logger, timestamp);
if (!silent) logger.error(error);
if (!silent && error instanceof Error) logger.error(error.message);
});
}
};

export const getFilesToDeleteInThemeAssets = async (
themeAssetsDir: string,
bundle: { [fileName: string]: RenderedChunk },
bundle: { [fileName: string]: OutputAsset | OutputChunk },
assetDestSet: Set<string>,
): Promise<string[]> => {
if (!bundle || !Object.keys(bundle).length) {
Expand All @@ -262,6 +263,7 @@ export const getFilesToDeleteInThemeAssets = async (
}

if (chunk.type === 'asset') {
console.log('asset', fileName);
return [...acc, fileName];
}

Expand Down Expand Up @@ -293,7 +295,7 @@ export const getFilesToDeleteInThemeAssets = async (
return filesToDelete;
};

export const getBundleFiles = (bundle: { [fileName: string]: RenderedChunk }): string[] => {
export const getBundleFiles = (bundle: { [fileName: string]: OutputAsset | OutputChunk }): string[] => {
if (!bundle || !Object.keys(bundle).length) {
return [];
}
Expand Down
2 changes: 1 addition & 1 deletion packages/vite-plugin-shopify-assets/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"baseUrl": ".",
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"skipLibCheck": false
"skipLibCheck": true
},
"include": ["*.ts", "src/**/*.ts"],
"exclude": ["dist", "build", "node_modules"]
Expand Down
Loading

0 comments on commit efde5b0

Please sign in to comment.