-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(config): load the config as a JS module instead of parsing i…
…t as JSON
- Loading branch information
Showing
5 changed files
with
44 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@commercetools-frontend/application-config': patch | ||
--- | ||
|
||
Internally load the Custom Application config as a JS module instead of parsing it as JSON. | ||
This is to unlock some future work. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* This script file is used to load and parse a JS module in a child process, | ||
* to isolate the Babel configuration from the main program and avoid causing | ||
* unnecessary issues. | ||
* | ||
* NOTE: keep this file as a `.js` file, as we want to be able to run this | ||
* in any Node environment. | ||
*/ | ||
|
||
const get = require('lodash/get'); | ||
|
||
function requireModule(filePath) { | ||
// Load JS modules using Babel, as we need to load | ||
// the config synchronously with `require`, no `await import`. | ||
require('@babel/register')({ | ||
babelrc: false, | ||
extensions: ['.js', '.cjs', '.mjs', '.ts'], | ||
presets: [ | ||
require.resolve('@commercetools-frontend/babel-preset-mc-app/production'), | ||
], | ||
}); | ||
|
||
// Require the module. It's expected that the module exports the application config | ||
const moduleExport = require(filePath); | ||
// In case we are loading an ES module, we need to pick the `default` export. | ||
return get(moduleExport, 'default', moduleExport); | ||
} | ||
|
||
module.exports = requireModule; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ | |
"files": [ | ||
"dist", | ||
"ssr", | ||
"scripts", | ||
"loaders", | ||
"schema.json", | ||
"package.json", | ||
"LICENSE", | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters