Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issue/61: split('/n') does not work on Windows #89

Merged
merged 3 commits into from
May 30, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions loader.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
"use strict";

const os = require('os');
const gql = require('./src');

// Takes `source` (the source GraphQL query string)
// and `doc` (the parsed GraphQL document) and tacks on
// the imported definitions.
function expandImports(source, doc) {
const lines = source.split('\n');
const lines = source.split(os.EOL);
let outputCode = `
var names = {};
function unique(defs) {
Expand All @@ -30,7 +31,7 @@ function expandImports(source, doc) {
const importFile = line.slice(1).split(' ')[1];
const parseDocument = `require(${importFile})`;
const appendDef = `doc.definitions = doc.definitions.concat(unique(${parseDocument}.definitions));`;
outputCode += appendDef + "\n";
outputCode += appendDef + os.EOL;
}
return (line.length !== 0 && line[0] !== '#');
});
Expand All @@ -47,5 +48,5 @@ module.exports = function(source) {
`;
const importOutputCode = expandImports(source, doc);

return outputCode + "\n" + importOutputCode + "\n" + `module.exports = doc;`;
return outputCode + os.EOL + importOutputCode + os.EOL + `module.exports = doc;`;
};
5 changes: 3 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const os = require('os');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dnalborczyk will this work in the browser environment? Does webpack polyfill this when prepublish is run?

Copy link
Contributor Author

@dnalborczyk dnalborczyk May 29, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the 'os' module does work in webpack. it's using: https://github.com/webpack/node-libs-browser, which in turn uses: https://github.com/CoderPuppy/os-browserify. that being said, I'm not so sure anymore if that is the right approach for src/index.js, since the new line escape sequence is always '\n', no matter which browser. though if src/index.js is only meant to run from within webpack, it might as well be fine. I can also revert the PR for src/index.js if it's more suitable ...

var parser = require('graphql/language/parser');

var parse = parser.parse;
Expand Down Expand Up @@ -45,8 +46,8 @@ function processFragments(ast) {
// this is a problem because the app developer is trying to register another fragment with
// the same name as one previously registered. So, we tell them about it.
if (printFragmentWarnings) {
console.warn("Warning: fragment with name " + fragmentName + " already exists.\n"
+ "graphql-tag enforces all fragment names across your application to be unique; read more about\n"
console.warn("Warning: fragment with name " + fragmentName + " already exists." + os.EOL +
+ "graphql-tag enforces all fragment names across your application to be unique; read more about" + os.EOL +
+ "this in the docs: http://dev.apollodata.com/core/fragments.html#unique-names");
}

Expand Down