@embeddable.com/sdk-core 4.3.0-next.0 → 4.3.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/lib/generate.d.ts +2 -0
- package/lib/index.esm.js +6 -2
- package/lib/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/generate.test.ts +87 -1
- package/src/generate.ts +14 -10
package/package.json
CHANGED
package/src/generate.test.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import generate, {
|
|
2
2
|
resetForTesting, TRIGGER_BUILD_ITERATION_LIMIT,
|
|
3
|
-
triggerWebComponentRebuild, generateDTS
|
|
3
|
+
triggerWebComponentRebuild, generateDTS,
|
|
4
|
+
injectBundleRender, injectCSS,
|
|
4
5
|
} from "./generate";
|
|
5
6
|
import * as fs from "node:fs/promises";
|
|
6
7
|
import * as path from "node:path";
|
|
@@ -67,6 +68,7 @@ vi.mock("node:path", async () => {
|
|
|
67
68
|
...actual,
|
|
68
69
|
resolve: vi.fn(),
|
|
69
70
|
join: vi.fn(),
|
|
71
|
+
relative: vi.fn(),
|
|
70
72
|
};
|
|
71
73
|
});
|
|
72
74
|
|
|
@@ -88,6 +90,7 @@ describe("generate", () => {
|
|
|
88
90
|
"styles.css",
|
|
89
91
|
] as any);
|
|
90
92
|
vi.mocked(path.resolve).mockImplementation((...args) => args.join("/"));
|
|
93
|
+
vi.mocked(path.relative).mockReturnValue("../buildDir/buildName");
|
|
91
94
|
vi.mocked(fs.readFile).mockResolvedValue("");
|
|
92
95
|
vi.mocked(loadConfig).mockResolvedValue({
|
|
93
96
|
config: {},
|
|
@@ -316,9 +319,92 @@ describe("generateDTS", () => {
|
|
|
316
319
|
});
|
|
317
320
|
});
|
|
318
321
|
|
|
322
|
+
describe("injectBundleRender cross-platform paths", () => {
|
|
323
|
+
const ctxWithFileName = {
|
|
324
|
+
...config,
|
|
325
|
+
"sdk-react": {
|
|
326
|
+
...config["sdk-react"],
|
|
327
|
+
outputOptions: {
|
|
328
|
+
buildName: "buildName",
|
|
329
|
+
fileName: "render.js",
|
|
330
|
+
},
|
|
331
|
+
},
|
|
332
|
+
};
|
|
333
|
+
|
|
334
|
+
beforeEach(() => {
|
|
335
|
+
vi.mocked(path.resolve).mockImplementation((...args) => args.join("/"));
|
|
336
|
+
vi.mocked(fs.readFile).mockResolvedValue("{{RENDER_IMPORT}}");
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
it("should use forward slashes in import when path.relative returns unix path", async () => {
|
|
340
|
+
vi.mocked(path.relative).mockReturnValue("../../buildDir/buildName");
|
|
341
|
+
|
|
342
|
+
await injectBundleRender(
|
|
343
|
+
ctxWithFileName as unknown as ResolvedEmbeddableConfig,
|
|
344
|
+
"sdk-react",
|
|
345
|
+
);
|
|
346
|
+
|
|
347
|
+
expect(fs.writeFile).toHaveBeenCalledWith(
|
|
348
|
+
expect.any(String),
|
|
349
|
+
expect.stringContaining("import render from '../../buildDir/buildName/render.js'"),
|
|
350
|
+
);
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
it("should replace backslashes with forward slashes when path.relative returns windows path", async () => {
|
|
354
|
+
vi.mocked(path.relative).mockReturnValue("..\\..\\buildDir\\buildName");
|
|
355
|
+
|
|
356
|
+
await injectBundleRender(
|
|
357
|
+
ctxWithFileName as unknown as ResolvedEmbeddableConfig,
|
|
358
|
+
"sdk-react",
|
|
359
|
+
);
|
|
360
|
+
|
|
361
|
+
expect(fs.writeFile).toHaveBeenCalledWith(
|
|
362
|
+
expect.any(String),
|
|
363
|
+
expect.stringContaining("import render from '../../buildDir/buildName/render.js'"),
|
|
364
|
+
);
|
|
365
|
+
});
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
describe("injectCSS cross-platform paths", () => {
|
|
369
|
+
beforeEach(() => {
|
|
370
|
+
vi.mocked(path.resolve).mockImplementation((...args) => args.join("/"));
|
|
371
|
+
vi.mocked(fs.readFile).mockResolvedValue("{{STYLES_IMPORT}}");
|
|
372
|
+
vi.mocked(fs.readdir).mockResolvedValue(["main.css"] as any);
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
it("should use forward slashes in @import when path.relative returns unix path", async () => {
|
|
376
|
+
vi.mocked(path.relative).mockReturnValue("../../buildDir/buildName");
|
|
377
|
+
|
|
378
|
+
await injectCSS(
|
|
379
|
+
config as unknown as ResolvedEmbeddableConfig,
|
|
380
|
+
"sdk-react",
|
|
381
|
+
);
|
|
382
|
+
|
|
383
|
+
expect(fs.writeFile).toHaveBeenCalledWith(
|
|
384
|
+
expect.any(String),
|
|
385
|
+
expect.stringContaining("@import '../../buildDir/buildName/main.css'"),
|
|
386
|
+
);
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
it("should replace backslashes with forward slashes when path.relative returns windows path", async () => {
|
|
390
|
+
vi.mocked(path.relative).mockReturnValue("..\\..\\buildDir\\buildName");
|
|
391
|
+
|
|
392
|
+
await injectCSS(
|
|
393
|
+
config as unknown as ResolvedEmbeddableConfig,
|
|
394
|
+
"sdk-react",
|
|
395
|
+
);
|
|
396
|
+
|
|
397
|
+
expect(fs.writeFile).toHaveBeenCalledWith(
|
|
398
|
+
expect.any(String),
|
|
399
|
+
expect.stringContaining("@import '../../buildDir/buildName/main.css'"),
|
|
400
|
+
);
|
|
401
|
+
});
|
|
402
|
+
});
|
|
403
|
+
|
|
319
404
|
describe("generate stencil build error", () => {
|
|
320
405
|
beforeEach(() => {
|
|
321
406
|
vi.mocked(path.resolve).mockImplementation((...args) => args.join("/"));
|
|
407
|
+
vi.mocked(path.relative).mockReturnValue("../buildDir/buildName");
|
|
322
408
|
vi.mocked(fs.readFile).mockResolvedValue("");
|
|
323
409
|
vi.mocked(fs.readdir).mockResolvedValue([] as any);
|
|
324
410
|
vi.mocked(loadConfig).mockResolvedValue({ config: {} } as any);
|
package/src/generate.ts
CHANGED
|
@@ -108,7 +108,7 @@ export async function generateDTS(
|
|
|
108
108
|
await runStencil(ctx, { dtsOnly: true });
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
-
async function injectCSS(
|
|
111
|
+
export async function injectCSS(
|
|
112
112
|
ctx: ResolvedEmbeddableConfig,
|
|
113
113
|
pluginName: PluginName,
|
|
114
114
|
) {
|
|
@@ -118,10 +118,12 @@ async function injectCSS(
|
|
|
118
118
|
);
|
|
119
119
|
const allFiles = await fs.readdir(CUSTOMER_BUILD);
|
|
120
120
|
|
|
121
|
-
const importFilePath = path
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
121
|
+
const importFilePath = path
|
|
122
|
+
.relative(
|
|
123
|
+
ctx.client.componentDir,
|
|
124
|
+
path.resolve(ctx.client.buildDir, ctx[pluginName].outputOptions.buildName),
|
|
125
|
+
)
|
|
126
|
+
.replaceAll("\\", "/");
|
|
125
127
|
|
|
126
128
|
const imports = allFiles
|
|
127
129
|
.filter((fileName) => fileName.endsWith(".css"))
|
|
@@ -153,14 +155,16 @@ async function injectCSS(
|
|
|
153
155
|
);
|
|
154
156
|
}
|
|
155
157
|
|
|
156
|
-
async function injectBundleRender(
|
|
158
|
+
export async function injectBundleRender(
|
|
157
159
|
ctx: ResolvedEmbeddableConfig,
|
|
158
160
|
pluginName: PluginName,
|
|
159
161
|
) {
|
|
160
|
-
const importFilePath = path
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
162
|
+
const importFilePath = path
|
|
163
|
+
.relative(
|
|
164
|
+
ctx.client.componentDir,
|
|
165
|
+
path.resolve(ctx.client.buildDir, ctx[pluginName].outputOptions.buildName),
|
|
166
|
+
)
|
|
167
|
+
.replaceAll("\\", "/");
|
|
164
168
|
const importStr = `import render from '${importFilePath}/${ctx[pluginName].outputOptions.fileName}';`;
|
|
165
169
|
|
|
166
170
|
let content = await fs.readFile(
|