rimecms 0.24.3 → 0.24.4

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.
@@ -6,3 +6,7 @@
6
6
  * - Outputs to .generated folder, preserving original folder structure
7
7
  */
8
8
  export function sanitize(): Promise<void>;
9
+ /**
10
+ * Updates imports in server files to use server versions of split modules
11
+ */
12
+ export function updateServerImports(content: any, splitFiles: any, currentDir: any): any;
@@ -50,6 +50,22 @@ export async function sanitize() {
50
50
  // Scan all TypeScript files (excluding .server.ts)
51
51
  const allFiles = await scanConfigFiles(configDir);
52
52
 
53
+ // Pre-scan files to determine which ones will be split (contain server content)
54
+ for (const filePath of allFiles) {
55
+ const relativePath = path.relative(configDir, filePath);
56
+ try {
57
+ const content = fs.readFileSync(filePath, 'utf-8');
58
+ const ast = babelParse(content, 'ts', { sourceType: 'module', attachComment: false });
59
+ const analysis = analyzeFile(ast);
60
+ if (analysis.hasServerContent) {
61
+ // Normalize to forward slashes to match how imports are compared later
62
+ splitFiles.add(relativePath.split(path.sep).join('/'));
63
+ }
64
+ } catch (err) {
65
+ logger.warn(`Failed to analyze ${relativePath} during pre-scan: ${err.message}`);
66
+ }
67
+ }
68
+
53
69
  // Also scan and copy all existing .server.ts files
54
70
  const serverFiles = await scanServerFiles(configDir);
55
71
 
@@ -666,12 +682,20 @@ function removeUnusedImports(ast) {
666
682
  /**
667
683
  * Updates imports in server files to use server versions of split modules
668
684
  */
669
- function updateServerImports(content, splitFiles, currentDir) {
685
+ export function updateServerImports(content, splitFiles, currentDir) {
670
686
  try {
671
687
  const ast = babelParse(content, 'ts', { sourceType: 'module', attachComment: false });
672
688
 
673
689
  let hasChanges = false;
674
690
 
691
+ // Helper to normalize paths for comparison with splitFiles entries
692
+ const normalizeForCompare = (p) =>
693
+ p
694
+ .replace(/^\.\/?/, '')
695
+ .split(path.sep)
696
+ .join('/');
697
+ const splitFilesSet = new Set(Array.from(splitFiles).map((s) => normalizeForCompare(s)));
698
+
675
699
  // Walk through all import declarations
676
700
  for (const node of ast.body) {
677
701
  if (t.isImportDeclaration(node) && t.isStringLiteral(node.source)) {
@@ -682,25 +706,47 @@ function updateServerImports(content, splitFiles, currentDir) {
682
706
  continue;
683
707
  }
684
708
 
685
- // Resolve the import path relative to current file's directory
686
- let resolvedPath = path.resolve(currentDir, importPath);
709
+ // Skip already server imports
710
+ if (importPath.includes('.server')) continue;
687
711
 
688
- // Handle .js extension - convert to .ts for checking
689
- if (resolvedPath.endsWith('.js')) {
690
- resolvedPath = resolvedPath.slice(0, -3) + '.ts';
712
+ // Normalize import path: remove trailing slashes and explicit extensions
713
+ const cleanedImport = importPath.replace(/\/+$/, '');
714
+ const importNoExt = cleanedImport.replace(/(\.js|\.ts)$/, '');
715
+
716
+ // Build candidate relative paths (relative to config dir)
717
+ const candidateFile = path.normalize(path.join(currentDir, importNoExt + '.ts'));
718
+ const candidateIndex = path.normalize(path.join(currentDir, importNoExt, 'index.ts'));
719
+
720
+ const candidateFileNorm = normalizeForCompare(candidateFile);
721
+ const candidateIndexNorm = normalizeForCompare(candidateIndex);
722
+
723
+ let matched = null;
724
+ let matchedIsIndex = false;
725
+
726
+ if (splitFilesSet.has(candidateFileNorm)) {
727
+ matched = candidateFileNorm;
728
+ matchedIsIndex = false;
729
+ } else if (splitFilesSet.has(candidateIndexNorm)) {
730
+ matched = candidateIndexNorm;
731
+ matchedIsIndex = true;
691
732
  }
692
733
 
693
- // Check if this import points to a split file
694
- const relativeResolvedPath = path.relative('.', resolvedPath);
695
- if (splitFiles.has(relativeResolvedPath)) {
696
- // Update import to use server version
697
- let newImportPath = importPath;
698
- if (newImportPath.endsWith('.js')) {
699
- newImportPath = newImportPath.slice(0, -3) + '.server.js';
734
+ if (matched) {
735
+ // Build new import path: prefer .server.js so runtime imports point to JS server files
736
+ let newImportPath;
737
+ if (matchedIsIndex) {
738
+ newImportPath = importNoExt + '/index.server.js';
700
739
  } else {
701
- newImportPath += '.server';
740
+ newImportPath = importNoExt + '.server.js';
702
741
  }
742
+
743
+ // Set the node's source value and ensure it renders with single quotes
703
744
  node.source.value = newImportPath;
745
+ if (!node.source.extra || typeof node.source.extra !== 'object') {
746
+ node.source.extra = {};
747
+ }
748
+ node.source.extra.raw = `'${newImportPath}'`;
749
+ node.source.extra.rawValue = newImportPath;
704
750
  hasChanges = true;
705
751
  }
706
752
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rimecms",
3
- "version": "0.24.3",
3
+ "version": "0.24.4",
4
4
  "homepage": "https://github.com/bienbiendev/rime",
5
5
  "scripts": {
6
6
  "dev": "vite dev",