Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
6c481c8
Add ES imports/exports to CoreImp AST
kl0tl Feb 6, 2020
52a692b
Print ES imports/exports
kl0tl Feb 6, 2020
cd40596
Codegen ES imports for PureScript modules
kl0tl Feb 6, 2020
607dd3d
Codegen ES imports for foreign modules
kl0tl Feb 6, 2020
19878e3
Codegen ES exports
kl0tl Feb 6, 2020
4889861
Extract both CJS and ES exports from foreign modules
kl0tl Feb 8, 2020
c03399f
Remove the redundant "use strict;" pragma from modules header
kl0tl Feb 8, 2020
71c2de3
Don’t emit empty statements for empty exports lists
kl0tl Feb 8, 2020
7d4ef3d
Bundle ES modules
kl0tl Feb 9, 2020
7f0c07e
Load ES modules with `esm` in the Node.js REPL and tests
kl0tl Feb 15, 2020
e006953
Escape primes in modules accessors
kl0tl Feb 15, 2020
243ec5e
Forbid unescaped primes in foreign modules exports
kl0tl Feb 15, 2020
ddbb2ad
Run tests against patched dependencies
kl0tl Feb 15, 2020
e5b1798
Rewrite ES modules in the browser REPL client
kl0tl Apr 23, 2020
47cdee9
Merge branch 'master' into es-modules
kl0tl Mar 20, 2021
c5ffab6
Revert "Load ES modules with `esm` in the Node.js REPL and tests"
kl0tl Mar 20, 2021
4713b2a
Allow Node.js to load .js files in the output directory as ES modules
kl0tl Mar 20, 2021
7784dd1
Import CommonJS foreign modules through an ES module wrapper
kl0tl Mar 20, 2021
1587749
Don't let tests nor the REPL compile into a node_modules directory
kl0tl Mar 20, 2021
ba9f084
Bundle re-exports
kl0tl Mar 20, 2021
65dab5d
Load bundles as CommonJS modules in tests
kl0tl Mar 20, 2021
830bbe2
Update Node.js version on CI
kl0tl Mar 20, 2021
4976eee
Disallow CommonJS exports named `default`
kl0tl Mar 20, 2021
f73c2bf
Disallow CommonJS exports and imports in ES foreign modules
kl0tl Mar 20, 2021
c56d3f5
Deprecate CommonJS foreign modules
kl0tl Mar 20, 2021
94af221
Convert CommonJS foreign modules in tests to ES modules
kl0tl Mar 20, 2021
15ebf0d
Don't optimize away dependencies of named ES exports of declarations
kl0tl Mar 21, 2021
8f19b7e
fixup! Import CommonJS foreign modules through an ES module wrapper
kl0tl Apr 3, 2021
7727c98
fixup! Don't optimize away dependencies of named ES exports of declar…
kl0tl Apr 3, 2021
bd45602
Revert "Disallow CommonJS exports named `default`"
kl0tl Jun 21, 2021
ca94c4b
Add tests for foreign CommonJS exports named default
kl0tl Jun 21, 2021
ec4dce5
Extend support to Node.js v12.0.0 with --experimental-modules
kl0tl Jul 2, 2021
0d6f928
Filter out Node.js experimental ES modules loader warning
kl0tl Jul 2, 2021
8e1caf8
Update bundler error messages
kl0tl Jul 2, 2021
7ef3aad
Merge branch 'master' into next
kl0tl Jul 3, 2021
d5437e0
Fix HLint warnings
kl0tl Jul 3, 2021
721807c
Merge remote-tracking branch 'upstream/master' into es-modules
kl0tl Jul 23, 2021
d3b6633
Add purity annotations to function applications and constructor insta…
kl0tl Jul 19, 2021
87e72e0
Merge remote-tracking branch 'upstream/master' into es-modules+purity…
i-am-the-slime Dec 26, 2021
c630052
Surround purity annotations in parens
i-am-the-slime Dec 28, 2021
8a0779c
Mention es modules in version
i-am-the-slime Dec 28, 2021
593230b
Bump version to 0.15.0
i-am-the-slime Dec 28, 2021
8a7b220
Add purity annotations to top-level applications only.
natefaubion Jan 26, 2022
a1258f2
Follow top-level literals as well
natefaubion Jan 27, 2022
f3b9d34
Annotate all top-level-reachable applications.
natefaubion Jan 27, 2022
b72f7f8
Traverse under lhs functions and operators
natefaubion Jan 27, 2022
d67aa9e
Use # for annotation.
natefaubion Jan 27, 2022
19f4bdc
Add comments, remove potentially aggressive cases.
natefaubion Jan 27, 2022
ce9a906
Simplify to uniform top-level IIFEs.
natefaubion Jan 27, 2022
9d997ea
Fix tests
sigma-andex Feb 4, 2022
7a458ff
Add myself to contributors
sigma-andex Feb 8, 2022
67c536a
Merge pull request #10 from working-group-purescript-es/add-to-contri…
thomashoneyman Feb 8, 2022
3a3abde
Fix experimental-modules flag required version (#11)
sigma-andex Feb 11, 2022
e535003
Add i-am-the-slime to contributors
i-am-the-slime Feb 13, 2022
d57898d
Fix pr comments (#12)
sigma-andex Feb 14, 2022
8f79b9d
Merge branch 'master' into es-modules+purity-annotations
sigma-andex Feb 18, 2022
efa6f87
Add resolutions to fix dep conflicts
JordanMartinez Feb 18, 2022
c35d12b
Add changelog.d entry for es modules (#14)
sigma-andex Feb 20, 2022
ed3f494
Update prefix to match script's expected one
JordanMartinez Feb 21, 2022
970a8e6
Drop unneeded whitespace
JordanMartinez Feb 21, 2022
16430f3
Update src/Language/PureScript/Errors.hs
sigma-andex Feb 21, 2022
f861e5e
Fix broken tests after spelling correction commit
sigma-andex Feb 21, 2022
fba2a49
Remove temporary entries from changelog
sigma-andex Feb 22, 2022
993ade0
Remove version update
sigma-andex Feb 24, 2022
69df129
Stop using es modules branch for lists dependency
JordanMartinez Feb 24, 2022
deec912
Merge branch 'master' into es-modules+purity-annotations
JordanMartinez Feb 25, 2022
a1a1eff
Refactor Pure -> Comment in CoreImp
rhendric Feb 25, 2022
9f29b4d
Refactor CoreImp modules
rhendric Feb 25, 2022
038108e
Be less liberal with IIFEs
rhendric Feb 25, 2022
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 .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:

- uses: "actions/setup-node@v1"
with:
node-version: "10"
node-version: "12"

- id: "haskell"
uses: "haskell/actions/setup@v1"
Expand Down
26 changes: 26 additions & 0 deletions CHANGELOG.d/breaking_switch-to-es-modules.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
* Switch from Common JS to ES modules

Previously, Purescript used Common JS for FFI declarations.

Before, FFI was declared like this...

```javascript
const mymodule = require('mymodule')

exports.myvar = mymodule.myvar
```

...and will be changed to this...

```javascript
import * as M from 'mymodule';
export const myvar = M.myvar
```
...or using the short version...

```javascript
export { myvar } from 'mymodule';
```

* FFI is annotated with `/* #__PURE__ */` so that bundlers can perform DCE
* The current LTS Node.js version `12` is now the required minimum version
2 changes: 2 additions & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ If you would prefer to use different terms, please use the section below instead
| [@xgrommx](https://github.com/xgrommx) | Denis Stoyanov | [MIT license](http://opensource.org/licenses/MIT) |
| [@MonoidMusician](https://github.com/MonoidMusician) | Verity Scheel | [MIT license](http://opensource.org/licenses/MIT) |
| [@thomashoneyman](https://github.com/thomashoneyman) | Thomas Honeyman | [MIT license](http://opensource.org/licenses/MIT) |
| [@sigma-andex](https://github.com/sigma-andex) | Jan Schulte | [MIT license](http://opensource.org/licenses/MIT) |
| [@i-am-the-slime](https://github.com/i-am-the-slime) | Mark Eibes | [MIT license](http://opensource.org/licenses/MIT) |

### Contributors using Modified Terms

Expand Down
18 changes: 8 additions & 10 deletions app/Command/REPL.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ import System.IO.UTF8 (readUTF8File)
import System.Exit
import System.Directory (doesFileExist, getCurrentDirectory)
import System.FilePath ((</>))
import System.FilePath.Glob (glob)
import System.Process (readProcessWithExitCode)
import qualified System.FilePath.Glob as Glob
import qualified Data.ByteString.Lazy.UTF8 as U

-- | Command line options
Expand Down Expand Up @@ -108,7 +107,7 @@ pasteMode =
-- | Make a JavaScript bundle for the browser.
bundle :: IO (Either Bundle.ErrorMessage String)
bundle = runExceptT $ do
inputFiles <- liftIO (glob (".psci_modules" </> "node_modules" </> "*" </> "*.js"))
inputFiles <- liftIO $ concat <$> Glob.globDir [Glob.compile "*/*.js", Glob.compile "*/foreign.cjs"] modulesDir
input <- for inputFiles $ \filename -> do
js <- liftIO (readUTF8File filename)
mid <- Bundle.guessModuleIdentifier filename
Expand Down Expand Up @@ -280,13 +279,12 @@ nodeBackend nodePath nodeArgs = Backend setup eval reload shutdown

eval :: () -> String -> IO ()
eval _ _ = do
writeFile indexFile "require('$PSCI')['$main']();"
process <- maybe findNodeProcess (pure . pure) nodePath
result <- traverse (\node -> readProcessWithExitCode node (nodeArgs ++ [indexFile]) "") process
writeFile indexFile "import('./$PSCI/index.js').then(({ $main }) => $main());"
result <- readNodeProcessWithExitCode nodePath (nodeArgs ++ [indexFile]) ""
case result of
Just (ExitSuccess, out, _) -> putStrLn out
Just (ExitFailure _, _, err) -> putStrLn err
Nothing -> putStrLn "Could not find node.js. Do you have node.js installed and available in your PATH?"
Right (ExitSuccess, out, _) -> putStrLn out
Right (ExitFailure _, _, err) -> putStrLn err
Left err -> putStrLn err

reload :: () -> IO ()
reload _ = return ()
Expand All @@ -303,7 +301,7 @@ command = loop <$> options
where
loop :: PSCiOptions -> IO ()
loop PSCiOptions{..} = do
inputFiles <- concat <$> traverse glob psciInputGlob
inputFiles <- concat <$> traverse Glob.glob psciInputGlob
e <- runExceptT $ do
modules <- ExceptT (loadAllModules inputFiles)
when (null modules) . liftIO $ do
Expand Down
15 changes: 13 additions & 2 deletions app/static/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,24 @@ var evaluate = function evaluate(js) {
// which will be returned to PSCi.
buffer.push(s);
};
// Replace any require(...) statements with lookups on the PSCI object.
// Replace any require and import statements with lookups on the PSCI object
// and export statements with assignments to module.exports.
var replaced = js.replace(/require\("[^"]*"\)/g, function(s) {
return "PSCI['" + s.split('/')[1] + "']";
}).replace(/import \* as ([^\s]+) from "([^"]*)"/g, function (_, as, from) {
return "var " + as + " = PSCI['" + from.split('/')[1] + "']";
}).replace(/export \{([^}]+)\} from "\.\/foreign\.js";?/g, function (_, exports) {
return exports.replace(/^\s*([^,\s]+),?\s*$/gm, function (_, exported) {
return "module.exports." + exported + " = $foreign." + exported + ";";
});
}).replace(/export \{([^}]+)\};?/g, function (_, exports) {
return exports.replace(/^\s*([^,\s]+)(?: as ([^\s]+))?,?\s*$/gm, function (_, exported, as) {
return "module.exports." + (as || exported) + " = " + exported + ";";
});
Copy link
Copy Markdown
Contributor

@JordanMartinez JordanMartinez Feb 11, 2022

Choose a reason for hiding this comment

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

Should these regexes account for extra spaces? For example

import * as f from "fs"; // normal spacing; regex will match this
import  * as f from "fs"; // typo space; regex will fail to match this

The require regex on which these are likely based did not need to account for extra whitespace issues.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

afaik this is in the repl in browser feature, which hasn't been updated yet.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah, I see. This code only runs when purs repl --port somePort is called. I've always just used purs repl, which is always using the Node backend.

which hasn't been updated yet.

But shouldn't this be fixed here? Or does that mess up tests and hence why it hasn't yet?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's not clear to me what the resolution was here. Do we need to note this in the release? Will it be updated or will it be removed? Will that happen in a subsequent PR?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Wasn't the idea to remove the browser repl in a subsequent PR?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm fine with removing it, but it wasn't clear to me there was any consensus here with the core team. Did I miss that?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I've missed a few meetings, but I don't think there has been consensus yet as I don't think this has come up. I'm up for removing it though because I've never used the browser version. If I want a REPL-like experience, I usually just use Try PureScript because there's a small bug in one part of my code and starting a REPL just to debug that one function isn't worth it to me.

});
// Wrap the module and evaluate it.
var wrapped =
[ 'var module = {};'
[ 'var module = { exports: {} };'
, '(function(module) {'
, replaced
, '})(module);'
Expand Down
1 change: 1 addition & 0 deletions purescript.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ library
Language.PureScript.CoreFn.Traversals
Language.PureScript.CoreImp
Language.PureScript.CoreImp.AST
Language.PureScript.CoreImp.Module
Language.PureScript.CoreImp.Optimizer
Language.PureScript.CoreImp.Optimizer.Blocks
Language.PureScript.CoreImp.Optimizer.Common
Expand Down
Loading