@blocklet/pages-kit-block-studio 0.6.7 → 0.6.8
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/lib/cjs/middlewares/init-resource-router.js +19 -1
- package/lib/cjs/plugins/vite-plugin-code-splitter.js +2 -10
- package/lib/cjs/tsconfig.tsbuildinfo +1 -1
- package/lib/cjs/utils/helper.js +5 -1
- package/lib/esm/middlewares/init-resource-router.js +20 -2
- package/lib/esm/plugins/vite-plugin-code-splitter.js +3 -11
- package/lib/esm/tsconfig.tsbuildinfo +1 -1
- package/lib/esm/utils/helper.js +3 -0
- package/lib/types/tsconfig.tsbuildinfo +1 -1
- package/lib/types/utils/helper.d.ts +2 -0
- package/package.json +3 -3
|
@@ -48,6 +48,7 @@ const fs_1 = __importDefault(require("fs"));
|
|
|
48
48
|
const get_1 = __importDefault(require("lodash/get"));
|
|
49
49
|
const set_1 = __importDefault(require("lodash/set"));
|
|
50
50
|
const path_1 = __importStar(require("path"));
|
|
51
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
51
52
|
const helper_1 = require("../utils/helper");
|
|
52
53
|
const DID = 'z2qa7BQdkEb3TwYyEYC1psK6uvmGnHSUHt5RM';
|
|
53
54
|
const RESOURCE_TYPE = 'page';
|
|
@@ -189,12 +190,29 @@ exports.initResourceRouter.post('/', async (req, res) => {
|
|
|
189
190
|
// set version to 2
|
|
190
191
|
(0, set_1.default)(metadata, 'version', 2);
|
|
191
192
|
// get code to metadata
|
|
192
|
-
const code = fs_1.default.readFileSync((0, path_1.join)(codeDir,
|
|
193
|
+
const code = fs_1.default.readFileSync((0, path_1.join)(codeDir, `${(0, helper_1.getComponentScriptName)(blockName, 'esm')}.js`), 'utf8');
|
|
193
194
|
if (code) {
|
|
194
195
|
(0, set_1.default)(metadata, 'renderer.script', code);
|
|
195
196
|
(0, set_1.default)(metadata, 'renderer.type', 'react-component');
|
|
196
197
|
(0, set_1.default)(metadata, 'renderer.chunks', chunksMap[jsName] || []);
|
|
197
198
|
}
|
|
199
|
+
// get cjs by code with transpileModule
|
|
200
|
+
try {
|
|
201
|
+
const cjsCode = typescript_1.default.transpileModule(code, {
|
|
202
|
+
compilerOptions: {
|
|
203
|
+
jsx: typescript_1.default.JsxEmit.React,
|
|
204
|
+
target: typescript_1.default.ScriptTarget.ES2016,
|
|
205
|
+
module: typescript_1.default.ModuleKind.CommonJS,
|
|
206
|
+
moduleResolution: typescript_1.default.ModuleResolutionKind.Node16,
|
|
207
|
+
},
|
|
208
|
+
}).outputText;
|
|
209
|
+
if (cjsCode) {
|
|
210
|
+
(0, set_1.default)(metadata, 'renderer.cjsScript', cjsCode);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
catch (error) {
|
|
214
|
+
// ignore error
|
|
215
|
+
}
|
|
198
216
|
// get edit component code
|
|
199
217
|
try {
|
|
200
218
|
const editComponentJsName = `${(0, helper_1.getEditComponentBlockName)(blockName)}.js`;
|
|
@@ -97,20 +97,12 @@ const minify = true;
|
|
|
97
97
|
const EXPORT_CONFIGS = [
|
|
98
98
|
{
|
|
99
99
|
exportName: 'default',
|
|
100
|
-
getBlockName: (key) =>
|
|
100
|
+
getBlockName: (key) => (0, helper_1.getComponentScriptName)(key, 'esm'),
|
|
101
101
|
description: 'Default',
|
|
102
102
|
supportSeparateFile: false,
|
|
103
103
|
target: 'browser',
|
|
104
104
|
external: [],
|
|
105
105
|
},
|
|
106
|
-
// {
|
|
107
|
-
// exportName: 'default',
|
|
108
|
-
// getBlockName: (key) => `${key}(default)`,
|
|
109
|
-
// description: 'Default CJS',
|
|
110
|
-
// supportSeparateFile: false,
|
|
111
|
-
// target: 'node',
|
|
112
|
-
// external: [],
|
|
113
|
-
// },
|
|
114
106
|
{
|
|
115
107
|
exportName: helper_1.EDIT_COMPONENT_NAME,
|
|
116
108
|
getBlockName: helper_1.getEditComponentBlockName,
|
|
@@ -514,7 +506,7 @@ function vitePluginCodeSplitter(options) {
|
|
|
514
506
|
return null; // Regular component file, defaults to browser
|
|
515
507
|
}
|
|
516
508
|
const exportName = match[1];
|
|
517
|
-
return EXPORT_CONFIGS.find((config) => config.
|
|
509
|
+
return EXPORT_CONFIGS.find((config) => config.getBlockName('').includes(exportName));
|
|
518
510
|
};
|
|
519
511
|
/**
|
|
520
512
|
* 🎯 FILE TYPE CLASSIFIER
|