Skip to content

Commit

Permalink
use node resolver module and add opt dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
jchip committed Jun 3, 2018
1 parent fcbba50 commit 5c03d63
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 140 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
"use strict";

var Path = require("path");
const Path = require("path");
const devPath = Path.join(__dirname, "..");

module.exports = {
devRequire: require("electrode-archetype-react-component-dev/require"),
// A normal `require.resolve` looks at `package.json:main`. We instead want
// just the _directory_ of the module. So use heuristic of finding dir of
// package.json which **must** exist at a predictable location.
devPath: Path.dirname(require.resolve("electrode-archetype-react-component-dev/package.json")),
devDir: devPath,
devPath,
devRequire: require("../require"),
webpack: {
devHostname: "localhost",
devPort: 2992,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ const optionalRequire = require("optional-require")(require);

const rootDir = process.cwd();

const jestPath = __dirname;
const fileMock = Path.join(jestPath, "__mocks__", "file-mock.js");
const frameworkMock = Path.join(jestPath, "__mocks__", "framework-mock.js");
const fileMock = Path.join(__dirname, "__mocks__", "file-mock.js");
const frameworkMock = Path.join(__dirname, "__mocks__", "framework-mock.js");

const archetypeOptions = optionalRequire(Path.resolve("archetype", "config"), {
const userConfig = optionalRequire(Path.resolve("archetype", "config"), {
default: {}
});

const jestDefaultConfig = {
rootDir,
resolver: require.resolve("electrode-node-resolver/lib/jest"),
moduleFileExtensions: ["js", "jsx"],
moduleDirectories: ["node_modules", "src"],
moduleNameMapper: {
Expand All @@ -23,4 +23,4 @@ const jestDefaultConfig = {
modulePathIgnorePatterns: ["<rootDir>/test", "<rootDir>/lib"]
};

module.exports = Object.assign({}, jestDefaultConfig, archetypeOptions.jest);
module.exports = Object.assign({}, jestDefaultConfig, userConfig.jest);
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
"use strict";

const Path = require("path");
const archetypeNodeModules = Path.join(
// A normal `require.resolve` looks at `package.json:main`. We instead want
// just the _directory_ of the module. So use heuristic of finding dir of
// package.json which **must** exist at a predictable location.
Path.dirname(require.resolve("electrode-archetype-react-component/package.json")),
"node_modules"
);
const archetypeDevNodeModules = Path.join(__dirname, "../../", "node_modules");
const archetype = require("electrode-archetype-react-component/config/archetype");
const archetypeNodeModules = Path.join(archetype.dir, "node_modules");
const archetypeDevNodeModules = Path.join(archetype.devDir, "node_modules");
const ModuleResolver = require("electrode-node-resolver/lib/webpack-plugin");

module.exports = {
resolveLoader: {
modules: [
archetypeNodeModules,
archetypeDevNodeModules,
"node_modules",
process.cwd()
],
extensions: [".js", ".jsx"]
modules: [archetypeNodeModules, archetypeDevNodeModules, "node_modules", process.cwd()],
extensions: [".js", ".jsx"],
plugins: [new ModuleResolver("module", "resolve", archetype.devDir, undefined)]
}
}
};
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
"use strict";

const ModuleResolver = require("../plugins/module-resolver");
const Path = require("path");
const archetypeNodeModules = Path.join(
// A normal `require.resolve` looks at `package.json:main`. We instead want
// just the _directory_ of the module. So use heuristic of finding dir of
// package.json which **must** exist at a predictable location.
Path.dirname(require.resolve("electrode-archetype-react-component/package.json")),
"node_modules"
);
const archetypeDevNodeModules = Path.join(__dirname, "../../", "node_modules");
const archetype = require("electrode-archetype-react-component/config/archetype");
const archetypeNodeModules = Path.join(archetype.dir, "node_modules");
const archetypeDevNodeModules = Path.join(archetype.devDir, "node_modules");
const ModuleResolver = require("electrode-node-resolver/lib/webpack-plugin");

module.exports = {
resolve: {
plugins: [new ModuleResolver("module", undefined, "resolve")],
plugins: [new ModuleResolver("module", "resolve", archetype.devDir, undefined)],
modules: [archetypeNodeModules, archetypeDevNodeModules, "node_modules", process.cwd()],
extensions: [".js", ".jsx"]
}
Expand Down

This file was deleted.

12 changes: 12 additions & 0 deletions packages/electrode-archetype-react-component-dev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
},
"license": "Apache-2.0",
"scripts": {},
"peerDependencies": {
"electrode-archetype-react-component": "^5.0.0"
},
"dependencies": {
"autoprefixer-stylus": "0.13.0",
"babel-cli": "^6.6.5",
Expand All @@ -37,6 +40,7 @@
"config": "^1.19.0",
"css-loader": "^0.28.9",
"electrode-check-dependencies": "^1.0.2",
"electrode-node-resolver": "../electrode-node-resolver",
"electrode-docgen": "^1.0.0",
"enzyme": "^3.0.0",
"enzyme-adapter-react-16": "^1.1.0",
Expand Down Expand Up @@ -102,6 +106,14 @@
"xclap": "^0.2.0",
"xsh": "^0.3.2"
},
"optionalDependencies": {
"electrode-archetype-opt-inferno": "^0.2.0",
"electrode-archetype-opt-react": "^1.0.0"
},
"devDependencies": {
"electrode-archetype-react-component": "../electrode-archetype-react-component",
"prettier": "^1.4.4"
},
"engines": {
"node": ">= 6",
"npm": ">= 3"
Expand Down
41 changes: 34 additions & 7 deletions packages/electrode-archetype-react-component/config/archetype.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
"use strict";

var Path = require("path");
const Path = require("path");
const optionalRequire = require("optional-require")(require);
const pkg = require("../package.json");
const dir = Path.join(__dirname, "..");

module.exports = {
devRequire: require("electrode-archetype-react-component-dev/require"),
// A normal `require.resolve` looks at `package.json:main`. We instead want
// just the _directory_ of the module. So use heuristic of finding dir of
// package.json which **must** exist at a predictable location.
devPath: Path.dirname(require.resolve("electrode-archetype-react-component-dev/package.json")),
dir,
pkg,
webpack: {
devHostname: "localhost",
devPort: 2992,
Expand All @@ -16,5 +16,32 @@ module.exports = {
},
karma: {
browser: process.env.KARMA_BROWSER === undefined ? "chrome" : process.env.KARMA_BROWSER
}
},
addArchetypeConfig: config => Object.assign(module.exports, config)
};

function checkTopDevArchetype() {
const devArchName = "electrode-archetype-react-component-dev";
const topPkg = require(Path.resolve("package.json"));
// in case this is being used for test/dev in the -dev archetype
if (topPkg.name === devArchName) {
return optionalRequire(Path.resolve("config/archetype"));
} else {
return optionalRequire(`${devArchName}/config/archetype`);
}
}

//
// Try to set dev settings, if the dev archetype is available.
// It may have been removed for production deployment.
//
function loadDev() {
const devArchetype = checkTopDevArchetype();
if (devArchetype) {
module.exports.addArchetypeConfig(devArchetype);
} else {
module.exports.noDev = true;
}
}

loadDev();
1 change: 1 addition & 0 deletions packages/electrode-archetype-react-component/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"xclap": "^0.2.0"
},
"optionalDependencies": {
"electrode-archetype-opt-inferno": "^0.2.0",
"electrode-archetype-opt-react": "^1.0.0"
},
"engines": {
Expand Down
2 changes: 0 additions & 2 deletions samples/demo-component/.fynrc

This file was deleted.

4 changes: 2 additions & 2 deletions samples/demo-component/packages/demo-component/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"electrode-demo-index": "^2.0.0"
},
"devDependencies": {
"electrode-archetype-react-component": "^5",
"electrode-archetype-react-component-dev": "^5",
"electrode-archetype-react-component": "../../../../packages/electrode-archetype-react-component",
"electrode-archetype-react-component-dev": "../../../../packages/electrode-archetype-react-component-dev",
"xclap": "^0.2.0"
},
"engines": {
Expand Down

0 comments on commit 5c03d63

Please sign in to comment.