arcane-os 0.5.12 → 0.5.13

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.
@@ -89,6 +89,7 @@ export async function materializeInstalledSdkRuntime({
89
89
  workspaceRoot:canonicalRoot,
90
90
  runtimeRoot:authority.installation.runtimeRoot,
91
91
  browserRuntimeRoot:authority.installation.browserRuntimeRoot,
92
+ sdkVersion:authority.installation.packageVersion,
92
93
  signal,
93
94
  onEvent
94
95
  });
@@ -12,7 +12,7 @@ import {
12
12
  import path from 'node:path';
13
13
  import {pathToFileURL} from 'node:url';
14
14
  import {withWorkspaceOperationLock} from '../workspace-operation-lock.mjs';
15
- import {inspectImportMapHtml} from '../import-map.mjs';
15
+ import {inspectImportMapHtml,readWorkspaceAssetVersion,rewriteAssetReferences} from '../import-map.mjs';
16
16
 
17
17
  export const ROOT_CONFIG_NAME='arcane-packager.json';
18
18
  export const APP_CONFIG_NAME='arcane-package.json';
@@ -704,6 +704,65 @@ async function packageWithContext(context,options={}){
704
704
  await copyBase();
705
705
  }
706
706
  const files=await listOutputFiles(stagingRoot,{signal});
707
+ // Traverse actual browser resources after the adapter finishes. Files
708
+ // included only as application documents retain their original content.
709
+ const version=await readWorkspaceAssetVersion(context.workspaceRoot);
710
+ const inventory=new Set(files);
711
+ const entryUrl=new URL(context.config.entry,'http://arcane.invalid/');
712
+ const entryDocument=inspected.browserDocuments.find(document=>document.path===context.config.entry);
713
+ const documentUrl=entryDocument?.bases[0]?.href
714
+ ?new URL(entryDocument.bases[0].href,entryUrl):entryUrl;
715
+ const pending=[{file:context.config.entry,documentUrl}];
716
+ for(const file of files){
717
+ if(/^arcane\/(?:modules|entities|components|css|sdk|dependencies)\//u.test(file)
718
+ &&/\.(?:m?js|html?|css)$/iu.test(file))pending.push({file,documentUrl});
719
+ }
720
+ for(const document of inspected.browserDocuments){
721
+ if(document.managedMaps.length>0){
722
+ const url=new URL(document.path,entryUrl.origin);
723
+ pending.push({file:document.path,documentUrl:document.bases[0]?.href
724
+ ?new URL(document.bases[0].href,url):url});
725
+ }
726
+ }
727
+ const visited=new Set();
728
+ const resources=new Map();
729
+ for(const current of pending){
730
+ const relative=current.file;
731
+ throwIfAborted(signal);
732
+ const contextKey=`${relative}\n${current.documentUrl.href}`;
733
+ if(visited.has(contextKey)||!inventory.has(relative)
734
+ ||!/\.(?:m?js|html?|css)$/iu.test(relative))continue;
735
+ visited.add(contextKey);
736
+ const filePath=path.join(stagingRoot,...relative.split('/'));
737
+ let resource=resources.get(relative);
738
+ if(!resource){
739
+ const original=await readFile(filePath,'utf8');
740
+ const references=[];
741
+ const content=rewriteAssetReferences(original,{
742
+ filePath:relative,version,onReference:reference=>references.push(reference)
743
+ });
744
+ if(content!==original)await writeFile(filePath,content,'utf8');
745
+ resource={references};
746
+ resources.set(relative,resource);
747
+ }
748
+ for(const {url,kind,baseHref,baseKind} of resource.references){
749
+ if(kind==='fetch'||(kind==='asset'&&!/\.css(?:[?#]|$)/iu.test(url))
750
+ ||(kind==='import'&&!/^(?:\.{1,2}\/|\/)/u.test(url)))continue;
751
+ try{
752
+ const ownerUrl=new URL(relative,entryUrl.origin);
753
+ const base=baseHref?new URL(baseHref,ownerUrl)
754
+ :baseKind==='document'?current.documentUrl:ownerUrl;
755
+ const target=new URL(url,base);
756
+ if(target.origin===entryUrl.origin){
757
+ pending.push({
758
+ file:decodeURIComponent(target.pathname).replace(/^\//u,''),
759
+ documentUrl:kind==='document'?target
760
+ :baseHref?new URL(baseHref,ownerUrl):current.documentUrl
761
+ });
762
+ }
763
+ }catch{ /* Non-URL values remain under their existing owner. */ }
764
+ }
765
+ }
707
766
  if(files.some(file=>pathKey(file)===pathKey(RELEASE_MANIFEST_NAME))){
708
767
  fail(`Package content must not author ${RELEASE_MANIFEST_NAME}.`);
709
768
  }
@@ -1,6 +1,8 @@
1
1
  import {randomUUID} from 'node:crypto';
2
- import {copyFile,lstat,mkdir,readdir,realpath,rename,rm} from 'node:fs/promises';
2
+ import {copyFile,lstat,mkdir,readFile,readdir,realpath,rename,rm,writeFile} from 'node:fs/promises';
3
3
  import path from 'node:path';
4
+ import {SDK_VERSION} from './constants.mjs';
5
+ import {rewriteAssetReferences} from './import-map.mjs';
4
6
  import {getSdkRoot} from './runtime.mjs';
5
7
  import {getSdkBrowserRuntimeRoot} from './sdk-browser-runtime.mjs';
6
8
 
@@ -47,12 +49,18 @@ async function realDirectory(location,label){
47
49
  return canonical;
48
50
  }
49
51
 
50
- async function copyCompleteEntry(source,destination,label,signal){
52
+ async function copyCompleteEntry(source,destination,label,signal,version){
51
53
  throwIfAborted(signal);
52
54
  const info=await lstat(source);
53
55
  if(info.isSymbolicLink())fail(`${label} must not contain a symbolic link or junction.`);
54
56
  if(info.isFile()){
55
- await copyFile(source,destination);
57
+ if(/\.(?:m?js|html?|css)$/iu.test(source)){
58
+ const original=await readFile(source,'utf8');
59
+ const content=rewriteAssetReferences(original,{filePath:source,version});
60
+ await writeFile(destination,content,'utf8');
61
+ }else{
62
+ await copyFile(source,destination);
63
+ }
56
64
  return;
57
65
  }
58
66
  if(!info.isDirectory())fail(`${label} contains a non-file entry.`);
@@ -65,7 +73,8 @@ async function copyCompleteEntry(source,destination,label,signal){
65
73
  path.join(source,entry.name),
66
74
  path.join(destination,entry.name),
67
75
  `${label}/${entry.name}`,
68
- signal
76
+ signal,
77
+ version
69
78
  );
70
79
  }
71
80
  }
@@ -78,6 +87,7 @@ export async function materializeWorkspaceRuntimeContent({
78
87
  workspaceRoot,
79
88
  runtimeRoot=path.join(getSdkRoot(),'runtime'),
80
89
  browserRuntimeRoot=getSdkBrowserRuntimeRoot(),
90
+ sdkVersion=SDK_VERSION,
81
91
  signal,
82
92
  onEvent
83
93
  }={}){
@@ -100,13 +110,14 @@ export async function materializeWorkspaceRuntimeContent({
100
110
 
101
111
  await mkdir(stagingRoot);
102
112
  try{
103
- await copyCompleteEntry(runtimeArcane,stagingRoot,'SDK Arcane runtime',signal);
113
+ await copyCompleteEntry(runtimeArcane,stagingRoot,'SDK Arcane runtime',signal,sdkVersion);
104
114
  await mkdir(path.join(stagingRoot,'dependencies'),{recursive:true});
105
115
  await copyCompleteEntry(
106
116
  runtimeStrongType,
107
117
  path.join(stagingRoot,'dependencies','strong-type'),
108
118
  'SDK strong-type runtime',
109
- signal
119
+ signal,
120
+ sdkVersion
110
121
  );
111
122
  const sdkDestination=path.join(stagingRoot,'sdk');
112
123
  await mkdir(sdkDestination,{recursive:true});
@@ -118,7 +129,8 @@ export async function materializeWorkspaceRuntimeContent({
118
129
  path.join(browserRuntime,entry.name),
119
130
  path.join(sdkDestination,entry.name),
120
131
  `SDK browser runtime/${entry.name}`,
121
- signal
132
+ signal,
133
+ sdkVersion
122
134
  );
123
135
  }
124
136