Skip to content

Commit f25d968

Browse files
authored
Merge pull request #51 from Andarist/safe-var-name-scoped-pkg
Support for scoped packages - remove scope from the name & remove it from dist location
2 parents ffa65d0 + a1e0599 commit f25d968

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

src/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ const readFile = promisify(fs.readFile);
2525
const stat = promisify(fs.stat);
2626
const isDir = name => stat(name).then( stats => stats.isDirectory() ).catch( () => false );
2727
const isFile = name => stat(name).then( stats => stats.isFile() ).catch( () => false );
28-
const safeVariableName = name => camelCase(name.toLowerCase().replace(/((^[^a-zA-Z]+)|[^\w.-])|([^a-zA-Z0-9]+$)/g, ''));
28+
const removeScope = name => name.replace(/^@.*\//, '');
29+
const safeVariableName = name => camelCase(removeScope(name).toLowerCase().replace(/((^[^a-zA-Z]+)|[^\w.-])|([^a-zA-Z0-9]+$)/g, ''));
2930

3031
const WATCH_OPTS = {
3132
exclude: 'node_modules/**'
@@ -56,7 +57,7 @@ export default async function microbundle(options) {
5657

5758
let main = resolve(cwd, options.output || options.pkg.main || 'dist');
5859
if (!main.match(/\.[a-z]+$/) || await isDir(main)) {
59-
main = resolve(main, `${options.pkg.name}.js`);
60+
main = resolve(main, `${removeScope(options.pkg.name)}.js`);
6061
}
6162
options.output = main;
6263

0 commit comments

Comments
 (0)