@toa.io/operations 1.0.0-alpha.31 → 1.0.0-alpha.310

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.
Files changed (76) hide show
  1. package/CHANGELOG.md +213 -0
  2. package/image/runtime.Dockerfile +14 -0
  3. package/package.json +10 -10
  4. package/readme.md +201 -0
  5. package/src/deployment/.deployment/.describe/components.js +1 -5
  6. package/src/deployment/.deployment/.describe/compositions.js +26 -7
  7. package/src/deployment/.deployment/.describe/dependencies.js +1 -6
  8. package/src/deployment/.deployment/.describe/events.js +63 -0
  9. package/src/deployment/.deployment/.describe/fold.js +42 -0
  10. package/src/deployment/.deployment/.describe/fold.test.js +108 -0
  11. package/src/deployment/.deployment/.describe/index.js +4 -13
  12. package/src/deployment/.deployment/.describe/mounts.js +17 -0
  13. package/src/deployment/.deployment/.describe/resources.js +129 -0
  14. package/src/deployment/.deployment/.describe/resources.test.js +129 -0
  15. package/src/deployment/.deployment/.describe/services.js +32 -6
  16. package/src/deployment/.deployment/.describe/services.test.js +78 -0
  17. package/src/deployment/.deployment/.describe/variables.js +5 -9
  18. package/src/deployment/.deployment/declare.js +1 -5
  19. package/src/deployment/.deployment/describe.js +153 -10
  20. package/src/deployment/.deployment/index.js +3 -9
  21. package/src/deployment/.deployment/merge.js +66 -6
  22. package/src/deployment/.deployment/merge.test.js +133 -0
  23. package/src/deployment/chart/templates/components.configmap.yaml +14 -0
  24. package/src/deployment/chart/templates/components.yaml +1 -1
  25. package/src/deployment/chart/templates/compositions.yaml +109 -4
  26. package/src/deployment/chart/templates/mono.yaml +195 -0
  27. package/src/deployment/chart/templates/services.yaml +97 -7
  28. package/src/deployment/chart/values.yaml +23 -1
  29. package/src/deployment/composition.js +8 -6
  30. package/src/deployment/deployment.js +147 -34
  31. package/src/deployment/drain.js +70 -0
  32. package/src/deployment/drain.test.js +64 -0
  33. package/src/deployment/factory.js +169 -37
  34. package/src/deployment/images/bundle.js +88 -0
  35. package/src/deployment/images/composition.Dockerfile +9 -17
  36. package/src/deployment/images/composition.js +9 -56
  37. package/src/deployment/images/dependencies.Dockerfile +23 -0
  38. package/src/deployment/images/dependencies.js +171 -0
  39. package/src/deployment/images/dependencies.test.js +268 -0
  40. package/src/deployment/images/factory.js +31 -15
  41. package/src/deployment/images/format.js +66 -0
  42. package/src/deployment/images/format.test.js +149 -0
  43. package/src/deployment/images/image.fixtures.js +17 -19
  44. package/src/deployment/images/image.js +79 -38
  45. package/src/deployment/images/image.test.js +11 -5
  46. package/src/deployment/images/index.js +1 -5
  47. package/src/deployment/images/mono.Dockerfile +11 -0
  48. package/src/deployment/images/mono.js +15 -0
  49. package/src/deployment/images/publish.js +91 -0
  50. package/src/deployment/images/runtime-base.test.js +97 -0
  51. package/src/deployment/images/service.Dockerfile +17 -5
  52. package/src/deployment/images/service.js +63 -14
  53. package/src/deployment/index.js +1 -5
  54. package/src/deployment/operator.js +22 -16
  55. package/src/deployment/operator.test.js +57 -7
  56. package/src/deployment/registry.js +210 -46
  57. package/src/deployment/registry.test.js +539 -0
  58. package/src/deployment/service.js +4 -6
  59. package/src/deployment/workspace.js +13 -8
  60. package/src/index.js +3 -2
  61. package/src/process.js +51 -13
  62. package/src/process.test.js +33 -0
  63. package/types/_deployment/composition.d.ts +2 -3
  64. package/types/_deployment/dependency.d.ts +13 -7
  65. package/types/_deployment/deployment.d.ts +7 -8
  66. package/types/_deployment/factory.d.ts +2 -4
  67. package/types/_deployment/images/factory.d.ts +6 -8
  68. package/types/_deployment/images/image.d.ts +16 -1
  69. package/types/_deployment/images/registry.d.ts +8 -11
  70. package/types/_deployment/operator.d.ts +10 -9
  71. package/types/_deployment/registry.d.ts +7 -4
  72. package/types/_deployment/service.d.ts +4 -3
  73. package/types/dependency.ts +79 -0
  74. package/types/index.ts +1 -0
  75. package/types/dependency.d.ts +0 -39
  76. package/types/index.d.ts +0 -1
@@ -0,0 +1,171 @@
1
+ import { basename, join } from 'node:path'
2
+ import { existsSync, readFileSync } from 'node:fs'
3
+ import { copyFile, mkdir, writeFile } from 'node:fs/promises'
4
+ import { createHash } from 'node:crypto'
5
+
6
+ import { Image } from './image.js'
7
+
8
+ /**
9
+ * What a bundle's components depend on, installed on the base: the layers that weigh the
10
+ * most and change the least, so they are an image of their own. Its tag digests everything
11
+ * the install reads, and nothing else: a change to the sources leaves it where it is, and a
12
+ * bundle is laid over it without building or moving it again.
13
+ *
14
+ * @implements {toa.deployment.images.Image}
15
+ */
16
+ export class Dependencies extends Image {
17
+ dockerfile = join(import.meta.dirname, 'dependencies.Dockerfile')
18
+ arguments = true
19
+
20
+ /** @type {toa.deployment.images.Bundle} */
21
+ #owner
22
+
23
+ #runtime
24
+ #registry
25
+
26
+ /** @type {string | undefined} */
27
+ #version
28
+
29
+ /**
30
+ * @param {string} scope
31
+ * @param {toa.norm.context.Runtime} runtime
32
+ * @param {toa.norm.context.Registry} registry
33
+ * @param {toa.deployment.images.Bundle} owner the bundle laid over this image
34
+ */
35
+ constructor(scope, runtime, registry, owner) {
36
+ super(scope, runtime, registry)
37
+
38
+ this.#owner = owner
39
+ this.#runtime = runtime
40
+ this.#registry = registry
41
+ }
42
+
43
+ /** Same repository as the bundle: a tag apart, not a name apart. */
44
+ get name() {
45
+ return this.#owner.name
46
+ }
47
+
48
+ get version() {
49
+ if (this.#version !== undefined) return this.#version
50
+
51
+ const hash = createHash('sha256')
52
+ const build = this.#registry.build ?? {}
53
+
54
+ const inputs = [
55
+ this.#runtime.version,
56
+ this.#runtime.registry,
57
+ this.#runtime.proxy,
58
+ this.base,
59
+ build.image,
60
+ build.run,
61
+ this.run,
62
+ ...(build.arguments ?? [])
63
+ ]
64
+
65
+ for (const input of inputs) hash.update(input ?? '').update('\0')
66
+
67
+ for (const [label, files] of this.#manifests())
68
+ for (const file of files)
69
+ hash.update(label).update(basename(file)).update(readFileSync(file))
70
+
71
+ hash.update(this.#packages().join('\n'))
72
+
73
+ this.#version = hash.digest('hex').slice(0, 8)
74
+
75
+ return this.#version
76
+ }
77
+
78
+ digest() {
79
+ return PREFIX + this.version
80
+ }
81
+
82
+ get base() {
83
+ if (this.#owner.image !== undefined) return this.#owner.image
84
+
85
+ const images = new Set(
86
+ this.#owner.components.map((component) => component.build?.image)
87
+ )
88
+
89
+ if (images.size > 1) throw new Error(this.#owner.conflict())
90
+
91
+ return images.values().next().value
92
+ }
93
+
94
+ get run() {
95
+ const commands = []
96
+
97
+ for (const component of this.#owner.components) {
98
+ const run = component.build?.run
99
+
100
+ if (run !== undefined) commands.push(run)
101
+ }
102
+
103
+ return commands.join('\n')
104
+ }
105
+
106
+ async prepare(root) {
107
+ const context = await super.prepare(join(root, DIRECTORY))
108
+
109
+ for (const [label, files] of this.#manifests()) {
110
+ const target = join(context, label)
111
+
112
+ await mkdir(target, { recursive: true })
113
+
114
+ for (const file of files) await copyFile(file, join(target, basename(file)))
115
+ }
116
+
117
+ const packages = this.#packages()
118
+
119
+ // written whether or not there are any, so the file is one thing the Dockerfile reads
120
+ await writeFile(join(context, PACKAGES), packages.join('\n'))
121
+
122
+ return context
123
+ }
124
+
125
+ /**
126
+ * What the extensions install for what this workload runs, as `name@version`: what its
127
+ * components declare, and what the services it hosts bring. A component states its own
128
+ * dependencies in its manifest; this is what the packages that read its declaration need,
129
+ * which its manifest has no way to say.
130
+ *
131
+ * @returns {string[]}
132
+ */
133
+ #packages() {
134
+ /** @type {Record<string, string>} */
135
+ const packages = { ...this.#owner.packages }
136
+
137
+ for (const component of this.#owner.components)
138
+ Object.assign(packages, component.packages)
139
+
140
+ return Object.entries(packages)
141
+ .map(([name, version]) => `${name}@${version}`)
142
+ .sort()
143
+ }
144
+
145
+ /**
146
+ * The files the install reads, by component label, in a fixed order.
147
+ *
148
+ * @returns {Array<[string, string[]]>}
149
+ */
150
+ #manifests() {
151
+ const manifests = []
152
+
153
+ for (const component of this.#owner.components) {
154
+ const files = MANIFESTS.map((name) => join(component.path, name)).filter(existsSync)
155
+
156
+ if (files.length > 0) manifests.push([component.locator.label, files])
157
+ }
158
+
159
+ return manifests.sort(([a], [b]) => a.localeCompare(b))
160
+ }
161
+ }
162
+
163
+ const PREFIX = 'deps-'
164
+
165
+ /** Where the contexts land, apart from the bundles', whose names they share. */
166
+ const DIRECTORY = 'dependencies'
167
+
168
+ const MANIFESTS = ['package.json', 'package-lock.json']
169
+
170
+ /** Where the install reads what the extensions need, one `name@version` per line. */
171
+ const PACKAGES = '.packages'
@@ -0,0 +1,268 @@
1
+ import { describe, it, beforeEach } from 'node:test'
2
+ import assert from 'node:assert/strict'
3
+
4
+ import { join } from 'node:path'
5
+ import { mkdtemp, mkdir, writeFile, readdir, readFile } from 'node:fs/promises'
6
+ import { tmpdir } from 'node:os'
7
+
8
+ import { Composition } from './composition.js'
9
+ import { Mono } from './mono.js'
10
+
11
+ /** @type {string} */
12
+ let root
13
+
14
+ /** @type {toa.norm.context.Runtime} */
15
+ let runtime
16
+
17
+ /** @type {toa.norm.context.Registry} */
18
+ let registry
19
+
20
+ /** @type {object} */
21
+ let composition
22
+
23
+ beforeEach(async () => {
24
+ root = await mkdtemp(join(tmpdir(), 'toa-dependencies-test'))
25
+ runtime = { version: '1.0.0-alpha.288' }
26
+ registry = { base: 'example.com/reg', platforms: ['linux/amd64'] }
27
+
28
+ composition = {
29
+ name: 'mono',
30
+ components: [
31
+ await component('one', { dependencies: { left: '1.0.0' } }),
32
+ await component('two'),
33
+ await component('three', { devDependencies: { right: '1.0.0' } }, 'lock')
34
+ ]
35
+ }
36
+ })
37
+
38
+ describe('reference', () => {
39
+ it('should share the repository and stand a prefix apart', () => {
40
+ const image = create()
41
+
42
+ assert.match(
43
+ image.dependencies.reference,
44
+ /^example\.com\/reg\/acme\/composition-mono:deps-[0-9a-f]{8}$/
45
+ )
46
+ assert.match(
47
+ image.reference,
48
+ /^example\.com\/reg\/acme\/composition-mono:[0-9a-f]{8}$/
49
+ )
50
+ assert.strictEqual(image.base, image.dependencies.reference)
51
+ })
52
+
53
+ it('should be the same for the same inputs', () => {
54
+ assert.strictEqual(create().dependencies.reference, create().dependencies.reference)
55
+ })
56
+
57
+ it('should change with a manifest', async () => {
58
+ const before = create()
59
+
60
+ await writeFile(
61
+ join(composition.components[0].path, 'package.json'),
62
+ JSON.stringify({ dependencies: { left: '1.0.1' } })
63
+ )
64
+
65
+ const after = create()
66
+
67
+ assert.notStrictEqual(after.dependencies.reference, before.dependencies.reference)
68
+ assert.notStrictEqual(after.reference, before.reference)
69
+ })
70
+
71
+ it('should change with a lockfile', async () => {
72
+ const before = create()
73
+
74
+ await writeFile(join(composition.components[2].path, 'package-lock.json'), 'other')
75
+
76
+ assert.notStrictEqual(create().dependencies.reference, before.dependencies.reference)
77
+ })
78
+
79
+ it('should change with what is run and with the runtime', () => {
80
+ const before = create()
81
+
82
+ composition.components[1].build = { run: 'apk add git' }
83
+
84
+ const run = create()
85
+
86
+ assert.notStrictEqual(run.dependencies.reference, before.dependencies.reference)
87
+
88
+ runtime.version = '1.0.0-alpha.289'
89
+
90
+ assert.notStrictEqual(create().dependencies.reference, run.dependencies.reference)
91
+ })
92
+
93
+ it('should change with what an extension installs', () => {
94
+ const before = create()
95
+
96
+ composition.components[1].packages = { cloudinary: '2.11.0' }
97
+
98
+ const component = create()
99
+
100
+ assert.notStrictEqual(component.dependencies.reference, before.dependencies.reference)
101
+
102
+ composition.packages = { 'lru-cache': '11.5.2' }
103
+
104
+ assert.notStrictEqual(create().dependencies.reference, component.dependencies.reference)
105
+ })
106
+
107
+ it('should change with the registry build settings', () => {
108
+ const before = create()
109
+
110
+ registry.build = { arguments: ['TOKEN'] }
111
+
112
+ assert.notStrictEqual(create().dependencies.reference, before.dependencies.reference)
113
+ })
114
+
115
+ it('should not change with the sources', async () => {
116
+ const before = create()
117
+
118
+ await writeFile(
119
+ join(composition.components[0].path, 'index.js'),
120
+ 'export const changed = true'
121
+ )
122
+ composition.components[0].version = 'ffffffff'
123
+
124
+ const after = create()
125
+
126
+ assert.strictEqual(after.dependencies.reference, before.dependencies.reference)
127
+ assert.notStrictEqual(after.reference, before.reference)
128
+ })
129
+ })
130
+
131
+ describe('prepare', () => {
132
+ it('should hold the manifests and nothing else', async () => {
133
+ const image = create()
134
+ const context = await image.dependencies.prepare(root)
135
+
136
+ assert.strictEqual(
137
+ context,
138
+ join(root, 'dependencies', `composition-mono.${image.dependencies.version}`)
139
+ )
140
+
141
+ const entries = (await readdir(context, { recursive: true })).sort()
142
+
143
+ assert.deepStrictEqual(entries, [
144
+ '.dockerignore',
145
+ '.packages',
146
+ 'Dockerfile',
147
+ 'one',
148
+ 'one/package.json',
149
+ 'three',
150
+ 'three/package-lock.json',
151
+ 'three/package.json'
152
+ ])
153
+
154
+ const dockerfile = await readFile(join(context, 'Dockerfile'), 'utf8')
155
+
156
+ assert.ok(dockerfile.includes('FROM ghcr.io/toa-io/runtime:1.0.0-alpha.288'))
157
+ assert.ok(dockerfile.includes('npm i --omit=dev'))
158
+ assert.ok(dockerfile.includes('WORKDIR /composition'))
159
+ assert.doesNotMatch(dockerfile, /USER node|CMD /)
160
+ })
161
+
162
+ it('should hold what the extensions install, deduplicated and ordered', async () => {
163
+ composition.components[0].packages = { cloudinary: '2.11.0' }
164
+ composition.components[1].packages = {
165
+ cloudinary: '2.11.0',
166
+ '@aws-sdk/client-s3': '3.1125.0'
167
+ }
168
+
169
+ const image = create()
170
+ const context = await image.dependencies.prepare(root)
171
+
172
+ assert.strictEqual(
173
+ await readFile(join(context, '.packages'), 'utf8'),
174
+ '@aws-sdk/client-s3@3.1125.0\ncloudinary@2.11.0'
175
+ )
176
+
177
+ const dockerfile = await readFile(join(context, 'Dockerfile'), 'utf8')
178
+
179
+ assert.ok(dockerfile.includes('npm i --prefix /toa --omit=dev $(cat .packages)'))
180
+ })
181
+
182
+ it('should hold what a service the composition runs brings', async () => {
183
+ composition.packages = { 'lru-cache': '11.5.2' }
184
+ composition.components[0].packages = { cloudinary: '2.11.0' }
185
+
186
+ const context = await create().dependencies.prepare(root)
187
+
188
+ assert.strictEqual(
189
+ await readFile(join(context, '.packages'), 'utf8'),
190
+ 'cloudinary@2.11.0\nlru-cache@11.5.2'
191
+ )
192
+ })
193
+
194
+ it('should hold an empty list where nothing is declared', async () => {
195
+ const context = await create().dependencies.prepare(root)
196
+
197
+ assert.strictEqual(await readFile(join(context, '.packages'), 'utf8'), '')
198
+ })
199
+
200
+ it('should lay the sources over the dependencies', async () => {
201
+ const image = create()
202
+
203
+ image.dependencies.tag()
204
+
205
+ const context = await image.prepare(root)
206
+ const dockerfile = await readFile(join(context, 'Dockerfile'), 'utf8')
207
+ const lines = dockerfile
208
+ .split('\n')
209
+ .filter((line) => line !== '' && !line.startsWith('#'))
210
+
211
+ // no USER: the runtime starts as root and drops to `node` itself, and nothing else
212
+ // touches the filesystem, which is what lets the layer be laid over a base never pulled
213
+ assert.deepStrictEqual(lines, [
214
+ `FROM ${image.dependencies.reference}`,
215
+ 'COPY --link . /composition',
216
+ 'CMD toa compose * --map /etc/toa/.map.json'
217
+ ])
218
+
219
+ const entries = (await readdir(context, { recursive: true })).sort()
220
+
221
+ assert.ok(entries.includes('one/index.js'))
222
+ assert.ok(entries.includes('two/package.json')) // declared for the component that had none
223
+ assert.ok(entries.includes('one/manifest.toa.json')) // what the process reads instead of normalizing
224
+ assert.ok(!entries.some((entry) => entry.includes('node_modules')))
225
+ })
226
+
227
+ it('should run mono the same way', async () => {
228
+ const image = new Mono('acme', runtime, registry, composition)
229
+
230
+ image.tag()
231
+
232
+ assert.match(image.dependencies.reference, /\/mono:deps-[0-9a-f]{8}$/)
233
+
234
+ const context = await image.prepare(root)
235
+ const dockerfile = await readFile(join(context, 'Dockerfile'), 'utf8')
236
+
237
+ assert.ok(dockerfile.includes('CMD toa mono *'))
238
+ assert.doesNotMatch(dockerfile, /^USER /m)
239
+ })
240
+ })
241
+
242
+ /** @returns {Composition} */
243
+ function create() {
244
+ const image = new Composition('acme', runtime, registry, composition)
245
+
246
+ image.tag()
247
+
248
+ return image
249
+ }
250
+
251
+ /**
252
+ * @param {string} label
253
+ * @param {object} [manifest]
254
+ * @param {string} [lock]
255
+ */
256
+ async function component(label, manifest, lock) {
257
+ const path = join(root, 'components', label)
258
+
259
+ await mkdir(join(path, 'node_modules', 'left'), { recursive: true })
260
+ await writeFile(join(path, 'index.js'), 'export const changed = false')
261
+ await writeFile(join(path, 'node_modules', 'left', 'index.js'), '')
262
+
263
+ if (manifest !== undefined)
264
+ await writeFile(join(path, 'package.json'), JSON.stringify(manifest))
265
+ if (lock !== undefined) await writeFile(join(path, 'package-lock.json'), lock)
266
+
267
+ return { path, version: 'abcdef12', locator: { id: `default.${label}`, label } }
268
+ }
@@ -1,12 +1,8 @@
1
- 'use strict'
1
+ import { Composition } from './composition.js'
2
+ import { Service } from './service.js'
3
+ import { Mono } from './mono.js'
2
4
 
3
- const { Composition } = require('./composition')
4
- const { Service } = require('./service')
5
-
6
- /**
7
- * @implements {toa.deployment.images.Factory}
8
- */
9
- class Factory {
5
+ export class Factory {
10
6
  /** @type {string} */
11
7
  #scope
12
8
 
@@ -21,7 +17,7 @@ class Factory {
21
17
  * @param {toa.norm.context.Runtime} runtime
22
18
  * @param {toa.norm.context.Registry} registry
23
19
  */
24
- constructor (scope, runtime, registry) {
20
+ constructor(scope, runtime, registry) {
25
21
  this.#scope = scope
26
22
  this.#runtime = runtime
27
23
  this.#registry = registry
@@ -30,8 +26,13 @@ class Factory {
30
26
  /**
31
27
  * @returns {Composition}
32
28
  */
33
- composition (composition) {
34
- const instance = new Composition(this.#scope, this.#runtime, this.#registry, composition)
29
+ composition(composition) {
30
+ const instance = new Composition(
31
+ this.#scope,
32
+ this.#runtime,
33
+ this.#registry,
34
+ composition
35
+ )
35
36
 
36
37
  instance.tag()
37
38
 
@@ -41,13 +42,28 @@ class Factory {
41
42
  /**
42
43
  * @returns {Service}
43
44
  */
44
- service (path, service) {
45
- const instance = new Service(this.#scope, this.#runtime, this.#registry, path, service)
45
+ service(path, service) {
46
+ const instance = new Service(
47
+ this.#scope,
48
+ this.#runtime,
49
+ this.#registry,
50
+ path,
51
+ service
52
+ )
46
53
 
47
54
  instance.tag()
48
55
 
49
56
  return instance
50
57
  }
51
- }
52
58
 
53
- exports.Factory = Factory
59
+ /**
60
+ * @returns {Mono}
61
+ */
62
+ mono(composition) {
63
+ const instance = new Mono(this.#scope, this.#runtime, this.#registry, composition)
64
+
65
+ instance.tag()
66
+
67
+ return instance
68
+ }
69
+ }
@@ -0,0 +1,66 @@
1
+ import { existsSync, readFileSync } from 'node:fs'
2
+ import { writeFile } from 'node:fs/promises'
3
+ import { dirname, join, parse } from 'node:path'
4
+
5
+ import { NORMALIZED, plain } from '@toa.io/norm'
6
+
7
+ /**
8
+ * A component is copied into the image on its own, away from the package that
9
+ * declared what its files are. Node reads a `.js` as CommonJS unless a manifest
10
+ * beside it says otherwise, so the one the component was written under is
11
+ * restated where it lands.
12
+ *
13
+ * A component that ships its own manifest already says so, and is left alone.
14
+ *
15
+ * @param {string} source the component in the workspace
16
+ * @param {string} target where it was copied
17
+ * @param {string} name
18
+ */
19
+ export async function declare(source, target, name) {
20
+ if (existsSync(join(target, MANIFEST))) return
21
+
22
+ await writeFile(
23
+ join(target, MANIFEST),
24
+ JSON.stringify({ name, private: true, type: format(source) }, null, 2) + '\n'
25
+ )
26
+ }
27
+
28
+ /**
29
+ * The manifest as this build read it, written beside the component so that the process which
30
+ * runs it does not read it again. See `plain` in `@toa.io/norm` for what is left out and why
31
+ * a build's answer is the one to trust.
32
+ *
33
+ * @param {toa.norm.Component} component
34
+ * @param {string} target where it was copied
35
+ */
36
+ export async function normalized(component, target) {
37
+ await writeFile(join(target, NORMALIZED), JSON.stringify(plain(component)))
38
+ }
39
+
40
+ /**
41
+ * The module format a directory's files are read as, which the nearest manifest
42
+ * above it decides.
43
+ *
44
+ * @param {string} directory
45
+ * @returns {'module' | 'commonjs'}
46
+ */
47
+ export function format(directory) {
48
+ const { root } = parse(directory)
49
+
50
+ let current = directory
51
+
52
+ while (current !== root) {
53
+ const manifest = join(current, MANIFEST)
54
+
55
+ if (existsSync(manifest))
56
+ return JSON.parse(readFileSync(manifest, 'utf8')).type === 'module'
57
+ ? 'module'
58
+ : 'commonjs'
59
+
60
+ current = dirname(current)
61
+ }
62
+
63
+ return 'commonjs'
64
+ }
65
+
66
+ const MANIFEST = 'package.json'