Skip to content

initial psc-package support #82

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

Merged
merged 8 commits into from
Feb 12, 2017
Merged

Conversation

develop7
Copy link
Contributor

@develop7 develop7 commented Feb 7, 2017

Initial and very basic support of psc-package. Sort of works with purescript-webpack-example (deps' paths are supplied to compiler, but compilation still fails)


This change is Reviewable

@ethul
Copy link
Owner

ethul commented Feb 7, 2017

Thank you for the PR! I will take a look and review this soon.

@ethul ethul self-requested a review February 8, 2017 03:42
README.md Outdated



Set `pscPackage` query parameter to `true` and delete `src` parameter to enable `psc-package` support
Copy link
Owner

Choose a reason for hiding this comment

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

Can we say remove or unset instead of delete here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure.

src/index.js Outdated
@@ -10,6 +10,8 @@ const PsModuleMap = require('./PsModuleMap');
const Psc = require('./Psc');
const PscIde = require('./PscIde');
const dargs = require('./dargs');
const execSync = require('child_process').execSync
Copy link
Owner

Choose a reason for hiding this comment

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

Just to ensure compatibility can we change this to cross-spawn? We run psc, etc., already with cross-spawn.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did notice you're using cross-spawn, and did honest try to run psc-package asynchronously, but ran into weird synchronization issue and decided to fall back to execSync. What I didn't try is to use cross-spawn's sync. On it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All right, my bad: I've forgot to remove src query parameter in webpack.config.js, that's why source paths have been ignore. I probably should add a warning about pscPackage being ignored if src is set.
So looks like there were no synchronization issues, just me.

src/index.js Outdated
bundleOutput: 'output/bundle.js',
bundleNamespace: 'PS',
bundle: false,
warnings: true,
output: 'output',
src: [
path.join('src', '**', '*.purs'),
path.join('bower_components', 'purescript-*', 'src', '**', '*.purs')
...depsPaths(query.pscPackage)
Copy link
Owner

Choose a reason for hiding this comment

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

Does npm run build work with the spread operator? We just have es2015 as the preset in the .babelrc. Do we need a babel plugin to support this?

Copy link
Contributor Author

@develop7 develop7 Feb 8, 2017

Choose a reason for hiding this comment

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

It totally did work for me, will look into it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All right, es2015 preset does include spread operator so the answer is no, we don't.

src/index.js Outdated
bundleModules: [],
warnings: [],
errors: []
}
Copy link
Owner

Choose a reason for hiding this comment

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

Sorry to be picky, but can we put the spacing back to what it was on lines 61 to 66. It looks like just an extra space (or two) has been added.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, that's IDEA being smartass, reverting. Is there some way to specify indents explicitly? .editorconfig maybe?

@ethul
Copy link
Owner

ethul commented Feb 8, 2017

Looking good. Just a few small comments. You mention it sort of works with the example. Are you still in-progress on this PR? Just curious. Thanks again!

@develop7
Copy link
Contributor Author

develop7 commented Feb 8, 2017

Thank you for the feedback!

You mention it sort of works with the example

Yes, this way:
image

 Are you still in-progress on this PR?

That depends of whether I need to implement adding psc-package-supplied paths to existing srcs. I'm just getting started with Purescript, so I'm not sure. Do I?

@develop7
Copy link
Contributor Author

develop7 commented Feb 8, 2017

And oh, there's no check for psc-package.json presence. Should it be added?

@develop7
Copy link
Contributor Author

develop7 commented Feb 8, 2017

OK, here's my attempt to use cross-spawn's sync:

const spawn = require('cross-spawn').sync
//...skip...
  const depsPaths = (pscPackage => {
    if (pscPackage) {
      debug('calling psc-package...')

      const paths = spawn('psc-package', ['sources']).stdout.toString().split(eol).filter(v => v != '');
      debug(paths)
      return paths
    }
    else {
      return [path.join('bower_components', 'purescript-*', 'src', '**', '*.purs')];
    }
  })
Here's the output:
$  npm run webpack:server:debug

> [email protected] webpack:server:debug /home/develop7/projects/purescript-webpack-example
> DEBUG=purs-loader webpack-dev-server --progress --inline --hot

 70% 1/1 build modules http://localhost:4008/
webpack result is served from /
content is served from .
 40% 4/8 build modules  purs-loader calling psc-package... +0ms
  purs-loader [ '.psc-package/psc-0.10.5/arrays/v3.1.0/src/**/*.purs',
  purs-loader   '.psc-package/psc-0.10.5/bifunctors/v2.0.0/src/**/*.purs',
  purs-loader   '.psc-package/psc-0.10.5/console/v2.0.0/src/**/*.purs',
  purs-loader   '.psc-package/psc-0.10.5/control/v2.0.0/src/**/*.purs',
  purs-loader   '.psc-package/psc-0.10.5/datetime/v2.0.0/src/**/*.purs',
  purs-loader   '.psc-package/psc-0.10.5/distributive/v2.0.0/src/**/*.purs',
  purs-loader   '.psc-package/psc-0.10.5/dom/v3.3.1/src/**/*.purs',
  purs-loader   '.psc-package/psc-0.10.5/eff/v2.0.0/src/**/*.purs',
  purs-loader   '.psc-package/psc-0.10.5/eff-functions/v2.0.0/src/**/*.purs',
  purs-loader   '.psc-package/psc-0.10.5/either/v2.1.0/src/**/*.purs',
  purs-loader   '.psc-package/psc-0.10.5/enums/v2.0.1/src/**/*.purs',
  purs-loader   '.psc-package/psc-0.10.5/exceptions/v2.0.0/src/**/*.purs',
  purs-loader   '.psc-package/psc-0.10.5/foldable-traversable/v2.0.0/src/**/*.purs',
  purs-loader   '.psc-package/psc-0.10.5/foreign/v3.0.1/src/**/*.purs',
  purs-loader   '.psc-package/psc-0.10.5/functions/v2.0.0/src/**/*.purs',
  purs-loader   '.psc-package/psc-0.10.5/generics/v3.2.0/src/**/*.purs',
  purs-loader   '.psc-package/psc-0.10.5/identity/v2.0.0/src/**/*.purs',
  purs-loader   '.psc-package/psc-0.10.5/integers/v2.1.0/src/**/*.purs',
  purs-loader   '.psc-package/psc-0.10.5/invariant/v2.0.0/src/**/*.purs',
  purs-loader   '.psc-package/psc-0.10.5/js-date/v3.0.0/src/**/*.purs',
  purs-loader   '.psc-package/psc-0.10.5/lazy/v2.0.0/src/**/*.purs',
  purs-loader   '.psc-package/psc-0.10.5/lists/v3.3.0/src/**/*.purs',
  purs-loader   '.psc-package/psc-0.10.5/math/v2.0.0/src/**/*.purs',
  purs-loader   '.psc-package/psc-0.10.5/maybe/v2.0.1/src/**/*.purs',
  purs-loader   '.psc-package/psc-0.10.5/media-types/v2.0.0/src/**/*.purs',
  purs-loader   '.psc-package/psc-0.10.5/monoid/v2.2.0/src/**/*.purs',
  purs-loader   '.psc-package/psc-0.10.5/newtype/v1.1.0/src/**/*.purs',
  purs-loader   '.psc-package/psc-0.10.5/nonempty/v3.0.0/src/**/*.purs',
  purs-loader   '.psc-package/psc-0.10.5/nullable/v2.0.0/src/**/*.purs',
  purs-loader   '.psc-package/psc-0.10.5/partial/v1.2.0/src/**/*.purs',
  purs-loader   '.psc-package/psc-0.10.5/prelude/v2.1.0/src/**/*.purs',
  purs-loader   '.psc-package/psc-0.10.5/proxy/v1.0.0/src/**/*.purs',
  purs-loader   '.psc-package/psc-0.10.5/react/v2.0.0/src/**/*.purs',
  purs-loader   '.psc-package/psc-0.10.5/react-dom/v2.0.0/src/**/*.purs',
  purs-loader   '.psc-package/psc-0.10.5/st/v2.0.0/src/**/*.purs',
  purs-loader   '.psc-package/psc-0.10.5/strings/v2.1.0/src/**/*.purs',
  purs-loader   '.psc-package/psc-0.10.5/tailrec/v2.0.1/src/**/*.purs',
  purs-loader   '.psc-package/psc-0.10.5/transformers/v2.0.2/src/**/*.purs',
  purs-loader   '.psc-package/psc-0.10.5/tuples/v3.0.0/src/**/*.purs',
  purs-loader   '.psc-package/psc-0.10.5/unfoldable/v2.0.0/src/**/*.purs',
  purs-loader   '.psc-package/psc-0.10.5/unsafe-coerce/v2.0.0/src/**/*.purs' ] +26ms
  purs-loader loader called Example +9ms
  purs-loader spawning compiler psa [ '--output=output', 'src/**/*.purs' ] +1ms
  purs-loader compiling PureScript... +1ms
 69% 77/78 build modules  purs-loader finished compiling PureScript. +565ms
                            
ERROR in ./src/Example.purs
Module build failed: Error: compilation failed
    at ChildProcess.<anonymous> (/home/develop7/projects/purs-loader/lib/Psc.js:48:16)
    at emitTwo (events.js:106:13)
    at ChildProcess.emit (events.js:192:7)
    at maybeClose (internal/child_process.js:890:16)
    at Socket.<anonymous> (internal/child_process.js:334:11)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:189:7)
    at Pipe._handle.close [as _onclose] (net.js:501:12)
 @ multi main

ERROR in [1/1 UnknownName] src/Example/Footer.purs:3:1

  3  import Prelude (Unit)
     ^^^^^^^^^^^^^^^^^^^^^
  
  Unknown module Prelude

           Src   Lib   All
Warnings   0     0     0  
Errors     1     0     1  

Note the source paths have been retrieved but weren't passed to psc. That's the weird synchronization issue I've mentioned before. So no luck so far. Am I missing something?

@develop7 develop7 force-pushed the feature/psc-package branch from 30d7b86 to 081c17d Compare February 10, 2017 10:45
@develop7
Copy link
Contributor Author

@ethul all right, seems to be ready to roll. I've added a warning that pscPackage is ignored when src is set, not sure it matches the overall style.

To be compatible with user-supplied paths and be less intrusive, I probably should extract psc-package support to a webpack plugin (shipped with purs-loader, but still), but that seems to be another story.

Thank you in advance.

@ethul
Copy link
Owner

ethul commented Feb 10, 2017

Thanks so much for working on this and making all of the updates! This is looking great. I will go through it over the weekend. Thanks again.

@ethul
Copy link
Owner

ethul commented Feb 11, 2017

I think the changes look good. However, after thinking about this more, I wonder if the psc-package functionality should append the results of running psc-package sources to the the user-supplied src configuration parameter.

Consider the following cases:

  • If pscPackage: false, then the current purs-loader behaviour remains; i.e., the user can custom define the src parameter, and if they do not define it then the value for the src is
src: [
  path.join('src', '**', '*.purs'),
  path.join('bower_components', 'purescript-*', 'src', '**', '*.purs')
]
  • If pscPackage: true and the user does not specify the src parameter, then the value for the src is
src: [
  path.join('src', '**', '*.purs'),
  ...results of running psc-package sources
]
  • If pscPackage: true and the user specifies the src parameter, then the value for the src is
src: [
  ...user specified src,
  ...results of running psc-package sources
]

What do you think?

I am leaning toward the behaviour defined by the three cases listed above because I think it satisfies if the user wants to keep using the existing purs-loader behaviour and also go all-in and let psc-package determine purescript dependency paths while the user only specifies their own application source paths.

The way that we have it set up in the PR at the moment is that the user would be unable to take advantage of psc-package if they wanted to specify other source paths outside of src/**/*.purs or be more selective about their source globs; e.g., src/App1/**/*.purs, src/App2/**/*.purs, etc. They'd have to specify them all manually, even the ones in .psc-package/....

If we decide to go the route described in the three cases above then I don't think we need the warning about specifying src and pscPackage because both parameters will work together. Also, to answer a previous question of yours, I don't think we need to check for a psc-package.json file.

Finally, and this is small request, but would you be willing to pull out lines 24-33 into a separate source file called PscPackage.js? I know there are not too many lines of code, but I think the separation would be nice to have. Thanks!

@ethul ethul self-requested a review February 11, 2017 22:43
Copy link
Owner

@ethul ethul left a comment

Choose a reason for hiding this comment

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

Submitting review for comment #82 (comment)

@develop7
Copy link
Contributor Author

 I am leaning toward the behaviour defined by the three cases listed above

Totally agree. Done in e92e5f3 :)

 would you be willing to pull out lines 24-33 into a separate source file called PscPackage.js?

Sure, I'm just not sure the file should be called this way — line 31 specifically mentions bower_components, which isn't quite related to psc-package. If we'll extract only psc-package-related stuff, it's going to be L26...L28 which do not like worth separate file to me. Could we put this issue aside for now?

Also reflect pscPackage support in "Default options" section
@ethul
Copy link
Owner

ethul commented Feb 12, 2017

Thank you very much for making the updates! Looks good. Also, no worries about extracting to a separate file. This can be done later on if we determine it is necessary.

@ethul ethul merged commit 86e2b3d into ethul:master Feb 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants