Skip to content

Commit 72619a0

Browse files
authored
fix: add externals with dash to globals (#643) (#667)
1 parent 4c6a7e0 commit 72619a0

File tree

5 files changed

+70
-2
lines changed

5 files changed

+70
-2
lines changed

src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -482,8 +482,8 @@ function createConfig(options, entry, format, writeMeta) {
482482
if (name instanceof RegExp) name = name.source;
483483

484484
// valid JS identifiers are usually library globals:
485-
if (name.match(/^[a-z_$][a-z0-9_$]*$/)) {
486-
globals[name] = name;
485+
if (name.match(/^[a-z_$][a-z0-9_\-$]*$/)) {
486+
globals[name] = camelCase(name);
487487
}
488488
return globals;
489489
}, {});

test/__snapshots__/index.test.js.snap

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,54 @@ exports[`fixtures build basic-css with microbundle 6`] = `
428428
"
429429
`;
430430
431+
exports[`fixtures build basic-dashed-external with microbundle 1`] = `
432+
"Used script: microbundle
433+
434+
Directory tree:
435+
436+
basic-dashed-external
437+
dist
438+
basic-dashed-external.esm.js
439+
basic-dashed-external.esm.js.map
440+
basic-dashed-external.js
441+
basic-dashed-external.js.map
442+
basic-dashed-external.umd.js
443+
basic-dashed-external.umd.js.map
444+
package.json
445+
src
446+
index.js
447+
two.js
448+
449+
450+
Build \\"basicDashedExternal\\" to dist:
451+
248 B: basic-dashed-external.js.gz
452+
188 B: basic-dashed-external.js.br
453+
214 B: basic-dashed-external.esm.js.gz
454+
164 B: basic-dashed-external.esm.js.br
455+
349 B: basic-dashed-external.umd.js.gz
456+
281 B: basic-dashed-external.umd.js.br"
457+
`;
458+
459+
exports[`fixtures build basic-dashed-external with microbundle 2`] = `6`;
460+
461+
exports[`fixtures build basic-dashed-external with microbundle 3`] = `
462+
"import r from\\"tiny-glob\\";var e=function(){try{var r=arguments;return Promise.resolve([].slice.call(r).reduce(function(r,e){return r+e},0))}catch(r){return Promise.reject(r)}};console.log(r);export default function(){try{var r=arguments,t=[].slice.call(r);return Promise.resolve(e.apply(void 0,t)).then(function(r){return Promise.resolve(e.apply(void 0,t)).then(function(e){return[r,e]})})}catch(r){return Promise.reject(r)}}
463+
//# sourceMappingURL=basic-dashed-external.esm.js.map
464+
"
465+
`;
466+
467+
exports[`fixtures build basic-dashed-external with microbundle 4`] = `
468+
"var e,r=(e=require(\\"tiny-glob\\"))&&\\"object\\"==typeof e&&\\"default\\"in e?e.default:e,t=function(){try{var e=arguments;return Promise.resolve([].slice.call(e).reduce(function(e,r){return e+r},0))}catch(e){return Promise.reject(e)}};console.log(r),module.exports=function(){try{var e=arguments,r=[].slice.call(e);return Promise.resolve(t.apply(void 0,r)).then(function(e){return Promise.resolve(t.apply(void 0,r)).then(function(r){return[e,r]})})}catch(e){return Promise.reject(e)}};
469+
//# sourceMappingURL=basic-dashed-external.js.map
470+
"
471+
`;
472+
473+
exports[`fixtures build basic-dashed-external with microbundle 5`] = `
474+
"!function(e,t){\\"object\\"==typeof exports&&\\"undefined\\"!=typeof module?module.exports=t(require(\\"tiny-glob\\")):\\"function\\"==typeof define&&define.amd?define([\\"tiny-glob\\"],t):(e=e||self).basicDashedExternal=t(e.tinyGlob)}(this,function(e){e=e&&Object.prototype.hasOwnProperty.call(e,\\"default\\")?e.default:e;var t=function(){try{var e=arguments;return Promise.resolve([].slice.call(e).reduce(function(e,t){return e+t},0))}catch(e){return Promise.reject(e)}};return console.log(e),function(){try{var e=arguments,r=[].slice.call(e);return Promise.resolve(t.apply(void 0,r)).then(function(e){return Promise.resolve(t.apply(void 0,r)).then(function(t){return[e,t]})})}catch(e){return Promise.reject(e)}}});
475+
//# sourceMappingURL=basic-dashed-external.umd.js.map
476+
"
477+
`;
478+
431479
exports[`fixtures build basic-flow with microbundle 1`] = `
432480
"Used script: microbundle
433481
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "basic-dashed-external",
3+
"scripts": {
4+
"build": "microbundle"
5+
},
6+
"dependencies": {
7+
"tiny-glob": "^0.2.6"
8+
}
9+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import tinyglob from 'tiny-glob';
2+
console.log(tinyglob);
3+
4+
import { two } from './two';
5+
6+
export default async function(...args) {
7+
return [await two(...args), await two(...args)];
8+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export async function two(...args) {
2+
return args.reduce((total, value) => total + value, 0);
3+
}

0 commit comments

Comments
 (0)