Skip to content

Commit

Permalink
0.5.1 release
Browse files Browse the repository at this point in the history
  • Loading branch information
JayCanuck committed Jan 27, 2017
2 parents 9574f01 + fc0c59e commit ddd092e
Show file tree
Hide file tree
Showing 20 changed files with 196 additions and 72 deletions.
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
## 0.5.1 (January 27, 2017)

## create

* Template updated for Enact 1.0.0-beta.2 and React 15.4.2.
* Template's .gitignore file now correctly includes `dist`.

## pack

* Added a `node` Enact build option to support polyfilling NodeJS components. See [here](https://github.com/enyojs/enact-dev/blob/master/README.md#enact-build-options) for more info.
* All localized appinfo.json resources and assets will now be correctly copied to the output directory.

# test

* Added a polyfill for String.prototype.repeat, as phantomjs lacks the API.
* Webpack build warnings will no longer spam the console in certain scenarios.
* Test action will now automatically fail when no test suite is found. This was done to allows tests which build incorrect or have missing modules to correctly fail. See [#38](https://github.com/enyojs/enact-dev/pull/38) for more background information.


## 0.5.0 (December 20, 2016)

Several additional documentation files have been added to the `docs` directory, to cover common topics.
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ The enact-dev tool will check the project's `package.json` looking for an option
* `isomorphic` _[boolean|string]_ - If `true`, it indicates the default entrypoint is isomorphic-compatible (and can be built via the `--isomorphic` enact-dev flag). If the value is a string, then it will use that value as a filepath to a custom isomorphic-compatible entrypoint.
* `title` _[string]_ - Title text that should be put within the HTML's `<title></title>` tags. Note: if this is a webOS-project, the title by default will be auto-detected from the appinfo.json content.
* `ri` _[object]_ - Resolution independence options to be forwarded to the [LESS plugin](https://github.com/enyojs/less-plugin-resolution-independence).
* `node` _[object]_ - Configuration settings for polyfilling NodeJS built-ins. See `node` [webpack option](https://webpack.github.io/docs/configuration.html#node).
* `proxy` _[string]_ - Proxy target during project `serve` to be used within the [http-proxy-middleware](https://github.com/chimurai/http-proxy-middleware).

For example:
Expand Down
13 changes: 8 additions & 5 deletions config/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function readJSON(file) {
try {
return JSON.parse(fs.readFileSync(file, {encoding:'utf8'}));
} catch(e) {
return undefined;
return null;
}
}

Expand All @@ -28,6 +28,7 @@ module.exports = function(karma) {
frameworks: ['mocha', 'chai', 'dirty-chai'],
files: [
require.resolve('./polyfills'),
require.resolve('string.prototype.repeat'),
require.resolve('./proptype-checker'),
'./!(node_modules|dist|build)/**/*-specs.js'
],
Expand All @@ -36,10 +37,11 @@ module.exports = function(karma) {
// add webpack as preprocessor
'./!(node_modules|dist|build)/**/*.js': ['webpack'],
[require.resolve('./polyfills')]: ['webpack'],
[require.resolve('string.prototype.repeat')]: ['webpack'],
[require.resolve('./proptype-checker')]: ['webpack']
},

failOnEmptyTestSuite: false,
failOnEmptyTestSuite: true,

webpack: {
// Use essentially the same webpack config as from the development build setup.
Expand Down Expand Up @@ -72,12 +74,12 @@ module.exports = function(karma) {
'react/lib/ExecutionEnvironment': true,
'react/lib/ReactContext': true
},
node: {
node: Object.assign({}, enact.node || {}, {
console: true,
fs: 'empty',
net: 'empty',
tls: 'empty'
},
}),
module: {
loaders: [
{test: /\.(js|jsx|es6)$/, loader: 'babel', exclude: /node_modules.(?!@enact)/,
Expand Down Expand Up @@ -144,7 +146,8 @@ module.exports = function(karma) {
reasons: false,
timings: false,
version: false,
children: false
children: false,
warnings: false
}
},

Expand Down
6 changes: 4 additions & 2 deletions config/webpack.config.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function readJSON(file) {
try {
return JSON.parse(fs.readFileSync(file, {encoding:'utf8'}));
} catch(e) {
return undefined;
return null;
}
}

Expand Down Expand Up @@ -85,6 +85,8 @@ module.exports = {
fallback: path.resolve('./node_modules')
},
// @remove-on-eject-end
// Optional configuration for polyfilling NodeJS built-ins.
node: enact.node || null,
module: {
// First, run the linter.
// It's important to do this before Babel processes the JS.
Expand All @@ -108,7 +110,7 @@ module.exports = {
extends: path.join(__dirname, '.babelrc'),
// @remove-on-eject-end
// This is a feature of `babel-loader` for webpack (not Babel itself).
// It enables caching results in ./node_modules/.cache/react-scripts/
// It enables caching results in ./node_modules/.cache/enact-dev/
// directory for faster rebuilds. So use findCacheDir() because of:
// https://github.com/facebookincubator/create-react-app/issues/483
cacheDirectory: findCacheDir({
Expand Down
4 changes: 3 additions & 1 deletion config/webpack.config.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function readJSON(file) {
try {
return JSON.parse(fs.readFileSync(file, {encoding:'utf8'}));
} catch(e) {
return undefined;
return null;
}
}

Expand Down Expand Up @@ -77,6 +77,8 @@ module.exports = {
fallback: path.resolve('./node_modules')
},
// @remove-on-eject-end
// Optional configuration for polyfilling NodeJS built-ins.
node: enact.node || null,
module: {
// First, run the linter.
// It's important to do this before Babel processes the JS.
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ The enact-dev package includes the following documentation:
* [Installation](./installation.md)
* [Starting a New App](./starting-a-new-app.md)
* [Loading an Existing App](./loading-existing-app.md)
* [Insomorphic Support](./isomorphic-support.md)
* [Isomorphic Support](./isomorphic-support.md)
17 changes: 15 additions & 2 deletions global-cli/modifiers/externals.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
var EnactFrameworkRefPlugin = require('./util/EnactFrameworkRefPlugin')
var
fs = require('fs'),
exists = require('path-exists').sync,
EnactFrameworkRefPlugin = require('./util/EnactFrameworkRefPlugin');

module.exports = function(config, opts) {
var resBundle = './resources/ilibmanifest.json';
if(!exists(resBundle)) {
if(!exists('./resources')) {
fs.mkdirSync('./resources');
}
fs.writeFileSync(resBundle, JSON.stringify({files:[]}, null, '\t'), {encoding:'utf8'});
}
config.entry.main.splice(config.entry.main.length-1, 0, resBundle);

// Add the reference plugin so the app uses the external framework
config.plugins.push(new EnactFrameworkRefPlugin({
name: 'enact_framework',
libraries: ['@enact', 'react', 'react-dom'],
external: {
path: opts.externals,
inject: opts['externals-inject'] || opts.inject
inject: opts['externals-inject'] || opts.inject,
snapshot: opts.snapshot
}
}));
};
2 changes: 1 addition & 1 deletion global-cli/modifiers/framework.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module.exports = function(config, opts) {
// Append additional options to the ilib-loader to skip './resources' detection/generation
var ilibLoader = helper.getLoaderByName(config, 'ilib');
if(ilibLoader) {
ilibLoader.loader += '?noSave&noResources';
ilibLoader.loader += '?noResources';
}

// Remove the HTML generation plugin and webOS-meta plugin
Expand Down
28 changes: 15 additions & 13 deletions global-cli/modifiers/isomorphic.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,22 @@ module.exports = function(config, opts) {
var iso = enact.isomorphic || enact.prerender;
// Only use isomorphic if an isomorphic entrypoint is specified
if(iso) {
var reactDOM = path.join(process.cwd(), 'node_modules', 'react-dom', 'index.js');
if(!exists(reactDOM)) {
reactDOM = require.resolve('react-dom');
if(!opts.externals) {
var reactDOM = path.join(process.cwd(), 'node_modules', 'react-dom', 'index.js');
if(!exists(reactDOM)) {
reactDOM = require.resolve('react-dom');
}
// Prepend react-dom as top level entrypoint so espose-loader will expose
// it to window.ReactDOM to allow runtime rendering of the app.
config.entry.main.unshift(reactDOM);

// Expose the 'react-dom' on a global context for App's rendering
// Currently maps the toolset to window.ReactDOM.
config.module.loaders.push({
test: reactDOM,
loader: 'expose?ReactDOM'
});
}
// Prepend react-dom as top level entrypoint so espose-loader will expose
// it to window.ReactDOM to allow runtime rendering of the app.
config.entry.main.unshift(reactDOM);

// If 'isomorphic' value is a string, use custom entrypoint.
if(typeof iso === 'string') {
Expand All @@ -40,13 +49,6 @@ module.exports = function(config, opts) {
// Use universal module definition to allow usage in Node and browser environments.
config.output.libraryTarget = 'umd';

// Expose the 'react-dom' on a global context for App's rendering
// Currently maps the toolset to window.ReactDOM.
config.module.loaders.push({
test: reactDOM,
loader: 'expose?ReactDOM'
});

// Update HTML webpack plugin to use the isomorphic template and include screentypes
var htmlPlugin = helper.getPluginByName(config, 'HtmlWebpackPlugin');
if(htmlPlugin) {
Expand Down
15 changes: 9 additions & 6 deletions global-cli/modifiers/snapshot.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var
path = require('path'),
fs = require('fs'),
helper = require('./util/config-helper'),
SnapshotPlugin = require('./util/SnapshotPlugin');

Expand All @@ -11,16 +12,18 @@ module.exports = function(config, opts) {
htmlPlugin.options.snapshot = true;
}

// Expose iLib so we can update _platform value once page loads, if used
config.module.loaders.push({
test: path.join(process.cwd(), 'node_modules', '@enact', 'i18n', 'ilib', 'lib', 'ilib.js'),
loader: 'expose?iLib'
// Expose iLib locale utility function module so we can update the locale on page load, if used
var babel = helper.findLoader(config, 'babel');
config.module.loaders.splice((babel>=0 ? babel : 0), 0, {
test: fs.realpathSync(path.join(process.cwd(), 'node_modules', '@enact', 'i18n', 'src', 'locale.js')),
loader: 'expose?iLibLocale'
});
}

// Include plugin to attempt generation of v8 snapshot binary if V8_MKSNAPSHOT env var is set
config.plugins.push(new SnapshotPlugin({
target: (opts.framework ? 'enact.js' : 'main.js'),
append: (opts.framework ? '\nenact_framework.load();\n' : undefined)
target: (opts.framework ? 'enact.js' : 'main.js')
// Disabled temporarily until effectiveness is proven
//append: (opts.framework ? '\nenact_framework.load();\n' : undefined)
}));
};
32 changes: 27 additions & 5 deletions global-cli/modifiers/util/EnactFrameworkPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ var
fs = require('fs'),
DllEntryPlugin = require('webpack/lib/DllEntryPlugin'),
DllModule = require('webpack/lib/DllModule'),
RawSource = require("webpack/lib/RawSource");
RawSource = require("webpack/lib/RawSource"),
exists = require('path-exists').sync;

var pkgCache = {};
var checkPkgMain = function(dir) {
Expand All @@ -20,11 +21,32 @@ var checkPkgMain = function(dir) {
}
};

var parentCache = {};
var findParent = function(dir) {
if(parentCache[dir]) {
return parentCache[dir];
} else {
var currPkg = path.join(dir, 'package.json');
if(exists(currPkg)) {
return dir;
} else {
if(dir === '/' || dir === '' || dir === '.') {
return null;
} else {
return findParent(path.dirname(dir));
}
}
}
};

function normalizeModuleID(id) {
var parent = path.dirname(id);
var main = checkPkgMain(parent);
if(main && path.resolve(id)===path.resolve(path.join(parent, main))) {
id = parent;
var dir = exists(id) && fs.statSync(id).isDirectory() ? id : path.dirname(id);
parentCache[dir] = findParent(dir);
if(parentCache[dir]) {
var main = checkPkgMain(parentCache[dir]);
if(main && path.resolve(id)===path.resolve(path.join(parentCache[dir], main))) {
id = parentCache[dir];
}
}
id = id.replace(/\\/g, '/');

Expand Down
53 changes: 44 additions & 9 deletions global-cli/modifiers/util/EnactFrameworkRefPlugin.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
var
path = require('path'),
fs = require('fs'),
exists = require('path-exists').sync,
ExternalsPlugin = require('webpack/lib/ExternalsPlugin'),
DelegatedSourceDependency = require('webpack/lib/dependencies/DelegatedSourceDependency'),
DelegatedModule = require('webpack/lib/DelegatedModule');
Expand All @@ -11,14 +13,12 @@ function DelegatedEnactFactoryPlugin(options) {
}
DelegatedEnactFactoryPlugin.prototype.apply = function(normalModuleFactory) {
var name = this.options.name;
var libs = this.options.libraries;
var libReg = new RegExp('^(' + this.options.libraries.join('|') + ')(?=[\\\\\\/]|$)');
normalModuleFactory.plugin('factory', function(factory) {
return function(data, callback) {
var request = data.dependency.request;
for(var i=0; i<libs.length; i++) {
if(request && request.indexOf(libs[i]) === 0) {
return callback(null, new DelegatedModule(name, request, 'require', request));
}
if(request && libReg.test(request)) {
return callback(null, new DelegatedModule(name, request, 'require', request));
}
return factory(data, callback);
};
Expand All @@ -34,6 +34,30 @@ function normalizePath(dir, file, compiler) {
}
}

function isNodeOutputFS(compiler) {
try {
var NodeOutputFileSystem = require('webpack/lib/node/NodeOutputFileSystem');
return (compiler.outputFileSystem.writeFile===NodeOutputFileSystem.prototype.writeFile);
} catch(e) {
console.error('SnapshotPlugin loader is not compatible with standalone global installs of Webpack.');
return false;
}
}

function updateAppInfo(output, blob) {
var appInfo = path.join(output, 'appinfo.json');
if(exists(appInfo)) {
try {
var meta = JSON.parse(fs.readFileSync(appInfo, {encoding:'utf8'}));
meta.v8SnapshotFile = blob;
fs.writeFileSync(appInfo, JSON.stringify(meta, null, '\t'), {encoding:'utf8'});
} catch(e) {
return new Error('Failed to set "v8SnapshotFile" property in appinfo.json');
}
}
}


// Reference plugin to handle rewiring the external Enact framework requests
function EnactFrameworkRefPlugin(opts) {
this.options = opts || {};
Expand Down Expand Up @@ -63,13 +87,14 @@ EnactFrameworkRefPlugin.prototype.apply = function(compiler) {
compilation.dependencyFactories.set(DelegatedSourceDependency, normalModuleFactory);

compilation.plugin('html-webpack-plugin-alter-chunks', function(chunks, params) {
var chunkFiles = [ normalizePath(external.inject, 'enact.css', compiler) ];
if(!external.snapshot) {
chunkFiles.unshift(normalizePath(external.inject, 'enact.js', compiler));
}
// Add the framework files as a pseudo-chunk so they get injected into the HTML
chunks.unshift({
names: ['enact_framework'],
files: [
normalizePath(external.inject, 'enact.js', compiler),
normalizePath(external.inject, 'enact.css', compiler)
]
files: chunkFiles
});

// Store the absolute filepath to the external framework so the PrerenderPlugin can use it
Expand All @@ -85,4 +110,14 @@ EnactFrameworkRefPlugin.prototype.apply = function(compiler) {
libraries: libs,
}));
});

if(external.snapshot) {
compiler.plugin('after-emit', function(compilation, callback) {
var err;
if(isNodeOutputFS(compiler)) {
err = updateAppInfo(compiler.options.output.path, normalizePath(external.inject, 'snapshot_blob.bin', compiler));
}
callback(err);
});
}
};
Loading

0 comments on commit ddd092e

Please sign in to comment.