Skip to content

Commit 01b26d2

Browse files
authored
Merge pull request #30 from forge-42/rr7_and_asset_inline_fix
Rr7 and asset inline fix
2 parents 8de76e0 + 9b540ee commit 01b26d2

19 files changed

+4711
-11484
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,5 @@ dist
129129
.yarn/install-state.gz
130130
.pnp.*
131131
/dist
132-
.history
132+
.history
133+
.react-router

package-lock.json

Lines changed: 4462 additions & 11163 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vite-plugin-icons-spritesheet",
3-
"version": "2.2.1",
3+
"version": "3.0.0",
44
"description": "Vite plugin that generates a spritesheet and types out of your icons folder.",
55
"main": "./dist/index.js",
66
"module": "./dist/index.mjs",
@@ -19,15 +19,15 @@
1919
"exports": {
2020
".": {
2121
"import": {
22+
"types": "./dist/index.d.mts",
2223
"import": "./dist/index.mjs",
23-
"default": "./dist/index.mjs",
24-
"types": "./dist/index.d.mts"
24+
"default": "./dist/index.mjs"
2525
},
2626
"require": {
27+
"types": "./dist/index.d.ts",
2728
"import": "./dist/index.js",
2829
"require": "./dist/index.js",
29-
"default": "./dist/index.js",
30-
"types": "./dist/index.d.ts"
30+
"default": "./dist/index.js"
3131
}
3232
}
3333
},
@@ -67,27 +67,23 @@
6767
],
6868
"homepage": "https://github.com/forge42dev/vite-plugin-icons-spritesheet#readme",
6969
"dependencies": {
70-
"chalk": "^4.1.2",
71-
"glob": "^10.3.12",
72-
"node-html-parser": "^6.1.13",
70+
"chalk": "^5.4.1",
71+
"glob": "^11.0.1",
72+
"node-html-parser": "^7.0.1",
7373
"tinyexec": "^0.3.2"
7474
},
7575
"peerDependencies": {
7676
"vite": ">=5.2.0"
7777
},
7878
"devDependencies": {
79-
"@types/node": "^20.12.7",
80-
"@typescript-eslint/eslint-plugin": "^7.5.0",
81-
"@typescript-eslint/parser": "^7.5.0",
82-
"@vitest/coverage-v8": "^1.5.2",
83-
"eslint": "8.56",
84-
"eslint-plugin-unused-imports": "^3.1.0",
85-
"happy-dom": "^14.7.1",
86-
"husky": "^9.0.11",
79+
"@types/node": "^22.13.1",
80+
"@vitest/coverage-v8": "^3.0.5",
81+
"happy-dom": "^16.8.1",
82+
"husky": "^9.1.7",
8783
"npm-run-all": "^4.1.5",
88-
"tsup": "^8.0.2",
89-
"typescript": "^5.4.5",
90-
"vite": "5.2.11",
91-
"vitest": "^1.5.2"
84+
"tsup": "^8.3.6",
85+
"typescript": "^5.7.3",
86+
"vite": "6.0.11",
87+
"vitest": "^3.0.5"
9288
}
93-
}
89+
}

src/index.ts

Lines changed: 41 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
/*eslint-disable no-console */
22
import { promises as fs } from "node:fs";
3+
import { mkdir } from "node:fs/promises";
34
import path from "node:path";
5+
import { stderr } from "node:process";
6+
import { Readable } from "node:stream";
7+
import chalk from "chalk";
48
import { glob } from "glob";
59
import { parse } from "node-html-parser";
6-
import chalk from "chalk";
10+
import { exec } from "tinyexec";
711
import type { Plugin } from "vite";
812
import { normalizePath } from "vite";
9-
import { mkdir } from "node:fs/promises";
10-
import { exec } from "tinyexec";
11-
import { stderr } from "node:process";
12-
import { Readable } from "node:stream";
1313

1414
type Formatter = "biome" | "prettier";
1515

@@ -45,14 +45,7 @@ interface PluginProps {
4545
* @default no formatter
4646
* @example "biome"
4747
*/
48-
formatter?: Formatter;
49-
/**
50-
* The path to the formatter config file
51-
* @default no path
52-
* @example "./biome.json"
53-
* @deprecated no need to provide a config path anymore
54-
*/
55-
pathToFormatterConfig?: string;
48+
formatter?: Formatter;
5649
/**
5750
* The cwd, defaults to process.cwd()
5851
* @default process.cwd()
@@ -201,14 +194,13 @@ async function lintFileContent(fileContent: string, formatter: Formatter | undef
201194
stdinStream.push(null);
202195

203196
const { process } = exec(formatter, options, {});
204-
if (!process?.stdin) {
205-
console.error("no process");
206-
return "";
197+
if (!process?.stdin) {
198+
return fileContent;
207199
}
208200
stdinStream.pipe(process.stdin);
209201
process.stderr?.pipe(stderr);
210-
process.on("error", (error) => {
211-
console.error(error);
202+
process.on("error", ( ) => {
203+
return fileContent
212204
});
213205
const formattedContent = await new Promise<string>((resolve) => {
214206
process.stdout?.on("data", (data) => {
@@ -218,12 +210,12 @@ async function lintFileContent(fileContent: string, formatter: Formatter | undef
218210
resolve(data.toString());
219211
});
220212
});
221-
return new Promise<string>((resolve, reject) => {
213+
return new Promise<string>((resolve) => {
222214
process.on("exit", (code) => {
223215
if (code === 0) {
224216
resolve(formattedContent);
225217
} else {
226-
reject(new Error(`${formatter} failed`));
218+
resolve(fileContent);
227219
}
228220
});
229221
});
@@ -286,8 +278,7 @@ export const iconsSpritesheet: (args: PluginProps | PluginProps[]) => any = (may
286278
fileName,
287279
cwd,
288280
iconNameTransformer,
289-
formatter,
290-
pathToFormatterConfig,
281+
formatter,
291282
} = config;
292283
const iconGenerator = async () =>
293284
generateIcons({
@@ -299,9 +290,7 @@ export const iconsSpritesheet: (args: PluginProps | PluginProps[]) => any = (may
299290
iconNameTransformer,
300291
formatter,
301292
});
302-
if (pathToFormatterConfig) {
303-
console.warn("\"pathToFormatterConfig\" is deprecated, please remove it from your config");
304-
}
293+
305294
const workDir = cwd ?? process.cwd();
306295
return {
307296
name: `icon-spritesheet-generator${i > 0 ? i.toString() : ""}`,
@@ -320,34 +309,35 @@ export const iconsSpritesheet: (args: PluginProps | PluginProps[]) => any = (may
320309
await iconGenerator();
321310
}
322311
},
323-
// Augment the config with our own assetsInlineLimit function, we want to do this only once
324-
async configResolved(config) {
325-
if (i === 0) {
326-
const subFunc =
327-
typeof config.build.assetsInlineLimit === "function" ? config.build.assetsInlineLimit : undefined;
328-
const limit = typeof config.build.assetsInlineLimit === "number" ? config.build.assetsInlineLimit : undefined;
312+
async config(config) {
313+
if (!config.build || i > 0) {
314+
return;
315+
}
316+
const subFunc =
317+
typeof config.build.assetsInlineLimit === "function" ? config.build.assetsInlineLimit : undefined;
318+
const limit = typeof config.build.assetsInlineLimit === "number" ? config.build.assetsInlineLimit : undefined;
329319

330-
config.build.assetsInlineLimit = (name, content) => {
331-
const isSpriteSheet = allSpriteSheetNames.some((spriteSheetName) => {
332-
return name.endsWith(normalizePath(`${outputDir}/${spriteSheetName}`));
333-
});
334-
// Our spritesheet? Early return
335-
if (isSpriteSheet) {
336-
return false;
337-
}
338-
// User defined limit? Check if it's smaller than the limit
339-
if (limit) {
340-
const size = content.byteLength;
341-
return size <= limit;
342-
}
343-
// User defined function? Run it
344-
if (typeof subFunc === "function") {
345-
return subFunc(name, content);
346-
}
320+
const assetsInlineLimitFunction = (name: string, content: Buffer) => {
321+
const isSpriteSheet = allSpriteSheetNames.some((spriteSheetName) => {
322+
return name.endsWith(normalizePath(`${outputDir}/${spriteSheetName}`));
323+
});
324+
// Our spritesheet? Early return
325+
if (isSpriteSheet) {
326+
return false;
327+
}
328+
// User defined limit? Check if it's smaller than the limit
329+
if (limit) {
330+
const size = content.byteLength;
331+
return size <= limit;
332+
}
333+
// User defined function? Run it
334+
if (typeof subFunc === "function") {
335+
return subFunc(name, content);
336+
}
347337

348-
return undefined;
349-
};
350-
}
338+
return undefined;
339+
};
340+
config.build.assetsInlineLimit = assetsInlineLimitFunction;
351341
},
352342
} satisfies Plugin<unknown>;
353343
});

test-apps/remix-vite-cjs/app/entry.client.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
* For more information, see https://remix.run/file-conventions/entry.client
55
*/
66

7-
import { RemixBrowser } from "@remix-run/react";
8-
import { startTransition, StrictMode } from "react";
7+
import { StrictMode, startTransition } from "react";
98
import { hydrateRoot } from "react-dom/client";
9+
import { HydratedRouter } from "react-router/dom";
1010

1111
startTransition(() => {
1212
hydrateRoot(
1313
document,
1414
<StrictMode>
15-
<RemixBrowser />
16-
</StrictMode>
15+
<HydratedRouter />
16+
</StrictMode>,
1717
);
1818
});

0 commit comments

Comments
 (0)