Skip to content
This repository has been archived by the owner on Jan 18, 2024. It is now read-only.

Commit

Permalink
Fix relative module resolution for config files (#2744)
Browse files Browse the repository at this point in the history
I was receiving a `MODULE_NOT_FOUND` error with my config since it references relative modules. This sets `configFile` as the `filename` argument to `require-from-string` so relative modules can be resolved properly
  • Loading branch information
nokutana authored Oct 1, 2020
1 parent c9260e9 commit 0464f6c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
9 changes: 9 additions & 0 deletions packages/config/src/__tests__/ConfigParsing-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ describe('getConfig', () => {
expect(exp.foo).toBe('bar');
expect(exp.name).toBe('cool+export-json_app.config');
});
it('parses a js config with import', () => {
const projectRoot = path.resolve(__dirname, './fixtures/language-support/js');
const configPath = path.resolve(projectRoot, 'with-import_app.config.js');
setCustomConfigPath(projectRoot, configPath);
const { exp } = getConfig(projectRoot, {
skipSDKVersionRequirement: true,
});
expect(exp.foo).toBe('bar');
});
xit('parses a yaml config', () => {
const projectRoot = path.resolve(__dirname, './fixtures/language-support/yaml');
const { exp } = getConfig(projectRoot, {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const { foo } = require('./export-json_app.config');

module.exports = function ({ config }) {
config.foo = foo;
return config;
};
2 changes: 1 addition & 1 deletion packages/config/src/evalConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function evalConfig(
presets: [preset],
});

let result = requireString(code);
let result = requireString(code, configFile);
if (result.default != null) {
result = result.default;
}
Expand Down

0 comments on commit 0464f6c

Please sign in to comment.