Skip to content

Commit

Permalink
Merge pull request #488 from marp-team/v2.2.1-segment-fault
Browse files Browse the repository at this point in the history
Fix segmentation fault that brings while resolving bundled engine
  • Loading branch information
yhatt authored Nov 21, 2022
2 parents 0c20d1a + 3835d82 commit c16fa75
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## [Unreleased]

### Fixed

- Fix segmentation fault that brings while resolving bundled engine ([#487](https://github.com/marp-team/marp-cli/issues/487), [#488](https://github.com/marp-team/marp-cli/pull/488))

## v2.2.1 - 2022-11-20

### Added
Expand Down
17 changes: 11 additions & 6 deletions src/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ export class ResolvedEngine {
process.env.NODE_ENV === 'test'
) {
ResolvedEngine._defaultEngine = await ResolvedEngine.resolve([
'@marp-team/marp-core',
delayedEngineResolver(
async () => (await import('@marp-team/marp-core')).Marp
),
'@marp-team/marp-core', // Manually-installed Marp Core

// Bundled Marp Core
// eslint-disable-next-line @typescript-eslint/no-var-requires -- import statement brings segmentation fault: https://github.com/marp-team/marp-cli/issues/487
delayedEngineResolver(async () => require('@marp-team/marp-core').Marp),
])
}
return ResolvedEngine._defaultEngine
Expand All @@ -62,7 +63,9 @@ export class ResolvedEngine {
(from && importFrom.silent(path.dirname(path.resolve(from)), eng)) ||
importFrom.silent(process.cwd(), eng)

if (resolved?.__esModule) resolved = resolved.default
if (resolved && typeof resolved === 'object' && 'default' in resolved) {
resolved = resolved.default
}
} else if (typeof eng === 'object' && eng[delayedEngineResolverSymbol]) {
resolved = await eng[delayedEngineResolverSymbol]()
} else {
Expand Down Expand Up @@ -97,7 +100,9 @@ export class ResolvedEngine {

if (
expt === klass ||
(expt?.__esModule && Object.values(expt).includes(klass))
(expt &&
typeof expt === 'object' &&
Object.values(expt).includes(klass))
)
return moduleId
}
Expand Down

0 comments on commit c16fa75

Please sign in to comment.