@embeddable.com/sdk-react 3.11.6 → 3.11.7-next.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.
- package/lib/generate.d.ts +29 -0
- package/lib/generate.test.d.ts +1 -0
- package/lib/index.esm.js +43 -14
- package/lib/index.esm.js.map +1 -1
- package/package.json +3 -3
package/lib/generate.d.ts
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
import * as vite from "vite";
|
|
2
|
+
import { WatcherOptions } from "rollup";
|
|
2
3
|
import { ResolvedEmbeddableConfig } from "@embeddable.com/sdk-core";
|
|
4
|
+
import { LogLevel } from "vite";
|
|
3
5
|
export declare const EMB_FILE_REGEX: RegExp;
|
|
4
6
|
declare const _default: (ctx: ResolvedEmbeddableConfig) => Promise<vite.Rollup.RollupOutput | vite.Rollup.RollupOutput[] | vite.Rollup.RollupWatcher>;
|
|
5
7
|
export default _default;
|
|
8
|
+
export declare function getViteConfig(ctx: ResolvedEmbeddableConfig, watch: WatcherOptions | null, plugins: any[]): {
|
|
9
|
+
logLevel: LogLevel;
|
|
10
|
+
resolve: {
|
|
11
|
+
alias?: Record<string, string>;
|
|
12
|
+
extensions: string[];
|
|
13
|
+
};
|
|
14
|
+
plugins: any[];
|
|
15
|
+
build: {
|
|
16
|
+
sourcemap: boolean | "inline";
|
|
17
|
+
watch: {
|
|
18
|
+
include: string[];
|
|
19
|
+
exclude: string[];
|
|
20
|
+
} | undefined;
|
|
21
|
+
minify: boolean;
|
|
22
|
+
rollupOptions: vite.Rollup.RollupOptions;
|
|
23
|
+
lib: {
|
|
24
|
+
entry: string;
|
|
25
|
+
formats: vite.LibraryFormats[];
|
|
26
|
+
fileName: string;
|
|
27
|
+
};
|
|
28
|
+
outDir: string;
|
|
29
|
+
};
|
|
30
|
+
define: {
|
|
31
|
+
"process.env.NODE_ENV": string;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
export declare function runViteBuild(ctx: ResolvedEmbeddableConfig, watch?: WatcherOptions | null): Promise<vite.Rollup.RollupOutput | vite.Rollup.RollupOutput[] | vite.Rollup.RollupWatcher>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/lib/index.esm.js
CHANGED
|
@@ -449,12 +449,12 @@ const loadJson = async (filePath) => {
|
|
|
449
449
|
|
|
450
450
|
const getComponentLibraryConfig = (componentLibrary) => {
|
|
451
451
|
let libraryName = componentLibrary;
|
|
452
|
-
|
|
452
|
+
let include;
|
|
453
453
|
const exclude = [];
|
|
454
454
|
if (typeof componentLibrary === "object" && componentLibrary !== null) {
|
|
455
455
|
libraryName = componentLibrary.name;
|
|
456
456
|
if (componentLibrary.include) {
|
|
457
|
-
include
|
|
457
|
+
include = [...componentLibrary.include];
|
|
458
458
|
}
|
|
459
459
|
if (componentLibrary.exclude) {
|
|
460
460
|
exclude.push(...componentLibrary.exclude);
|
|
@@ -468,7 +468,7 @@ const getComponentLibraryMeta = async (ctx, componentLibrary) => {
|
|
|
468
468
|
const libraryMeta = (await loadJson(getLibraryPath(ctx, libraryName, EXTERNAL_LIBRARY_META_FILE_NAME)));
|
|
469
469
|
const filterItems = (items) => {
|
|
470
470
|
let result = items;
|
|
471
|
-
if (include
|
|
471
|
+
if (include) {
|
|
472
472
|
result = result.filter((item) => include.includes(item));
|
|
473
473
|
}
|
|
474
474
|
return result.filter((item) => !exclude.includes(item));
|
|
@@ -1126,7 +1126,7 @@ const styledComponentsEntrypointModifier = {
|
|
|
1126
1126
|
const packageJsonFilePath = path.resolve(ctx.client.rootDir, "package.json");
|
|
1127
1127
|
try {
|
|
1128
1128
|
const packageJson = JSON.parse(await fs.readFile(packageJsonFilePath, "utf-8"));
|
|
1129
|
-
return !!
|
|
1129
|
+
return !!hasPackage(packageJson, "styled-components");
|
|
1130
1130
|
}
|
|
1131
1131
|
catch (error) {
|
|
1132
1132
|
console.error("styledComponentsEntrypointModifier: Error reading package.json", error);
|
|
@@ -1137,7 +1137,7 @@ const styledComponentsEntrypointModifier = {
|
|
|
1137
1137
|
|
|
1138
1138
|
const entrypointModifiers = [
|
|
1139
1139
|
styledComponentsEntrypointModifier,
|
|
1140
|
-
emotionReactEntrypointModifier
|
|
1140
|
+
emotionReactEntrypointModifier,
|
|
1141
1141
|
];
|
|
1142
1142
|
|
|
1143
1143
|
function findFilesWithWrongUsage(directory, pattern, mustEndWith = []) {
|
|
@@ -1333,7 +1333,7 @@ function getViteConfig(ctx, watch, plugins) {
|
|
|
1333
1333
|
},
|
|
1334
1334
|
plugins,
|
|
1335
1335
|
build: {
|
|
1336
|
-
sourcemap: true,
|
|
1336
|
+
sourcemap: watch ? "inline" : true, // Inline sourcemaps are faster in dev
|
|
1337
1337
|
watch: watch
|
|
1338
1338
|
? {
|
|
1339
1339
|
include: [ctx.client.srcDir + "/**"],
|
|
@@ -1344,6 +1344,7 @@ function getViteConfig(ctx, watch, plugins) {
|
|
|
1344
1344
|
rollupOptions: watch
|
|
1345
1345
|
? {
|
|
1346
1346
|
cache: true,
|
|
1347
|
+
treeshake: false, // Faster builds in dev
|
|
1347
1348
|
...ctx.client.rollupOptions,
|
|
1348
1349
|
output: {
|
|
1349
1350
|
sourcemapPathTransform: (relativeSourcePath, sourcemapPath) => {
|
|
@@ -1375,38 +1376,66 @@ async function calculateBundleHash(ctx) {
|
|
|
1375
1376
|
ctx.client.bundleHash = getContentHash(contentString);
|
|
1376
1377
|
}
|
|
1377
1378
|
async function runViteBuild(ctx, watch = null) {
|
|
1379
|
+
// In watch mode (development), combine both builds into one to avoid duplication
|
|
1380
|
+
if (watch) {
|
|
1381
|
+
const { externalComponents, externalEditors } = await findExternalComponents(ctx);
|
|
1382
|
+
return await vite.build(getViteConfig(ctx, watch, [
|
|
1383
|
+
viteReactPlugin(),
|
|
1384
|
+
validateComponentMetaPlugin(EMB_FILE_REGEX),
|
|
1385
|
+
extractComponentsConfigPlugin({
|
|
1386
|
+
isDev: true,
|
|
1387
|
+
globalKey: "componentsMeta",
|
|
1388
|
+
fileName: "embeddable-components-meta.js",
|
|
1389
|
+
outputDir: ctx.client.buildDir,
|
|
1390
|
+
componentFileRegex: EMB_FILE_REGEX,
|
|
1391
|
+
searchEntry: "defineComponent",
|
|
1392
|
+
useBundleHash: false,
|
|
1393
|
+
ctx,
|
|
1394
|
+
externalComponents: externalComponents,
|
|
1395
|
+
}),
|
|
1396
|
+
extractComponentsConfigPlugin({
|
|
1397
|
+
isDev: true,
|
|
1398
|
+
globalKey: "editorsMeta",
|
|
1399
|
+
fileName: "embeddable-editors-meta.js",
|
|
1400
|
+
outputDir: ctx.client.buildDir,
|
|
1401
|
+
componentFileRegex: EMB_FILE_REGEX,
|
|
1402
|
+
searchEntry: "defineEditor",
|
|
1403
|
+
useBundleHash: false,
|
|
1404
|
+
ctx,
|
|
1405
|
+
externalComponents: externalEditors,
|
|
1406
|
+
}),
|
|
1407
|
+
]));
|
|
1408
|
+
}
|
|
1378
1409
|
// Step 1: Initial build without extractComponentsConfigPlugin
|
|
1379
1410
|
await vite.build(getViteConfig(ctx, watch, [
|
|
1380
1411
|
viteReactPlugin(),
|
|
1381
1412
|
validateComponentMetaPlugin(EMB_FILE_REGEX),
|
|
1382
1413
|
]));
|
|
1383
1414
|
// Step 2: Calculate bundleHash in production mode
|
|
1384
|
-
|
|
1385
|
-
await calculateBundleHash(ctx);
|
|
1386
|
-
}
|
|
1415
|
+
await calculateBundleHash(ctx);
|
|
1387
1416
|
const { externalComponents, externalEditors } = await findExternalComponents(ctx);
|
|
1388
1417
|
// Step 3: Final build with extractComponentsConfigPlugin
|
|
1389
1418
|
return await vite.build(getViteConfig(ctx, watch, [
|
|
1390
1419
|
viteReactPlugin(),
|
|
1391
1420
|
extractComponentsConfigPlugin({
|
|
1392
|
-
isDev:
|
|
1421
|
+
isDev: false,
|
|
1393
1422
|
globalKey: "componentsMeta",
|
|
1394
1423
|
fileName: "embeddable-components-meta.js",
|
|
1395
1424
|
outputDir: ctx.client.buildDir,
|
|
1396
1425
|
componentFileRegex: EMB_FILE_REGEX,
|
|
1397
1426
|
searchEntry: "defineComponent",
|
|
1398
|
-
useBundleHash:
|
|
1427
|
+
useBundleHash: true,
|
|
1399
1428
|
ctx,
|
|
1400
1429
|
externalComponents: externalComponents,
|
|
1401
1430
|
}),
|
|
1402
1431
|
extractComponentsConfigPlugin({
|
|
1403
|
-
isDev:
|
|
1432
|
+
isDev: false,
|
|
1404
1433
|
globalKey: "editorsMeta",
|
|
1405
1434
|
fileName: "embeddable-editors-meta.js",
|
|
1406
1435
|
outputDir: ctx.client.buildDir,
|
|
1407
1436
|
componentFileRegex: EMB_FILE_REGEX,
|
|
1408
1437
|
searchEntry: "defineEditor",
|
|
1409
|
-
useBundleHash:
|
|
1438
|
+
useBundleHash: true,
|
|
1410
1439
|
ctx,
|
|
1411
1440
|
externalComponents: externalEditors,
|
|
1412
1441
|
}),
|
|
@@ -1471,7 +1500,7 @@ const findExternalComponents = async (ctx) => {
|
|
|
1471
1500
|
const externalComponents = [];
|
|
1472
1501
|
const externalEditors = [];
|
|
1473
1502
|
for (const componentLibrary of componentLibraries) {
|
|
1474
|
-
const { libraryName} = getComponentLibraryConfig(componentLibrary);
|
|
1503
|
+
const { libraryName } = getComponentLibraryConfig(componentLibrary);
|
|
1475
1504
|
try {
|
|
1476
1505
|
const libMeta = await getComponentLibraryMeta(ctx, componentLibrary);
|
|
1477
1506
|
if (libMeta.plugin !== "react") {
|