From 391bdbb1b4747e2e51090196d08ccef69d015da3 Mon Sep 17 00:00:00 2001 From: Gustaf Dalemar Date: Wed, 19 Oct 2016 20:10:29 +0200 Subject: [PATCH] Changed how the default entry files are found This change makes it work better in a nested structure, like when using npm link, without needing an explicit dependency. --- .../src/roc/index.js | 38 +++++++++++-------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/extensions/roc-package-web-app-react-dev/src/roc/index.js b/extensions/roc-package-web-app-react-dev/src/roc/index.js index 4755d2b..9d7513e 100644 --- a/extensions/roc-package-web-app-react-dev/src/roc/index.js +++ b/extensions/roc-package-web-app-react-dev/src/roc/index.js @@ -1,3 +1,5 @@ +import path from 'path'; + import { lazyFunctionRequire, generateDependencies } from 'roc'; import config from '../config/roc.config.js'; @@ -26,29 +28,33 @@ export default { }, { extension: 'roc', hook: 'update-settings', - action: () => (readSettings) => () => { + action: ({ context: { usedExtensions } }) => (readSettings) => () => { const settings = readSettings(); const newSettings = { build: { input: {} } }; - if (!settings.build.input.web) { - newSettings.build.input.web = require.resolve('roc-package-web-app-react/app/default/client'); - } + const rocPackageWebAppReact = usedExtensions.find(({ name }) => name === 'roc-package-web-app-react'); - if (!settings.build.input.node) { - newSettings.build.input.node = require.resolve('roc-package-web-app-react/app/default/server'); - } + if (rocPackageWebAppReact) { + if (!settings.build.input.web) { + newSettings.build.input.web = path.join(rocPackageWebAppReact.path, 'app/default/client.js'); + } + + if (!settings.build.input.node) { + newSettings.build.input.node = path.join(rocPackageWebAppReact.path, 'app/default/server.js'); + } - if (settings.build.resources.length > 0) { - const resources = settings.build.resources.map((resource) => { - const matches = /^roc-package-web-app-react\/(.*)/.exec(resource); - if (matches && matches[1]) { - return require.resolve(`roc-package-web-app-react/${matches[1]}`); - } + if (settings.build.resources.length > 0) { + const resources = settings.build.resources.map((resource) => { + const matches = /^roc-package-web-app-react\/(.*)/.exec(resource); + if (matches && matches[1]) { + return path.join(rocPackageWebAppReact.path, `/${matches[1]}`); + } - return resource; - }); + return resource; + }); - newSettings.build.resources = resources; + newSettings.build.resources = resources; + } } // If a change has been done we will run the hook