adapt-authoring-core 2.3.1 → 2.4.1
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.
|
@@ -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,12 @@ 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),
|
|
134
|
+
packageName: pkg.name,
|
|
132
135
|
rootDir: modDir
|
|
133
136
|
}
|
|
134
137
|
}
|
|
@@ -148,7 +151,7 @@ class DependencyLoader {
|
|
|
148
151
|
if (config.module === false) {
|
|
149
152
|
return
|
|
150
153
|
}
|
|
151
|
-
const { default: ModClass } = await import(
|
|
154
|
+
const { default: ModClass } = await import(config.packageName)
|
|
152
155
|
|
|
153
156
|
if (!_.isFunction(ModClass)) {
|
|
154
157
|
throw new Error('Expected class to be exported')
|
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)
|
|
@@ -306,6 +306,36 @@ describe('DependencyLoader', () => {
|
|
|
306
306
|
|
|
307
307
|
assert.equal(config.rootDir, testModuleDir)
|
|
308
308
|
})
|
|
309
|
+
|
|
310
|
+
it('should store original package name as packageName', async () => {
|
|
311
|
+
const mockApp = { rootDir: '/test' }
|
|
312
|
+
const loader = new DependencyLoader(mockApp)
|
|
313
|
+
|
|
314
|
+
const config = await loader.loadModuleConfig(testModuleDir)
|
|
315
|
+
|
|
316
|
+
assert.equal(config.packageName, 'test-module')
|
|
317
|
+
})
|
|
318
|
+
|
|
319
|
+
it('should preserve scoped package name in packageName while stripping scope from name', async () => {
|
|
320
|
+
const scopedDir = path.join(__dirname, 'data', 'scoped-module')
|
|
321
|
+
await fs.ensureDir(scopedDir)
|
|
322
|
+
await fs.writeJson(path.join(scopedDir, 'package.json'), {
|
|
323
|
+
name: '@cgkineo/adapt-authoring-test',
|
|
324
|
+
version: '1.0.0'
|
|
325
|
+
})
|
|
326
|
+
await fs.writeJson(path.join(scopedDir, 'adapt-authoring.json'), {
|
|
327
|
+
module: true
|
|
328
|
+
})
|
|
329
|
+
|
|
330
|
+
const mockApp = { rootDir: '/test' }
|
|
331
|
+
const loader = new DependencyLoader(mockApp)
|
|
332
|
+
const config = await loader.loadModuleConfig(scopedDir)
|
|
333
|
+
|
|
334
|
+
assert.equal(config.name, 'adapt-authoring-test')
|
|
335
|
+
assert.equal(config.packageName, '@cgkineo/adapt-authoring-test')
|
|
336
|
+
|
|
337
|
+
await fs.remove(scopedDir)
|
|
338
|
+
})
|
|
309
339
|
})
|
|
310
340
|
|
|
311
341
|
describe('#loadModules()', () => {
|
|
@@ -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
|
+
})
|