Skip to content
This repository was archived by the owner on Sep 16, 2023. It is now read-only.

Commit 7c49989

Browse files
danny-andrewsjdalton
authored andcommitted
Handle scoped packages correctly (#186)
1 parent 421468b commit 7c49989

File tree

5 files changed

+24
-5
lines changed

5 files changed

+24
-5
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"test": "mocha --check-leaks --compilers js:babel-register"
1818
},
1919
"devDependencies": {
20+
"@storybook/addon-links": "^3.2.0",
2021
"async": "^2.4.1",
2122
"babel-cli": "^6.24.1",
2223
"babel-core": "^6.25.0",
@@ -40,7 +41,8 @@
4041
},
4142
"dependencies": {
4243
"glob": "^7.1.1",
43-
"lodash": "^4.17.4"
44+
"lodash": "^4.17.4",
45+
"require-package-name": "^2.0.1"
4446
},
4547
"files": [
4648
"lib"

src/Package.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import _ from 'lodash';
2+
import requirePackageName from 'require-package-name';
23

34
const reLodash = /^lodash(?:-compat|-es)?$/;
45

@@ -7,10 +8,10 @@ const reLodash = /^lodash(?:-compat|-es)?$/;
78
export default class Package {
89
constructor(pkgPath) {
910
pkgPath = _.toString(pkgPath);
10-
const parts = pkgPath.split('/');
11+
const pkgName = requirePackageName(pkgPath);
1112

12-
this.base = _.tail(parts).join('/');
13-
this.id = parts[0];
13+
this.base = pkgPath.replace(new RegExp(pkgName + '/?'), '');
14+
this.id = pkgName;
1415
this.isLodash = _.constant(reLodash.test(this.id));
1516
this.path = pkgPath;
1617
}

test/fixtures/scoped-module/actual.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { register } from '@storybook/addon-links';
2+
3+
export default register;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'use strict';
2+
3+
Object.defineProperty(exports, "__esModule", {
4+
value: true
5+
});
6+
7+
var _register2 = require('@storybook/addon-links/register');
8+
9+
var _register3 = _interopRequireDefault(_register2);
10+
11+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12+
13+
exports.default = _register3.default;

test/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe('cherry-picked modular builds', function() {
2929
it(`should work with ${ testName }`, () => {
3030
const expected = fs.readFileSync(expectedPath, 'utf8');
3131
const actual = transformFileSync(actualPath, {
32-
'plugins': [[plugin, { 'id': lodashId }]]
32+
'plugins': [[plugin, { 'id': [lodashId, '@storybook/addon-links'] }]]
3333
}).code;
3434

3535
assert.strictEqual(_.trim(actual), _.trim(expected));

0 commit comments

Comments
 (0)