pinokiod 8.0.0 → 8.0.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.
package/kernel/index.js CHANGED
@@ -276,14 +276,17 @@ class Kernel {
276
276
  ]
277
277
  }
278
278
  if (config) {
279
- if (config.dns) {
279
+ const configuredDns = config.dns
280
+ config = {
281
+ ...config,
282
+ dns: configuredDns ? { ...configuredDns } : dns
283
+ }
284
+ if (configuredDns) {
280
285
  for(let key in config.dns) {
281
286
  if (config.dns[key]) {
282
287
  config.dns[key] = config.dns[key].concat(dns[key])
283
288
  }
284
289
  }
285
- } else {
286
- config.dns = dns
287
290
  }
288
291
  } else {
289
292
  config = {
package/kernel/loader.js CHANGED
@@ -57,6 +57,14 @@ class Loader {
57
57
  try { config = require(filepath) } catch (e) {
58
58
  console.log("> load", e, filepath)
59
59
  }
60
+ if (
61
+ config &&
62
+ typeof config === "object" &&
63
+ Object.prototype.hasOwnProperty.call(config, "default") &&
64
+ (config.__esModule === true || config[Symbol.toStringTag] === "Module")
65
+ ) {
66
+ config = config.default
67
+ }
60
68
  try {
61
69
  // if the required module is a class, return the instantiated object
62
70
  return new config();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinokiod",
3
- "version": "8.0.0",
3
+ "version": "8.0.1",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -144,3 +144,42 @@ test('dns keeps dynamic local and port routes without adding a static folder rou
144
144
  ])
145
145
  assert.equal(harness.buildStaticRoutes()['dynamic-app'], undefined)
146
146
  })
147
+
148
+ test('dns derives routes without mutating a frozen launcher config', async (t) => {
149
+ const harness = await createDnsHarness()
150
+ t.after(async () => {
151
+ await fs.rm(harness.root, { recursive: true, force: true })
152
+ })
153
+
154
+ const config = Object.freeze({ title: 'Frozen app' })
155
+ await harness.addApp('frozen-app', { script: config })
156
+
157
+ await harness.kernel.dns({ path: path.join(harness.apiRoot, 'frozen-app') })
158
+
159
+ assert.equal(Object.hasOwn(config, 'dns'), false)
160
+ assert.equal(harness.kernel.pinokio_configs['frozen-app'].title, 'Frozen app')
161
+ assert.deepEqual(harness.kernel.pinokio_configs['frozen-app'].dns['@'], [
162
+ '$local.url@start',
163
+ ])
164
+ })
165
+
166
+ test('dns derives routes from a frozen dns map', async (t) => {
167
+ const harness = await createDnsHarness()
168
+ t.after(async () => {
169
+ await fs.rm(harness.root, { recursive: true, force: true })
170
+ })
171
+
172
+ const configuredRoutes = Object.freeze([':7860'])
173
+ const configuredDns = Object.freeze({ '@': configuredRoutes })
174
+ const config = Object.freeze({ dns: configuredDns })
175
+ await harness.addApp('frozen-dns-app', { script: config })
176
+
177
+ await harness.kernel.dns({ path: path.join(harness.apiRoot, 'frozen-dns-app') })
178
+
179
+ assert.equal(config.dns, configuredDns)
180
+ assert.deepEqual(configuredRoutes, [':7860'])
181
+ assert.deepEqual(harness.kernel.pinokio_configs['frozen-dns-app'].dns['@'], [
182
+ ':7860',
183
+ '$local.url@start',
184
+ ])
185
+ })
@@ -0,0 +1,29 @@
1
+ const assert = require('node:assert/strict')
2
+ const fs = require('node:fs/promises')
3
+ const os = require('node:os')
4
+ const path = require('node:path')
5
+ const test = require('node:test')
6
+
7
+ const Loader = require('../kernel/loader')
8
+
9
+ test('loader unwraps an ESM namespace default export', async (t) => {
10
+ const root = await fs.mkdtemp(path.join(os.tmpdir(), 'pinokio-loader-esm-'))
11
+ const filepath = path.join(root, 'pinokio.js')
12
+ t.after(async () => {
13
+ await fs.rm(root, { recursive: true, force: true })
14
+ })
15
+
16
+ await fs.writeFile(path.join(root, 'package.json'), JSON.stringify({ type: 'module' }))
17
+ await fs.writeFile(filepath, `
18
+ export default {
19
+ title: 'ESM launcher',
20
+ menu: async () => []
21
+ }
22
+ `)
23
+
24
+ const loaded = await new Loader().load(filepath)
25
+
26
+ assert.equal(loaded.resolved.title, 'ESM launcher')
27
+ assert.equal(typeof loaded.resolved.menu, 'function')
28
+ assert.equal(Object.hasOwn(loaded.resolved, 'default'), false)
29
+ })