babel-plugin-inline-import-graphql-ast
Advanced tools
Comparing version 2.0.1-beta.0 to 2.0.1-beta.1
@@ -9,11 +9,7 @@ Object.defineProperty(exports, "__esModule", { | ||
var _path2 = _interopRequireDefault(_path); | ||
var _os = require('os'); | ||
var _os2 = _interopRequireDefault(_os); | ||
var _fs = require('fs'); | ||
var _fs2 = _interopRequireDefault(_fs); | ||
var _babylon = require('babylon'); | ||
@@ -24,4 +20,2 @@ var _graphqlTag = require('graphql-tag'); | ||
var _babylon = require('babylon'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -33,2 +27,4 @@ | ||
var seenNames = {}; | ||
exports.default = function (_ref) { | ||
@@ -42,8 +38,2 @@ var t = _ref.types; | ||
if (importPath.endsWith('.graphql') || importPath.endsWith('.gql')) { | ||
var buildInlineVariable = function buildInlineVariable(graphqlAST) { | ||
var babelAST = (0, _babylon.parse)('const obj = ' + JSON.stringify(graphqlAST)); | ||
var objExp = babelAST.program.body[0].declarations[0].init; | ||
return t.variableDeclarator(t.identifier(curPath.node.specifiers[0].local.name), t.objectExpression(objExp.properties)); | ||
}; | ||
var query = createQuery(importPath, state.file.opts.filename); | ||
@@ -56,2 +46,8 @@ query.processFragments(); | ||
} | ||
function buildInlineVariable(graphqlAST) { | ||
var babelAST = (0, _babylon.parse)('const obj = ' + JSON.stringify(graphqlAST)); | ||
var objExp = babelAST.program.body[0].declarations[0].init; | ||
return t.variableDeclarator(t.identifier(curPath.node.specifiers[0].local.name), t.objectExpression(objExp.properties)); | ||
} | ||
} | ||
@@ -64,4 +60,4 @@ } | ||
function createQuery(queryPath, babelPath) { | ||
var absPath = _path2.default.resolve(_path2.default.dirname(babelPath), queryPath); | ||
var source = _fs2.default.readFileSync(absPath).toString(); | ||
var absPath = (0, _path.resolve)((0, _path.dirname)(babelPath), queryPath); | ||
var source = (0, _fs.readFileSync)(absPath).toString(); | ||
var ast = null; | ||
@@ -72,14 +68,24 @@ var fragmentDefs = []; | ||
processFragments: function processFragments() { | ||
var imports = source.split(_os2.default.EOL).filter(function (line) { | ||
return line.startsWith('#import'); | ||
}); | ||
imports.forEach(function (statement) { | ||
var fragmentPath = statement.split(' ')[1].slice(1, -1); | ||
var absFragmentPath = _path2.default.resolve(_path2.default.dirname(absPath), fragmentPath); | ||
var fragmentSource = _fs2.default.readFileSync(absFragmentPath).toString(); | ||
fragmentDefs = [].concat(_toConsumableArray(fragmentDefs), _toConsumableArray((0, _graphqlTag2.default)(_templateObject, fragmentSource).definitions)); | ||
}); | ||
processImports(getImportStatements(source), (0, _path.dirname)(absPath)); | ||
function getImportStatements(src) { | ||
return src.split(_os.EOL).filter(function (line) { | ||
return line.startsWith('#import'); | ||
}); | ||
} | ||
function processImports(imports, relDir) { | ||
imports.forEach(function (statement) { | ||
var fragmentPath = statement.split(' ')[1].slice(1, -1); | ||
var absFragmentPath = (0, _path.resolve)(relDir, fragmentPath); | ||
var fragmentSource = (0, _fs.readFileSync)(absFragmentPath).toString(); | ||
var subFragments = getImportStatements(fragmentSource); | ||
if (subFragments.length > 0) { | ||
processImports(subFragments, (0, _path.dirname)(absFragmentPath)); | ||
} | ||
fragmentDefs = [].concat(_toConsumableArray((0, _graphqlTag2.default)(_templateObject, fragmentSource).definitions), _toConsumableArray(fragmentDefs)); | ||
}); | ||
} | ||
}, | ||
dedupeFragments: function dedupeFragments() { | ||
var seenNames = {}; | ||
fragmentDefs = fragmentDefs.filter(function (def) { | ||
@@ -86,0 +92,0 @@ if (def.kind !== 'FragmentDefinition') return true; |
{ | ||
"name": "babel-plugin-inline-import-graphql-ast", | ||
"version": "2.0.1-beta.0", | ||
"version": "2.0.1-beta.1", | ||
"description": "Babel plugin to make raw files importable", | ||
@@ -8,14 +8,4 @@ "author": "Alexander Roberts <detrohutt@gmail.com>", | ||
"main": "build/index.js", | ||
"files": [ | ||
"build" | ||
], | ||
"keywords": [ | ||
"babel-plugin", | ||
"apollo", | ||
"graphql", | ||
"gql", | ||
"extension", | ||
"import", | ||
"inline" | ||
], | ||
"files": ["build"], | ||
"keywords": ["babel-plugin", "apollo", "graphql", "gql", "extension", "import", "inline"], | ||
"repository": "detrohutt/babel-plugin-inline-import-graphql-ast", | ||
@@ -34,7 +24,12 @@ "scripts": { | ||
"babel-core": "^6.14.0", | ||
"babel-eslint": "^6.1.2", | ||
"babel-eslint": "^7.2.3", | ||
"babel-preset-es2015-without-strict": "0.0.4", | ||
"babel-preset-stage-1": "^6.13.0", | ||
"chai": "^3.5.0", | ||
"eslint": "^3.4.0", | ||
"eslint": "^4.3.0", | ||
"eslint-config-standard": "^10.2.1", | ||
"eslint-plugin-import": "^2.2.0", | ||
"eslint-plugin-node": "^5.1.1", | ||
"eslint-plugin-promise": "^3.5.0", | ||
"eslint-plugin-standard": "^3.0.1", | ||
"mocha": "^3.0.2", | ||
@@ -41,0 +36,0 @@ "sinon": "^1.17.5" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10983
85
14