Macro import paths with Windows separators are ignored
See original GitHub issuebabel-plugin-macros
version: 2.6.1node
version: 12.6.0npm
(oryarn
) version: yarn 1.16.0
Relevant code or config
import { _ } from '.\\macro'
import { it } from 'E:\\dev\\param.macro\\macro'
I came across this when testing param.macro and have noticed that tests will fail on Windows — the import path I generate for testing (an absolute Windows style path) is ignored by babel-plugin-macros
but is also further incompatible with it.
What you did:
Compile
What happened:
The macro is not activated.
Reproduction repository:
git clone https://github.com/citycide/bpm-repro.git
yarn
yarn build
dist.js
is created but was not transformed
Problem description:
- the macro regex only accounts for a unix path separator (
/
) - even once 1) is fixed, the
resolve
module throwsMODULE_NOT_FOUND
Suggested solution:
First the regex would need to be updated to something like this:
- const macrosRegex = /[./]macro(\.js)?$/
+ const macrosRegex = /[./\\]macro(\.js)?$/
However this isn’t enough as once applyMacros
is actually called, the resolve
module will throw:
Error: Cannot find module '.\macro' from 'E:\dev\param.macro'
There are existing issues that mention Windows but they all relate to tests.
Issue Analytics
- State:
- Created 4 years ago
- Comments:13 (4 by maintainers)
Top Results From Across the Web
VBA ignore System Separators Setting on opening CSV file
In my Windows OS, I set my "Date, time or number formats" with the following separators: Decimal: "," Milesimal: "." List: ";".
Read more >Formula errors in Excel when list separator is not set correctly
When entering a formula an error will occur if trying to use a symbol that is not the default 'list separator' in the...
Read more >Don't Treat Paths Like Strings | Twisted Oak Studios Blog
File paths are represented by strings, but they don't act like strings. ... Windows typically allows both \ and / as directory separators, ......
Read more >Change path separator in currfile - TeX - LaTeX Stack Exchange
If you wish to change the definition of a macro like \currfileabsdir so that explicit backslash-characters of category 12(other) are ...
Read more >std::filesystem::path - cppreference.com
Feature test macros (C++20) ... If the very last element in the path is a directory separator, the last iterator will dereference to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
If the host environment is webpack, absolute windows paths are allowed. Relative paths with windows separator are not.
I believe Node.js source can be considered a reference implementation.
It says that the thing you put in the import statement is called “module_request” (which not necessarily maps to a file system path 1:1). https://github.com/nodejs/node/blob/2983eaca84e9e79c19dba09fb036fe55131b8a5d/deps/v8/src/ast/modules.h#L37
It goes to GetModuleNamespace which is an abstract ECMAScript operation https://github.com/nodejs/node/blob/8aca934009225b30bff7d7927d2eb9f667dbff9f/deps/v8/src/runtime/runtime-module.cc#L38
https://tc39.es/ecma262/#sec-getmodulenamespace
That mentions the HostResolveImportedModule abstract operation which depends on the implementation of the host environment.
So the answer is actually “the spec says it depends on the host environment”.