@open-mercato/shared 0.4.11-develop.1525.b0f8ae5164 → 0.4.11-develop.1530.964c5df5df

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.
@@ -1,4 +1,4 @@
1
- const APP_VERSION = "0.4.11-develop.1525.b0f8ae5164";
1
+ const APP_VERSION = "0.4.11-develop.1530.964c5df5df";
2
2
  const appVersion = APP_VERSION;
3
3
  export {
4
4
  APP_VERSION,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/lib/version.ts"],
4
- "sourcesContent": ["// Build-time generated version\nexport const APP_VERSION = '0.4.11-develop.1525.b0f8ae5164'\nexport const appVersion = APP_VERSION\n"],
4
+ "sourcesContent": ["// Build-time generated version\nexport const APP_VERSION = '0.4.11-develop.1530.964c5df5df'\nexport const appVersion = APP_VERSION\n"],
5
5
  "mappings": "AACO,MAAM,cAAc;AACpB,MAAM,aAAa;",
6
6
  "names": []
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-mercato/shared",
3
- "version": "0.4.11-develop.1525.b0f8ae5164",
3
+ "version": "0.4.11-develop.1530.964c5df5df",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "scripts": {
@@ -0,0 +1,93 @@
1
+ import fs from 'node:fs'
2
+ import os from 'node:os'
3
+ import path from 'node:path'
4
+
5
+ import { findAllApps, findAppRoot, type AppRoot } from '../appResolver'
6
+
7
+ type NextConfigName = 'next.config.ts' | 'next.config.js' | 'next.config.mjs'
8
+
9
+ function createApp(rootDir: string, relativeAppDir: string, configName: NextConfigName, withGeneratedDir: boolean = true): AppRoot {
10
+ const appDir = path.join(rootDir, relativeAppDir)
11
+ const mercatoDir = path.join(appDir, '.mercato')
12
+ const generatedDir = path.join(mercatoDir, 'generated')
13
+
14
+ fs.mkdirSync(appDir, { recursive: true })
15
+ fs.writeFileSync(path.join(appDir, configName), 'export default {}')
16
+
17
+ if (withGeneratedDir) {
18
+ fs.mkdirSync(generatedDir, { recursive: true })
19
+ }
20
+
21
+ return { appDir, mercatoDir, generatedDir }
22
+ }
23
+
24
+ describe('appResolver', () => {
25
+ let tempDir: string
26
+
27
+ beforeEach(() => {
28
+ tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'open-mercato-app-resolver-'))
29
+ })
30
+
31
+ afterEach(() => {
32
+ fs.rmSync(tempDir, { recursive: true, force: true })
33
+ })
34
+
35
+ describe('findAppRoot', () => {
36
+ it('finds the nearest app root from a nested directory', () => {
37
+ const app = createApp(tempDir, 'apps/mercato', 'next.config.ts')
38
+ const nestedDir = path.join(app.appDir, 'src', 'modules', 'customers')
39
+
40
+ fs.mkdirSync(nestedDir, { recursive: true })
41
+
42
+ expect(findAppRoot(nestedDir)).toEqual(app)
43
+ })
44
+
45
+ it.each<NextConfigName>(['next.config.ts', 'next.config.js', 'next.config.mjs'])(
46
+ 'supports %s app config files',
47
+ (configName) => {
48
+ const app = createApp(tempDir, configName.replace(/\./g, '-'), configName)
49
+
50
+ expect(findAppRoot(app.appDir)).toEqual(app)
51
+ },
52
+ )
53
+
54
+ it('returns the nearest Next.js app even when generated output is missing', () => {
55
+ const outerApp = createApp(tempDir, 'apps/outer', 'next.config.ts')
56
+ const innerApp = createApp(outerApp.appDir, 'examples/inner', 'next.config.js', false)
57
+ const nestedDir = path.join(innerApp.appDir, 'src')
58
+
59
+ fs.mkdirSync(nestedDir, { recursive: true })
60
+
61
+ expect(findAppRoot(nestedDir)).toEqual(innerApp)
62
+ })
63
+
64
+ it('returns null when no Next.js app can be found', () => {
65
+ const nestedDir = path.join(tempDir, 'packages', 'shared', 'src')
66
+
67
+ fs.mkdirSync(nestedDir, { recursive: true })
68
+
69
+ expect(findAppRoot(nestedDir)).toBeNull()
70
+ })
71
+ })
72
+
73
+ describe('findAllApps', () => {
74
+ it('returns an empty array when the monorepo has no apps directory', () => {
75
+ expect(findAllApps(tempDir)).toEqual([])
76
+ })
77
+
78
+ it('returns only Next.js apps with generated output', () => {
79
+ createApp(tempDir, 'apps/mercato', 'next.config.ts')
80
+ createApp(tempDir, 'apps/docs', 'next.config.js')
81
+ createApp(tempDir, 'apps/admin', 'next.config.mjs')
82
+ createApp(tempDir, 'apps/incomplete', 'next.config.ts', false)
83
+
84
+ fs.writeFileSync(path.join(tempDir, 'apps', 'README.md'), 'not an app')
85
+
86
+ const appNames = findAllApps(tempDir)
87
+ .map((app) => path.basename(app.appDir))
88
+ .sort()
89
+
90
+ expect(appNames).toEqual(['admin', 'docs', 'mercato'])
91
+ })
92
+ })
93
+ })