Skip to content

Commit

Permalink
Fix segment fault while engine resolution
Browse files Browse the repository at this point in the history
Replaced import statement for bundled Marp Core into classic require.
  • Loading branch information
yhatt committed Nov 21, 2022
1 parent eca7a3d commit d593f5b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 35 deletions.
3 changes: 0 additions & 3 deletions marp-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

'use strict'

const SegfaultHandler = require('segfault-handler')
SegfaultHandler.registerHandler('crash.log')

require('v8-compile-cache')
require('./lib/marp-cli.js')
.cliInterface(process.argv.slice(2))
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@
"rollup-plugin-pug": "^1.1.1",
"rollup-plugin-terser": "^7.0.2",
"sass": "^1.56.1",
"segfault-handler": "^1.3.0",
"strip-ansi": "^7.0.1",
"stylelint": "^14.15.0",
"stylelint-config-prettier": "^9.0.4",
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
25 changes: 0 additions & 25 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2168,13 +2168,6 @@ binary-extensions@^2.0.0:
resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-2.2.0.tgz#75f502eeaf9ffde42fc98829645be4ea76bd9e2d"
integrity sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==

bindings@^1.2.1:
version "1.5.0"
resolved "https://registry.yarnpkg.com/bindings/-/bindings-1.5.0.tgz#10353c9e945334bc0511a6d90b38fbc7c9c504df"
integrity sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==
dependencies:
file-uri-to-path "1.0.0"

bl@^4.0.3:
version "4.1.0"
resolved "https://registry.yarnpkg.com/bl/-/bl-4.1.0.tgz#451535264182bec2fbbc83a62ab98cf11d9f7b3a"
Expand Down Expand Up @@ -3568,11 +3561,6 @@ file-entry-cache@^6.0.1:
dependencies:
flat-cache "^3.0.4"

[email protected]:
version "1.0.0"
resolved "https://registry.yarnpkg.com/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz#553a7b8446ff6f684359c445f1e37a05dacc33dd"
integrity sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==

fill-range@^7.0.1:
version "7.0.1"
resolved "https://registry.yarnpkg.com/fill-range/-/fill-range-7.0.1.tgz#1919a6a7c75fe38b2c7c77e5198535da9acdda40"
Expand Down Expand Up @@ -5521,11 +5509,6 @@ multistream@^4.1.0:
once "^1.4.0"
readable-stream "^3.6.0"

nan@^2.14.0:
version "2.17.0"
resolved "https://registry.yarnpkg.com/nan/-/nan-2.17.0.tgz#c0150a2368a182f033e9aa5195ec76ea41a199cb"
integrity sha512-2ZTgtl0nJsO0KQCjEpxcIr5D+Yv90plTitZt9JBfQvVJDS5seMl3FOvsh3+9CoYWXf/1l5OaZzzF6nDm4cagaQ==

nanoid@^3.3.4:
version "3.3.4"
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.3.4.tgz#730b67e3cd09e2deacf03c027c81c9d9dbc5e8ab"
Expand Down Expand Up @@ -6962,14 +6945,6 @@ saxes@^6.0.0:
dependencies:
xmlchars "^2.2.0"

segfault-handler@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/segfault-handler/-/segfault-handler-1.3.0.tgz#054bc847832fa14f218ba6a79e42877501c8870e"
integrity sha512-p7kVHo+4uoYkr0jmIiTBthwV5L2qmWtben/KDunDZ834mbos+tY+iO0//HpAJpOFSQZZ+wxKWuRo4DxV02B7Lg==
dependencies:
bindings "^1.2.1"
nan "^2.14.0"

"semver@2 || 3 || 4 || 5", semver@^5.4.1, semver@^5.5.0:
version "5.7.1"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.1.tgz#a954f931aeba508d307bbf069eff0c01c96116f7"
Expand Down

0 comments on commit d593f5b

Please sign in to comment.