adapt-authoring-core 2.3.1 → 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.
@@ -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`
@@ -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
- ...await fs.readJson(path.join(modDir, packageFileName)),
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/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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adapt-authoring-core",
3
- "version": "2.3.1",
3
+ "version": "2.4.0",
4
4
  "description": "A bundle of reusable 'core' functionality",
5
5
  "homepage": "https://github.com/adapt-security/adapt-authoring-core",
6
6
  "license": "GPL-3.0",
@@ -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, 'adapt-name')
295
+ assert.equal(config.name, 'pkg-name')
296
296
  assert.equal(config.description, 'from adapt')
297
297
 
298
298
  await fs.remove(overrideDir)
@@ -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
+ })