Skip to content

support all config file extensions (.js,.mjs,...)#3204

Merged
lukastaegert merged 3 commits intorollup:masterfrom
arlac77:master
Oct 31, 2019
Merged

support all config file extensions (.js,.mjs,...)#3204
lukastaegert merged 3 commits intorollup:masterfrom
arlac77:master

Conversation

@arlac77
Copy link
Copy Markdown
Contributor

@arlac77 arlac77 commented Oct 30, 2019

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes (bugfixes and features will not be merged without tests)
  • no

Breaking Changes?

  • yes (breaking changes will not be merged unless absolutely necessary)
  • no

List any relevant issue numbers: #3189

Description

support naming the config file *.mjs

rollup --config my.config.mjs

@codecov
Copy link
Copy Markdown

codecov Bot commented Oct 30, 2019

Codecov Report

Merging #3204 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3204      +/-   ##
==========================================
+ Coverage   90.63%   90.63%   +<.01%     
==========================================
  Files         167      167              
  Lines        5905     5906       +1     
  Branches     1792     1792              
==========================================
+ Hits         5352     5353       +1     
  Misses        336      336              
  Partials      217      217
Impacted Files Coverage Δ
cli/run/loadConfigFile.ts 84% <100%> (+0.66%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 53fb6fe...8f8bbfb. Read the comment docs.

Copy link
Copy Markdown
Member

@lukastaegert lukastaegert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test and doc changes look good, but I wonder if we might solve similar issues once and for all by allowing every extension, see my suggestion.

Comment thread cli/run/loadConfigFile.ts Outdated
defaultLoader(module, filename);
}
};
const extensions = ['.js','.mjs'];
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will work nicely for '.js' and '.mjs' but not other extensions, and is slightly complicated. How about this: As we KNOW the name of the config file, how about using path.extname to extract the extension of the config file and just modify the loader for this extension?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes perfect sense

@arlac77 arlac77 changed the title also support *.mjs as config file extension support all config file extensions (.js,.mjs,...) Oct 31, 2019
Copy link
Copy Markdown
Member

@lukastaegert lukastaegert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot, this looks really nice now!

@jrgleason
Copy link
Copy Markdown

jrgleason commented Jan 15, 2020

I am trying to use this and I am calling like...

../../node_modules/.bin/rollup -c rollup.config.mjs
import {getMJS} from "@jrg-material/build"

import pkg from './package.json';

export default [getMJS(pkg)];

but I get...

TypeError: defaultLoader is not a function
at Object.require.extensions. [as .mjs] (/Users/jackiegleason/Code/jrg-material/node_modules/rollup/dist/bin/rollup:834:17)
at Module.load (internal/modules/cjs/loader.js:1050:32)
at Function.Module._load (internal/modules/cjs/loader.js:945:14)
at Module.require (internal/modules/cjs/loader.js:1090:19)
at require (internal/modules/cjs/helpers.js:72:18)

Notice it seems to be using the cjs loader still.

@jrgleason
Copy link
Copy Markdown

looks like this does work (lerna and my node_modules is in root for dev deps)

import {getMJS} from "../../node_modules/@jrg-material/build/dist/index.mjs"

Is there a way to import without needing the relative path?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants