Rollup.js: Any Way to Reproduce Babel Module Resolver (eg. ~/foo => src/foo) - rollupjs

I've been using Webpack/Babel for awhile, and as part of that setup I use the Babel module resolver plugin so that I can do:
import foo from '~/somePath';
and have it get converted into:
import foo from 'PROJECT_HOME/somePath';
However, I'm now trying to switch to Rollup, which supports Babel but not Babel module resolvers. So, my question is, is there any way to simulate the ~/ => PROJECT_HOME/ functionality in Rollup?

Seems like rollup-plugin-alias could do that for you.

Related

Agda Installation PLFA Configuration

I am trying to use the Programming Language Foundation with Agda plfa library, however the import does not appear to be working properly.
I have cloned the repository and added the repository path to: ~/.agda/libraries and plfa to ~/.agda/defaults.
When I create a test.agda file and check a single line
module plfa.part1.Naturals where
I get an import error:
You tried to load /Users/johngfisher/Desktop/agda_test/nats.agda
which defines the module plfa.part1.Naturals. However, according to
the include path this module should be defined in
/Users/johngfisher/agda_env/libraries/plfa/src/plfa/part1/Naturals.lagda.md
The file is present in the location the import is coming from so I am unsure of why Agda is unable to find it. Any help would be appreciated.
module plfa.part1.Naturals where
defines a module named plfa.part1.Naturals
Did you mean to type
module test where
open import plfa.part1.Naturals
instead?

unable to find `as` method in `Config`

I saw the following code snippet
val settings = configuration.underlying.as[CookieSecretSettings]("silhouette.oauth1TokenSecretProvider")
I believe configuration is of type play.api.Configuration and underlying is of typeConfig` (https://www.playframework.com/documentation/2.6.x/api/scala/index.html#play.api.Configuration)
I copied the code in my Apploader (as I am using Compile Time Injection). The BuiltInComponentsFromContext has a configuration variable. I thought to use that as follows val config = configuration.underlying.as[CookieAuthenticatorSettings]("silhouette.authenticator") but the compiler cannot resolve as. What am I doing wrong?
The Config library seem to have asInstanceOf instead of as but I get other errors if I use that. I notice that the code for which as works uses play version 2.4.2 while I am using 2.6.12.
I realize this is an old question, but I stumbled upon this exact problem today and couldn't find anything helpful.
The as method is provided by a third-party library (Ficus) to read case classes and Scala types from Typesafe config. You need to include it in your build dependencies, then add to imports:
import net.ceedubs.ficus.Ficus._
import net.ceedubs.ficus.readers.ArbitraryTypeReader._

how does ES6 resolve import paths and can we customize its behavior

How can we customize a root directory to be the /, seems like this behavior is entirely depending on the relative path of the current file.
For example, I would prefer to use a couple of directory paths
src
style
components
and in deep nested direcotry components/header/navbar.js, i want to import without initialy slashes something like:
import Blah from 'src/models/Blah'
but instead I have to do
import Blah from '../../src/models/Blah'
If you use webpack to compile ES2015 codes,
you can use resolve field in webpack.config.js to select default path
resolve: {
modules: [path.join(__dirname, '..', 'app'), 'node_modules'],
},
such like above. In above case, webpack will handle /app directory as root.
The module identifier is completely opaque to ECMAScript. I.e. there are no rules in the language about how it should be interpreted. The module identifier is interpreted by the module loader (and in the broader context, the environment) or the module bundler you are using.
E.g. Node's rules for interpreting module identifiers can be found here and these are the rules that most bundlers that work with Node modules support.
But many bundlers provide ways to customize this.
Summary: How to do this and whether it is possible to do this depends on the environment/module loader/module bundler you are using. It has nothing to do with the language itself.
Related questions:
Webpack: Resolving require paths with webpack
Node.js: Avoid using relative paths on require()

Defining module names with Typescript

I'm trying to use TypeScript with RequireJS but I'm getting the following error:
Mismatched anonymous define() module.
I understand this is because Typescript is not emitting a module name and I'm loading the scripts into the page myself (I'm doing this as they are defined as a pre-defined bundle in the MVC project).
Currently the outputted .js looks like this:
define(["require", "exports", "jquery"], function(require, exports, $) {...
When I need it to emit:
define("MODULE_NAME" ["require", "exports", "jquery"], function(require, exports, $) {...
Is this possible with Typescript or should I look at replacing the bundle for minimization with Require.js's own optimization?
If you are using ASP.NET and the integrated script bundling, you are correct: The problem is that the bundle contains multiple anonymous modules. While it is good, common practice to work with anonymous modules (and let some compressor/optimizer do the naming later), this won't work for ASP.NET bundling because it only concatenates the input JS files. The solution is to make TypeScript create named modules. And this is possible with TS, so the answer to your question
Is this possible with Typescript
is definitely: Yes!
TypeScript 1.4 added the ability to emit AMD named modules to the compiler, like this:
///<amd-module name='NamedModule'/>
export class C {
}
The issue is not in the code generation (which is correct). The issue is that you probably have a script tag loading this JavaScript file. It should only be loaded by RequireJS, using data-main or as a dependency of another module.
See : http://requirejs.org/docs/errors.html#mismatch
Remove the script tag

update module on import to python interpreter

In short
How to force python interpreter to load the most up-to-date code version of my module everytime I make some changes in the module code?
Or at least reload the last modified version by typing
>>> from myModule import *
into console, without necessity to restart whole python console and setup everything again and again anytime I make some changes? This is extremely unpleasant behavior for debugging.
--------- LONGER STORY -----------
I tried to delete the .pyc file, and import it again - but it has no effect. It does't even create .pyc file again - so I expect it completely ignore my "import" command if the module is already loaded.
this also does not help:
>>> mymodule.myfunc() # the old version
>>> del myModule # unload mymodle from python conole / interpeter
... # now I removed .pyc
... # now I make some modifications in mymodule.myfunc() code
>>> mymodule.myfunc() # module is unknonwn, ... OK
>>> import myModule # try to load modified version
>>> mymodule.myfunc() # stil the old version :(((((, How it can remember?
I have tried also Spyder where is this feature called "User Module Deleter (UMD)"
http://pythonhosted.org/spyder/console.html#reloading-modules-the-user-module-deleter-umd
which I thought should do exactly this, but it seem it doesn't (Yes, I checked that it is turned on).
Maybe I'm missing something - can somebody explain me how is it supposed to be used?
Is this somehow affected by the fact that the imported module is not in "Working directory" but in PYTHONPATH ?
(Spyder dev here) I think at the moment you are not able to reload a module directly in the console (but we are considering to change this in the future).
The idea about UMD is that it will reload your modules but only if you run a file from the editor that imports them. It doesn't work if you want to reload them directly in the console.
Let's say you developed a module, then you are probably using it in a different script that (most likely) you'll be writing in our editor and send it to run to our console. UMD is a little bit of magic that reloads it for you when that happens.
Maybe useful for others. In Spyder 3.0.0, the modules can be reloaded by,
Tools -> Update modules names list.
It worked for me.

Resources