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

Integrate zephyr dead code elimination #158

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "purs-loader",
"version": "3.7.2",
"description": "A webpack loader for PureScript.",
"main": "lib/index.js",
"main": "src/index.js",
"files": [
"LICENSE",
"README.md",
Expand Down
11 changes: 10 additions & 1 deletion src/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const debugVerbose = debug_('purs-loader:verbose');

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

const zephyr = require('./zephyr');

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

Expand All @@ -20,6 +22,7 @@ module.exports = function compile(psModule) {
const compileArgs = (options.psc ? [] : [ 'compile' ]).concat(dargs(Object.assign({
_: options.src,
output: options.output,
codegen: options.zephyr ? "js,corefn" : undefined
}, options.pscArgs)))

const stderr = [];
Expand Down Expand Up @@ -58,7 +61,13 @@ module.exports = function compile(psModule) {
if (options.warnings && warningMessage.length) {
psModule.emitWarning(warningMessage);
}
resolve(psModule)

// zephyr dead code elimination
if(options.zephyr) {
zephyr(psModule).then(resolve);
} else {
resolve(psModule)
}
}
})
});
Expand Down
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ module.exports = function purescriptLoader(source, map) {
bundle: false,
warnings: true,
watch: false,
zephyr: false,
output: outputPath,
src: []
}, loaderOptions, {
Expand Down
34 changes: 34 additions & 0 deletions src/zephyr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'use strict';

const Promise = require('bluebird');

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

const debug_ = require('debug');

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

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

const zephyrCommand = 'zephyr';
const zephyrArgs = [ psModule.name, "-i", options.output, "-o", options.output ];

debug('zephyr %s %O', zephyrCommand, zephyrArgs)

return new Promise((resolve, reject) => {
debug('Running zephyr...')

const zephyr = spawn(zephyrCommand, zephyrArgs)

zephyr.on('close', code => {
debug('finished compiling zephyr.')
if (code !== 0) {
psModule.emitError("Zephyr failed");
reject(new Error('Zephyr failed'))
} else {
resolve(psModule);
}
})
});
};