@ossy/app 1.0.7 → 1.0.9

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/cli/build.js CHANGED
@@ -12,11 +12,10 @@ import copy from 'rollup-plugin-copy';
12
12
  import replace from '@rollup/plugin-replace';
13
13
  import arg from 'arg'
14
14
  import { ensureBuildStubs } from '../scripts/ensure-build-stubs.mjs'
15
- import { createRequire } from 'node:module'
16
15
 
17
- const PAGE_FILE_PATTERN = /\.page\.(jsx?|tsx?)$/
18
- const API_FILE_PATTERN = /\.api\.(mjs|cjs|js)$/
19
- const TASK_FILE_PATTERN = /\.task\.(mjs|cjs|js)$/
16
+ export const PAGE_FILE_PATTERN = /\.page\.(jsx?|tsx?)$/
17
+ export const API_FILE_PATTERN = /\.api\.(mjs|cjs|js)$/
18
+ export const TASK_FILE_PATTERN = /\.task\.(mjs|cjs|js)$/
20
19
  const RESOURCE_TEMPLATE_FILE_PATTERN = /\.resource\.js$/
21
20
 
22
21
  /** Written next to `*.resource.js` under `src/resource-templates/` when that dir exists. */
@@ -153,7 +152,6 @@ export function createOssyRollupPlugins ({
153
152
  middlewareSourcePath,
154
153
  configSourcePath,
155
154
  nodeEnv,
156
- nodeExternals: useNodeExternals = false,
157
155
  preferBuiltins = true,
158
156
  copyPublicFrom,
159
157
  buildPath,
@@ -185,16 +183,16 @@ export function createOssyRollupPlugins ({
185
183
  }),
186
184
  json(),
187
185
  ]
188
- if (useNodeExternals) {
189
- plugins.push(
190
- nodeExternals({
191
- deps: true,
192
- devDeps: false,
193
- peerDeps: true,
194
- packagePath: path.join(process.cwd(), 'package.json'),
195
- })
196
- )
197
- }
186
+
187
+ plugins.push(
188
+ nodeExternals({
189
+ deps: true,
190
+ devDeps: false,
191
+ peerDeps: true,
192
+ packagePath: path.join(process.cwd(), 'package.json'),
193
+ })
194
+ )
195
+
198
196
  plugins.push(
199
197
  resolveCommonJsDependencies(),
200
198
  resolveDependencies({ preferBuiltins }),
@@ -214,25 +212,10 @@ export function createOssyRollupPlugins ({
214
212
  return plugins
215
213
  }
216
214
 
217
- export function discoverApiFiles(srcDir) {
218
- const dir = path.resolve(srcDir)
219
- if (!fs.existsSync(dir) || !fs.statSync(dir).isDirectory()) {
220
- return []
221
- }
222
- const files = []
223
- const walk = (d) => {
224
- const entries = fs.readdirSync(d, { withFileTypes: true })
225
- for (const e of entries) {
226
- const full = path.join(d, e.name)
227
- if (e.isDirectory()) walk(full)
228
- else if (API_FILE_PATTERN.test(e.name)) files.push(full)
229
- }
230
- }
231
- walk(dir)
232
- return files.sort()
233
- }
234
-
235
- export function discoverTaskFiles(srcDir) {
215
+ /**
216
+ * Recursively lists files under `srcDir` whose basename matches `filePattern` (e.g. `/\.api\.js$/`).
217
+ */
218
+ export function discoverFilesByPattern (srcDir, filePattern) {
236
219
  const dir = path.resolve(srcDir)
237
220
  if (!fs.existsSync(dir) || !fs.statSync(dir).isDirectory()) {
238
221
  return []
@@ -243,7 +226,7 @@ export function discoverTaskFiles(srcDir) {
243
226
  for (const e of entries) {
244
227
  const full = path.join(d, e.name)
245
228
  if (e.isDirectory()) walk(full)
246
- else if (TASK_FILE_PATTERN.test(e.name)) files.push(full)
229
+ else if (filePattern.test(e.name)) files.push(full)
247
230
  }
248
231
  }
249
232
  walk(dir)
@@ -295,7 +278,7 @@ export function generateApiModule ({ generatedPath, apiFiles }) {
295
278
  export function resolveApiSource ({ srcDir, buildPath }) {
296
279
  ensureOssyGeneratedDir(buildPath)
297
280
  const generatedPath = path.join(ossyGeneratedDir(buildPath), OSSY_GEN_API_BASENAME)
298
- const apiFiles = discoverApiFiles(srcDir)
281
+ const apiFiles = discoverFilesByPattern(srcDir, API_FILE_PATTERN)
299
282
  fs.writeFileSync(
300
283
  generatedPath,
301
284
  generateApiModule({ generatedPath, apiFiles })
@@ -344,7 +327,7 @@ export function resolveTaskSource ({ srcDir, scriptDir, buildPath }) {
344
327
  ensureOssyGeneratedDir(buildPath)
345
328
  const generatedPath = path.join(ossyGeneratedDir(buildPath), OSSY_GEN_TASKS_BASENAME)
346
329
 
347
- const taskFiles = discoverTaskFiles(srcDir)
330
+ const taskFiles = discoverFilesByPattern(srcDir, TASK_FILE_PATTERN)
348
331
  if (taskFiles.length > 0) {
349
332
  fs.writeFileSync(
350
333
  generatedPath,
@@ -359,23 +342,6 @@ export function resolveTaskSource ({ srcDir, scriptDir, buildPath }) {
359
342
  return { taskSourcePath: defaultStub, taskOverviewFiles: [], usedGenerated: false }
360
343
  }
361
344
 
362
- export function discoverPageFiles(srcDir) {
363
- if (!fs.existsSync(srcDir) || !fs.statSync(srcDir).isDirectory()) {
364
- return []
365
- }
366
- const files = []
367
- const walk = (d) => {
368
- const entries = fs.readdirSync(d, { withFileTypes: true })
369
- for (const e of entries) {
370
- const full = path.join(d, e.name)
371
- if (e.isDirectory()) walk(full)
372
- else if (PAGE_FILE_PATTERN.test(e.name)) files.push(full)
373
- }
374
- }
375
- walk(srcDir)
376
- return files.sort()
377
- }
378
-
379
345
  export function filePathToRoute(filePath, srcDir) {
380
346
  const rel = path.relative(srcDir, filePath).replace(/\\/g, '/')
381
347
  let pathPart = rel.replace(PAGE_FILE_PATTERN, '').replace(/\/index$/, '').replace(/\/home$/, '') || 'home'
@@ -511,65 +477,6 @@ export function generatePagesModule (pageFiles, srcDir, generatedPath) {
511
477
  return lines.join('\n')
512
478
  }
513
479
 
514
- export async function discoverModulePageFiles({ configPath }) {
515
- if (!configPath || !fs.existsSync(configPath)) return []
516
- try {
517
- // Try a cheap static parse first so we don't depend on the config file being
518
- // importable (configs often import theme/template modules that may not be
519
- // resolvable in the build-time node context).
520
- const cfgSource = fs.readFileSync(configPath, 'utf8')
521
- const modules = []
522
-
523
- // pagesModules: ['a', "b"]
524
- const arrMatch = cfgSource.match(/pagesModules\s*:\s*\[([^\]]*)\]/m)
525
- if (arrMatch?.[1]) {
526
- const body = arrMatch[1]
527
- const re = /['"]([^'"]+)['"]/g
528
- let m
529
- while ((m = re.exec(body)) !== null) modules.push(m[1])
530
- }
531
-
532
- // pagesModule: 'a'
533
- if (modules.length === 0) {
534
- const singleMatch = cfgSource.match(/pagesModule\s*:\s*['"]([^'"]+)['"]/m)
535
- if (singleMatch?.[1]) modules.push(singleMatch[1])
536
- }
537
-
538
- if (modules.length) {
539
- const req = createRequire(path.resolve(process.cwd(), 'package.json'))
540
- const files = []
541
- for (const name of modules) {
542
- const pkgJsonPath = req.resolve(`${name}/package.json`)
543
- const pkgDir = path.dirname(pkgJsonPath)
544
- const modulePagesDir = path.join(pkgDir, 'src', 'pages')
545
- files.push(...discoverPageFiles(modulePagesDir))
546
- }
547
- return files
548
- }
549
-
550
- const mod = await import(url.pathToFileURL(configPath))
551
- const cfg = mod?.default ?? mod ?? {}
552
- const modules2 = Array.isArray(cfg.pagesModules)
553
- ? cfg.pagesModules
554
- : (typeof cfg.pagesModule === 'string' ? [cfg.pagesModule] : [])
555
-
556
- if (!modules2.length) return []
557
-
558
- const req = createRequire(path.resolve(process.cwd(), 'package.json'))
559
- const files = []
560
- for (const name of modules2) {
561
- const pkgJsonPath = req.resolve(`${name}/package.json`)
562
- const pkgDir = path.dirname(pkgJsonPath)
563
- const modulePagesDir = path.join(pkgDir, 'src', 'pages')
564
- files.push(...discoverPageFiles(modulePagesDir))
565
- }
566
- return files
567
- } catch (e) {
568
- console.warn('[@ossy/app][build] pagesModules config could not be loaded; continuing without modules')
569
- return []
570
- }
571
- }
572
-
573
480
  export function parsePagesFromSource(filePath) {
574
481
  try {
575
482
  const content = fs.readFileSync(filePath, 'utf8')
@@ -666,8 +573,7 @@ export const build = async (cliArgs) => {
666
573
  const buildPath = path.resolve('build')
667
574
  const srcDir = path.resolve('src')
668
575
  const configPath = path.resolve(options['--config'] || 'src/config.js');
669
- const pageFiles = discoverPageFiles(srcDir)
670
- const modulePageFiles = await discoverModulePageFiles({ configPath })
576
+ const pageFiles = discoverFilesByPattern(srcDir, PAGE_FILE_PATTERN)
671
577
 
672
578
  resetOssyBuildDir(buildPath)
673
579
 
@@ -675,14 +581,13 @@ export const build = async (cliArgs) => {
675
581
 
676
582
  const pagesGeneratedPath = path.join(ossyGeneratedDir(buildPath), OSSY_GEN_PAGES_BASENAME)
677
583
 
678
- const allPageFiles = [...pageFiles, ...modulePageFiles]
679
584
  fs.writeFileSync(
680
585
  pagesGeneratedPath,
681
- generatePagesModule(allPageFiles, srcDir, pagesGeneratedPath)
586
+ generatePagesModule(pageFiles, srcDir, pagesGeneratedPath)
682
587
  )
683
588
  const ossyDir = ossyGeneratedDir(buildPath)
684
- writePageHydrateStubs(allPageFiles, srcDir, ossyDir)
685
- const clientHydrateInput = buildClientHydrateInput(allPageFiles, srcDir, ossyDir)
589
+ writePageHydrateStubs(pageFiles, srcDir, ossyDir)
590
+ const clientHydrateInput = buildClientHydrateInput(pageFiles, srcDir, ossyDir)
686
591
 
687
592
  const {
688
593
  apiSourcePath: resolvedApi,
@@ -724,7 +629,6 @@ export const build = async (cliArgs) => {
724
629
 
725
630
  const serverPlugins = createOssyRollupPlugins({
726
631
  ...sharedPluginOpts,
727
- nodeExternals: true,
728
632
  preferBuiltins: true,
729
633
  copyPublicFrom: publicDir,
730
634
  })
@@ -747,7 +651,6 @@ export const build = async (cliArgs) => {
747
651
 
748
652
  const clientPlugins = createOssyRollupPlugins({
749
653
  ...sharedPluginOpts,
750
- nodeExternals: false,
751
654
  preferBuiltins: false,
752
655
  })
753
656
 
package/cli/dev.js CHANGED
@@ -3,9 +3,9 @@ import url from 'url';
3
3
  import fs from 'fs';
4
4
  import {
5
5
  printBuildOverview,
6
- discoverPageFiles,
6
+ discoverFilesByPattern,
7
+ PAGE_FILE_PATTERN,
7
8
  generatePagesModule,
8
- discoverModulePageFiles,
9
9
  resolveApiSource,
10
10
  resetOssyBuildDir,
11
11
  createOssyRollupPlugins,
@@ -37,23 +37,21 @@ export const dev = async (cliArgs) => {
37
37
  const buildPath = path.resolve('build')
38
38
  const srcDir = path.resolve('src')
39
39
  const configPath = path.resolve(options['--config'] || 'src/config.js');
40
- const pageFiles = discoverPageFiles(srcDir)
41
- const modulePageFiles = await discoverModulePageFiles({ configPath })
40
+ const pageFiles = discoverFilesByPattern(srcDir, PAGE_FILE_PATTERN)
42
41
 
43
42
  resetOssyBuildDir(buildPath)
44
43
 
45
44
  writeResourceTemplatesBarrelIfPresent({ cwd: process.cwd(), log: true })
46
45
 
47
- const allPageFiles = [...pageFiles, ...modulePageFiles]
48
46
  const pagesGeneratedPath = path.join(ossyGeneratedDir(buildPath), OSSY_GEN_PAGES_BASENAME)
49
47
  fs.writeFileSync(
50
48
  pagesGeneratedPath,
51
- generatePagesModule(allPageFiles, srcDir, pagesGeneratedPath)
49
+ generatePagesModule(pageFiles, srcDir, pagesGeneratedPath)
52
50
  )
53
51
  const effectivePagesSource = pagesGeneratedPath
54
52
  const ossyDir = ossyGeneratedDir(buildPath)
55
- writePageHydrateStubs(allPageFiles, srcDir, ossyDir)
56
- const clientHydrateInput = buildClientHydrateInput(allPageFiles, srcDir, ossyDir)
53
+ writePageHydrateStubs(pageFiles, srcDir, ossyDir)
54
+ const clientHydrateInput = buildClientHydrateInput(pageFiles, srcDir, ossyDir)
57
55
 
58
56
  const {
59
57
  apiSourcePath: resolvedApi,
@@ -95,14 +93,12 @@ export const dev = async (cliArgs) => {
95
93
 
96
94
  const serverPlugins = createOssyRollupPlugins({
97
95
  ...sharedPluginOpts,
98
- nodeExternals: true,
99
96
  preferBuiltins: true,
100
97
  copyPublicFrom: publicDir,
101
98
  })
102
99
 
103
100
  const clientPlugins = createOssyRollupPlugins({
104
101
  ...sharedPluginOpts,
105
- nodeExternals: false,
106
102
  preferBuiltins: false,
107
103
  })
108
104
 
@@ -219,13 +215,13 @@ export const dev = async (cliArgs) => {
219
215
  fs.watch(srcDir, { recursive: true }, (eventType, filename) => {
220
216
  if (!filename) return
221
217
  if (/\.page\.(jsx?|tsx?)$/.test(filename)) {
222
- const combined = [...discoverPageFiles(srcDir), ...modulePageFiles]
218
+ const refreshedPageFiles = discoverFilesByPattern(srcDir, PAGE_FILE_PATTERN)
223
219
  const regenPath = path.join(ossyGeneratedDir(buildPath), OSSY_GEN_PAGES_BASENAME)
224
- fs.writeFileSync(regenPath, generatePagesModule(combined, srcDir, regenPath))
225
- writePageHydrateStubs(combined, srcDir, ossyDir)
220
+ fs.writeFileSync(regenPath, generatePagesModule(refreshedPageFiles, srcDir, regenPath))
221
+ writePageHydrateStubs(refreshedPageFiles, srcDir, ossyDir)
226
222
  if (typeof watcher?.invalidate === 'function') {
227
223
  watcher.invalidate(regenPath)
228
- for (const f of combined) {
224
+ for (const f of refreshedPageFiles) {
229
225
  const hid = clientHydrateIdForPage(f, srcDir)
230
226
  watcher.invalidate(path.join(ossyDir, `hydrate-${hid}.jsx`))
231
227
  }
package/cli/index.js ADDED
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env node
2
+ import { build } from './build.js'
3
+ import { dev } from './dev.js'
4
+
5
+ const [,, command, ...restArgs] = process.argv
6
+
7
+ if (!command) {
8
+ console.error(
9
+ '[@ossy/app] No command provided. Usage: app dev | build'
10
+ )
11
+ process.exit(1)
12
+ }
13
+
14
+ const run = async () => {
15
+ if (command === 'dev') {
16
+ await dev(restArgs)
17
+ return
18
+ }
19
+ if (command === 'build') {
20
+ await build(restArgs)
21
+ return
22
+ }
23
+ console.error(`[@ossy/app] Unknown command: ${command}`)
24
+ process.exit(1)
25
+ }
26
+
27
+ run().catch((err) => {
28
+ console.error(err)
29
+ process.exit(1)
30
+ })
package/package.json CHANGED
@@ -1,10 +1,13 @@
1
1
  {
2
2
  "name": "@ossy/app",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "description": "",
5
5
  "source": "./src/index.js",
6
6
  "main": "./src/index.js",
7
7
  "type": "module",
8
+ "bin": {
9
+ "app": "./cli/index.js"
10
+ },
8
11
  "scripts": {
9
12
  "build": "echo Building not required",
10
13
  "test": "node --experimental-vm-modules ../node_modules/jest/bin/jest.js --verbose",
@@ -24,14 +27,14 @@
24
27
  "@babel/eslint-parser": "^7.15.8",
25
28
  "@babel/preset-react": "^7.26.3",
26
29
  "@babel/register": "^7.25.9",
27
- "@ossy/connected-components": "^1.0.7",
28
- "@ossy/design-system": "^1.0.7",
29
- "@ossy/pages": "^1.0.7",
30
- "@ossy/router": "^1.0.7",
31
- "@ossy/router-react": "^1.0.7",
32
- "@ossy/sdk": "^1.0.7",
33
- "@ossy/sdk-react": "^1.0.7",
34
- "@ossy/themes": "^1.0.7",
30
+ "@ossy/connected-components": "^1.0.9",
31
+ "@ossy/design-system": "^1.0.9",
32
+ "@ossy/pages": "^1.0.9",
33
+ "@ossy/router": "^1.0.9",
34
+ "@ossy/router-react": "^1.0.9",
35
+ "@ossy/sdk": "^1.0.9",
36
+ "@ossy/sdk-react": "^1.0.9",
37
+ "@ossy/themes": "^1.0.9",
35
38
  "@rollup/plugin-alias": "^6.0.0",
36
39
  "@rollup/plugin-babel": "6.1.0",
37
40
  "@rollup/plugin-commonjs": "^29.0.0",
@@ -64,5 +67,5 @@
64
67
  "README.md",
65
68
  "tsconfig.json"
66
69
  ],
67
- "gitHead": "70b3f02434c86812a9ddd58f6b062667650949c2"
70
+ "gitHead": "c9da4864730c693fe18339f0920a0802ce9c8ebf"
68
71
  }