Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 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
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 @@ -29,7 +29,7 @@ jobs:

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

- id: "haskell"
uses: "haskell/actions/setup@v1"
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 + ";";
});
});
// Wrap the module and evaluate it.
var wrapped =
[ 'var module = {};'
[ 'var module = { exports: {} };'
, '(function(module) {'
, replaced
, '})(module);'
Expand Down
Loading