question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Macro import paths with Windows separators are ignored

See original GitHub issue
  • babel-plugin-macros version: 2.6.1
  • node version: 12.6.0
  • npm (or yarn) 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:

  1. git clone https://github.com/citycide/bpm-repro.git
  2. yarn
  3. yarn build
  4. dist.js is created but was not transformed

Problem description:

  1. the macro regex only accounts for a unix path separator (/)
  2. even once 1) is fixed, the resolve module throws MODULE_NOT_FOUND

Suggested solution:

First the regex would need to be updated to something like this:

https://github.com/kentcdodds/babel-plugin-macros/blob/2d57c60adadd8904db9624614faffc34a251c40d/src/index.js#L5

- 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:closed
  • Created 4 years ago
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
sokracommented, Jul 10, 2019

If the host environment is webpack, absolute windows paths are allowed. Relative paths with windows separator are not.

1reaction
sompylasarcommented, Jul 10, 2019

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”.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found