adapt-authoring-core 2.1.2 → 2.1.3

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.
@@ -93,27 +93,29 @@ class DependencyLoader {
93
93
  .map(d => d.replace(`${metadataFileName}`, ''))
94
94
  .sort((a, b) => a.length < b.length ? -1 : 1)
95
95
 
96
- const configCache = {}
97
- await Promise.all(deps.map(async d => {
96
+ // sort so that core is loaded first, as other modules may use its config values
97
+ const corePathSegment = `/${this.app.name}/`
98
+ deps.sort((a, b) => {
99
+ if (a.endsWith(corePathSegment)) return -1
100
+ if (b.endsWith(corePathSegment)) return 1
101
+ return 0
102
+ })
103
+ for (const d of deps) {
98
104
  try {
99
- configCache[d] = await this.loadModuleConfig(d)
105
+ const c = await this.loadModuleConfig(d)
106
+ if (!this.configs[c.name]) {
107
+ this.configs[c.name] = c
108
+ if (c.peerDependencies) {
109
+ Object.keys(c.peerDependencies).forEach(p => {
110
+ this.peerDependencies[p] = [...(this.peerDependencies[p] || []), c.name]
111
+ })
112
+ }
113
+ }
100
114
  } catch (e) {
101
115
  this.logError(`Failed to load config for '${d}', module will not be loaded`)
102
116
  this.logError(e)
103
117
  }
104
- }))
105
- deps.forEach(d => {
106
- const c = configCache[d]
107
- if (this.configs[c.name]) {
108
- return
109
- }
110
- this.configs[c.name] = c
111
- if (c.peerDependencies) {
112
- Object.keys(c.peerDependencies).forEach(p => {
113
- this.peerDependencies[p] = [...(this.peerDependencies[p] || []), c.name]
114
- })
115
- }
116
- })
118
+ }
117
119
  this._configsLoaded = true
118
120
  await this.configsLoadedHook.invoke()
119
121
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adapt-authoring-core",
3
- "version": "2.1.2",
3
+ "version": "2.1.3",
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",
@@ -206,6 +206,39 @@ describe('DependencyLoader', () => {
206
206
  })
207
207
  })
208
208
 
209
+ describe('#loadConfigs()', () => {
210
+ let testRootDir
211
+
212
+ before(async () => {
213
+ testRootDir = path.join(__dirname, 'data', 'loadconfigs-root')
214
+ // create mock node_modules with core and modules that sort before it alphabetically
215
+ const authDir = path.join(testRootDir, 'node_modules', 'adapt-authoring-auth')
216
+ const configDir = path.join(testRootDir, 'node_modules', 'adapt-authoring-config')
217
+ const coreDir = path.join(testRootDir, 'node_modules', 'adapt-authoring-core')
218
+ await fs.ensureDir(authDir)
219
+ await fs.ensureDir(configDir)
220
+ await fs.ensureDir(coreDir)
221
+ await fs.writeJson(path.join(authDir, 'package.json'), { name: 'adapt-authoring-auth' })
222
+ await fs.writeJson(path.join(authDir, 'adapt-authoring.json'), { module: true })
223
+ await fs.writeJson(path.join(configDir, 'package.json'), { name: 'adapt-authoring-config' })
224
+ await fs.writeJson(path.join(configDir, 'adapt-authoring.json'), { module: true })
225
+ await fs.writeJson(path.join(coreDir, 'package.json'), { name: 'adapt-authoring-core' })
226
+ await fs.writeJson(path.join(coreDir, 'adapt-authoring.json'), { module: false })
227
+ })
228
+
229
+ after(async () => {
230
+ await fs.remove(testRootDir)
231
+ })
232
+
233
+ it('should load core config first', async () => {
234
+ const mockApp = { rootDir: testRootDir, name: 'adapt-authoring-core' }
235
+ const loader = new DependencyLoader(mockApp)
236
+ await loader.loadConfigs()
237
+ const names = Object.keys(loader.configs)
238
+ assert.equal(names[0], 'adapt-authoring-core')
239
+ })
240
+ })
241
+
209
242
  describe('#loadModuleConfig()', () => {
210
243
  let testModuleDir
211
244