Skip to content
This repository was archived by the owner on Apr 22, 2021. It is now read-only.

Commit de878aa

Browse files
committed
Prettify all files
1 parent 61be757 commit de878aa

File tree

3 files changed

+30
-28
lines changed

3 files changed

+30
-28
lines changed

index.js

+14-9
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@ const { pathExists } = require('fs-extra');
44
const { getOptions, parseQuery } = require('loader-utils');
55

66
const {
7-
exec,
8-
readFile,
9-
wait,
10-
packageExist,
11-
which,
7+
exec, readFile, wait, packageExist, which,
128
} = require('./lib/util');
139
const { getConfig, getLocalDependencies } = require('./lib/truffle');
1410

@@ -24,15 +20,16 @@ module.exports = async function loader(source) {
2420
try {
2521
const params = parseQuery(this.resourceQuery || '?');
2622
const options = getOptions(this);
27-
const network = (options && options.network) ? options.network : 'development';
23+
const network = options && options.network ? options.network : 'development';
2824
const disabled = options && options.disabled;
2925
const contractFolderPath = this.context;
3026
const cwd = path.resolve(contractFolderPath, '..');
3127
const contractFilePath = this.resourcePath;
3228
const config = await getConfig({ network, cwd });
3329
const contractsBuildDirectory = config.contracts_build_directory;
3430
const contractFileName = path.basename(contractFilePath);
35-
const contractName = params.contract || contractFileName.charAt(0).toUpperCase() + contractFileName.slice(1, contractFileName.length - 4);
31+
const contractName = params.contract
32+
|| contractFileName.charAt(0).toUpperCase() + contractFileName.slice(1, contractFileName.length - 4);
3633
const compiledContractPath = path.resolve(contractsBuildDirectory, `${contractName}.json`);
3734

3835
// check if compiled contract exists
@@ -78,7 +75,12 @@ module.exports = async function loader(source) {
7875
isZeppelinBusy = false;
7976
}
8077
} else {
81-
callback(new Error(`${oz} is required to support solidity hot-loading. Please run "npm i -D ${oz}", or disable hot-loading.`), '{}');
78+
callback(
79+
new Error(
80+
`${oz} is required to support solidity hot-loading. Please run "npm i -D ${oz}", or disable hot-loading.`,
81+
),
82+
'{}',
83+
);
8284
// return because if zos not installed we should fail
8385
return;
8486
}
@@ -95,7 +97,10 @@ module.exports = async function loader(source) {
9597
// return result to webpack
9698
callback(null, solJSON);
9799
} else {
98-
callback(new Error(`The contract '${compiledContractPath}' doesn't exist. Try to compile your contracts first.`), '{}');
100+
callback(
101+
new Error(`The contract '${compiledContractPath}' doesn't exist. Try to compile your contracts first.`),
102+
'{}',
103+
);
99104
}
100105
} catch (e) {
101106
// report error here, because configuration seems to be lacking

lib/truffle.js

+5-9
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const findUp = require('find-up');
66
const flatten = require('array-flatten');
77
const pathIsInside = require('path-is-inside');
88

9-
109
const { readFile } = require('./util');
1110

1211
// Finds truffle conifg file path
@@ -46,16 +45,14 @@ const getLocalDependencies = async (sourceContract, contractsBuildDirectory, con
4645
const contract = JSON.parse(solJSON);
4746

4847
// grab all base contracts
49-
const baseContractNames = ((((contract.ast || {})
50-
.nodes || [])
51-
.filter(node => node.name === contractName)[0] || {})
52-
.baseContracts || [])
48+
const baseContractNames = (
49+
(((contract.ast || {}).nodes || []).filter(node => node.name === contractName)[0] || {}).baseContracts || []
50+
)
5351
// grab base contract name
5452
.map(node => node.baseName.name);
5553

5654
// test if it exists locally
57-
const localBaseContracts = (await Promise.all(baseContractNames
58-
.map(name => readFile(jsonFilePathByName(name)))))
55+
const localBaseContracts = (await Promise.all(baseContractNames.map(name => readFile(jsonFilePathByName(name)))))
5956
.map(json => JSON.parse(json))
6057
// filter all contracts which are not local
6158
.filter(cont => pathIsInside(cont.ast.absolutePath, contractsDirectory));
@@ -66,8 +63,7 @@ const getLocalDependencies = async (sourceContract, contractsBuildDirectory, con
6663
// get local contract filepath
6764
.map(cont => cont.ast.absolutePath),
6865
// call recursive on all local base contracts
69-
...flatten(await Promise.all(localBaseContracts
70-
.map(cont => helper(cont.contractName)))),
66+
...flatten(await Promise.all(localBaseContracts.map(cont => helper(cont.contractName)))),
7167
];
7268
};
7369

test/compiler.js

+11-10
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,17 @@ export default (fixture, options = {}) => {
1111
filename: 'bundle.js',
1212
},
1313
module: {
14-
rules: [{
15-
test: /\.sol$/,
16-
use: [
17-
{ loader: 'json-loader' },
18-
{
19-
loader: path.resolve(__dirname, '../index.js'),
20-
options,
21-
},
22-
],
23-
},
14+
rules: [
15+
{
16+
test: /\.sol$/,
17+
use: [
18+
{ loader: 'json-loader' },
19+
{
20+
loader: path.resolve(__dirname, '../index.js'),
21+
options,
22+
},
23+
],
24+
},
2425
],
2526
},
2627
});

0 commit comments

Comments
 (0)