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.

import file without extension suffix

See original GitHub issue
  • import-all.macro version:
  • node version:
  • npm (or yarn) version:

Relevant code or config

import importAll from 'import-all.macro'

const entityClassesMap = importAll.sync('../../entities/*.*')

What you did:

What happened:

Output:

var _entitiesAppRepositoryTs = _interopRequireWildcard(require("../../entities/app-repository.ts"));

var _entitiesAppTs = _interopRequireWildcard(require("../../entities/app.ts"));

Reproduction repository:

Problem description:

I use typescript to code my project, so the files under ../../entities/*.* directory are all with extension .ts, importAll.sync() also generated imports for full paths with suffix .ts too.

The babel-node can execute the codes generated by import-all.marco. But after those .ts files were compiled into .js files, we can’t execute the .js file contain require for .ts files. Because there are not .ts files in dist directory.

Suggested solution:

Usually, we import js or ts modules without extension, so our import or requirement will work very well with the “same” file with different extensions.

So maybe import-all.macro can provide an option to strip the extension suffix when generated import statements?

The configuration in babel-plugin-macro.config.js

  importAll: {
    ignoreExtensions: ['.js', '.ts']
  }

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
kentcdoddscommented, Sep 6, 2020

I have an idea for this. How about we give you this API:

importAll: {
  transformModulePath(modulePath, importingModule) {
    return newModulePath
  },
}

This would allow for all kinds of flexibility.

0reactions
kentcdoddscommented, Sep 8, 2020

Thanks @chengjianhua. This is fixed in #24

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I get the filename without the extension from a path in ...
You can just find the index of the first dot in the basename and then slice the basename to get just the filename...
Read more >
How to get file extension in Python? - GeeksforGeeks
Method 2: Using Pathlib module. The pathlib.Path().suffix method of the Pathlib module can be used to extract the extension of the file path....
Read more >
Node.js — Get a File Name (With or Without Extension)
filename (path) : returns the file name without extension. Here's the sample code on how to use both functions: import Fs from '@supercharge/fs' ......
Read more >
Get filename without extension in Python - Techie Delight
This post will discuss how to get a filename without an extension from the specified path in Python. 1. Using os.path.splitext() function.
Read more >
mimetypes — Map filenames to MIME types — Python 3.11.1 ...
Dictionary mapping suffixes to suffixes. This is used to allow recognition of encoded files for which the encoding and the type are indicated...
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