-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use Config file instead of Environment Variables (#2227)
* Use cosmiconfig to read modular configuration, while allowing Env variables to override it * Add configuration tests * Change the default CDN to esm.sh * Update documentation to reflect new configuration approach * Use INTERNAL_ env variables to read configuration in JS files that can't call the config function * Refactor config() logic Co-authored-by: Steve King <[email protected]>
- Loading branch information
1 parent
2e87968
commit c84b426
Showing
23 changed files
with
324 additions
and
56 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 @@ | ||
--- | ||
'modular-scripts': major | ||
--- | ||
|
||
Changed default CDN from Skypack to esm.sh as skypack is no longer actively | ||
maintained. Add support for configuring modular through a configuration file. |
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,3 @@ | ||
module.exports = { | ||
useModularEsbuild: true, | ||
}; |
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
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
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
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
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
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
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
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
2 changes: 1 addition & 1 deletion
2
packages/modular-scripts/src/__tests__/__snapshots__/esmView.test.ts.snap
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`modular-scripts WHEN building a esm-view THEN matches the entrypoint snapshot 1`] = ` | ||
"import * as t from "https://cdn.skypack.dev/[email protected]"; | ||
"import * as t from "https://esm.sh/[email protected]"; | ||
function e() { | ||
return t.createElement( | ||
"div", | ||
|
51 changes: 51 additions & 0 deletions
51
packages/modular-scripts/src/__tests__/utils/config.test.ts
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,51 @@ | ||
import execa from 'execa'; | ||
import { copyFileSync } from 'fs'; | ||
import path from 'path'; | ||
import { createModularTestContext } from '../../test/utils'; | ||
import getModularRoot from '../../utils/getModularRoot'; | ||
|
||
const modularRoot = getModularRoot(); | ||
const configFixtures = path.join(modularRoot, '__fixtures__', 'test-config'); | ||
|
||
/** | ||
* Run modular with provided arguments in specified directory | ||
*/ | ||
function modular( | ||
args: string, | ||
cwd: string, | ||
opts: Record<string, unknown> = {}, | ||
) { | ||
return execa('yarnpkg', ['modular', ...args.split(' ')], { | ||
cwd, | ||
cleanup: true, | ||
...opts, | ||
}); | ||
} | ||
|
||
// Temporary test context paths set by createTempModularRepoWithTemplate() | ||
let tempModularRepo: string; | ||
|
||
describe('A simple modular repo with a .modular.js config file', () => { | ||
beforeEach(async () => { | ||
tempModularRepo = createModularTestContext(); | ||
await modular('add test-app --unstable-type app', tempModularRepo); | ||
copyFileSync( | ||
path.join(configFixtures, '.modular.js'), | ||
path.join(tempModularRepo, '.modular.js'), | ||
); | ||
}); | ||
it('builds using esbuild as specified in config file', async () => { | ||
const result = await modular(`build test-app --verbose`, tempModularRepo); | ||
expect(result.stdout).toContain('Building with esbuild'); | ||
expect(result.exitCode).toBe(0); | ||
}); | ||
it('builds using webpack if the environment variable is provided as it overrides the config', async () => { | ||
const result = await modular(`build test-app --verbose`, tempModularRepo, { | ||
env: { | ||
USE_MODULAR_ESBUILD: 'false', | ||
}, | ||
}); | ||
expect(result.stdout).toContain('Building with Webpack'); | ||
expect(result.exitCode).toBe(0); | ||
}); | ||
}); |
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
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
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
Oops, something went wrong.