-
-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #534 from marp-team/esm-config
ES Modules for the configuration file
- Loading branch information
Showing
14 changed files
with
246 additions
and
79 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,35 @@ | ||
import type { Marp } from '@marp-team/marp-core' | ||
import type { Marpit } from '@marp-team/marpit' | ||
import type { IMarpCLIConfig } from './config' | ||
import type { ResolvableEngine } from './engine' | ||
|
||
import { apiInterface } from './marp-cli' | ||
|
||
type Overwrite<T, U> = Omit<T, Extract<keyof T, keyof U>> & U | ||
|
||
export { ObservationHelper, waitForObservation } from './marp-cli' | ||
export { CLIError, CLIErrorCode } from './error' | ||
|
||
export const marpCli = apiInterface | ||
export default apiInterface | ||
|
||
// --- | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-empty-interface -- Use interface instead of type for better IntelliSense | ||
export interface Config<Engine extends typeof Marpit = typeof Marp> | ||
extends Overwrite< | ||
Omit< | ||
IMarpCLIConfig, | ||
/** | ||
* This option is internal setting for collaboration with Marp team tools such as Marp for VS Code. | ||
* It is not designed for users because the result of conversion may break if set wrong base URL. | ||
*/ | ||
'baseUrl' | ||
>, | ||
{ | ||
engine?: ResolvableEngine<Engine> | ||
image?: 'png' | 'jpeg' | ||
images?: 'png' | 'jpeg' | ||
options?: ConstructorParameters<Engine>[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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const cosmiconfig: typeof import('cosmiconfig') = | ||
jest.requireActual('cosmiconfig') | ||
|
||
const { | ||
cosmiconfig: originalCosmiconfig, | ||
defaultLoaders, | ||
defaultLoadersSync, | ||
} = cosmiconfig | ||
|
||
// Because of v8's bug, Jest fails with SIGSEGV if used dynamic import. | ||
// When using ESM in tests, you have to set up Jest to transpile config files into CommonJS with Babel. | ||
cosmiconfig.cosmiconfig = jest.fn((moduleName, options) => { | ||
return originalCosmiconfig(moduleName, { | ||
loaders: { | ||
// cosmiconfig sync loader is using `require()` to load JS | ||
...defaultLoaders, | ||
'.js': defaultLoadersSync['.js'], | ||
'.mjs': defaultLoadersSync['.js'], | ||
'.cjs': defaultLoadersSync['.js'], | ||
}, | ||
...(options ?? {}), | ||
}) | ||
}) | ||
|
||
module.exports = cosmiconfig |
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 @@ | ||
/** @type {import('../../../src/index').Config} */ | ||
const config = {} | ||
|
||
export default config | ||
|
||
console.debug('A config file within ESM project was loaded.') |
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,4 @@ | ||
{ | ||
"private": true, | ||
"type": "module" | ||
} |
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 @@ | ||
export default {} | ||
|
||
console.debug('A config file with .mjs extension was loaded.') |
Oops, something went wrong.