@mokup/cli 1.0.9 → 1.0.11

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/dist/index.cjs CHANGED
@@ -7,6 +7,7 @@ const node_buffer = require('node:buffer');
7
7
  const node_module = require('node:module');
8
8
  const node_url = require('node:url');
9
9
  const esbuild = require('@mokup/shared/esbuild');
10
+ const pathUtils = require('@mokup/shared/path-utils');
10
11
  const runtime = require('@mokup/runtime');
11
12
  const jsoncParser = require('@mokup/shared/jsonc-parser');
12
13
  const node = require('@mokup/server/node');
@@ -264,10 +265,6 @@ async function resolveDirectoryConfig(params) {
264
265
  };
265
266
  }
266
267
 
267
- function toPosix(value) {
268
- return value.replace(/\\/g, "/");
269
- }
270
-
271
268
  const supportedExtensions = /* @__PURE__ */ new Set([
272
269
  ".json",
273
270
  ".jsonc",
@@ -318,34 +315,10 @@ function resolveDirs(dir, root) {
318
315
  );
319
316
  return Array.from(new Set(normalized));
320
317
  }
321
- function testPatterns(patterns, value) {
322
- const list = Array.isArray(patterns) ? patterns : [patterns];
323
- return list.some((pattern) => pattern.test(value));
324
- }
325
- function matchesFilter(file, include, exclude) {
326
- const normalized = toPosix(file);
327
- if (exclude && testPatterns(exclude, normalized)) {
328
- return false;
329
- }
330
- if (include) {
331
- return testPatterns(include, normalized);
332
- }
333
- return true;
334
- }
335
318
  function normalizeIgnorePrefix(value, fallback = ["."]) {
336
319
  const list = typeof value === "undefined" ? fallback : Array.isArray(value) ? value : [value];
337
320
  return list.filter((entry) => typeof entry === "string" && entry.length > 0);
338
321
  }
339
- function hasIgnoredPrefix(file, rootDir, prefixes) {
340
- if (prefixes.length === 0) {
341
- return false;
342
- }
343
- const relativePath = toPosix(pathe.relative(rootDir, file));
344
- const segments = relativePath.split("/");
345
- return segments.some(
346
- (segment) => prefixes.some((prefix) => segment.startsWith(prefix))
347
- );
348
- }
349
322
  function isSupportedFile(file) {
350
323
  if (file.endsWith(".d.ts")) {
351
324
  return false;
@@ -363,7 +336,7 @@ function getHandlerModulePath(file, handlersDir, root) {
363
336
  const relNoExt = `${relFromRoot.slice(0, relFromRoot.length - ext.length)}.mjs`;
364
337
  const outputPath = pathe.join(handlersDir, relNoExt);
365
338
  const relFromOutDir = pathe.relative(pathe.dirname(handlersDir), outputPath);
366
- const normalized = toPosix(relFromOutDir);
339
+ const normalized = pathUtils.toPosix(relFromOutDir);
367
340
  return normalized.startsWith(".") ? normalized : `./${normalized}`;
368
341
  }
369
342
  async function writeHandlerIndex(handlerModuleMap, handlersDir, outDir) {
@@ -375,7 +348,7 @@ async function writeHandlerIndex(handlerModuleMap, handlersDir, outDir) {
375
348
  const entries = [];
376
349
  modulePaths.forEach((modulePath, index) => {
377
350
  const absolutePath = pathe.resolve(outDir, modulePath);
378
- const relImport = toPosix(pathe.relative(handlersDir, absolutePath));
351
+ const relImport = pathUtils.toPosix(pathe.relative(handlersDir, absolutePath));
379
352
  const importPath = relImport.startsWith(".") ? relImport : `./${relImport}`;
380
353
  const name = `module${index}`;
381
354
  imports.push(`import * as ${name} from '${importPath}'`);
@@ -509,7 +482,7 @@ function stripMethodSuffix(base) {
509
482
  };
510
483
  }
511
484
  function deriveRouteFromFile(file, rootDir, log) {
512
- const rel = toPosix(pathe.relative(rootDir, file));
485
+ const rel = pathUtils.toPosix(pathe.relative(rootDir, file));
513
486
  const ext = pathe.extname(rel);
514
487
  const withoutExt = rel.slice(0, rel.length - ext.length);
515
488
  const dir = pathe.dirname(withoutExt);
@@ -525,7 +498,7 @@ function deriveRouteFromFile(file, rootDir, log) {
525
498
  return null;
526
499
  }
527
500
  const joined = dir === "." ? name : pathe.join(dir, name);
528
- const segments = toPosix(joined).split("/");
501
+ const segments = pathUtils.toPosix(joined).split("/");
529
502
  if (segments.at(-1) === "index") {
530
503
  segments.pop();
531
504
  }
@@ -683,7 +656,7 @@ async function buildManifest(options = {}) {
683
656
  continue;
684
657
  }
685
658
  const effectiveIgnorePrefix = typeof config.ignorePrefix !== "undefined" ? normalizeIgnorePrefix(config.ignorePrefix, []) : globalIgnorePrefix;
686
- if (hasIgnoredPrefix(fileInfo.file, fileInfo.rootDir, effectiveIgnorePrefix)) {
659
+ if (pathUtils.hasIgnoredPrefix(fileInfo.file, fileInfo.rootDir, effectiveIgnorePrefix)) {
687
660
  continue;
688
661
  }
689
662
  if (!isSupportedFile(fileInfo.file)) {
@@ -691,7 +664,7 @@ async function buildManifest(options = {}) {
691
664
  }
692
665
  const effectiveInclude = typeof config.include !== "undefined" ? config.include : options.include;
693
666
  const effectiveExclude = typeof config.exclude !== "undefined" ? config.exclude : options.exclude;
694
- if (!matchesFilter(fileInfo.file, effectiveInclude, effectiveExclude)) {
667
+ if (!pathUtils.matchesFilter(fileInfo.file, effectiveInclude, effectiveExclude)) {
695
668
  continue;
696
669
  }
697
670
  const derived = deriveRouteFromFile(fileInfo.file, fileInfo.rootDir, options.log);
@@ -753,7 +726,7 @@ async function buildManifest(options = {}) {
753
726
  if (!response) {
754
727
  continue;
755
728
  }
756
- const source = toPosix(pathe.relative(root, fileInfo.file));
729
+ const source = pathUtils.toPosix(pathe.relative(root, fileInfo.file));
757
730
  const middlewareRefs = options.handlers === false ? [] : config.middlewares.map((entry) => {
758
731
  handlerSources.add(entry.file);
759
732
  const modulePath = getHandlerModulePath(entry.file, handlersDir, root);
package/dist/index.mjs CHANGED
@@ -1,10 +1,11 @@
1
1
  import { promises } from 'node:fs';
2
2
  import process, { cwd } from 'node:process';
3
- import { join, normalize, dirname, resolve, isAbsolute, relative, basename, extname } from '@mokup/shared/pathe';
3
+ import { join, normalize, dirname, resolve, isAbsolute, basename, extname, relative } from '@mokup/shared/pathe';
4
4
  import { Buffer } from 'node:buffer';
5
5
  import { createRequire } from 'node:module';
6
6
  import { pathToFileURL } from 'node:url';
7
7
  import { build } from '@mokup/shared/esbuild';
8
+ import { toPosix, hasIgnoredPrefix, matchesFilter } from '@mokup/shared/path-utils';
8
9
  import { parseRouteTemplate, compareRouteScore } from '@mokup/runtime';
9
10
  import { parse } from '@mokup/shared/jsonc-parser';
10
11
  import { createFetchServer, serve } from '@mokup/server/node';
@@ -257,10 +258,6 @@ async function resolveDirectoryConfig(params) {
257
258
  };
258
259
  }
259
260
 
260
- function toPosix(value) {
261
- return value.replace(/\\/g, "/");
262
- }
263
-
264
261
  const supportedExtensions = /* @__PURE__ */ new Set([
265
262
  ".json",
266
263
  ".jsonc",
@@ -311,34 +308,10 @@ function resolveDirs(dir, root) {
311
308
  );
312
309
  return Array.from(new Set(normalized));
313
310
  }
314
- function testPatterns(patterns, value) {
315
- const list = Array.isArray(patterns) ? patterns : [patterns];
316
- return list.some((pattern) => pattern.test(value));
317
- }
318
- function matchesFilter(file, include, exclude) {
319
- const normalized = toPosix(file);
320
- if (exclude && testPatterns(exclude, normalized)) {
321
- return false;
322
- }
323
- if (include) {
324
- return testPatterns(include, normalized);
325
- }
326
- return true;
327
- }
328
311
  function normalizeIgnorePrefix(value, fallback = ["."]) {
329
312
  const list = typeof value === "undefined" ? fallback : Array.isArray(value) ? value : [value];
330
313
  return list.filter((entry) => typeof entry === "string" && entry.length > 0);
331
314
  }
332
- function hasIgnoredPrefix(file, rootDir, prefixes) {
333
- if (prefixes.length === 0) {
334
- return false;
335
- }
336
- const relativePath = toPosix(relative(rootDir, file));
337
- const segments = relativePath.split("/");
338
- return segments.some(
339
- (segment) => prefixes.some((prefix) => segment.startsWith(prefix))
340
- );
341
- }
342
315
  function isSupportedFile(file) {
343
316
  if (file.endsWith(".d.ts")) {
344
317
  return false;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mokup/cli",
3
3
  "type": "module",
4
- "version": "1.0.9",
4
+ "version": "1.0.11",
5
5
  "description": "CLI for building mokup manifests and handlers.",
6
6
  "license": "MIT",
7
7
  "homepage": "https://mokup.icebreaker.top",
@@ -28,9 +28,9 @@
28
28
  ],
29
29
  "dependencies": {
30
30
  "commander": "^14.0.0",
31
- "@mokup/runtime": "1.0.5",
32
- "@mokup/server": "1.1.6",
33
- "@mokup/shared": "1.1.0"
31
+ "@mokup/runtime": "1.0.6",
32
+ "@mokup/server": "1.1.8",
33
+ "@mokup/shared": "1.1.1"
34
34
  },
35
35
  "devDependencies": {
36
36
  "@types/node": "^25.0.10",