Skip to content
This repository has been archived by the owner on Sep 9, 2021. It is now read-only.

Commit

Permalink
fix: inline camelcase dep
Browse files Browse the repository at this point in the history
  • Loading branch information
ramasilveyra committed Nov 26, 2020
1 parent bdeaadc commit eba886e
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 32 deletions.
31 changes: 4 additions & 27 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions package.json
Expand Up @@ -41,9 +41,8 @@
"webpack": "^4.0.0 || ^5.0.0"
},
"dependencies": {
"camelcase": "^6.2.0",
"loader-utils": "^2.0.0",
"schema-utils": "^3.0.0"
"schema-utils": "^3.0.0",
"loader-utils": "^2.0.0"
},
"devDependencies": {
"@babel/cli": "^7.11.6",
Expand Down
69 changes: 67 additions & 2 deletions src/utils.js
@@ -1,5 +1,4 @@
import { stringifyRequest } from 'loader-utils';
import camelcase from 'camelcase';

function getDefaultFilename(filename) {
if (typeof filename === 'function') {
Expand Down Expand Up @@ -49,7 +48,7 @@ function workerGenerator(loaderContext, workerFilename, workerSource, options) {

const esModule =
typeof options.esModule !== 'undefined' ? options.esModule : true;
const fnName = `${camelcase(workerFilename.replace(/\//g, ''))}Worker`;
const fnName = `${camelCase(workerFilename)}Worker`;

if (options.inline) {
const InlineWorkerPath = stringifyRequest(
Expand Down Expand Up @@ -114,6 +113,72 @@ const sourceURLWebpackRegex = RegExp(
);
/* eslint-enable prefer-template */

/*
* Based on https://github.com/sindresorhus/camelcase/tree/v6.2.0
* License: https://github.com/sindresorhus/camelcase/blob/v6.2.0/license
*/
function camelCase(input1) {
let input = input1;
input = input.trim();

if (input.length === 0) {
return '';
}

if (input.length === 1) {
return input.toLocaleLowerCase();
}

const hasUpperCase = input !== input.toLocaleLowerCase();

if (hasUpperCase) {
let isLastCharLower = false;
let isLastCharUpper = false;
let isLastLastCharUpper = false;

for (let i = 0; i < input.length; i++) {
const character = input[i];

if (isLastCharLower && /[\p{Lu}]/u.test(character)) {
input = `${input.slice(0, i)}-${input.slice(i)}`;
isLastCharLower = false;
isLastLastCharUpper = isLastCharUpper;
isLastCharUpper = true;
i += 1;
} else if (
isLastCharUpper &&
isLastLastCharUpper &&
/[\p{Ll}]/u.test(character)
) {
input = `${input.slice(0, i - 1)}-${input.slice(i - 1)}`;
isLastLastCharUpper = isLastCharUpper;
isLastCharUpper = false;
isLastCharLower = true;
} else {
isLastCharLower =
character.toLocaleLowerCase() === character &&
character.toLocaleUpperCase() !== character;
isLastLastCharUpper = isLastCharUpper;
isLastCharUpper =
character.toLocaleUpperCase() === character &&
character.toLocaleLowerCase() !== character;
}
}
}

input = input.replace(/^[_.\- ]+/, '');

input = input.toLocaleLowerCase();

return input
.replace(/[_.\- ]+([\p{Alpha}\p{N}_]|$)/gu, (_, p1) =>
p1.toLocaleUpperCase()
)
.replace(/\d+([\p{Alpha}\p{N}_]|$)/gu, (m) => m.toLocaleUpperCase())
// NOTE: addition to replace `/` or `\` with ``.
.replace(/(\/|\\)/g, '');
}

export {
getDefaultFilename,
getDefaultChunkFilename,
Expand Down

0 comments on commit eba886e

Please sign in to comment.