Skip to content

Commit

Permalink
fix: Corrects CSS output being overwritten when .cjs ext used
Browse files Browse the repository at this point in the history
  • Loading branch information
rschristian committed Feb 21, 2022
1 parent 778ca3c commit e6cbd0f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
23 changes: 11 additions & 12 deletions src/index.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 e6cbd0f

Please sign in to comment.