Skip to content

Commit

Permalink
feat: change the default config name to esmlm.config.js (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
Comandeer authored May 7, 2024
1 parent 39ebbbe commit c427ea4
Show file tree
Hide file tree
Showing 21 changed files with 15 additions and 13 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
* [#27]: support for Node 22.

### Changed
* [#31]: **BREAKING CHANGE**: changed the default config file name from `.esmlmrc.js` to `esmlm.config.js`.
* [#26]: **BREAKING CHANGE**: updated dependencies:

| Dependency | Old version | New version |
Expand Down Expand Up @@ -78,6 +79,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
[#24]: https://github.com/Comandeer/esm-loader-manager/issues/24
[#26]: https://github.com/Comandeer/esm-loader-manager/issues/26
[#27]: https://github.com/Comandeer/esm-loader-manager/issues/27
[#31]: https://github.com/Comandeer/esm-loader-manager/issues/31

[0.6.0]: https://github.com/Comandeer/esm-loader-manager/compare/v0.5.1...v0.6.0
[0.5.1]: https://github.com/Comandeer/esm-loader-manager/compare/v0.5.0...v0.5.1
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ The loader manager does nothing on its own but you can declare your loaders insi

### Configuration file format

The configuration file needs to be named `.esmlmrc.js` or `.esmlmrc.mjs`.
The configuration file needs to be named `esmlm.config.js` or `esmlm.config.mjs`.

The sample one could look like the one below:

Expand Down Expand Up @@ -99,15 +99,15 @@ The manager will look for the configuration file inside the CWD and go up until
```
- projectRoot/
|- package.json
|- .esmlmrc.js
|- esmlm.config.js
|- subdir/
| |- app.js
| |- .esmlmrc.js
| |- esmlm.config.js
|- someOtherDir/
| |- someOtherApp.js
```

If we launch Node.js inside `projectRoot/subdir`, the manager will use the `projectRoot/subdir/.esmlmrc.js` file. However, if we launch Node.js inside `projectRoot/someOtherDir` (which does not contain its own configuration file), the `projectRoot/.esmlmrc.js` one will be used.
If we launch Node.js inside `projectRoot/subdir`, the manager will use the `projectRoot/subdir/esmlm.config.js` file. However, if we launch Node.js inside `projectRoot/someOtherDir` (which does not contain its own configuration file), the `projectRoot/esmlm.config.js` one will be used.

If for some reason you want to have a config file under some other name, you can provide the path to it via `ESMLM_CONFIG` environment variable, e.g.

Expand Down Expand Up @@ -155,7 +155,7 @@ import samplePng from './sample.png';
console.log( samplePng ); // data:image/png;base64,[…]
```

**.esmlmrc.js**
**esmlm.config.js**

```javascript
export default {
Expand Down
2 changes: 1 addition & 1 deletion src/utilities/resolveConfigFile.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { readdir } from 'node:fs/promises';
import { resolve as resolvePath } from 'pathe';

const configFileName = '.esmlmrc';
const configFileName = 'esmlm.config';
const configFileExtensions = [
'.js',
'.mjs'
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
14 changes: 7 additions & 7 deletions tests/utilities/resolveConfigFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import mockFS from 'mock-fs';
import fixtureDirPath from '../__helpers__/fixtureDirPath.js';
import resolveConfigFile from '../../src/utilities/resolveConfigFile.js';

const configFileName = '.esmlmrc.js';
const configModuleFileName = '.esmlmrc.mjs';
const configFileName = 'esmlm.config.js';
const configModuleFileName = 'esmlm.config.mjs';
const simpleLoaderDirPath = resolvePath( fixtureDirPath, 'simpleLoader' );
const nestedLoaderDirPath = resolvePath( fixtureDirPath, 'nested' );
const nestedLoaderLevel1DirPath = resolvePath( nestedLoaderDirPath, 'level1' );
Expand All @@ -25,35 +25,35 @@ test.after( () => {
mockFS.restore();
} );

test( 'resolveConfigFile() points to the nearest .esmlmrc.js file (same dir)', async ( t ) => {
test( 'resolveConfigFile() points to the nearest esmlm.config.js file (same dir)', async ( t ) => {
const expectedConfigFilePath = resolvePath( simpleLoaderDirPath, configFileName );
const resolvedConfigFilePath = await resolveConfigFile( simpleLoaderDirPath, simpleLoaderDirPath );

t.is( resolvedConfigFilePath, expectedConfigFilePath );
} );

test( 'resolveConfigFile() points to the nearest .esmlmrc.js file (nested dir)', async ( t ) => {
test( 'resolveConfigFile() points to the nearest esmlm.config.js file (nested dir)', async ( t ) => {
const expectedConfigFilePath = resolvePath( nestedLoaderDirPath, configFileName );
const resolvedConfigFilePath = await resolveConfigFile( nestedLoaderLevel1DirPath, nestedLoaderDirPath );

t.is( resolvedConfigFilePath, expectedConfigFilePath );
} );

test( 'resolveConfigFile() points to the nearest .esmlmrc.js file (deeply nested dir)', async ( t ) => {
test( 'resolveConfigFile() points to the nearest esmlm.config.js file (deeply nested dir)', async ( t ) => {
const expectedConfigFilePath = resolvePath( nestedLoaderLevel2DirPath, configFileName );
const resolvedConfigFilePath = await resolveConfigFile( nestedLoaderLevel3DirPath, nestedLoaderDirPath );

t.is( resolvedConfigFilePath, expectedConfigFilePath );
} );

test( 'resolveConfigFile() points to the nearest .esmlmrc.mjs file', async ( t ) => {
test( 'resolveConfigFile() points to the nearest esmlm.config.mjs file', async ( t ) => {
const expectedConfigFilePath = resolvePath( moduleConfigFileDirPath, configModuleFileName );
const resolvedConfigFilePath = await resolveConfigFile( moduleConfigFileDirPath, moduleConfigFileDirPath );

t.is( resolvedConfigFilePath, expectedConfigFilePath );
} );

test( 'resolveConfigFile() prefers .esmlmrc.js over .esmlmrc.mjs', async ( t ) => {
test( 'resolveConfigFile() prefers esmlm.config.js over esmlm.config.mjs', async ( t ) => {
const expectedConfigFilePath = resolvePath( multipleConfigFilesDirPath, configFileName );
const resolvedConfigFilePath = await resolveConfigFile( multipleConfigFilesDirPath, multipleConfigFilesDirPath );

Expand Down

0 comments on commit c427ea4

Please sign in to comment.