devjar 0.9.0 → 0.9.1

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.
Files changed (2) hide show
  1. package/dist/index.js +25 -30
  2. package/package.json +7 -4
package/dist/index.js CHANGED
@@ -8,28 +8,14 @@ async function createModule(files, { resolveModule, dependencies = {}, runtime =
8
8
  function createLocalImportPlaceholder(moduleKey) {
9
9
  return `${localImportPrefix}${encodeURIComponent(moduleKey)}__`;
10
10
  }
11
- function createScopedSpecifier(moduleKey) {
12
- return `devjar-internal/${runtime.revision}/${encodeURIComponent(moduleKey)}`;
13
- }
14
- function registerImportMap(imports) {
15
- var _runtime;
16
- const script = document.createElement('script');
17
- script.type = 'importmap';
18
- script.textContent = JSON.stringify({
19
- imports
20
- });
21
- document.head.appendChild(script);
22
- ((_runtime = runtime).importMaps || (_runtime.importMaps = [])).push(script);
23
- }
24
11
  function createInlinedModule(code) {
25
12
  return `data:text/javascript;utf-8,${encodeURIComponent(code)}`;
26
13
  }
27
- function createCssModule(code, fileName) {
14
+ function createCssModule(code) {
28
15
  return `\
29
16
  const sheet = new CSSStyleSheet();
30
17
  sheet.replaceSync(${JSON.stringify(code)});
31
- export default sheet;
32
- //# sourceURL=devjar/${fileName}?v=${runtime.revision}`;
18
+ export default sheet;`;
33
19
  }
34
20
  function rewriteLocalImports(code, specifiers) {
35
21
  let rewritten = code;
@@ -71,35 +57,44 @@ export default sheet;
71
57
  for (const importedModules of Object.values(dependencies)){
72
58
  for (const moduleKey of importedModules)moduleKeys.add(moduleKey);
73
59
  }
74
- const scopedSpecifiers = {};
75
- for (const moduleKey of moduleKeys){
76
- scopedSpecifiers[moduleKey] = createScopedSpecifier(moduleKey);
77
- }
78
- const imports = {};
60
+ const moduleSources = {};
79
61
  for (const moduleKey of moduleKeys){
80
62
  if (!(moduleKey in files)) {
81
- imports[scopedSpecifiers[moduleKey]] = createInlinedModule(`throw new Error(${JSON.stringify('devjar: Module not found: ' + moduleKey)})`);
63
+ moduleSources[moduleKey] = `throw new Error(${JSON.stringify('devjar: Module not found: ' + moduleKey)})`;
82
64
  delete runtime.urls[moduleKey];
83
65
  continue;
84
66
  }
85
- if (!runtime.urls[moduleKey] || invalidated.has(moduleKey)) {
86
- const moduleCode = moduleKey.endsWith('.css') ? createCssModule(files[moduleKey], moduleKey) : rewriteLocalImports(`${files[moduleKey]}\n//# sourceURL=devjar/${moduleKey}?v=${runtime.revision}`, scopedSpecifiers);
87
- runtime.urls[moduleKey] = createInlinedModule(moduleCode);
67
+ moduleSources[moduleKey] = moduleKey.endsWith('.css') ? createCssModule(files[moduleKey]) : files[moduleKey];
68
+ }
69
+ const buildingUrls = new Set();
70
+ const buildModuleUrl = (moduleKey)=>{
71
+ if (runtime.urls[moduleKey] && !invalidated.has(moduleKey)) return runtime.urls[moduleKey];
72
+ if (buildingUrls.has(moduleKey)) {
73
+ throw new Error('devjar: Circular local imports are not supported: ' + moduleKey);
74
+ }
75
+ buildingUrls.add(moduleKey);
76
+ const specifiers = {};
77
+ for (const imported of dependencies[moduleKey] || []){
78
+ specifiers[imported] = buildModuleUrl(imported);
88
79
  }
89
- imports[scopedSpecifiers[moduleKey]] = runtime.urls[moduleKey];
80
+ const moduleCode = moduleKey.endsWith('.css') ? moduleSources[moduleKey] : rewriteLocalImports(moduleSources[moduleKey], specifiers);
81
+ runtime.urls[moduleKey] = createInlinedModule(moduleCode);
82
+ buildingUrls.delete(moduleKey);
83
+ return runtime.urls[moduleKey];
84
+ };
85
+ for (const moduleKey of moduleKeys){
86
+ buildModuleUrl(moduleKey);
90
87
  }
91
- registerImportMap(imports);
92
88
  if (!runtime.refreshRuntime) {
93
89
  const refreshModule = await import(/* webpackIgnore: true */ /* @vite-ignore */ /* turbopackIgnore: true */ resolveModule('react-refresh/runtime'));
94
90
  runtime.refreshRuntime = refreshModule.default || refreshModule;
95
91
  runtime.refreshRuntime.injectIntoGlobalHook(self);
96
92
  globalThis.__devjarRefreshRuntime = runtime.refreshRuntime;
97
93
  }
98
- const entrySpecifier = scopedSpecifiers['index'];
99
- if (!entrySpecifier) {
94
+ if (!runtime.urls['index']) {
100
95
  throw new Error('devjar: Module not found: index');
101
96
  }
102
- const module = await import(/* webpackIgnore: true */ /* @vite-ignore */ /* turbopackIgnore: true */ entrySpecifier);
97
+ const module = await import(/* webpackIgnore: true */ /* @vite-ignore */ /* turbopackIgnore: true */ runtime.urls['index']);
103
98
  runtime.files = {
104
99
  ...files
105
100
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "devjar",
3
- "version": "0.9.0",
3
+ "version": "0.9.1",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -9,6 +9,10 @@
9
9
  }
10
10
  },
11
11
  "license": "MIT",
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "https://github.com/huozhi/devjar"
15
+ },
12
16
  "files": [
13
17
  "dist"
14
18
  ],
@@ -29,9 +33,7 @@
29
33
  "react": "^19.0.0"
30
34
  },
31
35
  "dependencies": {
32
- "es-module-lexer": "1.6.0",
33
- "oxc-transform": "^0.137.0",
34
- "react-refresh": "^0.18.0"
36
+ "es-module-lexer": "1.6.0"
35
37
  },
36
38
  "devDependencies": {
37
39
  "@types/node": "^22.10.7",
@@ -42,6 +44,7 @@
42
44
  "dedent": "^1.7.0",
43
45
  "devjar": "link:",
44
46
  "next": "16.3.0-canary.69",
47
+ "oxc-transform": "^0.137.0",
45
48
  "react": "^19.2.1",
46
49
  "react-dom": "^19.2.1",
47
50
  "typescript": "^5.7.3"