Skip to content

Commit

Permalink
fix(esbuild): imports and plugin name
Browse files Browse the repository at this point in the history
  • Loading branch information
Anber committed Oct 5, 2023
1 parent 853454c commit 1b4e740
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions packages/esbuild/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* returns transformed code without template literals and attaches generated source maps
*/

import fs from 'fs';
import path from 'path';
import { readFileSync } from 'fs';
import { basename, dirname, isAbsolute, join, parse, posix } from 'path';

import type { Plugin, TransformOptions, Loader } from 'esbuild';
import { transformSync } from 'esbuild';
Expand Down Expand Up @@ -34,17 +34,17 @@ export default function wywInJS({
let options = esbuildOptions;
const cache = new TransformCacheCollection();
return {
name: 'linaria',
name: 'wyw-in-js',
setup(build) {
const cssLookup = new Map<string, string>();

const asyncResolve = async (
token: string,
importer: string
): Promise<string> => {
const context = path.isAbsolute(importer)
? path.dirname(importer)
: path.join(process.cwd(), path.dirname(importer));
const context = isAbsolute(importer)
? dirname(importer)
: join(process.cwd(), dirname(importer));

const result = await build.resolve(token, {
resolveDir: context,
Expand All @@ -55,7 +55,7 @@ export default function wywInJS({
throw new Error(`Cannot resolve ${token}`);
}

return result.path.replace(/\\/g, path.posix.sep);
return result.path.replace(/\\/g, posix.sep);
};

build.onResolve({ filter: /\.linaria\.css$/ }, (args) => {
Expand All @@ -69,13 +69,13 @@ export default function wywInJS({
return {
contents: cssLookup.get(args.path),
loader: 'css',
resolveDir: path.basename(args.path),
resolveDir: basename(args.path),
};
});

build.onLoad({ filter: /\.(js|jsx|ts|tsx)$/ }, async (args) => {
const rawCode = fs.readFileSync(args.path, 'utf8');
const { ext, name: filename } = path.parse(args.path);
const rawCode = readFileSync(args.path, 'utf8');
const { ext, name: filename } = parse(args.path);
const loader = ext.replace(/^\./, '') as Loader;

if (nodeModulesRegex.test(args.path)) {
Expand Down Expand Up @@ -124,7 +124,7 @@ export default function wywInJS({
return {
contents: code,
loader,
resolveDir: path.dirname(args.path),
resolveDir: dirname(args.path),
};
}

Expand All @@ -149,7 +149,7 @@ export default function wywInJS({
return {
contents,
loader,
resolveDir: path.dirname(args.path),
resolveDir: dirname(args.path),
};
});
},
Expand Down

0 comments on commit 1b4e740

Please sign in to comment.