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

Protect from empty options and adding schema-utils and loader-utils as a dependency, also remove console output #2

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[![Build Status](https://travis-ci.org/kmontag/protobufjs-loader.svg?branch=master)](https://travis-ci.org/kmontag/protobufjs-loader)
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)

# protobufjs-loader
# protobuf-preloader
Webpack loader to translate
[protobuf](https://github.com/google/protobuf/) definitions to
[ProtoBuf.js](https://github.com/dcodeIO/ProtoBuf.js/)
Expand All @@ -28,7 +28,7 @@ module.exports = {
rules: [{
test: /\.proto$/,
use: {
loader: 'protobufjs-loader',
loader: 'protobuf-preloader',
options: {
/* controls the "target" flag to pbjs - true for
* json-module, false for static-module.
Expand Down
9 changes: 4 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const fs = require('fs');
const path = require('path');
const loaderUtils = require("loader-utils");
const pbjs = require('protobufjs/cli').pbjs;
const protobuf = require('protobufjs');
const tmp = require('tmp-promise');
Expand Down Expand Up @@ -32,15 +31,16 @@ const schema = {
module.exports = function(source) {
let callback = this.async();
let self = this;
let loaderOptions = loaderUtils.getOptions(this)
// When the options is empty create an empty object instend getting null
let loaderOptions = getOptions(this) || {};
const options = Object.assign({
json: false,
// Default to the paths given to the compiler (this.options is the
// webpack options object)
paths: loaderOptions.paths || [],

pbjsArgs: [],
}, getOptions(this));
}, loaderOptions);
validateOptions(schema, options, 'protobufjs-loader');

let filename;
Expand Down Expand Up @@ -114,9 +114,8 @@ module.exports = function(source) {
loadDependencies.catch(function(depErr) {
callback(depErr);
}).then(function() {
console.dir(result)
callback(err, result);
});
});
});
};
};
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "protobufjs-loader-webpack4",
"name": "protobuf-preloader",
"version": "0.0.1",
"description": "Webpack loader to translate .proto definitions to ProtoBuf.js modules",
"main": "index.js",
Expand All @@ -17,7 +17,9 @@
"license": "MIT",
"dependencies": {
"protobufjs": "^6.8.0",
"tmp-promise": "^1.0.4"
"tmp-promise": "^1.0.4",
"loader-utils": "^1.2.3",
"schema-utils": "^1.0.0"
},
"devDependencies": {
"chai": "^4.1.2",
Expand Down Expand Up @@ -45,6 +47,6 @@
},
"repository": {
"type": "git",
"url": "https://github.com/PermissionData/protobufjs-loader.git"
"url": "https://github.com/moshe-kabala/protobufjs-loader"
}
}