@peerbit/vite 0.0.1-cccc078

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.
@@ -0,0 +1,10 @@
1
+ import { type PluginOption } from "vite";
2
+ declare const _default: (options?: {
3
+ packages?: string[];
4
+ assets?: {
5
+ src: string;
6
+ dest: string;
7
+ }[];
8
+ }) => PluginOption[];
9
+ export default _default;
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,MAAM,CAAC;mCAqE/B;IACR,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,MAAM,CAAC,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CACzC,KACC,YAAY,EAAE;AALjB,wBAkBE"}
@@ -0,0 +1,94 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import {} from "vite";
4
+ function dontMinimizeCertainPackagesPlugin(options = {}) {
5
+ options.packages = [
6
+ ...(options.packages || []),
7
+ "@sqlite.org/sqlite-wasm",
8
+ "@peerbit/any-store",
9
+ "@peerbit/any-store-opfs",
10
+ ];
11
+ return {
12
+ name: "dont-minimize-certain-packages",
13
+ config(config, { command }) {
14
+ if (command === "build") {
15
+ config.optimizeDeps = config.optimizeDeps || {};
16
+ config.optimizeDeps.exclude = config.optimizeDeps.exclude || [];
17
+ config.optimizeDeps.exclude.push(...options.packages);
18
+ }
19
+ },
20
+ };
21
+ }
22
+ function copyToPublicPlugin(options = {}) {
23
+ return {
24
+ name: "copy-to-public",
25
+ buildStart() {
26
+ if (options?.assets) {
27
+ options.assets.forEach(({ src, dest }) => {
28
+ const sourcePath = path.resolve(src);
29
+ const destinationPath = path.resolve(process.cwd(), "public", dest);
30
+ copyAssets(sourcePath, destinationPath);
31
+ });
32
+ }
33
+ },
34
+ };
35
+ }
36
+ const findLibraryInNodeModules = (library) => {
37
+ // scan upwards until we find the node_modules folder
38
+ let currentDir = process.cwd();
39
+ let nodeModulesDir = path.join(currentDir, "node_modules");
40
+ while (!fs.existsSync(path.join(nodeModulesDir, library))) {
41
+ currentDir = path.resolve(currentDir, "..");
42
+ nodeModulesDir = path.join(currentDir, "node_modules");
43
+ // we have found a .git folder, so we are at the root
44
+ // then stop
45
+ if (fs.existsSync(path.join(currentDir, ".git"))) {
46
+ break;
47
+ }
48
+ }
49
+ const libraryPath = path.join(nodeModulesDir, library);
50
+ if (!fs.existsSync(libraryPath)) {
51
+ throw new Error(`Library ${library} not found in node_modules`);
52
+ }
53
+ return libraryPath;
54
+ };
55
+ let pathsToCopy = [
56
+ "@peerbit/any-store-opfs/dist/peerbit",
57
+ "@peerbit/indexer-sqlite3/dist/peerbit",
58
+ ];
59
+ export default (options = {}) => {
60
+ let defaultAssets = pathsToCopy.map((path) => {
61
+ return {
62
+ src: findLibraryInNodeModules(path),
63
+ dest: "peerbit/",
64
+ };
65
+ });
66
+ return [
67
+ dontMinimizeCertainPackagesPlugin({ packages: options.packages }),
68
+ copyToPublicPlugin({
69
+ assets: [...defaultAssets, ...(options.assets || [])],
70
+ }),
71
+ ];
72
+ };
73
+ function copyAssets(srcPath, destPath) {
74
+ if (!fs.existsSync(srcPath)) {
75
+ throw new Error(`File ${srcPath} does not exist`);
76
+ }
77
+ if (fs.statSync(srcPath).isDirectory()) {
78
+ // Ensure the directory exists in the public folder
79
+ fs.mkdirSync(destPath, { recursive: true });
80
+ // Copy each file/directory inside the current directory
81
+ fs.readdirSync(srcPath).forEach((file) => {
82
+ const srcFilePath = path.join(srcPath, file);
83
+ const destFilePath = path.join(destPath, file);
84
+ copyAssets(srcFilePath, destFilePath); // Recursion for directories
85
+ });
86
+ }
87
+ else {
88
+ // Ensure the destination directory exists
89
+ fs.mkdirSync(path.dirname(destPath), { recursive: true });
90
+ // Copy the file
91
+ fs.copyFileSync(srcPath, destPath);
92
+ }
93
+ }
94
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAqB,MAAM,MAAM,CAAC;AAEzC,SAAS,iCAAiC,CACzC,UAAmC,EAAE;IAErC,OAAO,CAAC,QAAQ,GAAG;QAClB,GAAG,CAAC,OAAO,CAAC,QAAQ,IAAI,EAAE,CAAC;QAC3B,yBAAyB;QACzB,oBAAoB;QACpB,yBAAyB;KACzB,CAAC;IACF,OAAO;QACN,IAAI,EAAE,gCAAgC;QACtC,MAAM,CAAC,MAAW,EAAE,EAAE,OAAO,EAAO;YACnC,IAAI,OAAO,KAAK,OAAO,EAAE,CAAC;gBACzB,MAAM,CAAC,YAAY,GAAG,MAAM,CAAC,YAAY,IAAI,EAAE,CAAC;gBAChD,MAAM,CAAC,YAAY,CAAC,OAAO,GAAG,MAAM,CAAC,YAAY,CAAC,OAAO,IAAI,EAAE,CAAC;gBAChE,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;YACvD,CAAC;QACF,CAAC;KACD,CAAC;AACH,CAAC;AAED,SAAS,kBAAkB,CAC1B,UAAwD,EAAE;IAE1D,OAAO;QACN,IAAI,EAAE,gBAAgB;QACtB,UAAU;YACT,IAAI,OAAO,EAAE,MAAM,EAAE,CAAC;gBACrB,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,EAAE;oBACxC,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;oBACrC,MAAM,eAAe,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EA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CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IACpC,CAAC;AACF,CAAC"}
package/package.json ADDED
@@ -0,0 +1,74 @@
1
+ {
2
+ "name": "@peerbit/vite",
3
+ "version": "0.0.1-cccc078",
4
+ "description": "Plugin for Vite to use Peerbit",
5
+ "sideEffects": false,
6
+ "type": "module",
7
+ "types": "./dist/src/index.d.ts",
8
+ "typesVersions": {
9
+ "*": {
10
+ "*": [
11
+ "*",
12
+ "dist/*",
13
+ "dist/src/*",
14
+ "dist/src/*/index"
15
+ ],
16
+ "src/*": [
17
+ "*",
18
+ "dist/*",
19
+ "dist/src/*",
20
+ "dist/src/*/index"
21
+ ]
22
+ }
23
+ },
24
+ "files": [
25
+ "src",
26
+ "dist",
27
+ "!dist/e2e",
28
+ "!dist/test",
29
+ "!**/*.tsbuildinfo"
30
+ ],
31
+ "exports": {
32
+ ".": {
33
+ "types": "./dist/src/index.d.ts",
34
+ "import": "./dist/src/index.js"
35
+ }
36
+ },
37
+ "eslintConfig": {
38
+ "extends": "peerbit",
39
+ "parserOptions": {
40
+ "project": true,
41
+ "sourceType": "module"
42
+ },
43
+ "ignorePatterns": [
44
+ "!.aegir.js",
45
+ "test/ts-use",
46
+ "*.d.ts"
47
+ ]
48
+ },
49
+ "publishConfig": {
50
+ "access": "public"
51
+ },
52
+ "scripts": {
53
+ "clean": "aegir clean",
54
+ "build": "aegir build --no-bundle",
55
+ "test": "",
56
+ "lint": "aegir lint"
57
+ },
58
+ "repository": {
59
+ "type": "git",
60
+ "url": "https://github.com/dao-xyz/peerbit"
61
+ },
62
+ "engines": {
63
+ "node": ">=16.15.1"
64
+ },
65
+ "author": "dao.xyz",
66
+ "license": "MIT",
67
+ "dependencies": {
68
+ "vite": "^5.0.10"
69
+ },
70
+ "devDependencies": {},
71
+ "localMaintainers": [
72
+ "dao.xyz"
73
+ ]
74
+ }
package/src/index.ts ADDED
@@ -0,0 +1,114 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import { type PluginOption } from "vite";
4
+
5
+ function dontMinimizeCertainPackagesPlugin(
6
+ options: { packages?: string[] } = {},
7
+ ) {
8
+ options.packages = [
9
+ ...(options.packages || []),
10
+ "@sqlite.org/sqlite-wasm",
11
+ "@peerbit/any-store",
12
+ "@peerbit/any-store-opfs",
13
+ ];
14
+ return {
15
+ name: "dont-minimize-certain-packages",
16
+ config(config: any, { command }: any) {
17
+ if (command === "build") {
18
+ config.optimizeDeps = config.optimizeDeps || {};
19
+ config.optimizeDeps.exclude = config.optimizeDeps.exclude || [];
20
+ config.optimizeDeps.exclude.push(...options.packages);
21
+ }
22
+ },
23
+ };
24
+ }
25
+
26
+ function copyToPublicPlugin(
27
+ options: { assets?: { src: string; dest: string }[] } = {},
28
+ ) {
29
+ return {
30
+ name: "copy-to-public",
31
+ buildStart() {
32
+ if (options?.assets) {
33
+ options.assets.forEach(({ src, dest }) => {
34
+ const sourcePath = path.resolve(src);
35
+ const destinationPath = path.resolve(process.cwd(), "public", dest);
36
+
37
+ copyAssets(sourcePath, destinationPath);
38
+ });
39
+ }
40
+ },
41
+ };
42
+ }
43
+
44
+ const findLibraryInNodeModules = (library: string) => {
45
+ // scan upwards until we find the node_modules folder
46
+ let currentDir = process.cwd();
47
+ let nodeModulesDir = path.join(currentDir, "node_modules");
48
+
49
+ while (!fs.existsSync(path.join(nodeModulesDir, library))) {
50
+ currentDir = path.resolve(currentDir, "..");
51
+ nodeModulesDir = path.join(currentDir, "node_modules");
52
+
53
+ // we have found a .git folder, so we are at the root
54
+ // then stop
55
+ if (fs.existsSync(path.join(currentDir, ".git"))) {
56
+ break;
57
+ }
58
+ }
59
+ const libraryPath = path.join(nodeModulesDir, library);
60
+ if (!fs.existsSync(libraryPath)) {
61
+ throw new Error(`Library ${library} not found in node_modules`);
62
+ }
63
+
64
+ return libraryPath;
65
+ };
66
+
67
+ let pathsToCopy = [
68
+ "@peerbit/any-store-opfs/dist/peerbit",
69
+ "@peerbit/indexer-sqlite3/dist/peerbit",
70
+ ];
71
+ export default (
72
+ options: {
73
+ packages?: string[];
74
+ assets?: { src: string; dest: string }[];
75
+ } = {},
76
+ ): PluginOption[] => {
77
+ let defaultAssets = pathsToCopy.map((path) => {
78
+ return {
79
+ src: findLibraryInNodeModules(path),
80
+ dest: "peerbit/",
81
+ };
82
+ });
83
+ return [
84
+ dontMinimizeCertainPackagesPlugin({ packages: options.packages }),
85
+ copyToPublicPlugin({
86
+ assets: [...defaultAssets, ...(options.assets || [])],
87
+ }),
88
+ ];
89
+ };
90
+
91
+ function copyAssets(srcPath: string, destPath: string) {
92
+ if (!fs.existsSync(srcPath)) {
93
+ throw new Error(`File ${srcPath} does not exist`);
94
+ }
95
+
96
+ if (fs.statSync(srcPath).isDirectory()) {
97
+ // Ensure the directory exists in the public folder
98
+ fs.mkdirSync(destPath, { recursive: true });
99
+
100
+ // Copy each file/directory inside the current directory
101
+ fs.readdirSync(srcPath).forEach((file) => {
102
+ const srcFilePath = path.join(srcPath, file);
103
+ const destFilePath = path.join(destPath, file);
104
+
105
+ copyAssets(srcFilePath, destFilePath); // Recursion for directories
106
+ });
107
+ } else {
108
+ // Ensure the destination directory exists
109
+ fs.mkdirSync(path.dirname(destPath), { recursive: true });
110
+
111
+ // Copy the file
112
+ fs.copyFileSync(srcPath, destPath);
113
+ }
114
+ }