Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into serviveworker
# Conflicts: # package.json
- Loading branch information
Showing
23 changed files
with
310 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
var colors = require("colors"); | ||
var through = require("through2"); | ||
var keys = require("lodash/keys"); | ||
var omit = require("lodash/omit"); | ||
var defaultTo = require("lodash/defaultTo"); | ||
var isPluginExcludedFromBuild = require("../node/is_plugin_excluded"); | ||
|
||
module.exports = function() { | ||
return through.obj(function(data, enc, next) { | ||
try { | ||
next(null, addAtLoaderShim(data)); | ||
} catch (err) { | ||
next(err); | ||
} | ||
}); | ||
}; | ||
|
||
/** | ||
* Adds a node to the graph with an "@steal" shim | ||
* @param {Object} data - The slim stream data object | ||
* @return {Object} The mutated stream object | ||
*/ | ||
function addAtLoaderShim(data) { | ||
var graph = omit(data.graph, data.loader.configMain); | ||
|
||
if (includesAtSteal(graph)) { | ||
console.log( | ||
colors.yellow( | ||
`Warning: the @steal module is not fully supported in optimized builds` | ||
) | ||
); | ||
data.graph["@steal"] = makeShimNode(data.loader.main); | ||
} | ||
|
||
return data; | ||
} | ||
|
||
/** | ||
* Looks for "@steal" in the dependency graph | ||
* @param {Object} graph - The dependency graph | ||
* @return {boolean} true if found, false otherwise | ||
*/ | ||
function includesAtSteal(graph) { | ||
var found = false; | ||
|
||
var isAtSteal = function(name) { | ||
return name === "@steal"; | ||
}; | ||
|
||
keys(graph).forEach(function(name) { | ||
var node = graph[name]; | ||
|
||
if (isPluginExcludedFromBuild(node)) { | ||
return; | ||
} | ||
|
||
if (isAtSteal(name)) { | ||
return (found = true); | ||
} | ||
|
||
defaultTo(node.dependencies, []).forEach(function(depName) { | ||
if (isAtSteal(depName)) { | ||
return (found = true); | ||
} | ||
}); | ||
}); | ||
|
||
return found; | ||
} | ||
|
||
/** | ||
* Returns an @steal shim graph node | ||
* @param {string} main - The main module name | ||
* @return {Object} The faux "@steal" graph node | ||
*/ | ||
function makeShimNode(main) { | ||
return { | ||
bundles: [main], | ||
dependencies: ["@loader"], | ||
deps: ["@loader"], | ||
load: { | ||
address: "", | ||
metadata: { | ||
format: "amd", | ||
deps: ["@loader"], | ||
dependencies: ["@loader"] | ||
}, | ||
name: "@steal", | ||
source: ` | ||
define("@steal", ["@loader"], function(atLoader) { | ||
var steal = {}; | ||
steal.loader = atLoader; | ||
steal.done = function() { | ||
return Promise.resolve(); | ||
}; | ||
return steal; | ||
}); | ||
` | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,42 @@ | ||
var through = require("through2"); | ||
var omit = require("lodash/omit"); | ||
var clone = require("lodash/clone"); | ||
var assign = require("lodash/assign"); | ||
|
||
module.exports = function(options) { | ||
return through.obj(function(data, enc, next) { | ||
try { | ||
next(null, adjustBundlesPath(data, options)); | ||
next(null, options.target ? adjustBundlesPath(data, options) : data); | ||
} catch (err) { | ||
next(err); | ||
} | ||
}); | ||
}; | ||
|
||
/** | ||
* Appends the target name to the bundles path | ||
* | ||
* Each target build should be written in its own subfolder, e.g: | ||
* | ||
* dist/bundles/node | ||
* dist/bundles/web | ||
* dist/bundles/worker | ||
* | ||
* This should only happen when target is explicitly set. | ||
*/ | ||
function adjustBundlesPath(data, options) { | ||
if (options.target) { | ||
var path = require("path"); | ||
var path = require("path"); | ||
var configuration = clone(data.configuration); | ||
|
||
// override the configuration getter for `bundlesPath` so it | ||
// includes the target name | ||
var bundlesPath = data.configuration.bundlesPath; | ||
Object.defineProperty(data.configuration, "bundlesPath", { | ||
configurable: true, | ||
get: function() { | ||
return path.join(bundlesPath, options.target); | ||
} | ||
}); | ||
} | ||
var bundlesPath = configuration.bundlesPath; | ||
Object.defineProperty(configuration, "bundlesPath", { | ||
configurable: true, | ||
get: function() { | ||
return path.join(bundlesPath, options.target); | ||
} | ||
}); | ||
|
||
return data; | ||
return assign({}, omit(data, ["configuration"]), { | ||
configuration: configuration | ||
}); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.