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

Commit 04a77cf

Browse files
authored
Merge branch 'master' into oc-0.44.4-216.0.0
2 parents b6a003a + 865f54b commit 04a77cf

11 files changed

Lines changed: 108 additions & 48 deletions

File tree

acceptance-setup/__tests__/__snapshots__/acceptance.js.snap

Lines changed: 3 additions & 3 deletions
Large diffs are not rendered by default.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"husky": "^0.14.3",
55
"jest": "^22.4.2",
66
"lerna": "^2.4.0",
7-
"lint-staged": "7.1.0",
7+
"lint-staged": "7.1.1",
88
"oc": "0.44.4",
99
"prettier-eslint-cli": "^4.2.0"
1010
},

packages/oc-template-react-compiler/__tests__/__snapshots__/compile.js.snap

Lines changed: 32 additions & 32 deletions
Large diffs are not rendered by default.

packages/oc-template-react-compiler/__tests__/__snapshots__/compileView.js.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
exports[`valid component 1`] = `
44
Object {
55
"bundle": Object {
6-
"hashKey": "940a68df39eb3b2449c6256781f660c857d3890b",
6+
"hashKey": "7d47a0c151221c3f6a285fe966a4ca07cd6446fe",
77
},
88
"template": Object {
9-
"hashKey": "7ac03b60828e1be5987fc925d4a0bd1d05dc09d5",
9+
"hashKey": "31e3e6ab4d9dc8a8406a22dc7ae640256ecc3185",
1010
"src": "template.js",
1111
"type": "oc-template-react",
1212
},
1313
}
1414
`;
1515

16-
exports[`valid component 2`] = `"var oc=oc||{};oc.components=oc.components||{};oc.components['7ac03b60828e1be5987fc925d4a0bd1d05dc09d5']=function(model){ var modelHTML = model.__html ? model.__html : ''; var staticPath = model.reactComponent.props._staticPath; var props = JSON.stringify(model.reactComponent.props); return '<div id=\\"oc-reactRoot-react-component\\" class=\\"oc-reactRoot-react-component\\">' + modelHTML + '</div>' + '' + '<script>' + 'window.oc = window.oc || {};' + 'oc.cmd = oc.cmd || [];' + 'oc.cmd.push(function(oc){' + '' + 'oc.requireSeries([{\\"global\\":\\"PropTypes\\",\\"url\\":\\"https://unpkg.com/prop-types@15.6.1/prop-types.min.js\\",\\"name\\":\\"prop-types\\"},{\\"global\\":\\"React\\",\\"url\\":\\"https://unpkg.com/react@16.3.2/umd/react.production.min.js\\",\\"name\\":\\"react\\"},{\\"global\\":\\"ReactDOM\\",\\"url\\":\\"https://unpkg.com/react-dom@16.3.2/umd/react-dom.production.min.js\\",\\"name\\":\\"react-dom\\"}], function(){' + 'oc.require(' + '[\\"oc\\", \\"reactComponents\\", \\"940a68df39eb3b2449c6256781f660c857d3890b\\"],' + '\\"' + staticPath + 'react-component.js\\",' + 'function(ReactComponent){' + 'var targetNode = document.getElementById(\\"oc-reactRoot-react-component\\");' + 'targetNode.setAttribute(\\"id\\",\\"\\");' + 'ReactDOM.render(React.createElement(ReactComponent,' + props + '),targetNode);' + '}' + ');' + '});' + '});' + '</script>' }"`;
16+
exports[`valid component 2`] = `"var oc=oc||{};oc.components=oc.components||{};oc.components['31e3e6ab4d9dc8a8406a22dc7ae640256ecc3185']=function(model){ var modelHTML = model.__html ? model.__html : ''; var staticPath = model.reactComponent.props._staticPath; var props = JSON.stringify(model.reactComponent.props); return '<div id=\\"oc-reactRoot-react-component\\" class=\\"oc-reactRoot-react-component\\">' + modelHTML + '</div>' + '' + '<script>' + 'window.oc = window.oc || {};' + 'oc.cmd = oc.cmd || [];' + 'oc.cmd.push(function(oc){' + '' + 'oc.requireSeries([{\\"global\\":\\"PropTypes\\",\\"url\\":\\"https://unpkg.com/prop-types@15.6.1/prop-types.min.js\\",\\"name\\":\\"prop-types\\"},{\\"global\\":\\"React\\",\\"url\\":\\"https://unpkg.com/react@16.3.2/umd/react.production.min.js\\",\\"name\\":\\"react\\"},{\\"global\\":\\"ReactDOM\\",\\"url\\":\\"https://unpkg.com/react-dom@16.3.2/umd/react-dom.production.min.js\\",\\"name\\":\\"react-dom\\"}], function(){' + 'oc.require(' + '[\\"oc\\", \\"reactComponents\\", \\"7d47a0c151221c3f6a285fe966a4ca07cd6446fe\\"],' + '\\"' + staticPath + 'react-component.js\\",' + 'function(ReactComponent){' + 'var targetNode = document.getElementById(\\"oc-reactRoot-react-component\\");' + 'targetNode.setAttribute(\\"id\\",\\"\\");' + 'ReactDOM.render(React.createElement(ReactComponent,' + props + '),targetNode);' + '}' + ');' + '});' + '});' + '</script>' }"`;

packages/oc-template-react-compiler/__tests__/createExcludeRegex.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const createExcludeRegex = require("../lib/to-abstract-base-template-utils/createExcludeRegex");
1+
const createExcludeRegex = require("../lib/to-abstract-base-template-utils/oc-webpack/lib/configurator/createExcludeRegex");
22

33
test("should create a regex that match against any node module set aside given ones", () => {
44
const regex = createExcludeRegex([

packages/oc-template-react-compiler/lib/compileView.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"use strict";
22

33
const async = require("async");
4-
const compiler = require("oc-webpack").compiler;
54
const fs = require("fs-extra");
65
const hashBuilder = require("oc-hash-builder");
76
const MemoryFS = require("memory-fs");
@@ -11,7 +10,11 @@ const path = require("path");
1110
const reactComponentWrapper = require("oc-react-component-wrapper");
1211
const strings = require("oc-templates-messages");
1312

14-
const webpackConfigurator = require("./to-abstract-base-template-utils/webpackConfigurator");
13+
const {
14+
compiler,
15+
configurator: webpackConfigurator
16+
} = require("./to-abstract-base-template-utils/oc-webpack");
17+
1518
const fontFamilyUnicodeParser = require("./to-abstract-base-template-utils/font-family-unicode-parser");
1619
const reactOCProviderTemplate = require("./reactOCProviderTemplate");
1720
const viewTemplate = require("./viewTemplate");
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
"use strict";
2+
3+
const compiler = require("./lib/compiler");
4+
const configurator = require("./lib/configurator");
5+
6+
module.exports = {
7+
compiler,
8+
configurator
9+
};
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"use strict";
2+
3+
const MemoryFS = require("memory-fs");
4+
const webpack = require("webpack");
5+
6+
const memoryFs = new MemoryFS();
7+
8+
module.exports = function compiler(config, callback) {
9+
const logger = config.logger;
10+
delete config.logger;
11+
12+
const compiler = webpack(config);
13+
compiler.outputFileSystem = memoryFs;
14+
15+
compiler.run((error, stats) => {
16+
let softError;
17+
let warning;
18+
19+
// handleFatalError
20+
if (error) {
21+
return callback(error);
22+
}
23+
24+
const info = stats.toJson();
25+
// handleSoftErrors
26+
if (stats.hasErrors()) {
27+
softError = info.errors.toString();
28+
return callback(softError);
29+
}
30+
// handleWarnings
31+
if (stats.hasWarnings()) {
32+
warning = info.warnings.toString();
33+
}
34+
35+
const log = stats.toString(config.stats || "errors-only");
36+
37+
if (log) {
38+
logger.log(log);
39+
}
40+
callback(null, memoryFs.data);
41+
});
42+
};

packages/oc-template-react-compiler/lib/to-abstract-base-template-utils/createExcludeRegex.js renamed to packages/oc-template-react-compiler/lib/to-abstract-base-template-utils/oc-webpack/lib/configurator/createExcludeRegex.js

File renamed without changes.

packages/oc-template-react-compiler/lib/to-abstract-base-template-utils/webpackConfigurator.js renamed to packages/oc-template-react-compiler/lib/to-abstract-base-template-utils/oc-webpack/lib/configurator/index.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ const ExtractTextPlugin = require("extract-text-webpack-plugin");
44
const MinifyPlugin = require("babel-minify-webpack-plugin");
55
const externalDependenciesHandlers = require("oc-external-dependencies-handler");
66
const path = require("path");
7-
const webpack = require("oc-webpack").webpack;
7+
const webpack = require("webpack");
88

99
const createExcludeRegex = require("./createExcludeRegex");
1010

11-
module.exports = function webpackConfigGenerator(options) {
11+
module.exports = options => {
1212
const buildPath = options.buildPath || "/build";
1313
const production = options.production;
1414
const buildIncludes = options.buildIncludes.concat(
@@ -67,6 +67,13 @@ module.exports = function webpackConfigGenerator(options) {
6767
const cacheDirectory = !production;
6868

6969
return {
70+
mode: production ? "production" : "development",
71+
optimization: {
72+
// https://webpack.js.org/configuration/optimization/
73+
// Override production mode optimization for minification
74+
// As it currently breakes the build, still rely on babel-minify-webpack-plugin instead
75+
minimize: false
76+
},
7077
entry: options.viewPath,
7178
output: {
7279
path: buildPath,

0 commit comments

Comments
 (0)