Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

esbuild-css-modules-plugin

Package Overview
Dependencies
Maintainers
1
Versions
82
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

esbuild-css-modules-plugin - npm Package Compare versions

Comparing version 3.0.0-dev.1 to 3.0.0-dev.2

89

lib/plugin.js

@@ -52,2 +52,4 @@ import {

log('initialize build context with options:', options);
/** @param {string} to */

@@ -88,3 +90,3 @@ const relative = (to) => {

}
let root = globalThis.document.querySelector("${containerSelector}");
let root = globalThis.document.querySelector(${JSON.stringify(containerSelector)});
if (root && root.shadowRoot) {

@@ -143,24 +145,30 @@ root = root.shadowRoot;

patchedBuild.onLoad({ filter: /.*/, namespace: pluginCssNamespace }, ({ pluginData }) => {
const result = pluginData.builtCssResult;
if (!result) {
return;
patchedBuild.onLoad(
{ filter: /.*/, namespace: pluginCssNamespace },
({ path, pluginData, namespace }) => {
const result = pluginData.builtCssResult;
if (!result) {
return;
}
const { code, map } = result;
const codeWithSourcemap =
(code ? code.toString('utf8') : '') +
(map
? `\n/*# sourceMappingURL=data:application/json;base64,${map.toString('base64')} */`
: '');
log(`on load ${namespace}:${path} in ${relative(pluginData.resolveDir)}`);
return {
contents: codeWithSourcemap,
loader: patchedBuild.initialOptions.loader?.['.css'] || 'css',
resolveDir: pluginData.resolveDir
};
}
const { code, map } = result;
const codeWithSourcemap =
(code ? code.toString('utf8') : '') +
(map
? `\n/*# sourceMappingURL=data:application/json;base64,${map.toString('base64')} */`
: '');
);
return {
contents: codeWithSourcemap,
loader: patchedBuild.initialOptions.loader?.['.css'] || 'css',
resolveDir: pluginData.resolveDir
};
});
patchedBuild.onResolve(
{ filter: modulesCssRegExp, namespace: pluginJsNamespace },
({ path, pluginData, resolveDir }) => {
({ path, pluginData, resolveDir, namespace }) => {
log(`on resolve ${namespace}:${path} in ${relative(resolveDir)}`);
return {

@@ -179,3 +187,3 @@ path,

{ filter: new RegExp(`\\.${virtualJsExt}$`), namespace: pluginJsNamespace },
async ({ pluginData }) => {
async ({ pluginData, path, namespace }) => {
const { resolveDir, originPath } = pluginData;

@@ -185,2 +193,4 @@ const fullpath = _resolve(resolveDir, originPath);

log(`on load ${namespace}:${path} in ${relative(resolveDir)}`);
const classPrefix = basename(originPath, extname(originPath))

@@ -197,4 +207,7 @@ .replace(/[^a-zA-Z0-9]/g, '-')

const pathForLightningCss = _relative(process.cwd(), fullpath);
log(`build css modules for ${pathForLightningCss}`);
const result = buildFn({
filename: relativeFilePath,
filename: pathForLightningCss,
// @ts-ignore

@@ -220,3 +233,2 @@ code: shouldBundle ? undefined : await readFile(fullpath),

/** @type {string[]} */
// const jsLines = isEsbuildBundleMode ? [`import "${pluginNamespace}:${relativeFilePath}";`] : [];
const jsLines = isEsbuildBundleMode ? [`import "${originPath}";`] : [];

@@ -358,2 +370,5 @@

({ path, resolveDir }) => {
log(
`resolve ${path} in ${relative(resolveDir)} to ${path}.${virtualJsExt} with namespace ${pluginJsNamespace}`
);
return {

@@ -433,13 +448,19 @@ path: `${path}.${virtualJsExt}`,

patchedBuild.esbuild.build({
absWorkingDir: buildRoot,
define: defines,
outExtension: patchedBuild.initialOptions.outExtension,
allowOverwrite: true,
entryPoints,
write: true,
bundle: false,
sourcemap: patchedBuild.initialOptions.sourcemap,
outdir: buildRoot
});
log('build inject js');
patchedBuild.esbuild
.build({
absWorkingDir: buildRoot,
define: defines,
outExtension: patchedBuild.initialOptions.outExtension,
allowOverwrite: true,
entryPoints,
write: true,
bundle: false,
target: patchedBuild.initialOptions.target || 'esnext',
format: patchedBuild.initialOptions.format || 'esm',
sourcemap: patchedBuild.initialOptions.sourcemap,
outdir: buildRoot
})
.finally(() => log('build end'));
} else if (!isEsbuildBundleMode) {

@@ -451,2 +472,3 @@ /** @type {string[]} */

});
log(`modify \`*.css\` to \`*.js\` in output js files`);
await Promise.all(

@@ -463,2 +485,3 @@ builtJsFiles.map((js) => {

);
log('build end');
}

@@ -465,0 +488,0 @@ });

{
"name": "esbuild-css-modules-plugin",
"version": "3.0.0-dev.1",
"version": "3.0.0-dev.2",
"description": "A esbuild plugin to bundle css modules into js(x)/ts(x).",

@@ -5,0 +5,0 @@ "main": "./index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc