use path.resolve on package name
MODIFY
bin-src/lib/getStorybookMetadata.ts
bin-src/lib/getStorybookMetadata.ts
@@ -11,9 +11,15 @@ import { timeout, raceFulfilled } from './promises';
import { supportedAddons } from './supportedAddons';
import { builders } from './builders';
-export const resolvePackageJson = (pkg: string) => {
+export const resolvePackageJson = (log, pkg: string) => {
try {
- const packagePath = path.join(__dirname, `./node_modules/${pkg}/package.json`);
+ // we bundle this app for node, meaning all require calls are replaced by webpack.
+ // in this case we want to use node's actual require functionality!
+ // webpack will provide a '__non_webpack_require__' function to do this with,
+ // but this will obviously not be present during tests, hence the check and fallback to the normal require
+ // const r = typeof __non_webpack_require__ !== 'undefined' ? __non_webpack_require__ : require;
+ log.debug(pkg);
+ const packagePath = path.resolve(`${pkg}/package.json`);
return fs.readJson(packagePath);
} catch (error) {
return Promise.reject(error);
@@ -80,7 +86,7 @@ const findViewlayer = async ({ env, log, options, packageJson }) => {
// Verify that the viewlayer package is actually present in node_modules.
return Promise.race([
- resolvePackageJson(pkg)
+ resolvePackageJson(log, pkg)
.then((json) => {
log.debug(json);
return { viewLayer, version: json.version };
@@ -103,7 +109,7 @@ const findViewlayer = async ({ env, log, options, packageJson }) => {
return Promise.race([
raceFulfilled(
Object.entries(viewLayers).map(async ([key, value]) => {
- const json = await resolvePackageJson(key);
+ const json = await resolvePackageJson(log, key);
return { viewLayer: value, version: json.version };
})
).catch(() => Promise.reject(new Error(packageDoesNotExist(pkg)))),
@@ -169,7 +175,7 @@ export const findBuilder = async ({ log }, mainConfig) => {
log.debug('builder, ', name);
return Promise.race([
- resolvePackageJson(builders[name])
+ resolvePackageJson(log, builders[name])
.then((json) => ({ builder: { name, packageVersion: json.version } }))
.catch((e) => {
log.debug(e);

use path.resolve on package name