esbuild-css-modules-plugin
Advanced tools
Comparing version 3.0.0-dev.2 to 3.0.0-dev.3
import { | ||
basename, | ||
dirname, | ||
extname, | ||
@@ -10,3 +9,3 @@ sep, | ||
import { createHash } from 'node:crypto'; | ||
import { readFile, writeFile, unlink, appendFile, mkdir } from 'node:fs/promises'; | ||
import { readFile, writeFile, mkdir } from 'node:fs/promises'; | ||
import { | ||
@@ -25,3 +24,4 @@ getLogger, | ||
digestPlaceholder, | ||
pluginCssNamespace | ||
pluginCssNamespace, | ||
relativeToCwd | ||
} from './utils.js'; | ||
@@ -31,3 +31,2 @@ import { transform, bundle } from 'lightningcss'; | ||
import { createRequire } from 'node:module'; | ||
import { TextDecoder } from 'node:util'; | ||
@@ -160,3 +159,3 @@ const virtualJsExt = '__virtual__.js'; | ||
log(`on load ${namespace}:${path} in ${relative(pluginData.resolveDir)}`); | ||
log(`on load ${namespace}:${path} in ${relativeToCwd(pluginData.resolveDir)}`); | ||
@@ -174,3 +173,3 @@ return { | ||
({ path, pluginData, resolveDir, namespace }) => { | ||
log(`on resolve ${namespace}:${path} in ${relative(resolveDir)}`); | ||
log(`on resolve ${namespace}:${path} in ${relativeToCwd(resolveDir)}`); | ||
return { | ||
@@ -194,3 +193,3 @@ path, | ||
log(`on load ${namespace}:${path} in ${relative(resolveDir)}`); | ||
log(`on load ${namespace}:${path} in ${relativeToCwd(resolveDir)}`); | ||
@@ -208,3 +207,3 @@ const classPrefix = basename(originPath, extname(originPath)) | ||
const pathForLightningCss = _relative(process.cwd(), fullpath); | ||
const pathForLightningCss = relativeToCwd(fullpath); | ||
log(`build css modules for ${pathForLightningCss}`); | ||
@@ -325,2 +324,10 @@ | ||
const outdir = _resolve(buildRoot, patchedBuild.initialOptions.outdir ?? ''); | ||
let outfile = | ||
_resolve(outdir, originPath) + | ||
(patchedBuild.initialOptions.outExtension?.['.js'] || '.js'); | ||
if (patchedBuild.initialOptions.outbase) { | ||
const outbase = _resolve(outdir, patchedBuild.initialOptions.outbase); | ||
outfile = _resolve(outdir, '.' + outfile.replace(outbase, '')); | ||
} | ||
/** @type {import('esbuild').BuildOptions} */ | ||
@@ -333,4 +340,4 @@ const buildOption = { | ||
loader: 'js', | ||
resolveDir: pluginData.resolveDir, | ||
sourcefile: pluginData.originPath | ||
resolveDir: resolveDir, | ||
sourcefile: originPath | ||
}, | ||
@@ -346,5 +353,3 @@ format: patchedBuild.initialOptions.format, | ||
entryNames: patchedBuild.initialOptions.entryNames, | ||
outfile: | ||
_resolve(patchedBuild.initialOptions.outdir ?? '', pluginData.originPath) + | ||
(patchedBuild.initialOptions.outExtension?.['.js'] ?? '.js'), | ||
outfile, | ||
logLevel: patchedBuild.initialOptions.logLevel, | ||
@@ -358,2 +363,3 @@ define: { | ||
}; | ||
log('build', outfile); | ||
patchedBuild.esbuild.build(buildOption); | ||
@@ -375,3 +381,5 @@ | ||
log( | ||
`resolve ${path} in ${relative(resolveDir)} to ${path}.${virtualJsExt} with namespace ${pluginJsNamespace}` | ||
`resolve ${path} in ${relativeToCwd( | ||
resolveDir | ||
)} to ${path}.${virtualJsExt} with namespace ${pluginJsNamespace}` | ||
); | ||
@@ -378,0 +386,0 @@ return { |
@@ -201,2 +201,8 @@ import { isAbsolute, resolve, sep, relative } from 'node:path'; | ||
/** | ||
* @param {string} to | ||
* @returns string | ||
*/ | ||
const relativeToCwd = (to) => relative(process.cwd(), to); | ||
export { | ||
@@ -218,3 +224,4 @@ pluginName, | ||
contentsPlaceholder, | ||
digestPlaceholder | ||
digestPlaceholder, | ||
relativeToCwd | ||
}; |
{ | ||
"name": "esbuild-css-modules-plugin", | ||
"version": "3.0.0-dev.2", | ||
"version": "3.0.0-dev.3", | ||
"description": "A esbuild plugin to bundle css modules into js(x)/ts(x).", | ||
@@ -5,0 +5,0 @@ "main": "./index.js", |
31200
745