Skip to content

Commit

Permalink
fix: Corrects CSS output being overwritten when .cjs ext used (#919)
Browse files Browse the repository at this point in the history
  • Loading branch information
rschristian committed Mar 3, 2022
1 parent f04c85a commit 392d63e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/light-trainers-obey.md
@@ -0,0 +1,5 @@
---
'microbundle': patch
---

Fixes CSS output from being overwritten when also generating .cjs
23 changes: 11 additions & 12 deletions src/index.js
Expand Up @@ -20,7 +20,14 @@ import typescript from 'rollup-plugin-typescript2';
import json from '@rollup/plugin-json';
import OMT from '@surma/rollup-plugin-off-main-thread';
import logError from './log-error';
import { isDir, isFile, stdout, isTruthy, removeScope } from './utils';
import {
EXTENSION,
isDir,
isFile,
isTruthy,
stdout,
removeScope,
} from './utils';
import { getSizeInfo } from './lib/compressed-size';
import { normalizeMinifyOptions } from './lib/terser';
import {
Expand Down Expand Up @@ -279,17 +286,12 @@ function getMain({ options, entry, format }) {

let mainNoExtension = options.output;
if (options.multipleEntries) {
let name = entry.match(
/([\\/])index(\.(umd|cjs|es|m))?\.(mjs|cjs|[tj]sx?)$/,
)
let name = entry.match(new RegExp(/([\\/])index/.source + EXTENSION.source))
? mainNoExtension
: entry;
mainNoExtension = resolve(dirname(mainNoExtension), basename(name));
}
mainNoExtension = mainNoExtension.replace(
/(\.(umd|cjs|es|m))?\.(mjs|cjs|[tj]sx?)$/,
'',
);
mainNoExtension = mainNoExtension.replace(EXTENSION, '');

const mainsByFormat = {};

Expand Down Expand Up @@ -482,10 +484,7 @@ function createConfig(options, entry, format, writeMeta) {
extract:
!!writeMeta &&
options.css !== 'inline' &&
options.output.replace(
/(\.(umd|cjs|es|m))?\.(mjs|[tj]sx?)$/,
'.css',
),
options.output.replace(EXTENSION, '.css'),
minimize: options.compress,
sourceMap: options.sourcemap && options.css !== 'inline',
}),
Expand Down
2 changes: 2 additions & 0 deletions src/utils.js
Expand Up @@ -43,3 +43,5 @@ export function safeVariableName(name) {
const identifier = normalized.replace(INVALID_ES3_IDENT, '');
return camelCase(identifier);
}

export const EXTENSION = /(\.(umd|cjs|es|m))?\.([cm]?[tj]sx?)$/;

0 comments on commit 392d63e

Please sign in to comment.