Skip to content

Commit

Permalink
bug(ekscss): Fix types and lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
maxmilton committed Jul 15, 2024
1 parent 1a49618 commit 6b60085
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 27 deletions.
8 changes: 4 additions & 4 deletions packages/ekscss/src/compiler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable no-restricted-syntax, prefer-object-spread */

import * as stylis from 'stylis';
import {
map as _map,
Expand Down Expand Up @@ -32,7 +30,9 @@ export function onAfterBuild(callback: BuildHookFn): void {
// TODO: Write tests that prove this doesn't mutate the original object.
// TODO: This is only a shallow clone, should we do a deep clone? Use structuredClone or klona
function mergeDefaultGlobals(globals: Partial<XCSSGlobals>): XCSSGlobals {
// eslint-disable-next-line prefer-object-spread
const newGlobals = Object.assign({}, globals, {
// eslint-disable-next-line prefer-object-spread
fn: Object.assign({}, globals.fn),
});
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
Expand Down Expand Up @@ -74,11 +74,11 @@ export function compile(

for (const fn of afterBuildFns) fn();

// @ts-expect-error - reset for next compile
// @ts-expect-error - resetting ctx to initial state
// eslint-disable-next-line no-multi-assign
ctx.dependencies = ctx.from = ctx.rootDir = ctx.warnings = ctx.x = undefined;

let sourceMap;
let sourceMap: ReturnType<typeof compileSourceMap> | undefined;

if (map) {
if (process.env.BROWSER) {
Expand Down
36 changes: 17 additions & 19 deletions packages/ekscss/src/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable no-plusplus, no-restricted-syntax */

import type {
Context,
Middleware,
Expand Down Expand Up @@ -234,7 +232,7 @@ export function xcss(
}
}

// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing, @typescript-eslint/restrict-plus-operands
out += (val || (val == null || val === false ? '' : val)) + strings[index];
}

Expand All @@ -244,27 +242,27 @@ export function xcss(
/**
* Resolve XCSS plugins when specified as a stylis Middleware or string.
*
* Itterate over plugins and load plugins specified as a string that denotes
* Iterate over plugins and load plugins specified as a string that denotes
* either the name of a package or a file path. Useful when loading XCSS
* configuration from a JSON file.
*/
export function resolvePlugins(plugins: (Middleware | string)[]): Middleware[] {
if (process.env.BROWSER) {
throw new Error('Browser runtime does not support resolving plugins');
} else {
return plugins.map((plugin) => {
if (typeof plugin !== 'string') return plugin;

try {
// eslint-disable-next-line
const mod = require(plugin);
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
return (mod.default || mod) as Middleware;
} catch (error) {
// eslint-disable-next-line no-console
console.error(`Failed to load plugin "${plugin}"; ${String(error)}`);
return noop;
}
});
}

return plugins.map((plugin) => {
if (typeof plugin !== 'string') return plugin;

try {
// eslint-disable-next-line
const mod = require(plugin);
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
return (mod.default || mod) as Middleware;
} catch (error) {
// eslint-disable-next-line no-console
console.error(`Failed to load plugin "${plugin}":\n ${String(error)}`);
return noop;
}
});
}
8 changes: 4 additions & 4 deletions packages/ekscss/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { SourceMapGenerator } from 'source-map';
import type { Element as _Element, Middleware } from 'stylis';
import type { xcss as _xcss } from './helpers';
import type { SourceMapGenerator } from 'source-map-js';
import type { Middleware, Element as _Element } from 'stylis';
import type { xcss } from './helpers';

// eslint-disable-next-line unicorn/prefer-export-from
export type { Middleware };
Expand Down Expand Up @@ -93,7 +93,7 @@ export interface XCSSCompileOptions {

export type BuildHookFn = () => void;

export type XCSSTemplateFn = (xcss: typeof _xcss, x: XCSSGlobals) => string;
export type XCSSTemplateFn = (xcss_: typeof xcss, x: XCSSGlobals) => string;

export interface XCSSCompileResult {
css: string;
Expand Down

0 comments on commit 6b60085

Please sign in to comment.