Skip to content
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
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# http://editorconfig.org/

root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 2
trim_trailing_whitespace = true
38 changes: 38 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
root: true

env:
node: true
es6: true
es2017: true

extends: standard

parserOptions:
ecmaVersion: 2020

rules:
array-bracket-spacing:
- error
- always
array-callback-return: error
comma-dangle:
- error
- always-multiline
eqeqeq:
- error
- smart
guard-for-in: error
no-multiple-empty-lines:
- error
-
max: 2
maxEOF: 0
no-return-assign: error
no-useless-concat: error
space-before-function-paren:
- error
- never
quotes:
- error
- double
- avoid-escape
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
"scripts": {
"build": "babel src --out-dir lib",
"prepublish": "npm run build",
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"lint": "eslint src/",
"lint:fix": "eslint --fix src/"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -48,6 +50,8 @@
},
"devDependencies": {
"babel-cli": "^6.8.0",
"babel-preset-es2015": "^6.6.0"
"babel-preset-es2015": "^6.6.0",
"eslint": "^7.1.0",
"eslint-config-standard": "^14.1.1"
}
}
48 changes: 23 additions & 25 deletions src/bundle.js
Original file line number Diff line number Diff line change
@@ -1,59 +1,57 @@
'use strict';
"use strict"

const path = require('path');
const path = require("path")

const Promise = require('bluebird')
const Promise = require("bluebird")

const fs = Promise.promisifyAll(require('fs'))
const fs = Promise.promisifyAll(require("fs"))

const spawn = require('cross-spawn')
const spawn = require("cross-spawn")

const debug = require('debug')('purs-loader');
const debug = require("debug")("purs-loader")

const dargs = require('./dargs');
const dargs = require("./dargs")

module.exports = function bundle(options, bundleModules) {
const stdout = []

const stderr = []

const bundleCommand = options.pscBundle || 'purs';
const bundleCommand = options.pscBundle || "purs"

const bundleArgs = (options.pscBundle ? [] : [ 'bundle' ]).concat(dargs(Object.assign({
_: [path.join(options.output, '*', '*.js')],
const bundleArgs = (options.pscBundle ? [] : [ "bundle" ]).concat(dargs(Object.assign({
_: [ path.join(options.output, "*", "*.js") ],
output: options.bundleOutput,
namespace: options.bundleNamespace,
}, options.pscBundleArgs)));
}, options.pscBundleArgs)))

bundleModules.forEach(name => bundleArgs.push('--module', name))
bundleModules.forEach(name => bundleArgs.push("--module", name))

debug('bundle: %s %O', bundleCommand, bundleArgs);
debug("bundle: %s %O", bundleCommand, bundleArgs)

return (new Promise((resolve, reject) => {
debug('bundling PureScript...')
debug("bundling PureScript...")

const compilation = spawn(bundleCommand, bundleArgs)

compilation.stdout.on('data', data => stdout.push(data.toString()))
compilation.stdout.on("data", data => stdout.push(data.toString()))

compilation.stderr.on('data', data => stderr.push(data.toString()))
compilation.stderr.on("data", data => stderr.push(data.toString()))

compilation.on('close', code => {
debug('finished bundling PureScript.')
compilation.on("close", code => {
debug("finished bundling PureScript.")

if (code !== 0) {
const errorMessage = stderr.join('');
const errorMessage = stderr.join("")

if (errorMessage.length) {
reject(new Error(`bundling failed: ${errorMessage}`))
} else {
reject(new Error("bundling failed"))
}
else {
reject(new Error('bundling failed'))
}
}
else {
} else {
resolve(fs.appendFileAsync(options.bundleOutput, `module.exports = ${options.bundleNamespace}`))
}
})
}))
};
}
59 changes: 29 additions & 30 deletions src/compile.js
Original file line number Diff line number Diff line change
@@ -1,65 +1,64 @@
'use strict';
"use strict"

const Promise = require('bluebird');
const Promise = require("bluebird")

const spawn = require('cross-spawn');
const spawn = require("cross-spawn")

const debug_ = require('debug');
const debug_ = require("debug")

const debug = debug_('purs-loader');
const debug = debug_("purs-loader")

const debugVerbose = debug_('purs-loader:verbose');
const debugVerbose = debug_("purs-loader:verbose")

const dargs = require('./dargs');
const dargs = require("./dargs")

module.exports = function compile(psModule) {
const options = psModule.options

const compileCommand = options.psc || 'purs';
const compileCommand = options.psc || "purs"

const compileArgs = (options.psc ? [] : [ 'compile' ]).concat(dargs(Object.assign({
const compileArgs = (options.psc ? [] : [ "compile" ]).concat(dargs(Object.assign({
_: options.src,
output: options.output,
}, options.pscArgs)))

const stderr = [];
const stderr = []

debug('compile %s %O', compileCommand, compileArgs)
debug("compile %s %O", compileCommand, compileArgs)

return new Promise((resolve, reject) => {
debug('compiling PureScript...')
debug("compiling PureScript...")

const compilation = spawn(compileCommand, compileArgs)

compilation.stderr.on('data', data => {
stderr.push(data.toString());
});
compilation.stderr.on("data", data => {
stderr.push(data.toString())
})

compilation.stdout.on('data', data => {
debugVerbose(data.toString());
});
compilation.stdout.on("data", data => {
debugVerbose(data.toString())
})

compilation.on('close', code => {
debug('finished compiling PureScript.')
compilation.on("close", code => {
debug("finished compiling PureScript.")

if (code !== 0) {
const errorMessage = stderr.join('');
const errorMessage = stderr.join("")
if (errorMessage.length) {
psModule.emitError(errorMessage);
psModule.emitError(errorMessage)
}
if (options.watch) {
resolve(psModule);
}
else {
reject(new Error('compilation failed'))
resolve(psModule)
} else {
reject(new Error("compilation failed"))
}
} else {
const warningMessage = stderr.join('');
const warningMessage = stderr.join("")
if (options.warnings && warningMessage.length) {
psModule.emitWarning(warningMessage);
psModule.emitWarning(warningMessage)
}
resolve(psModule)
}
})
});
};
})
}
10 changes: 5 additions & 5 deletions src/dargs.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';
"use strict"

const dargs = require('dargs');
const dargs = require("dargs")

module.exports = function(obj){
return dargs(obj, {ignoreFalse: true});
};
module.exports = function(obj) {
return dargs(obj, { ignoreFalse: true })
}
Loading