Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
start on babel module bundling and type inferrence
- Loading branch information
Showing
12 changed files
with
213 additions
and
98 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export default class Bundler { | ||
constructor(opts) { | ||
this.resolvers = []; | ||
this.cache = {}; | ||
this.opts = opts; | ||
} | ||
|
||
addResolver(resolver) { | ||
this.resolvers.push(resolver); | ||
} | ||
|
||
transform() { | ||
|
||
} | ||
} |
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,25 @@ | ||
import { Promise } from "bluebird"; | ||
import resolve from "resolve"; | ||
import path from "path"; | ||
import fs from "fs"; | ||
|
||
export default function (request, parent) { | ||
return new Promise(function (resolve, reject) { | ||
resolve(request, { basedir: path.dirname(parent) }, function (err, res) { | ||
if (err) { | ||
resolve(null); | ||
} else { | ||
fs.readFile(res, "utf8", function (err) { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve({ | ||
filename: filename, | ||
content: content | ||
}); | ||
} | ||
}); | ||
} | ||
}); | ||
}); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,34 @@ | ||
import normalizeAst from "../helpers/normalize-ast"; | ||
import Transformer from "./transformer"; | ||
import object from "../helpers/object"; | ||
import File from "./file"; | ||
import each from "lodash/collection/each"; | ||
import Pipeline from "./transformer-pipeline"; | ||
|
||
export default function transform(code: string, opts?: Object) { | ||
var file = new File(opts); | ||
return file.parse(code); | ||
} | ||
var pipeline = new Pipeline; | ||
|
||
transform.fromAst = function (ast, code, opts) { | ||
ast = normalizeAst(ast); | ||
// | ||
|
||
var file = new File(opts); | ||
file.addCode(code); | ||
file.transform(ast); | ||
return file.generate(); | ||
}; | ||
import transformers from "./transformers"; | ||
pipeline.addTransformers(transformers); | ||
|
||
transform._ensureTransformerNames = function (type: string, rawKeys: Array<string>) { | ||
var keys = []; | ||
// | ||
|
||
for (var i = 0; i < rawKeys.length; i++) { | ||
var key = rawKeys[i]; | ||
import deprecated from "./transformers/deprecated"; | ||
pipeline.addDeprecated(deprecated); | ||
|
||
var deprecatedKey = transform.deprecatedTransformerMap[key]; | ||
var aliasKey = transform.aliasTransformerMap[key]; | ||
if (aliasKey) { | ||
keys.push(aliasKey); | ||
} else if (deprecatedKey) { | ||
// deprecated key, remap it to the new one | ||
console.error(`The transformer ${key} has been renamed to ${deprecatedKey}`); | ||
rawKeys.push(deprecatedKey); | ||
} else if (transform.transformers[key]) { | ||
// valid key | ||
keys.push(key); | ||
} else if (transform.namespaces[key]) { | ||
// namespace, append all transformers within this namespace | ||
keys = keys.concat(transform.namespaces[key]); | ||
} else { | ||
// invalid key | ||
throw new ReferenceError(`Unknown transformer ${key} specified in ${type}`); | ||
} | ||
} | ||
// | ||
|
||
return keys; | ||
}; | ||
import aliases from "./transformers/aliases"; | ||
pipeline.addDeprecated(aliases); | ||
|
||
transform.transformerNamespaces = object(); | ||
transform.transformers = object(); | ||
transform.namespaces = object(); | ||
// | ||
|
||
transform.deprecatedTransformerMap = require("./transformers/deprecated"); | ||
transform.aliasTransformerMap = require("./transformers/aliases"); | ||
transform.moduleFormatters = require("./modules"); | ||
import * as filters from "./transformers/filters"; | ||
pipeline.addFilter(filters.internal); | ||
pipeline.addFilter(filters.blacklist); | ||
pipeline.addFilter(filters.whitelist); | ||
pipeline.addFilter(filters.stage); | ||
pipeline.addFilter(filters.optional); | ||
|
||
import rawTransformers from "./transformers"; | ||
// | ||
|
||
each(rawTransformers, function (transformer, key) { | ||
var namespace = key.split(".")[0]; | ||
|
||
transform.namespaces[namespace] = transform.namespaces[namespace] || []; | ||
transform.namespaces[namespace].push(key); | ||
transform.transformerNamespaces[key] = namespace; | ||
|
||
transform.transformers[key] = new Transformer(key, transformer); | ||
}); | ||
var transform = pipeline.transform.bind(pipeline); | ||
transform.fromAst = pipeline.transformFromAst.bind(pipeline); | ||
transform.pipeline = pipeline; | ||
export default transform; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import Transformer from "./transformer"; | ||
import normalizeAst from "../helpers/normalize-ast"; | ||
import Bundler from "./bundler"; | ||
import assign from "lodash/object/assign"; | ||
import object from "../helpers/object"; | ||
import File from "./file"; | ||
|
||
export default class TransformerPipeline { | ||
constructor() { | ||
this.transformers = object(); | ||
this.namespaces = object(); | ||
this.deprecated = object(); | ||
this.aliases = object(); | ||
this.filters = []; | ||
} | ||
|
||
addTransformers(transformers) { | ||
for (var key in transformers) { | ||
this.addTransformer(key, transformers[key]); | ||
} | ||
return this; | ||
} | ||
|
||
addTransformer(key, transformer) { | ||
if (this.transformers[key]) throw new Error(); // todo: error | ||
|
||
var namespace = key.split(".")[0]; | ||
this.namespaces[namespace] = this.namespaces[namespace] || []; | ||
this.namespaces[namespace].push(key); | ||
this.namespaces[key] = namespace; | ||
|
||
this.transformers[key] = new Transformer(key, transformer); | ||
} | ||
|
||
addAliases(names) { | ||
assign(this.aliases, names); | ||
return this; | ||
} | ||
|
||
addDeprecated(names) { | ||
assign(this.deprecated, names); | ||
return this; | ||
} | ||
|
||
addFilter(filter: Function) { | ||
this.filters.push(filter); | ||
return this; | ||
} | ||
|
||
canTransform(transformer, fileOpts) { | ||
for (var filter of (this.filters: Array)) { | ||
var result = filter(transformer, fileOpts); | ||
if (result != null) return result; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
transform(code: string, opts?: Object) { | ||
var file = new File(opts, this); | ||
return file.parse(code); | ||
} | ||
|
||
transformFromAst(ast, code, opts) { | ||
ast = normalizeAst(ast); | ||
|
||
var file = new File(opts, this); | ||
file.addCode(code); | ||
file.transform(ast); | ||
return file.generate(); | ||
} | ||
|
||
createBundler() { | ||
return new Bundler(this); | ||
} | ||
|
||
_ensureTransformerNames(type: string, rawKeys: Array<string>) { | ||
var keys = []; | ||
|
||
for (var i = 0; i < rawKeys.length; i++) { | ||
var key = rawKeys[i]; | ||
|
||
var deprecatedKey = this.deprecated[key]; | ||
var aliasKey = this.aliases[key]; | ||
if (aliasKey) { | ||
keys.push(aliasKey); | ||
} else if (deprecatedKey) { | ||
// deprecated key, remap it to the new one | ||
console.error(`The transformer ${key} has been renamed to ${deprecatedKey}`); | ||
rawKeys.push(deprecatedKey); | ||
} else if (this.transformers[key]) { | ||
// valid key | ||
keys.push(key); | ||
} else if (this.namespaces[key]) { | ||
// namespace, append all transformers within this namespace | ||
keys = keys.concat(this.namespaces[key]); | ||
} else { | ||
// invalid key | ||
throw new ReferenceError(`Unknown transformer ${key} specified in ${type}`); | ||
} | ||
} | ||
|
||
return keys; | ||
} | ||
} |
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.
aaf4cbf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this commit
ember s
breaks with and endless ... (ember-cli v0.2.3 & node v0.12.0)aaf4cbf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aaf4cbf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, but
ember s
never comes up, it's just returns to the console prompt after endless of this messages...aaf4cbf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a workaround? This is breaking our CI process
aaf4cbf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aaf4cbf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aaf4cbf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't get me wrong, I don't want you to do anything you don't want to do :) It's just that all that are referencing this module use
"^5.0.0"
which get's this version and even if I stay on 5.0.0 it doesn't workaaf4cbf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it was not happening yesterday that's my point, and i see you commited this 10h ago, so this fit's in the time range
aaf4cbf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aaf4cbf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AMAZING!!! 👍 You made my day man :)
and believe me this would have bitten more people, it's just that it was 10hours out only :)
aaf4cbf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks so much again for the quick response
aaf4cbf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aaf4cbf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.