Skip to content

Commit

Permalink
chore: log short path (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
noyobo committed Jun 8, 2023
1 parent 33d1403 commit 50f57e8
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions __tests__/runTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const runTest = async (files: string[], outdir: string, options?: BuildOp
bundle: true,
write: false,
sourcemap: true,
logLevel: 'debug',
external: !!OUTPUT_HTML ? undefined : ['react', 'react-dom'],
// target: ['es2015', 'chrome58', 'safari10', 'ios10'],
plugins: [
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"dependencies": {
"browserslist": "^4.21.5",
"camel-case": "^4.1.2",
"colors": "1.4.0",
"deepmerge": "^4.3.1",
"esbuild": "^0.17.18",
"less": "^4.1.3",
Expand Down
8 changes: 6 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { CSSModulesConfig, transform } from 'lightningcss';
import { readFile } from 'fs/promises';
import qs from 'query-string';
import deepmerge from 'deepmerge';
import colors from 'colors';

import { transformLess } from './transform-less';
import { codeWithSourceMap, cssExportsToJs, generateTargets, parsePath, replaceExtension, resolvePath } from './utils';
Expand All @@ -12,6 +13,8 @@ import { transformSass } from './transform-sass';
import { TransformResult } from './types';
import { convertScssError } from './sass-utils';

colors.enable();

export { transformLess, convertLessError };

type StyleLoaderOptions = {
Expand All @@ -38,7 +41,7 @@ export const styleLoader = (options: StyleLoaderOptions = {}): Plugin => {
const { logLevel } = build.initialOptions;
if (logLevel === 'debug' || logLevel === 'verbose') {
return (...args) => {
console.log(`[esbuild-style-loader]`, ...args);
console.log(`[esbuild-style-loader]`.magenta.bold, ...args);
};
}
return () => void 0;
Expand All @@ -49,6 +52,7 @@ export const styleLoader = (options: StyleLoaderOptions = {}): Plugin => {
setup(build) {
const buildOptions = build.initialOptions;
const logger = getLogger(build);
const cwd = process.cwd();

const styleTransform = async (filePath: string): Promise<TransformResult> => {
const extname = PATH.extname(filePath);
Expand Down Expand Up @@ -113,7 +117,7 @@ export const styleLoader = (options: StyleLoaderOptions = {}): Plugin => {
try {
const t = Date.now();
result = await styleTransform(args.path);
logger(`Compile ${args.path} in ${Date.now() - t}ms`);
logger(`Compile`, PATH.relative(cwd, args.path).blue.underline, `in ${Date.now() - t}ms`);
cssContent = result.css;
cssSourceMap = result.map;
watchImports = result.imports;
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1366,6 +1366,11 @@ color-name@~1.1.4:
resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.4.tgz#c2a09a87acbde69543de6f63fa3995c826c536a2"
integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==

colors@1.4.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/colors/-/colors-1.4.0.tgz#c50491479d4c1bdaed2c9ced32cf7c7dc2360f78"
integrity sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA==

commander@^7.1.0:
version "7.2.0"
resolved "https://registry.npmmirror.com/commander/-/commander-7.2.0.tgz#a36cb57d0b501ce108e4d20559a150a391d97ab7"
Expand Down

0 comments on commit 50f57e8

Please sign in to comment.