devjar 0.6.0 → 0.7.0
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.js +18 -8
- package/package.json +2 -3
package/dist/index.js
CHANGED
|
@@ -41,11 +41,12 @@ async function createModule(files, { getModuleUrl }) {
|
|
|
41
41
|
createInlinedModule(code, fileName.endsWith('.css') ? 'css' : 'js')
|
|
42
42
|
]));
|
|
43
43
|
updateImportMap(imports);
|
|
44
|
-
return self.importShim('index
|
|
44
|
+
return self.importShim('index');
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
let esModuleLexerInit;
|
|
48
48
|
const isRelative = (s)=>s.startsWith('./');
|
|
49
|
+
const removeExtension = (str)=>str.replace(/\.[^/.]+$/, '');
|
|
49
50
|
function transformCode(_code, getModuleUrl, externals) {
|
|
50
51
|
const code = transform(_code, {
|
|
51
52
|
transforms: [
|
|
@@ -105,6 +106,7 @@ function replaceImports(source, getModuleUrl, externals) {
|
|
|
105
106
|
}
|
|
106
107
|
return code;
|
|
107
108
|
}
|
|
109
|
+
// createRenderer is going to be stringified and executed in the iframe
|
|
108
110
|
function createRenderer(createModule_, getModuleUrl) {
|
|
109
111
|
let reactRoot;
|
|
110
112
|
async function render(files) {
|
|
@@ -160,7 +162,7 @@ function createEsShimOptionsScript() {
|
|
|
160
162
|
return `\
|
|
161
163
|
window.esmsInitOptions = {
|
|
162
164
|
polyfillEnable: ['css-modules', 'json-modules'],
|
|
163
|
-
onerror:
|
|
165
|
+
onerror: console.error,
|
|
164
166
|
}`;
|
|
165
167
|
}
|
|
166
168
|
function useScript() {
|
|
@@ -219,7 +221,7 @@ function useLiveCode({ getModuleUrl }) {
|
|
|
219
221
|
type: 'module'
|
|
220
222
|
});
|
|
221
223
|
const tailwindScript = createScript(tailwindcssScriptRef, {
|
|
222
|
-
src: 'https://
|
|
224
|
+
src: 'https://unpkg.com/@tailwindcss/browser@4'
|
|
223
225
|
});
|
|
224
226
|
body.appendChild(div);
|
|
225
227
|
body.appendChild(esmShimOptionsScript);
|
|
@@ -252,11 +254,17 @@ function useLiveCode({ getModuleUrl }) {
|
|
|
252
254
|
* '@mod1': '...',
|
|
253
255
|
* '@mod2': '...',
|
|
254
256
|
*/ const transformedFiles = Object.keys(files).reduce((res, filename)=>{
|
|
255
|
-
|
|
257
|
+
// 1. Remove ./
|
|
258
|
+
// 2. For non css files, remove extension
|
|
259
|
+
// e.g. './styles.css' -> '@styles.css'
|
|
260
|
+
// e.g. './foo.js' -> '@foo'
|
|
261
|
+
const moduleKey = isRelative(filename) ? '@' + filename.slice(2) : filename;
|
|
256
262
|
if (filename.endsWith('.css')) {
|
|
257
|
-
res[
|
|
263
|
+
res[moduleKey] = files[filename];
|
|
258
264
|
} else {
|
|
259
|
-
|
|
265
|
+
// JS or TS files
|
|
266
|
+
const normalizedModuleKey = removeExtension(moduleKey);
|
|
267
|
+
res[normalizedModuleKey] = transformCode(files[filename], getModuleUrl, overrideExternals);
|
|
260
268
|
}
|
|
261
269
|
return res;
|
|
262
270
|
}, {});
|
|
@@ -269,13 +277,15 @@ function useLiveCode({ getModuleUrl }) {
|
|
|
269
277
|
} else {
|
|
270
278
|
// if render is not loaded yet, wait until it's loaded
|
|
271
279
|
script.onload = ()=>{
|
|
272
|
-
iframe.contentWindow.__render__(transformedFiles)
|
|
280
|
+
iframe.contentWindow.__render__(transformedFiles).catch((err)=>{
|
|
281
|
+
setError(err);
|
|
282
|
+
});
|
|
273
283
|
};
|
|
274
284
|
}
|
|
275
285
|
}
|
|
276
286
|
setError(undefined);
|
|
277
287
|
} catch (e) {
|
|
278
|
-
console.
|
|
288
|
+
console.warn(e);
|
|
279
289
|
setError(e);
|
|
280
290
|
}
|
|
281
291
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "devjar",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dist/index.js",
|
|
@@ -31,12 +31,11 @@
|
|
|
31
31
|
"@types/react": "^19.0.7",
|
|
32
32
|
"@types/react-dom": "^19.0.3",
|
|
33
33
|
"bunchee": "^6.3.2",
|
|
34
|
-
"codice": "
|
|
34
|
+
"codice": "1.0.0",
|
|
35
35
|
"devjar": "link:./",
|
|
36
36
|
"next": "^15.1.5",
|
|
37
37
|
"react": "^19.0.0",
|
|
38
38
|
"react-dom": "^19.0.0",
|
|
39
|
-
"sugar-high": "^0.8.2",
|
|
40
39
|
"typescript": "^5.7.3"
|
|
41
40
|
},
|
|
42
41
|
"packageManager": "pnpm@9.15.4"
|