adapt-authoring-core 2.3.0 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/plugins/coremodules.js +1 -1
- package/lib/DependencyLoader.js +4 -2
- package/lib/Hook.js +8 -2
- package/lib/Utils.js +1 -0
- package/lib/utils/stripScope.js +11 -0
- package/package.json +1 -1
- package/tests/DependencyLoader.spec.js +1 -1
- package/tests/Hook.spec.js +30 -0
- package/tests/utils-stripScope.spec.js +54 -0
|
@@ -11,7 +11,7 @@ export default class CoreModules {
|
|
|
11
11
|
|
|
12
12
|
async getWorkflowBadges (homepage) {
|
|
13
13
|
if (!homepage) return []
|
|
14
|
-
const workflows = ['tests', 'standardjs']
|
|
14
|
+
const workflows = ['tests', 'standardjs', 'releases']
|
|
15
15
|
const results = await Promise.all(workflows.map(async w => {
|
|
16
16
|
const url = `${homepage}/actions/workflows/${w}.yml`
|
|
17
17
|
const badgeUrl = `${url}/badge.svg`
|
package/lib/DependencyLoader.js
CHANGED
|
@@ -4,7 +4,7 @@ import fs from 'fs-extra'
|
|
|
4
4
|
import { glob } from 'glob'
|
|
5
5
|
import path from 'path'
|
|
6
6
|
import Hook from './Hook.js'
|
|
7
|
-
import { metadataFileName, packageFileName } from './Utils.js'
|
|
7
|
+
import { metadataFileName, packageFileName, stripScope } from './Utils.js'
|
|
8
8
|
/**
|
|
9
9
|
* Handles the loading of Adapt authoring tool module dependencies.
|
|
10
10
|
* @memberof core
|
|
@@ -126,9 +126,11 @@ class DependencyLoader {
|
|
|
126
126
|
* @return {Promise<Object>} Resolves with configuration object
|
|
127
127
|
*/
|
|
128
128
|
async loadModuleConfig (modDir) {
|
|
129
|
+
const pkg = await fs.readJson(path.join(modDir, packageFileName))
|
|
129
130
|
return {
|
|
130
|
-
...
|
|
131
|
+
...pkg,
|
|
131
132
|
...await fs.readJson(path.join(modDir, metadataFileName)),
|
|
133
|
+
name: stripScope(pkg.name),
|
|
132
134
|
rootDir: modDir
|
|
133
135
|
}
|
|
134
136
|
}
|
package/lib/Hook.js
CHANGED
|
@@ -96,13 +96,19 @@ class Hook {
|
|
|
96
96
|
* @return {Promise}
|
|
97
97
|
*/
|
|
98
98
|
async _invokeMiddleware (coreFn, ...args) {
|
|
99
|
-
let
|
|
99
|
+
let coreResult
|
|
100
|
+
const wrappedCoreFn = async (...a) => {
|
|
101
|
+
coreResult = await coreFn(...a)
|
|
102
|
+
return coreResult
|
|
103
|
+
}
|
|
104
|
+
let fn = wrappedCoreFn
|
|
100
105
|
for (let i = this._hookObservers.length - 1; i >= 0; i--) {
|
|
101
106
|
const observer = this._hookObservers[i]
|
|
102
107
|
const next = fn
|
|
103
108
|
fn = (...a) => observer(next, ...a)
|
|
104
109
|
}
|
|
105
|
-
|
|
110
|
+
const result = await fn(...args)
|
|
111
|
+
return result !== undefined ? result : coreResult
|
|
106
112
|
}
|
|
107
113
|
}
|
|
108
114
|
|
package/lib/Utils.js
CHANGED
|
@@ -8,4 +8,5 @@ export { toBoolean } from './utils/toBoolean.js'
|
|
|
8
8
|
export { ensureDir } from './utils/ensureDir.js'
|
|
9
9
|
export { escapeRegExp } from './utils/escapeRegExp.js'
|
|
10
10
|
export { stringifyValues } from './utils/stringifyValues.js'
|
|
11
|
+
export { stripScope } from './utils/stripScope.js'
|
|
11
12
|
export { loadDependencyFiles } from './utils/loadDependencyFiles.js'
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Strips the npm scope prefix from a package name (e.g. '@cgkineo/adapt-authoring-foo' becomes 'adapt-authoring-foo')
|
|
3
|
+
* @param {string} name - The package name
|
|
4
|
+
* @returns {string} The name without scope prefix
|
|
5
|
+
*/
|
|
6
|
+
export function stripScope (name) {
|
|
7
|
+
if (typeof name === 'string' && name.startsWith('@')) {
|
|
8
|
+
return name.replace(/^@[^/]+\//, '')
|
|
9
|
+
}
|
|
10
|
+
return name
|
|
11
|
+
}
|
package/package.json
CHANGED
|
@@ -292,7 +292,7 @@ describe('DependencyLoader', () => {
|
|
|
292
292
|
const loader = new DependencyLoader(mockApp)
|
|
293
293
|
const config = await loader.loadModuleConfig(overrideDir)
|
|
294
294
|
|
|
295
|
-
assert.equal(config.name, '
|
|
295
|
+
assert.equal(config.name, 'pkg-name')
|
|
296
296
|
assert.equal(config.description, 'from adapt')
|
|
297
297
|
|
|
298
298
|
await fs.remove(overrideDir)
|
package/tests/Hook.spec.js
CHANGED
|
@@ -483,6 +483,36 @@ describe('Hook', () => {
|
|
|
483
483
|
const result = await hook.invoke(core, 1)
|
|
484
484
|
assert.equal(result, 2)
|
|
485
485
|
})
|
|
486
|
+
|
|
487
|
+
it('should fall back to core result when observer calls next() without returning', async () => {
|
|
488
|
+
const hook = new Hook({ type: Hook.Types.Middleware })
|
|
489
|
+
hook.tap(async (next, val) => {
|
|
490
|
+
await next(val) // calls next but doesn't return the result
|
|
491
|
+
})
|
|
492
|
+
const core = async (val) => val * 3
|
|
493
|
+
const result = await hook.invoke(core, 7)
|
|
494
|
+
assert.equal(result, 21)
|
|
495
|
+
})
|
|
496
|
+
|
|
497
|
+
it('should fall back to core result through multiple non-returning observers', async () => {
|
|
498
|
+
const hook = new Hook({ type: Hook.Types.Middleware })
|
|
499
|
+
hook.tap(async (next, val) => { await next(val) })
|
|
500
|
+
hook.tap(async (next, val) => { await next(val) })
|
|
501
|
+
const core = async (val) => ({ id: val })
|
|
502
|
+
const result = await hook.invoke(core, 42)
|
|
503
|
+
assert.deepEqual(result, { id: 42 })
|
|
504
|
+
})
|
|
505
|
+
|
|
506
|
+
it('should prefer explicit observer return over core result fallback', async () => {
|
|
507
|
+
const hook = new Hook({ type: Hook.Types.Middleware })
|
|
508
|
+
hook.tap(async (next, val) => {
|
|
509
|
+
await next(val)
|
|
510
|
+
return 'transformed'
|
|
511
|
+
})
|
|
512
|
+
const core = async (val) => val
|
|
513
|
+
const result = await hook.invoke(core, 'original')
|
|
514
|
+
assert.equal(result, 'transformed')
|
|
515
|
+
})
|
|
486
516
|
})
|
|
487
517
|
})
|
|
488
518
|
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { describe, it } from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
3
|
+
|
|
4
|
+
import { stripScope } from '../lib/utils/stripScope.js'
|
|
5
|
+
|
|
6
|
+
describe('stripScope()', () => {
|
|
7
|
+
it('should strip a single-word scope', () => {
|
|
8
|
+
assert.equal(stripScope('@myorg/my-package'), 'my-package')
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
it('should strip a hyphenated scope', () => {
|
|
12
|
+
assert.equal(stripScope('@my-org/my-package'), 'my-package')
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
it('should strip a scope containing a dot', () => {
|
|
16
|
+
assert.equal(stripScope('@my.org/my-package'), 'my-package')
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
it('should strip a scope containing an underscore', () => {
|
|
20
|
+
assert.equal(stripScope('@my_org/my-package'), 'my-package')
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
it('should strip a scope containing numbers', () => {
|
|
24
|
+
assert.equal(stripScope('@org123/my-package'), 'my-package')
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
it('should return an unscoped name unchanged', () => {
|
|
28
|
+
assert.equal(stripScope('my-package'), 'my-package')
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
it('should return a short name unchanged', () => {
|
|
32
|
+
assert.equal(stripScope('lodash'), 'lodash')
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
it('should return an empty string unchanged', () => {
|
|
36
|
+
assert.equal(stripScope(''), '')
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
it('should return undefined unchanged', () => {
|
|
40
|
+
assert.equal(stripScope(undefined), undefined)
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
it('should return null unchanged', () => {
|
|
44
|
+
assert.equal(stripScope(null), null)
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
it('should handle scope with nested slashes in package name', () => {
|
|
48
|
+
assert.equal(stripScope('@scope/name/extra'), 'name/extra')
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
it('should handle @ in the middle of a name', () => {
|
|
52
|
+
assert.equal(stripScope('name@2.0.0'), 'name@2.0.0')
|
|
53
|
+
})
|
|
54
|
+
})
|