Ejemplo n.º 1
0
		transformActiveSource(node, key(options, outputFormat), function(node, source){
			var opts = Object.assign({}, options, {
				forceES5: loader.forceES5 !== false
			});
			var depMap = nodeDependencyMap(node);

			// this options is used by steal-tools transform
			if(opts.useNormalizedDependencies) {
				opts.normalizeMap = depMap;
			}

			// slim builds should use normalized modules names when numeric ids
			// cannot be assigned during the build. E.g: steal-conditional
			if (isOptimizedBuild(opts)) {
				opts.normalizeMap = loader.normalizeMap;
			}

			opts.transpiler = loader.transpiler || "babel"; // Babel is the default in Steal 1.x
			if(loader.babelOptions) {
				opts.babelOptions = loader.babelOptions;
				var npmPkg = node.load.metadata.npmPackage;
				if(npmPkg) {
					var pkgSteal = npmPkg.steal || npmPkg.system;
					if(pkgSteal && pkgSteal.babelOptions) {
						opts.babelOptions = pkgSteal.babelOptions;
					}
				}

				opts.babelOptions.presets = processBabelPresets({
					baseURL: loader.baseURL,
					babelOptions: opts.babelOptions,
					loaderEnv: loader.getEnv()
				});

				opts.babelOptions.plugins = processBabelPlugins({
					baseURL: loader.baseURL,
					babelOptions: opts.babelOptions,
					loaderEnv: loader.getEnv()
				});
			}
			// make sure load has activeSource
			var load = Object.assign({}, node.load);
			load.source = source.code || load.source;
			// Minify globals prior to transpiling because they can't
			// be minified after they become a System.define.
			if(load.metadata.format === "global" && options.minify) {
				load.source = minify({ code: load.source }, options).code;
			}
			// I'm not sure how to handle defined.  "less" is an example of something we
			// define.  Presumably these should all be ignored.
			// also ignore any non js build type ... for now ...!
			// also ignore modules that will not bundled (metadata => bundle: false), we can skip transpiling into AMD
			var buildType = load.metadata.buildType || "js";
			if(load.metadata.format === "defined" ||
				buildType !== "js" ||
				(load.metadata.hasOwnProperty('bundle') && load.metadata.bundle === false)) {
				return source;
			}
			if(opts.sourceMapPath) {
				opts.baseURL = opts.sourceMapPath;
			}
			if(opts.normalize) {
				var givenNormalize = opts.normalize;
				opts.normalize = function(name, curName){
					// if name === curName ... it's asking to normalize the current module's name
					// for something like define('component/component',[...])
					// component/component won't be in depMap.
					var isDefining = name === curName;
					var depLoad;
					if(isDefining) {
						depLoad = load;
					} else {
						var normalizedName = options.useNormalizedDependencies ?
							name : (depMap[name] || name);
						var depNode = graph[normalizedName];
						if(depNode) {
							depLoad = depNode.load;
						}
					}
					return givenNormalize.call(this, name, depLoad, curName,
											   load, loader, isDefining);
				};
			}
			try {
				return transpile.to(load, outputFormat, opts);
			} catch(err) {
				var message = "Unable to transpile " + load.name + ": \n\n" +
					err.message;
				err.message = message;
				throw err;
			}
		});
Ejemplo n.º 2
0
		transformActiveSource(node,key(options, outputFormat),function(node, source){

			var opts = _.clone(options);
			var depMap = nodeDependencyMap(node);

			if(opts.useNormalizedDependencies) {
				opts.normalizeMap = depMap;
			}
			if(loader.transpiler) {
				opts.transpiler = loader.transpiler;
			}
			if(loader.babelOptions) {
				opts.babelOptions = loader.babelOptions;
			}
			// make sure load has activeSource
			var load = _.clone(node.load, true);
			load.source = source.code || load.source;
			// Minify globals prior to transpiling because they can't
			// be minified after they become a System.define.
			if(load.metadata.format === "global" && options.minify) {
				load.source = minify({ code: load.source }, options).code;
			}
			// I'm not sure how to handle defined.  "less" is an example of something we
			// define.  Presumably these should all be ignored.
			// also ignore any non js build type ... for now ...!
			// also ignore modules that will not bundled (metadata => bundle: false), we can skip transpiling into AMD
			var buildType = load.metadata.buildType || "js";
			if(load.metadata.format === "defined" ||
				buildType !== "js" ||
				(load.metadata.hasOwnProperty('bundle') && load.metadata.bundle === false)) {
				return source;
			}
			if(opts.sourceMapPath) {
				opts.baseURL = opts.sourceMapPath;
			}
			if(opts.normalize) {

				var givenNormalize = opts.normalize;
				opts.normalize = function(name, curName){
					// if name === curName ... it's asking to normalize the current module's name
					// for something like define('component/component',[...])
					// component/component won't be in depMap.
					var depLoad;
					if(name === curName) {
						depLoad = load;
					} else {
						var normalizedName = options.useNormalizedDependencies ? name : depMap[name];
						var depNode = graph[normalizedName];
						if(depNode) {
							depLoad = depNode.load;
						}
					}
					return givenNormalize.call(this, name, depLoad, curName, load, loader);
				};
			}
			try {
				return transpile.to(load, outputFormat, opts);
			} catch(err) {
				var message = "Unable to transpile " + load.name + ": \n\n" +
					err.message;
				err.message = message;
				throw err;
			}
		});